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