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, |
0fb0cc75 | 5 | 2008, 2009 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" |
c906108c | 62 | |
1042e4c0 SS |
63 | /* readline include files */ |
64 | #include "readline/readline.h" | |
65 | #include "readline/history.h" | |
66 | ||
67 | /* readline defines this. */ | |
68 | #undef savestring | |
69 | ||
034dad6f | 70 | #include "mi/mi-common.h" |
104c1213 | 71 | |
44feb3ce TT |
72 | /* Arguments to pass as context to some catch command handlers. */ |
73 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
74 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 75 | |
44feb3ce | 76 | /* Prototypes for local functions. */ |
c906108c | 77 | |
a14ed312 | 78 | static void enable_delete_command (char *, int); |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_once_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 85 | |
a14ed312 | 86 | static void disable_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void enable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
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 | |
a6d9a66e UW |
108 | static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
109 | struct symtab_and_line, | |
110 | enum bptype); | |
c906108c | 111 | |
9f60f21b | 112 | static void check_duplicates (struct breakpoint *); |
c906108c | 113 | |
76897487 KB |
114 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
115 | ||
a6d9a66e UW |
116 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
117 | CORE_ADDR bpaddr, | |
88f7da05 | 118 | enum bptype bptype); |
76897487 | 119 | |
5af949e3 UW |
120 | static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR, |
121 | struct obj_section *, int); | |
c906108c | 122 | |
a14ed312 | 123 | static void breakpoints_info (char *, int); |
c906108c | 124 | |
a14ed312 | 125 | static void breakpoint_1 (int, int); |
c906108c | 126 | |
89f9893c | 127 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 128 | |
4efb68b1 | 129 | static int breakpoint_cond_eval (void *); |
c906108c | 130 | |
4efb68b1 | 131 | static void cleanup_executing_breakpoints (void *); |
c906108c | 132 | |
a14ed312 | 133 | static void commands_command (char *, int); |
c906108c | 134 | |
a14ed312 | 135 | static void condition_command (char *, int); |
c906108c | 136 | |
a14ed312 | 137 | static int get_number_trailer (char **, int); |
c906108c | 138 | |
a14ed312 | 139 | void set_breakpoint_count (int); |
c906108c | 140 | |
c5aa993b JM |
141 | typedef enum |
142 | { | |
143 | mark_inserted, | |
144 | mark_uninserted | |
145 | } | |
146 | insertion_state_t; | |
c906108c | 147 | |
0bde7532 | 148 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
c906108c | 149 | |
a14ed312 | 150 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
151 | |
152 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 153 | |
4efb68b1 | 154 | static int watchpoint_check (void *); |
c906108c | 155 | |
a14ed312 | 156 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 157 | |
a14ed312 | 158 | static int hw_breakpoint_used_count (void); |
c906108c | 159 | |
a14ed312 | 160 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 161 | |
a14ed312 | 162 | static void hbreak_command (char *, int); |
c906108c | 163 | |
a14ed312 | 164 | static void thbreak_command (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static void watch_command_1 (char *, int, int); |
c906108c | 167 | |
a14ed312 | 168 | static void rwatch_command (char *, int); |
c906108c | 169 | |
a14ed312 | 170 | static void awatch_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 173 | |
a14ed312 | 174 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 175 | |
a14ed312 | 176 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 179 | |
a14ed312 | 180 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 181 | |
a14ed312 | 182 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 183 | |
d85310f7 MS |
184 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
185 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 186 | |
a14ed312 | 187 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 190 | |
1aafd4da UW |
191 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
192 | ||
fe3f5fa8 VP |
193 | static void free_bp_location (struct bp_location *loc); |
194 | ||
39d61571 | 195 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 196 | |
b60e7edf | 197 | static void update_global_location_list (int); |
a5606eee | 198 | |
b60e7edf | 199 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
200 | |
201 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
202 | ||
203 | static void insert_breakpoint_locations (void); | |
a5606eee | 204 | |
1042e4c0 SS |
205 | static void tracepoints_info (char *, int); |
206 | ||
207 | static void delete_trace_command (char *, int); | |
208 | ||
209 | static void enable_trace_command (char *, int); | |
210 | ||
211 | static void disable_trace_command (char *, int); | |
212 | ||
213 | static void trace_pass_command (char *, int); | |
214 | ||
3daf8fe5 JG |
215 | static void skip_prologue_sal (struct symtab_and_line *sal); |
216 | ||
217 | ||
f3b1572e PA |
218 | /* Flag indicating that a command has proceeded the inferior past the |
219 | current breakpoint. */ | |
220 | ||
221 | static int breakpoint_proceeded; | |
222 | ||
2cec12e5 AR |
223 | static const char * |
224 | bpdisp_text (enum bpdisp disp) | |
225 | { | |
226 | /* NOTE: the following values are a part of MI protocol and represent | |
227 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
228 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
229 | return bpdisps[(int) disp]; | |
230 | } | |
c906108c | 231 | |
2cec12e5 | 232 | /* Prototypes for exported functions. */ |
c906108c SS |
233 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
234 | if such is available. */ | |
235 | static int can_use_hw_watchpoints; | |
236 | ||
920d2a44 AC |
237 | static void |
238 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
239 | struct cmd_list_element *c, | |
240 | const char *value) | |
241 | { | |
242 | fprintf_filtered (file, _("\ | |
243 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
244 | value); | |
245 | } | |
246 | ||
fa8d40ab JJ |
247 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
248 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
249 | for unrecognized breakpoint locations. | |
250 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
251 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
252 | static void |
253 | show_pending_break_support (struct ui_file *file, int from_tty, | |
254 | struct cmd_list_element *c, | |
255 | const char *value) | |
256 | { | |
257 | fprintf_filtered (file, _("\ | |
258 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
259 | value); | |
260 | } | |
fa8d40ab | 261 | |
765dc015 VP |
262 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
263 | set with "break" but falling in read-only memory. | |
264 | If 0, gdb will warn about such breakpoints, but won't automatically | |
265 | use hardware breakpoints. */ | |
266 | static int automatic_hardware_breakpoints; | |
267 | static void | |
268 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
269 | struct cmd_list_element *c, | |
270 | const char *value) | |
271 | { | |
272 | fprintf_filtered (file, _("\ | |
273 | Automatic usage of hardware breakpoints is %s.\n"), | |
274 | value); | |
275 | } | |
276 | ||
33e5cbd6 PA |
277 | /* If on, gdb will keep breakpoints inserted even as inferior is |
278 | stopped, and immediately insert any new breakpoints. If off, gdb | |
279 | will insert breakpoints into inferior only when resuming it, and | |
280 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
281 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
282 | ||
283 | static const char always_inserted_auto[] = "auto"; | |
284 | static const char always_inserted_on[] = "on"; | |
285 | static const char always_inserted_off[] = "off"; | |
286 | static const char *always_inserted_enums[] = { | |
287 | always_inserted_auto, | |
288 | always_inserted_off, | |
289 | always_inserted_on, | |
290 | NULL | |
291 | }; | |
292 | static const char *always_inserted_mode = always_inserted_auto; | |
293 | static void | |
74960c60 | 294 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 295 | struct cmd_list_element *c, const char *value) |
74960c60 | 296 | { |
33e5cbd6 PA |
297 | if (always_inserted_mode == always_inserted_auto) |
298 | fprintf_filtered (file, _("\ | |
299 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
300 | value, | |
301 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
302 | else | |
303 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
304 | } |
305 | ||
33e5cbd6 PA |
306 | int |
307 | breakpoints_always_inserted_mode (void) | |
308 | { | |
309 | return (always_inserted_mode == always_inserted_on | |
310 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
311 | } | |
765dc015 | 312 | |
a14ed312 | 313 | void _initialize_breakpoint (void); |
c906108c | 314 | |
c906108c SS |
315 | /* Are we executing breakpoint commands? */ |
316 | static int executing_breakpoint_commands; | |
317 | ||
c02f5703 MS |
318 | /* Are overlay event breakpoints enabled? */ |
319 | static int overlay_events_enabled; | |
320 | ||
c906108c SS |
321 | /* Walk the following statement or block through all breakpoints. |
322 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
323 | breakpoint. */ | |
324 | ||
5c44784c | 325 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 326 | |
5c44784c JM |
327 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
328 | for (B = breakpoint_chain; \ | |
329 | B ? (TMP=B->next, 1): 0; \ | |
330 | B = TMP) | |
c906108c | 331 | |
7cc221ef DJ |
332 | /* Similar iterators for the low-level breakpoints. */ |
333 | ||
0d381245 | 334 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
335 | |
336 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
337 | for (B = bp_location_chain; \ | |
0d381245 | 338 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
339 | B = TMP) |
340 | ||
1042e4c0 SS |
341 | /* Iterator for tracepoints only. */ |
342 | ||
343 | #define ALL_TRACEPOINTS(B) \ | |
344 | for (B = breakpoint_chain; B; B = B->next) \ | |
345 | if ((B)->type == bp_tracepoint) | |
346 | ||
7cc221ef | 347 | /* Chains of all breakpoints defined. */ |
c906108c SS |
348 | |
349 | struct breakpoint *breakpoint_chain; | |
350 | ||
7cc221ef DJ |
351 | struct bp_location *bp_location_chain; |
352 | ||
20874c92 VP |
353 | /* The locations that no longer correspond to any breakpoint, |
354 | unlinked from bp_location_chain, but for which a hit | |
355 | may still be reported by a target. */ | |
356 | VEC(bp_location_p) *moribund_locations = NULL; | |
357 | ||
c906108c SS |
358 | /* Number of last breakpoint made. */ |
359 | ||
360 | int breakpoint_count; | |
361 | ||
1042e4c0 SS |
362 | /* Number of last tracepoint made. */ |
363 | ||
364 | int tracepoint_count; | |
365 | ||
468d015d JJ |
366 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
367 | static int | |
368 | breakpoint_enabled (struct breakpoint *b) | |
369 | { | |
0d381245 | 370 | return (b->enable_state == bp_enabled); |
468d015d JJ |
371 | } |
372 | ||
c906108c SS |
373 | /* Set breakpoint count to NUM. */ |
374 | ||
375 | void | |
fba45db2 | 376 | set_breakpoint_count (int num) |
c906108c SS |
377 | { |
378 | breakpoint_count = num; | |
4fa62494 | 379 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
380 | } |
381 | ||
382 | /* Used in run_command to zero the hit count when a new run starts. */ | |
383 | ||
384 | void | |
fba45db2 | 385 | clear_breakpoint_hit_counts (void) |
c906108c SS |
386 | { |
387 | struct breakpoint *b; | |
388 | ||
389 | ALL_BREAKPOINTS (b) | |
390 | b->hit_count = 0; | |
391 | } | |
392 | ||
393 | /* Default address, symtab and line to put a breakpoint at | |
394 | for "break" command with no arg. | |
395 | if default_breakpoint_valid is zero, the other three are | |
396 | not valid, and "break" with no arg is an error. | |
397 | ||
398 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
399 | ||
400 | int default_breakpoint_valid; | |
401 | CORE_ADDR default_breakpoint_address; | |
402 | struct symtab *default_breakpoint_symtab; | |
403 | int default_breakpoint_line; | |
404 | \f | |
405 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
406 | Advance *PP after the string and any trailing whitespace. | |
407 | ||
408 | Currently the string can either be a number or "$" followed by the name | |
409 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 410 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
411 | |
412 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
413 | |
414 | TRAILER is a character which can be found after the number; most | |
415 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 416 | static int |
fba45db2 | 417 | get_number_trailer (char **pp, int trailer) |
c906108c | 418 | { |
5c44784c | 419 | int retval = 0; /* default */ |
c906108c SS |
420 | char *p = *pp; |
421 | ||
422 | if (p == NULL) | |
423 | /* Empty line means refer to the last breakpoint. */ | |
424 | return breakpoint_count; | |
425 | else if (*p == '$') | |
426 | { | |
427 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 428 | to pass to lookup_internalvar(). */ |
c906108c SS |
429 | char *varname; |
430 | char *start = ++p; | |
4fa62494 | 431 | LONGEST val; |
c906108c SS |
432 | |
433 | while (isalnum (*p) || *p == '_') | |
434 | p++; | |
435 | varname = (char *) alloca (p - start + 1); | |
436 | strncpy (varname, start, p - start); | |
437 | varname[p - start] = '\0'; | |
4fa62494 UW |
438 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
439 | retval = (int) val; | |
5c44784c JM |
440 | else |
441 | { | |
a3f17187 | 442 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
443 | retval = 0; |
444 | } | |
c906108c SS |
445 | } |
446 | else | |
447 | { | |
448 | if (*p == '-') | |
449 | ++p; | |
450 | while (*p >= '0' && *p <= '9') | |
451 | ++p; | |
452 | if (p == *pp) | |
453 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
454 | { |
455 | /* Skip non-numeric token */ | |
456 | while (*p && !isspace((int) *p)) | |
457 | ++p; | |
458 | /* Return zero, which caller must interpret as error. */ | |
459 | retval = 0; | |
460 | } | |
461 | else | |
462 | retval = atoi (*pp); | |
463 | } | |
464 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
465 | { | |
466 | /* Trailing junk: return 0 and let caller print error msg. */ | |
467 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
468 | ++p; | |
469 | retval = 0; | |
c906108c | 470 | } |
c906108c SS |
471 | while (isspace (*p)) |
472 | p++; | |
473 | *pp = p; | |
474 | return retval; | |
475 | } | |
5c44784c | 476 | |
11cf8741 | 477 | |
5c44784c JM |
478 | /* Like get_number_trailer, but don't allow a trailer. */ |
479 | int | |
fba45db2 | 480 | get_number (char **pp) |
5c44784c JM |
481 | { |
482 | return get_number_trailer (pp, '\0'); | |
483 | } | |
484 | ||
485 | /* Parse a number or a range. | |
486 | * A number will be of the form handled by get_number. | |
487 | * A range will be of the form <number1> - <number2>, and | |
488 | * will represent all the integers between number1 and number2, | |
489 | * inclusive. | |
490 | * | |
491 | * While processing a range, this fuction is called iteratively; | |
492 | * At each call it will return the next value in the range. | |
493 | * | |
494 | * At the beginning of parsing a range, the char pointer PP will | |
495 | * be advanced past <number1> and left pointing at the '-' token. | |
496 | * Subsequent calls will not advance the pointer until the range | |
497 | * is completed. The call that completes the range will advance | |
498 | * pointer PP past <number2>. | |
499 | */ | |
500 | ||
501 | int | |
fba45db2 | 502 | get_number_or_range (char **pp) |
5c44784c JM |
503 | { |
504 | static int last_retval, end_value; | |
505 | static char *end_ptr; | |
506 | static int in_range = 0; | |
507 | ||
508 | if (**pp != '-') | |
509 | { | |
510 | /* Default case: pp is pointing either to a solo number, | |
511 | or to the first number of a range. */ | |
512 | last_retval = get_number_trailer (pp, '-'); | |
513 | if (**pp == '-') | |
514 | { | |
515 | char **temp; | |
516 | ||
517 | /* This is the start of a range (<number1> - <number2>). | |
518 | Skip the '-', parse and remember the second number, | |
519 | and also remember the end of the final token. */ | |
520 | ||
521 | temp = &end_ptr; | |
522 | end_ptr = *pp + 1; | |
523 | while (isspace ((int) *end_ptr)) | |
524 | end_ptr++; /* skip white space */ | |
525 | end_value = get_number (temp); | |
526 | if (end_value < last_retval) | |
527 | { | |
8a3fe4f8 | 528 | error (_("inverted range")); |
5c44784c JM |
529 | } |
530 | else if (end_value == last_retval) | |
531 | { | |
532 | /* degenerate range (number1 == number2). Advance the | |
533 | token pointer so that the range will be treated as a | |
534 | single number. */ | |
535 | *pp = end_ptr; | |
536 | } | |
537 | else | |
538 | in_range = 1; | |
539 | } | |
540 | } | |
541 | else if (! in_range) | |
8a3fe4f8 | 542 | error (_("negative value")); |
5c44784c JM |
543 | else |
544 | { | |
545 | /* pp points to the '-' that betokens a range. All | |
546 | number-parsing has already been done. Return the next | |
547 | integer value (one greater than the saved previous value). | |
548 | Do not advance the token pointer 'pp' until the end of range | |
549 | is reached. */ | |
550 | ||
551 | if (++last_retval == end_value) | |
552 | { | |
553 | /* End of range reached; advance token pointer. */ | |
554 | *pp = end_ptr; | |
555 | in_range = 0; | |
556 | } | |
557 | } | |
558 | return last_retval; | |
559 | } | |
560 | ||
561 | ||
c906108c SS |
562 | \f |
563 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
564 | ||
565 | static void | |
fba45db2 | 566 | condition_command (char *arg, int from_tty) |
c906108c | 567 | { |
52f0bd74 | 568 | struct breakpoint *b; |
c906108c | 569 | char *p; |
52f0bd74 | 570 | int bnum; |
c906108c SS |
571 | |
572 | if (arg == 0) | |
e2e0b3e5 | 573 | error_no_arg (_("breakpoint number")); |
c906108c SS |
574 | |
575 | p = arg; | |
576 | bnum = get_number (&p); | |
5c44784c | 577 | if (bnum == 0) |
8a3fe4f8 | 578 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
579 | |
580 | ALL_BREAKPOINTS (b) | |
581 | if (b->number == bnum) | |
2f069f6f JB |
582 | { |
583 | struct bp_location *loc = b->loc; | |
584 | for (; loc; loc = loc->next) | |
585 | { | |
586 | if (loc->cond) | |
587 | { | |
588 | xfree (loc->cond); | |
589 | loc->cond = 0; | |
590 | } | |
591 | } | |
592 | if (b->cond_string != NULL) | |
593 | xfree (b->cond_string); | |
c906108c | 594 | |
2f069f6f JB |
595 | if (*p == 0) |
596 | { | |
597 | b->cond_string = NULL; | |
598 | if (from_tty) | |
599 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
600 | } | |
601 | else | |
602 | { | |
603 | arg = p; | |
604 | /* I don't know if it matters whether this is the string the user | |
605 | typed in or the decompiled expression. */ | |
1b36a34b | 606 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
607 | b->condition_not_parsed = 0; |
608 | for (loc = b->loc; loc; loc = loc->next) | |
609 | { | |
610 | arg = p; | |
611 | loc->cond = | |
612 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
613 | if (*arg) | |
614 | error (_("Junk at end of expression")); | |
615 | } | |
616 | } | |
617 | breakpoints_changed (); | |
383f836e | 618 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
619 | return; |
620 | } | |
c906108c | 621 | |
8a3fe4f8 | 622 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
623 | } |
624 | ||
c906108c | 625 | static void |
fba45db2 | 626 | commands_command (char *arg, int from_tty) |
c906108c | 627 | { |
52f0bd74 | 628 | struct breakpoint *b; |
c906108c | 629 | char *p; |
52f0bd74 | 630 | int bnum; |
c906108c SS |
631 | struct command_line *l; |
632 | ||
633 | /* If we allowed this, we would have problems with when to | |
634 | free the storage, if we change the commands currently | |
635 | being read from. */ | |
636 | ||
637 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 638 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
639 | |
640 | p = arg; | |
641 | bnum = get_number (&p); | |
5c44784c | 642 | |
c906108c | 643 | if (p && *p) |
8a3fe4f8 | 644 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 645 | |
c906108c SS |
646 | ALL_BREAKPOINTS (b) |
647 | if (b->number == bnum) | |
9ebf4acf AC |
648 | { |
649 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
650 | bnum); | |
651 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 652 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf AC |
653 | do_cleanups (cleanups); |
654 | free_command_lines (&b->commands); | |
655 | b->commands = l; | |
656 | breakpoints_changed (); | |
383f836e | 657 | observer_notify_breakpoint_modified (b->number); |
9ebf4acf | 658 | return; |
c5aa993b | 659 | } |
8a3fe4f8 | 660 | error (_("No breakpoint number %d."), bnum); |
c906108c | 661 | } |
40c03ae8 EZ |
662 | |
663 | /* Like commands_command, but instead of reading the commands from | |
664 | input stream, takes them from an already parsed command structure. | |
665 | ||
666 | This is used by cli-script.c to DTRT with breakpoint commands | |
667 | that are part of if and while bodies. */ | |
668 | enum command_control_type | |
669 | commands_from_control_command (char *arg, struct command_line *cmd) | |
670 | { | |
671 | struct breakpoint *b; | |
672 | char *p; | |
673 | int bnum; | |
674 | ||
675 | /* If we allowed this, we would have problems with when to | |
676 | free the storage, if we change the commands currently | |
677 | being read from. */ | |
678 | ||
679 | if (executing_breakpoint_commands) | |
680 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
681 | ||
682 | /* An empty string for the breakpoint number means the last | |
683 | breakpoint, but get_number expects a NULL pointer. */ | |
684 | if (arg && !*arg) | |
685 | p = NULL; | |
686 | else | |
687 | p = arg; | |
688 | bnum = get_number (&p); | |
689 | ||
690 | if (p && *p) | |
691 | error (_("Unexpected extra arguments following breakpoint number.")); | |
692 | ||
693 | ALL_BREAKPOINTS (b) | |
694 | if (b->number == bnum) | |
695 | { | |
696 | free_command_lines (&b->commands); | |
697 | if (cmd->body_count != 1) | |
698 | error (_("Invalid \"commands\" block structure.")); | |
699 | /* We need to copy the commands because if/while will free the | |
700 | list after it finishes execution. */ | |
701 | b->commands = copy_command_lines (cmd->body_list[0]); | |
702 | breakpoints_changed (); | |
383f836e | 703 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 704 | return simple_control; |
2f069f6f | 705 | } |
40c03ae8 EZ |
706 | error (_("No breakpoint number %d."), bnum); |
707 | } | |
c906108c | 708 | \f |
8defab1a DJ |
709 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
710 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 711 | |
8defab1a DJ |
712 | void |
713 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 714 | { |
8defab1a | 715 | struct bp_location *b; |
c906108c SS |
716 | CORE_ADDR bp_addr = 0; |
717 | int bp_size = 0; | |
8defab1a | 718 | int bptoffset = 0; |
c5aa993b | 719 | |
ffce0d52 | 720 | ALL_BP_LOCATIONS (b) |
c5aa993b | 721 | { |
ffce0d52 | 722 | if (b->owner->type == bp_none) |
8a3fe4f8 | 723 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
724 | b->owner->number); |
725 | ||
726 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 727 | continue; |
ffce0d52 | 728 | if (!b->inserted) |
c5aa993b JM |
729 | continue; |
730 | /* Addresses and length of the part of the breakpoint that | |
731 | we need to copy. */ | |
8181d85f DJ |
732 | bp_addr = b->target_info.placed_address; |
733 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 734 | if (bp_size == 0) |
8181d85f | 735 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 736 | continue; |
8defab1a | 737 | |
c5aa993b JM |
738 | if (bp_addr + bp_size <= memaddr) |
739 | /* The breakpoint is entirely before the chunk of memory we | |
740 | are reading. */ | |
741 | continue; | |
8defab1a | 742 | |
c5aa993b JM |
743 | if (bp_addr >= memaddr + len) |
744 | /* The breakpoint is entirely after the chunk of memory we are | |
745 | reading. */ | |
746 | continue; | |
c5aa993b | 747 | |
8defab1a DJ |
748 | /* Offset within shadow_contents. */ |
749 | if (bp_addr < memaddr) | |
750 | { | |
751 | /* Only copy the second part of the breakpoint. */ | |
752 | bp_size -= memaddr - bp_addr; | |
753 | bptoffset = memaddr - bp_addr; | |
754 | bp_addr = memaddr; | |
755 | } | |
c5aa993b | 756 | |
8defab1a DJ |
757 | if (bp_addr + bp_size > memaddr + len) |
758 | { | |
759 | /* Only copy the first part of the breakpoint. */ | |
760 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
761 | } | |
c5aa993b | 762 | |
8defab1a DJ |
763 | memcpy (buf + bp_addr - memaddr, |
764 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 765 | } |
c906108c | 766 | } |
c906108c | 767 | \f |
c5aa993b | 768 | |
687595f9 | 769 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 770 | static void |
687595f9 DJ |
771 | insert_catchpoint (struct ui_out *uo, void *args) |
772 | { | |
773 | struct breakpoint *b = (struct breakpoint *) args; | |
774 | int val = -1; | |
775 | ||
fe798b75 JB |
776 | gdb_assert (b->type == bp_catchpoint); |
777 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
778 | ||
779 | b->ops->insert (b); | |
687595f9 DJ |
780 | } |
781 | ||
a5606eee VP |
782 | static int |
783 | is_hardware_watchpoint (struct breakpoint *bpt) | |
784 | { | |
785 | return (bpt->type == bp_hardware_watchpoint | |
786 | || bpt->type == bp_read_watchpoint | |
787 | || bpt->type == bp_access_watchpoint); | |
788 | } | |
7270d8f2 | 789 | |
fa4727a6 DJ |
790 | /* Find the current value of a watchpoint on EXP. Return the value in |
791 | *VALP and *RESULTP and the chain of intermediate and final values | |
792 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
793 | not need them. | |
794 | ||
ccc57cf9 | 795 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
796 | be set to NULL. *RESULTP may be a lazy value, if the result could |
797 | not be read from memory. It is used to determine whether a value | |
798 | is user-specified (we should watch the whole value) or intermediate | |
799 | (we should watch only the bit used to locate the final value). | |
800 | ||
801 | If the final value, or any intermediate value, could not be read | |
802 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
803 | set to any referenced values. *VALP will never be a lazy value. | |
804 | This is the value which we store in struct breakpoint. | |
805 | ||
806 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
807 | value chain. The caller must free the values individually. If | |
808 | VAL_CHAIN is NULL, all generated values will be left on the value | |
809 | chain. */ | |
810 | ||
811 | static void | |
812 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
813 | struct value **resultp, struct value **val_chain) | |
814 | { | |
815 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 816 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
817 | |
818 | *valp = NULL; | |
819 | if (resultp) | |
820 | *resultp = NULL; | |
821 | if (val_chain) | |
822 | *val_chain = NULL; | |
823 | ||
824 | /* Evaluate the expression. */ | |
825 | mark = value_mark (); | |
826 | result = NULL; | |
ccc57cf9 PA |
827 | |
828 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
829 | { | |
830 | result = evaluate_expression (exp); | |
831 | } | |
832 | if (ex.reason < 0) | |
833 | { | |
834 | /* Ignore memory errors, we want watchpoints pointing at | |
835 | inaccessible memory to still be created; otherwise, throw the | |
836 | error to some higher catcher. */ | |
837 | switch (ex.error) | |
838 | { | |
839 | case MEMORY_ERROR: | |
840 | break; | |
841 | default: | |
842 | throw_exception (ex); | |
843 | break; | |
844 | } | |
845 | } | |
846 | ||
fa4727a6 DJ |
847 | new_mark = value_mark (); |
848 | if (mark == new_mark) | |
849 | return; | |
850 | if (resultp) | |
851 | *resultp = result; | |
852 | ||
853 | /* Make sure it's not lazy, so that after the target stops again we | |
854 | have a non-lazy previous value to compare with. */ | |
855 | if (result != NULL | |
856 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
857 | *valp = result; | |
858 | ||
859 | if (val_chain) | |
860 | { | |
861 | /* Return the chain of intermediate values. We use this to | |
862 | decide which addresses to watch. */ | |
863 | *val_chain = new_mark; | |
864 | value_release_to_mark (mark); | |
865 | } | |
866 | } | |
867 | ||
567e1b4e JB |
868 | /* Assuming that B is a watchpoint: |
869 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 870 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
871 | - Evaluate the condition if there is one, and store the result |
872 | in b->loc->cond. | |
a5606eee VP |
873 | - Update the list of values that must be watched in B->loc. |
874 | ||
bfa149ac JB |
875 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
876 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 877 | static void |
a5606eee | 878 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 879 | { |
a5606eee | 880 | int within_current_scope; |
a5606eee VP |
881 | struct frame_id saved_frame_id; |
882 | struct bp_location *loc; | |
883 | bpstat bs; | |
884 | ||
567e1b4e JB |
885 | /* We don't free locations. They are stored in bp_location_chain and |
886 | update_global_locations will eventually delete them and remove | |
887 | breakpoints if needed. */ | |
a5606eee VP |
888 | b->loc = NULL; |
889 | ||
890 | if (b->disposition == disp_del_at_next_stop) | |
891 | return; | |
892 | ||
893 | /* Save the current frame's ID so we can restore it after | |
894 | evaluating the watchpoint expression on its own frame. */ | |
895 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
896 | took a frame parameter, so that we didn't have to change the | |
897 | selected frame. */ | |
898 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
899 | ||
900 | /* Determine if the watchpoint is within scope. */ | |
901 | if (b->exp_valid_block == NULL) | |
902 | within_current_scope = 1; | |
903 | else | |
904 | { | |
905 | struct frame_info *fi; | |
906 | fi = frame_find_by_id (b->watchpoint_frame); | |
907 | within_current_scope = (fi != NULL); | |
908 | if (within_current_scope) | |
909 | select_frame (fi); | |
910 | } | |
911 | ||
912 | if (within_current_scope && reparse) | |
913 | { | |
914 | char *s; | |
915 | if (b->exp) | |
916 | { | |
917 | xfree (b->exp); | |
918 | b->exp = NULL; | |
919 | } | |
920 | s = b->exp_string; | |
921 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
922 | /* If the meaning of expression itself changed, the old value is | |
923 | no longer relevant. We don't want to report a watchpoint hit | |
924 | to the user when the old value and the new value may actually | |
925 | be completely different objects. */ | |
926 | value_free (b->val); | |
fa4727a6 DJ |
927 | b->val = NULL; |
928 | b->val_valid = 0; | |
a5606eee | 929 | } |
a5606eee VP |
930 | |
931 | /* If we failed to parse the expression, for example because | |
932 | it refers to a global variable in a not-yet-loaded shared library, | |
933 | don't try to insert watchpoint. We don't automatically delete | |
934 | such watchpoint, though, since failure to parse expression | |
935 | is different from out-of-scope watchpoint. */ | |
936 | if (within_current_scope && b->exp) | |
937 | { | |
fa4727a6 | 938 | struct value *val_chain, *v, *result, *next; |
a5606eee | 939 | |
fa4727a6 | 940 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 941 | |
a5606eee VP |
942 | /* Avoid setting b->val if it's already set. The meaning of |
943 | b->val is 'the last value' user saw, and we should update | |
944 | it only if we reported that last value to user. As it | |
945 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
946 | if (!b->val_valid) |
947 | { | |
948 | b->val = v; | |
949 | b->val_valid = 1; | |
950 | } | |
a5606eee | 951 | |
db2ad4c3 JK |
952 | /* Change the type of breakpoint between hardware assisted or an |
953 | ordinary watchpoint depending on the hardware support and free | |
954 | hardware slots. REPARSE is set when the inferior is started. */ | |
955 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
956 | && reparse) | |
957 | { | |
ca2d49e8 | 958 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
959 | |
960 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
961 | &other_type_used); | |
962 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
963 | ||
ca2d49e8 | 964 | if (!mem_cnt) |
db2ad4c3 JK |
965 | b->type = bp_watchpoint; |
966 | else | |
ca2d49e8 | 967 | { |
d92524f1 | 968 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
969 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
970 | if (target_resources_ok <= 0) | |
971 | b->type = bp_watchpoint; | |
972 | else | |
973 | b->type = bp_hardware_watchpoint; | |
974 | } | |
db2ad4c3 JK |
975 | } |
976 | ||
a5606eee | 977 | /* Look at each value on the value chain. */ |
fa4727a6 | 978 | for (v = val_chain; v; v = next) |
a5606eee VP |
979 | { |
980 | /* If it's a memory location, and GDB actually needed | |
981 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
982 | must watch it. If the first value returned is |
983 | still lazy, that means an error occurred reading it; | |
984 | watch it anyway in case it becomes readable. */ | |
a5606eee | 985 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 986 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
987 | { |
988 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 989 | |
a5606eee VP |
990 | /* We only watch structs and arrays if user asked |
991 | for it explicitly, never if they just happen to | |
992 | appear in the middle of some value chain. */ | |
fa4727a6 | 993 | if (v == result |
a5606eee VP |
994 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
995 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
996 | { | |
997 | CORE_ADDR addr; | |
998 | int len, type; | |
999 | struct bp_location *loc, **tmp; | |
1000 | ||
42ae5230 | 1001 | addr = value_address (v); |
a5606eee VP |
1002 | len = TYPE_LENGTH (value_type (v)); |
1003 | type = hw_write; | |
1004 | if (b->type == bp_read_watchpoint) | |
1005 | type = hw_read; | |
1006 | else if (b->type == bp_access_watchpoint) | |
1007 | type = hw_access; | |
1008 | ||
39d61571 | 1009 | loc = allocate_bp_location (b); |
a5606eee VP |
1010 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1011 | ; | |
1012 | *tmp = loc; | |
a6d9a66e | 1013 | loc->gdbarch = get_type_arch (value_type (v)); |
a5606eee VP |
1014 | loc->address = addr; |
1015 | loc->length = len; | |
1016 | loc->watchpoint_type = type; | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | next = value_next (v); | |
1021 | if (v != b->val) | |
1022 | value_free (v); | |
1023 | } | |
1024 | ||
2ec93238 MK |
1025 | /* We just regenerated the list of breakpoint locations. |
1026 | The new location does not have its condition field set to anything | |
1027 | and therefore, we must always reparse the cond_string, independently | |
1028 | of the value of the reparse flag. */ | |
1029 | if (b->cond_string != NULL) | |
a5606eee VP |
1030 | { |
1031 | char *s = b->cond_string; | |
a5606eee VP |
1032 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1033 | } | |
1034 | } | |
1035 | else if (!within_current_scope) | |
7270d8f2 | 1036 | { |
a5606eee | 1037 | printf_filtered (_("\ |
567e1b4e | 1038 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1039 | in which its expression is valid.\n"), |
1040 | b->number); | |
1041 | if (b->related_breakpoint) | |
1042 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1043 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1044 | } |
a5606eee VP |
1045 | |
1046 | /* Restore the selected frame. */ | |
1047 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1048 | } |
1049 | ||
a5606eee | 1050 | |
74960c60 VP |
1051 | /* Returns 1 iff breakpoint location should be |
1052 | inserted in the inferior. */ | |
1053 | static int | |
1054 | should_be_inserted (struct bp_location *bpt) | |
1055 | { | |
1056 | if (!breakpoint_enabled (bpt->owner)) | |
1057 | return 0; | |
1058 | ||
1059 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1060 | return 0; | |
1061 | ||
1062 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1063 | return 0; | |
1064 | ||
1042e4c0 SS |
1065 | /* Tracepoints are inserted by the target at a time of its choosing, |
1066 | not by us. */ | |
1067 | if (bpt->owner->type == bp_tracepoint) | |
1068 | return 0; | |
1069 | ||
74960c60 VP |
1070 | return 1; |
1071 | } | |
1072 | ||
879bfdc2 DJ |
1073 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1074 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1075 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1076 | |
1077 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1078 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1079 | static int |
879bfdc2 | 1080 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1081 | struct ui_file *tmp_error_stream, |
fa3a767f | 1082 | int *disabled_breaks, |
26bb91f3 | 1083 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1084 | { |
1085 | int val = 0; | |
1086 | ||
74960c60 | 1087 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1088 | return 0; |
1089 | ||
8181d85f DJ |
1090 | /* Initialize the target-specific information. */ |
1091 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1092 | bpt->target_info.placed_address = bpt->address; | |
1093 | ||
879bfdc2 DJ |
1094 | if (bpt->loc_type == bp_loc_software_breakpoint |
1095 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1096 | { | |
765dc015 VP |
1097 | if (bpt->owner->type != bp_hardware_breakpoint) |
1098 | { | |
1099 | /* If the explicitly specified breakpoint type | |
1100 | is not hardware breakpoint, check the memory map to see | |
1101 | if the breakpoint address is in read only memory or not. | |
1102 | Two important cases are: | |
1103 | - location type is not hardware breakpoint, memory | |
1104 | is readonly. We change the type of the location to | |
1105 | hardware breakpoint. | |
1106 | - location type is hardware breakpoint, memory is read-write. | |
1107 | This means we've previously made the location hardware one, but | |
1108 | then the memory map changed, so we undo. | |
1109 | ||
1110 | When breakpoints are removed, remove_breakpoints will | |
1111 | use location types we've just set here, the only possible | |
1112 | problem is that memory map has changed during running program, | |
1113 | but it's not going to work anyway with current gdb. */ | |
1114 | struct mem_region *mr | |
1115 | = lookup_mem_region (bpt->target_info.placed_address); | |
1116 | ||
1117 | if (mr) | |
1118 | { | |
1119 | if (automatic_hardware_breakpoints) | |
1120 | { | |
1121 | int changed = 0; | |
1122 | enum bp_loc_type new_type; | |
1123 | ||
1124 | if (mr->attrib.mode != MEM_RW) | |
1125 | new_type = bp_loc_hardware_breakpoint; | |
1126 | else | |
1127 | new_type = bp_loc_software_breakpoint; | |
1128 | ||
1129 | if (new_type != bpt->loc_type) | |
1130 | { | |
1131 | static int said = 0; | |
1132 | bpt->loc_type = new_type; | |
1133 | if (!said) | |
1134 | { | |
1135 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1136 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1137 | said = 1; |
1138 | } | |
1139 | } | |
1140 | } | |
1141 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1142 | && mr->attrib.mode != MEM_RW) | |
1143 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1144 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1145 | } |
1146 | } | |
1147 | ||
879bfdc2 DJ |
1148 | /* First check to see if we have to handle an overlay. */ |
1149 | if (overlay_debugging == ovly_off | |
1150 | || bpt->section == NULL | |
1151 | || !(section_is_overlay (bpt->section))) | |
1152 | { | |
1153 | /* No overlay handling: just set the breakpoint. */ | |
1154 | ||
1155 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1156 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1157 | &bpt->target_info); | |
879bfdc2 | 1158 | else |
a6d9a66e UW |
1159 | val = target_insert_breakpoint (bpt->gdbarch, |
1160 | &bpt->target_info); | |
879bfdc2 DJ |
1161 | } |
1162 | else | |
1163 | { | |
1164 | /* This breakpoint is in an overlay section. | |
1165 | Shall we set a breakpoint at the LMA? */ | |
1166 | if (!overlay_events_enabled) | |
1167 | { | |
1168 | /* Yes -- overlay event support is not active, | |
1169 | so we must try to set a breakpoint at the LMA. | |
1170 | This will not work for a hardware breakpoint. */ | |
1171 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1172 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1173 | bpt->owner->number); |
1174 | else | |
1175 | { | |
1176 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1177 | bpt->section); | |
1178 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1179 | bpt->overlay_target_info = bpt->target_info; |
1180 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1181 | val = target_insert_breakpoint (bpt->gdbarch, |
1182 | &bpt->overlay_target_info); | |
879bfdc2 | 1183 | if (val != 0) |
99361f52 DE |
1184 | fprintf_unfiltered (tmp_error_stream, |
1185 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1186 | bpt->owner->number); |
1187 | } | |
1188 | } | |
1189 | /* Shall we set a breakpoint at the VMA? */ | |
1190 | if (section_is_mapped (bpt->section)) | |
1191 | { | |
1192 | /* Yes. This overlay section is mapped into memory. */ | |
1193 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1194 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1195 | &bpt->target_info); | |
879bfdc2 | 1196 | else |
a6d9a66e UW |
1197 | val = target_insert_breakpoint (bpt->gdbarch, |
1198 | &bpt->target_info); | |
879bfdc2 DJ |
1199 | } |
1200 | else | |
1201 | { | |
1202 | /* No. This breakpoint will not be inserted. | |
1203 | No error, but do not mark the bp as 'inserted'. */ | |
1204 | return 0; | |
1205 | } | |
1206 | } | |
1207 | ||
1208 | if (val) | |
1209 | { | |
1210 | /* Can't set the breakpoint. */ | |
f5c9a895 | 1211 | if (solib_name_from_address (bpt->address)) |
879bfdc2 DJ |
1212 | { |
1213 | /* See also: disable_breakpoints_in_shlibs. */ | |
1214 | val = 0; | |
0d381245 | 1215 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1216 | if (!*disabled_breaks) |
1217 | { | |
1218 | fprintf_unfiltered (tmp_error_stream, | |
1219 | "Cannot insert breakpoint %d.\n", | |
1220 | bpt->owner->number); | |
1221 | fprintf_unfiltered (tmp_error_stream, | |
1222 | "Temporarily disabling shared library breakpoints:\n"); | |
1223 | } | |
1224 | *disabled_breaks = 1; | |
1225 | fprintf_unfiltered (tmp_error_stream, | |
1226 | "breakpoint #%d\n", bpt->owner->number); | |
1227 | } | |
1228 | else | |
879bfdc2 | 1229 | { |
879bfdc2 DJ |
1230 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1231 | { | |
1232 | *hw_breakpoint_error = 1; | |
1233 | fprintf_unfiltered (tmp_error_stream, | |
1234 | "Cannot insert hardware breakpoint %d.\n", | |
1235 | bpt->owner->number); | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | fprintf_unfiltered (tmp_error_stream, | |
1240 | "Cannot insert breakpoint %d.\n", | |
1241 | bpt->owner->number); | |
1242 | fprintf_filtered (tmp_error_stream, | |
1243 | "Error accessing memory address "); | |
5af949e3 UW |
1244 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1245 | tmp_error_stream); | |
879bfdc2 DJ |
1246 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1247 | safe_strerror (val)); | |
1248 | } | |
1249 | ||
1250 | } | |
1251 | } | |
1252 | else | |
1253 | bpt->inserted = 1; | |
1254 | ||
1255 | return val; | |
1256 | } | |
1257 | ||
1258 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1259 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1260 | watchpoints. It's not clear that it's necessary... */ | |
1261 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1262 | { | |
a5606eee VP |
1263 | val = target_insert_watchpoint (bpt->address, |
1264 | bpt->length, | |
1265 | bpt->watchpoint_type); | |
1266 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1267 | } |
1268 | ||
fe798b75 | 1269 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1270 | { |
71fff37b AC |
1271 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1272 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1273 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1274 | bpt->owner->number); | |
1275 | if (e.reason < 0) | |
879bfdc2 DJ |
1276 | bpt->owner->enable_state = bp_disabled; |
1277 | else | |
1278 | bpt->inserted = 1; | |
1640b821 DJ |
1279 | |
1280 | /* We've already printed an error message if there was a problem | |
1281 | inserting this catchpoint, and we've disabled the catchpoint, | |
1282 | so just return success. */ | |
1283 | return 0; | |
879bfdc2 DJ |
1284 | } |
1285 | ||
1286 | return 0; | |
1287 | } | |
1288 | ||
74960c60 VP |
1289 | /* Make sure all breakpoints are inserted in inferior. |
1290 | Throws exception on any error. | |
1291 | A breakpoint that is already inserted won't be inserted | |
1292 | again, so calling this function twice is safe. */ | |
1293 | void | |
1294 | insert_breakpoints (void) | |
1295 | { | |
1296 | struct breakpoint *bpt; | |
1297 | ||
1298 | ALL_BREAKPOINTS (bpt) | |
1299 | if (is_hardware_watchpoint (bpt)) | |
1300 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1301 | ||
b60e7edf | 1302 | update_global_location_list (1); |
74960c60 | 1303 | |
c35b1492 PA |
1304 | /* update_global_location_list does not insert breakpoints when |
1305 | always_inserted_mode is not enabled. Explicitly insert them | |
1306 | now. */ | |
1307 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1308 | insert_breakpoint_locations (); |
1309 | } | |
1310 | ||
c906108c SS |
1311 | /* insert_breakpoints is used when starting or continuing the program. |
1312 | remove_breakpoints is used when the program stops. | |
1313 | Both return zero if successful, | |
1314 | or an `errno' value if could not write the inferior. */ | |
1315 | ||
74960c60 VP |
1316 | static void |
1317 | insert_breakpoint_locations (void) | |
c906108c | 1318 | { |
a5606eee | 1319 | struct breakpoint *bpt; |
879bfdc2 | 1320 | struct bp_location *b, *temp; |
e236ba44 | 1321 | int error = 0; |
c906108c SS |
1322 | int val = 0; |
1323 | int disabled_breaks = 0; | |
81d0cc19 | 1324 | int hw_breakpoint_error = 0; |
c906108c | 1325 | |
81d0cc19 | 1326 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1327 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1328 | |
81d0cc19 GS |
1329 | /* Explicitly mark the warning -- this will only be printed if |
1330 | there was an error. */ | |
1331 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1332 | |
879bfdc2 DJ |
1333 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1334 | { | |
74960c60 | 1335 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1336 | continue; |
1337 | ||
f365de73 AS |
1338 | /* There is no point inserting thread-specific breakpoints if the |
1339 | thread no longer exists. */ | |
1340 | if (b->owner->thread != -1 | |
1341 | && !valid_thread_id (b->owner->thread)) | |
1342 | continue; | |
1343 | ||
879bfdc2 | 1344 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1345 | &disabled_breaks, |
879bfdc2 DJ |
1346 | &hw_breakpoint_error); |
1347 | if (val) | |
e236ba44 | 1348 | error = val; |
879bfdc2 | 1349 | } |
c906108c | 1350 | |
a5606eee VP |
1351 | /* If we failed to insert all locations of a watchpoint, |
1352 | remove them, as half-inserted watchpoint is of limited use. */ | |
1353 | ALL_BREAKPOINTS (bpt) | |
1354 | { | |
1355 | int some_failed = 0; | |
1356 | struct bp_location *loc; | |
1357 | ||
1358 | if (!is_hardware_watchpoint (bpt)) | |
1359 | continue; | |
1360 | ||
d6b74ac4 | 1361 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1362 | continue; |
74960c60 VP |
1363 | |
1364 | if (bpt->disposition == disp_del_at_next_stop) | |
1365 | continue; | |
a5606eee VP |
1366 | |
1367 | for (loc = bpt->loc; loc; loc = loc->next) | |
1368 | if (!loc->inserted) | |
1369 | { | |
1370 | some_failed = 1; | |
1371 | break; | |
1372 | } | |
1373 | if (some_failed) | |
1374 | { | |
1375 | for (loc = bpt->loc; loc; loc = loc->next) | |
1376 | if (loc->inserted) | |
1377 | remove_breakpoint (loc, mark_uninserted); | |
1378 | ||
1379 | hw_breakpoint_error = 1; | |
1380 | fprintf_unfiltered (tmp_error_stream, | |
1381 | "Could not insert hardware watchpoint %d.\n", | |
1382 | bpt->number); | |
1383 | error = -1; | |
1384 | } | |
1385 | } | |
1386 | ||
e236ba44 | 1387 | if (error) |
81d0cc19 GS |
1388 | { |
1389 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1390 | message about possibly exhausted resources. */ | |
879bfdc2 | 1391 | if (hw_breakpoint_error) |
81d0cc19 | 1392 | { |
c6510018 MS |
1393 | fprintf_unfiltered (tmp_error_stream, |
1394 | "Could not insert hardware breakpoints:\n\ | |
1395 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1396 | } |
81d0cc19 GS |
1397 | target_terminal_ours_for_output (); |
1398 | error_stream (tmp_error_stream); | |
1399 | } | |
f7545552 TT |
1400 | |
1401 | do_cleanups (cleanups); | |
c906108c SS |
1402 | } |
1403 | ||
c906108c | 1404 | int |
fba45db2 | 1405 | remove_breakpoints (void) |
c906108c | 1406 | { |
0bde7532 | 1407 | struct bp_location *b; |
c906108c SS |
1408 | int val; |
1409 | ||
0bde7532 | 1410 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1411 | { |
0bde7532 | 1412 | if (b->inserted) |
c5aa993b JM |
1413 | { |
1414 | val = remove_breakpoint (b, mark_uninserted); | |
1415 | if (val != 0) | |
1416 | return val; | |
1417 | } | |
1418 | } | |
c906108c SS |
1419 | return 0; |
1420 | } | |
1421 | ||
692590c1 | 1422 | int |
80ce1ecb | 1423 | remove_hw_watchpoints (void) |
692590c1 | 1424 | { |
0bde7532 | 1425 | struct bp_location *b; |
692590c1 MS |
1426 | int val; |
1427 | ||
0bde7532 | 1428 | ALL_BP_LOCATIONS (b) |
692590c1 | 1429 | { |
0bde7532 | 1430 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
692590c1 MS |
1431 | { |
1432 | val = remove_breakpoint (b, mark_uninserted); | |
1433 | if (val != 0) | |
1434 | return val; | |
1435 | } | |
1436 | } | |
1437 | return 0; | |
1438 | } | |
1439 | ||
c906108c | 1440 | int |
fba45db2 | 1441 | reattach_breakpoints (int pid) |
c906108c | 1442 | { |
0bde7532 | 1443 | struct bp_location *b; |
c906108c | 1444 | int val; |
ce696e05 | 1445 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 | 1446 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1447 | int dummy1 = 0, dummy2 = 0; |
a4954f26 DJ |
1448 | |
1449 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1450 | |
ce696e05 | 1451 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1452 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1453 | { |
0bde7532 | 1454 | if (b->inserted) |
c5aa993b | 1455 | { |
a4954f26 DJ |
1456 | b->inserted = 0; |
1457 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1458 | &dummy1, &dummy2); |
c5aa993b JM |
1459 | if (val != 0) |
1460 | { | |
ce696e05 | 1461 | do_cleanups (old_chain); |
c5aa993b JM |
1462 | return val; |
1463 | } | |
1464 | } | |
1465 | } | |
ce696e05 | 1466 | do_cleanups (old_chain); |
c906108c SS |
1467 | return 0; |
1468 | } | |
1469 | ||
e58b0e63 PA |
1470 | static int internal_breakpoint_number = -1; |
1471 | ||
e62c965a | 1472 | static struct breakpoint * |
a6d9a66e UW |
1473 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1474 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1475 | { |
e62c965a PP |
1476 | struct symtab_and_line sal; |
1477 | struct breakpoint *b; | |
1478 | ||
1479 | init_sal (&sal); /* initialize to zeroes */ | |
1480 | ||
1481 | sal.pc = address; | |
1482 | sal.section = find_pc_overlay (sal.pc); | |
1483 | ||
a6d9a66e | 1484 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1485 | b->number = internal_breakpoint_number--; |
1486 | b->disposition = disp_donttouch; | |
1487 | ||
1488 | return b; | |
1489 | } | |
1490 | ||
1491 | static void | |
69de3c6a | 1492 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1493 | { |
69de3c6a | 1494 | struct objfile *objfile; |
e62c965a | 1495 | |
69de3c6a PP |
1496 | ALL_OBJFILES (objfile) |
1497 | { | |
1498 | struct breakpoint *b; | |
1499 | struct minimal_symbol *m; | |
1500 | ||
1501 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1502 | if (m == NULL) | |
1503 | continue; | |
e62c965a | 1504 | |
a6d9a66e UW |
1505 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1506 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1507 | bp_overlay_event); |
1508 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1509 | |
69de3c6a PP |
1510 | if (overlay_debugging == ovly_auto) |
1511 | { | |
1512 | b->enable_state = bp_enabled; | |
1513 | overlay_events_enabled = 1; | |
1514 | } | |
1515 | else | |
1516 | { | |
1517 | b->enable_state = bp_disabled; | |
1518 | overlay_events_enabled = 0; | |
1519 | } | |
e62c965a PP |
1520 | } |
1521 | update_global_location_list (1); | |
1522 | } | |
1523 | ||
0fd8e87f UW |
1524 | static void |
1525 | create_longjmp_master_breakpoint (char *func_name) | |
1526 | { | |
1527 | struct objfile *objfile; | |
1528 | ||
1529 | ALL_OBJFILES (objfile) | |
1530 | { | |
1531 | struct breakpoint *b; | |
1532 | struct minimal_symbol *m; | |
1533 | ||
1534 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1535 | continue; | |
1536 | ||
1537 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1538 | if (m == NULL) | |
1539 | continue; | |
1540 | ||
a6d9a66e UW |
1541 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1542 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1543 | bp_longjmp_master); |
1544 | b->addr_string = xstrdup (func_name); | |
1545 | b->enable_state = bp_disabled; | |
1546 | } | |
1547 | update_global_location_list (1); | |
1548 | } | |
1549 | ||
c906108c | 1550 | void |
fba45db2 | 1551 | update_breakpoints_after_exec (void) |
c906108c | 1552 | { |
c5aa993b JM |
1553 | struct breakpoint *b; |
1554 | struct breakpoint *temp; | |
25b22b0a | 1555 | struct bp_location *bploc; |
c906108c | 1556 | |
25b22b0a PA |
1557 | /* We're about to delete breakpoints from GDB's lists. If the |
1558 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1559 | writing the breakpoints' "shadow contents" back into memory. The | |
1560 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1561 | do that. Instead, the target is responsible from marking | |
1562 | breakpoints out as soon as it detects an exec. We don't do that | |
1563 | here instead, because there may be other attempts to delete | |
1564 | breakpoints after detecting an exec and before reaching here. */ | |
1565 | ALL_BP_LOCATIONS (bploc) | |
1566 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1567 | |
1568 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1569 | { |
1570 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1571 | if (b->type == bp_shlib_event) | |
1572 | { | |
1573 | delete_breakpoint (b); | |
1574 | continue; | |
1575 | } | |
c906108c | 1576 | |
1900040c | 1577 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1578 | as must overlay event and longjmp master breakpoints. */ |
1579 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1580 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1581 | { |
1582 | delete_breakpoint (b); | |
1583 | continue; | |
1584 | } | |
1585 | ||
c5aa993b JM |
1586 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1587 | if (b->type == bp_step_resume) | |
1588 | { | |
1589 | delete_breakpoint (b); | |
1590 | continue; | |
1591 | } | |
1592 | ||
611c83ae PA |
1593 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1594 | after an exec. */ | |
1595 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1596 | { | |
1597 | delete_breakpoint (b); | |
1598 | continue; | |
1599 | } | |
1600 | ||
ce78b96d JB |
1601 | if (b->type == bp_catchpoint) |
1602 | { | |
1603 | /* For now, none of the bp_catchpoint breakpoints need to | |
1604 | do anything at this point. In the future, if some of | |
1605 | the catchpoints need to something, we will need to add | |
1606 | a new method, and call this method from here. */ | |
1607 | continue; | |
1608 | } | |
1609 | ||
c5aa993b JM |
1610 | /* bp_finish is a special case. The only way we ought to be able |
1611 | to see one of these when an exec() has happened, is if the user | |
1612 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1613 | carries them to the call-site of the current callee, by setting | |
1614 | a temporary bp there and resuming. But in this case, the finish | |
1615 | will carry them entirely through the vfork & exec. | |
1616 | ||
1617 | We don't want to allow a bp_finish to remain inserted now. But | |
1618 | we can't safely delete it, 'cause finish_command has a handle to | |
1619 | the bp on a bpstat, and will later want to delete it. There's a | |
1620 | chance (and I've seen it happen) that if we delete the bp_finish | |
1621 | here, that its storage will get reused by the time finish_command | |
1622 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1623 | We really must allow finish_command to delete a bp_finish. | |
1624 | ||
53a5351d JM |
1625 | In the absense of a general solution for the "how do we know |
1626 | it's safe to delete something others may have handles to?" | |
1627 | problem, what we'll do here is just uninsert the bp_finish, and | |
1628 | let finish_command delete it. | |
1629 | ||
1630 | (We know the bp_finish is "doomed" in the sense that it's | |
1631 | momentary, and will be deleted as soon as finish_command sees | |
1632 | the inferior stopped. So it doesn't matter that the bp's | |
1633 | address is probably bogus in the new a.out, unlike e.g., the | |
1634 | solib breakpoints.) */ | |
c5aa993b | 1635 | |
c5aa993b JM |
1636 | if (b->type == bp_finish) |
1637 | { | |
1638 | continue; | |
1639 | } | |
1640 | ||
1641 | /* Without a symbolic address, we have little hope of the | |
1642 | pre-exec() address meaning the same thing in the post-exec() | |
1643 | a.out. */ | |
1644 | if (b->addr_string == NULL) | |
1645 | { | |
1646 | delete_breakpoint (b); | |
1647 | continue; | |
1648 | } | |
c5aa993b | 1649 | } |
1900040c | 1650 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1651 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1652 | create_longjmp_master_breakpoint ("longjmp"); |
1653 | create_longjmp_master_breakpoint ("_longjmp"); | |
1654 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1655 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1656 | } |
1657 | ||
1658 | int | |
fba45db2 | 1659 | detach_breakpoints (int pid) |
c906108c | 1660 | { |
0bde7532 | 1661 | struct bp_location *b; |
c906108c | 1662 | int val; |
ce696e05 | 1663 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1664 | |
39f77062 | 1665 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1666 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1667 | |
ce696e05 KB |
1668 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1669 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1670 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1671 | { |
0bde7532 | 1672 | if (b->inserted) |
c5aa993b JM |
1673 | { |
1674 | val = remove_breakpoint (b, mark_inserted); | |
1675 | if (val != 0) | |
1676 | { | |
ce696e05 | 1677 | do_cleanups (old_chain); |
c5aa993b JM |
1678 | return val; |
1679 | } | |
1680 | } | |
1681 | } | |
ce696e05 | 1682 | do_cleanups (old_chain); |
c906108c SS |
1683 | return 0; |
1684 | } | |
1685 | ||
1686 | static int | |
0bde7532 | 1687 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1688 | { |
1689 | int val; | |
c5aa993b | 1690 | |
0bde7532 | 1691 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1692 | /* Permanent breakpoints cannot be inserted or removed. */ |
1693 | return 0; | |
1694 | ||
74960c60 VP |
1695 | /* The type of none suggests that owner is actually deleted. |
1696 | This should not ever happen. */ | |
1697 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1698 | |
1699 | if (b->loc_type == bp_loc_software_breakpoint | |
1700 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1701 | { |
c02f5703 MS |
1702 | /* "Normal" instruction breakpoint: either the standard |
1703 | trap-instruction bp (bp_breakpoint), or a | |
1704 | bp_hardware_breakpoint. */ | |
1705 | ||
1706 | /* First check to see if we have to handle an overlay. */ | |
1707 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1708 | || b->section == NULL |
1709 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1710 | { |
1711 | /* No overlay handling: just remove the breakpoint. */ | |
1712 | ||
0bde7532 | 1713 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1714 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1715 | else |
a6d9a66e | 1716 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1717 | } |
c906108c SS |
1718 | else |
1719 | { | |
c02f5703 MS |
1720 | /* This breakpoint is in an overlay section. |
1721 | Did we set a breakpoint at the LMA? */ | |
1722 | if (!overlay_events_enabled) | |
1723 | { | |
1724 | /* Yes -- overlay event support is not active, so we | |
1725 | should have set a breakpoint at the LMA. Remove it. | |
1726 | */ | |
c02f5703 MS |
1727 | /* Ignore any failures: if the LMA is in ROM, we will |
1728 | have already warned when we failed to insert it. */ | |
0bde7532 | 1729 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1730 | target_remove_hw_breakpoint (b->gdbarch, |
1731 | &b->overlay_target_info); | |
c02f5703 | 1732 | else |
a6d9a66e UW |
1733 | target_remove_breakpoint (b->gdbarch, |
1734 | &b->overlay_target_info); | |
c02f5703 MS |
1735 | } |
1736 | /* Did we set a breakpoint at the VMA? | |
1737 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1738 | if (b->inserted) |
c906108c | 1739 | { |
c02f5703 MS |
1740 | /* Yes -- remove it. Previously we did not bother to |
1741 | remove the breakpoint if the section had been | |
1742 | unmapped, but let's not rely on that being safe. We | |
1743 | don't know what the overlay manager might do. */ | |
0bde7532 | 1744 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1745 | val = target_remove_hw_breakpoint (b->gdbarch, |
1746 | &b->target_info); | |
aa67235e UW |
1747 | |
1748 | /* However, we should remove *software* breakpoints only | |
1749 | if the section is still mapped, or else we overwrite | |
1750 | wrong code with the saved shadow contents. */ | |
1751 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1752 | val = target_remove_breakpoint (b->gdbarch, |
1753 | &b->target_info); | |
aa67235e UW |
1754 | else |
1755 | val = 0; | |
c906108c | 1756 | } |
c02f5703 MS |
1757 | else |
1758 | { | |
1759 | /* No -- not inserted, so no need to remove. No error. */ | |
1760 | val = 0; | |
1761 | } | |
c906108c | 1762 | } |
879d1e6b UW |
1763 | |
1764 | /* In some cases, we might not be able to remove a breakpoint | |
1765 | in a shared library that has already been removed, but we | |
1766 | have not yet processed the shlib unload event. */ | |
f5c9a895 | 1767 | if (val && solib_name_from_address (b->address)) |
879d1e6b UW |
1768 | val = 0; |
1769 | ||
c906108c SS |
1770 | if (val) |
1771 | return val; | |
0bde7532 | 1772 | b->inserted = (is == mark_inserted); |
c906108c | 1773 | } |
a5606eee | 1774 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1775 | { |
278cd55f AC |
1776 | struct value *v; |
1777 | struct value *n; | |
c5aa993b | 1778 | |
0bde7532 | 1779 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1780 | val = target_remove_watchpoint (b->address, b->length, |
1781 | b->watchpoint_type); | |
2e70b7b9 | 1782 | |
c906108c | 1783 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1784 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1785 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1786 | b->owner->number); |
c906108c | 1787 | } |
ce78b96d JB |
1788 | else if (b->owner->type == bp_catchpoint |
1789 | && breakpoint_enabled (b->owner) | |
1790 | && !b->duplicate) | |
1791 | { | |
1792 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1793 | ||
1794 | val = b->owner->ops->remove (b->owner); | |
1795 | if (val) | |
1796 | return val; | |
1797 | b->inserted = (is == mark_inserted); | |
1798 | } | |
c906108c SS |
1799 | |
1800 | return 0; | |
1801 | } | |
1802 | ||
1803 | /* Clear the "inserted" flag in all breakpoints. */ | |
1804 | ||
25b22b0a | 1805 | void |
fba45db2 | 1806 | mark_breakpoints_out (void) |
c906108c | 1807 | { |
075f6582 | 1808 | struct bp_location *bpt; |
c906108c | 1809 | |
075f6582 DJ |
1810 | ALL_BP_LOCATIONS (bpt) |
1811 | bpt->inserted = 0; | |
c906108c SS |
1812 | } |
1813 | ||
53a5351d JM |
1814 | /* Clear the "inserted" flag in all breakpoints and delete any |
1815 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1816 | |
1817 | Plus other such housekeeping that has to be done for breakpoints | |
1818 | between runs. | |
1819 | ||
53a5351d JM |
1820 | Note: this function gets called at the end of a run (by |
1821 | generic_mourn_inferior) and when a run begins (by | |
1822 | init_wait_for_inferior). */ | |
c906108c SS |
1823 | |
1824 | ||
1825 | ||
1826 | void | |
fba45db2 | 1827 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1828 | { |
52f0bd74 | 1829 | struct breakpoint *b, *temp; |
075f6582 | 1830 | struct bp_location *bpt; |
1c5cfe86 | 1831 | int ix; |
c906108c | 1832 | |
50c71eaf PA |
1833 | /* If breakpoint locations are shared across processes, then there's |
1834 | nothing to do. */ | |
2567c7d9 | 1835 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
1836 | return; |
1837 | ||
075f6582 | 1838 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1839 | if (bpt->owner->enable_state != bp_permanent) |
1840 | bpt->inserted = 0; | |
075f6582 | 1841 | |
c906108c | 1842 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1843 | { |
c5aa993b JM |
1844 | switch (b->type) |
1845 | { | |
1846 | case bp_call_dummy: | |
1847 | case bp_watchpoint_scope: | |
c906108c | 1848 | |
c5aa993b JM |
1849 | /* If the call dummy breakpoint is at the entry point it will |
1850 | cause problems when the inferior is rerun, so we better | |
1851 | get rid of it. | |
c906108c | 1852 | |
c5aa993b JM |
1853 | Also get rid of scope breakpoints. */ |
1854 | delete_breakpoint (b); | |
1855 | break; | |
c906108c | 1856 | |
c5aa993b JM |
1857 | case bp_watchpoint: |
1858 | case bp_hardware_watchpoint: | |
1859 | case bp_read_watchpoint: | |
1860 | case bp_access_watchpoint: | |
c906108c | 1861 | |
c5aa993b JM |
1862 | /* Likewise for watchpoints on local expressions. */ |
1863 | if (b->exp_valid_block != NULL) | |
1864 | delete_breakpoint (b); | |
967af18d | 1865 | else if (context == inf_starting) |
c860120c PM |
1866 | { |
1867 | /* Reset val field to force reread of starting value | |
1868 | in insert_breakpoints. */ | |
1869 | if (b->val) | |
1870 | value_free (b->val); | |
1871 | b->val = NULL; | |
fa4727a6 | 1872 | b->val_valid = 0; |
c860120c | 1873 | } |
c5aa993b JM |
1874 | break; |
1875 | default: | |
c5aa993b JM |
1876 | break; |
1877 | } | |
1878 | } | |
1c5cfe86 PA |
1879 | |
1880 | /* Get rid of the moribund locations. */ | |
1881 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1882 | free_bp_location (bpt); | |
1883 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1884 | } |
1885 | ||
c2c6d25f JM |
1886 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1887 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1888 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1889 | permanent breakpoint. | |
1890 | - When continuing from a location with an ordinary breakpoint, we | |
1891 | actually single step once before calling insert_breakpoints. | |
1892 | - When continuing from a localion with a permanent breakpoint, we | |
1893 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1894 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1895 | |
c2c6d25f | 1896 | enum breakpoint_here |
fba45db2 | 1897 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1898 | { |
89f9893c | 1899 | const struct bp_location *bpt; |
c2c6d25f | 1900 | int any_breakpoint_here = 0; |
c906108c | 1901 | |
075f6582 DJ |
1902 | ALL_BP_LOCATIONS (bpt) |
1903 | { | |
1904 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1905 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1906 | continue; | |
1907 | ||
468d015d | 1908 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1909 | || bpt->owner->enable_state == bp_permanent) |
1910 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1911 | { | |
1912 | if (overlay_debugging | |
1913 | && section_is_overlay (bpt->section) | |
1914 | && !section_is_mapped (bpt->section)) | |
1915 | continue; /* unmapped overlay -- can't be a match */ | |
1916 | else if (bpt->owner->enable_state == bp_permanent) | |
1917 | return permanent_breakpoint_here; | |
1918 | else | |
1919 | any_breakpoint_here = 1; | |
1920 | } | |
1921 | } | |
c906108c | 1922 | |
c2c6d25f | 1923 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1924 | } |
1925 | ||
1c5cfe86 PA |
1926 | /* Return true if there's a moribund breakpoint at PC. */ |
1927 | ||
1928 | int | |
1929 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1930 | { | |
1931 | struct bp_location *loc; | |
1932 | int ix; | |
1933 | ||
1934 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1935 | if (loc->address == pc) | |
1936 | return 1; | |
1937 | ||
1938 | return 0; | |
1939 | } | |
c2c6d25f | 1940 | |
c36b740a VP |
1941 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1942 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1943 | This does not check for single-step breakpoints, which are | |
1944 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1945 | |
1946 | int | |
c36b740a | 1947 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1948 | { |
89f9893c | 1949 | const struct bp_location *bpt; |
c906108c | 1950 | |
075f6582 | 1951 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1952 | { |
075f6582 DJ |
1953 | if (bpt->loc_type != bp_loc_software_breakpoint |
1954 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1955 | continue; | |
1956 | ||
1957 | if (bpt->inserted | |
1958 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1959 | { | |
1960 | if (overlay_debugging | |
1961 | && section_is_overlay (bpt->section) | |
1962 | && !section_is_mapped (bpt->section)) | |
1963 | continue; /* unmapped overlay -- can't be a match */ | |
1964 | else | |
1965 | return 1; | |
1966 | } | |
c5aa993b | 1967 | } |
c36b740a VP |
1968 | return 0; |
1969 | } | |
1970 | ||
1971 | /* Returns non-zero iff there's either regular breakpoint | |
1972 | or a single step breakpoint inserted at PC. */ | |
1973 | ||
1974 | int | |
1975 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1976 | { | |
1977 | if (regular_breakpoint_inserted_here_p (pc)) | |
1978 | return 1; | |
c906108c | 1979 | |
1aafd4da UW |
1980 | if (single_step_breakpoint_inserted_here_p (pc)) |
1981 | return 1; | |
1982 | ||
c906108c SS |
1983 | return 0; |
1984 | } | |
1985 | ||
4fa8626c DJ |
1986 | /* This function returns non-zero iff there is a software breakpoint |
1987 | inserted at PC. */ | |
1988 | ||
1989 | int | |
1990 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
1991 | { | |
89f9893c | 1992 | const struct bp_location *bpt; |
4fa8626c DJ |
1993 | int any_breakpoint_here = 0; |
1994 | ||
1995 | ALL_BP_LOCATIONS (bpt) | |
1996 | { | |
1997 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
1998 | continue; | |
1999 | ||
0d381245 | 2000 | if (bpt->inserted |
4fa8626c DJ |
2001 | && bpt->address == pc) /* bp is enabled and matches pc */ |
2002 | { | |
2003 | if (overlay_debugging | |
2004 | && section_is_overlay (bpt->section) | |
2005 | && !section_is_mapped (bpt->section)) | |
2006 | continue; /* unmapped overlay -- can't be a match */ | |
2007 | else | |
2008 | return 1; | |
2009 | } | |
2010 | } | |
2011 | ||
1aafd4da UW |
2012 | /* Also check for software single-step breakpoints. */ |
2013 | if (single_step_breakpoint_inserted_here_p (pc)) | |
2014 | return 1; | |
2015 | ||
4fa8626c DJ |
2016 | return 0; |
2017 | } | |
2018 | ||
075f6582 DJ |
2019 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2020 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2021 | |
2022 | int | |
39f77062 | 2023 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 2024 | { |
89f9893c | 2025 | const struct bp_location *bpt; |
4a306c9a | 2026 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2027 | int thread = -1; |
4a306c9a | 2028 | int task = 0; |
a6f1cd96 | 2029 | |
075f6582 | 2030 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2031 | { |
075f6582 DJ |
2032 | if (bpt->loc_type != bp_loc_software_breakpoint |
2033 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2034 | continue; | |
2035 | ||
a6f1cd96 JB |
2036 | if (!breakpoint_enabled (bpt->owner) |
2037 | && bpt->owner->enable_state != bp_permanent) | |
2038 | continue; | |
2039 | ||
2040 | if (bpt->address != pc) | |
2041 | continue; | |
2042 | ||
2043 | if (bpt->owner->thread != -1) | |
075f6582 | 2044 | { |
a6f1cd96 JB |
2045 | /* This is a thread-specific breakpoint. Check that ptid |
2046 | matches that thread. If thread hasn't been computed yet, | |
2047 | it is now time to do so. */ | |
2048 | if (thread == -1) | |
2049 | thread = pid_to_thread_id (ptid); | |
2050 | if (bpt->owner->thread != thread) | |
2051 | continue; | |
075f6582 | 2052 | } |
a6f1cd96 | 2053 | |
4a306c9a JB |
2054 | if (bpt->owner->task != 0) |
2055 | { | |
2056 | /* This is a task-specific breakpoint. Check that ptid | |
2057 | matches that task. If task hasn't been computed yet, | |
2058 | it is now time to do so. */ | |
2059 | if (task == 0) | |
2060 | task = ada_get_task_number (ptid); | |
2061 | if (bpt->owner->task != task) | |
2062 | continue; | |
2063 | } | |
2064 | ||
a6f1cd96 JB |
2065 | if (overlay_debugging |
2066 | && section_is_overlay (bpt->section) | |
2067 | && !section_is_mapped (bpt->section)) | |
2068 | continue; /* unmapped overlay -- can't be a match */ | |
2069 | ||
2070 | return 1; | |
c5aa993b | 2071 | } |
c906108c SS |
2072 | |
2073 | return 0; | |
2074 | } | |
c906108c | 2075 | \f |
c5aa993b | 2076 | |
c906108c SS |
2077 | /* bpstat stuff. External routines' interfaces are documented |
2078 | in breakpoint.h. */ | |
2079 | ||
2080 | int | |
fba45db2 | 2081 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2082 | { |
533be4dd | 2083 | return (ep->type == bp_catchpoint); |
c906108c SS |
2084 | } |
2085 | ||
198757a8 VP |
2086 | void |
2087 | bpstat_free (bpstat bs) | |
2088 | { | |
2089 | if (bs->old_val != NULL) | |
2090 | value_free (bs->old_val); | |
2091 | free_command_lines (&bs->commands); | |
2092 | xfree (bs); | |
2093 | } | |
2094 | ||
c906108c SS |
2095 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2096 | Also free any storage that is part of a bpstat. */ | |
2097 | ||
2098 | void | |
fba45db2 | 2099 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2100 | { |
2101 | bpstat p; | |
2102 | bpstat q; | |
2103 | ||
2104 | if (bsp == 0) | |
2105 | return; | |
2106 | p = *bsp; | |
2107 | while (p != NULL) | |
2108 | { | |
2109 | q = p->next; | |
198757a8 | 2110 | bpstat_free (p); |
c906108c SS |
2111 | p = q; |
2112 | } | |
2113 | *bsp = NULL; | |
2114 | } | |
2115 | ||
2116 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2117 | is part of the bpstat is copied as well. */ | |
2118 | ||
2119 | bpstat | |
fba45db2 | 2120 | bpstat_copy (bpstat bs) |
c906108c SS |
2121 | { |
2122 | bpstat p = NULL; | |
2123 | bpstat tmp; | |
2124 | bpstat retval = NULL; | |
2125 | ||
2126 | if (bs == NULL) | |
2127 | return bs; | |
2128 | ||
2129 | for (; bs != NULL; bs = bs->next) | |
2130 | { | |
2131 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2132 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2133 | if (bs->commands != NULL) |
2134 | tmp->commands = copy_command_lines (bs->commands); | |
2135 | if (bs->old_val != NULL) | |
3c3185ac JK |
2136 | { |
2137 | tmp->old_val = value_copy (bs->old_val); | |
2138 | release_value (tmp->old_val); | |
2139 | } | |
31cc81e9 | 2140 | |
c906108c SS |
2141 | if (p == NULL) |
2142 | /* This is the first thing in the chain. */ | |
2143 | retval = tmp; | |
2144 | else | |
2145 | p->next = tmp; | |
2146 | p = tmp; | |
2147 | } | |
2148 | p->next = NULL; | |
2149 | return retval; | |
2150 | } | |
2151 | ||
2152 | /* Find the bpstat associated with this breakpoint */ | |
2153 | ||
2154 | bpstat | |
fba45db2 | 2155 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2156 | { |
c5aa993b JM |
2157 | if (bsp == NULL) |
2158 | return NULL; | |
c906108c | 2159 | |
c5aa993b JM |
2160 | for (; bsp != NULL; bsp = bsp->next) |
2161 | { | |
4f8d1dc6 | 2162 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2163 | return bsp; |
2164 | } | |
c906108c SS |
2165 | return NULL; |
2166 | } | |
2167 | ||
2168 | /* Find a step_resume breakpoint associated with this bpstat. | |
2169 | (If there are multiple step_resume bp's on the list, this function | |
2170 | will arbitrarily pick one.) | |
2171 | ||
2172 | It is an error to use this function if BPSTAT doesn't contain a | |
2173 | step_resume breakpoint. | |
2174 | ||
2175 | See wait_for_inferior's use of this function. */ | |
2176 | struct breakpoint * | |
fba45db2 | 2177 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2178 | { |
8601f500 MS |
2179 | int current_thread; |
2180 | ||
8a3fe4f8 | 2181 | gdb_assert (bsp != NULL); |
c906108c | 2182 | |
8601f500 MS |
2183 | current_thread = pid_to_thread_id (inferior_ptid); |
2184 | ||
c906108c SS |
2185 | for (; bsp != NULL; bsp = bsp->next) |
2186 | { | |
059fb39f PM |
2187 | if ((bsp->breakpoint_at != NULL) |
2188 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2189 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2190 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2191 | return bsp->breakpoint_at->owner; |
c906108c SS |
2192 | } |
2193 | ||
8a3fe4f8 | 2194 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2195 | } |
2196 | ||
2197 | ||
8671a17b | 2198 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2199 | at. *BSP upon return is a bpstat which points to the remaining |
2200 | breakpoints stopped at (but which is not guaranteed to be good for | |
2201 | anything but further calls to bpstat_num). | |
8671a17b PA |
2202 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2203 | Return -1 if stopped at a breakpoint that has been deleted since | |
2204 | we set it. | |
2205 | Return 1 otherwise. */ | |
c906108c SS |
2206 | |
2207 | int | |
8671a17b | 2208 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2209 | { |
2210 | struct breakpoint *b; | |
2211 | ||
2212 | if ((*bsp) == NULL) | |
2213 | return 0; /* No more breakpoint values */ | |
8671a17b | 2214 | |
4f8d1dc6 VP |
2215 | /* We assume we'll never have several bpstats that |
2216 | correspond to a single breakpoint -- otherwise, | |
2217 | this function might return the same number more | |
2218 | than once and this will look ugly. */ | |
2219 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2220 | *bsp = (*bsp)->next; |
2221 | if (b == NULL) | |
2222 | return -1; /* breakpoint that's been deleted since */ | |
2223 | ||
2224 | *num = b->number; /* We have its number */ | |
2225 | return 1; | |
c906108c SS |
2226 | } |
2227 | ||
2228 | /* Modify BS so that the actions will not be performed. */ | |
2229 | ||
2230 | void | |
fba45db2 | 2231 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2232 | { |
2233 | for (; bs != NULL; bs = bs->next) | |
2234 | { | |
c2b8ed2c | 2235 | free_command_lines (&bs->commands); |
c906108c SS |
2236 | if (bs->old_val != NULL) |
2237 | { | |
2238 | value_free (bs->old_val); | |
2239 | bs->old_val = NULL; | |
2240 | } | |
2241 | } | |
2242 | } | |
2243 | ||
f3b1572e PA |
2244 | /* Called when a command is about to proceed the inferior. */ |
2245 | ||
2246 | static void | |
2247 | breakpoint_about_to_proceed (void) | |
2248 | { | |
2249 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2250 | { | |
2251 | struct thread_info *tp = inferior_thread (); | |
2252 | ||
2253 | /* Allow inferior function calls in breakpoint commands to not | |
2254 | interrupt the command list. When the call finishes | |
2255 | successfully, the inferior will be standing at the same | |
2256 | breakpoint as if nothing happened. */ | |
2257 | if (tp->in_infcall) | |
2258 | return; | |
2259 | } | |
2260 | ||
2261 | breakpoint_proceeded = 1; | |
2262 | } | |
2263 | ||
c906108c | 2264 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2265 | static void |
4efb68b1 | 2266 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2267 | { |
2268 | executing_breakpoint_commands = 0; | |
2269 | } | |
2270 | ||
2271 | /* Execute all the commands associated with all the breakpoints at this | |
2272 | location. Any of these commands could cause the process to proceed | |
2273 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2274 | the global "breakpoint_proceeded" after each command. |
c906108c | 2275 | |
347bddb7 PA |
2276 | Returns true if a breakpoint command resumed the inferior. In that |
2277 | case, it is the caller's responsibility to recall it again with the | |
2278 | bpstat of the current thread. */ | |
2279 | ||
2280 | static int | |
2281 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2282 | { |
2283 | bpstat bs; | |
2284 | struct cleanup *old_chain; | |
347bddb7 | 2285 | int again = 0; |
c906108c SS |
2286 | |
2287 | /* Avoid endless recursion if a `source' command is contained | |
2288 | in bs->commands. */ | |
2289 | if (executing_breakpoint_commands) | |
347bddb7 | 2290 | return 0; |
c906108c SS |
2291 | |
2292 | executing_breakpoint_commands = 1; | |
2293 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2294 | ||
c906108c SS |
2295 | /* This pointer will iterate over the list of bpstat's. */ |
2296 | bs = *bsp; | |
2297 | ||
2298 | breakpoint_proceeded = 0; | |
2299 | for (; bs != NULL; bs = bs->next) | |
2300 | { | |
6c50ab1c JB |
2301 | struct command_line *cmd; |
2302 | struct cleanup *this_cmd_tree_chain; | |
2303 | ||
2304 | /* Take ownership of the BSP's command tree, if it has one. | |
2305 | ||
2306 | The command tree could legitimately contain commands like | |
2307 | 'step' and 'next', which call clear_proceed_status, which | |
2308 | frees stop_bpstat's command tree. To make sure this doesn't | |
2309 | free the tree we're executing out from under us, we need to | |
2310 | take ownership of the tree ourselves. Since a given bpstat's | |
2311 | commands are only executed once, we don't need to copy it; we | |
2312 | can clear the pointer in the bpstat, and make sure we free | |
2313 | the tree when we're done. */ | |
c906108c | 2314 | cmd = bs->commands; |
6c50ab1c JB |
2315 | bs->commands = 0; |
2316 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2317 | ||
c906108c SS |
2318 | while (cmd != NULL) |
2319 | { | |
2320 | execute_control_command (cmd); | |
2321 | ||
2322 | if (breakpoint_proceeded) | |
2323 | break; | |
2324 | else | |
2325 | cmd = cmd->next; | |
2326 | } | |
6c50ab1c JB |
2327 | |
2328 | /* We can free this command tree now. */ | |
2329 | do_cleanups (this_cmd_tree_chain); | |
2330 | ||
c906108c | 2331 | if (breakpoint_proceeded) |
32c1e744 VP |
2332 | { |
2333 | if (target_can_async_p ()) | |
347bddb7 PA |
2334 | /* If we are in async mode, then the target might be still |
2335 | running, not stopped at any breakpoint, so nothing for | |
2336 | us to do here -- just return to the event loop. */ | |
2337 | ; | |
32c1e744 VP |
2338 | else |
2339 | /* In sync mode, when execute_control_command returns | |
2340 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2341 | Breakpoint commands for that stop were not run, since |
2342 | execute_command does not run breakpoint commands -- | |
2343 | only command_line_handler does, but that one is not | |
2344 | involved in execution of breakpoint commands. So, we | |
2345 | can now execute breakpoint commands. It should be | |
2346 | noted that making execute_command do bpstat actions is | |
2347 | not an option -- in this case we'll have recursive | |
2348 | invocation of bpstat for each breakpoint with a | |
2349 | command, and can easily blow up GDB stack. Instead, we | |
2350 | return true, which will trigger the caller to recall us | |
2351 | with the new stop_bpstat. */ | |
2352 | again = 1; | |
2353 | break; | |
32c1e744 | 2354 | } |
c906108c | 2355 | } |
c2b8ed2c | 2356 | do_cleanups (old_chain); |
347bddb7 PA |
2357 | return again; |
2358 | } | |
2359 | ||
2360 | void | |
2361 | bpstat_do_actions (void) | |
2362 | { | |
2363 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2364 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2365 | && target_has_execution | |
2366 | && !is_exited (inferior_ptid) | |
2367 | && !is_executing (inferior_ptid)) | |
2368 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2369 | and only return when it is stopped at the next breakpoint, we | |
2370 | keep doing breakpoint actions until it returns false to | |
2371 | indicate the inferior was not resumed. */ | |
2372 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2373 | break; | |
c906108c SS |
2374 | } |
2375 | ||
fa4727a6 DJ |
2376 | /* Print out the (old or new) value associated with a watchpoint. */ |
2377 | ||
2378 | static void | |
2379 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2380 | { | |
2381 | if (val == NULL) | |
2382 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2383 | else | |
79a45b7d TT |
2384 | { |
2385 | struct value_print_options opts; | |
2386 | get_user_print_options (&opts); | |
2387 | value_print (val, stream, &opts); | |
2388 | } | |
fa4727a6 DJ |
2389 | } |
2390 | ||
e514a9d6 | 2391 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2392 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2393 | by having it set different print_it values. |
2394 | ||
2395 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2396 | through the bpstat list of things causing this stop, calling the | |
2397 | print_bp_stop_message function on each one. The behavior of the | |
2398 | print_bp_stop_message function depends on the print_it field of | |
2399 | bpstat. If such field so indicates, call this function here. | |
2400 | ||
2401 | Return values from this routine (ultimately used by bpstat_print() | |
2402 | and normal_stop() to decide what to do): | |
2403 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2404 | don't print anything else. | |
2405 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2406 | that something to be followed by a location. | |
2407 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2408 | that something to be followed by a location. | |
2409 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2410 | analysis. */ | |
c906108c | 2411 | |
917317f4 | 2412 | static enum print_stop_action |
fba45db2 | 2413 | print_it_typical (bpstat bs) |
c906108c | 2414 | { |
f7545552 | 2415 | struct cleanup *old_chain; |
4f8d1dc6 | 2416 | struct breakpoint *b; |
89f9893c | 2417 | const struct bp_location *bl; |
8b93c638 | 2418 | struct ui_stream *stb; |
f7545552 TT |
2419 | int bp_temp = 0; |
2420 | enum print_stop_action result; | |
2421 | ||
c906108c SS |
2422 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2423 | which has since been deleted. */ | |
e514a9d6 | 2424 | if (bs->breakpoint_at == NULL) |
917317f4 | 2425 | return PRINT_UNKNOWN; |
0d381245 VP |
2426 | bl = bs->breakpoint_at; |
2427 | b = bl->owner; | |
c906108c | 2428 | |
f7545552 TT |
2429 | stb = ui_out_stream_new (uiout); |
2430 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2431 | ||
4f8d1dc6 | 2432 | switch (b->type) |
c906108c | 2433 | { |
e514a9d6 JM |
2434 | case bp_breakpoint: |
2435 | case bp_hardware_breakpoint: | |
2cec12e5 | 2436 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2437 | if (bl->address != bl->requested_address) |
2438 | breakpoint_adjustment_warning (bl->requested_address, | |
2439 | bl->address, | |
4f8d1dc6 VP |
2440 | b->number, 1); |
2441 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2442 | if (bp_temp) |
2443 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2444 | else | |
2445 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2446 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2447 | { |
2448 | ui_out_field_string (uiout, "reason", | |
2449 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2450 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2451 | } | |
4f8d1dc6 | 2452 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2453 | ui_out_text (uiout, ", "); |
f7545552 | 2454 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2455 | break; |
2456 | ||
2457 | case bp_shlib_event: | |
917317f4 JM |
2458 | /* Did we stop because the user set the stop_on_solib_events |
2459 | variable? (If so, we report this as a generic, "Stopped due | |
2460 | to shlib event" message.) */ | |
a3f17187 | 2461 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2462 | result = PRINT_NOTHING; |
e514a9d6 JM |
2463 | break; |
2464 | ||
c4093a6a JM |
2465 | case bp_thread_event: |
2466 | /* Not sure how we will get here. | |
2467 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2468 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2469 | result = PRINT_NOTHING; |
c4093a6a JM |
2470 | break; |
2471 | ||
1900040c MS |
2472 | case bp_overlay_event: |
2473 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2474 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2475 | result = PRINT_NOTHING; |
1900040c MS |
2476 | break; |
2477 | ||
0fd8e87f UW |
2478 | case bp_longjmp_master: |
2479 | /* These should never be enabled. */ | |
2480 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2481 | result = PRINT_NOTHING; | |
2482 | break; | |
2483 | ||
e514a9d6 JM |
2484 | case bp_watchpoint: |
2485 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2486 | annotate_watchpoint (b->number); |
2487 | if (ui_out_is_mi_like_p (uiout)) | |
2488 | ui_out_field_string | |
2489 | (uiout, "reason", | |
2490 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2491 | mention (b); | |
f7545552 | 2492 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2493 | ui_out_text (uiout, "\nOld value = "); |
2494 | watchpoint_value_print (bs->old_val, stb->stream); | |
2495 | ui_out_field_stream (uiout, "old", stb); | |
2496 | ui_out_text (uiout, "\nNew value = "); | |
2497 | watchpoint_value_print (b->val, stb->stream); | |
2498 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2499 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2500 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2501 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2502 | break; |
2503 | ||
2504 | case bp_read_watchpoint: | |
9dc5e2a9 | 2505 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2506 | ui_out_field_string |
2507 | (uiout, "reason", | |
2508 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2509 | mention (b); |
f7545552 | 2510 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2511 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2512 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2513 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2514 | ui_out_text (uiout, "\n"); |
f7545552 | 2515 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2516 | break; |
2517 | ||
2518 | case bp_access_watchpoint: | |
fa4727a6 | 2519 | if (bs->old_val != NULL) |
8b93c638 | 2520 | { |
4f8d1dc6 | 2521 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2522 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2523 | ui_out_field_string |
2524 | (uiout, "reason", | |
2525 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2526 | mention (b); |
f7545552 | 2527 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2528 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2529 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2530 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2531 | ui_out_text (uiout, "\nNew value = "); |
2532 | } | |
2533 | else | |
2534 | { | |
4f8d1dc6 | 2535 | mention (b); |
9dc5e2a9 | 2536 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2537 | ui_out_field_string |
2538 | (uiout, "reason", | |
2539 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2540 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2541 | ui_out_text (uiout, "\nValue = "); |
2542 | } | |
fa4727a6 | 2543 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2544 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2545 | ui_out_text (uiout, "\n"); |
f7545552 | 2546 | result = PRINT_UNKNOWN; |
e514a9d6 | 2547 | break; |
4ce44c66 | 2548 | |
e514a9d6 JM |
2549 | /* Fall through, we don't deal with these types of breakpoints |
2550 | here. */ | |
2551 | ||
11cf8741 | 2552 | case bp_finish: |
9dc5e2a9 | 2553 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2554 | ui_out_field_string |
2555 | (uiout, "reason", | |
2556 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2557 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2558 | break; |
2559 | ||
e514a9d6 | 2560 | case bp_until: |
9dc5e2a9 | 2561 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2562 | ui_out_field_string |
2563 | (uiout, "reason", | |
2564 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2565 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2566 | break; |
2567 | ||
c2d11a7d | 2568 | case bp_none: |
e514a9d6 JM |
2569 | case bp_longjmp: |
2570 | case bp_longjmp_resume: | |
2571 | case bp_step_resume: | |
e514a9d6 JM |
2572 | case bp_watchpoint_scope: |
2573 | case bp_call_dummy: | |
1042e4c0 | 2574 | case bp_tracepoint: |
e514a9d6 | 2575 | default: |
f7545552 TT |
2576 | result = PRINT_UNKNOWN; |
2577 | break; | |
e514a9d6 | 2578 | } |
f7545552 TT |
2579 | |
2580 | do_cleanups (old_chain); | |
2581 | return result; | |
e514a9d6 JM |
2582 | } |
2583 | ||
2584 | /* Generic routine for printing messages indicating why we | |
2585 | stopped. The behavior of this function depends on the value | |
2586 | 'print_it' in the bpstat structure. Under some circumstances we | |
2587 | may decide not to print anything here and delegate the task to | |
2588 | normal_stop(). */ | |
2589 | ||
2590 | static enum print_stop_action | |
2591 | print_bp_stop_message (bpstat bs) | |
2592 | { | |
2593 | switch (bs->print_it) | |
2594 | { | |
2595 | case print_it_noop: | |
2596 | /* Nothing should be printed for this bpstat entry. */ | |
2597 | return PRINT_UNKNOWN; | |
2598 | break; | |
2599 | ||
2600 | case print_it_done: | |
2601 | /* We still want to print the frame, but we already printed the | |
2602 | relevant messages. */ | |
2603 | return PRINT_SRC_AND_LOC; | |
2604 | break; | |
2605 | ||
2606 | case print_it_normal: | |
4f8d1dc6 | 2607 | { |
89f9893c | 2608 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2609 | struct breakpoint *b = bl ? bl->owner : NULL; |
2610 | ||
2611 | /* Normal case. Call the breakpoint's print_it method, or | |
2612 | print_it_typical. */ | |
2613 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2614 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2615 | return b->ops->print_it (b); | |
2616 | else | |
2617 | return print_it_typical (bs); | |
2618 | } | |
2619 | break; | |
3086aeae | 2620 | |
e514a9d6 | 2621 | default: |
8e65ff28 | 2622 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2623 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2624 | break; |
c906108c | 2625 | } |
c906108c SS |
2626 | } |
2627 | ||
e514a9d6 JM |
2628 | /* Print a message indicating what happened. This is called from |
2629 | normal_stop(). The input to this routine is the head of the bpstat | |
2630 | list - a list of the eventpoints that caused this stop. This | |
2631 | routine calls the generic print routine for printing a message | |
2632 | about reasons for stopping. This will print (for example) the | |
2633 | "Breakpoint n," part of the output. The return value of this | |
2634 | routine is one of: | |
c906108c | 2635 | |
917317f4 JM |
2636 | PRINT_UNKNOWN: Means we printed nothing |
2637 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2638 | code to print the location. An example is |
2639 | "Breakpoint 1, " which should be followed by | |
2640 | the location. | |
917317f4 | 2641 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2642 | to also print the location part of the message. |
2643 | An example is the catch/throw messages, which | |
917317f4 JM |
2644 | don't require a location appended to the end. |
2645 | PRINT_NOTHING: We have done some printing and we don't need any | |
2646 | further info to be printed.*/ | |
c906108c | 2647 | |
917317f4 | 2648 | enum print_stop_action |
fba45db2 | 2649 | bpstat_print (bpstat bs) |
c906108c SS |
2650 | { |
2651 | int val; | |
c5aa993b | 2652 | |
c906108c | 2653 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2654 | (Currently all watchpoints go on the bpstat whether hit or not. |
2655 | That probably could (should) be changed, provided care is taken | |
c906108c | 2656 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2657 | for (; bs; bs = bs->next) |
2658 | { | |
2659 | val = print_bp_stop_message (bs); | |
2660 | if (val == PRINT_SRC_ONLY | |
2661 | || val == PRINT_SRC_AND_LOC | |
2662 | || val == PRINT_NOTHING) | |
2663 | return val; | |
2664 | } | |
c906108c | 2665 | |
e514a9d6 JM |
2666 | /* We reached the end of the chain, or we got a null BS to start |
2667 | with and nothing was printed. */ | |
917317f4 | 2668 | return PRINT_UNKNOWN; |
c906108c SS |
2669 | } |
2670 | ||
2671 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2672 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2673 | The argument is a "struct expression *" that has been cast to char * to | |
2674 | make it pass through catch_errors. */ | |
2675 | ||
2676 | static int | |
4efb68b1 | 2677 | breakpoint_cond_eval (void *exp) |
c906108c | 2678 | { |
278cd55f | 2679 | struct value *mark = value_mark (); |
c5aa993b | 2680 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2681 | value_free_to_mark (mark); |
2682 | return i; | |
2683 | } | |
2684 | ||
2685 | /* Allocate a new bpstat and chain it to the current one. */ | |
2686 | ||
2687 | static bpstat | |
89f9893c | 2688 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2689 | { |
2690 | bpstat bs; | |
2691 | ||
2692 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2693 | cbs->next = bs; | |
4f8d1dc6 | 2694 | bs->breakpoint_at = bl; |
c906108c SS |
2695 | /* If the condition is false, etc., don't do the commands. */ |
2696 | bs->commands = NULL; | |
2697 | bs->old_val = NULL; | |
2698 | bs->print_it = print_it_normal; | |
2699 | return bs; | |
2700 | } | |
2701 | \f | |
d983da9c DJ |
2702 | /* The target has stopped with waitstatus WS. Check if any hardware |
2703 | watchpoints have triggered, according to the target. */ | |
2704 | ||
2705 | int | |
2706 | watchpoints_triggered (struct target_waitstatus *ws) | |
2707 | { | |
d92524f1 | 2708 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2709 | CORE_ADDR addr; |
2710 | struct breakpoint *b; | |
2711 | ||
2712 | if (!stopped_by_watchpoint) | |
2713 | { | |
2714 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2715 | as not triggered. */ | |
2716 | ALL_BREAKPOINTS (b) | |
2717 | if (b->type == bp_hardware_watchpoint | |
2718 | || b->type == bp_read_watchpoint | |
2719 | || b->type == bp_access_watchpoint) | |
2720 | b->watchpoint_triggered = watch_triggered_no; | |
2721 | ||
2722 | return 0; | |
2723 | } | |
2724 | ||
2725 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2726 | { | |
2727 | /* We were stopped by a watchpoint, but we don't know where. | |
2728 | Mark all watchpoints as unknown. */ | |
2729 | ALL_BREAKPOINTS (b) | |
2730 | if (b->type == bp_hardware_watchpoint | |
2731 | || b->type == bp_read_watchpoint | |
2732 | || b->type == bp_access_watchpoint) | |
2733 | b->watchpoint_triggered = watch_triggered_unknown; | |
2734 | ||
2735 | return stopped_by_watchpoint; | |
2736 | } | |
2737 | ||
2738 | /* The target could report the data address. Mark watchpoints | |
2739 | affected by this data address as triggered, and all others as not | |
2740 | triggered. */ | |
2741 | ||
2742 | ALL_BREAKPOINTS (b) | |
2743 | if (b->type == bp_hardware_watchpoint | |
2744 | || b->type == bp_read_watchpoint | |
2745 | || b->type == bp_access_watchpoint) | |
2746 | { | |
a5606eee | 2747 | struct bp_location *loc; |
d983da9c DJ |
2748 | struct value *v; |
2749 | ||
2750 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2751 | for (loc = b->loc; loc; loc = loc->next) |
2752 | /* Exact match not required. Within range is | |
2753 | sufficient. */ | |
5009afc5 AS |
2754 | if (target_watchpoint_addr_within_range (¤t_target, |
2755 | addr, loc->address, | |
2756 | loc->length)) | |
a5606eee VP |
2757 | { |
2758 | b->watchpoint_triggered = watch_triggered_yes; | |
2759 | break; | |
2760 | } | |
d983da9c DJ |
2761 | } |
2762 | ||
2763 | return 1; | |
2764 | } | |
2765 | ||
c906108c SS |
2766 | /* Possible return values for watchpoint_check (this can't be an enum |
2767 | because of check_errors). */ | |
2768 | /* The watchpoint has been deleted. */ | |
2769 | #define WP_DELETED 1 | |
2770 | /* The value has changed. */ | |
2771 | #define WP_VALUE_CHANGED 2 | |
2772 | /* The value has not changed. */ | |
2773 | #define WP_VALUE_NOT_CHANGED 3 | |
2774 | ||
2775 | #define BP_TEMPFLAG 1 | |
2776 | #define BP_HARDWAREFLAG 2 | |
2777 | ||
2778 | /* Check watchpoint condition. */ | |
2779 | ||
2780 | static int | |
4efb68b1 | 2781 | watchpoint_check (void *p) |
c906108c SS |
2782 | { |
2783 | bpstat bs = (bpstat) p; | |
2784 | struct breakpoint *b; | |
2785 | struct frame_info *fr; | |
2786 | int within_current_scope; | |
2787 | ||
4f8d1dc6 | 2788 | b = bs->breakpoint_at->owner; |
c906108c SS |
2789 | |
2790 | if (b->exp_valid_block == NULL) | |
2791 | within_current_scope = 1; | |
2792 | else | |
2793 | { | |
edb3359d DJ |
2794 | struct frame_info *frame = get_current_frame (); |
2795 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
2796 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
2797 | ||
101dcfbe | 2798 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2799 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2800 | |
2801 | /* If we've gotten confused in the unwinder, we might have | |
2802 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
2803 | if (within_current_scope) |
2804 | { | |
2805 | struct symbol *function; | |
2806 | ||
2807 | function = get_frame_function (fr); | |
2808 | if (function == NULL | |
2809 | || !contained_in (b->exp_valid_block, | |
2810 | SYMBOL_BLOCK_VALUE (function))) | |
2811 | within_current_scope = 0; | |
2812 | } | |
69fbadd5 | 2813 | |
c12260ac CV |
2814 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2815 | in the function but the stack frame has already been invalidated. | |
2816 | Since we can't rely on the values of local variables after the | |
2817 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
2818 | state as `not changed' without further checking. Don't mark |
2819 | watchpoints as changed if the current frame is in an epilogue - | |
2820 | even if they are in some other frame, our view of the stack | |
2821 | is likely to be wrong. */ | |
2822 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
2823 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 2824 | |
edb3359d | 2825 | if (within_current_scope) |
c906108c SS |
2826 | /* If we end up stopping, the current frame will get selected |
2827 | in normal_stop. So this call to select_frame won't affect | |
2828 | the user. */ | |
0f7d239c | 2829 | select_frame (fr); |
c906108c | 2830 | } |
c5aa993b | 2831 | |
c906108c SS |
2832 | if (within_current_scope) |
2833 | { | |
2834 | /* We use value_{,free_to_}mark because it could be a | |
2835 | *long* time before we return to the command level and | |
c5aa993b JM |
2836 | call free_all_values. We can't call free_all_values because |
2837 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2838 | |
278cd55f | 2839 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2840 | struct value *new_val; |
2841 | ||
2842 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2843 | if ((b->val != NULL) != (new_val != NULL) | |
2844 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2845 | { |
fa4727a6 DJ |
2846 | if (new_val != NULL) |
2847 | { | |
2848 | release_value (new_val); | |
2849 | value_free_to_mark (mark); | |
2850 | } | |
c906108c SS |
2851 | bs->old_val = b->val; |
2852 | b->val = new_val; | |
fa4727a6 | 2853 | b->val_valid = 1; |
c906108c SS |
2854 | /* We will stop here */ |
2855 | return WP_VALUE_CHANGED; | |
2856 | } | |
2857 | else | |
2858 | { | |
2859 | /* Nothing changed, don't do anything. */ | |
2860 | value_free_to_mark (mark); | |
2861 | /* We won't stop here */ | |
2862 | return WP_VALUE_NOT_CHANGED; | |
2863 | } | |
2864 | } | |
2865 | else | |
2866 | { | |
2867 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2868 | if we temporarily ignored the watchpoint, then when |
2869 | we reenter the block in which it is valid it contains | |
2870 | garbage (in the case of a function, it may have two | |
2871 | garbage values, one before and one after the prologue). | |
2872 | So we can't even detect the first assignment to it and | |
2873 | watch after that (since the garbage may or may not equal | |
2874 | the first value assigned). */ | |
4ce44c66 JM |
2875 | /* We print all the stop information in print_it_typical(), but |
2876 | in this case, by the time we call print_it_typical() this bp | |
2877 | will be deleted already. So we have no choice but print the | |
2878 | information here. */ | |
9dc5e2a9 | 2879 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2880 | ui_out_field_string |
2881 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2882 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2883 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2884 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2885 | which its expression is valid.\n"); | |
4ce44c66 | 2886 | |
c906108c | 2887 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2888 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2889 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2890 | |
2891 | return WP_DELETED; | |
2892 | } | |
2893 | } | |
2894 | ||
18a18393 VP |
2895 | /* Return true if it looks like target has stopped due to hitting |
2896 | breakpoint location BL. This function does not check if we | |
2897 | should stop, only if BL explains the stop. */ | |
2898 | static int | |
2899 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2900 | { | |
2901 | struct breakpoint *b = bl->owner; | |
2902 | ||
2903 | if (b->type != bp_watchpoint | |
2904 | && b->type != bp_hardware_watchpoint | |
2905 | && b->type != bp_read_watchpoint | |
2906 | && b->type != bp_access_watchpoint | |
2907 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2908 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2909 | { |
2910 | if (bl->address != bp_addr) /* address doesn't match */ | |
2911 | return 0; | |
2912 | if (overlay_debugging /* unmapped overlay section */ | |
2913 | && section_is_overlay (bl->section) | |
2914 | && !section_is_mapped (bl->section)) | |
2915 | return 0; | |
2916 | } | |
2917 | ||
2918 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2919 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2920 | some data address). Otherwise gdb won't stop on a break instruction | |
2921 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2922 | been defined. Also skip watchpoints which we know did not trigger | |
2923 | (did not match the data address). */ | |
2924 | ||
2925 | if ((b->type == bp_hardware_watchpoint | |
2926 | || b->type == bp_read_watchpoint | |
2927 | || b->type == bp_access_watchpoint) | |
2928 | && b->watchpoint_triggered == watch_triggered_no) | |
2929 | return 0; | |
2930 | ||
2931 | if (b->type == bp_hardware_breakpoint) | |
2932 | { | |
2933 | if (bl->address != bp_addr) | |
2934 | return 0; | |
2935 | if (overlay_debugging /* unmapped overlay section */ | |
2936 | && section_is_overlay (bl->section) | |
2937 | && !section_is_mapped (bl->section)) | |
2938 | return 0; | |
2939 | } | |
ce78b96d | 2940 | |
ce78b96d JB |
2941 | if (b->type == bp_catchpoint) |
2942 | { | |
2943 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2944 | if (!b->ops->breakpoint_hit (b)) | |
2945 | return 0; | |
2946 | } | |
2947 | ||
18a18393 VP |
2948 | return 1; |
2949 | } | |
2950 | ||
2951 | /* If BS refers to a watchpoint, determine if the watched values | |
2952 | has actually changed, and we should stop. If not, set BS->stop | |
2953 | to 0. */ | |
2954 | static void | |
2955 | bpstat_check_watchpoint (bpstat bs) | |
2956 | { | |
2957 | const struct bp_location *bl = bs->breakpoint_at; | |
2958 | struct breakpoint *b = bl->owner; | |
2959 | ||
2960 | if (b->type == bp_watchpoint | |
2961 | || b->type == bp_read_watchpoint | |
2962 | || b->type == bp_access_watchpoint | |
2963 | || b->type == bp_hardware_watchpoint) | |
2964 | { | |
2965 | CORE_ADDR addr; | |
2966 | struct value *v; | |
2967 | int must_check_value = 0; | |
2968 | ||
2969 | if (b->type == bp_watchpoint) | |
2970 | /* For a software watchpoint, we must always check the | |
2971 | watched value. */ | |
2972 | must_check_value = 1; | |
2973 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2974 | /* We have a hardware watchpoint (read, write, or access) | |
2975 | and the target earlier reported an address watched by | |
2976 | this watchpoint. */ | |
2977 | must_check_value = 1; | |
2978 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2979 | && b->type == bp_hardware_watchpoint) | |
2980 | /* We were stopped by a hardware watchpoint, but the target could | |
2981 | not report the data address. We must check the watchpoint's | |
2982 | value. Access and read watchpoints are out of luck; without | |
2983 | a data address, we can't figure it out. */ | |
2984 | must_check_value = 1; | |
2985 | ||
2986 | if (must_check_value) | |
2987 | { | |
2988 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
2989 | b->number); | |
2990 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2991 | int e = catch_errors (watchpoint_check, bs, message, | |
2992 | RETURN_MASK_ALL); | |
2993 | do_cleanups (cleanups); | |
2994 | switch (e) | |
2995 | { | |
2996 | case WP_DELETED: | |
2997 | /* We've already printed what needs to be printed. */ | |
2998 | bs->print_it = print_it_done; | |
2999 | /* Stop. */ | |
3000 | break; | |
3001 | case WP_VALUE_CHANGED: | |
3002 | if (b->type == bp_read_watchpoint) | |
3003 | { | |
3004 | /* Don't stop: read watchpoints shouldn't fire if | |
3005 | the value has changed. This is for targets | |
3006 | which cannot set read-only watchpoints. */ | |
3007 | bs->print_it = print_it_noop; | |
3008 | bs->stop = 0; | |
3009 | } | |
3010 | break; | |
3011 | case WP_VALUE_NOT_CHANGED: | |
3012 | if (b->type == bp_hardware_watchpoint | |
3013 | || b->type == bp_watchpoint) | |
3014 | { | |
3015 | /* Don't stop: write watchpoints shouldn't fire if | |
3016 | the value hasn't changed. */ | |
3017 | bs->print_it = print_it_noop; | |
3018 | bs->stop = 0; | |
3019 | } | |
3020 | /* Stop. */ | |
3021 | break; | |
3022 | default: | |
3023 | /* Can't happen. */ | |
3024 | case 0: | |
3025 | /* Error from catch_errors. */ | |
3026 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3027 | if (b->related_breakpoint) | |
3028 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3029 | b->disposition = disp_del_at_next_stop; | |
3030 | /* We've already printed what needs to be printed. */ | |
3031 | bs->print_it = print_it_done; | |
3032 | break; | |
3033 | } | |
3034 | } | |
3035 | else /* must_check_value == 0 */ | |
3036 | { | |
3037 | /* This is a case where some watchpoint(s) triggered, but | |
3038 | not at the address of this watchpoint, or else no | |
3039 | watchpoint triggered after all. So don't print | |
3040 | anything for this watchpoint. */ | |
3041 | bs->print_it = print_it_noop; | |
3042 | bs->stop = 0; | |
3043 | } | |
3044 | } | |
3045 | } | |
3046 | ||
3047 | ||
3048 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3049 | of breakpoint referred to by BS. If we should not stop for this | |
3050 | breakpoint, set BS->stop to 0. */ | |
3051 | static void | |
3052 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3053 | { | |
3054 | int thread_id = pid_to_thread_id (ptid); | |
3055 | const struct bp_location *bl = bs->breakpoint_at; | |
3056 | struct breakpoint *b = bl->owner; | |
3057 | ||
3058 | if (frame_id_p (b->frame_id) | |
edb3359d | 3059 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3060 | bs->stop = 0; |
3061 | else if (bs->stop) | |
3062 | { | |
3063 | int value_is_zero = 0; | |
3064 | ||
3065 | /* If this is a scope breakpoint, mark the associated | |
3066 | watchpoint as triggered so that we will handle the | |
3067 | out-of-scope event. We'll get to the watchpoint next | |
3068 | iteration. */ | |
3069 | if (b->type == bp_watchpoint_scope) | |
3070 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3071 | ||
3072 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3073 | { | |
c5bc3a77 DJ |
3074 | /* We use value_mark and value_free_to_mark because it could |
3075 | be a long time before we return to the command level and | |
3076 | call free_all_values. We can't call free_all_values | |
3077 | because we might be in the middle of evaluating a | |
3078 | function call. */ | |
3079 | struct value *mark = value_mark (); | |
3080 | ||
edb3359d DJ |
3081 | /* Need to select the frame, with all that implies so that |
3082 | the conditions will have the right context. Because we | |
3083 | use the frame, we will not see an inlined function's | |
3084 | variables when we arrive at a breakpoint at the start | |
3085 | of the inlined function; the current frame will be the | |
3086 | call site. */ | |
18a18393 VP |
3087 | select_frame (get_current_frame ()); |
3088 | value_is_zero | |
3089 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3090 | "Error in testing breakpoint condition:\n", | |
3091 | RETURN_MASK_ALL); | |
3092 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3093 | value_free_to_mark (mark); |
18a18393 VP |
3094 | } |
3095 | if (bl->cond && value_is_zero) | |
3096 | { | |
3097 | bs->stop = 0; | |
3098 | } | |
3099 | else if (b->thread != -1 && b->thread != thread_id) | |
3100 | { | |
3101 | bs->stop = 0; | |
3102 | } | |
3103 | else if (b->ignore_count > 0) | |
3104 | { | |
3105 | b->ignore_count--; | |
3106 | annotate_ignore_count_change (); | |
3107 | bs->stop = 0; | |
3108 | /* Increase the hit count even though we don't | |
3109 | stop. */ | |
3110 | ++(b->hit_count); | |
3111 | } | |
3112 | } | |
3113 | } | |
3114 | ||
3115 | ||
9709f61c | 3116 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3117 | BP_ADDR in thread PTID. |
c906108c | 3118 | |
d983da9c | 3119 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3120 | don't understand this stop. Result is a chain of bpstat's such that: |
3121 | ||
c5aa993b | 3122 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3123 | |
c5aa993b | 3124 | if we understand why we stopped, the result is not null. |
c906108c | 3125 | |
c5aa993b JM |
3126 | Each element of the chain refers to a particular breakpoint or |
3127 | watchpoint at which we have stopped. (We may have stopped for | |
3128 | several reasons concurrently.) | |
c906108c | 3129 | |
c5aa993b JM |
3130 | Each element of the chain has valid next, breakpoint_at, |
3131 | commands, FIXME??? fields. */ | |
c906108c SS |
3132 | |
3133 | bpstat | |
d983da9c | 3134 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 3135 | { |
0d381245 | 3136 | struct breakpoint *b = NULL; |
89f9893c | 3137 | const struct bp_location *bl; |
20874c92 | 3138 | struct bp_location *loc; |
c906108c SS |
3139 | /* Root of the chain of bpstat's */ |
3140 | struct bpstats root_bs[1]; | |
3141 | /* Pointer to the last thing in the chain currently. */ | |
3142 | bpstat bs = root_bs; | |
20874c92 | 3143 | int ix; |
d832cb68 | 3144 | int need_remove_insert; |
c906108c | 3145 | |
0d381245 | 3146 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3147 | { |
0d381245 VP |
3148 | b = bl->owner; |
3149 | gdb_assert (b); | |
468d015d | 3150 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3151 | continue; |
3152 | ||
a5606eee VP |
3153 | /* For hardware watchpoints, we look only at the first location. |
3154 | The watchpoint_check function will work on entire expression, | |
3155 | not the individual locations. For read watchopints, the | |
3156 | watchpoints_triggered function have checked all locations | |
3157 | alrea | |
3158 | */ | |
3159 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3160 | continue; | |
3161 | ||
18a18393 VP |
3162 | if (!bpstat_check_location (bl, bp_addr)) |
3163 | continue; | |
3164 | ||
c5aa993b JM |
3165 | /* Come here if it's a watchpoint, or if the break address matches */ |
3166 | ||
0d381245 | 3167 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3168 | |
18a18393 VP |
3169 | /* Assume we stop. Should we find watchpoint that is not actually |
3170 | triggered, or if condition of breakpoint is false, we'll reset | |
3171 | 'stop' to 0. */ | |
c5aa993b JM |
3172 | bs->stop = 1; |
3173 | bs->print = 1; | |
3174 | ||
18a18393 VP |
3175 | bpstat_check_watchpoint (bs); |
3176 | if (!bs->stop) | |
3177 | continue; | |
c5aa993b | 3178 | |
0fd8e87f UW |
3179 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3180 | || b->type == bp_longjmp_master) | |
18a18393 | 3181 | /* We do not stop for these. */ |
c5aa993b JM |
3182 | bs->stop = 0; |
3183 | else | |
18a18393 VP |
3184 | bpstat_check_breakpoint_conditions (bs, ptid); |
3185 | ||
3186 | if (bs->stop) | |
c5aa993b | 3187 | { |
18a18393 | 3188 | ++(b->hit_count); |
d983da9c | 3189 | |
18a18393 VP |
3190 | /* We will stop here */ |
3191 | if (b->disposition == disp_disable) | |
c5aa993b | 3192 | { |
514f746b AR |
3193 | if (b->enable_state != bp_permanent) |
3194 | b->enable_state = bp_disabled; | |
b60e7edf | 3195 | update_global_location_list (0); |
c5aa993b | 3196 | } |
18a18393 VP |
3197 | if (b->silent) |
3198 | bs->print = 0; | |
3199 | bs->commands = b->commands; | |
059fb39f PM |
3200 | if (bs->commands |
3201 | && (strcmp ("silent", bs->commands->line) == 0 | |
3202 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3203 | { |
18a18393 VP |
3204 | bs->commands = bs->commands->next; |
3205 | bs->print = 0; | |
c5aa993b | 3206 | } |
18a18393 | 3207 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3208 | } |
18a18393 | 3209 | |
c5aa993b JM |
3210 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3211 | if (bs->stop == 0 || bs->print == 0) | |
3212 | bs->print_it = print_it_noop; | |
3213 | } | |
c906108c | 3214 | |
20874c92 VP |
3215 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3216 | { | |
3217 | if (loc->address == bp_addr) | |
3218 | { | |
3219 | bs = bpstat_alloc (loc, bs); | |
3220 | /* For hits of moribund locations, we should just proceed. */ | |
3221 | bs->stop = 0; | |
3222 | bs->print = 0; | |
3223 | bs->print_it = print_it_noop; | |
3224 | } | |
3225 | } | |
3226 | ||
c906108c SS |
3227 | bs->next = NULL; /* Terminate the chain */ |
3228 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3229 | ||
d983da9c DJ |
3230 | /* If we aren't stopping, the value of some hardware watchpoint may |
3231 | not have changed, but the intermediate memory locations we are | |
3232 | watching may have. Don't bother if we're stopping; this will get | |
3233 | done later. */ | |
3234 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3235 | if (bs->stop) | |
3236 | break; | |
3237 | ||
d832cb68 | 3238 | need_remove_insert = 0; |
d983da9c DJ |
3239 | if (bs == NULL) |
3240 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3241 | if (!bs->stop | |
20874c92 | 3242 | && bs->breakpoint_at->owner |
d983da9c DJ |
3243 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3244 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3245 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3246 | { | |
a5606eee VP |
3247 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3248 | location is no longer used by the watchpoint. Prevent | |
3249 | further code from trying to use it. */ | |
3250 | bs->breakpoint_at = NULL; | |
d832cb68 | 3251 | need_remove_insert = 1; |
d983da9c DJ |
3252 | } |
3253 | ||
d832cb68 DD |
3254 | if (need_remove_insert) |
3255 | { | |
3256 | remove_breakpoints (); | |
3257 | insert_breakpoints (); | |
3258 | } | |
3259 | ||
d983da9c | 3260 | return root_bs->next; |
c906108c SS |
3261 | } |
3262 | \f | |
3263 | /* Tell what to do about this bpstat. */ | |
3264 | struct bpstat_what | |
fba45db2 | 3265 | bpstat_what (bpstat bs) |
c906108c SS |
3266 | { |
3267 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3268 | enum class |
3269 | { | |
3270 | /* This bpstat element has no effect on the main_action. */ | |
3271 | no_effect = 0, | |
3272 | ||
3273 | /* There was a watchpoint, stop but don't print. */ | |
3274 | wp_silent, | |
c906108c | 3275 | |
c5aa993b JM |
3276 | /* There was a watchpoint, stop and print. */ |
3277 | wp_noisy, | |
c906108c | 3278 | |
c5aa993b JM |
3279 | /* There was a breakpoint but we're not stopping. */ |
3280 | bp_nostop, | |
c906108c | 3281 | |
c5aa993b JM |
3282 | /* There was a breakpoint, stop but don't print. */ |
3283 | bp_silent, | |
c906108c | 3284 | |
c5aa993b JM |
3285 | /* There was a breakpoint, stop and print. */ |
3286 | bp_noisy, | |
c906108c | 3287 | |
c5aa993b JM |
3288 | /* We hit the longjmp breakpoint. */ |
3289 | long_jump, | |
c906108c | 3290 | |
c5aa993b JM |
3291 | /* We hit the longjmp_resume breakpoint. */ |
3292 | long_resume, | |
c906108c | 3293 | |
c5aa993b JM |
3294 | /* We hit the step_resume breakpoint. */ |
3295 | step_resume, | |
c906108c | 3296 | |
c5aa993b JM |
3297 | /* We hit the shared library event breakpoint. */ |
3298 | shlib_event, | |
c906108c | 3299 | |
c5aa993b JM |
3300 | /* This is just used to count how many enums there are. */ |
3301 | class_last | |
c906108c SS |
3302 | }; |
3303 | ||
3304 | /* Here is the table which drives this routine. So that we can | |
3305 | format it pretty, we define some abbreviations for the | |
3306 | enum bpstat_what codes. */ | |
3307 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3308 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3309 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3310 | #define sgl BPSTAT_WHAT_SINGLE | |
3311 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3312 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3313 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3314 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
c906108c SS |
3315 | |
3316 | /* "Can't happen." Might want to print an error message. | |
3317 | abort() is not out of the question, but chances are GDB is just | |
3318 | a bit confused, not unusable. */ | |
3319 | #define err BPSTAT_WHAT_STOP_NOISY | |
3320 | ||
3321 | /* Given an old action and a class, come up with a new action. */ | |
3322 | /* One interesting property of this table is that wp_silent is the same | |
3323 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3324 | after stopping, the check for whether to step over a breakpoint | |
3325 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3326 | reference to how we stopped. We retain separate wp_silent and |
3327 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3328 | |
3329 | Another possibly interesting property of this table is that | |
3330 | there's a partial ordering, priority-like, of the actions. Once | |
3331 | you've decided that some action is appropriate, you'll never go | |
3332 | back and decide something of a lower priority is better. The | |
3333 | ordering is: | |
3334 | ||
d81191fc JB |
3335 | kc < clr sgl shl slr sn sr ss |
3336 | sgl < shl slr sn sr ss | |
3337 | slr < err shl sn sr ss | |
3338 | clr < err shl sn sr ss | |
3339 | ss < shl sn sr | |
3340 | sn < shl sr | |
3341 | shl < sr | |
4d5b2cd7 | 3342 | sr < |
c5aa993b | 3343 | |
43ff13b4 JM |
3344 | What I think this means is that we don't need a damned table |
3345 | here. If you just put the rows and columns in the right order, | |
3346 | it'd look awfully regular. We could simply walk the bpstat list | |
3347 | and choose the highest priority action we find, with a little | |
78b6a731 | 3348 | logic to handle the 'err' cases. */ |
c906108c SS |
3349 | |
3350 | /* step_resume entries: a step resume breakpoint overrides another | |
3351 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3352 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3353 | |
3354 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3355 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3356 | { | |
3357 | /* old action */ | |
d81191fc | 3358 | /* kc ss sn sgl slr clr sr shl |
c5aa993b JM |
3359 | */ |
3360 | /*no_effect */ | |
d81191fc | 3361 | {kc, ss, sn, sgl, slr, clr, sr, shl}, |
c5aa993b | 3362 | /*wp_silent */ |
d81191fc | 3363 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3364 | /*wp_noisy */ |
d81191fc | 3365 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3366 | /*bp_nostop */ |
d81191fc | 3367 | {sgl, ss, sn, sgl, slr, slr, sr, shl}, |
c5aa993b | 3368 | /*bp_silent */ |
d81191fc | 3369 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3370 | /*bp_noisy */ |
d81191fc | 3371 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3372 | /*long_jump */ |
d81191fc | 3373 | {slr, ss, sn, slr, slr, err, sr, shl}, |
c5aa993b | 3374 | /*long_resume */ |
d81191fc | 3375 | {clr, ss, sn, err, err, err, sr, shl}, |
c5aa993b | 3376 | /*step_resume */ |
d81191fc | 3377 | {sr, sr, sr, sr, sr, sr, sr, sr}, |
c5aa993b | 3378 | /*shlib */ |
d81191fc | 3379 | {shl, shl, shl, shl, shl, shl, sr, shl} |
c5aa993b | 3380 | }; |
c906108c SS |
3381 | |
3382 | #undef kc | |
3383 | #undef ss | |
3384 | #undef sn | |
3385 | #undef sgl | |
3386 | #undef slr | |
3387 | #undef clr | |
c906108c SS |
3388 | #undef err |
3389 | #undef sr | |
3390 | #undef ts | |
3391 | #undef shl | |
c906108c SS |
3392 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3393 | struct bpstat_what retval; | |
3394 | ||
3395 | retval.call_dummy = 0; | |
3396 | for (; bs != NULL; bs = bs->next) | |
3397 | { | |
3398 | enum class bs_class = no_effect; | |
3399 | if (bs->breakpoint_at == NULL) | |
3400 | /* I suspect this can happen if it was a momentary breakpoint | |
3401 | which has since been deleted. */ | |
3402 | continue; | |
20874c92 VP |
3403 | if (bs->breakpoint_at->owner == NULL) |
3404 | bs_class = bp_nostop; | |
3405 | else | |
4f8d1dc6 | 3406 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3407 | { |
3408 | case bp_none: | |
3409 | continue; | |
3410 | ||
3411 | case bp_breakpoint: | |
3412 | case bp_hardware_breakpoint: | |
3413 | case bp_until: | |
3414 | case bp_finish: | |
3415 | if (bs->stop) | |
3416 | { | |
3417 | if (bs->print) | |
3418 | bs_class = bp_noisy; | |
3419 | else | |
3420 | bs_class = bp_silent; | |
3421 | } | |
3422 | else | |
3423 | bs_class = bp_nostop; | |
3424 | break; | |
3425 | case bp_watchpoint: | |
3426 | case bp_hardware_watchpoint: | |
3427 | case bp_read_watchpoint: | |
3428 | case bp_access_watchpoint: | |
3429 | if (bs->stop) | |
3430 | { | |
3431 | if (bs->print) | |
3432 | bs_class = wp_noisy; | |
3433 | else | |
3434 | bs_class = wp_silent; | |
3435 | } | |
3436 | else | |
53a5351d JM |
3437 | /* There was a watchpoint, but we're not stopping. |
3438 | This requires no further action. */ | |
c906108c SS |
3439 | bs_class = no_effect; |
3440 | break; | |
3441 | case bp_longjmp: | |
3442 | bs_class = long_jump; | |
3443 | break; | |
3444 | case bp_longjmp_resume: | |
3445 | bs_class = long_resume; | |
3446 | break; | |
3447 | case bp_step_resume: | |
3448 | if (bs->stop) | |
3449 | { | |
3450 | bs_class = step_resume; | |
3451 | } | |
3452 | else | |
3453 | /* It is for the wrong frame. */ | |
3454 | bs_class = bp_nostop; | |
3455 | break; | |
c906108c SS |
3456 | case bp_watchpoint_scope: |
3457 | bs_class = bp_nostop; | |
3458 | break; | |
c5aa993b JM |
3459 | case bp_shlib_event: |
3460 | bs_class = shlib_event; | |
3461 | break; | |
c4093a6a | 3462 | case bp_thread_event: |
1900040c | 3463 | case bp_overlay_event: |
0fd8e87f | 3464 | case bp_longjmp_master: |
c4093a6a JM |
3465 | bs_class = bp_nostop; |
3466 | break; | |
ce78b96d | 3467 | case bp_catchpoint: |
c5aa993b JM |
3468 | if (bs->stop) |
3469 | { | |
3470 | if (bs->print) | |
3471 | bs_class = bp_noisy; | |
3472 | else | |
3473 | bs_class = bp_silent; | |
3474 | } | |
3475 | else | |
53a5351d JM |
3476 | /* There was a catchpoint, but we're not stopping. |
3477 | This requires no further action. */ | |
c5aa993b JM |
3478 | bs_class = no_effect; |
3479 | break; | |
c906108c | 3480 | case bp_call_dummy: |
53a5351d JM |
3481 | /* Make sure the action is stop (silent or noisy), |
3482 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3483 | bs_class = bp_silent; |
3484 | retval.call_dummy = 1; | |
3485 | break; | |
1042e4c0 SS |
3486 | case bp_tracepoint: |
3487 | /* Tracepoint hits should not be reported back to GDB, and | |
3488 | if one got through somehow, it should have been filtered | |
3489 | out already. */ | |
3490 | internal_error (__FILE__, __LINE__, | |
3491 | _("bpstat_what: bp_tracepoint encountered")); | |
3492 | break; | |
c906108c | 3493 | } |
c5aa993b | 3494 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3495 | } |
3496 | retval.main_action = current_action; | |
3497 | return retval; | |
3498 | } | |
3499 | ||
3500 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3501 | without hardware support). This isn't related to a specific bpstat, | |
3502 | just to things like whether watchpoints are set. */ | |
3503 | ||
c5aa993b | 3504 | int |
fba45db2 | 3505 | bpstat_should_step (void) |
c906108c SS |
3506 | { |
3507 | struct breakpoint *b; | |
3508 | ALL_BREAKPOINTS (b) | |
717a8278 | 3509 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3510 | return 1; |
c906108c SS |
3511 | return 0; |
3512 | } | |
3513 | ||
c906108c | 3514 | \f |
c5aa993b | 3515 | |
0d381245 VP |
3516 | static void print_breakpoint_location (struct breakpoint *b, |
3517 | struct bp_location *loc, | |
3518 | char *wrap_indent, | |
3519 | struct ui_stream *stb) | |
3520 | { | |
3521 | if (b->source_file) | |
3522 | { | |
3523 | struct symbol *sym | |
3524 | = find_pc_sect_function (loc->address, loc->section); | |
3525 | if (sym) | |
3526 | { | |
3527 | ui_out_text (uiout, "in "); | |
3528 | ui_out_field_string (uiout, "func", | |
3529 | SYMBOL_PRINT_NAME (sym)); | |
3530 | ui_out_wrap_hint (uiout, wrap_indent); | |
3531 | ui_out_text (uiout, " at "); | |
3532 | } | |
3533 | ui_out_field_string (uiout, "file", b->source_file); | |
3534 | ui_out_text (uiout, ":"); | |
3535 | ||
3536 | if (ui_out_is_mi_like_p (uiout)) | |
3537 | { | |
3538 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3539 | char *fullname = symtab_to_fullname (sal.symtab); | |
3540 | ||
3541 | if (fullname) | |
3542 | ui_out_field_string (uiout, "fullname", fullname); | |
3543 | } | |
3544 | ||
3545 | ui_out_field_int (uiout, "line", b->line_number); | |
3546 | } | |
3547 | else if (!b->loc) | |
3548 | { | |
3549 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3550 | } | |
3551 | else | |
3552 | { | |
3553 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3554 | ui_out_field_stream (uiout, "at", stb); | |
3555 | } | |
3556 | } | |
3557 | ||
c4093a6a | 3558 | /* Print B to gdb_stdout. */ |
c906108c | 3559 | static void |
0d381245 VP |
3560 | print_one_breakpoint_location (struct breakpoint *b, |
3561 | struct bp_location *loc, | |
3562 | int loc_number, | |
a6d9a66e UW |
3563 | struct bp_location **last_loc, |
3564 | int print_address_bits) | |
c906108c | 3565 | { |
52f0bd74 AC |
3566 | struct command_line *l; |
3567 | struct symbol *sym; | |
c4093a6a JM |
3568 | struct ep_type_description |
3569 | { | |
3570 | enum bptype type; | |
3571 | char *description; | |
3572 | }; | |
3573 | static struct ep_type_description bptypes[] = | |
c906108c | 3574 | { |
c5aa993b JM |
3575 | {bp_none, "?deleted?"}, |
3576 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3577 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3578 | {bp_until, "until"}, |
3579 | {bp_finish, "finish"}, | |
3580 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3581 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3582 | {bp_read_watchpoint, "read watchpoint"}, |
3583 | {bp_access_watchpoint, "acc watchpoint"}, | |
3584 | {bp_longjmp, "longjmp"}, | |
3585 | {bp_longjmp_resume, "longjmp resume"}, | |
3586 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3587 | {bp_watchpoint_scope, "watchpoint scope"}, |
3588 | {bp_call_dummy, "call dummy"}, | |
3589 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3590 | {bp_thread_event, "thread events"}, |
1900040c | 3591 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3592 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3593 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3594 | {bp_tracepoint, "tracepoint"}, |
c5aa993b | 3595 | }; |
c4093a6a | 3596 | |
c2c6d25f | 3597 | static char bpenables[] = "nynny"; |
c906108c | 3598 | char wrap_indent[80]; |
8b93c638 JM |
3599 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3600 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3601 | struct cleanup *bkpt_chain; |
c906108c | 3602 | |
0d381245 VP |
3603 | int header_of_multiple = 0; |
3604 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3605 | struct value_print_options opts; |
3606 | ||
3607 | get_user_print_options (&opts); | |
0d381245 VP |
3608 | |
3609 | gdb_assert (!loc || loc_number != 0); | |
3610 | /* See comment in print_one_breakpoint concerning | |
3611 | treatment of breakpoints with single disabled | |
3612 | location. */ | |
3613 | if (loc == NULL | |
3614 | && (b->loc != NULL | |
3615 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3616 | header_of_multiple = 1; | |
3617 | if (loc == NULL) | |
3618 | loc = b->loc; | |
3619 | ||
c4093a6a | 3620 | annotate_record (); |
3b31d625 | 3621 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3622 | |
3623 | /* 1 */ | |
3624 | annotate_field (0); | |
0d381245 VP |
3625 | if (part_of_multiple) |
3626 | { | |
3627 | char *formatted; | |
0c6773c1 | 3628 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3629 | ui_out_field_string (uiout, "number", formatted); |
3630 | xfree (formatted); | |
3631 | } | |
3632 | else | |
3633 | { | |
3634 | ui_out_field_int (uiout, "number", b->number); | |
3635 | } | |
c4093a6a JM |
3636 | |
3637 | /* 2 */ | |
3638 | annotate_field (1); | |
0d381245 VP |
3639 | if (part_of_multiple) |
3640 | ui_out_field_skip (uiout, "type"); | |
3641 | else | |
3642 | { | |
3643 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3644 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3645 | internal_error (__FILE__, __LINE__, | |
3646 | _("bptypes table does not describe type #%d."), | |
3647 | (int) b->type); | |
3648 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3649 | } | |
c4093a6a JM |
3650 | |
3651 | /* 3 */ | |
3652 | annotate_field (2); | |
0d381245 VP |
3653 | if (part_of_multiple) |
3654 | ui_out_field_skip (uiout, "disp"); | |
3655 | else | |
2cec12e5 | 3656 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3657 | |
c4093a6a JM |
3658 | |
3659 | /* 4 */ | |
3660 | annotate_field (3); | |
0d381245 | 3661 | if (part_of_multiple) |
54e52265 | 3662 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3663 | else |
54e52265 VP |
3664 | ui_out_field_fmt (uiout, "enabled", "%c", |
3665 | bpenables[(int) b->enable_state]); | |
3666 | ui_out_spaces (uiout, 2); | |
0d381245 | 3667 | |
c4093a6a JM |
3668 | |
3669 | /* 5 and 6 */ | |
3670 | strcpy (wrap_indent, " "); | |
79a45b7d | 3671 | if (opts.addressprint) |
75ac9d7b | 3672 | { |
a6d9a66e | 3673 | if (print_address_bits <= 32) |
75ac9d7b MS |
3674 | strcat (wrap_indent, " "); |
3675 | else | |
3676 | strcat (wrap_indent, " "); | |
3677 | } | |
c906108c | 3678 | |
3086aeae | 3679 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3680 | { |
3681 | /* Although the print_one can possibly print | |
3682 | all locations, calling it here is not likely | |
3683 | to get any nice result. So, make sure there's | |
3684 | just one location. */ | |
3685 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3686 | b->ops->print_one (b, last_loc); |
0d381245 | 3687 | } |
3086aeae DJ |
3688 | else |
3689 | switch (b->type) | |
3690 | { | |
3691 | case bp_none: | |
3692 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3693 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3694 | break; |
c906108c | 3695 | |
3086aeae DJ |
3696 | case bp_watchpoint: |
3697 | case bp_hardware_watchpoint: | |
3698 | case bp_read_watchpoint: | |
3699 | case bp_access_watchpoint: | |
3700 | /* Field 4, the address, is omitted (which makes the columns | |
3701 | not line up too nicely with the headers, but the effect | |
3702 | is relatively readable). */ | |
79a45b7d | 3703 | if (opts.addressprint) |
3086aeae DJ |
3704 | ui_out_field_skip (uiout, "addr"); |
3705 | annotate_field (5); | |
fa8a61dc | 3706 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3707 | break; |
3708 | ||
3086aeae DJ |
3709 | case bp_breakpoint: |
3710 | case bp_hardware_breakpoint: | |
3711 | case bp_until: | |
3712 | case bp_finish: | |
3713 | case bp_longjmp: | |
3714 | case bp_longjmp_resume: | |
3715 | case bp_step_resume: | |
3086aeae DJ |
3716 | case bp_watchpoint_scope: |
3717 | case bp_call_dummy: | |
3718 | case bp_shlib_event: | |
3719 | case bp_thread_event: | |
3720 | case bp_overlay_event: | |
0fd8e87f | 3721 | case bp_longjmp_master: |
1042e4c0 | 3722 | case bp_tracepoint: |
79a45b7d | 3723 | if (opts.addressprint) |
3086aeae DJ |
3724 | { |
3725 | annotate_field (4); | |
54e52265 | 3726 | if (header_of_multiple) |
0d381245 | 3727 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3728 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3729 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3730 | else |
5af949e3 UW |
3731 | ui_out_field_core_addr (uiout, "addr", |
3732 | loc->gdbarch, loc->address); | |
3086aeae DJ |
3733 | } |
3734 | annotate_field (5); | |
0d381245 VP |
3735 | if (!header_of_multiple) |
3736 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3737 | if (b->loc) | |
a6d9a66e | 3738 | *last_loc = b->loc; |
3086aeae DJ |
3739 | break; |
3740 | } | |
c906108c | 3741 | |
4a306c9a | 3742 | if (!part_of_multiple) |
c4093a6a | 3743 | { |
4a306c9a JB |
3744 | if (b->thread != -1) |
3745 | { | |
3746 | /* FIXME: This seems to be redundant and lost here; see the | |
3747 | "stop only in" line a little further down. */ | |
3748 | ui_out_text (uiout, " thread "); | |
3749 | ui_out_field_int (uiout, "thread", b->thread); | |
3750 | } | |
3751 | else if (b->task != 0) | |
3752 | { | |
3753 | ui_out_text (uiout, " task "); | |
3754 | ui_out_field_int (uiout, "task", b->task); | |
3755 | } | |
c4093a6a JM |
3756 | } |
3757 | ||
8b93c638 | 3758 | ui_out_text (uiout, "\n"); |
c4093a6a | 3759 | |
0d381245 | 3760 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3761 | { |
3762 | annotate_field (6); | |
8b93c638 | 3763 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3764 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3765 | the frame ID. */ | |
5af949e3 UW |
3766 | ui_out_field_core_addr (uiout, "frame", |
3767 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 3768 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3769 | } |
3770 | ||
0d381245 | 3771 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3772 | { |
f7f9143b JB |
3773 | /* We do not print the condition for Ada exception catchpoints |
3774 | because the condition is an internal implementation detail | |
3775 | that we do not want to expose to the user. */ | |
c4093a6a | 3776 | annotate_field (7); |
1042e4c0 SS |
3777 | if (b->type == bp_tracepoint) |
3778 | ui_out_text (uiout, "\ttrace only if "); | |
3779 | else | |
3780 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
3781 | ui_out_field_string (uiout, "cond", b->cond_string); |
3782 | ui_out_text (uiout, "\n"); | |
3783 | } | |
3784 | ||
0d381245 | 3785 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3786 | { |
3787 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3788 | ui_out_text (uiout, "\tstop only in thread "); |
3789 | ui_out_field_int (uiout, "thread", b->thread); | |
3790 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3791 | } |
3792 | ||
63c715c6 | 3793 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3794 | { |
3795 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3796 | if (ep_is_catchpoint (b)) |
3797 | ui_out_text (uiout, "\tcatchpoint"); | |
3798 | else | |
3799 | ui_out_text (uiout, "\tbreakpoint"); | |
3800 | ui_out_text (uiout, " already hit "); | |
3801 | ui_out_field_int (uiout, "times", b->hit_count); | |
3802 | if (b->hit_count == 1) | |
3803 | ui_out_text (uiout, " time\n"); | |
3804 | else | |
3805 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3806 | } |
3807 | ||
fb40c209 AC |
3808 | /* Output the count also if it is zero, but only if this is |
3809 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3810 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3811 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3812 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3813 | |
0d381245 | 3814 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3815 | { |
3816 | annotate_field (8); | |
8b93c638 JM |
3817 | ui_out_text (uiout, "\tignore next "); |
3818 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3819 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 3820 | } |
059fb39f PM |
3821 | |
3822 | l = b->commands; | |
3823 | if (!part_of_multiple && l) | |
c4093a6a | 3824 | { |
3b31d625 EZ |
3825 | struct cleanup *script_chain; |
3826 | ||
c4093a6a | 3827 | annotate_field (9); |
3b31d625 | 3828 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3829 | print_command_lines (uiout, l, 4); |
3b31d625 | 3830 | do_cleanups (script_chain); |
c4093a6a | 3831 | } |
d24317b4 | 3832 | |
1042e4c0 SS |
3833 | if (!part_of_multiple && b->pass_count) |
3834 | { | |
3835 | annotate_field (10); | |
3836 | ui_out_text (uiout, "\tpass count "); | |
3837 | ui_out_field_int (uiout, "pass", b->pass_count); | |
3838 | ui_out_text (uiout, " \n"); | |
3839 | } | |
3840 | ||
3841 | if (!part_of_multiple && b->step_count) | |
3842 | { | |
3843 | annotate_field (11); | |
3844 | ui_out_text (uiout, "\tstep count "); | |
3845 | ui_out_field_int (uiout, "step", b->step_count); | |
3846 | ui_out_text (uiout, " \n"); | |
3847 | } | |
3848 | ||
3849 | if (!part_of_multiple && b->actions) | |
3850 | { | |
3851 | struct action_line *action; | |
3852 | annotate_field (12); | |
3853 | for (action = b->actions; action; action = action->next) | |
3854 | { | |
3855 | ui_out_text (uiout, " A\t"); | |
3856 | ui_out_text (uiout, action->action); | |
3857 | ui_out_text (uiout, "\n"); | |
3858 | } | |
3859 | } | |
3860 | ||
d24317b4 VP |
3861 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
3862 | { | |
3863 | if (b->addr_string) | |
3864 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3865 | else if (b->exp_string) | |
3866 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3867 | } | |
3868 | ||
3b31d625 | 3869 | do_cleanups (bkpt_chain); |
8b93c638 | 3870 | do_cleanups (old_chain); |
c4093a6a | 3871 | } |
c5aa993b | 3872 | |
0d381245 VP |
3873 | static void |
3874 | print_one_breakpoint (struct breakpoint *b, | |
a6d9a66e | 3875 | struct bp_location **last_loc, int print_address_bits) |
0d381245 | 3876 | { |
a6d9a66e | 3877 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
0d381245 VP |
3878 | |
3879 | /* If this breakpoint has custom print function, | |
3880 | it's already printed. Otherwise, print individual | |
3881 | locations, if any. */ | |
3882 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3883 | { | |
3884 | /* If breakpoint has a single location that is | |
3885 | disabled, we print it as if it had | |
3886 | several locations, since otherwise it's hard to | |
3887 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3888 | situation. |
3889 | Note that while hardware watchpoints have | |
3890 | several locations internally, that's no a property | |
3891 | exposed to user. */ | |
0d381245 | 3892 | if (b->loc |
a5606eee | 3893 | && !is_hardware_watchpoint (b) |
0d381245 | 3894 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3895 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3896 | { |
3897 | struct bp_location *loc; | |
3898 | int n = 1; | |
3899 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e UW |
3900 | print_one_breakpoint_location (b, loc, n, last_loc, |
3901 | print_address_bits); | |
0d381245 VP |
3902 | } |
3903 | } | |
3904 | } | |
3905 | ||
a6d9a66e UW |
3906 | static int |
3907 | breakpoint_address_bits (struct breakpoint *b) | |
3908 | { | |
3909 | int print_address_bits = 0; | |
3910 | struct bp_location *loc; | |
3911 | ||
3912 | for (loc = b->loc; loc; loc = loc->next) | |
3913 | { | |
3914 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
3915 | if (addr_bit > print_address_bits) | |
3916 | print_address_bits = addr_bit; | |
3917 | } | |
3918 | ||
3919 | return print_address_bits; | |
3920 | } | |
0d381245 | 3921 | |
c4093a6a JM |
3922 | struct captured_breakpoint_query_args |
3923 | { | |
3924 | int bnum; | |
3925 | }; | |
c5aa993b | 3926 | |
c4093a6a | 3927 | static int |
2b65245e | 3928 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3929 | { |
3930 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3931 | struct breakpoint *b; |
a6d9a66e | 3932 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
3933 | ALL_BREAKPOINTS (b) |
3934 | { | |
3935 | if (args->bnum == b->number) | |
c5aa993b | 3936 | { |
a6d9a66e UW |
3937 | int print_address_bits = breakpoint_address_bits (b); |
3938 | print_one_breakpoint (b, &dummy_loc, print_address_bits); | |
c4093a6a | 3939 | return GDB_RC_OK; |
c5aa993b | 3940 | } |
c4093a6a JM |
3941 | } |
3942 | return GDB_RC_NONE; | |
3943 | } | |
c5aa993b | 3944 | |
c4093a6a | 3945 | enum gdb_rc |
ce43223b | 3946 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3947 | { |
3948 | struct captured_breakpoint_query_args args; | |
3949 | args.bnum = bnum; | |
3950 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3951 | an error. */ | |
b0b13bb4 DJ |
3952 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3953 | error_message, RETURN_MASK_ALL) < 0) | |
3954 | return GDB_RC_FAIL; | |
3955 | else | |
3956 | return GDB_RC_OK; | |
c4093a6a | 3957 | } |
c5aa993b | 3958 | |
7f3b0473 AC |
3959 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3960 | catchpoints, et.al.). */ | |
3961 | ||
3962 | static int | |
3963 | user_settable_breakpoint (const struct breakpoint *b) | |
3964 | { | |
3965 | return (b->type == bp_breakpoint | |
ce78b96d | 3966 | || b->type == bp_catchpoint |
7f3b0473 | 3967 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 3968 | || b->type == bp_tracepoint |
7f3b0473 AC |
3969 | || b->type == bp_watchpoint |
3970 | || b->type == bp_read_watchpoint | |
3971 | || b->type == bp_access_watchpoint | |
3972 | || b->type == bp_hardware_watchpoint); | |
3973 | } | |
3974 | ||
3975 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3976 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3977 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3978 | |
c4093a6a | 3979 | static void |
fba45db2 | 3980 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3981 | { |
52f0bd74 | 3982 | struct breakpoint *b; |
a6d9a66e | 3983 | struct bp_location *last_loc = NULL; |
7f3b0473 | 3984 | int nr_printable_breakpoints; |
3b31d625 | 3985 | struct cleanup *bkpttbl_chain; |
79a45b7d | 3986 | struct value_print_options opts; |
a6d9a66e | 3987 | int print_address_bits = 0; |
c4093a6a | 3988 | |
79a45b7d TT |
3989 | get_user_print_options (&opts); |
3990 | ||
a6d9a66e UW |
3991 | /* Compute the number of rows in the table, as well as the |
3992 | size required for address fields. */ | |
7f3b0473 AC |
3993 | nr_printable_breakpoints = 0; |
3994 | ALL_BREAKPOINTS (b) | |
3995 | if (bnum == -1 | |
3996 | || bnum == b->number) | |
3997 | { | |
3998 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
3999 | { |
4000 | int addr_bit = breakpoint_address_bits (b); | |
4001 | if (addr_bit > print_address_bits) | |
4002 | print_address_bits = addr_bit; | |
4003 | ||
4004 | nr_printable_breakpoints++; | |
4005 | } | |
7f3b0473 AC |
4006 | } |
4007 | ||
79a45b7d | 4008 | if (opts.addressprint) |
3b31d625 EZ |
4009 | bkpttbl_chain |
4010 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4011 | "BreakpointTable"); | |
8b93c638 | 4012 | else |
3b31d625 EZ |
4013 | bkpttbl_chain |
4014 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4015 | "BreakpointTable"); | |
8b93c638 | 4016 | |
7f3b0473 | 4017 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4018 | annotate_breakpoints_headers (); |
4019 | if (nr_printable_breakpoints > 0) | |
4020 | annotate_field (0); | |
0d381245 | 4021 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4022 | if (nr_printable_breakpoints > 0) |
4023 | annotate_field (1); | |
4024 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4025 | if (nr_printable_breakpoints > 0) | |
4026 | annotate_field (2); | |
4027 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4028 | if (nr_printable_breakpoints > 0) | |
4029 | annotate_field (3); | |
54e52265 | 4030 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4031 | if (opts.addressprint) |
7f3b0473 | 4032 | { |
d7faa9e7 AC |
4033 | if (nr_printable_breakpoints > 0) |
4034 | annotate_field (4); | |
a6d9a66e | 4035 | if (print_address_bits <= 32) |
b25959ec | 4036 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4037 | else |
b25959ec | 4038 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4039 | } |
d7faa9e7 AC |
4040 | if (nr_printable_breakpoints > 0) |
4041 | annotate_field (5); | |
4042 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4043 | ui_out_table_body (uiout); | |
4044 | if (nr_printable_breakpoints > 0) | |
4045 | annotate_breakpoints_table (); | |
7f3b0473 | 4046 | |
c4093a6a JM |
4047 | ALL_BREAKPOINTS (b) |
4048 | if (bnum == -1 | |
4049 | || bnum == b->number) | |
4050 | { | |
4051 | /* We only print out user settable breakpoints unless the | |
4052 | allflag is set. */ | |
7f3b0473 | 4053 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4054 | print_one_breakpoint (b, &last_loc, print_address_bits); |
c4093a6a JM |
4055 | } |
4056 | ||
3b31d625 | 4057 | do_cleanups (bkpttbl_chain); |
698384cd | 4058 | |
7f3b0473 | 4059 | if (nr_printable_breakpoints == 0) |
c906108c | 4060 | { |
8b93c638 JM |
4061 | if (bnum == -1) |
4062 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4063 | else | |
4064 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4065 | bnum); | |
c906108c SS |
4066 | } |
4067 | else | |
c4093a6a | 4068 | { |
a6d9a66e UW |
4069 | if (last_loc && !server_command) |
4070 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4071 | } |
c906108c | 4072 | |
c4093a6a JM |
4073 | /* FIXME? Should this be moved up so that it is only called when |
4074 | there have been breakpoints? */ | |
c906108c SS |
4075 | annotate_breakpoints_table_end (); |
4076 | } | |
4077 | ||
c906108c | 4078 | static void |
fba45db2 | 4079 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4080 | { |
4081 | int bnum = -1; | |
4082 | ||
4083 | if (bnum_exp) | |
bb518678 | 4084 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4085 | |
4086 | breakpoint_1 (bnum, 0); | |
4087 | } | |
4088 | ||
7a292a7a | 4089 | static void |
fba45db2 | 4090 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4091 | { |
4092 | int bnum = -1; | |
4093 | ||
4094 | if (bnum_exp) | |
bb518678 | 4095 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4096 | |
4097 | breakpoint_1 (bnum, 1); | |
4098 | } | |
4099 | ||
0d381245 | 4100 | static int |
714835d5 UW |
4101 | breakpoint_has_pc (struct breakpoint *b, |
4102 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
4103 | { |
4104 | struct bp_location *bl = b->loc; | |
4105 | for (; bl; bl = bl->next) | |
4106 | { | |
4107 | if (bl->address == pc | |
4108 | && (!overlay_debugging || bl->section == section)) | |
4109 | return 1; | |
4110 | } | |
4111 | return 0; | |
4112 | } | |
4113 | ||
c906108c SS |
4114 | /* Print a message describing any breakpoints set at PC. */ |
4115 | ||
4116 | static void | |
5af949e3 UW |
4117 | describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc, |
4118 | struct obj_section *section, int thread) | |
c906108c | 4119 | { |
52f0bd74 AC |
4120 | int others = 0; |
4121 | struct breakpoint *b; | |
c906108c SS |
4122 | |
4123 | ALL_BREAKPOINTS (b) | |
0d381245 | 4124 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
4125 | if (others > 0) |
4126 | { | |
a3f17187 AC |
4127 | if (others == 1) |
4128 | printf_filtered (_("Note: breakpoint ")); | |
4129 | else /* if (others == ???) */ | |
4130 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4131 | ALL_BREAKPOINTS (b) |
0d381245 VP |
4132 | if (breakpoint_has_pc (b, pc, section)) |
4133 | { | |
4134 | others--; | |
4135 | printf_filtered ("%d", b->number); | |
4136 | if (b->thread == -1 && thread != -1) | |
4137 | printf_filtered (" (all threads)"); | |
4138 | else if (b->thread != -1) | |
4139 | printf_filtered (" (thread %d)", b->thread); | |
4140 | printf_filtered ("%s%s ", | |
059fb39f PM |
4141 | ((b->enable_state == bp_disabled |
4142 | || b->enable_state == bp_call_disabled) | |
0d381245 VP |
4143 | ? " (disabled)" |
4144 | : b->enable_state == bp_permanent | |
4145 | ? " (permanent)" | |
4146 | : ""), | |
4147 | (others > 1) ? "," | |
4148 | : ((others == 1) ? " and" : "")); | |
4149 | } | |
a3f17187 | 4150 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4151 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4152 | printf_filtered (".\n"); |
4153 | } | |
4154 | } | |
4155 | \f | |
4156 | /* Set the default place to put a breakpoint | |
4157 | for the `break' command with no arguments. */ | |
4158 | ||
4159 | void | |
fba45db2 KB |
4160 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
4161 | int line) | |
c906108c SS |
4162 | { |
4163 | default_breakpoint_valid = valid; | |
4164 | default_breakpoint_address = addr; | |
4165 | default_breakpoint_symtab = symtab; | |
4166 | default_breakpoint_line = line; | |
4167 | } | |
4168 | ||
e4f237da KB |
4169 | /* Return true iff it is meaningful to use the address member of |
4170 | BPT. For some breakpoint types, the address member is irrelevant | |
4171 | and it makes no sense to attempt to compare it to other addresses | |
4172 | (or use it for any other purpose either). | |
4173 | ||
4174 | More specifically, each of the following breakpoint types will always | |
4175 | have a zero valued address and we don't want check_duplicates() to mark | |
4176 | breakpoints of any of these types to be a duplicate of an actual | |
4177 | breakpoint at address zero: | |
4178 | ||
4179 | bp_watchpoint | |
4180 | bp_hardware_watchpoint | |
4181 | bp_read_watchpoint | |
4182 | bp_access_watchpoint | |
fe798b75 | 4183 | bp_catchpoint */ |
e4f237da KB |
4184 | |
4185 | static int | |
4186 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4187 | { | |
4188 | enum bptype type = bpt->type; | |
4189 | ||
4190 | return (type != bp_watchpoint | |
4191 | && type != bp_hardware_watchpoint | |
4192 | && type != bp_read_watchpoint | |
4193 | && type != bp_access_watchpoint | |
fe798b75 | 4194 | && type != bp_catchpoint); |
e4f237da KB |
4195 | } |
4196 | ||
9f60f21b | 4197 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4198 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4199 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4200 | If we have a permanent breakpoint at the same place as BPT, make |
4201 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4202 | |
4203 | static void | |
714835d5 | 4204 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 4205 | { |
075f6582 | 4206 | struct bp_location *b; |
52f0bd74 | 4207 | int count = 0; |
075f6582 | 4208 | struct bp_location *perm_bp = 0; |
c906108c | 4209 | |
075f6582 DJ |
4210 | ALL_BP_LOCATIONS (b) |
4211 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4212 | && b->owner->enable_state != bp_call_disabled |
0d381245 VP |
4213 | && b->enabled |
4214 | && !b->shlib_disabled | |
075f6582 DJ |
4215 | && b->address == address /* address / overlay match */ |
4216 | && (!overlay_debugging || b->section == section) | |
4217 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 4218 | { |
c2c6d25f | 4219 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4220 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4221 | { |
4222 | perm_bp = b; | |
4223 | break; | |
4224 | } | |
4225 | ||
c5aa993b | 4226 | count++; |
075f6582 | 4227 | b->duplicate = count > 1; |
c5aa993b | 4228 | } |
c2c6d25f JM |
4229 | |
4230 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4231 | list again and declare all the other breakpoints there (except |
4232 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4233 | if (perm_bp) |
4234 | { | |
075f6582 | 4235 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4236 | |
4237 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4238 | if (! perm_bp->inserted) |
8e65ff28 | 4239 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4240 | _("allegedly permanent breakpoint is not " |
4241 | "actually inserted")); | |
c2c6d25f | 4242 | |
075f6582 | 4243 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4244 | if (b != perm_bp) |
4245 | { | |
aae64587 PA |
4246 | if (b->owner->enable_state != bp_permanent |
4247 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4248 | && b->owner->enable_state != bp_call_disabled |
0d381245 | 4249 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
4250 | && b->address == address /* address / overlay match */ |
4251 | && (!overlay_debugging || b->section == section) | |
4252 | && breakpoint_address_is_meaningful (b->owner)) | |
4253 | { | |
4254 | if (b->inserted) | |
4255 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4256 | _("another breakpoint was inserted on top of " |
4257 | "a permanent breakpoint")); | |
075f6582 DJ |
4258 | |
4259 | b->duplicate = 1; | |
4260 | } | |
c2c6d25f JM |
4261 | } |
4262 | } | |
c906108c SS |
4263 | } |
4264 | ||
0d381245 VP |
4265 | static void |
4266 | check_duplicates (struct breakpoint *bpt) | |
4267 | { | |
4268 | struct bp_location *bl = bpt->loc; | |
4269 | ||
4270 | if (! breakpoint_address_is_meaningful (bpt)) | |
4271 | return; | |
4272 | ||
4273 | for (; bl; bl = bl->next) | |
4274 | check_duplicates_for (bl->address, bl->section); | |
4275 | } | |
4276 | ||
76897487 KB |
4277 | static void |
4278 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4279 | int bnum, int have_bnum) | |
4280 | { | |
4281 | char astr1[40]; | |
4282 | char astr2[40]; | |
4283 | ||
bb599908 PH |
4284 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4285 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4286 | if (have_bnum) |
8a3fe4f8 | 4287 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4288 | bnum, astr1, astr2); |
4289 | else | |
8a3fe4f8 | 4290 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4291 | } |
4292 | ||
4293 | /* Adjust a breakpoint's address to account for architectural constraints | |
4294 | on breakpoint placement. Return the adjusted address. Note: Very | |
4295 | few targets require this kind of adjustment. For most targets, | |
4296 | this function is simply the identity function. */ | |
4297 | ||
4298 | static CORE_ADDR | |
a6d9a66e UW |
4299 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4300 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4301 | { |
a6d9a66e | 4302 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4303 | { |
4304 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4305 | return bpaddr; | |
4306 | } | |
88f7da05 KB |
4307 | else if (bptype == bp_watchpoint |
4308 | || bptype == bp_hardware_watchpoint | |
4309 | || bptype == bp_read_watchpoint | |
4310 | || bptype == bp_access_watchpoint | |
fe798b75 | 4311 | || bptype == bp_catchpoint) |
88f7da05 KB |
4312 | { |
4313 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4314 | have their addresses modified. */ | |
4315 | return bpaddr; | |
4316 | } | |
76897487 KB |
4317 | else |
4318 | { | |
4319 | CORE_ADDR adjusted_bpaddr; | |
4320 | ||
4321 | /* Some targets have architectural constraints on the placement | |
4322 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4323 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4324 | |
4325 | /* An adjusted breakpoint address can significantly alter | |
4326 | a user's expectations. Print a warning if an adjustment | |
4327 | is required. */ | |
4328 | if (adjusted_bpaddr != bpaddr) | |
4329 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4330 | ||
4331 | return adjusted_bpaddr; | |
4332 | } | |
4333 | } | |
4334 | ||
7cc221ef DJ |
4335 | /* Allocate a struct bp_location. */ |
4336 | ||
26bb91f3 | 4337 | static struct bp_location * |
39d61571 | 4338 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4339 | { |
4340 | struct bp_location *loc, *loc_p; | |
4341 | ||
4342 | loc = xmalloc (sizeof (struct bp_location)); | |
4343 | memset (loc, 0, sizeof (*loc)); | |
4344 | ||
e049a4b5 | 4345 | loc->owner = bpt; |
511a6cd4 | 4346 | loc->cond = NULL; |
0d381245 VP |
4347 | loc->shlib_disabled = 0; |
4348 | loc->enabled = 1; | |
e049a4b5 | 4349 | |
39d61571 | 4350 | switch (bpt->type) |
e049a4b5 DJ |
4351 | { |
4352 | case bp_breakpoint: | |
1042e4c0 | 4353 | case bp_tracepoint: |
e049a4b5 DJ |
4354 | case bp_until: |
4355 | case bp_finish: | |
4356 | case bp_longjmp: | |
4357 | case bp_longjmp_resume: | |
4358 | case bp_step_resume: | |
e049a4b5 DJ |
4359 | case bp_watchpoint_scope: |
4360 | case bp_call_dummy: | |
4361 | case bp_shlib_event: | |
4362 | case bp_thread_event: | |
4363 | case bp_overlay_event: | |
0fd8e87f | 4364 | case bp_longjmp_master: |
e049a4b5 DJ |
4365 | loc->loc_type = bp_loc_software_breakpoint; |
4366 | break; | |
4367 | case bp_hardware_breakpoint: | |
4368 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4369 | break; | |
4370 | case bp_hardware_watchpoint: | |
4371 | case bp_read_watchpoint: | |
4372 | case bp_access_watchpoint: | |
4373 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4374 | break; | |
4375 | case bp_watchpoint: | |
ce78b96d | 4376 | case bp_catchpoint: |
e049a4b5 DJ |
4377 | loc->loc_type = bp_loc_other; |
4378 | break; | |
4379 | default: | |
e2e0b3e5 | 4380 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4381 | } |
4382 | ||
7cc221ef DJ |
4383 | return loc; |
4384 | } | |
4385 | ||
fe3f5fa8 VP |
4386 | static void free_bp_location (struct bp_location *loc) |
4387 | { | |
4388 | if (loc->cond) | |
4389 | xfree (loc->cond); | |
74960c60 VP |
4390 | |
4391 | if (loc->function_name) | |
4392 | xfree (loc->function_name); | |
4393 | ||
fe3f5fa8 VP |
4394 | xfree (loc); |
4395 | } | |
4396 | ||
0d381245 VP |
4397 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4398 | that has type BPTYPE and has no locations as yet. */ | |
c906108c | 4399 | |
c40e75cd | 4400 | static struct breakpoint * |
a6d9a66e UW |
4401 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4402 | enum bptype bptype) | |
c906108c | 4403 | { |
52f0bd74 | 4404 | struct breakpoint *b, *b1; |
c906108c SS |
4405 | |
4406 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4407 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4408 | |
4d28f7a8 | 4409 | b->type = bptype; |
a6d9a66e | 4410 | b->gdbarch = gdbarch; |
c906108c SS |
4411 | b->language = current_language->la_language; |
4412 | b->input_radix = input_radix; | |
4413 | b->thread = -1; | |
b5de0fa7 | 4414 | b->enable_state = bp_enabled; |
c906108c SS |
4415 | b->next = 0; |
4416 | b->silent = 0; | |
4417 | b->ignore_count = 0; | |
4418 | b->commands = NULL; | |
818dd999 | 4419 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4420 | b->forked_inferior_pid = null_ptid; |
c906108c | 4421 | b->exec_pathname = NULL; |
3086aeae | 4422 | b->ops = NULL; |
0d381245 | 4423 | b->condition_not_parsed = 0; |
c906108c SS |
4424 | |
4425 | /* Add this breakpoint to the end of the chain | |
4426 | so that a list of breakpoints will come out in order | |
4427 | of increasing numbers. */ | |
4428 | ||
4429 | b1 = breakpoint_chain; | |
4430 | if (b1 == 0) | |
4431 | breakpoint_chain = b; | |
4432 | else | |
4433 | { | |
4434 | while (b1->next) | |
4435 | b1 = b1->next; | |
4436 | b1->next = b; | |
4437 | } | |
0d381245 VP |
4438 | return b; |
4439 | } | |
4440 | ||
4441 | /* Initialize loc->function_name. */ | |
4442 | static void | |
4443 | set_breakpoint_location_function (struct bp_location *loc) | |
4444 | { | |
4445 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4446 | || loc->owner->type == bp_hardware_breakpoint |
4447 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4448 | { |
4449 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4450 | NULL, NULL); | |
4451 | if (loc->function_name) | |
4452 | loc->function_name = xstrdup (loc->function_name); | |
4453 | } | |
4454 | } | |
4455 | ||
a6d9a66e UW |
4456 | /* Attempt to determine architecture of location identified by SAL. */ |
4457 | static struct gdbarch * | |
4458 | get_sal_arch (struct symtab_and_line sal) | |
4459 | { | |
4460 | if (sal.section) | |
4461 | return get_objfile_arch (sal.section->objfile); | |
4462 | if (sal.symtab) | |
4463 | return get_objfile_arch (sal.symtab->objfile); | |
4464 | ||
4465 | return NULL; | |
4466 | } | |
4467 | ||
0d381245 VP |
4468 | /* set_raw_breakpoint is a low level routine for allocating and |
4469 | partially initializing a breakpoint of type BPTYPE. The newly | |
4470 | created breakpoint's address, section, source file name, and line | |
4471 | number are provided by SAL. The newly created and partially | |
4472 | initialized breakpoint is added to the breakpoint chain and | |
4473 | is also returned as the value of this function. | |
4474 | ||
4475 | It is expected that the caller will complete the initialization of | |
4476 | the newly created breakpoint struct as well as output any status | |
4477 | information regarding the creation of a new breakpoint. In | |
4478 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4479 | number! Care should be taken to not allow an error to occur | |
4480 | prior to completing the initialization of the breakpoint. If this | |
4481 | should happen, a bogus breakpoint will be left on the chain. */ | |
4482 | ||
a6d9a66e UW |
4483 | static struct breakpoint * |
4484 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
4485 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4486 | { |
a6d9a66e | 4487 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4488 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4489 | struct gdbarch *loc_gdbarch; |
4490 | ||
4491 | loc_gdbarch = get_sal_arch (sal); | |
4492 | if (!loc_gdbarch) | |
4493 | loc_gdbarch = b->gdbarch; | |
0d381245 VP |
4494 | |
4495 | /* Adjust the breakpoint's address prior to allocating a location. | |
4496 | Once we call allocate_bp_location(), that mostly uninitialized | |
4497 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4498 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4499 | not want its scan of the location chain to find a breakpoint and |
4500 | location that's only been partially initialized. */ | |
a6d9a66e | 4501 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4502 | |
39d61571 | 4503 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4504 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4505 | b->loc->requested_address = sal.pc; |
4506 | b->loc->address = adjusted_address; | |
4507 | ||
4508 | if (sal.symtab == NULL) | |
4509 | b->source_file = NULL; | |
4510 | else | |
1b36a34b | 4511 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4512 | b->loc->section = sal.section; |
4513 | b->line_number = sal.line; | |
4514 | ||
4515 | set_breakpoint_location_function (b->loc); | |
c906108c | 4516 | |
c906108c SS |
4517 | breakpoints_changed (); |
4518 | ||
4519 | return b; | |
4520 | } | |
4521 | ||
c2c6d25f JM |
4522 | |
4523 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4524 | instruction, hard-wired into the inferior's code. */ | |
4525 | void | |
4526 | make_breakpoint_permanent (struct breakpoint *b) | |
4527 | { | |
0d381245 | 4528 | struct bp_location *bl; |
b5de0fa7 | 4529 | b->enable_state = bp_permanent; |
c2c6d25f | 4530 | |
0d381245 VP |
4531 | /* By definition, permanent breakpoints are already present in the code. |
4532 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4533 | is called in just one place, so it's hard to say if it's reasonable | |
4534 | to have permanent breakpoint with multiple locations or not, | |
4535 | but it's easy to implmement. */ | |
4536 | for (bl = b->loc; bl; bl = bl->next) | |
4537 | bl->inserted = 1; | |
c2c6d25f JM |
4538 | } |
4539 | ||
53a5351d | 4540 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4541 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4542 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4543 | ||
4544 | void | |
0fd8e87f | 4545 | set_longjmp_breakpoint (int thread) |
c906108c | 4546 | { |
0fd8e87f UW |
4547 | struct breakpoint *b, *temp; |
4548 | ||
4549 | /* To avoid having to rescan all objfile symbols at every step, | |
4550 | we maintain a list of continually-inserted but always disabled | |
4551 | longjmp "master" breakpoints. Here, we simply create momentary | |
4552 | clones of those and enable them for the requested thread. */ | |
4553 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4554 | if (b->type == bp_longjmp_master) | |
4555 | { | |
4556 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4557 | clone->type = bp_longjmp; | |
4558 | clone->thread = thread; | |
4559 | } | |
c906108c SS |
4560 | } |
4561 | ||
611c83ae | 4562 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4563 | void |
611c83ae | 4564 | delete_longjmp_breakpoint (int thread) |
c906108c | 4565 | { |
611c83ae | 4566 | struct breakpoint *b, *temp; |
c906108c | 4567 | |
611c83ae PA |
4568 | ALL_BREAKPOINTS_SAFE (b, temp) |
4569 | if (b->type == bp_longjmp) | |
4570 | { | |
4571 | if (b->thread == thread) | |
4572 | delete_breakpoint (b); | |
4573 | } | |
c906108c SS |
4574 | } |
4575 | ||
1900040c MS |
4576 | void |
4577 | enable_overlay_breakpoints (void) | |
4578 | { | |
52f0bd74 | 4579 | struct breakpoint *b; |
1900040c MS |
4580 | |
4581 | ALL_BREAKPOINTS (b) | |
4582 | if (b->type == bp_overlay_event) | |
4583 | { | |
4584 | b->enable_state = bp_enabled; | |
b60e7edf | 4585 | update_global_location_list (1); |
c02f5703 | 4586 | overlay_events_enabled = 1; |
1900040c MS |
4587 | } |
4588 | } | |
4589 | ||
4590 | void | |
4591 | disable_overlay_breakpoints (void) | |
4592 | { | |
52f0bd74 | 4593 | struct breakpoint *b; |
1900040c MS |
4594 | |
4595 | ALL_BREAKPOINTS (b) | |
4596 | if (b->type == bp_overlay_event) | |
4597 | { | |
4598 | b->enable_state = bp_disabled; | |
b60e7edf | 4599 | update_global_location_list (0); |
c02f5703 | 4600 | overlay_events_enabled = 0; |
1900040c MS |
4601 | } |
4602 | } | |
4603 | ||
c4093a6a | 4604 | struct breakpoint * |
a6d9a66e | 4605 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4606 | { |
4607 | struct breakpoint *b; | |
c4093a6a | 4608 | |
a6d9a66e | 4609 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4610 | |
b5de0fa7 | 4611 | b->enable_state = bp_enabled; |
c4093a6a | 4612 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4613 | b->addr_string |
4614 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4615 | |
b60e7edf | 4616 | update_global_location_list_nothrow (1); |
74960c60 | 4617 | |
c4093a6a JM |
4618 | return b; |
4619 | } | |
4620 | ||
4621 | void | |
4622 | remove_thread_event_breakpoints (void) | |
4623 | { | |
4624 | struct breakpoint *b, *temp; | |
4625 | ||
4626 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4627 | if (b->type == bp_thread_event) | |
4628 | delete_breakpoint (b); | |
4629 | } | |
4630 | ||
0101ce28 JJ |
4631 | struct captured_parse_breakpoint_args |
4632 | { | |
4633 | char **arg_p; | |
4634 | struct symtabs_and_lines *sals_p; | |
4635 | char ***addr_string_p; | |
4636 | int *not_found_ptr; | |
4637 | }; | |
4638 | ||
4639 | struct lang_and_radix | |
4640 | { | |
4641 | enum language lang; | |
4642 | int radix; | |
4643 | }; | |
4644 | ||
0101ce28 | 4645 | |
cae688ec JJ |
4646 | void |
4647 | remove_solib_event_breakpoints (void) | |
4648 | { | |
4649 | struct breakpoint *b, *temp; | |
4650 | ||
4651 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4652 | if (b->type == bp_shlib_event) | |
4653 | delete_breakpoint (b); | |
4654 | } | |
4655 | ||
4656 | struct breakpoint * | |
a6d9a66e | 4657 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4658 | { |
4659 | struct breakpoint *b; | |
4660 | ||
a6d9a66e | 4661 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4662 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4663 | return b; |
4664 | } | |
4665 | ||
4666 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4667 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4668 | ||
4669 | void | |
cb851954 | 4670 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4671 | { |
0d381245 | 4672 | struct bp_location *loc; |
cae688ec | 4673 | |
0d381245 | 4674 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4675 | { |
0d381245 VP |
4676 | struct breakpoint *b = loc->owner; |
4677 | /* We apply the check to all breakpoints, including disabled | |
4678 | for those with loc->duplicate set. This is so that when breakpoint | |
4679 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4680 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4681 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4682 | if (((b->type == bp_breakpoint) |
4683 | || (b->type == bp_hardware_breakpoint) | |
4684 | || (b->type == bp_tracepoint)) | |
0d381245 | 4685 | && !loc->shlib_disabled |
a77053c2 | 4686 | #ifdef PC_SOLIB |
0d381245 | 4687 | && PC_SOLIB (loc->address) |
a77053c2 | 4688 | #else |
f5c9a895 | 4689 | && solib_name_from_address (loc->address) |
a77053c2 MK |
4690 | #endif |
4691 | ) | |
0d381245 VP |
4692 | { |
4693 | loc->shlib_disabled = 1; | |
4694 | } | |
cae688ec JJ |
4695 | } |
4696 | } | |
4697 | ||
84acb35a JJ |
4698 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4699 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4700 | ||
75149521 | 4701 | static void |
84acb35a JJ |
4702 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4703 | { | |
0d381245 | 4704 | struct bp_location *loc; |
84acb35a JJ |
4705 | int disabled_shlib_breaks = 0; |
4706 | ||
c86cf029 VP |
4707 | /* SunOS a.out shared libraries are always mapped, so do not |
4708 | disable breakpoints; they will only be reported as unloaded | |
4709 | through clear_solib when GDB discards its shared library | |
4710 | list. See clear_solib for more information. */ | |
4711 | if (exec_bfd != NULL | |
4712 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
4713 | return; | |
4714 | ||
0d381245 | 4715 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4716 | { |
0d381245 VP |
4717 | struct breakpoint *b = loc->owner; |
4718 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4719 | || loc->loc_type == bp_loc_software_breakpoint) | |
e2dd7057 PP |
4720 | && !loc->shlib_disabled |
4721 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
4722 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 4723 | { |
e2dd7057 PP |
4724 | loc->shlib_disabled = 1; |
4725 | /* At this point, we cannot rely on remove_breakpoint | |
4726 | succeeding so we must mark the breakpoint as not inserted | |
4727 | to prevent future errors occurring in remove_breakpoints. */ | |
4728 | loc->inserted = 0; | |
4729 | if (!disabled_shlib_breaks) | |
4730 | { | |
4731 | target_terminal_ours_for_output (); | |
4732 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
4733 | solib->so_name); | |
84acb35a | 4734 | } |
e2dd7057 | 4735 | disabled_shlib_breaks = 1; |
84acb35a JJ |
4736 | } |
4737 | } | |
84acb35a JJ |
4738 | } |
4739 | ||
ce78b96d JB |
4740 | /* FORK & VFORK catchpoints. */ |
4741 | ||
4742 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4743 | ||
c906108c | 4744 | static void |
ce78b96d JB |
4745 | insert_catch_fork (struct breakpoint *b) |
4746 | { | |
4747 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4748 | } | |
4749 | ||
4750 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4751 | ||
4752 | static int | |
4753 | remove_catch_fork (struct breakpoint *b) | |
4754 | { | |
4755 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4756 | } | |
4757 | ||
4758 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4759 | catchpoints. */ | |
4760 | ||
4761 | static int | |
4762 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4763 | { | |
4764 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4765 | } | |
4766 | ||
4767 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4768 | ||
4769 | static enum print_stop_action | |
4770 | print_it_catch_fork (struct breakpoint *b) | |
4771 | { | |
4772 | annotate_catchpoint (b->number); | |
4773 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4774 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4775 | return PRINT_SRC_AND_LOC; | |
4776 | } | |
4777 | ||
4778 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4779 | ||
4780 | static void | |
a6d9a66e | 4781 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4782 | { |
79a45b7d TT |
4783 | struct value_print_options opts; |
4784 | ||
4785 | get_user_print_options (&opts); | |
4786 | ||
ce78b96d JB |
4787 | /* Field 4, the address, is omitted (which makes the columns |
4788 | not line up too nicely with the headers, but the effect | |
4789 | is relatively readable). */ | |
79a45b7d | 4790 | if (opts.addressprint) |
ce78b96d JB |
4791 | ui_out_field_skip (uiout, "addr"); |
4792 | annotate_field (5); | |
4793 | ui_out_text (uiout, "fork"); | |
4794 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4795 | { | |
4796 | ui_out_text (uiout, ", process "); | |
4797 | ui_out_field_int (uiout, "what", | |
4798 | ptid_get_pid (b->forked_inferior_pid)); | |
4799 | ui_out_spaces (uiout, 1); | |
4800 | } | |
4801 | } | |
4802 | ||
4803 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4804 | catchpoints. */ | |
4805 | ||
4806 | static void | |
4807 | print_mention_catch_fork (struct breakpoint *b) | |
4808 | { | |
4809 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4810 | } | |
4811 | ||
4812 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4813 | ||
4814 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4815 | { | |
4816 | insert_catch_fork, | |
4817 | remove_catch_fork, | |
4818 | breakpoint_hit_catch_fork, | |
4819 | print_it_catch_fork, | |
4820 | print_one_catch_fork, | |
4821 | print_mention_catch_fork | |
4822 | }; | |
4823 | ||
4824 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4825 | ||
4826 | static void | |
4827 | insert_catch_vfork (struct breakpoint *b) | |
4828 | { | |
4829 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4830 | } | |
4831 | ||
4832 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4833 | ||
4834 | static int | |
4835 | remove_catch_vfork (struct breakpoint *b) | |
4836 | { | |
4837 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4838 | } | |
4839 | ||
4840 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4841 | catchpoints. */ | |
4842 | ||
4843 | static int | |
4844 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4845 | { | |
4846 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4847 | } | |
4848 | ||
4849 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4850 | ||
4851 | static enum print_stop_action | |
4852 | print_it_catch_vfork (struct breakpoint *b) | |
4853 | { | |
4854 | annotate_catchpoint (b->number); | |
4855 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4856 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4857 | return PRINT_SRC_AND_LOC; | |
4858 | } | |
4859 | ||
4860 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4861 | ||
4862 | static void | |
a6d9a66e | 4863 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4864 | { |
79a45b7d TT |
4865 | struct value_print_options opts; |
4866 | ||
4867 | get_user_print_options (&opts); | |
ce78b96d JB |
4868 | /* Field 4, the address, is omitted (which makes the columns |
4869 | not line up too nicely with the headers, but the effect | |
4870 | is relatively readable). */ | |
79a45b7d | 4871 | if (opts.addressprint) |
ce78b96d JB |
4872 | ui_out_field_skip (uiout, "addr"); |
4873 | annotate_field (5); | |
4874 | ui_out_text (uiout, "vfork"); | |
4875 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4876 | { | |
4877 | ui_out_text (uiout, ", process "); | |
4878 | ui_out_field_int (uiout, "what", | |
4879 | ptid_get_pid (b->forked_inferior_pid)); | |
4880 | ui_out_spaces (uiout, 1); | |
4881 | } | |
4882 | } | |
4883 | ||
4884 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4885 | catchpoints. */ | |
4886 | ||
4887 | static void | |
4888 | print_mention_catch_vfork (struct breakpoint *b) | |
4889 | { | |
4890 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4891 | } | |
4892 | ||
4893 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4894 | ||
4895 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4896 | { | |
4897 | insert_catch_vfork, | |
4898 | remove_catch_vfork, | |
4899 | breakpoint_hit_catch_vfork, | |
4900 | print_it_catch_vfork, | |
4901 | print_one_catch_vfork, | |
4902 | print_mention_catch_vfork | |
4903 | }; | |
4904 | ||
4905 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4906 | ||
4907 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4908 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4909 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4910 | to the catchpoint. */ | |
4911 | ||
4912 | static struct breakpoint * | |
a6d9a66e UW |
4913 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
4914 | char *cond_string, struct breakpoint_ops *ops) | |
c906108c | 4915 | { |
c5aa993b JM |
4916 | struct symtab_and_line sal; |
4917 | struct breakpoint *b; | |
c5aa993b | 4918 | |
fe39c653 | 4919 | init_sal (&sal); |
c906108c SS |
4920 | sal.pc = 0; |
4921 | sal.symtab = NULL; | |
4922 | sal.line = 0; | |
c5aa993b | 4923 | |
a6d9a66e | 4924 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
4925 | set_breakpoint_count (breakpoint_count + 1); |
4926 | b->number = breakpoint_count; | |
ce78b96d | 4927 | |
1b36a34b | 4928 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 4929 | b->thread = -1; |
c906108c | 4930 | b->addr_string = NULL; |
b5de0fa7 EZ |
4931 | b->enable_state = bp_enabled; |
4932 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4933 | b->ops = ops; |
c5aa993b | 4934 | |
c906108c | 4935 | mention (b); |
ce78b96d | 4936 | update_global_location_list (1); |
c906108c | 4937 | |
ce78b96d | 4938 | return b; |
c906108c | 4939 | } |
c5aa993b | 4940 | |
9b70b993 | 4941 | static void |
a6d9a66e UW |
4942 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
4943 | int tempflag, char *cond_string, | |
ce78b96d | 4944 | struct breakpoint_ops *ops) |
c906108c | 4945 | { |
a6d9a66e UW |
4946 | struct breakpoint *b |
4947 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
4948 | |
4949 | /* FIXME: We should put this information in a breakpoint private data | |
4950 | area. */ | |
4951 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4952 | } |
4953 | ||
fe798b75 JB |
4954 | /* Exec catchpoints. */ |
4955 | ||
9b70b993 | 4956 | static void |
fe798b75 | 4957 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4958 | { |
fe798b75 JB |
4959 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4960 | } | |
c906108c | 4961 | |
fe798b75 JB |
4962 | static int |
4963 | remove_catch_exec (struct breakpoint *b) | |
4964 | { | |
4965 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
4966 | } | |
c906108c | 4967 | |
fe798b75 JB |
4968 | static int |
4969 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
4970 | { | |
4971 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
4972 | } | |
c906108c | 4973 | |
fe798b75 JB |
4974 | static enum print_stop_action |
4975 | print_it_catch_exec (struct breakpoint *b) | |
4976 | { | |
4977 | annotate_catchpoint (b->number); | |
4978 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
4979 | b->exec_pathname); | |
4980 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
4981 | } |
4982 | ||
fe798b75 | 4983 | static void |
a6d9a66e | 4984 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
4985 | { |
4986 | struct value_print_options opts; | |
4987 | ||
4988 | get_user_print_options (&opts); | |
4989 | ||
4990 | /* Field 4, the address, is omitted (which makes the columns | |
4991 | not line up too nicely with the headers, but the effect | |
4992 | is relatively readable). */ | |
4993 | if (opts.addressprint) | |
4994 | ui_out_field_skip (uiout, "addr"); | |
4995 | annotate_field (5); | |
4996 | ui_out_text (uiout, "exec"); | |
4997 | if (b->exec_pathname != NULL) | |
4998 | { | |
4999 | ui_out_text (uiout, ", program \""); | |
5000 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5001 | ui_out_text (uiout, "\" "); | |
5002 | } | |
5003 | } | |
5004 | ||
5005 | static void | |
5006 | print_mention_catch_exec (struct breakpoint *b) | |
5007 | { | |
5008 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5009 | } | |
5010 | ||
5011 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5012 | { | |
5013 | insert_catch_exec, | |
5014 | remove_catch_exec, | |
5015 | breakpoint_hit_catch_exec, | |
5016 | print_it_catch_exec, | |
5017 | print_one_catch_exec, | |
5018 | print_mention_catch_exec | |
5019 | }; | |
5020 | ||
c906108c | 5021 | static int |
fba45db2 | 5022 | hw_breakpoint_used_count (void) |
c906108c | 5023 | { |
52f0bd74 | 5024 | struct breakpoint *b; |
c906108c SS |
5025 | int i = 0; |
5026 | ||
5027 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5028 | { |
d6b74ac4 | 5029 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5030 | i++; |
5031 | } | |
c906108c SS |
5032 | |
5033 | return i; | |
5034 | } | |
5035 | ||
5036 | static int | |
fba45db2 | 5037 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5038 | { |
52f0bd74 | 5039 | struct breakpoint *b; |
c906108c SS |
5040 | int i = 0; |
5041 | ||
5042 | *other_type_used = 0; | |
5043 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5044 | { |
468d015d | 5045 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5046 | { |
5047 | if (b->type == type) | |
5048 | i++; | |
059fb39f PM |
5049 | else if ((b->type == bp_hardware_watchpoint |
5050 | || b->type == bp_read_watchpoint | |
5051 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5052 | *other_type_used = 1; |
5053 | } | |
5054 | } | |
c906108c SS |
5055 | return i; |
5056 | } | |
5057 | ||
c906108c | 5058 | void |
fba45db2 | 5059 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5060 | { |
c5aa993b | 5061 | struct breakpoint *b; |
c906108c SS |
5062 | |
5063 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5064 | { |
5065 | if (((b->type == bp_watchpoint) | |
5066 | || (b->type == bp_hardware_watchpoint) | |
5067 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5068 | || (b->type == bp_access_watchpoint)) |
468d015d | 5069 | && breakpoint_enabled (b)) |
c5aa993b | 5070 | { |
b5de0fa7 | 5071 | b->enable_state = bp_call_disabled; |
b60e7edf | 5072 | update_global_location_list (0); |
c5aa993b JM |
5073 | } |
5074 | } | |
c906108c SS |
5075 | } |
5076 | ||
5077 | void | |
fba45db2 | 5078 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5079 | { |
c5aa993b | 5080 | struct breakpoint *b; |
c906108c SS |
5081 | |
5082 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5083 | { |
5084 | if (((b->type == bp_watchpoint) | |
5085 | || (b->type == bp_hardware_watchpoint) | |
5086 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5087 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5088 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5089 | { |
b5de0fa7 | 5090 | b->enable_state = bp_enabled; |
b60e7edf | 5091 | update_global_location_list (1); |
c5aa993b JM |
5092 | } |
5093 | } | |
c906108c SS |
5094 | } |
5095 | ||
5096 | ||
5097 | /* Set a breakpoint that will evaporate an end of command | |
5098 | at address specified by SAL. | |
5099 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5100 | ||
5101 | struct breakpoint * | |
a6d9a66e UW |
5102 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5103 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5104 | { |
52f0bd74 | 5105 | struct breakpoint *b; |
edb3359d DJ |
5106 | |
5107 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5108 | one. */ | |
5109 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5110 | ||
a6d9a66e | 5111 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5112 | b->enable_state = bp_enabled; |
5113 | b->disposition = disp_donttouch; | |
818dd999 | 5114 | b->frame_id = frame_id; |
c906108c SS |
5115 | |
5116 | /* If we're debugging a multi-threaded program, then we | |
5117 | want momentary breakpoints to be active in only a | |
5118 | single thread of control. */ | |
39f77062 KB |
5119 | if (in_thread_list (inferior_ptid)) |
5120 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5121 | |
b60e7edf | 5122 | update_global_location_list_nothrow (1); |
74960c60 | 5123 | |
c906108c SS |
5124 | return b; |
5125 | } | |
611c83ae | 5126 | |
e58b0e63 PA |
5127 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5128 | ORIG is NULL. */ | |
5129 | ||
5130 | struct breakpoint * | |
5131 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5132 | { | |
5133 | struct breakpoint *copy; | |
5134 | ||
5135 | /* If there's nothing to clone, then return nothing. */ | |
5136 | if (orig == NULL) | |
5137 | return NULL; | |
5138 | ||
a6d9a66e | 5139 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5140 | copy->loc = allocate_bp_location (copy); |
5141 | set_breakpoint_location_function (copy->loc); | |
5142 | ||
a6d9a66e | 5143 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5144 | copy->loc->requested_address = orig->loc->requested_address; |
5145 | copy->loc->address = orig->loc->address; | |
5146 | copy->loc->section = orig->loc->section; | |
5147 | ||
5148 | if (orig->source_file == NULL) | |
5149 | copy->source_file = NULL; | |
5150 | else | |
5151 | copy->source_file = xstrdup (orig->source_file); | |
5152 | ||
5153 | copy->line_number = orig->line_number; | |
5154 | copy->frame_id = orig->frame_id; | |
5155 | copy->thread = orig->thread; | |
5156 | ||
5157 | copy->enable_state = bp_enabled; | |
5158 | copy->disposition = disp_donttouch; | |
5159 | copy->number = internal_breakpoint_number--; | |
5160 | ||
5161 | update_global_location_list_nothrow (0); | |
5162 | return copy; | |
5163 | } | |
5164 | ||
611c83ae | 5165 | struct breakpoint * |
a6d9a66e UW |
5166 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5167 | enum bptype type) | |
611c83ae PA |
5168 | { |
5169 | struct symtab_and_line sal; | |
5170 | ||
5171 | sal = find_pc_line (pc, 0); | |
5172 | sal.pc = pc; | |
5173 | sal.section = find_pc_overlay (pc); | |
5174 | sal.explicit_pc = 1; | |
5175 | ||
a6d9a66e | 5176 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5177 | } |
c906108c | 5178 | \f |
c5aa993b | 5179 | |
c906108c SS |
5180 | /* Tell the user we have just set a breakpoint B. */ |
5181 | ||
5182 | static void | |
fba45db2 | 5183 | mention (struct breakpoint *b) |
c906108c SS |
5184 | { |
5185 | int say_where = 0; | |
fa8a61dc | 5186 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5187 | struct value_print_options opts; |
5188 | ||
5189 | get_user_print_options (&opts); | |
8b93c638 | 5190 | |
9a4105ab AC |
5191 | /* FIXME: This is misplaced; mention() is called by things (like |
5192 | hitting a watchpoint) other than breakpoint creation. It should | |
5193 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5194 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5195 | observer_notify_breakpoint_created (b->number); |
c906108c | 5196 | |
3086aeae DJ |
5197 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5198 | b->ops->print_mention (b); | |
5199 | else | |
5200 | switch (b->type) | |
5201 | { | |
5202 | case bp_none: | |
a3f17187 | 5203 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5204 | break; |
5205 | case bp_watchpoint: | |
5206 | ui_out_text (uiout, "Watchpoint "); | |
5207 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5208 | ui_out_field_int (uiout, "number", b->number); | |
5209 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5210 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5211 | do_cleanups (ui_out_chain); |
5212 | break; | |
5213 | case bp_hardware_watchpoint: | |
5214 | ui_out_text (uiout, "Hardware watchpoint "); | |
5215 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5216 | ui_out_field_int (uiout, "number", b->number); | |
5217 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5218 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5219 | do_cleanups (ui_out_chain); |
5220 | break; | |
5221 | case bp_read_watchpoint: | |
5222 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5223 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5224 | ui_out_field_int (uiout, "number", b->number); | |
5225 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5226 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5227 | do_cleanups (ui_out_chain); |
5228 | break; | |
5229 | case bp_access_watchpoint: | |
5230 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5231 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5232 | ui_out_field_int (uiout, "number", b->number); | |
5233 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5234 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5235 | do_cleanups (ui_out_chain); |
5236 | break; | |
5237 | case bp_breakpoint: | |
5238 | if (ui_out_is_mi_like_p (uiout)) | |
5239 | { | |
5240 | say_where = 0; | |
5241 | break; | |
5242 | } | |
2cec12e5 AR |
5243 | if (b->disposition == disp_del) |
5244 | printf_filtered (_("Temporary breakpoint")); | |
5245 | else | |
5246 | printf_filtered (_("Breakpoint")); | |
5247 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5248 | say_where = 1; |
5249 | break; | |
5250 | case bp_hardware_breakpoint: | |
5251 | if (ui_out_is_mi_like_p (uiout)) | |
5252 | { | |
5253 | say_where = 0; | |
5254 | break; | |
5255 | } | |
a3f17187 | 5256 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5257 | say_where = 1; |
5258 | break; | |
1042e4c0 SS |
5259 | case bp_tracepoint: |
5260 | if (ui_out_is_mi_like_p (uiout)) | |
5261 | { | |
5262 | say_where = 0; | |
5263 | break; | |
5264 | } | |
5265 | printf_filtered (_("Tracepoint")); | |
5266 | printf_filtered (_(" %d"), b->number); | |
5267 | say_where = 1; | |
5268 | break; | |
3086aeae DJ |
5269 | |
5270 | case bp_until: | |
5271 | case bp_finish: | |
5272 | case bp_longjmp: | |
5273 | case bp_longjmp_resume: | |
5274 | case bp_step_resume: | |
3086aeae DJ |
5275 | case bp_call_dummy: |
5276 | case bp_watchpoint_scope: | |
5277 | case bp_shlib_event: | |
5278 | case bp_thread_event: | |
5279 | case bp_overlay_event: | |
0fd8e87f | 5280 | case bp_longjmp_master: |
3086aeae DJ |
5281 | break; |
5282 | } | |
c906108c | 5283 | |
c906108c SS |
5284 | if (say_where) |
5285 | { | |
a3f17187 AC |
5286 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5287 | single string. */ | |
0d381245 | 5288 | if (b->loc == NULL) |
c906108c | 5289 | { |
a3f17187 | 5290 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5291 | } |
5292 | else | |
5293 | { | |
79a45b7d | 5294 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5295 | { |
5296 | printf_filtered (" at "); | |
5af949e3 UW |
5297 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5298 | gdb_stdout); | |
0101ce28 JJ |
5299 | } |
5300 | if (b->source_file) | |
5301 | printf_filtered (": file %s, line %d.", | |
5302 | b->source_file, b->line_number); | |
0d381245 VP |
5303 | |
5304 | if (b->loc->next) | |
5305 | { | |
5306 | struct bp_location *loc = b->loc; | |
5307 | int n = 0; | |
5308 | for (; loc; loc = loc->next) | |
5309 | ++n; | |
5310 | printf_filtered (" (%d locations)", n); | |
5311 | } | |
5312 | ||
c906108c | 5313 | } |
c906108c | 5314 | } |
9dc5e2a9 | 5315 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5316 | return; |
c906108c SS |
5317 | printf_filtered ("\n"); |
5318 | } | |
c906108c | 5319 | \f |
c5aa993b | 5320 | |
0d381245 | 5321 | static struct bp_location * |
39d61571 | 5322 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5323 | const struct symtab_and_line *sal) |
5324 | { | |
5325 | struct bp_location *loc, **tmp; | |
5326 | ||
39d61571 | 5327 | loc = allocate_bp_location (b); |
0d381245 VP |
5328 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5329 | ; | |
5330 | *tmp = loc; | |
a6d9a66e UW |
5331 | loc->gdbarch = get_sal_arch (*sal); |
5332 | if (!loc->gdbarch) | |
5333 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5334 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5335 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5336 | loc->requested_address, b->type); | |
0d381245 VP |
5337 | loc->section = sal->section; |
5338 | ||
5339 | set_breakpoint_location_function (loc); | |
5340 | return loc; | |
5341 | } | |
514f746b AR |
5342 | \f |
5343 | ||
5344 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5345 | return 0 otherwise. */ | |
5346 | ||
5347 | static int | |
5348 | bp_loc_is_permanent (struct bp_location *loc) | |
5349 | { | |
5350 | int len; | |
5351 | CORE_ADDR addr; | |
5352 | const gdb_byte *brk; | |
5353 | gdb_byte *target_mem; | |
939c61fa JK |
5354 | struct cleanup *cleanup; |
5355 | int retval = 0; | |
514f746b AR |
5356 | |
5357 | gdb_assert (loc != NULL); | |
5358 | ||
5359 | addr = loc->address; | |
a6d9a66e | 5360 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 5361 | |
939c61fa JK |
5362 | /* Software breakpoints unsupported? */ |
5363 | if (brk == NULL) | |
5364 | return 0; | |
5365 | ||
514f746b AR |
5366 | target_mem = alloca (len); |
5367 | ||
939c61fa JK |
5368 | /* Enable the automatic memory restoration from breakpoints while |
5369 | we read the memory. Otherwise we could say about our temporary | |
5370 | breakpoints they are permanent. */ | |
5371 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5372 | ||
514f746b AR |
5373 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5374 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5375 | retval = 1; |
514f746b | 5376 | |
939c61fa JK |
5377 | do_cleanups (cleanup); |
5378 | ||
5379 | return retval; | |
514f746b AR |
5380 | } |
5381 | ||
5382 | ||
c3f6f71d | 5383 | |
018d34a4 VP |
5384 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5385 | as textual description of the location, and COND_STRING | |
db107f19 | 5386 | as condition expression. */ |
018d34a4 VP |
5387 | |
5388 | static void | |
a6d9a66e UW |
5389 | create_breakpoint (struct gdbarch *gdbarch, |
5390 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
5391 | char *cond_string, |
5392 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 5393 | int thread, int task, int ignore_count, |
41447f92 | 5394 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 5395 | { |
0d381245 VP |
5396 | struct breakpoint *b = NULL; |
5397 | int i; | |
018d34a4 VP |
5398 | |
5399 | if (type == bp_hardware_breakpoint) | |
5400 | { | |
5401 | int i = hw_breakpoint_used_count (); | |
5402 | int target_resources_ok = | |
d92524f1 | 5403 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
5404 | i + 1, 0); |
5405 | if (target_resources_ok == 0) | |
5406 | error (_("No hardware breakpoint support in the target.")); | |
5407 | else if (target_resources_ok < 0) | |
5408 | error (_("Hardware breakpoints used exceeds limit.")); | |
5409 | } | |
5410 | ||
0d381245 VP |
5411 | for (i = 0; i < sals.nelts; ++i) |
5412 | { | |
5413 | struct symtab_and_line sal = sals.sals[i]; | |
5414 | struct bp_location *loc; | |
5415 | ||
5416 | if (from_tty) | |
5af949e3 UW |
5417 | { |
5418 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
5419 | if (!loc_gdbarch) | |
5420 | loc_gdbarch = gdbarch; | |
5421 | ||
5422 | describe_other_breakpoints (loc_gdbarch, | |
5423 | sal.pc, sal.section, thread); | |
5424 | } | |
0d381245 VP |
5425 | |
5426 | if (i == 0) | |
5427 | { | |
a6d9a66e | 5428 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
5429 | set_breakpoint_count (breakpoint_count + 1); |
5430 | b->number = breakpoint_count; | |
5431 | b->thread = thread; | |
4a306c9a | 5432 | b->task = task; |
018d34a4 | 5433 | |
0d381245 VP |
5434 | b->cond_string = cond_string; |
5435 | b->ignore_count = ignore_count; | |
41447f92 | 5436 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 5437 | b->disposition = disposition; |
018d34a4 | 5438 | |
0d381245 VP |
5439 | loc = b->loc; |
5440 | } | |
5441 | else | |
018d34a4 | 5442 | { |
39d61571 | 5443 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5444 | } |
5445 | ||
514f746b AR |
5446 | if (bp_loc_is_permanent (loc)) |
5447 | make_breakpoint_permanent (b); | |
5448 | ||
0d381245 VP |
5449 | if (b->cond_string) |
5450 | { | |
5451 | char *arg = b->cond_string; | |
d32a6982 | 5452 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5453 | if (*arg) |
db107f19 | 5454 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5455 | } |
0d381245 | 5456 | } |
018d34a4 VP |
5457 | |
5458 | if (addr_string) | |
5459 | b->addr_string = addr_string; | |
5460 | else | |
5461 | /* addr_string has to be used or breakpoint_re_set will delete | |
5462 | me. */ | |
5af949e3 UW |
5463 | b->addr_string |
5464 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 5465 | |
604133b5 | 5466 | b->ops = ops; |
018d34a4 VP |
5467 | mention (b); |
5468 | } | |
5469 | ||
ed0616c6 VP |
5470 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5471 | elements to fill the void space. */ | |
2c0b251b PA |
5472 | static void |
5473 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
5474 | { |
5475 | int i = index_to_remove+1; | |
5476 | int last_index = sal->nelts-1; | |
5477 | ||
5478 | for (;i <= last_index; ++i) | |
5479 | sal->sals[i-1] = sal->sals[i]; | |
5480 | ||
5481 | --(sal->nelts); | |
5482 | } | |
5483 | ||
5484 | /* If appropriate, obtains all sals that correspond | |
5485 | to the same file and line as SAL. This is done | |
5486 | only if SAL does not have explicit PC and has | |
5487 | line and file information. If we got just a single | |
5488 | expanded sal, return the original. | |
5489 | ||
5490 | Otherwise, if SAL.explicit_line is not set, filter out | |
5491 | all sals for which the name of enclosing function | |
5492 | is different from SAL. This makes sure that if we have | |
5493 | breakpoint originally set in template instantiation, say | |
5494 | foo<int>(), we won't expand SAL to locations at the same | |
5495 | line in all existing instantiations of 'foo'. | |
5496 | ||
5497 | */ | |
2c0b251b | 5498 | static struct symtabs_and_lines |
ed0616c6 VP |
5499 | expand_line_sal_maybe (struct symtab_and_line sal) |
5500 | { | |
5501 | struct symtabs_and_lines expanded; | |
5502 | CORE_ADDR original_pc = sal.pc; | |
5503 | char *original_function = NULL; | |
5504 | int found; | |
5505 | int i; | |
5506 | ||
5507 | /* If we have explicit pc, don't expand. | |
5508 | If we have no line number, we can't expand. */ | |
5509 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5510 | { | |
5511 | expanded.nelts = 1; | |
5512 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5513 | expanded.sals[0] = sal; | |
5514 | return expanded; | |
5515 | } | |
5516 | ||
5517 | sal.pc = 0; | |
5518 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5519 | ||
5520 | expanded = expand_line_sal (sal); | |
5521 | if (expanded.nelts == 1) | |
5522 | { | |
5523 | /* We had one sal, we got one sal. Without futher | |
5524 | processing, just return the original sal. */ | |
5525 | xfree (expanded.sals); | |
5526 | expanded.nelts = 1; | |
5527 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5528 | sal.pc = original_pc; | |
5529 | expanded.sals[0] = sal; | |
5530 | return expanded; | |
5531 | } | |
5532 | ||
5533 | if (!sal.explicit_line) | |
5534 | { | |
5535 | CORE_ADDR func_addr, func_end; | |
5536 | for (i = 0; i < expanded.nelts; ++i) | |
5537 | { | |
5538 | CORE_ADDR pc = expanded.sals[i].pc; | |
5539 | char *this_function; | |
5540 | if (find_pc_partial_function (pc, &this_function, | |
5541 | &func_addr, &func_end)) | |
5542 | { | |
059fb39f PM |
5543 | if (this_function |
5544 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
5545 | { |
5546 | remove_sal (&expanded, i); | |
5547 | --i; | |
5548 | } | |
5549 | else if (func_addr == pc) | |
5550 | { | |
5551 | /* We're at beginning of a function, and should | |
5552 | skip prologue. */ | |
5553 | struct symbol *sym = find_pc_function (pc); | |
5554 | if (sym) | |
5555 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5556 | else | |
d80b854b UW |
5557 | { |
5558 | /* Since find_pc_partial_function returned true, | |
5559 | we should really always find the section here. */ | |
5560 | struct obj_section *section = find_pc_section (pc); | |
5561 | if (section) | |
5562 | { | |
5563 | struct gdbarch *gdbarch | |
5564 | = get_objfile_arch (section->objfile); | |
5565 | expanded.sals[i].pc | |
5566 | = gdbarch_skip_prologue (gdbarch, pc); | |
5567 | } | |
5568 | } | |
ed0616c6 VP |
5569 | } |
5570 | } | |
5571 | } | |
5572 | } | |
3daf8fe5 JG |
5573 | else |
5574 | { | |
5575 | for (i = 0; i < expanded.nelts; ++i) | |
5576 | { | |
5577 | /* If this SAL corresponds to a breakpoint inserted using a | |
5578 | line number, then skip the function prologue if necessary. */ | |
5579 | skip_prologue_sal (&expanded.sals[i]); | |
5580 | } | |
5581 | } | |
ed0616c6 VP |
5582 | |
5583 | ||
5584 | if (expanded.nelts <= 1) | |
5585 | { | |
5586 | /* This is un ugly workaround. If we get zero | |
5587 | expanded sals then something is really wrong. | |
5588 | Fix that by returnign the original sal. */ | |
5589 | xfree (expanded.sals); | |
5590 | expanded.nelts = 1; | |
5591 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5592 | sal.pc = original_pc; | |
5593 | expanded.sals[0] = sal; | |
5594 | return expanded; | |
5595 | } | |
5596 | ||
5597 | if (original_pc) | |
5598 | { | |
5599 | found = 0; | |
5600 | for (i = 0; i < expanded.nelts; ++i) | |
5601 | if (expanded.sals[i].pc == original_pc) | |
5602 | { | |
5603 | found = 1; | |
5604 | break; | |
5605 | } | |
5606 | gdb_assert (found); | |
5607 | } | |
5608 | ||
5609 | return expanded; | |
5610 | } | |
5611 | ||
018d34a4 VP |
5612 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5613 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5614 | value. COND_STRING, if not NULL, specified the condition to be | |
5615 | used for all breakpoints. Essentially the only case where | |
5616 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5617 | function. In that case, it's still not possible to specify | |
5618 | separate conditions for different overloaded functions, so | |
5619 | we take just a single condition string. | |
5620 | ||
c3f6f71d | 5621 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5622 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5623 | array contents). If the function fails (error() is called), the |
5624 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5625 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5626 | |
5627 | static void | |
a6d9a66e UW |
5628 | create_breakpoints (struct gdbarch *gdbarch, |
5629 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 5630 | char *cond_string, |
c3f6f71d | 5631 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 5632 | int thread, int task, int ignore_count, |
41447f92 VP |
5633 | struct breakpoint_ops *ops, int from_tty, |
5634 | int enabled) | |
c906108c | 5635 | { |
018d34a4 VP |
5636 | int i; |
5637 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5638 | { |
ed0616c6 VP |
5639 | struct symtabs_and_lines expanded = |
5640 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5641 | |
a6d9a66e | 5642 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 5643 | cond_string, type, disposition, |
4a306c9a | 5644 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 5645 | } |
c3f6f71d | 5646 | } |
c906108c | 5647 | |
c3f6f71d JM |
5648 | /* Parse ARG which is assumed to be a SAL specification possibly |
5649 | followed by conditionals. On return, SALS contains an array of SAL | |
5650 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5651 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5652 | |
b9362cc7 | 5653 | static void |
c3f6f71d JM |
5654 | parse_breakpoint_sals (char **address, |
5655 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5656 | char ***addr_string, |
5657 | int *not_found_ptr) | |
c3f6f71d JM |
5658 | { |
5659 | char *addr_start = *address; | |
5660 | *addr_string = NULL; | |
5661 | /* If no arg given, or if first arg is 'if ', use the default | |
5662 | breakpoint. */ | |
5663 | if ((*address) == NULL | |
5664 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5665 | { |
5666 | if (default_breakpoint_valid) | |
5667 | { | |
c3f6f71d | 5668 | struct symtab_and_line sal; |
fe39c653 | 5669 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5670 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5671 | xmalloc (sizeof (struct symtab_and_line)); |
5672 | sal.pc = default_breakpoint_address; | |
5673 | sal.line = default_breakpoint_line; | |
5674 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5675 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
5676 | |
5677 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
5678 | the default_breakpoint_address. So make sure to set | |
5679 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
5680 | sals to include all other instances with the same symtab and line. | |
5681 | */ | |
5682 | sal.explicit_pc = 1; | |
5683 | ||
c3f6f71d JM |
5684 | sals->sals[0] = sal; |
5685 | sals->nelts = 1; | |
c906108c SS |
5686 | } |
5687 | else | |
8a3fe4f8 | 5688 | error (_("No default breakpoint address now.")); |
c906108c SS |
5689 | } |
5690 | else | |
5691 | { | |
c906108c | 5692 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5693 | current_source_symtab (which is decode_line_1's default). This |
5694 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5695 | leaving default_breakpoint_* alone. |
5696 | ObjC: However, don't match an Objective-C method name which | |
5697 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5698 | |
c214a6fd | 5699 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5700 | |
c906108c | 5701 | if (default_breakpoint_valid |
0378c332 | 5702 | && (!cursal.symtab |
1aeae86e AF |
5703 | || ((strchr ("+-", (*address)[0]) != NULL) |
5704 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5705 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5706 | default_breakpoint_line, addr_string, |
5707 | not_found_ptr); | |
c906108c | 5708 | else |
0101ce28 JJ |
5709 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5710 | addr_string, not_found_ptr); | |
c906108c | 5711 | } |
c3f6f71d JM |
5712 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5713 | if (sals->nelts > 0 && *addr_string == NULL) | |
5714 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5715 | if (addr_start != (*address)) | |
c906108c | 5716 | { |
c3f6f71d JM |
5717 | int i; |
5718 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5719 | { |
c3f6f71d JM |
5720 | /* Add the string if not present. */ |
5721 | if ((*addr_string)[i] == NULL) | |
5722 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5723 | } |
5724 | } | |
c3f6f71d | 5725 | } |
c906108c | 5726 | |
c906108c | 5727 | |
c3f6f71d JM |
5728 | /* Convert each SAL into a real PC. Verify that the PC can be |
5729 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5730 | |
b9362cc7 | 5731 | static void |
c3f6f71d JM |
5732 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5733 | char *address) | |
5734 | { | |
5735 | int i; | |
5736 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5737 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5738 | } |
5739 | ||
05ff989b | 5740 | static void |
0101ce28 JJ |
5741 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5742 | { | |
5743 | struct captured_parse_breakpoint_args *args = data; | |
5744 | ||
5745 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5746 | args->not_found_ptr); | |
0101ce28 JJ |
5747 | } |
5748 | ||
018d34a4 VP |
5749 | /* Given TOK, a string specification of condition and thread, as |
5750 | accepted by the 'break' command, extract the condition | |
5751 | string and thread number and set *COND_STRING and *THREAD. | |
5752 | PC identifies the context at which the condition should be parsed. | |
5753 | If no condition is found, *COND_STRING is set to NULL. | |
5754 | If no thread is found, *THREAD is set to -1. */ | |
5755 | static void | |
5756 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 5757 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
5758 | { |
5759 | *cond_string = NULL; | |
5760 | *thread = -1; | |
5761 | while (tok && *tok) | |
5762 | { | |
5763 | char *end_tok; | |
5764 | int toklen; | |
5765 | char *cond_start = NULL; | |
5766 | char *cond_end = NULL; | |
5767 | while (*tok == ' ' || *tok == '\t') | |
5768 | tok++; | |
5769 | ||
5770 | end_tok = tok; | |
5771 | ||
5772 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5773 | end_tok++; | |
5774 | ||
5775 | toklen = end_tok - tok; | |
5776 | ||
5777 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5778 | { | |
f7545552 TT |
5779 | struct expression *expr; |
5780 | ||
018d34a4 | 5781 | tok = cond_start = end_tok + 1; |
f7545552 TT |
5782 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
5783 | xfree (expr); | |
018d34a4 VP |
5784 | cond_end = tok; |
5785 | *cond_string = savestring (cond_start, | |
5786 | cond_end - cond_start); | |
5787 | } | |
5788 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5789 | { | |
5790 | char *tmptok; | |
5791 | ||
5792 | tok = end_tok + 1; | |
5793 | tmptok = tok; | |
5794 | *thread = strtol (tok, &tok, 0); | |
5795 | if (tok == tmptok) | |
5796 | error (_("Junk after thread keyword.")); | |
5797 | if (!valid_thread_id (*thread)) | |
5798 | error (_("Unknown thread %d."), *thread); | |
5799 | } | |
4a306c9a JB |
5800 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
5801 | { | |
5802 | char *tmptok; | |
5803 | ||
5804 | tok = end_tok + 1; | |
5805 | tmptok = tok; | |
5806 | *task = strtol (tok, &tok, 0); | |
5807 | if (tok == tmptok) | |
5808 | error (_("Junk after task keyword.")); | |
5809 | if (!valid_task_id (*task)) | |
5810 | error (_("Unknown task %d\n"), *task); | |
5811 | } | |
018d34a4 VP |
5812 | else |
5813 | error (_("Junk at end of arguments.")); | |
5814 | } | |
5815 | } | |
5816 | ||
72b2ff0e VP |
5817 | /* Set a breakpoint. This function is shared between |
5818 | CLI and MI functions for setting a breakpoint. | |
5819 | This function has two major modes of operations, | |
5820 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5821 | If non-zero, the function will parse arg, extracting | |
5822 | breakpoint location, address and thread. Otherwise, | |
5823 | ARG is just the location of breakpoint, with condition | |
5824 | and thread specified by the COND_STRING and THREAD | |
5825 | parameters. */ | |
0101ce28 | 5826 | |
98deb0da | 5827 | static void |
a6d9a66e UW |
5828 | break_command_really (struct gdbarch *gdbarch, |
5829 | char *arg, char *cond_string, int thread, | |
60c46647 | 5830 | int parse_condition_and_thread, |
1042e4c0 | 5831 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
5832 | int ignore_count, |
5833 | enum auto_boolean pending_break_support, | |
604133b5 | 5834 | struct breakpoint_ops *ops, |
41447f92 VP |
5835 | int from_tty, |
5836 | int enabled) | |
c3f6f71d | 5837 | { |
71fff37b | 5838 | struct gdb_exception e; |
c3f6f71d | 5839 | struct symtabs_and_lines sals; |
0101ce28 | 5840 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5841 | char *copy_arg; |
5842 | char *err_msg; | |
c3f6f71d JM |
5843 | char *addr_start = arg; |
5844 | char **addr_string; | |
5845 | struct cleanup *old_chain; | |
80c99de1 | 5846 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 5847 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5848 | int i; |
0101ce28 | 5849 | int pending = 0; |
0101ce28 | 5850 | int not_found = 0; |
1042e4c0 | 5851 | enum bptype type_wanted; |
4a306c9a | 5852 | int task = 0; |
c3f6f71d | 5853 | |
c3f6f71d JM |
5854 | sals.sals = NULL; |
5855 | sals.nelts = 0; | |
5856 | addr_string = NULL; | |
c3f6f71d | 5857 | |
0101ce28 JJ |
5858 | parse_args.arg_p = &arg; |
5859 | parse_args.sals_p = &sals; | |
5860 | parse_args.addr_string_p = &addr_string; | |
5861 | parse_args.not_found_ptr = ¬_found; | |
5862 | ||
05ff989b AC |
5863 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5864 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5865 | |
5866 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5867 | switch (e.reason) |
0101ce28 | 5868 | { |
05ff989b | 5869 | case RETURN_QUIT: |
98deb0da | 5870 | throw_exception (e); |
05ff989b AC |
5871 | case RETURN_ERROR: |
5872 | switch (e.error) | |
0101ce28 | 5873 | { |
05ff989b | 5874 | case NOT_FOUND_ERROR: |
0101ce28 | 5875 | |
05ff989b AC |
5876 | /* If pending breakpoint support is turned off, throw |
5877 | error. */ | |
fa8d40ab JJ |
5878 | |
5879 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5880 | throw_exception (e); |
5881 | ||
5882 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5883 | |
05ff989b AC |
5884 | /* If pending breakpoint support is auto query and the user |
5885 | selects no, then simply return the error code. */ | |
059fb39f PM |
5886 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
5887 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5888 | return; |
fa8d40ab | 5889 | |
05ff989b AC |
5890 | /* At this point, either the user was queried about setting |
5891 | a pending breakpoint and selected yes, or pending | |
5892 | breakpoint behavior is on and thus a pending breakpoint | |
5893 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5894 | copy_arg = xstrdup (addr_start); |
5895 | addr_string = ©_arg; | |
5896 | sals.nelts = 1; | |
5897 | sals.sals = &pending_sal; | |
5898 | pending_sal.pc = 0; | |
5899 | pending = 1; | |
05ff989b AC |
5900 | break; |
5901 | default: | |
98deb0da | 5902 | throw_exception (e); |
0101ce28 | 5903 | } |
05ff989b AC |
5904 | default: |
5905 | if (!sals.nelts) | |
98deb0da | 5906 | return; |
0101ce28 | 5907 | } |
c3f6f71d JM |
5908 | |
5909 | /* Create a chain of things that always need to be cleaned up. */ | |
5910 | old_chain = make_cleanup (null_cleanup, 0); | |
5911 | ||
0101ce28 JJ |
5912 | if (!pending) |
5913 | { | |
5914 | /* Make sure that all storage allocated to SALS gets freed. */ | |
5915 | make_cleanup (xfree, sals.sals); | |
5916 | ||
5917 | /* Cleanup the addr_string array but not its contents. */ | |
5918 | make_cleanup (xfree, addr_string); | |
5919 | } | |
c3f6f71d | 5920 | |
c3f6f71d JM |
5921 | /* ----------------------------- SNIP ----------------------------- |
5922 | Anything added to the cleanup chain beyond this point is assumed | |
5923 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
5924 | then the memory is not reclaimed. */ |
5925 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
5926 | |
5927 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 5928 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
5929 | for (i = 0; i < sals.nelts; i++) |
5930 | { | |
5931 | if (addr_string[i] != NULL) | |
b8c9b27d | 5932 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
5933 | } |
5934 | ||
5935 | /* Resolve all line numbers to PC's and verify that the addresses | |
5936 | are ok for the target. */ | |
0101ce28 JJ |
5937 | if (!pending) |
5938 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 5939 | |
1042e4c0 SS |
5940 | type_wanted = (traceflag |
5941 | ? bp_tracepoint | |
5942 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
5943 | ||
c3f6f71d JM |
5944 | /* Verify that condition can be parsed, before setting any |
5945 | breakpoints. Allocate a separate condition expression for each | |
5946 | breakpoint. */ | |
0101ce28 | 5947 | if (!pending) |
c3f6f71d | 5948 | { |
2f069f6f | 5949 | if (parse_condition_and_thread) |
72b2ff0e VP |
5950 | { |
5951 | /* Here we only parse 'arg' to separate condition | |
5952 | from thread number, so parsing in context of first | |
5953 | sal is OK. When setting the breakpoint we'll | |
5954 | re-parse it in context of each sal. */ | |
5955 | cond_string = NULL; | |
5956 | thread = -1; | |
4a306c9a JB |
5957 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
5958 | &thread, &task); | |
72b2ff0e VP |
5959 | if (cond_string) |
5960 | make_cleanup (xfree, cond_string); | |
5961 | } | |
2f069f6f | 5962 | else |
72b2ff0e VP |
5963 | { |
5964 | /* Create a private copy of condition string. */ | |
5965 | if (cond_string) | |
5966 | { | |
5967 | cond_string = xstrdup (cond_string); | |
5968 | make_cleanup (xfree, cond_string); | |
5969 | } | |
5970 | } | |
a6d9a66e | 5971 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 5972 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 5973 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 5974 | } |
0101ce28 JJ |
5975 | else |
5976 | { | |
fe3f5fa8 | 5977 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
5978 | struct breakpoint *b; |
5979 | ||
0101ce28 JJ |
5980 | make_cleanup (xfree, copy_arg); |
5981 | ||
a6d9a66e | 5982 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
5983 | set_breakpoint_count (breakpoint_count + 1); |
5984 | b->number = breakpoint_count; | |
72b2ff0e | 5985 | b->thread = -1; |
018d34a4 | 5986 | b->addr_string = addr_string[0]; |
72b2ff0e | 5987 | b->cond_string = NULL; |
0101ce28 | 5988 | b->ignore_count = ignore_count; |
0101ce28 | 5989 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 5990 | b->condition_not_parsed = 1; |
604133b5 | 5991 | b->ops = ops; |
41447f92 | 5992 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
74960c60 | 5993 | |
0101ce28 JJ |
5994 | mention (b); |
5995 | } | |
5996 | ||
c3f6f71d | 5997 | if (sals.nelts > 1) |
8a3fe4f8 AC |
5998 | warning (_("Multiple breakpoints were set.\n" |
5999 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6000 | /* That's it. Discard the cleanups for data inserted into the |
6001 | breakpoint. */ | |
6002 | discard_cleanups (bkpt_chain); | |
6003 | /* But cleanup everything else. */ | |
c3f6f71d | 6004 | do_cleanups (old_chain); |
217dc9e2 | 6005 | |
80c99de1 | 6006 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6007 | update_global_location_list (1); |
c3f6f71d | 6008 | } |
c906108c | 6009 | |
72b2ff0e VP |
6010 | /* Set a breakpoint. |
6011 | ARG is a string describing breakpoint address, | |
6012 | condition, and thread. | |
6013 | FLAG specifies if a breakpoint is hardware on, | |
6014 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6015 | and BP_TEMPFLAG. */ | |
6016 | ||
98deb0da | 6017 | static void |
72b2ff0e | 6018 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6019 | { |
72b2ff0e VP |
6020 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6021 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6022 | |
a6d9a66e UW |
6023 | break_command_really (get_current_arch (), |
6024 | arg, | |
98deb0da | 6025 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6026 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6027 | 0 /* Ignore count */, |
604133b5 AR |
6028 | pending_break_support, |
6029 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6030 | from_tty, |
6031 | 1 /* enabled */); | |
c906108c SS |
6032 | } |
6033 | ||
72b2ff0e | 6034 | |
98deb0da | 6035 | void |
a6d9a66e UW |
6036 | set_breakpoint (struct gdbarch *gdbarch, |
6037 | char *address, char *condition, | |
c3f6f71d | 6038 | int hardwareflag, int tempflag, |
ce43223b | 6039 | int thread, int ignore_count, |
41447f92 | 6040 | int pending, int enabled) |
c3f6f71d | 6041 | { |
a6d9a66e UW |
6042 | break_command_really (gdbarch, |
6043 | address, condition, thread, | |
98deb0da | 6044 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6045 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6046 | ignore_count, |
6047 | pending | |
6048 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6049 | NULL, 0, enabled); |
c3f6f71d JM |
6050 | } |
6051 | ||
6a048695 JB |
6052 | /* Adjust SAL to the first instruction past the function prologue. |
6053 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6054 | the debugging information. explicit_pc and explicit_line are |
6055 | not modified. | |
6a048695 JB |
6056 | |
6057 | If SAL is already past the prologue, then do nothing. */ | |
6058 | ||
6059 | static void | |
6060 | skip_prologue_sal (struct symtab_and_line *sal) | |
6061 | { | |
6062 | struct symbol *sym = find_pc_function (sal->pc); | |
6063 | struct symtab_and_line start_sal; | |
6064 | ||
6065 | if (sym == NULL) | |
6066 | return; | |
6067 | ||
6068 | start_sal = find_function_start_sal (sym, 1); | |
6069 | if (sal->pc < start_sal.pc) | |
3daf8fe5 JG |
6070 | { |
6071 | start_sal.explicit_line = sal->explicit_line; | |
6072 | start_sal.explicit_pc = sal->explicit_pc; | |
6073 | *sal = start_sal; | |
6074 | } | |
6a048695 | 6075 | } |
c3f6f71d | 6076 | |
c906108c SS |
6077 | /* Helper function for break_command_1 and disassemble_command. */ |
6078 | ||
6079 | void | |
fba45db2 | 6080 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6081 | { |
6082 | CORE_ADDR pc; | |
6083 | ||
6084 | if (sal->pc == 0 && sal->symtab != NULL) | |
6085 | { | |
6086 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6087 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6088 | sal->line, sal->symtab->filename); |
6089 | sal->pc = pc; | |
6a048695 JB |
6090 | |
6091 | /* If this SAL corresponds to a breakpoint inserted using | |
6092 | a line number, then skip the function prologue if necessary. */ | |
6093 | if (sal->explicit_line) | |
56ef84b1 TT |
6094 | { |
6095 | /* Preserve the original line number. */ | |
6096 | int saved_line = sal->line; | |
6097 | skip_prologue_sal (sal); | |
6098 | sal->line = saved_line; | |
6099 | } | |
c906108c SS |
6100 | } |
6101 | ||
6102 | if (sal->section == 0 && sal->symtab != NULL) | |
6103 | { | |
6104 | struct blockvector *bv; | |
c5aa993b JM |
6105 | struct block *b; |
6106 | struct symbol *sym; | |
c906108c | 6107 | |
801e3a5b | 6108 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6109 | if (bv != NULL) |
6110 | { | |
7f0df278 | 6111 | sym = block_linkage_function (b); |
c906108c SS |
6112 | if (sym != NULL) |
6113 | { | |
6114 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6115 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6116 | } |
6117 | else | |
6118 | { | |
6119 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6120 | have to look harder. This case can be executed if we have |
6121 | line numbers but no functions (as can happen in assembly | |
6122 | source). */ | |
c906108c | 6123 | |
c5aa993b | 6124 | struct minimal_symbol *msym; |
c906108c SS |
6125 | |
6126 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6127 | if (msym) | |
714835d5 | 6128 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
6129 | } |
6130 | } | |
6131 | } | |
6132 | } | |
6133 | ||
6134 | void | |
fba45db2 | 6135 | break_command (char *arg, int from_tty) |
c906108c | 6136 | { |
db107f19 | 6137 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6138 | } |
6139 | ||
c906108c | 6140 | void |
fba45db2 | 6141 | tbreak_command (char *arg, int from_tty) |
c906108c | 6142 | { |
db107f19 | 6143 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6144 | } |
6145 | ||
c906108c | 6146 | static void |
fba45db2 | 6147 | hbreak_command (char *arg, int from_tty) |
c906108c | 6148 | { |
db107f19 | 6149 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6150 | } |
6151 | ||
6152 | static void | |
fba45db2 | 6153 | thbreak_command (char *arg, int from_tty) |
c906108c | 6154 | { |
db107f19 | 6155 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6156 | } |
6157 | ||
6158 | static void | |
fba45db2 | 6159 | stop_command (char *arg, int from_tty) |
c906108c | 6160 | { |
a3f17187 | 6161 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6162 | Usage: stop in <function | address>\n\ |
a3f17187 | 6163 | stop at <line>\n")); |
c906108c SS |
6164 | } |
6165 | ||
6166 | static void | |
fba45db2 | 6167 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6168 | { |
6169 | int badInput = 0; | |
6170 | ||
c5aa993b | 6171 | if (arg == (char *) NULL) |
c906108c SS |
6172 | badInput = 1; |
6173 | else if (*arg != '*') | |
6174 | { | |
6175 | char *argptr = arg; | |
6176 | int hasColon = 0; | |
6177 | ||
53a5351d JM |
6178 | /* look for a ':'. If this is a line number specification, then |
6179 | say it is bad, otherwise, it should be an address or | |
6180 | function/method name */ | |
c906108c | 6181 | while (*argptr && !hasColon) |
c5aa993b JM |
6182 | { |
6183 | hasColon = (*argptr == ':'); | |
6184 | argptr++; | |
6185 | } | |
c906108c SS |
6186 | |
6187 | if (hasColon) | |
c5aa993b | 6188 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6189 | else |
c5aa993b | 6190 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6191 | } |
6192 | ||
6193 | if (badInput) | |
a3f17187 | 6194 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6195 | else |
db107f19 | 6196 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6197 | } |
6198 | ||
6199 | static void | |
fba45db2 | 6200 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6201 | { |
6202 | int badInput = 0; | |
6203 | ||
c5aa993b | 6204 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6205 | badInput = 1; |
6206 | else | |
6207 | { | |
6208 | char *argptr = arg; | |
6209 | int hasColon = 0; | |
6210 | ||
6211 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6212 | it is probably a line number. */ |
c906108c | 6213 | while (*argptr && !hasColon) |
c5aa993b JM |
6214 | { |
6215 | hasColon = (*argptr == ':'); | |
6216 | argptr++; | |
6217 | } | |
c906108c SS |
6218 | |
6219 | if (hasColon) | |
c5aa993b | 6220 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6221 | else |
c5aa993b | 6222 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6223 | } |
6224 | ||
6225 | if (badInput) | |
a3f17187 | 6226 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6227 | else |
db107f19 | 6228 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6229 | } |
6230 | ||
53a5351d JM |
6231 | /* accessflag: hw_write: watch write, |
6232 | hw_read: watch read, | |
6233 | hw_access: watch access (read or write) */ | |
c906108c | 6234 | static void |
fba45db2 | 6235 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6236 | { |
a6d9a66e | 6237 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6238 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6239 | struct symtab_and_line sal; |
6240 | struct expression *exp; | |
6241 | struct block *exp_valid_block; | |
6242 | struct value *val, *mark; | |
6243 | struct frame_info *frame; | |
c906108c SS |
6244 | char *exp_start = NULL; |
6245 | char *exp_end = NULL; | |
37e4754d | 6246 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6247 | int toklen; |
6248 | char *cond_start = NULL; | |
6249 | char *cond_end = NULL; | |
6250 | struct expression *cond = NULL; | |
6251 | int i, other_type_used, target_resources_ok = 0; | |
6252 | enum bptype bp_type; | |
6253 | int mem_cnt = 0; | |
37e4754d | 6254 | int thread = -1; |
c906108c | 6255 | |
fe39c653 | 6256 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6257 | |
37e4754d LM |
6258 | /* Make sure that we actually have parameters to parse. */ |
6259 | if (arg != NULL && arg[0] != '\0') | |
6260 | { | |
6261 | toklen = strlen (arg); /* Size of argument list. */ | |
6262 | ||
6263 | /* Points tok to the end of the argument list. */ | |
6264 | tok = arg + toklen - 1; | |
6265 | ||
6266 | /* Go backwards in the parameters list. Skip the last parameter. | |
6267 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6268 | be the thread identifier. */ | |
6269 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6270 | tok--; | |
6271 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6272 | tok--; | |
6273 | ||
6274 | /* Points end_tok to the beginning of the last token. */ | |
6275 | id_tok_start = tok + 1; | |
6276 | ||
6277 | /* Go backwards in the parameters list. Skip one more parameter. | |
6278 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6279 | reach a "thread" token. */ | |
6280 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6281 | tok--; | |
6282 | ||
6283 | end_tok = tok; | |
6284 | ||
6285 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6286 | tok--; | |
6287 | ||
6288 | /* Move the pointer forward to skip the whitespace and | |
6289 | calculate the length of the token. */ | |
6290 | tok++; | |
6291 | toklen = end_tok - tok; | |
6292 | ||
6293 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6294 | { | |
6295 | /* At this point we've found a "thread" token, which means | |
6296 | the user is trying to set a watchpoint that triggers | |
6297 | only in a specific thread. */ | |
6298 | char *endp; | |
6299 | ||
6300 | /* Extract the thread ID from the next token. */ | |
6301 | thread = strtol (id_tok_start, &endp, 0); | |
6302 | ||
6303 | /* Check if the user provided a valid numeric value for the | |
6304 | thread ID. */ | |
6305 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6306 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
6307 | ||
6308 | /* Check if the thread actually exists. */ | |
6309 | if (!valid_thread_id (thread)) | |
6310 | error (_("Unknown thread %d."), thread); | |
6311 | ||
6312 | /* Truncate the string and get rid of the thread <thread_num> | |
6313 | parameter before the parameter list is parsed by the | |
6314 | evaluate_expression() function. */ | |
6315 | *tok = '\0'; | |
6316 | } | |
6317 | } | |
6318 | ||
6319 | /* Parse the rest of the arguments. */ | |
c906108c SS |
6320 | innermost_block = NULL; |
6321 | exp_start = arg; | |
6322 | exp = parse_exp_1 (&arg, 0, 0); | |
6323 | exp_end = arg; | |
fa8a61dc TT |
6324 | /* Remove trailing whitespace from the expression before saving it. |
6325 | This makes the eventual display of the expression string a bit | |
6326 | prettier. */ | |
6327 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
6328 | --exp_end; | |
6329 | ||
c906108c SS |
6330 | exp_valid_block = innermost_block; |
6331 | mark = value_mark (); | |
fa4727a6 DJ |
6332 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
6333 | if (val != NULL) | |
6334 | release_value (val); | |
c906108c SS |
6335 | |
6336 | tok = arg; | |
6337 | while (*tok == ' ' || *tok == '\t') | |
6338 | tok++; | |
6339 | end_tok = tok; | |
6340 | ||
6341 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6342 | end_tok++; | |
6343 | ||
6344 | toklen = end_tok - tok; | |
6345 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6346 | { | |
6347 | tok = cond_start = end_tok + 1; | |
6348 | cond = parse_exp_1 (&tok, 0, 0); | |
6349 | cond_end = tok; | |
6350 | } | |
6351 | if (*tok) | |
8a3fe4f8 | 6352 | error (_("Junk at end of command.")); |
c906108c | 6353 | |
53a5351d | 6354 | if (accessflag == hw_read) |
c5aa993b | 6355 | bp_type = bp_read_watchpoint; |
53a5351d | 6356 | else if (accessflag == hw_access) |
c5aa993b JM |
6357 | bp_type = bp_access_watchpoint; |
6358 | else | |
6359 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
6360 | |
6361 | mem_cnt = can_use_hardware_watchpoint (val); | |
6362 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 6363 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
6364 | if (mem_cnt != 0) |
6365 | { | |
6366 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 6367 | target_resources_ok = |
d92524f1 | 6368 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 6369 | other_type_used); |
c5aa993b | 6370 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6371 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 6372 | |
c5aa993b | 6373 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6374 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 6375 | } |
c906108c | 6376 | |
4d28f7a8 KB |
6377 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6378 | watchpoint could not be set. */ | |
6379 | if (!mem_cnt || target_resources_ok <= 0) | |
6380 | bp_type = bp_watchpoint; | |
6381 | ||
d983da9c | 6382 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
6383 | |
6384 | /* If the expression is "local", then set up a "watchpoint scope" | |
6385 | breakpoint at the point where we've left the scope of the watchpoint | |
6386 | expression. Create the scope breakpoint before the watchpoint, so | |
6387 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 6388 | if (innermost_block && frame) |
d983da9c | 6389 | { |
edb3359d DJ |
6390 | if (frame_id_p (frame_unwind_caller_id (frame))) |
6391 | { | |
6392 | scope_breakpoint | |
a6d9a66e UW |
6393 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
6394 | frame_unwind_caller_pc (frame), | |
edb3359d | 6395 | bp_watchpoint_scope); |
d983da9c | 6396 | |
edb3359d | 6397 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 6398 | |
edb3359d DJ |
6399 | /* Automatically delete the breakpoint when it hits. */ |
6400 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 6401 | |
edb3359d DJ |
6402 | /* Only break in the proper frame (help with recursion). */ |
6403 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 6404 | |
edb3359d | 6405 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
6406 | scope_breakpoint->loc->gdbarch |
6407 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
6408 | scope_breakpoint->loc->requested_address |
6409 | = frame_unwind_caller_pc (frame); | |
6410 | scope_breakpoint->loc->address | |
a6d9a66e UW |
6411 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
6412 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
6413 | scope_breakpoint->type); |
6414 | } | |
d983da9c DJ |
6415 | } |
6416 | ||
c906108c | 6417 | /* Now set up the breakpoint. */ |
a6d9a66e | 6418 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
6419 | set_breakpoint_count (breakpoint_count + 1); |
6420 | b->number = breakpoint_count; | |
37e4754d | 6421 | b->thread = thread; |
b5de0fa7 | 6422 | b->disposition = disp_donttouch; |
c906108c SS |
6423 | b->exp = exp; |
6424 | b->exp_valid_block = exp_valid_block; | |
6425 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6426 | b->val = val; | |
fa4727a6 | 6427 | b->val_valid = 1; |
511a6cd4 | 6428 | b->loc->cond = cond; |
c906108c SS |
6429 | if (cond_start) |
6430 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6431 | else | |
6432 | b->cond_string = 0; | |
c5aa993b | 6433 | |
c906108c | 6434 | if (frame) |
d983da9c | 6435 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6436 | else |
35a487f1 | 6437 | b->watchpoint_frame = null_frame_id; |
c906108c | 6438 | |
d983da9c | 6439 | if (scope_breakpoint != NULL) |
c906108c | 6440 | { |
d983da9c DJ |
6441 | /* The scope breakpoint is related to the watchpoint. We will |
6442 | need to act on them together. */ | |
6443 | b->related_breakpoint = scope_breakpoint; | |
6444 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6445 | } |
d983da9c | 6446 | |
c906108c SS |
6447 | value_free_to_mark (mark); |
6448 | mention (b); | |
b60e7edf | 6449 | update_global_location_list (1); |
c906108c SS |
6450 | } |
6451 | ||
6452 | /* Return count of locations need to be watched and can be handled | |
6453 | in hardware. If the watchpoint can not be handled | |
6454 | in hardware return zero. */ | |
6455 | ||
c906108c | 6456 | static int |
fba45db2 | 6457 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6458 | { |
6459 | int found_memory_cnt = 0; | |
2e70b7b9 | 6460 | struct value *head = v; |
c906108c SS |
6461 | |
6462 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6463 | if (!can_use_hw_watchpoints) |
c906108c | 6464 | return 0; |
c5aa993b | 6465 | |
5c44784c JM |
6466 | /* Make sure that the value of the expression depends only upon |
6467 | memory contents, and values computed from them within GDB. If we | |
6468 | find any register references or function calls, we can't use a | |
6469 | hardware watchpoint. | |
6470 | ||
6471 | The idea here is that evaluating an expression generates a series | |
6472 | of values, one holding the value of every subexpression. (The | |
6473 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6474 | a*b+c.) GDB's values hold almost enough information to establish | |
6475 | the criteria given above --- they identify memory lvalues, | |
6476 | register lvalues, computed values, etcetera. So we can evaluate | |
6477 | the expression, and then scan the chain of values that leaves | |
6478 | behind to decide whether we can detect any possible change to the | |
6479 | expression's final value using only hardware watchpoints. | |
6480 | ||
6481 | However, I don't think that the values returned by inferior | |
6482 | function calls are special in any way. So this function may not | |
6483 | notice that an expression involving an inferior function call | |
6484 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6485 | for (; v; v = value_next (v)) |
c906108c | 6486 | { |
5c44784c | 6487 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6488 | { |
d69fe07e | 6489 | if (value_lazy (v)) |
5c44784c JM |
6490 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6491 | we either just used its address (e.g., `a' in `a.b') or | |
6492 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6493 | ; | |
53a5351d | 6494 | else |
5c44784c JM |
6495 | { |
6496 | /* Ahh, memory we actually used! Check if we can cover | |
6497 | it with hardware watchpoints. */ | |
df407dfe | 6498 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6499 | |
6500 | /* We only watch structs and arrays if user asked for it | |
6501 | explicitly, never if they just happen to appear in a | |
6502 | middle of some value chain. */ | |
6503 | if (v == head | |
6504 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6505 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6506 | { | |
42ae5230 | 6507 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 6508 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 6509 | |
d92524f1 | 6510 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
6511 | return 0; |
6512 | else | |
6513 | found_memory_cnt++; | |
6514 | } | |
5c44784c | 6515 | } |
c5aa993b | 6516 | } |
5086187c AC |
6517 | else if (VALUE_LVAL (v) != not_lval |
6518 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6519 | return 0; /* ??? What does this represent? */ |
5086187c | 6520 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6521 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6522 | } |
6523 | ||
6524 | /* The expression itself looks suitable for using a hardware | |
6525 | watchpoint, but give the target machine a chance to reject it. */ | |
6526 | return found_memory_cnt; | |
6527 | } | |
6528 | ||
8b93c638 | 6529 | void |
fba45db2 | 6530 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6531 | { |
6532 | watch_command (arg, from_tty); | |
6533 | } | |
8926118c | 6534 | |
c5aa993b | 6535 | static void |
fba45db2 | 6536 | watch_command (char *arg, int from_tty) |
c906108c | 6537 | { |
53a5351d | 6538 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6539 | } |
6540 | ||
8b93c638 | 6541 | void |
fba45db2 | 6542 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6543 | { |
6544 | rwatch_command (arg, from_tty); | |
6545 | } | |
8926118c | 6546 | |
c5aa993b | 6547 | static void |
fba45db2 | 6548 | rwatch_command (char *arg, int from_tty) |
c906108c | 6549 | { |
53a5351d | 6550 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6551 | } |
6552 | ||
8b93c638 | 6553 | void |
fba45db2 | 6554 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6555 | { |
6556 | awatch_command (arg, from_tty); | |
6557 | } | |
8926118c | 6558 | |
c5aa993b | 6559 | static void |
fba45db2 | 6560 | awatch_command (char *arg, int from_tty) |
c906108c | 6561 | { |
53a5351d | 6562 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6563 | } |
c906108c | 6564 | \f |
c5aa993b | 6565 | |
43ff13b4 | 6566 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6567 | because it uses the mechanisms of breakpoints. */ |
6568 | ||
bfec99b2 PA |
6569 | struct until_break_command_continuation_args |
6570 | { | |
6571 | struct breakpoint *breakpoint; | |
6572 | struct breakpoint *breakpoint2; | |
6573 | }; | |
6574 | ||
43ff13b4 JM |
6575 | /* This function is called by fetch_inferior_event via the |
6576 | cmd_continuation pointer, to complete the until command. It takes | |
6577 | care of cleaning up the temporary breakpoints set up by the until | |
6578 | command. */ | |
c2c6d25f | 6579 | static void |
604ead4a | 6580 | until_break_command_continuation (void *arg) |
43ff13b4 | 6581 | { |
bfec99b2 PA |
6582 | struct until_break_command_continuation_args *a = arg; |
6583 | ||
6584 | delete_breakpoint (a->breakpoint); | |
6585 | if (a->breakpoint2) | |
6586 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6587 | } |
6588 | ||
c906108c | 6589 | void |
ae66c1fc | 6590 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6591 | { |
6592 | struct symtabs_and_lines sals; | |
6593 | struct symtab_and_line sal; | |
206415a3 | 6594 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 6595 | struct breakpoint *breakpoint; |
f107f563 | 6596 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6597 | struct cleanup *old_chain; |
6598 | ||
6599 | clear_proceed_status (); | |
6600 | ||
6601 | /* Set a breakpoint where the user wants it and at return from | |
6602 | this function */ | |
c5aa993b | 6603 | |
c906108c SS |
6604 | if (default_breakpoint_valid) |
6605 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6606 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6607 | else |
53a5351d | 6608 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6609 | 0, (char ***) NULL, NULL); |
c5aa993b | 6610 | |
c906108c | 6611 | if (sals.nelts != 1) |
8a3fe4f8 | 6612 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6613 | |
c906108c | 6614 | sal = sals.sals[0]; |
b8c9b27d | 6615 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6616 | |
c906108c | 6617 | if (*arg) |
8a3fe4f8 | 6618 | error (_("Junk at end of arguments.")); |
c5aa993b | 6619 | |
c906108c | 6620 | resolve_sal_pc (&sal); |
c5aa993b | 6621 | |
ae66c1fc EZ |
6622 | if (anywhere) |
6623 | /* If the user told us to continue until a specified location, | |
6624 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
6625 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6626 | null_frame_id, bp_until); | |
ae66c1fc | 6627 | else |
edb3359d | 6628 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 6629 | at the very same frame. */ |
a6d9a66e UW |
6630 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6631 | get_stack_frame_id (frame), | |
ae66c1fc | 6632 | bp_until); |
c5aa993b | 6633 | |
f107f563 | 6634 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6635 | |
ae66c1fc EZ |
6636 | /* Keep within the current frame, or in frames called by the current |
6637 | one. */ | |
edb3359d DJ |
6638 | |
6639 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 6640 | { |
edb3359d DJ |
6641 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
6642 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
6643 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
6644 | sal, | |
edb3359d | 6645 | frame_unwind_caller_id (frame), |
f107f563 VP |
6646 | bp_until); |
6647 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6648 | } |
c5aa993b | 6649 | |
c906108c | 6650 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6651 | |
6652 | /* If we are running asynchronously, and proceed call above has actually | |
6653 | managed to start the target, arrange for breakpoints to be | |
6654 | deleted when the target stops. Otherwise, we're already stopped and | |
6655 | delete breakpoints via cleanup chain. */ | |
6656 | ||
8ea051c5 | 6657 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6658 | { |
bfec99b2 PA |
6659 | struct until_break_command_continuation_args *args; |
6660 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6661 | |
bfec99b2 PA |
6662 | args->breakpoint = breakpoint; |
6663 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6664 | |
6665 | discard_cleanups (old_chain); | |
95e54da7 PA |
6666 | add_continuation (inferior_thread (), |
6667 | until_break_command_continuation, args, | |
604ead4a | 6668 | xfree); |
f107f563 VP |
6669 | } |
6670 | else | |
c5aa993b | 6671 | do_cleanups (old_chain); |
c906108c | 6672 | } |
ae66c1fc | 6673 | |
c906108c | 6674 | static void |
fba45db2 | 6675 | ep_skip_leading_whitespace (char **s) |
c906108c | 6676 | { |
c5aa993b JM |
6677 | if ((s == NULL) || (*s == NULL)) |
6678 | return; | |
6679 | while (isspace (**s)) | |
6680 | *s += 1; | |
c906108c | 6681 | } |
c5aa993b | 6682 | |
c906108c SS |
6683 | /* This function attempts to parse an optional "if <cond>" clause |
6684 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6685 | |
c906108c SS |
6686 | Else, it returns a pointer to the condition string. (It does not |
6687 | attempt to evaluate the string against a particular block.) And, | |
6688 | it updates arg to point to the first character following the parsed | |
6689 | if clause in the arg string. */ | |
53a5351d | 6690 | |
c906108c | 6691 | static char * |
fba45db2 | 6692 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6693 | { |
c5aa993b JM |
6694 | char *cond_string; |
6695 | ||
6696 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6697 | return NULL; |
c5aa993b | 6698 | |
c906108c SS |
6699 | /* Skip the "if" keyword. */ |
6700 | (*arg) += 2; | |
c5aa993b | 6701 | |
c906108c SS |
6702 | /* Skip any extra leading whitespace, and record the start of the |
6703 | condition string. */ | |
6704 | ep_skip_leading_whitespace (arg); | |
6705 | cond_string = *arg; | |
c5aa993b | 6706 | |
c906108c SS |
6707 | /* Assume that the condition occupies the remainder of the arg string. */ |
6708 | (*arg) += strlen (cond_string); | |
c5aa993b | 6709 | |
c906108c SS |
6710 | return cond_string; |
6711 | } | |
c5aa993b | 6712 | |
c906108c SS |
6713 | /* This function attempts to parse an optional filename from the arg |
6714 | string. If one is not found, it returns NULL. | |
c5aa993b | 6715 | |
c906108c SS |
6716 | Else, it returns a pointer to the parsed filename. (This function |
6717 | makes no attempt to verify that a file of that name exists, or is | |
6718 | accessible.) And, it updates arg to point to the first character | |
6719 | following the parsed filename in the arg string. | |
c5aa993b | 6720 | |
c906108c SS |
6721 | Note that clients needing to preserve the returned filename for |
6722 | future access should copy it to their own buffers. */ | |
6723 | static char * | |
fba45db2 | 6724 | ep_parse_optional_filename (char **arg) |
c906108c | 6725 | { |
c5aa993b JM |
6726 | static char filename[1024]; |
6727 | char *arg_p = *arg; | |
6728 | int i; | |
6729 | char c; | |
6730 | ||
c906108c SS |
6731 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6732 | return NULL; | |
c5aa993b JM |
6733 | |
6734 | for (i = 0;; i++) | |
c906108c SS |
6735 | { |
6736 | c = *arg_p; | |
6737 | if (isspace (c)) | |
c5aa993b | 6738 | c = '\0'; |
c906108c SS |
6739 | filename[i] = c; |
6740 | if (c == '\0') | |
c5aa993b | 6741 | break; |
c906108c SS |
6742 | arg_p++; |
6743 | } | |
6744 | *arg = arg_p; | |
c5aa993b | 6745 | |
c906108c SS |
6746 | return filename; |
6747 | } | |
c5aa993b | 6748 | |
c906108c SS |
6749 | /* Commands to deal with catching events, such as signals, exceptions, |
6750 | process start/exit, etc. */ | |
c5aa993b JM |
6751 | |
6752 | typedef enum | |
6753 | { | |
44feb3ce TT |
6754 | catch_fork_temporary, catch_vfork_temporary, |
6755 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6756 | } |
6757 | catch_fork_kind; | |
6758 | ||
c906108c | 6759 | static void |
44feb3ce | 6760 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6761 | { |
a6d9a66e | 6762 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 6763 | char *cond_string = NULL; |
44feb3ce TT |
6764 | catch_fork_kind fork_kind; |
6765 | int tempflag; | |
6766 | ||
6767 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6768 | tempflag = (fork_kind == catch_fork_temporary | |
6769 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6770 | |
44feb3ce TT |
6771 | if (!arg) |
6772 | arg = ""; | |
c906108c | 6773 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6774 | |
c906108c | 6775 | /* The allowed syntax is: |
c5aa993b JM |
6776 | catch [v]fork |
6777 | catch [v]fork if <cond> | |
6778 | ||
c906108c SS |
6779 | First, check if there's an if clause. */ |
6780 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6781 | |
c906108c | 6782 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6783 | error (_("Junk at end of arguments.")); |
c5aa993b | 6784 | |
c906108c SS |
6785 | /* If this target supports it, create a fork or vfork catchpoint |
6786 | and enable reporting of such events. */ | |
c5aa993b JM |
6787 | switch (fork_kind) |
6788 | { | |
44feb3ce TT |
6789 | case catch_fork_temporary: |
6790 | case catch_fork_permanent: | |
a6d9a66e | 6791 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6792 | &catch_fork_breakpoint_ops); |
c906108c | 6793 | break; |
44feb3ce TT |
6794 | case catch_vfork_temporary: |
6795 | case catch_vfork_permanent: | |
a6d9a66e | 6796 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6797 | &catch_vfork_breakpoint_ops); |
c906108c | 6798 | break; |
c5aa993b | 6799 | default: |
8a3fe4f8 | 6800 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6801 | break; |
c5aa993b | 6802 | } |
c906108c SS |
6803 | } |
6804 | ||
6805 | static void | |
44feb3ce | 6806 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6807 | { |
a6d9a66e | 6808 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 6809 | int tempflag; |
c5aa993b | 6810 | char *cond_string = NULL; |
c906108c | 6811 | |
44feb3ce TT |
6812 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6813 | ||
6814 | if (!arg) | |
6815 | arg = ""; | |
c906108c SS |
6816 | ep_skip_leading_whitespace (&arg); |
6817 | ||
6818 | /* The allowed syntax is: | |
c5aa993b JM |
6819 | catch exec |
6820 | catch exec if <cond> | |
c906108c SS |
6821 | |
6822 | First, check if there's an if clause. */ | |
6823 | cond_string = ep_parse_optional_if_clause (&arg); | |
6824 | ||
6825 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6826 | error (_("Junk at end of arguments.")); |
c906108c SS |
6827 | |
6828 | /* If this target supports it, create an exec catchpoint | |
6829 | and enable reporting of such events. */ | |
a6d9a66e UW |
6830 | create_catchpoint (gdbarch, tempflag, cond_string, |
6831 | &catch_exec_breakpoint_ops); | |
c906108c | 6832 | } |
c5aa993b | 6833 | |
3086aeae DJ |
6834 | static enum print_stop_action |
6835 | print_exception_catchpoint (struct breakpoint *b) | |
6836 | { | |
ade92717 | 6837 | int bp_temp, bp_throw; |
3086aeae | 6838 | |
ade92717 | 6839 | annotate_catchpoint (b->number); |
3086aeae | 6840 | |
ade92717 AR |
6841 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6842 | if (b->loc->address != b->loc->requested_address) | |
6843 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6844 | b->loc->address, | |
6845 | b->number, 1); | |
df2b6d2d | 6846 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6847 | ui_out_text (uiout, |
6848 | bp_temp ? "Temporary catchpoint " | |
6849 | : "Catchpoint "); | |
6850 | if (!ui_out_is_mi_like_p (uiout)) | |
6851 | ui_out_field_int (uiout, "bkptno", b->number); | |
6852 | ui_out_text (uiout, | |
c0b37c48 AR |
6853 | bp_throw ? " (exception thrown), " |
6854 | : " (exception caught), "); | |
ade92717 AR |
6855 | if (ui_out_is_mi_like_p (uiout)) |
6856 | { | |
6857 | ui_out_field_string (uiout, "reason", | |
6858 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6859 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6860 | ui_out_field_int (uiout, "bkptno", b->number); | |
6861 | } | |
3086aeae DJ |
6862 | return PRINT_SRC_AND_LOC; |
6863 | } | |
6864 | ||
6865 | static void | |
a6d9a66e | 6866 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 6867 | { |
79a45b7d TT |
6868 | struct value_print_options opts; |
6869 | get_user_print_options (&opts); | |
6870 | if (opts.addressprint) | |
3086aeae DJ |
6871 | { |
6872 | annotate_field (4); | |
604133b5 AR |
6873 | if (b->loc == NULL || b->loc->shlib_disabled) |
6874 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6875 | else | |
5af949e3 UW |
6876 | ui_out_field_core_addr (uiout, "addr", |
6877 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
6878 | } |
6879 | annotate_field (5); | |
604133b5 | 6880 | if (b->loc) |
a6d9a66e | 6881 | *last_loc = b->loc; |
3086aeae DJ |
6882 | if (strstr (b->addr_string, "throw") != NULL) |
6883 | ui_out_field_string (uiout, "what", "exception throw"); | |
6884 | else | |
6885 | ui_out_field_string (uiout, "what", "exception catch"); | |
6886 | } | |
6887 | ||
6888 | static void | |
6889 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6890 | { | |
ade92717 AR |
6891 | int bp_temp; |
6892 | int bp_throw; | |
6893 | ||
df2b6d2d | 6894 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6895 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6896 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6897 | : _("Catchpoint ")); | |
6898 | ui_out_field_int (uiout, "bkptno", b->number); | |
6899 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6900 | : _(" (catch)")); | |
3086aeae DJ |
6901 | } |
6902 | ||
6903 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6904 | NULL, /* insert */ |
6905 | NULL, /* remove */ | |
6906 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
6907 | print_exception_catchpoint, |
6908 | print_one_exception_catchpoint, | |
6909 | print_mention_exception_catchpoint | |
6910 | }; | |
6911 | ||
6912 | static int | |
6913 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6914 | enum exception_event_kind ex_event, int from_tty) | |
6915 | { | |
604133b5 AR |
6916 | char *trigger_func_name; |
6917 | ||
3086aeae | 6918 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 6919 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 6920 | else |
604133b5 | 6921 | trigger_func_name = "__cxa_throw"; |
3086aeae | 6922 | |
a6d9a66e UW |
6923 | break_command_really (get_current_arch (), |
6924 | trigger_func_name, cond_string, -1, | |
604133b5 | 6925 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6926 | tempflag, 0, 0, |
604133b5 AR |
6927 | 0, |
6928 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
6929 | &gnu_v3_exception_catchpoint_ops, from_tty, |
6930 | 1 /* enabled */); | |
3086aeae | 6931 | |
3086aeae DJ |
6932 | return 1; |
6933 | } | |
6934 | ||
c5aa993b | 6935 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6936 | |
6937 | static void | |
fba45db2 KB |
6938 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6939 | int tempflag, int from_tty) | |
c906108c | 6940 | { |
c5aa993b JM |
6941 | char *cond_string = NULL; |
6942 | struct symtab_and_line *sal = NULL; | |
6943 | ||
44feb3ce TT |
6944 | if (!arg) |
6945 | arg = ""; | |
c906108c | 6946 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6947 | |
c906108c SS |
6948 | cond_string = ep_parse_optional_if_clause (&arg); |
6949 | ||
6950 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6951 | error (_("Junk at end of arguments.")); |
c906108c | 6952 | |
059fb39f PM |
6953 | if (ex_event != EX_EVENT_THROW |
6954 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 6955 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 6956 | |
3086aeae DJ |
6957 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
6958 | return; | |
6959 | ||
8a3fe4f8 | 6960 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
6961 | } |
6962 | ||
44feb3ce TT |
6963 | /* Implementation of "catch catch" command. */ |
6964 | ||
6965 | static void | |
6966 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6967 | { | |
6968 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6969 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
6970 | } | |
6971 | ||
6972 | /* Implementation of "catch throw" command. */ | |
6973 | ||
6974 | static void | |
6975 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
6976 | { | |
6977 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
6978 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
6979 | } | |
6980 | ||
f7f9143b JB |
6981 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
6982 | ||
6983 | static void | |
a6d9a66e UW |
6984 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
6985 | struct symtab_and_line sal, | |
f7f9143b JB |
6986 | char *addr_string, |
6987 | char *exp_string, | |
6988 | char *cond_string, | |
6989 | struct expression *cond, | |
6990 | struct breakpoint_ops *ops, | |
6991 | int tempflag, | |
6992 | int from_tty) | |
6993 | { | |
6994 | struct breakpoint *b; | |
6995 | ||
6996 | if (from_tty) | |
6997 | { | |
5af949e3 UW |
6998 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
6999 | if (!loc_gdbarch) | |
7000 | loc_gdbarch = gdbarch; | |
7001 | ||
7002 | describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1); | |
f7f9143b JB |
7003 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7004 | version for exception catchpoints, because two catchpoints | |
7005 | used for different exception names will use the same address. | |
7006 | In this case, a "breakpoint ... also set at..." warning is | |
7007 | unproductive. Besides. the warning phrasing is also a bit | |
7008 | inapropriate, we should use the word catchpoint, and tell | |
7009 | the user what type of catchpoint it is. The above is good | |
7010 | enough for now, though. */ | |
7011 | } | |
7012 | ||
a6d9a66e | 7013 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7014 | set_breakpoint_count (breakpoint_count + 1); |
7015 | ||
7016 | b->enable_state = bp_enabled; | |
7017 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7018 | b->number = breakpoint_count; | |
7019 | b->ignore_count = 0; | |
511a6cd4 | 7020 | b->loc->cond = cond; |
f7f9143b JB |
7021 | b->addr_string = addr_string; |
7022 | b->language = language_ada; | |
7023 | b->cond_string = cond_string; | |
7024 | b->exp_string = exp_string; | |
7025 | b->thread = -1; | |
7026 | b->ops = ops; | |
f7f9143b JB |
7027 | |
7028 | mention (b); | |
b60e7edf | 7029 | update_global_location_list (1); |
f7f9143b JB |
7030 | } |
7031 | ||
7032 | /* Implement the "catch exception" command. */ | |
7033 | ||
7034 | static void | |
44feb3ce TT |
7035 | catch_ada_exception_command (char *arg, int from_tty, |
7036 | struct cmd_list_element *command) | |
f7f9143b | 7037 | { |
a6d9a66e | 7038 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7039 | int tempflag; |
f7f9143b JB |
7040 | struct symtab_and_line sal; |
7041 | enum bptype type; | |
7042 | char *addr_string = NULL; | |
7043 | char *exp_string = NULL; | |
7044 | char *cond_string = NULL; | |
7045 | struct expression *cond = NULL; | |
7046 | struct breakpoint_ops *ops = NULL; | |
7047 | ||
44feb3ce TT |
7048 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7049 | ||
7050 | if (!arg) | |
7051 | arg = ""; | |
f7f9143b JB |
7052 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7053 | &cond_string, &cond, &ops); | |
a6d9a66e | 7054 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7055 | cond_string, cond, ops, tempflag, |
7056 | from_tty); | |
7057 | } | |
7058 | ||
7059 | /* Implement the "catch assert" command. */ | |
7060 | ||
7061 | static void | |
44feb3ce | 7062 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7063 | { |
a6d9a66e | 7064 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7065 | int tempflag; |
f7f9143b JB |
7066 | struct symtab_and_line sal; |
7067 | char *addr_string = NULL; | |
7068 | struct breakpoint_ops *ops = NULL; | |
7069 | ||
44feb3ce TT |
7070 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7071 | ||
7072 | if (!arg) | |
7073 | arg = ""; | |
f7f9143b | 7074 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7075 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7076 | ops, tempflag, from_tty); | |
f7f9143b JB |
7077 | } |
7078 | ||
c906108c | 7079 | static void |
fba45db2 | 7080 | catch_command (char *arg, int from_tty) |
c906108c | 7081 | { |
44feb3ce | 7082 | error (_("Catch requires an event name.")); |
c906108c SS |
7083 | } |
7084 | \f | |
7085 | ||
7086 | static void | |
fba45db2 | 7087 | tcatch_command (char *arg, int from_tty) |
c906108c | 7088 | { |
44feb3ce | 7089 | error (_("Catch requires an event name.")); |
c906108c SS |
7090 | } |
7091 | ||
80f8a6eb | 7092 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7093 | |
7094 | static void | |
fba45db2 | 7095 | clear_command (char *arg, int from_tty) |
c906108c | 7096 | { |
d6e956e5 VP |
7097 | struct breakpoint *b; |
7098 | VEC(breakpoint_p) *found = 0; | |
7099 | int ix; | |
c906108c SS |
7100 | int default_match; |
7101 | struct symtabs_and_lines sals; | |
7102 | struct symtab_and_line sal; | |
c906108c SS |
7103 | int i; |
7104 | ||
7105 | if (arg) | |
7106 | { | |
7107 | sals = decode_line_spec (arg, 1); | |
7108 | default_match = 0; | |
7109 | } | |
7110 | else | |
7111 | { | |
c5aa993b | 7112 | sals.sals = (struct symtab_and_line *) |
c906108c | 7113 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7114 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7115 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7116 | sal.line = default_breakpoint_line; |
7117 | sal.symtab = default_breakpoint_symtab; | |
7118 | sal.pc = default_breakpoint_address; | |
7119 | if (sal.symtab == 0) | |
8a3fe4f8 | 7120 | error (_("No source file specified.")); |
c906108c SS |
7121 | |
7122 | sals.sals[0] = sal; | |
7123 | sals.nelts = 1; | |
7124 | ||
7125 | default_match = 1; | |
7126 | } | |
7127 | ||
ed0616c6 VP |
7128 | /* We don't call resolve_sal_pc here. That's not |
7129 | as bad as it seems, because all existing breakpoints | |
7130 | typically have both file/line and pc set. So, if | |
7131 | clear is given file/line, we can match this to existing | |
7132 | breakpoint without obtaining pc at all. | |
7133 | ||
7134 | We only support clearing given the address explicitly | |
7135 | present in breakpoint table. Say, we've set breakpoint | |
7136 | at file:line. There were several PC values for that file:line, | |
7137 | due to optimization, all in one block. | |
7138 | We've picked one PC value. If "clear" is issued with another | |
7139 | PC corresponding to the same file:line, the breakpoint won't | |
7140 | be cleared. We probably can still clear the breakpoint, but | |
7141 | since the other PC value is never presented to user, user | |
7142 | can only find it by guessing, and it does not seem important | |
7143 | to support that. */ | |
7144 | ||
c906108c | 7145 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7146 | to it. Do it in two passes, solely to preserve the current |
7147 | behavior that from_tty is forced true if we delete more than | |
7148 | one breakpoint. */ | |
c906108c | 7149 | |
80f8a6eb | 7150 | found = NULL; |
c906108c SS |
7151 | for (i = 0; i < sals.nelts; i++) |
7152 | { | |
7153 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7154 | If line given (pc == 0), clear all bpts on specified line. |
7155 | If defaulting, clear all bpts on default line | |
c906108c | 7156 | or at default pc. |
c5aa993b JM |
7157 | |
7158 | defaulting sal.pc != 0 tests to do | |
7159 | ||
7160 | 0 1 pc | |
7161 | 1 1 pc _and_ line | |
7162 | 0 0 line | |
7163 | 1 0 <can't happen> */ | |
c906108c SS |
7164 | |
7165 | sal = sals.sals[i]; | |
c906108c | 7166 | |
d6e956e5 VP |
7167 | /* Find all matching breakpoints and add them to |
7168 | 'found'. */ | |
7169 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7170 | { |
0d381245 | 7171 | int match = 0; |
80f8a6eb MS |
7172 | /* Are we going to delete b? */ |
7173 | if (b->type != bp_none | |
7174 | && b->type != bp_watchpoint | |
7175 | && b->type != bp_hardware_watchpoint | |
7176 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7177 | && b->type != bp_access_watchpoint) |
7178 | { | |
7179 | struct bp_location *loc = b->loc; | |
7180 | for (; loc; loc = loc->next) | |
7181 | { | |
7182 | int pc_match = sal.pc | |
7183 | && (loc->address == sal.pc) | |
7184 | && (!section_is_overlay (loc->section) | |
7185 | || loc->section == sal.section); | |
7186 | int line_match = ((default_match || (0 == sal.pc)) | |
7187 | && b->source_file != NULL | |
7188 | && sal.symtab != NULL | |
7189 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
7190 | && b->line_number == sal.line); | |
7191 | if (pc_match || line_match) | |
7192 | { | |
7193 | match = 1; | |
7194 | break; | |
7195 | } | |
7196 | } | |
7197 | } | |
7198 | ||
7199 | if (match) | |
d6e956e5 | 7200 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 7201 | } |
80f8a6eb MS |
7202 | } |
7203 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 7204 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
7205 | { |
7206 | if (arg) | |
8a3fe4f8 | 7207 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 7208 | else |
8a3fe4f8 | 7209 | error (_("No breakpoint at this line.")); |
80f8a6eb | 7210 | } |
c906108c | 7211 | |
d6e956e5 | 7212 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
7213 | from_tty = 1; /* Always report if deleted more than one */ |
7214 | if (from_tty) | |
a3f17187 | 7215 | { |
d6e956e5 | 7216 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
7217 | printf_unfiltered (_("Deleted breakpoint ")); |
7218 | else | |
7219 | printf_unfiltered (_("Deleted breakpoints ")); | |
7220 | } | |
80f8a6eb | 7221 | breakpoints_changed (); |
d6e956e5 VP |
7222 | |
7223 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 7224 | { |
c5aa993b | 7225 | if (from_tty) |
d6e956e5 VP |
7226 | printf_unfiltered ("%d ", b->number); |
7227 | delete_breakpoint (b); | |
c906108c | 7228 | } |
80f8a6eb MS |
7229 | if (from_tty) |
7230 | putchar_unfiltered ('\n'); | |
c906108c SS |
7231 | } |
7232 | \f | |
7233 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
7234 | all breakpoints that are marked for deletion, whether hit or not. | |
7235 | This is called after any breakpoint is hit, or after errors. */ | |
7236 | ||
7237 | void | |
fba45db2 | 7238 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
7239 | { |
7240 | struct breakpoint *b, *temp; | |
7241 | ||
7242 | for (; bs; bs = bs->next) | |
20874c92 VP |
7243 | if (bs->breakpoint_at |
7244 | && bs->breakpoint_at->owner | |
7245 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 7246 | && bs->stop) |
4f8d1dc6 | 7247 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
7248 | |
7249 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7250 | { |
b5de0fa7 | 7251 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
7252 | delete_breakpoint (b); |
7253 | } | |
c906108c SS |
7254 | } |
7255 | ||
f7545552 TT |
7256 | /* A cleanup function which destroys a vector. */ |
7257 | ||
7258 | static void | |
7259 | do_vec_free (void *p) | |
7260 | { | |
7261 | VEC(bp_location_p) **vec = p; | |
7262 | if (*vec) | |
7263 | VEC_free (bp_location_p, *vec); | |
7264 | } | |
7265 | ||
4cd9bd08 | 7266 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
7267 | into the inferior, only remove already-inserted locations that no |
7268 | longer should be inserted. Functions that delete a breakpoint or | |
7269 | breakpoints should pass false, so that deleting a breakpoint | |
7270 | doesn't have the side effect of inserting the locations of other | |
7271 | breakpoints that are marked not-inserted, but should_be_inserted | |
7272 | returns true on them. | |
7273 | ||
7274 | This behaviour is useful is situations close to tear-down -- e.g., | |
7275 | after an exec, while the target still has execution, but breakpoint | |
7276 | shadows of the previous executable image should *NOT* be restored | |
7277 | to the new image; or before detaching, where the target still has | |
7278 | execution and wants to delete breakpoints from GDB's lists, and all | |
7279 | breakpoints had already been removed from the inferior. */ | |
7280 | ||
0d381245 | 7281 | static void |
b60e7edf | 7282 | update_global_location_list (int should_insert) |
0d381245 | 7283 | { |
74960c60 VP |
7284 | struct breakpoint *b; |
7285 | struct bp_location **next = &bp_location_chain; | |
7286 | struct bp_location *loc; | |
7287 | struct bp_location *loc2; | |
74960c60 VP |
7288 | VEC(bp_location_p) *old_locations = NULL; |
7289 | int ret; | |
7290 | int ix; | |
f7545552 TT |
7291 | struct cleanup *cleanups; |
7292 | ||
7293 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
7294 | /* Store old locations for future reference. */ |
7295 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
7296 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 7297 | |
74960c60 VP |
7298 | bp_location_chain = NULL; |
7299 | ALL_BREAKPOINTS (b) | |
0d381245 | 7300 | { |
74960c60 | 7301 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 7302 | { |
74960c60 VP |
7303 | *next = loc; |
7304 | next = &(loc->global_next); | |
7305 | *next = NULL; | |
0d381245 | 7306 | } |
74960c60 VP |
7307 | } |
7308 | ||
7309 | /* Identify bp_location instances that are no longer present in the new | |
7310 | list, and therefore should be freed. Note that it's not necessary that | |
7311 | those locations should be removed from inferior -- if there's another | |
7312 | location at the same address (previously marked as duplicate), | |
7313 | we don't need to remove/insert the location. */ | |
7314 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
7315 | { | |
7316 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
7317 | have to free it. */ | |
7318 | int found_object = 0; | |
20874c92 VP |
7319 | /* Tells if the location should remain inserted in the target. */ |
7320 | int keep_in_target = 0; | |
7321 | int removed = 0; | |
74960c60 VP |
7322 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
7323 | if (loc2 == loc) | |
7324 | { | |
7325 | found_object = 1; | |
7326 | break; | |
7327 | } | |
7328 | ||
7329 | /* If this location is no longer present, and inserted, look if there's | |
7330 | maybe a new location at the same address. If so, mark that one | |
7331 | inserted, and don't remove this one. This is needed so that we | |
7332 | don't have a time window where a breakpoint at certain location is not | |
7333 | inserted. */ | |
7334 | ||
7335 | if (loc->inserted) | |
0d381245 | 7336 | { |
74960c60 | 7337 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
7338 | |
7339 | if (found_object && should_be_inserted (loc)) | |
7340 | { | |
7341 | /* The location is still present in the location list, and still | |
7342 | should be inserted. Don't do anything. */ | |
20874c92 | 7343 | keep_in_target = 1; |
74960c60 VP |
7344 | } |
7345 | else | |
7346 | { | |
7347 | /* The location is either no longer present, or got disabled. | |
7348 | See if there's another location at the same address, in which | |
7349 | case we don't need to remove this one from the target. */ | |
7350 | if (breakpoint_address_is_meaningful (loc->owner)) | |
7351 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
7352 | { | |
7353 | /* For the sake of should_insert_location. The | |
7354 | call to check_duplicates will fix up this later. */ | |
7355 | loc2->duplicate = 0; | |
7356 | if (should_be_inserted (loc2) | |
7357 | && loc2 != loc && loc2->address == loc->address) | |
7358 | { | |
7359 | loc2->inserted = 1; | |
7360 | loc2->target_info = loc->target_info; | |
20874c92 | 7361 | keep_in_target = 1; |
74960c60 VP |
7362 | break; |
7363 | } | |
7364 | } | |
7365 | } | |
7366 | ||
20874c92 VP |
7367 | if (!keep_in_target) |
7368 | { | |
7369 | if (remove_breakpoint (loc, mark_uninserted)) | |
7370 | { | |
7371 | /* This is just about all we can do. We could keep this | |
7372 | location on the global list, and try to remove it next | |
7373 | time, but there's no particular reason why we will | |
7374 | succeed next time. | |
7375 | ||
7376 | Note that at this point, loc->owner is still valid, | |
7377 | as delete_breakpoint frees the breakpoint only | |
7378 | after calling us. */ | |
7379 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
7380 | loc->owner->number); | |
7381 | } | |
7382 | removed = 1; | |
7383 | } | |
0d381245 | 7384 | } |
74960c60 VP |
7385 | |
7386 | if (!found_object) | |
1c5cfe86 PA |
7387 | { |
7388 | if (removed && non_stop) | |
20874c92 VP |
7389 | { |
7390 | /* This location was removed from the targets. In non-stop mode, | |
7391 | a race condition is possible where we've removed a breakpoint, | |
7392 | but stop events for that breakpoint are already queued and will | |
7393 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
7394 | we keep this breakpoint location for a bit, and will retire it | |
7395 | after we see 3 * thread_count events. | |
1c5cfe86 | 7396 | The theory here is that reporting of events should, |
20874c92 VP |
7397 | "on the average", be fair, so after that many event we'll see |
7398 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 7399 | longer need to keep this breakpoint. This is just a |
20874c92 | 7400 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 7401 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
7402 | loc->events_till_retirement = 3 * (thread_count () + 1); |
7403 | loc->owner = NULL; | |
20874c92 | 7404 | |
1c5cfe86 PA |
7405 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
7406 | } | |
7407 | else | |
7408 | free_bp_location (loc); | |
20874c92 | 7409 | } |
74960c60 | 7410 | } |
1c5cfe86 | 7411 | |
74960c60 VP |
7412 | ALL_BREAKPOINTS (b) |
7413 | { | |
7414 | check_duplicates (b); | |
0d381245 | 7415 | } |
74960c60 | 7416 | |
50c71eaf | 7417 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 7418 | && (have_live_inferiors () |
2567c7d9 | 7419 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 7420 | insert_breakpoint_locations (); |
f7545552 TT |
7421 | |
7422 | do_cleanups (cleanups); | |
74960c60 VP |
7423 | } |
7424 | ||
20874c92 VP |
7425 | void |
7426 | breakpoint_retire_moribund (void) | |
7427 | { | |
7428 | struct bp_location *loc; | |
7429 | int ix; | |
7430 | ||
7431 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7432 | if (--(loc->events_till_retirement) == 0) | |
7433 | { | |
7434 | free_bp_location (loc); | |
7435 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7436 | --ix; | |
7437 | } | |
7438 | } | |
7439 | ||
74960c60 | 7440 | static void |
b60e7edf | 7441 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7442 | { |
7443 | struct gdb_exception e; | |
7444 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7445 | update_global_location_list (inserting); |
0d381245 VP |
7446 | } |
7447 | ||
a474d7c2 PA |
7448 | /* Clear BPT from a BPS. */ |
7449 | static void | |
7450 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7451 | { | |
7452 | bpstat bs; | |
7453 | for (bs = bps; bs; bs = bs->next) | |
7454 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7455 | { | |
7456 | bs->breakpoint_at = NULL; | |
7457 | bs->old_val = NULL; | |
7458 | /* bs->commands will be freed later. */ | |
7459 | } | |
7460 | } | |
7461 | ||
7462 | /* Callback for iterate_over_threads. */ | |
7463 | static int | |
7464 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7465 | { | |
7466 | struct breakpoint *bpt = data; | |
7467 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7468 | return 0; | |
7469 | } | |
7470 | ||
53a5351d JM |
7471 | /* Delete a breakpoint and clean up all traces of it in the data |
7472 | structures. */ | |
c906108c SS |
7473 | |
7474 | void | |
fba45db2 | 7475 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7476 | { |
52f0bd74 | 7477 | struct breakpoint *b; |
74960c60 | 7478 | struct bp_location *loc, *next; |
c906108c | 7479 | |
8a3fe4f8 | 7480 | gdb_assert (bpt != NULL); |
c906108c SS |
7481 | |
7482 | /* Has this bp already been deleted? This can happen because multiple | |
7483 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7484 | ||
7485 | One example of this happening is a watchpoint's scope bp. When the | |
7486 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7487 | delete it. We also delete its scope bp. But the scope bp is marked | |
7488 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7489 | checked for auto-deleting bp's, which are deleted. | |
7490 | ||
7491 | A real solution to this problem might involve reference counts in bp's, | |
7492 | and/or giving them pointers back to their referencing bpstat's, and | |
7493 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7494 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7495 | if (bpt->type == bp_none) |
7496 | return; | |
7497 | ||
383f836e | 7498 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7499 | |
c906108c SS |
7500 | if (breakpoint_chain == bpt) |
7501 | breakpoint_chain = bpt->next; | |
7502 | ||
c906108c SS |
7503 | ALL_BREAKPOINTS (b) |
7504 | if (b->next == bpt) | |
c5aa993b JM |
7505 | { |
7506 | b->next = bpt->next; | |
7507 | break; | |
7508 | } | |
c906108c | 7509 | |
c906108c | 7510 | free_command_lines (&bpt->commands); |
c906108c | 7511 | if (bpt->cond_string != NULL) |
b8c9b27d | 7512 | xfree (bpt->cond_string); |
c906108c | 7513 | if (bpt->addr_string != NULL) |
b8c9b27d | 7514 | xfree (bpt->addr_string); |
c906108c | 7515 | if (bpt->exp != NULL) |
b8c9b27d | 7516 | xfree (bpt->exp); |
c906108c | 7517 | if (bpt->exp_string != NULL) |
b8c9b27d | 7518 | xfree (bpt->exp_string); |
c906108c SS |
7519 | if (bpt->val != NULL) |
7520 | value_free (bpt->val); | |
7521 | if (bpt->source_file != NULL) | |
b8c9b27d | 7522 | xfree (bpt->source_file); |
c906108c | 7523 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7524 | xfree (bpt->exec_pathname); |
c906108c SS |
7525 | |
7526 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7527 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7528 | We just check stop_bpstat for now. Note that we cannot just |
7529 | remove bpstats pointing at bpt from the stop_bpstat list | |
7530 | entirely, as breakpoint commands are associated with the bpstat; | |
7531 | if we remove it here, then the later call to | |
7532 | bpstat_do_actions (&stop_bpstat); | |
7533 | in event-top.c won't do anything, and temporary breakpoints | |
7534 | with commands won't work. */ | |
a474d7c2 | 7535 | |
a474d7c2 | 7536 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7537 | |
7538 | /* Now that breakpoint is removed from breakpoint | |
7539 | list, update the global location list. This | |
7540 | will remove locations that used to belong to | |
7541 | this breakpoint. Do this before freeing | |
7542 | the breakpoint itself, since remove_breakpoint | |
7543 | looks at location's owner. It might be better | |
7544 | design to have location completely self-contained, | |
7545 | but it's not the case now. */ | |
b60e7edf | 7546 | update_global_location_list (0); |
74960c60 VP |
7547 | |
7548 | ||
c906108c SS |
7549 | /* On the chance that someone will soon try again to delete this same |
7550 | bp, we mark it as deleted before freeing its storage. */ | |
7551 | bpt->type = bp_none; | |
7552 | ||
b8c9b27d | 7553 | xfree (bpt); |
c906108c SS |
7554 | } |
7555 | ||
4d6140d9 AC |
7556 | static void |
7557 | do_delete_breakpoint_cleanup (void *b) | |
7558 | { | |
7559 | delete_breakpoint (b); | |
7560 | } | |
7561 | ||
7562 | struct cleanup * | |
7563 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7564 | { | |
7565 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7566 | } | |
7567 | ||
c906108c | 7568 | void |
fba45db2 | 7569 | delete_command (char *arg, int from_tty) |
c906108c SS |
7570 | { |
7571 | struct breakpoint *b, *temp; | |
7572 | ||
ea9365bb TT |
7573 | dont_repeat (); |
7574 | ||
c906108c SS |
7575 | if (arg == 0) |
7576 | { | |
7577 | int breaks_to_delete = 0; | |
7578 | ||
7579 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7580 | Do not delete internal or call-dummy breakpoints, these |
7581 | have to be deleted with an explicit breakpoint number argument. */ | |
7582 | ALL_BREAKPOINTS (b) | |
7583 | { | |
059fb39f PM |
7584 | if (b->type != bp_call_dummy |
7585 | && b->type != bp_shlib_event | |
7586 | && b->type != bp_thread_event | |
7587 | && b->type != bp_overlay_event | |
0fd8e87f | 7588 | && b->type != bp_longjmp_master |
059fb39f | 7589 | && b->number >= 0) |
973d738b DJ |
7590 | { |
7591 | breaks_to_delete = 1; | |
7592 | break; | |
7593 | } | |
c5aa993b | 7594 | } |
c906108c SS |
7595 | |
7596 | /* Ask user only if there are some breakpoints to delete. */ | |
7597 | if (!from_tty | |
e2e0b3e5 | 7598 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7599 | { |
c5aa993b JM |
7600 | ALL_BREAKPOINTS_SAFE (b, temp) |
7601 | { | |
059fb39f PM |
7602 | if (b->type != bp_call_dummy |
7603 | && b->type != bp_shlib_event | |
7604 | && b->type != bp_thread_event | |
7605 | && b->type != bp_overlay_event | |
0fd8e87f | 7606 | && b->type != bp_longjmp_master |
059fb39f | 7607 | && b->number >= 0) |
c5aa993b JM |
7608 | delete_breakpoint (b); |
7609 | } | |
c906108c SS |
7610 | } |
7611 | } | |
7612 | else | |
7613 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7614 | } | |
7615 | ||
0d381245 VP |
7616 | static int |
7617 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7618 | { |
0d381245 VP |
7619 | for (; loc; loc = loc->next) |
7620 | if (!loc->shlib_disabled) | |
7621 | return 0; | |
7622 | return 1; | |
fe3f5fa8 VP |
7623 | } |
7624 | ||
776592bf DE |
7625 | /* Subroutine of update_breakpoint_locations to simplify it. |
7626 | Return non-zero if multiple fns in list LOC have the same name. | |
7627 | Null names are ignored. */ | |
7628 | ||
7629 | static int | |
7630 | ambiguous_names_p (struct bp_location *loc) | |
7631 | { | |
7632 | struct bp_location *l; | |
7633 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7634 | (int (*) (const void *, const void *)) streq, | |
7635 | NULL, xcalloc, xfree); | |
7636 | ||
7637 | for (l = loc; l != NULL; l = l->next) | |
7638 | { | |
7639 | const char **slot; | |
7640 | const char *name = l->function_name; | |
7641 | ||
7642 | /* Allow for some names to be NULL, ignore them. */ | |
7643 | if (name == NULL) | |
7644 | continue; | |
7645 | ||
7646 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7647 | INSERT); | |
7648 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7649 | NULL. */ | |
7650 | if (*slot != NULL) | |
7651 | { | |
7652 | htab_delete (htab); | |
7653 | return 1; | |
7654 | } | |
7655 | *slot = name; | |
7656 | } | |
7657 | ||
7658 | htab_delete (htab); | |
7659 | return 0; | |
7660 | } | |
7661 | ||
fe3f5fa8 | 7662 | static void |
0d381245 VP |
7663 | update_breakpoint_locations (struct breakpoint *b, |
7664 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7665 | { |
7666 | int i; | |
7667 | char *s; | |
0d381245 VP |
7668 | struct bp_location *existing_locations = b->loc; |
7669 | ||
7670 | /* If there's no new locations, and all existing locations | |
7671 | are pending, don't do anything. This optimizes | |
7672 | the common case where all locations are in the same | |
7673 | shared library, that was unloaded. We'd like to | |
7674 | retain the location, so that when the library | |
7675 | is loaded again, we don't loose the enabled/disabled | |
7676 | status of the individual locations. */ | |
7677 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7678 | return; |
7679 | ||
fe3f5fa8 VP |
7680 | b->loc = NULL; |
7681 | ||
0d381245 | 7682 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7683 | { |
0d381245 | 7684 | struct bp_location *new_loc = |
39d61571 | 7685 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7686 | |
0d381245 VP |
7687 | /* Reparse conditions, they might contain references to the |
7688 | old symtab. */ | |
7689 | if (b->cond_string != NULL) | |
7690 | { | |
7691 | struct gdb_exception e; | |
fe3f5fa8 | 7692 | |
0d381245 VP |
7693 | s = b->cond_string; |
7694 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7695 | { | |
7696 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7697 | 0); | |
7698 | } | |
7699 | if (e.reason < 0) | |
7700 | { | |
7701 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7702 | b->number, e.message); | |
7703 | new_loc->enabled = 0; | |
7704 | } | |
7705 | } | |
fe3f5fa8 | 7706 | |
0d381245 VP |
7707 | if (b->source_file != NULL) |
7708 | xfree (b->source_file); | |
7709 | if (sals.sals[i].symtab == NULL) | |
7710 | b->source_file = NULL; | |
7711 | else | |
1b36a34b | 7712 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 7713 | |
0d381245 VP |
7714 | if (b->line_number == 0) |
7715 | b->line_number = sals.sals[i].line; | |
7716 | } | |
fe3f5fa8 | 7717 | |
514f746b AR |
7718 | /* Update locations of permanent breakpoints. */ |
7719 | if (b->enable_state == bp_permanent) | |
7720 | make_breakpoint_permanent (b); | |
7721 | ||
0d381245 VP |
7722 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7723 | { | |
7724 | struct bp_location *e = existing_locations; | |
776592bf DE |
7725 | /* If there are multiple breakpoints with the same function name, |
7726 | e.g. for inline functions, comparing function names won't work. | |
7727 | Instead compare pc addresses; this is just a heuristic as things | |
7728 | may have moved, but in practice it gives the correct answer | |
7729 | often enough until a better solution is found. */ | |
7730 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7731 | ||
0d381245 VP |
7732 | for (; e; e = e->next) |
7733 | { | |
7734 | if (!e->enabled && e->function_name) | |
7735 | { | |
7736 | struct bp_location *l = b->loc; | |
776592bf DE |
7737 | if (have_ambiguous_names) |
7738 | { | |
7739 | for (; l; l = l->next) | |
7740 | if (e->address == l->address) | |
7741 | { | |
7742 | l->enabled = 0; | |
7743 | break; | |
7744 | } | |
7745 | } | |
7746 | else | |
7747 | { | |
7748 | for (; l; l = l->next) | |
7749 | if (l->function_name | |
7750 | && strcmp (e->function_name, l->function_name) == 0) | |
7751 | { | |
7752 | l->enabled = 0; | |
7753 | break; | |
7754 | } | |
7755 | } | |
0d381245 VP |
7756 | } |
7757 | } | |
7758 | } | |
fe3f5fa8 | 7759 | |
b60e7edf | 7760 | update_global_location_list (1); |
fe3f5fa8 VP |
7761 | } |
7762 | ||
7763 | ||
c906108c SS |
7764 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7765 | The value we return ends up being the return value from catch_errors. | |
7766 | Unused in this case. */ | |
7767 | ||
7768 | static int | |
4efb68b1 | 7769 | breakpoint_re_set_one (void *bint) |
c906108c | 7770 | { |
53a5351d JM |
7771 | /* get past catch_errs */ |
7772 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7773 | struct value *mark; |
7774 | int i; | |
fe3f5fa8 VP |
7775 | int not_found = 0; |
7776 | int *not_found_ptr = ¬_found; | |
7777 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7778 | struct symtabs_and_lines expanded; |
c906108c | 7779 | char *s; |
b5de0fa7 | 7780 | enum enable_state save_enable; |
fe3f5fa8 | 7781 | struct gdb_exception e; |
f7545552 | 7782 | struct cleanup *cleanups; |
c906108c SS |
7783 | |
7784 | switch (b->type) | |
7785 | { | |
7786 | case bp_none: | |
8a3fe4f8 | 7787 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7788 | b->number); |
c906108c SS |
7789 | return 0; |
7790 | case bp_breakpoint: | |
7791 | case bp_hardware_breakpoint: | |
1042e4c0 | 7792 | case bp_tracepoint: |
c906108c SS |
7793 | if (b->addr_string == NULL) |
7794 | { | |
7795 | /* Anything without a string can't be re-set. */ | |
7796 | delete_breakpoint (b); | |
7797 | return 0; | |
7798 | } | |
c906108c SS |
7799 | |
7800 | set_language (b->language); | |
7801 | input_radix = b->input_radix; | |
7802 | s = b->addr_string; | |
fe3f5fa8 | 7803 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7804 | { |
fe3f5fa8 VP |
7805 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7806 | not_found_ptr); | |
7807 | } | |
7808 | if (e.reason < 0) | |
7809 | { | |
7810 | int not_found_and_ok = 0; | |
7811 | /* For pending breakpoints, it's expected that parsing | |
7812 | will fail until the right shared library is loaded. | |
7813 | User has already told to create pending breakpoints and | |
7814 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7815 | state, then user already saw the message about that breakpoint | |
7816 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7817 | if (not_found |
7818 | && (b->condition_not_parsed | |
7819 | || (b->loc && b->loc->shlib_disabled) | |
7820 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7821 | not_found_and_ok = 1; |
7822 | ||
7823 | if (!not_found_and_ok) | |
c906108c | 7824 | { |
fe3f5fa8 VP |
7825 | /* We surely don't want to warn about the same breakpoint |
7826 | 10 times. One solution, implemented here, is disable | |
7827 | the breakpoint on error. Another solution would be to | |
7828 | have separate 'warning emitted' flag. Since this | |
7829 | happens only when a binary has changed, I don't know | |
7830 | which approach is better. */ | |
7831 | b->enable_state = bp_disabled; | |
7832 | throw_exception (e); | |
c906108c | 7833 | } |
fe3f5fa8 | 7834 | } |
c906108c | 7835 | |
fe3f5fa8 VP |
7836 | if (not_found) |
7837 | break; | |
7838 | ||
7839 | gdb_assert (sals.nelts == 1); | |
7840 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7841 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7842 | { |
7843 | char *cond_string = 0; | |
7844 | int thread = -1; | |
4a306c9a JB |
7845 | int task = 0; |
7846 | ||
fe3f5fa8 | 7847 | find_condition_and_thread (s, sals.sals[0].pc, |
4a306c9a | 7848 | &cond_string, &thread, &task); |
fe3f5fa8 VP |
7849 | if (cond_string) |
7850 | b->cond_string = cond_string; | |
7851 | b->thread = thread; | |
4a306c9a | 7852 | b->task = task; |
0d381245 | 7853 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7854 | } |
ed0616c6 | 7855 | expanded = expand_line_sal_maybe (sals.sals[0]); |
f7545552 | 7856 | cleanups = make_cleanup (xfree, sals.sals); |
ed0616c6 | 7857 | update_breakpoint_locations (b, expanded); |
f7545552 | 7858 | do_cleanups (cleanups); |
c906108c SS |
7859 | break; |
7860 | ||
7861 | case bp_watchpoint: | |
7862 | case bp_hardware_watchpoint: | |
7863 | case bp_read_watchpoint: | |
7864 | case bp_access_watchpoint: | |
0b3de036 VP |
7865 | /* Watchpoint can be either on expression using entirely global variables, |
7866 | or it can be on local variables. | |
7867 | ||
7868 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7869 | across program restarts. Since they can use variables from shared | |
7870 | libraries, we need to reparse expression as libraries are loaded | |
7871 | and unloaded. | |
7872 | ||
7873 | Watchpoints on local variables can also change meaning as result | |
7874 | of solib event. For example, if a watchpoint uses both a local and | |
7875 | a global variables in expression, it's a local watchpoint, but | |
7876 | unloading of a shared library will make the expression invalid. | |
7877 | This is not a very common use case, but we still re-evaluate | |
7878 | expression, to avoid surprises to the user. | |
7879 | ||
7880 | Note that for local watchpoints, we re-evaluate it only if | |
7881 | watchpoints frame id is still valid. If it's not, it means | |
7882 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7883 | I'm not sure we'll ever be called in this case. | |
7884 | ||
7885 | If a local watchpoint's frame id is still valid, then | |
7886 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7887 | ||
7888 | Don't do anything about disabled watchpoints, since they will | |
7889 | be reevaluated again when enabled. */ | |
a5606eee | 7890 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7891 | break; |
c5aa993b JM |
7892 | /* We needn't really do anything to reset these, since the mask |
7893 | that requests them is unaffected by e.g., new libraries being | |
7894 | loaded. */ | |
ce78b96d | 7895 | case bp_catchpoint: |
c906108c | 7896 | break; |
c5aa993b | 7897 | |
c906108c | 7898 | default: |
a3f17187 | 7899 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 7900 | /* fall through */ |
0fd8e87f UW |
7901 | /* Delete overlay event and longjmp master breakpoints; they will be |
7902 | reset later by breakpoint_re_set. */ | |
1900040c | 7903 | case bp_overlay_event: |
0fd8e87f | 7904 | case bp_longjmp_master: |
c906108c SS |
7905 | delete_breakpoint (b); |
7906 | break; | |
7907 | ||
c5aa993b JM |
7908 | /* This breakpoint is special, it's set up when the inferior |
7909 | starts and we really don't want to touch it. */ | |
c906108c SS |
7910 | case bp_shlib_event: |
7911 | ||
c4093a6a JM |
7912 | /* Like bp_shlib_event, this breakpoint type is special. |
7913 | Once it is set up, we do not want to touch it. */ | |
7914 | case bp_thread_event: | |
7915 | ||
c5aa993b JM |
7916 | /* Keep temporary breakpoints, which can be encountered when we step |
7917 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7918 | Otherwise these should have been blown away via the cleanup chain | |
7919 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7920 | case bp_until: |
7921 | case bp_finish: | |
7922 | case bp_watchpoint_scope: | |
7923 | case bp_call_dummy: | |
7924 | case bp_step_resume: | |
611c83ae PA |
7925 | case bp_longjmp: |
7926 | case bp_longjmp_resume: | |
c906108c SS |
7927 | break; |
7928 | } | |
7929 | ||
7930 | return 0; | |
7931 | } | |
7932 | ||
69de3c6a | 7933 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 7934 | void |
69de3c6a | 7935 | breakpoint_re_set (void) |
c906108c SS |
7936 | { |
7937 | struct breakpoint *b, *temp; | |
7938 | enum language save_language; | |
7939 | int save_input_radix; | |
c5aa993b | 7940 | |
c906108c SS |
7941 | save_language = current_language->la_language; |
7942 | save_input_radix = input_radix; | |
7943 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7944 | { |
53a5351d | 7945 | /* Format possible error msg */ |
fe3f5fa8 | 7946 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
7947 | b->number); |
7948 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 7949 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 7950 | do_cleanups (cleanups); |
c5aa993b | 7951 | } |
c906108c SS |
7952 | set_language (save_language); |
7953 | input_radix = save_input_radix; | |
e62c965a | 7954 | |
69de3c6a | 7955 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
7956 | create_longjmp_master_breakpoint ("longjmp"); |
7957 | create_longjmp_master_breakpoint ("_longjmp"); | |
7958 | create_longjmp_master_breakpoint ("siglongjmp"); | |
7959 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
7960 | } |
7961 | \f | |
c906108c SS |
7962 | /* Reset the thread number of this breakpoint: |
7963 | ||
7964 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 7965 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 7966 | void |
fba45db2 | 7967 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
7968 | { |
7969 | if (b->thread != -1) | |
7970 | { | |
39f77062 KB |
7971 | if (in_thread_list (inferior_ptid)) |
7972 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
7973 | } |
7974 | } | |
7975 | ||
03ac34d5 MS |
7976 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7977 | If from_tty is nonzero, it prints a message to that effect, | |
7978 | which ends with a period (no newline). */ | |
7979 | ||
c906108c | 7980 | void |
fba45db2 | 7981 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 7982 | { |
52f0bd74 | 7983 | struct breakpoint *b; |
c906108c SS |
7984 | |
7985 | if (count < 0) | |
7986 | count = 0; | |
7987 | ||
7988 | ALL_BREAKPOINTS (b) | |
7989 | if (b->number == bptnum) | |
c5aa993b JM |
7990 | { |
7991 | b->ignore_count = count; | |
221ea385 KS |
7992 | if (from_tty) |
7993 | { | |
7994 | if (count == 0) | |
a3f17187 | 7995 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
7996 | bptnum); |
7997 | else if (count == 1) | |
a3f17187 | 7998 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
7999 | bptnum); |
8000 | else | |
a3f17187 | 8001 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8002 | count, bptnum); |
8003 | } | |
c5aa993b | 8004 | breakpoints_changed (); |
383f836e | 8005 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8006 | return; |
8007 | } | |
c906108c | 8008 | |
8a3fe4f8 | 8009 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8010 | } |
8011 | ||
b2175913 MS |
8012 | void |
8013 | make_breakpoint_silent (struct breakpoint *b) | |
8014 | { | |
8015 | /* Silence the breakpoint. */ | |
8016 | b->silent = 1; | |
8017 | } | |
8018 | ||
c906108c SS |
8019 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8020 | ||
8021 | static void | |
fba45db2 | 8022 | ignore_command (char *args, int from_tty) |
c906108c SS |
8023 | { |
8024 | char *p = args; | |
52f0bd74 | 8025 | int num; |
c906108c SS |
8026 | |
8027 | if (p == 0) | |
e2e0b3e5 | 8028 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8029 | |
c906108c | 8030 | num = get_number (&p); |
5c44784c | 8031 | if (num == 0) |
8a3fe4f8 | 8032 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8033 | if (*p == 0) |
8a3fe4f8 | 8034 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8035 | |
8036 | set_ignore_count (num, | |
8037 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8038 | from_tty); | |
221ea385 KS |
8039 | if (from_tty) |
8040 | printf_filtered ("\n"); | |
c906108c SS |
8041 | } |
8042 | \f | |
8043 | /* Call FUNCTION on each of the breakpoints | |
8044 | whose numbers are given in ARGS. */ | |
8045 | ||
8046 | static void | |
831662b3 | 8047 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8048 | { |
52f0bd74 | 8049 | char *p = args; |
c906108c | 8050 | char *p1; |
52f0bd74 AC |
8051 | int num; |
8052 | struct breakpoint *b, *tmp; | |
11cf8741 | 8053 | int match; |
c906108c SS |
8054 | |
8055 | if (p == 0) | |
e2e0b3e5 | 8056 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8057 | |
8058 | while (*p) | |
8059 | { | |
11cf8741 | 8060 | match = 0; |
c906108c | 8061 | p1 = p; |
c5aa993b | 8062 | |
5c44784c JM |
8063 | num = get_number_or_range (&p1); |
8064 | if (num == 0) | |
c5aa993b | 8065 | { |
8a3fe4f8 | 8066 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8067 | } |
8068 | else | |
8069 | { | |
8070 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8071 | if (b->number == num) | |
8072 | { | |
8073 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8074 | match = 1; |
5c44784c JM |
8075 | function (b); |
8076 | if (related_breakpoint) | |
8077 | function (related_breakpoint); | |
11cf8741 | 8078 | break; |
5c44784c | 8079 | } |
11cf8741 | 8080 | if (match == 0) |
a3f17187 | 8081 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8082 | } |
c906108c SS |
8083 | p = p1; |
8084 | } | |
8085 | } | |
8086 | ||
0d381245 VP |
8087 | static struct bp_location * |
8088 | find_location_by_number (char *number) | |
8089 | { | |
8090 | char *dot = strchr (number, '.'); | |
8091 | char *p1; | |
8092 | int bp_num; | |
8093 | int loc_num; | |
8094 | struct breakpoint *b; | |
8095 | struct bp_location *loc; | |
8096 | ||
8097 | *dot = '\0'; | |
8098 | ||
8099 | p1 = number; | |
8100 | bp_num = get_number_or_range (&p1); | |
8101 | if (bp_num == 0) | |
8102 | error (_("Bad breakpoint number '%s'"), number); | |
8103 | ||
8104 | ALL_BREAKPOINTS (b) | |
8105 | if (b->number == bp_num) | |
8106 | { | |
8107 | break; | |
8108 | } | |
8109 | ||
8110 | if (!b || b->number != bp_num) | |
8111 | error (_("Bad breakpoint number '%s'"), number); | |
8112 | ||
8113 | p1 = dot+1; | |
8114 | loc_num = get_number_or_range (&p1); | |
8115 | if (loc_num == 0) | |
8116 | error (_("Bad breakpoint location number '%s'"), number); | |
8117 | ||
8118 | --loc_num; | |
8119 | loc = b->loc; | |
8120 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8121 | ; | |
8122 | if (!loc) | |
8123 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8124 | ||
8125 | return loc; | |
8126 | } | |
8127 | ||
8128 | ||
1900040c MS |
8129 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8130 | If from_tty is nonzero, it prints a message to that effect, | |
8131 | which ends with a period (no newline). */ | |
8132 | ||
c906108c | 8133 | void |
fba45db2 | 8134 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8135 | { |
8136 | /* Never disable a watchpoint scope breakpoint; we want to | |
8137 | hit them when we leave scope so we can delete both the | |
8138 | watchpoint and its scope breakpoint at that time. */ | |
8139 | if (bpt->type == bp_watchpoint_scope) | |
8140 | return; | |
8141 | ||
c2c6d25f | 8142 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 8143 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
8144 | return; |
8145 | ||
b5de0fa7 | 8146 | bpt->enable_state = bp_disabled; |
c906108c | 8147 | |
b60e7edf | 8148 | update_global_location_list (0); |
c906108c | 8149 | |
383f836e | 8150 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8151 | } |
8152 | ||
c906108c | 8153 | static void |
fba45db2 | 8154 | disable_command (char *args, int from_tty) |
c906108c | 8155 | { |
52f0bd74 | 8156 | struct breakpoint *bpt; |
c906108c SS |
8157 | if (args == 0) |
8158 | ALL_BREAKPOINTS (bpt) | |
8159 | switch (bpt->type) | |
c5aa993b JM |
8160 | { |
8161 | case bp_none: | |
8a3fe4f8 | 8162 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 8163 | bpt->number); |
c5aa993b JM |
8164 | continue; |
8165 | case bp_breakpoint: | |
1042e4c0 | 8166 | case bp_tracepoint: |
ce78b96d | 8167 | case bp_catchpoint: |
c5aa993b JM |
8168 | case bp_hardware_breakpoint: |
8169 | case bp_watchpoint: | |
8170 | case bp_hardware_watchpoint: | |
8171 | case bp_read_watchpoint: | |
8172 | case bp_access_watchpoint: | |
8173 | disable_breakpoint (bpt); | |
8174 | default: | |
8175 | continue; | |
8176 | } | |
0d381245 VP |
8177 | else if (strchr (args, '.')) |
8178 | { | |
8179 | struct bp_location *loc = find_location_by_number (args); | |
8180 | if (loc) | |
8181 | loc->enabled = 0; | |
b60e7edf | 8182 | update_global_location_list (0); |
0d381245 | 8183 | } |
c906108c SS |
8184 | else |
8185 | map_breakpoint_numbers (args, disable_breakpoint); | |
8186 | } | |
8187 | ||
8188 | static void | |
fba45db2 | 8189 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 8190 | { |
c906108c SS |
8191 | int target_resources_ok, other_type_used; |
8192 | struct value *mark; | |
8193 | ||
8194 | if (bpt->type == bp_hardware_breakpoint) | |
8195 | { | |
8196 | int i; | |
c5aa993b | 8197 | i = hw_breakpoint_used_count (); |
53a5351d | 8198 | target_resources_ok = |
d92524f1 | 8199 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 8200 | i + 1, 0); |
c906108c | 8201 | if (target_resources_ok == 0) |
8a3fe4f8 | 8202 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 8203 | else if (target_resources_ok < 0) |
8a3fe4f8 | 8204 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
8205 | } |
8206 | ||
059fb39f PM |
8207 | if (bpt->type == bp_watchpoint |
8208 | || bpt->type == bp_hardware_watchpoint | |
8209 | || bpt->type == bp_read_watchpoint | |
8210 | || bpt->type == bp_access_watchpoint) | |
c906108c | 8211 | { |
dde02812 ES |
8212 | struct gdb_exception e; |
8213 | ||
8214 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 8215 | { |
dde02812 | 8216 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 8217 | } |
dde02812 | 8218 | if (e.reason < 0) |
c5aa993b | 8219 | { |
dde02812 ES |
8220 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
8221 | bpt->number); | |
8222 | return; | |
c5aa993b | 8223 | } |
c906108c | 8224 | } |
0101ce28 | 8225 | |
b4c291bb KH |
8226 | if (bpt->enable_state != bp_permanent) |
8227 | bpt->enable_state = bp_enabled; | |
8228 | bpt->disposition = disposition; | |
b60e7edf | 8229 | update_global_location_list (1); |
b4c291bb KH |
8230 | breakpoints_changed (); |
8231 | ||
383f836e | 8232 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8233 | } |
8234 | ||
fe3f5fa8 | 8235 | |
c906108c | 8236 | void |
fba45db2 | 8237 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8238 | { |
8239 | do_enable_breakpoint (bpt, bpt->disposition); | |
8240 | } | |
8241 | ||
8242 | /* The enable command enables the specified breakpoints (or all defined | |
8243 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 8244 | in stopping the inferior. */ |
c906108c | 8245 | |
c906108c | 8246 | static void |
fba45db2 | 8247 | enable_command (char *args, int from_tty) |
c906108c | 8248 | { |
52f0bd74 | 8249 | struct breakpoint *bpt; |
c906108c SS |
8250 | if (args == 0) |
8251 | ALL_BREAKPOINTS (bpt) | |
8252 | switch (bpt->type) | |
c5aa993b JM |
8253 | { |
8254 | case bp_none: | |
8a3fe4f8 | 8255 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 8256 | bpt->number); |
c5aa993b JM |
8257 | continue; |
8258 | case bp_breakpoint: | |
1042e4c0 | 8259 | case bp_tracepoint: |
ce78b96d | 8260 | case bp_catchpoint: |
c5aa993b JM |
8261 | case bp_hardware_breakpoint: |
8262 | case bp_watchpoint: | |
8263 | case bp_hardware_watchpoint: | |
8264 | case bp_read_watchpoint: | |
8265 | case bp_access_watchpoint: | |
8266 | enable_breakpoint (bpt); | |
8267 | default: | |
8268 | continue; | |
8269 | } | |
0d381245 VP |
8270 | else if (strchr (args, '.')) |
8271 | { | |
8272 | struct bp_location *loc = find_location_by_number (args); | |
8273 | if (loc) | |
8274 | loc->enabled = 1; | |
b60e7edf | 8275 | update_global_location_list (1); |
0d381245 | 8276 | } |
c906108c SS |
8277 | else |
8278 | map_breakpoint_numbers (args, enable_breakpoint); | |
8279 | } | |
8280 | ||
8281 | static void | |
fba45db2 | 8282 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 8283 | { |
b5de0fa7 | 8284 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
8285 | } |
8286 | ||
c906108c | 8287 | static void |
fba45db2 | 8288 | enable_once_command (char *args, int from_tty) |
c906108c SS |
8289 | { |
8290 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
8291 | } | |
8292 | ||
8293 | static void | |
fba45db2 | 8294 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8295 | { |
b5de0fa7 | 8296 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
8297 | } |
8298 | ||
c906108c | 8299 | static void |
fba45db2 | 8300 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
8301 | { |
8302 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
8303 | } | |
8304 | \f | |
fa8d40ab JJ |
8305 | static void |
8306 | set_breakpoint_cmd (char *args, int from_tty) | |
8307 | { | |
8308 | } | |
8309 | ||
8310 | static void | |
8311 | show_breakpoint_cmd (char *args, int from_tty) | |
8312 | { | |
8313 | } | |
8314 | ||
c906108c SS |
8315 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
8316 | ||
8317 | struct symtabs_and_lines | |
fba45db2 | 8318 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
8319 | { |
8320 | struct symtabs_and_lines sals; | |
8321 | if (string == 0) | |
8a3fe4f8 | 8322 | error (_("Empty line specification.")); |
c906108c SS |
8323 | if (default_breakpoint_valid) |
8324 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
8325 | default_breakpoint_symtab, |
8326 | default_breakpoint_line, | |
68219205 | 8327 | (char ***) NULL, NULL); |
c906108c SS |
8328 | else |
8329 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 8330 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 8331 | if (*string) |
8a3fe4f8 | 8332 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
8333 | return sals; |
8334 | } | |
8181d85f DJ |
8335 | |
8336 | /* Create and insert a raw software breakpoint at PC. Return an | |
8337 | identifier, which should be used to remove the breakpoint later. | |
8338 | In general, places which call this should be using something on the | |
8339 | breakpoint chain instead; this function should be eliminated | |
8340 | someday. */ | |
8341 | ||
8342 | void * | |
a6d9a66e | 8343 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
8181d85f DJ |
8344 | { |
8345 | struct bp_target_info *bp_tgt; | |
8346 | ||
8347 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
8348 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
8349 | ||
8350 | bp_tgt->placed_address = pc; | |
a6d9a66e | 8351 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
8352 | { |
8353 | /* Could not insert the breakpoint. */ | |
8354 | xfree (bp_tgt); | |
8355 | return NULL; | |
8356 | } | |
8357 | ||
8358 | return bp_tgt; | |
8359 | } | |
8360 | ||
8361 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
8362 | ||
8363 | int | |
a6d9a66e | 8364 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
8365 | { |
8366 | struct bp_target_info *bp_tgt = bp; | |
8367 | int ret; | |
8368 | ||
a6d9a66e | 8369 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
8370 | xfree (bp_tgt); |
8371 | ||
8372 | return ret; | |
8373 | } | |
8374 | ||
8375 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
8376 | ||
8377 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 8378 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
8379 | |
8380 | /* Create and insert a breakpoint for software single step. */ | |
8381 | ||
8382 | void | |
a6d9a66e | 8383 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
8181d85f DJ |
8384 | { |
8385 | void **bpt_p; | |
8386 | ||
8387 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
8388 | { |
8389 | bpt_p = &single_step_breakpoints[0]; | |
8390 | single_step_gdbarch[0] = gdbarch; | |
8391 | } | |
8181d85f DJ |
8392 | else |
8393 | { | |
8394 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8395 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 8396 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
8397 | } |
8398 | ||
8399 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8400 | to only create the breakpoints once, and actually put them on the | |
8401 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8402 | adjust the addresses each time they were needed. Doing this requires | |
8403 | corresponding changes elsewhere where single step breakpoints are | |
8404 | handled, however. So, for now, we use this. */ | |
8405 | ||
a6d9a66e | 8406 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
8181d85f | 8407 | if (*bpt_p == NULL) |
5af949e3 UW |
8408 | error (_("Could not insert single-step breakpoint at %s"), |
8409 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
8410 | } |
8411 | ||
8412 | /* Remove and delete any breakpoints used for software single step. */ | |
8413 | ||
8414 | void | |
8415 | remove_single_step_breakpoints (void) | |
8416 | { | |
8417 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8418 | ||
8419 | /* See insert_single_step_breakpoint for more about this deprecated | |
8420 | call. */ | |
a6d9a66e UW |
8421 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
8422 | single_step_breakpoints[0]); | |
8423 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
8424 | single_step_breakpoints[0] = NULL; |
8425 | ||
8426 | if (single_step_breakpoints[1] != NULL) | |
8427 | { | |
a6d9a66e UW |
8428 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
8429 | single_step_breakpoints[1]); | |
8430 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
8431 | single_step_breakpoints[1] = NULL; |
8432 | } | |
8433 | } | |
8434 | ||
1aafd4da UW |
8435 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8436 | ||
8437 | static int | |
8438 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8439 | { | |
8440 | int i; | |
8441 | ||
8442 | for (i = 0; i < 2; i++) | |
8443 | { | |
8444 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8445 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8446 | return 1; | |
8447 | } | |
8448 | ||
8449 | return 0; | |
8450 | } | |
8451 | ||
1042e4c0 SS |
8452 | /* Tracepoint-specific operations. */ |
8453 | ||
8454 | /* Set tracepoint count to NUM. */ | |
8455 | static void | |
8456 | set_tracepoint_count (int num) | |
8457 | { | |
8458 | tracepoint_count = num; | |
4fa62494 | 8459 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
8460 | } |
8461 | ||
8462 | void | |
8463 | trace_command (char *arg, int from_tty) | |
8464 | { | |
a6d9a66e UW |
8465 | break_command_really (get_current_arch (), |
8466 | arg, | |
1042e4c0 SS |
8467 | NULL, 0, 1 /* parse arg */, |
8468 | 0 /* tempflag */, 0 /* hardwareflag */, | |
8469 | 1 /* traceflag */, | |
8470 | 0 /* Ignore count */, | |
8471 | pending_break_support, | |
8472 | NULL, | |
8473 | from_tty, | |
8474 | 1 /* enabled */); | |
8475 | set_tracepoint_count (breakpoint_count); | |
8476 | } | |
8477 | ||
8478 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
8479 | omitted. */ | |
8480 | ||
8481 | static void | |
8482 | tracepoints_info (char *tpnum_exp, int from_tty) | |
8483 | { | |
8484 | struct breakpoint *b; | |
8485 | int tps_to_list = 0; | |
8486 | ||
8487 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
8488 | if (tpnum_exp == 0) | |
8489 | { | |
8490 | ALL_TRACEPOINTS (b) | |
8491 | { | |
8492 | if (b->number >= 0) | |
8493 | { | |
8494 | tps_to_list = 1; | |
8495 | break; | |
8496 | } | |
8497 | } | |
8498 | if (!tps_to_list) | |
8499 | { | |
8500 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
8501 | return; | |
8502 | } | |
8503 | } | |
8504 | ||
8505 | /* Otherwise be the same as "info break". */ | |
8506 | breakpoints_info (tpnum_exp, from_tty); | |
8507 | } | |
8508 | ||
8509 | /* The 'enable trace' command enables tracepoints. | |
8510 | Not supported by all targets. */ | |
8511 | static void | |
8512 | enable_trace_command (char *args, int from_tty) | |
8513 | { | |
8514 | enable_command (args, from_tty); | |
8515 | } | |
8516 | ||
8517 | /* The 'disable trace' command disables tracepoints. | |
8518 | Not supported by all targets. */ | |
8519 | static void | |
8520 | disable_trace_command (char *args, int from_tty) | |
8521 | { | |
8522 | disable_command (args, from_tty); | |
8523 | } | |
8524 | ||
8525 | /* Remove a tracepoint (or all if no argument) */ | |
8526 | static void | |
8527 | delete_trace_command (char *arg, int from_tty) | |
8528 | { | |
8529 | struct breakpoint *b, *temp; | |
8530 | ||
8531 | dont_repeat (); | |
8532 | ||
8533 | if (arg == 0) | |
8534 | { | |
8535 | int breaks_to_delete = 0; | |
8536 | ||
8537 | /* Delete all breakpoints if no argument. | |
8538 | Do not delete internal or call-dummy breakpoints, these | |
8539 | have to be deleted with an explicit breakpoint number argument. */ | |
8540 | ALL_TRACEPOINTS (b) | |
8541 | { | |
8542 | if (b->number >= 0) | |
8543 | { | |
8544 | breaks_to_delete = 1; | |
8545 | break; | |
8546 | } | |
8547 | } | |
8548 | ||
8549 | /* Ask user only if there are some breakpoints to delete. */ | |
8550 | if (!from_tty | |
8551 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
8552 | { | |
8553 | ALL_BREAKPOINTS_SAFE (b, temp) | |
8554 | { | |
059fb39f PM |
8555 | if (b->type == bp_tracepoint |
8556 | && b->number >= 0) | |
1042e4c0 SS |
8557 | delete_breakpoint (b); |
8558 | } | |
8559 | } | |
8560 | } | |
8561 | else | |
8562 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8563 | } | |
8564 | ||
8565 | /* Set passcount for tracepoint. | |
8566 | ||
8567 | First command argument is passcount, second is tracepoint number. | |
8568 | If tracepoint number omitted, apply to most recently defined. | |
8569 | Also accepts special argument "all". */ | |
8570 | ||
8571 | static void | |
8572 | trace_pass_command (char *args, int from_tty) | |
8573 | { | |
8574 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
8575 | unsigned int count; | |
8576 | int all = 0; | |
8577 | ||
8578 | if (args == 0 || *args == 0) | |
8579 | error (_("passcount command requires an argument (count + optional TP num)")); | |
8580 | ||
8581 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
8582 | ||
8583 | while (*args && isspace ((int) *args)) | |
8584 | args++; | |
8585 | ||
8586 | if (*args && strncasecmp (args, "all", 3) == 0) | |
8587 | { | |
8588 | args += 3; /* Skip special argument "all". */ | |
8589 | all = 1; | |
8590 | if (*args) | |
8591 | error (_("Junk at end of arguments.")); | |
8592 | } | |
8593 | else | |
8594 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
8595 | ||
8596 | do | |
8597 | { | |
8598 | if (t1) | |
8599 | { | |
8600 | ALL_TRACEPOINTS (t2) | |
8601 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
8602 | { | |
8603 | t2->pass_count = count; | |
8604 | observer_notify_tracepoint_modified (t2->number); | |
8605 | if (from_tty) | |
8606 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
8607 | t2->number, count); | |
8608 | } | |
8609 | if (! all && *args) | |
8610 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
8611 | } | |
8612 | } | |
8613 | while (*args); | |
8614 | } | |
8615 | ||
8616 | struct breakpoint * | |
8617 | get_tracepoint (int num) | |
8618 | { | |
8619 | struct breakpoint *t; | |
8620 | ||
8621 | ALL_TRACEPOINTS (t) | |
8622 | if (t->number == num) | |
8623 | return t; | |
8624 | ||
8625 | return NULL; | |
8626 | } | |
8627 | ||
8628 | /* Utility: parse a tracepoint number and look it up in the list. | |
8629 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
8630 | if OPTIONAL_P is true, then if the argument is missing, the most | |
8631 | recent tracepoint (tracepoint_count) is returned. */ | |
8632 | struct breakpoint * | |
8633 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
8634 | { | |
8635 | extern int tracepoint_count; | |
8636 | struct breakpoint *t; | |
8637 | int tpnum; | |
8638 | char *instring = arg == NULL ? NULL : *arg; | |
8639 | ||
8640 | if (arg == NULL || *arg == NULL || ! **arg) | |
8641 | { | |
8642 | if (optional_p) | |
8643 | tpnum = tracepoint_count; | |
8644 | else | |
8645 | error_no_arg (_("tracepoint number")); | |
8646 | } | |
8647 | else | |
8648 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
8649 | ||
8650 | if (tpnum <= 0) | |
8651 | { | |
8652 | if (instring && *instring) | |
8653 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
8654 | instring); | |
8655 | else | |
8656 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
8657 | return NULL; | |
8658 | } | |
8659 | ||
8660 | ALL_TRACEPOINTS (t) | |
8661 | if (t->number == tpnum) | |
8662 | { | |
8663 | return t; | |
8664 | } | |
8665 | ||
8666 | /* FIXME: if we are in the middle of a range we don't want to give | |
8667 | a message. The current interface to get_number_or_range doesn't | |
8668 | allow us to discover this. */ | |
8669 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
8670 | return NULL; | |
8671 | } | |
8672 | ||
8673 | /* save-tracepoints command */ | |
8674 | static void | |
8675 | tracepoint_save_command (char *args, int from_tty) | |
8676 | { | |
8677 | struct breakpoint *tp; | |
8678 | int any_tp = 0; | |
8679 | struct action_line *line; | |
8680 | FILE *fp; | |
8681 | char *i1 = " ", *i2 = " "; | |
8682 | char *indent, *actionline, *pathname; | |
8683 | char tmp[40]; | |
8684 | struct cleanup *cleanup; | |
8685 | ||
8686 | if (args == 0 || *args == 0) | |
8687 | error (_("Argument required (file name in which to save tracepoints)")); | |
8688 | ||
8689 | /* See if we have anything to save. */ | |
8690 | ALL_TRACEPOINTS (tp) | |
8691 | { | |
8692 | any_tp = 1; | |
8693 | break; | |
8694 | } | |
8695 | if (!any_tp) | |
8696 | { | |
8697 | warning (_("save-tracepoints: no tracepoints to save.")); | |
8698 | return; | |
8699 | } | |
8700 | ||
8701 | pathname = tilde_expand (args); | |
8702 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
8703 | fp = fopen (pathname, "w"); |
8704 | if (!fp) | |
1042e4c0 SS |
8705 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
8706 | args, safe_strerror (errno)); | |
8707 | make_cleanup_fclose (fp); | |
8708 | ||
8709 | ALL_TRACEPOINTS (tp) | |
8710 | { | |
8711 | if (tp->addr_string) | |
8712 | fprintf (fp, "trace %s\n", tp->addr_string); | |
8713 | else | |
8714 | { | |
8715 | sprintf_vma (tmp, tp->loc->address); | |
8716 | fprintf (fp, "trace *0x%s\n", tmp); | |
8717 | } | |
8718 | ||
8719 | if (tp->pass_count) | |
8720 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
8721 | ||
8722 | if (tp->actions) | |
8723 | { | |
8724 | fprintf (fp, " actions\n"); | |
8725 | indent = i1; | |
8726 | for (line = tp->actions; line; line = line->next) | |
8727 | { | |
8728 | struct cmd_list_element *cmd; | |
8729 | ||
8730 | QUIT; /* allow user to bail out with ^C */ | |
8731 | actionline = line->action; | |
8732 | while (isspace ((int) *actionline)) | |
8733 | actionline++; | |
8734 | ||
8735 | fprintf (fp, "%s%s\n", indent, actionline); | |
8736 | if (*actionline != '#') /* skip for comment lines */ | |
8737 | { | |
8738 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
8739 | if (cmd == 0) | |
8740 | error (_("Bad action list item: %s"), actionline); | |
8741 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
8742 | indent = i2; | |
8743 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
8744 | indent = i1; | |
8745 | } | |
8746 | } | |
8747 | } | |
8748 | } | |
8749 | do_cleanups (cleanup); | |
8750 | if (from_tty) | |
8751 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
8752 | return; | |
8753 | } | |
8754 | ||
8755 | /* Create a vector of all tracepoints. */ | |
8756 | ||
8757 | VEC(breakpoint_p) * | |
8758 | all_tracepoints () | |
8759 | { | |
8760 | VEC(breakpoint_p) *tp_vec = 0; | |
8761 | struct breakpoint *tp; | |
8762 | ||
8763 | ALL_TRACEPOINTS (tp) | |
8764 | { | |
8765 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
8766 | } | |
8767 | ||
8768 | return tp_vec; | |
8769 | } | |
8770 | ||
c906108c | 8771 | \f |
31e2b00f AS |
8772 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8773 | It is defined as a macro to prevent duplication. | |
8774 | COMMAND should be a string constant containing the name of the command. */ | |
8775 | #define BREAK_ARGS_HELP(command) \ | |
8776 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8777 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8778 | If a line number is specified, break at start of code for that line.\n\ | |
8779 | If a function is specified, break at start of code for that function.\n\ | |
8780 | If an address is specified, break at that exact address.\n\ | |
8781 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8782 | This is useful for breaking on return to a stack frame.\n\ | |
8783 | \n\ | |
8784 | THREADNUM is the number from \"info threads\".\n\ | |
8785 | CONDITION is a boolean expression.\n\ | |
8786 | \n\ | |
8787 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8788 | \n\ | |
8789 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8790 | ||
44feb3ce TT |
8791 | /* List of subcommands for "catch". */ |
8792 | static struct cmd_list_element *catch_cmdlist; | |
8793 | ||
8794 | /* List of subcommands for "tcatch". */ | |
8795 | static struct cmd_list_element *tcatch_cmdlist; | |
8796 | ||
8797 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8798 | lists, and pass some additional user data to the command function. */ | |
8799 | static void | |
8800 | add_catch_command (char *name, char *docstring, | |
8801 | void (*sfunc) (char *args, int from_tty, | |
8802 | struct cmd_list_element *command), | |
8803 | void *user_data_catch, | |
8804 | void *user_data_tcatch) | |
8805 | { | |
8806 | struct cmd_list_element *command; | |
8807 | ||
8808 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8809 | &catch_cmdlist); | |
8810 | set_cmd_sfunc (command, sfunc); | |
8811 | set_cmd_context (command, user_data_catch); | |
8812 | ||
8813 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8814 | &tcatch_cmdlist); | |
8815 | set_cmd_sfunc (command, sfunc); | |
8816 | set_cmd_context (command, user_data_tcatch); | |
8817 | } | |
8818 | ||
c906108c | 8819 | void |
fba45db2 | 8820 | _initialize_breakpoint (void) |
c906108c | 8821 | { |
fa8d40ab JJ |
8822 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8823 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8824 | struct cmd_list_element *c; |
8825 | ||
84acb35a | 8826 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8827 | |
c906108c SS |
8828 | breakpoint_chain = 0; |
8829 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8830 | before a breakpoint is set. */ | |
8831 | breakpoint_count = 0; | |
8832 | ||
1042e4c0 SS |
8833 | tracepoint_count = 0; |
8834 | ||
1bedd215 AC |
8835 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8836 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8837 | Usage is `ignore N COUNT'.")); | |
c906108c | 8838 | if (xdb_commands) |
c5aa993b | 8839 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8840 | |
1bedd215 AC |
8841 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8842 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8843 | Give breakpoint number as argument after \"commands\".\n\ |
8844 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8845 | The commands themselves follow starting on the next line.\n\ | |
8846 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8847 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8848 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8849 | |
1bedd215 AC |
8850 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8851 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8852 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8853 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8854 | |
1bedd215 | 8855 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8856 | Set a temporary breakpoint.\n\ |
c906108c SS |
8857 | Like \"break\" except the breakpoint is only temporary,\n\ |
8858 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8859 | by using \"enable delete\" on the breakpoint number.\n\ |
8860 | \n" | |
8861 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8862 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8863 | |
1bedd215 | 8864 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8865 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8866 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8867 | some target hardware may not have this support.\n\ |
8868 | \n" | |
8869 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8870 | set_cmd_completer (c, location_completer); |
c906108c | 8871 | |
1bedd215 | 8872 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8873 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8874 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8875 | so it will be deleted when hit.\n\ |
8876 | \n" | |
8877 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8878 | set_cmd_completer (c, location_completer); |
c906108c | 8879 | |
1bedd215 AC |
8880 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8881 | Enable some breakpoints.\n\ | |
c906108c SS |
8882 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8883 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8884 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8885 | With a subcommand you can enable temporarily."), |
c906108c SS |
8886 | &enablelist, "enable ", 1, &cmdlist); |
8887 | if (xdb_commands) | |
1bedd215 AC |
8888 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8889 | Enable some breakpoints.\n\ | |
c906108c SS |
8890 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8891 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8892 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8893 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8894 | |
8895 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8896 | ||
1bedd215 AC |
8897 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
8898 | Enable some breakpoints.\n\ | |
c906108c SS |
8899 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8900 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8901 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 8902 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 8903 | |
1a966eab AC |
8904 | add_cmd ("once", no_class, enable_once_command, _("\ |
8905 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8906 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8907 | &enablebreaklist); |
8908 | ||
1a966eab AC |
8909 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8910 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8911 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8912 | &enablebreaklist); |
8913 | ||
1a966eab AC |
8914 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8915 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8916 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8917 | &enablelist); |
8918 | ||
1a966eab AC |
8919 | add_cmd ("once", no_class, enable_once_command, _("\ |
8920 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8921 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8922 | &enablelist); |
8923 | ||
1bedd215 AC |
8924 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
8925 | Disable some breakpoints.\n\ | |
c906108c SS |
8926 | Arguments are breakpoint numbers with spaces in between.\n\ |
8927 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8928 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
8929 | &disablelist, "disable ", 1, &cmdlist); |
8930 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
8931 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
8932 | if (xdb_commands) | |
1bedd215 AC |
8933 | add_com ("sb", class_breakpoint, disable_command, _("\ |
8934 | Disable some breakpoints.\n\ | |
c906108c SS |
8935 | Arguments are breakpoint numbers with spaces in between.\n\ |
8936 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8937 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 8938 | |
1a966eab AC |
8939 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
8940 | Disable some breakpoints.\n\ | |
c906108c SS |
8941 | Arguments are breakpoint numbers with spaces in between.\n\ |
8942 | To disable all breakpoints, give no argument.\n\ | |
8943 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 8944 | This command may be abbreviated \"disable\"."), |
c906108c SS |
8945 | &disablelist); |
8946 | ||
1bedd215 AC |
8947 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
8948 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8949 | Arguments are breakpoint numbers with spaces in between.\n\ |
8950 | To delete all breakpoints, give no argument.\n\ | |
8951 | \n\ | |
8952 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 8953 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
8954 | &deletelist, "delete ", 1, &cmdlist); |
8955 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 8956 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 8957 | if (xdb_commands) |
1bedd215 AC |
8958 | add_com ("db", class_breakpoint, delete_command, _("\ |
8959 | Delete some breakpoints.\n\ | |
c906108c | 8960 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 8961 | To delete all breakpoints, give no argument.\n")); |
c906108c | 8962 | |
1a966eab AC |
8963 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
8964 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
8965 | Arguments are breakpoint numbers with spaces in between.\n\ |
8966 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 8967 | This command may be abbreviated \"delete\"."), |
c906108c SS |
8968 | &deletelist); |
8969 | ||
1bedd215 AC |
8970 | add_com ("clear", class_breakpoint, clear_command, _("\ |
8971 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
8972 | Argument may be line number, function name, or \"*\" and an address.\n\ |
8973 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
8974 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
8975 | If an address is specified, breakpoints at that address are cleared.\n\ |
8976 | \n\ | |
8977 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
8978 | is executing in.\n\ |
8979 | \n\ | |
1bedd215 | 8980 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 8981 | |
1bedd215 | 8982 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
8983 | Set breakpoint at specified line or function.\n" |
8984 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 8985 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8986 | |
c906108c SS |
8987 | add_com_alias ("b", "break", class_run, 1); |
8988 | add_com_alias ("br", "break", class_run, 1); | |
8989 | add_com_alias ("bre", "break", class_run, 1); | |
8990 | add_com_alias ("brea", "break", class_run, 1); | |
8991 | ||
7681d515 PM |
8992 | if (xdb_commands) |
8993 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
8994 | |
8995 | if (dbx_commands) | |
8996 | { | |
1bedd215 AC |
8997 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
8998 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
8999 | &stoplist, "stop ", 1, &cmdlist); |
9000 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 9001 | _("Break in function or address."), &stoplist); |
c5aa993b | 9002 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 9003 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
9004 | add_com ("status", class_info, breakpoints_info, _("\ |
9005 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9006 | The \"Type\" column indicates one of:\n\ |
9007 | \tbreakpoint - normal breakpoint\n\ | |
9008 | \twatchpoint - watchpoint\n\ | |
9009 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9010 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9011 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9012 | address and file/line number respectively.\n\ |
9013 | \n\ | |
9014 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9015 | are set to the address of the last breakpoint listed unless the command\n\ |
9016 | is prefixed with \"server \".\n\n\ | |
c906108c | 9017 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9018 | breakpoint set.")); |
c906108c SS |
9019 | } |
9020 | ||
1bedd215 AC |
9021 | add_info ("breakpoints", breakpoints_info, _("\ |
9022 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9023 | The \"Type\" column indicates one of:\n\ |
9024 | \tbreakpoint - normal breakpoint\n\ | |
9025 | \twatchpoint - watchpoint\n\ | |
9026 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9027 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9028 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9029 | address and file/line number respectively.\n\ |
9030 | \n\ | |
9031 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9032 | are set to the address of the last breakpoint listed unless the command\n\ |
9033 | is prefixed with \"server \".\n\n\ | |
c906108c | 9034 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9035 | breakpoint set.")); |
c906108c SS |
9036 | |
9037 | if (xdb_commands) | |
1bedd215 AC |
9038 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9039 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9040 | The \"Type\" column indicates one of:\n\ |
9041 | \tbreakpoint - normal breakpoint\n\ | |
9042 | \twatchpoint - watchpoint\n\ | |
9043 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9044 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9045 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9046 | address and file/line number respectively.\n\ |
9047 | \n\ | |
9048 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9049 | are set to the address of the last breakpoint listed unless the command\n\ |
9050 | is prefixed with \"server \".\n\n\ | |
c906108c | 9051 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9052 | breakpoint set.")); |
c906108c | 9053 | |
1a966eab AC |
9054 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9055 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9056 | The \"Type\" column indicates one of:\n\ |
9057 | \tbreakpoint - normal breakpoint\n\ | |
9058 | \twatchpoint - watchpoint\n\ | |
9059 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9060 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9061 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9062 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9063 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9064 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9065 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
9066 | address and file/line number respectively.\n\ |
9067 | \n\ | |
9068 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9069 | are set to the address of the last breakpoint listed unless the command\n\ |
9070 | is prefixed with \"server \".\n\n\ | |
c906108c | 9071 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 9072 | breakpoint set."), |
c906108c SS |
9073 | &maintenanceinfolist); |
9074 | ||
44feb3ce TT |
9075 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
9076 | Set catchpoints to catch events."), | |
9077 | &catch_cmdlist, "catch ", | |
9078 | 0/*allow-unknown*/, &cmdlist); | |
9079 | ||
9080 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
9081 | Set temporary catchpoints to catch events."), | |
9082 | &tcatch_cmdlist, "tcatch ", | |
9083 | 0/*allow-unknown*/, &cmdlist); | |
9084 | ||
9085 | /* Add catch and tcatch sub-commands. */ | |
9086 | add_catch_command ("catch", _("\ | |
9087 | Catch an exception, when caught.\n\ | |
9088 | With an argument, catch only exceptions with the given name."), | |
9089 | catch_catch_command, | |
9090 | CATCH_PERMANENT, | |
9091 | CATCH_TEMPORARY); | |
9092 | add_catch_command ("throw", _("\ | |
9093 | Catch an exception, when thrown.\n\ | |
9094 | With an argument, catch only exceptions with the given name."), | |
9095 | catch_throw_command, | |
9096 | CATCH_PERMANENT, | |
9097 | CATCH_TEMPORARY); | |
9098 | add_catch_command ("fork", _("Catch calls to fork."), | |
9099 | catch_fork_command_1, | |
9100 | (void *) (uintptr_t) catch_fork_permanent, | |
9101 | (void *) (uintptr_t) catch_fork_temporary); | |
9102 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
9103 | catch_fork_command_1, | |
9104 | (void *) (uintptr_t) catch_vfork_permanent, | |
9105 | (void *) (uintptr_t) catch_vfork_temporary); | |
9106 | add_catch_command ("exec", _("Catch calls to exec."), | |
9107 | catch_exec_command_1, | |
9108 | CATCH_PERMANENT, | |
9109 | CATCH_TEMPORARY); | |
44feb3ce TT |
9110 | add_catch_command ("exception", _("\ |
9111 | Catch Ada exceptions, when raised.\n\ | |
9112 | With an argument, catch only exceptions with the given name."), | |
9113 | catch_ada_exception_command, | |
9114 | CATCH_PERMANENT, | |
9115 | CATCH_TEMPORARY); | |
9116 | add_catch_command ("assert", _("\ | |
9117 | Catch failed Ada assertions, when raised.\n\ | |
9118 | With an argument, catch only exceptions with the given name."), | |
9119 | catch_assert_command, | |
9120 | CATCH_PERMANENT, | |
9121 | CATCH_TEMPORARY); | |
c5aa993b | 9122 | |
1bedd215 AC |
9123 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
9124 | Set a watchpoint for an expression.\n\ | |
c906108c | 9125 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9126 | an expression changes.")); |
65d12d83 | 9127 | set_cmd_completer (c, expression_completer); |
c906108c | 9128 | |
1bedd215 AC |
9129 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
9130 | Set a read watchpoint for an expression.\n\ | |
c906108c | 9131 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9132 | an expression is read.")); |
65d12d83 | 9133 | set_cmd_completer (c, expression_completer); |
c906108c | 9134 | |
1bedd215 AC |
9135 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
9136 | Set a watchpoint for an expression.\n\ | |
c906108c | 9137 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9138 | an expression is either read or written.")); |
65d12d83 | 9139 | set_cmd_completer (c, expression_completer); |
c906108c SS |
9140 | |
9141 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 9142 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
9143 | |
9144 | ||
920d2a44 AC |
9145 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
9146 | respond to changes - contrary to the description. */ | |
85c07804 AC |
9147 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
9148 | &can_use_hw_watchpoints, _("\ | |
9149 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
9150 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
9151 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
9152 | such is available. (However, any hardware watchpoints that were\n\ | |
9153 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
9154 | hardware.)"), |
9155 | NULL, | |
920d2a44 | 9156 | show_can_use_hw_watchpoints, |
85c07804 | 9157 | &setlist, &showlist); |
c906108c SS |
9158 | |
9159 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 9160 | |
1042e4c0 SS |
9161 | /* Tracepoint manipulation commands. */ |
9162 | ||
9163 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
9164 | Set a tracepoint at specified line or function.\n\ | |
9165 | \n" | |
9166 | BREAK_ARGS_HELP ("trace") "\n\ | |
9167 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
9168 | set_cmd_completer (c, location_completer); | |
9169 | ||
9170 | add_com_alias ("tp", "trace", class_alias, 0); | |
9171 | add_com_alias ("tr", "trace", class_alias, 1); | |
9172 | add_com_alias ("tra", "trace", class_alias, 1); | |
9173 | add_com_alias ("trac", "trace", class_alias, 1); | |
9174 | ||
9175 | add_info ("tracepoints", tracepoints_info, _("\ | |
9176 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
9177 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
9178 | last tracepoint set.")); | |
9179 | ||
9180 | add_info_alias ("tp", "tracepoints", 1); | |
9181 | ||
9182 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
9183 | Delete specified tracepoints.\n\ | |
9184 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9185 | No argument means delete all tracepoints."), | |
9186 | &deletelist); | |
9187 | ||
9188 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
9189 | Disable specified tracepoints.\n\ | |
9190 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9191 | No argument means disable all tracepoints."), | |
9192 | &disablelist); | |
9193 | deprecate_cmd (c, "disable"); | |
9194 | ||
9195 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
9196 | Enable specified tracepoints.\n\ | |
9197 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9198 | No argument means enable all tracepoints."), | |
9199 | &enablelist); | |
9200 | deprecate_cmd (c, "enable"); | |
9201 | ||
9202 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
9203 | Set the passcount for a tracepoint.\n\ | |
9204 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
9205 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
9206 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
9207 | ||
9208 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
9209 | Save current tracepoint definitions as a script.\n\ | |
9210 | Use the 'source' command in another debug session to restore them.")); | |
9211 | set_cmd_completer (c, filename_completer); | |
9212 | ||
1bedd215 | 9213 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9214 | Breakpoint specific settings\n\ |
9215 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9216 | pending breakpoint behavior"), |
fa8d40ab JJ |
9217 | &breakpoint_set_cmdlist, "set breakpoint ", |
9218 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 9219 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9220 | Breakpoint specific settings\n\ |
9221 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9222 | pending breakpoint behavior"), |
fa8d40ab JJ |
9223 | &breakpoint_show_cmdlist, "show breakpoint ", |
9224 | 0/*allow-unknown*/, &showlist); | |
9225 | ||
7915a72c AC |
9226 | add_setshow_auto_boolean_cmd ("pending", no_class, |
9227 | &pending_break_support, _("\ | |
9228 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
9229 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
9230 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
9231 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
9232 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 9233 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 9234 | NULL, |
920d2a44 | 9235 | show_pending_break_support, |
6e1d7d6c AC |
9236 | &breakpoint_set_cmdlist, |
9237 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
9238 | |
9239 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
9240 | |
9241 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
9242 | &automatic_hardware_breakpoints, _("\ | |
9243 | Set automatic usage of hardware breakpoints."), _("\ | |
9244 | Show automatic usage of hardware breakpoints."), _("\ | |
9245 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
9246 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
9247 | a warning will be emitted for such breakpoints."), | |
9248 | NULL, | |
9249 | show_automatic_hardware_breakpoints, | |
9250 | &breakpoint_set_cmdlist, | |
9251 | &breakpoint_show_cmdlist); | |
74960c60 | 9252 | |
33e5cbd6 PA |
9253 | add_setshow_enum_cmd ("always-inserted", class_support, |
9254 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
9255 | Set mode for inserting breakpoints."), _("\ |
9256 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
9257 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
9258 | resumed, and removed when execution stops. When this mode is on,\n\ | |
9259 | breakpoints are inserted immediately and removed only when the user\n\ | |
9260 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
9261 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
9262 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
9263 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
9264 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
9265 | NULL, |
9266 | &show_always_inserted_mode, | |
9267 | &breakpoint_set_cmdlist, | |
9268 | &breakpoint_show_cmdlist); | |
765dc015 VP |
9269 | |
9270 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
9271 | |
9272 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 9273 | } |