]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4c38e0a4 | 5 | 2008, 2009, 2010 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
c906108c | 64 | |
1042e4c0 SS |
65 | /* readline include files */ |
66 | #include "readline/readline.h" | |
67 | #include "readline/history.h" | |
68 | ||
69 | /* readline defines this. */ | |
70 | #undef savestring | |
71 | ||
034dad6f | 72 | #include "mi/mi-common.h" |
104c1213 | 73 | |
44feb3ce TT |
74 | /* Arguments to pass as context to some catch command handlers. */ |
75 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
76 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 77 | |
44feb3ce | 78 | /* Prototypes for local functions. */ |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_command (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_once_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void disable_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_command (char *, int); |
c906108c | 87 | |
95a42b64 TT |
88 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
89 | void *), | |
90 | void *); | |
c906108c | 91 | |
a14ed312 | 92 | static void ignore_command (char *, int); |
c906108c | 93 | |
4efb68b1 | 94 | static int breakpoint_re_set_one (void *); |
c906108c | 95 | |
a14ed312 | 96 | static void clear_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void catch_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void watch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 103 | |
98deb0da | 104 | static void break_command_1 (char *, int, int); |
c906108c | 105 | |
a14ed312 | 106 | static void mention (struct breakpoint *); |
c906108c | 107 | |
63c252f8 PM |
108 | /* This function is used in gdbtk sources and thus can not be made static. */ |
109 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
110 | struct symtab_and_line, |
111 | enum bptype); | |
c906108c | 112 | |
76897487 KB |
113 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
114 | ||
a6d9a66e UW |
115 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
116 | CORE_ADDR bpaddr, | |
88f7da05 | 117 | enum bptype bptype); |
76897487 | 118 | |
6c95b8df PA |
119 | static void describe_other_breakpoints (struct gdbarch *, |
120 | struct program_space *, CORE_ADDR, | |
5af949e3 | 121 | struct obj_section *, int); |
c906108c | 122 | |
6c95b8df PA |
123 | static int breakpoint_address_match (struct address_space *aspace1, |
124 | CORE_ADDR addr1, | |
125 | struct address_space *aspace2, | |
126 | CORE_ADDR addr2); | |
127 | ||
85d721b8 PA |
128 | static int watchpoint_locations_match (struct bp_location *loc1, |
129 | struct bp_location *loc2); | |
130 | ||
a14ed312 | 131 | static void breakpoints_info (char *, int); |
c906108c | 132 | |
d77f58be SS |
133 | static void watchpoints_info (char *, int); |
134 | ||
135 | static int breakpoint_1 (int, int, int (*) (const struct breakpoint *)); | |
c906108c | 136 | |
89f9893c | 137 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 138 | |
4efb68b1 | 139 | static int breakpoint_cond_eval (void *); |
c906108c | 140 | |
4efb68b1 | 141 | static void cleanup_executing_breakpoints (void *); |
c906108c | 142 | |
a14ed312 | 143 | static void commands_command (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static void condition_command (char *, int); |
c906108c | 146 | |
a14ed312 | 147 | static int get_number_trailer (char **, int); |
c906108c | 148 | |
c5aa993b JM |
149 | typedef enum |
150 | { | |
151 | mark_inserted, | |
152 | mark_uninserted | |
153 | } | |
154 | insertion_state_t; | |
c906108c | 155 | |
0bde7532 | 156 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 157 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 158 | |
a14ed312 | 159 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
160 | |
161 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 162 | |
4efb68b1 | 163 | static int watchpoint_check (void *); |
c906108c | 164 | |
a14ed312 | 165 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 166 | |
a14ed312 | 167 | static int hw_breakpoint_used_count (void); |
c906108c | 168 | |
a14ed312 | 169 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 170 | |
a14ed312 | 171 | static void hbreak_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void thbreak_command (char *, int); |
c906108c | 174 | |
a14ed312 | 175 | static void watch_command_1 (char *, int, int); |
c906108c | 176 | |
a14ed312 | 177 | static void rwatch_command (char *, int); |
c906108c | 178 | |
a14ed312 | 179 | static void awatch_command (char *, int); |
c906108c | 180 | |
a14ed312 | 181 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 182 | |
a14ed312 | 183 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 184 | |
a14ed312 | 185 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 186 | |
a14ed312 | 187 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 190 | |
d85310f7 MS |
191 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
192 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 193 | |
a14ed312 | 194 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 195 | |
a14ed312 | 196 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 197 | |
6c95b8df PA |
198 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
199 | CORE_ADDR pc); | |
1aafd4da | 200 | |
fe3f5fa8 VP |
201 | static void free_bp_location (struct bp_location *loc); |
202 | ||
39d61571 | 203 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 204 | |
b60e7edf | 205 | static void update_global_location_list (int); |
a5606eee | 206 | |
b60e7edf | 207 | static void update_global_location_list_nothrow (int); |
74960c60 | 208 | |
d77f58be | 209 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 210 | |
d77f58be | 211 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 212 | |
74960c60 | 213 | static void insert_breakpoint_locations (void); |
a5606eee | 214 | |
a96d9b2e SDJ |
215 | static int syscall_catchpoint_p (struct breakpoint *b); |
216 | ||
1042e4c0 SS |
217 | static void tracepoints_info (char *, int); |
218 | ||
219 | static void delete_trace_command (char *, int); | |
220 | ||
221 | static void enable_trace_command (char *, int); | |
222 | ||
223 | static void disable_trace_command (char *, int); | |
224 | ||
225 | static void trace_pass_command (char *, int); | |
226 | ||
5cea2a26 PA |
227 | /* A reference-counted struct command_line. This lets multiple |
228 | breakpoints share a single command list. */ | |
229 | struct counted_command_line | |
230 | { | |
231 | /* The reference count. */ | |
232 | int refc; | |
233 | ||
234 | /* The command list. */ | |
235 | struct command_line *commands; | |
236 | }; | |
237 | ||
238 | struct command_line * | |
239 | breakpoint_commands (struct breakpoint *b) | |
240 | { | |
241 | return b->commands ? b->commands->commands : NULL; | |
242 | } | |
3daf8fe5 | 243 | |
f3b1572e PA |
244 | /* Flag indicating that a command has proceeded the inferior past the |
245 | current breakpoint. */ | |
246 | ||
247 | static int breakpoint_proceeded; | |
248 | ||
2cec12e5 AR |
249 | static const char * |
250 | bpdisp_text (enum bpdisp disp) | |
251 | { | |
252 | /* NOTE: the following values are a part of MI protocol and represent | |
253 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
254 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
255 | return bpdisps[(int) disp]; | |
256 | } | |
c906108c | 257 | |
2cec12e5 | 258 | /* Prototypes for exported functions. */ |
c906108c SS |
259 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
260 | if such is available. */ | |
261 | static int can_use_hw_watchpoints; | |
262 | ||
920d2a44 AC |
263 | static void |
264 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
265 | struct cmd_list_element *c, | |
266 | const char *value) | |
267 | { | |
268 | fprintf_filtered (file, _("\ | |
269 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
270 | value); | |
271 | } | |
272 | ||
fa8d40ab JJ |
273 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
274 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
275 | for unrecognized breakpoint locations. | |
276 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
277 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
278 | static void |
279 | show_pending_break_support (struct ui_file *file, int from_tty, | |
280 | struct cmd_list_element *c, | |
281 | const char *value) | |
282 | { | |
283 | fprintf_filtered (file, _("\ | |
284 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
285 | value); | |
286 | } | |
fa8d40ab | 287 | |
765dc015 VP |
288 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
289 | set with "break" but falling in read-only memory. | |
290 | If 0, gdb will warn about such breakpoints, but won't automatically | |
291 | use hardware breakpoints. */ | |
292 | static int automatic_hardware_breakpoints; | |
293 | static void | |
294 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
295 | struct cmd_list_element *c, | |
296 | const char *value) | |
297 | { | |
298 | fprintf_filtered (file, _("\ | |
299 | Automatic usage of hardware breakpoints is %s.\n"), | |
300 | value); | |
301 | } | |
302 | ||
33e5cbd6 PA |
303 | /* If on, gdb will keep breakpoints inserted even as inferior is |
304 | stopped, and immediately insert any new breakpoints. If off, gdb | |
305 | will insert breakpoints into inferior only when resuming it, and | |
306 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
307 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
308 | ||
309 | static const char always_inserted_auto[] = "auto"; | |
310 | static const char always_inserted_on[] = "on"; | |
311 | static const char always_inserted_off[] = "off"; | |
312 | static const char *always_inserted_enums[] = { | |
313 | always_inserted_auto, | |
314 | always_inserted_off, | |
315 | always_inserted_on, | |
316 | NULL | |
317 | }; | |
318 | static const char *always_inserted_mode = always_inserted_auto; | |
319 | static void | |
74960c60 | 320 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 321 | struct cmd_list_element *c, const char *value) |
74960c60 | 322 | { |
33e5cbd6 PA |
323 | if (always_inserted_mode == always_inserted_auto) |
324 | fprintf_filtered (file, _("\ | |
325 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
326 | value, | |
327 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
328 | else | |
329 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
330 | } |
331 | ||
33e5cbd6 PA |
332 | int |
333 | breakpoints_always_inserted_mode (void) | |
334 | { | |
335 | return (always_inserted_mode == always_inserted_on | |
336 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
337 | } | |
765dc015 | 338 | |
a14ed312 | 339 | void _initialize_breakpoint (void); |
c906108c | 340 | |
c906108c SS |
341 | /* Are we executing breakpoint commands? */ |
342 | static int executing_breakpoint_commands; | |
343 | ||
c02f5703 MS |
344 | /* Are overlay event breakpoints enabled? */ |
345 | static int overlay_events_enabled; | |
346 | ||
c906108c SS |
347 | /* Walk the following statement or block through all breakpoints. |
348 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
349 | breakpoint. */ | |
350 | ||
5c44784c | 351 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 352 | |
5c44784c JM |
353 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
354 | for (B = breakpoint_chain; \ | |
355 | B ? (TMP=B->next, 1): 0; \ | |
356 | B = TMP) | |
c906108c | 357 | |
876fa593 JK |
358 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
359 | provided so update_global_location_list must not be called while executing | |
360 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 361 | |
876fa593 JK |
362 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
363 | for (BP_TMP = bp_location; \ | |
364 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
365 | BP_TMP++) | |
7cc221ef | 366 | |
1042e4c0 SS |
367 | /* Iterator for tracepoints only. */ |
368 | ||
369 | #define ALL_TRACEPOINTS(B) \ | |
370 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 371 | if (is_tracepoint (B)) |
1042e4c0 | 372 | |
7cc221ef | 373 | /* Chains of all breakpoints defined. */ |
c906108c SS |
374 | |
375 | struct breakpoint *breakpoint_chain; | |
376 | ||
876fa593 JK |
377 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
378 | ||
379 | static struct bp_location **bp_location; | |
380 | ||
381 | /* Number of elements of BP_LOCATION. */ | |
382 | ||
383 | static unsigned bp_location_count; | |
384 | ||
385 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
386 | for the current elements of BP_LOCATION which get a valid result from | |
387 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
388 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
389 | ||
390 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
391 | ||
392 | /* Maximum offset plus alignment between | |
393 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
394 | the current elements of BP_LOCATION which get a valid result from | |
395 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
396 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
397 | ||
398 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 399 | |
20874c92 | 400 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 401 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
402 | may still be reported by a target. */ |
403 | VEC(bp_location_p) *moribund_locations = NULL; | |
404 | ||
c906108c SS |
405 | /* Number of last breakpoint made. */ |
406 | ||
95a42b64 TT |
407 | static int breakpoint_count; |
408 | ||
86b17b60 PA |
409 | /* The value of `breakpoint_count' before the last command that |
410 | created breakpoints. If the last (break-like) command created more | |
411 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
412 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
413 | static int prev_breakpoint_count; | |
c906108c | 414 | |
1042e4c0 SS |
415 | /* Number of last tracepoint made. */ |
416 | ||
95a42b64 | 417 | static int tracepoint_count; |
1042e4c0 | 418 | |
468d015d JJ |
419 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
420 | static int | |
421 | breakpoint_enabled (struct breakpoint *b) | |
422 | { | |
0d381245 | 423 | return (b->enable_state == bp_enabled); |
468d015d JJ |
424 | } |
425 | ||
c906108c SS |
426 | /* Set breakpoint count to NUM. */ |
427 | ||
95a42b64 | 428 | static void |
fba45db2 | 429 | set_breakpoint_count (int num) |
c906108c | 430 | { |
86b17b60 | 431 | prev_breakpoint_count = breakpoint_count; |
c906108c | 432 | breakpoint_count = num; |
4fa62494 | 433 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
434 | } |
435 | ||
86b17b60 PA |
436 | /* Used by `start_rbreak_breakpoints' below, to record the current |
437 | breakpoint count before "rbreak" creates any breakpoint. */ | |
438 | static int rbreak_start_breakpoint_count; | |
439 | ||
95a42b64 TT |
440 | /* Called at the start an "rbreak" command to record the first |
441 | breakpoint made. */ | |
86b17b60 | 442 | |
95a42b64 TT |
443 | void |
444 | start_rbreak_breakpoints (void) | |
445 | { | |
86b17b60 | 446 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
447 | } |
448 | ||
449 | /* Called at the end of an "rbreak" command to record the last | |
450 | breakpoint made. */ | |
86b17b60 | 451 | |
95a42b64 TT |
452 | void |
453 | end_rbreak_breakpoints (void) | |
454 | { | |
86b17b60 | 455 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
456 | } |
457 | ||
c906108c SS |
458 | /* Used in run_command to zero the hit count when a new run starts. */ |
459 | ||
460 | void | |
fba45db2 | 461 | clear_breakpoint_hit_counts (void) |
c906108c SS |
462 | { |
463 | struct breakpoint *b; | |
464 | ||
465 | ALL_BREAKPOINTS (b) | |
466 | b->hit_count = 0; | |
467 | } | |
468 | ||
9add0f1b TT |
469 | /* Allocate a new counted_command_line with reference count of 1. |
470 | The new structure owns COMMANDS. */ | |
471 | ||
472 | static struct counted_command_line * | |
473 | alloc_counted_command_line (struct command_line *commands) | |
474 | { | |
475 | struct counted_command_line *result | |
476 | = xmalloc (sizeof (struct counted_command_line)); | |
477 | result->refc = 1; | |
478 | result->commands = commands; | |
479 | return result; | |
480 | } | |
481 | ||
482 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
483 | ||
484 | static void | |
485 | incref_counted_command_line (struct counted_command_line *cmd) | |
486 | { | |
487 | if (cmd) | |
488 | ++cmd->refc; | |
489 | } | |
490 | ||
491 | /* Decrement reference count. If the reference count reaches 0, | |
492 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
493 | nothing if *CMDP is NULL. */ | |
494 | ||
495 | static void | |
496 | decref_counted_command_line (struct counted_command_line **cmdp) | |
497 | { | |
498 | if (*cmdp) | |
499 | { | |
500 | if (--(*cmdp)->refc == 0) | |
501 | { | |
502 | free_command_lines (&(*cmdp)->commands); | |
503 | xfree (*cmdp); | |
504 | } | |
505 | *cmdp = NULL; | |
506 | } | |
507 | } | |
508 | ||
509 | /* A cleanup function that calls decref_counted_command_line. */ | |
510 | ||
511 | static void | |
512 | do_cleanup_counted_command_line (void *arg) | |
513 | { | |
514 | decref_counted_command_line (arg); | |
515 | } | |
516 | ||
517 | /* Create a cleanup that calls decref_counted_command_line on the | |
518 | argument. */ | |
519 | ||
520 | static struct cleanup * | |
521 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
522 | { | |
523 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
524 | } | |
525 | ||
c906108c SS |
526 | /* Default address, symtab and line to put a breakpoint at |
527 | for "break" command with no arg. | |
528 | if default_breakpoint_valid is zero, the other three are | |
529 | not valid, and "break" with no arg is an error. | |
530 | ||
531 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
532 | ||
533 | int default_breakpoint_valid; | |
534 | CORE_ADDR default_breakpoint_address; | |
535 | struct symtab *default_breakpoint_symtab; | |
536 | int default_breakpoint_line; | |
6c95b8df PA |
537 | struct program_space *default_breakpoint_pspace; |
538 | ||
c906108c SS |
539 | \f |
540 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
541 | Advance *PP after the string and any trailing whitespace. | |
542 | ||
543 | Currently the string can either be a number or "$" followed by the name | |
544 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 545 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
546 | |
547 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
548 | |
549 | TRAILER is a character which can be found after the number; most | |
550 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 551 | static int |
fba45db2 | 552 | get_number_trailer (char **pp, int trailer) |
c906108c | 553 | { |
5c44784c | 554 | int retval = 0; /* default */ |
c906108c SS |
555 | char *p = *pp; |
556 | ||
557 | if (p == NULL) | |
558 | /* Empty line means refer to the last breakpoint. */ | |
559 | return breakpoint_count; | |
560 | else if (*p == '$') | |
561 | { | |
562 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 563 | to pass to lookup_internalvar(). */ |
c906108c SS |
564 | char *varname; |
565 | char *start = ++p; | |
4fa62494 | 566 | LONGEST val; |
c906108c SS |
567 | |
568 | while (isalnum (*p) || *p == '_') | |
569 | p++; | |
570 | varname = (char *) alloca (p - start + 1); | |
571 | strncpy (varname, start, p - start); | |
572 | varname[p - start] = '\0'; | |
4fa62494 UW |
573 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
574 | retval = (int) val; | |
5c44784c JM |
575 | else |
576 | { | |
a3f17187 | 577 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
578 | retval = 0; |
579 | } | |
c906108c SS |
580 | } |
581 | else | |
582 | { | |
583 | if (*p == '-') | |
584 | ++p; | |
585 | while (*p >= '0' && *p <= '9') | |
586 | ++p; | |
587 | if (p == *pp) | |
588 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
589 | { |
590 | /* Skip non-numeric token */ | |
591 | while (*p && !isspace((int) *p)) | |
592 | ++p; | |
593 | /* Return zero, which caller must interpret as error. */ | |
594 | retval = 0; | |
595 | } | |
596 | else | |
597 | retval = atoi (*pp); | |
598 | } | |
599 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
600 | { | |
601 | /* Trailing junk: return 0 and let caller print error msg. */ | |
602 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
603 | ++p; | |
604 | retval = 0; | |
c906108c | 605 | } |
c906108c SS |
606 | while (isspace (*p)) |
607 | p++; | |
608 | *pp = p; | |
609 | return retval; | |
610 | } | |
5c44784c | 611 | |
11cf8741 | 612 | |
5c44784c JM |
613 | /* Like get_number_trailer, but don't allow a trailer. */ |
614 | int | |
fba45db2 | 615 | get_number (char **pp) |
5c44784c JM |
616 | { |
617 | return get_number_trailer (pp, '\0'); | |
618 | } | |
619 | ||
620 | /* Parse a number or a range. | |
621 | * A number will be of the form handled by get_number. | |
622 | * A range will be of the form <number1> - <number2>, and | |
623 | * will represent all the integers between number1 and number2, | |
624 | * inclusive. | |
625 | * | |
626 | * While processing a range, this fuction is called iteratively; | |
627 | * At each call it will return the next value in the range. | |
628 | * | |
629 | * At the beginning of parsing a range, the char pointer PP will | |
630 | * be advanced past <number1> and left pointing at the '-' token. | |
631 | * Subsequent calls will not advance the pointer until the range | |
632 | * is completed. The call that completes the range will advance | |
633 | * pointer PP past <number2>. | |
634 | */ | |
635 | ||
636 | int | |
fba45db2 | 637 | get_number_or_range (char **pp) |
5c44784c JM |
638 | { |
639 | static int last_retval, end_value; | |
640 | static char *end_ptr; | |
641 | static int in_range = 0; | |
642 | ||
643 | if (**pp != '-') | |
644 | { | |
645 | /* Default case: pp is pointing either to a solo number, | |
646 | or to the first number of a range. */ | |
647 | last_retval = get_number_trailer (pp, '-'); | |
648 | if (**pp == '-') | |
649 | { | |
650 | char **temp; | |
651 | ||
652 | /* This is the start of a range (<number1> - <number2>). | |
653 | Skip the '-', parse and remember the second number, | |
654 | and also remember the end of the final token. */ | |
655 | ||
656 | temp = &end_ptr; | |
657 | end_ptr = *pp + 1; | |
658 | while (isspace ((int) *end_ptr)) | |
659 | end_ptr++; /* skip white space */ | |
660 | end_value = get_number (temp); | |
661 | if (end_value < last_retval) | |
662 | { | |
8a3fe4f8 | 663 | error (_("inverted range")); |
5c44784c JM |
664 | } |
665 | else if (end_value == last_retval) | |
666 | { | |
667 | /* degenerate range (number1 == number2). Advance the | |
668 | token pointer so that the range will be treated as a | |
669 | single number. */ | |
670 | *pp = end_ptr; | |
671 | } | |
672 | else | |
673 | in_range = 1; | |
674 | } | |
675 | } | |
676 | else if (! in_range) | |
8a3fe4f8 | 677 | error (_("negative value")); |
5c44784c JM |
678 | else |
679 | { | |
680 | /* pp points to the '-' that betokens a range. All | |
681 | number-parsing has already been done. Return the next | |
682 | integer value (one greater than the saved previous value). | |
683 | Do not advance the token pointer 'pp' until the end of range | |
684 | is reached. */ | |
685 | ||
686 | if (++last_retval == end_value) | |
687 | { | |
688 | /* End of range reached; advance token pointer. */ | |
689 | *pp = end_ptr; | |
690 | in_range = 0; | |
691 | } | |
692 | } | |
693 | return last_retval; | |
694 | } | |
695 | ||
48cb2d85 VP |
696 | /* Return the breakpoint with the specified number, or NULL |
697 | if the number does not refer to an existing breakpoint. */ | |
698 | ||
699 | struct breakpoint * | |
700 | get_breakpoint (int num) | |
701 | { | |
702 | struct breakpoint *b; | |
703 | ||
704 | ALL_BREAKPOINTS (b) | |
705 | if (b->number == num) | |
706 | return b; | |
707 | ||
708 | return NULL; | |
709 | } | |
5c44784c | 710 | |
c906108c | 711 | \f |
adc36818 PM |
712 | |
713 | void | |
714 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
715 | int from_tty) | |
716 | { | |
717 | struct bp_location *loc = b->loc; | |
718 | ||
719 | for (; loc; loc = loc->next) | |
720 | { | |
721 | xfree (loc->cond); | |
722 | loc->cond = NULL; | |
723 | } | |
724 | xfree (b->cond_string); | |
725 | b->cond_string = NULL; | |
726 | xfree (b->cond_exp); | |
727 | b->cond_exp = NULL; | |
728 | ||
729 | if (*exp == 0) | |
730 | { | |
731 | if (from_tty) | |
732 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
733 | } | |
734 | else | |
735 | { | |
736 | char *arg = exp; | |
737 | /* I don't know if it matters whether this is the string the user | |
738 | typed in or the decompiled expression. */ | |
739 | b->cond_string = xstrdup (arg); | |
740 | b->condition_not_parsed = 0; | |
741 | ||
742 | if (is_watchpoint (b)) | |
743 | { | |
744 | innermost_block = NULL; | |
745 | arg = exp; | |
746 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
747 | if (*arg) | |
748 | error (_("Junk at end of expression")); | |
749 | b->cond_exp_valid_block = innermost_block; | |
750 | } | |
751 | else | |
752 | { | |
753 | for (loc = b->loc; loc; loc = loc->next) | |
754 | { | |
755 | arg = exp; | |
756 | loc->cond = | |
757 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
758 | if (*arg) | |
759 | error (_("Junk at end of expression")); | |
760 | } | |
761 | } | |
762 | } | |
763 | breakpoints_changed (); | |
764 | observer_notify_breakpoint_modified (b->number); | |
765 | } | |
766 | ||
c906108c SS |
767 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
768 | ||
769 | static void | |
fba45db2 | 770 | condition_command (char *arg, int from_tty) |
c906108c | 771 | { |
52f0bd74 | 772 | struct breakpoint *b; |
c906108c | 773 | char *p; |
52f0bd74 | 774 | int bnum; |
c906108c SS |
775 | |
776 | if (arg == 0) | |
e2e0b3e5 | 777 | error_no_arg (_("breakpoint number")); |
c906108c SS |
778 | |
779 | p = arg; | |
780 | bnum = get_number (&p); | |
5c44784c | 781 | if (bnum == 0) |
8a3fe4f8 | 782 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
783 | |
784 | ALL_BREAKPOINTS (b) | |
785 | if (b->number == bnum) | |
2f069f6f | 786 | { |
adc36818 | 787 | set_breakpoint_condition (b, arg, from_tty); |
2f069f6f JB |
788 | return; |
789 | } | |
c906108c | 790 | |
8a3fe4f8 | 791 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
792 | } |
793 | ||
a7bdde9e VP |
794 | /* Check that COMMAND do not contain commands that are suitable |
795 | only for tracepoints and not suitable for ordinary breakpoints. | |
796 | Throw if any such commands is found. | |
797 | */ | |
798 | static void | |
799 | check_no_tracepoint_commands (struct command_line *commands) | |
800 | { | |
801 | struct command_line *c; | |
802 | for (c = commands; c; c = c->next) | |
803 | { | |
804 | int i; | |
805 | ||
806 | if (c->control_type == while_stepping_control) | |
807 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
808 | ||
809 | for (i = 0; i < c->body_count; ++i) | |
810 | check_no_tracepoint_commands ((c->body_list)[i]); | |
811 | ||
812 | /* Not that command parsing removes leading whitespace and comment | |
813 | lines and also empty lines. So, we only need to check for | |
814 | command directly. */ | |
815 | if (strstr (c->line, "collect ") == c->line) | |
816 | error (_("The 'collect' command can only be used for tracepoints")); | |
817 | ||
51661e93 VP |
818 | if (strstr (c->line, "teval ") == c->line) |
819 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
820 | } |
821 | } | |
822 | ||
d77f58be SS |
823 | /* Encapsulate tests for different types of tracepoints. */ |
824 | ||
a7bdde9e | 825 | int |
d77f58be | 826 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 827 | { |
d77f58be | 828 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); |
a7bdde9e | 829 | } |
d77f58be | 830 | |
95a42b64 TT |
831 | /* A helper function that validsates that COMMANDS are valid for a |
832 | breakpoint. This function will throw an exception if a problem is | |
833 | found. */ | |
48cb2d85 | 834 | |
95a42b64 TT |
835 | static void |
836 | validate_commands_for_breakpoint (struct breakpoint *b, | |
837 | struct command_line *commands) | |
48cb2d85 | 838 | { |
d77f58be | 839 | if (is_tracepoint (b)) |
a7bdde9e VP |
840 | { |
841 | /* We need to verify that each top-level element of commands | |
842 | is valid for tracepoints, that there's at most one while-stepping | |
843 | element, and that while-stepping's body has valid tracing commands | |
844 | excluding nested while-stepping. */ | |
845 | struct command_line *c; | |
846 | struct command_line *while_stepping = 0; | |
847 | for (c = commands; c; c = c->next) | |
848 | { | |
849 | char *l = c->line; | |
850 | if (c->control_type == while_stepping_control) | |
851 | { | |
852 | if (b->type == bp_fast_tracepoint) | |
853 | error (_("The 'while-stepping' command cannot be used for fast tracepoint")); | |
854 | ||
855 | if (while_stepping) | |
856 | error (_("The 'while-stepping' command can be used only once")); | |
857 | else | |
858 | while_stepping = c; | |
859 | } | |
860 | } | |
861 | if (while_stepping) | |
862 | { | |
863 | struct command_line *c2; | |
864 | ||
865 | gdb_assert (while_stepping->body_count == 1); | |
866 | c2 = while_stepping->body_list[0]; | |
867 | for (; c2; c2 = c2->next) | |
868 | { | |
869 | char *l = c2->line; | |
870 | if (c2->control_type == while_stepping_control) | |
871 | error (_("The 'while-stepping' command cannot be nested")); | |
872 | } | |
873 | } | |
874 | } | |
875 | else | |
876 | { | |
877 | check_no_tracepoint_commands (commands); | |
878 | } | |
95a42b64 TT |
879 | } |
880 | ||
881 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, | |
882 | validate that only allowed commands are included. | |
883 | */ | |
884 | ||
885 | void | |
886 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
887 | { | |
888 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 889 | |
9add0f1b TT |
890 | decref_counted_command_line (&b->commands); |
891 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
892 | breakpoints_changed (); |
893 | observer_notify_breakpoint_modified (b->number); | |
894 | } | |
895 | ||
95a42b64 TT |
896 | void |
897 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
898 | { |
899 | struct breakpoint *b = closure; | |
900 | validate_actionline (&line, b); | |
901 | } | |
902 | ||
95a42b64 TT |
903 | /* A structure used to pass information through |
904 | map_breakpoint_numbers. */ | |
905 | ||
906 | struct commands_info | |
907 | { | |
908 | /* True if the command was typed at a tty. */ | |
909 | int from_tty; | |
86b17b60 PA |
910 | |
911 | /* The breakpoint range spec. */ | |
912 | char *arg; | |
913 | ||
95a42b64 TT |
914 | /* Non-NULL if the body of the commands are being read from this |
915 | already-parsed command. */ | |
916 | struct command_line *control; | |
86b17b60 | 917 | |
95a42b64 TT |
918 | /* The command lines read from the user, or NULL if they have not |
919 | yet been read. */ | |
920 | struct counted_command_line *cmd; | |
921 | }; | |
922 | ||
923 | /* A callback for map_breakpoint_numbers that sets the commands for | |
924 | commands_command. */ | |
925 | ||
c906108c | 926 | static void |
95a42b64 | 927 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 928 | { |
95a42b64 | 929 | struct commands_info *info = data; |
c906108c | 930 | |
95a42b64 TT |
931 | if (info->cmd == NULL) |
932 | { | |
933 | struct command_line *l; | |
5c44784c | 934 | |
95a42b64 TT |
935 | if (info->control != NULL) |
936 | l = copy_command_lines (info->control->body_list[0]); | |
937 | else | |
86b17b60 PA |
938 | { |
939 | struct cleanup *old_chain; | |
940 | char *str; | |
c5aa993b | 941 | |
86b17b60 PA |
942 | str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."), |
943 | info->arg); | |
944 | ||
945 | old_chain = make_cleanup (xfree, str); | |
946 | ||
947 | l = read_command_lines (str, | |
948 | info->from_tty, 1, | |
d77f58be | 949 | (is_tracepoint (b) |
86b17b60 PA |
950 | ? check_tracepoint_command : 0), |
951 | b); | |
952 | ||
953 | do_cleanups (old_chain); | |
954 | } | |
a7bdde9e | 955 | |
95a42b64 TT |
956 | info->cmd = alloc_counted_command_line (l); |
957 | } | |
958 | ||
959 | /* If a breakpoint was on the list more than once, we don't need to | |
960 | do anything. */ | |
961 | if (b->commands != info->cmd) | |
962 | { | |
963 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
964 | incref_counted_command_line (info->cmd); | |
965 | decref_counted_command_line (&b->commands); | |
966 | b->commands = info->cmd; | |
967 | breakpoints_changed (); | |
968 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 969 | } |
95a42b64 TT |
970 | } |
971 | ||
972 | static void | |
973 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
974 | { | |
975 | struct cleanup *cleanups; | |
976 | struct commands_info info; | |
977 | ||
978 | info.from_tty = from_tty; | |
979 | info.control = control; | |
980 | info.cmd = NULL; | |
981 | /* If we read command lines from the user, then `info' will hold an | |
982 | extra reference to the commands that we must clean up. */ | |
983 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
984 | ||
985 | if (arg == NULL || !*arg) | |
986 | { | |
86b17b60 PA |
987 | if (breakpoint_count - prev_breakpoint_count > 1) |
988 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count); | |
95a42b64 TT |
989 | else if (breakpoint_count > 0) |
990 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
991 | else |
992 | { | |
993 | /* So that we don't try to free the incoming non-NULL | |
994 | argument in the cleanup below. Mapping breakpoint | |
995 | numbers will fail in this case. */ | |
996 | arg = NULL; | |
997 | } | |
95a42b64 | 998 | } |
9766ced4 SS |
999 | else |
1000 | /* The command loop has some static state, so we need to preserve | |
1001 | our argument. */ | |
1002 | arg = xstrdup (arg); | |
86b17b60 PA |
1003 | |
1004 | if (arg != NULL) | |
1005 | make_cleanup (xfree, arg); | |
1006 | ||
1007 | info.arg = arg; | |
95a42b64 TT |
1008 | |
1009 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1010 | ||
1011 | if (info.cmd == NULL) | |
1012 | error (_("No breakpoints specified.")); | |
1013 | ||
1014 | do_cleanups (cleanups); | |
1015 | } | |
1016 | ||
1017 | static void | |
1018 | commands_command (char *arg, int from_tty) | |
1019 | { | |
1020 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1021 | } |
40c03ae8 EZ |
1022 | |
1023 | /* Like commands_command, but instead of reading the commands from | |
1024 | input stream, takes them from an already parsed command structure. | |
1025 | ||
1026 | This is used by cli-script.c to DTRT with breakpoint commands | |
1027 | that are part of if and while bodies. */ | |
1028 | enum command_control_type | |
1029 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1030 | { | |
95a42b64 TT |
1031 | commands_command_1 (arg, 0, cmd); |
1032 | return simple_control; | |
40c03ae8 | 1033 | } |
876fa593 JK |
1034 | |
1035 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1036 | ||
1037 | static int | |
1038 | bp_location_has_shadow (struct bp_location *bl) | |
1039 | { | |
1040 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1041 | return 0; | |
1042 | if (!bl->inserted) | |
1043 | return 0; | |
1044 | if (bl->target_info.shadow_len == 0) | |
1045 | /* bp isn't valid, or doesn't shadow memory. */ | |
1046 | return 0; | |
1047 | return 1; | |
1048 | } | |
1049 | ||
8defab1a | 1050 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1051 | by replacing any memory breakpoints with their shadowed contents. |
1052 | ||
1053 | The range of shadowed area by each bp_location is: | |
1054 | b->address - bp_location_placed_address_before_address_max | |
1055 | up to b->address + bp_location_shadow_len_after_address_max | |
1056 | The range we were requested to resolve shadows for is: | |
1057 | memaddr ... memaddr + len | |
1058 | Thus the safe cutoff boundaries for performance optimization are | |
1059 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1060 | and: | |
1061 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1062 | |
8defab1a DJ |
1063 | void |
1064 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1065 | { |
876fa593 JK |
1066 | /* Left boundary, right boundary and median element of our binary search. */ |
1067 | unsigned bc_l, bc_r, bc; | |
1068 | ||
1069 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1070 | safe to report lower value but a failure to report higher one. */ | |
1071 | ||
1072 | bc_l = 0; | |
1073 | bc_r = bp_location_count; | |
1074 | while (bc_l + 1 < bc_r) | |
1075 | { | |
1076 | struct bp_location *b; | |
1077 | ||
1078 | bc = (bc_l + bc_r) / 2; | |
1079 | b = bp_location[bc]; | |
1080 | ||
1081 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1082 | Then advance the left boundary only if we are sure the BC element can | |
1083 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1084 | ||
1085 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1086 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1087 | MEMADDR. */ | |
c5aa993b | 1088 | |
876fa593 JK |
1089 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1090 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1091 | bc_l = bc; | |
1092 | else | |
1093 | bc_r = bc; | |
1094 | } | |
1095 | ||
1096 | /* Now do full processing of the found relevant range of elements. */ | |
1097 | ||
1098 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1099 | { |
876fa593 JK |
1100 | struct bp_location *b = bp_location[bc]; |
1101 | CORE_ADDR bp_addr = 0; | |
1102 | int bp_size = 0; | |
1103 | int bptoffset = 0; | |
1104 | ||
ffce0d52 | 1105 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1106 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1107 | b->owner->number); |
1108 | ||
876fa593 JK |
1109 | /* Performance optimization: any futher element can no longer affect BUF |
1110 | content. */ | |
1111 | ||
1112 | if (b->address >= bp_location_placed_address_before_address_max | |
1113 | && memaddr + len <= b->address | |
1114 | - bp_location_placed_address_before_address_max) | |
1115 | break; | |
1116 | ||
1117 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1118 | continue; |
6c95b8df PA |
1119 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1120 | current_program_space->aspace, 0)) | |
1121 | continue; | |
1122 | ||
c5aa993b JM |
1123 | /* Addresses and length of the part of the breakpoint that |
1124 | we need to copy. */ | |
8181d85f DJ |
1125 | bp_addr = b->target_info.placed_address; |
1126 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1127 | |
c5aa993b JM |
1128 | if (bp_addr + bp_size <= memaddr) |
1129 | /* The breakpoint is entirely before the chunk of memory we | |
1130 | are reading. */ | |
1131 | continue; | |
8defab1a | 1132 | |
c5aa993b JM |
1133 | if (bp_addr >= memaddr + len) |
1134 | /* The breakpoint is entirely after the chunk of memory we are | |
1135 | reading. */ | |
1136 | continue; | |
c5aa993b | 1137 | |
8defab1a DJ |
1138 | /* Offset within shadow_contents. */ |
1139 | if (bp_addr < memaddr) | |
1140 | { | |
1141 | /* Only copy the second part of the breakpoint. */ | |
1142 | bp_size -= memaddr - bp_addr; | |
1143 | bptoffset = memaddr - bp_addr; | |
1144 | bp_addr = memaddr; | |
1145 | } | |
c5aa993b | 1146 | |
8defab1a DJ |
1147 | if (bp_addr + bp_size > memaddr + len) |
1148 | { | |
1149 | /* Only copy the first part of the breakpoint. */ | |
1150 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1151 | } | |
c5aa993b | 1152 | |
8defab1a DJ |
1153 | memcpy (buf + bp_addr - memaddr, |
1154 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1155 | } |
c906108c | 1156 | } |
c906108c | 1157 | \f |
c5aa993b | 1158 | |
687595f9 | 1159 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1160 | static void |
687595f9 DJ |
1161 | insert_catchpoint (struct ui_out *uo, void *args) |
1162 | { | |
1163 | struct breakpoint *b = (struct breakpoint *) args; | |
1164 | int val = -1; | |
1165 | ||
fe798b75 JB |
1166 | gdb_assert (b->type == bp_catchpoint); |
1167 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1168 | ||
1169 | b->ops->insert (b); | |
687595f9 DJ |
1170 | } |
1171 | ||
60e1c644 PA |
1172 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1173 | ||
a5606eee | 1174 | static int |
d77f58be | 1175 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1176 | { |
1177 | return (bpt->type == bp_hardware_watchpoint | |
1178 | || bpt->type == bp_read_watchpoint | |
1179 | || bpt->type == bp_access_watchpoint); | |
1180 | } | |
7270d8f2 | 1181 | |
60e1c644 PA |
1182 | /* Return true if BPT is of any watchpoint kind, hardware or |
1183 | software. */ | |
1184 | ||
1185 | static int | |
d77f58be | 1186 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1187 | { |
1188 | return (is_hardware_watchpoint (bpt) | |
1189 | || bpt->type == bp_watchpoint); | |
1190 | } | |
1191 | ||
fa4727a6 DJ |
1192 | /* Find the current value of a watchpoint on EXP. Return the value in |
1193 | *VALP and *RESULTP and the chain of intermediate and final values | |
1194 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
1195 | not need them. | |
1196 | ||
ccc57cf9 | 1197 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
1198 | be set to NULL. *RESULTP may be a lazy value, if the result could |
1199 | not be read from memory. It is used to determine whether a value | |
1200 | is user-specified (we should watch the whole value) or intermediate | |
1201 | (we should watch only the bit used to locate the final value). | |
1202 | ||
1203 | If the final value, or any intermediate value, could not be read | |
1204 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
1205 | set to any referenced values. *VALP will never be a lazy value. | |
1206 | This is the value which we store in struct breakpoint. | |
1207 | ||
1208 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
1209 | value chain. The caller must free the values individually. If | |
1210 | VAL_CHAIN is NULL, all generated values will be left on the value | |
1211 | chain. */ | |
1212 | ||
1213 | static void | |
1214 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
1215 | struct value **resultp, struct value **val_chain) | |
1216 | { | |
1217 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 1218 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
1219 | |
1220 | *valp = NULL; | |
1221 | if (resultp) | |
1222 | *resultp = NULL; | |
1223 | if (val_chain) | |
1224 | *val_chain = NULL; | |
1225 | ||
1226 | /* Evaluate the expression. */ | |
1227 | mark = value_mark (); | |
1228 | result = NULL; | |
ccc57cf9 PA |
1229 | |
1230 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
1231 | { | |
1232 | result = evaluate_expression (exp); | |
1233 | } | |
1234 | if (ex.reason < 0) | |
1235 | { | |
1236 | /* Ignore memory errors, we want watchpoints pointing at | |
1237 | inaccessible memory to still be created; otherwise, throw the | |
1238 | error to some higher catcher. */ | |
1239 | switch (ex.error) | |
1240 | { | |
1241 | case MEMORY_ERROR: | |
1242 | break; | |
1243 | default: | |
1244 | throw_exception (ex); | |
1245 | break; | |
1246 | } | |
1247 | } | |
1248 | ||
fa4727a6 DJ |
1249 | new_mark = value_mark (); |
1250 | if (mark == new_mark) | |
1251 | return; | |
1252 | if (resultp) | |
1253 | *resultp = result; | |
1254 | ||
1255 | /* Make sure it's not lazy, so that after the target stops again we | |
1256 | have a non-lazy previous value to compare with. */ | |
1257 | if (result != NULL | |
1258 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
1259 | *valp = result; | |
1260 | ||
1261 | if (val_chain) | |
1262 | { | |
1263 | /* Return the chain of intermediate values. We use this to | |
1264 | decide which addresses to watch. */ | |
1265 | *val_chain = new_mark; | |
1266 | value_release_to_mark (mark); | |
1267 | } | |
1268 | } | |
1269 | ||
f6bc2008 PA |
1270 | /* Assuming that B is a watchpoint: returns true if the current thread |
1271 | and its running state are safe to evaluate or update watchpoint B. | |
1272 | Watchpoints on local expressions need to be evaluated in the | |
1273 | context of the thread that was current when the watchpoint was | |
1274 | created, and, that thread needs to be stopped to be able to select | |
1275 | the correct frame context. Watchpoints on global expressions can | |
1276 | be evaluated on any thread, and in any state. It is presently left | |
1277 | to the target allowing memory accesses when threads are | |
1278 | running. */ | |
1279 | ||
1280 | static int | |
1281 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1282 | { | |
1283 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1284 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1285 | && !is_executing (inferior_ptid))); | |
1286 | } | |
1287 | ||
567e1b4e JB |
1288 | /* Assuming that B is a watchpoint: |
1289 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1290 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1291 | - Evaluate the condition if there is one, and store the result |
1292 | in b->loc->cond. | |
a5606eee VP |
1293 | - Update the list of values that must be watched in B->loc. |
1294 | ||
bfa149ac | 1295 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1296 | If this is local watchpoint that is out of scope, delete it. |
1297 | ||
1298 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1299 | + inserted on each stop here. Normal breakpoints must never be removed | |
1300 | because they might be missed by a running thread when debugging in non-stop | |
1301 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1302 | processed here) are specific to each LWP since they are stored in each LWP's | |
1303 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1304 | order to be able to modify its hardware watchpoints. | |
1305 | ||
1306 | Hardware watchpoints must be reset exactly once after being presented to the | |
1307 | user. It cannot be done sooner, because it would reset the data used to | |
1308 | present the watchpoint hit to the user. And it must not be done later | |
1309 | because it could display the same single watchpoint hit during multiple GDB | |
1310 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1311 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1312 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1313 | memory content has not changed. | |
1314 | ||
1315 | The following constraints influence the location where we can reset hardware | |
1316 | watchpoints: | |
1317 | ||
1318 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1319 | several times when GDB stops. | |
1320 | ||
1321 | [linux] | |
1322 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1323 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1324 | reason for stopping, and all the other hits are presented later, one after | |
1325 | the other, each time the user requests the execution to be resumed. | |
1326 | Execution is not resumed for the threads still having pending hit event | |
1327 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1328 | the inferior on the first stop the thread hit event is kept being reported | |
1329 | from its cached value by linux_nat_stopped_data_address until the real | |
1330 | thread resume happens after the watchpoint gets presented and thus its | |
1331 | LWP_INFO->STATUS gets reset. | |
1332 | ||
1333 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1334 | removal from inferior. */ | |
1335 | ||
b40ce68a | 1336 | static void |
a5606eee | 1337 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1338 | { |
a5606eee | 1339 | int within_current_scope; |
a5606eee VP |
1340 | struct frame_id saved_frame_id; |
1341 | struct bp_location *loc; | |
66076460 | 1342 | int frame_saved; |
a5606eee VP |
1343 | bpstat bs; |
1344 | ||
f6bc2008 PA |
1345 | /* If this is a local watchpoint, we only want to check if the |
1346 | watchpoint frame is in scope if the current thread is the thread | |
1347 | that was used to create the watchpoint. */ | |
1348 | if (!watchpoint_in_thread_scope (b)) | |
1349 | return; | |
1350 | ||
876fa593 | 1351 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1352 | update_global_locations will eventually delete them and remove |
1353 | breakpoints if needed. */ | |
a5606eee VP |
1354 | b->loc = NULL; |
1355 | ||
1356 | if (b->disposition == disp_del_at_next_stop) | |
1357 | return; | |
1358 | ||
66076460 | 1359 | frame_saved = 0; |
a5606eee VP |
1360 | |
1361 | /* Determine if the watchpoint is within scope. */ | |
1362 | if (b->exp_valid_block == NULL) | |
1363 | within_current_scope = 1; | |
1364 | else | |
1365 | { | |
1366 | struct frame_info *fi; | |
66076460 DJ |
1367 | |
1368 | /* Save the current frame's ID so we can restore it after | |
1369 | evaluating the watchpoint expression on its own frame. */ | |
1370 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1371 | took a frame parameter, so that we didn't have to change the | |
1372 | selected frame. */ | |
1373 | frame_saved = 1; | |
1374 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1375 | ||
a5606eee VP |
1376 | fi = frame_find_by_id (b->watchpoint_frame); |
1377 | within_current_scope = (fi != NULL); | |
1378 | if (within_current_scope) | |
1379 | select_frame (fi); | |
1380 | } | |
1381 | ||
1382 | if (within_current_scope && reparse) | |
1383 | { | |
1384 | char *s; | |
1385 | if (b->exp) | |
1386 | { | |
1387 | xfree (b->exp); | |
1388 | b->exp = NULL; | |
1389 | } | |
1390 | s = b->exp_string; | |
1391 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1392 | /* If the meaning of expression itself changed, the old value is | |
1393 | no longer relevant. We don't want to report a watchpoint hit | |
1394 | to the user when the old value and the new value may actually | |
1395 | be completely different objects. */ | |
1396 | value_free (b->val); | |
fa4727a6 DJ |
1397 | b->val = NULL; |
1398 | b->val_valid = 0; | |
60e1c644 PA |
1399 | |
1400 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1401 | expression is stored in the breakpoint object, not in the | |
1402 | locations (re)created below. */ | |
1403 | if (b->cond_string != NULL) | |
1404 | { | |
1405 | if (b->cond_exp != NULL) | |
1406 | { | |
1407 | xfree (b->cond_exp); | |
1408 | b->cond_exp = NULL; | |
1409 | } | |
1410 | ||
1411 | s = b->cond_string; | |
1412 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1413 | } | |
a5606eee | 1414 | } |
a5606eee VP |
1415 | |
1416 | /* If we failed to parse the expression, for example because | |
1417 | it refers to a global variable in a not-yet-loaded shared library, | |
1418 | don't try to insert watchpoint. We don't automatically delete | |
1419 | such watchpoint, though, since failure to parse expression | |
1420 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1421 | if ( !target_has_execution) |
1422 | { | |
1423 | /* Without execution, memory can't change. No use to try and | |
1424 | set watchpoint locations. The watchpoint will be reset when | |
1425 | the target gains execution, through breakpoint_re_set. */ | |
1426 | } | |
1427 | else if (within_current_scope && b->exp) | |
a5606eee | 1428 | { |
fa4727a6 | 1429 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1430 | struct program_space *frame_pspace; |
a5606eee | 1431 | |
fa4727a6 | 1432 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1433 | |
a5606eee VP |
1434 | /* Avoid setting b->val if it's already set. The meaning of |
1435 | b->val is 'the last value' user saw, and we should update | |
1436 | it only if we reported that last value to user. As it | |
1437 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1438 | if (!b->val_valid) |
1439 | { | |
1440 | b->val = v; | |
1441 | b->val_valid = 1; | |
1442 | } | |
a5606eee | 1443 | |
db2ad4c3 JK |
1444 | /* Change the type of breakpoint between hardware assisted or an |
1445 | ordinary watchpoint depending on the hardware support and free | |
1446 | hardware slots. REPARSE is set when the inferior is started. */ | |
1447 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1448 | && reparse) | |
1449 | { | |
ca2d49e8 | 1450 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1451 | |
7b838ca2 TJB |
1452 | /* We need to determine how many resources are already used |
1453 | for all other hardware watchpoints to see if we still have | |
1454 | enough resources to also fit this watchpoint in as well. | |
1455 | To avoid the hw_watchpoint_used_count call below from counting | |
1456 | this watchpoint, make sure that it is marked as a software | |
1457 | watchpoint. */ | |
1458 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1459 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1460 | &other_type_used); | |
1461 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1462 | ||
ca2d49e8 | 1463 | if (!mem_cnt) |
db2ad4c3 JK |
1464 | b->type = bp_watchpoint; |
1465 | else | |
ca2d49e8 | 1466 | { |
d92524f1 | 1467 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1468 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1469 | if (target_resources_ok <= 0) | |
1470 | b->type = bp_watchpoint; | |
1471 | else | |
1472 | b->type = bp_hardware_watchpoint; | |
1473 | } | |
db2ad4c3 JK |
1474 | } |
1475 | ||
2d134ed3 PA |
1476 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1477 | ||
a5606eee | 1478 | /* Look at each value on the value chain. */ |
fa4727a6 | 1479 | for (v = val_chain; v; v = next) |
a5606eee VP |
1480 | { |
1481 | /* If it's a memory location, and GDB actually needed | |
1482 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1483 | must watch it. If the first value returned is |
1484 | still lazy, that means an error occurred reading it; | |
1485 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1486 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1487 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1488 | { |
1489 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1490 | |
a5606eee VP |
1491 | /* We only watch structs and arrays if user asked |
1492 | for it explicitly, never if they just happen to | |
1493 | appear in the middle of some value chain. */ | |
fa4727a6 | 1494 | if (v == result |
a5606eee VP |
1495 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1496 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1497 | { | |
1498 | CORE_ADDR addr; | |
1499 | int len, type; | |
1500 | struct bp_location *loc, **tmp; | |
1501 | ||
42ae5230 | 1502 | addr = value_address (v); |
a5606eee VP |
1503 | len = TYPE_LENGTH (value_type (v)); |
1504 | type = hw_write; | |
1505 | if (b->type == bp_read_watchpoint) | |
1506 | type = hw_read; | |
1507 | else if (b->type == bp_access_watchpoint) | |
1508 | type = hw_access; | |
1509 | ||
39d61571 | 1510 | loc = allocate_bp_location (b); |
a5606eee VP |
1511 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1512 | ; | |
1513 | *tmp = loc; | |
a6d9a66e | 1514 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1515 | |
1516 | loc->pspace = frame_pspace; | |
a5606eee VP |
1517 | loc->address = addr; |
1518 | loc->length = len; | |
1519 | loc->watchpoint_type = type; | |
1520 | } | |
1521 | } | |
1522 | ||
1523 | next = value_next (v); | |
1524 | if (v != b->val) | |
1525 | value_free (v); | |
1526 | } | |
1527 | ||
c7437ca6 PA |
1528 | /* If a software watchpoint is not watching any memory, then the |
1529 | above left it without any location set up. But, | |
1530 | bpstat_stop_status requires a location to be able to report | |
1531 | stops, so make sure there's at least a dummy one. */ | |
1532 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1533 | { | |
1534 | b->loc = allocate_bp_location (b); | |
1535 | b->loc->pspace = frame_pspace; | |
1536 | b->loc->address = -1; | |
1537 | b->loc->length = -1; | |
1538 | b->loc->watchpoint_type = -1; | |
1539 | } | |
a5606eee VP |
1540 | } |
1541 | else if (!within_current_scope) | |
7270d8f2 | 1542 | { |
a5606eee | 1543 | printf_filtered (_("\ |
567e1b4e | 1544 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1545 | in which its expression is valid.\n"), |
1546 | b->number); | |
1547 | if (b->related_breakpoint) | |
60e1c644 PA |
1548 | { |
1549 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1550 | b->related_breakpoint->related_breakpoint = NULL; | |
1551 | b->related_breakpoint= NULL; | |
1552 | } | |
a5606eee | 1553 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1554 | } |
a5606eee VP |
1555 | |
1556 | /* Restore the selected frame. */ | |
66076460 DJ |
1557 | if (frame_saved) |
1558 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1559 | } |
1560 | ||
a5606eee | 1561 | |
74960c60 VP |
1562 | /* Returns 1 iff breakpoint location should be |
1563 | inserted in the inferior. */ | |
1564 | static int | |
1565 | should_be_inserted (struct bp_location *bpt) | |
1566 | { | |
1567 | if (!breakpoint_enabled (bpt->owner)) | |
1568 | return 0; | |
1569 | ||
1570 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1571 | return 0; | |
1572 | ||
1573 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1574 | return 0; | |
1575 | ||
56710373 PA |
1576 | /* This is set for example, when we're attached to the parent of a |
1577 | vfork, and have detached from the child. The child is running | |
1578 | free, and we expect it to do an exec or exit, at which point the | |
1579 | OS makes the parent schedulable again (and the target reports | |
1580 | that the vfork is done). Until the child is done with the shared | |
1581 | memory region, do not insert breakpoints in the parent, otherwise | |
1582 | the child could still trip on the parent's breakpoints. Since | |
1583 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1584 | if (bpt->pspace->breakpoints_not_allowed) | |
1585 | return 0; | |
1586 | ||
1042e4c0 SS |
1587 | /* Tracepoints are inserted by the target at a time of its choosing, |
1588 | not by us. */ | |
d77f58be | 1589 | if (is_tracepoint (bpt->owner)) |
1042e4c0 SS |
1590 | return 0; |
1591 | ||
74960c60 VP |
1592 | return 1; |
1593 | } | |
1594 | ||
879bfdc2 DJ |
1595 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1596 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1597 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1598 | |
1599 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1600 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1601 | static int |
879bfdc2 | 1602 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1603 | struct ui_file *tmp_error_stream, |
fa3a767f | 1604 | int *disabled_breaks, |
26bb91f3 | 1605 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1606 | { |
1607 | int val = 0; | |
1608 | ||
74960c60 | 1609 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1610 | return 0; |
1611 | ||
8181d85f DJ |
1612 | /* Initialize the target-specific information. */ |
1613 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1614 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1615 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1616 | |
879bfdc2 DJ |
1617 | if (bpt->loc_type == bp_loc_software_breakpoint |
1618 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1619 | { | |
765dc015 VP |
1620 | if (bpt->owner->type != bp_hardware_breakpoint) |
1621 | { | |
1622 | /* If the explicitly specified breakpoint type | |
1623 | is not hardware breakpoint, check the memory map to see | |
1624 | if the breakpoint address is in read only memory or not. | |
1625 | Two important cases are: | |
1626 | - location type is not hardware breakpoint, memory | |
1627 | is readonly. We change the type of the location to | |
1628 | hardware breakpoint. | |
1629 | - location type is hardware breakpoint, memory is read-write. | |
1630 | This means we've previously made the location hardware one, but | |
1631 | then the memory map changed, so we undo. | |
1632 | ||
1633 | When breakpoints are removed, remove_breakpoints will | |
1634 | use location types we've just set here, the only possible | |
1635 | problem is that memory map has changed during running program, | |
1636 | but it's not going to work anyway with current gdb. */ | |
1637 | struct mem_region *mr | |
1638 | = lookup_mem_region (bpt->target_info.placed_address); | |
1639 | ||
1640 | if (mr) | |
1641 | { | |
1642 | if (automatic_hardware_breakpoints) | |
1643 | { | |
1644 | int changed = 0; | |
1645 | enum bp_loc_type new_type; | |
1646 | ||
1647 | if (mr->attrib.mode != MEM_RW) | |
1648 | new_type = bp_loc_hardware_breakpoint; | |
1649 | else | |
1650 | new_type = bp_loc_software_breakpoint; | |
1651 | ||
1652 | if (new_type != bpt->loc_type) | |
1653 | { | |
1654 | static int said = 0; | |
1655 | bpt->loc_type = new_type; | |
1656 | if (!said) | |
1657 | { | |
1658 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1659 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1660 | said = 1; |
1661 | } | |
1662 | } | |
1663 | } | |
1664 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1665 | && mr->attrib.mode != MEM_RW) | |
1666 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1667 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1668 | } |
1669 | } | |
1670 | ||
879bfdc2 DJ |
1671 | /* First check to see if we have to handle an overlay. */ |
1672 | if (overlay_debugging == ovly_off | |
1673 | || bpt->section == NULL | |
1674 | || !(section_is_overlay (bpt->section))) | |
1675 | { | |
1676 | /* No overlay handling: just set the breakpoint. */ | |
1677 | ||
1678 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1679 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1680 | &bpt->target_info); | |
879bfdc2 | 1681 | else |
a6d9a66e UW |
1682 | val = target_insert_breakpoint (bpt->gdbarch, |
1683 | &bpt->target_info); | |
879bfdc2 DJ |
1684 | } |
1685 | else | |
1686 | { | |
1687 | /* This breakpoint is in an overlay section. | |
1688 | Shall we set a breakpoint at the LMA? */ | |
1689 | if (!overlay_events_enabled) | |
1690 | { | |
1691 | /* Yes -- overlay event support is not active, | |
1692 | so we must try to set a breakpoint at the LMA. | |
1693 | This will not work for a hardware breakpoint. */ | |
1694 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1695 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1696 | bpt->owner->number); |
1697 | else | |
1698 | { | |
1699 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1700 | bpt->section); | |
1701 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1702 | bpt->overlay_target_info = bpt->target_info; |
1703 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1704 | val = target_insert_breakpoint (bpt->gdbarch, |
1705 | &bpt->overlay_target_info); | |
879bfdc2 | 1706 | if (val != 0) |
99361f52 DE |
1707 | fprintf_unfiltered (tmp_error_stream, |
1708 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1709 | bpt->owner->number); |
1710 | } | |
1711 | } | |
1712 | /* Shall we set a breakpoint at the VMA? */ | |
1713 | if (section_is_mapped (bpt->section)) | |
1714 | { | |
1715 | /* Yes. This overlay section is mapped into memory. */ | |
1716 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1717 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1718 | &bpt->target_info); | |
879bfdc2 | 1719 | else |
a6d9a66e UW |
1720 | val = target_insert_breakpoint (bpt->gdbarch, |
1721 | &bpt->target_info); | |
879bfdc2 DJ |
1722 | } |
1723 | else | |
1724 | { | |
1725 | /* No. This breakpoint will not be inserted. | |
1726 | No error, but do not mark the bp as 'inserted'. */ | |
1727 | return 0; | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | if (val) | |
1732 | { | |
1733 | /* Can't set the breakpoint. */ | |
6c95b8df | 1734 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1735 | { |
1736 | /* See also: disable_breakpoints_in_shlibs. */ | |
1737 | val = 0; | |
0d381245 | 1738 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1739 | if (!*disabled_breaks) |
1740 | { | |
1741 | fprintf_unfiltered (tmp_error_stream, | |
1742 | "Cannot insert breakpoint %d.\n", | |
1743 | bpt->owner->number); | |
1744 | fprintf_unfiltered (tmp_error_stream, | |
1745 | "Temporarily disabling shared library breakpoints:\n"); | |
1746 | } | |
1747 | *disabled_breaks = 1; | |
1748 | fprintf_unfiltered (tmp_error_stream, | |
1749 | "breakpoint #%d\n", bpt->owner->number); | |
1750 | } | |
1751 | else | |
879bfdc2 | 1752 | { |
879bfdc2 DJ |
1753 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1754 | { | |
1755 | *hw_breakpoint_error = 1; | |
1756 | fprintf_unfiltered (tmp_error_stream, | |
1757 | "Cannot insert hardware breakpoint %d.\n", | |
1758 | bpt->owner->number); | |
1759 | } | |
1760 | else | |
1761 | { | |
1762 | fprintf_unfiltered (tmp_error_stream, | |
1763 | "Cannot insert breakpoint %d.\n", | |
1764 | bpt->owner->number); | |
1765 | fprintf_filtered (tmp_error_stream, | |
1766 | "Error accessing memory address "); | |
5af949e3 UW |
1767 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1768 | tmp_error_stream); | |
879bfdc2 DJ |
1769 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1770 | safe_strerror (val)); | |
1771 | } | |
1772 | ||
1773 | } | |
1774 | } | |
1775 | else | |
1776 | bpt->inserted = 1; | |
1777 | ||
1778 | return val; | |
1779 | } | |
1780 | ||
1781 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1782 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1783 | watchpoints. It's not clear that it's necessary... */ | |
1784 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1785 | { | |
85d721b8 | 1786 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1787 | bpt->length, |
1788 | bpt->watchpoint_type); | |
85d721b8 PA |
1789 | |
1790 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1791 | supported, try emulating one with an access watchpoint. */ | |
1792 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1793 | { | |
1794 | struct bp_location *loc, **loc_temp; | |
1795 | ||
1796 | /* But don't try to insert it, if there's already another | |
1797 | hw_access location that would be considered a duplicate | |
1798 | of this one. */ | |
1799 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1800 | if (loc != bpt | |
1801 | && loc->watchpoint_type == hw_access | |
1802 | && watchpoint_locations_match (bpt, loc)) | |
1803 | { | |
1804 | bpt->duplicate = 1; | |
1805 | bpt->inserted = 1; | |
1806 | bpt->target_info = loc->target_info; | |
1807 | bpt->watchpoint_type = hw_access; | |
1808 | val = 0; | |
1809 | break; | |
1810 | } | |
1811 | ||
1812 | if (val == 1) | |
1813 | { | |
1814 | val = target_insert_watchpoint (bpt->address, | |
1815 | bpt->length, | |
1816 | hw_access); | |
1817 | if (val == 0) | |
1818 | bpt->watchpoint_type = hw_access; | |
1819 | } | |
1820 | } | |
1821 | ||
1822 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1823 | } |
1824 | ||
fe798b75 | 1825 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1826 | { |
71fff37b AC |
1827 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1828 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1829 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1830 | bpt->owner->number); | |
1831 | if (e.reason < 0) | |
879bfdc2 DJ |
1832 | bpt->owner->enable_state = bp_disabled; |
1833 | else | |
1834 | bpt->inserted = 1; | |
1640b821 DJ |
1835 | |
1836 | /* We've already printed an error message if there was a problem | |
1837 | inserting this catchpoint, and we've disabled the catchpoint, | |
1838 | so just return success. */ | |
1839 | return 0; | |
879bfdc2 DJ |
1840 | } |
1841 | ||
1842 | return 0; | |
1843 | } | |
1844 | ||
6c95b8df PA |
1845 | /* This function is called when program space PSPACE is about to be |
1846 | deleted. It takes care of updating breakpoints to not reference | |
1847 | PSPACE anymore. */ | |
1848 | ||
1849 | void | |
1850 | breakpoint_program_space_exit (struct program_space *pspace) | |
1851 | { | |
1852 | struct breakpoint *b, *b_temp; | |
876fa593 | 1853 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1854 | |
1855 | /* Remove any breakpoint that was set through this program space. */ | |
1856 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1857 | { | |
1858 | if (b->pspace == pspace) | |
1859 | delete_breakpoint (b); | |
1860 | } | |
1861 | ||
1862 | /* Breakpoints set through other program spaces could have locations | |
1863 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1864 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1865 | { |
1866 | struct bp_location *tmp; | |
1867 | ||
1868 | if (loc->pspace == pspace) | |
1869 | { | |
1870 | if (loc->owner->loc == loc) | |
1871 | loc->owner->loc = loc->next; | |
1872 | else | |
1873 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1874 | if (tmp->next == loc) | |
1875 | { | |
1876 | tmp->next = loc->next; | |
1877 | break; | |
1878 | } | |
1879 | } | |
1880 | } | |
1881 | ||
1882 | /* Now update the global location list to permanently delete the | |
1883 | removed locations above. */ | |
1884 | update_global_location_list (0); | |
1885 | } | |
1886 | ||
74960c60 VP |
1887 | /* Make sure all breakpoints are inserted in inferior. |
1888 | Throws exception on any error. | |
1889 | A breakpoint that is already inserted won't be inserted | |
1890 | again, so calling this function twice is safe. */ | |
1891 | void | |
1892 | insert_breakpoints (void) | |
1893 | { | |
1894 | struct breakpoint *bpt; | |
1895 | ||
1896 | ALL_BREAKPOINTS (bpt) | |
1897 | if (is_hardware_watchpoint (bpt)) | |
1898 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1899 | ||
b60e7edf | 1900 | update_global_location_list (1); |
74960c60 | 1901 | |
c35b1492 PA |
1902 | /* update_global_location_list does not insert breakpoints when |
1903 | always_inserted_mode is not enabled. Explicitly insert them | |
1904 | now. */ | |
1905 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1906 | insert_breakpoint_locations (); |
1907 | } | |
1908 | ||
c906108c SS |
1909 | /* insert_breakpoints is used when starting or continuing the program. |
1910 | remove_breakpoints is used when the program stops. | |
1911 | Both return zero if successful, | |
1912 | or an `errno' value if could not write the inferior. */ | |
1913 | ||
74960c60 VP |
1914 | static void |
1915 | insert_breakpoint_locations (void) | |
c906108c | 1916 | { |
a5606eee | 1917 | struct breakpoint *bpt; |
876fa593 | 1918 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1919 | int error = 0; |
c906108c SS |
1920 | int val = 0; |
1921 | int disabled_breaks = 0; | |
81d0cc19 | 1922 | int hw_breakpoint_error = 0; |
c906108c | 1923 | |
81d0cc19 | 1924 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1925 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1926 | |
81d0cc19 GS |
1927 | /* Explicitly mark the warning -- this will only be printed if |
1928 | there was an error. */ | |
1929 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1930 | |
1931 | save_current_space_and_thread (); | |
1932 | ||
876fa593 | 1933 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1934 | { |
6c95b8df PA |
1935 | struct thread_info *tp; |
1936 | CORE_ADDR last_addr; | |
1937 | ||
74960c60 | 1938 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1939 | continue; |
1940 | ||
f365de73 AS |
1941 | /* There is no point inserting thread-specific breakpoints if the |
1942 | thread no longer exists. */ | |
1943 | if (b->owner->thread != -1 | |
1944 | && !valid_thread_id (b->owner->thread)) | |
1945 | continue; | |
1946 | ||
6c95b8df PA |
1947 | switch_to_program_space_and_thread (b->pspace); |
1948 | ||
1949 | /* For targets that support global breakpoints, there's no need | |
1950 | to select an inferior to insert breakpoint to. In fact, even | |
1951 | if we aren't attached to any process yet, we should still | |
1952 | insert breakpoints. */ | |
1953 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1954 | && ptid_equal (inferior_ptid, null_ptid)) | |
1955 | continue; | |
1956 | ||
879bfdc2 | 1957 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1958 | &disabled_breaks, |
879bfdc2 DJ |
1959 | &hw_breakpoint_error); |
1960 | if (val) | |
e236ba44 | 1961 | error = val; |
879bfdc2 | 1962 | } |
c906108c | 1963 | |
a5606eee VP |
1964 | /* If we failed to insert all locations of a watchpoint, |
1965 | remove them, as half-inserted watchpoint is of limited use. */ | |
1966 | ALL_BREAKPOINTS (bpt) | |
1967 | { | |
1968 | int some_failed = 0; | |
1969 | struct bp_location *loc; | |
1970 | ||
1971 | if (!is_hardware_watchpoint (bpt)) | |
1972 | continue; | |
1973 | ||
d6b74ac4 | 1974 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1975 | continue; |
74960c60 VP |
1976 | |
1977 | if (bpt->disposition == disp_del_at_next_stop) | |
1978 | continue; | |
a5606eee VP |
1979 | |
1980 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1981 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1982 | { |
1983 | some_failed = 1; | |
1984 | break; | |
1985 | } | |
1986 | if (some_failed) | |
1987 | { | |
1988 | for (loc = bpt->loc; loc; loc = loc->next) | |
1989 | if (loc->inserted) | |
1990 | remove_breakpoint (loc, mark_uninserted); | |
1991 | ||
1992 | hw_breakpoint_error = 1; | |
1993 | fprintf_unfiltered (tmp_error_stream, | |
1994 | "Could not insert hardware watchpoint %d.\n", | |
1995 | bpt->number); | |
1996 | error = -1; | |
1997 | } | |
1998 | } | |
1999 | ||
e236ba44 | 2000 | if (error) |
81d0cc19 GS |
2001 | { |
2002 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2003 | message about possibly exhausted resources. */ | |
879bfdc2 | 2004 | if (hw_breakpoint_error) |
81d0cc19 | 2005 | { |
c6510018 MS |
2006 | fprintf_unfiltered (tmp_error_stream, |
2007 | "Could not insert hardware breakpoints:\n\ | |
2008 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2009 | } |
81d0cc19 GS |
2010 | target_terminal_ours_for_output (); |
2011 | error_stream (tmp_error_stream); | |
2012 | } | |
f7545552 TT |
2013 | |
2014 | do_cleanups (cleanups); | |
c906108c SS |
2015 | } |
2016 | ||
c906108c | 2017 | int |
fba45db2 | 2018 | remove_breakpoints (void) |
c906108c | 2019 | { |
876fa593 | 2020 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2021 | int val = 0; |
c906108c | 2022 | |
876fa593 | 2023 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2024 | { |
0bde7532 | 2025 | if (b->inserted) |
3a1bae8e | 2026 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 2027 | } |
3a1bae8e | 2028 | return val; |
c906108c SS |
2029 | } |
2030 | ||
6c95b8df PA |
2031 | /* Remove breakpoints of process PID. */ |
2032 | ||
2033 | int | |
2034 | remove_breakpoints_pid (int pid) | |
2035 | { | |
876fa593 | 2036 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
2037 | int val; |
2038 | struct inferior *inf = find_inferior_pid (pid); | |
2039 | ||
876fa593 | 2040 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
2041 | { |
2042 | if (b->pspace != inf->pspace) | |
2043 | continue; | |
2044 | ||
2045 | if (b->inserted) | |
2046 | { | |
2047 | val = remove_breakpoint (b, mark_uninserted); | |
2048 | if (val != 0) | |
2049 | return val; | |
2050 | } | |
2051 | } | |
2052 | return 0; | |
2053 | } | |
2054 | ||
692590c1 | 2055 | int |
80ce1ecb | 2056 | remove_hw_watchpoints (void) |
692590c1 | 2057 | { |
876fa593 | 2058 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2059 | int val = 0; |
692590c1 | 2060 | |
876fa593 | 2061 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2062 | { |
0bde7532 | 2063 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2064 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2065 | } |
3a1bae8e | 2066 | return val; |
692590c1 MS |
2067 | } |
2068 | ||
c906108c | 2069 | int |
fba45db2 | 2070 | reattach_breakpoints (int pid) |
c906108c | 2071 | { |
6c95b8df | 2072 | struct cleanup *old_chain; |
876fa593 | 2073 | struct bp_location *b, **bp_tmp; |
c906108c | 2074 | int val; |
a4954f26 | 2075 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2076 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2077 | struct inferior *inf; |
2078 | struct thread_info *tp; | |
2079 | ||
2080 | tp = any_live_thread_of_process (pid); | |
2081 | if (tp == NULL) | |
2082 | return 1; | |
2083 | ||
2084 | inf = find_inferior_pid (pid); | |
2085 | old_chain = save_inferior_ptid (); | |
2086 | ||
2087 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2088 | |
2089 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2090 | |
876fa593 | 2091 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2092 | { |
6c95b8df PA |
2093 | if (b->pspace != inf->pspace) |
2094 | continue; | |
2095 | ||
0bde7532 | 2096 | if (b->inserted) |
c5aa993b | 2097 | { |
a4954f26 DJ |
2098 | b->inserted = 0; |
2099 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2100 | &dummy1, &dummy2); |
c5aa993b JM |
2101 | if (val != 0) |
2102 | { | |
ce696e05 | 2103 | do_cleanups (old_chain); |
c5aa993b JM |
2104 | return val; |
2105 | } | |
2106 | } | |
2107 | } | |
ce696e05 | 2108 | do_cleanups (old_chain); |
c906108c SS |
2109 | return 0; |
2110 | } | |
2111 | ||
e58b0e63 PA |
2112 | static int internal_breakpoint_number = -1; |
2113 | ||
e62c965a | 2114 | static struct breakpoint * |
a6d9a66e UW |
2115 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2116 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2117 | { |
e62c965a PP |
2118 | struct symtab_and_line sal; |
2119 | struct breakpoint *b; | |
2120 | ||
2121 | init_sal (&sal); /* initialize to zeroes */ | |
2122 | ||
2123 | sal.pc = address; | |
2124 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2125 | sal.pspace = current_program_space; |
e62c965a | 2126 | |
a6d9a66e | 2127 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2128 | b->number = internal_breakpoint_number--; |
2129 | b->disposition = disp_donttouch; | |
2130 | ||
2131 | return b; | |
2132 | } | |
2133 | ||
2134 | static void | |
69de3c6a | 2135 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2136 | { |
69de3c6a | 2137 | struct objfile *objfile; |
e62c965a | 2138 | |
69de3c6a PP |
2139 | ALL_OBJFILES (objfile) |
2140 | { | |
2141 | struct breakpoint *b; | |
2142 | struct minimal_symbol *m; | |
2143 | ||
2144 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2145 | if (m == NULL) | |
2146 | continue; | |
e62c965a | 2147 | |
a6d9a66e UW |
2148 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2149 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2150 | bp_overlay_event); |
2151 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2152 | |
69de3c6a PP |
2153 | if (overlay_debugging == ovly_auto) |
2154 | { | |
2155 | b->enable_state = bp_enabled; | |
2156 | overlay_events_enabled = 1; | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | b->enable_state = bp_disabled; | |
2161 | overlay_events_enabled = 0; | |
2162 | } | |
e62c965a PP |
2163 | } |
2164 | update_global_location_list (1); | |
2165 | } | |
2166 | ||
0fd8e87f UW |
2167 | static void |
2168 | create_longjmp_master_breakpoint (char *func_name) | |
2169 | { | |
6c95b8df | 2170 | struct program_space *pspace; |
0fd8e87f | 2171 | struct objfile *objfile; |
6c95b8df PA |
2172 | struct cleanup *old_chain; |
2173 | ||
2174 | old_chain = save_current_program_space (); | |
0fd8e87f | 2175 | |
6c95b8df | 2176 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2177 | ALL_OBJFILES (objfile) |
2178 | { | |
2179 | struct breakpoint *b; | |
2180 | struct minimal_symbol *m; | |
2181 | ||
2182 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2183 | continue; | |
2184 | ||
6c95b8df PA |
2185 | set_current_program_space (pspace); |
2186 | ||
0fd8e87f UW |
2187 | m = lookup_minimal_symbol_text (func_name, objfile); |
2188 | if (m == NULL) | |
2189 | continue; | |
2190 | ||
a6d9a66e UW |
2191 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2192 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2193 | bp_longjmp_master); |
2194 | b->addr_string = xstrdup (func_name); | |
2195 | b->enable_state = bp_disabled; | |
2196 | } | |
2197 | update_global_location_list (1); | |
6c95b8df PA |
2198 | |
2199 | do_cleanups (old_chain); | |
0fd8e87f UW |
2200 | } |
2201 | ||
aa7d318d TT |
2202 | /* Create a master std::terminate breakpoint. The actual function |
2203 | looked for is named FUNC_NAME. */ | |
2204 | static void | |
2205 | create_std_terminate_master_breakpoint (const char *func_name) | |
2206 | { | |
2207 | struct program_space *pspace; | |
2208 | struct objfile *objfile; | |
2209 | struct cleanup *old_chain; | |
2210 | ||
2211 | old_chain = save_current_program_space (); | |
2212 | ||
2213 | ALL_PSPACES (pspace) | |
2214 | ALL_OBJFILES (objfile) | |
2215 | { | |
2216 | struct breakpoint *b; | |
2217 | struct minimal_symbol *m; | |
2218 | ||
2219 | set_current_program_space (pspace); | |
2220 | ||
2221 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2222 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2223 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2224 | continue; | |
2225 | ||
2226 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2227 | SYMBOL_VALUE_ADDRESS (m), | |
2228 | bp_std_terminate_master); | |
2229 | b->addr_string = xstrdup (func_name); | |
2230 | b->enable_state = bp_disabled; | |
2231 | } | |
2232 | update_global_location_list (1); | |
2233 | ||
2234 | do_cleanups (old_chain); | |
2235 | } | |
2236 | ||
c906108c | 2237 | void |
fba45db2 | 2238 | update_breakpoints_after_exec (void) |
c906108c | 2239 | { |
c5aa993b JM |
2240 | struct breakpoint *b; |
2241 | struct breakpoint *temp; | |
876fa593 | 2242 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2243 | |
25b22b0a PA |
2244 | /* We're about to delete breakpoints from GDB's lists. If the |
2245 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2246 | writing the breakpoints' "shadow contents" back into memory. The | |
2247 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2248 | do that. Instead, the target is responsible from marking | |
2249 | breakpoints out as soon as it detects an exec. We don't do that | |
2250 | here instead, because there may be other attempts to delete | |
2251 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2252 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2253 | if (bploc->pspace == current_program_space) |
2254 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2255 | |
2256 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2257 | { |
6c95b8df PA |
2258 | if (b->pspace != current_program_space) |
2259 | continue; | |
2260 | ||
c5aa993b JM |
2261 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2262 | if (b->type == bp_shlib_event) | |
2263 | { | |
2264 | delete_breakpoint (b); | |
2265 | continue; | |
2266 | } | |
c906108c | 2267 | |
4efc6507 DE |
2268 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2269 | if (b->type == bp_jit_event) | |
2270 | { | |
2271 | delete_breakpoint (b); | |
2272 | continue; | |
2273 | } | |
2274 | ||
1900040c | 2275 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2276 | as must overlay event and longjmp master breakpoints. */ |
2277 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2278 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2279 | { |
2280 | delete_breakpoint (b); | |
2281 | continue; | |
2282 | } | |
2283 | ||
c5aa993b JM |
2284 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2285 | if (b->type == bp_step_resume) | |
2286 | { | |
2287 | delete_breakpoint (b); | |
2288 | continue; | |
2289 | } | |
2290 | ||
611c83ae PA |
2291 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2292 | after an exec. */ | |
2293 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2294 | { | |
2295 | delete_breakpoint (b); | |
2296 | continue; | |
2297 | } | |
2298 | ||
ce78b96d JB |
2299 | if (b->type == bp_catchpoint) |
2300 | { | |
2301 | /* For now, none of the bp_catchpoint breakpoints need to | |
2302 | do anything at this point. In the future, if some of | |
2303 | the catchpoints need to something, we will need to add | |
2304 | a new method, and call this method from here. */ | |
2305 | continue; | |
2306 | } | |
2307 | ||
c5aa993b JM |
2308 | /* bp_finish is a special case. The only way we ought to be able |
2309 | to see one of these when an exec() has happened, is if the user | |
2310 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2311 | carries them to the call-site of the current callee, by setting | |
2312 | a temporary bp there and resuming. But in this case, the finish | |
2313 | will carry them entirely through the vfork & exec. | |
2314 | ||
2315 | We don't want to allow a bp_finish to remain inserted now. But | |
2316 | we can't safely delete it, 'cause finish_command has a handle to | |
2317 | the bp on a bpstat, and will later want to delete it. There's a | |
2318 | chance (and I've seen it happen) that if we delete the bp_finish | |
2319 | here, that its storage will get reused by the time finish_command | |
2320 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2321 | We really must allow finish_command to delete a bp_finish. | |
2322 | ||
53a5351d JM |
2323 | In the absense of a general solution for the "how do we know |
2324 | it's safe to delete something others may have handles to?" | |
2325 | problem, what we'll do here is just uninsert the bp_finish, and | |
2326 | let finish_command delete it. | |
2327 | ||
2328 | (We know the bp_finish is "doomed" in the sense that it's | |
2329 | momentary, and will be deleted as soon as finish_command sees | |
2330 | the inferior stopped. So it doesn't matter that the bp's | |
2331 | address is probably bogus in the new a.out, unlike e.g., the | |
2332 | solib breakpoints.) */ | |
c5aa993b | 2333 | |
c5aa993b JM |
2334 | if (b->type == bp_finish) |
2335 | { | |
2336 | continue; | |
2337 | } | |
2338 | ||
2339 | /* Without a symbolic address, we have little hope of the | |
2340 | pre-exec() address meaning the same thing in the post-exec() | |
2341 | a.out. */ | |
2342 | if (b->addr_string == NULL) | |
2343 | { | |
2344 | delete_breakpoint (b); | |
2345 | continue; | |
2346 | } | |
c5aa993b | 2347 | } |
1900040c | 2348 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2349 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2350 | create_longjmp_master_breakpoint ("longjmp"); |
2351 | create_longjmp_master_breakpoint ("_longjmp"); | |
2352 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2353 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2354 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2355 | } |
2356 | ||
2357 | int | |
fba45db2 | 2358 | detach_breakpoints (int pid) |
c906108c | 2359 | { |
876fa593 | 2360 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2361 | int val = 0; |
ce696e05 | 2362 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2363 | struct inferior *inf = current_inferior (); |
c5aa993b | 2364 | |
39f77062 | 2365 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2366 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2367 | |
6c95b8df | 2368 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2369 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2370 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2371 | { |
6c95b8df PA |
2372 | if (b->pspace != inf->pspace) |
2373 | continue; | |
2374 | ||
0bde7532 | 2375 | if (b->inserted) |
6c95b8df | 2376 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2377 | } |
ce696e05 | 2378 | do_cleanups (old_chain); |
3a1bae8e | 2379 | return val; |
c906108c SS |
2380 | } |
2381 | ||
6c95b8df PA |
2382 | /* Remove the breakpoint location B from the current address space. |
2383 | Note that this is used to detach breakpoints from a child fork. | |
2384 | When we get here, the child isn't in the inferior list, and neither | |
2385 | do we have objects to represent its address space --- we should | |
2386 | *not* look at b->pspace->aspace here. */ | |
2387 | ||
c906108c | 2388 | static int |
6c95b8df | 2389 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2390 | { |
2391 | int val; | |
6c95b8df | 2392 | struct cleanup *old_chain; |
c5aa993b | 2393 | |
0bde7532 | 2394 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2395 | /* Permanent breakpoints cannot be inserted or removed. */ |
2396 | return 0; | |
2397 | ||
74960c60 VP |
2398 | /* The type of none suggests that owner is actually deleted. |
2399 | This should not ever happen. */ | |
2400 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2401 | |
2402 | if (b->loc_type == bp_loc_software_breakpoint | |
2403 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2404 | { |
c02f5703 MS |
2405 | /* "Normal" instruction breakpoint: either the standard |
2406 | trap-instruction bp (bp_breakpoint), or a | |
2407 | bp_hardware_breakpoint. */ | |
2408 | ||
2409 | /* First check to see if we have to handle an overlay. */ | |
2410 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2411 | || b->section == NULL |
2412 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2413 | { |
2414 | /* No overlay handling: just remove the breakpoint. */ | |
2415 | ||
0bde7532 | 2416 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2417 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2418 | else |
a6d9a66e | 2419 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2420 | } |
c906108c SS |
2421 | else |
2422 | { | |
c02f5703 MS |
2423 | /* This breakpoint is in an overlay section. |
2424 | Did we set a breakpoint at the LMA? */ | |
2425 | if (!overlay_events_enabled) | |
2426 | { | |
2427 | /* Yes -- overlay event support is not active, so we | |
2428 | should have set a breakpoint at the LMA. Remove it. | |
2429 | */ | |
c02f5703 MS |
2430 | /* Ignore any failures: if the LMA is in ROM, we will |
2431 | have already warned when we failed to insert it. */ | |
0bde7532 | 2432 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2433 | target_remove_hw_breakpoint (b->gdbarch, |
2434 | &b->overlay_target_info); | |
c02f5703 | 2435 | else |
a6d9a66e UW |
2436 | target_remove_breakpoint (b->gdbarch, |
2437 | &b->overlay_target_info); | |
c02f5703 MS |
2438 | } |
2439 | /* Did we set a breakpoint at the VMA? | |
2440 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2441 | if (b->inserted) |
c906108c | 2442 | { |
c02f5703 MS |
2443 | /* Yes -- remove it. Previously we did not bother to |
2444 | remove the breakpoint if the section had been | |
2445 | unmapped, but let's not rely on that being safe. We | |
2446 | don't know what the overlay manager might do. */ | |
0bde7532 | 2447 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2448 | val = target_remove_hw_breakpoint (b->gdbarch, |
2449 | &b->target_info); | |
aa67235e UW |
2450 | |
2451 | /* However, we should remove *software* breakpoints only | |
2452 | if the section is still mapped, or else we overwrite | |
2453 | wrong code with the saved shadow contents. */ | |
2454 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2455 | val = target_remove_breakpoint (b->gdbarch, |
2456 | &b->target_info); | |
aa67235e UW |
2457 | else |
2458 | val = 0; | |
c906108c | 2459 | } |
c02f5703 MS |
2460 | else |
2461 | { | |
2462 | /* No -- not inserted, so no need to remove. No error. */ | |
2463 | val = 0; | |
2464 | } | |
c906108c | 2465 | } |
879d1e6b UW |
2466 | |
2467 | /* In some cases, we might not be able to remove a breakpoint | |
2468 | in a shared library that has already been removed, but we | |
2469 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2470 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2471 | val = 0; |
2472 | ||
c906108c SS |
2473 | if (val) |
2474 | return val; | |
0bde7532 | 2475 | b->inserted = (is == mark_inserted); |
c906108c | 2476 | } |
a5606eee | 2477 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2478 | { |
278cd55f AC |
2479 | struct value *v; |
2480 | struct value *n; | |
c5aa993b | 2481 | |
0bde7532 | 2482 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2483 | val = target_remove_watchpoint (b->address, b->length, |
2484 | b->watchpoint_type); | |
2e70b7b9 | 2485 | |
c906108c | 2486 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2487 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2488 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2489 | b->owner->number); |
c906108c | 2490 | } |
ce78b96d JB |
2491 | else if (b->owner->type == bp_catchpoint |
2492 | && breakpoint_enabled (b->owner) | |
2493 | && !b->duplicate) | |
2494 | { | |
2495 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2496 | ||
2497 | val = b->owner->ops->remove (b->owner); | |
2498 | if (val) | |
2499 | return val; | |
2500 | b->inserted = (is == mark_inserted); | |
2501 | } | |
c906108c SS |
2502 | |
2503 | return 0; | |
2504 | } | |
2505 | ||
6c95b8df PA |
2506 | static int |
2507 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2508 | { | |
2509 | int ret; | |
2510 | struct cleanup *old_chain; | |
2511 | ||
2512 | if (b->owner->enable_state == bp_permanent) | |
2513 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2514 | return 0; | |
2515 | ||
2516 | /* The type of none suggests that owner is actually deleted. | |
2517 | This should not ever happen. */ | |
2518 | gdb_assert (b->owner->type != bp_none); | |
2519 | ||
2520 | old_chain = save_current_space_and_thread (); | |
2521 | ||
2522 | switch_to_program_space_and_thread (b->pspace); | |
2523 | ||
2524 | ret = remove_breakpoint_1 (b, is); | |
2525 | ||
2526 | do_cleanups (old_chain); | |
2527 | return ret; | |
2528 | } | |
2529 | ||
c906108c SS |
2530 | /* Clear the "inserted" flag in all breakpoints. */ |
2531 | ||
25b22b0a | 2532 | void |
fba45db2 | 2533 | mark_breakpoints_out (void) |
c906108c | 2534 | { |
876fa593 | 2535 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2536 | |
876fa593 | 2537 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2538 | if (bpt->pspace == current_program_space) |
2539 | bpt->inserted = 0; | |
c906108c SS |
2540 | } |
2541 | ||
53a5351d JM |
2542 | /* Clear the "inserted" flag in all breakpoints and delete any |
2543 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2544 | |
2545 | Plus other such housekeeping that has to be done for breakpoints | |
2546 | between runs. | |
2547 | ||
53a5351d JM |
2548 | Note: this function gets called at the end of a run (by |
2549 | generic_mourn_inferior) and when a run begins (by | |
2550 | init_wait_for_inferior). */ | |
c906108c SS |
2551 | |
2552 | ||
2553 | ||
2554 | void | |
fba45db2 | 2555 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2556 | { |
52f0bd74 | 2557 | struct breakpoint *b, *temp; |
876fa593 | 2558 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2559 | int ix; |
6c95b8df | 2560 | struct program_space *pspace = current_program_space; |
c906108c | 2561 | |
50c71eaf PA |
2562 | /* If breakpoint locations are shared across processes, then there's |
2563 | nothing to do. */ | |
2567c7d9 | 2564 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2565 | return; |
2566 | ||
876fa593 | 2567 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2568 | { |
2569 | if (bpt->pspace == pspace | |
2570 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2571 | bpt->inserted = 0; |
6c95b8df | 2572 | } |
075f6582 | 2573 | |
c906108c | 2574 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2575 | { |
6c95b8df PA |
2576 | if (b->loc && b->loc->pspace != pspace) |
2577 | continue; | |
2578 | ||
c5aa993b JM |
2579 | switch (b->type) |
2580 | { | |
2581 | case bp_call_dummy: | |
c906108c | 2582 | |
c5aa993b | 2583 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2584 | cause problems when the inferior is rerun, so we better get |
2585 | rid of it. */ | |
2586 | ||
2587 | case bp_watchpoint_scope: | |
2588 | ||
2589 | /* Also get rid of scope breakpoints. */ | |
2590 | ||
2591 | case bp_shlib_event: | |
2592 | ||
2593 | /* Also remove solib event breakpoints. Their addresses may | |
2594 | have changed since the last time we ran the program. | |
2595 | Actually we may now be debugging against different target; | |
2596 | and so the solib backend that installed this breakpoint may | |
2597 | not be used in by the target. E.g., | |
2598 | ||
2599 | (gdb) file prog-linux | |
2600 | (gdb) run # native linux target | |
2601 | ... | |
2602 | (gdb) kill | |
2603 | (gdb) file prog-win.exe | |
2604 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2605 | */ | |
c906108c | 2606 | |
c5aa993b JM |
2607 | delete_breakpoint (b); |
2608 | break; | |
c906108c | 2609 | |
c5aa993b JM |
2610 | case bp_watchpoint: |
2611 | case bp_hardware_watchpoint: | |
2612 | case bp_read_watchpoint: | |
2613 | case bp_access_watchpoint: | |
c906108c | 2614 | |
c5aa993b JM |
2615 | /* Likewise for watchpoints on local expressions. */ |
2616 | if (b->exp_valid_block != NULL) | |
2617 | delete_breakpoint (b); | |
967af18d | 2618 | else if (context == inf_starting) |
c860120c PM |
2619 | { |
2620 | /* Reset val field to force reread of starting value | |
2621 | in insert_breakpoints. */ | |
2622 | if (b->val) | |
2623 | value_free (b->val); | |
2624 | b->val = NULL; | |
fa4727a6 | 2625 | b->val_valid = 0; |
c860120c | 2626 | } |
c5aa993b JM |
2627 | break; |
2628 | default: | |
c5aa993b JM |
2629 | break; |
2630 | } | |
2631 | } | |
1c5cfe86 PA |
2632 | |
2633 | /* Get rid of the moribund locations. */ | |
2634 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2635 | free_bp_location (bpt); | |
2636 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2637 | } |
2638 | ||
6c95b8df PA |
2639 | /* These functions concern about actual breakpoints inserted in the |
2640 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2641 | we need to hop over the bkpt --- so we check for address space | |
2642 | match, not program space. */ | |
2643 | ||
c2c6d25f JM |
2644 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2645 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2646 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2647 | permanent breakpoint. | |
2648 | - When continuing from a location with an ordinary breakpoint, we | |
2649 | actually single step once before calling insert_breakpoints. | |
2650 | - When continuing from a localion with a permanent breakpoint, we | |
2651 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2652 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2653 | |
c2c6d25f | 2654 | enum breakpoint_here |
6c95b8df | 2655 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2656 | { |
876fa593 | 2657 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2658 | int any_breakpoint_here = 0; |
c906108c | 2659 | |
876fa593 | 2660 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2661 | { |
2662 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2663 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2664 | continue; | |
2665 | ||
468d015d | 2666 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2667 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2668 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2669 | aspace, pc)) | |
075f6582 DJ |
2670 | { |
2671 | if (overlay_debugging | |
2672 | && section_is_overlay (bpt->section) | |
2673 | && !section_is_mapped (bpt->section)) | |
2674 | continue; /* unmapped overlay -- can't be a match */ | |
2675 | else if (bpt->owner->enable_state == bp_permanent) | |
2676 | return permanent_breakpoint_here; | |
2677 | else | |
2678 | any_breakpoint_here = 1; | |
2679 | } | |
2680 | } | |
c906108c | 2681 | |
c2c6d25f | 2682 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2683 | } |
2684 | ||
1c5cfe86 PA |
2685 | /* Return true if there's a moribund breakpoint at PC. */ |
2686 | ||
2687 | int | |
6c95b8df | 2688 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2689 | { |
2690 | struct bp_location *loc; | |
2691 | int ix; | |
2692 | ||
2693 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2694 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2695 | aspace, pc)) | |
1c5cfe86 PA |
2696 | return 1; |
2697 | ||
2698 | return 0; | |
2699 | } | |
c2c6d25f | 2700 | |
c36b740a | 2701 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2702 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2703 | This does not check for single-step breakpoints, which are |
2704 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2705 | |
2706 | int | |
6c95b8df | 2707 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2708 | { |
876fa593 | 2709 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2710 | |
876fa593 | 2711 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2712 | { |
075f6582 DJ |
2713 | if (bpt->loc_type != bp_loc_software_breakpoint |
2714 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2715 | continue; | |
2716 | ||
2717 | if (bpt->inserted | |
6c95b8df PA |
2718 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2719 | aspace, pc)) | |
075f6582 DJ |
2720 | { |
2721 | if (overlay_debugging | |
2722 | && section_is_overlay (bpt->section) | |
2723 | && !section_is_mapped (bpt->section)) | |
2724 | continue; /* unmapped overlay -- can't be a match */ | |
2725 | else | |
2726 | return 1; | |
2727 | } | |
c5aa993b | 2728 | } |
c36b740a VP |
2729 | return 0; |
2730 | } | |
2731 | ||
2732 | /* Returns non-zero iff there's either regular breakpoint | |
2733 | or a single step breakpoint inserted at PC. */ | |
2734 | ||
2735 | int | |
6c95b8df | 2736 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2737 | { |
6c95b8df | 2738 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2739 | return 1; |
c906108c | 2740 | |
6c95b8df | 2741 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2742 | return 1; |
2743 | ||
c906108c SS |
2744 | return 0; |
2745 | } | |
2746 | ||
4fa8626c DJ |
2747 | /* This function returns non-zero iff there is a software breakpoint |
2748 | inserted at PC. */ | |
2749 | ||
2750 | int | |
6c95b8df | 2751 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2752 | { |
876fa593 | 2753 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2754 | int any_breakpoint_here = 0; |
2755 | ||
876fa593 | 2756 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2757 | { |
2758 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2759 | continue; | |
2760 | ||
0d381245 | 2761 | if (bpt->inserted |
6c95b8df PA |
2762 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2763 | aspace, pc)) | |
4fa8626c DJ |
2764 | { |
2765 | if (overlay_debugging | |
2766 | && section_is_overlay (bpt->section) | |
2767 | && !section_is_mapped (bpt->section)) | |
2768 | continue; /* unmapped overlay -- can't be a match */ | |
2769 | else | |
2770 | return 1; | |
2771 | } | |
2772 | } | |
2773 | ||
1aafd4da | 2774 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2775 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2776 | return 1; |
2777 | ||
4fa8626c DJ |
2778 | return 0; |
2779 | } | |
2780 | ||
9093389c PA |
2781 | int |
2782 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2783 | CORE_ADDR addr, ULONGEST len) | |
2784 | { | |
2785 | struct breakpoint *bpt; | |
2786 | ||
2787 | ALL_BREAKPOINTS (bpt) | |
2788 | { | |
2789 | struct bp_location *loc; | |
2790 | ||
2791 | if (bpt->type != bp_hardware_watchpoint | |
2792 | && bpt->type != bp_access_watchpoint) | |
2793 | continue; | |
2794 | ||
2795 | if (!breakpoint_enabled (bpt)) | |
2796 | continue; | |
2797 | ||
2798 | for (loc = bpt->loc; loc; loc = loc->next) | |
2799 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2800 | { | |
2801 | CORE_ADDR l, h; | |
2802 | ||
2803 | /* Check for intersection. */ | |
2804 | l = max (loc->address, addr); | |
2805 | h = min (loc->address + loc->length, addr + len); | |
2806 | if (l < h) | |
2807 | return 1; | |
2808 | } | |
2809 | } | |
2810 | return 0; | |
2811 | } | |
2812 | ||
075f6582 DJ |
2813 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2814 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2815 | |
2816 | int | |
6c95b8df PA |
2817 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2818 | ptid_t ptid) | |
c906108c | 2819 | { |
876fa593 | 2820 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2821 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2822 | int thread = -1; |
4a306c9a | 2823 | int task = 0; |
a6f1cd96 | 2824 | |
876fa593 | 2825 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2826 | { |
075f6582 DJ |
2827 | if (bpt->loc_type != bp_loc_software_breakpoint |
2828 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2829 | continue; | |
2830 | ||
a6f1cd96 JB |
2831 | if (!breakpoint_enabled (bpt->owner) |
2832 | && bpt->owner->enable_state != bp_permanent) | |
2833 | continue; | |
2834 | ||
6c95b8df PA |
2835 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2836 | aspace, pc)) | |
a6f1cd96 JB |
2837 | continue; |
2838 | ||
2839 | if (bpt->owner->thread != -1) | |
075f6582 | 2840 | { |
a6f1cd96 JB |
2841 | /* This is a thread-specific breakpoint. Check that ptid |
2842 | matches that thread. If thread hasn't been computed yet, | |
2843 | it is now time to do so. */ | |
2844 | if (thread == -1) | |
2845 | thread = pid_to_thread_id (ptid); | |
2846 | if (bpt->owner->thread != thread) | |
2847 | continue; | |
075f6582 | 2848 | } |
a6f1cd96 | 2849 | |
4a306c9a JB |
2850 | if (bpt->owner->task != 0) |
2851 | { | |
2852 | /* This is a task-specific breakpoint. Check that ptid | |
2853 | matches that task. If task hasn't been computed yet, | |
2854 | it is now time to do so. */ | |
2855 | if (task == 0) | |
2856 | task = ada_get_task_number (ptid); | |
2857 | if (bpt->owner->task != task) | |
2858 | continue; | |
2859 | } | |
2860 | ||
a6f1cd96 JB |
2861 | if (overlay_debugging |
2862 | && section_is_overlay (bpt->section) | |
2863 | && !section_is_mapped (bpt->section)) | |
2864 | continue; /* unmapped overlay -- can't be a match */ | |
2865 | ||
2866 | return 1; | |
c5aa993b | 2867 | } |
c906108c SS |
2868 | |
2869 | return 0; | |
2870 | } | |
c906108c | 2871 | \f |
c5aa993b | 2872 | |
c906108c SS |
2873 | /* bpstat stuff. External routines' interfaces are documented |
2874 | in breakpoint.h. */ | |
2875 | ||
2876 | int | |
fba45db2 | 2877 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2878 | { |
533be4dd | 2879 | return (ep->type == bp_catchpoint); |
c906108c SS |
2880 | } |
2881 | ||
198757a8 VP |
2882 | void |
2883 | bpstat_free (bpstat bs) | |
2884 | { | |
2885 | if (bs->old_val != NULL) | |
2886 | value_free (bs->old_val); | |
9add0f1b | 2887 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2888 | xfree (bs); |
2889 | } | |
2890 | ||
c906108c SS |
2891 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2892 | Also free any storage that is part of a bpstat. */ | |
2893 | ||
2894 | void | |
fba45db2 | 2895 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2896 | { |
2897 | bpstat p; | |
2898 | bpstat q; | |
2899 | ||
2900 | if (bsp == 0) | |
2901 | return; | |
2902 | p = *bsp; | |
2903 | while (p != NULL) | |
2904 | { | |
2905 | q = p->next; | |
198757a8 | 2906 | bpstat_free (p); |
c906108c SS |
2907 | p = q; |
2908 | } | |
2909 | *bsp = NULL; | |
2910 | } | |
2911 | ||
2912 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2913 | is part of the bpstat is copied as well. */ | |
2914 | ||
2915 | bpstat | |
fba45db2 | 2916 | bpstat_copy (bpstat bs) |
c906108c SS |
2917 | { |
2918 | bpstat p = NULL; | |
2919 | bpstat tmp; | |
2920 | bpstat retval = NULL; | |
2921 | ||
2922 | if (bs == NULL) | |
2923 | return bs; | |
2924 | ||
2925 | for (; bs != NULL; bs = bs->next) | |
2926 | { | |
2927 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2928 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2929 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2930 | if (bs->old_val != NULL) |
3c3185ac JK |
2931 | { |
2932 | tmp->old_val = value_copy (bs->old_val); | |
2933 | release_value (tmp->old_val); | |
2934 | } | |
31cc81e9 | 2935 | |
c906108c SS |
2936 | if (p == NULL) |
2937 | /* This is the first thing in the chain. */ | |
2938 | retval = tmp; | |
2939 | else | |
2940 | p->next = tmp; | |
2941 | p = tmp; | |
2942 | } | |
2943 | p->next = NULL; | |
2944 | return retval; | |
2945 | } | |
2946 | ||
2947 | /* Find the bpstat associated with this breakpoint */ | |
2948 | ||
2949 | bpstat | |
fba45db2 | 2950 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2951 | { |
c5aa993b JM |
2952 | if (bsp == NULL) |
2953 | return NULL; | |
c906108c | 2954 | |
c5aa993b JM |
2955 | for (; bsp != NULL; bsp = bsp->next) |
2956 | { | |
4f8d1dc6 | 2957 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2958 | return bsp; |
2959 | } | |
c906108c SS |
2960 | return NULL; |
2961 | } | |
2962 | ||
8671a17b | 2963 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2964 | at. *BSP upon return is a bpstat which points to the remaining |
2965 | breakpoints stopped at (but which is not guaranteed to be good for | |
2966 | anything but further calls to bpstat_num). | |
8671a17b PA |
2967 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2968 | Return -1 if stopped at a breakpoint that has been deleted since | |
2969 | we set it. | |
2970 | Return 1 otherwise. */ | |
c906108c SS |
2971 | |
2972 | int | |
8671a17b | 2973 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2974 | { |
2975 | struct breakpoint *b; | |
2976 | ||
2977 | if ((*bsp) == NULL) | |
2978 | return 0; /* No more breakpoint values */ | |
8671a17b | 2979 | |
4f8d1dc6 VP |
2980 | /* We assume we'll never have several bpstats that |
2981 | correspond to a single breakpoint -- otherwise, | |
2982 | this function might return the same number more | |
2983 | than once and this will look ugly. */ | |
2984 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2985 | *bsp = (*bsp)->next; |
2986 | if (b == NULL) | |
2987 | return -1; /* breakpoint that's been deleted since */ | |
2988 | ||
2989 | *num = b->number; /* We have its number */ | |
2990 | return 1; | |
c906108c SS |
2991 | } |
2992 | ||
2993 | /* Modify BS so that the actions will not be performed. */ | |
2994 | ||
2995 | void | |
fba45db2 | 2996 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2997 | { |
2998 | for (; bs != NULL; bs = bs->next) | |
2999 | { | |
9add0f1b | 3000 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3001 | bs->commands_left = NULL; |
c906108c SS |
3002 | if (bs->old_val != NULL) |
3003 | { | |
3004 | value_free (bs->old_val); | |
3005 | bs->old_val = NULL; | |
3006 | } | |
3007 | } | |
3008 | } | |
3009 | ||
f3b1572e PA |
3010 | /* Called when a command is about to proceed the inferior. */ |
3011 | ||
3012 | static void | |
3013 | breakpoint_about_to_proceed (void) | |
3014 | { | |
3015 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3016 | { | |
3017 | struct thread_info *tp = inferior_thread (); | |
3018 | ||
3019 | /* Allow inferior function calls in breakpoint commands to not | |
3020 | interrupt the command list. When the call finishes | |
3021 | successfully, the inferior will be standing at the same | |
3022 | breakpoint as if nothing happened. */ | |
3023 | if (tp->in_infcall) | |
3024 | return; | |
3025 | } | |
3026 | ||
3027 | breakpoint_proceeded = 1; | |
3028 | } | |
3029 | ||
c906108c | 3030 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3031 | static void |
4efb68b1 | 3032 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3033 | { |
3034 | executing_breakpoint_commands = 0; | |
3035 | } | |
3036 | ||
3037 | /* Execute all the commands associated with all the breakpoints at this | |
3038 | location. Any of these commands could cause the process to proceed | |
3039 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3040 | the global "breakpoint_proceeded" after each command. |
c906108c | 3041 | |
347bddb7 PA |
3042 | Returns true if a breakpoint command resumed the inferior. In that |
3043 | case, it is the caller's responsibility to recall it again with the | |
3044 | bpstat of the current thread. */ | |
3045 | ||
3046 | static int | |
3047 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3048 | { |
3049 | bpstat bs; | |
3050 | struct cleanup *old_chain; | |
347bddb7 | 3051 | int again = 0; |
c906108c SS |
3052 | |
3053 | /* Avoid endless recursion if a `source' command is contained | |
3054 | in bs->commands. */ | |
3055 | if (executing_breakpoint_commands) | |
347bddb7 | 3056 | return 0; |
c906108c SS |
3057 | |
3058 | executing_breakpoint_commands = 1; | |
3059 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3060 | ||
c906108c SS |
3061 | /* This pointer will iterate over the list of bpstat's. */ |
3062 | bs = *bsp; | |
3063 | ||
3064 | breakpoint_proceeded = 0; | |
3065 | for (; bs != NULL; bs = bs->next) | |
3066 | { | |
9add0f1b | 3067 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3068 | struct command_line *cmd; |
3069 | struct cleanup *this_cmd_tree_chain; | |
3070 | ||
3071 | /* Take ownership of the BSP's command tree, if it has one. | |
3072 | ||
3073 | The command tree could legitimately contain commands like | |
3074 | 'step' and 'next', which call clear_proceed_status, which | |
3075 | frees stop_bpstat's command tree. To make sure this doesn't | |
3076 | free the tree we're executing out from under us, we need to | |
3077 | take ownership of the tree ourselves. Since a given bpstat's | |
3078 | commands are only executed once, we don't need to copy it; we | |
3079 | can clear the pointer in the bpstat, and make sure we free | |
3080 | the tree when we're done. */ | |
9add0f1b TT |
3081 | ccmd = bs->commands; |
3082 | bs->commands = NULL; | |
3083 | this_cmd_tree_chain | |
3084 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3085 | cmd = bs->commands_left; | |
3086 | bs->commands_left = NULL; | |
6c50ab1c | 3087 | |
c906108c SS |
3088 | while (cmd != NULL) |
3089 | { | |
3090 | execute_control_command (cmd); | |
3091 | ||
3092 | if (breakpoint_proceeded) | |
3093 | break; | |
3094 | else | |
3095 | cmd = cmd->next; | |
3096 | } | |
6c50ab1c JB |
3097 | |
3098 | /* We can free this command tree now. */ | |
3099 | do_cleanups (this_cmd_tree_chain); | |
3100 | ||
c906108c | 3101 | if (breakpoint_proceeded) |
32c1e744 VP |
3102 | { |
3103 | if (target_can_async_p ()) | |
347bddb7 PA |
3104 | /* If we are in async mode, then the target might be still |
3105 | running, not stopped at any breakpoint, so nothing for | |
3106 | us to do here -- just return to the event loop. */ | |
3107 | ; | |
32c1e744 VP |
3108 | else |
3109 | /* In sync mode, when execute_control_command returns | |
3110 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3111 | Breakpoint commands for that stop were not run, since |
3112 | execute_command does not run breakpoint commands -- | |
3113 | only command_line_handler does, but that one is not | |
3114 | involved in execution of breakpoint commands. So, we | |
3115 | can now execute breakpoint commands. It should be | |
3116 | noted that making execute_command do bpstat actions is | |
3117 | not an option -- in this case we'll have recursive | |
3118 | invocation of bpstat for each breakpoint with a | |
3119 | command, and can easily blow up GDB stack. Instead, we | |
3120 | return true, which will trigger the caller to recall us | |
3121 | with the new stop_bpstat. */ | |
3122 | again = 1; | |
3123 | break; | |
32c1e744 | 3124 | } |
c906108c | 3125 | } |
c2b8ed2c | 3126 | do_cleanups (old_chain); |
347bddb7 PA |
3127 | return again; |
3128 | } | |
3129 | ||
3130 | void | |
3131 | bpstat_do_actions (void) | |
3132 | { | |
3133 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3134 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3135 | && target_has_execution | |
3136 | && !is_exited (inferior_ptid) | |
3137 | && !is_executing (inferior_ptid)) | |
3138 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3139 | and only return when it is stopped at the next breakpoint, we | |
3140 | keep doing breakpoint actions until it returns false to | |
3141 | indicate the inferior was not resumed. */ | |
3142 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3143 | break; | |
c906108c SS |
3144 | } |
3145 | ||
fa4727a6 DJ |
3146 | /* Print out the (old or new) value associated with a watchpoint. */ |
3147 | ||
3148 | static void | |
3149 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3150 | { | |
3151 | if (val == NULL) | |
3152 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3153 | else | |
79a45b7d TT |
3154 | { |
3155 | struct value_print_options opts; | |
3156 | get_user_print_options (&opts); | |
3157 | value_print (val, stream, &opts); | |
3158 | } | |
fa4727a6 DJ |
3159 | } |
3160 | ||
e514a9d6 | 3161 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3162 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3163 | by having it set different print_it values. |
3164 | ||
3165 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3166 | through the bpstat list of things causing this stop, calling the | |
3167 | print_bp_stop_message function on each one. The behavior of the | |
3168 | print_bp_stop_message function depends on the print_it field of | |
3169 | bpstat. If such field so indicates, call this function here. | |
3170 | ||
3171 | Return values from this routine (ultimately used by bpstat_print() | |
3172 | and normal_stop() to decide what to do): | |
3173 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3174 | don't print anything else. | |
3175 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3176 | that something to be followed by a location. | |
3177 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3178 | that something to be followed by a location. | |
3179 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3180 | analysis. */ | |
c906108c | 3181 | |
917317f4 | 3182 | static enum print_stop_action |
fba45db2 | 3183 | print_it_typical (bpstat bs) |
c906108c | 3184 | { |
f7545552 | 3185 | struct cleanup *old_chain; |
4f8d1dc6 | 3186 | struct breakpoint *b; |
89f9893c | 3187 | const struct bp_location *bl; |
8b93c638 | 3188 | struct ui_stream *stb; |
f7545552 TT |
3189 | int bp_temp = 0; |
3190 | enum print_stop_action result; | |
3191 | ||
c906108c SS |
3192 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3193 | which has since been deleted. */ | |
e514a9d6 | 3194 | if (bs->breakpoint_at == NULL) |
917317f4 | 3195 | return PRINT_UNKNOWN; |
0d381245 VP |
3196 | bl = bs->breakpoint_at; |
3197 | b = bl->owner; | |
c906108c | 3198 | |
f7545552 TT |
3199 | stb = ui_out_stream_new (uiout); |
3200 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3201 | ||
4f8d1dc6 | 3202 | switch (b->type) |
c906108c | 3203 | { |
e514a9d6 JM |
3204 | case bp_breakpoint: |
3205 | case bp_hardware_breakpoint: | |
2cec12e5 | 3206 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3207 | if (bl->address != bl->requested_address) |
3208 | breakpoint_adjustment_warning (bl->requested_address, | |
3209 | bl->address, | |
4f8d1dc6 VP |
3210 | b->number, 1); |
3211 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3212 | if (bp_temp) |
3213 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3214 | else | |
3215 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3216 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3217 | { |
3218 | ui_out_field_string (uiout, "reason", | |
3219 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3220 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3221 | } | |
4f8d1dc6 | 3222 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3223 | ui_out_text (uiout, ", "); |
f7545552 | 3224 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3225 | break; |
3226 | ||
3227 | case bp_shlib_event: | |
917317f4 JM |
3228 | /* Did we stop because the user set the stop_on_solib_events |
3229 | variable? (If so, we report this as a generic, "Stopped due | |
3230 | to shlib event" message.) */ | |
a3f17187 | 3231 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3232 | result = PRINT_NOTHING; |
e514a9d6 JM |
3233 | break; |
3234 | ||
c4093a6a JM |
3235 | case bp_thread_event: |
3236 | /* Not sure how we will get here. | |
3237 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3238 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3239 | result = PRINT_NOTHING; |
c4093a6a JM |
3240 | break; |
3241 | ||
1900040c MS |
3242 | case bp_overlay_event: |
3243 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3244 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3245 | result = PRINT_NOTHING; |
1900040c MS |
3246 | break; |
3247 | ||
0fd8e87f UW |
3248 | case bp_longjmp_master: |
3249 | /* These should never be enabled. */ | |
3250 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3251 | result = PRINT_NOTHING; | |
3252 | break; | |
3253 | ||
aa7d318d TT |
3254 | case bp_std_terminate_master: |
3255 | /* These should never be enabled. */ | |
3256 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3257 | result = PRINT_NOTHING; | |
3258 | break; | |
3259 | ||
e514a9d6 JM |
3260 | case bp_watchpoint: |
3261 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3262 | annotate_watchpoint (b->number); |
3263 | if (ui_out_is_mi_like_p (uiout)) | |
3264 | ui_out_field_string | |
3265 | (uiout, "reason", | |
3266 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3267 | mention (b); | |
f7545552 | 3268 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3269 | ui_out_text (uiout, "\nOld value = "); |
3270 | watchpoint_value_print (bs->old_val, stb->stream); | |
3271 | ui_out_field_stream (uiout, "old", stb); | |
3272 | ui_out_text (uiout, "\nNew value = "); | |
3273 | watchpoint_value_print (b->val, stb->stream); | |
3274 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3275 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3276 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3277 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3278 | break; |
3279 | ||
3280 | case bp_read_watchpoint: | |
9dc5e2a9 | 3281 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3282 | ui_out_field_string |
3283 | (uiout, "reason", | |
3284 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3285 | mention (b); |
f7545552 | 3286 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3287 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3288 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3289 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3290 | ui_out_text (uiout, "\n"); |
f7545552 | 3291 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3292 | break; |
3293 | ||
3294 | case bp_access_watchpoint: | |
fa4727a6 | 3295 | if (bs->old_val != NULL) |
8b93c638 | 3296 | { |
4f8d1dc6 | 3297 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3298 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3299 | ui_out_field_string |
3300 | (uiout, "reason", | |
3301 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3302 | mention (b); |
f7545552 | 3303 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3304 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3305 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3306 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3307 | ui_out_text (uiout, "\nNew value = "); |
3308 | } | |
3309 | else | |
3310 | { | |
4f8d1dc6 | 3311 | mention (b); |
9dc5e2a9 | 3312 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3313 | ui_out_field_string |
3314 | (uiout, "reason", | |
3315 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3316 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3317 | ui_out_text (uiout, "\nValue = "); |
3318 | } | |
fa4727a6 | 3319 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3320 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3321 | ui_out_text (uiout, "\n"); |
f7545552 | 3322 | result = PRINT_UNKNOWN; |
e514a9d6 | 3323 | break; |
4ce44c66 | 3324 | |
e514a9d6 JM |
3325 | /* Fall through, we don't deal with these types of breakpoints |
3326 | here. */ | |
3327 | ||
11cf8741 | 3328 | case bp_finish: |
9dc5e2a9 | 3329 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3330 | ui_out_field_string |
3331 | (uiout, "reason", | |
3332 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3333 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3334 | break; |
3335 | ||
e514a9d6 | 3336 | case bp_until: |
9dc5e2a9 | 3337 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3338 | ui_out_field_string |
3339 | (uiout, "reason", | |
3340 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3341 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3342 | break; |
3343 | ||
c2d11a7d | 3344 | case bp_none: |
e514a9d6 JM |
3345 | case bp_longjmp: |
3346 | case bp_longjmp_resume: | |
3347 | case bp_step_resume: | |
e514a9d6 JM |
3348 | case bp_watchpoint_scope: |
3349 | case bp_call_dummy: | |
aa7d318d | 3350 | case bp_std_terminate: |
1042e4c0 | 3351 | case bp_tracepoint: |
7a697b8d | 3352 | case bp_fast_tracepoint: |
4efc6507 | 3353 | case bp_jit_event: |
e514a9d6 | 3354 | default: |
f7545552 TT |
3355 | result = PRINT_UNKNOWN; |
3356 | break; | |
e514a9d6 | 3357 | } |
f7545552 TT |
3358 | |
3359 | do_cleanups (old_chain); | |
3360 | return result; | |
e514a9d6 JM |
3361 | } |
3362 | ||
3363 | /* Generic routine for printing messages indicating why we | |
3364 | stopped. The behavior of this function depends on the value | |
3365 | 'print_it' in the bpstat structure. Under some circumstances we | |
3366 | may decide not to print anything here and delegate the task to | |
3367 | normal_stop(). */ | |
3368 | ||
3369 | static enum print_stop_action | |
3370 | print_bp_stop_message (bpstat bs) | |
3371 | { | |
3372 | switch (bs->print_it) | |
3373 | { | |
3374 | case print_it_noop: | |
3375 | /* Nothing should be printed for this bpstat entry. */ | |
3376 | return PRINT_UNKNOWN; | |
3377 | break; | |
3378 | ||
3379 | case print_it_done: | |
3380 | /* We still want to print the frame, but we already printed the | |
3381 | relevant messages. */ | |
3382 | return PRINT_SRC_AND_LOC; | |
3383 | break; | |
3384 | ||
3385 | case print_it_normal: | |
4f8d1dc6 | 3386 | { |
89f9893c | 3387 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3388 | struct breakpoint *b = bl ? bl->owner : NULL; |
3389 | ||
3390 | /* Normal case. Call the breakpoint's print_it method, or | |
3391 | print_it_typical. */ | |
3392 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3393 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3394 | return b->ops->print_it (b); | |
3395 | else | |
3396 | return print_it_typical (bs); | |
3397 | } | |
3398 | break; | |
3086aeae | 3399 | |
e514a9d6 | 3400 | default: |
8e65ff28 | 3401 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3402 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3403 | break; |
c906108c | 3404 | } |
c906108c SS |
3405 | } |
3406 | ||
e514a9d6 JM |
3407 | /* Print a message indicating what happened. This is called from |
3408 | normal_stop(). The input to this routine is the head of the bpstat | |
3409 | list - a list of the eventpoints that caused this stop. This | |
3410 | routine calls the generic print routine for printing a message | |
3411 | about reasons for stopping. This will print (for example) the | |
3412 | "Breakpoint n," part of the output. The return value of this | |
3413 | routine is one of: | |
c906108c | 3414 | |
917317f4 JM |
3415 | PRINT_UNKNOWN: Means we printed nothing |
3416 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3417 | code to print the location. An example is |
3418 | "Breakpoint 1, " which should be followed by | |
3419 | the location. | |
917317f4 | 3420 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3421 | to also print the location part of the message. |
3422 | An example is the catch/throw messages, which | |
917317f4 JM |
3423 | don't require a location appended to the end. |
3424 | PRINT_NOTHING: We have done some printing and we don't need any | |
3425 | further info to be printed.*/ | |
c906108c | 3426 | |
917317f4 | 3427 | enum print_stop_action |
fba45db2 | 3428 | bpstat_print (bpstat bs) |
c906108c SS |
3429 | { |
3430 | int val; | |
c5aa993b | 3431 | |
c906108c | 3432 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3433 | (Currently all watchpoints go on the bpstat whether hit or not. |
3434 | That probably could (should) be changed, provided care is taken | |
c906108c | 3435 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3436 | for (; bs; bs = bs->next) |
3437 | { | |
3438 | val = print_bp_stop_message (bs); | |
3439 | if (val == PRINT_SRC_ONLY | |
3440 | || val == PRINT_SRC_AND_LOC | |
3441 | || val == PRINT_NOTHING) | |
3442 | return val; | |
3443 | } | |
c906108c | 3444 | |
e514a9d6 JM |
3445 | /* We reached the end of the chain, or we got a null BS to start |
3446 | with and nothing was printed. */ | |
917317f4 | 3447 | return PRINT_UNKNOWN; |
c906108c SS |
3448 | } |
3449 | ||
3450 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3451 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3452 | The argument is a "struct expression *" that has been cast to char * to | |
3453 | make it pass through catch_errors. */ | |
3454 | ||
3455 | static int | |
4efb68b1 | 3456 | breakpoint_cond_eval (void *exp) |
c906108c | 3457 | { |
278cd55f | 3458 | struct value *mark = value_mark (); |
c5aa993b | 3459 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3460 | value_free_to_mark (mark); |
3461 | return i; | |
3462 | } | |
3463 | ||
3464 | /* Allocate a new bpstat and chain it to the current one. */ | |
3465 | ||
3466 | static bpstat | |
89f9893c | 3467 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3468 | { |
3469 | bpstat bs; | |
3470 | ||
3471 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3472 | cbs->next = bs; | |
4f8d1dc6 | 3473 | bs->breakpoint_at = bl; |
c906108c SS |
3474 | /* If the condition is false, etc., don't do the commands. */ |
3475 | bs->commands = NULL; | |
9add0f1b | 3476 | bs->commands_left = NULL; |
c906108c SS |
3477 | bs->old_val = NULL; |
3478 | bs->print_it = print_it_normal; | |
3479 | return bs; | |
3480 | } | |
3481 | \f | |
d983da9c DJ |
3482 | /* The target has stopped with waitstatus WS. Check if any hardware |
3483 | watchpoints have triggered, according to the target. */ | |
3484 | ||
3485 | int | |
3486 | watchpoints_triggered (struct target_waitstatus *ws) | |
3487 | { | |
d92524f1 | 3488 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3489 | CORE_ADDR addr; |
3490 | struct breakpoint *b; | |
3491 | ||
3492 | if (!stopped_by_watchpoint) | |
3493 | { | |
3494 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3495 | as not triggered. */ | |
3496 | ALL_BREAKPOINTS (b) | |
3497 | if (b->type == bp_hardware_watchpoint | |
3498 | || b->type == bp_read_watchpoint | |
3499 | || b->type == bp_access_watchpoint) | |
3500 | b->watchpoint_triggered = watch_triggered_no; | |
3501 | ||
3502 | return 0; | |
3503 | } | |
3504 | ||
3505 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3506 | { | |
3507 | /* We were stopped by a watchpoint, but we don't know where. | |
3508 | Mark all watchpoints as unknown. */ | |
3509 | ALL_BREAKPOINTS (b) | |
3510 | if (b->type == bp_hardware_watchpoint | |
3511 | || b->type == bp_read_watchpoint | |
3512 | || b->type == bp_access_watchpoint) | |
3513 | b->watchpoint_triggered = watch_triggered_unknown; | |
3514 | ||
3515 | return stopped_by_watchpoint; | |
3516 | } | |
3517 | ||
3518 | /* The target could report the data address. Mark watchpoints | |
3519 | affected by this data address as triggered, and all others as not | |
3520 | triggered. */ | |
3521 | ||
3522 | ALL_BREAKPOINTS (b) | |
3523 | if (b->type == bp_hardware_watchpoint | |
3524 | || b->type == bp_read_watchpoint | |
3525 | || b->type == bp_access_watchpoint) | |
3526 | { | |
a5606eee | 3527 | struct bp_location *loc; |
d983da9c DJ |
3528 | struct value *v; |
3529 | ||
3530 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3531 | for (loc = b->loc; loc; loc = loc->next) |
3532 | /* Exact match not required. Within range is | |
3533 | sufficient. */ | |
5009afc5 AS |
3534 | if (target_watchpoint_addr_within_range (¤t_target, |
3535 | addr, loc->address, | |
3536 | loc->length)) | |
a5606eee VP |
3537 | { |
3538 | b->watchpoint_triggered = watch_triggered_yes; | |
3539 | break; | |
3540 | } | |
d983da9c DJ |
3541 | } |
3542 | ||
3543 | return 1; | |
3544 | } | |
3545 | ||
c906108c SS |
3546 | /* Possible return values for watchpoint_check (this can't be an enum |
3547 | because of check_errors). */ | |
3548 | /* The watchpoint has been deleted. */ | |
3549 | #define WP_DELETED 1 | |
3550 | /* The value has changed. */ | |
3551 | #define WP_VALUE_CHANGED 2 | |
3552 | /* The value has not changed. */ | |
3553 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3554 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3555 | #define WP_IGNORE 4 | |
c906108c SS |
3556 | |
3557 | #define BP_TEMPFLAG 1 | |
3558 | #define BP_HARDWAREFLAG 2 | |
3559 | ||
553e4c11 JB |
3560 | /* Evaluate watchpoint condition expression and check if its value changed. |
3561 | ||
3562 | P should be a pointer to struct bpstat, but is defined as a void * | |
3563 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3564 | |
3565 | static int | |
4efb68b1 | 3566 | watchpoint_check (void *p) |
c906108c SS |
3567 | { |
3568 | bpstat bs = (bpstat) p; | |
3569 | struct breakpoint *b; | |
3570 | struct frame_info *fr; | |
3571 | int within_current_scope; | |
3572 | ||
4f8d1dc6 | 3573 | b = bs->breakpoint_at->owner; |
c906108c | 3574 | |
f6bc2008 PA |
3575 | /* If this is a local watchpoint, we only want to check if the |
3576 | watchpoint frame is in scope if the current thread is the thread | |
3577 | that was used to create the watchpoint. */ | |
3578 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3579 | return WP_IGNORE; |
f6bc2008 | 3580 | |
c906108c SS |
3581 | if (b->exp_valid_block == NULL) |
3582 | within_current_scope = 1; | |
3583 | else | |
3584 | { | |
edb3359d DJ |
3585 | struct frame_info *frame = get_current_frame (); |
3586 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3587 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3588 | ||
a0f49112 JK |
3589 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3590 | in the function but the stack frame has already been invalidated. | |
3591 | Since we can't rely on the values of local variables after the | |
3592 | stack has been destroyed, we are treating the watchpoint in that | |
3593 | state as `not changed' without further checking. Don't mark | |
3594 | watchpoints as changed if the current frame is in an epilogue - | |
3595 | even if they are in some other frame, our view of the stack | |
3596 | is likely to be wrong and frame_find_by_id could error out. */ | |
3597 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3598 | return WP_IGNORE; |
a0f49112 | 3599 | |
101dcfbe | 3600 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3601 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3602 | |
3603 | /* If we've gotten confused in the unwinder, we might have | |
3604 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3605 | if (within_current_scope) |
3606 | { | |
3607 | struct symbol *function; | |
3608 | ||
3609 | function = get_frame_function (fr); | |
3610 | if (function == NULL | |
3611 | || !contained_in (b->exp_valid_block, | |
3612 | SYMBOL_BLOCK_VALUE (function))) | |
3613 | within_current_scope = 0; | |
3614 | } | |
69fbadd5 | 3615 | |
edb3359d | 3616 | if (within_current_scope) |
c906108c SS |
3617 | /* If we end up stopping, the current frame will get selected |
3618 | in normal_stop. So this call to select_frame won't affect | |
3619 | the user. */ | |
0f7d239c | 3620 | select_frame (fr); |
c906108c | 3621 | } |
c5aa993b | 3622 | |
c906108c SS |
3623 | if (within_current_scope) |
3624 | { | |
3625 | /* We use value_{,free_to_}mark because it could be a | |
3626 | *long* time before we return to the command level and | |
c5aa993b JM |
3627 | call free_all_values. We can't call free_all_values because |
3628 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3629 | |
278cd55f | 3630 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3631 | struct value *new_val; |
3632 | ||
3633 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3634 | |
3635 | /* We use value_equal_contents instead of value_equal because the latter | |
3636 | coerces an array to a pointer, thus comparing just the address of the | |
3637 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3638 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3639 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3640 | { |
fa4727a6 DJ |
3641 | if (new_val != NULL) |
3642 | { | |
3643 | release_value (new_val); | |
3644 | value_free_to_mark (mark); | |
3645 | } | |
c906108c SS |
3646 | bs->old_val = b->val; |
3647 | b->val = new_val; | |
fa4727a6 | 3648 | b->val_valid = 1; |
c906108c SS |
3649 | return WP_VALUE_CHANGED; |
3650 | } | |
3651 | else | |
3652 | { | |
60e1c644 | 3653 | /* Nothing changed. */ |
c906108c | 3654 | value_free_to_mark (mark); |
c906108c SS |
3655 | return WP_VALUE_NOT_CHANGED; |
3656 | } | |
3657 | } | |
3658 | else | |
3659 | { | |
3660 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3661 | if we temporarily ignored the watchpoint, then when |
3662 | we reenter the block in which it is valid it contains | |
3663 | garbage (in the case of a function, it may have two | |
3664 | garbage values, one before and one after the prologue). | |
3665 | So we can't even detect the first assignment to it and | |
3666 | watch after that (since the garbage may or may not equal | |
3667 | the first value assigned). */ | |
4ce44c66 JM |
3668 | /* We print all the stop information in print_it_typical(), but |
3669 | in this case, by the time we call print_it_typical() this bp | |
3670 | will be deleted already. So we have no choice but print the | |
3671 | information here. */ | |
9dc5e2a9 | 3672 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3673 | ui_out_field_string |
3674 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3675 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3676 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3677 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3678 | which its expression is valid.\n"); | |
4ce44c66 | 3679 | |
c906108c | 3680 | if (b->related_breakpoint) |
60e1c644 PA |
3681 | { |
3682 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3683 | b->related_breakpoint->related_breakpoint = NULL; | |
3684 | b->related_breakpoint = NULL; | |
3685 | } | |
b5de0fa7 | 3686 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3687 | |
3688 | return WP_DELETED; | |
3689 | } | |
3690 | } | |
3691 | ||
18a18393 VP |
3692 | /* Return true if it looks like target has stopped due to hitting |
3693 | breakpoint location BL. This function does not check if we | |
3694 | should stop, only if BL explains the stop. */ | |
3695 | static int | |
6c95b8df PA |
3696 | bpstat_check_location (const struct bp_location *bl, |
3697 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3698 | { |
3699 | struct breakpoint *b = bl->owner; | |
3700 | ||
e8595ef6 SS |
3701 | /* By definition, the inferior does not report stops at |
3702 | tracepoints. */ | |
d77f58be | 3703 | if (is_tracepoint (b)) |
e8595ef6 SS |
3704 | return 0; |
3705 | ||
18a18393 VP |
3706 | if (b->type != bp_watchpoint |
3707 | && b->type != bp_hardware_watchpoint | |
3708 | && b->type != bp_read_watchpoint | |
3709 | && b->type != bp_access_watchpoint | |
3710 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3711 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3712 | { |
6c95b8df PA |
3713 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3714 | aspace, bp_addr)) | |
18a18393 VP |
3715 | return 0; |
3716 | if (overlay_debugging /* unmapped overlay section */ | |
3717 | && section_is_overlay (bl->section) | |
3718 | && !section_is_mapped (bl->section)) | |
3719 | return 0; | |
3720 | } | |
3721 | ||
3722 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3723 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3724 | some data address). Otherwise gdb won't stop on a break instruction | |
3725 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3726 | been defined. Also skip watchpoints which we know did not trigger | |
3727 | (did not match the data address). */ | |
3728 | ||
3729 | if ((b->type == bp_hardware_watchpoint | |
3730 | || b->type == bp_read_watchpoint | |
3731 | || b->type == bp_access_watchpoint) | |
3732 | && b->watchpoint_triggered == watch_triggered_no) | |
3733 | return 0; | |
3734 | ||
3735 | if (b->type == bp_hardware_breakpoint) | |
3736 | { | |
3737 | if (bl->address != bp_addr) | |
3738 | return 0; | |
3739 | if (overlay_debugging /* unmapped overlay section */ | |
3740 | && section_is_overlay (bl->section) | |
3741 | && !section_is_mapped (bl->section)) | |
3742 | return 0; | |
3743 | } | |
ce78b96d | 3744 | |
ce78b96d JB |
3745 | if (b->type == bp_catchpoint) |
3746 | { | |
3747 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3748 | if (!b->ops->breakpoint_hit (b)) | |
3749 | return 0; | |
3750 | } | |
3751 | ||
18a18393 VP |
3752 | return 1; |
3753 | } | |
3754 | ||
3755 | /* If BS refers to a watchpoint, determine if the watched values | |
3756 | has actually changed, and we should stop. If not, set BS->stop | |
3757 | to 0. */ | |
3758 | static void | |
3759 | bpstat_check_watchpoint (bpstat bs) | |
3760 | { | |
3761 | const struct bp_location *bl = bs->breakpoint_at; | |
3762 | struct breakpoint *b = bl->owner; | |
3763 | ||
3764 | if (b->type == bp_watchpoint | |
3765 | || b->type == bp_read_watchpoint | |
3766 | || b->type == bp_access_watchpoint | |
3767 | || b->type == bp_hardware_watchpoint) | |
3768 | { | |
3769 | CORE_ADDR addr; | |
3770 | struct value *v; | |
3771 | int must_check_value = 0; | |
3772 | ||
3773 | if (b->type == bp_watchpoint) | |
3774 | /* For a software watchpoint, we must always check the | |
3775 | watched value. */ | |
3776 | must_check_value = 1; | |
3777 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3778 | /* We have a hardware watchpoint (read, write, or access) | |
3779 | and the target earlier reported an address watched by | |
3780 | this watchpoint. */ | |
3781 | must_check_value = 1; | |
3782 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3783 | && b->type == bp_hardware_watchpoint) | |
3784 | /* We were stopped by a hardware watchpoint, but the target could | |
3785 | not report the data address. We must check the watchpoint's | |
3786 | value. Access and read watchpoints are out of luck; without | |
3787 | a data address, we can't figure it out. */ | |
3788 | must_check_value = 1; | |
3789 | ||
3790 | if (must_check_value) | |
3791 | { | |
3792 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3793 | b->number); | |
3794 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3795 | int e = catch_errors (watchpoint_check, bs, message, | |
3796 | RETURN_MASK_ALL); | |
3797 | do_cleanups (cleanups); | |
3798 | switch (e) | |
3799 | { | |
3800 | case WP_DELETED: | |
3801 | /* We've already printed what needs to be printed. */ | |
3802 | bs->print_it = print_it_done; | |
3803 | /* Stop. */ | |
3804 | break; | |
60e1c644 PA |
3805 | case WP_IGNORE: |
3806 | bs->print_it = print_it_noop; | |
3807 | bs->stop = 0; | |
3808 | break; | |
18a18393 VP |
3809 | case WP_VALUE_CHANGED: |
3810 | if (b->type == bp_read_watchpoint) | |
3811 | { | |
85d721b8 PA |
3812 | /* There are two cases to consider here: |
3813 | ||
3814 | 1. we're watching the triggered memory for reads. | |
3815 | In that case, trust the target, and always report | |
3816 | the watchpoint hit to the user. Even though | |
3817 | reads don't cause value changes, the value may | |
3818 | have changed since the last time it was read, and | |
3819 | since we're not trapping writes, we will not see | |
3820 | those, and as such we should ignore our notion of | |
3821 | old value. | |
3822 | ||
3823 | 2. we're watching the triggered memory for both | |
3824 | reads and writes. There are two ways this may | |
3825 | happen: | |
3826 | ||
3827 | 2.1. this is a target that can't break on data | |
3828 | reads only, but can break on accesses (reads or | |
3829 | writes), such as e.g., x86. We detect this case | |
3830 | at the time we try to insert read watchpoints. | |
3831 | ||
3832 | 2.2. otherwise, the target supports read | |
3833 | watchpoints, but, the user set an access or write | |
3834 | watchpoint watching the same memory as this read | |
3835 | watchpoint. | |
3836 | ||
3837 | If we're watching memory writes as well as reads, | |
3838 | ignore watchpoint hits when we find that the | |
3839 | value hasn't changed, as reads don't cause | |
3840 | changes. This still gives false positives when | |
3841 | the program writes the same value to memory as | |
3842 | what there was already in memory (we will confuse | |
3843 | it for a read), but it's much better than | |
3844 | nothing. */ | |
3845 | ||
3846 | int other_write_watchpoint = 0; | |
3847 | ||
3848 | if (bl->watchpoint_type == hw_read) | |
3849 | { | |
3850 | struct breakpoint *other_b; | |
3851 | ||
3852 | ALL_BREAKPOINTS (other_b) | |
3853 | if ((other_b->type == bp_hardware_watchpoint | |
3854 | || other_b->type == bp_access_watchpoint) | |
3855 | && (other_b->watchpoint_triggered | |
3856 | == watch_triggered_yes)) | |
3857 | { | |
3858 | other_write_watchpoint = 1; | |
3859 | break; | |
3860 | } | |
3861 | } | |
3862 | ||
3863 | if (other_write_watchpoint | |
3864 | || bl->watchpoint_type == hw_access) | |
3865 | { | |
3866 | /* We're watching the same memory for writes, | |
3867 | and the value changed since the last time we | |
3868 | updated it, so this trap must be for a write. | |
3869 | Ignore it. */ | |
3870 | bs->print_it = print_it_noop; | |
3871 | bs->stop = 0; | |
3872 | } | |
18a18393 VP |
3873 | } |
3874 | break; | |
3875 | case WP_VALUE_NOT_CHANGED: | |
3876 | if (b->type == bp_hardware_watchpoint | |
3877 | || b->type == bp_watchpoint) | |
3878 | { | |
3879 | /* Don't stop: write watchpoints shouldn't fire if | |
3880 | the value hasn't changed. */ | |
3881 | bs->print_it = print_it_noop; | |
3882 | bs->stop = 0; | |
3883 | } | |
3884 | /* Stop. */ | |
3885 | break; | |
3886 | default: | |
3887 | /* Can't happen. */ | |
3888 | case 0: | |
3889 | /* Error from catch_errors. */ | |
3890 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3891 | if (b->related_breakpoint) | |
3892 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3893 | b->disposition = disp_del_at_next_stop; | |
3894 | /* We've already printed what needs to be printed. */ | |
3895 | bs->print_it = print_it_done; | |
3896 | break; | |
3897 | } | |
3898 | } | |
3899 | else /* must_check_value == 0 */ | |
3900 | { | |
3901 | /* This is a case where some watchpoint(s) triggered, but | |
3902 | not at the address of this watchpoint, or else no | |
3903 | watchpoint triggered after all. So don't print | |
3904 | anything for this watchpoint. */ | |
3905 | bs->print_it = print_it_noop; | |
3906 | bs->stop = 0; | |
3907 | } | |
3908 | } | |
3909 | } | |
3910 | ||
3911 | ||
3912 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3913 | of breakpoint referred to by BS. If we should not stop for this | |
3914 | breakpoint, set BS->stop to 0. */ | |
3915 | static void | |
3916 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3917 | { | |
3918 | int thread_id = pid_to_thread_id (ptid); | |
3919 | const struct bp_location *bl = bs->breakpoint_at; | |
3920 | struct breakpoint *b = bl->owner; | |
3921 | ||
3922 | if (frame_id_p (b->frame_id) | |
edb3359d | 3923 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3924 | bs->stop = 0; |
3925 | else if (bs->stop) | |
3926 | { | |
3927 | int value_is_zero = 0; | |
60e1c644 PA |
3928 | struct expression *cond; |
3929 | ||
18a18393 VP |
3930 | /* If this is a scope breakpoint, mark the associated |
3931 | watchpoint as triggered so that we will handle the | |
3932 | out-of-scope event. We'll get to the watchpoint next | |
3933 | iteration. */ | |
3934 | if (b->type == bp_watchpoint_scope) | |
3935 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3936 | |
3937 | if (is_watchpoint (b)) | |
3938 | cond = b->cond_exp; | |
3939 | else | |
3940 | cond = bl->cond; | |
3941 | ||
3942 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3943 | { |
60e1c644 PA |
3944 | int within_current_scope = 1; |
3945 | ||
c5bc3a77 DJ |
3946 | /* We use value_mark and value_free_to_mark because it could |
3947 | be a long time before we return to the command level and | |
3948 | call free_all_values. We can't call free_all_values | |
3949 | because we might be in the middle of evaluating a | |
3950 | function call. */ | |
3951 | struct value *mark = value_mark (); | |
3952 | ||
edb3359d DJ |
3953 | /* Need to select the frame, with all that implies so that |
3954 | the conditions will have the right context. Because we | |
3955 | use the frame, we will not see an inlined function's | |
3956 | variables when we arrive at a breakpoint at the start | |
3957 | of the inlined function; the current frame will be the | |
3958 | call site. */ | |
60e1c644 PA |
3959 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3960 | select_frame (get_current_frame ()); | |
3961 | else | |
3962 | { | |
3963 | struct frame_info *frame; | |
3964 | ||
3965 | /* For local watchpoint expressions, which particular | |
3966 | instance of a local is being watched matters, so we | |
3967 | keep track of the frame to evaluate the expression | |
3968 | in. To evaluate the condition however, it doesn't | |
3969 | really matter which instantiation of the function | |
3970 | where the condition makes sense triggers the | |
3971 | watchpoint. This allows an expression like "watch | |
3972 | global if q > 10" set in `func', catch writes to | |
3973 | global on all threads that call `func', or catch | |
3974 | writes on all recursive calls of `func' by a single | |
3975 | thread. We simply always evaluate the condition in | |
3976 | the innermost frame that's executing where it makes | |
3977 | sense to evaluate the condition. It seems | |
3978 | intuitive. */ | |
3979 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3980 | if (frame != NULL) | |
3981 | select_frame (frame); | |
3982 | else | |
3983 | within_current_scope = 0; | |
3984 | } | |
3985 | if (within_current_scope) | |
3986 | value_is_zero | |
3987 | = catch_errors (breakpoint_cond_eval, cond, | |
3988 | "Error in testing breakpoint condition:\n", | |
3989 | RETURN_MASK_ALL); | |
3990 | else | |
3991 | { | |
3992 | warning (_("Watchpoint condition cannot be tested " | |
3993 | "in the current scope")); | |
3994 | /* If we failed to set the right context for this | |
3995 | watchpoint, unconditionally report it. */ | |
3996 | value_is_zero = 0; | |
3997 | } | |
18a18393 | 3998 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3999 | value_free_to_mark (mark); |
18a18393 | 4000 | } |
60e1c644 PA |
4001 | |
4002 | if (cond && value_is_zero) | |
18a18393 VP |
4003 | { |
4004 | bs->stop = 0; | |
4005 | } | |
4006 | else if (b->thread != -1 && b->thread != thread_id) | |
4007 | { | |
4008 | bs->stop = 0; | |
4009 | } | |
4010 | else if (b->ignore_count > 0) | |
4011 | { | |
4012 | b->ignore_count--; | |
4013 | annotate_ignore_count_change (); | |
4014 | bs->stop = 0; | |
4015 | /* Increase the hit count even though we don't | |
4016 | stop. */ | |
4017 | ++(b->hit_count); | |
4018 | } | |
4019 | } | |
4020 | } | |
4021 | ||
4022 | ||
9709f61c | 4023 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4024 | BP_ADDR in thread PTID. |
c906108c | 4025 | |
d983da9c | 4026 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4027 | don't understand this stop. Result is a chain of bpstat's such that: |
4028 | ||
c5aa993b | 4029 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4030 | |
c5aa993b | 4031 | if we understand why we stopped, the result is not null. |
c906108c | 4032 | |
c5aa993b JM |
4033 | Each element of the chain refers to a particular breakpoint or |
4034 | watchpoint at which we have stopped. (We may have stopped for | |
4035 | several reasons concurrently.) | |
c906108c | 4036 | |
c5aa993b JM |
4037 | Each element of the chain has valid next, breakpoint_at, |
4038 | commands, FIXME??? fields. */ | |
c906108c SS |
4039 | |
4040 | bpstat | |
6c95b8df PA |
4041 | bpstat_stop_status (struct address_space *aspace, |
4042 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4043 | { |
0d381245 | 4044 | struct breakpoint *b = NULL; |
876fa593 | 4045 | struct bp_location *bl, **blp_tmp; |
20874c92 | 4046 | struct bp_location *loc; |
c906108c SS |
4047 | /* Root of the chain of bpstat's */ |
4048 | struct bpstats root_bs[1]; | |
4049 | /* Pointer to the last thing in the chain currently. */ | |
4050 | bpstat bs = root_bs; | |
20874c92 | 4051 | int ix; |
429374b8 | 4052 | int need_remove_insert; |
c906108c | 4053 | |
429374b8 JK |
4054 | /* ALL_BP_LOCATIONS iteration would break across |
4055 | update_global_location_list possibly executed by | |
4056 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4057 | |
429374b8 JK |
4058 | ALL_BREAKPOINTS (b) |
4059 | { | |
4060 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4061 | continue; | |
a5606eee | 4062 | |
429374b8 JK |
4063 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4064 | { | |
4065 | /* For hardware watchpoints, we look only at the first location. | |
4066 | The watchpoint_check function will work on entire expression, | |
4067 | not the individual locations. For read watchopints, the | |
4068 | watchpoints_triggered function have checked all locations | |
4069 | already. */ | |
4070 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4071 | break; | |
18a18393 | 4072 | |
429374b8 JK |
4073 | if (bl->shlib_disabled) |
4074 | continue; | |
c5aa993b | 4075 | |
429374b8 JK |
4076 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4077 | continue; | |
c5aa993b | 4078 | |
429374b8 | 4079 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4080 | |
429374b8 | 4081 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4082 | |
429374b8 JK |
4083 | /* Assume we stop. Should we find watchpoint that is not actually |
4084 | triggered, or if condition of breakpoint is false, we'll reset | |
4085 | 'stop' to 0. */ | |
4086 | bs->stop = 1; | |
4087 | bs->print = 1; | |
d983da9c | 4088 | |
429374b8 JK |
4089 | bpstat_check_watchpoint (bs); |
4090 | if (!bs->stop) | |
4091 | continue; | |
18a18393 | 4092 | |
429374b8 | 4093 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4094 | || b->type == bp_longjmp_master |
4095 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4096 | /* We do not stop for these. */ |
4097 | bs->stop = 0; | |
4098 | else | |
4099 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4100 | ||
4101 | if (bs->stop) | |
4102 | { | |
4103 | ++(b->hit_count); | |
c906108c | 4104 | |
429374b8 JK |
4105 | /* We will stop here */ |
4106 | if (b->disposition == disp_disable) | |
4107 | { | |
4108 | if (b->enable_state != bp_permanent) | |
4109 | b->enable_state = bp_disabled; | |
4110 | update_global_location_list (0); | |
4111 | } | |
4112 | if (b->silent) | |
4113 | bs->print = 0; | |
4114 | bs->commands = b->commands; | |
9add0f1b TT |
4115 | incref_counted_command_line (bs->commands); |
4116 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4117 | if (bs->commands_left | |
4118 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4119 | || (xdb_commands | |
4120 | && strcmp ("Q", | |
4121 | bs->commands_left->line) == 0))) | |
429374b8 | 4122 | { |
9add0f1b | 4123 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4124 | bs->print = 0; |
4125 | } | |
429374b8 JK |
4126 | } |
4127 | ||
4128 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4129 | if (bs->stop == 0 || bs->print == 0) | |
4130 | bs->print_it = print_it_noop; | |
4131 | } | |
4132 | } | |
876fa593 | 4133 | |
20874c92 VP |
4134 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4135 | { | |
6c95b8df PA |
4136 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4137 | aspace, bp_addr)) | |
20874c92 VP |
4138 | { |
4139 | bs = bpstat_alloc (loc, bs); | |
4140 | /* For hits of moribund locations, we should just proceed. */ | |
4141 | bs->stop = 0; | |
4142 | bs->print = 0; | |
4143 | bs->print_it = print_it_noop; | |
4144 | } | |
4145 | } | |
4146 | ||
c906108c | 4147 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4148 | |
d983da9c DJ |
4149 | /* If we aren't stopping, the value of some hardware watchpoint may |
4150 | not have changed, but the intermediate memory locations we are | |
4151 | watching may have. Don't bother if we're stopping; this will get | |
4152 | done later. */ | |
d832cb68 | 4153 | need_remove_insert = 0; |
1f7ccab2 | 4154 | if (! bpstat_causes_stop (root_bs->next)) |
d983da9c DJ |
4155 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
4156 | if (!bs->stop | |
20874c92 | 4157 | && bs->breakpoint_at->owner |
2d134ed3 | 4158 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4159 | { |
2d134ed3 PA |
4160 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4161 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4162 | Prevent further code from trying to use it. */ | |
a5606eee | 4163 | bs->breakpoint_at = NULL; |
d832cb68 | 4164 | need_remove_insert = 1; |
d983da9c DJ |
4165 | } |
4166 | ||
d832cb68 | 4167 | if (need_remove_insert) |
2d134ed3 | 4168 | update_global_location_list (1); |
d832cb68 | 4169 | |
d983da9c | 4170 | return root_bs->next; |
c906108c SS |
4171 | } |
4172 | \f | |
4173 | /* Tell what to do about this bpstat. */ | |
4174 | struct bpstat_what | |
fba45db2 | 4175 | bpstat_what (bpstat bs) |
c906108c SS |
4176 | { |
4177 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
4178 | enum class |
4179 | { | |
4180 | /* This bpstat element has no effect on the main_action. */ | |
4181 | no_effect = 0, | |
4182 | ||
4183 | /* There was a watchpoint, stop but don't print. */ | |
4184 | wp_silent, | |
c906108c | 4185 | |
c5aa993b JM |
4186 | /* There was a watchpoint, stop and print. */ |
4187 | wp_noisy, | |
c906108c | 4188 | |
c5aa993b JM |
4189 | /* There was a breakpoint but we're not stopping. */ |
4190 | bp_nostop, | |
c906108c | 4191 | |
c5aa993b JM |
4192 | /* There was a breakpoint, stop but don't print. */ |
4193 | bp_silent, | |
c906108c | 4194 | |
c5aa993b JM |
4195 | /* There was a breakpoint, stop and print. */ |
4196 | bp_noisy, | |
c906108c | 4197 | |
c5aa993b JM |
4198 | /* We hit the longjmp breakpoint. */ |
4199 | long_jump, | |
c906108c | 4200 | |
c5aa993b JM |
4201 | /* We hit the longjmp_resume breakpoint. */ |
4202 | long_resume, | |
c906108c | 4203 | |
c5aa993b JM |
4204 | /* We hit the step_resume breakpoint. */ |
4205 | step_resume, | |
c906108c | 4206 | |
c5aa993b JM |
4207 | /* We hit the shared library event breakpoint. */ |
4208 | shlib_event, | |
c906108c | 4209 | |
4efc6507 DE |
4210 | /* We hit the jit event breakpoint. */ |
4211 | jit_event, | |
4212 | ||
c5aa993b JM |
4213 | /* This is just used to count how many enums there are. */ |
4214 | class_last | |
c906108c SS |
4215 | }; |
4216 | ||
4217 | /* Here is the table which drives this routine. So that we can | |
4218 | format it pretty, we define some abbreviations for the | |
4219 | enum bpstat_what codes. */ | |
4220 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
4221 | #define ss BPSTAT_WHAT_STOP_SILENT | |
4222 | #define sn BPSTAT_WHAT_STOP_NOISY | |
4223 | #define sgl BPSTAT_WHAT_SINGLE | |
4224 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
4225 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 4226 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 4227 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 4228 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
4229 | |
4230 | /* "Can't happen." Might want to print an error message. | |
4231 | abort() is not out of the question, but chances are GDB is just | |
4232 | a bit confused, not unusable. */ | |
4233 | #define err BPSTAT_WHAT_STOP_NOISY | |
4234 | ||
4235 | /* Given an old action and a class, come up with a new action. */ | |
4236 | /* One interesting property of this table is that wp_silent is the same | |
4237 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
4238 | after stopping, the check for whether to step over a breakpoint | |
4239 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
4240 | reference to how we stopped. We retain separate wp_silent and |
4241 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
4242 | |
4243 | Another possibly interesting property of this table is that | |
4244 | there's a partial ordering, priority-like, of the actions. Once | |
4245 | you've decided that some action is appropriate, you'll never go | |
4246 | back and decide something of a lower priority is better. The | |
4247 | ordering is: | |
4248 | ||
4efc6507 DE |
4249 | kc < jit clr sgl shl slr sn sr ss |
4250 | sgl < jit shl slr sn sr ss | |
4251 | slr < jit err shl sn sr ss | |
4252 | clr < jit err shl sn sr ss | |
4253 | ss < jit shl sn sr | |
4254 | sn < jit shl sr | |
4255 | jit < shl sr | |
d81191fc | 4256 | shl < sr |
4d5b2cd7 | 4257 | sr < |
c5aa993b | 4258 | |
43ff13b4 JM |
4259 | What I think this means is that we don't need a damned table |
4260 | here. If you just put the rows and columns in the right order, | |
4261 | it'd look awfully regular. We could simply walk the bpstat list | |
4262 | and choose the highest priority action we find, with a little | |
78b6a731 | 4263 | logic to handle the 'err' cases. */ |
c906108c SS |
4264 | |
4265 | /* step_resume entries: a step resume breakpoint overrides another | |
4266 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 4267 | at where we set the step_resume breakpoint). */ |
c906108c SS |
4268 | |
4269 | static const enum bpstat_what_main_action | |
c5aa993b JM |
4270 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
4271 | { | |
4272 | /* old action */ | |
4efc6507 DE |
4273 | /* kc ss sn sgl slr clr sr shl jit */ |
4274 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
4275 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4276 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4277 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
4278 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
4279 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
4280 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
4281 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
4282 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
4283 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
4284 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 4285 | }; |
c906108c SS |
4286 | |
4287 | #undef kc | |
4288 | #undef ss | |
4289 | #undef sn | |
4290 | #undef sgl | |
4291 | #undef slr | |
4292 | #undef clr | |
c906108c SS |
4293 | #undef err |
4294 | #undef sr | |
4295 | #undef ts | |
4296 | #undef shl | |
4efc6507 | 4297 | #undef jit |
c906108c SS |
4298 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
4299 | struct bpstat_what retval; | |
4300 | ||
aa7d318d | 4301 | retval.call_dummy = STOP_NONE; |
c906108c SS |
4302 | for (; bs != NULL; bs = bs->next) |
4303 | { | |
4304 | enum class bs_class = no_effect; | |
4305 | if (bs->breakpoint_at == NULL) | |
4306 | /* I suspect this can happen if it was a momentary breakpoint | |
4307 | which has since been deleted. */ | |
4308 | continue; | |
20874c92 VP |
4309 | if (bs->breakpoint_at->owner == NULL) |
4310 | bs_class = bp_nostop; | |
4311 | else | |
4f8d1dc6 | 4312 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
4313 | { |
4314 | case bp_none: | |
4315 | continue; | |
4316 | ||
4317 | case bp_breakpoint: | |
4318 | case bp_hardware_breakpoint: | |
4319 | case bp_until: | |
4320 | case bp_finish: | |
4321 | if (bs->stop) | |
4322 | { | |
4323 | if (bs->print) | |
4324 | bs_class = bp_noisy; | |
4325 | else | |
4326 | bs_class = bp_silent; | |
4327 | } | |
4328 | else | |
4329 | bs_class = bp_nostop; | |
4330 | break; | |
4331 | case bp_watchpoint: | |
4332 | case bp_hardware_watchpoint: | |
4333 | case bp_read_watchpoint: | |
4334 | case bp_access_watchpoint: | |
4335 | if (bs->stop) | |
4336 | { | |
4337 | if (bs->print) | |
4338 | bs_class = wp_noisy; | |
4339 | else | |
4340 | bs_class = wp_silent; | |
4341 | } | |
4342 | else | |
53a5351d JM |
4343 | /* There was a watchpoint, but we're not stopping. |
4344 | This requires no further action. */ | |
c906108c SS |
4345 | bs_class = no_effect; |
4346 | break; | |
4347 | case bp_longjmp: | |
4348 | bs_class = long_jump; | |
4349 | break; | |
4350 | case bp_longjmp_resume: | |
4351 | bs_class = long_resume; | |
4352 | break; | |
4353 | case bp_step_resume: | |
4354 | if (bs->stop) | |
4355 | { | |
4356 | bs_class = step_resume; | |
4357 | } | |
4358 | else | |
4359 | /* It is for the wrong frame. */ | |
4360 | bs_class = bp_nostop; | |
4361 | break; | |
c906108c SS |
4362 | case bp_watchpoint_scope: |
4363 | bs_class = bp_nostop; | |
4364 | break; | |
c5aa993b JM |
4365 | case bp_shlib_event: |
4366 | bs_class = shlib_event; | |
4367 | break; | |
4efc6507 DE |
4368 | case bp_jit_event: |
4369 | bs_class = jit_event; | |
4370 | break; | |
c4093a6a | 4371 | case bp_thread_event: |
1900040c | 4372 | case bp_overlay_event: |
0fd8e87f | 4373 | case bp_longjmp_master: |
aa7d318d | 4374 | case bp_std_terminate_master: |
c4093a6a JM |
4375 | bs_class = bp_nostop; |
4376 | break; | |
ce78b96d | 4377 | case bp_catchpoint: |
c5aa993b JM |
4378 | if (bs->stop) |
4379 | { | |
4380 | if (bs->print) | |
4381 | bs_class = bp_noisy; | |
4382 | else | |
4383 | bs_class = bp_silent; | |
4384 | } | |
4385 | else | |
53a5351d JM |
4386 | /* There was a catchpoint, but we're not stopping. |
4387 | This requires no further action. */ | |
c5aa993b JM |
4388 | bs_class = no_effect; |
4389 | break; | |
c906108c | 4390 | case bp_call_dummy: |
53a5351d JM |
4391 | /* Make sure the action is stop (silent or noisy), |
4392 | so infrun.c pops the dummy frame. */ | |
c906108c | 4393 | bs_class = bp_silent; |
aa7d318d TT |
4394 | retval.call_dummy = STOP_STACK_DUMMY; |
4395 | break; | |
4396 | case bp_std_terminate: | |
4397 | /* Make sure the action is stop (silent or noisy), | |
4398 | so infrun.c pops the dummy frame. */ | |
4399 | bs_class = bp_silent; | |
4400 | retval.call_dummy = STOP_STD_TERMINATE; | |
c906108c | 4401 | break; |
1042e4c0 | 4402 | case bp_tracepoint: |
7a697b8d | 4403 | case bp_fast_tracepoint: |
1042e4c0 SS |
4404 | /* Tracepoint hits should not be reported back to GDB, and |
4405 | if one got through somehow, it should have been filtered | |
4406 | out already. */ | |
4407 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4408 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4409 | break; |
c906108c | 4410 | } |
c5aa993b | 4411 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4412 | } |
4413 | retval.main_action = current_action; | |
4414 | return retval; | |
4415 | } | |
4416 | ||
4417 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4418 | without hardware support). This isn't related to a specific bpstat, | |
4419 | just to things like whether watchpoints are set. */ | |
4420 | ||
c5aa993b | 4421 | int |
fba45db2 | 4422 | bpstat_should_step (void) |
c906108c SS |
4423 | { |
4424 | struct breakpoint *b; | |
4425 | ALL_BREAKPOINTS (b) | |
717a8278 | 4426 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4427 | return 1; |
c906108c SS |
4428 | return 0; |
4429 | } | |
4430 | ||
67822962 PA |
4431 | int |
4432 | bpstat_causes_stop (bpstat bs) | |
4433 | { | |
4434 | for (; bs != NULL; bs = bs->next) | |
4435 | if (bs->stop) | |
4436 | return 1; | |
4437 | ||
4438 | return 0; | |
4439 | } | |
4440 | ||
c906108c | 4441 | \f |
c5aa993b | 4442 | |
859825b8 JK |
4443 | /* Print the LOC location out of the list of B->LOC locations. */ |
4444 | ||
0d381245 VP |
4445 | static void print_breakpoint_location (struct breakpoint *b, |
4446 | struct bp_location *loc, | |
4447 | char *wrap_indent, | |
4448 | struct ui_stream *stb) | |
4449 | { | |
6c95b8df PA |
4450 | struct cleanup *old_chain = save_current_program_space (); |
4451 | ||
859825b8 JK |
4452 | if (loc != NULL && loc->shlib_disabled) |
4453 | loc = NULL; | |
4454 | ||
6c95b8df PA |
4455 | if (loc != NULL) |
4456 | set_current_program_space (loc->pspace); | |
4457 | ||
859825b8 | 4458 | if (b->source_file && loc) |
0d381245 VP |
4459 | { |
4460 | struct symbol *sym | |
4461 | = find_pc_sect_function (loc->address, loc->section); | |
4462 | if (sym) | |
4463 | { | |
4464 | ui_out_text (uiout, "in "); | |
4465 | ui_out_field_string (uiout, "func", | |
4466 | SYMBOL_PRINT_NAME (sym)); | |
4467 | ui_out_wrap_hint (uiout, wrap_indent); | |
4468 | ui_out_text (uiout, " at "); | |
4469 | } | |
4470 | ui_out_field_string (uiout, "file", b->source_file); | |
4471 | ui_out_text (uiout, ":"); | |
4472 | ||
4473 | if (ui_out_is_mi_like_p (uiout)) | |
4474 | { | |
4475 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4476 | char *fullname = symtab_to_fullname (sal.symtab); | |
4477 | ||
4478 | if (fullname) | |
4479 | ui_out_field_string (uiout, "fullname", fullname); | |
4480 | } | |
4481 | ||
4482 | ui_out_field_int (uiout, "line", b->line_number); | |
4483 | } | |
859825b8 | 4484 | else if (loc) |
0d381245 | 4485 | { |
22e722e1 DJ |
4486 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4487 | demangle, ""); | |
0d381245 VP |
4488 | ui_out_field_stream (uiout, "at", stb); |
4489 | } | |
859825b8 JK |
4490 | else |
4491 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4492 | |
4493 | do_cleanups (old_chain); | |
0d381245 VP |
4494 | } |
4495 | ||
c4093a6a | 4496 | /* Print B to gdb_stdout. */ |
c906108c | 4497 | static void |
0d381245 VP |
4498 | print_one_breakpoint_location (struct breakpoint *b, |
4499 | struct bp_location *loc, | |
4500 | int loc_number, | |
a6d9a66e | 4501 | struct bp_location **last_loc, |
6c95b8df PA |
4502 | int print_address_bits, |
4503 | int allflag) | |
c906108c | 4504 | { |
52f0bd74 AC |
4505 | struct command_line *l; |
4506 | struct symbol *sym; | |
c4093a6a JM |
4507 | struct ep_type_description |
4508 | { | |
4509 | enum bptype type; | |
4510 | char *description; | |
4511 | }; | |
4512 | static struct ep_type_description bptypes[] = | |
c906108c | 4513 | { |
c5aa993b JM |
4514 | {bp_none, "?deleted?"}, |
4515 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4516 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4517 | {bp_until, "until"}, |
4518 | {bp_finish, "finish"}, | |
4519 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4520 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4521 | {bp_read_watchpoint, "read watchpoint"}, |
4522 | {bp_access_watchpoint, "acc watchpoint"}, | |
4523 | {bp_longjmp, "longjmp"}, | |
4524 | {bp_longjmp_resume, "longjmp resume"}, | |
4525 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4526 | {bp_watchpoint_scope, "watchpoint scope"}, |
4527 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4528 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4529 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4530 | {bp_thread_event, "thread events"}, |
1900040c | 4531 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4532 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4533 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4534 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4535 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4536 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4537 | {bp_jit_event, "jit events"}, |
c5aa993b | 4538 | }; |
c4093a6a | 4539 | |
c2c6d25f | 4540 | static char bpenables[] = "nynny"; |
c906108c | 4541 | char wrap_indent[80]; |
8b93c638 JM |
4542 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4543 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4544 | struct cleanup *bkpt_chain; |
c906108c | 4545 | |
0d381245 VP |
4546 | int header_of_multiple = 0; |
4547 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4548 | struct value_print_options opts; |
4549 | ||
4550 | get_user_print_options (&opts); | |
0d381245 VP |
4551 | |
4552 | gdb_assert (!loc || loc_number != 0); | |
4553 | /* See comment in print_one_breakpoint concerning | |
4554 | treatment of breakpoints with single disabled | |
4555 | location. */ | |
4556 | if (loc == NULL | |
4557 | && (b->loc != NULL | |
4558 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4559 | header_of_multiple = 1; | |
4560 | if (loc == NULL) | |
4561 | loc = b->loc; | |
4562 | ||
c4093a6a | 4563 | annotate_record (); |
3b31d625 | 4564 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4565 | |
4566 | /* 1 */ | |
4567 | annotate_field (0); | |
0d381245 VP |
4568 | if (part_of_multiple) |
4569 | { | |
4570 | char *formatted; | |
0c6773c1 | 4571 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4572 | ui_out_field_string (uiout, "number", formatted); |
4573 | xfree (formatted); | |
4574 | } | |
4575 | else | |
4576 | { | |
4577 | ui_out_field_int (uiout, "number", b->number); | |
4578 | } | |
c4093a6a JM |
4579 | |
4580 | /* 2 */ | |
4581 | annotate_field (1); | |
0d381245 VP |
4582 | if (part_of_multiple) |
4583 | ui_out_field_skip (uiout, "type"); | |
4584 | else | |
4585 | { | |
4586 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4587 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4588 | internal_error (__FILE__, __LINE__, | |
4589 | _("bptypes table does not describe type #%d."), | |
4590 | (int) b->type); | |
4591 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4592 | } | |
c4093a6a JM |
4593 | |
4594 | /* 3 */ | |
4595 | annotate_field (2); | |
0d381245 VP |
4596 | if (part_of_multiple) |
4597 | ui_out_field_skip (uiout, "disp"); | |
4598 | else | |
2cec12e5 | 4599 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4600 | |
c4093a6a JM |
4601 | |
4602 | /* 4 */ | |
4603 | annotate_field (3); | |
0d381245 | 4604 | if (part_of_multiple) |
54e52265 | 4605 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4606 | else |
54e52265 VP |
4607 | ui_out_field_fmt (uiout, "enabled", "%c", |
4608 | bpenables[(int) b->enable_state]); | |
4609 | ui_out_spaces (uiout, 2); | |
0d381245 | 4610 | |
c4093a6a JM |
4611 | |
4612 | /* 5 and 6 */ | |
4613 | strcpy (wrap_indent, " "); | |
79a45b7d | 4614 | if (opts.addressprint) |
75ac9d7b | 4615 | { |
a6d9a66e | 4616 | if (print_address_bits <= 32) |
75ac9d7b MS |
4617 | strcat (wrap_indent, " "); |
4618 | else | |
4619 | strcat (wrap_indent, " "); | |
4620 | } | |
c906108c | 4621 | |
3086aeae | 4622 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4623 | { |
4624 | /* Although the print_one can possibly print | |
4625 | all locations, calling it here is not likely | |
4626 | to get any nice result. So, make sure there's | |
4627 | just one location. */ | |
4628 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4629 | b->ops->print_one (b, last_loc); |
0d381245 | 4630 | } |
3086aeae DJ |
4631 | else |
4632 | switch (b->type) | |
4633 | { | |
4634 | case bp_none: | |
4635 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4636 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4637 | break; |
c906108c | 4638 | |
3086aeae DJ |
4639 | case bp_watchpoint: |
4640 | case bp_hardware_watchpoint: | |
4641 | case bp_read_watchpoint: | |
4642 | case bp_access_watchpoint: | |
4643 | /* Field 4, the address, is omitted (which makes the columns | |
4644 | not line up too nicely with the headers, but the effect | |
4645 | is relatively readable). */ | |
79a45b7d | 4646 | if (opts.addressprint) |
3086aeae DJ |
4647 | ui_out_field_skip (uiout, "addr"); |
4648 | annotate_field (5); | |
fa8a61dc | 4649 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4650 | break; |
4651 | ||
3086aeae DJ |
4652 | case bp_breakpoint: |
4653 | case bp_hardware_breakpoint: | |
4654 | case bp_until: | |
4655 | case bp_finish: | |
4656 | case bp_longjmp: | |
4657 | case bp_longjmp_resume: | |
4658 | case bp_step_resume: | |
3086aeae DJ |
4659 | case bp_watchpoint_scope: |
4660 | case bp_call_dummy: | |
aa7d318d | 4661 | case bp_std_terminate: |
3086aeae DJ |
4662 | case bp_shlib_event: |
4663 | case bp_thread_event: | |
4664 | case bp_overlay_event: | |
0fd8e87f | 4665 | case bp_longjmp_master: |
aa7d318d | 4666 | case bp_std_terminate_master: |
1042e4c0 | 4667 | case bp_tracepoint: |
7a697b8d | 4668 | case bp_fast_tracepoint: |
4efc6507 | 4669 | case bp_jit_event: |
79a45b7d | 4670 | if (opts.addressprint) |
3086aeae DJ |
4671 | { |
4672 | annotate_field (4); | |
54e52265 | 4673 | if (header_of_multiple) |
0d381245 | 4674 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4675 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4676 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4677 | else |
5af949e3 UW |
4678 | ui_out_field_core_addr (uiout, "addr", |
4679 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4680 | } |
4681 | annotate_field (5); | |
0d381245 VP |
4682 | if (!header_of_multiple) |
4683 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4684 | if (b->loc) | |
a6d9a66e | 4685 | *last_loc = b->loc; |
3086aeae DJ |
4686 | break; |
4687 | } | |
c906108c | 4688 | |
6c95b8df PA |
4689 | |
4690 | /* For backward compatibility, don't display inferiors unless there | |
4691 | are several. */ | |
4692 | if (loc != NULL | |
4693 | && !header_of_multiple | |
4694 | && (allflag | |
4695 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4696 | && (number_of_program_spaces () > 1 | |
4697 | || number_of_inferiors () > 1) | |
4698 | && loc->owner->type != bp_catchpoint))) | |
4699 | { | |
4700 | struct inferior *inf; | |
4701 | int first = 1; | |
4702 | ||
4703 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4704 | { | |
4705 | if (inf->pspace == loc->pspace) | |
4706 | { | |
4707 | if (first) | |
4708 | { | |
4709 | first = 0; | |
4710 | ui_out_text (uiout, " inf "); | |
4711 | } | |
4712 | else | |
4713 | ui_out_text (uiout, ", "); | |
4714 | ui_out_text (uiout, plongest (inf->num)); | |
4715 | } | |
4716 | } | |
4717 | } | |
4718 | ||
4a306c9a | 4719 | if (!part_of_multiple) |
c4093a6a | 4720 | { |
4a306c9a JB |
4721 | if (b->thread != -1) |
4722 | { | |
4723 | /* FIXME: This seems to be redundant and lost here; see the | |
4724 | "stop only in" line a little further down. */ | |
4725 | ui_out_text (uiout, " thread "); | |
4726 | ui_out_field_int (uiout, "thread", b->thread); | |
4727 | } | |
4728 | else if (b->task != 0) | |
4729 | { | |
4730 | ui_out_text (uiout, " task "); | |
4731 | ui_out_field_int (uiout, "task", b->task); | |
4732 | } | |
c4093a6a JM |
4733 | } |
4734 | ||
8b93c638 | 4735 | ui_out_text (uiout, "\n"); |
c4093a6a | 4736 | |
0d381245 | 4737 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4738 | { |
4739 | annotate_field (6); | |
8b93c638 | 4740 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4741 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4742 | the frame ID. */ | |
5af949e3 UW |
4743 | ui_out_field_core_addr (uiout, "frame", |
4744 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4745 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4746 | } |
4747 | ||
0d381245 | 4748 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4749 | { |
f7f9143b JB |
4750 | /* We do not print the condition for Ada exception catchpoints |
4751 | because the condition is an internal implementation detail | |
4752 | that we do not want to expose to the user. */ | |
c4093a6a | 4753 | annotate_field (7); |
d77f58be | 4754 | if (is_tracepoint (b)) |
1042e4c0 SS |
4755 | ui_out_text (uiout, "\ttrace only if "); |
4756 | else | |
4757 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4758 | ui_out_field_string (uiout, "cond", b->cond_string); |
4759 | ui_out_text (uiout, "\n"); | |
4760 | } | |
4761 | ||
0d381245 | 4762 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4763 | { |
4764 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4765 | ui_out_text (uiout, "\tstop only in thread "); |
4766 | ui_out_field_int (uiout, "thread", b->thread); | |
4767 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4768 | } |
4769 | ||
63c715c6 | 4770 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4771 | { |
4772 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4773 | if (ep_is_catchpoint (b)) |
4774 | ui_out_text (uiout, "\tcatchpoint"); | |
4775 | else | |
4776 | ui_out_text (uiout, "\tbreakpoint"); | |
4777 | ui_out_text (uiout, " already hit "); | |
4778 | ui_out_field_int (uiout, "times", b->hit_count); | |
4779 | if (b->hit_count == 1) | |
4780 | ui_out_text (uiout, " time\n"); | |
4781 | else | |
4782 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4783 | } |
4784 | ||
fb40c209 AC |
4785 | /* Output the count also if it is zero, but only if this is |
4786 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4787 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4788 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4789 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4790 | |
0d381245 | 4791 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4792 | { |
4793 | annotate_field (8); | |
8b93c638 JM |
4794 | ui_out_text (uiout, "\tignore next "); |
4795 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4796 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4797 | } |
059fb39f | 4798 | |
9add0f1b | 4799 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4800 | if (!part_of_multiple && l) |
c4093a6a | 4801 | { |
3b31d625 EZ |
4802 | struct cleanup *script_chain; |
4803 | ||
c4093a6a | 4804 | annotate_field (9); |
3b31d625 | 4805 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4806 | print_command_lines (uiout, l, 4); |
3b31d625 | 4807 | do_cleanups (script_chain); |
c4093a6a | 4808 | } |
d24317b4 | 4809 | |
1042e4c0 SS |
4810 | if (!part_of_multiple && b->pass_count) |
4811 | { | |
4812 | annotate_field (10); | |
4813 | ui_out_text (uiout, "\tpass count "); | |
4814 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4815 | ui_out_text (uiout, " \n"); | |
4816 | } | |
4817 | ||
d24317b4 VP |
4818 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4819 | { | |
4820 | if (b->addr_string) | |
4821 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4822 | else if (b->exp_string) | |
4823 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4824 | } | |
4825 | ||
3b31d625 | 4826 | do_cleanups (bkpt_chain); |
8b93c638 | 4827 | do_cleanups (old_chain); |
c4093a6a | 4828 | } |
c5aa993b | 4829 | |
0d381245 VP |
4830 | static void |
4831 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4832 | struct bp_location **last_loc, int print_address_bits, |
4833 | int allflag) | |
0d381245 | 4834 | { |
6c95b8df PA |
4835 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4836 | print_address_bits, allflag); | |
0d381245 VP |
4837 | |
4838 | /* If this breakpoint has custom print function, | |
4839 | it's already printed. Otherwise, print individual | |
4840 | locations, if any. */ | |
4841 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4842 | { | |
4843 | /* If breakpoint has a single location that is | |
4844 | disabled, we print it as if it had | |
4845 | several locations, since otherwise it's hard to | |
4846 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4847 | situation. |
4848 | Note that while hardware watchpoints have | |
4849 | several locations internally, that's no a property | |
4850 | exposed to user. */ | |
0d381245 | 4851 | if (b->loc |
a5606eee | 4852 | && !is_hardware_watchpoint (b) |
0d381245 | 4853 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4854 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4855 | { |
4856 | struct bp_location *loc; | |
4857 | int n = 1; | |
4858 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4859 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4860 | print_address_bits, allflag); |
0d381245 VP |
4861 | } |
4862 | } | |
4863 | } | |
4864 | ||
a6d9a66e UW |
4865 | static int |
4866 | breakpoint_address_bits (struct breakpoint *b) | |
4867 | { | |
4868 | int print_address_bits = 0; | |
4869 | struct bp_location *loc; | |
4870 | ||
4871 | for (loc = b->loc; loc; loc = loc->next) | |
4872 | { | |
c7437ca6 PA |
4873 | int addr_bit; |
4874 | ||
4875 | /* Software watchpoints that aren't watching memory don't have | |
4876 | an address to print. */ | |
4877 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4878 | continue; | |
4879 | ||
4880 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4881 | if (addr_bit > print_address_bits) |
4882 | print_address_bits = addr_bit; | |
4883 | } | |
4884 | ||
4885 | return print_address_bits; | |
4886 | } | |
0d381245 | 4887 | |
c4093a6a JM |
4888 | struct captured_breakpoint_query_args |
4889 | { | |
4890 | int bnum; | |
4891 | }; | |
c5aa993b | 4892 | |
c4093a6a | 4893 | static int |
2b65245e | 4894 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4895 | { |
4896 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4897 | struct breakpoint *b; |
a6d9a66e | 4898 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4899 | ALL_BREAKPOINTS (b) |
4900 | { | |
4901 | if (args->bnum == b->number) | |
c5aa993b | 4902 | { |
a6d9a66e | 4903 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4904 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4905 | return GDB_RC_OK; |
c5aa993b | 4906 | } |
c4093a6a JM |
4907 | } |
4908 | return GDB_RC_NONE; | |
4909 | } | |
c5aa993b | 4910 | |
c4093a6a | 4911 | enum gdb_rc |
ce43223b | 4912 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4913 | { |
4914 | struct captured_breakpoint_query_args args; | |
4915 | args.bnum = bnum; | |
4916 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4917 | an error. */ | |
b0b13bb4 DJ |
4918 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4919 | error_message, RETURN_MASK_ALL) < 0) | |
4920 | return GDB_RC_FAIL; | |
4921 | else | |
4922 | return GDB_RC_OK; | |
c4093a6a | 4923 | } |
c5aa993b | 4924 | |
7f3b0473 AC |
4925 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4926 | catchpoints, et.al.). */ | |
4927 | ||
4928 | static int | |
4929 | user_settable_breakpoint (const struct breakpoint *b) | |
4930 | { | |
4931 | return (b->type == bp_breakpoint | |
ce78b96d | 4932 | || b->type == bp_catchpoint |
7f3b0473 | 4933 | || b->type == bp_hardware_breakpoint |
d77f58be | 4934 | || is_tracepoint (b) |
7f3b0473 AC |
4935 | || b->type == bp_watchpoint |
4936 | || b->type == bp_read_watchpoint | |
4937 | || b->type == bp_access_watchpoint | |
4938 | || b->type == bp_hardware_watchpoint); | |
4939 | } | |
4940 | ||
4941 | /* Print information on user settable breakpoint (watchpoint, etc) | |
d77f58be SS |
4942 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
4943 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
4944 | FILTER is non-NULL, call it on each breakpoint and only include the | |
4945 | ones for which it returns non-zero. Return the total number of | |
4946 | breakpoints listed. */ | |
c906108c | 4947 | |
d77f58be SS |
4948 | static int |
4949 | breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) | |
c4093a6a | 4950 | { |
52f0bd74 | 4951 | struct breakpoint *b; |
a6d9a66e | 4952 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4953 | int nr_printable_breakpoints; |
3b31d625 | 4954 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4955 | struct value_print_options opts; |
a6d9a66e | 4956 | int print_address_bits = 0; |
c4093a6a | 4957 | |
79a45b7d TT |
4958 | get_user_print_options (&opts); |
4959 | ||
a6d9a66e UW |
4960 | /* Compute the number of rows in the table, as well as the |
4961 | size required for address fields. */ | |
7f3b0473 AC |
4962 | nr_printable_breakpoints = 0; |
4963 | ALL_BREAKPOINTS (b) | |
4964 | if (bnum == -1 | |
4965 | || bnum == b->number) | |
4966 | { | |
d77f58be SS |
4967 | /* If we have a filter, only list the breakpoints it accepts. */ |
4968 | if (filter && !filter (b)) | |
4969 | continue; | |
4970 | ||
7f3b0473 | 4971 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e UW |
4972 | { |
4973 | int addr_bit = breakpoint_address_bits (b); | |
4974 | if (addr_bit > print_address_bits) | |
4975 | print_address_bits = addr_bit; | |
4976 | ||
4977 | nr_printable_breakpoints++; | |
4978 | } | |
7f3b0473 AC |
4979 | } |
4980 | ||
79a45b7d | 4981 | if (opts.addressprint) |
3b31d625 EZ |
4982 | bkpttbl_chain |
4983 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4984 | "BreakpointTable"); | |
8b93c638 | 4985 | else |
3b31d625 EZ |
4986 | bkpttbl_chain |
4987 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4988 | "BreakpointTable"); | |
8b93c638 | 4989 | |
7f3b0473 | 4990 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4991 | annotate_breakpoints_headers (); |
4992 | if (nr_printable_breakpoints > 0) | |
4993 | annotate_field (0); | |
0d381245 | 4994 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4995 | if (nr_printable_breakpoints > 0) |
4996 | annotate_field (1); | |
4997 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4998 | if (nr_printable_breakpoints > 0) | |
4999 | annotate_field (2); | |
5000 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
5001 | if (nr_printable_breakpoints > 0) | |
5002 | annotate_field (3); | |
54e52265 | 5003 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5004 | if (opts.addressprint) |
7f3b0473 | 5005 | { |
d7faa9e7 AC |
5006 | if (nr_printable_breakpoints > 0) |
5007 | annotate_field (4); | |
a6d9a66e | 5008 | if (print_address_bits <= 32) |
b25959ec | 5009 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 5010 | else |
b25959ec | 5011 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 5012 | } |
d7faa9e7 AC |
5013 | if (nr_printable_breakpoints > 0) |
5014 | annotate_field (5); | |
5015 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5016 | ui_out_table_body (uiout); | |
5017 | if (nr_printable_breakpoints > 0) | |
5018 | annotate_breakpoints_table (); | |
7f3b0473 | 5019 | |
c4093a6a | 5020 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5021 | { |
5022 | QUIT; | |
c4093a6a JM |
5023 | if (bnum == -1 |
5024 | || bnum == b->number) | |
5025 | { | |
d77f58be SS |
5026 | /* If we have a filter, only list the breakpoints it accepts. */ |
5027 | if (filter && !filter (b)) | |
5028 | continue; | |
5029 | ||
c4093a6a JM |
5030 | /* We only print out user settable breakpoints unless the |
5031 | allflag is set. */ | |
7f3b0473 | 5032 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5033 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5034 | } |
bad56014 | 5035 | } |
c4093a6a | 5036 | |
3b31d625 | 5037 | do_cleanups (bkpttbl_chain); |
698384cd | 5038 | |
7f3b0473 | 5039 | if (nr_printable_breakpoints == 0) |
c906108c | 5040 | { |
d77f58be SS |
5041 | /* If there's a filter, let the caller decide how to report empty list. */ |
5042 | if (!filter) | |
5043 | { | |
5044 | if (bnum == -1) | |
5045 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5046 | else | |
5047 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5048 | bnum); | |
5049 | } | |
c906108c SS |
5050 | } |
5051 | else | |
c4093a6a | 5052 | { |
a6d9a66e UW |
5053 | if (last_loc && !server_command) |
5054 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5055 | } |
c906108c | 5056 | |
c4093a6a JM |
5057 | /* FIXME? Should this be moved up so that it is only called when |
5058 | there have been breakpoints? */ | |
c906108c | 5059 | annotate_breakpoints_table_end (); |
d77f58be SS |
5060 | |
5061 | return nr_printable_breakpoints; | |
c906108c SS |
5062 | } |
5063 | ||
ad443146 SS |
5064 | /* Display the value of default-collect in a way that is generally |
5065 | compatible with the breakpoint list. */ | |
5066 | ||
5067 | static void | |
5068 | default_collect_info (void) | |
5069 | { | |
5070 | /* If it has no value (which is frequently the case), say nothing; a | |
5071 | message like "No default-collect." gets in user's face when it's | |
5072 | not wanted. */ | |
5073 | if (!*default_collect) | |
5074 | return; | |
5075 | ||
5076 | /* The following phrase lines up nicely with per-tracepoint collect | |
5077 | actions. */ | |
5078 | ui_out_text (uiout, "default collect "); | |
5079 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5080 | ui_out_text (uiout, " \n"); | |
5081 | } | |
5082 | ||
c906108c | 5083 | static void |
fba45db2 | 5084 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5085 | { |
5086 | int bnum = -1; | |
5087 | ||
5088 | if (bnum_exp) | |
bb518678 | 5089 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5090 | |
d77f58be | 5091 | breakpoint_1 (bnum, 0, NULL); |
ad443146 SS |
5092 | |
5093 | default_collect_info (); | |
d77f58be SS |
5094 | } |
5095 | ||
5096 | static void | |
5097 | watchpoints_info (char *wpnum_exp, int from_tty) | |
5098 | { | |
5099 | int wpnum = -1, num_printed; | |
5100 | ||
5101 | if (wpnum_exp) | |
5102 | wpnum = parse_and_eval_long (wpnum_exp); | |
5103 | ||
5104 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); | |
5105 | ||
5106 | if (num_printed == 0) | |
5107 | { | |
5108 | if (wpnum == -1) | |
5109 | ui_out_message (uiout, 0, "No watchpoints.\n"); | |
5110 | else | |
5111 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); | |
5112 | } | |
c906108c SS |
5113 | } |
5114 | ||
7a292a7a | 5115 | static void |
fba45db2 | 5116 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5117 | { |
5118 | int bnum = -1; | |
5119 | ||
5120 | if (bnum_exp) | |
bb518678 | 5121 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5122 | |
d77f58be | 5123 | breakpoint_1 (bnum, 1, NULL); |
ad443146 SS |
5124 | |
5125 | default_collect_info (); | |
c906108c SS |
5126 | } |
5127 | ||
0d381245 | 5128 | static int |
714835d5 | 5129 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5130 | struct program_space *pspace, |
714835d5 | 5131 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5132 | { |
5133 | struct bp_location *bl = b->loc; | |
5134 | for (; bl; bl = bl->next) | |
5135 | { | |
6c95b8df PA |
5136 | if (bl->pspace == pspace |
5137 | && bl->address == pc | |
0d381245 VP |
5138 | && (!overlay_debugging || bl->section == section)) |
5139 | return 1; | |
5140 | } | |
5141 | return 0; | |
5142 | } | |
5143 | ||
6c95b8df PA |
5144 | /* Print a message describing any breakpoints set at PC. This |
5145 | concerns with logical breakpoints, so we match program spaces, not | |
5146 | address spaces. */ | |
c906108c SS |
5147 | |
5148 | static void | |
6c95b8df PA |
5149 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5150 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5151 | struct obj_section *section, int thread) |
c906108c | 5152 | { |
52f0bd74 AC |
5153 | int others = 0; |
5154 | struct breakpoint *b; | |
c906108c SS |
5155 | |
5156 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5157 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5158 | if (others > 0) |
5159 | { | |
a3f17187 AC |
5160 | if (others == 1) |
5161 | printf_filtered (_("Note: breakpoint ")); | |
5162 | else /* if (others == ???) */ | |
5163 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5164 | ALL_BREAKPOINTS (b) |
6c95b8df | 5165 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5166 | { |
5167 | others--; | |
5168 | printf_filtered ("%d", b->number); | |
5169 | if (b->thread == -1 && thread != -1) | |
5170 | printf_filtered (" (all threads)"); | |
5171 | else if (b->thread != -1) | |
5172 | printf_filtered (" (thread %d)", b->thread); | |
5173 | printf_filtered ("%s%s ", | |
059fb39f | 5174 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5175 | || b->enable_state == bp_call_disabled |
5176 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5177 | ? " (disabled)" |
5178 | : b->enable_state == bp_permanent | |
5179 | ? " (permanent)" | |
5180 | : ""), | |
5181 | (others > 1) ? "," | |
5182 | : ((others == 1) ? " and" : "")); | |
5183 | } | |
a3f17187 | 5184 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5185 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5186 | printf_filtered (".\n"); |
5187 | } | |
5188 | } | |
5189 | \f | |
5190 | /* Set the default place to put a breakpoint | |
5191 | for the `break' command with no arguments. */ | |
5192 | ||
5193 | void | |
6c95b8df PA |
5194 | set_default_breakpoint (int valid, struct program_space *pspace, |
5195 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5196 | int line) |
c906108c SS |
5197 | { |
5198 | default_breakpoint_valid = valid; | |
6c95b8df | 5199 | default_breakpoint_pspace = pspace; |
c906108c SS |
5200 | default_breakpoint_address = addr; |
5201 | default_breakpoint_symtab = symtab; | |
5202 | default_breakpoint_line = line; | |
5203 | } | |
5204 | ||
e4f237da KB |
5205 | /* Return true iff it is meaningful to use the address member of |
5206 | BPT. For some breakpoint types, the address member is irrelevant | |
5207 | and it makes no sense to attempt to compare it to other addresses | |
5208 | (or use it for any other purpose either). | |
5209 | ||
5210 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5211 | have a zero valued address and we don't want to mark breakpoints of any of |
5212 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5213 | |
5214 | bp_watchpoint | |
2d134ed3 PA |
5215 | bp_catchpoint |
5216 | ||
5217 | */ | |
e4f237da KB |
5218 | |
5219 | static int | |
5220 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5221 | { | |
5222 | enum bptype type = bpt->type; | |
5223 | ||
2d134ed3 PA |
5224 | return (type != bp_watchpoint && type != bp_catchpoint); |
5225 | } | |
5226 | ||
5227 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5228 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5229 | ||
5230 | static int | |
5231 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5232 | { | |
85d721b8 PA |
5233 | /* Note that this checks the owner's type, not the location's. In |
5234 | case the target does not support read watchpoints, but does | |
5235 | support access watchpoints, we'll have bp_read_watchpoint | |
5236 | watchpoints with hw_access locations. Those should be considered | |
5237 | duplicates of hw_read locations. The hw_read locations will | |
5238 | become hw_access locations later. */ | |
2d134ed3 PA |
5239 | return (loc1->owner->type == loc2->owner->type |
5240 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5241 | && loc1->address == loc2->address | |
5242 | && loc1->length == loc2->length); | |
e4f237da KB |
5243 | } |
5244 | ||
6c95b8df PA |
5245 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5246 | same breakpoint location. In most targets, this can only be true | |
5247 | if ASPACE1 matches ASPACE2. On targets that have global | |
5248 | breakpoints, the address space doesn't really matter. */ | |
5249 | ||
5250 | static int | |
5251 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5252 | struct address_space *aspace2, CORE_ADDR addr2) | |
5253 | { | |
5254 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5255 | || aspace1 == aspace2) | |
5256 | && addr1 == addr2); | |
5257 | } | |
5258 | ||
2d134ed3 PA |
5259 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5260 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5261 | represent the same location. */ | |
5262 | ||
5263 | static int | |
5264 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5265 | { | |
5266 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5267 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
5268 | ||
5269 | if (hw_point1 != hw_point2) | |
5270 | return 0; | |
5271 | else if (hw_point1) | |
5272 | return watchpoint_locations_match (loc1, loc2); | |
5273 | else | |
5274 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5275 | loc2->pspace->aspace, loc2->address); | |
5276 | } | |
5277 | ||
76897487 KB |
5278 | static void |
5279 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5280 | int bnum, int have_bnum) | |
5281 | { | |
5282 | char astr1[40]; | |
5283 | char astr2[40]; | |
5284 | ||
bb599908 PH |
5285 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5286 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5287 | if (have_bnum) |
8a3fe4f8 | 5288 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5289 | bnum, astr1, astr2); |
5290 | else | |
8a3fe4f8 | 5291 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5292 | } |
5293 | ||
5294 | /* Adjust a breakpoint's address to account for architectural constraints | |
5295 | on breakpoint placement. Return the adjusted address. Note: Very | |
5296 | few targets require this kind of adjustment. For most targets, | |
5297 | this function is simply the identity function. */ | |
5298 | ||
5299 | static CORE_ADDR | |
a6d9a66e UW |
5300 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5301 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5302 | { |
a6d9a66e | 5303 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5304 | { |
5305 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5306 | return bpaddr; | |
5307 | } | |
88f7da05 KB |
5308 | else if (bptype == bp_watchpoint |
5309 | || bptype == bp_hardware_watchpoint | |
5310 | || bptype == bp_read_watchpoint | |
5311 | || bptype == bp_access_watchpoint | |
fe798b75 | 5312 | || bptype == bp_catchpoint) |
88f7da05 KB |
5313 | { |
5314 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5315 | have their addresses modified. */ | |
5316 | return bpaddr; | |
5317 | } | |
76897487 KB |
5318 | else |
5319 | { | |
5320 | CORE_ADDR adjusted_bpaddr; | |
5321 | ||
5322 | /* Some targets have architectural constraints on the placement | |
5323 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5324 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5325 | |
5326 | /* An adjusted breakpoint address can significantly alter | |
5327 | a user's expectations. Print a warning if an adjustment | |
5328 | is required. */ | |
5329 | if (adjusted_bpaddr != bpaddr) | |
5330 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5331 | ||
5332 | return adjusted_bpaddr; | |
5333 | } | |
5334 | } | |
5335 | ||
7cc221ef DJ |
5336 | /* Allocate a struct bp_location. */ |
5337 | ||
26bb91f3 | 5338 | static struct bp_location * |
39d61571 | 5339 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
5340 | { |
5341 | struct bp_location *loc, *loc_p; | |
5342 | ||
5343 | loc = xmalloc (sizeof (struct bp_location)); | |
5344 | memset (loc, 0, sizeof (*loc)); | |
5345 | ||
e049a4b5 | 5346 | loc->owner = bpt; |
511a6cd4 | 5347 | loc->cond = NULL; |
0d381245 VP |
5348 | loc->shlib_disabled = 0; |
5349 | loc->enabled = 1; | |
e049a4b5 | 5350 | |
39d61571 | 5351 | switch (bpt->type) |
e049a4b5 DJ |
5352 | { |
5353 | case bp_breakpoint: | |
5354 | case bp_until: | |
5355 | case bp_finish: | |
5356 | case bp_longjmp: | |
5357 | case bp_longjmp_resume: | |
5358 | case bp_step_resume: | |
e049a4b5 DJ |
5359 | case bp_watchpoint_scope: |
5360 | case bp_call_dummy: | |
aa7d318d | 5361 | case bp_std_terminate: |
e049a4b5 DJ |
5362 | case bp_shlib_event: |
5363 | case bp_thread_event: | |
5364 | case bp_overlay_event: | |
4efc6507 | 5365 | case bp_jit_event: |
0fd8e87f | 5366 | case bp_longjmp_master: |
aa7d318d | 5367 | case bp_std_terminate_master: |
e049a4b5 DJ |
5368 | loc->loc_type = bp_loc_software_breakpoint; |
5369 | break; | |
5370 | case bp_hardware_breakpoint: | |
5371 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5372 | break; | |
5373 | case bp_hardware_watchpoint: | |
5374 | case bp_read_watchpoint: | |
5375 | case bp_access_watchpoint: | |
5376 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5377 | break; | |
5378 | case bp_watchpoint: | |
ce78b96d | 5379 | case bp_catchpoint: |
15c3d785 PA |
5380 | case bp_tracepoint: |
5381 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
5382 | loc->loc_type = bp_loc_other; |
5383 | break; | |
5384 | default: | |
e2e0b3e5 | 5385 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5386 | } |
5387 | ||
7cc221ef DJ |
5388 | return loc; |
5389 | } | |
5390 | ||
fe3f5fa8 VP |
5391 | static void free_bp_location (struct bp_location *loc) |
5392 | { | |
5393 | if (loc->cond) | |
5394 | xfree (loc->cond); | |
74960c60 VP |
5395 | |
5396 | if (loc->function_name) | |
5397 | xfree (loc->function_name); | |
5398 | ||
fe3f5fa8 VP |
5399 | xfree (loc); |
5400 | } | |
5401 | ||
0d381245 VP |
5402 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5403 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5404 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5405 | |
c40e75cd | 5406 | static struct breakpoint * |
a6d9a66e UW |
5407 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5408 | enum bptype bptype) | |
c906108c | 5409 | { |
52f0bd74 | 5410 | struct breakpoint *b, *b1; |
c906108c SS |
5411 | |
5412 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5413 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5414 | |
4d28f7a8 | 5415 | b->type = bptype; |
a6d9a66e | 5416 | b->gdbarch = gdbarch; |
c906108c SS |
5417 | b->language = current_language->la_language; |
5418 | b->input_radix = input_radix; | |
5419 | b->thread = -1; | |
b5de0fa7 | 5420 | b->enable_state = bp_enabled; |
c906108c SS |
5421 | b->next = 0; |
5422 | b->silent = 0; | |
5423 | b->ignore_count = 0; | |
5424 | b->commands = NULL; | |
818dd999 | 5425 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5426 | b->forked_inferior_pid = null_ptid; |
c906108c | 5427 | b->exec_pathname = NULL; |
a96d9b2e | 5428 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5429 | b->ops = NULL; |
0d381245 | 5430 | b->condition_not_parsed = 0; |
c906108c SS |
5431 | |
5432 | /* Add this breakpoint to the end of the chain | |
5433 | so that a list of breakpoints will come out in order | |
5434 | of increasing numbers. */ | |
5435 | ||
5436 | b1 = breakpoint_chain; | |
5437 | if (b1 == 0) | |
5438 | breakpoint_chain = b; | |
5439 | else | |
5440 | { | |
5441 | while (b1->next) | |
5442 | b1 = b1->next; | |
5443 | b1->next = b; | |
5444 | } | |
0d381245 VP |
5445 | return b; |
5446 | } | |
5447 | ||
5448 | /* Initialize loc->function_name. */ | |
5449 | static void | |
5450 | set_breakpoint_location_function (struct bp_location *loc) | |
5451 | { | |
5452 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5453 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5454 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5455 | { |
5456 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5457 | NULL, NULL); | |
5458 | if (loc->function_name) | |
5459 | loc->function_name = xstrdup (loc->function_name); | |
5460 | } | |
5461 | } | |
5462 | ||
a6d9a66e UW |
5463 | /* Attempt to determine architecture of location identified by SAL. */ |
5464 | static struct gdbarch * | |
5465 | get_sal_arch (struct symtab_and_line sal) | |
5466 | { | |
5467 | if (sal.section) | |
5468 | return get_objfile_arch (sal.section->objfile); | |
5469 | if (sal.symtab) | |
5470 | return get_objfile_arch (sal.symtab->objfile); | |
5471 | ||
5472 | return NULL; | |
5473 | } | |
5474 | ||
0d381245 VP |
5475 | /* set_raw_breakpoint is a low level routine for allocating and |
5476 | partially initializing a breakpoint of type BPTYPE. The newly | |
5477 | created breakpoint's address, section, source file name, and line | |
5478 | number are provided by SAL. The newly created and partially | |
5479 | initialized breakpoint is added to the breakpoint chain and | |
5480 | is also returned as the value of this function. | |
5481 | ||
5482 | It is expected that the caller will complete the initialization of | |
5483 | the newly created breakpoint struct as well as output any status | |
5484 | information regarding the creation of a new breakpoint. In | |
5485 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5486 | number! Care should be taken to not allow an error to occur | |
5487 | prior to completing the initialization of the breakpoint. If this | |
5488 | should happen, a bogus breakpoint will be left on the chain. */ | |
5489 | ||
63c252f8 | 5490 | struct breakpoint * |
a6d9a66e UW |
5491 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5492 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5493 | { |
a6d9a66e | 5494 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5495 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5496 | struct gdbarch *loc_gdbarch; |
5497 | ||
5498 | loc_gdbarch = get_sal_arch (sal); | |
5499 | if (!loc_gdbarch) | |
5500 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5501 | |
6c95b8df PA |
5502 | if (bptype != bp_catchpoint) |
5503 | gdb_assert (sal.pspace != NULL); | |
5504 | ||
0d381245 VP |
5505 | /* Adjust the breakpoint's address prior to allocating a location. |
5506 | Once we call allocate_bp_location(), that mostly uninitialized | |
5507 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5508 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5509 | not want its scan of the location chain to find a breakpoint and |
5510 | location that's only been partially initialized. */ | |
a6d9a66e | 5511 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5512 | |
39d61571 | 5513 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5514 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5515 | b->loc->requested_address = sal.pc; |
5516 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5517 | b->loc->pspace = sal.pspace; |
5518 | ||
5519 | /* Store the program space that was used to set the breakpoint, for | |
5520 | breakpoint resetting. */ | |
5521 | b->pspace = sal.pspace; | |
0d381245 VP |
5522 | |
5523 | if (sal.symtab == NULL) | |
5524 | b->source_file = NULL; | |
5525 | else | |
1b36a34b | 5526 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5527 | b->loc->section = sal.section; |
5528 | b->line_number = sal.line; | |
5529 | ||
5530 | set_breakpoint_location_function (b->loc); | |
c906108c | 5531 | |
c906108c SS |
5532 | breakpoints_changed (); |
5533 | ||
5534 | return b; | |
5535 | } | |
5536 | ||
c2c6d25f JM |
5537 | |
5538 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5539 | instruction, hard-wired into the inferior's code. */ | |
5540 | void | |
5541 | make_breakpoint_permanent (struct breakpoint *b) | |
5542 | { | |
0d381245 | 5543 | struct bp_location *bl; |
b5de0fa7 | 5544 | b->enable_state = bp_permanent; |
c2c6d25f | 5545 | |
0d381245 VP |
5546 | /* By definition, permanent breakpoints are already present in the code. |
5547 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5548 | is called in just one place, so it's hard to say if it's reasonable | |
5549 | to have permanent breakpoint with multiple locations or not, | |
5550 | but it's easy to implmement. */ | |
5551 | for (bl = b->loc; bl; bl = bl->next) | |
5552 | bl->inserted = 1; | |
c2c6d25f JM |
5553 | } |
5554 | ||
53a5351d | 5555 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5556 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5557 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5558 | ||
5559 | void | |
0fd8e87f | 5560 | set_longjmp_breakpoint (int thread) |
c906108c | 5561 | { |
0fd8e87f UW |
5562 | struct breakpoint *b, *temp; |
5563 | ||
5564 | /* To avoid having to rescan all objfile symbols at every step, | |
5565 | we maintain a list of continually-inserted but always disabled | |
5566 | longjmp "master" breakpoints. Here, we simply create momentary | |
5567 | clones of those and enable them for the requested thread. */ | |
5568 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5569 | if (b->pspace == current_program_space |
5570 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5571 | { |
5572 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5573 | clone->type = bp_longjmp; | |
5574 | clone->thread = thread; | |
5575 | } | |
c906108c SS |
5576 | } |
5577 | ||
611c83ae | 5578 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5579 | void |
611c83ae | 5580 | delete_longjmp_breakpoint (int thread) |
c906108c | 5581 | { |
611c83ae | 5582 | struct breakpoint *b, *temp; |
c906108c | 5583 | |
611c83ae PA |
5584 | ALL_BREAKPOINTS_SAFE (b, temp) |
5585 | if (b->type == bp_longjmp) | |
5586 | { | |
5587 | if (b->thread == thread) | |
5588 | delete_breakpoint (b); | |
5589 | } | |
c906108c SS |
5590 | } |
5591 | ||
1900040c MS |
5592 | void |
5593 | enable_overlay_breakpoints (void) | |
5594 | { | |
52f0bd74 | 5595 | struct breakpoint *b; |
1900040c MS |
5596 | |
5597 | ALL_BREAKPOINTS (b) | |
5598 | if (b->type == bp_overlay_event) | |
5599 | { | |
5600 | b->enable_state = bp_enabled; | |
b60e7edf | 5601 | update_global_location_list (1); |
c02f5703 | 5602 | overlay_events_enabled = 1; |
1900040c MS |
5603 | } |
5604 | } | |
5605 | ||
5606 | void | |
5607 | disable_overlay_breakpoints (void) | |
5608 | { | |
52f0bd74 | 5609 | struct breakpoint *b; |
1900040c MS |
5610 | |
5611 | ALL_BREAKPOINTS (b) | |
5612 | if (b->type == bp_overlay_event) | |
5613 | { | |
5614 | b->enable_state = bp_disabled; | |
b60e7edf | 5615 | update_global_location_list (0); |
c02f5703 | 5616 | overlay_events_enabled = 0; |
1900040c MS |
5617 | } |
5618 | } | |
5619 | ||
aa7d318d TT |
5620 | /* Set an active std::terminate breakpoint for each std::terminate |
5621 | master breakpoint. */ | |
5622 | void | |
5623 | set_std_terminate_breakpoint (void) | |
5624 | { | |
5625 | struct breakpoint *b, *temp; | |
5626 | ||
5627 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5628 | if (b->pspace == current_program_space | |
5629 | && b->type == bp_std_terminate_master) | |
5630 | { | |
5631 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5632 | clone->type = bp_std_terminate; | |
5633 | } | |
5634 | } | |
5635 | ||
5636 | /* Delete all the std::terminate breakpoints. */ | |
5637 | void | |
5638 | delete_std_terminate_breakpoint (void) | |
5639 | { | |
5640 | struct breakpoint *b, *temp; | |
5641 | ||
5642 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5643 | if (b->type == bp_std_terminate) | |
5644 | delete_breakpoint (b); | |
5645 | } | |
5646 | ||
c4093a6a | 5647 | struct breakpoint * |
a6d9a66e | 5648 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5649 | { |
5650 | struct breakpoint *b; | |
c4093a6a | 5651 | |
a6d9a66e | 5652 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5653 | |
b5de0fa7 | 5654 | b->enable_state = bp_enabled; |
c4093a6a | 5655 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5656 | b->addr_string |
5657 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5658 | |
b60e7edf | 5659 | update_global_location_list_nothrow (1); |
74960c60 | 5660 | |
c4093a6a JM |
5661 | return b; |
5662 | } | |
5663 | ||
5664 | void | |
5665 | remove_thread_event_breakpoints (void) | |
5666 | { | |
5667 | struct breakpoint *b, *temp; | |
5668 | ||
5669 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5670 | if (b->type == bp_thread_event |
5671 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5672 | delete_breakpoint (b); |
5673 | } | |
5674 | ||
0101ce28 JJ |
5675 | struct captured_parse_breakpoint_args |
5676 | { | |
5677 | char **arg_p; | |
5678 | struct symtabs_and_lines *sals_p; | |
5679 | char ***addr_string_p; | |
5680 | int *not_found_ptr; | |
5681 | }; | |
5682 | ||
5683 | struct lang_and_radix | |
5684 | { | |
5685 | enum language lang; | |
5686 | int radix; | |
5687 | }; | |
5688 | ||
4efc6507 DE |
5689 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5690 | ||
5691 | struct breakpoint * | |
5692 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5693 | { | |
5694 | struct breakpoint *b; | |
5695 | ||
5696 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5697 | update_global_location_list_nothrow (1); | |
5698 | return b; | |
5699 | } | |
0101ce28 | 5700 | |
cae688ec JJ |
5701 | void |
5702 | remove_solib_event_breakpoints (void) | |
5703 | { | |
5704 | struct breakpoint *b, *temp; | |
5705 | ||
5706 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5707 | if (b->type == bp_shlib_event |
5708 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5709 | delete_breakpoint (b); |
5710 | } | |
5711 | ||
5712 | struct breakpoint * | |
a6d9a66e | 5713 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5714 | { |
5715 | struct breakpoint *b; | |
5716 | ||
a6d9a66e | 5717 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5718 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5719 | return b; |
5720 | } | |
5721 | ||
5722 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5723 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5724 | ||
5725 | void | |
cb851954 | 5726 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5727 | { |
876fa593 | 5728 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5729 | |
876fa593 | 5730 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5731 | { |
0d381245 VP |
5732 | struct breakpoint *b = loc->owner; |
5733 | /* We apply the check to all breakpoints, including disabled | |
5734 | for those with loc->duplicate set. This is so that when breakpoint | |
5735 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5736 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5737 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5738 | if (((b->type == bp_breakpoint) |
508ccb1f | 5739 | || (b->type == bp_jit_event) |
1042e4c0 | 5740 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 5741 | || (is_tracepoint (b))) |
6c95b8df | 5742 | && loc->pspace == current_program_space |
0d381245 | 5743 | && !loc->shlib_disabled |
a77053c2 | 5744 | #ifdef PC_SOLIB |
0d381245 | 5745 | && PC_SOLIB (loc->address) |
a77053c2 | 5746 | #else |
6c95b8df | 5747 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5748 | #endif |
5749 | ) | |
0d381245 VP |
5750 | { |
5751 | loc->shlib_disabled = 1; | |
5752 | } | |
cae688ec JJ |
5753 | } |
5754 | } | |
5755 | ||
84acb35a JJ |
5756 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5757 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5758 | ||
75149521 | 5759 | static void |
84acb35a JJ |
5760 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5761 | { | |
876fa593 | 5762 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5763 | int disabled_shlib_breaks = 0; |
5764 | ||
c86cf029 VP |
5765 | /* SunOS a.out shared libraries are always mapped, so do not |
5766 | disable breakpoints; they will only be reported as unloaded | |
5767 | through clear_solib when GDB discards its shared library | |
5768 | list. See clear_solib for more information. */ | |
5769 | if (exec_bfd != NULL | |
5770 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5771 | return; | |
5772 | ||
876fa593 | 5773 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5774 | { |
0d381245 VP |
5775 | struct breakpoint *b = loc->owner; |
5776 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5777 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5778 | && solib->pspace == loc->pspace |
e2dd7057 | 5779 | && !loc->shlib_disabled |
508ccb1f TT |
5780 | && (b->type == bp_breakpoint |
5781 | || b->type == bp_jit_event | |
5782 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5783 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5784 | { |
e2dd7057 PP |
5785 | loc->shlib_disabled = 1; |
5786 | /* At this point, we cannot rely on remove_breakpoint | |
5787 | succeeding so we must mark the breakpoint as not inserted | |
5788 | to prevent future errors occurring in remove_breakpoints. */ | |
5789 | loc->inserted = 0; | |
5790 | if (!disabled_shlib_breaks) | |
5791 | { | |
5792 | target_terminal_ours_for_output (); | |
5793 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5794 | solib->so_name); | |
84acb35a | 5795 | } |
e2dd7057 | 5796 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5797 | } |
5798 | } | |
84acb35a JJ |
5799 | } |
5800 | ||
ce78b96d JB |
5801 | /* FORK & VFORK catchpoints. */ |
5802 | ||
5803 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5804 | ||
c906108c | 5805 | static void |
ce78b96d JB |
5806 | insert_catch_fork (struct breakpoint *b) |
5807 | { | |
5808 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5809 | } | |
5810 | ||
5811 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5812 | ||
5813 | static int | |
5814 | remove_catch_fork (struct breakpoint *b) | |
5815 | { | |
5816 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5817 | } | |
5818 | ||
5819 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5820 | catchpoints. */ | |
5821 | ||
5822 | static int | |
5823 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5824 | { | |
5825 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5826 | } | |
5827 | ||
5828 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5829 | ||
5830 | static enum print_stop_action | |
5831 | print_it_catch_fork (struct breakpoint *b) | |
5832 | { | |
5833 | annotate_catchpoint (b->number); | |
5834 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5835 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5836 | return PRINT_SRC_AND_LOC; | |
5837 | } | |
5838 | ||
5839 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5840 | ||
5841 | static void | |
a6d9a66e | 5842 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5843 | { |
79a45b7d TT |
5844 | struct value_print_options opts; |
5845 | ||
5846 | get_user_print_options (&opts); | |
5847 | ||
ce78b96d JB |
5848 | /* Field 4, the address, is omitted (which makes the columns |
5849 | not line up too nicely with the headers, but the effect | |
5850 | is relatively readable). */ | |
79a45b7d | 5851 | if (opts.addressprint) |
ce78b96d JB |
5852 | ui_out_field_skip (uiout, "addr"); |
5853 | annotate_field (5); | |
5854 | ui_out_text (uiout, "fork"); | |
5855 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5856 | { | |
5857 | ui_out_text (uiout, ", process "); | |
5858 | ui_out_field_int (uiout, "what", | |
5859 | ptid_get_pid (b->forked_inferior_pid)); | |
5860 | ui_out_spaces (uiout, 1); | |
5861 | } | |
5862 | } | |
5863 | ||
5864 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5865 | catchpoints. */ | |
5866 | ||
5867 | static void | |
5868 | print_mention_catch_fork (struct breakpoint *b) | |
5869 | { | |
5870 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5871 | } | |
5872 | ||
5873 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5874 | ||
5875 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5876 | { | |
5877 | insert_catch_fork, | |
5878 | remove_catch_fork, | |
5879 | breakpoint_hit_catch_fork, | |
5880 | print_it_catch_fork, | |
5881 | print_one_catch_fork, | |
5882 | print_mention_catch_fork | |
5883 | }; | |
5884 | ||
5885 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5886 | ||
5887 | static void | |
5888 | insert_catch_vfork (struct breakpoint *b) | |
5889 | { | |
5890 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5891 | } | |
5892 | ||
5893 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5894 | ||
5895 | static int | |
5896 | remove_catch_vfork (struct breakpoint *b) | |
5897 | { | |
5898 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5899 | } | |
5900 | ||
5901 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5902 | catchpoints. */ | |
5903 | ||
5904 | static int | |
5905 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5906 | { | |
5907 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5908 | } | |
5909 | ||
5910 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5911 | ||
5912 | static enum print_stop_action | |
5913 | print_it_catch_vfork (struct breakpoint *b) | |
5914 | { | |
5915 | annotate_catchpoint (b->number); | |
5916 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5917 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5918 | return PRINT_SRC_AND_LOC; | |
5919 | } | |
5920 | ||
5921 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5922 | ||
5923 | static void | |
a6d9a66e | 5924 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5925 | { |
79a45b7d TT |
5926 | struct value_print_options opts; |
5927 | ||
5928 | get_user_print_options (&opts); | |
ce78b96d JB |
5929 | /* Field 4, the address, is omitted (which makes the columns |
5930 | not line up too nicely with the headers, but the effect | |
5931 | is relatively readable). */ | |
79a45b7d | 5932 | if (opts.addressprint) |
ce78b96d JB |
5933 | ui_out_field_skip (uiout, "addr"); |
5934 | annotate_field (5); | |
5935 | ui_out_text (uiout, "vfork"); | |
5936 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5937 | { | |
5938 | ui_out_text (uiout, ", process "); | |
5939 | ui_out_field_int (uiout, "what", | |
5940 | ptid_get_pid (b->forked_inferior_pid)); | |
5941 | ui_out_spaces (uiout, 1); | |
5942 | } | |
5943 | } | |
5944 | ||
5945 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5946 | catchpoints. */ | |
5947 | ||
5948 | static void | |
5949 | print_mention_catch_vfork (struct breakpoint *b) | |
5950 | { | |
5951 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5952 | } | |
5953 | ||
5954 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5955 | ||
5956 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5957 | { | |
5958 | insert_catch_vfork, | |
5959 | remove_catch_vfork, | |
5960 | breakpoint_hit_catch_vfork, | |
5961 | print_it_catch_vfork, | |
5962 | print_one_catch_vfork, | |
5963 | print_mention_catch_vfork | |
5964 | }; | |
5965 | ||
a96d9b2e SDJ |
5966 | /* Implement the "insert" breakpoint_ops method for syscall |
5967 | catchpoints. */ | |
5968 | ||
5969 | static void | |
5970 | insert_catch_syscall (struct breakpoint *b) | |
5971 | { | |
5972 | struct inferior *inf = current_inferior (); | |
5973 | ||
5974 | ++inf->total_syscalls_count; | |
5975 | if (!b->syscalls_to_be_caught) | |
5976 | ++inf->any_syscall_count; | |
5977 | else | |
5978 | { | |
5979 | int i, iter; | |
5980 | for (i = 0; | |
5981 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5982 | i++) | |
5983 | { | |
5984 | int elem; | |
5985 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5986 | { | |
5987 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5988 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5989 | uintptr_t vec_addr; | |
5990 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5991 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5992 | vec_addr_offset; | |
5993 | memset ((void *) vec_addr, 0, | |
5994 | (iter + 1 - old_size) * sizeof (int)); | |
5995 | } | |
5996 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5997 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5998 | } | |
5999 | } | |
6000 | ||
6001 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6002 | inf->total_syscalls_count != 0, | |
6003 | inf->any_syscall_count, | |
6004 | VEC_length (int, inf->syscalls_counts), | |
6005 | VEC_address (int, inf->syscalls_counts)); | |
6006 | } | |
6007 | ||
6008 | /* Implement the "remove" breakpoint_ops method for syscall | |
6009 | catchpoints. */ | |
6010 | ||
6011 | static int | |
6012 | remove_catch_syscall (struct breakpoint *b) | |
6013 | { | |
6014 | struct inferior *inf = current_inferior (); | |
6015 | ||
6016 | --inf->total_syscalls_count; | |
6017 | if (!b->syscalls_to_be_caught) | |
6018 | --inf->any_syscall_count; | |
6019 | else | |
6020 | { | |
6021 | int i, iter; | |
6022 | for (i = 0; | |
6023 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6024 | i++) | |
6025 | { | |
6026 | int elem; | |
6027 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6028 | /* Shouldn't happen. */ | |
6029 | continue; | |
6030 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6031 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6032 | } | |
6033 | } | |
6034 | ||
6035 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6036 | inf->total_syscalls_count != 0, | |
6037 | inf->any_syscall_count, | |
6038 | VEC_length (int, inf->syscalls_counts), | |
6039 | VEC_address (int, inf->syscalls_counts)); | |
6040 | } | |
6041 | ||
6042 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6043 | catchpoints. */ | |
6044 | ||
6045 | static int | |
6046 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6047 | { | |
6048 | /* We must check if we are catching specific syscalls in this breakpoint. | |
6049 | If we are, then we must guarantee that the called syscall is the same | |
6050 | syscall we are catching. */ | |
6051 | int syscall_number = 0; | |
6052 | ||
6053 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6054 | return 0; | |
6055 | ||
6056 | /* Now, checking if the syscall is the same. */ | |
6057 | if (b->syscalls_to_be_caught) | |
6058 | { | |
6059 | int i, iter; | |
6060 | for (i = 0; | |
6061 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6062 | i++) | |
6063 | if (syscall_number == iter) | |
6064 | break; | |
6065 | /* Not the same. */ | |
6066 | if (!iter) | |
6067 | return 0; | |
6068 | } | |
6069 | ||
6070 | return 1; | |
6071 | } | |
6072 | ||
6073 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6074 | catchpoints. */ | |
6075 | ||
6076 | static enum print_stop_action | |
6077 | print_it_catch_syscall (struct breakpoint *b) | |
6078 | { | |
6079 | /* These are needed because we want to know in which state a | |
6080 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6081 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6082 | must print "called syscall" or "returned from syscall". */ | |
6083 | ptid_t ptid; | |
6084 | struct target_waitstatus last; | |
6085 | struct syscall s; | |
6086 | struct cleanup *old_chain; | |
6087 | char *syscall_id; | |
6088 | ||
6089 | get_last_target_status (&ptid, &last); | |
6090 | ||
6091 | get_syscall_by_number (last.value.syscall_number, &s); | |
6092 | ||
6093 | annotate_catchpoint (b->number); | |
6094 | ||
6095 | if (s.name == NULL) | |
6096 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6097 | else | |
6098 | syscall_id = xstrprintf ("'%s'", s.name); | |
6099 | ||
6100 | old_chain = make_cleanup (xfree, syscall_id); | |
6101 | ||
6102 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6103 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6104 | b->number, syscall_id); | |
6105 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6106 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6107 | b->number, syscall_id); | |
6108 | ||
6109 | do_cleanups (old_chain); | |
6110 | ||
6111 | return PRINT_SRC_AND_LOC; | |
6112 | } | |
6113 | ||
6114 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6115 | catchpoints. */ | |
6116 | ||
6117 | static void | |
6118 | print_one_catch_syscall (struct breakpoint *b, | |
6119 | struct bp_location **last_loc) | |
6120 | { | |
6121 | struct value_print_options opts; | |
6122 | ||
6123 | get_user_print_options (&opts); | |
6124 | /* Field 4, the address, is omitted (which makes the columns | |
6125 | not line up too nicely with the headers, but the effect | |
6126 | is relatively readable). */ | |
6127 | if (opts.addressprint) | |
6128 | ui_out_field_skip (uiout, "addr"); | |
6129 | annotate_field (5); | |
6130 | ||
6131 | if (b->syscalls_to_be_caught | |
6132 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6133 | ui_out_text (uiout, "syscalls \""); | |
6134 | else | |
6135 | ui_out_text (uiout, "syscall \""); | |
6136 | ||
6137 | if (b->syscalls_to_be_caught) | |
6138 | { | |
6139 | int i, iter; | |
6140 | char *text = xstrprintf ("%s", ""); | |
6141 | for (i = 0; | |
6142 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6143 | i++) | |
6144 | { | |
6145 | char *x = text; | |
6146 | struct syscall s; | |
6147 | get_syscall_by_number (iter, &s); | |
6148 | ||
6149 | if (s.name != NULL) | |
6150 | text = xstrprintf ("%s%s, ", text, s.name); | |
6151 | else | |
6152 | text = xstrprintf ("%s%d, ", text, iter); | |
6153 | ||
6154 | /* We have to xfree the last 'text' (now stored at 'x') | |
6155 | because xstrprintf dinamically allocates new space for it | |
6156 | on every call. */ | |
6157 | xfree (x); | |
6158 | } | |
6159 | /* Remove the last comma. */ | |
6160 | text[strlen (text) - 2] = '\0'; | |
6161 | ui_out_field_string (uiout, "what", text); | |
6162 | } | |
6163 | else | |
6164 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6165 | ui_out_text (uiout, "\" "); | |
6166 | } | |
6167 | ||
6168 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6169 | catchpoints. */ | |
6170 | ||
6171 | static void | |
6172 | print_mention_catch_syscall (struct breakpoint *b) | |
6173 | { | |
6174 | if (b->syscalls_to_be_caught) | |
6175 | { | |
6176 | int i, iter; | |
6177 | ||
6178 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6179 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6180 | else | |
6181 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6182 | ||
6183 | for (i = 0; | |
6184 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6185 | i++) | |
6186 | { | |
6187 | struct syscall s; | |
6188 | get_syscall_by_number (iter, &s); | |
6189 | ||
6190 | if (s.name) | |
6191 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6192 | else | |
6193 | printf_filtered (" %d", s.number); | |
6194 | } | |
6195 | printf_filtered (")"); | |
6196 | } | |
6197 | else | |
6198 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6199 | b->number); | |
6200 | } | |
6201 | ||
6202 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
6203 | ||
6204 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6205 | { | |
6206 | insert_catch_syscall, | |
6207 | remove_catch_syscall, | |
6208 | breakpoint_hit_catch_syscall, | |
6209 | print_it_catch_syscall, | |
6210 | print_one_catch_syscall, | |
6211 | print_mention_catch_syscall | |
6212 | }; | |
6213 | ||
6214 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6215 | ||
6216 | static int | |
6217 | syscall_catchpoint_p (struct breakpoint *b) | |
6218 | { | |
6219 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6220 | } | |
6221 | ||
6222 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6223 | but does NOT mention it nor update the global location list. | |
6224 | This is useful if you need to fill more fields in the | |
6225 | struct breakpoint before calling mention. | |
ce78b96d JB |
6226 | |
6227 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6228 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6229 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6230 | to the catchpoint. */ | |
6231 | ||
6232 | static struct breakpoint * | |
a96d9b2e SDJ |
6233 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6234 | char *cond_string, | |
6235 | struct breakpoint_ops *ops) | |
c906108c | 6236 | { |
c5aa993b JM |
6237 | struct symtab_and_line sal; |
6238 | struct breakpoint *b; | |
c5aa993b | 6239 | |
fe39c653 | 6240 | init_sal (&sal); |
6c95b8df | 6241 | sal.pspace = current_program_space; |
c5aa993b | 6242 | |
a6d9a66e | 6243 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6244 | set_breakpoint_count (breakpoint_count + 1); |
6245 | b->number = breakpoint_count; | |
ce78b96d | 6246 | |
1b36a34b | 6247 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6248 | b->thread = -1; |
c906108c | 6249 | b->addr_string = NULL; |
b5de0fa7 EZ |
6250 | b->enable_state = bp_enabled; |
6251 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6252 | b->ops = ops; |
c5aa993b | 6253 | |
a96d9b2e SDJ |
6254 | return b; |
6255 | } | |
6256 | ||
6257 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6258 | ||
6259 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6260 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6261 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6262 | to the catchpoint. */ | |
6263 | ||
6264 | static struct breakpoint * | |
6265 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6266 | char *cond_string, struct breakpoint_ops *ops) | |
6267 | { | |
6268 | struct breakpoint *b = | |
6269 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6270 | ||
c906108c | 6271 | mention (b); |
ce78b96d | 6272 | update_global_location_list (1); |
c906108c | 6273 | |
ce78b96d | 6274 | return b; |
c906108c | 6275 | } |
c5aa993b | 6276 | |
9b70b993 | 6277 | static void |
a6d9a66e UW |
6278 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6279 | int tempflag, char *cond_string, | |
ce78b96d | 6280 | struct breakpoint_ops *ops) |
c906108c | 6281 | { |
a6d9a66e UW |
6282 | struct breakpoint *b |
6283 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6284 | |
6285 | /* FIXME: We should put this information in a breakpoint private data | |
6286 | area. */ | |
6287 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6288 | } |
6289 | ||
fe798b75 JB |
6290 | /* Exec catchpoints. */ |
6291 | ||
9b70b993 | 6292 | static void |
fe798b75 | 6293 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6294 | { |
fe798b75 JB |
6295 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6296 | } | |
c906108c | 6297 | |
fe798b75 JB |
6298 | static int |
6299 | remove_catch_exec (struct breakpoint *b) | |
6300 | { | |
6301 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6302 | } | |
c906108c | 6303 | |
fe798b75 JB |
6304 | static int |
6305 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6306 | { | |
6307 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6308 | } | |
c906108c | 6309 | |
fe798b75 JB |
6310 | static enum print_stop_action |
6311 | print_it_catch_exec (struct breakpoint *b) | |
6312 | { | |
6313 | annotate_catchpoint (b->number); | |
6314 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6315 | b->exec_pathname); | |
6316 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6317 | } |
6318 | ||
fe798b75 | 6319 | static void |
a6d9a66e | 6320 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6321 | { |
6322 | struct value_print_options opts; | |
6323 | ||
6324 | get_user_print_options (&opts); | |
6325 | ||
6326 | /* Field 4, the address, is omitted (which makes the columns | |
6327 | not line up too nicely with the headers, but the effect | |
6328 | is relatively readable). */ | |
6329 | if (opts.addressprint) | |
6330 | ui_out_field_skip (uiout, "addr"); | |
6331 | annotate_field (5); | |
6332 | ui_out_text (uiout, "exec"); | |
6333 | if (b->exec_pathname != NULL) | |
6334 | { | |
6335 | ui_out_text (uiout, ", program \""); | |
6336 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6337 | ui_out_text (uiout, "\" "); | |
6338 | } | |
6339 | } | |
6340 | ||
6341 | static void | |
6342 | print_mention_catch_exec (struct breakpoint *b) | |
6343 | { | |
6344 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6345 | } | |
6346 | ||
6347 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
6348 | { | |
6349 | insert_catch_exec, | |
6350 | remove_catch_exec, | |
6351 | breakpoint_hit_catch_exec, | |
6352 | print_it_catch_exec, | |
6353 | print_one_catch_exec, | |
6354 | print_mention_catch_exec | |
6355 | }; | |
6356 | ||
a96d9b2e SDJ |
6357 | static void |
6358 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6359 | struct breakpoint_ops *ops) | |
6360 | { | |
6361 | struct gdbarch *gdbarch = get_current_arch (); | |
6362 | struct breakpoint *b = | |
6363 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6364 | ||
6365 | b->syscalls_to_be_caught = filter; | |
6366 | ||
6367 | /* Now, we have to mention the breakpoint and update the global | |
6368 | location list. */ | |
6369 | mention (b); | |
6370 | update_global_location_list (1); | |
6371 | } | |
6372 | ||
c906108c | 6373 | static int |
fba45db2 | 6374 | hw_breakpoint_used_count (void) |
c906108c | 6375 | { |
52f0bd74 | 6376 | struct breakpoint *b; |
c906108c SS |
6377 | int i = 0; |
6378 | ||
6379 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6380 | { |
d6b74ac4 | 6381 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6382 | i++; |
6383 | } | |
c906108c SS |
6384 | |
6385 | return i; | |
6386 | } | |
6387 | ||
6388 | static int | |
fba45db2 | 6389 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6390 | { |
52f0bd74 | 6391 | struct breakpoint *b; |
c906108c SS |
6392 | int i = 0; |
6393 | ||
6394 | *other_type_used = 0; | |
6395 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6396 | { |
468d015d | 6397 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6398 | { |
6399 | if (b->type == type) | |
6400 | i++; | |
059fb39f PM |
6401 | else if ((b->type == bp_hardware_watchpoint |
6402 | || b->type == bp_read_watchpoint | |
6403 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
6404 | *other_type_used = 1; |
6405 | } | |
6406 | } | |
c906108c SS |
6407 | return i; |
6408 | } | |
6409 | ||
c906108c | 6410 | void |
fba45db2 | 6411 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6412 | { |
c5aa993b | 6413 | struct breakpoint *b; |
c906108c SS |
6414 | |
6415 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6416 | { |
6417 | if (((b->type == bp_watchpoint) | |
6418 | || (b->type == bp_hardware_watchpoint) | |
6419 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6420 | || (b->type == bp_access_watchpoint)) |
468d015d | 6421 | && breakpoint_enabled (b)) |
c5aa993b | 6422 | { |
b5de0fa7 | 6423 | b->enable_state = bp_call_disabled; |
b60e7edf | 6424 | update_global_location_list (0); |
c5aa993b JM |
6425 | } |
6426 | } | |
c906108c SS |
6427 | } |
6428 | ||
6429 | void | |
fba45db2 | 6430 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6431 | { |
c5aa993b | 6432 | struct breakpoint *b; |
c906108c SS |
6433 | |
6434 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6435 | { |
6436 | if (((b->type == bp_watchpoint) | |
6437 | || (b->type == bp_hardware_watchpoint) | |
6438 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6439 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6440 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6441 | { |
b5de0fa7 | 6442 | b->enable_state = bp_enabled; |
b60e7edf | 6443 | update_global_location_list (1); |
c5aa993b JM |
6444 | } |
6445 | } | |
c906108c SS |
6446 | } |
6447 | ||
8bea4e01 UW |
6448 | void |
6449 | disable_breakpoints_before_startup (void) | |
6450 | { | |
6451 | struct breakpoint *b; | |
6452 | int found = 0; | |
6453 | ||
6454 | ALL_BREAKPOINTS (b) | |
6455 | { | |
6c95b8df PA |
6456 | if (b->pspace != current_program_space) |
6457 | continue; | |
6458 | ||
8bea4e01 UW |
6459 | if ((b->type == bp_breakpoint |
6460 | || b->type == bp_hardware_breakpoint) | |
6461 | && breakpoint_enabled (b)) | |
6462 | { | |
6463 | b->enable_state = bp_startup_disabled; | |
6464 | found = 1; | |
6465 | } | |
6466 | } | |
6467 | ||
6468 | if (found) | |
6469 | update_global_location_list (0); | |
6470 | ||
6c95b8df | 6471 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6472 | } |
6473 | ||
6474 | void | |
6475 | enable_breakpoints_after_startup (void) | |
6476 | { | |
6477 | struct breakpoint *b; | |
6478 | int found = 0; | |
6479 | ||
6c95b8df | 6480 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6481 | |
6482 | ALL_BREAKPOINTS (b) | |
6483 | { | |
6c95b8df PA |
6484 | if (b->pspace != current_program_space) |
6485 | continue; | |
6486 | ||
8bea4e01 UW |
6487 | if ((b->type == bp_breakpoint |
6488 | || b->type == bp_hardware_breakpoint) | |
6489 | && b->enable_state == bp_startup_disabled) | |
6490 | { | |
6491 | b->enable_state = bp_enabled; | |
6492 | found = 1; | |
6493 | } | |
6494 | } | |
6495 | ||
6496 | if (found) | |
6497 | breakpoint_re_set (); | |
6498 | } | |
6499 | ||
c906108c SS |
6500 | |
6501 | /* Set a breakpoint that will evaporate an end of command | |
6502 | at address specified by SAL. | |
6503 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6504 | ||
6505 | struct breakpoint * | |
a6d9a66e UW |
6506 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6507 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6508 | { |
52f0bd74 | 6509 | struct breakpoint *b; |
edb3359d DJ |
6510 | |
6511 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6512 | one. */ | |
6513 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6514 | ||
a6d9a66e | 6515 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6516 | b->enable_state = bp_enabled; |
6517 | b->disposition = disp_donttouch; | |
818dd999 | 6518 | b->frame_id = frame_id; |
c906108c SS |
6519 | |
6520 | /* If we're debugging a multi-threaded program, then we | |
6521 | want momentary breakpoints to be active in only a | |
6522 | single thread of control. */ | |
39f77062 KB |
6523 | if (in_thread_list (inferior_ptid)) |
6524 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6525 | |
b60e7edf | 6526 | update_global_location_list_nothrow (1); |
74960c60 | 6527 | |
c906108c SS |
6528 | return b; |
6529 | } | |
611c83ae | 6530 | |
e58b0e63 PA |
6531 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6532 | ORIG is NULL. */ | |
6533 | ||
6534 | struct breakpoint * | |
6535 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6536 | { | |
6537 | struct breakpoint *copy; | |
6538 | ||
6539 | /* If there's nothing to clone, then return nothing. */ | |
6540 | if (orig == NULL) | |
6541 | return NULL; | |
6542 | ||
a6d9a66e | 6543 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6544 | copy->loc = allocate_bp_location (copy); |
6545 | set_breakpoint_location_function (copy->loc); | |
6546 | ||
a6d9a66e | 6547 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6548 | copy->loc->requested_address = orig->loc->requested_address; |
6549 | copy->loc->address = orig->loc->address; | |
6550 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6551 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6552 | |
6553 | if (orig->source_file == NULL) | |
6554 | copy->source_file = NULL; | |
6555 | else | |
6556 | copy->source_file = xstrdup (orig->source_file); | |
6557 | ||
6558 | copy->line_number = orig->line_number; | |
6559 | copy->frame_id = orig->frame_id; | |
6560 | copy->thread = orig->thread; | |
6c95b8df | 6561 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6562 | |
6563 | copy->enable_state = bp_enabled; | |
6564 | copy->disposition = disp_donttouch; | |
6565 | copy->number = internal_breakpoint_number--; | |
6566 | ||
6567 | update_global_location_list_nothrow (0); | |
6568 | return copy; | |
6569 | } | |
6570 | ||
611c83ae | 6571 | struct breakpoint * |
a6d9a66e UW |
6572 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6573 | enum bptype type) | |
611c83ae PA |
6574 | { |
6575 | struct symtab_and_line sal; | |
6576 | ||
6577 | sal = find_pc_line (pc, 0); | |
6578 | sal.pc = pc; | |
6579 | sal.section = find_pc_overlay (pc); | |
6580 | sal.explicit_pc = 1; | |
6581 | ||
a6d9a66e | 6582 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6583 | } |
c906108c | 6584 | \f |
c5aa993b | 6585 | |
c906108c SS |
6586 | /* Tell the user we have just set a breakpoint B. */ |
6587 | ||
6588 | static void | |
fba45db2 | 6589 | mention (struct breakpoint *b) |
c906108c SS |
6590 | { |
6591 | int say_where = 0; | |
fa8a61dc | 6592 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6593 | struct value_print_options opts; |
6594 | ||
6595 | get_user_print_options (&opts); | |
8b93c638 | 6596 | |
9a4105ab AC |
6597 | /* FIXME: This is misplaced; mention() is called by things (like |
6598 | hitting a watchpoint) other than breakpoint creation. It should | |
6599 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6600 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6601 | observer_notify_breakpoint_created (b->number); |
c906108c | 6602 | |
3086aeae DJ |
6603 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6604 | b->ops->print_mention (b); | |
6605 | else | |
6606 | switch (b->type) | |
6607 | { | |
6608 | case bp_none: | |
a3f17187 | 6609 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6610 | break; |
6611 | case bp_watchpoint: | |
6612 | ui_out_text (uiout, "Watchpoint "); | |
6613 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6614 | ui_out_field_int (uiout, "number", b->number); | |
6615 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6616 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6617 | do_cleanups (ui_out_chain); |
6618 | break; | |
6619 | case bp_hardware_watchpoint: | |
6620 | ui_out_text (uiout, "Hardware watchpoint "); | |
6621 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6622 | ui_out_field_int (uiout, "number", b->number); | |
6623 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6624 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6625 | do_cleanups (ui_out_chain); |
6626 | break; | |
6627 | case bp_read_watchpoint: | |
6628 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6629 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6630 | ui_out_field_int (uiout, "number", b->number); | |
6631 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6632 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6633 | do_cleanups (ui_out_chain); |
6634 | break; | |
6635 | case bp_access_watchpoint: | |
6636 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6637 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6638 | ui_out_field_int (uiout, "number", b->number); | |
6639 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6640 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6641 | do_cleanups (ui_out_chain); |
6642 | break; | |
6643 | case bp_breakpoint: | |
6644 | if (ui_out_is_mi_like_p (uiout)) | |
6645 | { | |
6646 | say_where = 0; | |
6647 | break; | |
6648 | } | |
2cec12e5 AR |
6649 | if (b->disposition == disp_del) |
6650 | printf_filtered (_("Temporary breakpoint")); | |
6651 | else | |
6652 | printf_filtered (_("Breakpoint")); | |
6653 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6654 | say_where = 1; |
6655 | break; | |
6656 | case bp_hardware_breakpoint: | |
6657 | if (ui_out_is_mi_like_p (uiout)) | |
6658 | { | |
6659 | say_where = 0; | |
6660 | break; | |
6661 | } | |
a3f17187 | 6662 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6663 | say_where = 1; |
6664 | break; | |
1042e4c0 SS |
6665 | case bp_tracepoint: |
6666 | if (ui_out_is_mi_like_p (uiout)) | |
6667 | { | |
6668 | say_where = 0; | |
6669 | break; | |
6670 | } | |
6671 | printf_filtered (_("Tracepoint")); | |
6672 | printf_filtered (_(" %d"), b->number); | |
6673 | say_where = 1; | |
6674 | break; | |
7a697b8d SS |
6675 | case bp_fast_tracepoint: |
6676 | if (ui_out_is_mi_like_p (uiout)) | |
6677 | { | |
6678 | say_where = 0; | |
6679 | break; | |
6680 | } | |
6681 | printf_filtered (_("Fast tracepoint")); | |
6682 | printf_filtered (_(" %d"), b->number); | |
6683 | say_where = 1; | |
6684 | break; | |
3086aeae DJ |
6685 | |
6686 | case bp_until: | |
6687 | case bp_finish: | |
6688 | case bp_longjmp: | |
6689 | case bp_longjmp_resume: | |
6690 | case bp_step_resume: | |
3086aeae | 6691 | case bp_call_dummy: |
aa7d318d | 6692 | case bp_std_terminate: |
3086aeae DJ |
6693 | case bp_watchpoint_scope: |
6694 | case bp_shlib_event: | |
6695 | case bp_thread_event: | |
6696 | case bp_overlay_event: | |
4efc6507 | 6697 | case bp_jit_event: |
0fd8e87f | 6698 | case bp_longjmp_master: |
aa7d318d | 6699 | case bp_std_terminate_master: |
3086aeae DJ |
6700 | break; |
6701 | } | |
c906108c | 6702 | |
c906108c SS |
6703 | if (say_where) |
6704 | { | |
a3f17187 AC |
6705 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6706 | single string. */ | |
0d381245 | 6707 | if (b->loc == NULL) |
c906108c | 6708 | { |
a3f17187 | 6709 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6710 | } |
6711 | else | |
6712 | { | |
79a45b7d | 6713 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6714 | { |
6715 | printf_filtered (" at "); | |
5af949e3 UW |
6716 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6717 | gdb_stdout); | |
0101ce28 JJ |
6718 | } |
6719 | if (b->source_file) | |
6720 | printf_filtered (": file %s, line %d.", | |
6721 | b->source_file, b->line_number); | |
0d381245 VP |
6722 | |
6723 | if (b->loc->next) | |
6724 | { | |
6725 | struct bp_location *loc = b->loc; | |
6726 | int n = 0; | |
6727 | for (; loc; loc = loc->next) | |
6728 | ++n; | |
6729 | printf_filtered (" (%d locations)", n); | |
6730 | } | |
6731 | ||
c906108c | 6732 | } |
c906108c | 6733 | } |
9dc5e2a9 | 6734 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6735 | return; |
c906108c SS |
6736 | printf_filtered ("\n"); |
6737 | } | |
c906108c | 6738 | \f |
c5aa993b | 6739 | |
0d381245 | 6740 | static struct bp_location * |
39d61571 | 6741 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6742 | const struct symtab_and_line *sal) |
6743 | { | |
6744 | struct bp_location *loc, **tmp; | |
6745 | ||
39d61571 | 6746 | loc = allocate_bp_location (b); |
0d381245 VP |
6747 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6748 | ; | |
6749 | *tmp = loc; | |
a6d9a66e UW |
6750 | loc->gdbarch = get_sal_arch (*sal); |
6751 | if (!loc->gdbarch) | |
6752 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6753 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6754 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6755 | loc->requested_address, b->type); | |
6c95b8df PA |
6756 | loc->pspace = sal->pspace; |
6757 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6758 | loc->section = sal->section; |
6759 | ||
6760 | set_breakpoint_location_function (loc); | |
6761 | return loc; | |
6762 | } | |
514f746b AR |
6763 | \f |
6764 | ||
6765 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6766 | return 0 otherwise. */ | |
6767 | ||
6768 | static int | |
6769 | bp_loc_is_permanent (struct bp_location *loc) | |
6770 | { | |
6771 | int len; | |
6772 | CORE_ADDR addr; | |
6773 | const gdb_byte *brk; | |
6774 | gdb_byte *target_mem; | |
939c61fa JK |
6775 | struct cleanup *cleanup; |
6776 | int retval = 0; | |
514f746b AR |
6777 | |
6778 | gdb_assert (loc != NULL); | |
6779 | ||
6780 | addr = loc->address; | |
a6d9a66e | 6781 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6782 | |
939c61fa JK |
6783 | /* Software breakpoints unsupported? */ |
6784 | if (brk == NULL) | |
6785 | return 0; | |
6786 | ||
514f746b AR |
6787 | target_mem = alloca (len); |
6788 | ||
939c61fa JK |
6789 | /* Enable the automatic memory restoration from breakpoints while |
6790 | we read the memory. Otherwise we could say about our temporary | |
6791 | breakpoints they are permanent. */ | |
6c95b8df PA |
6792 | cleanup = save_current_space_and_thread (); |
6793 | ||
6794 | switch_to_program_space_and_thread (loc->pspace); | |
6795 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6796 | |
514f746b AR |
6797 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6798 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6799 | retval = 1; |
514f746b | 6800 | |
939c61fa JK |
6801 | do_cleanups (cleanup); |
6802 | ||
6803 | return retval; | |
514f746b AR |
6804 | } |
6805 | ||
6806 | ||
c3f6f71d | 6807 | |
018d34a4 VP |
6808 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6809 | as textual description of the location, and COND_STRING | |
db107f19 | 6810 | as condition expression. */ |
018d34a4 VP |
6811 | |
6812 | static void | |
8cdf0e15 VP |
6813 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6814 | struct symtabs_and_lines sals, char *addr_string, | |
6815 | char *cond_string, | |
6816 | enum bptype type, enum bpdisp disposition, | |
6817 | int thread, int task, int ignore_count, | |
6818 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6819 | { |
0d381245 VP |
6820 | struct breakpoint *b = NULL; |
6821 | int i; | |
018d34a4 VP |
6822 | |
6823 | if (type == bp_hardware_breakpoint) | |
6824 | { | |
6825 | int i = hw_breakpoint_used_count (); | |
6826 | int target_resources_ok = | |
d92524f1 | 6827 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6828 | i + 1, 0); |
6829 | if (target_resources_ok == 0) | |
6830 | error (_("No hardware breakpoint support in the target.")); | |
6831 | else if (target_resources_ok < 0) | |
6832 | error (_("Hardware breakpoints used exceeds limit.")); | |
6833 | } | |
6834 | ||
6c95b8df PA |
6835 | gdb_assert (sals.nelts > 0); |
6836 | ||
0d381245 VP |
6837 | for (i = 0; i < sals.nelts; ++i) |
6838 | { | |
6839 | struct symtab_and_line sal = sals.sals[i]; | |
6840 | struct bp_location *loc; | |
6841 | ||
6842 | if (from_tty) | |
5af949e3 UW |
6843 | { |
6844 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6845 | if (!loc_gdbarch) | |
6846 | loc_gdbarch = gdbarch; | |
6847 | ||
6848 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6849 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6850 | } |
0d381245 VP |
6851 | |
6852 | if (i == 0) | |
6853 | { | |
a6d9a66e | 6854 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6855 | set_breakpoint_count (breakpoint_count + 1); |
6856 | b->number = breakpoint_count; | |
6857 | b->thread = thread; | |
4a306c9a | 6858 | b->task = task; |
018d34a4 | 6859 | |
0d381245 VP |
6860 | b->cond_string = cond_string; |
6861 | b->ignore_count = ignore_count; | |
41447f92 | 6862 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6863 | b->disposition = disposition; |
018d34a4 | 6864 | |
6c95b8df PA |
6865 | b->pspace = sals.sals[0].pspace; |
6866 | ||
6867 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6868 | && (b->type == bp_breakpoint |
6869 | || b->type == bp_hardware_breakpoint)) | |
6870 | b->enable_state = bp_startup_disabled; | |
6871 | ||
0d381245 VP |
6872 | loc = b->loc; |
6873 | } | |
6874 | else | |
018d34a4 | 6875 | { |
39d61571 | 6876 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6877 | } |
6878 | ||
514f746b AR |
6879 | if (bp_loc_is_permanent (loc)) |
6880 | make_breakpoint_permanent (b); | |
6881 | ||
0d381245 VP |
6882 | if (b->cond_string) |
6883 | { | |
6884 | char *arg = b->cond_string; | |
d32a6982 | 6885 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6886 | if (*arg) |
db107f19 | 6887 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6888 | } |
0d381245 | 6889 | } |
018d34a4 VP |
6890 | |
6891 | if (addr_string) | |
6892 | b->addr_string = addr_string; | |
6893 | else | |
6894 | /* addr_string has to be used or breakpoint_re_set will delete | |
6895 | me. */ | |
5af949e3 UW |
6896 | b->addr_string |
6897 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6898 | |
604133b5 | 6899 | b->ops = ops; |
018d34a4 VP |
6900 | mention (b); |
6901 | } | |
6902 | ||
ed0616c6 VP |
6903 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6904 | elements to fill the void space. */ | |
2c0b251b PA |
6905 | static void |
6906 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6907 | { |
6908 | int i = index_to_remove+1; | |
6909 | int last_index = sal->nelts-1; | |
6910 | ||
6911 | for (;i <= last_index; ++i) | |
6912 | sal->sals[i-1] = sal->sals[i]; | |
6913 | ||
6914 | --(sal->nelts); | |
6915 | } | |
6916 | ||
6c95b8df PA |
6917 | /* If appropriate, obtains all sals that correspond to the same file |
6918 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6919 | will want to set a breakpoint at foo.c:line, and not really care | |
6920 | about program spaces. This is done only if SAL does not have | |
6921 | explicit PC and has line and file information. If we got just a | |
6922 | single expanded sal, return the original. | |
ed0616c6 | 6923 | |
6c95b8df PA |
6924 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6925 | which the name of enclosing function is different from SAL. This | |
6926 | makes sure that if we have breakpoint originally set in template | |
6927 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6928 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6929 | |
2c0b251b | 6930 | static struct symtabs_and_lines |
ed0616c6 VP |
6931 | expand_line_sal_maybe (struct symtab_and_line sal) |
6932 | { | |
6933 | struct symtabs_and_lines expanded; | |
6934 | CORE_ADDR original_pc = sal.pc; | |
6935 | char *original_function = NULL; | |
6936 | int found; | |
6937 | int i; | |
6c95b8df | 6938 | struct cleanup *old_chain; |
ed0616c6 VP |
6939 | |
6940 | /* If we have explicit pc, don't expand. | |
6941 | If we have no line number, we can't expand. */ | |
6942 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6943 | { | |
6944 | expanded.nelts = 1; | |
6945 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6946 | expanded.sals[0] = sal; | |
6947 | return expanded; | |
6948 | } | |
6949 | ||
6950 | sal.pc = 0; | |
6c95b8df PA |
6951 | |
6952 | old_chain = save_current_space_and_thread (); | |
6953 | ||
6954 | switch_to_program_space_and_thread (sal.pspace); | |
6955 | ||
ed0616c6 | 6956 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6957 | |
6958 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6959 | expanded = expand_line_sal (sal); |
6c95b8df | 6960 | |
ed0616c6 VP |
6961 | if (expanded.nelts == 1) |
6962 | { | |
3dba1c98 JB |
6963 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6964 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6965 | xfree (expanded.sals); |
6966 | expanded.nelts = 1; | |
6967 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6968 | sal.pc = original_pc; | |
6969 | expanded.sals[0] = sal; | |
3dba1c98 | 6970 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6971 | do_cleanups (old_chain); |
ed0616c6 VP |
6972 | return expanded; |
6973 | } | |
6974 | ||
6975 | if (!sal.explicit_line) | |
6976 | { | |
6977 | CORE_ADDR func_addr, func_end; | |
6978 | for (i = 0; i < expanded.nelts; ++i) | |
6979 | { | |
6980 | CORE_ADDR pc = expanded.sals[i].pc; | |
6981 | char *this_function; | |
6c95b8df PA |
6982 | |
6983 | /* We need to switch threads as well since we're about to | |
6984 | read memory. */ | |
6985 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6986 | ||
ed0616c6 VP |
6987 | if (find_pc_partial_function (pc, &this_function, |
6988 | &func_addr, &func_end)) | |
6989 | { | |
059fb39f PM |
6990 | if (this_function |
6991 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6992 | { |
6993 | remove_sal (&expanded, i); | |
6994 | --i; | |
6995 | } | |
ed0616c6 VP |
6996 | } |
6997 | } | |
6998 | } | |
059acae7 UW |
6999 | |
7000 | /* Skip the function prologue if necessary. */ | |
7001 | for (i = 0; i < expanded.nelts; ++i) | |
7002 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7003 | |
6c95b8df PA |
7004 | do_cleanups (old_chain); |
7005 | ||
ed0616c6 VP |
7006 | if (expanded.nelts <= 1) |
7007 | { | |
7008 | /* This is un ugly workaround. If we get zero | |
7009 | expanded sals then something is really wrong. | |
7010 | Fix that by returnign the original sal. */ | |
7011 | xfree (expanded.sals); | |
7012 | expanded.nelts = 1; | |
7013 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7014 | sal.pc = original_pc; | |
7015 | expanded.sals[0] = sal; | |
7016 | return expanded; | |
7017 | } | |
7018 | ||
7019 | if (original_pc) | |
7020 | { | |
7021 | found = 0; | |
7022 | for (i = 0; i < expanded.nelts; ++i) | |
7023 | if (expanded.sals[i].pc == original_pc) | |
7024 | { | |
7025 | found = 1; | |
7026 | break; | |
7027 | } | |
7028 | gdb_assert (found); | |
7029 | } | |
7030 | ||
7031 | return expanded; | |
7032 | } | |
7033 | ||
018d34a4 VP |
7034 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7035 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7036 | value. COND_STRING, if not NULL, specified the condition to be | |
7037 | used for all breakpoints. Essentially the only case where | |
7038 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7039 | function. In that case, it's still not possible to specify | |
7040 | separate conditions for different overloaded functions, so | |
7041 | we take just a single condition string. | |
7042 | ||
c3f6f71d | 7043 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7044 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7045 | array contents). If the function fails (error() is called), the |
7046 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
7047 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
7048 | |
7049 | static void | |
8cdf0e15 VP |
7050 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7051 | struct symtabs_and_lines sals, char **addr_string, | |
7052 | char *cond_string, | |
7053 | enum bptype type, enum bpdisp disposition, | |
7054 | int thread, int task, int ignore_count, | |
7055 | struct breakpoint_ops *ops, int from_tty, | |
7056 | int enabled) | |
c906108c | 7057 | { |
018d34a4 VP |
7058 | int i; |
7059 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 7060 | { |
ed0616c6 VP |
7061 | struct symtabs_and_lines expanded = |
7062 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7063 | |
8cdf0e15 VP |
7064 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7065 | cond_string, type, disposition, | |
7066 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7067 | } |
c3f6f71d | 7068 | } |
c906108c | 7069 | |
c3f6f71d JM |
7070 | /* Parse ARG which is assumed to be a SAL specification possibly |
7071 | followed by conditionals. On return, SALS contains an array of SAL | |
7072 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7073 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7074 | |
b9362cc7 | 7075 | static void |
c3f6f71d JM |
7076 | parse_breakpoint_sals (char **address, |
7077 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7078 | char ***addr_string, |
7079 | int *not_found_ptr) | |
c3f6f71d JM |
7080 | { |
7081 | char *addr_start = *address; | |
7082 | *addr_string = NULL; | |
7083 | /* If no arg given, or if first arg is 'if ', use the default | |
7084 | breakpoint. */ | |
7085 | if ((*address) == NULL | |
7086 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7087 | { |
7088 | if (default_breakpoint_valid) | |
7089 | { | |
c3f6f71d | 7090 | struct symtab_and_line sal; |
fe39c653 | 7091 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7092 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7093 | xmalloc (sizeof (struct symtab_and_line)); |
7094 | sal.pc = default_breakpoint_address; | |
7095 | sal.line = default_breakpoint_line; | |
7096 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7097 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7098 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7099 | |
7100 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7101 | the default_breakpoint_address. So make sure to set | |
7102 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7103 | sals to include all other instances with the same symtab and line. | |
7104 | */ | |
7105 | sal.explicit_pc = 1; | |
7106 | ||
c3f6f71d JM |
7107 | sals->sals[0] = sal; |
7108 | sals->nelts = 1; | |
c906108c SS |
7109 | } |
7110 | else | |
8a3fe4f8 | 7111 | error (_("No default breakpoint address now.")); |
c906108c SS |
7112 | } |
7113 | else | |
7114 | { | |
c906108c | 7115 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7116 | current_source_symtab (which is decode_line_1's default). This |
7117 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7118 | leaving default_breakpoint_* alone. |
7119 | ObjC: However, don't match an Objective-C method name which | |
7120 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7121 | |
c214a6fd | 7122 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7123 | |
c906108c | 7124 | if (default_breakpoint_valid |
0378c332 | 7125 | && (!cursal.symtab |
1aeae86e AF |
7126 | || ((strchr ("+-", (*address)[0]) != NULL) |
7127 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7128 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7129 | default_breakpoint_line, addr_string, |
7130 | not_found_ptr); | |
c906108c | 7131 | else |
0101ce28 JJ |
7132 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7133 | addr_string, not_found_ptr); | |
c906108c | 7134 | } |
c3f6f71d JM |
7135 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7136 | if (sals->nelts > 0 && *addr_string == NULL) | |
7137 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7138 | if (addr_start != (*address)) | |
c906108c | 7139 | { |
c3f6f71d JM |
7140 | int i; |
7141 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 7142 | { |
c3f6f71d JM |
7143 | /* Add the string if not present. */ |
7144 | if ((*addr_string)[i] == NULL) | |
7145 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
7146 | } |
7147 | } | |
c3f6f71d | 7148 | } |
c906108c | 7149 | |
c906108c | 7150 | |
c3f6f71d JM |
7151 | /* Convert each SAL into a real PC. Verify that the PC can be |
7152 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7153 | |
b9362cc7 | 7154 | static void |
c3f6f71d JM |
7155 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
7156 | char *address) | |
7157 | { | |
7158 | int i; | |
7159 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 7160 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7161 | } |
7162 | ||
7a697b8d SS |
7163 | /* Fast tracepoints may have restrictions on valid locations. For |
7164 | instance, a fast tracepoint using a jump instead of a trap will | |
7165 | likely have to overwrite more bytes than a trap would, and so can | |
7166 | only be placed where the instruction is longer than the jump, or a | |
7167 | multi-instruction sequence does not have a jump into the middle of | |
7168 | it, etc. */ | |
7169 | ||
7170 | static void | |
7171 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7172 | struct symtabs_and_lines *sals) | |
7173 | { | |
7174 | int i, rslt; | |
7175 | struct symtab_and_line *sal; | |
7176 | char *msg; | |
7177 | struct cleanup *old_chain; | |
7178 | ||
7179 | for (i = 0; i < sals->nelts; i++) | |
7180 | { | |
7181 | sal = &sals->sals[i]; | |
7182 | ||
7183 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7184 | NULL, &msg); | |
7185 | old_chain = make_cleanup (xfree, msg); | |
7186 | ||
7187 | if (!rslt) | |
7188 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7189 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7190 | ||
7191 | do_cleanups (old_chain); | |
7192 | } | |
7193 | } | |
7194 | ||
05ff989b | 7195 | static void |
0101ce28 JJ |
7196 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7197 | { | |
7198 | struct captured_parse_breakpoint_args *args = data; | |
7199 | ||
7200 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7201 | args->not_found_ptr); | |
0101ce28 JJ |
7202 | } |
7203 | ||
018d34a4 VP |
7204 | /* Given TOK, a string specification of condition and thread, as |
7205 | accepted by the 'break' command, extract the condition | |
7206 | string and thread number and set *COND_STRING and *THREAD. | |
7207 | PC identifies the context at which the condition should be parsed. | |
7208 | If no condition is found, *COND_STRING is set to NULL. | |
7209 | If no thread is found, *THREAD is set to -1. */ | |
7210 | static void | |
7211 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7212 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7213 | { |
7214 | *cond_string = NULL; | |
7215 | *thread = -1; | |
7216 | while (tok && *tok) | |
7217 | { | |
7218 | char *end_tok; | |
7219 | int toklen; | |
7220 | char *cond_start = NULL; | |
7221 | char *cond_end = NULL; | |
7222 | while (*tok == ' ' || *tok == '\t') | |
7223 | tok++; | |
7224 | ||
7225 | end_tok = tok; | |
7226 | ||
7227 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7228 | end_tok++; | |
7229 | ||
7230 | toklen = end_tok - tok; | |
7231 | ||
7232 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7233 | { | |
f7545552 TT |
7234 | struct expression *expr; |
7235 | ||
018d34a4 | 7236 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7237 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7238 | xfree (expr); | |
018d34a4 VP |
7239 | cond_end = tok; |
7240 | *cond_string = savestring (cond_start, | |
7241 | cond_end - cond_start); | |
7242 | } | |
7243 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7244 | { | |
7245 | char *tmptok; | |
7246 | ||
7247 | tok = end_tok + 1; | |
7248 | tmptok = tok; | |
7249 | *thread = strtol (tok, &tok, 0); | |
7250 | if (tok == tmptok) | |
7251 | error (_("Junk after thread keyword.")); | |
7252 | if (!valid_thread_id (*thread)) | |
7253 | error (_("Unknown thread %d."), *thread); | |
7254 | } | |
4a306c9a JB |
7255 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7256 | { | |
7257 | char *tmptok; | |
7258 | ||
7259 | tok = end_tok + 1; | |
7260 | tmptok = tok; | |
7261 | *task = strtol (tok, &tok, 0); | |
7262 | if (tok == tmptok) | |
7263 | error (_("Junk after task keyword.")); | |
7264 | if (!valid_task_id (*task)) | |
b6199126 | 7265 | error (_("Unknown task %d."), *task); |
4a306c9a | 7266 | } |
018d34a4 VP |
7267 | else |
7268 | error (_("Junk at end of arguments.")); | |
7269 | } | |
7270 | } | |
7271 | ||
fd9b8c24 PA |
7272 | /* Set a breakpoint. This function is shared between CLI and MI |
7273 | functions for setting a breakpoint. This function has two major | |
7274 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7275 | parameter. If non-zero, the function will parse arg, extracting | |
7276 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7277 | location of breakpoint, with condition and thread specified by the | |
7278 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7279 | was created; false otherwise. */ | |
0101ce28 | 7280 | |
8cdf0e15 VP |
7281 | int |
7282 | create_breakpoint (struct gdbarch *gdbarch, | |
7283 | char *arg, char *cond_string, int thread, | |
7284 | int parse_condition_and_thread, | |
7285 | int tempflag, int hardwareflag, int traceflag, | |
7286 | int ignore_count, | |
7287 | enum auto_boolean pending_break_support, | |
7288 | struct breakpoint_ops *ops, | |
7289 | int from_tty, | |
7290 | int enabled) | |
c3f6f71d | 7291 | { |
71fff37b | 7292 | struct gdb_exception e; |
c3f6f71d | 7293 | struct symtabs_and_lines sals; |
0101ce28 | 7294 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
7295 | char *copy_arg; |
7296 | char *err_msg; | |
c3f6f71d JM |
7297 | char *addr_start = arg; |
7298 | char **addr_string; | |
7299 | struct cleanup *old_chain; | |
80c99de1 | 7300 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7301 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7302 | int i; |
0101ce28 | 7303 | int pending = 0; |
0101ce28 | 7304 | int not_found = 0; |
1042e4c0 | 7305 | enum bptype type_wanted; |
4a306c9a | 7306 | int task = 0; |
86b17b60 | 7307 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7308 | |
c3f6f71d JM |
7309 | sals.sals = NULL; |
7310 | sals.nelts = 0; | |
7311 | addr_string = NULL; | |
c3f6f71d | 7312 | |
0101ce28 JJ |
7313 | parse_args.arg_p = &arg; |
7314 | parse_args.sals_p = &sals; | |
7315 | parse_args.addr_string_p = &addr_string; | |
7316 | parse_args.not_found_ptr = ¬_found; | |
7317 | ||
05ff989b AC |
7318 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7319 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7320 | |
7321 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7322 | switch (e.reason) |
0101ce28 | 7323 | { |
05ff989b | 7324 | case RETURN_QUIT: |
98deb0da | 7325 | throw_exception (e); |
05ff989b AC |
7326 | case RETURN_ERROR: |
7327 | switch (e.error) | |
0101ce28 | 7328 | { |
05ff989b | 7329 | case NOT_FOUND_ERROR: |
0101ce28 | 7330 | |
05ff989b AC |
7331 | /* If pending breakpoint support is turned off, throw |
7332 | error. */ | |
fa8d40ab JJ |
7333 | |
7334 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7335 | throw_exception (e); |
7336 | ||
7337 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7338 | |
05ff989b AC |
7339 | /* If pending breakpoint support is auto query and the user |
7340 | selects no, then simply return the error code. */ | |
059fb39f PM |
7341 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7342 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7343 | return 0; |
fa8d40ab | 7344 | |
05ff989b AC |
7345 | /* At this point, either the user was queried about setting |
7346 | a pending breakpoint and selected yes, or pending | |
7347 | breakpoint behavior is on and thus a pending breakpoint | |
7348 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7349 | copy_arg = xstrdup (addr_start); |
7350 | addr_string = ©_arg; | |
7351 | sals.nelts = 1; | |
7352 | sals.sals = &pending_sal; | |
7353 | pending_sal.pc = 0; | |
7354 | pending = 1; | |
05ff989b AC |
7355 | break; |
7356 | default: | |
98deb0da | 7357 | throw_exception (e); |
0101ce28 | 7358 | } |
05ff989b AC |
7359 | default: |
7360 | if (!sals.nelts) | |
fd9b8c24 | 7361 | return 0; |
0101ce28 | 7362 | } |
c3f6f71d JM |
7363 | |
7364 | /* Create a chain of things that always need to be cleaned up. */ | |
7365 | old_chain = make_cleanup (null_cleanup, 0); | |
7366 | ||
0101ce28 JJ |
7367 | if (!pending) |
7368 | { | |
7369 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7370 | make_cleanup (xfree, sals.sals); | |
7371 | ||
7372 | /* Cleanup the addr_string array but not its contents. */ | |
7373 | make_cleanup (xfree, addr_string); | |
7374 | } | |
c3f6f71d | 7375 | |
c3f6f71d JM |
7376 | /* ----------------------------- SNIP ----------------------------- |
7377 | Anything added to the cleanup chain beyond this point is assumed | |
7378 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7379 | then the memory is not reclaimed. */ |
7380 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7381 | |
7382 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7383 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7384 | for (i = 0; i < sals.nelts; i++) |
7385 | { | |
7386 | if (addr_string[i] != NULL) | |
b8c9b27d | 7387 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7388 | } |
7389 | ||
7390 | /* Resolve all line numbers to PC's and verify that the addresses | |
7391 | are ok for the target. */ | |
0101ce28 JJ |
7392 | if (!pending) |
7393 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 7394 | |
1042e4c0 | 7395 | type_wanted = (traceflag |
7a697b8d | 7396 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
7397 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
7398 | ||
7a697b8d SS |
7399 | /* Fast tracepoints may have additional restrictions on location. */ |
7400 | if (type_wanted == bp_fast_tracepoint) | |
7401 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7402 | ||
c3f6f71d JM |
7403 | /* Verify that condition can be parsed, before setting any |
7404 | breakpoints. Allocate a separate condition expression for each | |
7405 | breakpoint. */ | |
0101ce28 | 7406 | if (!pending) |
c3f6f71d | 7407 | { |
2f069f6f | 7408 | if (parse_condition_and_thread) |
72b2ff0e VP |
7409 | { |
7410 | /* Here we only parse 'arg' to separate condition | |
7411 | from thread number, so parsing in context of first | |
7412 | sal is OK. When setting the breakpoint we'll | |
7413 | re-parse it in context of each sal. */ | |
7414 | cond_string = NULL; | |
7415 | thread = -1; | |
4a306c9a JB |
7416 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7417 | &thread, &task); | |
72b2ff0e VP |
7418 | if (cond_string) |
7419 | make_cleanup (xfree, cond_string); | |
7420 | } | |
2f069f6f | 7421 | else |
72b2ff0e VP |
7422 | { |
7423 | /* Create a private copy of condition string. */ | |
7424 | if (cond_string) | |
7425 | { | |
7426 | cond_string = xstrdup (cond_string); | |
7427 | make_cleanup (xfree, cond_string); | |
7428 | } | |
7429 | } | |
8cdf0e15 VP |
7430 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
7431 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7432 | thread, task, ignore_count, ops, from_tty, | |
7433 | enabled); | |
c906108c | 7434 | } |
0101ce28 JJ |
7435 | else |
7436 | { | |
fe3f5fa8 | 7437 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7438 | struct breakpoint *b; |
7439 | ||
0101ce28 JJ |
7440 | make_cleanup (xfree, copy_arg); |
7441 | ||
a6d9a66e | 7442 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7443 | set_breakpoint_count (breakpoint_count + 1); |
7444 | b->number = breakpoint_count; | |
72b2ff0e | 7445 | b->thread = -1; |
018d34a4 | 7446 | b->addr_string = addr_string[0]; |
72b2ff0e | 7447 | b->cond_string = NULL; |
0101ce28 | 7448 | b->ignore_count = ignore_count; |
0101ce28 | 7449 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7450 | b->condition_not_parsed = 1; |
604133b5 | 7451 | b->ops = ops; |
41447f92 | 7452 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7453 | b->pspace = current_program_space; |
74960c60 | 7454 | |
6c95b8df | 7455 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7456 | && (b->type == bp_breakpoint |
7457 | || b->type == bp_hardware_breakpoint)) | |
7458 | b->enable_state = bp_startup_disabled; | |
7459 | ||
0101ce28 JJ |
7460 | mention (b); |
7461 | } | |
7462 | ||
c3f6f71d | 7463 | if (sals.nelts > 1) |
95a42b64 TT |
7464 | { |
7465 | warning (_("Multiple breakpoints were set.\n" | |
7466 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7467 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7468 | } |
7469 | ||
80c99de1 PA |
7470 | /* That's it. Discard the cleanups for data inserted into the |
7471 | breakpoint. */ | |
7472 | discard_cleanups (bkpt_chain); | |
7473 | /* But cleanup everything else. */ | |
c3f6f71d | 7474 | do_cleanups (old_chain); |
217dc9e2 | 7475 | |
80c99de1 | 7476 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7477 | update_global_location_list (1); |
fd9b8c24 PA |
7478 | |
7479 | return 1; | |
c3f6f71d | 7480 | } |
c906108c | 7481 | |
72b2ff0e VP |
7482 | /* Set a breakpoint. |
7483 | ARG is a string describing breakpoint address, | |
7484 | condition, and thread. | |
7485 | FLAG specifies if a breakpoint is hardware on, | |
7486 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7487 | and BP_TEMPFLAG. */ | |
7488 | ||
98deb0da | 7489 | static void |
72b2ff0e | 7490 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7491 | { |
72b2ff0e VP |
7492 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7493 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7494 | |
8cdf0e15 VP |
7495 | create_breakpoint (get_current_arch (), |
7496 | arg, | |
7497 | NULL, 0, 1 /* parse arg */, | |
7498 | tempflag, hardwareflag, 0 /* traceflag */, | |
7499 | 0 /* Ignore count */, | |
7500 | pending_break_support, | |
7501 | NULL /* breakpoint_ops */, | |
7502 | from_tty, | |
7503 | 1 /* enabled */); | |
c906108c SS |
7504 | } |
7505 | ||
72b2ff0e | 7506 | |
c3f6f71d | 7507 | |
c906108c SS |
7508 | /* Helper function for break_command_1 and disassemble_command. */ |
7509 | ||
7510 | void | |
fba45db2 | 7511 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7512 | { |
7513 | CORE_ADDR pc; | |
7514 | ||
7515 | if (sal->pc == 0 && sal->symtab != NULL) | |
7516 | { | |
7517 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7518 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7519 | sal->line, sal->symtab->filename); |
7520 | sal->pc = pc; | |
6a048695 JB |
7521 | |
7522 | /* If this SAL corresponds to a breakpoint inserted using | |
7523 | a line number, then skip the function prologue if necessary. */ | |
7524 | if (sal->explicit_line) | |
059acae7 | 7525 | skip_prologue_sal (sal); |
c906108c SS |
7526 | } |
7527 | ||
7528 | if (sal->section == 0 && sal->symtab != NULL) | |
7529 | { | |
7530 | struct blockvector *bv; | |
c5aa993b JM |
7531 | struct block *b; |
7532 | struct symbol *sym; | |
c906108c | 7533 | |
801e3a5b | 7534 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7535 | if (bv != NULL) |
7536 | { | |
7f0df278 | 7537 | sym = block_linkage_function (b); |
c906108c SS |
7538 | if (sym != NULL) |
7539 | { | |
7540 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7541 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7542 | } |
7543 | else | |
7544 | { | |
7545 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7546 | have to look harder. This case can be executed if we have |
7547 | line numbers but no functions (as can happen in assembly | |
7548 | source). */ | |
c906108c | 7549 | |
c5aa993b | 7550 | struct minimal_symbol *msym; |
6c95b8df PA |
7551 | struct cleanup *old_chain = save_current_space_and_thread (); |
7552 | ||
7553 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7554 | |
7555 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7556 | if (msym) | |
714835d5 | 7557 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7558 | |
7559 | do_cleanups (old_chain); | |
c906108c SS |
7560 | } |
7561 | } | |
7562 | } | |
7563 | } | |
7564 | ||
7565 | void | |
fba45db2 | 7566 | break_command (char *arg, int from_tty) |
c906108c | 7567 | { |
db107f19 | 7568 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7569 | } |
7570 | ||
c906108c | 7571 | void |
fba45db2 | 7572 | tbreak_command (char *arg, int from_tty) |
c906108c | 7573 | { |
db107f19 | 7574 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7575 | } |
7576 | ||
c906108c | 7577 | static void |
fba45db2 | 7578 | hbreak_command (char *arg, int from_tty) |
c906108c | 7579 | { |
db107f19 | 7580 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7581 | } |
7582 | ||
7583 | static void | |
fba45db2 | 7584 | thbreak_command (char *arg, int from_tty) |
c906108c | 7585 | { |
db107f19 | 7586 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7587 | } |
7588 | ||
7589 | static void | |
fba45db2 | 7590 | stop_command (char *arg, int from_tty) |
c906108c | 7591 | { |
a3f17187 | 7592 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7593 | Usage: stop in <function | address>\n\ |
a3f17187 | 7594 | stop at <line>\n")); |
c906108c SS |
7595 | } |
7596 | ||
7597 | static void | |
fba45db2 | 7598 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7599 | { |
7600 | int badInput = 0; | |
7601 | ||
c5aa993b | 7602 | if (arg == (char *) NULL) |
c906108c SS |
7603 | badInput = 1; |
7604 | else if (*arg != '*') | |
7605 | { | |
7606 | char *argptr = arg; | |
7607 | int hasColon = 0; | |
7608 | ||
53a5351d JM |
7609 | /* look for a ':'. If this is a line number specification, then |
7610 | say it is bad, otherwise, it should be an address or | |
7611 | function/method name */ | |
c906108c | 7612 | while (*argptr && !hasColon) |
c5aa993b JM |
7613 | { |
7614 | hasColon = (*argptr == ':'); | |
7615 | argptr++; | |
7616 | } | |
c906108c SS |
7617 | |
7618 | if (hasColon) | |
c5aa993b | 7619 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7620 | else |
c5aa993b | 7621 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7622 | } |
7623 | ||
7624 | if (badInput) | |
a3f17187 | 7625 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7626 | else |
db107f19 | 7627 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7628 | } |
7629 | ||
7630 | static void | |
fba45db2 | 7631 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7632 | { |
7633 | int badInput = 0; | |
7634 | ||
c5aa993b | 7635 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7636 | badInput = 1; |
7637 | else | |
7638 | { | |
7639 | char *argptr = arg; | |
7640 | int hasColon = 0; | |
7641 | ||
7642 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7643 | it is probably a line number. */ |
c906108c | 7644 | while (*argptr && !hasColon) |
c5aa993b JM |
7645 | { |
7646 | hasColon = (*argptr == ':'); | |
7647 | argptr++; | |
7648 | } | |
c906108c SS |
7649 | |
7650 | if (hasColon) | |
c5aa993b | 7651 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7652 | else |
c5aa993b | 7653 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7654 | } |
7655 | ||
7656 | if (badInput) | |
a3f17187 | 7657 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7658 | else |
db107f19 | 7659 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7660 | } |
7661 | ||
53a5351d JM |
7662 | /* accessflag: hw_write: watch write, |
7663 | hw_read: watch read, | |
7664 | hw_access: watch access (read or write) */ | |
c906108c | 7665 | static void |
fba45db2 | 7666 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7667 | { |
a6d9a66e | 7668 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7669 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7670 | struct expression *exp; |
60e1c644 | 7671 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7672 | struct value *val, *mark; |
7673 | struct frame_info *frame; | |
c906108c SS |
7674 | char *exp_start = NULL; |
7675 | char *exp_end = NULL; | |
37e4754d | 7676 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7677 | int toklen; |
7678 | char *cond_start = NULL; | |
7679 | char *cond_end = NULL; | |
c906108c SS |
7680 | int i, other_type_used, target_resources_ok = 0; |
7681 | enum bptype bp_type; | |
7682 | int mem_cnt = 0; | |
37e4754d | 7683 | int thread = -1; |
c906108c | 7684 | |
37e4754d LM |
7685 | /* Make sure that we actually have parameters to parse. */ |
7686 | if (arg != NULL && arg[0] != '\0') | |
7687 | { | |
7688 | toklen = strlen (arg); /* Size of argument list. */ | |
7689 | ||
7690 | /* Points tok to the end of the argument list. */ | |
7691 | tok = arg + toklen - 1; | |
7692 | ||
7693 | /* Go backwards in the parameters list. Skip the last parameter. | |
7694 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7695 | be the thread identifier. */ | |
7696 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7697 | tok--; | |
7698 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7699 | tok--; | |
7700 | ||
7701 | /* Points end_tok to the beginning of the last token. */ | |
7702 | id_tok_start = tok + 1; | |
7703 | ||
7704 | /* Go backwards in the parameters list. Skip one more parameter. | |
7705 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7706 | reach a "thread" token. */ | |
7707 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7708 | tok--; | |
7709 | ||
7710 | end_tok = tok; | |
7711 | ||
7712 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7713 | tok--; | |
7714 | ||
7715 | /* Move the pointer forward to skip the whitespace and | |
7716 | calculate the length of the token. */ | |
7717 | tok++; | |
7718 | toklen = end_tok - tok; | |
7719 | ||
7720 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7721 | { | |
7722 | /* At this point we've found a "thread" token, which means | |
7723 | the user is trying to set a watchpoint that triggers | |
7724 | only in a specific thread. */ | |
7725 | char *endp; | |
7726 | ||
7727 | /* Extract the thread ID from the next token. */ | |
7728 | thread = strtol (id_tok_start, &endp, 0); | |
7729 | ||
7730 | /* Check if the user provided a valid numeric value for the | |
7731 | thread ID. */ | |
7732 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7733 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7734 | ||
7735 | /* Check if the thread actually exists. */ | |
7736 | if (!valid_thread_id (thread)) | |
7737 | error (_("Unknown thread %d."), thread); | |
7738 | ||
7739 | /* Truncate the string and get rid of the thread <thread_num> | |
7740 | parameter before the parameter list is parsed by the | |
7741 | evaluate_expression() function. */ | |
7742 | *tok = '\0'; | |
7743 | } | |
7744 | } | |
7745 | ||
7746 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7747 | innermost_block = NULL; |
7748 | exp_start = arg; | |
7749 | exp = parse_exp_1 (&arg, 0, 0); | |
7750 | exp_end = arg; | |
fa8a61dc TT |
7751 | /* Remove trailing whitespace from the expression before saving it. |
7752 | This makes the eventual display of the expression string a bit | |
7753 | prettier. */ | |
7754 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7755 | --exp_end; | |
7756 | ||
c906108c SS |
7757 | exp_valid_block = innermost_block; |
7758 | mark = value_mark (); | |
fa4727a6 DJ |
7759 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7760 | if (val != NULL) | |
7761 | release_value (val); | |
c906108c SS |
7762 | |
7763 | tok = arg; | |
7764 | while (*tok == ' ' || *tok == '\t') | |
7765 | tok++; | |
7766 | end_tok = tok; | |
7767 | ||
7768 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7769 | end_tok++; | |
7770 | ||
7771 | toklen = end_tok - tok; | |
7772 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7773 | { | |
2d134ed3 PA |
7774 | struct expression *cond; |
7775 | ||
60e1c644 | 7776 | innermost_block = NULL; |
c906108c SS |
7777 | tok = cond_start = end_tok + 1; |
7778 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
7779 | |
7780 | /* The watchpoint expression may not be local, but the condition | |
7781 | may still be. E.g.: `watch global if local > 0'. */ | |
7782 | cond_exp_valid_block = innermost_block; | |
7783 | ||
2d134ed3 | 7784 | xfree (cond); |
c906108c SS |
7785 | cond_end = tok; |
7786 | } | |
7787 | if (*tok) | |
8a3fe4f8 | 7788 | error (_("Junk at end of command.")); |
c906108c | 7789 | |
53a5351d | 7790 | if (accessflag == hw_read) |
c5aa993b | 7791 | bp_type = bp_read_watchpoint; |
53a5351d | 7792 | else if (accessflag == hw_access) |
c5aa993b JM |
7793 | bp_type = bp_access_watchpoint; |
7794 | else | |
7795 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7796 | |
7797 | mem_cnt = can_use_hardware_watchpoint (val); | |
7798 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7799 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7800 | if (mem_cnt != 0) |
7801 | { | |
7802 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7803 | target_resources_ok = |
d92524f1 | 7804 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7805 | other_type_used); |
c5aa993b | 7806 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7807 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7808 | |
c5aa993b | 7809 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7810 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7811 | } |
c906108c | 7812 | |
4d28f7a8 KB |
7813 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7814 | watchpoint could not be set. */ | |
7815 | if (!mem_cnt || target_resources_ok <= 0) | |
7816 | bp_type = bp_watchpoint; | |
7817 | ||
d983da9c | 7818 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7819 | |
7820 | /* If the expression is "local", then set up a "watchpoint scope" | |
7821 | breakpoint at the point where we've left the scope of the watchpoint | |
7822 | expression. Create the scope breakpoint before the watchpoint, so | |
7823 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 7824 | if (exp_valid_block && frame) |
d983da9c | 7825 | { |
edb3359d DJ |
7826 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7827 | { | |
7828 | scope_breakpoint | |
a6d9a66e UW |
7829 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7830 | frame_unwind_caller_pc (frame), | |
edb3359d | 7831 | bp_watchpoint_scope); |
d983da9c | 7832 | |
edb3359d | 7833 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7834 | |
edb3359d DJ |
7835 | /* Automatically delete the breakpoint when it hits. */ |
7836 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7837 | |
edb3359d DJ |
7838 | /* Only break in the proper frame (help with recursion). */ |
7839 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7840 | |
edb3359d | 7841 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7842 | scope_breakpoint->loc->gdbarch |
7843 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7844 | scope_breakpoint->loc->requested_address |
7845 | = frame_unwind_caller_pc (frame); | |
7846 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7847 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7848 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7849 | scope_breakpoint->type); |
7850 | } | |
d983da9c DJ |
7851 | } |
7852 | ||
c906108c | 7853 | /* Now set up the breakpoint. */ |
2d134ed3 | 7854 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7855 | set_breakpoint_count (breakpoint_count + 1); |
7856 | b->number = breakpoint_count; | |
37e4754d | 7857 | b->thread = thread; |
b5de0fa7 | 7858 | b->disposition = disp_donttouch; |
c906108c SS |
7859 | b->exp = exp; |
7860 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 7861 | b->cond_exp_valid_block = cond_exp_valid_block; |
c906108c SS |
7862 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
7863 | b->val = val; | |
fa4727a6 | 7864 | b->val_valid = 1; |
c906108c SS |
7865 | if (cond_start) |
7866 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7867 | else | |
7868 | b->cond_string = 0; | |
c5aa993b | 7869 | |
c906108c | 7870 | if (frame) |
f6bc2008 PA |
7871 | { |
7872 | b->watchpoint_frame = get_frame_id (frame); | |
7873 | b->watchpoint_thread = inferior_ptid; | |
7874 | } | |
c906108c | 7875 | else |
f6bc2008 PA |
7876 | { |
7877 | b->watchpoint_frame = null_frame_id; | |
7878 | b->watchpoint_thread = null_ptid; | |
7879 | } | |
c906108c | 7880 | |
d983da9c | 7881 | if (scope_breakpoint != NULL) |
c906108c | 7882 | { |
d983da9c DJ |
7883 | /* The scope breakpoint is related to the watchpoint. We will |
7884 | need to act on them together. */ | |
7885 | b->related_breakpoint = scope_breakpoint; | |
7886 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7887 | } |
d983da9c | 7888 | |
c906108c | 7889 | value_free_to_mark (mark); |
2d134ed3 PA |
7890 | |
7891 | /* Finally update the new watchpoint. This creates the locations | |
7892 | that should be inserted. */ | |
7893 | update_watchpoint (b, 1); | |
7894 | ||
c906108c | 7895 | mention (b); |
b60e7edf | 7896 | update_global_location_list (1); |
c906108c SS |
7897 | } |
7898 | ||
7899 | /* Return count of locations need to be watched and can be handled | |
7900 | in hardware. If the watchpoint can not be handled | |
7901 | in hardware return zero. */ | |
7902 | ||
c906108c | 7903 | static int |
fba45db2 | 7904 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7905 | { |
7906 | int found_memory_cnt = 0; | |
2e70b7b9 | 7907 | struct value *head = v; |
c906108c SS |
7908 | |
7909 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7910 | if (!can_use_hw_watchpoints) |
c906108c | 7911 | return 0; |
c5aa993b | 7912 | |
5c44784c JM |
7913 | /* Make sure that the value of the expression depends only upon |
7914 | memory contents, and values computed from them within GDB. If we | |
7915 | find any register references or function calls, we can't use a | |
7916 | hardware watchpoint. | |
7917 | ||
7918 | The idea here is that evaluating an expression generates a series | |
7919 | of values, one holding the value of every subexpression. (The | |
7920 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7921 | a*b+c.) GDB's values hold almost enough information to establish | |
7922 | the criteria given above --- they identify memory lvalues, | |
7923 | register lvalues, computed values, etcetera. So we can evaluate | |
7924 | the expression, and then scan the chain of values that leaves | |
7925 | behind to decide whether we can detect any possible change to the | |
7926 | expression's final value using only hardware watchpoints. | |
7927 | ||
7928 | However, I don't think that the values returned by inferior | |
7929 | function calls are special in any way. So this function may not | |
7930 | notice that an expression involving an inferior function call | |
7931 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7932 | for (; v; v = value_next (v)) |
c906108c | 7933 | { |
5c44784c | 7934 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7935 | { |
d69fe07e | 7936 | if (value_lazy (v)) |
5c44784c JM |
7937 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7938 | we either just used its address (e.g., `a' in `a.b') or | |
7939 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7940 | ; | |
53a5351d | 7941 | else |
5c44784c JM |
7942 | { |
7943 | /* Ahh, memory we actually used! Check if we can cover | |
7944 | it with hardware watchpoints. */ | |
df407dfe | 7945 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7946 | |
7947 | /* We only watch structs and arrays if user asked for it | |
7948 | explicitly, never if they just happen to appear in a | |
7949 | middle of some value chain. */ | |
7950 | if (v == head | |
7951 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7952 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7953 | { | |
42ae5230 | 7954 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7955 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7956 | |
d92524f1 | 7957 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7958 | return 0; |
7959 | else | |
7960 | found_memory_cnt++; | |
7961 | } | |
5c44784c | 7962 | } |
c5aa993b | 7963 | } |
5086187c AC |
7964 | else if (VALUE_LVAL (v) != not_lval |
7965 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7966 | return 0; /* ??? What does this represent? */ |
5086187c | 7967 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7968 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7969 | } |
7970 | ||
7971 | /* The expression itself looks suitable for using a hardware | |
7972 | watchpoint, but give the target machine a chance to reject it. */ | |
7973 | return found_memory_cnt; | |
7974 | } | |
7975 | ||
8b93c638 | 7976 | void |
fba45db2 | 7977 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7978 | { |
7979 | watch_command (arg, from_tty); | |
7980 | } | |
8926118c | 7981 | |
c5aa993b | 7982 | static void |
fba45db2 | 7983 | watch_command (char *arg, int from_tty) |
c906108c | 7984 | { |
53a5351d | 7985 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7986 | } |
7987 | ||
8b93c638 | 7988 | void |
fba45db2 | 7989 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7990 | { |
7991 | rwatch_command (arg, from_tty); | |
7992 | } | |
8926118c | 7993 | |
c5aa993b | 7994 | static void |
fba45db2 | 7995 | rwatch_command (char *arg, int from_tty) |
c906108c | 7996 | { |
53a5351d | 7997 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7998 | } |
7999 | ||
8b93c638 | 8000 | void |
fba45db2 | 8001 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
8002 | { |
8003 | awatch_command (arg, from_tty); | |
8004 | } | |
8926118c | 8005 | |
c5aa993b | 8006 | static void |
fba45db2 | 8007 | awatch_command (char *arg, int from_tty) |
c906108c | 8008 | { |
53a5351d | 8009 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 8010 | } |
c906108c | 8011 | \f |
c5aa993b | 8012 | |
43ff13b4 | 8013 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8014 | because it uses the mechanisms of breakpoints. */ |
8015 | ||
bfec99b2 PA |
8016 | struct until_break_command_continuation_args |
8017 | { | |
8018 | struct breakpoint *breakpoint; | |
8019 | struct breakpoint *breakpoint2; | |
8020 | }; | |
8021 | ||
43ff13b4 JM |
8022 | /* This function is called by fetch_inferior_event via the |
8023 | cmd_continuation pointer, to complete the until command. It takes | |
8024 | care of cleaning up the temporary breakpoints set up by the until | |
8025 | command. */ | |
c2c6d25f | 8026 | static void |
604ead4a | 8027 | until_break_command_continuation (void *arg) |
43ff13b4 | 8028 | { |
bfec99b2 PA |
8029 | struct until_break_command_continuation_args *a = arg; |
8030 | ||
8031 | delete_breakpoint (a->breakpoint); | |
8032 | if (a->breakpoint2) | |
8033 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
8034 | } |
8035 | ||
c906108c | 8036 | void |
ae66c1fc | 8037 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8038 | { |
8039 | struct symtabs_and_lines sals; | |
8040 | struct symtab_and_line sal; | |
206415a3 | 8041 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8042 | struct breakpoint *breakpoint; |
f107f563 | 8043 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
8044 | struct cleanup *old_chain; |
8045 | ||
8046 | clear_proceed_status (); | |
8047 | ||
8048 | /* Set a breakpoint where the user wants it and at return from | |
8049 | this function */ | |
c5aa993b | 8050 | |
c906108c SS |
8051 | if (default_breakpoint_valid) |
8052 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8053 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8054 | else |
53a5351d | 8055 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8056 | 0, (char ***) NULL, NULL); |
c5aa993b | 8057 | |
c906108c | 8058 | if (sals.nelts != 1) |
8a3fe4f8 | 8059 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8060 | |
c906108c | 8061 | sal = sals.sals[0]; |
b8c9b27d | 8062 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8063 | |
c906108c | 8064 | if (*arg) |
8a3fe4f8 | 8065 | error (_("Junk at end of arguments.")); |
c5aa993b | 8066 | |
c906108c | 8067 | resolve_sal_pc (&sal); |
c5aa993b | 8068 | |
ae66c1fc EZ |
8069 | if (anywhere) |
8070 | /* If the user told us to continue until a specified location, | |
8071 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8072 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8073 | null_frame_id, bp_until); | |
ae66c1fc | 8074 | else |
edb3359d | 8075 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8076 | at the very same frame. */ |
a6d9a66e UW |
8077 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8078 | get_stack_frame_id (frame), | |
ae66c1fc | 8079 | bp_until); |
c5aa993b | 8080 | |
f107f563 | 8081 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8082 | |
ae66c1fc EZ |
8083 | /* Keep within the current frame, or in frames called by the current |
8084 | one. */ | |
edb3359d DJ |
8085 | |
8086 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8087 | { |
edb3359d DJ |
8088 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8089 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8090 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8091 | sal, | |
edb3359d | 8092 | frame_unwind_caller_id (frame), |
f107f563 VP |
8093 | bp_until); |
8094 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8095 | } |
c5aa993b | 8096 | |
c906108c | 8097 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8098 | |
8099 | /* If we are running asynchronously, and proceed call above has actually | |
8100 | managed to start the target, arrange for breakpoints to be | |
8101 | deleted when the target stops. Otherwise, we're already stopped and | |
8102 | delete breakpoints via cleanup chain. */ | |
8103 | ||
8ea051c5 | 8104 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8105 | { |
bfec99b2 PA |
8106 | struct until_break_command_continuation_args *args; |
8107 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8108 | |
bfec99b2 PA |
8109 | args->breakpoint = breakpoint; |
8110 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8111 | |
8112 | discard_cleanups (old_chain); | |
95e54da7 PA |
8113 | add_continuation (inferior_thread (), |
8114 | until_break_command_continuation, args, | |
604ead4a | 8115 | xfree); |
f107f563 VP |
8116 | } |
8117 | else | |
c5aa993b | 8118 | do_cleanups (old_chain); |
c906108c | 8119 | } |
ae66c1fc | 8120 | |
c906108c | 8121 | static void |
fba45db2 | 8122 | ep_skip_leading_whitespace (char **s) |
c906108c | 8123 | { |
c5aa993b JM |
8124 | if ((s == NULL) || (*s == NULL)) |
8125 | return; | |
8126 | while (isspace (**s)) | |
8127 | *s += 1; | |
c906108c | 8128 | } |
c5aa993b | 8129 | |
c906108c SS |
8130 | /* This function attempts to parse an optional "if <cond>" clause |
8131 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8132 | |
c906108c SS |
8133 | Else, it returns a pointer to the condition string. (It does not |
8134 | attempt to evaluate the string against a particular block.) And, | |
8135 | it updates arg to point to the first character following the parsed | |
8136 | if clause in the arg string. */ | |
53a5351d | 8137 | |
c906108c | 8138 | static char * |
fba45db2 | 8139 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8140 | { |
c5aa993b JM |
8141 | char *cond_string; |
8142 | ||
8143 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8144 | return NULL; |
c5aa993b | 8145 | |
c906108c SS |
8146 | /* Skip the "if" keyword. */ |
8147 | (*arg) += 2; | |
c5aa993b | 8148 | |
c906108c SS |
8149 | /* Skip any extra leading whitespace, and record the start of the |
8150 | condition string. */ | |
8151 | ep_skip_leading_whitespace (arg); | |
8152 | cond_string = *arg; | |
c5aa993b | 8153 | |
c906108c SS |
8154 | /* Assume that the condition occupies the remainder of the arg string. */ |
8155 | (*arg) += strlen (cond_string); | |
c5aa993b | 8156 | |
c906108c SS |
8157 | return cond_string; |
8158 | } | |
c5aa993b | 8159 | |
c906108c SS |
8160 | /* Commands to deal with catching events, such as signals, exceptions, |
8161 | process start/exit, etc. */ | |
c5aa993b JM |
8162 | |
8163 | typedef enum | |
8164 | { | |
44feb3ce TT |
8165 | catch_fork_temporary, catch_vfork_temporary, |
8166 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8167 | } |
8168 | catch_fork_kind; | |
8169 | ||
c906108c | 8170 | static void |
44feb3ce | 8171 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8172 | { |
a6d9a66e | 8173 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8174 | char *cond_string = NULL; |
44feb3ce TT |
8175 | catch_fork_kind fork_kind; |
8176 | int tempflag; | |
8177 | ||
8178 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8179 | tempflag = (fork_kind == catch_fork_temporary | |
8180 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8181 | |
44feb3ce TT |
8182 | if (!arg) |
8183 | arg = ""; | |
c906108c | 8184 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8185 | |
c906108c | 8186 | /* The allowed syntax is: |
c5aa993b JM |
8187 | catch [v]fork |
8188 | catch [v]fork if <cond> | |
8189 | ||
c906108c SS |
8190 | First, check if there's an if clause. */ |
8191 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8192 | |
c906108c | 8193 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8194 | error (_("Junk at end of arguments.")); |
c5aa993b | 8195 | |
c906108c SS |
8196 | /* If this target supports it, create a fork or vfork catchpoint |
8197 | and enable reporting of such events. */ | |
c5aa993b JM |
8198 | switch (fork_kind) |
8199 | { | |
44feb3ce TT |
8200 | case catch_fork_temporary: |
8201 | case catch_fork_permanent: | |
a6d9a66e | 8202 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8203 | &catch_fork_breakpoint_ops); |
c906108c | 8204 | break; |
44feb3ce TT |
8205 | case catch_vfork_temporary: |
8206 | case catch_vfork_permanent: | |
a6d9a66e | 8207 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8208 | &catch_vfork_breakpoint_ops); |
c906108c | 8209 | break; |
c5aa993b | 8210 | default: |
8a3fe4f8 | 8211 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8212 | break; |
c5aa993b | 8213 | } |
c906108c SS |
8214 | } |
8215 | ||
8216 | static void | |
44feb3ce | 8217 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 8218 | { |
a6d9a66e | 8219 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8220 | int tempflag; |
c5aa993b | 8221 | char *cond_string = NULL; |
c906108c | 8222 | |
44feb3ce TT |
8223 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8224 | ||
8225 | if (!arg) | |
8226 | arg = ""; | |
c906108c SS |
8227 | ep_skip_leading_whitespace (&arg); |
8228 | ||
8229 | /* The allowed syntax is: | |
c5aa993b JM |
8230 | catch exec |
8231 | catch exec if <cond> | |
c906108c SS |
8232 | |
8233 | First, check if there's an if clause. */ | |
8234 | cond_string = ep_parse_optional_if_clause (&arg); | |
8235 | ||
8236 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8237 | error (_("Junk at end of arguments.")); |
c906108c SS |
8238 | |
8239 | /* If this target supports it, create an exec catchpoint | |
8240 | and enable reporting of such events. */ | |
a6d9a66e UW |
8241 | create_catchpoint (gdbarch, tempflag, cond_string, |
8242 | &catch_exec_breakpoint_ops); | |
c906108c | 8243 | } |
c5aa993b | 8244 | |
3086aeae DJ |
8245 | static enum print_stop_action |
8246 | print_exception_catchpoint (struct breakpoint *b) | |
8247 | { | |
ade92717 | 8248 | int bp_temp, bp_throw; |
3086aeae | 8249 | |
ade92717 | 8250 | annotate_catchpoint (b->number); |
3086aeae | 8251 | |
ade92717 AR |
8252 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8253 | if (b->loc->address != b->loc->requested_address) | |
8254 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8255 | b->loc->address, | |
8256 | b->number, 1); | |
df2b6d2d | 8257 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8258 | ui_out_text (uiout, |
8259 | bp_temp ? "Temporary catchpoint " | |
8260 | : "Catchpoint "); | |
8261 | if (!ui_out_is_mi_like_p (uiout)) | |
8262 | ui_out_field_int (uiout, "bkptno", b->number); | |
8263 | ui_out_text (uiout, | |
c0b37c48 AR |
8264 | bp_throw ? " (exception thrown), " |
8265 | : " (exception caught), "); | |
ade92717 AR |
8266 | if (ui_out_is_mi_like_p (uiout)) |
8267 | { | |
8268 | ui_out_field_string (uiout, "reason", | |
8269 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8270 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8271 | ui_out_field_int (uiout, "bkptno", b->number); | |
8272 | } | |
3086aeae DJ |
8273 | return PRINT_SRC_AND_LOC; |
8274 | } | |
8275 | ||
8276 | static void | |
a6d9a66e | 8277 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 8278 | { |
79a45b7d TT |
8279 | struct value_print_options opts; |
8280 | get_user_print_options (&opts); | |
8281 | if (opts.addressprint) | |
3086aeae DJ |
8282 | { |
8283 | annotate_field (4); | |
604133b5 AR |
8284 | if (b->loc == NULL || b->loc->shlib_disabled) |
8285 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8286 | else | |
5af949e3 UW |
8287 | ui_out_field_core_addr (uiout, "addr", |
8288 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8289 | } |
8290 | annotate_field (5); | |
604133b5 | 8291 | if (b->loc) |
a6d9a66e | 8292 | *last_loc = b->loc; |
3086aeae DJ |
8293 | if (strstr (b->addr_string, "throw") != NULL) |
8294 | ui_out_field_string (uiout, "what", "exception throw"); | |
8295 | else | |
8296 | ui_out_field_string (uiout, "what", "exception catch"); | |
8297 | } | |
8298 | ||
8299 | static void | |
8300 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8301 | { | |
ade92717 AR |
8302 | int bp_temp; |
8303 | int bp_throw; | |
8304 | ||
df2b6d2d | 8305 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8306 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8307 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8308 | : _("Catchpoint ")); | |
8309 | ui_out_field_int (uiout, "bkptno", b->number); | |
8310 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8311 | : _(" (catch)")); | |
3086aeae DJ |
8312 | } |
8313 | ||
8314 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
8315 | NULL, /* insert */ |
8316 | NULL, /* remove */ | |
8317 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8318 | print_exception_catchpoint, |
8319 | print_one_exception_catchpoint, | |
8320 | print_mention_exception_catchpoint | |
8321 | }; | |
8322 | ||
8323 | static int | |
8324 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8325 | enum exception_event_kind ex_event, int from_tty) | |
8326 | { | |
604133b5 AR |
8327 | char *trigger_func_name; |
8328 | ||
3086aeae | 8329 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8330 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8331 | else |
604133b5 | 8332 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8333 | |
8cdf0e15 VP |
8334 | create_breakpoint (get_current_arch (), |
8335 | trigger_func_name, cond_string, -1, | |
8336 | 0 /* condition and thread are valid. */, | |
8337 | tempflag, 0, 0, | |
8338 | 0, | |
8339 | AUTO_BOOLEAN_TRUE /* pending */, | |
8340 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8341 | 1 /* enabled */); | |
3086aeae | 8342 | |
3086aeae DJ |
8343 | return 1; |
8344 | } | |
8345 | ||
c5aa993b | 8346 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8347 | |
8348 | static void | |
fba45db2 KB |
8349 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8350 | int tempflag, int from_tty) | |
c906108c | 8351 | { |
c5aa993b JM |
8352 | char *cond_string = NULL; |
8353 | struct symtab_and_line *sal = NULL; | |
8354 | ||
44feb3ce TT |
8355 | if (!arg) |
8356 | arg = ""; | |
c906108c | 8357 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8358 | |
c906108c SS |
8359 | cond_string = ep_parse_optional_if_clause (&arg); |
8360 | ||
8361 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8362 | error (_("Junk at end of arguments.")); |
c906108c | 8363 | |
059fb39f PM |
8364 | if (ex_event != EX_EVENT_THROW |
8365 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8366 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8367 | |
3086aeae DJ |
8368 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8369 | return; | |
8370 | ||
8a3fe4f8 | 8371 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8372 | } |
8373 | ||
44feb3ce TT |
8374 | /* Implementation of "catch catch" command. */ |
8375 | ||
8376 | static void | |
8377 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8378 | { | |
8379 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8380 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8381 | } | |
8382 | ||
8383 | /* Implementation of "catch throw" command. */ | |
8384 | ||
8385 | static void | |
8386 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8387 | { | |
8388 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8389 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8390 | } | |
8391 | ||
f7f9143b JB |
8392 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8393 | ||
8394 | static void | |
a6d9a66e UW |
8395 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8396 | struct symtab_and_line sal, | |
f7f9143b JB |
8397 | char *addr_string, |
8398 | char *exp_string, | |
8399 | char *cond_string, | |
8400 | struct expression *cond, | |
8401 | struct breakpoint_ops *ops, | |
8402 | int tempflag, | |
8403 | int from_tty) | |
8404 | { | |
8405 | struct breakpoint *b; | |
8406 | ||
8407 | if (from_tty) | |
8408 | { | |
5af949e3 UW |
8409 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8410 | if (!loc_gdbarch) | |
8411 | loc_gdbarch = gdbarch; | |
8412 | ||
6c95b8df PA |
8413 | describe_other_breakpoints (loc_gdbarch, |
8414 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8415 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8416 | version for exception catchpoints, because two catchpoints | |
8417 | used for different exception names will use the same address. | |
8418 | In this case, a "breakpoint ... also set at..." warning is | |
8419 | unproductive. Besides. the warning phrasing is also a bit | |
8420 | inapropriate, we should use the word catchpoint, and tell | |
8421 | the user what type of catchpoint it is. The above is good | |
8422 | enough for now, though. */ | |
8423 | } | |
8424 | ||
a6d9a66e | 8425 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8426 | set_breakpoint_count (breakpoint_count + 1); |
8427 | ||
8428 | b->enable_state = bp_enabled; | |
8429 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8430 | b->number = breakpoint_count; | |
8431 | b->ignore_count = 0; | |
511a6cd4 | 8432 | b->loc->cond = cond; |
f7f9143b JB |
8433 | b->addr_string = addr_string; |
8434 | b->language = language_ada; | |
8435 | b->cond_string = cond_string; | |
8436 | b->exp_string = exp_string; | |
8437 | b->thread = -1; | |
8438 | b->ops = ops; | |
f7f9143b JB |
8439 | |
8440 | mention (b); | |
b60e7edf | 8441 | update_global_location_list (1); |
f7f9143b JB |
8442 | } |
8443 | ||
8444 | /* Implement the "catch exception" command. */ | |
8445 | ||
8446 | static void | |
44feb3ce TT |
8447 | catch_ada_exception_command (char *arg, int from_tty, |
8448 | struct cmd_list_element *command) | |
f7f9143b | 8449 | { |
a6d9a66e | 8450 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8451 | int tempflag; |
f7f9143b JB |
8452 | struct symtab_and_line sal; |
8453 | enum bptype type; | |
8454 | char *addr_string = NULL; | |
8455 | char *exp_string = NULL; | |
8456 | char *cond_string = NULL; | |
8457 | struct expression *cond = NULL; | |
8458 | struct breakpoint_ops *ops = NULL; | |
8459 | ||
44feb3ce TT |
8460 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8461 | ||
8462 | if (!arg) | |
8463 | arg = ""; | |
f7f9143b JB |
8464 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8465 | &cond_string, &cond, &ops); | |
a6d9a66e | 8466 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8467 | cond_string, cond, ops, tempflag, |
8468 | from_tty); | |
8469 | } | |
8470 | ||
a96d9b2e SDJ |
8471 | /* Cleanup function for a syscall filter list. */ |
8472 | static void | |
8473 | clean_up_filters (void *arg) | |
8474 | { | |
8475 | VEC(int) *iter = *(VEC(int) **) arg; | |
8476 | VEC_free (int, iter); | |
8477 | } | |
8478 | ||
8479 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8480 | filter list, or NULL if no filtering is required. */ | |
8481 | static VEC(int) * | |
8482 | catch_syscall_split_args (char *arg) | |
8483 | { | |
8484 | VEC(int) *result = NULL; | |
8485 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8486 | ||
8487 | while (*arg != '\0') | |
8488 | { | |
8489 | int i, syscall_number; | |
8490 | char *endptr; | |
8491 | char cur_name[128]; | |
8492 | struct syscall s; | |
8493 | ||
8494 | /* Skip whitespace. */ | |
8495 | while (isspace (*arg)) | |
8496 | arg++; | |
8497 | ||
8498 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8499 | cur_name[i] = arg[i]; | |
8500 | cur_name[i] = '\0'; | |
8501 | arg += i; | |
8502 | ||
8503 | /* Check if the user provided a syscall name or a number. */ | |
8504 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8505 | if (*endptr == '\0') | |
bccd0dd2 | 8506 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8507 | else |
8508 | { | |
8509 | /* We have a name. Let's check if it's valid and convert it | |
8510 | to a number. */ | |
8511 | get_syscall_by_name (cur_name, &s); | |
8512 | ||
8513 | if (s.number == UNKNOWN_SYSCALL) | |
8514 | /* Here we have to issue an error instead of a warning, because | |
8515 | GDB cannot do anything useful if there's no syscall number to | |
8516 | be caught. */ | |
8517 | error (_("Unknown syscall name '%s'."), cur_name); | |
8518 | } | |
8519 | ||
8520 | /* Ok, it's valid. */ | |
8521 | VEC_safe_push (int, result, s.number); | |
8522 | } | |
8523 | ||
8524 | discard_cleanups (cleanup); | |
8525 | return result; | |
8526 | } | |
8527 | ||
8528 | /* Implement the "catch syscall" command. */ | |
8529 | ||
8530 | static void | |
8531 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8532 | { | |
8533 | int tempflag; | |
8534 | VEC(int) *filter; | |
8535 | struct syscall s; | |
8536 | struct gdbarch *gdbarch = get_current_arch (); | |
8537 | ||
8538 | /* Checking if the feature if supported. */ | |
8539 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8540 | error (_("The feature 'catch syscall' is not supported on \ | |
8541 | this architeture yet.")); | |
8542 | ||
8543 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8544 | ||
8545 | ep_skip_leading_whitespace (&arg); | |
8546 | ||
8547 | /* We need to do this first "dummy" translation in order | |
8548 | to get the syscall XML file loaded or, most important, | |
8549 | to display a warning to the user if there's no XML file | |
8550 | for his/her architecture. */ | |
8551 | get_syscall_by_number (0, &s); | |
8552 | ||
8553 | /* The allowed syntax is: | |
8554 | catch syscall | |
8555 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8556 | ||
8557 | Let's check if there's a syscall name. */ | |
8558 | ||
8559 | if (arg != NULL) | |
8560 | filter = catch_syscall_split_args (arg); | |
8561 | else | |
8562 | filter = NULL; | |
8563 | ||
8564 | create_syscall_event_catchpoint (tempflag, filter, | |
8565 | &catch_syscall_breakpoint_ops); | |
8566 | } | |
8567 | ||
f7f9143b JB |
8568 | /* Implement the "catch assert" command. */ |
8569 | ||
8570 | static void | |
44feb3ce | 8571 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8572 | { |
a6d9a66e | 8573 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8574 | int tempflag; |
f7f9143b JB |
8575 | struct symtab_and_line sal; |
8576 | char *addr_string = NULL; | |
8577 | struct breakpoint_ops *ops = NULL; | |
8578 | ||
44feb3ce TT |
8579 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8580 | ||
8581 | if (!arg) | |
8582 | arg = ""; | |
f7f9143b | 8583 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8584 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8585 | ops, tempflag, from_tty); | |
f7f9143b JB |
8586 | } |
8587 | ||
c906108c | 8588 | static void |
fba45db2 | 8589 | catch_command (char *arg, int from_tty) |
c906108c | 8590 | { |
44feb3ce | 8591 | error (_("Catch requires an event name.")); |
c906108c SS |
8592 | } |
8593 | \f | |
8594 | ||
8595 | static void | |
fba45db2 | 8596 | tcatch_command (char *arg, int from_tty) |
c906108c | 8597 | { |
44feb3ce | 8598 | error (_("Catch requires an event name.")); |
c906108c SS |
8599 | } |
8600 | ||
80f8a6eb | 8601 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8602 | |
8603 | static void | |
fba45db2 | 8604 | clear_command (char *arg, int from_tty) |
c906108c | 8605 | { |
d6e956e5 VP |
8606 | struct breakpoint *b; |
8607 | VEC(breakpoint_p) *found = 0; | |
8608 | int ix; | |
c906108c SS |
8609 | int default_match; |
8610 | struct symtabs_and_lines sals; | |
8611 | struct symtab_and_line sal; | |
c906108c SS |
8612 | int i; |
8613 | ||
8614 | if (arg) | |
8615 | { | |
8616 | sals = decode_line_spec (arg, 1); | |
8617 | default_match = 0; | |
8618 | } | |
8619 | else | |
8620 | { | |
c5aa993b | 8621 | sals.sals = (struct symtab_and_line *) |
c906108c | 8622 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8623 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8624 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8625 | sal.line = default_breakpoint_line; |
8626 | sal.symtab = default_breakpoint_symtab; | |
8627 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8628 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8629 | if (sal.symtab == 0) |
8a3fe4f8 | 8630 | error (_("No source file specified.")); |
c906108c SS |
8631 | |
8632 | sals.sals[0] = sal; | |
8633 | sals.nelts = 1; | |
8634 | ||
8635 | default_match = 1; | |
8636 | } | |
8637 | ||
ed0616c6 VP |
8638 | /* We don't call resolve_sal_pc here. That's not |
8639 | as bad as it seems, because all existing breakpoints | |
8640 | typically have both file/line and pc set. So, if | |
8641 | clear is given file/line, we can match this to existing | |
8642 | breakpoint without obtaining pc at all. | |
8643 | ||
8644 | We only support clearing given the address explicitly | |
8645 | present in breakpoint table. Say, we've set breakpoint | |
8646 | at file:line. There were several PC values for that file:line, | |
8647 | due to optimization, all in one block. | |
8648 | We've picked one PC value. If "clear" is issued with another | |
8649 | PC corresponding to the same file:line, the breakpoint won't | |
8650 | be cleared. We probably can still clear the breakpoint, but | |
8651 | since the other PC value is never presented to user, user | |
8652 | can only find it by guessing, and it does not seem important | |
8653 | to support that. */ | |
8654 | ||
c906108c | 8655 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8656 | to it. Do it in two passes, solely to preserve the current |
8657 | behavior that from_tty is forced true if we delete more than | |
8658 | one breakpoint. */ | |
c906108c | 8659 | |
80f8a6eb | 8660 | found = NULL; |
c906108c SS |
8661 | for (i = 0; i < sals.nelts; i++) |
8662 | { | |
8663 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8664 | If line given (pc == 0), clear all bpts on specified line. |
8665 | If defaulting, clear all bpts on default line | |
c906108c | 8666 | or at default pc. |
c5aa993b JM |
8667 | |
8668 | defaulting sal.pc != 0 tests to do | |
8669 | ||
8670 | 0 1 pc | |
8671 | 1 1 pc _and_ line | |
8672 | 0 0 line | |
8673 | 1 0 <can't happen> */ | |
c906108c SS |
8674 | |
8675 | sal = sals.sals[i]; | |
c906108c | 8676 | |
d6e956e5 VP |
8677 | /* Find all matching breakpoints and add them to |
8678 | 'found'. */ | |
8679 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8680 | { |
0d381245 | 8681 | int match = 0; |
80f8a6eb MS |
8682 | /* Are we going to delete b? */ |
8683 | if (b->type != bp_none | |
8684 | && b->type != bp_watchpoint | |
8685 | && b->type != bp_hardware_watchpoint | |
8686 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8687 | && b->type != bp_access_watchpoint) |
8688 | { | |
8689 | struct bp_location *loc = b->loc; | |
8690 | for (; loc; loc = loc->next) | |
8691 | { | |
6c95b8df PA |
8692 | int pc_match = sal.pc |
8693 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8694 | && (loc->address == sal.pc) |
8695 | && (!section_is_overlay (loc->section) | |
8696 | || loc->section == sal.section); | |
8697 | int line_match = ((default_match || (0 == sal.pc)) | |
8698 | && b->source_file != NULL | |
8699 | && sal.symtab != NULL | |
6c95b8df | 8700 | && sal.pspace == loc->pspace |
0d381245 VP |
8701 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8702 | && b->line_number == sal.line); | |
8703 | if (pc_match || line_match) | |
8704 | { | |
8705 | match = 1; | |
8706 | break; | |
8707 | } | |
8708 | } | |
8709 | } | |
8710 | ||
8711 | if (match) | |
d6e956e5 | 8712 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8713 | } |
80f8a6eb MS |
8714 | } |
8715 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8716 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8717 | { |
8718 | if (arg) | |
8a3fe4f8 | 8719 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8720 | else |
8a3fe4f8 | 8721 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8722 | } |
c906108c | 8723 | |
d6e956e5 | 8724 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8725 | from_tty = 1; /* Always report if deleted more than one */ |
8726 | if (from_tty) | |
a3f17187 | 8727 | { |
d6e956e5 | 8728 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8729 | printf_unfiltered (_("Deleted breakpoint ")); |
8730 | else | |
8731 | printf_unfiltered (_("Deleted breakpoints ")); | |
8732 | } | |
80f8a6eb | 8733 | breakpoints_changed (); |
d6e956e5 VP |
8734 | |
8735 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8736 | { |
c5aa993b | 8737 | if (from_tty) |
d6e956e5 VP |
8738 | printf_unfiltered ("%d ", b->number); |
8739 | delete_breakpoint (b); | |
c906108c | 8740 | } |
80f8a6eb MS |
8741 | if (from_tty) |
8742 | putchar_unfiltered ('\n'); | |
c906108c SS |
8743 | } |
8744 | \f | |
8745 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8746 | all breakpoints that are marked for deletion, whether hit or not. | |
8747 | This is called after any breakpoint is hit, or after errors. */ | |
8748 | ||
8749 | void | |
fba45db2 | 8750 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8751 | { |
8752 | struct breakpoint *b, *temp; | |
8753 | ||
8754 | for (; bs; bs = bs->next) | |
20874c92 VP |
8755 | if (bs->breakpoint_at |
8756 | && bs->breakpoint_at->owner | |
8757 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8758 | && bs->stop) |
4f8d1dc6 | 8759 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8760 | |
8761 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8762 | { |
b5de0fa7 | 8763 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8764 | delete_breakpoint (b); |
8765 | } | |
c906108c SS |
8766 | } |
8767 | ||
494cfb0f | 8768 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8769 | Sort elements primarily by their ADDRESS (no matter what does |
8770 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8771 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8772 | is sorted stable way despite qsort being an instable algorithm. */ | |
8773 | ||
8774 | static int | |
494cfb0f | 8775 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8776 | { |
494cfb0f JK |
8777 | struct bp_location *a = *(void **) ap; |
8778 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8779 | int a_perm = a->owner->enable_state == bp_permanent; |
8780 | int b_perm = b->owner->enable_state == bp_permanent; | |
8781 | ||
8782 | if (a->address != b->address) | |
8783 | return (a->address > b->address) - (a->address < b->address); | |
8784 | ||
8785 | /* Sort permanent breakpoints first. */ | |
8786 | if (a_perm != b_perm) | |
8787 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8788 | ||
8789 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8790 | breakpoint can be sorted in arbitrary order. */ | |
8791 | ||
8792 | if (a->owner->number != b->owner->number) | |
8793 | return (a->owner->number > b->owner->number) | |
8794 | - (a->owner->number < b->owner->number); | |
8795 | ||
8796 | return (a > b) - (a < b); | |
8797 | } | |
8798 | ||
876fa593 JK |
8799 | /* Set bp_location_placed_address_before_address_max and |
8800 | bp_location_shadow_len_after_address_max according to the current content of | |
8801 | the bp_location array. */ | |
f7545552 TT |
8802 | |
8803 | static void | |
876fa593 | 8804 | bp_location_target_extensions_update (void) |
f7545552 | 8805 | { |
876fa593 JK |
8806 | struct bp_location *bl, **blp_tmp; |
8807 | ||
8808 | bp_location_placed_address_before_address_max = 0; | |
8809 | bp_location_shadow_len_after_address_max = 0; | |
8810 | ||
8811 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8812 | { | |
8813 | CORE_ADDR start, end, addr; | |
8814 | ||
8815 | if (!bp_location_has_shadow (bl)) | |
8816 | continue; | |
8817 | ||
8818 | start = bl->target_info.placed_address; | |
8819 | end = start + bl->target_info.shadow_len; | |
8820 | ||
8821 | gdb_assert (bl->address >= start); | |
8822 | addr = bl->address - start; | |
8823 | if (addr > bp_location_placed_address_before_address_max) | |
8824 | bp_location_placed_address_before_address_max = addr; | |
8825 | ||
8826 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8827 | ||
8828 | gdb_assert (bl->address < end); | |
8829 | addr = end - bl->address; | |
8830 | if (addr > bp_location_shadow_len_after_address_max) | |
8831 | bp_location_shadow_len_after_address_max = addr; | |
8832 | } | |
f7545552 TT |
8833 | } |
8834 | ||
4cd9bd08 | 8835 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8836 | into the inferior, only remove already-inserted locations that no |
8837 | longer should be inserted. Functions that delete a breakpoint or | |
8838 | breakpoints should pass false, so that deleting a breakpoint | |
8839 | doesn't have the side effect of inserting the locations of other | |
8840 | breakpoints that are marked not-inserted, but should_be_inserted | |
8841 | returns true on them. | |
8842 | ||
8843 | This behaviour is useful is situations close to tear-down -- e.g., | |
8844 | after an exec, while the target still has execution, but breakpoint | |
8845 | shadows of the previous executable image should *NOT* be restored | |
8846 | to the new image; or before detaching, where the target still has | |
8847 | execution and wants to delete breakpoints from GDB's lists, and all | |
8848 | breakpoints had already been removed from the inferior. */ | |
8849 | ||
0d381245 | 8850 | static void |
b60e7edf | 8851 | update_global_location_list (int should_insert) |
0d381245 | 8852 | { |
74960c60 | 8853 | struct breakpoint *b; |
876fa593 | 8854 | struct bp_location **locp, *loc; |
f7545552 TT |
8855 | struct cleanup *cleanups; |
8856 | ||
2d134ed3 PA |
8857 | /* Used in the duplicates detection below. When iterating over all |
8858 | bp_locations, points to the first bp_location of a given address. | |
8859 | Breakpoints and watchpoints of different types are never | |
8860 | duplicates of each other. Keep one pointer for each type of | |
8861 | breakpoint/watchpoint, so we only need to loop over all locations | |
8862 | once. */ | |
8863 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8864 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8865 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8866 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8867 | |
8868 | /* Saved former bp_location array which we compare against the newly built | |
8869 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8870 | struct bp_location **old_location, **old_locp; | |
8871 | unsigned old_location_count; | |
8872 | ||
8873 | old_location = bp_location; | |
8874 | old_location_count = bp_location_count; | |
8875 | bp_location = NULL; | |
8876 | bp_location_count = 0; | |
8877 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8878 | |
74960c60 | 8879 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8880 | for (loc = b->loc; loc; loc = loc->next) |
8881 | bp_location_count++; | |
8882 | ||
8883 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8884 | locp = bp_location; | |
8885 | ALL_BREAKPOINTS (b) | |
8886 | for (loc = b->loc; loc; loc = loc->next) | |
8887 | *locp++ = loc; | |
8888 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8889 | bp_location_compare); |
876fa593 JK |
8890 | |
8891 | bp_location_target_extensions_update (); | |
74960c60 VP |
8892 | |
8893 | /* Identify bp_location instances that are no longer present in the new | |
8894 | list, and therefore should be freed. Note that it's not necessary that | |
8895 | those locations should be removed from inferior -- if there's another | |
8896 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8897 | we don't need to remove/insert the location. |
8898 | ||
8899 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8900 | former bp_location array state respectively. */ | |
8901 | ||
8902 | locp = bp_location; | |
8903 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8904 | old_locp++) | |
74960c60 | 8905 | { |
876fa593 | 8906 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8907 | struct bp_location **loc2p; |
876fa593 JK |
8908 | |
8909 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8910 | have to free it. */ |
c7d46a38 | 8911 | int found_object = 0; |
20874c92 VP |
8912 | /* Tells if the location should remain inserted in the target. */ |
8913 | int keep_in_target = 0; | |
8914 | int removed = 0; | |
876fa593 JK |
8915 | |
8916 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8917 | at or being the one matching OLD_LOC. */ | |
8918 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8919 | && (*locp)->address < old_loc->address) |
876fa593 | 8920 | locp++; |
c7d46a38 PA |
8921 | |
8922 | for (loc2p = locp; | |
8923 | (loc2p < bp_location + bp_location_count | |
8924 | && (*loc2p)->address == old_loc->address); | |
8925 | loc2p++) | |
8926 | { | |
8927 | if (*loc2p == old_loc) | |
8928 | { | |
8929 | found_object = 1; | |
8930 | break; | |
8931 | } | |
8932 | } | |
74960c60 VP |
8933 | |
8934 | /* If this location is no longer present, and inserted, look if there's | |
8935 | maybe a new location at the same address. If so, mark that one | |
8936 | inserted, and don't remove this one. This is needed so that we | |
8937 | don't have a time window where a breakpoint at certain location is not | |
8938 | inserted. */ | |
8939 | ||
876fa593 | 8940 | if (old_loc->inserted) |
0d381245 | 8941 | { |
74960c60 | 8942 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8943 | |
876fa593 | 8944 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8945 | { |
8946 | /* The location is still present in the location list, and still | |
8947 | should be inserted. Don't do anything. */ | |
20874c92 | 8948 | keep_in_target = 1; |
74960c60 VP |
8949 | } |
8950 | else | |
8951 | { | |
8952 | /* The location is either no longer present, or got disabled. | |
8953 | See if there's another location at the same address, in which | |
8954 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8955 | |
8956 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8957 | { | |
876fa593 | 8958 | for (loc2p = locp; |
c7d46a38 PA |
8959 | (loc2p < bp_location + bp_location_count |
8960 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8961 | loc2p++) |
8962 | { | |
8963 | struct bp_location *loc2 = *loc2p; | |
8964 | ||
2d134ed3 | 8965 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8966 | { |
8967 | /* For the sake of should_be_inserted. | |
8968 | Duplicates check below will fix up this later. */ | |
8969 | loc2->duplicate = 0; | |
85d721b8 PA |
8970 | |
8971 | /* Read watchpoint locations are switched to | |
8972 | access watchpoints, if the former are not | |
8973 | supported, but the latter are. */ | |
8974 | if (is_hardware_watchpoint (old_loc->owner)) | |
8975 | { | |
8976 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8977 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8978 | } | |
8979 | ||
c7d46a38 PA |
8980 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8981 | { | |
8982 | loc2->inserted = 1; | |
8983 | loc2->target_info = old_loc->target_info; | |
8984 | keep_in_target = 1; | |
8985 | break; | |
8986 | } | |
876fa593 JK |
8987 | } |
8988 | } | |
8989 | } | |
74960c60 VP |
8990 | } |
8991 | ||
20874c92 VP |
8992 | if (!keep_in_target) |
8993 | { | |
876fa593 | 8994 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8995 | { |
8996 | /* This is just about all we can do. We could keep this | |
8997 | location on the global list, and try to remove it next | |
8998 | time, but there's no particular reason why we will | |
8999 | succeed next time. | |
9000 | ||
876fa593 | 9001 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
9002 | as delete_breakpoint frees the breakpoint only |
9003 | after calling us. */ | |
9004 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 9005 | old_loc->owner->number); |
20874c92 VP |
9006 | } |
9007 | removed = 1; | |
9008 | } | |
0d381245 | 9009 | } |
74960c60 VP |
9010 | |
9011 | if (!found_object) | |
1c5cfe86 | 9012 | { |
db82e815 PA |
9013 | if (removed && non_stop |
9014 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9015 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9016 | { |
db82e815 PA |
9017 | /* This location was removed from the target. In |
9018 | non-stop mode, a race condition is possible where | |
9019 | we've removed a breakpoint, but stop events for that | |
9020 | breakpoint are already queued and will arrive later. | |
9021 | We apply an heuristic to be able to distinguish such | |
9022 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9023 | breakpoint location for a bit, and will retire it | |
9024 | after we see some number of events. The theory here | |
9025 | is that reporting of events should, "on the average", | |
9026 | be fair, so after a while we'll see events from all | |
9027 | threads that have anything of interest, and no longer | |
9028 | need to keep this breakpoint location around. We | |
9029 | don't hold locations forever so to reduce chances of | |
9030 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9031 | SIGTRAP. | |
9032 | ||
9033 | The heuristic failing can be disastrous on | |
9034 | decr_pc_after_break targets. | |
9035 | ||
9036 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9037 | if we fail to recognize a late breakpoint SIGTRAP, | |
9038 | because events_till_retirement has reached 0 too | |
9039 | soon, we'll fail to do the PC adjustment, and report | |
9040 | a random SIGTRAP to the user. When the user resumes | |
9041 | the inferior, it will most likely immediately crash | |
9042 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
9043 | corrupted, because of being resumed e.g., in the | |
9044 | middle of a multi-byte instruction, or skipped a | |
9045 | one-byte instruction. This was actually seen happen | |
9046 | on native x86-linux, and should be less rare on | |
9047 | targets that do not support new thread events, like | |
9048 | remote, due to the heuristic depending on | |
9049 | thread_count. | |
9050 | ||
9051 | Mistaking a random SIGTRAP for a breakpoint trap | |
9052 | causes similar symptoms (PC adjustment applied when | |
9053 | it shouldn't), but then again, playing with SIGTRAPs | |
9054 | behind the debugger's back is asking for trouble. | |
9055 | ||
9056 | Since hardware watchpoint traps are always | |
9057 | distinguishable from other traps, so we don't need to | |
9058 | apply keep hardware watchpoint moribund locations | |
9059 | around. We simply always ignore hardware watchpoint | |
9060 | traps we can no longer explain. */ | |
9061 | ||
876fa593 JK |
9062 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9063 | old_loc->owner = NULL; | |
20874c92 | 9064 | |
876fa593 | 9065 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9066 | } |
9067 | else | |
876fa593 | 9068 | free_bp_location (old_loc); |
20874c92 | 9069 | } |
74960c60 | 9070 | } |
1c5cfe86 | 9071 | |
2d134ed3 PA |
9072 | /* Rescan breakpoints at the same address and section, marking the |
9073 | first one as "first" and any others as "duplicates". This is so | |
9074 | that the bpt instruction is only inserted once. If we have a | |
9075 | permanent breakpoint at the same place as BPT, make that one the | |
9076 | official one, and the rest as duplicates. Permanent breakpoints | |
9077 | are sorted first for the same address. | |
9078 | ||
9079 | Do the same for hardware watchpoints, but also considering the | |
9080 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9081 | |
2d134ed3 PA |
9082 | bp_loc_first = NULL; |
9083 | wp_loc_first = NULL; | |
9084 | awp_loc_first = NULL; | |
9085 | rwp_loc_first = NULL; | |
876fa593 | 9086 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9087 | { |
876fa593 | 9088 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9089 | struct bp_location **loc_first_p; |
876fa593 JK |
9090 | |
9091 | if (b->enable_state == bp_disabled | |
9092 | || b->enable_state == bp_call_disabled | |
9093 | || b->enable_state == bp_startup_disabled | |
9094 | || !loc->enabled | |
9095 | || loc->shlib_disabled | |
15c3d785 | 9096 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9097 | || is_tracepoint (b)) |
876fa593 JK |
9098 | continue; |
9099 | ||
9100 | /* Permanent breakpoint should always be inserted. */ | |
9101 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9102 | internal_error (__FILE__, __LINE__, | |
9103 | _("allegedly permanent breakpoint is not " | |
9104 | "actually inserted")); | |
9105 | ||
2d134ed3 PA |
9106 | if (b->type == bp_hardware_watchpoint) |
9107 | loc_first_p = &wp_loc_first; | |
9108 | else if (b->type == bp_read_watchpoint) | |
9109 | loc_first_p = &rwp_loc_first; | |
9110 | else if (b->type == bp_access_watchpoint) | |
9111 | loc_first_p = &awp_loc_first; | |
9112 | else | |
9113 | loc_first_p = &bp_loc_first; | |
9114 | ||
9115 | if (*loc_first_p == NULL | |
9116 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9117 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9118 | { |
2d134ed3 | 9119 | *loc_first_p = loc; |
876fa593 JK |
9120 | loc->duplicate = 0; |
9121 | continue; | |
9122 | } | |
9123 | ||
9124 | loc->duplicate = 1; | |
9125 | ||
2d134ed3 PA |
9126 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9127 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9128 | internal_error (__FILE__, __LINE__, |
9129 | _("another breakpoint was inserted on top of " | |
9130 | "a permanent breakpoint")); | |
0d381245 | 9131 | } |
74960c60 | 9132 | |
50c71eaf | 9133 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9134 | && (have_live_inferiors () |
2567c7d9 | 9135 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9136 | insert_breakpoint_locations (); |
f7545552 TT |
9137 | |
9138 | do_cleanups (cleanups); | |
74960c60 VP |
9139 | } |
9140 | ||
20874c92 VP |
9141 | void |
9142 | breakpoint_retire_moribund (void) | |
9143 | { | |
9144 | struct bp_location *loc; | |
9145 | int ix; | |
9146 | ||
9147 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9148 | if (--(loc->events_till_retirement) == 0) | |
9149 | { | |
9150 | free_bp_location (loc); | |
9151 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9152 | --ix; | |
9153 | } | |
9154 | } | |
9155 | ||
74960c60 | 9156 | static void |
b60e7edf | 9157 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9158 | { |
9159 | struct gdb_exception e; | |
9160 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 9161 | update_global_location_list (inserting); |
0d381245 VP |
9162 | } |
9163 | ||
a474d7c2 PA |
9164 | /* Clear BPT from a BPS. */ |
9165 | static void | |
9166 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
9167 | { | |
9168 | bpstat bs; | |
9169 | for (bs = bps; bs; bs = bs->next) | |
9170 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
9171 | { | |
9172 | bs->breakpoint_at = NULL; | |
9173 | bs->old_val = NULL; | |
9174 | /* bs->commands will be freed later. */ | |
9175 | } | |
9176 | } | |
9177 | ||
9178 | /* Callback for iterate_over_threads. */ | |
9179 | static int | |
9180 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
9181 | { | |
9182 | struct breakpoint *bpt = data; | |
9183 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
9184 | return 0; | |
9185 | } | |
9186 | ||
53a5351d JM |
9187 | /* Delete a breakpoint and clean up all traces of it in the data |
9188 | structures. */ | |
c906108c SS |
9189 | |
9190 | void | |
fba45db2 | 9191 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9192 | { |
52f0bd74 | 9193 | struct breakpoint *b; |
74960c60 | 9194 | struct bp_location *loc, *next; |
c906108c | 9195 | |
8a3fe4f8 | 9196 | gdb_assert (bpt != NULL); |
c906108c SS |
9197 | |
9198 | /* Has this bp already been deleted? This can happen because multiple | |
9199 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9200 | ||
9201 | One example of this happening is a watchpoint's scope bp. When the | |
9202 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9203 | delete it. We also delete its scope bp. But the scope bp is marked | |
9204 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9205 | checked for auto-deleting bp's, which are deleted. | |
9206 | ||
9207 | A real solution to this problem might involve reference counts in bp's, | |
9208 | and/or giving them pointers back to their referencing bpstat's, and | |
9209 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9210 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9211 | if (bpt->type == bp_none) |
9212 | return; | |
9213 | ||
e5a0a904 JK |
9214 | /* At least avoid this stale reference until the reference counting of |
9215 | breakpoints gets resolved. */ | |
9216 | if (bpt->related_breakpoint != NULL) | |
9217 | { | |
9218 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9219 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9220 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9221 | bpt->related_breakpoint = NULL; | |
9222 | } | |
9223 | ||
383f836e | 9224 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9225 | |
c906108c SS |
9226 | if (breakpoint_chain == bpt) |
9227 | breakpoint_chain = bpt->next; | |
9228 | ||
c906108c SS |
9229 | ALL_BREAKPOINTS (b) |
9230 | if (b->next == bpt) | |
c5aa993b JM |
9231 | { |
9232 | b->next = bpt->next; | |
9233 | break; | |
9234 | } | |
c906108c | 9235 | |
9add0f1b | 9236 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9237 | xfree (bpt->cond_string); |
9238 | xfree (bpt->cond_exp); | |
9239 | xfree (bpt->addr_string); | |
9240 | xfree (bpt->exp); | |
9241 | xfree (bpt->exp_string); | |
9242 | value_free (bpt->val); | |
9243 | xfree (bpt->source_file); | |
9244 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9245 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
9246 | |
9247 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
9248 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
9249 | We just check stop_bpstat for now. Note that we cannot just |
9250 | remove bpstats pointing at bpt from the stop_bpstat list | |
9251 | entirely, as breakpoint commands are associated with the bpstat; | |
9252 | if we remove it here, then the later call to | |
9253 | bpstat_do_actions (&stop_bpstat); | |
9254 | in event-top.c won't do anything, and temporary breakpoints | |
9255 | with commands won't work. */ | |
a474d7c2 | 9256 | |
a474d7c2 | 9257 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
9258 | |
9259 | /* Now that breakpoint is removed from breakpoint | |
9260 | list, update the global location list. This | |
9261 | will remove locations that used to belong to | |
9262 | this breakpoint. Do this before freeing | |
9263 | the breakpoint itself, since remove_breakpoint | |
9264 | looks at location's owner. It might be better | |
9265 | design to have location completely self-contained, | |
9266 | but it's not the case now. */ | |
b60e7edf | 9267 | update_global_location_list (0); |
74960c60 VP |
9268 | |
9269 | ||
c906108c SS |
9270 | /* On the chance that someone will soon try again to delete this same |
9271 | bp, we mark it as deleted before freeing its storage. */ | |
9272 | bpt->type = bp_none; | |
9273 | ||
b8c9b27d | 9274 | xfree (bpt); |
c906108c SS |
9275 | } |
9276 | ||
4d6140d9 AC |
9277 | static void |
9278 | do_delete_breakpoint_cleanup (void *b) | |
9279 | { | |
9280 | delete_breakpoint (b); | |
9281 | } | |
9282 | ||
9283 | struct cleanup * | |
9284 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9285 | { | |
9286 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9287 | } | |
9288 | ||
95a42b64 TT |
9289 | /* A callback for map_breakpoint_numbers that calls |
9290 | delete_breakpoint. */ | |
9291 | ||
9292 | static void | |
9293 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9294 | { | |
9295 | delete_breakpoint (b); | |
9296 | } | |
9297 | ||
c906108c | 9298 | void |
fba45db2 | 9299 | delete_command (char *arg, int from_tty) |
c906108c SS |
9300 | { |
9301 | struct breakpoint *b, *temp; | |
9302 | ||
ea9365bb TT |
9303 | dont_repeat (); |
9304 | ||
c906108c SS |
9305 | if (arg == 0) |
9306 | { | |
9307 | int breaks_to_delete = 0; | |
9308 | ||
9309 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9310 | Do not delete internal or call-dummy breakpoints, these |
9311 | have to be deleted with an explicit breakpoint number argument. */ | |
9312 | ALL_BREAKPOINTS (b) | |
9313 | { | |
059fb39f | 9314 | if (b->type != bp_call_dummy |
aa7d318d | 9315 | && b->type != bp_std_terminate |
059fb39f | 9316 | && b->type != bp_shlib_event |
4efc6507 | 9317 | && b->type != bp_jit_event |
059fb39f PM |
9318 | && b->type != bp_thread_event |
9319 | && b->type != bp_overlay_event | |
0fd8e87f | 9320 | && b->type != bp_longjmp_master |
aa7d318d | 9321 | && b->type != bp_std_terminate_master |
059fb39f | 9322 | && b->number >= 0) |
973d738b DJ |
9323 | { |
9324 | breaks_to_delete = 1; | |
9325 | break; | |
9326 | } | |
c5aa993b | 9327 | } |
c906108c SS |
9328 | |
9329 | /* Ask user only if there are some breakpoints to delete. */ | |
9330 | if (!from_tty | |
e2e0b3e5 | 9331 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9332 | { |
c5aa993b JM |
9333 | ALL_BREAKPOINTS_SAFE (b, temp) |
9334 | { | |
059fb39f | 9335 | if (b->type != bp_call_dummy |
aa7d318d | 9336 | && b->type != bp_std_terminate |
059fb39f PM |
9337 | && b->type != bp_shlib_event |
9338 | && b->type != bp_thread_event | |
4efc6507 | 9339 | && b->type != bp_jit_event |
059fb39f | 9340 | && b->type != bp_overlay_event |
0fd8e87f | 9341 | && b->type != bp_longjmp_master |
aa7d318d | 9342 | && b->type != bp_std_terminate_master |
059fb39f | 9343 | && b->number >= 0) |
c5aa993b JM |
9344 | delete_breakpoint (b); |
9345 | } | |
c906108c SS |
9346 | } |
9347 | } | |
9348 | else | |
95a42b64 | 9349 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9350 | } |
9351 | ||
0d381245 VP |
9352 | static int |
9353 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9354 | { |
0d381245 VP |
9355 | for (; loc; loc = loc->next) |
9356 | if (!loc->shlib_disabled) | |
9357 | return 0; | |
9358 | return 1; | |
fe3f5fa8 VP |
9359 | } |
9360 | ||
776592bf DE |
9361 | /* Subroutine of update_breakpoint_locations to simplify it. |
9362 | Return non-zero if multiple fns in list LOC have the same name. | |
9363 | Null names are ignored. */ | |
9364 | ||
9365 | static int | |
9366 | ambiguous_names_p (struct bp_location *loc) | |
9367 | { | |
9368 | struct bp_location *l; | |
9369 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
9370 | (int (*) (const void *, const void *)) streq, | |
9371 | NULL, xcalloc, xfree); | |
9372 | ||
9373 | for (l = loc; l != NULL; l = l->next) | |
9374 | { | |
9375 | const char **slot; | |
9376 | const char *name = l->function_name; | |
9377 | ||
9378 | /* Allow for some names to be NULL, ignore them. */ | |
9379 | if (name == NULL) | |
9380 | continue; | |
9381 | ||
9382 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9383 | INSERT); | |
9384 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9385 | NULL. */ | |
9386 | if (*slot != NULL) | |
9387 | { | |
9388 | htab_delete (htab); | |
9389 | return 1; | |
9390 | } | |
9391 | *slot = name; | |
9392 | } | |
9393 | ||
9394 | htab_delete (htab); | |
9395 | return 0; | |
9396 | } | |
9397 | ||
fe3f5fa8 | 9398 | static void |
0d381245 VP |
9399 | update_breakpoint_locations (struct breakpoint *b, |
9400 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9401 | { |
9402 | int i; | |
9403 | char *s; | |
0d381245 VP |
9404 | struct bp_location *existing_locations = b->loc; |
9405 | ||
9406 | /* If there's no new locations, and all existing locations | |
9407 | are pending, don't do anything. This optimizes | |
9408 | the common case where all locations are in the same | |
9409 | shared library, that was unloaded. We'd like to | |
9410 | retain the location, so that when the library | |
9411 | is loaded again, we don't loose the enabled/disabled | |
9412 | status of the individual locations. */ | |
9413 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9414 | return; |
9415 | ||
fe3f5fa8 VP |
9416 | b->loc = NULL; |
9417 | ||
0d381245 | 9418 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9419 | { |
0d381245 | 9420 | struct bp_location *new_loc = |
39d61571 | 9421 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9422 | |
0d381245 VP |
9423 | /* Reparse conditions, they might contain references to the |
9424 | old symtab. */ | |
9425 | if (b->cond_string != NULL) | |
9426 | { | |
9427 | struct gdb_exception e; | |
fe3f5fa8 | 9428 | |
0d381245 VP |
9429 | s = b->cond_string; |
9430 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9431 | { | |
9432 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9433 | 0); | |
9434 | } | |
9435 | if (e.reason < 0) | |
9436 | { | |
9437 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9438 | b->number, e.message); | |
9439 | new_loc->enabled = 0; | |
9440 | } | |
9441 | } | |
fe3f5fa8 | 9442 | |
0d381245 VP |
9443 | if (b->source_file != NULL) |
9444 | xfree (b->source_file); | |
9445 | if (sals.sals[i].symtab == NULL) | |
9446 | b->source_file = NULL; | |
9447 | else | |
1b36a34b | 9448 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9449 | |
0d381245 VP |
9450 | if (b->line_number == 0) |
9451 | b->line_number = sals.sals[i].line; | |
9452 | } | |
fe3f5fa8 | 9453 | |
514f746b AR |
9454 | /* Update locations of permanent breakpoints. */ |
9455 | if (b->enable_state == bp_permanent) | |
9456 | make_breakpoint_permanent (b); | |
9457 | ||
0d381245 VP |
9458 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9459 | { | |
9460 | struct bp_location *e = existing_locations; | |
776592bf DE |
9461 | /* If there are multiple breakpoints with the same function name, |
9462 | e.g. for inline functions, comparing function names won't work. | |
9463 | Instead compare pc addresses; this is just a heuristic as things | |
9464 | may have moved, but in practice it gives the correct answer | |
9465 | often enough until a better solution is found. */ | |
9466 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9467 | ||
0d381245 VP |
9468 | for (; e; e = e->next) |
9469 | { | |
9470 | if (!e->enabled && e->function_name) | |
9471 | { | |
9472 | struct bp_location *l = b->loc; | |
776592bf DE |
9473 | if (have_ambiguous_names) |
9474 | { | |
9475 | for (; l; l = l->next) | |
6c95b8df PA |
9476 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9477 | l->pspace->aspace, l->address)) | |
776592bf DE |
9478 | { |
9479 | l->enabled = 0; | |
9480 | break; | |
9481 | } | |
9482 | } | |
9483 | else | |
9484 | { | |
9485 | for (; l; l = l->next) | |
9486 | if (l->function_name | |
9487 | && strcmp (e->function_name, l->function_name) == 0) | |
9488 | { | |
9489 | l->enabled = 0; | |
9490 | break; | |
9491 | } | |
9492 | } | |
0d381245 VP |
9493 | } |
9494 | } | |
9495 | } | |
fe3f5fa8 | 9496 | |
b60e7edf | 9497 | update_global_location_list (1); |
fe3f5fa8 VP |
9498 | } |
9499 | ||
9500 | ||
c906108c SS |
9501 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9502 | The value we return ends up being the return value from catch_errors. | |
9503 | Unused in this case. */ | |
9504 | ||
9505 | static int | |
4efb68b1 | 9506 | breakpoint_re_set_one (void *bint) |
c906108c | 9507 | { |
53a5351d JM |
9508 | /* get past catch_errs */ |
9509 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9510 | struct value *mark; |
9511 | int i; | |
fe3f5fa8 VP |
9512 | int not_found = 0; |
9513 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9514 | struct symtabs_and_lines sals = {0}; |
9515 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9516 | char *s; |
b5de0fa7 | 9517 | enum enable_state save_enable; |
fe3f5fa8 | 9518 | struct gdb_exception e; |
6c95b8df | 9519 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9520 | |
9521 | switch (b->type) | |
9522 | { | |
9523 | case bp_none: | |
8a3fe4f8 | 9524 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9525 | b->number); |
c906108c SS |
9526 | return 0; |
9527 | case bp_breakpoint: | |
9528 | case bp_hardware_breakpoint: | |
1042e4c0 | 9529 | case bp_tracepoint: |
7a697b8d | 9530 | case bp_fast_tracepoint: |
8bea4e01 UW |
9531 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9532 | if (b->enable_state == bp_startup_disabled) | |
9533 | return 0; | |
9534 | ||
c906108c SS |
9535 | if (b->addr_string == NULL) |
9536 | { | |
9537 | /* Anything without a string can't be re-set. */ | |
9538 | delete_breakpoint (b); | |
9539 | return 0; | |
9540 | } | |
c906108c SS |
9541 | |
9542 | set_language (b->language); | |
9543 | input_radix = b->input_radix; | |
9544 | s = b->addr_string; | |
6c95b8df PA |
9545 | |
9546 | save_current_space_and_thread (); | |
9547 | switch_to_program_space_and_thread (b->pspace); | |
9548 | ||
fe3f5fa8 | 9549 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9550 | { |
fe3f5fa8 VP |
9551 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9552 | not_found_ptr); | |
9553 | } | |
9554 | if (e.reason < 0) | |
9555 | { | |
9556 | int not_found_and_ok = 0; | |
9557 | /* For pending breakpoints, it's expected that parsing | |
9558 | will fail until the right shared library is loaded. | |
9559 | User has already told to create pending breakpoints and | |
9560 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9561 | state, then user already saw the message about that breakpoint | |
9562 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9563 | if (not_found |
9564 | && (b->condition_not_parsed | |
9565 | || (b->loc && b->loc->shlib_disabled) | |
9566 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9567 | not_found_and_ok = 1; |
9568 | ||
9569 | if (!not_found_and_ok) | |
c906108c | 9570 | { |
fe3f5fa8 VP |
9571 | /* We surely don't want to warn about the same breakpoint |
9572 | 10 times. One solution, implemented here, is disable | |
9573 | the breakpoint on error. Another solution would be to | |
9574 | have separate 'warning emitted' flag. Since this | |
9575 | happens only when a binary has changed, I don't know | |
9576 | which approach is better. */ | |
9577 | b->enable_state = bp_disabled; | |
9578 | throw_exception (e); | |
c906108c | 9579 | } |
fe3f5fa8 | 9580 | } |
c906108c | 9581 | |
6c95b8df | 9582 | if (!not_found) |
fe3f5fa8 | 9583 | { |
6c95b8df PA |
9584 | gdb_assert (sals.nelts == 1); |
9585 | ||
9586 | resolve_sal_pc (&sals.sals[0]); | |
9587 | if (b->condition_not_parsed && s && s[0]) | |
9588 | { | |
9589 | char *cond_string = 0; | |
9590 | int thread = -1; | |
9591 | int task = 0; | |
9592 | ||
9593 | find_condition_and_thread (s, sals.sals[0].pc, | |
9594 | &cond_string, &thread, &task); | |
9595 | if (cond_string) | |
9596 | b->cond_string = cond_string; | |
9597 | b->thread = thread; | |
9598 | b->task = task; | |
9599 | b->condition_not_parsed = 0; | |
9600 | } | |
9601 | ||
9602 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9603 | } |
6c95b8df PA |
9604 | |
9605 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9606 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9607 | break; |
9608 | ||
9609 | case bp_watchpoint: | |
9610 | case bp_hardware_watchpoint: | |
9611 | case bp_read_watchpoint: | |
9612 | case bp_access_watchpoint: | |
0b3de036 VP |
9613 | /* Watchpoint can be either on expression using entirely global variables, |
9614 | or it can be on local variables. | |
9615 | ||
9616 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9617 | across program restarts. Since they can use variables from shared | |
9618 | libraries, we need to reparse expression as libraries are loaded | |
9619 | and unloaded. | |
9620 | ||
9621 | Watchpoints on local variables can also change meaning as result | |
9622 | of solib event. For example, if a watchpoint uses both a local and | |
9623 | a global variables in expression, it's a local watchpoint, but | |
9624 | unloading of a shared library will make the expression invalid. | |
9625 | This is not a very common use case, but we still re-evaluate | |
9626 | expression, to avoid surprises to the user. | |
9627 | ||
9628 | Note that for local watchpoints, we re-evaluate it only if | |
9629 | watchpoints frame id is still valid. If it's not, it means | |
9630 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9631 | I'm not sure we'll ever be called in this case. | |
9632 | ||
9633 | If a local watchpoint's frame id is still valid, then | |
9634 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9635 | ||
9636 | Don't do anything about disabled watchpoints, since they will | |
9637 | be reevaluated again when enabled. */ | |
a5606eee | 9638 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9639 | break; |
c5aa993b JM |
9640 | /* We needn't really do anything to reset these, since the mask |
9641 | that requests them is unaffected by e.g., new libraries being | |
9642 | loaded. */ | |
ce78b96d | 9643 | case bp_catchpoint: |
c906108c | 9644 | break; |
c5aa993b | 9645 | |
c906108c | 9646 | default: |
a3f17187 | 9647 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9648 | /* fall through */ |
0fd8e87f UW |
9649 | /* Delete overlay event and longjmp master breakpoints; they will be |
9650 | reset later by breakpoint_re_set. */ | |
1900040c | 9651 | case bp_overlay_event: |
0fd8e87f | 9652 | case bp_longjmp_master: |
aa7d318d | 9653 | case bp_std_terminate_master: |
c906108c SS |
9654 | delete_breakpoint (b); |
9655 | break; | |
9656 | ||
c5aa993b JM |
9657 | /* This breakpoint is special, it's set up when the inferior |
9658 | starts and we really don't want to touch it. */ | |
c906108c SS |
9659 | case bp_shlib_event: |
9660 | ||
c4093a6a JM |
9661 | /* Like bp_shlib_event, this breakpoint type is special. |
9662 | Once it is set up, we do not want to touch it. */ | |
9663 | case bp_thread_event: | |
9664 | ||
c5aa993b JM |
9665 | /* Keep temporary breakpoints, which can be encountered when we step |
9666 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9667 | Otherwise these should have been blown away via the cleanup chain | |
9668 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9669 | case bp_until: |
9670 | case bp_finish: | |
9671 | case bp_watchpoint_scope: | |
9672 | case bp_call_dummy: | |
aa7d318d | 9673 | case bp_std_terminate: |
c906108c | 9674 | case bp_step_resume: |
611c83ae PA |
9675 | case bp_longjmp: |
9676 | case bp_longjmp_resume: | |
4efc6507 | 9677 | case bp_jit_event: |
c906108c SS |
9678 | break; |
9679 | } | |
9680 | ||
6c95b8df | 9681 | do_cleanups (cleanups); |
c906108c SS |
9682 | return 0; |
9683 | } | |
9684 | ||
69de3c6a | 9685 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9686 | void |
69de3c6a | 9687 | breakpoint_re_set (void) |
c906108c SS |
9688 | { |
9689 | struct breakpoint *b, *temp; | |
9690 | enum language save_language; | |
9691 | int save_input_radix; | |
6c95b8df | 9692 | struct cleanup *old_chain; |
c5aa993b | 9693 | |
c906108c SS |
9694 | save_language = current_language->la_language; |
9695 | save_input_radix = input_radix; | |
6c95b8df PA |
9696 | old_chain = save_current_program_space (); |
9697 | ||
c906108c | 9698 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9699 | { |
53a5351d | 9700 | /* Format possible error msg */ |
fe3f5fa8 | 9701 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9702 | b->number); |
9703 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9704 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9705 | do_cleanups (cleanups); |
c5aa993b | 9706 | } |
c906108c SS |
9707 | set_language (save_language); |
9708 | input_radix = save_input_radix; | |
e62c965a | 9709 | |
0756c555 | 9710 | jit_breakpoint_re_set (); |
4efc6507 | 9711 | |
6c95b8df PA |
9712 | do_cleanups (old_chain); |
9713 | ||
69de3c6a | 9714 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9715 | create_longjmp_master_breakpoint ("longjmp"); |
9716 | create_longjmp_master_breakpoint ("_longjmp"); | |
9717 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9718 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 9719 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
9720 | } |
9721 | \f | |
c906108c SS |
9722 | /* Reset the thread number of this breakpoint: |
9723 | ||
9724 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9725 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9726 | void |
fba45db2 | 9727 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9728 | { |
9729 | if (b->thread != -1) | |
9730 | { | |
39f77062 KB |
9731 | if (in_thread_list (inferior_ptid)) |
9732 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9733 | |
9734 | /* We're being called after following a fork. The new fork is | |
9735 | selected as current, and unless this was a vfork will have a | |
9736 | different program space from the original thread. Reset that | |
9737 | as well. */ | |
9738 | b->loc->pspace = current_program_space; | |
c906108c SS |
9739 | } |
9740 | } | |
9741 | ||
03ac34d5 MS |
9742 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9743 | If from_tty is nonzero, it prints a message to that effect, | |
9744 | which ends with a period (no newline). */ | |
9745 | ||
c906108c | 9746 | void |
fba45db2 | 9747 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9748 | { |
52f0bd74 | 9749 | struct breakpoint *b; |
c906108c SS |
9750 | |
9751 | if (count < 0) | |
9752 | count = 0; | |
9753 | ||
9754 | ALL_BREAKPOINTS (b) | |
9755 | if (b->number == bptnum) | |
c5aa993b | 9756 | { |
d77f58be SS |
9757 | if (is_tracepoint (b)) |
9758 | { | |
9759 | if (from_tty && count != 0) | |
9760 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
9761 | bptnum); | |
9762 | return; | |
9763 | } | |
9764 | ||
c5aa993b | 9765 | b->ignore_count = count; |
221ea385 KS |
9766 | if (from_tty) |
9767 | { | |
9768 | if (count == 0) | |
a3f17187 | 9769 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9770 | bptnum); |
9771 | else if (count == 1) | |
a3f17187 | 9772 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9773 | bptnum); |
9774 | else | |
a3f17187 | 9775 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9776 | count, bptnum); |
9777 | } | |
c5aa993b | 9778 | breakpoints_changed (); |
383f836e | 9779 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9780 | return; |
9781 | } | |
c906108c | 9782 | |
8a3fe4f8 | 9783 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9784 | } |
9785 | ||
b2175913 MS |
9786 | void |
9787 | make_breakpoint_silent (struct breakpoint *b) | |
9788 | { | |
9789 | /* Silence the breakpoint. */ | |
9790 | b->silent = 1; | |
9791 | } | |
9792 | ||
c906108c SS |
9793 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9794 | ||
9795 | static void | |
fba45db2 | 9796 | ignore_command (char *args, int from_tty) |
c906108c SS |
9797 | { |
9798 | char *p = args; | |
52f0bd74 | 9799 | int num; |
c906108c SS |
9800 | |
9801 | if (p == 0) | |
e2e0b3e5 | 9802 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9803 | |
c906108c | 9804 | num = get_number (&p); |
5c44784c | 9805 | if (num == 0) |
8a3fe4f8 | 9806 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9807 | if (*p == 0) |
8a3fe4f8 | 9808 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9809 | |
9810 | set_ignore_count (num, | |
9811 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9812 | from_tty); | |
221ea385 KS |
9813 | if (from_tty) |
9814 | printf_filtered ("\n"); | |
c906108c SS |
9815 | } |
9816 | \f | |
9817 | /* Call FUNCTION on each of the breakpoints | |
9818 | whose numbers are given in ARGS. */ | |
9819 | ||
9820 | static void | |
95a42b64 TT |
9821 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
9822 | void *), | |
9823 | void *data) | |
c906108c | 9824 | { |
52f0bd74 | 9825 | char *p = args; |
c906108c | 9826 | char *p1; |
52f0bd74 AC |
9827 | int num; |
9828 | struct breakpoint *b, *tmp; | |
11cf8741 | 9829 | int match; |
c906108c SS |
9830 | |
9831 | if (p == 0) | |
e2e0b3e5 | 9832 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9833 | |
9834 | while (*p) | |
9835 | { | |
11cf8741 | 9836 | match = 0; |
c906108c | 9837 | p1 = p; |
c5aa993b | 9838 | |
5c44784c JM |
9839 | num = get_number_or_range (&p1); |
9840 | if (num == 0) | |
c5aa993b | 9841 | { |
8a3fe4f8 | 9842 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9843 | } |
9844 | else | |
9845 | { | |
9846 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9847 | if (b->number == num) | |
9848 | { | |
9849 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9850 | match = 1; |
95a42b64 | 9851 | function (b, data); |
5c44784c | 9852 | if (related_breakpoint) |
95a42b64 | 9853 | function (related_breakpoint, data); |
11cf8741 | 9854 | break; |
5c44784c | 9855 | } |
11cf8741 | 9856 | if (match == 0) |
a3f17187 | 9857 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9858 | } |
c906108c SS |
9859 | p = p1; |
9860 | } | |
9861 | } | |
9862 | ||
0d381245 VP |
9863 | static struct bp_location * |
9864 | find_location_by_number (char *number) | |
9865 | { | |
9866 | char *dot = strchr (number, '.'); | |
9867 | char *p1; | |
9868 | int bp_num; | |
9869 | int loc_num; | |
9870 | struct breakpoint *b; | |
9871 | struct bp_location *loc; | |
9872 | ||
9873 | *dot = '\0'; | |
9874 | ||
9875 | p1 = number; | |
9876 | bp_num = get_number_or_range (&p1); | |
9877 | if (bp_num == 0) | |
9878 | error (_("Bad breakpoint number '%s'"), number); | |
9879 | ||
9880 | ALL_BREAKPOINTS (b) | |
9881 | if (b->number == bp_num) | |
9882 | { | |
9883 | break; | |
9884 | } | |
9885 | ||
9886 | if (!b || b->number != bp_num) | |
9887 | error (_("Bad breakpoint number '%s'"), number); | |
9888 | ||
9889 | p1 = dot+1; | |
9890 | loc_num = get_number_or_range (&p1); | |
9891 | if (loc_num == 0) | |
9892 | error (_("Bad breakpoint location number '%s'"), number); | |
9893 | ||
9894 | --loc_num; | |
9895 | loc = b->loc; | |
9896 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9897 | ; | |
9898 | if (!loc) | |
9899 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9900 | ||
9901 | return loc; | |
9902 | } | |
9903 | ||
9904 | ||
1900040c MS |
9905 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9906 | If from_tty is nonzero, it prints a message to that effect, | |
9907 | which ends with a period (no newline). */ | |
9908 | ||
c906108c | 9909 | void |
fba45db2 | 9910 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9911 | { |
9912 | /* Never disable a watchpoint scope breakpoint; we want to | |
9913 | hit them when we leave scope so we can delete both the | |
9914 | watchpoint and its scope breakpoint at that time. */ | |
9915 | if (bpt->type == bp_watchpoint_scope) | |
9916 | return; | |
9917 | ||
c2c6d25f | 9918 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9919 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9920 | return; |
9921 | ||
b5de0fa7 | 9922 | bpt->enable_state = bp_disabled; |
c906108c | 9923 | |
b60e7edf | 9924 | update_global_location_list (0); |
c906108c | 9925 | |
383f836e | 9926 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9927 | } |
9928 | ||
95a42b64 TT |
9929 | /* A callback for map_breakpoint_numbers that calls |
9930 | disable_breakpoint. */ | |
9931 | ||
9932 | static void | |
9933 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
9934 | { | |
9935 | disable_breakpoint (b); | |
9936 | } | |
9937 | ||
c906108c | 9938 | static void |
fba45db2 | 9939 | disable_command (char *args, int from_tty) |
c906108c | 9940 | { |
52f0bd74 | 9941 | struct breakpoint *bpt; |
c906108c SS |
9942 | if (args == 0) |
9943 | ALL_BREAKPOINTS (bpt) | |
9944 | switch (bpt->type) | |
c5aa993b JM |
9945 | { |
9946 | case bp_none: | |
8a3fe4f8 | 9947 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9948 | bpt->number); |
c5aa993b JM |
9949 | continue; |
9950 | case bp_breakpoint: | |
1042e4c0 | 9951 | case bp_tracepoint: |
7a697b8d | 9952 | case bp_fast_tracepoint: |
ce78b96d | 9953 | case bp_catchpoint: |
c5aa993b JM |
9954 | case bp_hardware_breakpoint: |
9955 | case bp_watchpoint: | |
9956 | case bp_hardware_watchpoint: | |
9957 | case bp_read_watchpoint: | |
9958 | case bp_access_watchpoint: | |
9959 | disable_breakpoint (bpt); | |
9960 | default: | |
9961 | continue; | |
9962 | } | |
0d381245 VP |
9963 | else if (strchr (args, '.')) |
9964 | { | |
9965 | struct bp_location *loc = find_location_by_number (args); | |
9966 | if (loc) | |
9967 | loc->enabled = 0; | |
b60e7edf | 9968 | update_global_location_list (0); |
0d381245 | 9969 | } |
c906108c | 9970 | else |
95a42b64 | 9971 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
9972 | } |
9973 | ||
9974 | static void | |
fba45db2 | 9975 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9976 | { |
c906108c SS |
9977 | int target_resources_ok, other_type_used; |
9978 | struct value *mark; | |
9979 | ||
9980 | if (bpt->type == bp_hardware_breakpoint) | |
9981 | { | |
9982 | int i; | |
c5aa993b | 9983 | i = hw_breakpoint_used_count (); |
53a5351d | 9984 | target_resources_ok = |
d92524f1 | 9985 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9986 | i + 1, 0); |
c906108c | 9987 | if (target_resources_ok == 0) |
8a3fe4f8 | 9988 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9989 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9990 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9991 | } |
9992 | ||
059fb39f PM |
9993 | if (bpt->type == bp_watchpoint |
9994 | || bpt->type == bp_hardware_watchpoint | |
9995 | || bpt->type == bp_read_watchpoint | |
9996 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9997 | { |
dde02812 ES |
9998 | struct gdb_exception e; |
9999 | ||
10000 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10001 | { |
dde02812 | 10002 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10003 | } |
dde02812 | 10004 | if (e.reason < 0) |
c5aa993b | 10005 | { |
dde02812 ES |
10006 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
10007 | bpt->number); | |
10008 | return; | |
c5aa993b | 10009 | } |
c906108c | 10010 | } |
0101ce28 | 10011 | |
b4c291bb KH |
10012 | if (bpt->enable_state != bp_permanent) |
10013 | bpt->enable_state = bp_enabled; | |
10014 | bpt->disposition = disposition; | |
b60e7edf | 10015 | update_global_location_list (1); |
b4c291bb KH |
10016 | breakpoints_changed (); |
10017 | ||
383f836e | 10018 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10019 | } |
10020 | ||
fe3f5fa8 | 10021 | |
c906108c | 10022 | void |
fba45db2 | 10023 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10024 | { |
10025 | do_enable_breakpoint (bpt, bpt->disposition); | |
10026 | } | |
10027 | ||
95a42b64 TT |
10028 | /* A callback for map_breakpoint_numbers that calls |
10029 | enable_breakpoint. */ | |
10030 | ||
10031 | static void | |
10032 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10033 | { | |
10034 | enable_breakpoint (b); | |
10035 | } | |
10036 | ||
c906108c SS |
10037 | /* The enable command enables the specified breakpoints (or all defined |
10038 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10039 | in stopping the inferior. */ |
c906108c | 10040 | |
c906108c | 10041 | static void |
fba45db2 | 10042 | enable_command (char *args, int from_tty) |
c906108c | 10043 | { |
52f0bd74 | 10044 | struct breakpoint *bpt; |
c906108c SS |
10045 | if (args == 0) |
10046 | ALL_BREAKPOINTS (bpt) | |
10047 | switch (bpt->type) | |
c5aa993b JM |
10048 | { |
10049 | case bp_none: | |
8a3fe4f8 | 10050 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10051 | bpt->number); |
c5aa993b JM |
10052 | continue; |
10053 | case bp_breakpoint: | |
1042e4c0 | 10054 | case bp_tracepoint: |
7a697b8d | 10055 | case bp_fast_tracepoint: |
ce78b96d | 10056 | case bp_catchpoint: |
c5aa993b JM |
10057 | case bp_hardware_breakpoint: |
10058 | case bp_watchpoint: | |
10059 | case bp_hardware_watchpoint: | |
10060 | case bp_read_watchpoint: | |
10061 | case bp_access_watchpoint: | |
10062 | enable_breakpoint (bpt); | |
10063 | default: | |
10064 | continue; | |
10065 | } | |
0d381245 VP |
10066 | else if (strchr (args, '.')) |
10067 | { | |
10068 | struct bp_location *loc = find_location_by_number (args); | |
10069 | if (loc) | |
10070 | loc->enabled = 1; | |
b60e7edf | 10071 | update_global_location_list (1); |
0d381245 | 10072 | } |
c906108c | 10073 | else |
95a42b64 | 10074 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10075 | } |
10076 | ||
10077 | static void | |
95a42b64 | 10078 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10079 | { |
b5de0fa7 | 10080 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10081 | } |
10082 | ||
c906108c | 10083 | static void |
fba45db2 | 10084 | enable_once_command (char *args, int from_tty) |
c906108c | 10085 | { |
95a42b64 | 10086 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10087 | } |
10088 | ||
10089 | static void | |
95a42b64 | 10090 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10091 | { |
b5de0fa7 | 10092 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10093 | } |
10094 | ||
c906108c | 10095 | static void |
fba45db2 | 10096 | enable_delete_command (char *args, int from_tty) |
c906108c | 10097 | { |
95a42b64 | 10098 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10099 | } |
10100 | \f | |
fa8d40ab JJ |
10101 | static void |
10102 | set_breakpoint_cmd (char *args, int from_tty) | |
10103 | { | |
10104 | } | |
10105 | ||
10106 | static void | |
10107 | show_breakpoint_cmd (char *args, int from_tty) | |
10108 | { | |
10109 | } | |
10110 | ||
1f3b5d1b PP |
10111 | /* Invalidate last known value of any hardware watchpoint if |
10112 | the memory which that value represents has been written to by | |
10113 | GDB itself. */ | |
10114 | ||
10115 | static void | |
10116 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10117 | const bfd_byte *data) | |
10118 | { | |
10119 | struct breakpoint *bp; | |
10120 | ||
10121 | ALL_BREAKPOINTS (bp) | |
10122 | if (bp->enable_state == bp_enabled | |
10123 | && bp->type == bp_hardware_watchpoint | |
10124 | && bp->val_valid && bp->val) | |
10125 | { | |
10126 | struct bp_location *loc; | |
10127 | ||
10128 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10129 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10130 | && loc->address + loc->length > addr | |
10131 | && addr + len > loc->address) | |
10132 | { | |
10133 | value_free (bp->val); | |
10134 | bp->val = NULL; | |
10135 | bp->val_valid = 0; | |
10136 | } | |
10137 | } | |
10138 | } | |
10139 | ||
c906108c SS |
10140 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10141 | ||
10142 | struct symtabs_and_lines | |
fba45db2 | 10143 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10144 | { |
10145 | struct symtabs_and_lines sals; | |
10146 | if (string == 0) | |
8a3fe4f8 | 10147 | error (_("Empty line specification.")); |
c906108c SS |
10148 | if (default_breakpoint_valid) |
10149 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10150 | default_breakpoint_symtab, |
10151 | default_breakpoint_line, | |
68219205 | 10152 | (char ***) NULL, NULL); |
c906108c SS |
10153 | else |
10154 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10155 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10156 | if (*string) |
8a3fe4f8 | 10157 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10158 | return sals; |
10159 | } | |
8181d85f DJ |
10160 | |
10161 | /* Create and insert a raw software breakpoint at PC. Return an | |
10162 | identifier, which should be used to remove the breakpoint later. | |
10163 | In general, places which call this should be using something on the | |
10164 | breakpoint chain instead; this function should be eliminated | |
10165 | someday. */ | |
10166 | ||
10167 | void * | |
6c95b8df PA |
10168 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10169 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10170 | { |
10171 | struct bp_target_info *bp_tgt; | |
10172 | ||
6c95b8df | 10173 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10174 | |
6c95b8df | 10175 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10176 | bp_tgt->placed_address = pc; |
6c95b8df | 10177 | |
a6d9a66e | 10178 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10179 | { |
10180 | /* Could not insert the breakpoint. */ | |
10181 | xfree (bp_tgt); | |
10182 | return NULL; | |
10183 | } | |
10184 | ||
10185 | return bp_tgt; | |
10186 | } | |
10187 | ||
10188 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10189 | ||
10190 | int | |
a6d9a66e | 10191 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10192 | { |
10193 | struct bp_target_info *bp_tgt = bp; | |
10194 | int ret; | |
10195 | ||
a6d9a66e | 10196 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10197 | xfree (bp_tgt); |
10198 | ||
10199 | return ret; | |
10200 | } | |
10201 | ||
10202 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10203 | ||
10204 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10205 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10206 | |
10207 | /* Create and insert a breakpoint for software single step. */ | |
10208 | ||
10209 | void | |
6c95b8df PA |
10210 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10211 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10212 | { |
10213 | void **bpt_p; | |
10214 | ||
10215 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10216 | { |
10217 | bpt_p = &single_step_breakpoints[0]; | |
10218 | single_step_gdbarch[0] = gdbarch; | |
10219 | } | |
8181d85f DJ |
10220 | else |
10221 | { | |
10222 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10223 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10224 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10225 | } |
10226 | ||
10227 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10228 | to only create the breakpoints once, and actually put them on the | |
10229 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10230 | adjust the addresses each time they were needed. Doing this requires | |
10231 | corresponding changes elsewhere where single step breakpoints are | |
10232 | handled, however. So, for now, we use this. */ | |
10233 | ||
6c95b8df | 10234 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10235 | if (*bpt_p == NULL) |
5af949e3 UW |
10236 | error (_("Could not insert single-step breakpoint at %s"), |
10237 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10238 | } |
10239 | ||
10240 | /* Remove and delete any breakpoints used for software single step. */ | |
10241 | ||
10242 | void | |
10243 | remove_single_step_breakpoints (void) | |
10244 | { | |
10245 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10246 | ||
10247 | /* See insert_single_step_breakpoint for more about this deprecated | |
10248 | call. */ | |
a6d9a66e UW |
10249 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10250 | single_step_breakpoints[0]); | |
10251 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10252 | single_step_breakpoints[0] = NULL; |
10253 | ||
10254 | if (single_step_breakpoints[1] != NULL) | |
10255 | { | |
a6d9a66e UW |
10256 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10257 | single_step_breakpoints[1]); | |
10258 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10259 | single_step_breakpoints[1] = NULL; |
10260 | } | |
10261 | } | |
10262 | ||
1aafd4da UW |
10263 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10264 | ||
10265 | static int | |
6c95b8df | 10266 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
10267 | { |
10268 | int i; | |
10269 | ||
10270 | for (i = 0; i < 2; i++) | |
10271 | { | |
10272 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10273 | if (bp_tgt |
10274 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10275 | bp_tgt->placed_address, | |
10276 | aspace, pc)) | |
1aafd4da UW |
10277 | return 1; |
10278 | } | |
10279 | ||
10280 | return 0; | |
10281 | } | |
10282 | ||
a96d9b2e SDJ |
10283 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10284 | non-zero otherwise. */ | |
10285 | static int | |
10286 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10287 | { | |
10288 | if (syscall_catchpoint_p (bp) | |
10289 | && bp->enable_state != bp_disabled | |
10290 | && bp->enable_state != bp_call_disabled) | |
10291 | return 1; | |
10292 | else | |
10293 | return 0; | |
10294 | } | |
10295 | ||
10296 | int | |
10297 | catch_syscall_enabled (void) | |
10298 | { | |
10299 | struct inferior *inf = current_inferior (); | |
10300 | ||
10301 | return inf->total_syscalls_count != 0; | |
10302 | } | |
10303 | ||
10304 | int | |
10305 | catching_syscall_number (int syscall_number) | |
10306 | { | |
10307 | struct breakpoint *bp; | |
10308 | ||
10309 | ALL_BREAKPOINTS (bp) | |
10310 | if (is_syscall_catchpoint_enabled (bp)) | |
10311 | { | |
10312 | if (bp->syscalls_to_be_caught) | |
10313 | { | |
10314 | int i, iter; | |
10315 | for (i = 0; | |
10316 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10317 | i++) | |
10318 | if (syscall_number == iter) | |
10319 | return 1; | |
10320 | } | |
10321 | else | |
10322 | return 1; | |
10323 | } | |
10324 | ||
10325 | return 0; | |
10326 | } | |
10327 | ||
10328 | /* Complete syscall names. Used by "catch syscall". */ | |
10329 | static char ** | |
10330 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10331 | char *text, char *word) | |
10332 | { | |
10333 | const char **list = get_syscall_names (); | |
10334 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
10335 | } | |
10336 | ||
1042e4c0 SS |
10337 | /* Tracepoint-specific operations. */ |
10338 | ||
10339 | /* Set tracepoint count to NUM. */ | |
10340 | static void | |
10341 | set_tracepoint_count (int num) | |
10342 | { | |
10343 | tracepoint_count = num; | |
4fa62494 | 10344 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10345 | } |
10346 | ||
10347 | void | |
10348 | trace_command (char *arg, int from_tty) | |
10349 | { | |
8cdf0e15 VP |
10350 | if (create_breakpoint (get_current_arch (), |
10351 | arg, | |
10352 | NULL, 0, 1 /* parse arg */, | |
10353 | 0 /* tempflag */, 0 /* hardwareflag */, | |
10354 | 1 /* traceflag */, | |
10355 | 0 /* Ignore count */, | |
10356 | pending_break_support, | |
10357 | NULL, | |
10358 | from_tty, | |
10359 | 1 /* enabled */)) | |
fd9b8c24 | 10360 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10361 | } |
10362 | ||
7a697b8d SS |
10363 | void |
10364 | ftrace_command (char *arg, int from_tty) | |
10365 | { | |
8cdf0e15 VP |
10366 | if (create_breakpoint (get_current_arch (), |
10367 | arg, | |
10368 | NULL, 0, 1 /* parse arg */, | |
10369 | 0 /* tempflag */, 1 /* hardwareflag */, | |
10370 | 1 /* traceflag */, | |
10371 | 0 /* Ignore count */, | |
10372 | pending_break_support, | |
10373 | NULL, | |
10374 | from_tty, | |
10375 | 1 /* enabled */)) | |
fd9b8c24 | 10376 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
10377 | } |
10378 | ||
409873ef SS |
10379 | /* Set up a fake reader function that gets command lines from a linked |
10380 | list that was acquired during tracepoint uploading. */ | |
10381 | ||
10382 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 10383 | static int next_cmd; |
409873ef SS |
10384 | |
10385 | static char * | |
10386 | read_uploaded_action (void) | |
10387 | { | |
10388 | char *rslt; | |
10389 | ||
3149d8c1 | 10390 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 10391 | |
3149d8c1 | 10392 | next_cmd++; |
409873ef SS |
10393 | |
10394 | return rslt; | |
10395 | } | |
10396 | ||
00bf0b85 SS |
10397 | /* Given information about a tracepoint as recorded on a target (which |
10398 | can be either a live system or a trace file), attempt to create an | |
10399 | equivalent GDB tracepoint. This is not a reliable process, since | |
10400 | the target does not necessarily have all the information used when | |
10401 | the tracepoint was originally defined. */ | |
10402 | ||
10403 | struct breakpoint * | |
10404 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 10405 | { |
409873ef | 10406 | char *addr_str, small_buf[100]; |
d5551862 | 10407 | struct breakpoint *tp; |
fd9b8c24 | 10408 | |
409873ef SS |
10409 | if (utp->at_string) |
10410 | addr_str = utp->at_string; | |
10411 | else | |
10412 | { | |
10413 | /* In the absence of a source location, fall back to raw | |
10414 | address. Since there is no way to confirm that the address | |
10415 | means the same thing as when the trace was started, warn the | |
10416 | user. */ | |
10417 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), | |
10418 | utp->number); | |
10419 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
10420 | addr_str = small_buf; | |
10421 | } | |
10422 | ||
10423 | /* There's not much we can do with a sequence of bytecodes. */ | |
10424 | if (utp->cond && !utp->cond_string) | |
10425 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), | |
10426 | utp->number); | |
d5551862 | 10427 | |
8cdf0e15 | 10428 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
10429 | addr_str, |
10430 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 VP |
10431 | 0 /* tempflag */, |
10432 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
10433 | 1 /* traceflag */, | |
10434 | 0 /* Ignore count */, | |
10435 | pending_break_support, | |
10436 | NULL, | |
10437 | 0 /* from_tty */, | |
10438 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
10439 | return NULL; |
10440 | ||
00bf0b85 SS |
10441 | set_tracepoint_count (breakpoint_count); |
10442 | ||
409873ef | 10443 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
10444 | tp = get_tracepoint (tracepoint_count); |
10445 | gdb_assert (tp != NULL); | |
d5551862 | 10446 | |
00bf0b85 SS |
10447 | if (utp->pass > 0) |
10448 | { | |
409873ef | 10449 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 10450 | |
409873ef | 10451 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
10452 | } |
10453 | ||
409873ef SS |
10454 | /* If we have uploaded versions of the original commands, set up a |
10455 | special-purpose "reader" function and call the usual command line | |
10456 | reader, then pass the result to the breakpoint command-setting | |
10457 | function. */ | |
3149d8c1 | 10458 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 10459 | { |
409873ef | 10460 | struct command_line *cmd_list; |
00bf0b85 | 10461 | |
409873ef | 10462 | this_utp = utp; |
3149d8c1 | 10463 | next_cmd = 0; |
d5551862 | 10464 | |
409873ef SS |
10465 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
10466 | ||
10467 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 10468 | } |
3149d8c1 SS |
10469 | else if (!VEC_empty (char_ptr, utp->actions) |
10470 | || !VEC_empty (char_ptr, utp->step_actions)) | |
409873ef SS |
10471 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), |
10472 | utp->number); | |
00bf0b85 SS |
10473 | |
10474 | return tp; | |
10475 | } | |
10476 | ||
1042e4c0 SS |
10477 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10478 | omitted. */ | |
10479 | ||
10480 | static void | |
10481 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10482 | { | |
d77f58be SS |
10483 | int tpnum = -1, num_printed; |
10484 | ||
10485 | if (tpnum_exp) | |
10486 | tpnum = parse_and_eval_long (tpnum_exp); | |
1042e4c0 | 10487 | |
d77f58be SS |
10488 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
10489 | ||
10490 | if (num_printed == 0) | |
1042e4c0 | 10491 | { |
d77f58be SS |
10492 | if (tpnum == -1) |
10493 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10494 | else | |
10495 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); | |
1042e4c0 | 10496 | } |
ad443146 SS |
10497 | |
10498 | default_collect_info (); | |
1042e4c0 SS |
10499 | } |
10500 | ||
10501 | /* The 'enable trace' command enables tracepoints. | |
10502 | Not supported by all targets. */ | |
10503 | static void | |
10504 | enable_trace_command (char *args, int from_tty) | |
10505 | { | |
10506 | enable_command (args, from_tty); | |
10507 | } | |
10508 | ||
10509 | /* The 'disable trace' command disables tracepoints. | |
10510 | Not supported by all targets. */ | |
10511 | static void | |
10512 | disable_trace_command (char *args, int from_tty) | |
10513 | { | |
10514 | disable_command (args, from_tty); | |
10515 | } | |
10516 | ||
10517 | /* Remove a tracepoint (or all if no argument) */ | |
10518 | static void | |
10519 | delete_trace_command (char *arg, int from_tty) | |
10520 | { | |
10521 | struct breakpoint *b, *temp; | |
10522 | ||
10523 | dont_repeat (); | |
10524 | ||
10525 | if (arg == 0) | |
10526 | { | |
10527 | int breaks_to_delete = 0; | |
10528 | ||
10529 | /* Delete all breakpoints if no argument. | |
10530 | Do not delete internal or call-dummy breakpoints, these | |
10531 | have to be deleted with an explicit breakpoint number argument. */ | |
10532 | ALL_TRACEPOINTS (b) | |
10533 | { | |
10534 | if (b->number >= 0) | |
10535 | { | |
10536 | breaks_to_delete = 1; | |
10537 | break; | |
10538 | } | |
10539 | } | |
10540 | ||
10541 | /* Ask user only if there are some breakpoints to delete. */ | |
10542 | if (!from_tty | |
10543 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10544 | { | |
10545 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10546 | { | |
d77f58be | 10547 | if (is_tracepoint (b) |
059fb39f | 10548 | && b->number >= 0) |
1042e4c0 SS |
10549 | delete_breakpoint (b); |
10550 | } | |
10551 | } | |
10552 | } | |
10553 | else | |
95a42b64 | 10554 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
10555 | } |
10556 | ||
10557 | /* Set passcount for tracepoint. | |
10558 | ||
10559 | First command argument is passcount, second is tracepoint number. | |
10560 | If tracepoint number omitted, apply to most recently defined. | |
10561 | Also accepts special argument "all". */ | |
10562 | ||
10563 | static void | |
10564 | trace_pass_command (char *args, int from_tty) | |
10565 | { | |
10566 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10567 | unsigned int count; | |
10568 | int all = 0; | |
10569 | ||
10570 | if (args == 0 || *args == 0) | |
10571 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10572 | ||
10573 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10574 | ||
10575 | while (*args && isspace ((int) *args)) | |
10576 | args++; | |
10577 | ||
10578 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10579 | { | |
10580 | args += 3; /* Skip special argument "all". */ | |
10581 | all = 1; | |
10582 | if (*args) | |
10583 | error (_("Junk at end of arguments.")); | |
10584 | } | |
10585 | else | |
10586 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10587 | ||
10588 | do | |
10589 | { | |
10590 | if (t1) | |
10591 | { | |
10592 | ALL_TRACEPOINTS (t2) | |
10593 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10594 | { | |
10595 | t2->pass_count = count; | |
10596 | observer_notify_tracepoint_modified (t2->number); | |
10597 | if (from_tty) | |
10598 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10599 | t2->number, count); | |
10600 | } | |
10601 | if (! all && *args) | |
10602 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10603 | } | |
10604 | } | |
10605 | while (*args); | |
10606 | } | |
10607 | ||
10608 | struct breakpoint * | |
10609 | get_tracepoint (int num) | |
10610 | { | |
10611 | struct breakpoint *t; | |
10612 | ||
10613 | ALL_TRACEPOINTS (t) | |
10614 | if (t->number == num) | |
10615 | return t; | |
10616 | ||
10617 | return NULL; | |
10618 | } | |
10619 | ||
d5551862 SS |
10620 | /* Find the tracepoint with the given target-side number (which may be |
10621 | different from the tracepoint number after disconnecting and | |
10622 | reconnecting). */ | |
10623 | ||
10624 | struct breakpoint * | |
10625 | get_tracepoint_by_number_on_target (int num) | |
10626 | { | |
10627 | struct breakpoint *t; | |
10628 | ||
10629 | ALL_TRACEPOINTS (t) | |
10630 | if (t->number_on_target == num) | |
10631 | return t; | |
10632 | ||
10633 | return NULL; | |
10634 | } | |
10635 | ||
1042e4c0 SS |
10636 | /* Utility: parse a tracepoint number and look it up in the list. |
10637 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10638 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10639 | recent tracepoint (tracepoint_count) is returned. */ | |
10640 | struct breakpoint * | |
10641 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10642 | { | |
10643 | extern int tracepoint_count; | |
10644 | struct breakpoint *t; | |
10645 | int tpnum; | |
10646 | char *instring = arg == NULL ? NULL : *arg; | |
10647 | ||
10648 | if (arg == NULL || *arg == NULL || ! **arg) | |
10649 | { | |
10650 | if (optional_p) | |
10651 | tpnum = tracepoint_count; | |
10652 | else | |
10653 | error_no_arg (_("tracepoint number")); | |
10654 | } | |
10655 | else | |
10656 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10657 | ||
10658 | if (tpnum <= 0) | |
10659 | { | |
10660 | if (instring && *instring) | |
10661 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10662 | instring); | |
10663 | else | |
10664 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10665 | return NULL; | |
10666 | } | |
10667 | ||
10668 | ALL_TRACEPOINTS (t) | |
10669 | if (t->number == tpnum) | |
10670 | { | |
10671 | return t; | |
10672 | } | |
10673 | ||
10674 | /* FIXME: if we are in the middle of a range we don't want to give | |
10675 | a message. The current interface to get_number_or_range doesn't | |
10676 | allow us to discover this. */ | |
10677 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10678 | return NULL; | |
10679 | } | |
10680 | ||
10681 | /* save-tracepoints command */ | |
10682 | static void | |
10683 | tracepoint_save_command (char *args, int from_tty) | |
10684 | { | |
10685 | struct breakpoint *tp; | |
10686 | int any_tp = 0; | |
a7bdde9e VP |
10687 | struct command_line *line; |
10688 | char *pathname; | |
1042e4c0 SS |
10689 | char tmp[40]; |
10690 | struct cleanup *cleanup; | |
a7bdde9e | 10691 | struct ui_file *fp; |
1042e4c0 SS |
10692 | |
10693 | if (args == 0 || *args == 0) | |
10694 | error (_("Argument required (file name in which to save tracepoints)")); | |
10695 | ||
10696 | /* See if we have anything to save. */ | |
10697 | ALL_TRACEPOINTS (tp) | |
10698 | { | |
10699 | any_tp = 1; | |
10700 | break; | |
10701 | } | |
10702 | if (!any_tp) | |
10703 | { | |
10704 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10705 | return; | |
10706 | } | |
10707 | ||
10708 | pathname = tilde_expand (args); | |
10709 | cleanup = make_cleanup (xfree, pathname); | |
a7bdde9e | 10710 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 10711 | if (!fp) |
1042e4c0 SS |
10712 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10713 | args, safe_strerror (errno)); | |
a7bdde9e | 10714 | make_cleanup_ui_file_delete (fp); |
8bf6485c SS |
10715 | |
10716 | save_trace_state_variables (fp); | |
10717 | ||
1042e4c0 SS |
10718 | ALL_TRACEPOINTS (tp) |
10719 | { | |
8bf6485c SS |
10720 | if (tp->type == bp_fast_tracepoint) |
10721 | fprintf_unfiltered (fp, "ftrace"); | |
10722 | else | |
10723 | fprintf_unfiltered (fp, "trace"); | |
10724 | ||
1042e4c0 | 10725 | if (tp->addr_string) |
8bf6485c | 10726 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
1042e4c0 SS |
10727 | else |
10728 | { | |
10729 | sprintf_vma (tmp, tp->loc->address); | |
8bf6485c | 10730 | fprintf_unfiltered (fp, " *0x%s", tmp); |
1042e4c0 SS |
10731 | } |
10732 | ||
8bf6485c SS |
10733 | if (tp->cond_string) |
10734 | fprintf_unfiltered (fp, " if %s", tp->cond_string); | |
10735 | ||
10736 | fprintf_unfiltered (fp, "\n"); | |
10737 | ||
1042e4c0 | 10738 | if (tp->pass_count) |
a7bdde9e | 10739 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 10740 | |
a7bdde9e | 10741 | if (tp->commands) |
1042e4c0 | 10742 | { |
a7bdde9e VP |
10743 | volatile struct gdb_exception ex; |
10744 | ||
10745 | fprintf_unfiltered (fp, " actions\n"); | |
10746 | ||
10747 | ui_out_redirect (uiout, fp); | |
10748 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 10749 | { |
9add0f1b | 10750 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
10751 | } |
10752 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 10753 | |
a7bdde9e VP |
10754 | if (ex.reason < 0) |
10755 | throw_exception (ex); | |
1042e4c0 | 10756 | |
a7bdde9e | 10757 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 SS |
10758 | } |
10759 | } | |
8bf6485c SS |
10760 | |
10761 | if (*default_collect) | |
10762 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); | |
10763 | ||
1042e4c0 SS |
10764 | do_cleanups (cleanup); |
10765 | if (from_tty) | |
10766 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10767 | return; | |
10768 | } | |
10769 | ||
10770 | /* Create a vector of all tracepoints. */ | |
10771 | ||
10772 | VEC(breakpoint_p) * | |
10773 | all_tracepoints () | |
10774 | { | |
10775 | VEC(breakpoint_p) *tp_vec = 0; | |
10776 | struct breakpoint *tp; | |
10777 | ||
10778 | ALL_TRACEPOINTS (tp) | |
10779 | { | |
10780 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10781 | } | |
10782 | ||
10783 | return tp_vec; | |
10784 | } | |
10785 | ||
c906108c | 10786 | \f |
31e2b00f AS |
10787 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10788 | It is defined as a macro to prevent duplication. | |
10789 | COMMAND should be a string constant containing the name of the command. */ | |
10790 | #define BREAK_ARGS_HELP(command) \ | |
10791 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10792 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10793 | If a line number is specified, break at start of code for that line.\n\ | |
10794 | If a function is specified, break at start of code for that function.\n\ | |
10795 | If an address is specified, break at that exact address.\n\ | |
10796 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10797 | This is useful for breaking on return to a stack frame.\n\ | |
10798 | \n\ | |
10799 | THREADNUM is the number from \"info threads\".\n\ | |
10800 | CONDITION is a boolean expression.\n\ | |
10801 | \n\ | |
10802 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10803 | \n\ | |
10804 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10805 | ||
44feb3ce TT |
10806 | /* List of subcommands for "catch". */ |
10807 | static struct cmd_list_element *catch_cmdlist; | |
10808 | ||
10809 | /* List of subcommands for "tcatch". */ | |
10810 | static struct cmd_list_element *tcatch_cmdlist; | |
10811 | ||
10812 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10813 | lists, and pass some additional user data to the command function. */ | |
10814 | static void | |
10815 | add_catch_command (char *name, char *docstring, | |
10816 | void (*sfunc) (char *args, int from_tty, | |
10817 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10818 | char **(*completer) (struct cmd_list_element *cmd, |
10819 | char *text, char *word), | |
44feb3ce TT |
10820 | void *user_data_catch, |
10821 | void *user_data_tcatch) | |
10822 | { | |
10823 | struct cmd_list_element *command; | |
10824 | ||
10825 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10826 | &catch_cmdlist); | |
10827 | set_cmd_sfunc (command, sfunc); | |
10828 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10829 | set_cmd_completer (command, completer); |
44feb3ce TT |
10830 | |
10831 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10832 | &tcatch_cmdlist); | |
10833 | set_cmd_sfunc (command, sfunc); | |
10834 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10835 | set_cmd_completer (command, completer); |
44feb3ce TT |
10836 | } |
10837 | ||
6c95b8df | 10838 | static void |
a79b8f6e | 10839 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10840 | { |
6c95b8df PA |
10841 | inf->total_syscalls_count = 0; |
10842 | inf->any_syscall_count = 0; | |
10843 | VEC_free (int, inf->syscalls_counts); | |
10844 | } | |
10845 | ||
c906108c | 10846 | void |
fba45db2 | 10847 | _initialize_breakpoint (void) |
c906108c | 10848 | { |
fa8d40ab JJ |
10849 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10850 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10851 | struct cmd_list_element *c; |
10852 | ||
84acb35a | 10853 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10854 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10855 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10856 | |
c906108c SS |
10857 | breakpoint_chain = 0; |
10858 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10859 | before a breakpoint is set. */ | |
10860 | breakpoint_count = 0; | |
10861 | ||
1042e4c0 SS |
10862 | tracepoint_count = 0; |
10863 | ||
1bedd215 AC |
10864 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10865 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10866 | Usage is `ignore N COUNT'.")); | |
c906108c | 10867 | if (xdb_commands) |
c5aa993b | 10868 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10869 | |
1bedd215 AC |
10870 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10871 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10872 | Give breakpoint number as argument after \"commands\".\n\ |
10873 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10874 | The commands themselves follow starting on the next line.\n\ | |
10875 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10876 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10877 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10878 | |
1bedd215 AC |
10879 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10880 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10881 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10882 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10883 | |
1bedd215 | 10884 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10885 | Set a temporary breakpoint.\n\ |
c906108c SS |
10886 | Like \"break\" except the breakpoint is only temporary,\n\ |
10887 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10888 | by using \"enable delete\" on the breakpoint number.\n\ |
10889 | \n" | |
10890 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10891 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10892 | |
1bedd215 | 10893 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10894 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10895 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10896 | some target hardware may not have this support.\n\ |
10897 | \n" | |
10898 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10899 | set_cmd_completer (c, location_completer); |
c906108c | 10900 | |
1bedd215 | 10901 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10902 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10903 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10904 | so it will be deleted when hit.\n\ |
10905 | \n" | |
10906 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10907 | set_cmd_completer (c, location_completer); |
c906108c | 10908 | |
1bedd215 AC |
10909 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10910 | Enable some breakpoints.\n\ | |
c906108c SS |
10911 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10912 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10913 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10914 | With a subcommand you can enable temporarily."), |
c906108c SS |
10915 | &enablelist, "enable ", 1, &cmdlist); |
10916 | if (xdb_commands) | |
1bedd215 AC |
10917 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10918 | Enable some breakpoints.\n\ | |
c906108c SS |
10919 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10920 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10921 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10922 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10923 | |
10924 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10925 | ||
1bedd215 AC |
10926 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10927 | Enable some breakpoints.\n\ | |
c906108c SS |
10928 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10929 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10930 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10931 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10932 | |
1a966eab AC |
10933 | add_cmd ("once", no_class, enable_once_command, _("\ |
10934 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10935 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10936 | &enablebreaklist); |
10937 | ||
1a966eab AC |
10938 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10939 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10940 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10941 | &enablebreaklist); |
10942 | ||
1a966eab AC |
10943 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10944 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10945 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10946 | &enablelist); |
10947 | ||
1a966eab AC |
10948 | add_cmd ("once", no_class, enable_once_command, _("\ |
10949 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10950 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10951 | &enablelist); |
10952 | ||
1bedd215 AC |
10953 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10954 | Disable some breakpoints.\n\ | |
c906108c SS |
10955 | Arguments are breakpoint numbers with spaces in between.\n\ |
10956 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10957 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10958 | &disablelist, "disable ", 1, &cmdlist); |
10959 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10960 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10961 | if (xdb_commands) | |
1bedd215 AC |
10962 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10963 | Disable some breakpoints.\n\ | |
c906108c SS |
10964 | Arguments are breakpoint numbers with spaces in between.\n\ |
10965 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10966 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10967 | |
1a966eab AC |
10968 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10969 | Disable some breakpoints.\n\ | |
c906108c SS |
10970 | Arguments are breakpoint numbers with spaces in between.\n\ |
10971 | To disable all breakpoints, give no argument.\n\ | |
10972 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10973 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10974 | &disablelist); |
10975 | ||
1bedd215 AC |
10976 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10977 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10978 | Arguments are breakpoint numbers with spaces in between.\n\ |
10979 | To delete all breakpoints, give no argument.\n\ | |
10980 | \n\ | |
10981 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10982 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10983 | &deletelist, "delete ", 1, &cmdlist); |
10984 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10985 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10986 | if (xdb_commands) |
1bedd215 AC |
10987 | add_com ("db", class_breakpoint, delete_command, _("\ |
10988 | Delete some breakpoints.\n\ | |
c906108c | 10989 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10990 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10991 | |
1a966eab AC |
10992 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10993 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10994 | Arguments are breakpoint numbers with spaces in between.\n\ |
10995 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10996 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10997 | &deletelist); |
10998 | ||
1bedd215 AC |
10999 | add_com ("clear", class_breakpoint, clear_command, _("\ |
11000 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
11001 | Argument may be line number, function name, or \"*\" and an address.\n\ |
11002 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
11003 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
11004 | If an address is specified, breakpoints at that address are cleared.\n\ |
11005 | \n\ | |
11006 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
11007 | is executing in.\n\ |
11008 | \n\ | |
1bedd215 | 11009 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 11010 | |
1bedd215 | 11011 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
11012 | Set breakpoint at specified line or function.\n" |
11013 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 11014 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 11015 | |
c906108c SS |
11016 | add_com_alias ("b", "break", class_run, 1); |
11017 | add_com_alias ("br", "break", class_run, 1); | |
11018 | add_com_alias ("bre", "break", class_run, 1); | |
11019 | add_com_alias ("brea", "break", class_run, 1); | |
11020 | ||
7681d515 PM |
11021 | if (xdb_commands) |
11022 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
11023 | |
11024 | if (dbx_commands) | |
11025 | { | |
1bedd215 AC |
11026 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
11027 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
11028 | &stoplist, "stop ", 1, &cmdlist); |
11029 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 11030 | _("Break in function or address."), &stoplist); |
c5aa993b | 11031 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 11032 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
11033 | add_com ("status", class_info, breakpoints_info, _("\ |
11034 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11035 | The \"Type\" column indicates one of:\n\ |
11036 | \tbreakpoint - normal breakpoint\n\ | |
11037 | \twatchpoint - watchpoint\n\ | |
11038 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11039 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11040 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11041 | address and file/line number respectively.\n\ |
11042 | \n\ | |
11043 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11044 | are set to the address of the last breakpoint listed unless the command\n\ |
11045 | is prefixed with \"server \".\n\n\ | |
c906108c | 11046 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11047 | breakpoint set.")); |
c906108c SS |
11048 | } |
11049 | ||
1bedd215 AC |
11050 | add_info ("breakpoints", breakpoints_info, _("\ |
11051 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11052 | The \"Type\" column indicates one of:\n\ |
11053 | \tbreakpoint - normal breakpoint\n\ | |
11054 | \twatchpoint - watchpoint\n\ | |
11055 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11056 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11057 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11058 | address and file/line number respectively.\n\ |
11059 | \n\ | |
11060 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11061 | are set to the address of the last breakpoint listed unless the command\n\ |
11062 | is prefixed with \"server \".\n\n\ | |
c906108c | 11063 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11064 | breakpoint set.")); |
c906108c | 11065 | |
6b04bdb7 MS |
11066 | add_info_alias ("b", "breakpoints", 1); |
11067 | ||
c906108c | 11068 | if (xdb_commands) |
1bedd215 AC |
11069 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11070 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11071 | The \"Type\" column indicates one of:\n\ |
11072 | \tbreakpoint - normal breakpoint\n\ | |
11073 | \twatchpoint - watchpoint\n\ | |
11074 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11075 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11076 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11077 | address and file/line number respectively.\n\ |
11078 | \n\ | |
11079 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11080 | are set to the address of the last breakpoint listed unless the command\n\ |
11081 | is prefixed with \"server \".\n\n\ | |
c906108c | 11082 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11083 | breakpoint set.")); |
c906108c | 11084 | |
1a966eab AC |
11085 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11086 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11087 | The \"Type\" column indicates one of:\n\ |
11088 | \tbreakpoint - normal breakpoint\n\ | |
11089 | \twatchpoint - watchpoint\n\ | |
11090 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11091 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11092 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11093 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11094 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11095 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11096 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11097 | address and file/line number respectively.\n\ |
11098 | \n\ | |
11099 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11100 | are set to the address of the last breakpoint listed unless the command\n\ |
11101 | is prefixed with \"server \".\n\n\ | |
c906108c | 11102 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11103 | breakpoint set."), |
c906108c SS |
11104 | &maintenanceinfolist); |
11105 | ||
44feb3ce TT |
11106 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11107 | Set catchpoints to catch events."), | |
11108 | &catch_cmdlist, "catch ", | |
11109 | 0/*allow-unknown*/, &cmdlist); | |
11110 | ||
11111 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11112 | Set temporary catchpoints to catch events."), | |
11113 | &tcatch_cmdlist, "tcatch ", | |
11114 | 0/*allow-unknown*/, &cmdlist); | |
11115 | ||
11116 | /* Add catch and tcatch sub-commands. */ | |
11117 | add_catch_command ("catch", _("\ | |
11118 | Catch an exception, when caught.\n\ | |
11119 | With an argument, catch only exceptions with the given name."), | |
11120 | catch_catch_command, | |
a96d9b2e | 11121 | NULL, |
44feb3ce TT |
11122 | CATCH_PERMANENT, |
11123 | CATCH_TEMPORARY); | |
11124 | add_catch_command ("throw", _("\ | |
11125 | Catch an exception, when thrown.\n\ | |
11126 | With an argument, catch only exceptions with the given name."), | |
11127 | catch_throw_command, | |
a96d9b2e | 11128 | NULL, |
44feb3ce TT |
11129 | CATCH_PERMANENT, |
11130 | CATCH_TEMPORARY); | |
11131 | add_catch_command ("fork", _("Catch calls to fork."), | |
11132 | catch_fork_command_1, | |
a96d9b2e | 11133 | NULL, |
44feb3ce TT |
11134 | (void *) (uintptr_t) catch_fork_permanent, |
11135 | (void *) (uintptr_t) catch_fork_temporary); | |
11136 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11137 | catch_fork_command_1, | |
a96d9b2e | 11138 | NULL, |
44feb3ce TT |
11139 | (void *) (uintptr_t) catch_vfork_permanent, |
11140 | (void *) (uintptr_t) catch_vfork_temporary); | |
11141 | add_catch_command ("exec", _("Catch calls to exec."), | |
11142 | catch_exec_command_1, | |
a96d9b2e SDJ |
11143 | NULL, |
11144 | CATCH_PERMANENT, | |
11145 | CATCH_TEMPORARY); | |
11146 | add_catch_command ("syscall", _("\ | |
11147 | Catch system calls by their names and/or numbers.\n\ | |
11148 | Arguments say which system calls to catch. If no arguments\n\ | |
11149 | are given, every system call will be caught.\n\ | |
11150 | Arguments, if given, should be one or more system call names\n\ | |
11151 | (if your system supports that), or system call numbers."), | |
11152 | catch_syscall_command_1, | |
11153 | catch_syscall_completer, | |
44feb3ce TT |
11154 | CATCH_PERMANENT, |
11155 | CATCH_TEMPORARY); | |
44feb3ce TT |
11156 | add_catch_command ("exception", _("\ |
11157 | Catch Ada exceptions, when raised.\n\ | |
11158 | With an argument, catch only exceptions with the given name."), | |
11159 | catch_ada_exception_command, | |
a96d9b2e | 11160 | NULL, |
44feb3ce TT |
11161 | CATCH_PERMANENT, |
11162 | CATCH_TEMPORARY); | |
11163 | add_catch_command ("assert", _("\ | |
11164 | Catch failed Ada assertions, when raised.\n\ | |
11165 | With an argument, catch only exceptions with the given name."), | |
11166 | catch_assert_command, | |
a96d9b2e | 11167 | NULL, |
44feb3ce TT |
11168 | CATCH_PERMANENT, |
11169 | CATCH_TEMPORARY); | |
c5aa993b | 11170 | |
1bedd215 AC |
11171 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11172 | Set a watchpoint for an expression.\n\ | |
c906108c | 11173 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11174 | an expression changes.")); |
65d12d83 | 11175 | set_cmd_completer (c, expression_completer); |
c906108c | 11176 | |
1bedd215 AC |
11177 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11178 | Set a read watchpoint for an expression.\n\ | |
c906108c | 11179 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11180 | an expression is read.")); |
65d12d83 | 11181 | set_cmd_completer (c, expression_completer); |
c906108c | 11182 | |
1bedd215 AC |
11183 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11184 | Set a watchpoint for an expression.\n\ | |
c906108c | 11185 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 11186 | an expression is either read or written.")); |
65d12d83 | 11187 | set_cmd_completer (c, expression_completer); |
c906108c | 11188 | |
d77f58be SS |
11189 | add_info ("watchpoints", watchpoints_info, _("\ |
11190 | Status of watchpoints, or watchpoint number NUMBER.")); | |
11191 | ||
c906108c SS |
11192 | |
11193 | ||
920d2a44 AC |
11194 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11195 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11196 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11197 | &can_use_hw_watchpoints, _("\ | |
11198 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11199 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11200 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11201 | such is available. (However, any hardware watchpoints that were\n\ | |
11202 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11203 | hardware.)"), |
11204 | NULL, | |
920d2a44 | 11205 | show_can_use_hw_watchpoints, |
85c07804 | 11206 | &setlist, &showlist); |
c906108c SS |
11207 | |
11208 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11209 | |
1042e4c0 SS |
11210 | /* Tracepoint manipulation commands. */ |
11211 | ||
11212 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11213 | Set a tracepoint at specified line or function.\n\ | |
11214 | \n" | |
11215 | BREAK_ARGS_HELP ("trace") "\n\ | |
11216 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11217 | set_cmd_completer (c, location_completer); | |
11218 | ||
11219 | add_com_alias ("tp", "trace", class_alias, 0); | |
11220 | add_com_alias ("tr", "trace", class_alias, 1); | |
11221 | add_com_alias ("tra", "trace", class_alias, 1); | |
11222 | add_com_alias ("trac", "trace", class_alias, 1); | |
11223 | ||
7a697b8d SS |
11224 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11225 | Set a fast tracepoint at specified line or function.\n\ | |
11226 | \n" | |
11227 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11228 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11229 | set_cmd_completer (c, location_completer); | |
11230 | ||
1042e4c0 SS |
11231 | add_info ("tracepoints", tracepoints_info, _("\ |
11232 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
11233 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
11234 | last tracepoint set.")); | |
11235 | ||
11236 | add_info_alias ("tp", "tracepoints", 1); | |
11237 | ||
11238 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
11239 | Delete specified tracepoints.\n\ | |
11240 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11241 | No argument means delete all tracepoints."), | |
11242 | &deletelist); | |
11243 | ||
11244 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
11245 | Disable specified tracepoints.\n\ | |
11246 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11247 | No argument means disable all tracepoints."), | |
11248 | &disablelist); | |
11249 | deprecate_cmd (c, "disable"); | |
11250 | ||
11251 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
11252 | Enable specified tracepoints.\n\ | |
11253 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
11254 | No argument means enable all tracepoints."), | |
11255 | &enablelist); | |
11256 | deprecate_cmd (c, "enable"); | |
11257 | ||
11258 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
11259 | Set the passcount for a tracepoint.\n\ | |
11260 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
11261 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
11262 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
11263 | ||
11264 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
11265 | Save current tracepoint definitions as a script.\n\ | |
11266 | Use the 'source' command in another debug session to restore them.")); | |
11267 | set_cmd_completer (c, filename_completer); | |
11268 | ||
1bedd215 | 11269 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11270 | Breakpoint specific settings\n\ |
11271 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11272 | pending breakpoint behavior"), |
fa8d40ab JJ |
11273 | &breakpoint_set_cmdlist, "set breakpoint ", |
11274 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 11275 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
11276 | Breakpoint specific settings\n\ |
11277 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 11278 | pending breakpoint behavior"), |
fa8d40ab JJ |
11279 | &breakpoint_show_cmdlist, "show breakpoint ", |
11280 | 0/*allow-unknown*/, &showlist); | |
11281 | ||
7915a72c AC |
11282 | add_setshow_auto_boolean_cmd ("pending", no_class, |
11283 | &pending_break_support, _("\ | |
11284 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
11285 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
11286 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
11287 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
11288 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 11289 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 11290 | NULL, |
920d2a44 | 11291 | show_pending_break_support, |
6e1d7d6c AC |
11292 | &breakpoint_set_cmdlist, |
11293 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
11294 | |
11295 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
11296 | |
11297 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
11298 | &automatic_hardware_breakpoints, _("\ | |
11299 | Set automatic usage of hardware breakpoints."), _("\ | |
11300 | Show automatic usage of hardware breakpoints."), _("\ | |
11301 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
11302 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
11303 | a warning will be emitted for such breakpoints."), | |
11304 | NULL, | |
11305 | show_automatic_hardware_breakpoints, | |
11306 | &breakpoint_set_cmdlist, | |
11307 | &breakpoint_show_cmdlist); | |
74960c60 | 11308 | |
33e5cbd6 PA |
11309 | add_setshow_enum_cmd ("always-inserted", class_support, |
11310 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
11311 | Set mode for inserting breakpoints."), _("\ |
11312 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
11313 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
11314 | resumed, and removed when execution stops. When this mode is on,\n\ | |
11315 | breakpoints are inserted immediately and removed only when the user\n\ | |
11316 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
11317 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
11318 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
11319 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
11320 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
11321 | NULL, |
11322 | &show_always_inserted_mode, | |
11323 | &breakpoint_set_cmdlist, | |
11324 | &breakpoint_show_cmdlist); | |
765dc015 VP |
11325 | |
11326 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
11327 | |
11328 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 11329 | } |