Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c AC |
2 | |
3 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, | |
a881cf8e | 4 | 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software |
8926118c | 5 | 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 | |
11 | the Free Software Foundation; either version 2 of the License, or | |
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 JM |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
23 | |
24 | #include "defs.h" | |
25 | #include <ctype.h> | |
26 | #include "symtab.h" | |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "expression.h" | |
31 | #include "gdbcore.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "value.h" | |
34 | #include "command.h" | |
35 | #include "inferior.h" | |
36 | #include "gdbthread.h" | |
37 | #include "target.h" | |
38 | #include "language.h" | |
39 | #include "gdb_string.h" | |
40 | #include "demangle.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
c906108c | 52 | |
104c1213 JM |
53 | #include "gdb-events.h" |
54 | ||
c906108c SS |
55 | /* Prototypes for local functions. */ |
56 | ||
c2c6d25f JM |
57 | static void until_break_command_continuation (struct continuation_arg *arg); |
58 | ||
a14ed312 | 59 | static void catch_command_1 (char *, int, int); |
c906108c | 60 | |
a14ed312 | 61 | static void enable_delete_command (char *, int); |
c906108c | 62 | |
a14ed312 | 63 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 64 | |
a14ed312 | 65 | static void enable_once_command (char *, int); |
c906108c | 66 | |
a14ed312 | 67 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 68 | |
a14ed312 | 69 | static void disable_command (char *, int); |
c906108c | 70 | |
a14ed312 | 71 | static void enable_command (char *, int); |
c906108c | 72 | |
a14ed312 | 73 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 74 | |
a14ed312 | 75 | static void ignore_command (char *, int); |
c906108c | 76 | |
4efb68b1 | 77 | static int breakpoint_re_set_one (void *); |
c906108c | 78 | |
a14ed312 | 79 | static void clear_command (char *, int); |
c906108c | 80 | |
a14ed312 | 81 | static void catch_command (char *, int); |
c906108c | 82 | |
a14ed312 | 83 | static void watch_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 86 | |
e5d66720 PS |
87 | extern void break_at_finish_command (char *, int); |
88 | extern void break_at_finish_at_depth_command (char *, int); | |
7a292a7a | 89 | |
e5d66720 | 90 | extern void tbreak_at_finish_command (char *, int); |
7a292a7a | 91 | |
a14ed312 | 92 | static void break_command_1 (char *, int, int); |
c906108c | 93 | |
a14ed312 | 94 | static void mention (struct breakpoint *); |
c906108c | 95 | |
4d28f7a8 | 96 | struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype); |
c906108c | 97 | |
9f60f21b | 98 | static void check_duplicates (struct breakpoint *); |
c906108c | 99 | |
76897487 KB |
100 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
101 | ||
102 | static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr); | |
103 | ||
a14ed312 | 104 | static void describe_other_breakpoints (CORE_ADDR, asection *); |
c906108c | 105 | |
a14ed312 | 106 | static void breakpoints_info (char *, int); |
c906108c | 107 | |
a14ed312 | 108 | static void breakpoint_1 (int, int); |
c906108c | 109 | |
a14ed312 | 110 | static bpstat bpstat_alloc (struct breakpoint *, bpstat); |
c906108c | 111 | |
4efb68b1 | 112 | static int breakpoint_cond_eval (void *); |
c906108c | 113 | |
4efb68b1 | 114 | static void cleanup_executing_breakpoints (void *); |
c906108c | 115 | |
a14ed312 | 116 | static void commands_command (char *, int); |
c906108c | 117 | |
a14ed312 | 118 | static void condition_command (char *, int); |
c906108c | 119 | |
a14ed312 | 120 | static int get_number_trailer (char **, int); |
c906108c | 121 | |
a14ed312 | 122 | void set_breakpoint_count (int); |
c906108c | 123 | |
c5aa993b JM |
124 | typedef enum |
125 | { | |
126 | mark_inserted, | |
127 | mark_uninserted | |
128 | } | |
129 | insertion_state_t; | |
c906108c | 130 | |
a14ed312 | 131 | static int remove_breakpoint (struct breakpoint *, insertion_state_t); |
c906108c | 132 | |
a14ed312 | 133 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
134 | |
135 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 136 | |
c5aa993b JM |
137 | typedef struct |
138 | { | |
139 | enum exception_event_kind kind; | |
b5de0fa7 | 140 | int enable_p; |
c5aa993b JM |
141 | } |
142 | args_for_catchpoint_enable; | |
c906108c | 143 | |
4efb68b1 | 144 | static int watchpoint_check (void *); |
c906108c | 145 | |
4efb68b1 | 146 | static int cover_target_enable_exception_callback (void *); |
c906108c | 147 | |
a14ed312 | 148 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 149 | |
a14ed312 | 150 | static void create_longjmp_breakpoint (char *); |
c906108c | 151 | |
1900040c MS |
152 | static void create_overlay_event_breakpoint (char *); |
153 | ||
a14ed312 | 154 | static int hw_breakpoint_used_count (void); |
c906108c | 155 | |
a14ed312 | 156 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 157 | |
a14ed312 | 158 | static void hbreak_command (char *, int); |
c906108c | 159 | |
a14ed312 | 160 | static void thbreak_command (char *, int); |
c906108c | 161 | |
a14ed312 | 162 | static void watch_command_1 (char *, int, int); |
c906108c | 163 | |
a14ed312 | 164 | static void rwatch_command (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static void awatch_command (char *, int); |
c906108c | 167 | |
a14ed312 | 168 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 169 | |
a14ed312 KB |
170 | static void solib_load_unload_1 (char *hookname, |
171 | int tempflag, | |
172 | char *dll_pathname, | |
173 | char *cond_string, enum bptype bp_kind); | |
7a292a7a | 174 | |
a14ed312 KB |
175 | static void create_fork_vfork_event_catchpoint (int tempflag, |
176 | char *cond_string, | |
177 | enum bptype bp_kind); | |
7a292a7a | 178 | |
a14ed312 KB |
179 | static void break_at_finish_at_depth_command_1 (char *arg, |
180 | int flag, int from_tty); | |
7a292a7a | 181 | |
a14ed312 | 182 | static void break_at_finish_command_1 (char *arg, int flag, int from_tty); |
7a292a7a | 183 | |
a14ed312 | 184 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 189 | |
a14ed312 | 190 | static char *ep_find_event_name_end (char *arg); |
7a292a7a | 191 | |
a14ed312 | 192 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 193 | |
a14ed312 | 194 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 195 | |
e514a9d6 | 196 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) |
a14ed312 | 197 | static void catch_exec_command_1 (char *arg, int tempflag, int from_tty); |
e514a9d6 | 198 | #endif |
7a292a7a | 199 | |
d85310f7 MS |
200 | static void create_exception_catchpoint (int tempflag, char *cond_string, |
201 | enum exception_event_kind ex_event, | |
202 | struct symtab_and_line *sal); | |
7a292a7a | 203 | |
d85310f7 MS |
204 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
205 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 206 | |
a14ed312 | 207 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 208 | |
a14ed312 | 209 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 210 | |
c906108c SS |
211 | /* Prototypes for exported functions. */ |
212 | ||
c906108c SS |
213 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
214 | if such is available. */ | |
215 | static int can_use_hw_watchpoints; | |
216 | ||
a14ed312 | 217 | void _initialize_breakpoint (void); |
c906108c | 218 | |
c5aa993b | 219 | extern int addressprint; /* Print machine addresses? */ |
c906108c | 220 | |
c906108c SS |
221 | /* Are we executing breakpoint commands? */ |
222 | static int executing_breakpoint_commands; | |
223 | ||
c02f5703 MS |
224 | /* Are overlay event breakpoints enabled? */ |
225 | static int overlay_events_enabled; | |
226 | ||
c906108c SS |
227 | /* Walk the following statement or block through all breakpoints. |
228 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
229 | breakpoint. */ | |
230 | ||
5c44784c | 231 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 232 | |
5c44784c JM |
233 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
234 | for (B = breakpoint_chain; \ | |
235 | B ? (TMP=B->next, 1): 0; \ | |
236 | B = TMP) | |
c906108c | 237 | |
7cc221ef DJ |
238 | /* Similar iterators for the low-level breakpoints. */ |
239 | ||
240 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next) | |
241 | ||
242 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
243 | for (B = bp_location_chain; \ | |
244 | B ? (TMP=B->next, 1): 0; \ | |
245 | B = TMP) | |
246 | ||
c906108c SS |
247 | /* True if SHIFT_INST_REGS defined, false otherwise. */ |
248 | ||
249 | int must_shift_inst_regs = | |
250 | #if defined(SHIFT_INST_REGS) | |
251 | 1 | |
252 | #else | |
253 | 0 | |
254 | #endif | |
c5aa993b | 255 | ; |
c906108c SS |
256 | |
257 | /* True if breakpoint hit counts should be displayed in breakpoint info. */ | |
258 | ||
259 | int show_breakpoint_hit_counts = 1; | |
260 | ||
7cc221ef | 261 | /* Chains of all breakpoints defined. */ |
c906108c SS |
262 | |
263 | struct breakpoint *breakpoint_chain; | |
264 | ||
7cc221ef DJ |
265 | struct bp_location *bp_location_chain; |
266 | ||
c906108c SS |
267 | /* Number of last breakpoint made. */ |
268 | ||
269 | int breakpoint_count; | |
270 | ||
c5aa993b JM |
271 | /* Pointer to current exception event record */ |
272 | static struct exception_event_record *current_exception_event; | |
c906108c SS |
273 | |
274 | /* Indicator of whether exception catchpoints should be nuked | |
275 | between runs of a program */ | |
276 | int exception_catchpoints_are_fragile = 0; | |
c5aa993b | 277 | |
c906108c SS |
278 | /* Indicator of when exception catchpoints set-up should be |
279 | reinitialized -- e.g. when program is re-run */ | |
280 | int exception_support_initialized = 0; | |
281 | ||
282 | /* This function returns a pointer to the string representation of the | |
283 | pathname of the dynamically-linked library that has just been | |
284 | loaded. | |
285 | ||
286 | This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE, | |
287 | or undefined results are guaranteed. | |
288 | ||
289 | This string's contents are only valid immediately after the | |
290 | inferior has stopped in the dynamic linker hook, and becomes | |
291 | invalid as soon as the inferior is continued. Clients should make | |
292 | a copy of this string if they wish to continue the inferior and | |
293 | then access the string. */ | |
294 | ||
295 | #ifndef SOLIB_LOADED_LIBRARY_PATHNAME | |
296 | #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) "" | |
297 | #endif | |
298 | ||
299 | /* This function returns a pointer to the string representation of the | |
300 | pathname of the dynamically-linked library that has just been | |
301 | unloaded. | |
302 | ||
303 | This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is | |
304 | TRUE, or undefined results are guaranteed. | |
305 | ||
306 | This string's contents are only valid immediately after the | |
307 | inferior has stopped in the dynamic linker hook, and becomes | |
308 | invalid as soon as the inferior is continued. Clients should make | |
309 | a copy of this string if they wish to continue the inferior and | |
310 | then access the string. */ | |
311 | ||
312 | #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME | |
313 | #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) "" | |
314 | #endif | |
315 | ||
316 | /* This function is called by the "catch load" command. It allows the | |
317 | debugger to be notified by the dynamic linker when a specified | |
318 | library file (or any library file, if filename is NULL) is loaded. */ | |
319 | ||
320 | #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK | |
321 | #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \ | |
322 | error ("catch of library loads not yet implemented on this platform") | |
323 | #endif | |
324 | ||
325 | /* This function is called by the "catch unload" command. It allows | |
326 | the debugger to be notified by the dynamic linker when a specified | |
327 | library file (or any library file, if filename is NULL) is | |
328 | unloaded. */ | |
329 | ||
330 | #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK | |
331 | #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \ | |
332 | error ("catch of library unloads not yet implemented on this platform") | |
333 | #endif | |
334 | ||
335 | /* Set breakpoint count to NUM. */ | |
336 | ||
337 | void | |
fba45db2 | 338 | set_breakpoint_count (int num) |
c906108c SS |
339 | { |
340 | breakpoint_count = num; | |
341 | set_internalvar (lookup_internalvar ("bpnum"), | |
342 | value_from_longest (builtin_type_int, (LONGEST) num)); | |
343 | } | |
344 | ||
345 | /* Used in run_command to zero the hit count when a new run starts. */ | |
346 | ||
347 | void | |
fba45db2 | 348 | clear_breakpoint_hit_counts (void) |
c906108c SS |
349 | { |
350 | struct breakpoint *b; | |
351 | ||
352 | ALL_BREAKPOINTS (b) | |
353 | b->hit_count = 0; | |
354 | } | |
355 | ||
356 | /* Default address, symtab and line to put a breakpoint at | |
357 | for "break" command with no arg. | |
358 | if default_breakpoint_valid is zero, the other three are | |
359 | not valid, and "break" with no arg is an error. | |
360 | ||
361 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
362 | ||
363 | int default_breakpoint_valid; | |
364 | CORE_ADDR default_breakpoint_address; | |
365 | struct symtab *default_breakpoint_symtab; | |
366 | int default_breakpoint_line; | |
367 | \f | |
368 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
369 | Advance *PP after the string and any trailing whitespace. | |
370 | ||
371 | Currently the string can either be a number or "$" followed by the name | |
372 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c JM |
373 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
374 | ||
375 | TRAILER is a character which can be found after the number; most | |
376 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 377 | static int |
fba45db2 | 378 | get_number_trailer (char **pp, int trailer) |
c906108c | 379 | { |
5c44784c | 380 | int retval = 0; /* default */ |
c906108c SS |
381 | char *p = *pp; |
382 | ||
383 | if (p == NULL) | |
384 | /* Empty line means refer to the last breakpoint. */ | |
385 | return breakpoint_count; | |
386 | else if (*p == '$') | |
387 | { | |
388 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 389 | to pass to lookup_internalvar(). */ |
c906108c SS |
390 | char *varname; |
391 | char *start = ++p; | |
278cd55f | 392 | struct value *val; |
c906108c SS |
393 | |
394 | while (isalnum (*p) || *p == '_') | |
395 | p++; | |
396 | varname = (char *) alloca (p - start + 1); | |
397 | strncpy (varname, start, p - start); | |
398 | varname[p - start] = '\0'; | |
399 | val = value_of_internalvar (lookup_internalvar (varname)); | |
5c44784c JM |
400 | if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT) |
401 | retval = (int) value_as_long (val); | |
402 | else | |
403 | { | |
404 | printf_filtered ("Convenience variable must have integer value.\n"); | |
405 | retval = 0; | |
406 | } | |
c906108c SS |
407 | } |
408 | else | |
409 | { | |
410 | if (*p == '-') | |
411 | ++p; | |
412 | while (*p >= '0' && *p <= '9') | |
413 | ++p; | |
414 | if (p == *pp) | |
415 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
416 | { |
417 | /* Skip non-numeric token */ | |
418 | while (*p && !isspace((int) *p)) | |
419 | ++p; | |
420 | /* Return zero, which caller must interpret as error. */ | |
421 | retval = 0; | |
422 | } | |
423 | else | |
424 | retval = atoi (*pp); | |
425 | } | |
426 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
427 | { | |
428 | /* Trailing junk: return 0 and let caller print error msg. */ | |
429 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
430 | ++p; | |
431 | retval = 0; | |
c906108c | 432 | } |
c906108c SS |
433 | while (isspace (*p)) |
434 | p++; | |
435 | *pp = p; | |
436 | return retval; | |
437 | } | |
5c44784c | 438 | |
11cf8741 | 439 | |
5c44784c JM |
440 | /* Like get_number_trailer, but don't allow a trailer. */ |
441 | int | |
fba45db2 | 442 | get_number (char **pp) |
5c44784c JM |
443 | { |
444 | return get_number_trailer (pp, '\0'); | |
445 | } | |
446 | ||
447 | /* Parse a number or a range. | |
448 | * A number will be of the form handled by get_number. | |
449 | * A range will be of the form <number1> - <number2>, and | |
450 | * will represent all the integers between number1 and number2, | |
451 | * inclusive. | |
452 | * | |
453 | * While processing a range, this fuction is called iteratively; | |
454 | * At each call it will return the next value in the range. | |
455 | * | |
456 | * At the beginning of parsing a range, the char pointer PP will | |
457 | * be advanced past <number1> and left pointing at the '-' token. | |
458 | * Subsequent calls will not advance the pointer until the range | |
459 | * is completed. The call that completes the range will advance | |
460 | * pointer PP past <number2>. | |
461 | */ | |
462 | ||
463 | int | |
fba45db2 | 464 | get_number_or_range (char **pp) |
5c44784c JM |
465 | { |
466 | static int last_retval, end_value; | |
467 | static char *end_ptr; | |
468 | static int in_range = 0; | |
469 | ||
470 | if (**pp != '-') | |
471 | { | |
472 | /* Default case: pp is pointing either to a solo number, | |
473 | or to the first number of a range. */ | |
474 | last_retval = get_number_trailer (pp, '-'); | |
475 | if (**pp == '-') | |
476 | { | |
477 | char **temp; | |
478 | ||
479 | /* This is the start of a range (<number1> - <number2>). | |
480 | Skip the '-', parse and remember the second number, | |
481 | and also remember the end of the final token. */ | |
482 | ||
483 | temp = &end_ptr; | |
484 | end_ptr = *pp + 1; | |
485 | while (isspace ((int) *end_ptr)) | |
486 | end_ptr++; /* skip white space */ | |
487 | end_value = get_number (temp); | |
488 | if (end_value < last_retval) | |
489 | { | |
490 | error ("inverted range"); | |
491 | } | |
492 | else if (end_value == last_retval) | |
493 | { | |
494 | /* degenerate range (number1 == number2). Advance the | |
495 | token pointer so that the range will be treated as a | |
496 | single number. */ | |
497 | *pp = end_ptr; | |
498 | } | |
499 | else | |
500 | in_range = 1; | |
501 | } | |
502 | } | |
503 | else if (! in_range) | |
504 | error ("negative value"); | |
505 | else | |
506 | { | |
507 | /* pp points to the '-' that betokens a range. All | |
508 | number-parsing has already been done. Return the next | |
509 | integer value (one greater than the saved previous value). | |
510 | Do not advance the token pointer 'pp' until the end of range | |
511 | is reached. */ | |
512 | ||
513 | if (++last_retval == end_value) | |
514 | { | |
515 | /* End of range reached; advance token pointer. */ | |
516 | *pp = end_ptr; | |
517 | in_range = 0; | |
518 | } | |
519 | } | |
520 | return last_retval; | |
521 | } | |
522 | ||
523 | ||
c906108c SS |
524 | \f |
525 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
526 | ||
527 | static void | |
fba45db2 | 528 | condition_command (char *arg, int from_tty) |
c906108c | 529 | { |
52f0bd74 | 530 | struct breakpoint *b; |
c906108c | 531 | char *p; |
52f0bd74 | 532 | int bnum; |
c906108c SS |
533 | |
534 | if (arg == 0) | |
535 | error_no_arg ("breakpoint number"); | |
536 | ||
537 | p = arg; | |
538 | bnum = get_number (&p); | |
5c44784c JM |
539 | if (bnum == 0) |
540 | error ("Bad breakpoint argument: '%s'", arg); | |
c906108c SS |
541 | |
542 | ALL_BREAKPOINTS (b) | |
543 | if (b->number == bnum) | |
c5aa993b JM |
544 | { |
545 | if (b->cond) | |
546 | { | |
b8c9b27d | 547 | xfree (b->cond); |
c5aa993b JM |
548 | b->cond = 0; |
549 | } | |
550 | if (b->cond_string != NULL) | |
b8c9b27d | 551 | xfree (b->cond_string); |
c906108c | 552 | |
c5aa993b JM |
553 | if (*p == 0) |
554 | { | |
555 | b->cond = 0; | |
556 | b->cond_string = NULL; | |
557 | if (from_tty) | |
558 | printf_filtered ("Breakpoint %d now unconditional.\n", bnum); | |
559 | } | |
560 | else | |
561 | { | |
562 | arg = p; | |
563 | /* I don't know if it matters whether this is the string the user | |
564 | typed in or the decompiled expression. */ | |
565 | b->cond_string = savestring (arg, strlen (arg)); | |
5cab636d | 566 | b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0); |
c5aa993b JM |
567 | if (*arg) |
568 | error ("Junk at end of expression"); | |
569 | } | |
570 | breakpoints_changed (); | |
221ea385 | 571 | breakpoint_modify_event (b->number); |
c5aa993b JM |
572 | return; |
573 | } | |
c906108c SS |
574 | |
575 | error ("No breakpoint number %d.", bnum); | |
576 | } | |
577 | ||
c906108c | 578 | static void |
fba45db2 | 579 | commands_command (char *arg, int from_tty) |
c906108c | 580 | { |
52f0bd74 | 581 | struct breakpoint *b; |
c906108c | 582 | char *p; |
52f0bd74 | 583 | int bnum; |
c906108c SS |
584 | struct command_line *l; |
585 | ||
586 | /* If we allowed this, we would have problems with when to | |
587 | free the storage, if we change the commands currently | |
588 | being read from. */ | |
589 | ||
590 | if (executing_breakpoint_commands) | |
591 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
592 | ||
593 | p = arg; | |
594 | bnum = get_number (&p); | |
5c44784c | 595 | |
c906108c SS |
596 | if (p && *p) |
597 | error ("Unexpected extra arguments following breakpoint number."); | |
c5aa993b | 598 | |
c906108c SS |
599 | ALL_BREAKPOINTS (b) |
600 | if (b->number == bnum) | |
9ebf4acf AC |
601 | { |
602 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
603 | bnum); | |
604 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
605 | l = read_command_lines (tmpbuf, from_tty); | |
606 | do_cleanups (cleanups); | |
607 | free_command_lines (&b->commands); | |
608 | b->commands = l; | |
609 | breakpoints_changed (); | |
610 | breakpoint_modify_event (b->number); | |
611 | return; | |
c5aa993b | 612 | } |
c906108c SS |
613 | error ("No breakpoint number %d.", bnum); |
614 | } | |
615 | \f | |
616 | /* Like target_read_memory() but if breakpoints are inserted, return | |
617 | the shadow contents instead of the breakpoints themselves. | |
618 | ||
619 | Read "memory data" from whatever target or inferior we have. | |
620 | Returns zero if successful, errno value if not. EIO is used | |
621 | for address out of bounds. If breakpoints are inserted, returns | |
622 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ | |
623 | ||
624 | int | |
fba45db2 | 625 | read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len) |
c906108c SS |
626 | { |
627 | int status; | |
ffce0d52 | 628 | struct bp_location *b; |
c906108c SS |
629 | CORE_ADDR bp_addr = 0; |
630 | int bp_size = 0; | |
631 | ||
632 | if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) | |
633 | /* No breakpoints on this machine. */ | |
634 | return target_read_memory (memaddr, myaddr, len); | |
c5aa993b | 635 | |
ffce0d52 | 636 | ALL_BP_LOCATIONS (b) |
c5aa993b | 637 | { |
ffce0d52 DJ |
638 | if (b->owner->type == bp_none) |
639 | warning ("reading through apparently deleted breakpoint #%d?", | |
640 | b->owner->number); | |
641 | ||
642 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 643 | continue; |
ffce0d52 | 644 | if (!b->inserted) |
c5aa993b JM |
645 | continue; |
646 | /* Addresses and length of the part of the breakpoint that | |
647 | we need to copy. */ | |
648 | /* XXXX The m68k, sh and h8300 have different local and remote | |
649 | breakpoint values. BREAKPOINT_FROM_PC still manages to | |
650 | correctly determine the breakpoints memory address and size | |
651 | for these targets. */ | |
ffce0d52 | 652 | bp_addr = b->address; |
c5aa993b JM |
653 | bp_size = 0; |
654 | if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) | |
655 | continue; | |
656 | if (bp_size == 0) | |
657 | /* bp isn't valid */ | |
658 | continue; | |
659 | if (bp_addr + bp_size <= memaddr) | |
660 | /* The breakpoint is entirely before the chunk of memory we | |
661 | are reading. */ | |
662 | continue; | |
663 | if (bp_addr >= memaddr + len) | |
664 | /* The breakpoint is entirely after the chunk of memory we are | |
665 | reading. */ | |
666 | continue; | |
667 | /* Copy the breakpoint from the shadow contents, and recurse for | |
668 | the things before and after. */ | |
c906108c | 669 | { |
c5aa993b JM |
670 | /* Offset within shadow_contents. */ |
671 | int bptoffset = 0; | |
c906108c | 672 | |
c5aa993b JM |
673 | if (bp_addr < memaddr) |
674 | { | |
675 | /* Only copy the second part of the breakpoint. */ | |
676 | bp_size -= memaddr - bp_addr; | |
677 | bptoffset = memaddr - bp_addr; | |
678 | bp_addr = memaddr; | |
679 | } | |
680 | ||
681 | if (bp_addr + bp_size > memaddr + len) | |
682 | { | |
683 | /* Only copy the first part of the breakpoint. */ | |
684 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
685 | } | |
686 | ||
687 | memcpy (myaddr + bp_addr - memaddr, | |
ffce0d52 | 688 | b->shadow_contents + bptoffset, bp_size); |
c5aa993b JM |
689 | |
690 | if (bp_addr > memaddr) | |
691 | { | |
692 | /* Copy the section of memory before the breakpoint. */ | |
693 | status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr); | |
694 | if (status != 0) | |
695 | return status; | |
696 | } | |
697 | ||
698 | if (bp_addr + bp_size < memaddr + len) | |
699 | { | |
700 | /* Copy the section of memory after the breakpoint. */ | |
d85310f7 MS |
701 | status = read_memory_nobpt (bp_addr + bp_size, |
702 | myaddr + bp_addr + bp_size - memaddr, | |
703 | memaddr + len - (bp_addr + bp_size)); | |
c5aa993b JM |
704 | if (status != 0) |
705 | return status; | |
706 | } | |
707 | return 0; | |
c906108c | 708 | } |
c5aa993b | 709 | } |
c906108c SS |
710 | /* Nothing overlaps. Just call read_memory_noerr. */ |
711 | return target_read_memory (memaddr, myaddr, len); | |
712 | } | |
c906108c | 713 | \f |
c5aa993b | 714 | |
687595f9 | 715 | /* A wrapper function for inserting catchpoints. */ |
3f8091c1 | 716 | static int |
687595f9 DJ |
717 | insert_catchpoint (struct ui_out *uo, void *args) |
718 | { | |
719 | struct breakpoint *b = (struct breakpoint *) args; | |
720 | int val = -1; | |
721 | ||
722 | switch (b->type) | |
723 | { | |
724 | case bp_catch_fork: | |
725 | val = target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
726 | break; | |
727 | case bp_catch_vfork: | |
728 | val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
729 | break; | |
730 | case bp_catch_exec: | |
731 | val = target_insert_exec_catchpoint (PIDGET (inferior_ptid)); | |
732 | break; | |
733 | default: | |
1171114a | 734 | internal_error (__FILE__, __LINE__, "unknown breakpoint type"); |
687595f9 DJ |
735 | break; |
736 | } | |
737 | ||
738 | if (val < 0) | |
739 | throw_exception (RETURN_ERROR); | |
740 | ||
741 | return 0; | |
742 | } | |
743 | ||
879bfdc2 DJ |
744 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
745 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
746 | PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems. | |
747 | ||
748 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
749 | method for each breakpoint or catchpoint type. */ | |
750 | int | |
751 | insert_bp_location (struct bp_location *bpt, | |
752 | struct ui_file *tmp_error_stream, | |
753 | int *disabled_breaks, int *process_warning, | |
754 | int *hw_breakpoint_error) | |
755 | { | |
756 | int val = 0; | |
757 | ||
758 | /* Permanent breakpoints cannot be inserted or removed. Disabled | |
759 | breakpoints should not be inserted. */ | |
760 | if (bpt->owner->enable_state != bp_enabled) | |
761 | return 0; | |
762 | ||
763 | if (bpt->inserted || bpt->duplicate) | |
764 | return 0; | |
765 | ||
766 | if (bpt->loc_type == bp_loc_software_breakpoint | |
767 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
768 | { | |
769 | /* First check to see if we have to handle an overlay. */ | |
770 | if (overlay_debugging == ovly_off | |
771 | || bpt->section == NULL | |
772 | || !(section_is_overlay (bpt->section))) | |
773 | { | |
774 | /* No overlay handling: just set the breakpoint. */ | |
775 | ||
776 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
777 | val = target_insert_hw_breakpoint (bpt->address, | |
778 | bpt->shadow_contents); | |
779 | else | |
780 | val = target_insert_breakpoint (bpt->address, | |
781 | bpt->shadow_contents); | |
782 | } | |
783 | else | |
784 | { | |
785 | /* This breakpoint is in an overlay section. | |
786 | Shall we set a breakpoint at the LMA? */ | |
787 | if (!overlay_events_enabled) | |
788 | { | |
789 | /* Yes -- overlay event support is not active, | |
790 | so we must try to set a breakpoint at the LMA. | |
791 | This will not work for a hardware breakpoint. */ | |
792 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
793 | warning ("hardware breakpoint %d not supported in overlay!\n", | |
794 | bpt->owner->number); | |
795 | else | |
796 | { | |
797 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
798 | bpt->section); | |
799 | /* Set a software (trap) breakpoint at the LMA. */ | |
800 | val = target_insert_breakpoint (addr, bpt->shadow_contents); | |
801 | if (val != 0) | |
802 | fprintf_unfiltered (tmp_error_stream, | |
803 | "Overlay breakpoint %d failed: in ROM?", | |
804 | bpt->owner->number); | |
805 | } | |
806 | } | |
807 | /* Shall we set a breakpoint at the VMA? */ | |
808 | if (section_is_mapped (bpt->section)) | |
809 | { | |
810 | /* Yes. This overlay section is mapped into memory. */ | |
811 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
812 | val = target_insert_hw_breakpoint (bpt->address, | |
813 | bpt->shadow_contents); | |
814 | else | |
815 | val = target_insert_breakpoint (bpt->address, | |
816 | bpt->shadow_contents); | |
817 | } | |
818 | else | |
819 | { | |
820 | /* No. This breakpoint will not be inserted. | |
821 | No error, but do not mark the bp as 'inserted'. */ | |
822 | return 0; | |
823 | } | |
824 | } | |
825 | ||
826 | if (val) | |
827 | { | |
828 | /* Can't set the breakpoint. */ | |
829 | #if defined (DISABLE_UNSETTABLE_BREAK) | |
830 | if (DISABLE_UNSETTABLE_BREAK (bpt->address)) | |
831 | { | |
832 | /* See also: disable_breakpoints_in_shlibs. */ | |
833 | val = 0; | |
834 | bpt->owner->enable_state = bp_shlib_disabled; | |
835 | if (!*disabled_breaks) | |
836 | { | |
837 | fprintf_unfiltered (tmp_error_stream, | |
838 | "Cannot insert breakpoint %d.\n", | |
839 | bpt->owner->number); | |
840 | fprintf_unfiltered (tmp_error_stream, | |
841 | "Temporarily disabling shared library breakpoints:\n"); | |
842 | } | |
843 | *disabled_breaks = 1; | |
844 | fprintf_unfiltered (tmp_error_stream, | |
845 | "breakpoint #%d\n", bpt->owner->number); | |
846 | } | |
847 | else | |
848 | #endif | |
849 | { | |
850 | #ifdef ONE_PROCESS_WRITETEXT | |
851 | *process_warning = 1; | |
852 | #endif | |
853 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
854 | { | |
855 | *hw_breakpoint_error = 1; | |
856 | fprintf_unfiltered (tmp_error_stream, | |
857 | "Cannot insert hardware breakpoint %d.\n", | |
858 | bpt->owner->number); | |
859 | } | |
860 | else | |
861 | { | |
862 | fprintf_unfiltered (tmp_error_stream, | |
863 | "Cannot insert breakpoint %d.\n", | |
864 | bpt->owner->number); | |
865 | fprintf_filtered (tmp_error_stream, | |
866 | "Error accessing memory address "); | |
867 | print_address_numeric (bpt->address, 1, tmp_error_stream); | |
868 | fprintf_filtered (tmp_error_stream, ": %s.\n", | |
869 | safe_strerror (val)); | |
870 | } | |
871 | ||
872 | } | |
873 | } | |
874 | else | |
875 | bpt->inserted = 1; | |
876 | ||
877 | return val; | |
878 | } | |
879 | ||
880 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
881 | /* NOTE drow/2003-09-08: This state only exists for removing | |
882 | watchpoints. It's not clear that it's necessary... */ | |
883 | && bpt->owner->disposition != disp_del_at_next_stop) | |
884 | { | |
885 | /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints | |
886 | based on the expression. Ideally this should happen at a higher level, | |
887 | and there should be one bp_location for each computed address we | |
888 | must watch. As soon as a many-to-one mapping is available I'll | |
889 | convert this. */ | |
890 | ||
891 | struct frame_info *saved_frame; | |
892 | int saved_level, within_current_scope; | |
893 | struct value *mark = value_mark (); | |
894 | struct value *v; | |
895 | ||
896 | /* Save the current frame and level so we can restore it after | |
897 | evaluating the watchpoint expression on its own frame. */ | |
898 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
899 | took a frame parameter, so that we didn't have to change the | |
900 | selected frame. */ | |
901 | saved_frame = deprecated_selected_frame; | |
902 | saved_level = frame_relative_level (deprecated_selected_frame); | |
903 | ||
904 | /* Determine if the watchpoint is within scope. */ | |
905 | if (bpt->owner->exp_valid_block == NULL) | |
906 | within_current_scope = 1; | |
907 | else | |
908 | { | |
909 | struct frame_info *fi; | |
910 | fi = frame_find_by_id (bpt->owner->watchpoint_frame); | |
911 | within_current_scope = (fi != NULL); | |
912 | if (within_current_scope) | |
913 | select_frame (fi); | |
914 | } | |
915 | ||
916 | if (within_current_scope) | |
917 | { | |
918 | /* Evaluate the expression and cut the chain of values | |
919 | produced off from the value chain. | |
920 | ||
921 | Make sure the value returned isn't lazy; we use | |
922 | laziness to determine what memory GDB actually needed | |
923 | in order to compute the value of the expression. */ | |
924 | v = evaluate_expression (bpt->owner->exp); | |
925 | VALUE_CONTENTS (v); | |
926 | value_release_to_mark (mark); | |
927 | ||
928 | bpt->owner->val_chain = v; | |
929 | bpt->inserted = 1; | |
930 | ||
931 | /* Look at each value on the value chain. */ | |
932 | for (; v; v = v->next) | |
933 | { | |
934 | /* If it's a memory location, and GDB actually needed | |
935 | its contents to evaluate the expression, then we | |
936 | must watch it. */ | |
937 | if (VALUE_LVAL (v) == lval_memory | |
938 | && ! VALUE_LAZY (v)) | |
939 | { | |
940 | struct type *vtype = check_typedef (VALUE_TYPE (v)); | |
941 | ||
942 | /* We only watch structs and arrays if user asked | |
943 | for it explicitly, never if they just happen to | |
944 | appear in the middle of some value chain. */ | |
945 | if (v == bpt->owner->val_chain | |
946 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
947 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
948 | { | |
949 | CORE_ADDR addr; | |
950 | int len, type; | |
951 | ||
952 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
953 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
954 | type = hw_write; | |
955 | if (bpt->owner->type == bp_read_watchpoint) | |
956 | type = hw_read; | |
957 | else if (bpt->owner->type == bp_access_watchpoint) | |
958 | type = hw_access; | |
959 | ||
960 | val = target_insert_watchpoint (addr, len, type); | |
961 | if (val == -1) | |
962 | { | |
963 | /* Don't exit the loop, try to insert | |
964 | every value on the value chain. That's | |
965 | because we will be removing all the | |
966 | watches below, and removing a | |
967 | watchpoint we didn't insert could have | |
968 | adverse effects. */ | |
969 | bpt->inserted = 0; | |
970 | } | |
971 | val = 0; | |
972 | } | |
973 | } | |
974 | } | |
975 | /* Failure to insert a watchpoint on any memory value in the | |
976 | value chain brings us here. */ | |
977 | if (!bpt->inserted) | |
978 | { | |
979 | remove_breakpoint (bpt->owner, mark_uninserted); | |
980 | *hw_breakpoint_error = 1; | |
981 | fprintf_unfiltered (tmp_error_stream, | |
982 | "Could not insert hardware watchpoint %d.\n", | |
983 | bpt->owner->number); | |
984 | val = -1; | |
985 | } | |
986 | } | |
987 | else | |
988 | { | |
989 | printf_filtered ("Hardware watchpoint %d deleted ", bpt->owner->number); | |
990 | printf_filtered ("because the program has left the block \n"); | |
991 | printf_filtered ("in which its expression is valid.\n"); | |
992 | if (bpt->owner->related_breakpoint) | |
993 | bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop; | |
994 | bpt->owner->disposition = disp_del_at_next_stop; | |
995 | } | |
996 | ||
997 | /* Restore the frame and level. */ | |
998 | if (saved_frame != deprecated_selected_frame | |
999 | || saved_level != frame_relative_level (deprecated_selected_frame)) | |
1000 | select_frame (saved_frame); | |
1001 | ||
1002 | return val; | |
1003 | } | |
1004 | ||
1005 | else if (ep_is_exception_catchpoint (bpt->owner)) | |
1006 | { | |
1007 | /* FIXME drow/2003-09-09: This code sets both a catchpoint and a | |
1008 | breakpoint. Once again, it would be better if this was represented | |
1009 | as two bp_locations. */ | |
1010 | ||
1011 | /* If we get here, we must have a callback mechanism for exception | |
1012 | events -- with g++ style embedded label support, we insert | |
1013 | ordinary breakpoints and not catchpoints. */ | |
1014 | val = target_insert_breakpoint (bpt->address, bpt->shadow_contents); | |
1015 | if (val) | |
1016 | { | |
1017 | /* Couldn't set breakpoint for some reason */ | |
1018 | fprintf_unfiltered (tmp_error_stream, | |
1019 | "Cannot insert catchpoint %d; disabling it.\n", | |
1020 | bpt->owner->number); | |
1021 | fprintf_filtered (tmp_error_stream, | |
1022 | "Error accessing memory address "); | |
1023 | print_address_numeric (bpt->address, 1, tmp_error_stream); | |
1024 | fprintf_filtered (tmp_error_stream, ": %s.\n", | |
1025 | safe_strerror (val)); | |
1026 | bpt->owner->enable_state = bp_disabled; | |
1027 | } | |
1028 | else | |
1029 | { | |
1030 | /* Bp set, now make sure callbacks are enabled */ | |
1031 | /* Format possible error msg */ | |
1032 | char *message = xstrprintf ("Error inserting catchpoint %d:\n", | |
1033 | bpt->owner->number); | |
1034 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
1035 | int val; | |
1036 | args_for_catchpoint_enable args; | |
1037 | args.kind = bpt->owner->type == bp_catch_catch ? | |
1038 | EX_EVENT_CATCH : EX_EVENT_THROW; | |
1039 | args.enable_p = 1; | |
1040 | val = catch_errors (cover_target_enable_exception_callback, | |
1041 | &args, message, RETURN_MASK_ALL); | |
1042 | do_cleanups (cleanups); | |
1043 | if (val != 0 && val != -1) | |
1044 | bpt->inserted = 1; | |
1045 | ||
1046 | /* Check if something went wrong; val == 0 can be ignored */ | |
1047 | if (val == -1) | |
1048 | { | |
1049 | /* something went wrong */ | |
1050 | fprintf_unfiltered (tmp_error_stream, | |
1051 | "Cannot insert catchpoint %d; disabling it.\n", | |
1052 | bpt->owner->number); | |
1053 | bpt->owner->enable_state = bp_disabled; | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | return val; | |
1058 | } | |
1059 | ||
1060 | else if (bpt->owner->type == bp_catch_fork | |
1061 | || bpt->owner->type == bp_catch_vfork | |
1062 | || bpt->owner->type == bp_catch_exec) | |
1063 | { | |
1064 | char *prefix = xstrprintf ("warning: inserting catchpoint %d: ", | |
1065 | bpt->owner->number); | |
1066 | struct cleanup *cleanups = make_cleanup (xfree, prefix); | |
1067 | val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix, | |
1068 | RETURN_MASK_ERROR); | |
1069 | do_cleanups (cleanups); | |
1070 | if (val < 0) | |
1071 | bpt->owner->enable_state = bp_disabled; | |
1072 | else | |
1073 | bpt->inserted = 1; | |
1074 | return val; | |
1075 | } | |
1076 | ||
1077 | return 0; | |
1078 | } | |
1079 | ||
c906108c SS |
1080 | /* insert_breakpoints is used when starting or continuing the program. |
1081 | remove_breakpoints is used when the program stops. | |
1082 | Both return zero if successful, | |
1083 | or an `errno' value if could not write the inferior. */ | |
1084 | ||
1085 | int | |
fba45db2 | 1086 | insert_breakpoints (void) |
c906108c | 1087 | { |
879bfdc2 | 1088 | struct bp_location *b, *temp; |
53a5351d | 1089 | int return_val = 0; /* return success code. */ |
c906108c SS |
1090 | int val = 0; |
1091 | int disabled_breaks = 0; | |
81d0cc19 GS |
1092 | int hw_breakpoint_error = 0; |
1093 | int process_warning = 0; | |
c906108c | 1094 | |
81d0cc19 GS |
1095 | struct ui_file *tmp_error_stream = mem_fileopen (); |
1096 | make_cleanup_ui_file_delete (tmp_error_stream); | |
1097 | ||
1098 | /* Explicitly mark the warning -- this will only be printed if | |
1099 | there was an error. */ | |
1100 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
c906108c | 1101 | |
879bfdc2 DJ |
1102 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1103 | { | |
1104 | /* Permanent breakpoints cannot be inserted or removed. Disabled | |
1105 | breakpoints should not be inserted. */ | |
1106 | if (b->owner->enable_state != bp_enabled) | |
1107 | continue; | |
1108 | ||
1109 | /* FIXME drow/2003-10-07: This code should be pushed elsewhere when | |
1110 | hardware watchpoints are split into multiple loc breakpoints. */ | |
1111 | if ((b->loc_type == bp_loc_hardware_watchpoint | |
1112 | || b->owner->type == bp_watchpoint) && !b->owner->val) | |
1113 | { | |
1114 | struct value *val; | |
1115 | val = evaluate_expression (b->owner->exp); | |
1116 | release_value (val); | |
1117 | if (VALUE_LAZY (val)) | |
1118 | value_fetch_lazy (val); | |
1119 | b->owner->val = val; | |
1120 | } | |
a881cf8e | 1121 | |
879bfdc2 DJ |
1122 | val = insert_bp_location (b, tmp_error_stream, |
1123 | &disabled_breaks, &process_warning, | |
1124 | &hw_breakpoint_error); | |
1125 | if (val) | |
1126 | return_val = val; | |
1127 | } | |
c906108c | 1128 | |
879bfdc2 | 1129 | if (return_val) |
81d0cc19 GS |
1130 | { |
1131 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1132 | message about possibly exhausted resources. */ | |
879bfdc2 | 1133 | if (hw_breakpoint_error) |
81d0cc19 | 1134 | { |
c6510018 MS |
1135 | fprintf_unfiltered (tmp_error_stream, |
1136 | "Could not insert hardware breakpoints:\n\ | |
1137 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1138 | } |
c6510018 | 1139 | #ifdef ONE_PROCESS_WRITETEXT |
81d0cc19 | 1140 | if (process_warning) |
c6510018 MS |
1141 | fprintf_unfiltered (tmp_error_stream, |
1142 | "The same program may be running in another process."); | |
1143 | #endif | |
81d0cc19 GS |
1144 | target_terminal_ours_for_output (); |
1145 | error_stream (tmp_error_stream); | |
1146 | } | |
53a5351d | 1147 | return return_val; |
c906108c SS |
1148 | } |
1149 | ||
c906108c | 1150 | int |
fba45db2 | 1151 | remove_breakpoints (void) |
c906108c | 1152 | { |
52f0bd74 | 1153 | struct breakpoint *b; |
c906108c SS |
1154 | int val; |
1155 | ||
1156 | ALL_BREAKPOINTS (b) | |
c5aa993b | 1157 | { |
5cab636d | 1158 | if (b->loc->inserted) |
c5aa993b JM |
1159 | { |
1160 | val = remove_breakpoint (b, mark_uninserted); | |
1161 | if (val != 0) | |
1162 | return val; | |
1163 | } | |
1164 | } | |
c906108c SS |
1165 | return 0; |
1166 | } | |
1167 | ||
692590c1 | 1168 | int |
80ce1ecb | 1169 | remove_hw_watchpoints (void) |
692590c1 | 1170 | { |
52f0bd74 | 1171 | struct breakpoint *b; |
692590c1 MS |
1172 | int val; |
1173 | ||
1174 | ALL_BREAKPOINTS (b) | |
1175 | { | |
5cab636d | 1176 | if (b->loc->inserted |
692590c1 MS |
1177 | && (b->type == bp_hardware_watchpoint |
1178 | || b->type == bp_read_watchpoint | |
1179 | || b->type == bp_access_watchpoint)) | |
1180 | { | |
1181 | val = remove_breakpoint (b, mark_uninserted); | |
1182 | if (val != 0) | |
1183 | return val; | |
1184 | } | |
1185 | } | |
1186 | return 0; | |
1187 | } | |
1188 | ||
c906108c | 1189 | int |
fba45db2 | 1190 | reattach_breakpoints (int pid) |
c906108c | 1191 | { |
52f0bd74 | 1192 | struct breakpoint *b; |
c906108c | 1193 | int val; |
ce696e05 | 1194 | struct cleanup *old_chain = save_inferior_ptid (); |
c906108c | 1195 | |
ce696e05 KB |
1196 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1197 | inferior_ptid = pid_to_ptid (pid); | |
c906108c | 1198 | ALL_BREAKPOINTS (b) |
c5aa993b | 1199 | { |
5cab636d | 1200 | if (b->loc->inserted) |
c5aa993b JM |
1201 | { |
1202 | remove_breakpoint (b, mark_inserted); | |
1203 | if (b->type == bp_hardware_breakpoint) | |
5cab636d | 1204 | val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents); |
c5aa993b | 1205 | else |
5cab636d | 1206 | val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents); |
c5aa993b JM |
1207 | if (val != 0) |
1208 | { | |
ce696e05 | 1209 | do_cleanups (old_chain); |
c5aa993b JM |
1210 | return val; |
1211 | } | |
1212 | } | |
1213 | } | |
ce696e05 | 1214 | do_cleanups (old_chain); |
c906108c SS |
1215 | return 0; |
1216 | } | |
1217 | ||
1218 | void | |
fba45db2 | 1219 | update_breakpoints_after_exec (void) |
c906108c | 1220 | { |
c5aa993b JM |
1221 | struct breakpoint *b; |
1222 | struct breakpoint *temp; | |
c906108c SS |
1223 | |
1224 | /* Doing this first prevents the badness of having delete_breakpoint() | |
1225 | write a breakpoint's current "shadow contents" to lift the bp. That | |
1226 | shadow is NOT valid after an exec()! */ | |
1227 | mark_breakpoints_out (); | |
1228 | ||
1229 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1230 | { |
1231 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1232 | if (b->type == bp_shlib_event) | |
1233 | { | |
1234 | delete_breakpoint (b); | |
1235 | continue; | |
1236 | } | |
c906108c | 1237 | |
1900040c MS |
1238 | /* Thread event breakpoints must be set anew after an exec(), |
1239 | as must overlay event breakpoints. */ | |
1240 | if (b->type == bp_thread_event || b->type == bp_overlay_event) | |
c4093a6a JM |
1241 | { |
1242 | delete_breakpoint (b); | |
1243 | continue; | |
1244 | } | |
1245 | ||
c5aa993b JM |
1246 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1247 | if (b->type == bp_step_resume) | |
1248 | { | |
1249 | delete_breakpoint (b); | |
1250 | continue; | |
1251 | } | |
1252 | ||
1253 | /* Ditto the sigtramp handler breakpoints. */ | |
1254 | if (b->type == bp_through_sigtramp) | |
1255 | { | |
1256 | delete_breakpoint (b); | |
1257 | continue; | |
1258 | } | |
1259 | ||
1260 | /* Ditto the exception-handling catchpoints. */ | |
1261 | if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw)) | |
1262 | { | |
1263 | delete_breakpoint (b); | |
1264 | continue; | |
1265 | } | |
1266 | ||
1267 | /* Don't delete an exec catchpoint, because else the inferior | |
1268 | won't stop when it ought! | |
1269 | ||
1270 | Similarly, we probably ought to keep vfork catchpoints, 'cause | |
53a5351d JM |
1271 | on this target, we may not be able to stop when the vfork is |
1272 | seen, but only when the subsequent exec is seen. (And because | |
1273 | deleting fork catchpoints here but not vfork catchpoints will | |
1274 | seem mysterious to users, keep those too.) | |
c5aa993b JM |
1275 | |
1276 | ??rehrauer: Let's hope that merely clearing out this catchpoint's | |
1277 | target address field, if any, is sufficient to have it be reset | |
644a1fe1 JB |
1278 | automagically. Certainly on HP-UX that's true. |
1279 | ||
1280 | Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly | |
41989fcd AC |
1281 | valid code address on some platforms (like the mn10300 |
1282 | simulators). We shouldn't assign any special interpretation to | |
1283 | a breakpoint with a zero address. And in fact, GDB doesn't --- | |
1284 | I can't see what that comment above is talking about. As far | |
1285 | as I can tell, setting the address of a | |
644a1fe1 JB |
1286 | bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero |
1287 | is meaningless, since those are implemented with HP-UX kernel | |
1288 | hackery, not by storing breakpoint instructions somewhere. */ | |
c5aa993b JM |
1289 | if ((b->type == bp_catch_exec) || |
1290 | (b->type == bp_catch_vfork) || | |
1291 | (b->type == bp_catch_fork)) | |
1292 | { | |
5cab636d | 1293 | b->loc->address = (CORE_ADDR) NULL; |
c5aa993b JM |
1294 | continue; |
1295 | } | |
1296 | ||
1297 | /* bp_finish is a special case. The only way we ought to be able | |
1298 | to see one of these when an exec() has happened, is if the user | |
1299 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1300 | carries them to the call-site of the current callee, by setting | |
1301 | a temporary bp there and resuming. But in this case, the finish | |
1302 | will carry them entirely through the vfork & exec. | |
1303 | ||
1304 | We don't want to allow a bp_finish to remain inserted now. But | |
1305 | we can't safely delete it, 'cause finish_command has a handle to | |
1306 | the bp on a bpstat, and will later want to delete it. There's a | |
1307 | chance (and I've seen it happen) that if we delete the bp_finish | |
1308 | here, that its storage will get reused by the time finish_command | |
1309 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1310 | We really must allow finish_command to delete a bp_finish. | |
1311 | ||
53a5351d JM |
1312 | In the absense of a general solution for the "how do we know |
1313 | it's safe to delete something others may have handles to?" | |
1314 | problem, what we'll do here is just uninsert the bp_finish, and | |
1315 | let finish_command delete it. | |
1316 | ||
1317 | (We know the bp_finish is "doomed" in the sense that it's | |
1318 | momentary, and will be deleted as soon as finish_command sees | |
1319 | the inferior stopped. So it doesn't matter that the bp's | |
1320 | address is probably bogus in the new a.out, unlike e.g., the | |
1321 | solib breakpoints.) */ | |
c5aa993b | 1322 | |
c5aa993b JM |
1323 | if (b->type == bp_finish) |
1324 | { | |
1325 | continue; | |
1326 | } | |
1327 | ||
1328 | /* Without a symbolic address, we have little hope of the | |
1329 | pre-exec() address meaning the same thing in the post-exec() | |
1330 | a.out. */ | |
1331 | if (b->addr_string == NULL) | |
1332 | { | |
1333 | delete_breakpoint (b); | |
1334 | continue; | |
1335 | } | |
1336 | ||
1337 | /* If this breakpoint has survived the above battery of checks, then | |
1338 | it must have a symbolic address. Be sure that it gets reevaluated | |
644a1fe1 JB |
1339 | to a target address, rather than reusing the old evaluation. |
1340 | ||
1341 | Jim Blandy <jimb@redhat.com>: As explained above in the comment | |
1342 | for bp_catch_exec and friends, I'm pretty sure this is entirely | |
1343 | unnecessary. A call to breakpoint_re_set_one always recomputes | |
1344 | the breakpoint's address from scratch, or deletes it if it can't. | |
1345 | So I think this assignment could be deleted without effect. */ | |
5cab636d | 1346 | b->loc->address = (CORE_ADDR) NULL; |
c5aa993b | 1347 | } |
1900040c MS |
1348 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
1349 | create_overlay_event_breakpoint ("_ovly_debug_event"); | |
c906108c SS |
1350 | } |
1351 | ||
1352 | int | |
fba45db2 | 1353 | detach_breakpoints (int pid) |
c906108c | 1354 | { |
52f0bd74 | 1355 | struct breakpoint *b; |
c906108c | 1356 | int val; |
ce696e05 | 1357 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1358 | |
39f77062 KB |
1359 | if (pid == PIDGET (inferior_ptid)) |
1360 | error ("Cannot detach breakpoints of inferior_ptid"); | |
c5aa993b | 1361 | |
ce696e05 KB |
1362 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1363 | inferior_ptid = pid_to_ptid (pid); | |
c906108c | 1364 | ALL_BREAKPOINTS (b) |
c5aa993b | 1365 | { |
5cab636d | 1366 | if (b->loc->inserted) |
c5aa993b JM |
1367 | { |
1368 | val = remove_breakpoint (b, mark_inserted); | |
1369 | if (val != 0) | |
1370 | { | |
ce696e05 | 1371 | do_cleanups (old_chain); |
c5aa993b JM |
1372 | return val; |
1373 | } | |
1374 | } | |
1375 | } | |
ce696e05 | 1376 | do_cleanups (old_chain); |
c906108c SS |
1377 | return 0; |
1378 | } | |
1379 | ||
1380 | static int | |
fba45db2 | 1381 | remove_breakpoint (struct breakpoint *b, insertion_state_t is) |
c906108c SS |
1382 | { |
1383 | int val; | |
c5aa993b | 1384 | |
b5de0fa7 | 1385 | if (b->enable_state == bp_permanent) |
c2c6d25f JM |
1386 | /* Permanent breakpoints cannot be inserted or removed. */ |
1387 | return 0; | |
1388 | ||
c906108c | 1389 | if (b->type == bp_none) |
53a5351d JM |
1390 | warning ("attempted to remove apparently deleted breakpoint #%d?", |
1391 | b->number); | |
c906108c SS |
1392 | |
1393 | if (b->type != bp_watchpoint | |
1394 | && b->type != bp_hardware_watchpoint | |
1395 | && b->type != bp_read_watchpoint | |
1396 | && b->type != bp_access_watchpoint | |
1397 | && b->type != bp_catch_fork | |
1398 | && b->type != bp_catch_vfork | |
1399 | && b->type != bp_catch_exec | |
1400 | && b->type != bp_catch_catch | |
1401 | && b->type != bp_catch_throw) | |
c906108c | 1402 | { |
c02f5703 MS |
1403 | /* "Normal" instruction breakpoint: either the standard |
1404 | trap-instruction bp (bp_breakpoint), or a | |
1405 | bp_hardware_breakpoint. */ | |
1406 | ||
1407 | /* First check to see if we have to handle an overlay. */ | |
1408 | if (overlay_debugging == ovly_off | |
cf3a9e5b DJ |
1409 | || b->loc->section == NULL |
1410 | || !(section_is_overlay (b->loc->section))) | |
c02f5703 MS |
1411 | { |
1412 | /* No overlay handling: just remove the breakpoint. */ | |
1413 | ||
1414 | if (b->type == bp_hardware_breakpoint) | |
5cab636d DJ |
1415 | val = target_remove_hw_breakpoint (b->loc->address, |
1416 | b->loc->shadow_contents); | |
c02f5703 | 1417 | else |
5cab636d | 1418 | val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents); |
c02f5703 | 1419 | } |
c906108c SS |
1420 | else |
1421 | { | |
c02f5703 MS |
1422 | /* This breakpoint is in an overlay section. |
1423 | Did we set a breakpoint at the LMA? */ | |
1424 | if (!overlay_events_enabled) | |
1425 | { | |
1426 | /* Yes -- overlay event support is not active, so we | |
1427 | should have set a breakpoint at the LMA. Remove it. | |
1428 | */ | |
5cab636d | 1429 | CORE_ADDR addr = overlay_unmapped_address (b->loc->address, |
cf3a9e5b | 1430 | b->loc->section); |
c02f5703 MS |
1431 | /* Ignore any failures: if the LMA is in ROM, we will |
1432 | have already warned when we failed to insert it. */ | |
1433 | if (b->type != bp_hardware_breakpoint) | |
5cab636d | 1434 | target_remove_hw_breakpoint (addr, b->loc->shadow_contents); |
c02f5703 | 1435 | else |
5cab636d | 1436 | target_remove_breakpoint (addr, b->loc->shadow_contents); |
c02f5703 MS |
1437 | } |
1438 | /* Did we set a breakpoint at the VMA? | |
1439 | If so, we will have marked the breakpoint 'inserted'. */ | |
5cab636d | 1440 | if (b->loc->inserted) |
c906108c | 1441 | { |
c02f5703 MS |
1442 | /* Yes -- remove it. Previously we did not bother to |
1443 | remove the breakpoint if the section had been | |
1444 | unmapped, but let's not rely on that being safe. We | |
1445 | don't know what the overlay manager might do. */ | |
1446 | if (b->type == bp_hardware_breakpoint) | |
5cab636d DJ |
1447 | val = target_remove_hw_breakpoint (b->loc->address, |
1448 | b->loc->shadow_contents); | |
c02f5703 | 1449 | else |
5cab636d DJ |
1450 | val = target_remove_breakpoint (b->loc->address, |
1451 | b->loc->shadow_contents); | |
c906108c | 1452 | } |
c02f5703 MS |
1453 | else |
1454 | { | |
1455 | /* No -- not inserted, so no need to remove. No error. */ | |
1456 | val = 0; | |
1457 | } | |
c906108c SS |
1458 | } |
1459 | if (val) | |
1460 | return val; | |
5cab636d | 1461 | b->loc->inserted = (is == mark_inserted); |
c906108c SS |
1462 | } |
1463 | else if ((b->type == bp_hardware_watchpoint || | |
c5aa993b JM |
1464 | b->type == bp_read_watchpoint || |
1465 | b->type == bp_access_watchpoint) | |
b5de0fa7 | 1466 | && b->enable_state == bp_enabled |
5cab636d | 1467 | && !b->loc->duplicate) |
c906108c | 1468 | { |
278cd55f AC |
1469 | struct value *v; |
1470 | struct value *n; | |
c5aa993b | 1471 | |
5cab636d | 1472 | b->loc->inserted = (is == mark_inserted); |
c906108c SS |
1473 | /* Walk down the saved value chain. */ |
1474 | for (v = b->val_chain; v; v = v->next) | |
1475 | { | |
1476 | /* For each memory reference remove the watchpoint | |
1477 | at that address. */ | |
5c44784c JM |
1478 | if (VALUE_LVAL (v) == lval_memory |
1479 | && ! VALUE_LAZY (v)) | |
c906108c | 1480 | { |
2e70b7b9 MS |
1481 | struct type *vtype = check_typedef (VALUE_TYPE (v)); |
1482 | ||
1483 | if (v == b->val_chain | |
1484 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
1485 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1486 | { | |
1487 | CORE_ADDR addr; | |
1488 | int len, type; | |
1489 | ||
1490 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
1491 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
1492 | type = hw_write; | |
1493 | if (b->type == bp_read_watchpoint) | |
1494 | type = hw_read; | |
1495 | else if (b->type == bp_access_watchpoint) | |
1496 | type = hw_access; | |
1497 | ||
1498 | val = target_remove_watchpoint (addr, len, type); | |
1499 | if (val == -1) | |
5cab636d | 1500 | b->loc->inserted = 1; |
2e70b7b9 MS |
1501 | val = 0; |
1502 | } | |
c906108c SS |
1503 | } |
1504 | } | |
1505 | /* Failure to remove any of the hardware watchpoints comes here. */ | |
5cab636d | 1506 | if ((is == mark_uninserted) && (b->loc->inserted)) |
53a5351d | 1507 | warning ("Could not remove hardware watchpoint %d.", |
c906108c | 1508 | b->number); |
c5aa993b | 1509 | |
c906108c | 1510 | /* Free the saved value chain. We will construct a new one |
c5aa993b | 1511 | the next time the watchpoint is inserted. */ |
c906108c SS |
1512 | for (v = b->val_chain; v; v = n) |
1513 | { | |
1514 | n = v->next; | |
1515 | value_free (v); | |
1516 | } | |
1517 | b->val_chain = NULL; | |
1518 | } | |
1519 | else if ((b->type == bp_catch_fork || | |
c5aa993b JM |
1520 | b->type == bp_catch_vfork || |
1521 | b->type == bp_catch_exec) | |
b5de0fa7 | 1522 | && b->enable_state == bp_enabled |
5cab636d | 1523 | && !b->loc->duplicate) |
c906108c SS |
1524 | { |
1525 | val = -1; | |
1526 | switch (b->type) | |
c5aa993b JM |
1527 | { |
1528 | case bp_catch_fork: | |
39f77062 | 1529 | val = target_remove_fork_catchpoint (PIDGET (inferior_ptid)); |
c5aa993b JM |
1530 | break; |
1531 | case bp_catch_vfork: | |
39f77062 | 1532 | val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); |
c5aa993b JM |
1533 | break; |
1534 | case bp_catch_exec: | |
39f77062 | 1535 | val = target_remove_exec_catchpoint (PIDGET (inferior_ptid)); |
c5aa993b | 1536 | break; |
ac9a91a7 | 1537 | default: |
53a5351d | 1538 | warning ("Internal error, %s line %d.", __FILE__, __LINE__); |
ac9a91a7 | 1539 | break; |
c5aa993b | 1540 | } |
c906108c SS |
1541 | if (val) |
1542 | return val; | |
5cab636d | 1543 | b->loc->inserted = (is == mark_inserted); |
c906108c SS |
1544 | } |
1545 | else if ((b->type == bp_catch_catch || | |
c5aa993b | 1546 | b->type == bp_catch_throw) |
b5de0fa7 | 1547 | && b->enable_state == bp_enabled |
5cab636d | 1548 | && !b->loc->duplicate) |
c906108c SS |
1549 | { |
1550 | ||
5cab636d | 1551 | val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents); |
c906108c | 1552 | if (val) |
c5aa993b | 1553 | return val; |
5cab636d | 1554 | b->loc->inserted = (is == mark_inserted); |
c906108c SS |
1555 | } |
1556 | else if (ep_is_exception_catchpoint (b) | |
5cab636d | 1557 | && b->loc->inserted /* sometimes previous insert doesn't happen */ |
b5de0fa7 | 1558 | && b->enable_state == bp_enabled |
5cab636d | 1559 | && !b->loc->duplicate) |
c906108c SS |
1560 | { |
1561 | ||
5cab636d | 1562 | val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents); |
c906108c | 1563 | if (val) |
c5aa993b JM |
1564 | return val; |
1565 | ||
5cab636d | 1566 | b->loc->inserted = (is == mark_inserted); |
c906108c SS |
1567 | } |
1568 | ||
1569 | return 0; | |
1570 | } | |
1571 | ||
1572 | /* Clear the "inserted" flag in all breakpoints. */ | |
1573 | ||
1574 | void | |
fba45db2 | 1575 | mark_breakpoints_out (void) |
c906108c | 1576 | { |
52f0bd74 | 1577 | struct breakpoint *b; |
c906108c SS |
1578 | |
1579 | ALL_BREAKPOINTS (b) | |
5cab636d | 1580 | b->loc->inserted = 0; |
c906108c SS |
1581 | } |
1582 | ||
53a5351d JM |
1583 | /* Clear the "inserted" flag in all breakpoints and delete any |
1584 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1585 | |
1586 | Plus other such housekeeping that has to be done for breakpoints | |
1587 | between runs. | |
1588 | ||
53a5351d JM |
1589 | Note: this function gets called at the end of a run (by |
1590 | generic_mourn_inferior) and when a run begins (by | |
1591 | init_wait_for_inferior). */ | |
c906108c SS |
1592 | |
1593 | ||
1594 | ||
1595 | void | |
fba45db2 | 1596 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1597 | { |
52f0bd74 | 1598 | struct breakpoint *b, *temp; |
c906108c SS |
1599 | static int warning_needed = 0; |
1600 | ||
1601 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1602 | { |
5cab636d | 1603 | b->loc->inserted = 0; |
c906108c | 1604 | |
c5aa993b JM |
1605 | switch (b->type) |
1606 | { | |
1607 | case bp_call_dummy: | |
1608 | case bp_watchpoint_scope: | |
c906108c | 1609 | |
c5aa993b JM |
1610 | /* If the call dummy breakpoint is at the entry point it will |
1611 | cause problems when the inferior is rerun, so we better | |
1612 | get rid of it. | |
c906108c | 1613 | |
c5aa993b JM |
1614 | Also get rid of scope breakpoints. */ |
1615 | delete_breakpoint (b); | |
1616 | break; | |
c906108c | 1617 | |
c5aa993b JM |
1618 | case bp_watchpoint: |
1619 | case bp_hardware_watchpoint: | |
1620 | case bp_read_watchpoint: | |
1621 | case bp_access_watchpoint: | |
c906108c | 1622 | |
c5aa993b JM |
1623 | /* Likewise for watchpoints on local expressions. */ |
1624 | if (b->exp_valid_block != NULL) | |
1625 | delete_breakpoint (b); | |
c860120c PM |
1626 | if (context == inf_starting) |
1627 | { | |
1628 | /* Reset val field to force reread of starting value | |
1629 | in insert_breakpoints. */ | |
1630 | if (b->val) | |
1631 | value_free (b->val); | |
1632 | b->val = NULL; | |
1633 | } | |
c5aa993b JM |
1634 | break; |
1635 | default: | |
1636 | /* Likewise for exception catchpoints in dynamic-linked | |
1637 | executables where required */ | |
1638 | if (ep_is_exception_catchpoint (b) && | |
1639 | exception_catchpoints_are_fragile) | |
1640 | { | |
1641 | warning_needed = 1; | |
c906108c | 1642 | delete_breakpoint (b); |
c5aa993b JM |
1643 | } |
1644 | break; | |
1645 | } | |
1646 | } | |
c906108c SS |
1647 | |
1648 | if (exception_catchpoints_are_fragile) | |
1649 | exception_support_initialized = 0; | |
1650 | ||
c5aa993b | 1651 | /* Don't issue the warning unless it's really needed... */ |
c906108c SS |
1652 | if (warning_needed && (context != inf_exited)) |
1653 | { | |
53a5351d JM |
1654 | warning ("Exception catchpoints from last run were deleted."); |
1655 | warning ("You must reinsert them explicitly."); | |
c906108c | 1656 | warning_needed = 0; |
c5aa993b | 1657 | } |
c906108c SS |
1658 | } |
1659 | ||
c2c6d25f JM |
1660 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1661 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1662 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1663 | permanent breakpoint. | |
1664 | - When continuing from a location with an ordinary breakpoint, we | |
1665 | actually single step once before calling insert_breakpoints. | |
1666 | - When continuing from a localion with a permanent breakpoint, we | |
1667 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1668 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1669 | |
c2c6d25f | 1670 | enum breakpoint_here |
fba45db2 | 1671 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1672 | { |
52f0bd74 | 1673 | struct breakpoint *b; |
c2c6d25f | 1674 | int any_breakpoint_here = 0; |
c906108c SS |
1675 | |
1676 | ALL_BREAKPOINTS (b) | |
b5de0fa7 EZ |
1677 | if ((b->enable_state == bp_enabled |
1678 | || b->enable_state == bp_permanent) | |
5cab636d | 1679 | && b->loc->address == pc) /* bp is enabled and matches pc */ |
c2c6d25f | 1680 | { |
9f04af04 | 1681 | if (overlay_debugging |
cf3a9e5b DJ |
1682 | && section_is_overlay (b->loc->section) |
1683 | && !section_is_mapped (b->loc->section)) | |
c2c6d25f | 1684 | continue; /* unmapped overlay -- can't be a match */ |
b5de0fa7 | 1685 | else if (b->enable_state == bp_permanent) |
c2c6d25f JM |
1686 | return permanent_breakpoint_here; |
1687 | else | |
1688 | any_breakpoint_here = 1; | |
1689 | } | |
c906108c | 1690 | |
c2c6d25f | 1691 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1692 | } |
1693 | ||
c2c6d25f | 1694 | |
53a5351d JM |
1695 | /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), |
1696 | but it only returns true if there is actually a breakpoint inserted | |
1697 | at PC. */ | |
c906108c SS |
1698 | |
1699 | int | |
fba45db2 | 1700 | breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1701 | { |
52f0bd74 | 1702 | struct breakpoint *b; |
c906108c SS |
1703 | |
1704 | ALL_BREAKPOINTS (b) | |
5cab636d DJ |
1705 | if (b->loc->inserted |
1706 | && b->loc->address == pc) /* bp is inserted and matches pc */ | |
c5aa993b | 1707 | { |
9f04af04 | 1708 | if (overlay_debugging |
cf3a9e5b DJ |
1709 | && section_is_overlay (b->loc->section) |
1710 | && !section_is_mapped (b->loc->section)) | |
c5aa993b JM |
1711 | continue; /* unmapped overlay -- can't be a match */ |
1712 | else | |
1713 | return 1; | |
1714 | } | |
c906108c SS |
1715 | |
1716 | return 0; | |
1717 | } | |
1718 | ||
53a5351d | 1719 | /* Return nonzero if FRAME is a dummy frame. We can't use |
ae45cd16 | 1720 | DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would |
ac2adee5 | 1721 | take too much time, at least using frame_register() on the 68k. |
ae45cd16 | 1722 | This means that for this function to work right a port must use the |
53a5351d | 1723 | bp_call_dummy breakpoint. */ |
c906108c SS |
1724 | |
1725 | int | |
bf1e52be | 1726 | deprecated_frame_in_dummy (struct frame_info *frame) |
c906108c | 1727 | { |
c906108c SS |
1728 | struct breakpoint *b; |
1729 | ||
0225421b | 1730 | /* This function is used by two files: get_frame_type(), after first |
07555a72 AC |
1731 | checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and |
1732 | sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */ | |
1733 | gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES); | |
c5aa993b | 1734 | |
c906108c | 1735 | ALL_BREAKPOINTS (b) |
c5aa993b JM |
1736 | { |
1737 | if (b->type == bp_call_dummy | |
818dd999 | 1738 | && frame_id_eq (b->frame_id, get_frame_id (frame)) |
c5aa993b JM |
1739 | /* We need to check the PC as well as the frame on the sparc, |
1740 | for signals.exp in the testsuite. */ | |
bdd78e62 | 1741 | && (get_frame_pc (frame) |
5cab636d | 1742 | >= (b->loc->address |
b1e29e33 | 1743 | - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE)) |
5cab636d | 1744 | && get_frame_pc (frame) <= b->loc->address) |
c5aa993b JM |
1745 | return 1; |
1746 | } | |
c906108c SS |
1747 | return 0; |
1748 | } | |
1749 | ||
2c8f79c2 MS |
1750 | /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at |
1751 | PC is valid for process/thread PID. */ | |
c906108c SS |
1752 | |
1753 | int | |
39f77062 | 1754 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c SS |
1755 | { |
1756 | struct breakpoint *b; | |
1757 | int thread; | |
1758 | ||
39f77062 | 1759 | thread = pid_to_thread_id (ptid); |
c906108c SS |
1760 | |
1761 | ALL_BREAKPOINTS (b) | |
b5de0fa7 EZ |
1762 | if (b->enable_state != bp_disabled |
1763 | && b->enable_state != bp_shlib_disabled | |
1764 | && b->enable_state != bp_call_disabled | |
5cab636d | 1765 | && b->loc->address == pc |
c906108c | 1766 | && (b->thread == -1 || b->thread == thread)) |
c5aa993b | 1767 | { |
9f04af04 | 1768 | if (overlay_debugging |
cf3a9e5b DJ |
1769 | && section_is_overlay (b->loc->section) |
1770 | && !section_is_mapped (b->loc->section)) | |
c5aa993b JM |
1771 | continue; /* unmapped overlay -- can't be a match */ |
1772 | else | |
1773 | return 1; | |
1774 | } | |
c906108c SS |
1775 | |
1776 | return 0; | |
1777 | } | |
c906108c | 1778 | \f |
c5aa993b | 1779 | |
c906108c SS |
1780 | /* bpstat stuff. External routines' interfaces are documented |
1781 | in breakpoint.h. */ | |
1782 | ||
1783 | int | |
fba45db2 | 1784 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c SS |
1785 | { |
1786 | return | |
1787 | (ep->type == bp_catch_load) | |
1788 | || (ep->type == bp_catch_unload) | |
1789 | || (ep->type == bp_catch_fork) | |
1790 | || (ep->type == bp_catch_vfork) | |
1791 | || (ep->type == bp_catch_exec) | |
1792 | || (ep->type == bp_catch_catch) | |
d85310f7 | 1793 | || (ep->type == bp_catch_throw); |
c906108c | 1794 | |
c5aa993b | 1795 | /* ??rehrauer: Add more kinds here, as are implemented... */ |
c906108c | 1796 | } |
c5aa993b | 1797 | |
c906108c | 1798 | int |
fba45db2 | 1799 | ep_is_shlib_catchpoint (struct breakpoint *ep) |
c906108c SS |
1800 | { |
1801 | return | |
1802 | (ep->type == bp_catch_load) | |
d85310f7 | 1803 | || (ep->type == bp_catch_unload); |
c906108c SS |
1804 | } |
1805 | ||
1806 | int | |
fba45db2 | 1807 | ep_is_exception_catchpoint (struct breakpoint *ep) |
c906108c SS |
1808 | { |
1809 | return | |
1810 | (ep->type == bp_catch_catch) | |
d85310f7 | 1811 | || (ep->type == bp_catch_throw); |
c906108c SS |
1812 | } |
1813 | ||
1814 | /* Clear a bpstat so that it says we are not at any breakpoint. | |
1815 | Also free any storage that is part of a bpstat. */ | |
1816 | ||
1817 | void | |
fba45db2 | 1818 | bpstat_clear (bpstat *bsp) |
c906108c SS |
1819 | { |
1820 | bpstat p; | |
1821 | bpstat q; | |
1822 | ||
1823 | if (bsp == 0) | |
1824 | return; | |
1825 | p = *bsp; | |
1826 | while (p != NULL) | |
1827 | { | |
1828 | q = p->next; | |
1829 | if (p->old_val != NULL) | |
1830 | value_free (p->old_val); | |
c2b8ed2c | 1831 | free_command_lines (&p->commands); |
b8c9b27d | 1832 | xfree (p); |
c906108c SS |
1833 | p = q; |
1834 | } | |
1835 | *bsp = NULL; | |
1836 | } | |
1837 | ||
1838 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
1839 | is part of the bpstat is copied as well. */ | |
1840 | ||
1841 | bpstat | |
fba45db2 | 1842 | bpstat_copy (bpstat bs) |
c906108c SS |
1843 | { |
1844 | bpstat p = NULL; | |
1845 | bpstat tmp; | |
1846 | bpstat retval = NULL; | |
1847 | ||
1848 | if (bs == NULL) | |
1849 | return bs; | |
1850 | ||
1851 | for (; bs != NULL; bs = bs->next) | |
1852 | { | |
1853 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
1854 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
1855 | if (bs->commands != NULL) |
1856 | tmp->commands = copy_command_lines (bs->commands); | |
1857 | if (bs->old_val != NULL) | |
1858 | tmp->old_val = value_copy (bs->old_val); | |
1859 | ||
c906108c SS |
1860 | if (p == NULL) |
1861 | /* This is the first thing in the chain. */ | |
1862 | retval = tmp; | |
1863 | else | |
1864 | p->next = tmp; | |
1865 | p = tmp; | |
1866 | } | |
1867 | p->next = NULL; | |
1868 | return retval; | |
1869 | } | |
1870 | ||
1871 | /* Find the bpstat associated with this breakpoint */ | |
1872 | ||
1873 | bpstat | |
fba45db2 | 1874 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 1875 | { |
c5aa993b JM |
1876 | if (bsp == NULL) |
1877 | return NULL; | |
c906108c | 1878 | |
c5aa993b JM |
1879 | for (; bsp != NULL; bsp = bsp->next) |
1880 | { | |
1881 | if (bsp->breakpoint_at == breakpoint) | |
1882 | return bsp; | |
1883 | } | |
c906108c SS |
1884 | return NULL; |
1885 | } | |
1886 | ||
1887 | /* Find a step_resume breakpoint associated with this bpstat. | |
1888 | (If there are multiple step_resume bp's on the list, this function | |
1889 | will arbitrarily pick one.) | |
1890 | ||
1891 | It is an error to use this function if BPSTAT doesn't contain a | |
1892 | step_resume breakpoint. | |
1893 | ||
1894 | See wait_for_inferior's use of this function. */ | |
1895 | struct breakpoint * | |
fba45db2 | 1896 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 1897 | { |
8601f500 MS |
1898 | int current_thread; |
1899 | ||
c906108c SS |
1900 | if (bsp == NULL) |
1901 | error ("Internal error (bpstat_find_step_resume_breakpoint)"); | |
1902 | ||
8601f500 MS |
1903 | current_thread = pid_to_thread_id (inferior_ptid); |
1904 | ||
c906108c SS |
1905 | for (; bsp != NULL; bsp = bsp->next) |
1906 | { | |
1907 | if ((bsp->breakpoint_at != NULL) && | |
8601f500 MS |
1908 | (bsp->breakpoint_at->type == bp_step_resume) && |
1909 | (bsp->breakpoint_at->thread == current_thread || | |
1910 | bsp->breakpoint_at->thread == -1)) | |
c5aa993b | 1911 | return bsp->breakpoint_at; |
c906108c SS |
1912 | } |
1913 | ||
1914 | error ("Internal error (no step_resume breakpoint found)"); | |
1915 | } | |
1916 | ||
1917 | ||
1918 | /* Return the breakpoint number of the first breakpoint we are stopped | |
1919 | at. *BSP upon return is a bpstat which points to the remaining | |
1920 | breakpoints stopped at (but which is not guaranteed to be good for | |
1921 | anything but further calls to bpstat_num). | |
1922 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ | |
1923 | ||
1924 | int | |
fba45db2 | 1925 | bpstat_num (bpstat *bsp) |
c906108c SS |
1926 | { |
1927 | struct breakpoint *b; | |
1928 | ||
1929 | if ((*bsp) == NULL) | |
1930 | return 0; /* No more breakpoint values */ | |
1931 | else | |
1932 | { | |
1933 | b = (*bsp)->breakpoint_at; | |
1934 | *bsp = (*bsp)->next; | |
1935 | if (b == NULL) | |
1936 | return -1; /* breakpoint that's been deleted since */ | |
1937 | else | |
c5aa993b | 1938 | return b->number; /* We have its number */ |
c906108c SS |
1939 | } |
1940 | } | |
1941 | ||
1942 | /* Modify BS so that the actions will not be performed. */ | |
1943 | ||
1944 | void | |
fba45db2 | 1945 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
1946 | { |
1947 | for (; bs != NULL; bs = bs->next) | |
1948 | { | |
c2b8ed2c | 1949 | free_command_lines (&bs->commands); |
c906108c SS |
1950 | if (bs->old_val != NULL) |
1951 | { | |
1952 | value_free (bs->old_val); | |
1953 | bs->old_val = NULL; | |
1954 | } | |
1955 | } | |
1956 | } | |
1957 | ||
1958 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ | |
c906108c | 1959 | static void |
4efb68b1 | 1960 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
1961 | { |
1962 | executing_breakpoint_commands = 0; | |
1963 | } | |
1964 | ||
1965 | /* Execute all the commands associated with all the breakpoints at this | |
1966 | location. Any of these commands could cause the process to proceed | |
1967 | beyond this point, etc. We look out for such changes by checking | |
1968 | the global "breakpoint_proceeded" after each command. */ | |
1969 | ||
1970 | void | |
fba45db2 | 1971 | bpstat_do_actions (bpstat *bsp) |
c906108c SS |
1972 | { |
1973 | bpstat bs; | |
1974 | struct cleanup *old_chain; | |
1975 | struct command_line *cmd; | |
1976 | ||
1977 | /* Avoid endless recursion if a `source' command is contained | |
1978 | in bs->commands. */ | |
1979 | if (executing_breakpoint_commands) | |
1980 | return; | |
1981 | ||
1982 | executing_breakpoint_commands = 1; | |
1983 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
1984 | ||
1985 | top: | |
1986 | /* Note that (as of this writing), our callers all appear to | |
1987 | be passing us the address of global stop_bpstat. And, if | |
1988 | our calls to execute_control_command cause the inferior to | |
1989 | proceed, that global (and hence, *bsp) will change. | |
1990 | ||
1991 | We must be careful to not touch *bsp unless the inferior | |
1992 | has not proceeded. */ | |
1993 | ||
1994 | /* This pointer will iterate over the list of bpstat's. */ | |
1995 | bs = *bsp; | |
1996 | ||
1997 | breakpoint_proceeded = 0; | |
1998 | for (; bs != NULL; bs = bs->next) | |
1999 | { | |
2000 | cmd = bs->commands; | |
2001 | while (cmd != NULL) | |
2002 | { | |
2003 | execute_control_command (cmd); | |
2004 | ||
2005 | if (breakpoint_proceeded) | |
2006 | break; | |
2007 | else | |
2008 | cmd = cmd->next; | |
2009 | } | |
2010 | if (breakpoint_proceeded) | |
2011 | /* The inferior is proceeded by the command; bomb out now. | |
2012 | The bpstat chain has been blown away by wait_for_inferior. | |
2013 | But since execution has stopped again, there is a new bpstat | |
2014 | to look at, so start over. */ | |
2015 | goto top; | |
2016 | else | |
c2b8ed2c | 2017 | free_command_lines (&bs->commands); |
c906108c | 2018 | } |
c2b8ed2c | 2019 | do_cleanups (old_chain); |
c906108c SS |
2020 | } |
2021 | ||
e514a9d6 | 2022 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2023 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2024 | by having it set different print_it values. |
2025 | ||
2026 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2027 | through the bpstat list of things causing this stop, calling the | |
2028 | print_bp_stop_message function on each one. The behavior of the | |
2029 | print_bp_stop_message function depends on the print_it field of | |
2030 | bpstat. If such field so indicates, call this function here. | |
2031 | ||
2032 | Return values from this routine (ultimately used by bpstat_print() | |
2033 | and normal_stop() to decide what to do): | |
2034 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2035 | don't print anything else. | |
2036 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2037 | that something to be followed by a location. | |
2038 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2039 | that something to be followed by a location. | |
2040 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2041 | analysis. */ | |
c906108c | 2042 | |
917317f4 | 2043 | static enum print_stop_action |
fba45db2 | 2044 | print_it_typical (bpstat bs) |
c906108c | 2045 | { |
3b31d625 | 2046 | struct cleanup *old_chain, *ui_out_chain; |
8b93c638 JM |
2047 | struct ui_stream *stb; |
2048 | stb = ui_out_stream_new (uiout); | |
b02eeafb | 2049 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
c906108c SS |
2050 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2051 | which has since been deleted. */ | |
e514a9d6 | 2052 | if (bs->breakpoint_at == NULL) |
917317f4 | 2053 | return PRINT_UNKNOWN; |
c906108c | 2054 | |
e514a9d6 | 2055 | switch (bs->breakpoint_at->type) |
c906108c | 2056 | { |
e514a9d6 JM |
2057 | case bp_breakpoint: |
2058 | case bp_hardware_breakpoint: | |
5cab636d DJ |
2059 | if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address) |
2060 | breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address, | |
2061 | bs->breakpoint_at->loc->address, | |
76897487 | 2062 | bs->breakpoint_at->number, 1); |
8b93c638 JM |
2063 | annotate_breakpoint (bs->breakpoint_at->number); |
2064 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2065 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2066 | ui_out_field_string (uiout, "reason", "breakpoint-hit"); |
8b93c638 JM |
2067 | ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number); |
2068 | ui_out_text (uiout, ", "); | |
2069 | return PRINT_SRC_AND_LOC; | |
e514a9d6 JM |
2070 | break; |
2071 | ||
2072 | case bp_shlib_event: | |
917317f4 JM |
2073 | /* Did we stop because the user set the stop_on_solib_events |
2074 | variable? (If so, we report this as a generic, "Stopped due | |
2075 | to shlib event" message.) */ | |
e514a9d6 JM |
2076 | printf_filtered ("Stopped due to shared library event\n"); |
2077 | return PRINT_NOTHING; | |
2078 | break; | |
2079 | ||
c4093a6a JM |
2080 | case bp_thread_event: |
2081 | /* Not sure how we will get here. | |
2082 | GDB should not stop for these breakpoints. */ | |
2083 | printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n"); | |
2084 | return PRINT_NOTHING; | |
2085 | break; | |
2086 | ||
1900040c MS |
2087 | case bp_overlay_event: |
2088 | /* By analogy with the thread event, GDB should not stop for these. */ | |
2089 | printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n"); | |
2090 | return PRINT_NOTHING; | |
2091 | break; | |
2092 | ||
e514a9d6 | 2093 | case bp_catch_load: |
c906108c SS |
2094 | annotate_catchpoint (bs->breakpoint_at->number); |
2095 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
e514a9d6 JM |
2096 | printf_filtered ("loaded"); |
2097 | printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname); | |
2098 | return PRINT_SRC_AND_LOC; | |
2099 | break; | |
2100 | ||
2101 | case bp_catch_unload: | |
2102 | annotate_catchpoint (bs->breakpoint_at->number); | |
2103 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
2104 | printf_filtered ("unloaded"); | |
2105 | printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname); | |
2106 | return PRINT_SRC_AND_LOC; | |
2107 | break; | |
2108 | ||
2109 | case bp_catch_fork: | |
2110 | annotate_catchpoint (bs->breakpoint_at->number); | |
2111 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
2112 | printf_filtered ("forked"); | |
53a5351d JM |
2113 | printf_filtered (" process %d), ", |
2114 | bs->breakpoint_at->forked_inferior_pid); | |
917317f4 | 2115 | return PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2116 | break; |
2117 | ||
2118 | case bp_catch_vfork: | |
2119 | annotate_catchpoint (bs->breakpoint_at->number); | |
2120 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
2121 | printf_filtered ("vforked"); | |
2122 | printf_filtered (" process %d), ", | |
2123 | bs->breakpoint_at->forked_inferior_pid); | |
2124 | return PRINT_SRC_AND_LOC; | |
2125 | break; | |
2126 | ||
2127 | case bp_catch_exec: | |
c906108c SS |
2128 | annotate_catchpoint (bs->breakpoint_at->number); |
2129 | printf_filtered ("\nCatchpoint %d (exec'd %s), ", | |
c5aa993b JM |
2130 | bs->breakpoint_at->number, |
2131 | bs->breakpoint_at->exec_pathname); | |
917317f4 | 2132 | return PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2133 | break; |
2134 | ||
2135 | case bp_catch_catch: | |
53a5351d JM |
2136 | if (current_exception_event && |
2137 | (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH)) | |
c5aa993b JM |
2138 | { |
2139 | annotate_catchpoint (bs->breakpoint_at->number); | |
53a5351d JM |
2140 | printf_filtered ("\nCatchpoint %d (exception caught), ", |
2141 | bs->breakpoint_at->number); | |
c5aa993b JM |
2142 | printf_filtered ("throw location "); |
2143 | if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) | |
2144 | printf_filtered ("%s:%d", | |
2145 | CURRENT_EXCEPTION_THROW_FILE, | |
2146 | CURRENT_EXCEPTION_THROW_LINE); | |
2147 | else | |
2148 | printf_filtered ("unknown"); | |
2149 | ||
2150 | printf_filtered (", catch location "); | |
2151 | if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) | |
2152 | printf_filtered ("%s:%d", | |
2153 | CURRENT_EXCEPTION_CATCH_FILE, | |
2154 | CURRENT_EXCEPTION_CATCH_LINE); | |
2155 | else | |
2156 | printf_filtered ("unknown"); | |
2157 | ||
2158 | printf_filtered ("\n"); | |
e514a9d6 JM |
2159 | /* don't bother to print location frame info */ |
2160 | return PRINT_SRC_ONLY; | |
c5aa993b | 2161 | } |
c906108c | 2162 | else |
c5aa993b | 2163 | { |
e514a9d6 JM |
2164 | /* really throw, some other bpstat will handle it */ |
2165 | return PRINT_UNKNOWN; | |
c5aa993b | 2166 | } |
e514a9d6 JM |
2167 | break; |
2168 | ||
2169 | case bp_catch_throw: | |
53a5351d JM |
2170 | if (current_exception_event && |
2171 | (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW)) | |
c5aa993b JM |
2172 | { |
2173 | annotate_catchpoint (bs->breakpoint_at->number); | |
53a5351d JM |
2174 | printf_filtered ("\nCatchpoint %d (exception thrown), ", |
2175 | bs->breakpoint_at->number); | |
c5aa993b JM |
2176 | printf_filtered ("throw location "); |
2177 | if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) | |
2178 | printf_filtered ("%s:%d", | |
2179 | CURRENT_EXCEPTION_THROW_FILE, | |
2180 | CURRENT_EXCEPTION_THROW_LINE); | |
2181 | else | |
2182 | printf_filtered ("unknown"); | |
2183 | ||
2184 | printf_filtered (", catch location "); | |
2185 | if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) | |
2186 | printf_filtered ("%s:%d", | |
2187 | CURRENT_EXCEPTION_CATCH_FILE, | |
2188 | CURRENT_EXCEPTION_CATCH_LINE); | |
2189 | else | |
2190 | printf_filtered ("unknown"); | |
2191 | ||
2192 | printf_filtered ("\n"); | |
e514a9d6 JM |
2193 | /* don't bother to print location frame info */ |
2194 | return PRINT_SRC_ONLY; | |
c5aa993b | 2195 | } |
c906108c | 2196 | else |
c5aa993b | 2197 | { |
e514a9d6 JM |
2198 | /* really catch, some other bpstat will handle it */ |
2199 | return PRINT_UNKNOWN; | |
c5aa993b | 2200 | } |
e514a9d6 | 2201 | break; |
c906108c | 2202 | |
e514a9d6 JM |
2203 | case bp_watchpoint: |
2204 | case bp_hardware_watchpoint: | |
2205 | if (bs->old_val != NULL) | |
2206 | { | |
2207 | annotate_watchpoint (bs->breakpoint_at->number); | |
9dc5e2a9 | 2208 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2209 | ui_out_field_string (uiout, "reason", "watchpoint-trigger"); |
8b93c638 | 2210 | mention (bs->breakpoint_at); |
3b31d625 | 2211 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2212 | ui_out_text (uiout, "\nOld value = "); |
2213 | value_print (bs->old_val, stb->stream, 0, Val_pretty_default); | |
2214 | ui_out_field_stream (uiout, "old", stb); | |
2215 | ui_out_text (uiout, "\nNew value = "); | |
2216 | value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default); | |
2217 | ui_out_field_stream (uiout, "new", stb); | |
3b31d625 | 2218 | do_cleanups (ui_out_chain); |
8b93c638 | 2219 | ui_out_text (uiout, "\n"); |
e514a9d6 JM |
2220 | value_free (bs->old_val); |
2221 | bs->old_val = NULL; | |
2222 | } | |
2223 | /* More than one watchpoint may have been triggered. */ | |
2224 | return PRINT_UNKNOWN; | |
2225 | break; | |
2226 | ||
2227 | case bp_read_watchpoint: | |
9dc5e2a9 | 2228 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2229 | ui_out_field_string (uiout, "reason", "read-watchpoint-trigger"); |
8b93c638 | 2230 | mention (bs->breakpoint_at); |
3b31d625 | 2231 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2232 | ui_out_text (uiout, "\nValue = "); |
2233 | value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default); | |
2234 | ui_out_field_stream (uiout, "value", stb); | |
3b31d625 | 2235 | do_cleanups (ui_out_chain); |
8b93c638 | 2236 | ui_out_text (uiout, "\n"); |
917317f4 | 2237 | return PRINT_UNKNOWN; |
e514a9d6 JM |
2238 | break; |
2239 | ||
2240 | case bp_access_watchpoint: | |
8b93c638 JM |
2241 | if (bs->old_val != NULL) |
2242 | { | |
2243 | annotate_watchpoint (bs->breakpoint_at->number); | |
9dc5e2a9 | 2244 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2245 | ui_out_field_string (uiout, "reason", "access-watchpoint-trigger"); |
8b93c638 | 2246 | mention (bs->breakpoint_at); |
3b31d625 | 2247 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2248 | ui_out_text (uiout, "\nOld value = "); |
2249 | value_print (bs->old_val, stb->stream, 0, Val_pretty_default); | |
2250 | ui_out_field_stream (uiout, "old", stb); | |
2251 | value_free (bs->old_val); | |
2252 | bs->old_val = NULL; | |
2253 | ui_out_text (uiout, "\nNew value = "); | |
2254 | } | |
2255 | else | |
2256 | { | |
2257 | mention (bs->breakpoint_at); | |
9dc5e2a9 | 2258 | if (ui_out_is_mi_like_p (uiout)) |
c97fe386 | 2259 | ui_out_field_string (uiout, "reason", "access-watchpoint-trigger"); |
3b31d625 | 2260 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2261 | ui_out_text (uiout, "\nValue = "); |
2262 | } | |
2263 | value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default); | |
2264 | ui_out_field_stream (uiout, "new", stb); | |
3b31d625 | 2265 | do_cleanups (ui_out_chain); |
8b93c638 | 2266 | ui_out_text (uiout, "\n"); |
917317f4 | 2267 | return PRINT_UNKNOWN; |
e514a9d6 | 2268 | break; |
4ce44c66 | 2269 | |
e514a9d6 JM |
2270 | /* Fall through, we don't deal with these types of breakpoints |
2271 | here. */ | |
2272 | ||
11cf8741 | 2273 | case bp_finish: |
9dc5e2a9 | 2274 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2275 | ui_out_field_string (uiout, "reason", "function-finished"); |
8b93c638 JM |
2276 | return PRINT_UNKNOWN; |
2277 | break; | |
2278 | ||
e514a9d6 | 2279 | case bp_until: |
9dc5e2a9 | 2280 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2281 | ui_out_field_string (uiout, "reason", "location-reached"); |
8b93c638 JM |
2282 | return PRINT_UNKNOWN; |
2283 | break; | |
2284 | ||
c2d11a7d | 2285 | case bp_none: |
e514a9d6 JM |
2286 | case bp_longjmp: |
2287 | case bp_longjmp_resume: | |
2288 | case bp_step_resume: | |
2289 | case bp_through_sigtramp: | |
2290 | case bp_watchpoint_scope: | |
2291 | case bp_call_dummy: | |
2292 | default: | |
2293 | return PRINT_UNKNOWN; | |
2294 | } | |
2295 | } | |
2296 | ||
2297 | /* Generic routine for printing messages indicating why we | |
2298 | stopped. The behavior of this function depends on the value | |
2299 | 'print_it' in the bpstat structure. Under some circumstances we | |
2300 | may decide not to print anything here and delegate the task to | |
2301 | normal_stop(). */ | |
2302 | ||
2303 | static enum print_stop_action | |
2304 | print_bp_stop_message (bpstat bs) | |
2305 | { | |
2306 | switch (bs->print_it) | |
2307 | { | |
2308 | case print_it_noop: | |
2309 | /* Nothing should be printed for this bpstat entry. */ | |
2310 | return PRINT_UNKNOWN; | |
2311 | break; | |
2312 | ||
2313 | case print_it_done: | |
2314 | /* We still want to print the frame, but we already printed the | |
2315 | relevant messages. */ | |
2316 | return PRINT_SRC_AND_LOC; | |
2317 | break; | |
2318 | ||
2319 | case print_it_normal: | |
3086aeae DJ |
2320 | /* Normal case. Call the breakpoint's print_it method, or |
2321 | print_it_typical. */ | |
2322 | if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL | |
2323 | && bs->breakpoint_at->ops->print_it != NULL) | |
2324 | return bs->breakpoint_at->ops->print_it (bs->breakpoint_at); | |
2325 | else | |
2326 | return print_it_typical (bs); | |
e514a9d6 | 2327 | break; |
3086aeae | 2328 | |
e514a9d6 | 2329 | default: |
8e65ff28 AC |
2330 | internal_error (__FILE__, __LINE__, |
2331 | "print_bp_stop_message: unrecognized enum value"); | |
e514a9d6 | 2332 | break; |
c906108c | 2333 | } |
c906108c SS |
2334 | } |
2335 | ||
e514a9d6 JM |
2336 | /* Print a message indicating what happened. This is called from |
2337 | normal_stop(). The input to this routine is the head of the bpstat | |
2338 | list - a list of the eventpoints that caused this stop. This | |
2339 | routine calls the generic print routine for printing a message | |
2340 | about reasons for stopping. This will print (for example) the | |
2341 | "Breakpoint n," part of the output. The return value of this | |
2342 | routine is one of: | |
c906108c | 2343 | |
917317f4 JM |
2344 | PRINT_UNKNOWN: Means we printed nothing |
2345 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2346 | code to print the location. An example is |
2347 | "Breakpoint 1, " which should be followed by | |
2348 | the location. | |
917317f4 | 2349 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2350 | to also print the location part of the message. |
2351 | An example is the catch/throw messages, which | |
917317f4 JM |
2352 | don't require a location appended to the end. |
2353 | PRINT_NOTHING: We have done some printing and we don't need any | |
2354 | further info to be printed.*/ | |
c906108c | 2355 | |
917317f4 | 2356 | enum print_stop_action |
fba45db2 | 2357 | bpstat_print (bpstat bs) |
c906108c SS |
2358 | { |
2359 | int val; | |
c5aa993b | 2360 | |
c906108c | 2361 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2362 | (Currently all watchpoints go on the bpstat whether hit or not. |
2363 | That probably could (should) be changed, provided care is taken | |
c906108c | 2364 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2365 | for (; bs; bs = bs->next) |
2366 | { | |
2367 | val = print_bp_stop_message (bs); | |
2368 | if (val == PRINT_SRC_ONLY | |
2369 | || val == PRINT_SRC_AND_LOC | |
2370 | || val == PRINT_NOTHING) | |
2371 | return val; | |
2372 | } | |
c906108c | 2373 | |
e514a9d6 JM |
2374 | /* We reached the end of the chain, or we got a null BS to start |
2375 | with and nothing was printed. */ | |
917317f4 | 2376 | return PRINT_UNKNOWN; |
c906108c SS |
2377 | } |
2378 | ||
2379 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2380 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2381 | The argument is a "struct expression *" that has been cast to char * to | |
2382 | make it pass through catch_errors. */ | |
2383 | ||
2384 | static int | |
4efb68b1 | 2385 | breakpoint_cond_eval (void *exp) |
c906108c | 2386 | { |
278cd55f | 2387 | struct value *mark = value_mark (); |
c5aa993b | 2388 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2389 | value_free_to_mark (mark); |
2390 | return i; | |
2391 | } | |
2392 | ||
2393 | /* Allocate a new bpstat and chain it to the current one. */ | |
2394 | ||
2395 | static bpstat | |
831662b3 | 2396 | bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2397 | { |
2398 | bpstat bs; | |
2399 | ||
2400 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2401 | cbs->next = bs; | |
2402 | bs->breakpoint_at = b; | |
2403 | /* If the condition is false, etc., don't do the commands. */ | |
2404 | bs->commands = NULL; | |
2405 | bs->old_val = NULL; | |
2406 | bs->print_it = print_it_normal; | |
2407 | return bs; | |
2408 | } | |
2409 | \f | |
2410 | /* Possible return values for watchpoint_check (this can't be an enum | |
2411 | because of check_errors). */ | |
2412 | /* The watchpoint has been deleted. */ | |
2413 | #define WP_DELETED 1 | |
2414 | /* The value has changed. */ | |
2415 | #define WP_VALUE_CHANGED 2 | |
2416 | /* The value has not changed. */ | |
2417 | #define WP_VALUE_NOT_CHANGED 3 | |
2418 | ||
2419 | #define BP_TEMPFLAG 1 | |
2420 | #define BP_HARDWAREFLAG 2 | |
2421 | ||
2422 | /* Check watchpoint condition. */ | |
2423 | ||
2424 | static int | |
4efb68b1 | 2425 | watchpoint_check (void *p) |
c906108c SS |
2426 | { |
2427 | bpstat bs = (bpstat) p; | |
2428 | struct breakpoint *b; | |
2429 | struct frame_info *fr; | |
2430 | int within_current_scope; | |
a6fbcf2f CV |
2431 | #if 0 |
2432 | struct frame_id current_frame_id; | |
2433 | #endif | |
c906108c SS |
2434 | |
2435 | b = bs->breakpoint_at; | |
2436 | ||
2437 | if (b->exp_valid_block == NULL) | |
2438 | within_current_scope = 1; | |
2439 | else | |
2440 | { | |
2441 | /* There is no current frame at this moment. If we're going to have | |
c5aa993b JM |
2442 | any chance of handling watchpoints on local variables, we'll need |
2443 | the frame chain (so we can determine if we're in scope). */ | |
2444 | reinit_frame_cache (); | |
101dcfbe | 2445 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2446 | within_current_scope = (fr != NULL); |
c12260ac CV |
2447 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2448 | in the function but the stack frame has already been invalidated. | |
2449 | Since we can't rely on the values of local variables after the | |
2450 | stack has been destroyed, we are treating the watchpoint in that | |
a957e642 CV |
2451 | state as `not changed' without further checking. |
2452 | ||
2453 | vinschen/2003-09-04: The former implementation left out the case | |
2454 | that the watchpoint frame couldn't be found by frame_find_by_id() | |
2455 | because the current PC is currently in an epilogue. Calling | |
2456 | gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */ | |
a6fbcf2f | 2457 | if ((!within_current_scope || fr == get_current_frame ()) |
c12260ac CV |
2458 | && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ())) |
2459 | return WP_VALUE_NOT_CHANGED; | |
a6fbcf2f | 2460 | if (fr && within_current_scope) |
c906108c SS |
2461 | /* If we end up stopping, the current frame will get selected |
2462 | in normal_stop. So this call to select_frame won't affect | |
2463 | the user. */ | |
0f7d239c | 2464 | select_frame (fr); |
c906108c | 2465 | } |
c5aa993b | 2466 | |
c906108c SS |
2467 | if (within_current_scope) |
2468 | { | |
2469 | /* We use value_{,free_to_}mark because it could be a | |
2470 | *long* time before we return to the command level and | |
c5aa993b JM |
2471 | call free_all_values. We can't call free_all_values because |
2472 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2473 | |
278cd55f AC |
2474 | struct value *mark = value_mark (); |
2475 | struct value *new_val = evaluate_expression (bs->breakpoint_at->exp); | |
c906108c SS |
2476 | if (!value_equal (b->val, new_val)) |
2477 | { | |
2478 | release_value (new_val); | |
2479 | value_free_to_mark (mark); | |
2480 | bs->old_val = b->val; | |
2481 | b->val = new_val; | |
2482 | /* We will stop here */ | |
2483 | return WP_VALUE_CHANGED; | |
2484 | } | |
2485 | else | |
2486 | { | |
2487 | /* Nothing changed, don't do anything. */ | |
2488 | value_free_to_mark (mark); | |
2489 | /* We won't stop here */ | |
2490 | return WP_VALUE_NOT_CHANGED; | |
2491 | } | |
2492 | } | |
2493 | else | |
2494 | { | |
2495 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2496 | if we temporarily ignored the watchpoint, then when |
2497 | we reenter the block in which it is valid it contains | |
2498 | garbage (in the case of a function, it may have two | |
2499 | garbage values, one before and one after the prologue). | |
2500 | So we can't even detect the first assignment to it and | |
2501 | watch after that (since the garbage may or may not equal | |
2502 | the first value assigned). */ | |
4ce44c66 JM |
2503 | /* We print all the stop information in print_it_typical(), but |
2504 | in this case, by the time we call print_it_typical() this bp | |
2505 | will be deleted already. So we have no choice but print the | |
2506 | information here. */ | |
9dc5e2a9 | 2507 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2508 | ui_out_field_string (uiout, "reason", "watchpoint-scope"); |
8b93c638 JM |
2509 | ui_out_text (uiout, "\nWatchpoint "); |
2510 | ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number); | |
2511 | ui_out_text (uiout, " deleted because the program has left the block in\n\ | |
2512 | which its expression is valid.\n"); | |
4ce44c66 | 2513 | |
c906108c | 2514 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2515 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2516 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2517 | |
2518 | return WP_DELETED; | |
2519 | } | |
2520 | } | |
2521 | ||
c906108c SS |
2522 | /* Get a bpstat associated with having just stopped at address *PC |
2523 | and frame address CORE_ADDRESS. Update *PC to point at the | |
6e31adb3 | 2524 | breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero |
c906108c SS |
2525 | if this is known to not be a real breakpoint (it could still be a |
2526 | watchpoint, though). */ | |
2527 | ||
2528 | /* Determine whether we stopped at a breakpoint, etc, or whether we | |
2529 | don't understand this stop. Result is a chain of bpstat's such that: | |
2530 | ||
c5aa993b | 2531 | if we don't understand the stop, the result is a null pointer. |
c906108c | 2532 | |
c5aa993b | 2533 | if we understand why we stopped, the result is not null. |
c906108c | 2534 | |
c5aa993b JM |
2535 | Each element of the chain refers to a particular breakpoint or |
2536 | watchpoint at which we have stopped. (We may have stopped for | |
2537 | several reasons concurrently.) | |
c906108c | 2538 | |
c5aa993b JM |
2539 | Each element of the chain has valid next, breakpoint_at, |
2540 | commands, FIXME??? fields. */ | |
c906108c SS |
2541 | |
2542 | bpstat | |
6e31adb3 | 2543 | bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint) |
c906108c | 2544 | { |
52f0bd74 | 2545 | struct breakpoint *b, *temp; |
c906108c SS |
2546 | CORE_ADDR bp_addr; |
2547 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ | |
2548 | int real_breakpoint = 0; | |
2549 | /* Root of the chain of bpstat's */ | |
2550 | struct bpstats root_bs[1]; | |
2551 | /* Pointer to the last thing in the chain currently. */ | |
2552 | bpstat bs = root_bs; | |
c906108c | 2553 | |
6e31adb3 AC |
2554 | /* Get the address where the breakpoint would have been. The |
2555 | "not_a_sw_breakpoint" argument is meant to distinguish between a | |
2556 | breakpoint trap event and a trace/singlestep trap event. For a | |
2557 | trace/singlestep trap event, we would not want to subtract | |
2558 | DECR_PC_AFTER_BREAK from the PC. */ | |
80b34fab | 2559 | |
c8edd8b4 | 2560 | bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK); |
c906108c SS |
2561 | |
2562 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2563 | { |
b5de0fa7 EZ |
2564 | if (b->enable_state == bp_disabled |
2565 | || b->enable_state == bp_shlib_disabled | |
2566 | || b->enable_state == bp_call_disabled) | |
c5aa993b JM |
2567 | continue; |
2568 | ||
2569 | if (b->type != bp_watchpoint | |
2570 | && b->type != bp_hardware_watchpoint | |
2571 | && b->type != bp_read_watchpoint | |
2572 | && b->type != bp_access_watchpoint | |
2573 | && b->type != bp_hardware_breakpoint | |
2574 | && b->type != bp_catch_fork | |
2575 | && b->type != bp_catch_vfork | |
2576 | && b->type != bp_catch_exec | |
2577 | && b->type != bp_catch_catch | |
2578 | && b->type != bp_catch_throw) /* a non-watchpoint bp */ | |
9f04af04 | 2579 | { |
5cab636d | 2580 | if (b->loc->address != bp_addr) /* address doesn't match */ |
9f04af04 MS |
2581 | continue; |
2582 | if (overlay_debugging /* unmapped overlay section */ | |
cf3a9e5b DJ |
2583 | && section_is_overlay (b->loc->section) |
2584 | && !section_is_mapped (b->loc->section)) | |
9f04af04 MS |
2585 | continue; |
2586 | } | |
c906108c | 2587 | |
c02f5703 MS |
2588 | if (b->type == bp_hardware_breakpoint) |
2589 | { | |
5cab636d | 2590 | if (b->loc->address != (*pc - DECR_PC_AFTER_HW_BREAK)) |
c02f5703 MS |
2591 | continue; |
2592 | if (overlay_debugging /* unmapped overlay section */ | |
cf3a9e5b DJ |
2593 | && section_is_overlay (b->loc->section) |
2594 | && !section_is_mapped (b->loc->section)) | |
c02f5703 MS |
2595 | continue; |
2596 | } | |
c5aa993b | 2597 | |
c5aa993b JM |
2598 | /* Is this a catchpoint of a load or unload? If so, did we |
2599 | get a load or unload of the specified library? If not, | |
2600 | ignore it. */ | |
2601 | if ((b->type == bp_catch_load) | |
c906108c | 2602 | #if defined(SOLIB_HAVE_LOAD_EVENT) |
39f77062 | 2603 | && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid)) |
c5aa993b | 2604 | || ((b->dll_pathname != NULL) |
53a5351d | 2605 | && (strcmp (b->dll_pathname, |
39f77062 KB |
2606 | SOLIB_LOADED_LIBRARY_PATHNAME ( |
2607 | PIDGET (inferior_ptid))) | |
53a5351d | 2608 | != 0))) |
c906108c | 2609 | #endif |
c5aa993b JM |
2610 | ) |
2611 | continue; | |
2612 | ||
2613 | if ((b->type == bp_catch_unload) | |
c906108c | 2614 | #if defined(SOLIB_HAVE_UNLOAD_EVENT) |
39f77062 | 2615 | && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid)) |
c5aa993b | 2616 | || ((b->dll_pathname != NULL) |
53a5351d | 2617 | && (strcmp (b->dll_pathname, |
39f77062 KB |
2618 | SOLIB_UNLOADED_LIBRARY_PATHNAME ( |
2619 | PIDGET (inferior_ptid))) | |
53a5351d | 2620 | != 0))) |
c906108c | 2621 | #endif |
c5aa993b JM |
2622 | ) |
2623 | continue; | |
c906108c | 2624 | |
c5aa993b | 2625 | if ((b->type == bp_catch_fork) |
47932f85 DJ |
2626 | && !inferior_has_forked (PIDGET (inferior_ptid), |
2627 | &b->forked_inferior_pid)) | |
c5aa993b | 2628 | continue; |
c906108c | 2629 | |
c5aa993b | 2630 | if ((b->type == bp_catch_vfork) |
47932f85 DJ |
2631 | && !inferior_has_vforked (PIDGET (inferior_ptid), |
2632 | &b->forked_inferior_pid)) | |
c5aa993b | 2633 | continue; |
c906108c | 2634 | |
c5aa993b | 2635 | if ((b->type == bp_catch_exec) |
47932f85 | 2636 | && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname)) |
c5aa993b | 2637 | continue; |
c906108c | 2638 | |
c5aa993b JM |
2639 | if (ep_is_exception_catchpoint (b) && |
2640 | !(current_exception_event = target_get_current_exception_event ())) | |
2641 | continue; | |
c906108c | 2642 | |
c5aa993b JM |
2643 | /* Come here if it's a watchpoint, or if the break address matches */ |
2644 | ||
2645 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ | |
2646 | ||
2647 | /* Watchpoints may change this, if not found to have triggered. */ | |
2648 | bs->stop = 1; | |
2649 | bs->print = 1; | |
2650 | ||
53a5351d JM |
2651 | if (b->type == bp_watchpoint || |
2652 | b->type == bp_hardware_watchpoint) | |
c5aa993b | 2653 | { |
9ebf4acf AC |
2654 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", |
2655 | b->number); | |
2656 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2657 | int e = catch_errors (watchpoint_check, bs, message, | |
2658 | RETURN_MASK_ALL); | |
2659 | do_cleanups (cleanups); | |
2660 | switch (e) | |
c5aa993b JM |
2661 | { |
2662 | case WP_DELETED: | |
2663 | /* We've already printed what needs to be printed. */ | |
4ce44c66 JM |
2664 | /* Actually this is superfluous, because by the time we |
2665 | call print_it_typical() the wp will be already deleted, | |
2666 | and the function will return immediately. */ | |
c5aa993b JM |
2667 | bs->print_it = print_it_done; |
2668 | /* Stop. */ | |
2669 | break; | |
2670 | case WP_VALUE_CHANGED: | |
2671 | /* Stop. */ | |
2672 | ++(b->hit_count); | |
2673 | break; | |
2674 | case WP_VALUE_NOT_CHANGED: | |
2675 | /* Don't stop. */ | |
2676 | bs->print_it = print_it_noop; | |
2677 | bs->stop = 0; | |
c5aa993b JM |
2678 | continue; |
2679 | default: | |
2680 | /* Can't happen. */ | |
2681 | /* FALLTHROUGH */ | |
2682 | case 0: | |
2683 | /* Error from catch_errors. */ | |
2684 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2685 | if (b->related_breakpoint) | |
b5de0fa7 EZ |
2686 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2687 | b->disposition = disp_del_at_next_stop; | |
c5aa993b JM |
2688 | /* We've already printed what needs to be printed. */ |
2689 | bs->print_it = print_it_done; | |
2690 | ||
2691 | /* Stop. */ | |
2692 | break; | |
2693 | } | |
2694 | } | |
53a5351d JM |
2695 | else if (b->type == bp_read_watchpoint || |
2696 | b->type == bp_access_watchpoint) | |
c5aa993b JM |
2697 | { |
2698 | CORE_ADDR addr; | |
278cd55f | 2699 | struct value *v; |
c5aa993b JM |
2700 | int found = 0; |
2701 | ||
2702 | addr = target_stopped_data_address (); | |
2703 | if (addr == 0) | |
2704 | continue; | |
2705 | for (v = b->val_chain; v; v = v->next) | |
2706 | { | |
5c44784c JM |
2707 | if (VALUE_LVAL (v) == lval_memory |
2708 | && ! VALUE_LAZY (v)) | |
c5aa993b | 2709 | { |
2e70b7b9 MS |
2710 | struct type *vtype = check_typedef (VALUE_TYPE (v)); |
2711 | ||
2712 | if (v == b->val_chain | |
2713 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
2714 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2715 | { | |
2716 | CORE_ADDR vaddr; | |
2717 | ||
2718 | vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
2719 | /* Exact match not required. Within range is | |
2720 | sufficient. */ | |
2721 | if (addr >= vaddr && | |
2722 | addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v))) | |
2723 | found = 1; | |
2724 | } | |
c5aa993b JM |
2725 | } |
2726 | } | |
2727 | if (found) | |
9ebf4acf AC |
2728 | { |
2729 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
2730 | b->number); | |
2731 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2732 | int e = catch_errors (watchpoint_check, bs, message, | |
2733 | RETURN_MASK_ALL); | |
2734 | do_cleanups (cleanups); | |
2735 | switch (e) | |
2736 | { | |
2737 | case WP_DELETED: | |
2738 | /* We've already printed what needs to be printed. */ | |
2739 | bs->print_it = print_it_done; | |
2740 | /* Stop. */ | |
2741 | break; | |
2742 | case WP_VALUE_CHANGED: | |
2743 | if (b->type == bp_read_watchpoint) | |
2744 | { | |
2745 | /* Don't stop: read watchpoints shouldn't fire if | |
2746 | the value has changed. This is for targets | |
2747 | which cannot set read-only watchpoints. */ | |
2748 | bs->print_it = print_it_noop; | |
2749 | bs->stop = 0; | |
2750 | continue; | |
2751 | } | |
2752 | ++(b->hit_count); | |
2753 | break; | |
2754 | case WP_VALUE_NOT_CHANGED: | |
2755 | /* Stop. */ | |
2756 | ++(b->hit_count); | |
2757 | break; | |
2758 | default: | |
2759 | /* Can't happen. */ | |
2760 | case 0: | |
2761 | /* Error from catch_errors. */ | |
2762 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2763 | if (b->related_breakpoint) | |
2764 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
2765 | b->disposition = disp_del_at_next_stop; | |
2766 | /* We've already printed what needs to be printed. */ | |
2767 | bs->print_it = print_it_done; | |
2768 | break; | |
2769 | } | |
2770 | } | |
53a5351d JM |
2771 | else /* found == 0 */ |
2772 | { | |
2773 | /* This is a case where some watchpoint(s) triggered, | |
2774 | but not at the address of this watchpoint (FOUND | |
2775 | was left zero). So don't print anything for this | |
2776 | watchpoint. */ | |
2777 | bs->print_it = print_it_noop; | |
2778 | bs->stop = 0; | |
2779 | continue; | |
2780 | } | |
c5aa993b JM |
2781 | } |
2782 | else | |
2783 | { | |
2784 | /* By definition, an encountered breakpoint is a triggered | |
2785 | breakpoint. */ | |
2786 | ++(b->hit_count); | |
c906108c | 2787 | |
c5aa993b JM |
2788 | real_breakpoint = 1; |
2789 | } | |
2790 | ||
818dd999 AC |
2791 | if (frame_id_p (b->frame_id) |
2792 | && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ()))) | |
c5aa993b JM |
2793 | bs->stop = 0; |
2794 | else | |
2795 | { | |
2796 | int value_is_zero = 0; | |
2797 | ||
2798 | if (b->cond) | |
2799 | { | |
2800 | /* Need to select the frame, with all that implies | |
2801 | so that the conditions will have the right context. */ | |
0f7d239c | 2802 | select_frame (get_current_frame ()); |
c5aa993b JM |
2803 | value_is_zero |
2804 | = catch_errors (breakpoint_cond_eval, (b->cond), | |
2805 | "Error in testing breakpoint condition:\n", | |
2806 | RETURN_MASK_ALL); | |
2807 | /* FIXME-someday, should give breakpoint # */ | |
2808 | free_all_values (); | |
2809 | } | |
2810 | if (b->cond && value_is_zero) | |
2811 | { | |
2812 | bs->stop = 0; | |
2813 | /* Don't consider this a hit. */ | |
2814 | --(b->hit_count); | |
2815 | } | |
2816 | else if (b->ignore_count > 0) | |
2817 | { | |
2818 | b->ignore_count--; | |
5c44784c | 2819 | annotate_ignore_count_change (); |
c5aa993b JM |
2820 | bs->stop = 0; |
2821 | } | |
2822 | else | |
2823 | { | |
2824 | /* We will stop here */ | |
b5de0fa7 EZ |
2825 | if (b->disposition == disp_disable) |
2826 | b->enable_state = bp_disabled; | |
c5aa993b JM |
2827 | if (b->silent) |
2828 | bs->print = 0; | |
552f4abf | 2829 | bs->commands = b->commands; |
c5aa993b JM |
2830 | if (bs->commands && |
2831 | (STREQ ("silent", bs->commands->line) || | |
2832 | (xdb_commands && STREQ ("Q", bs->commands->line)))) | |
2833 | { | |
2834 | bs->commands = bs->commands->next; | |
c906108c | 2835 | bs->print = 0; |
c5aa993b | 2836 | } |
552f4abf | 2837 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b JM |
2838 | } |
2839 | } | |
2840 | /* Print nothing for this entry if we dont stop or if we dont print. */ | |
2841 | if (bs->stop == 0 || bs->print == 0) | |
2842 | bs->print_it = print_it_noop; | |
2843 | } | |
c906108c SS |
2844 | |
2845 | bs->next = NULL; /* Terminate the chain */ | |
2846 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
2847 | ||
2848 | if (real_breakpoint && bs) | |
2849 | { | |
c5aa993b | 2850 | if (bs->breakpoint_at->type == bp_hardware_breakpoint) |
c906108c | 2851 | { |
c5aa993b | 2852 | if (DECR_PC_AFTER_HW_BREAK != 0) |
c906108c SS |
2853 | { |
2854 | *pc = *pc - DECR_PC_AFTER_HW_BREAK; | |
2855 | write_pc (*pc); | |
2856 | } | |
2857 | } | |
2858 | else | |
2859 | { | |
2860 | if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs) | |
2861 | { | |
2862 | *pc = bp_addr; | |
2863 | #if defined (SHIFT_INST_REGS) | |
c5aa993b | 2864 | SHIFT_INST_REGS (); |
c906108c SS |
2865 | #else /* No SHIFT_INST_REGS. */ |
2866 | write_pc (bp_addr); | |
2867 | #endif /* No SHIFT_INST_REGS. */ | |
2868 | } | |
2869 | } | |
2870 | } | |
2871 | ||
2872 | /* The value of a hardware watchpoint hasn't changed, but the | |
2873 | intermediate memory locations we are watching may have. */ | |
c5aa993b | 2874 | if (bs && !bs->stop && |
c906108c SS |
2875 | (bs->breakpoint_at->type == bp_hardware_watchpoint || |
2876 | bs->breakpoint_at->type == bp_read_watchpoint || | |
2877 | bs->breakpoint_at->type == bp_access_watchpoint)) | |
2878 | { | |
2879 | remove_breakpoints (); | |
2880 | insert_breakpoints (); | |
2881 | } | |
2882 | return bs; | |
2883 | } | |
2884 | \f | |
2885 | /* Tell what to do about this bpstat. */ | |
2886 | struct bpstat_what | |
fba45db2 | 2887 | bpstat_what (bpstat bs) |
c906108c SS |
2888 | { |
2889 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
2890 | enum class |
2891 | { | |
2892 | /* This bpstat element has no effect on the main_action. */ | |
2893 | no_effect = 0, | |
2894 | ||
2895 | /* There was a watchpoint, stop but don't print. */ | |
2896 | wp_silent, | |
c906108c | 2897 | |
c5aa993b JM |
2898 | /* There was a watchpoint, stop and print. */ |
2899 | wp_noisy, | |
c906108c | 2900 | |
c5aa993b JM |
2901 | /* There was a breakpoint but we're not stopping. */ |
2902 | bp_nostop, | |
c906108c | 2903 | |
c5aa993b JM |
2904 | /* There was a breakpoint, stop but don't print. */ |
2905 | bp_silent, | |
c906108c | 2906 | |
c5aa993b JM |
2907 | /* There was a breakpoint, stop and print. */ |
2908 | bp_noisy, | |
c906108c | 2909 | |
c5aa993b JM |
2910 | /* We hit the longjmp breakpoint. */ |
2911 | long_jump, | |
c906108c | 2912 | |
c5aa993b JM |
2913 | /* We hit the longjmp_resume breakpoint. */ |
2914 | long_resume, | |
c906108c | 2915 | |
c5aa993b JM |
2916 | /* We hit the step_resume breakpoint. */ |
2917 | step_resume, | |
c906108c | 2918 | |
c5aa993b JM |
2919 | /* We hit the through_sigtramp breakpoint. */ |
2920 | through_sig, | |
c906108c | 2921 | |
c5aa993b JM |
2922 | /* We hit the shared library event breakpoint. */ |
2923 | shlib_event, | |
c906108c | 2924 | |
c5aa993b JM |
2925 | /* We caught a shared library event. */ |
2926 | catch_shlib_event, | |
c906108c | 2927 | |
c5aa993b JM |
2928 | /* This is just used to count how many enums there are. */ |
2929 | class_last | |
c906108c SS |
2930 | }; |
2931 | ||
2932 | /* Here is the table which drives this routine. So that we can | |
2933 | format it pretty, we define some abbreviations for the | |
2934 | enum bpstat_what codes. */ | |
2935 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
2936 | #define ss BPSTAT_WHAT_STOP_SILENT | |
2937 | #define sn BPSTAT_WHAT_STOP_NOISY | |
2938 | #define sgl BPSTAT_WHAT_SINGLE | |
2939 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
2940 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
2941 | #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE | |
2942 | #define sr BPSTAT_WHAT_STEP_RESUME | |
2943 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP | |
2944 | #define shl BPSTAT_WHAT_CHECK_SHLIBS | |
2945 | #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK | |
2946 | ||
2947 | /* "Can't happen." Might want to print an error message. | |
2948 | abort() is not out of the question, but chances are GDB is just | |
2949 | a bit confused, not unusable. */ | |
2950 | #define err BPSTAT_WHAT_STOP_NOISY | |
2951 | ||
2952 | /* Given an old action and a class, come up with a new action. */ | |
2953 | /* One interesting property of this table is that wp_silent is the same | |
2954 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
2955 | after stopping, the check for whether to step over a breakpoint | |
2956 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
2957 | reference to how we stopped. We retain separate wp_silent and |
2958 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
2959 | |
2960 | Another possibly interesting property of this table is that | |
2961 | there's a partial ordering, priority-like, of the actions. Once | |
2962 | you've decided that some action is appropriate, you'll never go | |
2963 | back and decide something of a lower priority is better. The | |
2964 | ordering is: | |
2965 | ||
7e73cedf | 2966 | kc < clr sgl shl shlr slr sn sr ss ts |
c5aa993b JM |
2967 | sgl < clrs shl shlr slr sn sr ss ts |
2968 | slr < err shl shlr sn sr ss ts | |
2969 | clr < clrs err shl shlr sn sr ss ts | |
2970 | clrs < err shl shlr sn sr ss ts | |
2971 | ss < shl shlr sn sr ts | |
2972 | sn < shl shlr sr ts | |
2973 | sr < shl shlr ts | |
2974 | shl < shlr | |
2975 | ts < | |
2976 | shlr < | |
2977 | ||
43ff13b4 JM |
2978 | What I think this means is that we don't need a damned table |
2979 | here. If you just put the rows and columns in the right order, | |
2980 | it'd look awfully regular. We could simply walk the bpstat list | |
2981 | and choose the highest priority action we find, with a little | |
2982 | logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/ | |
2983 | CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says | |
2984 | is messy anyway). */ | |
c906108c SS |
2985 | |
2986 | /* step_resume entries: a step resume breakpoint overrides another | |
2987 | breakpoint of signal handling (see comment in wait_for_inferior | |
d7bd68ca | 2988 | at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */ |
c906108c SS |
2989 | /* We handle the through_sigtramp_breakpoint the same way; having both |
2990 | one of those and a step_resume_breakpoint is probably very rare (?). */ | |
2991 | ||
2992 | static const enum bpstat_what_main_action | |
c5aa993b JM |
2993 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
2994 | { | |
2995 | /* old action */ | |
2996 | /* kc ss sn sgl slr clr clrs sr ts shl shlr | |
2997 | */ | |
2998 | /*no_effect */ | |
2999 | {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr}, | |
3000 | /*wp_silent */ | |
3001 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
3002 | /*wp_noisy */ | |
3003 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
3004 | /*bp_nostop */ | |
3005 | {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr}, | |
3006 | /*bp_silent */ | |
3007 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
3008 | /*bp_noisy */ | |
3009 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
3010 | /*long_jump */ | |
a48bb0b3 | 3011 | {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr}, |
c5aa993b JM |
3012 | /*long_resume */ |
3013 | {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr}, | |
3014 | /*step_resume */ | |
3015 | {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr}, | |
3016 | /*through_sig */ | |
3017 | {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr}, | |
3018 | /*shlib */ | |
3019 | {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr}, | |
3020 | /*catch_shlib */ | |
3021 | {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr} | |
3022 | }; | |
c906108c SS |
3023 | |
3024 | #undef kc | |
3025 | #undef ss | |
3026 | #undef sn | |
3027 | #undef sgl | |
3028 | #undef slr | |
3029 | #undef clr | |
3030 | #undef clrs | |
3031 | #undef err | |
3032 | #undef sr | |
3033 | #undef ts | |
3034 | #undef shl | |
3035 | #undef shlr | |
3036 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; | |
3037 | struct bpstat_what retval; | |
3038 | ||
3039 | retval.call_dummy = 0; | |
3040 | for (; bs != NULL; bs = bs->next) | |
3041 | { | |
3042 | enum class bs_class = no_effect; | |
3043 | if (bs->breakpoint_at == NULL) | |
3044 | /* I suspect this can happen if it was a momentary breakpoint | |
3045 | which has since been deleted. */ | |
3046 | continue; | |
3047 | switch (bs->breakpoint_at->type) | |
3048 | { | |
3049 | case bp_none: | |
3050 | continue; | |
3051 | ||
3052 | case bp_breakpoint: | |
3053 | case bp_hardware_breakpoint: | |
3054 | case bp_until: | |
3055 | case bp_finish: | |
3056 | if (bs->stop) | |
3057 | { | |
3058 | if (bs->print) | |
3059 | bs_class = bp_noisy; | |
3060 | else | |
3061 | bs_class = bp_silent; | |
3062 | } | |
3063 | else | |
3064 | bs_class = bp_nostop; | |
3065 | break; | |
3066 | case bp_watchpoint: | |
3067 | case bp_hardware_watchpoint: | |
3068 | case bp_read_watchpoint: | |
3069 | case bp_access_watchpoint: | |
3070 | if (bs->stop) | |
3071 | { | |
3072 | if (bs->print) | |
3073 | bs_class = wp_noisy; | |
3074 | else | |
3075 | bs_class = wp_silent; | |
3076 | } | |
3077 | else | |
53a5351d JM |
3078 | /* There was a watchpoint, but we're not stopping. |
3079 | This requires no further action. */ | |
c906108c SS |
3080 | bs_class = no_effect; |
3081 | break; | |
3082 | case bp_longjmp: | |
3083 | bs_class = long_jump; | |
3084 | break; | |
3085 | case bp_longjmp_resume: | |
3086 | bs_class = long_resume; | |
3087 | break; | |
3088 | case bp_step_resume: | |
3089 | if (bs->stop) | |
3090 | { | |
3091 | bs_class = step_resume; | |
3092 | } | |
3093 | else | |
3094 | /* It is for the wrong frame. */ | |
3095 | bs_class = bp_nostop; | |
3096 | break; | |
3097 | case bp_through_sigtramp: | |
3098 | bs_class = through_sig; | |
3099 | break; | |
3100 | case bp_watchpoint_scope: | |
3101 | bs_class = bp_nostop; | |
3102 | break; | |
c5aa993b JM |
3103 | case bp_shlib_event: |
3104 | bs_class = shlib_event; | |
3105 | break; | |
c4093a6a | 3106 | case bp_thread_event: |
1900040c | 3107 | case bp_overlay_event: |
c4093a6a JM |
3108 | bs_class = bp_nostop; |
3109 | break; | |
c5aa993b JM |
3110 | case bp_catch_load: |
3111 | case bp_catch_unload: | |
3112 | /* Only if this catchpoint triggered should we cause the | |
3113 | step-out-of-dld behaviour. Otherwise, we ignore this | |
3114 | catchpoint. */ | |
3115 | if (bs->stop) | |
3116 | bs_class = catch_shlib_event; | |
3117 | else | |
3118 | bs_class = no_effect; | |
3119 | break; | |
3120 | case bp_catch_fork: | |
3121 | case bp_catch_vfork: | |
3122 | case bp_catch_exec: | |
3123 | if (bs->stop) | |
3124 | { | |
3125 | if (bs->print) | |
3126 | bs_class = bp_noisy; | |
3127 | else | |
3128 | bs_class = bp_silent; | |
3129 | } | |
3130 | else | |
53a5351d JM |
3131 | /* There was a catchpoint, but we're not stopping. |
3132 | This requires no further action. */ | |
c5aa993b JM |
3133 | bs_class = no_effect; |
3134 | break; | |
3135 | case bp_catch_catch: | |
3136 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH) | |
3137 | bs_class = bp_nostop; | |
3138 | else if (bs->stop) | |
3139 | bs_class = bs->print ? bp_noisy : bp_silent; | |
3140 | break; | |
3141 | case bp_catch_throw: | |
3142 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW) | |
3143 | bs_class = bp_nostop; | |
3144 | else if (bs->stop) | |
3145 | bs_class = bs->print ? bp_noisy : bp_silent; | |
c906108c | 3146 | break; |
c906108c | 3147 | case bp_call_dummy: |
53a5351d JM |
3148 | /* Make sure the action is stop (silent or noisy), |
3149 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3150 | bs_class = bp_silent; |
3151 | retval.call_dummy = 1; | |
3152 | break; | |
3153 | } | |
c5aa993b | 3154 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3155 | } |
3156 | retval.main_action = current_action; | |
3157 | return retval; | |
3158 | } | |
3159 | ||
3160 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3161 | without hardware support). This isn't related to a specific bpstat, | |
3162 | just to things like whether watchpoints are set. */ | |
3163 | ||
c5aa993b | 3164 | int |
fba45db2 | 3165 | bpstat_should_step (void) |
c906108c SS |
3166 | { |
3167 | struct breakpoint *b; | |
3168 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 3169 | if (b->enable_state == bp_enabled && b->type == bp_watchpoint) |
3172dc30 | 3170 | return 1; |
c906108c SS |
3171 | return 0; |
3172 | } | |
3173 | ||
3174 | /* Nonzero if there are enabled hardware watchpoints. */ | |
3175 | int | |
fba45db2 | 3176 | bpstat_have_active_hw_watchpoints (void) |
c906108c SS |
3177 | { |
3178 | struct breakpoint *b; | |
3179 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 3180 | if ((b->enable_state == bp_enabled) && |
5cab636d | 3181 | (b->loc->inserted) && |
c5aa993b JM |
3182 | ((b->type == bp_hardware_watchpoint) || |
3183 | (b->type == bp_read_watchpoint) || | |
3184 | (b->type == bp_access_watchpoint))) | |
3172dc30 | 3185 | return 1; |
c906108c SS |
3186 | return 0; |
3187 | } | |
c906108c | 3188 | \f |
c5aa993b | 3189 | |
c906108c SS |
3190 | /* Given a bpstat that records zero or more triggered eventpoints, this |
3191 | function returns another bpstat which contains only the catchpoints | |
3192 | on that first list, if any. */ | |
3193 | void | |
fba45db2 | 3194 | bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list) |
c5aa993b JM |
3195 | { |
3196 | struct bpstats root_bs[1]; | |
3197 | bpstat bs = root_bs; | |
3198 | struct breakpoint *ep; | |
3199 | char *dll_pathname; | |
3200 | ||
c906108c SS |
3201 | bpstat_clear (cp_list); |
3202 | root_bs->next = NULL; | |
c5aa993b JM |
3203 | |
3204 | for (; ep_list != NULL; ep_list = ep_list->next) | |
c906108c SS |
3205 | { |
3206 | /* Is this eventpoint a catchpoint? If not, ignore it. */ | |
3207 | ep = ep_list->breakpoint_at; | |
3208 | if (ep == NULL) | |
c5aa993b JM |
3209 | break; |
3210 | if ((ep->type != bp_catch_load) && | |
3211 | (ep->type != bp_catch_unload) && | |
3212 | (ep->type != bp_catch_catch) && | |
53a5351d JM |
3213 | (ep->type != bp_catch_throw)) |
3214 | /* pai: (temp) ADD fork/vfork here!! */ | |
c5aa993b JM |
3215 | continue; |
3216 | ||
c906108c SS |
3217 | /* Yes; add it to the list. */ |
3218 | bs = bpstat_alloc (ep, bs); | |
3219 | *bs = *ep_list; | |
3220 | bs->next = NULL; | |
3221 | bs = root_bs->next; | |
c5aa993b | 3222 | |
c906108c SS |
3223 | #if defined(SOLIB_ADD) |
3224 | /* Also, for each triggered catchpoint, tag it with the name of | |
3225 | the library that caused this trigger. (We copy the name now, | |
3226 | because it's only guaranteed to be available NOW, when the | |
3227 | catchpoint triggers. Clients who may wish to know the name | |
3228 | later must get it from the catchpoint itself.) */ | |
3229 | if (ep->triggered_dll_pathname != NULL) | |
b8c9b27d | 3230 | xfree (ep->triggered_dll_pathname); |
c906108c | 3231 | if (ep->type == bp_catch_load) |
39f77062 KB |
3232 | dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME ( |
3233 | PIDGET (inferior_ptid)); | |
c906108c | 3234 | else |
39f77062 KB |
3235 | dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME ( |
3236 | PIDGET (inferior_ptid)); | |
c906108c SS |
3237 | #else |
3238 | dll_pathname = NULL; | |
3239 | #endif | |
3240 | if (dll_pathname) | |
3241 | { | |
53a5351d JM |
3242 | ep->triggered_dll_pathname = (char *) |
3243 | xmalloc (strlen (dll_pathname) + 1); | |
c906108c SS |
3244 | strcpy (ep->triggered_dll_pathname, dll_pathname); |
3245 | } | |
3246 | else | |
3247 | ep->triggered_dll_pathname = NULL; | |
3248 | } | |
c5aa993b | 3249 | |
c906108c SS |
3250 | *cp_list = bs; |
3251 | } | |
3252 | ||
c4093a6a | 3253 | /* Print B to gdb_stdout. */ |
c906108c | 3254 | static void |
c4093a6a JM |
3255 | print_one_breakpoint (struct breakpoint *b, |
3256 | CORE_ADDR *last_addr) | |
c906108c | 3257 | { |
52f0bd74 AC |
3258 | struct command_line *l; |
3259 | struct symbol *sym; | |
c4093a6a JM |
3260 | struct ep_type_description |
3261 | { | |
3262 | enum bptype type; | |
3263 | char *description; | |
3264 | }; | |
3265 | static struct ep_type_description bptypes[] = | |
c906108c | 3266 | { |
c5aa993b JM |
3267 | {bp_none, "?deleted?"}, |
3268 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3269 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3270 | {bp_until, "until"}, |
3271 | {bp_finish, "finish"}, | |
3272 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3273 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3274 | {bp_read_watchpoint, "read watchpoint"}, |
3275 | {bp_access_watchpoint, "acc watchpoint"}, | |
3276 | {bp_longjmp, "longjmp"}, | |
3277 | {bp_longjmp_resume, "longjmp resume"}, | |
3278 | {bp_step_resume, "step resume"}, | |
3279 | {bp_through_sigtramp, "sigtramp"}, | |
3280 | {bp_watchpoint_scope, "watchpoint scope"}, | |
3281 | {bp_call_dummy, "call dummy"}, | |
3282 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3283 | {bp_thread_event, "thread events"}, |
1900040c | 3284 | {bp_overlay_event, "overlay events"}, |
c5aa993b JM |
3285 | {bp_catch_load, "catch load"}, |
3286 | {bp_catch_unload, "catch unload"}, | |
3287 | {bp_catch_fork, "catch fork"}, | |
3288 | {bp_catch_vfork, "catch vfork"}, | |
3289 | {bp_catch_exec, "catch exec"}, | |
3290 | {bp_catch_catch, "catch catch"}, | |
3291 | {bp_catch_throw, "catch throw"} | |
3292 | }; | |
c4093a6a | 3293 | |
c5aa993b JM |
3294 | static char *bpdisps[] = |
3295 | {"del", "dstp", "dis", "keep"}; | |
c2c6d25f | 3296 | static char bpenables[] = "nynny"; |
c906108c | 3297 | char wrap_indent[80]; |
8b93c638 JM |
3298 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3299 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3300 | struct cleanup *bkpt_chain; |
c906108c | 3301 | |
c4093a6a | 3302 | annotate_record (); |
3b31d625 | 3303 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3304 | |
3305 | /* 1 */ | |
3306 | annotate_field (0); | |
8b93c638 | 3307 | ui_out_field_int (uiout, "number", b->number); |
c4093a6a JM |
3308 | |
3309 | /* 2 */ | |
3310 | annotate_field (1); | |
3311 | if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3312 | || ((int) b->type != bptypes[(int) b->type].type)) | |
8e65ff28 AC |
3313 | internal_error (__FILE__, __LINE__, |
3314 | "bptypes table does not describe type #%d.", | |
c4093a6a | 3315 | (int) b->type); |
8b93c638 | 3316 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); |
c4093a6a JM |
3317 | |
3318 | /* 3 */ | |
3319 | annotate_field (2); | |
8b93c638 | 3320 | ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]); |
c4093a6a JM |
3321 | |
3322 | /* 4 */ | |
3323 | annotate_field (3); | |
b5de0fa7 | 3324 | ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]); |
8b93c638 | 3325 | ui_out_spaces (uiout, 2); |
c4093a6a JM |
3326 | |
3327 | /* 5 and 6 */ | |
3328 | strcpy (wrap_indent, " "); | |
3329 | if (addressprint) | |
75ac9d7b MS |
3330 | { |
3331 | if (TARGET_ADDR_BIT <= 32) | |
3332 | strcat (wrap_indent, " "); | |
3333 | else | |
3334 | strcat (wrap_indent, " "); | |
3335 | } | |
c906108c | 3336 | |
3086aeae DJ |
3337 | if (b->ops != NULL && b->ops->print_one != NULL) |
3338 | b->ops->print_one (b, last_addr); | |
3339 | else | |
3340 | switch (b->type) | |
3341 | { | |
3342 | case bp_none: | |
3343 | internal_error (__FILE__, __LINE__, | |
3344 | "print_one_breakpoint: bp_none encountered\n"); | |
3345 | break; | |
c906108c | 3346 | |
3086aeae DJ |
3347 | case bp_watchpoint: |
3348 | case bp_hardware_watchpoint: | |
3349 | case bp_read_watchpoint: | |
3350 | case bp_access_watchpoint: | |
3351 | /* Field 4, the address, is omitted (which makes the columns | |
3352 | not line up too nicely with the headers, but the effect | |
3353 | is relatively readable). */ | |
3354 | if (addressprint) | |
3355 | ui_out_field_skip (uiout, "addr"); | |
3356 | annotate_field (5); | |
3357 | print_expression (b->exp, stb->stream); | |
3358 | ui_out_field_stream (uiout, "what", stb); | |
3359 | break; | |
3360 | ||
3361 | case bp_catch_load: | |
3362 | case bp_catch_unload: | |
3363 | /* Field 4, the address, is omitted (which makes the columns | |
3364 | not line up too nicely with the headers, but the effect | |
3365 | is relatively readable). */ | |
3366 | if (addressprint) | |
3367 | ui_out_field_skip (uiout, "addr"); | |
3368 | annotate_field (5); | |
3369 | if (b->dll_pathname == NULL) | |
3370 | { | |
3371 | ui_out_field_string (uiout, "what", "<any library>"); | |
3372 | ui_out_spaces (uiout, 1); | |
3373 | } | |
3374 | else | |
3375 | { | |
3376 | ui_out_text (uiout, "library \""); | |
3377 | ui_out_field_string (uiout, "what", b->dll_pathname); | |
3378 | ui_out_text (uiout, "\" "); | |
3379 | } | |
3380 | break; | |
3381 | ||
3382 | case bp_catch_fork: | |
3383 | case bp_catch_vfork: | |
3384 | /* Field 4, the address, is omitted (which makes the columns | |
3385 | not line up too nicely with the headers, but the effect | |
3386 | is relatively readable). */ | |
3387 | if (addressprint) | |
3388 | ui_out_field_skip (uiout, "addr"); | |
3389 | annotate_field (5); | |
3390 | if (b->forked_inferior_pid != 0) | |
3391 | { | |
3392 | ui_out_text (uiout, "process "); | |
3393 | ui_out_field_int (uiout, "what", b->forked_inferior_pid); | |
3394 | ui_out_spaces (uiout, 1); | |
3395 | } | |
3396 | ||
3397 | case bp_catch_exec: | |
3398 | /* Field 4, the address, is omitted (which makes the columns | |
3399 | not line up too nicely with the headers, but the effect | |
3400 | is relatively readable). */ | |
3401 | if (addressprint) | |
3402 | ui_out_field_skip (uiout, "addr"); | |
3403 | annotate_field (5); | |
3404 | if (b->exec_pathname != NULL) | |
3405 | { | |
3406 | ui_out_text (uiout, "program \""); | |
3407 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
3408 | ui_out_text (uiout, "\" "); | |
3409 | } | |
3410 | break; | |
3411 | ||
3412 | case bp_catch_catch: | |
3413 | /* Field 4, the address, is omitted (which makes the columns | |
3414 | not line up too nicely with the headers, but the effect | |
3415 | is relatively readable). */ | |
3416 | if (addressprint) | |
3417 | ui_out_field_skip (uiout, "addr"); | |
3418 | annotate_field (5); | |
3419 | ui_out_field_string (uiout, "what", "exception catch"); | |
3420 | ui_out_spaces (uiout, 1); | |
3421 | break; | |
3422 | ||
3423 | case bp_catch_throw: | |
3424 | /* Field 4, the address, is omitted (which makes the columns | |
3425 | not line up too nicely with the headers, but the effect | |
3426 | is relatively readable). */ | |
3427 | if (addressprint) | |
3428 | ui_out_field_skip (uiout, "addr"); | |
3429 | annotate_field (5); | |
3430 | ui_out_field_string (uiout, "what", "exception throw"); | |
3431 | ui_out_spaces (uiout, 1); | |
3432 | break; | |
3433 | ||
3434 | case bp_breakpoint: | |
3435 | case bp_hardware_breakpoint: | |
3436 | case bp_until: | |
3437 | case bp_finish: | |
3438 | case bp_longjmp: | |
3439 | case bp_longjmp_resume: | |
3440 | case bp_step_resume: | |
3441 | case bp_through_sigtramp: | |
3442 | case bp_watchpoint_scope: | |
3443 | case bp_call_dummy: | |
3444 | case bp_shlib_event: | |
3445 | case bp_thread_event: | |
3446 | case bp_overlay_event: | |
3447 | if (addressprint) | |
3448 | { | |
3449 | annotate_field (4); | |
5cab636d | 3450 | ui_out_field_core_addr (uiout, "addr", b->loc->address); |
3086aeae DJ |
3451 | } |
3452 | annotate_field (5); | |
5cab636d | 3453 | *last_addr = b->loc->address; |
3086aeae DJ |
3454 | if (b->source_file) |
3455 | { | |
cf3a9e5b | 3456 | sym = find_pc_sect_function (b->loc->address, b->loc->section); |
3086aeae DJ |
3457 | if (sym) |
3458 | { | |
3459 | ui_out_text (uiout, "in "); | |
3460 | ui_out_field_string (uiout, "func", | |
3461 | SYMBOL_PRINT_NAME (sym)); | |
3462 | ui_out_wrap_hint (uiout, wrap_indent); | |
3463 | ui_out_text (uiout, " at "); | |
3464 | } | |
3465 | ui_out_field_string (uiout, "file", b->source_file); | |
3466 | ui_out_text (uiout, ":"); | |
3467 | ui_out_field_int (uiout, "line", b->line_number); | |
3468 | } | |
3469 | else | |
3470 | { | |
5cab636d | 3471 | print_address_symbolic (b->loc->address, stb->stream, demangle, ""); |
3086aeae DJ |
3472 | ui_out_field_stream (uiout, "at", stb); |
3473 | } | |
3474 | break; | |
3475 | } | |
c906108c | 3476 | |
c4093a6a JM |
3477 | if (b->thread != -1) |
3478 | { | |
8b93c638 JM |
3479 | /* FIXME: This seems to be redundant and lost here; see the |
3480 | "stop only in" line a little further down. */ | |
3481 | ui_out_text (uiout, " thread "); | |
3482 | ui_out_field_int (uiout, "thread", b->thread); | |
c4093a6a JM |
3483 | } |
3484 | ||
8b93c638 | 3485 | ui_out_text (uiout, "\n"); |
c4093a6a | 3486 | |
818dd999 | 3487 | if (frame_id_p (b->frame_id)) |
c4093a6a JM |
3488 | { |
3489 | annotate_field (6); | |
8b93c638 | 3490 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3491 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3492 | the frame ID. */ | |
d0a55772 | 3493 | ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr); |
8b93c638 | 3494 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3495 | } |
3496 | ||
3497 | if (b->cond) | |
3498 | { | |
3499 | annotate_field (7); | |
8b93c638 JM |
3500 | ui_out_text (uiout, "\tstop only if "); |
3501 | print_expression (b->cond, stb->stream); | |
3502 | ui_out_field_stream (uiout, "cond", stb); | |
3503 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3504 | } |
3505 | ||
3506 | if (b->thread != -1) | |
3507 | { | |
3508 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3509 | ui_out_text (uiout, "\tstop only in thread "); |
3510 | ui_out_field_int (uiout, "thread", b->thread); | |
3511 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3512 | } |
3513 | ||
3514 | if (show_breakpoint_hit_counts && b->hit_count) | |
3515 | { | |
3516 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3517 | if (ep_is_catchpoint (b)) |
3518 | ui_out_text (uiout, "\tcatchpoint"); | |
3519 | else | |
3520 | ui_out_text (uiout, "\tbreakpoint"); | |
3521 | ui_out_text (uiout, " already hit "); | |
3522 | ui_out_field_int (uiout, "times", b->hit_count); | |
3523 | if (b->hit_count == 1) | |
3524 | ui_out_text (uiout, " time\n"); | |
3525 | else | |
3526 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3527 | } |
3528 | ||
fb40c209 AC |
3529 | /* Output the count also if it is zero, but only if this is |
3530 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3531 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 AC |
3532 | if (show_breakpoint_hit_counts && b->hit_count == 0) |
3533 | ui_out_field_int (uiout, "times", b->hit_count); | |
8b93c638 | 3534 | |
c4093a6a JM |
3535 | if (b->ignore_count) |
3536 | { | |
3537 | annotate_field (8); | |
8b93c638 JM |
3538 | ui_out_text (uiout, "\tignore next "); |
3539 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3540 | ui_out_text (uiout, " hits\n"); | |
c4093a6a JM |
3541 | } |
3542 | ||
3543 | if ((l = b->commands)) | |
3544 | { | |
3b31d625 EZ |
3545 | struct cleanup *script_chain; |
3546 | ||
c4093a6a | 3547 | annotate_field (9); |
3b31d625 | 3548 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3549 | print_command_lines (uiout, l, 4); |
3b31d625 | 3550 | do_cleanups (script_chain); |
c4093a6a | 3551 | } |
3b31d625 | 3552 | do_cleanups (bkpt_chain); |
8b93c638 | 3553 | do_cleanups (old_chain); |
c4093a6a | 3554 | } |
c5aa993b | 3555 | |
c4093a6a JM |
3556 | struct captured_breakpoint_query_args |
3557 | { | |
3558 | int bnum; | |
3559 | }; | |
c5aa993b | 3560 | |
c4093a6a | 3561 | static int |
2b65245e | 3562 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3563 | { |
3564 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3565 | struct breakpoint *b; |
c4093a6a JM |
3566 | CORE_ADDR dummy_addr = 0; |
3567 | ALL_BREAKPOINTS (b) | |
3568 | { | |
3569 | if (args->bnum == b->number) | |
c5aa993b | 3570 | { |
c4093a6a JM |
3571 | print_one_breakpoint (b, &dummy_addr); |
3572 | return GDB_RC_OK; | |
c5aa993b | 3573 | } |
c4093a6a JM |
3574 | } |
3575 | return GDB_RC_NONE; | |
3576 | } | |
c5aa993b | 3577 | |
c4093a6a | 3578 | enum gdb_rc |
2b65245e | 3579 | gdb_breakpoint_query (struct ui_out *uiout, int bnum) |
c4093a6a JM |
3580 | { |
3581 | struct captured_breakpoint_query_args args; | |
3582 | args.bnum = bnum; | |
3583 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3584 | an error. */ | |
2b65245e AC |
3585 | return catch_exceptions (uiout, do_captured_breakpoint_query, &args, |
3586 | NULL, RETURN_MASK_ALL); | |
c4093a6a | 3587 | } |
c5aa993b | 3588 | |
7f3b0473 AC |
3589 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3590 | catchpoints, et.al.). */ | |
3591 | ||
3592 | static int | |
3593 | user_settable_breakpoint (const struct breakpoint *b) | |
3594 | { | |
3595 | return (b->type == bp_breakpoint | |
3596 | || b->type == bp_catch_load | |
3597 | || b->type == bp_catch_unload | |
3598 | || b->type == bp_catch_fork | |
3599 | || b->type == bp_catch_vfork | |
3600 | || b->type == bp_catch_exec | |
3601 | || b->type == bp_catch_catch | |
3602 | || b->type == bp_catch_throw | |
3603 | || b->type == bp_hardware_breakpoint | |
3604 | || b->type == bp_watchpoint | |
3605 | || b->type == bp_read_watchpoint | |
3606 | || b->type == bp_access_watchpoint | |
3607 | || b->type == bp_hardware_watchpoint); | |
3608 | } | |
3609 | ||
3610 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3611 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3612 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3613 | |
c4093a6a | 3614 | static void |
fba45db2 | 3615 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3616 | { |
52f0bd74 | 3617 | struct breakpoint *b; |
c4093a6a | 3618 | CORE_ADDR last_addr = (CORE_ADDR) -1; |
7f3b0473 | 3619 | int nr_printable_breakpoints; |
3b31d625 | 3620 | struct cleanup *bkpttbl_chain; |
c4093a6a | 3621 | |
7f3b0473 AC |
3622 | /* Compute the number of rows in the table. */ |
3623 | nr_printable_breakpoints = 0; | |
3624 | ALL_BREAKPOINTS (b) | |
3625 | if (bnum == -1 | |
3626 | || bnum == b->number) | |
3627 | { | |
3628 | if (allflag || user_settable_breakpoint (b)) | |
3629 | nr_printable_breakpoints++; | |
3630 | } | |
3631 | ||
8b93c638 | 3632 | if (addressprint) |
3b31d625 EZ |
3633 | bkpttbl_chain |
3634 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
3635 | "BreakpointTable"); | |
8b93c638 | 3636 | else |
3b31d625 EZ |
3637 | bkpttbl_chain |
3638 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
3639 | "BreakpointTable"); | |
8b93c638 | 3640 | |
7f3b0473 | 3641 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
3642 | annotate_breakpoints_headers (); |
3643 | if (nr_printable_breakpoints > 0) | |
3644 | annotate_field (0); | |
3645 | ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */ | |
3646 | if (nr_printable_breakpoints > 0) | |
3647 | annotate_field (1); | |
3648 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
3649 | if (nr_printable_breakpoints > 0) | |
3650 | annotate_field (2); | |
3651 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
3652 | if (nr_printable_breakpoints > 0) | |
3653 | annotate_field (3); | |
3654 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ | |
3655 | if (addressprint) | |
7f3b0473 | 3656 | { |
d7faa9e7 AC |
3657 | if (nr_printable_breakpoints > 0) |
3658 | annotate_field (4); | |
7f3b0473 | 3659 | if (TARGET_ADDR_BIT <= 32) |
b25959ec | 3660 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3661 | else |
b25959ec | 3662 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3663 | } |
d7faa9e7 AC |
3664 | if (nr_printable_breakpoints > 0) |
3665 | annotate_field (5); | |
3666 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
3667 | ui_out_table_body (uiout); | |
3668 | if (nr_printable_breakpoints > 0) | |
3669 | annotate_breakpoints_table (); | |
7f3b0473 | 3670 | |
c4093a6a JM |
3671 | ALL_BREAKPOINTS (b) |
3672 | if (bnum == -1 | |
3673 | || bnum == b->number) | |
3674 | { | |
3675 | /* We only print out user settable breakpoints unless the | |
3676 | allflag is set. */ | |
7f3b0473 AC |
3677 | if (allflag || user_settable_breakpoint (b)) |
3678 | print_one_breakpoint (b, &last_addr); | |
c4093a6a JM |
3679 | } |
3680 | ||
3b31d625 | 3681 | do_cleanups (bkpttbl_chain); |
698384cd | 3682 | |
7f3b0473 | 3683 | if (nr_printable_breakpoints == 0) |
c906108c | 3684 | { |
8b93c638 JM |
3685 | if (bnum == -1) |
3686 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
3687 | else | |
3688 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
3689 | bnum); | |
c906108c SS |
3690 | } |
3691 | else | |
c4093a6a JM |
3692 | { |
3693 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
3694 | that a comparison of an unsigned with -1 is always false. */ | |
3695 | if (last_addr != (CORE_ADDR) -1) | |
3696 | set_next_address (last_addr); | |
3697 | } | |
c906108c | 3698 | |
c4093a6a JM |
3699 | /* FIXME? Should this be moved up so that it is only called when |
3700 | there have been breakpoints? */ | |
c906108c SS |
3701 | annotate_breakpoints_table_end (); |
3702 | } | |
3703 | ||
c906108c | 3704 | static void |
fba45db2 | 3705 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
3706 | { |
3707 | int bnum = -1; | |
3708 | ||
3709 | if (bnum_exp) | |
bb518678 | 3710 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3711 | |
3712 | breakpoint_1 (bnum, 0); | |
3713 | } | |
3714 | ||
7a292a7a | 3715 | static void |
fba45db2 | 3716 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
3717 | { |
3718 | int bnum = -1; | |
3719 | ||
3720 | if (bnum_exp) | |
bb518678 | 3721 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3722 | |
3723 | breakpoint_1 (bnum, 1); | |
3724 | } | |
3725 | ||
c906108c SS |
3726 | /* Print a message describing any breakpoints set at PC. */ |
3727 | ||
3728 | static void | |
fba45db2 | 3729 | describe_other_breakpoints (CORE_ADDR pc, asection *section) |
c906108c | 3730 | { |
52f0bd74 AC |
3731 | int others = 0; |
3732 | struct breakpoint *b; | |
c906108c SS |
3733 | |
3734 | ALL_BREAKPOINTS (b) | |
5cab636d | 3735 | if (b->loc->address == pc) /* address match / overlay match */ |
cf3a9e5b | 3736 | if (!overlay_debugging || b->loc->section == section) |
9f04af04 | 3737 | others++; |
c906108c SS |
3738 | if (others > 0) |
3739 | { | |
3740 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); | |
3741 | ALL_BREAKPOINTS (b) | |
5cab636d | 3742 | if (b->loc->address == pc) /* address match / overlay match */ |
cf3a9e5b | 3743 | if (!overlay_debugging || b->loc->section == section) |
9f04af04 MS |
3744 | { |
3745 | others--; | |
3746 | printf_filtered ("%d%s%s ", | |
3747 | b->number, | |
3748 | ((b->enable_state == bp_disabled || | |
3749 | b->enable_state == bp_shlib_disabled || | |
3750 | b->enable_state == bp_call_disabled) | |
3751 | ? " (disabled)" | |
3752 | : b->enable_state == bp_permanent | |
3753 | ? " (permanent)" | |
3754 | : ""), | |
3755 | (others > 1) ? "," | |
3756 | : ((others == 1) ? " and" : "")); | |
3757 | } | |
c906108c SS |
3758 | printf_filtered ("also set at pc "); |
3759 | print_address_numeric (pc, 1, gdb_stdout); | |
3760 | printf_filtered (".\n"); | |
3761 | } | |
3762 | } | |
3763 | \f | |
3764 | /* Set the default place to put a breakpoint | |
3765 | for the `break' command with no arguments. */ | |
3766 | ||
3767 | void | |
fba45db2 KB |
3768 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
3769 | int line) | |
c906108c SS |
3770 | { |
3771 | default_breakpoint_valid = valid; | |
3772 | default_breakpoint_address = addr; | |
3773 | default_breakpoint_symtab = symtab; | |
3774 | default_breakpoint_line = line; | |
3775 | } | |
3776 | ||
e4f237da KB |
3777 | /* Return true iff it is meaningful to use the address member of |
3778 | BPT. For some breakpoint types, the address member is irrelevant | |
3779 | and it makes no sense to attempt to compare it to other addresses | |
3780 | (or use it for any other purpose either). | |
3781 | ||
3782 | More specifically, each of the following breakpoint types will always | |
3783 | have a zero valued address and we don't want check_duplicates() to mark | |
3784 | breakpoints of any of these types to be a duplicate of an actual | |
3785 | breakpoint at address zero: | |
3786 | ||
3787 | bp_watchpoint | |
3788 | bp_hardware_watchpoint | |
3789 | bp_read_watchpoint | |
3790 | bp_access_watchpoint | |
3791 | bp_catch_exec | |
3792 | bp_longjmp_resume | |
3793 | bp_catch_fork | |
3794 | bp_catch_vork */ | |
3795 | ||
3796 | static int | |
3797 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
3798 | { | |
3799 | enum bptype type = bpt->type; | |
3800 | ||
3801 | return (type != bp_watchpoint | |
3802 | && type != bp_hardware_watchpoint | |
3803 | && type != bp_read_watchpoint | |
3804 | && type != bp_access_watchpoint | |
3805 | && type != bp_catch_exec | |
3806 | && type != bp_longjmp_resume | |
3807 | && type != bp_catch_fork | |
3808 | && type != bp_catch_vfork); | |
3809 | } | |
3810 | ||
9f60f21b | 3811 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 3812 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 3813 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
3814 | If we have a permanent breakpoint at the same place as BPT, make |
3815 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
3816 | |
3817 | static void | |
9f60f21b | 3818 | check_duplicates (struct breakpoint *bpt) |
c906108c | 3819 | { |
52f0bd74 AC |
3820 | struct breakpoint *b; |
3821 | int count = 0; | |
c2c6d25f | 3822 | struct breakpoint *perm_bp = 0; |
5cab636d | 3823 | CORE_ADDR address = bpt->loc->address; |
cf3a9e5b | 3824 | asection *section = bpt->loc->section; |
c906108c | 3825 | |
e4f237da | 3826 | if (! breakpoint_address_is_meaningful (bpt)) |
c906108c SS |
3827 | return; |
3828 | ||
3829 | ALL_BREAKPOINTS (b) | |
b5de0fa7 EZ |
3830 | if (b->enable_state != bp_disabled |
3831 | && b->enable_state != bp_shlib_disabled | |
3832 | && b->enable_state != bp_call_disabled | |
5cab636d | 3833 | && b->loc->address == address /* address / overlay match */ |
cf3a9e5b | 3834 | && (!overlay_debugging || b->loc->section == section) |
e4f237da | 3835 | && breakpoint_address_is_meaningful (b)) |
c5aa993b | 3836 | { |
c2c6d25f | 3837 | /* Have we found a permanent breakpoint? */ |
b5de0fa7 | 3838 | if (b->enable_state == bp_permanent) |
c2c6d25f JM |
3839 | { |
3840 | perm_bp = b; | |
3841 | break; | |
3842 | } | |
3843 | ||
c5aa993b | 3844 | count++; |
5cab636d | 3845 | b->loc->duplicate = count > 1; |
c5aa993b | 3846 | } |
c2c6d25f JM |
3847 | |
3848 | /* If we found a permanent breakpoint at this address, go over the | |
3849 | list again and declare all the other breakpoints there to be the | |
3850 | duplicates. */ | |
3851 | if (perm_bp) | |
3852 | { | |
5cab636d | 3853 | perm_bp->loc->duplicate = 0; |
c2c6d25f JM |
3854 | |
3855 | /* Permanent breakpoint should always be inserted. */ | |
5cab636d | 3856 | if (! perm_bp->loc->inserted) |
8e65ff28 AC |
3857 | internal_error (__FILE__, __LINE__, |
3858 | "allegedly permanent breakpoint is not " | |
c2c6d25f JM |
3859 | "actually inserted"); |
3860 | ||
3861 | ALL_BREAKPOINTS (b) | |
3862 | if (b != perm_bp) | |
3863 | { | |
5cab636d | 3864 | if (b->loc->inserted) |
8e65ff28 AC |
3865 | internal_error (__FILE__, __LINE__, |
3866 | "another breakpoint was inserted on top of " | |
c2c6d25f JM |
3867 | "a permanent breakpoint"); |
3868 | ||
b5de0fa7 EZ |
3869 | if (b->enable_state != bp_disabled |
3870 | && b->enable_state != bp_shlib_disabled | |
3871 | && b->enable_state != bp_call_disabled | |
5cab636d | 3872 | && b->loc->address == address /* address / overlay match */ |
cf3a9e5b | 3873 | && (!overlay_debugging || b->loc->section == section) |
e4f237da | 3874 | && breakpoint_address_is_meaningful (b)) |
5cab636d | 3875 | b->loc->duplicate = 1; |
c2c6d25f JM |
3876 | } |
3877 | } | |
c906108c SS |
3878 | } |
3879 | ||
76897487 KB |
3880 | static void |
3881 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
3882 | int bnum, int have_bnum) | |
3883 | { | |
3884 | char astr1[40]; | |
3885 | char astr2[40]; | |
3886 | ||
3887 | strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l")); | |
3888 | strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l")); | |
3889 | if (have_bnum) | |
3890 | warning ("Breakpoint %d address previously adjusted from %s to %s.", | |
3891 | bnum, astr1, astr2); | |
3892 | else | |
3893 | warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2); | |
3894 | } | |
3895 | ||
3896 | /* Adjust a breakpoint's address to account for architectural constraints | |
3897 | on breakpoint placement. Return the adjusted address. Note: Very | |
3898 | few targets require this kind of adjustment. For most targets, | |
3899 | this function is simply the identity function. */ | |
3900 | ||
3901 | static CORE_ADDR | |
3902 | adjust_breakpoint_address (CORE_ADDR bpaddr) | |
3903 | { | |
3904 | if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch)) | |
3905 | { | |
3906 | /* Very few targets need any kind of breakpoint adjustment. */ | |
3907 | return bpaddr; | |
3908 | } | |
3909 | else | |
3910 | { | |
3911 | CORE_ADDR adjusted_bpaddr; | |
3912 | ||
3913 | /* Some targets have architectural constraints on the placement | |
3914 | of breakpoint instructions. Obtain the adjusted address. */ | |
3915 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch, | |
3916 | bpaddr); | |
3917 | ||
3918 | /* An adjusted breakpoint address can significantly alter | |
3919 | a user's expectations. Print a warning if an adjustment | |
3920 | is required. */ | |
3921 | if (adjusted_bpaddr != bpaddr) | |
3922 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
3923 | ||
3924 | return adjusted_bpaddr; | |
3925 | } | |
3926 | } | |
3927 | ||
7cc221ef DJ |
3928 | /* Allocate a struct bp_location. */ |
3929 | ||
3930 | struct bp_location * | |
e049a4b5 | 3931 | allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type) |
7cc221ef DJ |
3932 | { |
3933 | struct bp_location *loc, *loc_p; | |
3934 | ||
3935 | loc = xmalloc (sizeof (struct bp_location)); | |
3936 | memset (loc, 0, sizeof (*loc)); | |
3937 | ||
e049a4b5 DJ |
3938 | loc->owner = bpt; |
3939 | ||
3940 | switch (bp_type) | |
3941 | { | |
3942 | case bp_breakpoint: | |
3943 | case bp_until: | |
3944 | case bp_finish: | |
3945 | case bp_longjmp: | |
3946 | case bp_longjmp_resume: | |
3947 | case bp_step_resume: | |
3948 | case bp_through_sigtramp: | |
3949 | case bp_watchpoint_scope: | |
3950 | case bp_call_dummy: | |
3951 | case bp_shlib_event: | |
3952 | case bp_thread_event: | |
3953 | case bp_overlay_event: | |
3954 | case bp_catch_load: | |
3955 | case bp_catch_unload: | |
3956 | loc->loc_type = bp_loc_software_breakpoint; | |
3957 | break; | |
3958 | case bp_hardware_breakpoint: | |
3959 | loc->loc_type = bp_loc_hardware_breakpoint; | |
3960 | break; | |
3961 | case bp_hardware_watchpoint: | |
3962 | case bp_read_watchpoint: | |
3963 | case bp_access_watchpoint: | |
3964 | loc->loc_type = bp_loc_hardware_watchpoint; | |
3965 | break; | |
3966 | case bp_watchpoint: | |
3967 | case bp_catch_fork: | |
3968 | case bp_catch_vfork: | |
3969 | case bp_catch_exec: | |
3970 | case bp_catch_catch: | |
3971 | case bp_catch_throw: | |
3972 | loc->loc_type = bp_loc_other; | |
3973 | break; | |
3974 | default: | |
3975 | internal_error (__FILE__, __LINE__, "unknown breakpoint type"); | |
3976 | } | |
3977 | ||
7cc221ef DJ |
3978 | /* Add this breakpoint to the end of the chain. */ |
3979 | ||
3980 | loc_p = bp_location_chain; | |
3981 | if (loc_p == 0) | |
3982 | bp_location_chain = loc; | |
3983 | else | |
3984 | { | |
3985 | while (loc_p->next) | |
3986 | loc_p = loc_p->next; | |
3987 | loc_p->next = loc; | |
3988 | } | |
3989 | ||
3990 | return loc; | |
3991 | } | |
3992 | ||
4d28f7a8 KB |
3993 | /* set_raw_breakpoint() is a low level routine for allocating and |
3994 | partially initializing a breakpoint of type BPTYPE. The newly | |
3995 | created breakpoint's address, section, source file name, and line | |
3996 | number are provided by SAL. The newly created and partially | |
3997 | initialized breakpoint is added to the breakpoint chain and | |
3998 | is also returned as the value of this function. | |
c906108c | 3999 | |
4d28f7a8 KB |
4000 | It is expected that the caller will complete the initialization of |
4001 | the newly created breakpoint struct as well as output any status | |
4002 | information regarding the creation of a new breakpoint. In | |
4003 | particular, set_raw_breakpoint() does NOT set the breakpoint | |
4004 | number! Care should be taken to not allow an error() to occur | |
4005 | prior to completing the initialization of the breakpoint. If this | |
4006 | should happen, a bogus breakpoint will be left on the chain. */ | |
c906108c SS |
4007 | |
4008 | struct breakpoint * | |
4d28f7a8 | 4009 | set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype) |
c906108c | 4010 | { |
52f0bd74 | 4011 | struct breakpoint *b, *b1; |
c906108c SS |
4012 | |
4013 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4014 | memset (b, 0, sizeof (*b)); | |
e049a4b5 | 4015 | b->loc = allocate_bp_location (b, bptype); |
5cab636d DJ |
4016 | b->loc->requested_address = sal.pc; |
4017 | b->loc->address = adjust_breakpoint_address (b->loc->requested_address); | |
c906108c SS |
4018 | if (sal.symtab == NULL) |
4019 | b->source_file = NULL; | |
4020 | else | |
4021 | b->source_file = savestring (sal.symtab->filename, | |
4022 | strlen (sal.symtab->filename)); | |
cf3a9e5b | 4023 | b->loc->section = sal.section; |
4d28f7a8 | 4024 | b->type = bptype; |
c906108c SS |
4025 | b->language = current_language->la_language; |
4026 | b->input_radix = input_radix; | |
4027 | b->thread = -1; | |
4028 | b->line_number = sal.line; | |
b5de0fa7 | 4029 | b->enable_state = bp_enabled; |
c906108c SS |
4030 | b->next = 0; |
4031 | b->silent = 0; | |
4032 | b->ignore_count = 0; | |
4033 | b->commands = NULL; | |
818dd999 | 4034 | b->frame_id = null_frame_id; |
c906108c SS |
4035 | b->dll_pathname = NULL; |
4036 | b->triggered_dll_pathname = NULL; | |
4037 | b->forked_inferior_pid = 0; | |
4038 | b->exec_pathname = NULL; | |
3086aeae | 4039 | b->ops = NULL; |
c906108c SS |
4040 | |
4041 | /* Add this breakpoint to the end of the chain | |
4042 | so that a list of breakpoints will come out in order | |
4043 | of increasing numbers. */ | |
4044 | ||
4045 | b1 = breakpoint_chain; | |
4046 | if (b1 == 0) | |
4047 | breakpoint_chain = b; | |
4048 | else | |
4049 | { | |
4050 | while (b1->next) | |
4051 | b1 = b1->next; | |
4052 | b1->next = b; | |
4053 | } | |
4054 | ||
9f60f21b | 4055 | check_duplicates (b); |
c906108c SS |
4056 | breakpoints_changed (); |
4057 | ||
4058 | return b; | |
4059 | } | |
4060 | ||
c2c6d25f JM |
4061 | |
4062 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4063 | instruction, hard-wired into the inferior's code. */ | |
4064 | void | |
4065 | make_breakpoint_permanent (struct breakpoint *b) | |
4066 | { | |
b5de0fa7 | 4067 | b->enable_state = bp_permanent; |
c2c6d25f JM |
4068 | |
4069 | /* By definition, permanent breakpoints are already present in the code. */ | |
5cab636d | 4070 | b->loc->inserted = 1; |
c2c6d25f JM |
4071 | } |
4072 | ||
1900040c MS |
4073 | static struct breakpoint * |
4074 | create_internal_breakpoint (CORE_ADDR address, enum bptype type) | |
4075 | { | |
4076 | static int internal_breakpoint_number = -1; | |
4077 | struct symtab_and_line sal; | |
4078 | struct breakpoint *b; | |
4079 | ||
fe39c653 | 4080 | init_sal (&sal); /* initialize to zeroes */ |
1900040c MS |
4081 | |
4082 | sal.pc = address; | |
4083 | sal.section = find_pc_overlay (sal.pc); | |
4084 | ||
4085 | b = set_raw_breakpoint (sal, type); | |
4086 | b->number = internal_breakpoint_number--; | |
4087 | b->disposition = disp_donttouch; | |
4088 | ||
4089 | return b; | |
4090 | } | |
4091 | ||
c906108c SS |
4092 | |
4093 | static void | |
fba45db2 | 4094 | create_longjmp_breakpoint (char *func_name) |
c906108c | 4095 | { |
c906108c | 4096 | struct breakpoint *b; |
1900040c | 4097 | struct minimal_symbol *m; |
c906108c | 4098 | |
1900040c MS |
4099 | if (func_name == NULL) |
4100 | b = create_internal_breakpoint (0, bp_longjmp_resume); | |
4101 | else | |
c906108c | 4102 | { |
5520a790 | 4103 | if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL) |
c906108c | 4104 | return; |
1900040c MS |
4105 | |
4106 | b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp); | |
c906108c | 4107 | } |
c906108c | 4108 | |
b5de0fa7 | 4109 | b->enable_state = bp_disabled; |
c906108c SS |
4110 | b->silent = 1; |
4111 | if (func_name) | |
4fcf66da | 4112 | b->addr_string = xstrdup (func_name); |
c906108c SS |
4113 | } |
4114 | ||
53a5351d JM |
4115 | /* Call this routine when stepping and nexting to enable a breakpoint |
4116 | if we do a longjmp(). When we hit that breakpoint, call | |
c906108c SS |
4117 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4118 | ||
4119 | void | |
fba45db2 | 4120 | enable_longjmp_breakpoint (void) |
c906108c | 4121 | { |
52f0bd74 | 4122 | struct breakpoint *b; |
c906108c SS |
4123 | |
4124 | ALL_BREAKPOINTS (b) | |
4125 | if (b->type == bp_longjmp) | |
c5aa993b | 4126 | { |
b5de0fa7 | 4127 | b->enable_state = bp_enabled; |
9f60f21b | 4128 | check_duplicates (b); |
c5aa993b | 4129 | } |
c906108c SS |
4130 | } |
4131 | ||
4132 | void | |
fba45db2 | 4133 | disable_longjmp_breakpoint (void) |
c906108c | 4134 | { |
52f0bd74 | 4135 | struct breakpoint *b; |
c906108c SS |
4136 | |
4137 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4138 | if (b->type == bp_longjmp |
c906108c | 4139 | || b->type == bp_longjmp_resume) |
c5aa993b | 4140 | { |
b5de0fa7 | 4141 | b->enable_state = bp_disabled; |
9f60f21b | 4142 | check_duplicates (b); |
c5aa993b | 4143 | } |
c906108c SS |
4144 | } |
4145 | ||
1900040c MS |
4146 | static void |
4147 | create_overlay_event_breakpoint (char *func_name) | |
4148 | { | |
4149 | struct breakpoint *b; | |
4150 | struct minimal_symbol *m; | |
4151 | ||
5520a790 | 4152 | if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL) |
1900040c MS |
4153 | return; |
4154 | ||
4155 | b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), | |
4156 | bp_overlay_event); | |
4157 | b->addr_string = xstrdup (func_name); | |
4158 | ||
4159 | if (overlay_debugging == ovly_auto) | |
c02f5703 MS |
4160 | { |
4161 | b->enable_state = bp_enabled; | |
4162 | overlay_events_enabled = 1; | |
4163 | } | |
1900040c | 4164 | else |
c02f5703 MS |
4165 | { |
4166 | b->enable_state = bp_disabled; | |
4167 | overlay_events_enabled = 0; | |
4168 | } | |
1900040c MS |
4169 | } |
4170 | ||
4171 | void | |
4172 | enable_overlay_breakpoints (void) | |
4173 | { | |
52f0bd74 | 4174 | struct breakpoint *b; |
1900040c MS |
4175 | |
4176 | ALL_BREAKPOINTS (b) | |
4177 | if (b->type == bp_overlay_event) | |
4178 | { | |
4179 | b->enable_state = bp_enabled; | |
4180 | check_duplicates (b); | |
c02f5703 | 4181 | overlay_events_enabled = 1; |
1900040c MS |
4182 | } |
4183 | } | |
4184 | ||
4185 | void | |
4186 | disable_overlay_breakpoints (void) | |
4187 | { | |
52f0bd74 | 4188 | struct breakpoint *b; |
1900040c MS |
4189 | |
4190 | ALL_BREAKPOINTS (b) | |
4191 | if (b->type == bp_overlay_event) | |
4192 | { | |
4193 | b->enable_state = bp_disabled; | |
4194 | check_duplicates (b); | |
c02f5703 | 4195 | overlay_events_enabled = 0; |
1900040c MS |
4196 | } |
4197 | } | |
4198 | ||
c4093a6a | 4199 | struct breakpoint * |
fba45db2 | 4200 | create_thread_event_breakpoint (CORE_ADDR address) |
c4093a6a JM |
4201 | { |
4202 | struct breakpoint *b; | |
c4093a6a | 4203 | |
1900040c | 4204 | b = create_internal_breakpoint (address, bp_thread_event); |
c4093a6a | 4205 | |
b5de0fa7 | 4206 | b->enable_state = bp_enabled; |
c4093a6a | 4207 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5cab636d | 4208 | xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address)); |
c4093a6a JM |
4209 | |
4210 | return b; | |
4211 | } | |
4212 | ||
4213 | void | |
4214 | remove_thread_event_breakpoints (void) | |
4215 | { | |
4216 | struct breakpoint *b, *temp; | |
4217 | ||
4218 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4219 | if (b->type == bp_thread_event) | |
4220 | delete_breakpoint (b); | |
4221 | } | |
4222 | ||
c906108c SS |
4223 | #ifdef SOLIB_ADD |
4224 | void | |
fba45db2 | 4225 | remove_solib_event_breakpoints (void) |
c906108c | 4226 | { |
52f0bd74 | 4227 | struct breakpoint *b, *temp; |
c906108c SS |
4228 | |
4229 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4230 | if (b->type == bp_shlib_event) | |
3172dc30 | 4231 | delete_breakpoint (b); |
c906108c SS |
4232 | } |
4233 | ||
c2c6d25f | 4234 | struct breakpoint * |
fba45db2 | 4235 | create_solib_event_breakpoint (CORE_ADDR address) |
c906108c SS |
4236 | { |
4237 | struct breakpoint *b; | |
c2c6d25f | 4238 | |
1900040c | 4239 | b = create_internal_breakpoint (address, bp_shlib_event); |
c2c6d25f | 4240 | return b; |
c906108c SS |
4241 | } |
4242 | ||
104c1213 JM |
4243 | /* Disable any breakpoints that are on code in shared libraries. Only |
4244 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4245 | ||
c906108c | 4246 | void |
fba45db2 | 4247 | disable_breakpoints_in_shlibs (int silent) |
c906108c | 4248 | { |
c5aa993b JM |
4249 | struct breakpoint *b; |
4250 | int disabled_shlib_breaks = 0; | |
c906108c SS |
4251 | |
4252 | /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */ | |
4253 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4254 | { |
c906108c | 4255 | #if defined (PC_SOLIB) |
c5aa993b JM |
4256 | if (((b->type == bp_breakpoint) || |
4257 | (b->type == bp_hardware_breakpoint)) && | |
b5de0fa7 | 4258 | b->enable_state == bp_enabled && |
5cab636d DJ |
4259 | !b->loc->duplicate && |
4260 | PC_SOLIB (b->loc->address)) | |
c5aa993b | 4261 | { |
b5de0fa7 | 4262 | b->enable_state = bp_shlib_disabled; |
c5aa993b JM |
4263 | if (!silent) |
4264 | { | |
4265 | if (!disabled_shlib_breaks) | |
4266 | { | |
4267 | target_terminal_ours_for_output (); | |
53a5351d | 4268 | warning ("Temporarily disabling shared library breakpoints:"); |
c5aa993b JM |
4269 | } |
4270 | disabled_shlib_breaks = 1; | |
53a5351d | 4271 | warning ("breakpoint #%d ", b->number); |
c5aa993b JM |
4272 | } |
4273 | } | |
c906108c | 4274 | #endif |
c5aa993b | 4275 | } |
c906108c SS |
4276 | } |
4277 | ||
4278 | /* Try to reenable any breakpoints in shared libraries. */ | |
4279 | void | |
fba45db2 | 4280 | re_enable_breakpoints_in_shlibs (void) |
c906108c SS |
4281 | { |
4282 | struct breakpoint *b; | |
4283 | ||
4284 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 4285 | if (b->enable_state == bp_shlib_disabled) |
c5aa993b JM |
4286 | { |
4287 | char buf[1]; | |
c906108c | 4288 | |
c5aa993b JM |
4289 | /* Do not reenable the breakpoint if the shared library |
4290 | is still not mapped in. */ | |
5cab636d | 4291 | if (target_read_memory (b->loc->address, buf, 1) == 0) |
b5de0fa7 | 4292 | b->enable_state = bp_enabled; |
c5aa993b | 4293 | } |
c906108c SS |
4294 | } |
4295 | ||
4296 | #endif | |
4297 | ||
4298 | static void | |
fba45db2 KB |
4299 | solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname, |
4300 | char *cond_string, enum bptype bp_kind) | |
c906108c | 4301 | { |
c5aa993b | 4302 | struct breakpoint *b; |
c906108c | 4303 | struct symtabs_and_lines sals; |
c5aa993b JM |
4304 | struct cleanup *old_chain; |
4305 | struct cleanup *canonical_strings_chain = NULL; | |
c5aa993b JM |
4306 | char *addr_start = hookname; |
4307 | char *addr_end = NULL; | |
4308 | char **canonical = (char **) NULL; | |
4309 | int thread = -1; /* All threads. */ | |
4310 | ||
c906108c SS |
4311 | /* Set a breakpoint on the specified hook. */ |
4312 | sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical); | |
4313 | addr_end = hookname; | |
c5aa993b | 4314 | |
c906108c SS |
4315 | if (sals.nelts == 0) |
4316 | { | |
4317 | warning ("Unable to set a breakpoint on dynamic linker callback."); | |
4318 | warning ("Suggest linking with /opt/langtools/lib/end.o."); | |
4319 | warning ("GDB will be unable to track shl_load/shl_unload calls"); | |
4320 | return; | |
4321 | } | |
4322 | if (sals.nelts != 1) | |
4323 | { | |
53a5351d | 4324 | warning ("Unable to set unique breakpoint on dynamic linker callback."); |
c906108c SS |
4325 | warning ("GDB will be unable to track shl_load/shl_unload calls"); |
4326 | return; | |
4327 | } | |
4328 | ||
53a5351d JM |
4329 | /* Make sure that all storage allocated in decode_line_1 gets freed |
4330 | in case the following errors out. */ | |
b8c9b27d | 4331 | old_chain = make_cleanup (xfree, sals.sals); |
c5aa993b | 4332 | if (canonical != (char **) NULL) |
c906108c | 4333 | { |
b8c9b27d | 4334 | make_cleanup (xfree, canonical); |
c906108c SS |
4335 | canonical_strings_chain = make_cleanup (null_cleanup, 0); |
4336 | if (canonical[0] != NULL) | |
b8c9b27d | 4337 | make_cleanup (xfree, canonical[0]); |
c906108c | 4338 | } |
c5aa993b | 4339 | |
c906108c | 4340 | resolve_sal_pc (&sals.sals[0]); |
c5aa993b | 4341 | |
c906108c | 4342 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
c5aa993b | 4343 | if (canonical != (char **) NULL) |
c906108c | 4344 | discard_cleanups (canonical_strings_chain); |
c5aa993b | 4345 | |
4d28f7a8 | 4346 | b = set_raw_breakpoint (sals.sals[0], bp_kind); |
c906108c SS |
4347 | set_breakpoint_count (breakpoint_count + 1); |
4348 | b->number = breakpoint_count; | |
4349 | b->cond = NULL; | |
53a5351d JM |
4350 | b->cond_string = (cond_string == NULL) ? |
4351 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c | 4352 | b->thread = thread; |
c5aa993b JM |
4353 | |
4354 | if (canonical != (char **) NULL && canonical[0] != NULL) | |
c906108c SS |
4355 | b->addr_string = canonical[0]; |
4356 | else if (addr_start) | |
4357 | b->addr_string = savestring (addr_start, addr_end - addr_start); | |
c5aa993b | 4358 | |
b5de0fa7 EZ |
4359 | b->enable_state = bp_enabled; |
4360 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c5aa993b | 4361 | |
c906108c SS |
4362 | if (dll_pathname == NULL) |
4363 | b->dll_pathname = NULL; | |
4364 | else | |
4365 | { | |
4366 | b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1); | |
4367 | strcpy (b->dll_pathname, dll_pathname); | |
4368 | } | |
c5aa993b | 4369 | |
c906108c SS |
4370 | mention (b); |
4371 | do_cleanups (old_chain); | |
4372 | } | |
4373 | ||
4374 | void | |
fba45db2 KB |
4375 | create_solib_load_event_breakpoint (char *hookname, int tempflag, |
4376 | char *dll_pathname, char *cond_string) | |
c906108c | 4377 | { |
53a5351d JM |
4378 | solib_load_unload_1 (hookname, tempflag, dll_pathname, |
4379 | cond_string, bp_catch_load); | |
c906108c SS |
4380 | } |
4381 | ||
4382 | void | |
fba45db2 KB |
4383 | create_solib_unload_event_breakpoint (char *hookname, int tempflag, |
4384 | char *dll_pathname, char *cond_string) | |
c906108c | 4385 | { |
53a5351d JM |
4386 | solib_load_unload_1 (hookname,tempflag, dll_pathname, |
4387 | cond_string, bp_catch_unload); | |
c906108c SS |
4388 | } |
4389 | ||
4390 | static void | |
fba45db2 KB |
4391 | create_fork_vfork_event_catchpoint (int tempflag, char *cond_string, |
4392 | enum bptype bp_kind) | |
c906108c | 4393 | { |
c5aa993b JM |
4394 | struct symtab_and_line sal; |
4395 | struct breakpoint *b; | |
4396 | int thread = -1; /* All threads. */ | |
4397 | ||
fe39c653 | 4398 | init_sal (&sal); |
c906108c SS |
4399 | sal.pc = 0; |
4400 | sal.symtab = NULL; | |
4401 | sal.line = 0; | |
c5aa993b | 4402 | |
4d28f7a8 | 4403 | b = set_raw_breakpoint (sal, bp_kind); |
c906108c SS |
4404 | set_breakpoint_count (breakpoint_count + 1); |
4405 | b->number = breakpoint_count; | |
4406 | b->cond = NULL; | |
53a5351d JM |
4407 | b->cond_string = (cond_string == NULL) ? |
4408 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
4409 | b->thread = thread; |
4410 | b->addr_string = NULL; | |
b5de0fa7 EZ |
4411 | b->enable_state = bp_enabled; |
4412 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c | 4413 | b->forked_inferior_pid = 0; |
c5aa993b | 4414 | |
c906108c SS |
4415 | mention (b); |
4416 | } | |
4417 | ||
4418 | void | |
fba45db2 | 4419 | create_fork_event_catchpoint (int tempflag, char *cond_string) |
c906108c SS |
4420 | { |
4421 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork); | |
4422 | } | |
c5aa993b | 4423 | |
c906108c | 4424 | void |
fba45db2 | 4425 | create_vfork_event_catchpoint (int tempflag, char *cond_string) |
c906108c SS |
4426 | { |
4427 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork); | |
4428 | } | |
4429 | ||
4430 | void | |
fba45db2 | 4431 | create_exec_event_catchpoint (int tempflag, char *cond_string) |
c906108c | 4432 | { |
c5aa993b JM |
4433 | struct symtab_and_line sal; |
4434 | struct breakpoint *b; | |
4435 | int thread = -1; /* All threads. */ | |
c906108c | 4436 | |
fe39c653 | 4437 | init_sal (&sal); |
c906108c SS |
4438 | sal.pc = 0; |
4439 | sal.symtab = NULL; | |
4440 | sal.line = 0; | |
4441 | ||
4d28f7a8 | 4442 | b = set_raw_breakpoint (sal, bp_catch_exec); |
c906108c SS |
4443 | set_breakpoint_count (breakpoint_count + 1); |
4444 | b->number = breakpoint_count; | |
4445 | b->cond = NULL; | |
53a5351d JM |
4446 | b->cond_string = (cond_string == NULL) ? |
4447 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
4448 | b->thread = thread; |
4449 | b->addr_string = NULL; | |
b5de0fa7 EZ |
4450 | b->enable_state = bp_enabled; |
4451 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c | 4452 | |
c906108c SS |
4453 | mention (b); |
4454 | } | |
4455 | ||
4456 | static int | |
fba45db2 | 4457 | hw_breakpoint_used_count (void) |
c906108c | 4458 | { |
52f0bd74 | 4459 | struct breakpoint *b; |
c906108c SS |
4460 | int i = 0; |
4461 | ||
4462 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4463 | { |
b5de0fa7 | 4464 | if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled) |
c5aa993b JM |
4465 | i++; |
4466 | } | |
c906108c SS |
4467 | |
4468 | return i; | |
4469 | } | |
4470 | ||
4471 | static int | |
fba45db2 | 4472 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 4473 | { |
52f0bd74 | 4474 | struct breakpoint *b; |
c906108c SS |
4475 | int i = 0; |
4476 | ||
4477 | *other_type_used = 0; | |
4478 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4479 | { |
b5de0fa7 | 4480 | if (b->enable_state == bp_enabled) |
c5aa993b JM |
4481 | { |
4482 | if (b->type == type) | |
4483 | i++; | |
4484 | else if ((b->type == bp_hardware_watchpoint || | |
4485 | b->type == bp_read_watchpoint || | |
4486 | b->type == bp_access_watchpoint) | |
b5de0fa7 | 4487 | && b->enable_state == bp_enabled) |
c5aa993b JM |
4488 | *other_type_used = 1; |
4489 | } | |
4490 | } | |
c906108c SS |
4491 | return i; |
4492 | } | |
4493 | ||
53a5351d JM |
4494 | /* Call this after hitting the longjmp() breakpoint. Use this to set |
4495 | a new breakpoint at the target of the jmp_buf. | |
c906108c | 4496 | |
53a5351d JM |
4497 | FIXME - This ought to be done by setting a temporary breakpoint |
4498 | that gets deleted automatically... */ | |
c906108c SS |
4499 | |
4500 | void | |
818dd999 | 4501 | set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id) |
c906108c | 4502 | { |
52f0bd74 | 4503 | struct breakpoint *b; |
c906108c SS |
4504 | |
4505 | ALL_BREAKPOINTS (b) | |
4506 | if (b->type == bp_longjmp_resume) | |
c5aa993b | 4507 | { |
5cab636d DJ |
4508 | b->loc->requested_address = pc; |
4509 | b->loc->address = adjust_breakpoint_address (b->loc->requested_address); | |
b5de0fa7 | 4510 | b->enable_state = bp_enabled; |
818dd999 | 4511 | b->frame_id = frame_id; |
9f60f21b | 4512 | check_duplicates (b); |
c5aa993b JM |
4513 | return; |
4514 | } | |
c906108c SS |
4515 | } |
4516 | ||
4517 | void | |
fba45db2 | 4518 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 4519 | { |
c5aa993b | 4520 | struct breakpoint *b; |
c906108c SS |
4521 | |
4522 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4523 | { |
4524 | if (((b->type == bp_watchpoint) | |
4525 | || (b->type == bp_hardware_watchpoint) | |
4526 | || (b->type == bp_read_watchpoint) | |
4527 | || (b->type == bp_access_watchpoint) | |
4528 | || ep_is_exception_catchpoint (b)) | |
b5de0fa7 | 4529 | && (b->enable_state == bp_enabled)) |
c5aa993b | 4530 | { |
b5de0fa7 | 4531 | b->enable_state = bp_call_disabled; |
9f60f21b | 4532 | check_duplicates (b); |
c5aa993b JM |
4533 | } |
4534 | } | |
c906108c SS |
4535 | } |
4536 | ||
4537 | void | |
fba45db2 | 4538 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 4539 | { |
c5aa993b | 4540 | struct breakpoint *b; |
c906108c SS |
4541 | |
4542 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4543 | { |
4544 | if (((b->type == bp_watchpoint) | |
4545 | || (b->type == bp_hardware_watchpoint) | |
4546 | || (b->type == bp_read_watchpoint) | |
4547 | || (b->type == bp_access_watchpoint) | |
4548 | || ep_is_exception_catchpoint (b)) | |
b5de0fa7 | 4549 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 4550 | { |
b5de0fa7 | 4551 | b->enable_state = bp_enabled; |
9f60f21b | 4552 | check_duplicates (b); |
c5aa993b JM |
4553 | } |
4554 | } | |
c906108c SS |
4555 | } |
4556 | ||
4557 | ||
4558 | /* Set a breakpoint that will evaporate an end of command | |
4559 | at address specified by SAL. | |
4560 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
4561 | ||
4562 | struct breakpoint * | |
818dd999 | 4563 | set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id, |
fba45db2 | 4564 | enum bptype type) |
c906108c | 4565 | { |
52f0bd74 | 4566 | struct breakpoint *b; |
4d28f7a8 | 4567 | b = set_raw_breakpoint (sal, type); |
b5de0fa7 EZ |
4568 | b->enable_state = bp_enabled; |
4569 | b->disposition = disp_donttouch; | |
818dd999 | 4570 | b->frame_id = frame_id; |
c906108c SS |
4571 | |
4572 | /* If we're debugging a multi-threaded program, then we | |
4573 | want momentary breakpoints to be active in only a | |
4574 | single thread of control. */ | |
39f77062 KB |
4575 | if (in_thread_list (inferior_ptid)) |
4576 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
4577 | |
4578 | return b; | |
4579 | } | |
c906108c | 4580 | \f |
c5aa993b | 4581 | |
c906108c SS |
4582 | /* Tell the user we have just set a breakpoint B. */ |
4583 | ||
4584 | static void | |
fba45db2 | 4585 | mention (struct breakpoint *b) |
c906108c SS |
4586 | { |
4587 | int say_where = 0; | |
3b31d625 | 4588 | struct cleanup *old_chain, *ui_out_chain; |
8b93c638 JM |
4589 | struct ui_stream *stb; |
4590 | ||
4591 | stb = ui_out_stream_new (uiout); | |
b02eeafb | 4592 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
c906108c SS |
4593 | |
4594 | /* FIXME: This is misplaced; mention() is called by things (like hitting a | |
4595 | watchpoint) other than breakpoint creation. It should be possible to | |
4596 | clean this up and at the same time replace the random calls to | |
4597 | breakpoint_changed with this hook, as has already been done for | |
4598 | delete_breakpoint_hook and so on. */ | |
4599 | if (create_breakpoint_hook) | |
4600 | create_breakpoint_hook (b); | |
104c1213 | 4601 | breakpoint_create_event (b->number); |
c906108c | 4602 | |
3086aeae DJ |
4603 | if (b->ops != NULL && b->ops->print_mention != NULL) |
4604 | b->ops->print_mention (b); | |
4605 | else | |
4606 | switch (b->type) | |
4607 | { | |
4608 | case bp_none: | |
4609 | printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number); | |
4610 | break; | |
4611 | case bp_watchpoint: | |
4612 | ui_out_text (uiout, "Watchpoint "); | |
4613 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4614 | ui_out_field_int (uiout, "number", b->number); | |
4615 | ui_out_text (uiout, ": "); | |
4616 | print_expression (b->exp, stb->stream); | |
4617 | ui_out_field_stream (uiout, "exp", stb); | |
4618 | do_cleanups (ui_out_chain); | |
4619 | break; | |
4620 | case bp_hardware_watchpoint: | |
4621 | ui_out_text (uiout, "Hardware watchpoint "); | |
4622 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4623 | ui_out_field_int (uiout, "number", b->number); | |
4624 | ui_out_text (uiout, ": "); | |
4625 | print_expression (b->exp, stb->stream); | |
4626 | ui_out_field_stream (uiout, "exp", stb); | |
4627 | do_cleanups (ui_out_chain); | |
4628 | break; | |
4629 | case bp_read_watchpoint: | |
4630 | ui_out_text (uiout, "Hardware read watchpoint "); | |
4631 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
4632 | ui_out_field_int (uiout, "number", b->number); | |
4633 | ui_out_text (uiout, ": "); | |
4634 | print_expression (b->exp, stb->stream); | |
4635 | ui_out_field_stream (uiout, "exp", stb); | |
4636 | do_cleanups (ui_out_chain); | |
4637 | break; | |
4638 | case bp_access_watchpoint: | |
4639 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
4640 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
4641 | ui_out_field_int (uiout, "number", b->number); | |
4642 | ui_out_text (uiout, ": "); | |
4643 | print_expression (b->exp, stb->stream); | |
4644 | ui_out_field_stream (uiout, "exp", stb); | |
4645 | do_cleanups (ui_out_chain); | |
4646 | break; | |
4647 | case bp_breakpoint: | |
4648 | if (ui_out_is_mi_like_p (uiout)) | |
4649 | { | |
4650 | say_where = 0; | |
4651 | break; | |
4652 | } | |
4653 | printf_filtered ("Breakpoint %d", b->number); | |
4654 | say_where = 1; | |
4655 | break; | |
4656 | case bp_hardware_breakpoint: | |
4657 | if (ui_out_is_mi_like_p (uiout)) | |
4658 | { | |
4659 | say_where = 0; | |
4660 | break; | |
4661 | } | |
4662 | printf_filtered ("Hardware assisted breakpoint %d", b->number); | |
4663 | say_where = 1; | |
4664 | break; | |
4665 | case bp_catch_load: | |
4666 | case bp_catch_unload: | |
4667 | printf_filtered ("Catchpoint %d (%s %s)", | |
4668 | b->number, | |
4669 | (b->type == bp_catch_load) ? "load" : "unload", | |
4670 | (b->dll_pathname != NULL) ? | |
4671 | b->dll_pathname : "<any library>"); | |
4672 | break; | |
4673 | case bp_catch_fork: | |
4674 | case bp_catch_vfork: | |
4675 | printf_filtered ("Catchpoint %d (%s)", | |
4676 | b->number, | |
4677 | (b->type == bp_catch_fork) ? "fork" : "vfork"); | |
4678 | break; | |
4679 | case bp_catch_exec: | |
4680 | printf_filtered ("Catchpoint %d (exec)", | |
4681 | b->number); | |
4682 | break; | |
4683 | case bp_catch_catch: | |
4684 | case bp_catch_throw: | |
4685 | printf_filtered ("Catchpoint %d (%s)", | |
4686 | b->number, | |
4687 | (b->type == bp_catch_catch) ? "catch" : "throw"); | |
4688 | break; | |
4689 | ||
4690 | case bp_until: | |
4691 | case bp_finish: | |
4692 | case bp_longjmp: | |
4693 | case bp_longjmp_resume: | |
4694 | case bp_step_resume: | |
4695 | case bp_through_sigtramp: | |
4696 | case bp_call_dummy: | |
4697 | case bp_watchpoint_scope: | |
4698 | case bp_shlib_event: | |
4699 | case bp_thread_event: | |
4700 | case bp_overlay_event: | |
4701 | break; | |
4702 | } | |
c906108c | 4703 | |
c906108c SS |
4704 | if (say_where) |
4705 | { | |
4706 | if (addressprint || b->source_file == NULL) | |
4707 | { | |
4708 | printf_filtered (" at "); | |
5cab636d | 4709 | print_address_numeric (b->loc->address, 1, gdb_stdout); |
c906108c SS |
4710 | } |
4711 | if (b->source_file) | |
4712 | printf_filtered (": file %s, line %d.", | |
4713 | b->source_file, b->line_number); | |
c906108c | 4714 | } |
8b93c638 | 4715 | do_cleanups (old_chain); |
9dc5e2a9 | 4716 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 4717 | return; |
c906108c SS |
4718 | printf_filtered ("\n"); |
4719 | } | |
c906108c | 4720 | \f |
c5aa993b | 4721 | |
c3f6f71d JM |
4722 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
4723 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i], | |
4724 | COND[i] and COND_STRING[i] values. | |
4725 | ||
4726 | NOTE: If the function succeeds, the caller is expected to cleanup | |
4727 | the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the | |
4728 | array contents). If the function fails (error() is called), the | |
4729 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4730 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
4731 | |
4732 | static void | |
c3f6f71d JM |
4733 | create_breakpoints (struct symtabs_and_lines sals, char **addr_string, |
4734 | struct expression **cond, char **cond_string, | |
4735 | enum bptype type, enum bpdisp disposition, | |
4736 | int thread, int ignore_count, int from_tty) | |
c906108c | 4737 | { |
c3f6f71d JM |
4738 | if (type == bp_hardware_breakpoint) |
4739 | { | |
4740 | int i = hw_breakpoint_used_count (); | |
4741 | int target_resources_ok = | |
4742 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
4743 | i + sals.nelts, 0); | |
4744 | if (target_resources_ok == 0) | |
4745 | error ("No hardware breakpoint support in the target."); | |
4746 | else if (target_resources_ok < 0) | |
4747 | error ("Hardware breakpoints used exceeds limit."); | |
4748 | } | |
c906108c | 4749 | |
c3f6f71d JM |
4750 | /* Now set all the breakpoints. */ |
4751 | { | |
4752 | int i; | |
4753 | for (i = 0; i < sals.nelts; i++) | |
4754 | { | |
4755 | struct breakpoint *b; | |
4756 | struct symtab_and_line sal = sals.sals[i]; | |
c906108c | 4757 | |
c3f6f71d JM |
4758 | if (from_tty) |
4759 | describe_other_breakpoints (sal.pc, sal.section); | |
4760 | ||
4d28f7a8 | 4761 | b = set_raw_breakpoint (sal, type); |
c3f6f71d JM |
4762 | set_breakpoint_count (breakpoint_count + 1); |
4763 | b->number = breakpoint_count; | |
c3f6f71d JM |
4764 | b->cond = cond[i]; |
4765 | b->thread = thread; | |
d8ef46f5 DJ |
4766 | if (addr_string[i]) |
4767 | b->addr_string = addr_string[i]; | |
4768 | else | |
4769 | /* addr_string has to be used or breakpoint_re_set will delete | |
4770 | me. */ | |
5cab636d | 4771 | xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address)); |
c3f6f71d JM |
4772 | b->cond_string = cond_string[i]; |
4773 | b->ignore_count = ignore_count; | |
b5de0fa7 | 4774 | b->enable_state = bp_enabled; |
c3f6f71d JM |
4775 | b->disposition = disposition; |
4776 | mention (b); | |
4777 | } | |
4778 | } | |
4779 | } | |
c906108c | 4780 | |
c3f6f71d JM |
4781 | /* Parse ARG which is assumed to be a SAL specification possibly |
4782 | followed by conditionals. On return, SALS contains an array of SAL | |
4783 | addresses found. ADDR_STRING contains a vector of (canonical) | |
4784 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 4785 | |
b9362cc7 | 4786 | static void |
c3f6f71d JM |
4787 | parse_breakpoint_sals (char **address, |
4788 | struct symtabs_and_lines *sals, | |
4789 | char ***addr_string) | |
4790 | { | |
4791 | char *addr_start = *address; | |
4792 | *addr_string = NULL; | |
4793 | /* If no arg given, or if first arg is 'if ', use the default | |
4794 | breakpoint. */ | |
4795 | if ((*address) == NULL | |
4796 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
4797 | { |
4798 | if (default_breakpoint_valid) | |
4799 | { | |
c3f6f71d | 4800 | struct symtab_and_line sal; |
fe39c653 | 4801 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 4802 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
4803 | xmalloc (sizeof (struct symtab_and_line)); |
4804 | sal.pc = default_breakpoint_address; | |
4805 | sal.line = default_breakpoint_line; | |
4806 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 4807 | sal.section = find_pc_overlay (sal.pc); |
c3f6f71d JM |
4808 | sals->sals[0] = sal; |
4809 | sals->nelts = 1; | |
c906108c SS |
4810 | } |
4811 | else | |
4812 | error ("No default breakpoint address now."); | |
4813 | } | |
4814 | else | |
4815 | { | |
c906108c | 4816 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
4817 | current_source_symtab (which is decode_line_1's default). This |
4818 | should produce the results we want almost all of the time while | |
1aeae86e AF |
4819 | leaving default_breakpoint_* alone. |
4820 | ObjC: However, don't match an Objective-C method name which | |
4821 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 4822 | |
c214a6fd | 4823 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 4824 | |
c906108c | 4825 | if (default_breakpoint_valid |
0378c332 | 4826 | && (!cursal.symtab |
1aeae86e AF |
4827 | || ((strchr ("+-", (*address)[0]) != NULL) |
4828 | && ((*address)[1] != '[')))) | |
c3f6f71d JM |
4829 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
4830 | default_breakpoint_line, addr_string); | |
c906108c | 4831 | else |
389e51db | 4832 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string); |
c906108c | 4833 | } |
c3f6f71d JM |
4834 | /* For any SAL that didn't have a canonical string, fill one in. */ |
4835 | if (sals->nelts > 0 && *addr_string == NULL) | |
4836 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
4837 | if (addr_start != (*address)) | |
c906108c | 4838 | { |
c3f6f71d JM |
4839 | int i; |
4840 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 4841 | { |
c3f6f71d JM |
4842 | /* Add the string if not present. */ |
4843 | if ((*addr_string)[i] == NULL) | |
4844 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
4845 | } |
4846 | } | |
c3f6f71d | 4847 | } |
c906108c | 4848 | |
c906108c | 4849 | |
c3f6f71d JM |
4850 | /* Convert each SAL into a real PC. Verify that the PC can be |
4851 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 4852 | |
b9362cc7 | 4853 | static void |
c3f6f71d JM |
4854 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
4855 | char *address) | |
4856 | { | |
4857 | int i; | |
4858 | for (i = 0; i < sals->nelts; i++) | |
4859 | { | |
4860 | resolve_sal_pc (&sals->sals[i]); | |
c906108c SS |
4861 | |
4862 | /* It's possible for the PC to be nonzero, but still an illegal | |
4863 | value on some targets. | |
4864 | ||
4865 | For example, on HP-UX if you start gdb, and before running the | |
4866 | inferior you try to set a breakpoint on a shared library function | |
4867 | "foo" where the inferior doesn't call "foo" directly but does | |
4868 | pass its address to another function call, then we do find a | |
4869 | minimal symbol for the "foo", but it's address is invalid. | |
4870 | (Appears to be an index into a table that the loader sets up | |
4871 | when the inferior is run.) | |
4872 | ||
4873 | Give the target a chance to bless sals.sals[i].pc before we | |
4874 | try to make a breakpoint for it. */ | |
c3f6f71d | 4875 | if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc)) |
c5aa993b | 4876 | { |
c3f6f71d JM |
4877 | if (address == NULL) |
4878 | error ("Cannot break without a running program."); | |
4879 | else | |
4880 | error ("Cannot break on %s without a running program.", | |
4881 | address); | |
c5aa993b | 4882 | } |
c3f6f71d JM |
4883 | } |
4884 | } | |
4885 | ||
4886 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
4887 | flag: first bit : 0 non-temporary, 1 temporary. | |
4888 | second bit : 0 normal breakpoint, 1 hardware breakpoint. */ | |
c5aa993b | 4889 | |
c3f6f71d | 4890 | static void |
fba45db2 | 4891 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d JM |
4892 | { |
4893 | int tempflag, hardwareflag; | |
4894 | struct symtabs_and_lines sals; | |
52f0bd74 | 4895 | struct expression **cond = 0; |
c3f6f71d JM |
4896 | /* Pointers in arg to the start, and one past the end, of the |
4897 | condition. */ | |
4898 | char **cond_string = (char **) NULL; | |
4899 | char *addr_start = arg; | |
4900 | char **addr_string; | |
4901 | struct cleanup *old_chain; | |
4902 | struct cleanup *breakpoint_chain = NULL; | |
4903 | int i; | |
4904 | int thread = -1; | |
4905 | int ignore_count = 0; | |
4906 | ||
4907 | hardwareflag = flag & BP_HARDWAREFLAG; | |
4908 | tempflag = flag & BP_TEMPFLAG; | |
c906108c | 4909 | |
c3f6f71d JM |
4910 | sals.sals = NULL; |
4911 | sals.nelts = 0; | |
4912 | addr_string = NULL; | |
4913 | parse_breakpoint_sals (&arg, &sals, &addr_string); | |
4914 | ||
4915 | if (!sals.nelts) | |
4916 | return; | |
4917 | ||
4918 | /* Create a chain of things that always need to be cleaned up. */ | |
4919 | old_chain = make_cleanup (null_cleanup, 0); | |
4920 | ||
4921 | /* Make sure that all storage allocated to SALS gets freed. */ | |
b8c9b27d | 4922 | make_cleanup (xfree, sals.sals); |
c3f6f71d JM |
4923 | |
4924 | /* Cleanup the addr_string array but not its contents. */ | |
b8c9b27d | 4925 | make_cleanup (xfree, addr_string); |
c3f6f71d JM |
4926 | |
4927 | /* Allocate space for all the cond expressions. */ | |
4928 | cond = xcalloc (sals.nelts, sizeof (struct expression *)); | |
b8c9b27d | 4929 | make_cleanup (xfree, cond); |
c3f6f71d JM |
4930 | |
4931 | /* Allocate space for all the cond strings. */ | |
4932 | cond_string = xcalloc (sals.nelts, sizeof (char **)); | |
b8c9b27d | 4933 | make_cleanup (xfree, cond_string); |
c3f6f71d JM |
4934 | |
4935 | /* ----------------------------- SNIP ----------------------------- | |
4936 | Anything added to the cleanup chain beyond this point is assumed | |
4937 | to be part of a breakpoint. If the breakpoint create succeeds | |
4938 | then the memory is not reclaimed. */ | |
4939 | breakpoint_chain = make_cleanup (null_cleanup, 0); | |
4940 | ||
4941 | /* Mark the contents of the addr_string for cleanup. These go on | |
4942 | the breakpoint_chain and only occure if the breakpoint create | |
4943 | fails. */ | |
4944 | for (i = 0; i < sals.nelts; i++) | |
4945 | { | |
4946 | if (addr_string[i] != NULL) | |
b8c9b27d | 4947 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
4948 | } |
4949 | ||
4950 | /* Resolve all line numbers to PC's and verify that the addresses | |
4951 | are ok for the target. */ | |
4952 | breakpoint_sals_to_pc (&sals, addr_start); | |
4953 | ||
4954 | /* Verify that condition can be parsed, before setting any | |
4955 | breakpoints. Allocate a separate condition expression for each | |
4956 | breakpoint. */ | |
4957 | thread = -1; /* No specific thread yet */ | |
4958 | for (i = 0; i < sals.nelts; i++) | |
4959 | { | |
4960 | char *tok = arg; | |
c906108c SS |
4961 | while (tok && *tok) |
4962 | { | |
c3f6f71d JM |
4963 | char *end_tok; |
4964 | int toklen; | |
4965 | char *cond_start = NULL; | |
4966 | char *cond_end = NULL; | |
c906108c SS |
4967 | while (*tok == ' ' || *tok == '\t') |
4968 | tok++; | |
4969 | ||
4970 | end_tok = tok; | |
4971 | ||
4972 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
4973 | end_tok++; | |
4974 | ||
4975 | toklen = end_tok - tok; | |
4976 | ||
4977 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
4978 | { | |
4979 | tok = cond_start = end_tok + 1; | |
c3f6f71d | 4980 | cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); |
b8c9b27d | 4981 | make_cleanup (xfree, cond[i]); |
c906108c | 4982 | cond_end = tok; |
c3f6f71d | 4983 | cond_string[i] = savestring (cond_start, cond_end - cond_start); |
b8c9b27d | 4984 | make_cleanup (xfree, cond_string[i]); |
c906108c SS |
4985 | } |
4986 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
4987 | { | |
4988 | char *tmptok; | |
4989 | ||
4990 | tok = end_tok + 1; | |
4991 | tmptok = tok; | |
4992 | thread = strtol (tok, &tok, 0); | |
4993 | if (tok == tmptok) | |
4994 | error ("Junk after thread keyword."); | |
4995 | if (!valid_thread_id (thread)) | |
4996 | error ("Unknown thread %d\n", thread); | |
4997 | } | |
4998 | else | |
4999 | error ("Junk at end of arguments."); | |
5000 | } | |
5001 | } | |
c906108c | 5002 | |
c3f6f71d JM |
5003 | create_breakpoints (sals, addr_string, cond, cond_string, |
5004 | hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, | |
b5de0fa7 | 5005 | tempflag ? disp_del : disp_donttouch, |
c3f6f71d JM |
5006 | thread, ignore_count, from_tty); |
5007 | ||
5008 | if (sals.nelts > 1) | |
5009 | { | |
5010 | warning ("Multiple breakpoints were set."); | |
5011 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 5012 | } |
c3f6f71d JM |
5013 | /* That's it. Discard the cleanups for data inserted into the |
5014 | breakpoint. */ | |
5015 | discard_cleanups (breakpoint_chain); | |
5016 | /* But cleanup everything else. */ | |
5017 | do_cleanups (old_chain); | |
5018 | } | |
c906108c | 5019 | |
c3f6f71d JM |
5020 | /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function, |
5021 | linenum or *address) with COND and IGNORE_COUNT. */ | |
c906108c | 5022 | |
c3f6f71d JM |
5023 | struct captured_breakpoint_args |
5024 | { | |
5025 | char *address; | |
5026 | char *condition; | |
5027 | int hardwareflag; | |
5028 | int tempflag; | |
5029 | int thread; | |
5030 | int ignore_count; | |
5031 | }; | |
5032 | ||
5033 | static int | |
5034 | do_captured_breakpoint (void *data) | |
5035 | { | |
5036 | struct captured_breakpoint_args *args = data; | |
5037 | struct symtabs_and_lines sals; | |
52f0bd74 | 5038 | struct expression **cond; |
c3f6f71d JM |
5039 | struct cleanup *old_chain; |
5040 | struct cleanup *breakpoint_chain = NULL; | |
5041 | int i; | |
5042 | char **addr_string; | |
5043 | char **cond_string; | |
5044 | ||
5045 | char *address_end; | |
5046 | ||
5047 | /* Parse the source and lines spec. Delay check that the expression | |
5048 | didn't contain trailing garbage until after cleanups are in | |
5049 | place. */ | |
5050 | sals.sals = NULL; | |
5051 | sals.nelts = 0; | |
5052 | address_end = args->address; | |
5053 | addr_string = NULL; | |
5054 | parse_breakpoint_sals (&address_end, &sals, &addr_string); | |
5055 | ||
5056 | if (!sals.nelts) | |
5057 | return GDB_RC_NONE; | |
5058 | ||
5059 | /* Create a chain of things at always need to be cleaned up. */ | |
5060 | old_chain = make_cleanup (null_cleanup, 0); | |
5061 | ||
5062 | /* Always have a addr_string array, even if it is empty. */ | |
b8c9b27d | 5063 | make_cleanup (xfree, addr_string); |
c3f6f71d JM |
5064 | |
5065 | /* Make sure that all storage allocated to SALS gets freed. */ | |
b8c9b27d | 5066 | make_cleanup (xfree, sals.sals); |
c3f6f71d JM |
5067 | |
5068 | /* Allocate space for all the cond expressions. */ | |
5069 | cond = xcalloc (sals.nelts, sizeof (struct expression *)); | |
b8c9b27d | 5070 | make_cleanup (xfree, cond); |
c3f6f71d JM |
5071 | |
5072 | /* Allocate space for all the cond strings. */ | |
5073 | cond_string = xcalloc (sals.nelts, sizeof (char **)); | |
b8c9b27d | 5074 | make_cleanup (xfree, cond_string); |
c3f6f71d JM |
5075 | |
5076 | /* ----------------------------- SNIP ----------------------------- | |
5077 | Anything added to the cleanup chain beyond this point is assumed | |
5078 | to be part of a breakpoint. If the breakpoint create goes | |
5079 | through then that memory is not cleaned up. */ | |
5080 | breakpoint_chain = make_cleanup (null_cleanup, 0); | |
5081 | ||
5082 | /* Mark the contents of the addr_string for cleanup. These go on | |
5083 | the breakpoint_chain and only occure if the breakpoint create | |
5084 | fails. */ | |
c906108c SS |
5085 | for (i = 0; i < sals.nelts; i++) |
5086 | { | |
c3f6f71d | 5087 | if (addr_string[i] != NULL) |
b8c9b27d | 5088 | make_cleanup (xfree, addr_string[i]); |
c906108c SS |
5089 | } |
5090 | ||
c3f6f71d JM |
5091 | /* Wait until now before checking for garbage at the end of the |
5092 | address. That way cleanups can take care of freeing any | |
5093 | memory. */ | |
5094 | if (*address_end != '\0') | |
5095 | error ("Garbage %s following breakpoint address", address_end); | |
5096 | ||
5097 | /* Resolve all line numbers to PC's. */ | |
5098 | breakpoint_sals_to_pc (&sals, args->address); | |
5099 | ||
5100 | /* Verify that conditions can be parsed, before setting any | |
5101 | breakpoints. */ | |
5102 | for (i = 0; i < sals.nelts; i++) | |
c906108c | 5103 | { |
c3f6f71d JM |
5104 | if (args->condition != NULL) |
5105 | { | |
5106 | char *tok = args->condition; | |
5107 | cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); | |
5108 | if (*tok != '\0') | |
5109 | error ("Garbage %s follows condition", tok); | |
b8c9b27d | 5110 | make_cleanup (xfree, cond[i]); |
c3f6f71d JM |
5111 | cond_string[i] = xstrdup (args->condition); |
5112 | } | |
c906108c | 5113 | } |
c3f6f71d JM |
5114 | |
5115 | create_breakpoints (sals, addr_string, cond, cond_string, | |
5116 | args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, | |
b5de0fa7 | 5117 | args->tempflag ? disp_del : disp_donttouch, |
c3f6f71d JM |
5118 | args->thread, args->ignore_count, 0/*from-tty*/); |
5119 | ||
5120 | /* That's it. Discard the cleanups for data inserted into the | |
5121 | breakpoint. */ | |
5122 | discard_cleanups (breakpoint_chain); | |
5123 | /* But cleanup everything else. */ | |
c906108c | 5124 | do_cleanups (old_chain); |
c3f6f71d | 5125 | return GDB_RC_OK; |
c906108c SS |
5126 | } |
5127 | ||
c3f6f71d JM |
5128 | enum gdb_rc |
5129 | gdb_breakpoint (char *address, char *condition, | |
5130 | int hardwareflag, int tempflag, | |
5131 | int thread, int ignore_count) | |
5132 | { | |
5133 | struct captured_breakpoint_args args; | |
5134 | args.address = address; | |
5135 | args.condition = condition; | |
5136 | args.hardwareflag = hardwareflag; | |
5137 | args.tempflag = tempflag; | |
5138 | args.thread = thread; | |
5139 | args.ignore_count = ignore_count; | |
5140 | return catch_errors (do_captured_breakpoint, &args, | |
5141 | NULL, RETURN_MASK_ALL); | |
5142 | } | |
5143 | ||
5144 | ||
c906108c | 5145 | static void |
fba45db2 | 5146 | break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty) |
c906108c SS |
5147 | { |
5148 | struct frame_info *frame; | |
5149 | CORE_ADDR low, high, selected_pc = 0; | |
7f7e9482 AC |
5150 | char *extra_args = NULL; |
5151 | char *level_arg; | |
c906108c SS |
5152 | int extra_args_len = 0, if_arg = 0; |
5153 | ||
5154 | if (!arg || | |
5155 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
5156 | { | |
5157 | ||
5158 | if (default_breakpoint_valid) | |
5159 | { | |
6e7f8b9c | 5160 | if (deprecated_selected_frame) |
c906108c | 5161 | { |
bdd78e62 | 5162 | selected_pc = get_frame_pc (deprecated_selected_frame); |
c906108c SS |
5163 | if (arg) |
5164 | if_arg = 1; | |
5165 | } | |
5166 | else | |
5167 | error ("No selected frame."); | |
5168 | } | |
5169 | else | |
5170 | error ("No default breakpoint address now."); | |
5171 | } | |
5172 | else | |
5173 | { | |
5174 | extra_args = strchr (arg, ' '); | |
5175 | if (extra_args) | |
5176 | { | |
5177 | extra_args++; | |
5178 | extra_args_len = strlen (extra_args); | |
5179 | level_arg = (char *) xmalloc (extra_args - arg); | |
5180 | strncpy (level_arg, arg, extra_args - arg - 1); | |
5181 | level_arg[extra_args - arg - 1] = '\0'; | |
5182 | } | |
5183 | else | |
5184 | { | |
5185 | level_arg = (char *) xmalloc (strlen (arg) + 1); | |
5186 | strcpy (level_arg, arg); | |
5187 | } | |
5188 | ||
5189 | frame = parse_frame_specification (level_arg); | |
5190 | if (frame) | |
bdd78e62 | 5191 | selected_pc = get_frame_pc (frame); |
c906108c SS |
5192 | else |
5193 | selected_pc = 0; | |
5194 | } | |
5195 | if (if_arg) | |
5196 | { | |
5197 | extra_args = arg; | |
c5aa993b | 5198 | extra_args_len = strlen (arg); |
c906108c SS |
5199 | } |
5200 | ||
5201 | if (selected_pc) | |
5202 | { | |
c5aa993b | 5203 | if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high)) |
c906108c | 5204 | { |
9ebf4acf | 5205 | char *addr_string; |
c906108c | 5206 | if (extra_args_len) |
9ebf4acf | 5207 | addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args); |
c906108c | 5208 | else |
9ebf4acf | 5209 | addr_string = xstrprintf ("*0x%s", paddr_nz (high)); |
c906108c | 5210 | break_command_1 (addr_string, flag, from_tty); |
b8c9b27d | 5211 | xfree (addr_string); |
c906108c SS |
5212 | } |
5213 | else | |
5214 | error ("No function contains the specified address"); | |
5215 | } | |
5216 | else | |
5217 | error ("Unable to set breakpoint at procedure exit"); | |
5218 | } | |
5219 | ||
5220 | ||
5221 | static void | |
fba45db2 | 5222 | break_at_finish_command_1 (char *arg, int flag, int from_tty) |
c906108c SS |
5223 | { |
5224 | char *addr_string, *break_string, *beg_addr_string; | |
5225 | CORE_ADDR low, high; | |
5226 | struct symtabs_and_lines sals; | |
5227 | struct symtab_and_line sal; | |
5228 | struct cleanup *old_chain; | |
7f7e9482 | 5229 | char *extra_args = NULL; |
c906108c SS |
5230 | int extra_args_len = 0; |
5231 | int i, if_arg = 0; | |
5232 | ||
5233 | if (!arg || | |
5234 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
5235 | { | |
5236 | if (default_breakpoint_valid) | |
5237 | { | |
6e7f8b9c | 5238 | if (deprecated_selected_frame) |
c906108c | 5239 | { |
9ebf4acf AC |
5240 | addr_string = xstrprintf ("*0x%s", |
5241 | paddr_nz (get_frame_pc (deprecated_selected_frame))); | |
c906108c SS |
5242 | if (arg) |
5243 | if_arg = 1; | |
5244 | } | |
5245 | else | |
5246 | error ("No selected frame."); | |
5247 | } | |
5248 | else | |
5249 | error ("No default breakpoint address now."); | |
5250 | } | |
5251 | else | |
5252 | { | |
5253 | addr_string = (char *) xmalloc (strlen (arg) + 1); | |
5254 | strcpy (addr_string, arg); | |
5255 | } | |
5256 | ||
5257 | if (if_arg) | |
5258 | { | |
5259 | extra_args = arg; | |
c5aa993b JM |
5260 | extra_args_len = strlen (arg); |
5261 | } | |
5262 | else if (arg) | |
5263 | { | |
5264 | /* get the stuff after the function name or address */ | |
5265 | extra_args = strchr (arg, ' '); | |
5266 | if (extra_args) | |
5267 | { | |
5268 | extra_args++; | |
5269 | extra_args_len = strlen (extra_args); | |
5270 | } | |
c906108c | 5271 | } |
c906108c SS |
5272 | |
5273 | sals.sals = NULL; | |
5274 | sals.nelts = 0; | |
5275 | ||
c5aa993b JM |
5276 | beg_addr_string = addr_string; |
5277 | sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0, | |
5278 | (char ***) NULL); | |
c906108c | 5279 | |
b8c9b27d KB |
5280 | xfree (beg_addr_string); |
5281 | old_chain = make_cleanup (xfree, sals.sals); | |
c906108c SS |
5282 | for (i = 0; (i < sals.nelts); i++) |
5283 | { | |
5284 | sal = sals.sals[i]; | |
c5aa993b | 5285 | if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high)) |
c906108c | 5286 | { |
9ebf4acf | 5287 | break_string; |
c906108c | 5288 | if (extra_args_len) |
9ebf4acf AC |
5289 | break_string = xstrprintf ("*0x%s %s", paddr_nz (high), |
5290 | extra_args); | |
c906108c | 5291 | else |
9ebf4acf | 5292 | break_string = xstrprintf ("*0x%s", paddr_nz (high)); |
c906108c | 5293 | break_command_1 (break_string, flag, from_tty); |
b8c9b27d | 5294 | xfree (break_string); |
c906108c SS |
5295 | } |
5296 | else | |
5297 | error ("No function contains the specified address"); | |
5298 | } | |
5299 | if (sals.nelts > 1) | |
5300 | { | |
53a5351d JM |
5301 | warning ("Multiple breakpoints were set.\n"); |
5302 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 5303 | } |
c5aa993b | 5304 | do_cleanups (old_chain); |
c906108c SS |
5305 | } |
5306 | ||
5307 | ||
5308 | /* Helper function for break_command_1 and disassemble_command. */ | |
5309 | ||
5310 | void | |
fba45db2 | 5311 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
5312 | { |
5313 | CORE_ADDR pc; | |
5314 | ||
5315 | if (sal->pc == 0 && sal->symtab != NULL) | |
5316 | { | |
5317 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
5318 | error ("No line %d in file \"%s\".", | |
5319 | sal->line, sal->symtab->filename); | |
5320 | sal->pc = pc; | |
5321 | } | |
5322 | ||
5323 | if (sal->section == 0 && sal->symtab != NULL) | |
5324 | { | |
5325 | struct blockvector *bv; | |
c5aa993b JM |
5326 | struct block *b; |
5327 | struct symbol *sym; | |
5328 | int index; | |
c906108c | 5329 | |
c5aa993b | 5330 | bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab); |
c906108c SS |
5331 | if (bv != NULL) |
5332 | { | |
c5aa993b | 5333 | b = BLOCKVECTOR_BLOCK (bv, index); |
c906108c SS |
5334 | sym = block_function (b); |
5335 | if (sym != NULL) | |
5336 | { | |
5337 | fixup_symbol_section (sym, sal->symtab->objfile); | |
5338 | sal->section = SYMBOL_BFD_SECTION (sym); | |
5339 | } | |
5340 | else | |
5341 | { | |
5342 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
5343 | have to look harder. This case can be executed if we have |
5344 | line numbers but no functions (as can happen in assembly | |
5345 | source). */ | |
c906108c | 5346 | |
c5aa993b | 5347 | struct minimal_symbol *msym; |
c906108c SS |
5348 | |
5349 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
5350 | if (msym) | |
5351 | sal->section = SYMBOL_BFD_SECTION (msym); | |
5352 | } | |
5353 | } | |
5354 | } | |
5355 | } | |
5356 | ||
5357 | void | |
fba45db2 | 5358 | break_command (char *arg, int from_tty) |
c906108c SS |
5359 | { |
5360 | break_command_1 (arg, 0, from_tty); | |
5361 | } | |
5362 | ||
502fd408 | 5363 | void |
fba45db2 | 5364 | break_at_finish_command (char *arg, int from_tty) |
c906108c SS |
5365 | { |
5366 | break_at_finish_command_1 (arg, 0, from_tty); | |
5367 | } | |
5368 | ||
502fd408 | 5369 | void |
fba45db2 | 5370 | break_at_finish_at_depth_command (char *arg, int from_tty) |
c906108c SS |
5371 | { |
5372 | break_at_finish_at_depth_command_1 (arg, 0, from_tty); | |
5373 | } | |
5374 | ||
5375 | void | |
fba45db2 | 5376 | tbreak_command (char *arg, int from_tty) |
c906108c SS |
5377 | { |
5378 | break_command_1 (arg, BP_TEMPFLAG, from_tty); | |
5379 | } | |
5380 | ||
502fd408 | 5381 | void |
fba45db2 | 5382 | tbreak_at_finish_command (char *arg, int from_tty) |
c906108c SS |
5383 | { |
5384 | break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty); | |
5385 | } | |
5386 | ||
5387 | static void | |
fba45db2 | 5388 | hbreak_command (char *arg, int from_tty) |
c906108c SS |
5389 | { |
5390 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); | |
5391 | } | |
5392 | ||
5393 | static void | |
fba45db2 | 5394 | thbreak_command (char *arg, int from_tty) |
c906108c SS |
5395 | { |
5396 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); | |
5397 | } | |
5398 | ||
5399 | static void | |
fba45db2 | 5400 | stop_command (char *arg, int from_tty) |
c906108c SS |
5401 | { |
5402 | printf_filtered ("Specify the type of breakpoint to set.\n\ | |
5403 | Usage: stop in <function | address>\n\ | |
5404 | stop at <line>\n"); | |
5405 | } | |
5406 | ||
5407 | static void | |
fba45db2 | 5408 | stopin_command (char *arg, int from_tty) |
c906108c SS |
5409 | { |
5410 | int badInput = 0; | |
5411 | ||
c5aa993b | 5412 | if (arg == (char *) NULL) |
c906108c SS |
5413 | badInput = 1; |
5414 | else if (*arg != '*') | |
5415 | { | |
5416 | char *argptr = arg; | |
5417 | int hasColon = 0; | |
5418 | ||
53a5351d JM |
5419 | /* look for a ':'. If this is a line number specification, then |
5420 | say it is bad, otherwise, it should be an address or | |
5421 | function/method name */ | |
c906108c | 5422 | while (*argptr && !hasColon) |
c5aa993b JM |
5423 | { |
5424 | hasColon = (*argptr == ':'); | |
5425 | argptr++; | |
5426 | } | |
c906108c SS |
5427 | |
5428 | if (hasColon) | |
c5aa993b | 5429 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 5430 | else |
c5aa993b | 5431 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
5432 | } |
5433 | ||
5434 | if (badInput) | |
c5aa993b | 5435 | printf_filtered ("Usage: stop in <function | address>\n"); |
c906108c SS |
5436 | else |
5437 | break_command_1 (arg, 0, from_tty); | |
5438 | } | |
5439 | ||
5440 | static void | |
fba45db2 | 5441 | stopat_command (char *arg, int from_tty) |
c906108c SS |
5442 | { |
5443 | int badInput = 0; | |
5444 | ||
c5aa993b | 5445 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
5446 | badInput = 1; |
5447 | else | |
5448 | { | |
5449 | char *argptr = arg; | |
5450 | int hasColon = 0; | |
5451 | ||
5452 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 5453 | it is probably a line number. */ |
c906108c | 5454 | while (*argptr && !hasColon) |
c5aa993b JM |
5455 | { |
5456 | hasColon = (*argptr == ':'); | |
5457 | argptr++; | |
5458 | } | |
c906108c SS |
5459 | |
5460 | if (hasColon) | |
c5aa993b | 5461 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 5462 | else |
c5aa993b | 5463 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
5464 | } |
5465 | ||
5466 | if (badInput) | |
c5aa993b | 5467 | printf_filtered ("Usage: stop at <line>\n"); |
c906108c SS |
5468 | else |
5469 | break_command_1 (arg, 0, from_tty); | |
5470 | } | |
5471 | ||
53a5351d JM |
5472 | /* accessflag: hw_write: watch write, |
5473 | hw_read: watch read, | |
5474 | hw_access: watch access (read or write) */ | |
c906108c | 5475 | static void |
fba45db2 | 5476 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c SS |
5477 | { |
5478 | struct breakpoint *b; | |
5479 | struct symtab_and_line sal; | |
5480 | struct expression *exp; | |
5481 | struct block *exp_valid_block; | |
5482 | struct value *val, *mark; | |
5483 | struct frame_info *frame; | |
5484 | struct frame_info *prev_frame = NULL; | |
5485 | char *exp_start = NULL; | |
5486 | char *exp_end = NULL; | |
5487 | char *tok, *end_tok; | |
5488 | int toklen; | |
5489 | char *cond_start = NULL; | |
5490 | char *cond_end = NULL; | |
5491 | struct expression *cond = NULL; | |
5492 | int i, other_type_used, target_resources_ok = 0; | |
5493 | enum bptype bp_type; | |
5494 | int mem_cnt = 0; | |
5495 | ||
fe39c653 | 5496 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 5497 | |
c906108c SS |
5498 | /* Parse arguments. */ |
5499 | innermost_block = NULL; | |
5500 | exp_start = arg; | |
5501 | exp = parse_exp_1 (&arg, 0, 0); | |
5502 | exp_end = arg; | |
5503 | exp_valid_block = innermost_block; | |
5504 | mark = value_mark (); | |
5505 | val = evaluate_expression (exp); | |
5506 | release_value (val); | |
5507 | if (VALUE_LAZY (val)) | |
5508 | value_fetch_lazy (val); | |
5509 | ||
5510 | tok = arg; | |
5511 | while (*tok == ' ' || *tok == '\t') | |
5512 | tok++; | |
5513 | end_tok = tok; | |
5514 | ||
5515 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5516 | end_tok++; | |
5517 | ||
5518 | toklen = end_tok - tok; | |
5519 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5520 | { | |
5521 | tok = cond_start = end_tok + 1; | |
5522 | cond = parse_exp_1 (&tok, 0, 0); | |
5523 | cond_end = tok; | |
5524 | } | |
5525 | if (*tok) | |
c5aa993b | 5526 | error ("Junk at end of command."); |
c906108c | 5527 | |
53a5351d | 5528 | if (accessflag == hw_read) |
c5aa993b | 5529 | bp_type = bp_read_watchpoint; |
53a5351d | 5530 | else if (accessflag == hw_access) |
c5aa993b JM |
5531 | bp_type = bp_access_watchpoint; |
5532 | else | |
5533 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
5534 | |
5535 | mem_cnt = can_use_hardware_watchpoint (val); | |
5536 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
5537 | error ("Expression cannot be implemented with read/access watchpoint."); | |
c5aa993b JM |
5538 | if (mem_cnt != 0) |
5539 | { | |
5540 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d JM |
5541 | target_resources_ok = |
5542 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, | |
5543 | other_type_used); | |
c5aa993b | 5544 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
53a5351d JM |
5545 | error ("Target does not support this type of hardware watchpoint."); |
5546 | ||
c5aa993b | 5547 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
53a5351d | 5548 | error ("Target can only support one kind of HW watchpoint at a time."); |
c5aa993b | 5549 | } |
c906108c SS |
5550 | |
5551 | #if defined(HPUXHPPA) | |
c5aa993b | 5552 | /* On HP-UX if you set a h/w |
c906108c SS |
5553 | watchpoint before the "run" command, the inferior dies with a e.g., |
5554 | SIGILL once you start it. I initially believed this was due to a | |
5555 | bad interaction between page protection traps and the initial | |
5556 | startup sequence by the dynamic linker. | |
5557 | ||
5558 | However, I tried avoiding that by having HP-UX's implementation of | |
39f77062 | 5559 | TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid |
c906108c SS |
5560 | yet, which forced slow watches before a "run" or "attach", and it |
5561 | still fails somewhere in the startup code. | |
5562 | ||
5563 | Until I figure out what's happening, I'm disallowing watches altogether | |
5564 | before the "run" or "attach" command. We'll tell the user they must | |
5565 | set watches after getting the program started. */ | |
c5aa993b | 5566 | if (!target_has_execution) |
c906108c SS |
5567 | { |
5568 | warning ("can't do that without a running program; try \"break main\", \"run\" first"); | |
5569 | return; | |
5570 | } | |
5571 | #endif /* HPUXHPPA */ | |
c5aa993b | 5572 | |
4d28f7a8 KB |
5573 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
5574 | watchpoint could not be set. */ | |
5575 | if (!mem_cnt || target_resources_ok <= 0) | |
5576 | bp_type = bp_watchpoint; | |
5577 | ||
c906108c | 5578 | /* Now set up the breakpoint. */ |
4d28f7a8 | 5579 | b = set_raw_breakpoint (sal, bp_type); |
c906108c SS |
5580 | set_breakpoint_count (breakpoint_count + 1); |
5581 | b->number = breakpoint_count; | |
b5de0fa7 | 5582 | b->disposition = disp_donttouch; |
c906108c SS |
5583 | b->exp = exp; |
5584 | b->exp_valid_block = exp_valid_block; | |
5585 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
5586 | b->val = val; | |
5587 | b->cond = cond; | |
5588 | if (cond_start) | |
5589 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
5590 | else | |
5591 | b->cond_string = 0; | |
c5aa993b | 5592 | |
c906108c SS |
5593 | frame = block_innermost_frame (exp_valid_block); |
5594 | if (frame) | |
5595 | { | |
5596 | prev_frame = get_prev_frame (frame); | |
7a424e99 | 5597 | b->watchpoint_frame = get_frame_id (frame); |
c906108c SS |
5598 | } |
5599 | else | |
101dcfbe AC |
5600 | { |
5601 | memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame)); | |
5602 | } | |
c906108c | 5603 | |
c906108c SS |
5604 | /* If the expression is "local", then set up a "watchpoint scope" |
5605 | breakpoint at the point where we've left the scope of the watchpoint | |
5606 | expression. */ | |
5607 | if (innermost_block) | |
5608 | { | |
5609 | if (prev_frame) | |
5610 | { | |
5611 | struct breakpoint *scope_breakpoint; | |
e86ae29f KS |
5612 | scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame), |
5613 | bp_watchpoint_scope); | |
c906108c | 5614 | |
b5de0fa7 | 5615 | scope_breakpoint->enable_state = bp_enabled; |
c906108c SS |
5616 | |
5617 | /* Automatically delete the breakpoint when it hits. */ | |
b5de0fa7 | 5618 | scope_breakpoint->disposition = disp_del; |
c906108c SS |
5619 | |
5620 | /* Only break in the proper frame (help with recursion). */ | |
818dd999 | 5621 | scope_breakpoint->frame_id = get_frame_id (prev_frame); |
c906108c SS |
5622 | |
5623 | /* Set the address at which we will stop. */ | |
5cab636d DJ |
5624 | scope_breakpoint->loc->requested_address |
5625 | = get_frame_pc (prev_frame); | |
5626 | scope_breakpoint->loc->address | |
5627 | = adjust_breakpoint_address (scope_breakpoint->loc->requested_address); | |
c906108c SS |
5628 | |
5629 | /* The scope breakpoint is related to the watchpoint. We | |
5630 | will need to act on them together. */ | |
5631 | b->related_breakpoint = scope_breakpoint; | |
5632 | } | |
5633 | } | |
5634 | value_free_to_mark (mark); | |
5635 | mention (b); | |
5636 | } | |
5637 | ||
5638 | /* Return count of locations need to be watched and can be handled | |
5639 | in hardware. If the watchpoint can not be handled | |
5640 | in hardware return zero. */ | |
5641 | ||
5642 | #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT) | |
53a5351d | 5643 | #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \ |
b1e29e33 | 5644 | ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE)) |
53a5351d JM |
5645 | #endif |
5646 | ||
5647 | #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT) | |
5648 | #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \ | |
6ab3a9c9 | 5649 | (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)) |
c906108c SS |
5650 | #endif |
5651 | ||
5652 | static int | |
fba45db2 | 5653 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
5654 | { |
5655 | int found_memory_cnt = 0; | |
2e70b7b9 | 5656 | struct value *head = v; |
c906108c SS |
5657 | |
5658 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 5659 | if (!can_use_hw_watchpoints) |
c906108c | 5660 | return 0; |
c5aa993b | 5661 | |
5c44784c JM |
5662 | /* Make sure that the value of the expression depends only upon |
5663 | memory contents, and values computed from them within GDB. If we | |
5664 | find any register references or function calls, we can't use a | |
5665 | hardware watchpoint. | |
5666 | ||
5667 | The idea here is that evaluating an expression generates a series | |
5668 | of values, one holding the value of every subexpression. (The | |
5669 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
5670 | a*b+c.) GDB's values hold almost enough information to establish | |
5671 | the criteria given above --- they identify memory lvalues, | |
5672 | register lvalues, computed values, etcetera. So we can evaluate | |
5673 | the expression, and then scan the chain of values that leaves | |
5674 | behind to decide whether we can detect any possible change to the | |
5675 | expression's final value using only hardware watchpoints. | |
5676 | ||
5677 | However, I don't think that the values returned by inferior | |
5678 | function calls are special in any way. So this function may not | |
5679 | notice that an expression involving an inferior function call | |
5680 | can't be watched with hardware watchpoints. FIXME. */ | |
c5aa993b | 5681 | for (; v; v = v->next) |
c906108c | 5682 | { |
5c44784c | 5683 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 5684 | { |
5c44784c JM |
5685 | if (VALUE_LAZY (v)) |
5686 | /* A lazy memory lvalue is one that GDB never needed to fetch; | |
5687 | we either just used its address (e.g., `a' in `a.b') or | |
5688 | we never needed it at all (e.g., `a' in `a,b'). */ | |
5689 | ; | |
53a5351d | 5690 | else |
5c44784c JM |
5691 | { |
5692 | /* Ahh, memory we actually used! Check if we can cover | |
5693 | it with hardware watchpoints. */ | |
2e70b7b9 MS |
5694 | struct type *vtype = check_typedef (VALUE_TYPE (v)); |
5695 | ||
5696 | /* We only watch structs and arrays if user asked for it | |
5697 | explicitly, never if they just happen to appear in a | |
5698 | middle of some value chain. */ | |
5699 | if (v == head | |
5700 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
5701 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
5702 | { | |
5703 | CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
5704 | int len = TYPE_LENGTH (VALUE_TYPE (v)); | |
5705 | ||
5706 | if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len)) | |
5707 | return 0; | |
5708 | else | |
5709 | found_memory_cnt++; | |
5710 | } | |
5c44784c | 5711 | } |
c5aa993b | 5712 | } |
c906108c | 5713 | else if (v->lval != not_lval && v->modifiable == 0) |
53a5351d JM |
5714 | return 0; /* ??? What does this represent? */ |
5715 | else if (v->lval == lval_register) | |
5716 | return 0; /* cannot watch a register with a HW watchpoint */ | |
c906108c SS |
5717 | } |
5718 | ||
5719 | /* The expression itself looks suitable for using a hardware | |
5720 | watchpoint, but give the target machine a chance to reject it. */ | |
5721 | return found_memory_cnt; | |
5722 | } | |
5723 | ||
8b93c638 | 5724 | void |
fba45db2 | 5725 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5726 | { |
5727 | watch_command (arg, from_tty); | |
5728 | } | |
8926118c | 5729 | |
c5aa993b | 5730 | static void |
fba45db2 | 5731 | watch_command (char *arg, int from_tty) |
c906108c | 5732 | { |
53a5351d | 5733 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
5734 | } |
5735 | ||
8b93c638 | 5736 | void |
fba45db2 | 5737 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5738 | { |
5739 | rwatch_command (arg, from_tty); | |
5740 | } | |
8926118c | 5741 | |
c5aa993b | 5742 | static void |
fba45db2 | 5743 | rwatch_command (char *arg, int from_tty) |
c906108c | 5744 | { |
53a5351d | 5745 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
5746 | } |
5747 | ||
8b93c638 | 5748 | void |
fba45db2 | 5749 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5750 | { |
5751 | awatch_command (arg, from_tty); | |
5752 | } | |
8926118c | 5753 | |
c5aa993b | 5754 | static void |
fba45db2 | 5755 | awatch_command (char *arg, int from_tty) |
c906108c | 5756 | { |
53a5351d | 5757 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 5758 | } |
c906108c | 5759 | \f |
c5aa993b | 5760 | |
43ff13b4 | 5761 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
5762 | because it uses the mechanisms of breakpoints. */ |
5763 | ||
43ff13b4 JM |
5764 | /* This function is called by fetch_inferior_event via the |
5765 | cmd_continuation pointer, to complete the until command. It takes | |
5766 | care of cleaning up the temporary breakpoints set up by the until | |
5767 | command. */ | |
c2c6d25f JM |
5768 | static void |
5769 | until_break_command_continuation (struct continuation_arg *arg) | |
43ff13b4 | 5770 | { |
0d06e24b JM |
5771 | struct cleanup *cleanups; |
5772 | ||
57e687d9 | 5773 | cleanups = (struct cleanup *) arg->data.pointer; |
0d06e24b | 5774 | do_exec_cleanups (cleanups); |
43ff13b4 JM |
5775 | } |
5776 | ||
c906108c | 5777 | void |
ae66c1fc | 5778 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
5779 | { |
5780 | struct symtabs_and_lines sals; | |
5781 | struct symtab_and_line sal; | |
6e7f8b9c | 5782 | struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame); |
c906108c SS |
5783 | struct breakpoint *breakpoint; |
5784 | struct cleanup *old_chain; | |
0d06e24b JM |
5785 | struct continuation_arg *arg1; |
5786 | ||
c906108c SS |
5787 | |
5788 | clear_proceed_status (); | |
5789 | ||
5790 | /* Set a breakpoint where the user wants it and at return from | |
5791 | this function */ | |
c5aa993b | 5792 | |
c906108c SS |
5793 | if (default_breakpoint_valid) |
5794 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
c5aa993b | 5795 | default_breakpoint_line, (char ***) NULL); |
c906108c | 5796 | else |
53a5351d JM |
5797 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
5798 | 0, (char ***) NULL); | |
c5aa993b | 5799 | |
c906108c SS |
5800 | if (sals.nelts != 1) |
5801 | error ("Couldn't get information on specified line."); | |
c5aa993b | 5802 | |
c906108c | 5803 | sal = sals.sals[0]; |
b8c9b27d | 5804 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 5805 | |
c906108c SS |
5806 | if (*arg) |
5807 | error ("Junk at end of arguments."); | |
c5aa993b | 5808 | |
c906108c | 5809 | resolve_sal_pc (&sal); |
c5aa993b | 5810 | |
ae66c1fc EZ |
5811 | if (anywhere) |
5812 | /* If the user told us to continue until a specified location, | |
5813 | we don't specify a frame at which we need to stop. */ | |
5814 | breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until); | |
5815 | else | |
5816 | /* Otherwise, specify the current frame, because we want to stop only | |
5817 | at the very same frame. */ | |
5818 | breakpoint = set_momentary_breakpoint (sal, | |
5819 | get_frame_id (deprecated_selected_frame), | |
5820 | bp_until); | |
c5aa993b | 5821 | |
6426a772 | 5822 | if (!event_loop_p || !target_can_async_p ()) |
4d6140d9 | 5823 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 | 5824 | else |
4d6140d9 | 5825 | old_chain = make_exec_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 JM |
5826 | |
5827 | /* If we are running asynchronously, and the target supports async | |
5828 | execution, we are not waiting for the target to stop, in the call | |
5829 | tp proceed, below. This means that we cannot delete the | |
5830 | brekpoints until the target has actually stopped. The only place | |
5831 | where we get a chance to do that is in fetch_inferior_event, so | |
5832 | we must set things up for that. */ | |
5833 | ||
6426a772 | 5834 | if (event_loop_p && target_can_async_p ()) |
43ff13b4 | 5835 | { |
0d06e24b JM |
5836 | /* In this case the arg for the continuation is just the point |
5837 | in the exec_cleanups chain from where to start doing | |
5838 | cleanups, because all the continuation does is the cleanups in | |
5839 | the exec_cleanup_chain. */ | |
5840 | arg1 = | |
5841 | (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg)); | |
57e687d9 MS |
5842 | arg1->next = NULL; |
5843 | arg1->data.pointer = old_chain; | |
0d06e24b JM |
5844 | |
5845 | add_continuation (until_break_command_continuation, arg1); | |
43ff13b4 | 5846 | } |
c906108c | 5847 | |
ae66c1fc EZ |
5848 | /* Keep within the current frame, or in frames called by the current |
5849 | one. */ | |
c906108c SS |
5850 | if (prev_frame) |
5851 | { | |
30f7db39 AC |
5852 | sal = find_pc_line (get_frame_pc (prev_frame), 0); |
5853 | sal.pc = get_frame_pc (prev_frame); | |
818dd999 AC |
5854 | breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame), |
5855 | bp_until); | |
6426a772 | 5856 | if (!event_loop_p || !target_can_async_p ()) |
4d6140d9 | 5857 | make_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 | 5858 | else |
4d6140d9 | 5859 | make_exec_cleanup_delete_breakpoint (breakpoint); |
c906108c | 5860 | } |
c5aa993b | 5861 | |
c906108c | 5862 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
43ff13b4 JM |
5863 | /* Do the cleanups now, anly if we are not running asynchronously, |
5864 | of if we are, but the target is still synchronous. */ | |
6426a772 | 5865 | if (!event_loop_p || !target_can_async_p ()) |
c5aa993b | 5866 | do_cleanups (old_chain); |
c906108c | 5867 | } |
ae66c1fc | 5868 | |
c906108c SS |
5869 | #if 0 |
5870 | /* These aren't used; I don't konw what they were for. */ | |
5871 | /* Set a breakpoint at the catch clause for NAME. */ | |
5872 | static int | |
fba45db2 | 5873 | catch_breakpoint (char *name) |
c906108c SS |
5874 | { |
5875 | } | |
5876 | ||
5877 | static int | |
fba45db2 | 5878 | disable_catch_breakpoint (void) |
c906108c SS |
5879 | { |
5880 | } | |
5881 | ||
5882 | static int | |
fba45db2 | 5883 | delete_catch_breakpoint (void) |
c906108c SS |
5884 | { |
5885 | } | |
5886 | ||
5887 | static int | |
fba45db2 | 5888 | enable_catch_breakpoint (void) |
c906108c SS |
5889 | { |
5890 | } | |
5891 | #endif /* 0 */ | |
5892 | ||
c906108c | 5893 | static void |
fba45db2 | 5894 | ep_skip_leading_whitespace (char **s) |
c906108c | 5895 | { |
c5aa993b JM |
5896 | if ((s == NULL) || (*s == NULL)) |
5897 | return; | |
5898 | while (isspace (**s)) | |
5899 | *s += 1; | |
c906108c | 5900 | } |
c5aa993b | 5901 | |
c906108c SS |
5902 | /* This function examines a string, and attempts to find a token |
5903 | that might be an event name in the leading characters. If a | |
5904 | possible match is found, a pointer to the last character of | |
5905 | the token is returned. Else, NULL is returned. */ | |
53a5351d | 5906 | |
c906108c | 5907 | static char * |
fba45db2 | 5908 | ep_find_event_name_end (char *arg) |
c906108c | 5909 | { |
c5aa993b JM |
5910 | char *s = arg; |
5911 | char *event_name_end = NULL; | |
5912 | ||
c906108c SS |
5913 | /* If we could depend upon the presense of strrpbrk, we'd use that... */ |
5914 | if (arg == NULL) | |
5915 | return NULL; | |
c5aa993b | 5916 | |
c906108c | 5917 | /* We break out of the loop when we find a token delimiter. |
c5aa993b JM |
5918 | Basically, we're looking for alphanumerics and underscores; |
5919 | anything else delimites the token. */ | |
c906108c SS |
5920 | while (*s != '\0') |
5921 | { | |
c5aa993b JM |
5922 | if (!isalnum (*s) && (*s != '_')) |
5923 | break; | |
c906108c SS |
5924 | event_name_end = s; |
5925 | s++; | |
5926 | } | |
c5aa993b | 5927 | |
c906108c SS |
5928 | return event_name_end; |
5929 | } | |
5930 | ||
c5aa993b | 5931 | |
c906108c SS |
5932 | /* This function attempts to parse an optional "if <cond>" clause |
5933 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 5934 | |
c906108c SS |
5935 | Else, it returns a pointer to the condition string. (It does not |
5936 | attempt to evaluate the string against a particular block.) And, | |
5937 | it updates arg to point to the first character following the parsed | |
5938 | if clause in the arg string. */ | |
53a5351d | 5939 | |
c906108c | 5940 | static char * |
fba45db2 | 5941 | ep_parse_optional_if_clause (char **arg) |
c906108c | 5942 | { |
c5aa993b JM |
5943 | char *cond_string; |
5944 | ||
5945 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 5946 | return NULL; |
c5aa993b | 5947 | |
c906108c SS |
5948 | /* Skip the "if" keyword. */ |
5949 | (*arg) += 2; | |
c5aa993b | 5950 | |
c906108c SS |
5951 | /* Skip any extra leading whitespace, and record the start of the |
5952 | condition string. */ | |
5953 | ep_skip_leading_whitespace (arg); | |
5954 | cond_string = *arg; | |
c5aa993b | 5955 | |
c906108c SS |
5956 | /* Assume that the condition occupies the remainder of the arg string. */ |
5957 | (*arg) += strlen (cond_string); | |
c5aa993b | 5958 | |
c906108c SS |
5959 | return cond_string; |
5960 | } | |
c5aa993b | 5961 | |
c906108c SS |
5962 | /* This function attempts to parse an optional filename from the arg |
5963 | string. If one is not found, it returns NULL. | |
c5aa993b | 5964 | |
c906108c SS |
5965 | Else, it returns a pointer to the parsed filename. (This function |
5966 | makes no attempt to verify that a file of that name exists, or is | |
5967 | accessible.) And, it updates arg to point to the first character | |
5968 | following the parsed filename in the arg string. | |
c5aa993b | 5969 | |
c906108c SS |
5970 | Note that clients needing to preserve the returned filename for |
5971 | future access should copy it to their own buffers. */ | |
5972 | static char * | |
fba45db2 | 5973 | ep_parse_optional_filename (char **arg) |
c906108c | 5974 | { |
c5aa993b JM |
5975 | static char filename[1024]; |
5976 | char *arg_p = *arg; | |
5977 | int i; | |
5978 | char c; | |
5979 | ||
c906108c SS |
5980 | if ((*arg_p == '\0') || isspace (*arg_p)) |
5981 | return NULL; | |
c5aa993b JM |
5982 | |
5983 | for (i = 0;; i++) | |
c906108c SS |
5984 | { |
5985 | c = *arg_p; | |
5986 | if (isspace (c)) | |
c5aa993b | 5987 | c = '\0'; |
c906108c SS |
5988 | filename[i] = c; |
5989 | if (c == '\0') | |
c5aa993b | 5990 | break; |
c906108c SS |
5991 | arg_p++; |
5992 | } | |
5993 | *arg = arg_p; | |
c5aa993b | 5994 | |
c906108c SS |
5995 | return filename; |
5996 | } | |
c5aa993b | 5997 | |
c906108c SS |
5998 | /* Commands to deal with catching events, such as signals, exceptions, |
5999 | process start/exit, etc. */ | |
c5aa993b JM |
6000 | |
6001 | typedef enum | |
6002 | { | |
6003 | catch_fork, catch_vfork | |
6004 | } | |
6005 | catch_fork_kind; | |
6006 | ||
e514a9d6 | 6007 | #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT) |
a14ed312 KB |
6008 | static void catch_fork_command_1 (catch_fork_kind fork_kind, |
6009 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 6010 | |
c906108c | 6011 | static void |
fba45db2 KB |
6012 | catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag, |
6013 | int from_tty) | |
c906108c | 6014 | { |
c5aa993b JM |
6015 | char *cond_string = NULL; |
6016 | ||
c906108c | 6017 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6018 | |
c906108c | 6019 | /* The allowed syntax is: |
c5aa993b JM |
6020 | catch [v]fork |
6021 | catch [v]fork if <cond> | |
6022 | ||
c906108c SS |
6023 | First, check if there's an if clause. */ |
6024 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6025 | |
c906108c SS |
6026 | if ((*arg != '\0') && !isspace (*arg)) |
6027 | error ("Junk at end of arguments."); | |
c5aa993b | 6028 | |
c906108c SS |
6029 | /* If this target supports it, create a fork or vfork catchpoint |
6030 | and enable reporting of such events. */ | |
c5aa993b JM |
6031 | switch (fork_kind) |
6032 | { | |
6033 | case catch_fork: | |
c906108c SS |
6034 | create_fork_event_catchpoint (tempflag, cond_string); |
6035 | break; | |
c5aa993b | 6036 | case catch_vfork: |
c906108c SS |
6037 | create_vfork_event_catchpoint (tempflag, cond_string); |
6038 | break; | |
c5aa993b | 6039 | default: |
c906108c SS |
6040 | error ("unsupported or unknown fork kind; cannot catch it"); |
6041 | break; | |
c5aa993b | 6042 | } |
c906108c | 6043 | } |
e514a9d6 | 6044 | #endif |
c906108c | 6045 | |
e514a9d6 | 6046 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) |
c906108c | 6047 | static void |
fba45db2 | 6048 | catch_exec_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 6049 | { |
c5aa993b | 6050 | char *cond_string = NULL; |
c906108c SS |
6051 | |
6052 | ep_skip_leading_whitespace (&arg); | |
6053 | ||
6054 | /* The allowed syntax is: | |
c5aa993b JM |
6055 | catch exec |
6056 | catch exec if <cond> | |
c906108c SS |
6057 | |
6058 | First, check if there's an if clause. */ | |
6059 | cond_string = ep_parse_optional_if_clause (&arg); | |
6060 | ||
6061 | if ((*arg != '\0') && !isspace (*arg)) | |
6062 | error ("Junk at end of arguments."); | |
6063 | ||
6064 | /* If this target supports it, create an exec catchpoint | |
6065 | and enable reporting of such events. */ | |
6066 | create_exec_event_catchpoint (tempflag, cond_string); | |
6067 | } | |
e514a9d6 | 6068 | #endif |
c5aa993b | 6069 | |
c906108c SS |
6070 | #if defined(SOLIB_ADD) |
6071 | static void | |
fba45db2 | 6072 | catch_load_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 6073 | { |
c5aa993b JM |
6074 | char *dll_pathname = NULL; |
6075 | char *cond_string = NULL; | |
6076 | ||
c906108c | 6077 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6078 | |
c906108c | 6079 | /* The allowed syntax is: |
c5aa993b JM |
6080 | catch load |
6081 | catch load if <cond> | |
6082 | catch load <filename> | |
6083 | catch load <filename> if <cond> | |
6084 | ||
c906108c SS |
6085 | The user is not allowed to specify the <filename> after an |
6086 | if clause. | |
c5aa993b | 6087 | |
c906108c | 6088 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 6089 | |
c906108c SS |
6090 | First, check if there's an if clause. If so, then there |
6091 | cannot be a filename. */ | |
6092 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6093 | |
c906108c SS |
6094 | /* If there was an if clause, then there cannot be a filename. |
6095 | Else, there might be a filename and an if clause. */ | |
6096 | if (cond_string == NULL) | |
6097 | { | |
6098 | dll_pathname = ep_parse_optional_filename (&arg); | |
6099 | ep_skip_leading_whitespace (&arg); | |
6100 | cond_string = ep_parse_optional_if_clause (&arg); | |
6101 | } | |
c5aa993b | 6102 | |
c906108c SS |
6103 | if ((*arg != '\0') && !isspace (*arg)) |
6104 | error ("Junk at end of arguments."); | |
c5aa993b | 6105 | |
c906108c SS |
6106 | /* Create a load breakpoint that only triggers when a load of |
6107 | the specified dll (or any dll, if no pathname was specified) | |
6108 | occurs. */ | |
39f77062 | 6109 | SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag, |
53a5351d | 6110 | dll_pathname, cond_string); |
c906108c | 6111 | } |
c5aa993b | 6112 | |
c906108c | 6113 | static void |
fba45db2 | 6114 | catch_unload_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 6115 | { |
c5aa993b JM |
6116 | char *dll_pathname = NULL; |
6117 | char *cond_string = NULL; | |
6118 | ||
c906108c | 6119 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6120 | |
c906108c | 6121 | /* The allowed syntax is: |
c5aa993b JM |
6122 | catch unload |
6123 | catch unload if <cond> | |
6124 | catch unload <filename> | |
6125 | catch unload <filename> if <cond> | |
6126 | ||
c906108c SS |
6127 | The user is not allowed to specify the <filename> after an |
6128 | if clause. | |
c5aa993b | 6129 | |
c906108c | 6130 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 6131 | |
c906108c SS |
6132 | First, check if there's an if clause. If so, then there |
6133 | cannot be a filename. */ | |
6134 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6135 | |
c906108c SS |
6136 | /* If there was an if clause, then there cannot be a filename. |
6137 | Else, there might be a filename and an if clause. */ | |
6138 | if (cond_string == NULL) | |
6139 | { | |
6140 | dll_pathname = ep_parse_optional_filename (&arg); | |
6141 | ep_skip_leading_whitespace (&arg); | |
6142 | cond_string = ep_parse_optional_if_clause (&arg); | |
6143 | } | |
c5aa993b | 6144 | |
c906108c SS |
6145 | if ((*arg != '\0') && !isspace (*arg)) |
6146 | error ("Junk at end of arguments."); | |
c5aa993b | 6147 | |
c906108c SS |
6148 | /* Create an unload breakpoint that only triggers when an unload of |
6149 | the specified dll (or any dll, if no pathname was specified) | |
6150 | occurs. */ | |
39f77062 | 6151 | SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag, |
53a5351d | 6152 | dll_pathname, cond_string); |
c906108c SS |
6153 | } |
6154 | #endif /* SOLIB_ADD */ | |
6155 | ||
6156 | /* Commands to deal with catching exceptions. */ | |
6157 | ||
6158 | /* Set a breakpoint at the specified callback routine for an | |
c5aa993b | 6159 | exception event callback */ |
c906108c SS |
6160 | |
6161 | static void | |
fba45db2 KB |
6162 | create_exception_catchpoint (int tempflag, char *cond_string, |
6163 | enum exception_event_kind ex_event, | |
6164 | struct symtab_and_line *sal) | |
c906108c | 6165 | { |
c5aa993b | 6166 | struct breakpoint *b; |
c5aa993b | 6167 | int thread = -1; /* All threads. */ |
4d28f7a8 | 6168 | enum bptype bptype; |
c906108c | 6169 | |
c5aa993b | 6170 | if (!sal) /* no exception support? */ |
c906108c SS |
6171 | return; |
6172 | ||
c906108c SS |
6173 | switch (ex_event) |
6174 | { | |
c5aa993b | 6175 | case EX_EVENT_THROW: |
4d28f7a8 | 6176 | bptype = bp_catch_throw; |
c5aa993b JM |
6177 | break; |
6178 | case EX_EVENT_CATCH: | |
4d28f7a8 | 6179 | bptype = bp_catch_catch; |
c5aa993b JM |
6180 | break; |
6181 | default: /* error condition */ | |
c5aa993b | 6182 | error ("Internal error -- invalid catchpoint kind"); |
c906108c | 6183 | } |
4d28f7a8 KB |
6184 | |
6185 | b = set_raw_breakpoint (*sal, bptype); | |
6186 | set_breakpoint_count (breakpoint_count + 1); | |
6187 | b->number = breakpoint_count; | |
6188 | b->cond = NULL; | |
6189 | b->cond_string = (cond_string == NULL) ? | |
6190 | NULL : savestring (cond_string, strlen (cond_string)); | |
6191 | b->thread = thread; | |
6192 | b->addr_string = NULL; | |
b5de0fa7 EZ |
6193 | b->enable_state = bp_enabled; |
6194 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c SS |
6195 | mention (b); |
6196 | } | |
6197 | ||
3086aeae DJ |
6198 | static enum print_stop_action |
6199 | print_exception_catchpoint (struct breakpoint *b) | |
6200 | { | |
6201 | annotate_catchpoint (b->number); | |
6202 | ||
6203 | if (strstr (b->addr_string, "throw") != NULL) | |
6204 | printf_filtered ("\nCatchpoint %d (exception thrown)\n", | |
6205 | b->number); | |
6206 | else | |
6207 | printf_filtered ("\nCatchpoint %d (exception caught)\n", | |
6208 | b->number); | |
6209 | ||
6210 | return PRINT_SRC_AND_LOC; | |
6211 | } | |
6212 | ||
6213 | static void | |
6214 | print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr) | |
6215 | { | |
6216 | if (addressprint) | |
6217 | { | |
6218 | annotate_field (4); | |
5cab636d | 6219 | ui_out_field_core_addr (uiout, "addr", b->loc->address); |
3086aeae DJ |
6220 | } |
6221 | annotate_field (5); | |
5cab636d | 6222 | *last_addr = b->loc->address; |
3086aeae DJ |
6223 | if (strstr (b->addr_string, "throw") != NULL) |
6224 | ui_out_field_string (uiout, "what", "exception throw"); | |
6225 | else | |
6226 | ui_out_field_string (uiout, "what", "exception catch"); | |
6227 | } | |
6228 | ||
6229 | static void | |
6230 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6231 | { | |
6232 | if (strstr (b->addr_string, "throw") != NULL) | |
6233 | printf_filtered ("Catchpoint %d (throw)", b->number); | |
6234 | else | |
6235 | printf_filtered ("Catchpoint %d (catch)", b->number); | |
6236 | } | |
6237 | ||
6238 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
6239 | print_exception_catchpoint, | |
6240 | print_one_exception_catchpoint, | |
6241 | print_mention_exception_catchpoint | |
6242 | }; | |
6243 | ||
6244 | static int | |
6245 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6246 | enum exception_event_kind ex_event, int from_tty) | |
6247 | { | |
6248 | char *trigger_func_name, *nameptr; | |
6249 | struct symtabs_and_lines sals; | |
6250 | struct breakpoint *b; | |
6251 | ||
6252 | if (ex_event == EX_EVENT_CATCH) | |
6253 | trigger_func_name = xstrdup ("__cxa_begin_catch"); | |
6254 | else | |
6255 | trigger_func_name = xstrdup ("__cxa_throw"); | |
6256 | ||
6257 | nameptr = trigger_func_name; | |
6258 | sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL); | |
6259 | if (sals.nelts == 0) | |
6260 | { | |
b59661bd | 6261 | xfree (trigger_func_name); |
3086aeae DJ |
6262 | return 0; |
6263 | } | |
6264 | ||
6265 | b = set_raw_breakpoint (sals.sals[0], bp_breakpoint); | |
6266 | set_breakpoint_count (breakpoint_count + 1); | |
6267 | b->number = breakpoint_count; | |
6268 | b->cond = NULL; | |
6269 | b->cond_string = (cond_string == NULL) ? | |
6270 | NULL : savestring (cond_string, strlen (cond_string)); | |
6271 | b->thread = -1; | |
6272 | b->addr_string = trigger_func_name; | |
6273 | b->enable_state = bp_enabled; | |
6274 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
6275 | b->ops = &gnu_v3_exception_catchpoint_ops; | |
6276 | ||
b59661bd | 6277 | xfree (sals.sals); |
3086aeae DJ |
6278 | mention (b); |
6279 | return 1; | |
6280 | } | |
6281 | ||
c5aa993b | 6282 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6283 | |
6284 | static void | |
fba45db2 KB |
6285 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6286 | int tempflag, int from_tty) | |
c906108c | 6287 | { |
c5aa993b JM |
6288 | char *cond_string = NULL; |
6289 | struct symtab_and_line *sal = NULL; | |
6290 | ||
c906108c | 6291 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6292 | |
c906108c SS |
6293 | cond_string = ep_parse_optional_if_clause (&arg); |
6294 | ||
6295 | if ((*arg != '\0') && !isspace (*arg)) | |
6296 | error ("Junk at end of arguments."); | |
6297 | ||
6298 | if ((ex_event != EX_EVENT_THROW) && | |
6299 | (ex_event != EX_EVENT_CATCH)) | |
6300 | error ("Unsupported or unknown exception event; cannot catch it"); | |
6301 | ||
3086aeae DJ |
6302 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
6303 | return; | |
6304 | ||
c906108c SS |
6305 | /* See if we can find a callback routine */ |
6306 | sal = target_enable_exception_callback (ex_event, 1); | |
6307 | ||
c5aa993b | 6308 | if (sal) |
c906108c SS |
6309 | { |
6310 | /* We have callbacks from the runtime system for exceptions. | |
c5aa993b | 6311 | Set a breakpoint on the sal found, if no errors */ |
c906108c | 6312 | if (sal != (struct symtab_and_line *) -1) |
c5aa993b | 6313 | create_exception_catchpoint (tempflag, cond_string, ex_event, sal); |
c906108c | 6314 | else |
53a5351d | 6315 | return; /* something went wrong with setting up callbacks */ |
c906108c | 6316 | } |
c5aa993b | 6317 | |
69f567ae | 6318 | warning ("Unsupported with this platform/compiler combination."); |
c906108c SS |
6319 | } |
6320 | ||
6321 | /* Cover routine to allow wrapping target_enable_exception_catchpoints | |
6322 | inside a catch_errors */ | |
6323 | ||
6324 | static int | |
4efb68b1 | 6325 | cover_target_enable_exception_callback (void *arg) |
c906108c SS |
6326 | { |
6327 | args_for_catchpoint_enable *args = arg; | |
6328 | struct symtab_and_line *sal; | |
b5de0fa7 | 6329 | sal = target_enable_exception_callback (args->kind, args->enable_p); |
c906108c SS |
6330 | if (sal == NULL) |
6331 | return 0; | |
6332 | else if (sal == (struct symtab_and_line *) -1) | |
6333 | return -1; | |
6334 | else | |
c5aa993b | 6335 | return 1; /*is valid */ |
c906108c SS |
6336 | } |
6337 | ||
c906108c | 6338 | static void |
fba45db2 | 6339 | catch_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 6340 | { |
c5aa993b | 6341 | |
c906108c SS |
6342 | /* The first argument may be an event name, such as "start" or "load". |
6343 | If so, then handle it as such. If it doesn't match an event name, | |
6344 | then attempt to interpret it as an exception name. (This latter is | |
6345 | the v4.16-and-earlier GDB meaning of the "catch" command.) | |
c5aa993b | 6346 | |
c906108c | 6347 | First, try to find the bounds of what might be an event name. */ |
c5aa993b JM |
6348 | char *arg1_start = arg; |
6349 | char *arg1_end; | |
6350 | int arg1_length; | |
6351 | ||
c906108c SS |
6352 | if (arg1_start == NULL) |
6353 | { | |
c5aa993b | 6354 | /* Old behaviour was to use pre-v-4.16 syntax */ |
c906108c SS |
6355 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
6356 | /* return; */ | |
c5aa993b | 6357 | /* Now, this is not allowed */ |
c906108c SS |
6358 | error ("Catch requires an event name."); |
6359 | ||
6360 | } | |
6361 | arg1_end = ep_find_event_name_end (arg1_start); | |
6362 | if (arg1_end == NULL) | |
6363 | error ("catch requires an event"); | |
6364 | arg1_length = arg1_end + 1 - arg1_start; | |
c5aa993b | 6365 | |
c906108c SS |
6366 | /* Try to match what we found against known event names. */ |
6367 | if (strncmp (arg1_start, "signal", arg1_length) == 0) | |
6368 | { | |
6369 | error ("Catch of signal not yet implemented"); | |
6370 | } | |
6371 | else if (strncmp (arg1_start, "catch", arg1_length) == 0) | |
6372 | { | |
53a5351d JM |
6373 | catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1, |
6374 | tempflag, from_tty); | |
c906108c SS |
6375 | } |
6376 | else if (strncmp (arg1_start, "throw", arg1_length) == 0) | |
6377 | { | |
53a5351d JM |
6378 | catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1, |
6379 | tempflag, from_tty); | |
c906108c SS |
6380 | } |
6381 | else if (strncmp (arg1_start, "thread_start", arg1_length) == 0) | |
6382 | { | |
6383 | error ("Catch of thread_start not yet implemented"); | |
6384 | } | |
6385 | else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0) | |
6386 | { | |
6387 | error ("Catch of thread_exit not yet implemented"); | |
6388 | } | |
6389 | else if (strncmp (arg1_start, "thread_join", arg1_length) == 0) | |
6390 | { | |
6391 | error ("Catch of thread_join not yet implemented"); | |
6392 | } | |
6393 | else if (strncmp (arg1_start, "start", arg1_length) == 0) | |
6394 | { | |
6395 | error ("Catch of start not yet implemented"); | |
6396 | } | |
6397 | else if (strncmp (arg1_start, "exit", arg1_length) == 0) | |
6398 | { | |
6399 | error ("Catch of exit not yet implemented"); | |
6400 | } | |
6401 | else if (strncmp (arg1_start, "fork", arg1_length) == 0) | |
6402 | { | |
6403 | #if defined(CHILD_INSERT_FORK_CATCHPOINT) | |
c5aa993b | 6404 | catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6405 | #else |
6406 | error ("Catch of fork not yet implemented"); | |
6407 | #endif | |
6408 | } | |
6409 | else if (strncmp (arg1_start, "vfork", arg1_length) == 0) | |
6410 | { | |
6411 | #if defined(CHILD_INSERT_VFORK_CATCHPOINT) | |
c5aa993b | 6412 | catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6413 | #else |
6414 | error ("Catch of vfork not yet implemented"); | |
6415 | #endif | |
6416 | } | |
6417 | else if (strncmp (arg1_start, "exec", arg1_length) == 0) | |
6418 | { | |
6419 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) | |
c5aa993b | 6420 | catch_exec_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6421 | #else |
6422 | error ("Catch of exec not yet implemented"); | |
6423 | #endif | |
6424 | } | |
6425 | else if (strncmp (arg1_start, "load", arg1_length) == 0) | |
6426 | { | |
6427 | #if defined(SOLIB_ADD) | |
c5aa993b | 6428 | catch_load_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6429 | #else |
6430 | error ("Catch of load not implemented"); | |
6431 | #endif | |
6432 | } | |
6433 | else if (strncmp (arg1_start, "unload", arg1_length) == 0) | |
6434 | { | |
6435 | #if defined(SOLIB_ADD) | |
c5aa993b | 6436 | catch_unload_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6437 | #else |
6438 | error ("Catch of load not implemented"); | |
6439 | #endif | |
6440 | } | |
6441 | else if (strncmp (arg1_start, "stop", arg1_length) == 0) | |
6442 | { | |
6443 | error ("Catch of stop not yet implemented"); | |
6444 | } | |
c5aa993b | 6445 | |
c906108c SS |
6446 | /* This doesn't appear to be an event name */ |
6447 | ||
6448 | else | |
6449 | { | |
6450 | /* Pre-v.4.16 behaviour was to treat the argument | |
c5aa993b | 6451 | as the name of an exception */ |
c906108c | 6452 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
c5aa993b | 6453 | /* Now this is not allowed */ |
c906108c SS |
6454 | error ("Unknown event kind specified for catch"); |
6455 | ||
6456 | } | |
6457 | } | |
6458 | ||
6459 | /* Used by the gui, could be made a worker for other things. */ | |
6460 | ||
6461 | struct breakpoint * | |
fba45db2 | 6462 | set_breakpoint_sal (struct symtab_and_line sal) |
c906108c SS |
6463 | { |
6464 | struct breakpoint *b; | |
4d28f7a8 | 6465 | b = set_raw_breakpoint (sal, bp_breakpoint); |
c906108c SS |
6466 | set_breakpoint_count (breakpoint_count + 1); |
6467 | b->number = breakpoint_count; | |
c906108c SS |
6468 | b->cond = 0; |
6469 | b->thread = -1; | |
6470 | return b; | |
6471 | } | |
6472 | ||
6473 | #if 0 | |
6474 | /* These aren't used; I don't know what they were for. */ | |
6475 | /* Disable breakpoints on all catch clauses described in ARGS. */ | |
6476 | static void | |
fba45db2 | 6477 | disable_catch (char *args) |
c906108c SS |
6478 | { |
6479 | /* Map the disable command to catch clauses described in ARGS. */ | |
6480 | } | |
6481 | ||
6482 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
6483 | static void | |
fba45db2 | 6484 | enable_catch (char *args) |
c906108c SS |
6485 | { |
6486 | /* Map the disable command to catch clauses described in ARGS. */ | |
6487 | } | |
6488 | ||
6489 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
6490 | static void | |
fba45db2 | 6491 | delete_catch (char *args) |
c906108c SS |
6492 | { |
6493 | /* Map the delete command to catch clauses described in ARGS. */ | |
6494 | } | |
6495 | #endif /* 0 */ | |
6496 | ||
6497 | static void | |
fba45db2 | 6498 | catch_command (char *arg, int from_tty) |
c906108c SS |
6499 | { |
6500 | catch_command_1 (arg, 0, from_tty); | |
6501 | } | |
6502 | \f | |
6503 | ||
6504 | static void | |
fba45db2 | 6505 | tcatch_command (char *arg, int from_tty) |
c906108c SS |
6506 | { |
6507 | catch_command_1 (arg, 1, from_tty); | |
6508 | } | |
6509 | ||
80f8a6eb | 6510 | /* Delete breakpoints by address or line. */ |
c906108c SS |
6511 | |
6512 | static void | |
fba45db2 | 6513 | clear_command (char *arg, int from_tty) |
c906108c | 6514 | { |
80f8a6eb | 6515 | struct breakpoint *b, *tmp, *prev, *found; |
c906108c SS |
6516 | int default_match; |
6517 | struct symtabs_and_lines sals; | |
6518 | struct symtab_and_line sal; | |
c906108c SS |
6519 | int i; |
6520 | ||
6521 | if (arg) | |
6522 | { | |
6523 | sals = decode_line_spec (arg, 1); | |
6524 | default_match = 0; | |
6525 | } | |
6526 | else | |
6527 | { | |
c5aa993b | 6528 | sals.sals = (struct symtab_and_line *) |
c906108c | 6529 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 6530 | make_cleanup (xfree, sals.sals); |
fe39c653 | 6531 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
6532 | sal.line = default_breakpoint_line; |
6533 | sal.symtab = default_breakpoint_symtab; | |
6534 | sal.pc = default_breakpoint_address; | |
6535 | if (sal.symtab == 0) | |
6536 | error ("No source file specified."); | |
6537 | ||
6538 | sals.sals[0] = sal; | |
6539 | sals.nelts = 1; | |
6540 | ||
6541 | default_match = 1; | |
6542 | } | |
6543 | ||
6544 | /* For each line spec given, delete bps which correspond | |
80f8a6eb MS |
6545 | to it. Do it in two passes, solely to preserve the current |
6546 | behavior that from_tty is forced true if we delete more than | |
6547 | one breakpoint. */ | |
c906108c | 6548 | |
80f8a6eb | 6549 | found = NULL; |
c906108c SS |
6550 | for (i = 0; i < sals.nelts; i++) |
6551 | { | |
6552 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
6553 | If line given (pc == 0), clear all bpts on specified line. |
6554 | If defaulting, clear all bpts on default line | |
c906108c | 6555 | or at default pc. |
c5aa993b JM |
6556 | |
6557 | defaulting sal.pc != 0 tests to do | |
6558 | ||
6559 | 0 1 pc | |
6560 | 1 1 pc _and_ line | |
6561 | 0 0 line | |
6562 | 1 0 <can't happen> */ | |
c906108c SS |
6563 | |
6564 | sal = sals.sals[i]; | |
80f8a6eb | 6565 | prev = NULL; |
c906108c | 6566 | |
80f8a6eb MS |
6567 | /* Find all matching breakpoints, remove them from the |
6568 | breakpoint chain, and add them to the 'found' chain. */ | |
6569 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
c5aa993b | 6570 | { |
80f8a6eb MS |
6571 | /* Are we going to delete b? */ |
6572 | if (b->type != bp_none | |
6573 | && b->type != bp_watchpoint | |
6574 | && b->type != bp_hardware_watchpoint | |
6575 | && b->type != bp_read_watchpoint | |
6576 | && b->type != bp_access_watchpoint | |
6577 | /* Not if b is a watchpoint of any sort... */ | |
5cab636d | 6578 | && (((sal.pc && (b->loc->address == sal.pc)) |
cf3a9e5b DJ |
6579 | && (!section_is_overlay (b->loc->section) |
6580 | || b->loc->section == sal.section)) | |
80f8a6eb MS |
6581 | /* Yes, if sal.pc matches b (modulo overlays). */ |
6582 | || ((default_match || (0 == sal.pc)) | |
6583 | && b->source_file != NULL | |
6584 | && sal.symtab != NULL | |
6585 | && STREQ (b->source_file, sal.symtab->filename) | |
6586 | && b->line_number == sal.line))) | |
6587 | /* Yes, if sal source file and line matches b. */ | |
6588 | { | |
6589 | /* Remove it from breakpoint_chain... */ | |
6590 | if (b == breakpoint_chain) | |
6591 | { | |
6592 | /* b is at the head of the list */ | |
6593 | breakpoint_chain = b->next; | |
6594 | } | |
6595 | else | |
6596 | { | |
6597 | prev->next = b->next; | |
6598 | } | |
6599 | /* And add it to 'found' chain. */ | |
6600 | b->next = found; | |
6601 | found = b; | |
6602 | } | |
c906108c | 6603 | else |
80f8a6eb MS |
6604 | { |
6605 | /* Keep b, and keep a pointer to it. */ | |
6606 | prev = b; | |
6607 | } | |
c906108c | 6608 | } |
80f8a6eb MS |
6609 | } |
6610 | /* Now go thru the 'found' chain and delete them. */ | |
6611 | if (found == 0) | |
6612 | { | |
6613 | if (arg) | |
6614 | error ("No breakpoint at %s.", arg); | |
6615 | else | |
6616 | error ("No breakpoint at this line."); | |
6617 | } | |
c906108c | 6618 | |
80f8a6eb MS |
6619 | if (found->next) |
6620 | from_tty = 1; /* Always report if deleted more than one */ | |
6621 | if (from_tty) | |
6622 | printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); | |
6623 | breakpoints_changed (); | |
6624 | while (found) | |
6625 | { | |
c5aa993b | 6626 | if (from_tty) |
80f8a6eb MS |
6627 | printf_unfiltered ("%d ", found->number); |
6628 | tmp = found->next; | |
6629 | delete_breakpoint (found); | |
6630 | found = tmp; | |
c906108c | 6631 | } |
80f8a6eb MS |
6632 | if (from_tty) |
6633 | putchar_unfiltered ('\n'); | |
c906108c SS |
6634 | } |
6635 | \f | |
6636 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
6637 | all breakpoints that are marked for deletion, whether hit or not. | |
6638 | This is called after any breakpoint is hit, or after errors. */ | |
6639 | ||
6640 | void | |
fba45db2 | 6641 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
6642 | { |
6643 | struct breakpoint *b, *temp; | |
6644 | ||
6645 | for (; bs; bs = bs->next) | |
b5de0fa7 | 6646 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del |
c906108c SS |
6647 | && bs->stop) |
6648 | delete_breakpoint (bs->breakpoint_at); | |
6649 | ||
6650 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 6651 | { |
b5de0fa7 | 6652 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
6653 | delete_breakpoint (b); |
6654 | } | |
c906108c SS |
6655 | } |
6656 | ||
53a5351d JM |
6657 | /* Delete a breakpoint and clean up all traces of it in the data |
6658 | structures. */ | |
c906108c SS |
6659 | |
6660 | void | |
fba45db2 | 6661 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 6662 | { |
52f0bd74 AC |
6663 | struct breakpoint *b; |
6664 | bpstat bs; | |
7cc221ef | 6665 | struct bp_location *loc; |
c906108c SS |
6666 | |
6667 | if (bpt == NULL) | |
6668 | error ("Internal error (attempted to delete a NULL breakpoint)"); | |
6669 | ||
6670 | ||
6671 | /* Has this bp already been deleted? This can happen because multiple | |
6672 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
6673 | ||
6674 | One example of this happening is a watchpoint's scope bp. When the | |
6675 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
6676 | delete it. We also delete its scope bp. But the scope bp is marked | |
6677 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
6678 | checked for auto-deleting bp's, which are deleted. | |
6679 | ||
6680 | A real solution to this problem might involve reference counts in bp's, | |
6681 | and/or giving them pointers back to their referencing bpstat's, and | |
6682 | teaching delete_breakpoint to only free a bp's storage when no more | |
6683 | references were extent. A cheaper bandaid was chosen. */ | |
6684 | if (bpt->type == bp_none) | |
6685 | return; | |
6686 | ||
6687 | if (delete_breakpoint_hook) | |
6688 | delete_breakpoint_hook (bpt); | |
104c1213 | 6689 | breakpoint_delete_event (bpt->number); |
c906108c | 6690 | |
5cab636d | 6691 | if (bpt->loc->inserted) |
2e663524 | 6692 | remove_breakpoint (bpt, mark_inserted); |
c5aa993b | 6693 | |
c906108c SS |
6694 | if (breakpoint_chain == bpt) |
6695 | breakpoint_chain = bpt->next; | |
6696 | ||
7cc221ef DJ |
6697 | if (bp_location_chain == bpt->loc) |
6698 | bp_location_chain = bpt->loc->next; | |
6699 | ||
c906108c SS |
6700 | /* If we have callback-style exception catchpoints, don't go through |
6701 | the adjustments to the C++ runtime library etc. if the inferior | |
6702 | isn't actually running. target_enable_exception_callback for a | |
6703 | null target ops vector gives an undesirable error message, so we | |
6704 | check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's | |
c5aa993b | 6705 | exceptions are supported in this way, it's OK for now. FIXME */ |
c906108c SS |
6706 | if (ep_is_exception_catchpoint (bpt) && target_has_execution) |
6707 | { | |
53a5351d | 6708 | /* Format possible error msg */ |
9ebf4acf AC |
6709 | char *message = xstrprintf ("Error in deleting catchpoint %d:\n", |
6710 | bpt->number); | |
6711 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
6712 | args_for_catchpoint_enable args; | |
53a5351d JM |
6713 | args.kind = bpt->type == bp_catch_catch ? |
6714 | EX_EVENT_CATCH : EX_EVENT_THROW; | |
b5de0fa7 | 6715 | args.enable_p = 0; |
c906108c SS |
6716 | catch_errors (cover_target_enable_exception_callback, &args, |
6717 | message, RETURN_MASK_ALL); | |
9ebf4acf | 6718 | do_cleanups (cleanups); |
c906108c SS |
6719 | } |
6720 | ||
6721 | ||
6722 | ALL_BREAKPOINTS (b) | |
6723 | if (b->next == bpt) | |
c5aa993b JM |
6724 | { |
6725 | b->next = bpt->next; | |
6726 | break; | |
6727 | } | |
c906108c | 6728 | |
7cc221ef DJ |
6729 | ALL_BP_LOCATIONS (loc) |
6730 | if (loc->next == bpt->loc) | |
6731 | { | |
6732 | loc->next = bpt->loc->next; | |
6733 | break; | |
6734 | } | |
6735 | ||
9f60f21b | 6736 | check_duplicates (bpt); |
c906108c SS |
6737 | /* If this breakpoint was inserted, and there is another breakpoint |
6738 | at the same address, we need to insert the other breakpoint. */ | |
5cab636d | 6739 | if (bpt->loc->inserted |
c906108c SS |
6740 | && bpt->type != bp_hardware_watchpoint |
6741 | && bpt->type != bp_read_watchpoint | |
6742 | && bpt->type != bp_access_watchpoint | |
6743 | && bpt->type != bp_catch_fork | |
6744 | && bpt->type != bp_catch_vfork | |
6745 | && bpt->type != bp_catch_exec) | |
6746 | { | |
6747 | ALL_BREAKPOINTS (b) | |
5cab636d | 6748 | if (b->loc->address == bpt->loc->address |
cf3a9e5b | 6749 | && b->loc->section == bpt->loc->section |
5cab636d | 6750 | && !b->loc->duplicate |
b5de0fa7 EZ |
6751 | && b->enable_state != bp_disabled |
6752 | && b->enable_state != bp_shlib_disabled | |
6753 | && b->enable_state != bp_call_disabled) | |
c5aa993b JM |
6754 | { |
6755 | int val; | |
53a5351d | 6756 | |
c2c6d25f JM |
6757 | /* We should never reach this point if there is a permanent |
6758 | breakpoint at the same address as the one being deleted. | |
6759 | If there is a permanent breakpoint somewhere, it should | |
6760 | always be the only one inserted. */ | |
b5de0fa7 | 6761 | if (b->enable_state == bp_permanent) |
8e65ff28 AC |
6762 | internal_error (__FILE__, __LINE__, |
6763 | "another breakpoint was inserted on top of " | |
c2c6d25f JM |
6764 | "a permanent breakpoint"); |
6765 | ||
53a5351d | 6766 | if (b->type == bp_hardware_breakpoint) |
5cab636d | 6767 | val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents); |
53a5351d | 6768 | else |
5cab636d | 6769 | val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents); |
53a5351d | 6770 | |
81d0cc19 | 6771 | /* If there was an error in the insert, print a message, then stop execution. */ |
c5aa993b JM |
6772 | if (val != 0) |
6773 | { | |
81d0cc19 GS |
6774 | struct ui_file *tmp_error_stream = mem_fileopen (); |
6775 | make_cleanup_ui_file_delete (tmp_error_stream); | |
6776 | ||
6777 | ||
6778 | if (b->type == bp_hardware_breakpoint) | |
6779 | { | |
6780 | fprintf_unfiltered (tmp_error_stream, | |
6781 | "Cannot insert hardware breakpoint %d.\n" | |
6782 | "You may have requested too many hardware breakpoints.\n", | |
6783 | b->number); | |
6784 | } | |
6785 | else | |
6786 | { | |
6787 | fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number); | |
6788 | fprintf_filtered (tmp_error_stream, "Error accessing memory address "); | |
5cab636d | 6789 | print_address_numeric (b->loc->address, 1, tmp_error_stream); |
81d0cc19 GS |
6790 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
6791 | safe_strerror (val)); | |
6792 | } | |
6793 | ||
6794 | fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process."); | |
c5aa993b | 6795 | target_terminal_ours_for_output (); |
81d0cc19 | 6796 | error_stream(tmp_error_stream); |
c5aa993b JM |
6797 | } |
6798 | else | |
5cab636d | 6799 | b->loc->inserted = 1; |
c5aa993b | 6800 | } |
c906108c SS |
6801 | } |
6802 | ||
6803 | free_command_lines (&bpt->commands); | |
6804 | if (bpt->cond) | |
b8c9b27d | 6805 | xfree (bpt->cond); |
c906108c | 6806 | if (bpt->cond_string != NULL) |
b8c9b27d | 6807 | xfree (bpt->cond_string); |
c906108c | 6808 | if (bpt->addr_string != NULL) |
b8c9b27d | 6809 | xfree (bpt->addr_string); |
c906108c | 6810 | if (bpt->exp != NULL) |
b8c9b27d | 6811 | xfree (bpt->exp); |
c906108c | 6812 | if (bpt->exp_string != NULL) |
b8c9b27d | 6813 | xfree (bpt->exp_string); |
c906108c SS |
6814 | if (bpt->val != NULL) |
6815 | value_free (bpt->val); | |
6816 | if (bpt->source_file != NULL) | |
b8c9b27d | 6817 | xfree (bpt->source_file); |
c906108c | 6818 | if (bpt->dll_pathname != NULL) |
b8c9b27d | 6819 | xfree (bpt->dll_pathname); |
c906108c | 6820 | if (bpt->triggered_dll_pathname != NULL) |
b8c9b27d | 6821 | xfree (bpt->triggered_dll_pathname); |
c906108c | 6822 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 6823 | xfree (bpt->exec_pathname); |
c906108c SS |
6824 | |
6825 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
6826 | /* FIXME, how can we find all bpstat's? | |
6827 | We just check stop_bpstat for now. */ | |
6828 | for (bs = stop_bpstat; bs; bs = bs->next) | |
6829 | if (bs->breakpoint_at == bpt) | |
6830 | { | |
6831 | bs->breakpoint_at = NULL; | |
c906108c | 6832 | bs->old_val = NULL; |
c2b8ed2c | 6833 | /* bs->commands will be freed later. */ |
c906108c SS |
6834 | } |
6835 | /* On the chance that someone will soon try again to delete this same | |
6836 | bp, we mark it as deleted before freeing its storage. */ | |
6837 | bpt->type = bp_none; | |
6838 | ||
5cab636d | 6839 | xfree (bpt->loc); |
b8c9b27d | 6840 | xfree (bpt); |
c906108c SS |
6841 | } |
6842 | ||
4d6140d9 AC |
6843 | static void |
6844 | do_delete_breakpoint_cleanup (void *b) | |
6845 | { | |
6846 | delete_breakpoint (b); | |
6847 | } | |
6848 | ||
6849 | struct cleanup * | |
6850 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
6851 | { | |
6852 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
6853 | } | |
6854 | ||
6855 | struct cleanup * | |
6856 | make_exec_cleanup_delete_breakpoint (struct breakpoint *b) | |
6857 | { | |
6858 | return make_exec_cleanup (do_delete_breakpoint_cleanup, b); | |
6859 | } | |
6860 | ||
c906108c | 6861 | void |
fba45db2 | 6862 | delete_command (char *arg, int from_tty) |
c906108c SS |
6863 | { |
6864 | struct breakpoint *b, *temp; | |
6865 | ||
ea9365bb TT |
6866 | dont_repeat (); |
6867 | ||
c906108c SS |
6868 | if (arg == 0) |
6869 | { | |
6870 | int breaks_to_delete = 0; | |
6871 | ||
6872 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
6873 | Do not delete internal or call-dummy breakpoints, these |
6874 | have to be deleted with an explicit breakpoint number argument. */ | |
6875 | ALL_BREAKPOINTS (b) | |
6876 | { | |
6877 | if (b->type != bp_call_dummy && | |
6878 | b->type != bp_shlib_event && | |
c4093a6a | 6879 | b->type != bp_thread_event && |
1900040c | 6880 | b->type != bp_overlay_event && |
c5aa993b JM |
6881 | b->number >= 0) |
6882 | breaks_to_delete = 1; | |
6883 | } | |
c906108c SS |
6884 | |
6885 | /* Ask user only if there are some breakpoints to delete. */ | |
6886 | if (!from_tty | |
6887 | || (breaks_to_delete && query ("Delete all breakpoints? "))) | |
6888 | { | |
c5aa993b JM |
6889 | ALL_BREAKPOINTS_SAFE (b, temp) |
6890 | { | |
6891 | if (b->type != bp_call_dummy && | |
6892 | b->type != bp_shlib_event && | |
c4093a6a | 6893 | b->type != bp_thread_event && |
1900040c | 6894 | b->type != bp_overlay_event && |
c5aa993b JM |
6895 | b->number >= 0) |
6896 | delete_breakpoint (b); | |
6897 | } | |
c906108c SS |
6898 | } |
6899 | } | |
6900 | else | |
6901 | map_breakpoint_numbers (arg, delete_breakpoint); | |
6902 | } | |
6903 | ||
6904 | /* Reset a breakpoint given it's struct breakpoint * BINT. | |
6905 | The value we return ends up being the return value from catch_errors. | |
6906 | Unused in this case. */ | |
6907 | ||
6908 | static int | |
4efb68b1 | 6909 | breakpoint_re_set_one (void *bint) |
c906108c | 6910 | { |
53a5351d JM |
6911 | /* get past catch_errs */ |
6912 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
6913 | struct value *mark; |
6914 | int i; | |
6915 | struct symtabs_and_lines sals; | |
6916 | char *s; | |
b5de0fa7 | 6917 | enum enable_state save_enable; |
c906108c SS |
6918 | |
6919 | switch (b->type) | |
6920 | { | |
6921 | case bp_none: | |
53a5351d JM |
6922 | warning ("attempted to reset apparently deleted breakpoint #%d?", |
6923 | b->number); | |
c906108c SS |
6924 | return 0; |
6925 | case bp_breakpoint: | |
6926 | case bp_hardware_breakpoint: | |
6927 | case bp_catch_load: | |
6928 | case bp_catch_unload: | |
6929 | if (b->addr_string == NULL) | |
6930 | { | |
6931 | /* Anything without a string can't be re-set. */ | |
6932 | delete_breakpoint (b); | |
6933 | return 0; | |
6934 | } | |
b18c45ed AC |
6935 | /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote: |
6936 | ||
6937 | ``And a hack it is, although Apple's Darwin version of GDB | |
6938 | contains an almost identical hack to implement a "future | |
6939 | break" command. It seems to work in many real world cases, | |
6940 | but it is easy to come up with a test case where the patch | |
6941 | doesn't help at all.'' | |
6942 | ||
6943 | ``It seems that the way GDB implements breakpoints - in - | |
6944 | shared - libraries was designed for a.out shared library | |
6945 | systems (SunOS 4) where shared libraries were loaded at a | |
6946 | fixed address in memory. Since ELF shared libraries can (and | |
6947 | will) be loaded at any address in memory, things break. | |
6948 | Fixing this is not trivial. Therefore, I'm not sure whether | |
6949 | we should add this hack to the branch only. I cannot | |
6950 | guarantee that things will be fixed on the trunk in the near | |
6951 | future.'' | |
6952 | ||
6953 | In case we have a problem, disable this breakpoint. We'll | |
6954 | restore its status if we succeed. Don't disable a | |
6955 | shlib_disabled breakpoint though. There's a fair chance we | |
6956 | can't re-set it if the shared library it's in hasn't been | |
6957 | loaded yet. */ | |
b5de0fa7 | 6958 | save_enable = b->enable_state; |
b18c45ed AC |
6959 | if (b->enable_state != bp_shlib_disabled) |
6960 | b->enable_state = bp_disabled; | |
c906108c SS |
6961 | |
6962 | set_language (b->language); | |
6963 | input_radix = b->input_radix; | |
6964 | s = b->addr_string; | |
c5aa993b | 6965 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
6966 | for (i = 0; i < sals.nelts; i++) |
6967 | { | |
6968 | resolve_sal_pc (&sals.sals[i]); | |
6969 | ||
6970 | /* Reparse conditions, they might contain references to the | |
6971 | old symtab. */ | |
6972 | if (b->cond_string != NULL) | |
6973 | { | |
6974 | s = b->cond_string; | |
6975 | if (b->cond) | |
b8c9b27d | 6976 | xfree (b->cond); |
c906108c SS |
6977 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); |
6978 | } | |
6979 | ||
c5aa993b | 6980 | /* We need to re-set the breakpoint if the address changes... */ |
5cab636d | 6981 | if (b->loc->address != sals.sals[i].pc |
c5aa993b JM |
6982 | /* ...or new and old breakpoints both have source files, and |
6983 | the source file name or the line number changes... */ | |
c906108c SS |
6984 | || (b->source_file != NULL |
6985 | && sals.sals[i].symtab != NULL | |
6986 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) | |
6987 | || b->line_number != sals.sals[i].line) | |
c906108c | 6988 | ) |
c5aa993b JM |
6989 | /* ...or we switch between having a source file and not having |
6990 | one. */ | |
6991 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) | |
6992 | ) | |
c906108c SS |
6993 | { |
6994 | if (b->source_file != NULL) | |
b8c9b27d | 6995 | xfree (b->source_file); |
c906108c SS |
6996 | if (sals.sals[i].symtab == NULL) |
6997 | b->source_file = NULL; | |
6998 | else | |
6999 | b->source_file = | |
7000 | savestring (sals.sals[i].symtab->filename, | |
7001 | strlen (sals.sals[i].symtab->filename)); | |
7002 | b->line_number = sals.sals[i].line; | |
5cab636d DJ |
7003 | b->loc->requested_address = sals.sals[i].pc; |
7004 | b->loc->address | |
7005 | = adjust_breakpoint_address (b->loc->requested_address); | |
c906108c | 7006 | |
c5aa993b | 7007 | /* Used to check for duplicates here, but that can |
261c4ca2 | 7008 | cause trouble, as it doesn't check for disabled |
c5aa993b | 7009 | breakpoints. */ |
c906108c SS |
7010 | |
7011 | mention (b); | |
7012 | ||
7013 | /* Might be better to do this just once per breakpoint_re_set, | |
c5aa993b | 7014 | rather than once for every breakpoint. */ |
c906108c SS |
7015 | breakpoints_changed (); |
7016 | } | |
cf3a9e5b | 7017 | b->loc->section = sals.sals[i].section; |
b5de0fa7 | 7018 | b->enable_state = save_enable; /* Restore it, this worked. */ |
c906108c SS |
7019 | |
7020 | ||
c5aa993b | 7021 | /* Now that this is re-enabled, check_duplicates |
c906108c | 7022 | can be used. */ |
9f60f21b | 7023 | check_duplicates (b); |
c906108c SS |
7024 | |
7025 | } | |
b8c9b27d | 7026 | xfree (sals.sals); |
c906108c SS |
7027 | break; |
7028 | ||
7029 | case bp_watchpoint: | |
7030 | case bp_hardware_watchpoint: | |
7031 | case bp_read_watchpoint: | |
7032 | case bp_access_watchpoint: | |
7033 | innermost_block = NULL; | |
53a5351d JM |
7034 | /* The issue arises of what context to evaluate this in. The |
7035 | same one as when it was set, but what does that mean when | |
7036 | symbols have been re-read? We could save the filename and | |
7037 | functionname, but if the context is more local than that, the | |
7038 | best we could do would be something like how many levels deep | |
7039 | and which index at that particular level, but that's going to | |
7040 | be less stable than filenames or function names. */ | |
7041 | ||
c906108c SS |
7042 | /* So for now, just use a global context. */ |
7043 | if (b->exp) | |
b8c9b27d | 7044 | xfree (b->exp); |
c906108c SS |
7045 | b->exp = parse_expression (b->exp_string); |
7046 | b->exp_valid_block = innermost_block; | |
7047 | mark = value_mark (); | |
7048 | if (b->val) | |
7049 | value_free (b->val); | |
7050 | b->val = evaluate_expression (b->exp); | |
7051 | release_value (b->val); | |
a881cf8e | 7052 | if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled) |
c906108c SS |
7053 | value_fetch_lazy (b->val); |
7054 | ||
7055 | if (b->cond_string != NULL) | |
7056 | { | |
7057 | s = b->cond_string; | |
7058 | if (b->cond) | |
b8c9b27d | 7059 | xfree (b->cond); |
c5aa993b | 7060 | b->cond = parse_exp_1 (&s, (struct block *) 0, 0); |
c906108c | 7061 | } |
b5de0fa7 | 7062 | if (b->enable_state == bp_enabled) |
c906108c SS |
7063 | mention (b); |
7064 | value_free_to_mark (mark); | |
7065 | break; | |
c5aa993b JM |
7066 | case bp_catch_catch: |
7067 | case bp_catch_throw: | |
c906108c | 7068 | break; |
c5aa993b JM |
7069 | /* We needn't really do anything to reset these, since the mask |
7070 | that requests them is unaffected by e.g., new libraries being | |
7071 | loaded. */ | |
c906108c SS |
7072 | case bp_catch_fork: |
7073 | case bp_catch_vfork: | |
7074 | case bp_catch_exec: | |
7075 | break; | |
c5aa993b | 7076 | |
c906108c SS |
7077 | default: |
7078 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); | |
7079 | /* fall through */ | |
1900040c MS |
7080 | /* Delete longjmp and overlay event breakpoints; they will be |
7081 | reset later by breakpoint_re_set. */ | |
c906108c SS |
7082 | case bp_longjmp: |
7083 | case bp_longjmp_resume: | |
1900040c | 7084 | case bp_overlay_event: |
c906108c SS |
7085 | delete_breakpoint (b); |
7086 | break; | |
7087 | ||
c5aa993b JM |
7088 | /* This breakpoint is special, it's set up when the inferior |
7089 | starts and we really don't want to touch it. */ | |
c906108c SS |
7090 | case bp_shlib_event: |
7091 | ||
c4093a6a JM |
7092 | /* Like bp_shlib_event, this breakpoint type is special. |
7093 | Once it is set up, we do not want to touch it. */ | |
7094 | case bp_thread_event: | |
7095 | ||
c5aa993b JM |
7096 | /* Keep temporary breakpoints, which can be encountered when we step |
7097 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7098 | Otherwise these should have been blown away via the cleanup chain | |
7099 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7100 | case bp_until: |
7101 | case bp_finish: | |
7102 | case bp_watchpoint_scope: | |
7103 | case bp_call_dummy: | |
7104 | case bp_step_resume: | |
7105 | break; | |
7106 | } | |
7107 | ||
7108 | return 0; | |
7109 | } | |
7110 | ||
7111 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
7112 | void | |
fba45db2 | 7113 | breakpoint_re_set (void) |
c906108c SS |
7114 | { |
7115 | struct breakpoint *b, *temp; | |
7116 | enum language save_language; | |
7117 | int save_input_radix; | |
c5aa993b | 7118 | |
c906108c SS |
7119 | save_language = current_language->la_language; |
7120 | save_input_radix = input_radix; | |
7121 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7122 | { |
53a5351d | 7123 | /* Format possible error msg */ |
9ebf4acf AC |
7124 | char *message = xstrprintf ("Error in re-setting breakpoint %d:\n", |
7125 | b->number); | |
7126 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 7127 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 7128 | do_cleanups (cleanups); |
c5aa993b | 7129 | } |
c906108c SS |
7130 | set_language (save_language); |
7131 | input_radix = save_input_radix; | |
7132 | ||
9df628e0 RE |
7133 | if (GET_LONGJMP_TARGET_P ()) |
7134 | { | |
7135 | create_longjmp_breakpoint ("longjmp"); | |
7136 | create_longjmp_breakpoint ("_longjmp"); | |
7137 | create_longjmp_breakpoint ("siglongjmp"); | |
7138 | create_longjmp_breakpoint ("_siglongjmp"); | |
7139 | create_longjmp_breakpoint (NULL); | |
7140 | } | |
1900040c MS |
7141 | |
7142 | create_overlay_event_breakpoint ("_ovly_debug_event"); | |
c906108c SS |
7143 | } |
7144 | \f | |
c906108c SS |
7145 | /* Reset the thread number of this breakpoint: |
7146 | ||
7147 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 7148 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 7149 | void |
fba45db2 | 7150 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
7151 | { |
7152 | if (b->thread != -1) | |
7153 | { | |
39f77062 KB |
7154 | if (in_thread_list (inferior_ptid)) |
7155 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
7156 | } |
7157 | } | |
7158 | ||
03ac34d5 MS |
7159 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7160 | If from_tty is nonzero, it prints a message to that effect, | |
7161 | which ends with a period (no newline). */ | |
7162 | ||
c906108c | 7163 | void |
fba45db2 | 7164 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 7165 | { |
52f0bd74 | 7166 | struct breakpoint *b; |
c906108c SS |
7167 | |
7168 | if (count < 0) | |
7169 | count = 0; | |
7170 | ||
7171 | ALL_BREAKPOINTS (b) | |
7172 | if (b->number == bptnum) | |
c5aa993b JM |
7173 | { |
7174 | b->ignore_count = count; | |
221ea385 KS |
7175 | if (from_tty) |
7176 | { | |
7177 | if (count == 0) | |
7178 | printf_filtered ("Will stop next time breakpoint %d is reached.", | |
7179 | bptnum); | |
7180 | else if (count == 1) | |
7181 | printf_filtered ("Will ignore next crossing of breakpoint %d.", | |
7182 | bptnum); | |
7183 | else | |
7184 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", | |
7185 | count, bptnum); | |
7186 | } | |
c5aa993b | 7187 | breakpoints_changed (); |
221ea385 | 7188 | breakpoint_modify_event (b->number); |
c5aa993b JM |
7189 | return; |
7190 | } | |
c906108c SS |
7191 | |
7192 | error ("No breakpoint number %d.", bptnum); | |
7193 | } | |
7194 | ||
7195 | /* Clear the ignore counts of all breakpoints. */ | |
7196 | void | |
fba45db2 | 7197 | breakpoint_clear_ignore_counts (void) |
c906108c SS |
7198 | { |
7199 | struct breakpoint *b; | |
7200 | ||
7201 | ALL_BREAKPOINTS (b) | |
7202 | b->ignore_count = 0; | |
7203 | } | |
7204 | ||
7205 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
7206 | ||
7207 | static void | |
fba45db2 | 7208 | ignore_command (char *args, int from_tty) |
c906108c SS |
7209 | { |
7210 | char *p = args; | |
52f0bd74 | 7211 | int num; |
c906108c SS |
7212 | |
7213 | if (p == 0) | |
7214 | error_no_arg ("a breakpoint number"); | |
c5aa993b | 7215 | |
c906108c | 7216 | num = get_number (&p); |
5c44784c JM |
7217 | if (num == 0) |
7218 | error ("bad breakpoint number: '%s'", args); | |
c906108c SS |
7219 | if (*p == 0) |
7220 | error ("Second argument (specified ignore-count) is missing."); | |
7221 | ||
7222 | set_ignore_count (num, | |
7223 | longest_to_int (value_as_long (parse_and_eval (p))), | |
7224 | from_tty); | |
221ea385 KS |
7225 | if (from_tty) |
7226 | printf_filtered ("\n"); | |
c906108c SS |
7227 | } |
7228 | \f | |
7229 | /* Call FUNCTION on each of the breakpoints | |
7230 | whose numbers are given in ARGS. */ | |
7231 | ||
7232 | static void | |
831662b3 | 7233 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 7234 | { |
52f0bd74 | 7235 | char *p = args; |
c906108c | 7236 | char *p1; |
52f0bd74 AC |
7237 | int num; |
7238 | struct breakpoint *b, *tmp; | |
11cf8741 | 7239 | int match; |
c906108c SS |
7240 | |
7241 | if (p == 0) | |
7242 | error_no_arg ("one or more breakpoint numbers"); | |
7243 | ||
7244 | while (*p) | |
7245 | { | |
11cf8741 | 7246 | match = 0; |
c906108c | 7247 | p1 = p; |
c5aa993b | 7248 | |
5c44784c JM |
7249 | num = get_number_or_range (&p1); |
7250 | if (num == 0) | |
c5aa993b | 7251 | { |
5c44784c JM |
7252 | warning ("bad breakpoint number at or near '%s'", p); |
7253 | } | |
7254 | else | |
7255 | { | |
7256 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
7257 | if (b->number == num) | |
7258 | { | |
7259 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 7260 | match = 1; |
5c44784c JM |
7261 | function (b); |
7262 | if (related_breakpoint) | |
7263 | function (related_breakpoint); | |
11cf8741 | 7264 | break; |
5c44784c | 7265 | } |
11cf8741 JM |
7266 | if (match == 0) |
7267 | printf_unfiltered ("No breakpoint number %d.\n", num); | |
c5aa993b | 7268 | } |
c906108c SS |
7269 | p = p1; |
7270 | } | |
7271 | } | |
7272 | ||
1900040c MS |
7273 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7274 | If from_tty is nonzero, it prints a message to that effect, | |
7275 | which ends with a period (no newline). */ | |
7276 | ||
c906108c | 7277 | void |
fba45db2 | 7278 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7279 | { |
7280 | /* Never disable a watchpoint scope breakpoint; we want to | |
7281 | hit them when we leave scope so we can delete both the | |
7282 | watchpoint and its scope breakpoint at that time. */ | |
7283 | if (bpt->type == bp_watchpoint_scope) | |
7284 | return; | |
7285 | ||
c2c6d25f | 7286 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 7287 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
7288 | return; |
7289 | ||
b5de0fa7 | 7290 | bpt->enable_state = bp_disabled; |
c906108c | 7291 | |
9f60f21b | 7292 | check_duplicates (bpt); |
c906108c SS |
7293 | |
7294 | if (modify_breakpoint_hook) | |
7295 | modify_breakpoint_hook (bpt); | |
104c1213 | 7296 | breakpoint_modify_event (bpt->number); |
c906108c SS |
7297 | } |
7298 | ||
c906108c | 7299 | static void |
fba45db2 | 7300 | disable_command (char *args, int from_tty) |
c906108c | 7301 | { |
52f0bd74 | 7302 | struct breakpoint *bpt; |
c906108c SS |
7303 | if (args == 0) |
7304 | ALL_BREAKPOINTS (bpt) | |
7305 | switch (bpt->type) | |
c5aa993b JM |
7306 | { |
7307 | case bp_none: | |
53a5351d JM |
7308 | warning ("attempted to disable apparently deleted breakpoint #%d?", |
7309 | bpt->number); | |
c5aa993b JM |
7310 | continue; |
7311 | case bp_breakpoint: | |
7312 | case bp_catch_load: | |
7313 | case bp_catch_unload: | |
7314 | case bp_catch_fork: | |
7315 | case bp_catch_vfork: | |
7316 | case bp_catch_exec: | |
7317 | case bp_catch_catch: | |
7318 | case bp_catch_throw: | |
7319 | case bp_hardware_breakpoint: | |
7320 | case bp_watchpoint: | |
7321 | case bp_hardware_watchpoint: | |
7322 | case bp_read_watchpoint: | |
7323 | case bp_access_watchpoint: | |
7324 | disable_breakpoint (bpt); | |
7325 | default: | |
7326 | continue; | |
7327 | } | |
c906108c SS |
7328 | else |
7329 | map_breakpoint_numbers (args, disable_breakpoint); | |
7330 | } | |
7331 | ||
7332 | static void | |
fba45db2 | 7333 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c SS |
7334 | { |
7335 | struct frame_info *save_selected_frame = NULL; | |
7336 | int save_selected_frame_level = -1; | |
7337 | int target_resources_ok, other_type_used; | |
7338 | struct value *mark; | |
7339 | ||
7340 | if (bpt->type == bp_hardware_breakpoint) | |
7341 | { | |
7342 | int i; | |
c5aa993b | 7343 | i = hw_breakpoint_used_count (); |
53a5351d JM |
7344 | target_resources_ok = |
7345 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
7346 | i + 1, 0); | |
c906108c | 7347 | if (target_resources_ok == 0) |
c5aa993b | 7348 | error ("No hardware breakpoint support in the target."); |
c906108c | 7349 | else if (target_resources_ok < 0) |
c5aa993b | 7350 | error ("Hardware breakpoints used exceeds limit."); |
c906108c SS |
7351 | } |
7352 | ||
b5de0fa7 EZ |
7353 | if (bpt->enable_state != bp_permanent) |
7354 | bpt->enable_state = bp_enabled; | |
c906108c | 7355 | bpt->disposition = disposition; |
9f60f21b | 7356 | check_duplicates (bpt); |
c906108c SS |
7357 | breakpoints_changed (); |
7358 | ||
53a5351d JM |
7359 | if (bpt->type == bp_watchpoint || |
7360 | bpt->type == bp_hardware_watchpoint || | |
7361 | bpt->type == bp_read_watchpoint || | |
7362 | bpt->type == bp_access_watchpoint) | |
c906108c SS |
7363 | { |
7364 | if (bpt->exp_valid_block != NULL) | |
7365 | { | |
7366 | struct frame_info *fr = | |
101dcfbe | 7367 | fr = frame_find_by_id (bpt->watchpoint_frame); |
c906108c SS |
7368 | if (fr == NULL) |
7369 | { | |
7370 | printf_filtered ("\ | |
7371 | Cannot enable watchpoint %d because the block in which its expression\n\ | |
7372 | is valid is not currently in scope.\n", bpt->number); | |
b5de0fa7 | 7373 | bpt->enable_state = bp_disabled; |
c906108c SS |
7374 | return; |
7375 | } | |
7376 | ||
6e7f8b9c AC |
7377 | save_selected_frame = deprecated_selected_frame; |
7378 | save_selected_frame_level = frame_relative_level (deprecated_selected_frame); | |
0f7d239c | 7379 | select_frame (fr); |
c906108c SS |
7380 | } |
7381 | ||
7382 | value_free (bpt->val); | |
7383 | mark = value_mark (); | |
7384 | bpt->val = evaluate_expression (bpt->exp); | |
7385 | release_value (bpt->val); | |
7386 | if (VALUE_LAZY (bpt->val)) | |
7387 | value_fetch_lazy (bpt->val); | |
7388 | ||
7389 | if (bpt->type == bp_hardware_watchpoint || | |
c5aa993b JM |
7390 | bpt->type == bp_read_watchpoint || |
7391 | bpt->type == bp_access_watchpoint) | |
7392 | { | |
7393 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); | |
7394 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); | |
7395 | ||
7396 | /* Hack around 'unused var' error for some targets here */ | |
7397 | (void) mem_cnt, i; | |
7398 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( | |
7399 | bpt->type, i + mem_cnt, other_type_used); | |
7400 | /* we can consider of type is bp_hardware_watchpoint, convert to | |
7401 | bp_watchpoint in the following condition */ | |
7402 | if (target_resources_ok < 0) | |
7403 | { | |
7404 | printf_filtered ("\ | |
c906108c SS |
7405 | Cannot enable watchpoint %d because target watch resources\n\ |
7406 | have been allocated for other watchpoints.\n", bpt->number); | |
b5de0fa7 | 7407 | bpt->enable_state = bp_disabled; |
c5aa993b JM |
7408 | value_free_to_mark (mark); |
7409 | return; | |
7410 | } | |
7411 | } | |
c906108c SS |
7412 | |
7413 | if (save_selected_frame_level >= 0) | |
0f7d239c | 7414 | select_frame (save_selected_frame); |
c906108c SS |
7415 | value_free_to_mark (mark); |
7416 | } | |
7417 | if (modify_breakpoint_hook) | |
7418 | modify_breakpoint_hook (bpt); | |
104c1213 | 7419 | breakpoint_modify_event (bpt->number); |
c906108c SS |
7420 | } |
7421 | ||
7422 | void | |
fba45db2 | 7423 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7424 | { |
7425 | do_enable_breakpoint (bpt, bpt->disposition); | |
7426 | } | |
7427 | ||
7428 | /* The enable command enables the specified breakpoints (or all defined | |
7429 | breakpoints) so they once again become (or continue to be) effective | |
7430 | in stopping the inferior. */ | |
7431 | ||
c906108c | 7432 | static void |
fba45db2 | 7433 | enable_command (char *args, int from_tty) |
c906108c | 7434 | { |
52f0bd74 | 7435 | struct breakpoint *bpt; |
c906108c SS |
7436 | if (args == 0) |
7437 | ALL_BREAKPOINTS (bpt) | |
7438 | switch (bpt->type) | |
c5aa993b JM |
7439 | { |
7440 | case bp_none: | |
53a5351d JM |
7441 | warning ("attempted to enable apparently deleted breakpoint #%d?", |
7442 | bpt->number); | |
c5aa993b JM |
7443 | continue; |
7444 | case bp_breakpoint: | |
7445 | case bp_catch_load: | |
7446 | case bp_catch_unload: | |
7447 | case bp_catch_fork: | |
7448 | case bp_catch_vfork: | |
7449 | case bp_catch_exec: | |
7450 | case bp_catch_catch: | |
7451 | case bp_catch_throw: | |
7452 | case bp_hardware_breakpoint: | |
7453 | case bp_watchpoint: | |
7454 | case bp_hardware_watchpoint: | |
7455 | case bp_read_watchpoint: | |
7456 | case bp_access_watchpoint: | |
7457 | enable_breakpoint (bpt); | |
7458 | default: | |
7459 | continue; | |
7460 | } | |
c906108c SS |
7461 | else |
7462 | map_breakpoint_numbers (args, enable_breakpoint); | |
7463 | } | |
7464 | ||
7465 | static void | |
fba45db2 | 7466 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 7467 | { |
b5de0fa7 | 7468 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
7469 | } |
7470 | ||
c906108c | 7471 | static void |
fba45db2 | 7472 | enable_once_command (char *args, int from_tty) |
c906108c SS |
7473 | { |
7474 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
7475 | } | |
7476 | ||
7477 | static void | |
fba45db2 | 7478 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7479 | { |
b5de0fa7 | 7480 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
7481 | } |
7482 | ||
c906108c | 7483 | static void |
fba45db2 | 7484 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
7485 | { |
7486 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
7487 | } | |
7488 | \f | |
7489 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ | |
7490 | ||
7491 | struct symtabs_and_lines | |
fba45db2 | 7492 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
7493 | { |
7494 | struct symtabs_and_lines sals; | |
7495 | if (string == 0) | |
7496 | error ("Empty line specification."); | |
7497 | if (default_breakpoint_valid) | |
7498 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
7499 | default_breakpoint_symtab, |
7500 | default_breakpoint_line, | |
c5aa993b | 7501 | (char ***) NULL); |
c906108c SS |
7502 | else |
7503 | sals = decode_line_1 (&string, funfirstline, | |
c5aa993b | 7504 | (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
7505 | if (*string) |
7506 | error ("Junk at end of line specification: %s", string); | |
7507 | return sals; | |
7508 | } | |
7509 | \f | |
7510 | void | |
fba45db2 | 7511 | _initialize_breakpoint (void) |
c906108c SS |
7512 | { |
7513 | struct cmd_list_element *c; | |
7514 | ||
7515 | breakpoint_chain = 0; | |
7516 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
7517 | before a breakpoint is set. */ | |
7518 | breakpoint_count = 0; | |
7519 | ||
7520 | add_com ("ignore", class_breakpoint, ignore_command, | |
7521 | "Set ignore-count of breakpoint number N to COUNT.\n\ | |
7522 | Usage is `ignore N COUNT'."); | |
7523 | if (xdb_commands) | |
c5aa993b | 7524 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c SS |
7525 | |
7526 | add_com ("commands", class_breakpoint, commands_command, | |
7527 | "Set commands to be executed when a breakpoint is hit.\n\ | |
7528 | Give breakpoint number as argument after \"commands\".\n\ | |
7529 | With no argument, the targeted breakpoint is the last one set.\n\ | |
7530 | The commands themselves follow starting on the next line.\n\ | |
7531 | Type a line containing \"end\" to indicate the end of them.\n\ | |
7532 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
7533 | then no output is printed when it is hit, except what the commands print."); | |
7534 | ||
7535 | add_com ("condition", class_breakpoint, condition_command, | |
7536 | "Specify breakpoint number N to break only if COND is true.\n\ | |
7537 | Usage is `condition N COND', where N is an integer and COND is an\n\ | |
d4654627 | 7538 | expression to be evaluated whenever breakpoint N is reached."); |
c906108c | 7539 | |
c94fdfd0 EZ |
7540 | c = add_com ("tbreak", class_breakpoint, tbreak_command, |
7541 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7542 | Like \"break\" except the breakpoint is only temporary,\n\ |
7543 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
7544 | by using \"enable delete\" on the breakpoint number."); | |
5ba2abeb | 7545 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 7546 | |
c94fdfd0 EZ |
7547 | c = add_com ("hbreak", class_breakpoint, hbreak_command, |
7548 | "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7549 | Like \"break\" except the breakpoint requires hardware support,\n\ |
7550 | some target hardware may not have this support."); | |
5ba2abeb | 7551 | set_cmd_completer (c, location_completer); |
c906108c | 7552 | |
c94fdfd0 EZ |
7553 | c = add_com ("thbreak", class_breakpoint, thbreak_command, |
7554 | "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7555 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
7556 | so it will be deleted when hit."); | |
5ba2abeb | 7557 | set_cmd_completer (c, location_completer); |
c906108c SS |
7558 | |
7559 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
7560 | "Enable some breakpoints.\n\ | |
7561 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
7562 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
7563 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7564 | With a subcommand you can enable temporarily.", | |
7565 | &enablelist, "enable ", 1, &cmdlist); | |
7566 | if (xdb_commands) | |
c5aa993b JM |
7567 | add_com ("ab", class_breakpoint, enable_command, |
7568 | "Enable some breakpoints.\n\ | |
c906108c SS |
7569 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
7570 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
7571 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7572 | With a subcommand you can enable temporarily."); | |
7573 | ||
7574 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
7575 | ||
7576 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
c5aa993b | 7577 | "Enable some breakpoints.\n\ |
c906108c SS |
7578 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
7579 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7580 | May be abbreviated to simply \"enable\".\n", | |
c5aa993b | 7581 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c SS |
7582 | |
7583 | add_cmd ("once", no_class, enable_once_command, | |
7584 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
7585 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
7586 | &enablebreaklist); | |
7587 | ||
7588 | add_cmd ("delete", no_class, enable_delete_command, | |
7589 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
7590 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
7591 | &enablebreaklist); | |
7592 | ||
7593 | add_cmd ("delete", no_class, enable_delete_command, | |
7594 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
7595 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
7596 | &enablelist); | |
7597 | ||
7598 | add_cmd ("once", no_class, enable_once_command, | |
7599 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
7600 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
7601 | &enablelist); | |
7602 | ||
7603 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
c5aa993b | 7604 | "Disable some breakpoints.\n\ |
c906108c SS |
7605 | Arguments are breakpoint numbers with spaces in between.\n\ |
7606 | To disable all breakpoints, give no argument.\n\ | |
7607 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
7608 | &disablelist, "disable ", 1, &cmdlist); | |
7609 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
7610 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
7611 | if (xdb_commands) | |
c5aa993b JM |
7612 | add_com ("sb", class_breakpoint, disable_command, |
7613 | "Disable some breakpoints.\n\ | |
c906108c SS |
7614 | Arguments are breakpoint numbers with spaces in between.\n\ |
7615 | To disable all breakpoints, give no argument.\n\ | |
7616 | A disabled breakpoint is not forgotten, but has no effect until reenabled."); | |
7617 | ||
7618 | add_cmd ("breakpoints", class_alias, disable_command, | |
7619 | "Disable some breakpoints.\n\ | |
7620 | Arguments are breakpoint numbers with spaces in between.\n\ | |
7621 | To disable all breakpoints, give no argument.\n\ | |
7622 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
7623 | This command may be abbreviated \"disable\".", | |
7624 | &disablelist); | |
7625 | ||
7626 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
c5aa993b | 7627 | "Delete some breakpoints or auto-display expressions.\n\ |
c906108c SS |
7628 | Arguments are breakpoint numbers with spaces in between.\n\ |
7629 | To delete all breakpoints, give no argument.\n\ | |
7630 | \n\ | |
7631 | Also a prefix command for deletion of other GDB objects.\n\ | |
7632 | The \"unset\" command is also an alias for \"delete\".", | |
7633 | &deletelist, "delete ", 1, &cmdlist); | |
7634 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7635 | if (xdb_commands) | |
7636 | add_com ("db", class_breakpoint, delete_command, | |
c5aa993b | 7637 | "Delete some breakpoints.\n\ |
c906108c SS |
7638 | Arguments are breakpoint numbers with spaces in between.\n\ |
7639 | To delete all breakpoints, give no argument.\n"); | |
7640 | ||
7641 | add_cmd ("breakpoints", class_alias, delete_command, | |
7642 | "Delete some breakpoints or auto-display expressions.\n\ | |
7643 | Arguments are breakpoint numbers with spaces in between.\n\ | |
7644 | To delete all breakpoints, give no argument.\n\ | |
7645 | This command may be abbreviated \"delete\".", | |
7646 | &deletelist); | |
7647 | ||
7648 | add_com ("clear", class_breakpoint, clear_command, | |
7649 | concat ("Clear breakpoint at specified line or function.\n\ | |
7650 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
7651 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
7652 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
7653 | If an address is specified, breakpoints at that address are cleared.\n\n", | |
c5aa993b | 7654 | "With no argument, clears all breakpoints in the line that the selected frame\n\ |
c906108c SS |
7655 | is executing in.\n\ |
7656 | \n\ | |
7657 | See also the \"delete\" command which clears breakpoints by number.", NULL)); | |
7658 | ||
c94fdfd0 EZ |
7659 | c = add_com ("break", class_breakpoint, break_command, |
7660 | concat ("Set breakpoint at specified line or function.\n\ | |
c906108c SS |
7661 | Argument may be line number, function name, or \"*\" and an address.\n\ |
7662 | If line number is specified, break at start of code for that line.\n\ | |
7663 | If function is specified, break at start of code for that function.\n\ | |
7664 | If an address is specified, break at that exact address.\n", | |
c5aa993b | 7665 | "With no arg, uses current execution address of selected stack frame.\n\ |
c906108c SS |
7666 | This is useful for breaking on return to a stack frame.\n\ |
7667 | \n\ | |
7668 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
7669 | \n\ | |
7670 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); | |
5ba2abeb | 7671 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 7672 | |
c906108c SS |
7673 | add_com_alias ("b", "break", class_run, 1); |
7674 | add_com_alias ("br", "break", class_run, 1); | |
7675 | add_com_alias ("bre", "break", class_run, 1); | |
7676 | add_com_alias ("brea", "break", class_run, 1); | |
7677 | ||
502fd408 | 7678 | if (xdb_commands) |
c906108c SS |
7679 | { |
7680 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
7681 | add_com_alias ("bu", "ubreak", class_breakpoint, 1); | |
c906108c SS |
7682 | } |
7683 | ||
7684 | if (dbx_commands) | |
7685 | { | |
c5aa993b JM |
7686 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, |
7687 | "Break in function/address or break at a line in the current file.", | |
7688 | &stoplist, "stop ", 1, &cmdlist); | |
7689 | add_cmd ("in", class_breakpoint, stopin_command, | |
7690 | "Break in function or address.\n", &stoplist); | |
7691 | add_cmd ("at", class_breakpoint, stopat_command, | |
7692 | "Break at a line in the current file.\n", &stoplist); | |
7693 | add_com ("status", class_info, breakpoints_info, | |
7694 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
7695 | The \"Type\" column indicates one of:\n\ |
7696 | \tbreakpoint - normal breakpoint\n\ | |
7697 | \twatchpoint - watchpoint\n\ | |
7698 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7699 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7700 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7701 | address and file/line number respectively.\n\n", | |
c5aa993b | 7702 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7703 | are set to the address of the last breakpoint listed.\n\n\ |
7704 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7705 | breakpoint set.", NULL)); | |
7706 | } | |
7707 | ||
7708 | add_info ("breakpoints", breakpoints_info, | |
7709 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
7710 | The \"Type\" column indicates one of:\n\ | |
7711 | \tbreakpoint - normal breakpoint\n\ | |
7712 | \twatchpoint - watchpoint\n\ | |
7713 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7714 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7715 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7716 | address and file/line number respectively.\n\n", | |
c5aa993b | 7717 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7718 | are set to the address of the last breakpoint listed.\n\n\ |
7719 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7720 | breakpoint set.", NULL)); | |
7721 | ||
7722 | if (xdb_commands) | |
c5aa993b JM |
7723 | add_com ("lb", class_breakpoint, breakpoints_info, |
7724 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
7725 | The \"Type\" column indicates one of:\n\ |
7726 | \tbreakpoint - normal breakpoint\n\ | |
7727 | \twatchpoint - watchpoint\n\ | |
7728 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7729 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7730 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7731 | address and file/line number respectively.\n\n", | |
c5aa993b | 7732 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7733 | are set to the address of the last breakpoint listed.\n\n\ |
7734 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7735 | breakpoint set.", NULL)); | |
7736 | ||
c906108c | 7737 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, |
c5aa993b | 7738 | concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
7739 | The \"Type\" column indicates one of:\n\ |
7740 | \tbreakpoint - normal breakpoint\n\ | |
7741 | \twatchpoint - watchpoint\n\ | |
7742 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
7743 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
7744 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
7745 | \tfinish - internal breakpoint used by the \"finish\" command\n", | |
c5aa993b | 7746 | "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
c906108c SS |
7747 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
7748 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7749 | address and file/line number respectively.\n\n", | |
c5aa993b | 7750 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7751 | are set to the address of the last breakpoint listed.\n\n\ |
7752 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7753 | breakpoint set.", NULL), | |
7754 | &maintenanceinfolist); | |
7755 | ||
c906108c | 7756 | add_com ("catch", class_breakpoint, catch_command, |
c5aa993b | 7757 | "Set catchpoints to catch events.\n\ |
c906108c SS |
7758 | Raised signals may be caught:\n\ |
7759 | \tcatch signal - all signals\n\ | |
7760 | \tcatch signal <signame> - a particular signal\n\ | |
7761 | Raised exceptions may be caught:\n\ | |
7762 | \tcatch throw - all exceptions, when thrown\n\ | |
7763 | \tcatch throw <exceptname> - a particular exception, when thrown\n\ | |
7764 | \tcatch catch - all exceptions, when caught\n\ | |
7765 | \tcatch catch <exceptname> - a particular exception, when caught\n\ | |
7766 | Thread or process events may be caught:\n\ | |
7767 | \tcatch thread_start - any threads, just after creation\n\ | |
7768 | \tcatch thread_exit - any threads, just before expiration\n\ | |
7769 | \tcatch thread_join - any threads, just after joins\n\ | |
7770 | Process events may be caught:\n\ | |
7771 | \tcatch start - any processes, just after creation\n\ | |
7772 | \tcatch exit - any processes, just before expiration\n\ | |
7773 | \tcatch fork - calls to fork()\n\ | |
7774 | \tcatch vfork - calls to vfork()\n\ | |
7775 | \tcatch exec - calls to exec()\n\ | |
7776 | Dynamically-linked library events may be caught:\n\ | |
7777 | \tcatch load - loads of any library\n\ | |
7778 | \tcatch load <libname> - loads of a particular library\n\ | |
7779 | \tcatch unload - unloads of any library\n\ | |
7780 | \tcatch unload <libname> - unloads of a particular library\n\ | |
7781 | The act of your program's execution stopping may also be caught:\n\ | |
7782 | \tcatch stop\n\n\ | |
7783 | C++ exceptions may be caught:\n\ | |
7784 | \tcatch throw - all exceptions, when thrown\n\ | |
7785 | \tcatch catch - all exceptions, when caught\n\ | |
7786 | \n\ | |
7787 | Do \"help set follow-fork-mode\" for info on debugging your program\n\ | |
7788 | after a fork or vfork is caught.\n\n\ | |
7789 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
c5aa993b | 7790 | |
c906108c | 7791 | add_com ("tcatch", class_breakpoint, tcatch_command, |
c5aa993b | 7792 | "Set temporary catchpoints to catch events.\n\ |
c906108c SS |
7793 | Args like \"catch\" command.\n\ |
7794 | Like \"catch\" except the catchpoint is only temporary,\n\ | |
7795 | so it will be deleted when hit. Equivalent to \"catch\" followed\n\ | |
7796 | by using \"enable delete\" on the catchpoint number."); | |
c5aa993b | 7797 | |
c94fdfd0 EZ |
7798 | c = add_com ("watch", class_breakpoint, watch_command, |
7799 | "Set a watchpoint for an expression.\n\ | |
c906108c SS |
7800 | A watchpoint stops execution of your program whenever the value of\n\ |
7801 | an expression changes."); | |
5ba2abeb | 7802 | set_cmd_completer (c, location_completer); |
c906108c | 7803 | |
c94fdfd0 EZ |
7804 | c = add_com ("rwatch", class_breakpoint, rwatch_command, |
7805 | "Set a read watchpoint for an expression.\n\ | |
c906108c SS |
7806 | A watchpoint stops execution of your program whenever the value of\n\ |
7807 | an expression is read."); | |
5ba2abeb | 7808 | set_cmd_completer (c, location_completer); |
c906108c | 7809 | |
c94fdfd0 EZ |
7810 | c = add_com ("awatch", class_breakpoint, awatch_command, |
7811 | "Set a watchpoint for an expression.\n\ | |
c906108c SS |
7812 | A watchpoint stops execution of your program whenever the value of\n\ |
7813 | an expression is either read or written."); | |
5ba2abeb | 7814 | set_cmd_completer (c, location_completer); |
c906108c SS |
7815 | |
7816 | add_info ("watchpoints", breakpoints_info, | |
7817 | "Synonym for ``info breakpoints''."); | |
7818 | ||
7819 | ||
7820 | c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger, | |
c5aa993b JM |
7821 | (char *) &can_use_hw_watchpoints, |
7822 | "Set debugger's willingness to use watchpoint hardware.\n\ | |
c906108c SS |
7823 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
7824 | such is available. (However, any hardware watchpoints that were\n\ | |
7825 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
7826 | hardware.)", | |
c5aa993b | 7827 | &setlist); |
c906108c SS |
7828 | add_show_from_set (c, &showlist); |
7829 | ||
7830 | can_use_hw_watchpoints = 1; | |
7831 | } |