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