]>
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: | |
3086aeae DJ |
2274 | /* Normal case. Call the breakpoint's print_it method, or |
2275 | print_it_typical. */ | |
2276 | if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL | |
2277 | && bs->breakpoint_at->ops->print_it != NULL) | |
2278 | return bs->breakpoint_at->ops->print_it (bs->breakpoint_at); | |
2279 | else | |
2280 | return print_it_typical (bs); | |
e514a9d6 | 2281 | break; |
3086aeae | 2282 | |
e514a9d6 | 2283 | default: |
8e65ff28 AC |
2284 | internal_error (__FILE__, __LINE__, |
2285 | "print_bp_stop_message: unrecognized enum value"); | |
e514a9d6 | 2286 | break; |
c906108c | 2287 | } |
c906108c SS |
2288 | } |
2289 | ||
e514a9d6 JM |
2290 | /* Print a message indicating what happened. This is called from |
2291 | normal_stop(). The input to this routine is the head of the bpstat | |
2292 | list - a list of the eventpoints that caused this stop. This | |
2293 | routine calls the generic print routine for printing a message | |
2294 | about reasons for stopping. This will print (for example) the | |
2295 | "Breakpoint n," part of the output. The return value of this | |
2296 | routine is one of: | |
c906108c | 2297 | |
917317f4 JM |
2298 | PRINT_UNKNOWN: Means we printed nothing |
2299 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2300 | code to print the location. An example is |
2301 | "Breakpoint 1, " which should be followed by | |
2302 | the location. | |
917317f4 | 2303 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2304 | to also print the location part of the message. |
2305 | An example is the catch/throw messages, which | |
917317f4 JM |
2306 | don't require a location appended to the end. |
2307 | PRINT_NOTHING: We have done some printing and we don't need any | |
2308 | further info to be printed.*/ | |
c906108c | 2309 | |
917317f4 | 2310 | enum print_stop_action |
fba45db2 | 2311 | bpstat_print (bpstat bs) |
c906108c SS |
2312 | { |
2313 | int val; | |
c5aa993b | 2314 | |
c906108c | 2315 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2316 | (Currently all watchpoints go on the bpstat whether hit or not. |
2317 | That probably could (should) be changed, provided care is taken | |
c906108c | 2318 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2319 | for (; bs; bs = bs->next) |
2320 | { | |
2321 | val = print_bp_stop_message (bs); | |
2322 | if (val == PRINT_SRC_ONLY | |
2323 | || val == PRINT_SRC_AND_LOC | |
2324 | || val == PRINT_NOTHING) | |
2325 | return val; | |
2326 | } | |
c906108c | 2327 | |
e514a9d6 JM |
2328 | /* We reached the end of the chain, or we got a null BS to start |
2329 | with and nothing was printed. */ | |
917317f4 | 2330 | return PRINT_UNKNOWN; |
c906108c SS |
2331 | } |
2332 | ||
2333 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2334 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2335 | The argument is a "struct expression *" that has been cast to char * to | |
2336 | make it pass through catch_errors. */ | |
2337 | ||
2338 | static int | |
4efb68b1 | 2339 | breakpoint_cond_eval (void *exp) |
c906108c | 2340 | { |
278cd55f | 2341 | struct value *mark = value_mark (); |
c5aa993b | 2342 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2343 | value_free_to_mark (mark); |
2344 | return i; | |
2345 | } | |
2346 | ||
2347 | /* Allocate a new bpstat and chain it to the current one. */ | |
2348 | ||
2349 | static bpstat | |
831662b3 | 2350 | bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2351 | { |
2352 | bpstat bs; | |
2353 | ||
2354 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2355 | cbs->next = bs; | |
2356 | bs->breakpoint_at = b; | |
2357 | /* If the condition is false, etc., don't do the commands. */ | |
2358 | bs->commands = NULL; | |
2359 | bs->old_val = NULL; | |
2360 | bs->print_it = print_it_normal; | |
2361 | return bs; | |
2362 | } | |
2363 | \f | |
2364 | /* Possible return values for watchpoint_check (this can't be an enum | |
2365 | because of check_errors). */ | |
2366 | /* The watchpoint has been deleted. */ | |
2367 | #define WP_DELETED 1 | |
2368 | /* The value has changed. */ | |
2369 | #define WP_VALUE_CHANGED 2 | |
2370 | /* The value has not changed. */ | |
2371 | #define WP_VALUE_NOT_CHANGED 3 | |
2372 | ||
2373 | #define BP_TEMPFLAG 1 | |
2374 | #define BP_HARDWAREFLAG 2 | |
2375 | ||
2376 | /* Check watchpoint condition. */ | |
2377 | ||
2378 | static int | |
4efb68b1 | 2379 | watchpoint_check (void *p) |
c906108c SS |
2380 | { |
2381 | bpstat bs = (bpstat) p; | |
2382 | struct breakpoint *b; | |
2383 | struct frame_info *fr; | |
2384 | int within_current_scope; | |
2385 | ||
2386 | b = bs->breakpoint_at; | |
2387 | ||
2388 | if (b->exp_valid_block == NULL) | |
2389 | within_current_scope = 1; | |
2390 | else | |
2391 | { | |
2392 | /* There is no current frame at this moment. If we're going to have | |
c5aa993b JM |
2393 | any chance of handling watchpoints on local variables, we'll need |
2394 | the frame chain (so we can determine if we're in scope). */ | |
2395 | reinit_frame_cache (); | |
101dcfbe | 2396 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2397 | within_current_scope = (fr != NULL); |
c12260ac CV |
2398 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2399 | in the function but the stack frame has already been invalidated. | |
2400 | Since we can't rely on the values of local variables after the | |
2401 | stack has been destroyed, we are treating the watchpoint in that | |
2402 | state as `not changed' without further checking. */ | |
2403 | if (within_current_scope && fr == get_current_frame () | |
2404 | && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ())) | |
2405 | return WP_VALUE_NOT_CHANGED; | |
c906108c SS |
2406 | if (within_current_scope) |
2407 | /* If we end up stopping, the current frame will get selected | |
2408 | in normal_stop. So this call to select_frame won't affect | |
2409 | the user. */ | |
0f7d239c | 2410 | select_frame (fr); |
c906108c | 2411 | } |
c5aa993b | 2412 | |
c906108c SS |
2413 | if (within_current_scope) |
2414 | { | |
2415 | /* We use value_{,free_to_}mark because it could be a | |
2416 | *long* time before we return to the command level and | |
c5aa993b JM |
2417 | call free_all_values. We can't call free_all_values because |
2418 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2419 | |
278cd55f AC |
2420 | struct value *mark = value_mark (); |
2421 | struct value *new_val = evaluate_expression (bs->breakpoint_at->exp); | |
c906108c SS |
2422 | if (!value_equal (b->val, new_val)) |
2423 | { | |
2424 | release_value (new_val); | |
2425 | value_free_to_mark (mark); | |
2426 | bs->old_val = b->val; | |
2427 | b->val = new_val; | |
2428 | /* We will stop here */ | |
2429 | return WP_VALUE_CHANGED; | |
2430 | } | |
2431 | else | |
2432 | { | |
2433 | /* Nothing changed, don't do anything. */ | |
2434 | value_free_to_mark (mark); | |
2435 | /* We won't stop here */ | |
2436 | return WP_VALUE_NOT_CHANGED; | |
2437 | } | |
2438 | } | |
2439 | else | |
2440 | { | |
2441 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2442 | if we temporarily ignored the watchpoint, then when |
2443 | we reenter the block in which it is valid it contains | |
2444 | garbage (in the case of a function, it may have two | |
2445 | garbage values, one before and one after the prologue). | |
2446 | So we can't even detect the first assignment to it and | |
2447 | watch after that (since the garbage may or may not equal | |
2448 | the first value assigned). */ | |
4ce44c66 JM |
2449 | /* We print all the stop information in print_it_typical(), but |
2450 | in this case, by the time we call print_it_typical() this bp | |
2451 | will be deleted already. So we have no choice but print the | |
2452 | information here. */ | |
9dc5e2a9 | 2453 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2454 | ui_out_field_string (uiout, "reason", "watchpoint-scope"); |
8b93c638 JM |
2455 | ui_out_text (uiout, "\nWatchpoint "); |
2456 | ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number); | |
2457 | ui_out_text (uiout, " deleted because the program has left the block in\n\ | |
2458 | which its expression is valid.\n"); | |
4ce44c66 | 2459 | |
c906108c | 2460 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2461 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2462 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2463 | |
2464 | return WP_DELETED; | |
2465 | } | |
2466 | } | |
2467 | ||
c906108c SS |
2468 | /* Get a bpstat associated with having just stopped at address *PC |
2469 | and frame address CORE_ADDRESS. Update *PC to point at the | |
6e31adb3 | 2470 | breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero |
c906108c SS |
2471 | if this is known to not be a real breakpoint (it could still be a |
2472 | watchpoint, though). */ | |
2473 | ||
2474 | /* Determine whether we stopped at a breakpoint, etc, or whether we | |
2475 | don't understand this stop. Result is a chain of bpstat's such that: | |
2476 | ||
c5aa993b | 2477 | if we don't understand the stop, the result is a null pointer. |
c906108c | 2478 | |
c5aa993b | 2479 | if we understand why we stopped, the result is not null. |
c906108c | 2480 | |
c5aa993b JM |
2481 | Each element of the chain refers to a particular breakpoint or |
2482 | watchpoint at which we have stopped. (We may have stopped for | |
2483 | several reasons concurrently.) | |
c906108c | 2484 | |
c5aa993b JM |
2485 | Each element of the chain has valid next, breakpoint_at, |
2486 | commands, FIXME??? fields. */ | |
c906108c SS |
2487 | |
2488 | bpstat | |
6e31adb3 | 2489 | bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint) |
c906108c SS |
2490 | { |
2491 | register struct breakpoint *b, *temp; | |
2492 | CORE_ADDR bp_addr; | |
2493 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ | |
2494 | int real_breakpoint = 0; | |
2495 | /* Root of the chain of bpstat's */ | |
2496 | struct bpstats root_bs[1]; | |
2497 | /* Pointer to the last thing in the chain currently. */ | |
2498 | bpstat bs = root_bs; | |
2499 | static char message1[] = | |
c5aa993b JM |
2500 | "Error evaluating expression for watchpoint %d\n"; |
2501 | char message[sizeof (message1) + 30 /* slop */ ]; | |
c906108c | 2502 | |
6e31adb3 AC |
2503 | /* Get the address where the breakpoint would have been. The |
2504 | "not_a_sw_breakpoint" argument is meant to distinguish between a | |
2505 | breakpoint trap event and a trace/singlestep trap event. For a | |
2506 | trace/singlestep trap event, we would not want to subtract | |
2507 | DECR_PC_AFTER_BREAK from the PC. */ | |
80b34fab | 2508 | |
c8edd8b4 | 2509 | bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK); |
c906108c SS |
2510 | |
2511 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2512 | { |
b5de0fa7 EZ |
2513 | if (b->enable_state == bp_disabled |
2514 | || b->enable_state == bp_shlib_disabled | |
2515 | || b->enable_state == bp_call_disabled) | |
c5aa993b JM |
2516 | continue; |
2517 | ||
2518 | if (b->type != bp_watchpoint | |
2519 | && b->type != bp_hardware_watchpoint | |
2520 | && b->type != bp_read_watchpoint | |
2521 | && b->type != bp_access_watchpoint | |
2522 | && b->type != bp_hardware_breakpoint | |
2523 | && b->type != bp_catch_fork | |
2524 | && b->type != bp_catch_vfork | |
2525 | && b->type != bp_catch_exec | |
2526 | && b->type != bp_catch_catch | |
2527 | && b->type != bp_catch_throw) /* a non-watchpoint bp */ | |
9f04af04 MS |
2528 | { |
2529 | if (b->address != bp_addr) /* address doesn't match */ | |
2530 | continue; | |
2531 | if (overlay_debugging /* unmapped overlay section */ | |
2532 | && section_is_overlay (b->section) | |
2533 | && !section_is_mapped (b->section)) | |
2534 | continue; | |
2535 | } | |
c906108c | 2536 | |
c02f5703 MS |
2537 | if (b->type == bp_hardware_breakpoint) |
2538 | { | |
2539 | if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK)) | |
2540 | continue; | |
2541 | if (overlay_debugging /* unmapped overlay section */ | |
2542 | && section_is_overlay (b->section) | |
2543 | && !section_is_mapped (b->section)) | |
2544 | continue; | |
2545 | } | |
c5aa993b | 2546 | |
c5aa993b JM |
2547 | /* Is this a catchpoint of a load or unload? If so, did we |
2548 | get a load or unload of the specified library? If not, | |
2549 | ignore it. */ | |
2550 | if ((b->type == bp_catch_load) | |
c906108c | 2551 | #if defined(SOLIB_HAVE_LOAD_EVENT) |
39f77062 | 2552 | && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid)) |
c5aa993b | 2553 | || ((b->dll_pathname != NULL) |
53a5351d | 2554 | && (strcmp (b->dll_pathname, |
39f77062 KB |
2555 | SOLIB_LOADED_LIBRARY_PATHNAME ( |
2556 | PIDGET (inferior_ptid))) | |
53a5351d | 2557 | != 0))) |
c906108c | 2558 | #endif |
c5aa993b JM |
2559 | ) |
2560 | continue; | |
2561 | ||
2562 | if ((b->type == bp_catch_unload) | |
c906108c | 2563 | #if defined(SOLIB_HAVE_UNLOAD_EVENT) |
39f77062 | 2564 | && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid)) |
c5aa993b | 2565 | || ((b->dll_pathname != NULL) |
53a5351d | 2566 | && (strcmp (b->dll_pathname, |
39f77062 KB |
2567 | SOLIB_UNLOADED_LIBRARY_PATHNAME ( |
2568 | PIDGET (inferior_ptid))) | |
53a5351d | 2569 | != 0))) |
c906108c | 2570 | #endif |
c5aa993b JM |
2571 | ) |
2572 | continue; | |
c906108c | 2573 | |
c5aa993b | 2574 | if ((b->type == bp_catch_fork) |
47932f85 DJ |
2575 | && !inferior_has_forked (PIDGET (inferior_ptid), |
2576 | &b->forked_inferior_pid)) | |
c5aa993b | 2577 | continue; |
c906108c | 2578 | |
c5aa993b | 2579 | if ((b->type == bp_catch_vfork) |
47932f85 DJ |
2580 | && !inferior_has_vforked (PIDGET (inferior_ptid), |
2581 | &b->forked_inferior_pid)) | |
c5aa993b | 2582 | continue; |
c906108c | 2583 | |
c5aa993b | 2584 | if ((b->type == bp_catch_exec) |
47932f85 | 2585 | && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname)) |
c5aa993b | 2586 | continue; |
c906108c | 2587 | |
c5aa993b JM |
2588 | if (ep_is_exception_catchpoint (b) && |
2589 | !(current_exception_event = target_get_current_exception_event ())) | |
2590 | continue; | |
c906108c | 2591 | |
c5aa993b JM |
2592 | /* Come here if it's a watchpoint, or if the break address matches */ |
2593 | ||
2594 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ | |
2595 | ||
2596 | /* Watchpoints may change this, if not found to have triggered. */ | |
2597 | bs->stop = 1; | |
2598 | bs->print = 1; | |
2599 | ||
2600 | sprintf (message, message1, b->number); | |
53a5351d JM |
2601 | if (b->type == bp_watchpoint || |
2602 | b->type == bp_hardware_watchpoint) | |
c5aa993b | 2603 | { |
53a5351d JM |
2604 | switch (catch_errors (watchpoint_check, bs, message, |
2605 | RETURN_MASK_ALL)) | |
c5aa993b JM |
2606 | { |
2607 | case WP_DELETED: | |
2608 | /* We've already printed what needs to be printed. */ | |
4ce44c66 JM |
2609 | /* Actually this is superfluous, because by the time we |
2610 | call print_it_typical() the wp will be already deleted, | |
2611 | and the function will return immediately. */ | |
c5aa993b JM |
2612 | bs->print_it = print_it_done; |
2613 | /* Stop. */ | |
2614 | break; | |
2615 | case WP_VALUE_CHANGED: | |
2616 | /* Stop. */ | |
2617 | ++(b->hit_count); | |
2618 | break; | |
2619 | case WP_VALUE_NOT_CHANGED: | |
2620 | /* Don't stop. */ | |
2621 | bs->print_it = print_it_noop; | |
2622 | bs->stop = 0; | |
c5aa993b JM |
2623 | continue; |
2624 | default: | |
2625 | /* Can't happen. */ | |
2626 | /* FALLTHROUGH */ | |
2627 | case 0: | |
2628 | /* Error from catch_errors. */ | |
2629 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2630 | if (b->related_breakpoint) | |
b5de0fa7 EZ |
2631 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2632 | b->disposition = disp_del_at_next_stop; | |
c5aa993b JM |
2633 | /* We've already printed what needs to be printed. */ |
2634 | bs->print_it = print_it_done; | |
2635 | ||
2636 | /* Stop. */ | |
2637 | break; | |
2638 | } | |
2639 | } | |
53a5351d JM |
2640 | else if (b->type == bp_read_watchpoint || |
2641 | b->type == bp_access_watchpoint) | |
c5aa993b JM |
2642 | { |
2643 | CORE_ADDR addr; | |
278cd55f | 2644 | struct value *v; |
c5aa993b JM |
2645 | int found = 0; |
2646 | ||
2647 | addr = target_stopped_data_address (); | |
2648 | if (addr == 0) | |
2649 | continue; | |
2650 | for (v = b->val_chain; v; v = v->next) | |
2651 | { | |
5c44784c JM |
2652 | if (VALUE_LVAL (v) == lval_memory |
2653 | && ! VALUE_LAZY (v)) | |
c5aa993b | 2654 | { |
2e70b7b9 MS |
2655 | struct type *vtype = check_typedef (VALUE_TYPE (v)); |
2656 | ||
2657 | if (v == b->val_chain | |
2658 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
2659 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2660 | { | |
2661 | CORE_ADDR vaddr; | |
2662 | ||
2663 | vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
2664 | /* Exact match not required. Within range is | |
2665 | sufficient. */ | |
2666 | if (addr >= vaddr && | |
2667 | addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v))) | |
2668 | found = 1; | |
2669 | } | |
c5aa993b JM |
2670 | } |
2671 | } | |
2672 | if (found) | |
53a5351d JM |
2673 | switch (catch_errors (watchpoint_check, bs, message, |
2674 | RETURN_MASK_ALL)) | |
c906108c SS |
2675 | { |
2676 | case WP_DELETED: | |
2677 | /* We've already printed what needs to be printed. */ | |
2678 | bs->print_it = print_it_done; | |
2679 | /* Stop. */ | |
2680 | break; | |
2681 | case WP_VALUE_CHANGED: | |
99e5c1c8 MS |
2682 | if (b->type == bp_read_watchpoint) |
2683 | { | |
2684 | /* Don't stop: read watchpoints shouldn't fire if | |
2685 | the value has changed. This is for targets which | |
2686 | cannot set read-only watchpoints. */ | |
2687 | bs->print_it = print_it_noop; | |
2688 | bs->stop = 0; | |
2689 | continue; | |
2690 | } | |
2691 | ++(b->hit_count); | |
2692 | break; | |
c5aa993b | 2693 | case WP_VALUE_NOT_CHANGED: |
c906108c SS |
2694 | /* Stop. */ |
2695 | ++(b->hit_count); | |
2696 | break; | |
c906108c SS |
2697 | default: |
2698 | /* Can't happen. */ | |
c906108c SS |
2699 | case 0: |
2700 | /* Error from catch_errors. */ | |
2701 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2702 | if (b->related_breakpoint) | |
b5de0fa7 EZ |
2703 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2704 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2705 | /* We've already printed what needs to be printed. */ |
2706 | bs->print_it = print_it_done; | |
c906108c SS |
2707 | break; |
2708 | } | |
53a5351d JM |
2709 | else /* found == 0 */ |
2710 | { | |
2711 | /* This is a case where some watchpoint(s) triggered, | |
2712 | but not at the address of this watchpoint (FOUND | |
2713 | was left zero). So don't print anything for this | |
2714 | watchpoint. */ | |
2715 | bs->print_it = print_it_noop; | |
2716 | bs->stop = 0; | |
2717 | continue; | |
2718 | } | |
c5aa993b JM |
2719 | } |
2720 | else | |
2721 | { | |
2722 | /* By definition, an encountered breakpoint is a triggered | |
2723 | breakpoint. */ | |
2724 | ++(b->hit_count); | |
c906108c | 2725 | |
c5aa993b JM |
2726 | real_breakpoint = 1; |
2727 | } | |
2728 | ||
818dd999 AC |
2729 | if (frame_id_p (b->frame_id) |
2730 | && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ()))) | |
c5aa993b JM |
2731 | bs->stop = 0; |
2732 | else | |
2733 | { | |
2734 | int value_is_zero = 0; | |
2735 | ||
2736 | if (b->cond) | |
2737 | { | |
2738 | /* Need to select the frame, with all that implies | |
2739 | so that the conditions will have the right context. */ | |
0f7d239c | 2740 | select_frame (get_current_frame ()); |
c5aa993b JM |
2741 | value_is_zero |
2742 | = catch_errors (breakpoint_cond_eval, (b->cond), | |
2743 | "Error in testing breakpoint condition:\n", | |
2744 | RETURN_MASK_ALL); | |
2745 | /* FIXME-someday, should give breakpoint # */ | |
2746 | free_all_values (); | |
2747 | } | |
2748 | if (b->cond && value_is_zero) | |
2749 | { | |
2750 | bs->stop = 0; | |
2751 | /* Don't consider this a hit. */ | |
2752 | --(b->hit_count); | |
2753 | } | |
2754 | else if (b->ignore_count > 0) | |
2755 | { | |
2756 | b->ignore_count--; | |
5c44784c | 2757 | annotate_ignore_count_change (); |
c5aa993b JM |
2758 | bs->stop = 0; |
2759 | } | |
2760 | else | |
2761 | { | |
2762 | /* We will stop here */ | |
b5de0fa7 EZ |
2763 | if (b->disposition == disp_disable) |
2764 | b->enable_state = bp_disabled; | |
c5aa993b JM |
2765 | if (b->silent) |
2766 | bs->print = 0; | |
552f4abf | 2767 | bs->commands = b->commands; |
c5aa993b JM |
2768 | if (bs->commands && |
2769 | (STREQ ("silent", bs->commands->line) || | |
2770 | (xdb_commands && STREQ ("Q", bs->commands->line)))) | |
2771 | { | |
2772 | bs->commands = bs->commands->next; | |
c906108c | 2773 | bs->print = 0; |
c5aa993b | 2774 | } |
552f4abf | 2775 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b JM |
2776 | } |
2777 | } | |
2778 | /* Print nothing for this entry if we dont stop or if we dont print. */ | |
2779 | if (bs->stop == 0 || bs->print == 0) | |
2780 | bs->print_it = print_it_noop; | |
2781 | } | |
c906108c SS |
2782 | |
2783 | bs->next = NULL; /* Terminate the chain */ | |
2784 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
2785 | ||
2786 | if (real_breakpoint && bs) | |
2787 | { | |
c5aa993b | 2788 | if (bs->breakpoint_at->type == bp_hardware_breakpoint) |
c906108c | 2789 | { |
c5aa993b | 2790 | if (DECR_PC_AFTER_HW_BREAK != 0) |
c906108c SS |
2791 | { |
2792 | *pc = *pc - DECR_PC_AFTER_HW_BREAK; | |
2793 | write_pc (*pc); | |
2794 | } | |
2795 | } | |
2796 | else | |
2797 | { | |
2798 | if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs) | |
2799 | { | |
2800 | *pc = bp_addr; | |
2801 | #if defined (SHIFT_INST_REGS) | |
c5aa993b | 2802 | SHIFT_INST_REGS (); |
c906108c SS |
2803 | #else /* No SHIFT_INST_REGS. */ |
2804 | write_pc (bp_addr); | |
2805 | #endif /* No SHIFT_INST_REGS. */ | |
2806 | } | |
2807 | } | |
2808 | } | |
2809 | ||
2810 | /* The value of a hardware watchpoint hasn't changed, but the | |
2811 | intermediate memory locations we are watching may have. */ | |
c5aa993b | 2812 | if (bs && !bs->stop && |
c906108c SS |
2813 | (bs->breakpoint_at->type == bp_hardware_watchpoint || |
2814 | bs->breakpoint_at->type == bp_read_watchpoint || | |
2815 | bs->breakpoint_at->type == bp_access_watchpoint)) | |
2816 | { | |
2817 | remove_breakpoints (); | |
2818 | insert_breakpoints (); | |
2819 | } | |
2820 | return bs; | |
2821 | } | |
2822 | \f | |
2823 | /* Tell what to do about this bpstat. */ | |
2824 | struct bpstat_what | |
fba45db2 | 2825 | bpstat_what (bpstat bs) |
c906108c SS |
2826 | { |
2827 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
2828 | enum class |
2829 | { | |
2830 | /* This bpstat element has no effect on the main_action. */ | |
2831 | no_effect = 0, | |
2832 | ||
2833 | /* There was a watchpoint, stop but don't print. */ | |
2834 | wp_silent, | |
c906108c | 2835 | |
c5aa993b JM |
2836 | /* There was a watchpoint, stop and print. */ |
2837 | wp_noisy, | |
c906108c | 2838 | |
c5aa993b JM |
2839 | /* There was a breakpoint but we're not stopping. */ |
2840 | bp_nostop, | |
c906108c | 2841 | |
c5aa993b JM |
2842 | /* There was a breakpoint, stop but don't print. */ |
2843 | bp_silent, | |
c906108c | 2844 | |
c5aa993b JM |
2845 | /* There was a breakpoint, stop and print. */ |
2846 | bp_noisy, | |
c906108c | 2847 | |
c5aa993b JM |
2848 | /* We hit the longjmp breakpoint. */ |
2849 | long_jump, | |
c906108c | 2850 | |
c5aa993b JM |
2851 | /* We hit the longjmp_resume breakpoint. */ |
2852 | long_resume, | |
c906108c | 2853 | |
c5aa993b JM |
2854 | /* We hit the step_resume breakpoint. */ |
2855 | step_resume, | |
c906108c | 2856 | |
c5aa993b JM |
2857 | /* We hit the through_sigtramp breakpoint. */ |
2858 | through_sig, | |
c906108c | 2859 | |
c5aa993b JM |
2860 | /* We hit the shared library event breakpoint. */ |
2861 | shlib_event, | |
c906108c | 2862 | |
c5aa993b JM |
2863 | /* We caught a shared library event. */ |
2864 | catch_shlib_event, | |
c906108c | 2865 | |
c5aa993b JM |
2866 | /* This is just used to count how many enums there are. */ |
2867 | class_last | |
c906108c SS |
2868 | }; |
2869 | ||
2870 | /* Here is the table which drives this routine. So that we can | |
2871 | format it pretty, we define some abbreviations for the | |
2872 | enum bpstat_what codes. */ | |
2873 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
2874 | #define ss BPSTAT_WHAT_STOP_SILENT | |
2875 | #define sn BPSTAT_WHAT_STOP_NOISY | |
2876 | #define sgl BPSTAT_WHAT_SINGLE | |
2877 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
2878 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
2879 | #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE | |
2880 | #define sr BPSTAT_WHAT_STEP_RESUME | |
2881 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP | |
2882 | #define shl BPSTAT_WHAT_CHECK_SHLIBS | |
2883 | #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK | |
2884 | ||
2885 | /* "Can't happen." Might want to print an error message. | |
2886 | abort() is not out of the question, but chances are GDB is just | |
2887 | a bit confused, not unusable. */ | |
2888 | #define err BPSTAT_WHAT_STOP_NOISY | |
2889 | ||
2890 | /* Given an old action and a class, come up with a new action. */ | |
2891 | /* One interesting property of this table is that wp_silent is the same | |
2892 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
2893 | after stopping, the check for whether to step over a breakpoint | |
2894 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
2895 | reference to how we stopped. We retain separate wp_silent and |
2896 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
2897 | |
2898 | Another possibly interesting property of this table is that | |
2899 | there's a partial ordering, priority-like, of the actions. Once | |
2900 | you've decided that some action is appropriate, you'll never go | |
2901 | back and decide something of a lower priority is better. The | |
2902 | ordering is: | |
2903 | ||
7e73cedf | 2904 | kc < clr sgl shl shlr slr sn sr ss ts |
c5aa993b JM |
2905 | sgl < clrs shl shlr slr sn sr ss ts |
2906 | slr < err shl shlr sn sr ss ts | |
2907 | clr < clrs err shl shlr sn sr ss ts | |
2908 | clrs < err shl shlr sn sr ss ts | |
2909 | ss < shl shlr sn sr ts | |
2910 | sn < shl shlr sr ts | |
2911 | sr < shl shlr ts | |
2912 | shl < shlr | |
2913 | ts < | |
2914 | shlr < | |
2915 | ||
43ff13b4 JM |
2916 | What I think this means is that we don't need a damned table |
2917 | here. If you just put the rows and columns in the right order, | |
2918 | it'd look awfully regular. We could simply walk the bpstat list | |
2919 | and choose the highest priority action we find, with a little | |
2920 | logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/ | |
2921 | CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says | |
2922 | is messy anyway). */ | |
c906108c SS |
2923 | |
2924 | /* step_resume entries: a step resume breakpoint overrides another | |
2925 | breakpoint of signal handling (see comment in wait_for_inferior | |
d7bd68ca | 2926 | at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */ |
c906108c SS |
2927 | /* We handle the through_sigtramp_breakpoint the same way; having both |
2928 | one of those and a step_resume_breakpoint is probably very rare (?). */ | |
2929 | ||
2930 | static const enum bpstat_what_main_action | |
c5aa993b JM |
2931 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
2932 | { | |
2933 | /* old action */ | |
2934 | /* kc ss sn sgl slr clr clrs sr ts shl shlr | |
2935 | */ | |
2936 | /*no_effect */ | |
2937 | {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr}, | |
2938 | /*wp_silent */ | |
2939 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
2940 | /*wp_noisy */ | |
2941 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
2942 | /*bp_nostop */ | |
2943 | {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr}, | |
2944 | /*bp_silent */ | |
2945 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
2946 | /*bp_noisy */ | |
2947 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
2948 | /*long_jump */ | |
a48bb0b3 | 2949 | {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr}, |
c5aa993b JM |
2950 | /*long_resume */ |
2951 | {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr}, | |
2952 | /*step_resume */ | |
2953 | {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr}, | |
2954 | /*through_sig */ | |
2955 | {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr}, | |
2956 | /*shlib */ | |
2957 | {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr}, | |
2958 | /*catch_shlib */ | |
2959 | {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr} | |
2960 | }; | |
c906108c SS |
2961 | |
2962 | #undef kc | |
2963 | #undef ss | |
2964 | #undef sn | |
2965 | #undef sgl | |
2966 | #undef slr | |
2967 | #undef clr | |
2968 | #undef clrs | |
2969 | #undef err | |
2970 | #undef sr | |
2971 | #undef ts | |
2972 | #undef shl | |
2973 | #undef shlr | |
2974 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; | |
2975 | struct bpstat_what retval; | |
2976 | ||
2977 | retval.call_dummy = 0; | |
2978 | for (; bs != NULL; bs = bs->next) | |
2979 | { | |
2980 | enum class bs_class = no_effect; | |
2981 | if (bs->breakpoint_at == NULL) | |
2982 | /* I suspect this can happen if it was a momentary breakpoint | |
2983 | which has since been deleted. */ | |
2984 | continue; | |
2985 | switch (bs->breakpoint_at->type) | |
2986 | { | |
2987 | case bp_none: | |
2988 | continue; | |
2989 | ||
2990 | case bp_breakpoint: | |
2991 | case bp_hardware_breakpoint: | |
2992 | case bp_until: | |
2993 | case bp_finish: | |
2994 | if (bs->stop) | |
2995 | { | |
2996 | if (bs->print) | |
2997 | bs_class = bp_noisy; | |
2998 | else | |
2999 | bs_class = bp_silent; | |
3000 | } | |
3001 | else | |
3002 | bs_class = bp_nostop; | |
3003 | break; | |
3004 | case bp_watchpoint: | |
3005 | case bp_hardware_watchpoint: | |
3006 | case bp_read_watchpoint: | |
3007 | case bp_access_watchpoint: | |
3008 | if (bs->stop) | |
3009 | { | |
3010 | if (bs->print) | |
3011 | bs_class = wp_noisy; | |
3012 | else | |
3013 | bs_class = wp_silent; | |
3014 | } | |
3015 | else | |
53a5351d JM |
3016 | /* There was a watchpoint, but we're not stopping. |
3017 | This requires no further action. */ | |
c906108c SS |
3018 | bs_class = no_effect; |
3019 | break; | |
3020 | case bp_longjmp: | |
3021 | bs_class = long_jump; | |
3022 | break; | |
3023 | case bp_longjmp_resume: | |
3024 | bs_class = long_resume; | |
3025 | break; | |
3026 | case bp_step_resume: | |
3027 | if (bs->stop) | |
3028 | { | |
3029 | bs_class = step_resume; | |
3030 | } | |
3031 | else | |
3032 | /* It is for the wrong frame. */ | |
3033 | bs_class = bp_nostop; | |
3034 | break; | |
3035 | case bp_through_sigtramp: | |
3036 | bs_class = through_sig; | |
3037 | break; | |
3038 | case bp_watchpoint_scope: | |
3039 | bs_class = bp_nostop; | |
3040 | break; | |
c5aa993b JM |
3041 | case bp_shlib_event: |
3042 | bs_class = shlib_event; | |
3043 | break; | |
c4093a6a | 3044 | case bp_thread_event: |
1900040c | 3045 | case bp_overlay_event: |
c4093a6a JM |
3046 | bs_class = bp_nostop; |
3047 | break; | |
c5aa993b JM |
3048 | case bp_catch_load: |
3049 | case bp_catch_unload: | |
3050 | /* Only if this catchpoint triggered should we cause the | |
3051 | step-out-of-dld behaviour. Otherwise, we ignore this | |
3052 | catchpoint. */ | |
3053 | if (bs->stop) | |
3054 | bs_class = catch_shlib_event; | |
3055 | else | |
3056 | bs_class = no_effect; | |
3057 | break; | |
3058 | case bp_catch_fork: | |
3059 | case bp_catch_vfork: | |
3060 | case bp_catch_exec: | |
3061 | if (bs->stop) | |
3062 | { | |
3063 | if (bs->print) | |
3064 | bs_class = bp_noisy; | |
3065 | else | |
3066 | bs_class = bp_silent; | |
3067 | } | |
3068 | else | |
53a5351d JM |
3069 | /* There was a catchpoint, but we're not stopping. |
3070 | This requires no further action. */ | |
c5aa993b JM |
3071 | bs_class = no_effect; |
3072 | break; | |
3073 | case bp_catch_catch: | |
3074 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH) | |
3075 | bs_class = bp_nostop; | |
3076 | else if (bs->stop) | |
3077 | bs_class = bs->print ? bp_noisy : bp_silent; | |
3078 | break; | |
3079 | case bp_catch_throw: | |
3080 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW) | |
3081 | bs_class = bp_nostop; | |
3082 | else if (bs->stop) | |
3083 | bs_class = bs->print ? bp_noisy : bp_silent; | |
c906108c | 3084 | break; |
c906108c | 3085 | case bp_call_dummy: |
53a5351d JM |
3086 | /* Make sure the action is stop (silent or noisy), |
3087 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3088 | bs_class = bp_silent; |
3089 | retval.call_dummy = 1; | |
3090 | break; | |
3091 | } | |
c5aa993b | 3092 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3093 | } |
3094 | retval.main_action = current_action; | |
3095 | return retval; | |
3096 | } | |
3097 | ||
3098 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3099 | without hardware support). This isn't related to a specific bpstat, | |
3100 | just to things like whether watchpoints are set. */ | |
3101 | ||
c5aa993b | 3102 | int |
fba45db2 | 3103 | bpstat_should_step (void) |
c906108c SS |
3104 | { |
3105 | struct breakpoint *b; | |
3106 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 3107 | if (b->enable_state == bp_enabled && b->type == bp_watchpoint) |
3172dc30 | 3108 | return 1; |
c906108c SS |
3109 | return 0; |
3110 | } | |
3111 | ||
3112 | /* Nonzero if there are enabled hardware watchpoints. */ | |
3113 | int | |
fba45db2 | 3114 | bpstat_have_active_hw_watchpoints (void) |
c906108c SS |
3115 | { |
3116 | struct breakpoint *b; | |
3117 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 3118 | if ((b->enable_state == bp_enabled) && |
c5aa993b JM |
3119 | (b->inserted) && |
3120 | ((b->type == bp_hardware_watchpoint) || | |
3121 | (b->type == bp_read_watchpoint) || | |
3122 | (b->type == bp_access_watchpoint))) | |
3172dc30 | 3123 | return 1; |
c906108c SS |
3124 | return 0; |
3125 | } | |
c906108c | 3126 | \f |
c5aa993b | 3127 | |
c906108c SS |
3128 | /* Given a bpstat that records zero or more triggered eventpoints, this |
3129 | function returns another bpstat which contains only the catchpoints | |
3130 | on that first list, if any. */ | |
3131 | void | |
fba45db2 | 3132 | bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list) |
c5aa993b JM |
3133 | { |
3134 | struct bpstats root_bs[1]; | |
3135 | bpstat bs = root_bs; | |
3136 | struct breakpoint *ep; | |
3137 | char *dll_pathname; | |
3138 | ||
c906108c SS |
3139 | bpstat_clear (cp_list); |
3140 | root_bs->next = NULL; | |
c5aa993b JM |
3141 | |
3142 | for (; ep_list != NULL; ep_list = ep_list->next) | |
c906108c SS |
3143 | { |
3144 | /* Is this eventpoint a catchpoint? If not, ignore it. */ | |
3145 | ep = ep_list->breakpoint_at; | |
3146 | if (ep == NULL) | |
c5aa993b JM |
3147 | break; |
3148 | if ((ep->type != bp_catch_load) && | |
3149 | (ep->type != bp_catch_unload) && | |
3150 | (ep->type != bp_catch_catch) && | |
53a5351d JM |
3151 | (ep->type != bp_catch_throw)) |
3152 | /* pai: (temp) ADD fork/vfork here!! */ | |
c5aa993b JM |
3153 | continue; |
3154 | ||
c906108c SS |
3155 | /* Yes; add it to the list. */ |
3156 | bs = bpstat_alloc (ep, bs); | |
3157 | *bs = *ep_list; | |
3158 | bs->next = NULL; | |
3159 | bs = root_bs->next; | |
c5aa993b | 3160 | |
c906108c SS |
3161 | #if defined(SOLIB_ADD) |
3162 | /* Also, for each triggered catchpoint, tag it with the name of | |
3163 | the library that caused this trigger. (We copy the name now, | |
3164 | because it's only guaranteed to be available NOW, when the | |
3165 | catchpoint triggers. Clients who may wish to know the name | |
3166 | later must get it from the catchpoint itself.) */ | |
3167 | if (ep->triggered_dll_pathname != NULL) | |
b8c9b27d | 3168 | xfree (ep->triggered_dll_pathname); |
c906108c | 3169 | if (ep->type == bp_catch_load) |
39f77062 KB |
3170 | dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME ( |
3171 | PIDGET (inferior_ptid)); | |
c906108c | 3172 | else |
39f77062 KB |
3173 | dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME ( |
3174 | PIDGET (inferior_ptid)); | |
c906108c SS |
3175 | #else |
3176 | dll_pathname = NULL; | |
3177 | #endif | |
3178 | if (dll_pathname) | |
3179 | { | |
53a5351d JM |
3180 | ep->triggered_dll_pathname = (char *) |
3181 | xmalloc (strlen (dll_pathname) + 1); | |
c906108c SS |
3182 | strcpy (ep->triggered_dll_pathname, dll_pathname); |
3183 | } | |
3184 | else | |
3185 | ep->triggered_dll_pathname = NULL; | |
3186 | } | |
c5aa993b | 3187 | |
c906108c SS |
3188 | *cp_list = bs; |
3189 | } | |
3190 | ||
c4093a6a | 3191 | /* Print B to gdb_stdout. */ |
c906108c | 3192 | static void |
c4093a6a JM |
3193 | print_one_breakpoint (struct breakpoint *b, |
3194 | CORE_ADDR *last_addr) | |
c906108c | 3195 | { |
c906108c SS |
3196 | register struct command_line *l; |
3197 | register struct symbol *sym; | |
c4093a6a JM |
3198 | struct ep_type_description |
3199 | { | |
3200 | enum bptype type; | |
3201 | char *description; | |
3202 | }; | |
3203 | static struct ep_type_description bptypes[] = | |
c906108c | 3204 | { |
c5aa993b JM |
3205 | {bp_none, "?deleted?"}, |
3206 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3207 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3208 | {bp_until, "until"}, |
3209 | {bp_finish, "finish"}, | |
3210 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3211 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3212 | {bp_read_watchpoint, "read watchpoint"}, |
3213 | {bp_access_watchpoint, "acc watchpoint"}, | |
3214 | {bp_longjmp, "longjmp"}, | |
3215 | {bp_longjmp_resume, "longjmp resume"}, | |
3216 | {bp_step_resume, "step resume"}, | |
3217 | {bp_through_sigtramp, "sigtramp"}, | |
3218 | {bp_watchpoint_scope, "watchpoint scope"}, | |
3219 | {bp_call_dummy, "call dummy"}, | |
3220 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3221 | {bp_thread_event, "thread events"}, |
1900040c | 3222 | {bp_overlay_event, "overlay events"}, |
c5aa993b JM |
3223 | {bp_catch_load, "catch load"}, |
3224 | {bp_catch_unload, "catch unload"}, | |
3225 | {bp_catch_fork, "catch fork"}, | |
3226 | {bp_catch_vfork, "catch vfork"}, | |
3227 | {bp_catch_exec, "catch exec"}, | |
3228 | {bp_catch_catch, "catch catch"}, | |
3229 | {bp_catch_throw, "catch throw"} | |
3230 | }; | |
c4093a6a | 3231 | |
c5aa993b JM |
3232 | static char *bpdisps[] = |
3233 | {"del", "dstp", "dis", "keep"}; | |
c2c6d25f | 3234 | static char bpenables[] = "nynny"; |
c906108c | 3235 | char wrap_indent[80]; |
8b93c638 JM |
3236 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3237 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3238 | struct cleanup *bkpt_chain; |
c906108c | 3239 | |
c4093a6a | 3240 | annotate_record (); |
3b31d625 | 3241 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3242 | |
3243 | /* 1 */ | |
3244 | annotate_field (0); | |
8b93c638 | 3245 | ui_out_field_int (uiout, "number", b->number); |
c4093a6a JM |
3246 | |
3247 | /* 2 */ | |
3248 | annotate_field (1); | |
3249 | if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3250 | || ((int) b->type != bptypes[(int) b->type].type)) | |
8e65ff28 AC |
3251 | internal_error (__FILE__, __LINE__, |
3252 | "bptypes table does not describe type #%d.", | |
c4093a6a | 3253 | (int) b->type); |
8b93c638 | 3254 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); |
c4093a6a JM |
3255 | |
3256 | /* 3 */ | |
3257 | annotate_field (2); | |
8b93c638 | 3258 | ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]); |
c4093a6a JM |
3259 | |
3260 | /* 4 */ | |
3261 | annotate_field (3); | |
b5de0fa7 | 3262 | ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]); |
8b93c638 | 3263 | ui_out_spaces (uiout, 2); |
c4093a6a JM |
3264 | |
3265 | /* 5 and 6 */ | |
3266 | strcpy (wrap_indent, " "); | |
3267 | if (addressprint) | |
75ac9d7b MS |
3268 | { |
3269 | if (TARGET_ADDR_BIT <= 32) | |
3270 | strcat (wrap_indent, " "); | |
3271 | else | |
3272 | strcat (wrap_indent, " "); | |
3273 | } | |
c906108c | 3274 | |
3086aeae DJ |
3275 | if (b->ops != NULL && b->ops->print_one != NULL) |
3276 | b->ops->print_one (b, last_addr); | |
3277 | else | |
3278 | switch (b->type) | |
3279 | { | |
3280 | case bp_none: | |
3281 | internal_error (__FILE__, __LINE__, | |
3282 | "print_one_breakpoint: bp_none encountered\n"); | |
3283 | break; | |
c906108c | 3284 | |
3086aeae DJ |
3285 | case bp_watchpoint: |
3286 | case bp_hardware_watchpoint: | |
3287 | case bp_read_watchpoint: | |
3288 | case bp_access_watchpoint: | |
3289 | /* Field 4, the address, is omitted (which makes the columns | |
3290 | not line up too nicely with the headers, but the effect | |
3291 | is relatively readable). */ | |
3292 | if (addressprint) | |
3293 | ui_out_field_skip (uiout, "addr"); | |
3294 | annotate_field (5); | |
3295 | print_expression (b->exp, stb->stream); | |
3296 | ui_out_field_stream (uiout, "what", stb); | |
3297 | break; | |
3298 | ||
3299 | case bp_catch_load: | |
3300 | case bp_catch_unload: | |
3301 | /* Field 4, the address, is omitted (which makes the columns | |
3302 | not line up too nicely with the headers, but the effect | |
3303 | is relatively readable). */ | |
3304 | if (addressprint) | |
3305 | ui_out_field_skip (uiout, "addr"); | |
3306 | annotate_field (5); | |
3307 | if (b->dll_pathname == NULL) | |
3308 | { | |
3309 | ui_out_field_string (uiout, "what", "<any library>"); | |
3310 | ui_out_spaces (uiout, 1); | |
3311 | } | |
3312 | else | |
3313 | { | |
3314 | ui_out_text (uiout, "library \""); | |
3315 | ui_out_field_string (uiout, "what", b->dll_pathname); | |
3316 | ui_out_text (uiout, "\" "); | |
3317 | } | |
3318 | break; | |
3319 | ||
3320 | case bp_catch_fork: | |
3321 | case bp_catch_vfork: | |
3322 | /* Field 4, the address, is omitted (which makes the columns | |
3323 | not line up too nicely with the headers, but the effect | |
3324 | is relatively readable). */ | |
3325 | if (addressprint) | |
3326 | ui_out_field_skip (uiout, "addr"); | |
3327 | annotate_field (5); | |
3328 | if (b->forked_inferior_pid != 0) | |
3329 | { | |
3330 | ui_out_text (uiout, "process "); | |
3331 | ui_out_field_int (uiout, "what", b->forked_inferior_pid); | |
3332 | ui_out_spaces (uiout, 1); | |
3333 | } | |
3334 | ||
3335 | case bp_catch_exec: | |
3336 | /* Field 4, the address, is omitted (which makes the columns | |
3337 | not line up too nicely with the headers, but the effect | |
3338 | is relatively readable). */ | |
3339 | if (addressprint) | |
3340 | ui_out_field_skip (uiout, "addr"); | |
3341 | annotate_field (5); | |
3342 | if (b->exec_pathname != NULL) | |
3343 | { | |
3344 | ui_out_text (uiout, "program \""); | |
3345 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
3346 | ui_out_text (uiout, "\" "); | |
3347 | } | |
3348 | break; | |
3349 | ||
3350 | case bp_catch_catch: | |
3351 | /* Field 4, the address, is omitted (which makes the columns | |
3352 | not line up too nicely with the headers, but the effect | |
3353 | is relatively readable). */ | |
3354 | if (addressprint) | |
3355 | ui_out_field_skip (uiout, "addr"); | |
3356 | annotate_field (5); | |
3357 | ui_out_field_string (uiout, "what", "exception catch"); | |
3358 | ui_out_spaces (uiout, 1); | |
3359 | break; | |
3360 | ||
3361 | case bp_catch_throw: | |
3362 | /* Field 4, the address, is omitted (which makes the columns | |
3363 | not line up too nicely with the headers, but the effect | |
3364 | is relatively readable). */ | |
3365 | if (addressprint) | |
3366 | ui_out_field_skip (uiout, "addr"); | |
3367 | annotate_field (5); | |
3368 | ui_out_field_string (uiout, "what", "exception throw"); | |
3369 | ui_out_spaces (uiout, 1); | |
3370 | break; | |
3371 | ||
3372 | case bp_breakpoint: | |
3373 | case bp_hardware_breakpoint: | |
3374 | case bp_until: | |
3375 | case bp_finish: | |
3376 | case bp_longjmp: | |
3377 | case bp_longjmp_resume: | |
3378 | case bp_step_resume: | |
3379 | case bp_through_sigtramp: | |
3380 | case bp_watchpoint_scope: | |
3381 | case bp_call_dummy: | |
3382 | case bp_shlib_event: | |
3383 | case bp_thread_event: | |
3384 | case bp_overlay_event: | |
3385 | if (addressprint) | |
3386 | { | |
3387 | annotate_field (4); | |
3388 | ui_out_field_core_addr (uiout, "addr", b->address); | |
3389 | } | |
3390 | annotate_field (5); | |
3391 | *last_addr = b->address; | |
3392 | if (b->source_file) | |
3393 | { | |
3394 | sym = find_pc_sect_function (b->address, b->section); | |
3395 | if (sym) | |
3396 | { | |
3397 | ui_out_text (uiout, "in "); | |
3398 | ui_out_field_string (uiout, "func", | |
3399 | SYMBOL_PRINT_NAME (sym)); | |
3400 | ui_out_wrap_hint (uiout, wrap_indent); | |
3401 | ui_out_text (uiout, " at "); | |
3402 | } | |
3403 | ui_out_field_string (uiout, "file", b->source_file); | |
3404 | ui_out_text (uiout, ":"); | |
3405 | ui_out_field_int (uiout, "line", b->line_number); | |
3406 | } | |
3407 | else | |
3408 | { | |
3409 | print_address_symbolic (b->address, stb->stream, demangle, ""); | |
3410 | ui_out_field_stream (uiout, "at", stb); | |
3411 | } | |
3412 | break; | |
3413 | } | |
c906108c | 3414 | |
c4093a6a JM |
3415 | if (b->thread != -1) |
3416 | { | |
8b93c638 JM |
3417 | /* FIXME: This seems to be redundant and lost here; see the |
3418 | "stop only in" line a little further down. */ | |
3419 | ui_out_text (uiout, " thread "); | |
3420 | ui_out_field_int (uiout, "thread", b->thread); | |
c4093a6a JM |
3421 | } |
3422 | ||
8b93c638 | 3423 | ui_out_text (uiout, "\n"); |
c4093a6a | 3424 | |
818dd999 | 3425 | if (frame_id_p (b->frame_id)) |
c4093a6a JM |
3426 | { |
3427 | annotate_field (6); | |
8b93c638 | 3428 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3429 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3430 | the frame ID. */ | |
d0a55772 | 3431 | ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr); |
8b93c638 | 3432 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3433 | } |
3434 | ||
3435 | if (b->cond) | |
3436 | { | |
3437 | annotate_field (7); | |
8b93c638 JM |
3438 | ui_out_text (uiout, "\tstop only if "); |
3439 | print_expression (b->cond, stb->stream); | |
3440 | ui_out_field_stream (uiout, "cond", stb); | |
3441 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3442 | } |
3443 | ||
3444 | if (b->thread != -1) | |
3445 | { | |
3446 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3447 | ui_out_text (uiout, "\tstop only in thread "); |
3448 | ui_out_field_int (uiout, "thread", b->thread); | |
3449 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3450 | } |
3451 | ||
3452 | if (show_breakpoint_hit_counts && b->hit_count) | |
3453 | { | |
3454 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3455 | if (ep_is_catchpoint (b)) |
3456 | ui_out_text (uiout, "\tcatchpoint"); | |
3457 | else | |
3458 | ui_out_text (uiout, "\tbreakpoint"); | |
3459 | ui_out_text (uiout, " already hit "); | |
3460 | ui_out_field_int (uiout, "times", b->hit_count); | |
3461 | if (b->hit_count == 1) | |
3462 | ui_out_text (uiout, " time\n"); | |
3463 | else | |
3464 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3465 | } |
3466 | ||
fb40c209 AC |
3467 | /* Output the count also if it is zero, but only if this is |
3468 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3469 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 AC |
3470 | if (show_breakpoint_hit_counts && b->hit_count == 0) |
3471 | ui_out_field_int (uiout, "times", b->hit_count); | |
8b93c638 | 3472 | |
c4093a6a JM |
3473 | if (b->ignore_count) |
3474 | { | |
3475 | annotate_field (8); | |
8b93c638 JM |
3476 | ui_out_text (uiout, "\tignore next "); |
3477 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3478 | ui_out_text (uiout, " hits\n"); | |
c4093a6a JM |
3479 | } |
3480 | ||
3481 | if ((l = b->commands)) | |
3482 | { | |
3b31d625 EZ |
3483 | struct cleanup *script_chain; |
3484 | ||
c4093a6a | 3485 | annotate_field (9); |
3b31d625 | 3486 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3487 | print_command_lines (uiout, l, 4); |
3b31d625 | 3488 | do_cleanups (script_chain); |
c4093a6a | 3489 | } |
3b31d625 | 3490 | do_cleanups (bkpt_chain); |
8b93c638 | 3491 | do_cleanups (old_chain); |
c4093a6a | 3492 | } |
c5aa993b | 3493 | |
c4093a6a JM |
3494 | struct captured_breakpoint_query_args |
3495 | { | |
3496 | int bnum; | |
3497 | }; | |
c5aa993b | 3498 | |
c4093a6a | 3499 | static int |
2b65245e | 3500 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3501 | { |
3502 | struct captured_breakpoint_query_args *args = data; | |
3503 | register struct breakpoint *b; | |
3504 | CORE_ADDR dummy_addr = 0; | |
3505 | ALL_BREAKPOINTS (b) | |
3506 | { | |
3507 | if (args->bnum == b->number) | |
c5aa993b | 3508 | { |
c4093a6a JM |
3509 | print_one_breakpoint (b, &dummy_addr); |
3510 | return GDB_RC_OK; | |
c5aa993b | 3511 | } |
c4093a6a JM |
3512 | } |
3513 | return GDB_RC_NONE; | |
3514 | } | |
c5aa993b | 3515 | |
c4093a6a | 3516 | enum gdb_rc |
2b65245e | 3517 | gdb_breakpoint_query (struct ui_out *uiout, int bnum) |
c4093a6a JM |
3518 | { |
3519 | struct captured_breakpoint_query_args args; | |
3520 | args.bnum = bnum; | |
3521 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3522 | an error. */ | |
2b65245e AC |
3523 | return catch_exceptions (uiout, do_captured_breakpoint_query, &args, |
3524 | NULL, RETURN_MASK_ALL); | |
c4093a6a | 3525 | } |
c5aa993b | 3526 | |
7f3b0473 AC |
3527 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3528 | catchpoints, et.al.). */ | |
3529 | ||
3530 | static int | |
3531 | user_settable_breakpoint (const struct breakpoint *b) | |
3532 | { | |
3533 | return (b->type == bp_breakpoint | |
3534 | || b->type == bp_catch_load | |
3535 | || b->type == bp_catch_unload | |
3536 | || b->type == bp_catch_fork | |
3537 | || b->type == bp_catch_vfork | |
3538 | || b->type == bp_catch_exec | |
3539 | || b->type == bp_catch_catch | |
3540 | || b->type == bp_catch_throw | |
3541 | || b->type == bp_hardware_breakpoint | |
3542 | || b->type == bp_watchpoint | |
3543 | || b->type == bp_read_watchpoint | |
3544 | || b->type == bp_access_watchpoint | |
3545 | || b->type == bp_hardware_watchpoint); | |
3546 | } | |
3547 | ||
3548 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3549 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3550 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3551 | |
c4093a6a | 3552 | static void |
fba45db2 | 3553 | breakpoint_1 (int bnum, int allflag) |
c4093a6a JM |
3554 | { |
3555 | register struct breakpoint *b; | |
3556 | CORE_ADDR last_addr = (CORE_ADDR) -1; | |
7f3b0473 | 3557 | int nr_printable_breakpoints; |
3b31d625 | 3558 | struct cleanup *bkpttbl_chain; |
c4093a6a | 3559 | |
7f3b0473 AC |
3560 | /* Compute the number of rows in the table. */ |
3561 | nr_printable_breakpoints = 0; | |
3562 | ALL_BREAKPOINTS (b) | |
3563 | if (bnum == -1 | |
3564 | || bnum == b->number) | |
3565 | { | |
3566 | if (allflag || user_settable_breakpoint (b)) | |
3567 | nr_printable_breakpoints++; | |
3568 | } | |
3569 | ||
8b93c638 | 3570 | if (addressprint) |
3b31d625 EZ |
3571 | bkpttbl_chain |
3572 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
3573 | "BreakpointTable"); | |
8b93c638 | 3574 | else |
3b31d625 EZ |
3575 | bkpttbl_chain |
3576 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
3577 | "BreakpointTable"); | |
8b93c638 | 3578 | |
7f3b0473 | 3579 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
3580 | annotate_breakpoints_headers (); |
3581 | if (nr_printable_breakpoints > 0) | |
3582 | annotate_field (0); | |
3583 | ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */ | |
3584 | if (nr_printable_breakpoints > 0) | |
3585 | annotate_field (1); | |
3586 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
3587 | if (nr_printable_breakpoints > 0) | |
3588 | annotate_field (2); | |
3589 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
3590 | if (nr_printable_breakpoints > 0) | |
3591 | annotate_field (3); | |
3592 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ | |
3593 | if (addressprint) | |
7f3b0473 | 3594 | { |
d7faa9e7 AC |
3595 | if (nr_printable_breakpoints > 0) |
3596 | annotate_field (4); | |
7f3b0473 | 3597 | if (TARGET_ADDR_BIT <= 32) |
b25959ec | 3598 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3599 | else |
b25959ec | 3600 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 3601 | } |
d7faa9e7 AC |
3602 | if (nr_printable_breakpoints > 0) |
3603 | annotate_field (5); | |
3604 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
3605 | ui_out_table_body (uiout); | |
3606 | if (nr_printable_breakpoints > 0) | |
3607 | annotate_breakpoints_table (); | |
7f3b0473 | 3608 | |
c4093a6a JM |
3609 | ALL_BREAKPOINTS (b) |
3610 | if (bnum == -1 | |
3611 | || bnum == b->number) | |
3612 | { | |
3613 | /* We only print out user settable breakpoints unless the | |
3614 | allflag is set. */ | |
7f3b0473 AC |
3615 | if (allflag || user_settable_breakpoint (b)) |
3616 | print_one_breakpoint (b, &last_addr); | |
c4093a6a JM |
3617 | } |
3618 | ||
3b31d625 | 3619 | do_cleanups (bkpttbl_chain); |
698384cd | 3620 | |
7f3b0473 | 3621 | if (nr_printable_breakpoints == 0) |
c906108c | 3622 | { |
8b93c638 JM |
3623 | if (bnum == -1) |
3624 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
3625 | else | |
3626 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
3627 | bnum); | |
c906108c SS |
3628 | } |
3629 | else | |
c4093a6a JM |
3630 | { |
3631 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
3632 | that a comparison of an unsigned with -1 is always false. */ | |
3633 | if (last_addr != (CORE_ADDR) -1) | |
3634 | set_next_address (last_addr); | |
3635 | } | |
c906108c | 3636 | |
c4093a6a JM |
3637 | /* FIXME? Should this be moved up so that it is only called when |
3638 | there have been breakpoints? */ | |
c906108c SS |
3639 | annotate_breakpoints_table_end (); |
3640 | } | |
3641 | ||
3642 | /* ARGSUSED */ | |
3643 | static void | |
fba45db2 | 3644 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
3645 | { |
3646 | int bnum = -1; | |
3647 | ||
3648 | if (bnum_exp) | |
bb518678 | 3649 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3650 | |
3651 | breakpoint_1 (bnum, 0); | |
3652 | } | |
3653 | ||
c906108c | 3654 | /* ARGSUSED */ |
7a292a7a | 3655 | static void |
fba45db2 | 3656 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
3657 | { |
3658 | int bnum = -1; | |
3659 | ||
3660 | if (bnum_exp) | |
bb518678 | 3661 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
3662 | |
3663 | breakpoint_1 (bnum, 1); | |
3664 | } | |
3665 | ||
c906108c SS |
3666 | /* Print a message describing any breakpoints set at PC. */ |
3667 | ||
3668 | static void | |
fba45db2 | 3669 | describe_other_breakpoints (CORE_ADDR pc, asection *section) |
c906108c SS |
3670 | { |
3671 | register int others = 0; | |
3672 | register struct breakpoint *b; | |
3673 | ||
3674 | ALL_BREAKPOINTS (b) | |
9f04af04 MS |
3675 | if (b->address == pc) /* address match / overlay match */ |
3676 | if (!overlay_debugging || b->section == section) | |
3677 | others++; | |
c906108c SS |
3678 | if (others > 0) |
3679 | { | |
3680 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); | |
3681 | ALL_BREAKPOINTS (b) | |
9f04af04 MS |
3682 | if (b->address == pc) /* address match / overlay match */ |
3683 | if (!overlay_debugging || b->section == section) | |
3684 | { | |
3685 | others--; | |
3686 | printf_filtered ("%d%s%s ", | |
3687 | b->number, | |
3688 | ((b->enable_state == bp_disabled || | |
3689 | b->enable_state == bp_shlib_disabled || | |
3690 | b->enable_state == bp_call_disabled) | |
3691 | ? " (disabled)" | |
3692 | : b->enable_state == bp_permanent | |
3693 | ? " (permanent)" | |
3694 | : ""), | |
3695 | (others > 1) ? "," | |
3696 | : ((others == 1) ? " and" : "")); | |
3697 | } | |
c906108c SS |
3698 | printf_filtered ("also set at pc "); |
3699 | print_address_numeric (pc, 1, gdb_stdout); | |
3700 | printf_filtered (".\n"); | |
3701 | } | |
3702 | } | |
3703 | \f | |
3704 | /* Set the default place to put a breakpoint | |
3705 | for the `break' command with no arguments. */ | |
3706 | ||
3707 | void | |
fba45db2 KB |
3708 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
3709 | int line) | |
c906108c SS |
3710 | { |
3711 | default_breakpoint_valid = valid; | |
3712 | default_breakpoint_address = addr; | |
3713 | default_breakpoint_symtab = symtab; | |
3714 | default_breakpoint_line = line; | |
3715 | } | |
3716 | ||
e4f237da KB |
3717 | /* Return true iff it is meaningful to use the address member of |
3718 | BPT. For some breakpoint types, the address member is irrelevant | |
3719 | and it makes no sense to attempt to compare it to other addresses | |
3720 | (or use it for any other purpose either). | |
3721 | ||
3722 | More specifically, each of the following breakpoint types will always | |
3723 | have a zero valued address and we don't want check_duplicates() to mark | |
3724 | breakpoints of any of these types to be a duplicate of an actual | |
3725 | breakpoint at address zero: | |
3726 | ||
3727 | bp_watchpoint | |
3728 | bp_hardware_watchpoint | |
3729 | bp_read_watchpoint | |
3730 | bp_access_watchpoint | |
3731 | bp_catch_exec | |
3732 | bp_longjmp_resume | |
3733 | bp_catch_fork | |
3734 | bp_catch_vork */ | |
3735 | ||
3736 | static int | |
3737 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
3738 | { | |
3739 | enum bptype type = bpt->type; | |
3740 | ||
3741 | return (type != bp_watchpoint | |
3742 | && type != bp_hardware_watchpoint | |
3743 | && type != bp_read_watchpoint | |
3744 | && type != bp_access_watchpoint | |
3745 | && type != bp_catch_exec | |
3746 | && type != bp_longjmp_resume | |
3747 | && type != bp_catch_fork | |
3748 | && type != bp_catch_vfork); | |
3749 | } | |
3750 | ||
9f60f21b | 3751 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 3752 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 3753 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
3754 | If we have a permanent breakpoint at the same place as BPT, make |
3755 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
3756 | |
3757 | static void | |
9f60f21b | 3758 | check_duplicates (struct breakpoint *bpt) |
c906108c SS |
3759 | { |
3760 | register struct breakpoint *b; | |
3761 | register int count = 0; | |
c2c6d25f | 3762 | struct breakpoint *perm_bp = 0; |
9f60f21b JB |
3763 | CORE_ADDR address = bpt->address; |
3764 | asection *section = bpt->section; | |
c906108c | 3765 | |
e4f237da | 3766 | if (! breakpoint_address_is_meaningful (bpt)) |
c906108c SS |
3767 | return; |
3768 | ||
3769 | ALL_BREAKPOINTS (b) | |
b5de0fa7 EZ |
3770 | if (b->enable_state != bp_disabled |
3771 | && b->enable_state != bp_shlib_disabled | |
3772 | && b->enable_state != bp_call_disabled | |
9f04af04 MS |
3773 | && b->address == address /* address / overlay match */ |
3774 | && (!overlay_debugging || b->section == section) | |
e4f237da | 3775 | && breakpoint_address_is_meaningful (b)) |
c5aa993b | 3776 | { |
c2c6d25f | 3777 | /* Have we found a permanent breakpoint? */ |
b5de0fa7 | 3778 | if (b->enable_state == bp_permanent) |
c2c6d25f JM |
3779 | { |
3780 | perm_bp = b; | |
3781 | break; | |
3782 | } | |
3783 | ||
c5aa993b JM |
3784 | count++; |
3785 | b->duplicate = count > 1; | |
3786 | } | |
c2c6d25f JM |
3787 | |
3788 | /* If we found a permanent breakpoint at this address, go over the | |
3789 | list again and declare all the other breakpoints there to be the | |
3790 | duplicates. */ | |
3791 | if (perm_bp) | |
3792 | { | |
3793 | perm_bp->duplicate = 0; | |
3794 | ||
3795 | /* Permanent breakpoint should always be inserted. */ | |
3796 | if (! perm_bp->inserted) | |
8e65ff28 AC |
3797 | internal_error (__FILE__, __LINE__, |
3798 | "allegedly permanent breakpoint is not " | |
c2c6d25f JM |
3799 | "actually inserted"); |
3800 | ||
3801 | ALL_BREAKPOINTS (b) | |
3802 | if (b != perm_bp) | |
3803 | { | |
3804 | if (b->inserted) | |
8e65ff28 AC |
3805 | internal_error (__FILE__, __LINE__, |
3806 | "another breakpoint was inserted on top of " | |
c2c6d25f JM |
3807 | "a permanent breakpoint"); |
3808 | ||
b5de0fa7 EZ |
3809 | if (b->enable_state != bp_disabled |
3810 | && b->enable_state != bp_shlib_disabled | |
3811 | && b->enable_state != bp_call_disabled | |
9f04af04 MS |
3812 | && b->address == address /* address / overlay match */ |
3813 | && (!overlay_debugging || b->section == section) | |
e4f237da | 3814 | && breakpoint_address_is_meaningful (b)) |
c2c6d25f JM |
3815 | b->duplicate = 1; |
3816 | } | |
3817 | } | |
c906108c SS |
3818 | } |
3819 | ||
4d28f7a8 KB |
3820 | /* set_raw_breakpoint() is a low level routine for allocating and |
3821 | partially initializing a breakpoint of type BPTYPE. The newly | |
3822 | created breakpoint's address, section, source file name, and line | |
3823 | number are provided by SAL. The newly created and partially | |
3824 | initialized breakpoint is added to the breakpoint chain and | |
3825 | is also returned as the value of this function. | |
c906108c | 3826 | |
4d28f7a8 KB |
3827 | It is expected that the caller will complete the initialization of |
3828 | the newly created breakpoint struct as well as output any status | |
3829 | information regarding the creation of a new breakpoint. In | |
3830 | particular, set_raw_breakpoint() does NOT set the breakpoint | |
3831 | number! Care should be taken to not allow an error() to occur | |
3832 | prior to completing the initialization of the breakpoint. If this | |
3833 | should happen, a bogus breakpoint will be left on the chain. */ | |
c906108c SS |
3834 | |
3835 | struct breakpoint * | |
4d28f7a8 | 3836 | set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype) |
c906108c SS |
3837 | { |
3838 | register struct breakpoint *b, *b1; | |
3839 | ||
3840 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
3841 | memset (b, 0, sizeof (*b)); | |
3842 | b->address = sal.pc; | |
3843 | if (sal.symtab == NULL) | |
3844 | b->source_file = NULL; | |
3845 | else | |
3846 | b->source_file = savestring (sal.symtab->filename, | |
3847 | strlen (sal.symtab->filename)); | |
3848 | b->section = sal.section; | |
4d28f7a8 | 3849 | b->type = bptype; |
c906108c SS |
3850 | b->language = current_language->la_language; |
3851 | b->input_radix = input_radix; | |
3852 | b->thread = -1; | |
3853 | b->line_number = sal.line; | |
b5de0fa7 | 3854 | b->enable_state = bp_enabled; |
c906108c SS |
3855 | b->next = 0; |
3856 | b->silent = 0; | |
3857 | b->ignore_count = 0; | |
3858 | b->commands = NULL; | |
818dd999 | 3859 | b->frame_id = null_frame_id; |
c906108c SS |
3860 | b->dll_pathname = NULL; |
3861 | b->triggered_dll_pathname = NULL; | |
3862 | b->forked_inferior_pid = 0; | |
3863 | b->exec_pathname = NULL; | |
3086aeae | 3864 | b->ops = NULL; |
c906108c SS |
3865 | |
3866 | /* Add this breakpoint to the end of the chain | |
3867 | so that a list of breakpoints will come out in order | |
3868 | of increasing numbers. */ | |
3869 | ||
3870 | b1 = breakpoint_chain; | |
3871 | if (b1 == 0) | |
3872 | breakpoint_chain = b; | |
3873 | else | |
3874 | { | |
3875 | while (b1->next) | |
3876 | b1 = b1->next; | |
3877 | b1->next = b; | |
3878 | } | |
3879 | ||
9f60f21b | 3880 | check_duplicates (b); |
c906108c SS |
3881 | breakpoints_changed (); |
3882 | ||
3883 | return b; | |
3884 | } | |
3885 | ||
c2c6d25f JM |
3886 | |
3887 | /* Note that the breakpoint object B describes a permanent breakpoint | |
3888 | instruction, hard-wired into the inferior's code. */ | |
3889 | void | |
3890 | make_breakpoint_permanent (struct breakpoint *b) | |
3891 | { | |
b5de0fa7 | 3892 | b->enable_state = bp_permanent; |
c2c6d25f JM |
3893 | |
3894 | /* By definition, permanent breakpoints are already present in the code. */ | |
3895 | b->inserted = 1; | |
3896 | } | |
3897 | ||
1900040c MS |
3898 | static struct breakpoint * |
3899 | create_internal_breakpoint (CORE_ADDR address, enum bptype type) | |
3900 | { | |
3901 | static int internal_breakpoint_number = -1; | |
3902 | struct symtab_and_line sal; | |
3903 | struct breakpoint *b; | |
3904 | ||
fe39c653 | 3905 | init_sal (&sal); /* initialize to zeroes */ |
1900040c MS |
3906 | |
3907 | sal.pc = address; | |
3908 | sal.section = find_pc_overlay (sal.pc); | |
3909 | ||
3910 | b = set_raw_breakpoint (sal, type); | |
3911 | b->number = internal_breakpoint_number--; | |
3912 | b->disposition = disp_donttouch; | |
3913 | ||
3914 | return b; | |
3915 | } | |
3916 | ||
c906108c SS |
3917 | |
3918 | static void | |
fba45db2 | 3919 | create_longjmp_breakpoint (char *func_name) |
c906108c | 3920 | { |
c906108c | 3921 | struct breakpoint *b; |
1900040c | 3922 | struct minimal_symbol *m; |
c906108c | 3923 | |
1900040c MS |
3924 | if (func_name == NULL) |
3925 | b = create_internal_breakpoint (0, bp_longjmp_resume); | |
3926 | else | |
c906108c | 3927 | { |
1900040c | 3928 | if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL) |
c906108c | 3929 | return; |
1900040c MS |
3930 | |
3931 | b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp); | |
c906108c | 3932 | } |
c906108c | 3933 | |
b5de0fa7 | 3934 | b->enable_state = bp_disabled; |
c906108c SS |
3935 | b->silent = 1; |
3936 | if (func_name) | |
4fcf66da | 3937 | b->addr_string = xstrdup (func_name); |
c906108c SS |
3938 | } |
3939 | ||
53a5351d JM |
3940 | /* Call this routine when stepping and nexting to enable a breakpoint |
3941 | if we do a longjmp(). When we hit that breakpoint, call | |
c906108c SS |
3942 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
3943 | ||
3944 | void | |
fba45db2 | 3945 | enable_longjmp_breakpoint (void) |
c906108c SS |
3946 | { |
3947 | register struct breakpoint *b; | |
3948 | ||
3949 | ALL_BREAKPOINTS (b) | |
3950 | if (b->type == bp_longjmp) | |
c5aa993b | 3951 | { |
b5de0fa7 | 3952 | b->enable_state = bp_enabled; |
9f60f21b | 3953 | check_duplicates (b); |
c5aa993b | 3954 | } |
c906108c SS |
3955 | } |
3956 | ||
3957 | void | |
fba45db2 | 3958 | disable_longjmp_breakpoint (void) |
c906108c SS |
3959 | { |
3960 | register struct breakpoint *b; | |
3961 | ||
3962 | ALL_BREAKPOINTS (b) | |
c5aa993b | 3963 | if (b->type == bp_longjmp |
c906108c | 3964 | || b->type == bp_longjmp_resume) |
c5aa993b | 3965 | { |
b5de0fa7 | 3966 | b->enable_state = bp_disabled; |
9f60f21b | 3967 | check_duplicates (b); |
c5aa993b | 3968 | } |
c906108c SS |
3969 | } |
3970 | ||
1900040c MS |
3971 | static void |
3972 | create_overlay_event_breakpoint (char *func_name) | |
3973 | { | |
3974 | struct breakpoint *b; | |
3975 | struct minimal_symbol *m; | |
3976 | ||
3977 | if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL) | |
3978 | return; | |
3979 | ||
3980 | b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), | |
3981 | bp_overlay_event); | |
3982 | b->addr_string = xstrdup (func_name); | |
3983 | ||
3984 | if (overlay_debugging == ovly_auto) | |
c02f5703 MS |
3985 | { |
3986 | b->enable_state = bp_enabled; | |
3987 | overlay_events_enabled = 1; | |
3988 | } | |
1900040c | 3989 | else |
c02f5703 MS |
3990 | { |
3991 | b->enable_state = bp_disabled; | |
3992 | overlay_events_enabled = 0; | |
3993 | } | |
1900040c MS |
3994 | } |
3995 | ||
3996 | void | |
3997 | enable_overlay_breakpoints (void) | |
3998 | { | |
3999 | register struct breakpoint *b; | |
4000 | ||
4001 | ALL_BREAKPOINTS (b) | |
4002 | if (b->type == bp_overlay_event) | |
4003 | { | |
4004 | b->enable_state = bp_enabled; | |
4005 | check_duplicates (b); | |
c02f5703 | 4006 | overlay_events_enabled = 1; |
1900040c MS |
4007 | } |
4008 | } | |
4009 | ||
4010 | void | |
4011 | disable_overlay_breakpoints (void) | |
4012 | { | |
4013 | register struct breakpoint *b; | |
4014 | ||
4015 | ALL_BREAKPOINTS (b) | |
4016 | if (b->type == bp_overlay_event) | |
4017 | { | |
4018 | b->enable_state = bp_disabled; | |
4019 | check_duplicates (b); | |
c02f5703 | 4020 | overlay_events_enabled = 0; |
1900040c MS |
4021 | } |
4022 | } | |
4023 | ||
c4093a6a | 4024 | struct breakpoint * |
fba45db2 | 4025 | create_thread_event_breakpoint (CORE_ADDR address) |
c4093a6a JM |
4026 | { |
4027 | struct breakpoint *b; | |
c4093a6a | 4028 | |
1900040c | 4029 | b = create_internal_breakpoint (address, bp_thread_event); |
c4093a6a | 4030 | |
b5de0fa7 | 4031 | b->enable_state = bp_enabled; |
c4093a6a | 4032 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
d8ef46f5 | 4033 | xasprintf (&b->addr_string, "*0x%s", paddr (b->address)); |
c4093a6a JM |
4034 | |
4035 | return b; | |
4036 | } | |
4037 | ||
4038 | void | |
4039 | remove_thread_event_breakpoints (void) | |
4040 | { | |
4041 | struct breakpoint *b, *temp; | |
4042 | ||
4043 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4044 | if (b->type == bp_thread_event) | |
4045 | delete_breakpoint (b); | |
4046 | } | |
4047 | ||
c906108c SS |
4048 | #ifdef SOLIB_ADD |
4049 | void | |
fba45db2 | 4050 | remove_solib_event_breakpoints (void) |
c906108c SS |
4051 | { |
4052 | register struct breakpoint *b, *temp; | |
4053 | ||
4054 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4055 | if (b->type == bp_shlib_event) | |
3172dc30 | 4056 | delete_breakpoint (b); |
c906108c SS |
4057 | } |
4058 | ||
c2c6d25f | 4059 | struct breakpoint * |
fba45db2 | 4060 | create_solib_event_breakpoint (CORE_ADDR address) |
c906108c SS |
4061 | { |
4062 | struct breakpoint *b; | |
c2c6d25f | 4063 | |
1900040c | 4064 | b = create_internal_breakpoint (address, bp_shlib_event); |
c2c6d25f | 4065 | return b; |
c906108c SS |
4066 | } |
4067 | ||
104c1213 JM |
4068 | /* Disable any breakpoints that are on code in shared libraries. Only |
4069 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4070 | ||
c906108c | 4071 | void |
fba45db2 | 4072 | disable_breakpoints_in_shlibs (int silent) |
c906108c | 4073 | { |
c5aa993b JM |
4074 | struct breakpoint *b; |
4075 | int disabled_shlib_breaks = 0; | |
c906108c SS |
4076 | |
4077 | /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */ | |
4078 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4079 | { |
c906108c | 4080 | #if defined (PC_SOLIB) |
c5aa993b JM |
4081 | if (((b->type == bp_breakpoint) || |
4082 | (b->type == bp_hardware_breakpoint)) && | |
b5de0fa7 | 4083 | b->enable_state == bp_enabled && |
c5aa993b JM |
4084 | !b->duplicate && |
4085 | PC_SOLIB (b->address)) | |
4086 | { | |
b5de0fa7 | 4087 | b->enable_state = bp_shlib_disabled; |
c5aa993b JM |
4088 | if (!silent) |
4089 | { | |
4090 | if (!disabled_shlib_breaks) | |
4091 | { | |
4092 | target_terminal_ours_for_output (); | |
53a5351d | 4093 | warning ("Temporarily disabling shared library breakpoints:"); |
c5aa993b JM |
4094 | } |
4095 | disabled_shlib_breaks = 1; | |
53a5351d | 4096 | warning ("breakpoint #%d ", b->number); |
c5aa993b JM |
4097 | } |
4098 | } | |
c906108c | 4099 | #endif |
c5aa993b | 4100 | } |
c906108c SS |
4101 | } |
4102 | ||
4103 | /* Try to reenable any breakpoints in shared libraries. */ | |
4104 | void | |
fba45db2 | 4105 | re_enable_breakpoints_in_shlibs (void) |
c906108c SS |
4106 | { |
4107 | struct breakpoint *b; | |
4108 | ||
4109 | ALL_BREAKPOINTS (b) | |
b5de0fa7 | 4110 | if (b->enable_state == bp_shlib_disabled) |
c5aa993b JM |
4111 | { |
4112 | char buf[1]; | |
c906108c | 4113 | |
c5aa993b JM |
4114 | /* Do not reenable the breakpoint if the shared library |
4115 | is still not mapped in. */ | |
4116 | if (target_read_memory (b->address, buf, 1) == 0) | |
b5de0fa7 | 4117 | b->enable_state = bp_enabled; |
c5aa993b | 4118 | } |
c906108c SS |
4119 | } |
4120 | ||
4121 | #endif | |
4122 | ||
4123 | static void | |
fba45db2 KB |
4124 | solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname, |
4125 | char *cond_string, enum bptype bp_kind) | |
c906108c | 4126 | { |
c5aa993b | 4127 | struct breakpoint *b; |
c906108c | 4128 | struct symtabs_and_lines sals; |
c5aa993b JM |
4129 | struct cleanup *old_chain; |
4130 | struct cleanup *canonical_strings_chain = NULL; | |
c5aa993b JM |
4131 | char *addr_start = hookname; |
4132 | char *addr_end = NULL; | |
4133 | char **canonical = (char **) NULL; | |
4134 | int thread = -1; /* All threads. */ | |
4135 | ||
c906108c SS |
4136 | /* Set a breakpoint on the specified hook. */ |
4137 | sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical); | |
4138 | addr_end = hookname; | |
c5aa993b | 4139 | |
c906108c SS |
4140 | if (sals.nelts == 0) |
4141 | { | |
4142 | warning ("Unable to set a breakpoint on dynamic linker callback."); | |
4143 | warning ("Suggest linking with /opt/langtools/lib/end.o."); | |
4144 | warning ("GDB will be unable to track shl_load/shl_unload calls"); | |
4145 | return; | |
4146 | } | |
4147 | if (sals.nelts != 1) | |
4148 | { | |
53a5351d | 4149 | warning ("Unable to set unique breakpoint on dynamic linker callback."); |
c906108c SS |
4150 | warning ("GDB will be unable to track shl_load/shl_unload calls"); |
4151 | return; | |
4152 | } | |
4153 | ||
53a5351d JM |
4154 | /* Make sure that all storage allocated in decode_line_1 gets freed |
4155 | in case the following errors out. */ | |
b8c9b27d | 4156 | old_chain = make_cleanup (xfree, sals.sals); |
c5aa993b | 4157 | if (canonical != (char **) NULL) |
c906108c | 4158 | { |
b8c9b27d | 4159 | make_cleanup (xfree, canonical); |
c906108c SS |
4160 | canonical_strings_chain = make_cleanup (null_cleanup, 0); |
4161 | if (canonical[0] != NULL) | |
b8c9b27d | 4162 | make_cleanup (xfree, canonical[0]); |
c906108c | 4163 | } |
c5aa993b | 4164 | |
c906108c | 4165 | resolve_sal_pc (&sals.sals[0]); |
c5aa993b | 4166 | |
c906108c | 4167 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
c5aa993b | 4168 | if (canonical != (char **) NULL) |
c906108c | 4169 | discard_cleanups (canonical_strings_chain); |
c5aa993b | 4170 | |
4d28f7a8 | 4171 | b = set_raw_breakpoint (sals.sals[0], bp_kind); |
c906108c SS |
4172 | set_breakpoint_count (breakpoint_count + 1); |
4173 | b->number = breakpoint_count; | |
4174 | b->cond = NULL; | |
53a5351d JM |
4175 | b->cond_string = (cond_string == NULL) ? |
4176 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c | 4177 | b->thread = thread; |
c5aa993b JM |
4178 | |
4179 | if (canonical != (char **) NULL && canonical[0] != NULL) | |
c906108c SS |
4180 | b->addr_string = canonical[0]; |
4181 | else if (addr_start) | |
4182 | b->addr_string = savestring (addr_start, addr_end - addr_start); | |
c5aa993b | 4183 | |
b5de0fa7 EZ |
4184 | b->enable_state = bp_enabled; |
4185 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c5aa993b | 4186 | |
c906108c SS |
4187 | if (dll_pathname == NULL) |
4188 | b->dll_pathname = NULL; | |
4189 | else | |
4190 | { | |
4191 | b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1); | |
4192 | strcpy (b->dll_pathname, dll_pathname); | |
4193 | } | |
c5aa993b | 4194 | |
c906108c SS |
4195 | mention (b); |
4196 | do_cleanups (old_chain); | |
4197 | } | |
4198 | ||
4199 | void | |
fba45db2 KB |
4200 | create_solib_load_event_breakpoint (char *hookname, int tempflag, |
4201 | char *dll_pathname, char *cond_string) | |
c906108c | 4202 | { |
53a5351d JM |
4203 | solib_load_unload_1 (hookname, tempflag, dll_pathname, |
4204 | cond_string, bp_catch_load); | |
c906108c SS |
4205 | } |
4206 | ||
4207 | void | |
fba45db2 KB |
4208 | create_solib_unload_event_breakpoint (char *hookname, int tempflag, |
4209 | char *dll_pathname, char *cond_string) | |
c906108c | 4210 | { |
53a5351d JM |
4211 | solib_load_unload_1 (hookname,tempflag, dll_pathname, |
4212 | cond_string, bp_catch_unload); | |
c906108c SS |
4213 | } |
4214 | ||
4215 | static void | |
fba45db2 KB |
4216 | create_fork_vfork_event_catchpoint (int tempflag, char *cond_string, |
4217 | enum bptype bp_kind) | |
c906108c | 4218 | { |
c5aa993b JM |
4219 | struct symtab_and_line sal; |
4220 | struct breakpoint *b; | |
4221 | int thread = -1; /* All threads. */ | |
4222 | ||
fe39c653 | 4223 | init_sal (&sal); |
c906108c SS |
4224 | sal.pc = 0; |
4225 | sal.symtab = NULL; | |
4226 | sal.line = 0; | |
c5aa993b | 4227 | |
4d28f7a8 | 4228 | b = set_raw_breakpoint (sal, bp_kind); |
c906108c SS |
4229 | set_breakpoint_count (breakpoint_count + 1); |
4230 | b->number = breakpoint_count; | |
4231 | b->cond = NULL; | |
53a5351d JM |
4232 | b->cond_string = (cond_string == NULL) ? |
4233 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
4234 | b->thread = thread; |
4235 | b->addr_string = NULL; | |
b5de0fa7 EZ |
4236 | b->enable_state = bp_enabled; |
4237 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c | 4238 | b->forked_inferior_pid = 0; |
c5aa993b | 4239 | |
c906108c SS |
4240 | mention (b); |
4241 | } | |
4242 | ||
4243 | void | |
fba45db2 | 4244 | create_fork_event_catchpoint (int tempflag, char *cond_string) |
c906108c SS |
4245 | { |
4246 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork); | |
4247 | } | |
c5aa993b | 4248 | |
c906108c | 4249 | void |
fba45db2 | 4250 | create_vfork_event_catchpoint (int tempflag, char *cond_string) |
c906108c SS |
4251 | { |
4252 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork); | |
4253 | } | |
4254 | ||
4255 | void | |
fba45db2 | 4256 | create_exec_event_catchpoint (int tempflag, char *cond_string) |
c906108c | 4257 | { |
c5aa993b JM |
4258 | struct symtab_and_line sal; |
4259 | struct breakpoint *b; | |
4260 | int thread = -1; /* All threads. */ | |
c906108c | 4261 | |
fe39c653 | 4262 | init_sal (&sal); |
c906108c SS |
4263 | sal.pc = 0; |
4264 | sal.symtab = NULL; | |
4265 | sal.line = 0; | |
4266 | ||
4d28f7a8 | 4267 | b = set_raw_breakpoint (sal, bp_catch_exec); |
c906108c SS |
4268 | set_breakpoint_count (breakpoint_count + 1); |
4269 | b->number = breakpoint_count; | |
4270 | b->cond = NULL; | |
53a5351d JM |
4271 | b->cond_string = (cond_string == NULL) ? |
4272 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
4273 | b->thread = thread; |
4274 | b->addr_string = NULL; | |
b5de0fa7 EZ |
4275 | b->enable_state = bp_enabled; |
4276 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c | 4277 | |
c906108c SS |
4278 | mention (b); |
4279 | } | |
4280 | ||
4281 | static int | |
fba45db2 | 4282 | hw_breakpoint_used_count (void) |
c906108c SS |
4283 | { |
4284 | register struct breakpoint *b; | |
4285 | int i = 0; | |
4286 | ||
4287 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4288 | { |
b5de0fa7 | 4289 | if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled) |
c5aa993b JM |
4290 | i++; |
4291 | } | |
c906108c SS |
4292 | |
4293 | return i; | |
4294 | } | |
4295 | ||
4296 | static int | |
fba45db2 | 4297 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c SS |
4298 | { |
4299 | register struct breakpoint *b; | |
4300 | int i = 0; | |
4301 | ||
4302 | *other_type_used = 0; | |
4303 | ALL_BREAKPOINTS (b) | |
c5aa993b | 4304 | { |
b5de0fa7 | 4305 | if (b->enable_state == bp_enabled) |
c5aa993b JM |
4306 | { |
4307 | if (b->type == type) | |
4308 | i++; | |
4309 | else if ((b->type == bp_hardware_watchpoint || | |
4310 | b->type == bp_read_watchpoint || | |
4311 | b->type == bp_access_watchpoint) | |
b5de0fa7 | 4312 | && b->enable_state == bp_enabled) |
c5aa993b JM |
4313 | *other_type_used = 1; |
4314 | } | |
4315 | } | |
c906108c SS |
4316 | return i; |
4317 | } | |
4318 | ||
53a5351d JM |
4319 | /* Call this after hitting the longjmp() breakpoint. Use this to set |
4320 | a new breakpoint at the target of the jmp_buf. | |
c906108c | 4321 | |
53a5351d JM |
4322 | FIXME - This ought to be done by setting a temporary breakpoint |
4323 | that gets deleted automatically... */ | |
c906108c SS |
4324 | |
4325 | void | |
818dd999 | 4326 | set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id) |
c906108c SS |
4327 | { |
4328 | register struct breakpoint *b; | |
4329 | ||
4330 | ALL_BREAKPOINTS (b) | |
4331 | if (b->type == bp_longjmp_resume) | |
c5aa993b JM |
4332 | { |
4333 | b->address = pc; | |
b5de0fa7 | 4334 | b->enable_state = bp_enabled; |
818dd999 | 4335 | b->frame_id = frame_id; |
9f60f21b | 4336 | check_duplicates (b); |
c5aa993b JM |
4337 | return; |
4338 | } | |
c906108c SS |
4339 | } |
4340 | ||
4341 | void | |
fba45db2 | 4342 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 4343 | { |
c5aa993b | 4344 | struct breakpoint *b; |
c906108c SS |
4345 | |
4346 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4347 | { |
4348 | if (((b->type == bp_watchpoint) | |
4349 | || (b->type == bp_hardware_watchpoint) | |
4350 | || (b->type == bp_read_watchpoint) | |
4351 | || (b->type == bp_access_watchpoint) | |
4352 | || ep_is_exception_catchpoint (b)) | |
b5de0fa7 | 4353 | && (b->enable_state == bp_enabled)) |
c5aa993b | 4354 | { |
b5de0fa7 | 4355 | b->enable_state = bp_call_disabled; |
9f60f21b | 4356 | check_duplicates (b); |
c5aa993b JM |
4357 | } |
4358 | } | |
c906108c SS |
4359 | } |
4360 | ||
4361 | void | |
fba45db2 | 4362 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 4363 | { |
c5aa993b | 4364 | struct breakpoint *b; |
c906108c SS |
4365 | |
4366 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
4367 | { |
4368 | if (((b->type == bp_watchpoint) | |
4369 | || (b->type == bp_hardware_watchpoint) | |
4370 | || (b->type == bp_read_watchpoint) | |
4371 | || (b->type == bp_access_watchpoint) | |
4372 | || ep_is_exception_catchpoint (b)) | |
b5de0fa7 | 4373 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 4374 | { |
b5de0fa7 | 4375 | b->enable_state = bp_enabled; |
9f60f21b | 4376 | check_duplicates (b); |
c5aa993b JM |
4377 | } |
4378 | } | |
c906108c SS |
4379 | } |
4380 | ||
4381 | ||
4382 | /* Set a breakpoint that will evaporate an end of command | |
4383 | at address specified by SAL. | |
4384 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
4385 | ||
4386 | struct breakpoint * | |
818dd999 | 4387 | set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id, |
fba45db2 | 4388 | enum bptype type) |
c906108c SS |
4389 | { |
4390 | register struct breakpoint *b; | |
4d28f7a8 | 4391 | b = set_raw_breakpoint (sal, type); |
b5de0fa7 EZ |
4392 | b->enable_state = bp_enabled; |
4393 | b->disposition = disp_donttouch; | |
818dd999 | 4394 | b->frame_id = frame_id; |
c906108c SS |
4395 | |
4396 | /* If we're debugging a multi-threaded program, then we | |
4397 | want momentary breakpoints to be active in only a | |
4398 | single thread of control. */ | |
39f77062 KB |
4399 | if (in_thread_list (inferior_ptid)) |
4400 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
4401 | |
4402 | return b; | |
4403 | } | |
c906108c | 4404 | \f |
c5aa993b | 4405 | |
c906108c SS |
4406 | /* Tell the user we have just set a breakpoint B. */ |
4407 | ||
4408 | static void | |
fba45db2 | 4409 | mention (struct breakpoint *b) |
c906108c SS |
4410 | { |
4411 | int say_where = 0; | |
3b31d625 | 4412 | struct cleanup *old_chain, *ui_out_chain; |
8b93c638 JM |
4413 | struct ui_stream *stb; |
4414 | ||
4415 | stb = ui_out_stream_new (uiout); | |
b02eeafb | 4416 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
c906108c SS |
4417 | |
4418 | /* FIXME: This is misplaced; mention() is called by things (like hitting a | |
4419 | watchpoint) other than breakpoint creation. It should be possible to | |
4420 | clean this up and at the same time replace the random calls to | |
4421 | breakpoint_changed with this hook, as has already been done for | |
4422 | delete_breakpoint_hook and so on. */ | |
4423 | if (create_breakpoint_hook) | |
4424 | create_breakpoint_hook (b); | |
104c1213 | 4425 | breakpoint_create_event (b->number); |
c906108c | 4426 | |
3086aeae DJ |
4427 | if (b->ops != NULL && b->ops->print_mention != NULL) |
4428 | b->ops->print_mention (b); | |
4429 | else | |
4430 | switch (b->type) | |
4431 | { | |
4432 | case bp_none: | |
4433 | printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number); | |
4434 | break; | |
4435 | case bp_watchpoint: | |
4436 | ui_out_text (uiout, "Watchpoint "); | |
4437 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4438 | ui_out_field_int (uiout, "number", b->number); | |
4439 | ui_out_text (uiout, ": "); | |
4440 | print_expression (b->exp, stb->stream); | |
4441 | ui_out_field_stream (uiout, "exp", stb); | |
4442 | do_cleanups (ui_out_chain); | |
4443 | break; | |
4444 | case bp_hardware_watchpoint: | |
4445 | ui_out_text (uiout, "Hardware watchpoint "); | |
4446 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
4447 | ui_out_field_int (uiout, "number", b->number); | |
4448 | ui_out_text (uiout, ": "); | |
4449 | print_expression (b->exp, stb->stream); | |
4450 | ui_out_field_stream (uiout, "exp", stb); | |
4451 | do_cleanups (ui_out_chain); | |
4452 | break; | |
4453 | case bp_read_watchpoint: | |
4454 | ui_out_text (uiout, "Hardware read watchpoint "); | |
4455 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
4456 | ui_out_field_int (uiout, "number", b->number); | |
4457 | ui_out_text (uiout, ": "); | |
4458 | print_expression (b->exp, stb->stream); | |
4459 | ui_out_field_stream (uiout, "exp", stb); | |
4460 | do_cleanups (ui_out_chain); | |
4461 | break; | |
4462 | case bp_access_watchpoint: | |
4463 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
4464 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
4465 | ui_out_field_int (uiout, "number", b->number); | |
4466 | ui_out_text (uiout, ": "); | |
4467 | print_expression (b->exp, stb->stream); | |
4468 | ui_out_field_stream (uiout, "exp", stb); | |
4469 | do_cleanups (ui_out_chain); | |
4470 | break; | |
4471 | case bp_breakpoint: | |
4472 | if (ui_out_is_mi_like_p (uiout)) | |
4473 | { | |
4474 | say_where = 0; | |
4475 | break; | |
4476 | } | |
4477 | printf_filtered ("Breakpoint %d", b->number); | |
4478 | say_where = 1; | |
4479 | break; | |
4480 | case bp_hardware_breakpoint: | |
4481 | if (ui_out_is_mi_like_p (uiout)) | |
4482 | { | |
4483 | say_where = 0; | |
4484 | break; | |
4485 | } | |
4486 | printf_filtered ("Hardware assisted breakpoint %d", b->number); | |
4487 | say_where = 1; | |
4488 | break; | |
4489 | case bp_catch_load: | |
4490 | case bp_catch_unload: | |
4491 | printf_filtered ("Catchpoint %d (%s %s)", | |
4492 | b->number, | |
4493 | (b->type == bp_catch_load) ? "load" : "unload", | |
4494 | (b->dll_pathname != NULL) ? | |
4495 | b->dll_pathname : "<any library>"); | |
4496 | break; | |
4497 | case bp_catch_fork: | |
4498 | case bp_catch_vfork: | |
4499 | printf_filtered ("Catchpoint %d (%s)", | |
4500 | b->number, | |
4501 | (b->type == bp_catch_fork) ? "fork" : "vfork"); | |
4502 | break; | |
4503 | case bp_catch_exec: | |
4504 | printf_filtered ("Catchpoint %d (exec)", | |
4505 | b->number); | |
4506 | break; | |
4507 | case bp_catch_catch: | |
4508 | case bp_catch_throw: | |
4509 | printf_filtered ("Catchpoint %d (%s)", | |
4510 | b->number, | |
4511 | (b->type == bp_catch_catch) ? "catch" : "throw"); | |
4512 | break; | |
4513 | ||
4514 | case bp_until: | |
4515 | case bp_finish: | |
4516 | case bp_longjmp: | |
4517 | case bp_longjmp_resume: | |
4518 | case bp_step_resume: | |
4519 | case bp_through_sigtramp: | |
4520 | case bp_call_dummy: | |
4521 | case bp_watchpoint_scope: | |
4522 | case bp_shlib_event: | |
4523 | case bp_thread_event: | |
4524 | case bp_overlay_event: | |
4525 | break; | |
4526 | } | |
c906108c | 4527 | |
c906108c SS |
4528 | if (say_where) |
4529 | { | |
4530 | if (addressprint || b->source_file == NULL) | |
4531 | { | |
4532 | printf_filtered (" at "); | |
4533 | print_address_numeric (b->address, 1, gdb_stdout); | |
4534 | } | |
4535 | if (b->source_file) | |
4536 | printf_filtered (": file %s, line %d.", | |
4537 | b->source_file, b->line_number); | |
c906108c | 4538 | } |
8b93c638 | 4539 | do_cleanups (old_chain); |
9dc5e2a9 | 4540 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 4541 | return; |
c906108c SS |
4542 | printf_filtered ("\n"); |
4543 | } | |
c906108c | 4544 | \f |
c5aa993b | 4545 | |
c3f6f71d JM |
4546 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
4547 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i], | |
4548 | COND[i] and COND_STRING[i] values. | |
4549 | ||
4550 | NOTE: If the function succeeds, the caller is expected to cleanup | |
4551 | the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the | |
4552 | array contents). If the function fails (error() is called), the | |
4553 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4554 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
4555 | |
4556 | static void | |
c3f6f71d JM |
4557 | create_breakpoints (struct symtabs_and_lines sals, char **addr_string, |
4558 | struct expression **cond, char **cond_string, | |
4559 | enum bptype type, enum bpdisp disposition, | |
4560 | int thread, int ignore_count, int from_tty) | |
c906108c | 4561 | { |
c3f6f71d JM |
4562 | if (type == bp_hardware_breakpoint) |
4563 | { | |
4564 | int i = hw_breakpoint_used_count (); | |
4565 | int target_resources_ok = | |
4566 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
4567 | i + sals.nelts, 0); | |
4568 | if (target_resources_ok == 0) | |
4569 | error ("No hardware breakpoint support in the target."); | |
4570 | else if (target_resources_ok < 0) | |
4571 | error ("Hardware breakpoints used exceeds limit."); | |
4572 | } | |
c906108c | 4573 | |
c3f6f71d JM |
4574 | /* Now set all the breakpoints. */ |
4575 | { | |
4576 | int i; | |
4577 | for (i = 0; i < sals.nelts; i++) | |
4578 | { | |
4579 | struct breakpoint *b; | |
4580 | struct symtab_and_line sal = sals.sals[i]; | |
c906108c | 4581 | |
c3f6f71d JM |
4582 | if (from_tty) |
4583 | describe_other_breakpoints (sal.pc, sal.section); | |
4584 | ||
4d28f7a8 | 4585 | b = set_raw_breakpoint (sal, type); |
c3f6f71d JM |
4586 | set_breakpoint_count (breakpoint_count + 1); |
4587 | b->number = breakpoint_count; | |
c3f6f71d JM |
4588 | b->cond = cond[i]; |
4589 | b->thread = thread; | |
d8ef46f5 DJ |
4590 | if (addr_string[i]) |
4591 | b->addr_string = addr_string[i]; | |
4592 | else | |
4593 | /* addr_string has to be used or breakpoint_re_set will delete | |
4594 | me. */ | |
4595 | xasprintf (&b->addr_string, "*0x%s", paddr (b->address)); | |
c3f6f71d JM |
4596 | b->cond_string = cond_string[i]; |
4597 | b->ignore_count = ignore_count; | |
b5de0fa7 | 4598 | b->enable_state = bp_enabled; |
c3f6f71d JM |
4599 | b->disposition = disposition; |
4600 | mention (b); | |
4601 | } | |
4602 | } | |
4603 | } | |
c906108c | 4604 | |
c3f6f71d JM |
4605 | /* Parse ARG which is assumed to be a SAL specification possibly |
4606 | followed by conditionals. On return, SALS contains an array of SAL | |
4607 | addresses found. ADDR_STRING contains a vector of (canonical) | |
4608 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 4609 | |
c3f6f71d JM |
4610 | void |
4611 | parse_breakpoint_sals (char **address, | |
4612 | struct symtabs_and_lines *sals, | |
4613 | char ***addr_string) | |
4614 | { | |
4615 | char *addr_start = *address; | |
4616 | *addr_string = NULL; | |
4617 | /* If no arg given, or if first arg is 'if ', use the default | |
4618 | breakpoint. */ | |
4619 | if ((*address) == NULL | |
4620 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
4621 | { |
4622 | if (default_breakpoint_valid) | |
4623 | { | |
c3f6f71d | 4624 | struct symtab_and_line sal; |
fe39c653 | 4625 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 4626 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
4627 | xmalloc (sizeof (struct symtab_and_line)); |
4628 | sal.pc = default_breakpoint_address; | |
4629 | sal.line = default_breakpoint_line; | |
4630 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 4631 | sal.section = find_pc_overlay (sal.pc); |
c3f6f71d JM |
4632 | sals->sals[0] = sal; |
4633 | sals->nelts = 1; | |
c906108c SS |
4634 | } |
4635 | else | |
4636 | error ("No default breakpoint address now."); | |
4637 | } | |
4638 | else | |
4639 | { | |
c906108c | 4640 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
4641 | current_source_symtab (which is decode_line_1's default). This |
4642 | should produce the results we want almost all of the time while | |
1aeae86e AF |
4643 | leaving default_breakpoint_* alone. |
4644 | ObjC: However, don't match an Objective-C method name which | |
4645 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 4646 | |
c214a6fd | 4647 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 4648 | |
c906108c | 4649 | if (default_breakpoint_valid |
0378c332 | 4650 | && (!cursal.symtab |
1aeae86e AF |
4651 | || ((strchr ("+-", (*address)[0]) != NULL) |
4652 | && ((*address)[1] != '[')))) | |
c3f6f71d JM |
4653 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
4654 | default_breakpoint_line, addr_string); | |
c906108c | 4655 | else |
389e51db | 4656 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string); |
c906108c | 4657 | } |
c3f6f71d JM |
4658 | /* For any SAL that didn't have a canonical string, fill one in. */ |
4659 | if (sals->nelts > 0 && *addr_string == NULL) | |
4660 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
4661 | if (addr_start != (*address)) | |
c906108c | 4662 | { |
c3f6f71d JM |
4663 | int i; |
4664 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 4665 | { |
c3f6f71d JM |
4666 | /* Add the string if not present. */ |
4667 | if ((*addr_string)[i] == NULL) | |
4668 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
4669 | } |
4670 | } | |
c3f6f71d | 4671 | } |
c906108c | 4672 | |
c906108c | 4673 | |
c3f6f71d JM |
4674 | /* Convert each SAL into a real PC. Verify that the PC can be |
4675 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 4676 | |
c3f6f71d JM |
4677 | void |
4678 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, | |
4679 | char *address) | |
4680 | { | |
4681 | int i; | |
4682 | for (i = 0; i < sals->nelts; i++) | |
4683 | { | |
4684 | resolve_sal_pc (&sals->sals[i]); | |
c906108c SS |
4685 | |
4686 | /* It's possible for the PC to be nonzero, but still an illegal | |
4687 | value on some targets. | |
4688 | ||
4689 | For example, on HP-UX if you start gdb, and before running the | |
4690 | inferior you try to set a breakpoint on a shared library function | |
4691 | "foo" where the inferior doesn't call "foo" directly but does | |
4692 | pass its address to another function call, then we do find a | |
4693 | minimal symbol for the "foo", but it's address is invalid. | |
4694 | (Appears to be an index into a table that the loader sets up | |
4695 | when the inferior is run.) | |
4696 | ||
4697 | Give the target a chance to bless sals.sals[i].pc before we | |
4698 | try to make a breakpoint for it. */ | |
c3f6f71d | 4699 | if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc)) |
c5aa993b | 4700 | { |
c3f6f71d JM |
4701 | if (address == NULL) |
4702 | error ("Cannot break without a running program."); | |
4703 | else | |
4704 | error ("Cannot break on %s without a running program.", | |
4705 | address); | |
c5aa993b | 4706 | } |
c3f6f71d JM |
4707 | } |
4708 | } | |
4709 | ||
4710 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
4711 | flag: first bit : 0 non-temporary, 1 temporary. | |
4712 | second bit : 0 normal breakpoint, 1 hardware breakpoint. */ | |
c5aa993b | 4713 | |
c3f6f71d | 4714 | static void |
fba45db2 | 4715 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d JM |
4716 | { |
4717 | int tempflag, hardwareflag; | |
4718 | struct symtabs_and_lines sals; | |
4719 | register struct expression **cond = 0; | |
4720 | /* Pointers in arg to the start, and one past the end, of the | |
4721 | condition. */ | |
4722 | char **cond_string = (char **) NULL; | |
4723 | char *addr_start = arg; | |
4724 | char **addr_string; | |
4725 | struct cleanup *old_chain; | |
4726 | struct cleanup *breakpoint_chain = NULL; | |
4727 | int i; | |
4728 | int thread = -1; | |
4729 | int ignore_count = 0; | |
4730 | ||
4731 | hardwareflag = flag & BP_HARDWAREFLAG; | |
4732 | tempflag = flag & BP_TEMPFLAG; | |
c906108c | 4733 | |
c3f6f71d JM |
4734 | sals.sals = NULL; |
4735 | sals.nelts = 0; | |
4736 | addr_string = NULL; | |
4737 | parse_breakpoint_sals (&arg, &sals, &addr_string); | |
4738 | ||
4739 | if (!sals.nelts) | |
4740 | return; | |
4741 | ||
4742 | /* Create a chain of things that always need to be cleaned up. */ | |
4743 | old_chain = make_cleanup (null_cleanup, 0); | |
4744 | ||
4745 | /* Make sure that all storage allocated to SALS gets freed. */ | |
b8c9b27d | 4746 | make_cleanup (xfree, sals.sals); |
c3f6f71d JM |
4747 | |
4748 | /* Cleanup the addr_string array but not its contents. */ | |
b8c9b27d | 4749 | make_cleanup (xfree, addr_string); |
c3f6f71d JM |
4750 | |
4751 | /* Allocate space for all the cond expressions. */ | |
4752 | cond = xcalloc (sals.nelts, sizeof (struct expression *)); | |
b8c9b27d | 4753 | make_cleanup (xfree, cond); |
c3f6f71d JM |
4754 | |
4755 | /* Allocate space for all the cond strings. */ | |
4756 | cond_string = xcalloc (sals.nelts, sizeof (char **)); | |
b8c9b27d | 4757 | make_cleanup (xfree, cond_string); |
c3f6f71d JM |
4758 | |
4759 | /* ----------------------------- SNIP ----------------------------- | |
4760 | Anything added to the cleanup chain beyond this point is assumed | |
4761 | to be part of a breakpoint. If the breakpoint create succeeds | |
4762 | then the memory is not reclaimed. */ | |
4763 | breakpoint_chain = make_cleanup (null_cleanup, 0); | |
4764 | ||
4765 | /* Mark the contents of the addr_string for cleanup. These go on | |
4766 | the breakpoint_chain and only occure if the breakpoint create | |
4767 | fails. */ | |
4768 | for (i = 0; i < sals.nelts; i++) | |
4769 | { | |
4770 | if (addr_string[i] != NULL) | |
b8c9b27d | 4771 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
4772 | } |
4773 | ||
4774 | /* Resolve all line numbers to PC's and verify that the addresses | |
4775 | are ok for the target. */ | |
4776 | breakpoint_sals_to_pc (&sals, addr_start); | |
4777 | ||
4778 | /* Verify that condition can be parsed, before setting any | |
4779 | breakpoints. Allocate a separate condition expression for each | |
4780 | breakpoint. */ | |
4781 | thread = -1; /* No specific thread yet */ | |
4782 | for (i = 0; i < sals.nelts; i++) | |
4783 | { | |
4784 | char *tok = arg; | |
c906108c SS |
4785 | while (tok && *tok) |
4786 | { | |
c3f6f71d JM |
4787 | char *end_tok; |
4788 | int toklen; | |
4789 | char *cond_start = NULL; | |
4790 | char *cond_end = NULL; | |
c906108c SS |
4791 | while (*tok == ' ' || *tok == '\t') |
4792 | tok++; | |
4793 | ||
4794 | end_tok = tok; | |
4795 | ||
4796 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
4797 | end_tok++; | |
4798 | ||
4799 | toklen = end_tok - tok; | |
4800 | ||
4801 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
4802 | { | |
4803 | tok = cond_start = end_tok + 1; | |
c3f6f71d | 4804 | cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); |
b8c9b27d | 4805 | make_cleanup (xfree, cond[i]); |
c906108c | 4806 | cond_end = tok; |
c3f6f71d | 4807 | cond_string[i] = savestring (cond_start, cond_end - cond_start); |
b8c9b27d | 4808 | make_cleanup (xfree, cond_string[i]); |
c906108c SS |
4809 | } |
4810 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
4811 | { | |
4812 | char *tmptok; | |
4813 | ||
4814 | tok = end_tok + 1; | |
4815 | tmptok = tok; | |
4816 | thread = strtol (tok, &tok, 0); | |
4817 | if (tok == tmptok) | |
4818 | error ("Junk after thread keyword."); | |
4819 | if (!valid_thread_id (thread)) | |
4820 | error ("Unknown thread %d\n", thread); | |
4821 | } | |
4822 | else | |
4823 | error ("Junk at end of arguments."); | |
4824 | } | |
4825 | } | |
c906108c | 4826 | |
c3f6f71d JM |
4827 | create_breakpoints (sals, addr_string, cond, cond_string, |
4828 | hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, | |
b5de0fa7 | 4829 | tempflag ? disp_del : disp_donttouch, |
c3f6f71d JM |
4830 | thread, ignore_count, from_tty); |
4831 | ||
4832 | if (sals.nelts > 1) | |
4833 | { | |
4834 | warning ("Multiple breakpoints were set."); | |
4835 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 4836 | } |
c3f6f71d JM |
4837 | /* That's it. Discard the cleanups for data inserted into the |
4838 | breakpoint. */ | |
4839 | discard_cleanups (breakpoint_chain); | |
4840 | /* But cleanup everything else. */ | |
4841 | do_cleanups (old_chain); | |
4842 | } | |
c906108c | 4843 | |
c3f6f71d JM |
4844 | /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function, |
4845 | linenum or *address) with COND and IGNORE_COUNT. */ | |
c906108c | 4846 | |
c3f6f71d JM |
4847 | struct captured_breakpoint_args |
4848 | { | |
4849 | char *address; | |
4850 | char *condition; | |
4851 | int hardwareflag; | |
4852 | int tempflag; | |
4853 | int thread; | |
4854 | int ignore_count; | |
4855 | }; | |
4856 | ||
4857 | static int | |
4858 | do_captured_breakpoint (void *data) | |
4859 | { | |
4860 | struct captured_breakpoint_args *args = data; | |
4861 | struct symtabs_and_lines sals; | |
4862 | register struct expression **cond; | |
4863 | struct cleanup *old_chain; | |
4864 | struct cleanup *breakpoint_chain = NULL; | |
4865 | int i; | |
4866 | char **addr_string; | |
4867 | char **cond_string; | |
4868 | ||
4869 | char *address_end; | |
4870 | ||
4871 | /* Parse the source and lines spec. Delay check that the expression | |
4872 | didn't contain trailing garbage until after cleanups are in | |
4873 | place. */ | |
4874 | sals.sals = NULL; | |
4875 | sals.nelts = 0; | |
4876 | address_end = args->address; | |
4877 | addr_string = NULL; | |
4878 | parse_breakpoint_sals (&address_end, &sals, &addr_string); | |
4879 | ||
4880 | if (!sals.nelts) | |
4881 | return GDB_RC_NONE; | |
4882 | ||
4883 | /* Create a chain of things at always need to be cleaned up. */ | |
4884 | old_chain = make_cleanup (null_cleanup, 0); | |
4885 | ||
4886 | /* Always have a addr_string array, even if it is empty. */ | |
b8c9b27d | 4887 | make_cleanup (xfree, addr_string); |
c3f6f71d JM |
4888 | |
4889 | /* Make sure that all storage allocated to SALS gets freed. */ | |
b8c9b27d | 4890 | make_cleanup (xfree, sals.sals); |
c3f6f71d JM |
4891 | |
4892 | /* Allocate space for all the cond expressions. */ | |
4893 | cond = xcalloc (sals.nelts, sizeof (struct expression *)); | |
b8c9b27d | 4894 | make_cleanup (xfree, cond); |
c3f6f71d JM |
4895 | |
4896 | /* Allocate space for all the cond strings. */ | |
4897 | cond_string = xcalloc (sals.nelts, sizeof (char **)); | |
b8c9b27d | 4898 | make_cleanup (xfree, cond_string); |
c3f6f71d JM |
4899 | |
4900 | /* ----------------------------- SNIP ----------------------------- | |
4901 | Anything added to the cleanup chain beyond this point is assumed | |
4902 | to be part of a breakpoint. If the breakpoint create goes | |
4903 | through then that memory is not cleaned up. */ | |
4904 | breakpoint_chain = make_cleanup (null_cleanup, 0); | |
4905 | ||
4906 | /* Mark the contents of the addr_string for cleanup. These go on | |
4907 | the breakpoint_chain and only occure if the breakpoint create | |
4908 | fails. */ | |
c906108c SS |
4909 | for (i = 0; i < sals.nelts; i++) |
4910 | { | |
c3f6f71d | 4911 | if (addr_string[i] != NULL) |
b8c9b27d | 4912 | make_cleanup (xfree, addr_string[i]); |
c906108c SS |
4913 | } |
4914 | ||
c3f6f71d JM |
4915 | /* Wait until now before checking for garbage at the end of the |
4916 | address. That way cleanups can take care of freeing any | |
4917 | memory. */ | |
4918 | if (*address_end != '\0') | |
4919 | error ("Garbage %s following breakpoint address", address_end); | |
4920 | ||
4921 | /* Resolve all line numbers to PC's. */ | |
4922 | breakpoint_sals_to_pc (&sals, args->address); | |
4923 | ||
4924 | /* Verify that conditions can be parsed, before setting any | |
4925 | breakpoints. */ | |
4926 | for (i = 0; i < sals.nelts; i++) | |
c906108c | 4927 | { |
c3f6f71d JM |
4928 | if (args->condition != NULL) |
4929 | { | |
4930 | char *tok = args->condition; | |
4931 | cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); | |
4932 | if (*tok != '\0') | |
4933 | error ("Garbage %s follows condition", tok); | |
b8c9b27d | 4934 | make_cleanup (xfree, cond[i]); |
c3f6f71d JM |
4935 | cond_string[i] = xstrdup (args->condition); |
4936 | } | |
c906108c | 4937 | } |
c3f6f71d JM |
4938 | |
4939 | create_breakpoints (sals, addr_string, cond, cond_string, | |
4940 | args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, | |
b5de0fa7 | 4941 | args->tempflag ? disp_del : disp_donttouch, |
c3f6f71d JM |
4942 | args->thread, args->ignore_count, 0/*from-tty*/); |
4943 | ||
4944 | /* That's it. Discard the cleanups for data inserted into the | |
4945 | breakpoint. */ | |
4946 | discard_cleanups (breakpoint_chain); | |
4947 | /* But cleanup everything else. */ | |
c906108c | 4948 | do_cleanups (old_chain); |
c3f6f71d | 4949 | return GDB_RC_OK; |
c906108c SS |
4950 | } |
4951 | ||
c3f6f71d JM |
4952 | enum gdb_rc |
4953 | gdb_breakpoint (char *address, char *condition, | |
4954 | int hardwareflag, int tempflag, | |
4955 | int thread, int ignore_count) | |
4956 | { | |
4957 | struct captured_breakpoint_args args; | |
4958 | args.address = address; | |
4959 | args.condition = condition; | |
4960 | args.hardwareflag = hardwareflag; | |
4961 | args.tempflag = tempflag; | |
4962 | args.thread = thread; | |
4963 | args.ignore_count = ignore_count; | |
4964 | return catch_errors (do_captured_breakpoint, &args, | |
4965 | NULL, RETURN_MASK_ALL); | |
4966 | } | |
4967 | ||
4968 | ||
c906108c | 4969 | static void |
fba45db2 | 4970 | break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty) |
c906108c SS |
4971 | { |
4972 | struct frame_info *frame; | |
4973 | CORE_ADDR low, high, selected_pc = 0; | |
7f7e9482 AC |
4974 | char *extra_args = NULL; |
4975 | char *level_arg; | |
4976 | char *addr_string; | |
c906108c SS |
4977 | int extra_args_len = 0, if_arg = 0; |
4978 | ||
4979 | if (!arg || | |
4980 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
4981 | { | |
4982 | ||
4983 | if (default_breakpoint_valid) | |
4984 | { | |
6e7f8b9c | 4985 | if (deprecated_selected_frame) |
c906108c | 4986 | { |
bdd78e62 | 4987 | selected_pc = get_frame_pc (deprecated_selected_frame); |
c906108c SS |
4988 | if (arg) |
4989 | if_arg = 1; | |
4990 | } | |
4991 | else | |
4992 | error ("No selected frame."); | |
4993 | } | |
4994 | else | |
4995 | error ("No default breakpoint address now."); | |
4996 | } | |
4997 | else | |
4998 | { | |
4999 | extra_args = strchr (arg, ' '); | |
5000 | if (extra_args) | |
5001 | { | |
5002 | extra_args++; | |
5003 | extra_args_len = strlen (extra_args); | |
5004 | level_arg = (char *) xmalloc (extra_args - arg); | |
5005 | strncpy (level_arg, arg, extra_args - arg - 1); | |
5006 | level_arg[extra_args - arg - 1] = '\0'; | |
5007 | } | |
5008 | else | |
5009 | { | |
5010 | level_arg = (char *) xmalloc (strlen (arg) + 1); | |
5011 | strcpy (level_arg, arg); | |
5012 | } | |
5013 | ||
5014 | frame = parse_frame_specification (level_arg); | |
5015 | if (frame) | |
bdd78e62 | 5016 | selected_pc = get_frame_pc (frame); |
c906108c SS |
5017 | else |
5018 | selected_pc = 0; | |
5019 | } | |
5020 | if (if_arg) | |
5021 | { | |
5022 | extra_args = arg; | |
c5aa993b | 5023 | extra_args_len = strlen (arg); |
c906108c SS |
5024 | } |
5025 | ||
5026 | if (selected_pc) | |
5027 | { | |
c5aa993b | 5028 | if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high)) |
c906108c SS |
5029 | { |
5030 | addr_string = (char *) xmalloc (26 + extra_args_len); | |
5031 | if (extra_args_len) | |
d4f3574e | 5032 | sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args); |
c906108c | 5033 | else |
d4f3574e | 5034 | sprintf (addr_string, "*0x%s", paddr_nz (high)); |
c906108c | 5035 | break_command_1 (addr_string, flag, from_tty); |
b8c9b27d | 5036 | xfree (addr_string); |
c906108c SS |
5037 | } |
5038 | else | |
5039 | error ("No function contains the specified address"); | |
5040 | } | |
5041 | else | |
5042 | error ("Unable to set breakpoint at procedure exit"); | |
5043 | } | |
5044 | ||
5045 | ||
5046 | static void | |
fba45db2 | 5047 | break_at_finish_command_1 (char *arg, int flag, int from_tty) |
c906108c SS |
5048 | { |
5049 | char *addr_string, *break_string, *beg_addr_string; | |
5050 | CORE_ADDR low, high; | |
5051 | struct symtabs_and_lines sals; | |
5052 | struct symtab_and_line sal; | |
5053 | struct cleanup *old_chain; | |
7f7e9482 | 5054 | char *extra_args = NULL; |
c906108c SS |
5055 | int extra_args_len = 0; |
5056 | int i, if_arg = 0; | |
5057 | ||
5058 | if (!arg || | |
5059 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
5060 | { | |
5061 | if (default_breakpoint_valid) | |
5062 | { | |
6e7f8b9c | 5063 | if (deprecated_selected_frame) |
c906108c SS |
5064 | { |
5065 | addr_string = (char *) xmalloc (15); | |
bdd78e62 AC |
5066 | sprintf (addr_string, "*0x%s", |
5067 | paddr_nz (get_frame_pc (deprecated_selected_frame))); | |
c906108c SS |
5068 | if (arg) |
5069 | if_arg = 1; | |
5070 | } | |
5071 | else | |
5072 | error ("No selected frame."); | |
5073 | } | |
5074 | else | |
5075 | error ("No default breakpoint address now."); | |
5076 | } | |
5077 | else | |
5078 | { | |
5079 | addr_string = (char *) xmalloc (strlen (arg) + 1); | |
5080 | strcpy (addr_string, arg); | |
5081 | } | |
5082 | ||
5083 | if (if_arg) | |
5084 | { | |
5085 | extra_args = arg; | |
c5aa993b JM |
5086 | extra_args_len = strlen (arg); |
5087 | } | |
5088 | else if (arg) | |
5089 | { | |
5090 | /* get the stuff after the function name or address */ | |
5091 | extra_args = strchr (arg, ' '); | |
5092 | if (extra_args) | |
5093 | { | |
5094 | extra_args++; | |
5095 | extra_args_len = strlen (extra_args); | |
5096 | } | |
c906108c | 5097 | } |
c906108c SS |
5098 | |
5099 | sals.sals = NULL; | |
5100 | sals.nelts = 0; | |
5101 | ||
c5aa993b JM |
5102 | beg_addr_string = addr_string; |
5103 | sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0, | |
5104 | (char ***) NULL); | |
c906108c | 5105 | |
b8c9b27d KB |
5106 | xfree (beg_addr_string); |
5107 | old_chain = make_cleanup (xfree, sals.sals); | |
c906108c SS |
5108 | for (i = 0; (i < sals.nelts); i++) |
5109 | { | |
5110 | sal = sals.sals[i]; | |
c5aa993b | 5111 | if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high)) |
c906108c SS |
5112 | { |
5113 | break_string = (char *) xmalloc (extra_args_len + 26); | |
5114 | if (extra_args_len) | |
d4f3574e | 5115 | sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args); |
c906108c | 5116 | else |
d4f3574e | 5117 | sprintf (break_string, "*0x%s", paddr_nz (high)); |
c906108c | 5118 | break_command_1 (break_string, flag, from_tty); |
b8c9b27d | 5119 | xfree (break_string); |
c906108c SS |
5120 | } |
5121 | else | |
5122 | error ("No function contains the specified address"); | |
5123 | } | |
5124 | if (sals.nelts > 1) | |
5125 | { | |
53a5351d JM |
5126 | warning ("Multiple breakpoints were set.\n"); |
5127 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 5128 | } |
c5aa993b | 5129 | do_cleanups (old_chain); |
c906108c SS |
5130 | } |
5131 | ||
5132 | ||
5133 | /* Helper function for break_command_1 and disassemble_command. */ | |
5134 | ||
5135 | void | |
fba45db2 | 5136 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
5137 | { |
5138 | CORE_ADDR pc; | |
5139 | ||
5140 | if (sal->pc == 0 && sal->symtab != NULL) | |
5141 | { | |
5142 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
5143 | error ("No line %d in file \"%s\".", | |
5144 | sal->line, sal->symtab->filename); | |
5145 | sal->pc = pc; | |
5146 | } | |
5147 | ||
5148 | if (sal->section == 0 && sal->symtab != NULL) | |
5149 | { | |
5150 | struct blockvector *bv; | |
c5aa993b JM |
5151 | struct block *b; |
5152 | struct symbol *sym; | |
5153 | int index; | |
c906108c | 5154 | |
c5aa993b | 5155 | bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab); |
c906108c SS |
5156 | if (bv != NULL) |
5157 | { | |
c5aa993b | 5158 | b = BLOCKVECTOR_BLOCK (bv, index); |
c906108c SS |
5159 | sym = block_function (b); |
5160 | if (sym != NULL) | |
5161 | { | |
5162 | fixup_symbol_section (sym, sal->symtab->objfile); | |
5163 | sal->section = SYMBOL_BFD_SECTION (sym); | |
5164 | } | |
5165 | else | |
5166 | { | |
5167 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
5168 | have to look harder. This case can be executed if we have |
5169 | line numbers but no functions (as can happen in assembly | |
5170 | source). */ | |
c906108c | 5171 | |
c5aa993b | 5172 | struct minimal_symbol *msym; |
c906108c SS |
5173 | |
5174 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
5175 | if (msym) | |
5176 | sal->section = SYMBOL_BFD_SECTION (msym); | |
5177 | } | |
5178 | } | |
5179 | } | |
5180 | } | |
5181 | ||
5182 | void | |
fba45db2 | 5183 | break_command (char *arg, int from_tty) |
c906108c SS |
5184 | { |
5185 | break_command_1 (arg, 0, from_tty); | |
5186 | } | |
5187 | ||
502fd408 | 5188 | void |
fba45db2 | 5189 | break_at_finish_command (char *arg, int from_tty) |
c906108c SS |
5190 | { |
5191 | break_at_finish_command_1 (arg, 0, from_tty); | |
5192 | } | |
5193 | ||
502fd408 | 5194 | void |
fba45db2 | 5195 | break_at_finish_at_depth_command (char *arg, int from_tty) |
c906108c SS |
5196 | { |
5197 | break_at_finish_at_depth_command_1 (arg, 0, from_tty); | |
5198 | } | |
5199 | ||
5200 | void | |
fba45db2 | 5201 | tbreak_command (char *arg, int from_tty) |
c906108c SS |
5202 | { |
5203 | break_command_1 (arg, BP_TEMPFLAG, from_tty); | |
5204 | } | |
5205 | ||
502fd408 | 5206 | void |
fba45db2 | 5207 | tbreak_at_finish_command (char *arg, int from_tty) |
c906108c SS |
5208 | { |
5209 | break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty); | |
5210 | } | |
5211 | ||
5212 | static void | |
fba45db2 | 5213 | hbreak_command (char *arg, int from_tty) |
c906108c SS |
5214 | { |
5215 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); | |
5216 | } | |
5217 | ||
5218 | static void | |
fba45db2 | 5219 | thbreak_command (char *arg, int from_tty) |
c906108c SS |
5220 | { |
5221 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); | |
5222 | } | |
5223 | ||
5224 | static void | |
fba45db2 | 5225 | stop_command (char *arg, int from_tty) |
c906108c SS |
5226 | { |
5227 | printf_filtered ("Specify the type of breakpoint to set.\n\ | |
5228 | Usage: stop in <function | address>\n\ | |
5229 | stop at <line>\n"); | |
5230 | } | |
5231 | ||
5232 | static void | |
fba45db2 | 5233 | stopin_command (char *arg, int from_tty) |
c906108c SS |
5234 | { |
5235 | int badInput = 0; | |
5236 | ||
c5aa993b | 5237 | if (arg == (char *) NULL) |
c906108c SS |
5238 | badInput = 1; |
5239 | else if (*arg != '*') | |
5240 | { | |
5241 | char *argptr = arg; | |
5242 | int hasColon = 0; | |
5243 | ||
53a5351d JM |
5244 | /* look for a ':'. If this is a line number specification, then |
5245 | say it is bad, otherwise, it should be an address or | |
5246 | function/method name */ | |
c906108c | 5247 | while (*argptr && !hasColon) |
c5aa993b JM |
5248 | { |
5249 | hasColon = (*argptr == ':'); | |
5250 | argptr++; | |
5251 | } | |
c906108c SS |
5252 | |
5253 | if (hasColon) | |
c5aa993b | 5254 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 5255 | else |
c5aa993b | 5256 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
5257 | } |
5258 | ||
5259 | if (badInput) | |
c5aa993b | 5260 | printf_filtered ("Usage: stop in <function | address>\n"); |
c906108c SS |
5261 | else |
5262 | break_command_1 (arg, 0, from_tty); | |
5263 | } | |
5264 | ||
5265 | static void | |
fba45db2 | 5266 | stopat_command (char *arg, int from_tty) |
c906108c SS |
5267 | { |
5268 | int badInput = 0; | |
5269 | ||
c5aa993b | 5270 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
5271 | badInput = 1; |
5272 | else | |
5273 | { | |
5274 | char *argptr = arg; | |
5275 | int hasColon = 0; | |
5276 | ||
5277 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 5278 | it is probably a line number. */ |
c906108c | 5279 | while (*argptr && !hasColon) |
c5aa993b JM |
5280 | { |
5281 | hasColon = (*argptr == ':'); | |
5282 | argptr++; | |
5283 | } | |
c906108c SS |
5284 | |
5285 | if (hasColon) | |
c5aa993b | 5286 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 5287 | else |
c5aa993b | 5288 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
5289 | } |
5290 | ||
5291 | if (badInput) | |
c5aa993b | 5292 | printf_filtered ("Usage: stop at <line>\n"); |
c906108c SS |
5293 | else |
5294 | break_command_1 (arg, 0, from_tty); | |
5295 | } | |
5296 | ||
5297 | /* ARGSUSED */ | |
53a5351d JM |
5298 | /* accessflag: hw_write: watch write, |
5299 | hw_read: watch read, | |
5300 | hw_access: watch access (read or write) */ | |
c906108c | 5301 | static void |
fba45db2 | 5302 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c SS |
5303 | { |
5304 | struct breakpoint *b; | |
5305 | struct symtab_and_line sal; | |
5306 | struct expression *exp; | |
5307 | struct block *exp_valid_block; | |
5308 | struct value *val, *mark; | |
5309 | struct frame_info *frame; | |
5310 | struct frame_info *prev_frame = NULL; | |
5311 | char *exp_start = NULL; | |
5312 | char *exp_end = NULL; | |
5313 | char *tok, *end_tok; | |
5314 | int toklen; | |
5315 | char *cond_start = NULL; | |
5316 | char *cond_end = NULL; | |
5317 | struct expression *cond = NULL; | |
5318 | int i, other_type_used, target_resources_ok = 0; | |
5319 | enum bptype bp_type; | |
5320 | int mem_cnt = 0; | |
5321 | ||
fe39c653 | 5322 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 5323 | |
c906108c SS |
5324 | /* Parse arguments. */ |
5325 | innermost_block = NULL; | |
5326 | exp_start = arg; | |
5327 | exp = parse_exp_1 (&arg, 0, 0); | |
5328 | exp_end = arg; | |
5329 | exp_valid_block = innermost_block; | |
5330 | mark = value_mark (); | |
5331 | val = evaluate_expression (exp); | |
5332 | release_value (val); | |
5333 | if (VALUE_LAZY (val)) | |
5334 | value_fetch_lazy (val); | |
5335 | ||
5336 | tok = arg; | |
5337 | while (*tok == ' ' || *tok == '\t') | |
5338 | tok++; | |
5339 | end_tok = tok; | |
5340 | ||
5341 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5342 | end_tok++; | |
5343 | ||
5344 | toklen = end_tok - tok; | |
5345 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5346 | { | |
5347 | tok = cond_start = end_tok + 1; | |
5348 | cond = parse_exp_1 (&tok, 0, 0); | |
5349 | cond_end = tok; | |
5350 | } | |
5351 | if (*tok) | |
c5aa993b | 5352 | error ("Junk at end of command."); |
c906108c | 5353 | |
53a5351d | 5354 | if (accessflag == hw_read) |
c5aa993b | 5355 | bp_type = bp_read_watchpoint; |
53a5351d | 5356 | else if (accessflag == hw_access) |
c5aa993b JM |
5357 | bp_type = bp_access_watchpoint; |
5358 | else | |
5359 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
5360 | |
5361 | mem_cnt = can_use_hardware_watchpoint (val); | |
5362 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
5363 | error ("Expression cannot be implemented with read/access watchpoint."); | |
c5aa993b JM |
5364 | if (mem_cnt != 0) |
5365 | { | |
5366 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d JM |
5367 | target_resources_ok = |
5368 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, | |
5369 | other_type_used); | |
c5aa993b | 5370 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
53a5351d JM |
5371 | error ("Target does not support this type of hardware watchpoint."); |
5372 | ||
c5aa993b | 5373 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
53a5351d | 5374 | error ("Target can only support one kind of HW watchpoint at a time."); |
c5aa993b | 5375 | } |
c906108c SS |
5376 | |
5377 | #if defined(HPUXHPPA) | |
c5aa993b | 5378 | /* On HP-UX if you set a h/w |
c906108c SS |
5379 | watchpoint before the "run" command, the inferior dies with a e.g., |
5380 | SIGILL once you start it. I initially believed this was due to a | |
5381 | bad interaction between page protection traps and the initial | |
5382 | startup sequence by the dynamic linker. | |
5383 | ||
5384 | However, I tried avoiding that by having HP-UX's implementation of | |
39f77062 | 5385 | TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid |
c906108c SS |
5386 | yet, which forced slow watches before a "run" or "attach", and it |
5387 | still fails somewhere in the startup code. | |
5388 | ||
5389 | Until I figure out what's happening, I'm disallowing watches altogether | |
5390 | before the "run" or "attach" command. We'll tell the user they must | |
5391 | set watches after getting the program started. */ | |
c5aa993b | 5392 | if (!target_has_execution) |
c906108c SS |
5393 | { |
5394 | warning ("can't do that without a running program; try \"break main\", \"run\" first"); | |
5395 | return; | |
5396 | } | |
5397 | #endif /* HPUXHPPA */ | |
c5aa993b | 5398 | |
4d28f7a8 KB |
5399 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
5400 | watchpoint could not be set. */ | |
5401 | if (!mem_cnt || target_resources_ok <= 0) | |
5402 | bp_type = bp_watchpoint; | |
5403 | ||
c906108c | 5404 | /* Now set up the breakpoint. */ |
4d28f7a8 | 5405 | b = set_raw_breakpoint (sal, bp_type); |
c906108c SS |
5406 | set_breakpoint_count (breakpoint_count + 1); |
5407 | b->number = breakpoint_count; | |
b5de0fa7 | 5408 | b->disposition = disp_donttouch; |
c906108c SS |
5409 | b->exp = exp; |
5410 | b->exp_valid_block = exp_valid_block; | |
5411 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
5412 | b->val = val; | |
5413 | b->cond = cond; | |
5414 | if (cond_start) | |
5415 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
5416 | else | |
5417 | b->cond_string = 0; | |
c5aa993b | 5418 | |
c906108c SS |
5419 | frame = block_innermost_frame (exp_valid_block); |
5420 | if (frame) | |
5421 | { | |
5422 | prev_frame = get_prev_frame (frame); | |
7a424e99 | 5423 | b->watchpoint_frame = get_frame_id (frame); |
c906108c SS |
5424 | } |
5425 | else | |
101dcfbe AC |
5426 | { |
5427 | memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame)); | |
5428 | } | |
c906108c | 5429 | |
c906108c SS |
5430 | /* If the expression is "local", then set up a "watchpoint scope" |
5431 | breakpoint at the point where we've left the scope of the watchpoint | |
5432 | expression. */ | |
5433 | if (innermost_block) | |
5434 | { | |
5435 | if (prev_frame) | |
5436 | { | |
5437 | struct breakpoint *scope_breakpoint; | |
e86ae29f KS |
5438 | scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame), |
5439 | bp_watchpoint_scope); | |
c906108c | 5440 | |
b5de0fa7 | 5441 | scope_breakpoint->enable_state = bp_enabled; |
c906108c SS |
5442 | |
5443 | /* Automatically delete the breakpoint when it hits. */ | |
b5de0fa7 | 5444 | scope_breakpoint->disposition = disp_del; |
c906108c SS |
5445 | |
5446 | /* Only break in the proper frame (help with recursion). */ | |
818dd999 | 5447 | scope_breakpoint->frame_id = get_frame_id (prev_frame); |
c906108c SS |
5448 | |
5449 | /* Set the address at which we will stop. */ | |
5450 | scope_breakpoint->address = get_frame_pc (prev_frame); | |
5451 | ||
5452 | /* The scope breakpoint is related to the watchpoint. We | |
5453 | will need to act on them together. */ | |
5454 | b->related_breakpoint = scope_breakpoint; | |
5455 | } | |
5456 | } | |
5457 | value_free_to_mark (mark); | |
5458 | mention (b); | |
5459 | } | |
5460 | ||
5461 | /* Return count of locations need to be watched and can be handled | |
5462 | in hardware. If the watchpoint can not be handled | |
5463 | in hardware return zero. */ | |
5464 | ||
5465 | #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT) | |
53a5351d JM |
5466 | #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \ |
5467 | ((BYTE_SIZE) <= (REGISTER_SIZE)) | |
5468 | #endif | |
5469 | ||
5470 | #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT) | |
5471 | #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \ | |
6ab3a9c9 | 5472 | (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)) |
c906108c SS |
5473 | #endif |
5474 | ||
5475 | static int | |
fba45db2 | 5476 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
5477 | { |
5478 | int found_memory_cnt = 0; | |
2e70b7b9 | 5479 | struct value *head = v; |
c906108c SS |
5480 | |
5481 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 5482 | if (!can_use_hw_watchpoints) |
c906108c | 5483 | return 0; |
c5aa993b | 5484 | |
5c44784c JM |
5485 | /* Make sure that the value of the expression depends only upon |
5486 | memory contents, and values computed from them within GDB. If we | |
5487 | find any register references or function calls, we can't use a | |
5488 | hardware watchpoint. | |
5489 | ||
5490 | The idea here is that evaluating an expression generates a series | |
5491 | of values, one holding the value of every subexpression. (The | |
5492 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
5493 | a*b+c.) GDB's values hold almost enough information to establish | |
5494 | the criteria given above --- they identify memory lvalues, | |
5495 | register lvalues, computed values, etcetera. So we can evaluate | |
5496 | the expression, and then scan the chain of values that leaves | |
5497 | behind to decide whether we can detect any possible change to the | |
5498 | expression's final value using only hardware watchpoints. | |
5499 | ||
5500 | However, I don't think that the values returned by inferior | |
5501 | function calls are special in any way. So this function may not | |
5502 | notice that an expression involving an inferior function call | |
5503 | can't be watched with hardware watchpoints. FIXME. */ | |
c5aa993b | 5504 | for (; v; v = v->next) |
c906108c | 5505 | { |
5c44784c | 5506 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 5507 | { |
5c44784c JM |
5508 | if (VALUE_LAZY (v)) |
5509 | /* A lazy memory lvalue is one that GDB never needed to fetch; | |
5510 | we either just used its address (e.g., `a' in `a.b') or | |
5511 | we never needed it at all (e.g., `a' in `a,b'). */ | |
5512 | ; | |
53a5351d | 5513 | else |
5c44784c JM |
5514 | { |
5515 | /* Ahh, memory we actually used! Check if we can cover | |
5516 | it with hardware watchpoints. */ | |
2e70b7b9 MS |
5517 | struct type *vtype = check_typedef (VALUE_TYPE (v)); |
5518 | ||
5519 | /* We only watch structs and arrays if user asked for it | |
5520 | explicitly, never if they just happen to appear in a | |
5521 | middle of some value chain. */ | |
5522 | if (v == head | |
5523 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
5524 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
5525 | { | |
5526 | CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
5527 | int len = TYPE_LENGTH (VALUE_TYPE (v)); | |
5528 | ||
5529 | if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len)) | |
5530 | return 0; | |
5531 | else | |
5532 | found_memory_cnt++; | |
5533 | } | |
5c44784c | 5534 | } |
c5aa993b | 5535 | } |
c906108c | 5536 | else if (v->lval != not_lval && v->modifiable == 0) |
53a5351d JM |
5537 | return 0; /* ??? What does this represent? */ |
5538 | else if (v->lval == lval_register) | |
5539 | return 0; /* cannot watch a register with a HW watchpoint */ | |
c906108c SS |
5540 | } |
5541 | ||
5542 | /* The expression itself looks suitable for using a hardware | |
5543 | watchpoint, but give the target machine a chance to reject it. */ | |
5544 | return found_memory_cnt; | |
5545 | } | |
5546 | ||
8b93c638 | 5547 | void |
fba45db2 | 5548 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5549 | { |
5550 | watch_command (arg, from_tty); | |
5551 | } | |
8926118c | 5552 | |
c5aa993b | 5553 | static void |
fba45db2 | 5554 | watch_command (char *arg, int from_tty) |
c906108c | 5555 | { |
53a5351d | 5556 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
5557 | } |
5558 | ||
8b93c638 | 5559 | void |
fba45db2 | 5560 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5561 | { |
5562 | rwatch_command (arg, from_tty); | |
5563 | } | |
8926118c | 5564 | |
c5aa993b | 5565 | static void |
fba45db2 | 5566 | rwatch_command (char *arg, int from_tty) |
c906108c | 5567 | { |
53a5351d | 5568 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
5569 | } |
5570 | ||
8b93c638 | 5571 | void |
fba45db2 | 5572 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
5573 | { |
5574 | awatch_command (arg, from_tty); | |
5575 | } | |
8926118c | 5576 | |
c5aa993b | 5577 | static void |
fba45db2 | 5578 | awatch_command (char *arg, int from_tty) |
c906108c | 5579 | { |
53a5351d | 5580 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 5581 | } |
c906108c | 5582 | \f |
c5aa993b | 5583 | |
43ff13b4 | 5584 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
5585 | because it uses the mechanisms of breakpoints. */ |
5586 | ||
43ff13b4 JM |
5587 | /* This function is called by fetch_inferior_event via the |
5588 | cmd_continuation pointer, to complete the until command. It takes | |
5589 | care of cleaning up the temporary breakpoints set up by the until | |
5590 | command. */ | |
c2c6d25f JM |
5591 | static void |
5592 | until_break_command_continuation (struct continuation_arg *arg) | |
43ff13b4 | 5593 | { |
0d06e24b JM |
5594 | struct cleanup *cleanups; |
5595 | ||
57e687d9 | 5596 | cleanups = (struct cleanup *) arg->data.pointer; |
0d06e24b | 5597 | do_exec_cleanups (cleanups); |
43ff13b4 JM |
5598 | } |
5599 | ||
c906108c SS |
5600 | /* ARGSUSED */ |
5601 | void | |
ae66c1fc | 5602 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
5603 | { |
5604 | struct symtabs_and_lines sals; | |
5605 | struct symtab_and_line sal; | |
6e7f8b9c | 5606 | struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame); |
c906108c SS |
5607 | struct breakpoint *breakpoint; |
5608 | struct cleanup *old_chain; | |
0d06e24b JM |
5609 | struct continuation_arg *arg1; |
5610 | ||
c906108c SS |
5611 | |
5612 | clear_proceed_status (); | |
5613 | ||
5614 | /* Set a breakpoint where the user wants it and at return from | |
5615 | this function */ | |
c5aa993b | 5616 | |
c906108c SS |
5617 | if (default_breakpoint_valid) |
5618 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
c5aa993b | 5619 | default_breakpoint_line, (char ***) NULL); |
c906108c | 5620 | else |
53a5351d JM |
5621 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
5622 | 0, (char ***) NULL); | |
c5aa993b | 5623 | |
c906108c SS |
5624 | if (sals.nelts != 1) |
5625 | error ("Couldn't get information on specified line."); | |
c5aa993b | 5626 | |
c906108c | 5627 | sal = sals.sals[0]; |
b8c9b27d | 5628 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 5629 | |
c906108c SS |
5630 | if (*arg) |
5631 | error ("Junk at end of arguments."); | |
c5aa993b | 5632 | |
c906108c | 5633 | resolve_sal_pc (&sal); |
c5aa993b | 5634 | |
ae66c1fc EZ |
5635 | if (anywhere) |
5636 | /* If the user told us to continue until a specified location, | |
5637 | we don't specify a frame at which we need to stop. */ | |
5638 | breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until); | |
5639 | else | |
5640 | /* Otherwise, specify the current frame, because we want to stop only | |
5641 | at the very same frame. */ | |
5642 | breakpoint = set_momentary_breakpoint (sal, | |
5643 | get_frame_id (deprecated_selected_frame), | |
5644 | bp_until); | |
c5aa993b | 5645 | |
6426a772 | 5646 | if (!event_loop_p || !target_can_async_p ()) |
4d6140d9 | 5647 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 | 5648 | else |
4d6140d9 | 5649 | old_chain = make_exec_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 JM |
5650 | |
5651 | /* If we are running asynchronously, and the target supports async | |
5652 | execution, we are not waiting for the target to stop, in the call | |
5653 | tp proceed, below. This means that we cannot delete the | |
5654 | brekpoints until the target has actually stopped. The only place | |
5655 | where we get a chance to do that is in fetch_inferior_event, so | |
5656 | we must set things up for that. */ | |
5657 | ||
6426a772 | 5658 | if (event_loop_p && target_can_async_p ()) |
43ff13b4 | 5659 | { |
0d06e24b JM |
5660 | /* In this case the arg for the continuation is just the point |
5661 | in the exec_cleanups chain from where to start doing | |
5662 | cleanups, because all the continuation does is the cleanups in | |
5663 | the exec_cleanup_chain. */ | |
5664 | arg1 = | |
5665 | (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg)); | |
57e687d9 MS |
5666 | arg1->next = NULL; |
5667 | arg1->data.pointer = old_chain; | |
0d06e24b JM |
5668 | |
5669 | add_continuation (until_break_command_continuation, arg1); | |
43ff13b4 | 5670 | } |
c906108c | 5671 | |
ae66c1fc EZ |
5672 | /* Keep within the current frame, or in frames called by the current |
5673 | one. */ | |
c906108c SS |
5674 | if (prev_frame) |
5675 | { | |
30f7db39 AC |
5676 | sal = find_pc_line (get_frame_pc (prev_frame), 0); |
5677 | sal.pc = get_frame_pc (prev_frame); | |
818dd999 AC |
5678 | breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame), |
5679 | bp_until); | |
6426a772 | 5680 | if (!event_loop_p || !target_can_async_p ()) |
4d6140d9 | 5681 | make_cleanup_delete_breakpoint (breakpoint); |
43ff13b4 | 5682 | else |
4d6140d9 | 5683 | make_exec_cleanup_delete_breakpoint (breakpoint); |
c906108c | 5684 | } |
c5aa993b | 5685 | |
c906108c | 5686 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
43ff13b4 JM |
5687 | /* Do the cleanups now, anly if we are not running asynchronously, |
5688 | of if we are, but the target is still synchronous. */ | |
6426a772 | 5689 | if (!event_loop_p || !target_can_async_p ()) |
c5aa993b | 5690 | do_cleanups (old_chain); |
c906108c | 5691 | } |
ae66c1fc | 5692 | |
c906108c SS |
5693 | #if 0 |
5694 | /* These aren't used; I don't konw what they were for. */ | |
5695 | /* Set a breakpoint at the catch clause for NAME. */ | |
5696 | static int | |
fba45db2 | 5697 | catch_breakpoint (char *name) |
c906108c SS |
5698 | { |
5699 | } | |
5700 | ||
5701 | static int | |
fba45db2 | 5702 | disable_catch_breakpoint (void) |
c906108c SS |
5703 | { |
5704 | } | |
5705 | ||
5706 | static int | |
fba45db2 | 5707 | delete_catch_breakpoint (void) |
c906108c SS |
5708 | { |
5709 | } | |
5710 | ||
5711 | static int | |
fba45db2 | 5712 | enable_catch_breakpoint (void) |
c906108c SS |
5713 | { |
5714 | } | |
5715 | #endif /* 0 */ | |
5716 | ||
c906108c | 5717 | static void |
fba45db2 | 5718 | ep_skip_leading_whitespace (char **s) |
c906108c | 5719 | { |
c5aa993b JM |
5720 | if ((s == NULL) || (*s == NULL)) |
5721 | return; | |
5722 | while (isspace (**s)) | |
5723 | *s += 1; | |
c906108c | 5724 | } |
c5aa993b | 5725 | |
c906108c SS |
5726 | /* This function examines a string, and attempts to find a token |
5727 | that might be an event name in the leading characters. If a | |
5728 | possible match is found, a pointer to the last character of | |
5729 | the token is returned. Else, NULL is returned. */ | |
53a5351d | 5730 | |
c906108c | 5731 | static char * |
fba45db2 | 5732 | ep_find_event_name_end (char *arg) |
c906108c | 5733 | { |
c5aa993b JM |
5734 | char *s = arg; |
5735 | char *event_name_end = NULL; | |
5736 | ||
c906108c SS |
5737 | /* If we could depend upon the presense of strrpbrk, we'd use that... */ |
5738 | if (arg == NULL) | |
5739 | return NULL; | |
c5aa993b | 5740 | |
c906108c | 5741 | /* We break out of the loop when we find a token delimiter. |
c5aa993b JM |
5742 | Basically, we're looking for alphanumerics and underscores; |
5743 | anything else delimites the token. */ | |
c906108c SS |
5744 | while (*s != '\0') |
5745 | { | |
c5aa993b JM |
5746 | if (!isalnum (*s) && (*s != '_')) |
5747 | break; | |
c906108c SS |
5748 | event_name_end = s; |
5749 | s++; | |
5750 | } | |
c5aa993b | 5751 | |
c906108c SS |
5752 | return event_name_end; |
5753 | } | |
5754 | ||
c5aa993b | 5755 | |
c906108c SS |
5756 | /* This function attempts to parse an optional "if <cond>" clause |
5757 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 5758 | |
c906108c SS |
5759 | Else, it returns a pointer to the condition string. (It does not |
5760 | attempt to evaluate the string against a particular block.) And, | |
5761 | it updates arg to point to the first character following the parsed | |
5762 | if clause in the arg string. */ | |
53a5351d | 5763 | |
c906108c | 5764 | static char * |
fba45db2 | 5765 | ep_parse_optional_if_clause (char **arg) |
c906108c | 5766 | { |
c5aa993b JM |
5767 | char *cond_string; |
5768 | ||
5769 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 5770 | return NULL; |
c5aa993b | 5771 | |
c906108c SS |
5772 | /* Skip the "if" keyword. */ |
5773 | (*arg) += 2; | |
c5aa993b | 5774 | |
c906108c SS |
5775 | /* Skip any extra leading whitespace, and record the start of the |
5776 | condition string. */ | |
5777 | ep_skip_leading_whitespace (arg); | |
5778 | cond_string = *arg; | |
c5aa993b | 5779 | |
c906108c SS |
5780 | /* Assume that the condition occupies the remainder of the arg string. */ |
5781 | (*arg) += strlen (cond_string); | |
c5aa993b | 5782 | |
c906108c SS |
5783 | return cond_string; |
5784 | } | |
c5aa993b | 5785 | |
c906108c SS |
5786 | /* This function attempts to parse an optional filename from the arg |
5787 | string. If one is not found, it returns NULL. | |
c5aa993b | 5788 | |
c906108c SS |
5789 | Else, it returns a pointer to the parsed filename. (This function |
5790 | makes no attempt to verify that a file of that name exists, or is | |
5791 | accessible.) And, it updates arg to point to the first character | |
5792 | following the parsed filename in the arg string. | |
c5aa993b | 5793 | |
c906108c SS |
5794 | Note that clients needing to preserve the returned filename for |
5795 | future access should copy it to their own buffers. */ | |
5796 | static char * | |
fba45db2 | 5797 | ep_parse_optional_filename (char **arg) |
c906108c | 5798 | { |
c5aa993b JM |
5799 | static char filename[1024]; |
5800 | char *arg_p = *arg; | |
5801 | int i; | |
5802 | char c; | |
5803 | ||
c906108c SS |
5804 | if ((*arg_p == '\0') || isspace (*arg_p)) |
5805 | return NULL; | |
c5aa993b JM |
5806 | |
5807 | for (i = 0;; i++) | |
c906108c SS |
5808 | { |
5809 | c = *arg_p; | |
5810 | if (isspace (c)) | |
c5aa993b | 5811 | c = '\0'; |
c906108c SS |
5812 | filename[i] = c; |
5813 | if (c == '\0') | |
c5aa993b | 5814 | break; |
c906108c SS |
5815 | arg_p++; |
5816 | } | |
5817 | *arg = arg_p; | |
c5aa993b | 5818 | |
c906108c SS |
5819 | return filename; |
5820 | } | |
c5aa993b | 5821 | |
c906108c SS |
5822 | /* Commands to deal with catching events, such as signals, exceptions, |
5823 | process start/exit, etc. */ | |
c5aa993b JM |
5824 | |
5825 | typedef enum | |
5826 | { | |
5827 | catch_fork, catch_vfork | |
5828 | } | |
5829 | catch_fork_kind; | |
5830 | ||
e514a9d6 | 5831 | #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT) |
a14ed312 KB |
5832 | static void catch_fork_command_1 (catch_fork_kind fork_kind, |
5833 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 5834 | |
c906108c | 5835 | static void |
fba45db2 KB |
5836 | catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag, |
5837 | int from_tty) | |
c906108c | 5838 | { |
c5aa993b JM |
5839 | char *cond_string = NULL; |
5840 | ||
c906108c | 5841 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5842 | |
c906108c | 5843 | /* The allowed syntax is: |
c5aa993b JM |
5844 | catch [v]fork |
5845 | catch [v]fork if <cond> | |
5846 | ||
c906108c SS |
5847 | First, check if there's an if clause. */ |
5848 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5849 | |
c906108c SS |
5850 | if ((*arg != '\0') && !isspace (*arg)) |
5851 | error ("Junk at end of arguments."); | |
c5aa993b | 5852 | |
c906108c SS |
5853 | /* If this target supports it, create a fork or vfork catchpoint |
5854 | and enable reporting of such events. */ | |
c5aa993b JM |
5855 | switch (fork_kind) |
5856 | { | |
5857 | case catch_fork: | |
c906108c SS |
5858 | create_fork_event_catchpoint (tempflag, cond_string); |
5859 | break; | |
c5aa993b | 5860 | case catch_vfork: |
c906108c SS |
5861 | create_vfork_event_catchpoint (tempflag, cond_string); |
5862 | break; | |
c5aa993b | 5863 | default: |
c906108c SS |
5864 | error ("unsupported or unknown fork kind; cannot catch it"); |
5865 | break; | |
c5aa993b | 5866 | } |
c906108c | 5867 | } |
e514a9d6 | 5868 | #endif |
c906108c | 5869 | |
e514a9d6 | 5870 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) |
c906108c | 5871 | static void |
fba45db2 | 5872 | catch_exec_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 5873 | { |
c5aa993b | 5874 | char *cond_string = NULL; |
c906108c SS |
5875 | |
5876 | ep_skip_leading_whitespace (&arg); | |
5877 | ||
5878 | /* The allowed syntax is: | |
c5aa993b JM |
5879 | catch exec |
5880 | catch exec if <cond> | |
c906108c SS |
5881 | |
5882 | First, check if there's an if clause. */ | |
5883 | cond_string = ep_parse_optional_if_clause (&arg); | |
5884 | ||
5885 | if ((*arg != '\0') && !isspace (*arg)) | |
5886 | error ("Junk at end of arguments."); | |
5887 | ||
5888 | /* If this target supports it, create an exec catchpoint | |
5889 | and enable reporting of such events. */ | |
5890 | create_exec_event_catchpoint (tempflag, cond_string); | |
5891 | } | |
e514a9d6 | 5892 | #endif |
c5aa993b | 5893 | |
c906108c SS |
5894 | #if defined(SOLIB_ADD) |
5895 | static void | |
fba45db2 | 5896 | catch_load_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 5897 | { |
c5aa993b JM |
5898 | char *dll_pathname = NULL; |
5899 | char *cond_string = NULL; | |
5900 | ||
c906108c | 5901 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5902 | |
c906108c | 5903 | /* The allowed syntax is: |
c5aa993b JM |
5904 | catch load |
5905 | catch load if <cond> | |
5906 | catch load <filename> | |
5907 | catch load <filename> if <cond> | |
5908 | ||
c906108c SS |
5909 | The user is not allowed to specify the <filename> after an |
5910 | if clause. | |
c5aa993b | 5911 | |
c906108c | 5912 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 5913 | |
c906108c SS |
5914 | First, check if there's an if clause. If so, then there |
5915 | cannot be a filename. */ | |
5916 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5917 | |
c906108c SS |
5918 | /* If there was an if clause, then there cannot be a filename. |
5919 | Else, there might be a filename and an if clause. */ | |
5920 | if (cond_string == NULL) | |
5921 | { | |
5922 | dll_pathname = ep_parse_optional_filename (&arg); | |
5923 | ep_skip_leading_whitespace (&arg); | |
5924 | cond_string = ep_parse_optional_if_clause (&arg); | |
5925 | } | |
c5aa993b | 5926 | |
c906108c SS |
5927 | if ((*arg != '\0') && !isspace (*arg)) |
5928 | error ("Junk at end of arguments."); | |
c5aa993b | 5929 | |
c906108c SS |
5930 | /* Create a load breakpoint that only triggers when a load of |
5931 | the specified dll (or any dll, if no pathname was specified) | |
5932 | occurs. */ | |
39f77062 | 5933 | SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag, |
53a5351d | 5934 | dll_pathname, cond_string); |
c906108c | 5935 | } |
c5aa993b | 5936 | |
c906108c | 5937 | static void |
fba45db2 | 5938 | catch_unload_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 5939 | { |
c5aa993b JM |
5940 | char *dll_pathname = NULL; |
5941 | char *cond_string = NULL; | |
5942 | ||
c906108c | 5943 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5944 | |
c906108c | 5945 | /* The allowed syntax is: |
c5aa993b JM |
5946 | catch unload |
5947 | catch unload if <cond> | |
5948 | catch unload <filename> | |
5949 | catch unload <filename> if <cond> | |
5950 | ||
c906108c SS |
5951 | The user is not allowed to specify the <filename> after an |
5952 | if clause. | |
c5aa993b | 5953 | |
c906108c | 5954 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 5955 | |
c906108c SS |
5956 | First, check if there's an if clause. If so, then there |
5957 | cannot be a filename. */ | |
5958 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5959 | |
c906108c SS |
5960 | /* If there was an if clause, then there cannot be a filename. |
5961 | Else, there might be a filename and an if clause. */ | |
5962 | if (cond_string == NULL) | |
5963 | { | |
5964 | dll_pathname = ep_parse_optional_filename (&arg); | |
5965 | ep_skip_leading_whitespace (&arg); | |
5966 | cond_string = ep_parse_optional_if_clause (&arg); | |
5967 | } | |
c5aa993b | 5968 | |
c906108c SS |
5969 | if ((*arg != '\0') && !isspace (*arg)) |
5970 | error ("Junk at end of arguments."); | |
c5aa993b | 5971 | |
c906108c SS |
5972 | /* Create an unload breakpoint that only triggers when an unload of |
5973 | the specified dll (or any dll, if no pathname was specified) | |
5974 | occurs. */ | |
39f77062 | 5975 | SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag, |
53a5351d | 5976 | dll_pathname, cond_string); |
c906108c SS |
5977 | } |
5978 | #endif /* SOLIB_ADD */ | |
5979 | ||
5980 | /* Commands to deal with catching exceptions. */ | |
5981 | ||
5982 | /* Set a breakpoint at the specified callback routine for an | |
c5aa993b | 5983 | exception event callback */ |
c906108c SS |
5984 | |
5985 | static void | |
fba45db2 KB |
5986 | create_exception_catchpoint (int tempflag, char *cond_string, |
5987 | enum exception_event_kind ex_event, | |
5988 | struct symtab_and_line *sal) | |
c906108c | 5989 | { |
c5aa993b | 5990 | struct breakpoint *b; |
c5aa993b | 5991 | int thread = -1; /* All threads. */ |
4d28f7a8 | 5992 | enum bptype bptype; |
c906108c | 5993 | |
c5aa993b | 5994 | if (!sal) /* no exception support? */ |
c906108c SS |
5995 | return; |
5996 | ||
c906108c SS |
5997 | switch (ex_event) |
5998 | { | |
c5aa993b | 5999 | case EX_EVENT_THROW: |
4d28f7a8 | 6000 | bptype = bp_catch_throw; |
c5aa993b JM |
6001 | break; |
6002 | case EX_EVENT_CATCH: | |
4d28f7a8 | 6003 | bptype = bp_catch_catch; |
c5aa993b JM |
6004 | break; |
6005 | default: /* error condition */ | |
c5aa993b | 6006 | error ("Internal error -- invalid catchpoint kind"); |
c906108c | 6007 | } |
4d28f7a8 KB |
6008 | |
6009 | b = set_raw_breakpoint (*sal, bptype); | |
6010 | set_breakpoint_count (breakpoint_count + 1); | |
6011 | b->number = breakpoint_count; | |
6012 | b->cond = NULL; | |
6013 | b->cond_string = (cond_string == NULL) ? | |
6014 | NULL : savestring (cond_string, strlen (cond_string)); | |
6015 | b->thread = thread; | |
6016 | b->addr_string = NULL; | |
b5de0fa7 EZ |
6017 | b->enable_state = bp_enabled; |
6018 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
c906108c SS |
6019 | mention (b); |
6020 | } | |
6021 | ||
3086aeae DJ |
6022 | static enum print_stop_action |
6023 | print_exception_catchpoint (struct breakpoint *b) | |
6024 | { | |
6025 | annotate_catchpoint (b->number); | |
6026 | ||
6027 | if (strstr (b->addr_string, "throw") != NULL) | |
6028 | printf_filtered ("\nCatchpoint %d (exception thrown)\n", | |
6029 | b->number); | |
6030 | else | |
6031 | printf_filtered ("\nCatchpoint %d (exception caught)\n", | |
6032 | b->number); | |
6033 | ||
6034 | return PRINT_SRC_AND_LOC; | |
6035 | } | |
6036 | ||
6037 | static void | |
6038 | print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr) | |
6039 | { | |
6040 | if (addressprint) | |
6041 | { | |
6042 | annotate_field (4); | |
6043 | ui_out_field_core_addr (uiout, "addr", b->address); | |
6044 | } | |
6045 | annotate_field (5); | |
6046 | *last_addr = b->address; | |
6047 | if (strstr (b->addr_string, "throw") != NULL) | |
6048 | ui_out_field_string (uiout, "what", "exception throw"); | |
6049 | else | |
6050 | ui_out_field_string (uiout, "what", "exception catch"); | |
6051 | } | |
6052 | ||
6053 | static void | |
6054 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6055 | { | |
6056 | if (strstr (b->addr_string, "throw") != NULL) | |
6057 | printf_filtered ("Catchpoint %d (throw)", b->number); | |
6058 | else | |
6059 | printf_filtered ("Catchpoint %d (catch)", b->number); | |
6060 | } | |
6061 | ||
6062 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
6063 | print_exception_catchpoint, | |
6064 | print_one_exception_catchpoint, | |
6065 | print_mention_exception_catchpoint | |
6066 | }; | |
6067 | ||
6068 | static int | |
6069 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6070 | enum exception_event_kind ex_event, int from_tty) | |
6071 | { | |
6072 | char *trigger_func_name, *nameptr; | |
6073 | struct symtabs_and_lines sals; | |
6074 | struct breakpoint *b; | |
6075 | ||
6076 | if (ex_event == EX_EVENT_CATCH) | |
6077 | trigger_func_name = xstrdup ("__cxa_begin_catch"); | |
6078 | else | |
6079 | trigger_func_name = xstrdup ("__cxa_throw"); | |
6080 | ||
6081 | nameptr = trigger_func_name; | |
6082 | sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL); | |
6083 | if (sals.nelts == 0) | |
6084 | { | |
6085 | free (trigger_func_name); | |
6086 | return 0; | |
6087 | } | |
6088 | ||
6089 | b = set_raw_breakpoint (sals.sals[0], bp_breakpoint); | |
6090 | set_breakpoint_count (breakpoint_count + 1); | |
6091 | b->number = breakpoint_count; | |
6092 | b->cond = NULL; | |
6093 | b->cond_string = (cond_string == NULL) ? | |
6094 | NULL : savestring (cond_string, strlen (cond_string)); | |
6095 | b->thread = -1; | |
6096 | b->addr_string = trigger_func_name; | |
6097 | b->enable_state = bp_enabled; | |
6098 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
6099 | b->ops = &gnu_v3_exception_catchpoint_ops; | |
6100 | ||
6101 | free (sals.sals); | |
6102 | mention (b); | |
6103 | return 1; | |
6104 | } | |
6105 | ||
c5aa993b | 6106 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6107 | |
6108 | static void | |
fba45db2 KB |
6109 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6110 | int tempflag, int from_tty) | |
c906108c | 6111 | { |
c5aa993b JM |
6112 | char *cond_string = NULL; |
6113 | struct symtab_and_line *sal = NULL; | |
6114 | ||
c906108c | 6115 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6116 | |
c906108c SS |
6117 | cond_string = ep_parse_optional_if_clause (&arg); |
6118 | ||
6119 | if ((*arg != '\0') && !isspace (*arg)) | |
6120 | error ("Junk at end of arguments."); | |
6121 | ||
6122 | if ((ex_event != EX_EVENT_THROW) && | |
6123 | (ex_event != EX_EVENT_CATCH)) | |
6124 | error ("Unsupported or unknown exception event; cannot catch it"); | |
6125 | ||
3086aeae DJ |
6126 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
6127 | return; | |
6128 | ||
c906108c SS |
6129 | /* See if we can find a callback routine */ |
6130 | sal = target_enable_exception_callback (ex_event, 1); | |
6131 | ||
c5aa993b | 6132 | if (sal) |
c906108c SS |
6133 | { |
6134 | /* We have callbacks from the runtime system for exceptions. | |
c5aa993b | 6135 | Set a breakpoint on the sal found, if no errors */ |
c906108c | 6136 | if (sal != (struct symtab_and_line *) -1) |
c5aa993b | 6137 | create_exception_catchpoint (tempflag, cond_string, ex_event, sal); |
c906108c | 6138 | else |
53a5351d | 6139 | return; /* something went wrong with setting up callbacks */ |
c906108c | 6140 | } |
c5aa993b | 6141 | |
69f567ae | 6142 | warning ("Unsupported with this platform/compiler combination."); |
c906108c SS |
6143 | } |
6144 | ||
6145 | /* Cover routine to allow wrapping target_enable_exception_catchpoints | |
6146 | inside a catch_errors */ | |
6147 | ||
6148 | static int | |
4efb68b1 | 6149 | cover_target_enable_exception_callback (void *arg) |
c906108c SS |
6150 | { |
6151 | args_for_catchpoint_enable *args = arg; | |
6152 | struct symtab_and_line *sal; | |
b5de0fa7 | 6153 | sal = target_enable_exception_callback (args->kind, args->enable_p); |
c906108c SS |
6154 | if (sal == NULL) |
6155 | return 0; | |
6156 | else if (sal == (struct symtab_and_line *) -1) | |
6157 | return -1; | |
6158 | else | |
c5aa993b | 6159 | return 1; /*is valid */ |
c906108c SS |
6160 | } |
6161 | ||
c906108c | 6162 | static void |
fba45db2 | 6163 | catch_command_1 (char *arg, int tempflag, int from_tty) |
c906108c | 6164 | { |
c5aa993b | 6165 | |
c906108c SS |
6166 | /* The first argument may be an event name, such as "start" or "load". |
6167 | If so, then handle it as such. If it doesn't match an event name, | |
6168 | then attempt to interpret it as an exception name. (This latter is | |
6169 | the v4.16-and-earlier GDB meaning of the "catch" command.) | |
c5aa993b | 6170 | |
c906108c | 6171 | First, try to find the bounds of what might be an event name. */ |
c5aa993b JM |
6172 | char *arg1_start = arg; |
6173 | char *arg1_end; | |
6174 | int arg1_length; | |
6175 | ||
c906108c SS |
6176 | if (arg1_start == NULL) |
6177 | { | |
c5aa993b | 6178 | /* Old behaviour was to use pre-v-4.16 syntax */ |
c906108c SS |
6179 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
6180 | /* return; */ | |
c5aa993b | 6181 | /* Now, this is not allowed */ |
c906108c SS |
6182 | error ("Catch requires an event name."); |
6183 | ||
6184 | } | |
6185 | arg1_end = ep_find_event_name_end (arg1_start); | |
6186 | if (arg1_end == NULL) | |
6187 | error ("catch requires an event"); | |
6188 | arg1_length = arg1_end + 1 - arg1_start; | |
c5aa993b | 6189 | |
c906108c SS |
6190 | /* Try to match what we found against known event names. */ |
6191 | if (strncmp (arg1_start, "signal", arg1_length) == 0) | |
6192 | { | |
6193 | error ("Catch of signal not yet implemented"); | |
6194 | } | |
6195 | else if (strncmp (arg1_start, "catch", arg1_length) == 0) | |
6196 | { | |
53a5351d JM |
6197 | catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1, |
6198 | tempflag, from_tty); | |
c906108c SS |
6199 | } |
6200 | else if (strncmp (arg1_start, "throw", arg1_length) == 0) | |
6201 | { | |
53a5351d JM |
6202 | catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1, |
6203 | tempflag, from_tty); | |
c906108c SS |
6204 | } |
6205 | else if (strncmp (arg1_start, "thread_start", arg1_length) == 0) | |
6206 | { | |
6207 | error ("Catch of thread_start not yet implemented"); | |
6208 | } | |
6209 | else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0) | |
6210 | { | |
6211 | error ("Catch of thread_exit not yet implemented"); | |
6212 | } | |
6213 | else if (strncmp (arg1_start, "thread_join", arg1_length) == 0) | |
6214 | { | |
6215 | error ("Catch of thread_join not yet implemented"); | |
6216 | } | |
6217 | else if (strncmp (arg1_start, "start", arg1_length) == 0) | |
6218 | { | |
6219 | error ("Catch of start not yet implemented"); | |
6220 | } | |
6221 | else if (strncmp (arg1_start, "exit", arg1_length) == 0) | |
6222 | { | |
6223 | error ("Catch of exit not yet implemented"); | |
6224 | } | |
6225 | else if (strncmp (arg1_start, "fork", arg1_length) == 0) | |
6226 | { | |
6227 | #if defined(CHILD_INSERT_FORK_CATCHPOINT) | |
c5aa993b | 6228 | catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6229 | #else |
6230 | error ("Catch of fork not yet implemented"); | |
6231 | #endif | |
6232 | } | |
6233 | else if (strncmp (arg1_start, "vfork", arg1_length) == 0) | |
6234 | { | |
6235 | #if defined(CHILD_INSERT_VFORK_CATCHPOINT) | |
c5aa993b | 6236 | catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6237 | #else |
6238 | error ("Catch of vfork not yet implemented"); | |
6239 | #endif | |
6240 | } | |
6241 | else if (strncmp (arg1_start, "exec", arg1_length) == 0) | |
6242 | { | |
6243 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) | |
c5aa993b | 6244 | catch_exec_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6245 | #else |
6246 | error ("Catch of exec not yet implemented"); | |
6247 | #endif | |
6248 | } | |
6249 | else if (strncmp (arg1_start, "load", arg1_length) == 0) | |
6250 | { | |
6251 | #if defined(SOLIB_ADD) | |
c5aa993b | 6252 | catch_load_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6253 | #else |
6254 | error ("Catch of load not implemented"); | |
6255 | #endif | |
6256 | } | |
6257 | else if (strncmp (arg1_start, "unload", arg1_length) == 0) | |
6258 | { | |
6259 | #if defined(SOLIB_ADD) | |
c5aa993b | 6260 | catch_unload_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
6261 | #else |
6262 | error ("Catch of load not implemented"); | |
6263 | #endif | |
6264 | } | |
6265 | else if (strncmp (arg1_start, "stop", arg1_length) == 0) | |
6266 | { | |
6267 | error ("Catch of stop not yet implemented"); | |
6268 | } | |
c5aa993b | 6269 | |
c906108c SS |
6270 | /* This doesn't appear to be an event name */ |
6271 | ||
6272 | else | |
6273 | { | |
6274 | /* Pre-v.4.16 behaviour was to treat the argument | |
c5aa993b | 6275 | as the name of an exception */ |
c906108c | 6276 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
c5aa993b | 6277 | /* Now this is not allowed */ |
c906108c SS |
6278 | error ("Unknown event kind specified for catch"); |
6279 | ||
6280 | } | |
6281 | } | |
6282 | ||
6283 | /* Used by the gui, could be made a worker for other things. */ | |
6284 | ||
6285 | struct breakpoint * | |
fba45db2 | 6286 | set_breakpoint_sal (struct symtab_and_line sal) |
c906108c SS |
6287 | { |
6288 | struct breakpoint *b; | |
4d28f7a8 | 6289 | b = set_raw_breakpoint (sal, bp_breakpoint); |
c906108c SS |
6290 | set_breakpoint_count (breakpoint_count + 1); |
6291 | b->number = breakpoint_count; | |
c906108c SS |
6292 | b->cond = 0; |
6293 | b->thread = -1; | |
6294 | return b; | |
6295 | } | |
6296 | ||
6297 | #if 0 | |
6298 | /* These aren't used; I don't know what they were for. */ | |
6299 | /* Disable breakpoints on all catch clauses described in ARGS. */ | |
6300 | static void | |
fba45db2 | 6301 | disable_catch (char *args) |
c906108c SS |
6302 | { |
6303 | /* Map the disable command to catch clauses described in ARGS. */ | |
6304 | } | |
6305 | ||
6306 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
6307 | static void | |
fba45db2 | 6308 | enable_catch (char *args) |
c906108c SS |
6309 | { |
6310 | /* Map the disable command to catch clauses described in ARGS. */ | |
6311 | } | |
6312 | ||
6313 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
6314 | static void | |
fba45db2 | 6315 | delete_catch (char *args) |
c906108c SS |
6316 | { |
6317 | /* Map the delete command to catch clauses described in ARGS. */ | |
6318 | } | |
6319 | #endif /* 0 */ | |
6320 | ||
6321 | static void | |
fba45db2 | 6322 | catch_command (char *arg, int from_tty) |
c906108c SS |
6323 | { |
6324 | catch_command_1 (arg, 0, from_tty); | |
6325 | } | |
6326 | \f | |
6327 | ||
6328 | static void | |
fba45db2 | 6329 | tcatch_command (char *arg, int from_tty) |
c906108c SS |
6330 | { |
6331 | catch_command_1 (arg, 1, from_tty); | |
6332 | } | |
6333 | ||
80f8a6eb | 6334 | /* Delete breakpoints by address or line. */ |
c906108c SS |
6335 | |
6336 | static void | |
fba45db2 | 6337 | clear_command (char *arg, int from_tty) |
c906108c | 6338 | { |
80f8a6eb | 6339 | struct breakpoint *b, *tmp, *prev, *found; |
c906108c SS |
6340 | int default_match; |
6341 | struct symtabs_and_lines sals; | |
6342 | struct symtab_and_line sal; | |
c906108c SS |
6343 | int i; |
6344 | ||
6345 | if (arg) | |
6346 | { | |
6347 | sals = decode_line_spec (arg, 1); | |
6348 | default_match = 0; | |
6349 | } | |
6350 | else | |
6351 | { | |
c5aa993b | 6352 | sals.sals = (struct symtab_and_line *) |
c906108c | 6353 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 6354 | make_cleanup (xfree, sals.sals); |
fe39c653 | 6355 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
6356 | sal.line = default_breakpoint_line; |
6357 | sal.symtab = default_breakpoint_symtab; | |
6358 | sal.pc = default_breakpoint_address; | |
6359 | if (sal.symtab == 0) | |
6360 | error ("No source file specified."); | |
6361 | ||
6362 | sals.sals[0] = sal; | |
6363 | sals.nelts = 1; | |
6364 | ||
6365 | default_match = 1; | |
6366 | } | |
6367 | ||
6368 | /* For each line spec given, delete bps which correspond | |
80f8a6eb MS |
6369 | to it. Do it in two passes, solely to preserve the current |
6370 | behavior that from_tty is forced true if we delete more than | |
6371 | one breakpoint. */ | |
c906108c | 6372 | |
80f8a6eb | 6373 | found = NULL; |
c906108c SS |
6374 | for (i = 0; i < sals.nelts; i++) |
6375 | { | |
6376 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
6377 | If line given (pc == 0), clear all bpts on specified line. |
6378 | If defaulting, clear all bpts on default line | |
c906108c | 6379 | or at default pc. |
c5aa993b JM |
6380 | |
6381 | defaulting sal.pc != 0 tests to do | |
6382 | ||
6383 | 0 1 pc | |
6384 | 1 1 pc _and_ line | |
6385 | 0 0 line | |
6386 | 1 0 <can't happen> */ | |
c906108c SS |
6387 | |
6388 | sal = sals.sals[i]; | |
80f8a6eb | 6389 | prev = NULL; |
c906108c | 6390 | |
80f8a6eb MS |
6391 | /* Find all matching breakpoints, remove them from the |
6392 | breakpoint chain, and add them to the 'found' chain. */ | |
6393 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
c5aa993b | 6394 | { |
80f8a6eb MS |
6395 | /* Are we going to delete b? */ |
6396 | if (b->type != bp_none | |
6397 | && b->type != bp_watchpoint | |
6398 | && b->type != bp_hardware_watchpoint | |
6399 | && b->type != bp_read_watchpoint | |
6400 | && b->type != bp_access_watchpoint | |
6401 | /* Not if b is a watchpoint of any sort... */ | |
6402 | && (((sal.pc && (b->address == sal.pc)) | |
6403 | && (!section_is_overlay (b->section) | |
6404 | || b->section == sal.section)) | |
6405 | /* Yes, if sal.pc matches b (modulo overlays). */ | |
6406 | || ((default_match || (0 == sal.pc)) | |
6407 | && b->source_file != NULL | |
6408 | && sal.symtab != NULL | |
6409 | && STREQ (b->source_file, sal.symtab->filename) | |
6410 | && b->line_number == sal.line))) | |
6411 | /* Yes, if sal source file and line matches b. */ | |
6412 | { | |
6413 | /* Remove it from breakpoint_chain... */ | |
6414 | if (b == breakpoint_chain) | |
6415 | { | |
6416 | /* b is at the head of the list */ | |
6417 | breakpoint_chain = b->next; | |
6418 | } | |
6419 | else | |
6420 | { | |
6421 | prev->next = b->next; | |
6422 | } | |
6423 | /* And add it to 'found' chain. */ | |
6424 | b->next = found; | |
6425 | found = b; | |
6426 | } | |
c906108c | 6427 | else |
80f8a6eb MS |
6428 | { |
6429 | /* Keep b, and keep a pointer to it. */ | |
6430 | prev = b; | |
6431 | } | |
c906108c | 6432 | } |
80f8a6eb MS |
6433 | } |
6434 | /* Now go thru the 'found' chain and delete them. */ | |
6435 | if (found == 0) | |
6436 | { | |
6437 | if (arg) | |
6438 | error ("No breakpoint at %s.", arg); | |
6439 | else | |
6440 | error ("No breakpoint at this line."); | |
6441 | } | |
c906108c | 6442 | |
80f8a6eb MS |
6443 | if (found->next) |
6444 | from_tty = 1; /* Always report if deleted more than one */ | |
6445 | if (from_tty) | |
6446 | printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); | |
6447 | breakpoints_changed (); | |
6448 | while (found) | |
6449 | { | |
c5aa993b | 6450 | if (from_tty) |
80f8a6eb MS |
6451 | printf_unfiltered ("%d ", found->number); |
6452 | tmp = found->next; | |
6453 | delete_breakpoint (found); | |
6454 | found = tmp; | |
c906108c | 6455 | } |
80f8a6eb MS |
6456 | if (from_tty) |
6457 | putchar_unfiltered ('\n'); | |
c906108c SS |
6458 | } |
6459 | \f | |
6460 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
6461 | all breakpoints that are marked for deletion, whether hit or not. | |
6462 | This is called after any breakpoint is hit, or after errors. */ | |
6463 | ||
6464 | void | |
fba45db2 | 6465 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
6466 | { |
6467 | struct breakpoint *b, *temp; | |
6468 | ||
6469 | for (; bs; bs = bs->next) | |
b5de0fa7 | 6470 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del |
c906108c SS |
6471 | && bs->stop) |
6472 | delete_breakpoint (bs->breakpoint_at); | |
6473 | ||
6474 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 6475 | { |
b5de0fa7 | 6476 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
6477 | delete_breakpoint (b); |
6478 | } | |
c906108c SS |
6479 | } |
6480 | ||
53a5351d JM |
6481 | /* Delete a breakpoint and clean up all traces of it in the data |
6482 | structures. */ | |
c906108c SS |
6483 | |
6484 | void | |
fba45db2 | 6485 | delete_breakpoint (struct breakpoint *bpt) |
c906108c SS |
6486 | { |
6487 | register struct breakpoint *b; | |
6488 | register bpstat bs; | |
6489 | ||
6490 | if (bpt == NULL) | |
6491 | error ("Internal error (attempted to delete a NULL breakpoint)"); | |
6492 | ||
6493 | ||
6494 | /* Has this bp already been deleted? This can happen because multiple | |
6495 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
6496 | ||
6497 | One example of this happening is a watchpoint's scope bp. When the | |
6498 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
6499 | delete it. We also delete its scope bp. But the scope bp is marked | |
6500 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
6501 | checked for auto-deleting bp's, which are deleted. | |
6502 | ||
6503 | A real solution to this problem might involve reference counts in bp's, | |
6504 | and/or giving them pointers back to their referencing bpstat's, and | |
6505 | teaching delete_breakpoint to only free a bp's storage when no more | |
6506 | references were extent. A cheaper bandaid was chosen. */ | |
6507 | if (bpt->type == bp_none) | |
6508 | return; | |
6509 | ||
6510 | if (delete_breakpoint_hook) | |
6511 | delete_breakpoint_hook (bpt); | |
104c1213 | 6512 | breakpoint_delete_event (bpt->number); |
c906108c SS |
6513 | |
6514 | if (bpt->inserted) | |
2e663524 | 6515 | remove_breakpoint (bpt, mark_inserted); |
c5aa993b | 6516 | |
c906108c SS |
6517 | if (breakpoint_chain == bpt) |
6518 | breakpoint_chain = bpt->next; | |
6519 | ||
6520 | /* If we have callback-style exception catchpoints, don't go through | |
6521 | the adjustments to the C++ runtime library etc. if the inferior | |
6522 | isn't actually running. target_enable_exception_callback for a | |
6523 | null target ops vector gives an undesirable error message, so we | |
6524 | check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's | |
c5aa993b | 6525 | exceptions are supported in this way, it's OK for now. FIXME */ |
c906108c SS |
6526 | if (ep_is_exception_catchpoint (bpt) && target_has_execution) |
6527 | { | |
6528 | static char message1[] = "Error in deleting catchpoint %d:\n"; | |
6529 | static char message[sizeof (message1) + 30]; | |
6530 | args_for_catchpoint_enable args; | |
6531 | ||
53a5351d JM |
6532 | /* Format possible error msg */ |
6533 | sprintf (message, message1, bpt->number); | |
6534 | args.kind = bpt->type == bp_catch_catch ? | |
6535 | EX_EVENT_CATCH : EX_EVENT_THROW; | |
b5de0fa7 | 6536 | args.enable_p = 0; |
c906108c SS |
6537 | catch_errors (cover_target_enable_exception_callback, &args, |
6538 | message, RETURN_MASK_ALL); | |
6539 | } | |
6540 | ||
6541 | ||
6542 | ALL_BREAKPOINTS (b) | |
6543 | if (b->next == bpt) | |
c5aa993b JM |
6544 | { |
6545 | b->next = bpt->next; | |
6546 | break; | |
6547 | } | |
c906108c | 6548 | |
9f60f21b | 6549 | check_duplicates (bpt); |
c906108c SS |
6550 | /* If this breakpoint was inserted, and there is another breakpoint |
6551 | at the same address, we need to insert the other breakpoint. */ | |
6552 | if (bpt->inserted | |
6553 | && bpt->type != bp_hardware_watchpoint | |
6554 | && bpt->type != bp_read_watchpoint | |
6555 | && bpt->type != bp_access_watchpoint | |
6556 | && bpt->type != bp_catch_fork | |
6557 | && bpt->type != bp_catch_vfork | |
6558 | && bpt->type != bp_catch_exec) | |
6559 | { | |
6560 | ALL_BREAKPOINTS (b) | |
6561 | if (b->address == bpt->address | |
6562 | && b->section == bpt->section | |
6563 | && !b->duplicate | |
b5de0fa7 EZ |
6564 | && b->enable_state != bp_disabled |
6565 | && b->enable_state != bp_shlib_disabled | |
6566 | && b->enable_state != bp_call_disabled) | |
c5aa993b JM |
6567 | { |
6568 | int val; | |
53a5351d | 6569 | |
c2c6d25f JM |
6570 | /* We should never reach this point if there is a permanent |
6571 | breakpoint at the same address as the one being deleted. | |
6572 | If there is a permanent breakpoint somewhere, it should | |
6573 | always be the only one inserted. */ | |
b5de0fa7 | 6574 | if (b->enable_state == bp_permanent) |
8e65ff28 AC |
6575 | internal_error (__FILE__, __LINE__, |
6576 | "another breakpoint was inserted on top of " | |
c2c6d25f JM |
6577 | "a permanent breakpoint"); |
6578 | ||
53a5351d JM |
6579 | if (b->type == bp_hardware_breakpoint) |
6580 | val = target_insert_hw_breakpoint (b->address, b->shadow_contents); | |
6581 | else | |
6582 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
6583 | ||
81d0cc19 | 6584 | /* If there was an error in the insert, print a message, then stop execution. */ |
c5aa993b JM |
6585 | if (val != 0) |
6586 | { | |
81d0cc19 GS |
6587 | struct ui_file *tmp_error_stream = mem_fileopen (); |
6588 | make_cleanup_ui_file_delete (tmp_error_stream); | |
6589 | ||
6590 | ||
6591 | if (b->type == bp_hardware_breakpoint) | |
6592 | { | |
6593 | fprintf_unfiltered (tmp_error_stream, | |
6594 | "Cannot insert hardware breakpoint %d.\n" | |
6595 | "You may have requested too many hardware breakpoints.\n", | |
6596 | b->number); | |
6597 | } | |
6598 | else | |
6599 | { | |
6600 | fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number); | |
6601 | fprintf_filtered (tmp_error_stream, "Error accessing memory address "); | |
6602 | print_address_numeric (b->address, 1, tmp_error_stream); | |
6603 | fprintf_filtered (tmp_error_stream, ": %s.\n", | |
6604 | safe_strerror (val)); | |
6605 | } | |
6606 | ||
6607 | fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process."); | |
c5aa993b | 6608 | target_terminal_ours_for_output (); |
81d0cc19 | 6609 | error_stream(tmp_error_stream); |
c5aa993b JM |
6610 | } |
6611 | else | |
6612 | b->inserted = 1; | |
6613 | } | |
c906108c SS |
6614 | } |
6615 | ||
6616 | free_command_lines (&bpt->commands); | |
6617 | if (bpt->cond) | |
b8c9b27d | 6618 | xfree (bpt->cond); |
c906108c | 6619 | if (bpt->cond_string != NULL) |
b8c9b27d | 6620 | xfree (bpt->cond_string); |
c906108c | 6621 | if (bpt->addr_string != NULL) |
b8c9b27d | 6622 | xfree (bpt->addr_string); |
c906108c | 6623 | if (bpt->exp != NULL) |
b8c9b27d | 6624 | xfree (bpt->exp); |
c906108c | 6625 | if (bpt->exp_string != NULL) |
b8c9b27d | 6626 | xfree (bpt->exp_string); |
c906108c SS |
6627 | if (bpt->val != NULL) |
6628 | value_free (bpt->val); | |
6629 | if (bpt->source_file != NULL) | |
b8c9b27d | 6630 | xfree (bpt->source_file); |
c906108c | 6631 | if (bpt->dll_pathname != NULL) |
b8c9b27d | 6632 | xfree (bpt->dll_pathname); |
c906108c | 6633 | if (bpt->triggered_dll_pathname != NULL) |
b8c9b27d | 6634 | xfree (bpt->triggered_dll_pathname); |
c906108c | 6635 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 6636 | xfree (bpt->exec_pathname); |
c906108c SS |
6637 | |
6638 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
6639 | /* FIXME, how can we find all bpstat's? | |
6640 | We just check stop_bpstat for now. */ | |
6641 | for (bs = stop_bpstat; bs; bs = bs->next) | |
6642 | if (bs->breakpoint_at == bpt) | |
6643 | { | |
6644 | bs->breakpoint_at = NULL; | |
c906108c | 6645 | bs->old_val = NULL; |
c2b8ed2c | 6646 | /* bs->commands will be freed later. */ |
c906108c SS |
6647 | } |
6648 | /* On the chance that someone will soon try again to delete this same | |
6649 | bp, we mark it as deleted before freeing its storage. */ | |
6650 | bpt->type = bp_none; | |
6651 | ||
b8c9b27d | 6652 | xfree (bpt); |
c906108c SS |
6653 | } |
6654 | ||
4d6140d9 AC |
6655 | static void |
6656 | do_delete_breakpoint_cleanup (void *b) | |
6657 | { | |
6658 | delete_breakpoint (b); | |
6659 | } | |
6660 | ||
6661 | struct cleanup * | |
6662 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
6663 | { | |
6664 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
6665 | } | |
6666 | ||
6667 | struct cleanup * | |
6668 | make_exec_cleanup_delete_breakpoint (struct breakpoint *b) | |
6669 | { | |
6670 | return make_exec_cleanup (do_delete_breakpoint_cleanup, b); | |
6671 | } | |
6672 | ||
c906108c | 6673 | void |
fba45db2 | 6674 | delete_command (char *arg, int from_tty) |
c906108c SS |
6675 | { |
6676 | struct breakpoint *b, *temp; | |
6677 | ||
ea9365bb TT |
6678 | dont_repeat (); |
6679 | ||
c906108c SS |
6680 | if (arg == 0) |
6681 | { | |
6682 | int breaks_to_delete = 0; | |
6683 | ||
6684 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
6685 | Do not delete internal or call-dummy breakpoints, these |
6686 | have to be deleted with an explicit breakpoint number argument. */ | |
6687 | ALL_BREAKPOINTS (b) | |
6688 | { | |
6689 | if (b->type != bp_call_dummy && | |
6690 | b->type != bp_shlib_event && | |
c4093a6a | 6691 | b->type != bp_thread_event && |
1900040c | 6692 | b->type != bp_overlay_event && |
c5aa993b JM |
6693 | b->number >= 0) |
6694 | breaks_to_delete = 1; | |
6695 | } | |
c906108c SS |
6696 | |
6697 | /* Ask user only if there are some breakpoints to delete. */ | |
6698 | if (!from_tty | |
6699 | || (breaks_to_delete && query ("Delete all breakpoints? "))) | |
6700 | { | |
c5aa993b JM |
6701 | ALL_BREAKPOINTS_SAFE (b, temp) |
6702 | { | |
6703 | if (b->type != bp_call_dummy && | |
6704 | b->type != bp_shlib_event && | |
c4093a6a | 6705 | b->type != bp_thread_event && |
1900040c | 6706 | b->type != bp_overlay_event && |
c5aa993b JM |
6707 | b->number >= 0) |
6708 | delete_breakpoint (b); | |
6709 | } | |
c906108c SS |
6710 | } |
6711 | } | |
6712 | else | |
6713 | map_breakpoint_numbers (arg, delete_breakpoint); | |
6714 | } | |
6715 | ||
6716 | /* Reset a breakpoint given it's struct breakpoint * BINT. | |
6717 | The value we return ends up being the return value from catch_errors. | |
6718 | Unused in this case. */ | |
6719 | ||
6720 | static int | |
4efb68b1 | 6721 | breakpoint_re_set_one (void *bint) |
c906108c | 6722 | { |
53a5351d JM |
6723 | /* get past catch_errs */ |
6724 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
6725 | struct value *mark; |
6726 | int i; | |
6727 | struct symtabs_and_lines sals; | |
6728 | char *s; | |
b5de0fa7 | 6729 | enum enable_state save_enable; |
c906108c SS |
6730 | |
6731 | switch (b->type) | |
6732 | { | |
6733 | case bp_none: | |
53a5351d JM |
6734 | warning ("attempted to reset apparently deleted breakpoint #%d?", |
6735 | b->number); | |
c906108c SS |
6736 | return 0; |
6737 | case bp_breakpoint: | |
6738 | case bp_hardware_breakpoint: | |
6739 | case bp_catch_load: | |
6740 | case bp_catch_unload: | |
6741 | if (b->addr_string == NULL) | |
6742 | { | |
6743 | /* Anything without a string can't be re-set. */ | |
6744 | delete_breakpoint (b); | |
6745 | return 0; | |
6746 | } | |
b18c45ed AC |
6747 | /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote: |
6748 | ||
6749 | ``And a hack it is, although Apple's Darwin version of GDB | |
6750 | contains an almost identical hack to implement a "future | |
6751 | break" command. It seems to work in many real world cases, | |
6752 | but it is easy to come up with a test case where the patch | |
6753 | doesn't help at all.'' | |
6754 | ||
6755 | ``It seems that the way GDB implements breakpoints - in - | |
6756 | shared - libraries was designed for a.out shared library | |
6757 | systems (SunOS 4) where shared libraries were loaded at a | |
6758 | fixed address in memory. Since ELF shared libraries can (and | |
6759 | will) be loaded at any address in memory, things break. | |
6760 | Fixing this is not trivial. Therefore, I'm not sure whether | |
6761 | we should add this hack to the branch only. I cannot | |
6762 | guarantee that things will be fixed on the trunk in the near | |
6763 | future.'' | |
6764 | ||
6765 | In case we have a problem, disable this breakpoint. We'll | |
6766 | restore its status if we succeed. Don't disable a | |
6767 | shlib_disabled breakpoint though. There's a fair chance we | |
6768 | can't re-set it if the shared library it's in hasn't been | |
6769 | loaded yet. */ | |
b5de0fa7 | 6770 | save_enable = b->enable_state; |
b18c45ed AC |
6771 | if (b->enable_state != bp_shlib_disabled) |
6772 | b->enable_state = bp_disabled; | |
c906108c SS |
6773 | |
6774 | set_language (b->language); | |
6775 | input_radix = b->input_radix; | |
6776 | s = b->addr_string; | |
c5aa993b | 6777 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
6778 | for (i = 0; i < sals.nelts; i++) |
6779 | { | |
6780 | resolve_sal_pc (&sals.sals[i]); | |
6781 | ||
6782 | /* Reparse conditions, they might contain references to the | |
6783 | old symtab. */ | |
6784 | if (b->cond_string != NULL) | |
6785 | { | |
6786 | s = b->cond_string; | |
6787 | if (b->cond) | |
b8c9b27d | 6788 | xfree (b->cond); |
c906108c SS |
6789 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); |
6790 | } | |
6791 | ||
c5aa993b | 6792 | /* We need to re-set the breakpoint if the address changes... */ |
c906108c | 6793 | if (b->address != sals.sals[i].pc |
c5aa993b JM |
6794 | /* ...or new and old breakpoints both have source files, and |
6795 | the source file name or the line number changes... */ | |
c906108c SS |
6796 | || (b->source_file != NULL |
6797 | && sals.sals[i].symtab != NULL | |
6798 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) | |
6799 | || b->line_number != sals.sals[i].line) | |
c906108c | 6800 | ) |
c5aa993b JM |
6801 | /* ...or we switch between having a source file and not having |
6802 | one. */ | |
6803 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) | |
6804 | ) | |
c906108c SS |
6805 | { |
6806 | if (b->source_file != NULL) | |
b8c9b27d | 6807 | xfree (b->source_file); |
c906108c SS |
6808 | if (sals.sals[i].symtab == NULL) |
6809 | b->source_file = NULL; | |
6810 | else | |
6811 | b->source_file = | |
6812 | savestring (sals.sals[i].symtab->filename, | |
6813 | strlen (sals.sals[i].symtab->filename)); | |
6814 | b->line_number = sals.sals[i].line; | |
6815 | b->address = sals.sals[i].pc; | |
6816 | ||
c5aa993b | 6817 | /* Used to check for duplicates here, but that can |
261c4ca2 | 6818 | cause trouble, as it doesn't check for disabled |
c5aa993b | 6819 | breakpoints. */ |
c906108c SS |
6820 | |
6821 | mention (b); | |
6822 | ||
6823 | /* Might be better to do this just once per breakpoint_re_set, | |
c5aa993b | 6824 | rather than once for every breakpoint. */ |
c906108c SS |
6825 | breakpoints_changed (); |
6826 | } | |
6827 | b->section = sals.sals[i].section; | |
b5de0fa7 | 6828 | b->enable_state = save_enable; /* Restore it, this worked. */ |
c906108c SS |
6829 | |
6830 | ||
c5aa993b | 6831 | /* Now that this is re-enabled, check_duplicates |
c906108c | 6832 | can be used. */ |
9f60f21b | 6833 | check_duplicates (b); |
c906108c SS |
6834 | |
6835 | } | |
b8c9b27d | 6836 | xfree (sals.sals); |
c906108c SS |
6837 | break; |
6838 | ||
6839 | case bp_watchpoint: | |
6840 | case bp_hardware_watchpoint: | |
6841 | case bp_read_watchpoint: | |
6842 | case bp_access_watchpoint: | |
6843 | innermost_block = NULL; | |
53a5351d JM |
6844 | /* The issue arises of what context to evaluate this in. The |
6845 | same one as when it was set, but what does that mean when | |
6846 | symbols have been re-read? We could save the filename and | |
6847 | functionname, but if the context is more local than that, the | |
6848 | best we could do would be something like how many levels deep | |
6849 | and which index at that particular level, but that's going to | |
6850 | be less stable than filenames or function names. */ | |
6851 | ||
c906108c SS |
6852 | /* So for now, just use a global context. */ |
6853 | if (b->exp) | |
b8c9b27d | 6854 | xfree (b->exp); |
c906108c SS |
6855 | b->exp = parse_expression (b->exp_string); |
6856 | b->exp_valid_block = innermost_block; | |
6857 | mark = value_mark (); | |
6858 | if (b->val) | |
6859 | value_free (b->val); | |
6860 | b->val = evaluate_expression (b->exp); | |
6861 | release_value (b->val); | |
a881cf8e | 6862 | if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled) |
c906108c SS |
6863 | value_fetch_lazy (b->val); |
6864 | ||
6865 | if (b->cond_string != NULL) | |
6866 | { | |
6867 | s = b->cond_string; | |
6868 | if (b->cond) | |
b8c9b27d | 6869 | xfree (b->cond); |
c5aa993b | 6870 | b->cond = parse_exp_1 (&s, (struct block *) 0, 0); |
c906108c | 6871 | } |
b5de0fa7 | 6872 | if (b->enable_state == bp_enabled) |
c906108c SS |
6873 | mention (b); |
6874 | value_free_to_mark (mark); | |
6875 | break; | |
c5aa993b JM |
6876 | case bp_catch_catch: |
6877 | case bp_catch_throw: | |
c906108c | 6878 | break; |
c5aa993b JM |
6879 | /* We needn't really do anything to reset these, since the mask |
6880 | that requests them is unaffected by e.g., new libraries being | |
6881 | loaded. */ | |
c906108c SS |
6882 | case bp_catch_fork: |
6883 | case bp_catch_vfork: | |
6884 | case bp_catch_exec: | |
6885 | break; | |
c5aa993b | 6886 | |
c906108c SS |
6887 | default: |
6888 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); | |
6889 | /* fall through */ | |
1900040c MS |
6890 | /* Delete longjmp and overlay event breakpoints; they will be |
6891 | reset later by breakpoint_re_set. */ | |
c906108c SS |
6892 | case bp_longjmp: |
6893 | case bp_longjmp_resume: | |
1900040c | 6894 | case bp_overlay_event: |
c906108c SS |
6895 | delete_breakpoint (b); |
6896 | break; | |
6897 | ||
c5aa993b JM |
6898 | /* This breakpoint is special, it's set up when the inferior |
6899 | starts and we really don't want to touch it. */ | |
c906108c SS |
6900 | case bp_shlib_event: |
6901 | ||
c4093a6a JM |
6902 | /* Like bp_shlib_event, this breakpoint type is special. |
6903 | Once it is set up, we do not want to touch it. */ | |
6904 | case bp_thread_event: | |
6905 | ||
c5aa993b JM |
6906 | /* Keep temporary breakpoints, which can be encountered when we step |
6907 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
6908 | Otherwise these should have been blown away via the cleanup chain | |
6909 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
6910 | case bp_until: |
6911 | case bp_finish: | |
6912 | case bp_watchpoint_scope: | |
6913 | case bp_call_dummy: | |
6914 | case bp_step_resume: | |
6915 | break; | |
6916 | } | |
6917 | ||
6918 | return 0; | |
6919 | } | |
6920 | ||
6921 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
6922 | void | |
fba45db2 | 6923 | breakpoint_re_set (void) |
c906108c SS |
6924 | { |
6925 | struct breakpoint *b, *temp; | |
6926 | enum language save_language; | |
6927 | int save_input_radix; | |
6928 | static char message1[] = "Error in re-setting breakpoint %d:\n"; | |
c5aa993b JM |
6929 | char message[sizeof (message1) + 30 /* slop */ ]; |
6930 | ||
c906108c SS |
6931 | save_language = current_language->la_language; |
6932 | save_input_radix = input_radix; | |
6933 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 6934 | { |
53a5351d JM |
6935 | /* Format possible error msg */ |
6936 | sprintf (message, message1, b->number); | |
c5aa993b JM |
6937 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
6938 | } | |
c906108c SS |
6939 | set_language (save_language); |
6940 | input_radix = save_input_radix; | |
6941 | ||
9df628e0 RE |
6942 | if (GET_LONGJMP_TARGET_P ()) |
6943 | { | |
6944 | create_longjmp_breakpoint ("longjmp"); | |
6945 | create_longjmp_breakpoint ("_longjmp"); | |
6946 | create_longjmp_breakpoint ("siglongjmp"); | |
6947 | create_longjmp_breakpoint ("_siglongjmp"); | |
6948 | create_longjmp_breakpoint (NULL); | |
6949 | } | |
1900040c MS |
6950 | |
6951 | create_overlay_event_breakpoint ("_ovly_debug_event"); | |
c906108c SS |
6952 | } |
6953 | \f | |
c906108c SS |
6954 | /* Reset the thread number of this breakpoint: |
6955 | ||
6956 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 6957 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 6958 | void |
fba45db2 | 6959 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
6960 | { |
6961 | if (b->thread != -1) | |
6962 | { | |
39f77062 KB |
6963 | if (in_thread_list (inferior_ptid)) |
6964 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
6965 | } |
6966 | } | |
6967 | ||
03ac34d5 MS |
6968 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
6969 | If from_tty is nonzero, it prints a message to that effect, | |
6970 | which ends with a period (no newline). */ | |
6971 | ||
c906108c | 6972 | void |
fba45db2 | 6973 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c SS |
6974 | { |
6975 | register struct breakpoint *b; | |
6976 | ||
6977 | if (count < 0) | |
6978 | count = 0; | |
6979 | ||
6980 | ALL_BREAKPOINTS (b) | |
6981 | if (b->number == bptnum) | |
c5aa993b JM |
6982 | { |
6983 | b->ignore_count = count; | |
221ea385 KS |
6984 | if (from_tty) |
6985 | { | |
6986 | if (count == 0) | |
6987 | printf_filtered ("Will stop next time breakpoint %d is reached.", | |
6988 | bptnum); | |
6989 | else if (count == 1) | |
6990 | printf_filtered ("Will ignore next crossing of breakpoint %d.", | |
6991 | bptnum); | |
6992 | else | |
6993 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", | |
6994 | count, bptnum); | |
6995 | } | |
c5aa993b | 6996 | breakpoints_changed (); |
221ea385 | 6997 | breakpoint_modify_event (b->number); |
c5aa993b JM |
6998 | return; |
6999 | } | |
c906108c SS |
7000 | |
7001 | error ("No breakpoint number %d.", bptnum); | |
7002 | } | |
7003 | ||
7004 | /* Clear the ignore counts of all breakpoints. */ | |
7005 | void | |
fba45db2 | 7006 | breakpoint_clear_ignore_counts (void) |
c906108c SS |
7007 | { |
7008 | struct breakpoint *b; | |
7009 | ||
7010 | ALL_BREAKPOINTS (b) | |
7011 | b->ignore_count = 0; | |
7012 | } | |
7013 | ||
7014 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
7015 | ||
7016 | static void | |
fba45db2 | 7017 | ignore_command (char *args, int from_tty) |
c906108c SS |
7018 | { |
7019 | char *p = args; | |
7020 | register int num; | |
7021 | ||
7022 | if (p == 0) | |
7023 | error_no_arg ("a breakpoint number"); | |
c5aa993b | 7024 | |
c906108c | 7025 | num = get_number (&p); |
5c44784c JM |
7026 | if (num == 0) |
7027 | error ("bad breakpoint number: '%s'", args); | |
c906108c SS |
7028 | if (*p == 0) |
7029 | error ("Second argument (specified ignore-count) is missing."); | |
7030 | ||
7031 | set_ignore_count (num, | |
7032 | longest_to_int (value_as_long (parse_and_eval (p))), | |
7033 | from_tty); | |
221ea385 KS |
7034 | if (from_tty) |
7035 | printf_filtered ("\n"); | |
c906108c SS |
7036 | } |
7037 | \f | |
7038 | /* Call FUNCTION on each of the breakpoints | |
7039 | whose numbers are given in ARGS. */ | |
7040 | ||
7041 | static void | |
831662b3 | 7042 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c SS |
7043 | { |
7044 | register char *p = args; | |
7045 | char *p1; | |
7046 | register int num; | |
5c44784c | 7047 | register struct breakpoint *b, *tmp; |
11cf8741 | 7048 | int match; |
c906108c SS |
7049 | |
7050 | if (p == 0) | |
7051 | error_no_arg ("one or more breakpoint numbers"); | |
7052 | ||
7053 | while (*p) | |
7054 | { | |
11cf8741 | 7055 | match = 0; |
c906108c | 7056 | p1 = p; |
c5aa993b | 7057 | |
5c44784c JM |
7058 | num = get_number_or_range (&p1); |
7059 | if (num == 0) | |
c5aa993b | 7060 | { |
5c44784c JM |
7061 | warning ("bad breakpoint number at or near '%s'", p); |
7062 | } | |
7063 | else | |
7064 | { | |
7065 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
7066 | if (b->number == num) | |
7067 | { | |
7068 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 7069 | match = 1; |
5c44784c JM |
7070 | function (b); |
7071 | if (related_breakpoint) | |
7072 | function (related_breakpoint); | |
11cf8741 | 7073 | break; |
5c44784c | 7074 | } |
11cf8741 JM |
7075 | if (match == 0) |
7076 | printf_unfiltered ("No breakpoint number %d.\n", num); | |
c5aa993b | 7077 | } |
c906108c SS |
7078 | p = p1; |
7079 | } | |
7080 | } | |
7081 | ||
1900040c MS |
7082 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
7083 | If from_tty is nonzero, it prints a message to that effect, | |
7084 | which ends with a period (no newline). */ | |
7085 | ||
c906108c | 7086 | void |
fba45db2 | 7087 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7088 | { |
7089 | /* Never disable a watchpoint scope breakpoint; we want to | |
7090 | hit them when we leave scope so we can delete both the | |
7091 | watchpoint and its scope breakpoint at that time. */ | |
7092 | if (bpt->type == bp_watchpoint_scope) | |
7093 | return; | |
7094 | ||
c2c6d25f | 7095 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 7096 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
7097 | return; |
7098 | ||
b5de0fa7 | 7099 | bpt->enable_state = bp_disabled; |
c906108c | 7100 | |
9f60f21b | 7101 | check_duplicates (bpt); |
c906108c SS |
7102 | |
7103 | if (modify_breakpoint_hook) | |
7104 | modify_breakpoint_hook (bpt); | |
104c1213 | 7105 | breakpoint_modify_event (bpt->number); |
c906108c SS |
7106 | } |
7107 | ||
7108 | /* ARGSUSED */ | |
7109 | static void | |
fba45db2 | 7110 | disable_command (char *args, int from_tty) |
c906108c SS |
7111 | { |
7112 | register struct breakpoint *bpt; | |
7113 | if (args == 0) | |
7114 | ALL_BREAKPOINTS (bpt) | |
7115 | switch (bpt->type) | |
c5aa993b JM |
7116 | { |
7117 | case bp_none: | |
53a5351d JM |
7118 | warning ("attempted to disable apparently deleted breakpoint #%d?", |
7119 | bpt->number); | |
c5aa993b JM |
7120 | continue; |
7121 | case bp_breakpoint: | |
7122 | case bp_catch_load: | |
7123 | case bp_catch_unload: | |
7124 | case bp_catch_fork: | |
7125 | case bp_catch_vfork: | |
7126 | case bp_catch_exec: | |
7127 | case bp_catch_catch: | |
7128 | case bp_catch_throw: | |
7129 | case bp_hardware_breakpoint: | |
7130 | case bp_watchpoint: | |
7131 | case bp_hardware_watchpoint: | |
7132 | case bp_read_watchpoint: | |
7133 | case bp_access_watchpoint: | |
7134 | disable_breakpoint (bpt); | |
7135 | default: | |
7136 | continue; | |
7137 | } | |
c906108c SS |
7138 | else |
7139 | map_breakpoint_numbers (args, disable_breakpoint); | |
7140 | } | |
7141 | ||
7142 | static void | |
fba45db2 | 7143 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c SS |
7144 | { |
7145 | struct frame_info *save_selected_frame = NULL; | |
7146 | int save_selected_frame_level = -1; | |
7147 | int target_resources_ok, other_type_used; | |
7148 | struct value *mark; | |
7149 | ||
7150 | if (bpt->type == bp_hardware_breakpoint) | |
7151 | { | |
7152 | int i; | |
c5aa993b | 7153 | i = hw_breakpoint_used_count (); |
53a5351d JM |
7154 | target_resources_ok = |
7155 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
7156 | i + 1, 0); | |
c906108c | 7157 | if (target_resources_ok == 0) |
c5aa993b | 7158 | error ("No hardware breakpoint support in the target."); |
c906108c | 7159 | else if (target_resources_ok < 0) |
c5aa993b | 7160 | error ("Hardware breakpoints used exceeds limit."); |
c906108c SS |
7161 | } |
7162 | ||
b5de0fa7 EZ |
7163 | if (bpt->enable_state != bp_permanent) |
7164 | bpt->enable_state = bp_enabled; | |
c906108c | 7165 | bpt->disposition = disposition; |
9f60f21b | 7166 | check_duplicates (bpt); |
c906108c SS |
7167 | breakpoints_changed (); |
7168 | ||
53a5351d JM |
7169 | if (bpt->type == bp_watchpoint || |
7170 | bpt->type == bp_hardware_watchpoint || | |
7171 | bpt->type == bp_read_watchpoint || | |
7172 | bpt->type == bp_access_watchpoint) | |
c906108c SS |
7173 | { |
7174 | if (bpt->exp_valid_block != NULL) | |
7175 | { | |
7176 | struct frame_info *fr = | |
101dcfbe | 7177 | fr = frame_find_by_id (bpt->watchpoint_frame); |
c906108c SS |
7178 | if (fr == NULL) |
7179 | { | |
7180 | printf_filtered ("\ | |
7181 | Cannot enable watchpoint %d because the block in which its expression\n\ | |
7182 | is valid is not currently in scope.\n", bpt->number); | |
b5de0fa7 | 7183 | bpt->enable_state = bp_disabled; |
c906108c SS |
7184 | return; |
7185 | } | |
7186 | ||
6e7f8b9c AC |
7187 | save_selected_frame = deprecated_selected_frame; |
7188 | save_selected_frame_level = frame_relative_level (deprecated_selected_frame); | |
0f7d239c | 7189 | select_frame (fr); |
c906108c SS |
7190 | } |
7191 | ||
7192 | value_free (bpt->val); | |
7193 | mark = value_mark (); | |
7194 | bpt->val = evaluate_expression (bpt->exp); | |
7195 | release_value (bpt->val); | |
7196 | if (VALUE_LAZY (bpt->val)) | |
7197 | value_fetch_lazy (bpt->val); | |
7198 | ||
7199 | if (bpt->type == bp_hardware_watchpoint || | |
c5aa993b JM |
7200 | bpt->type == bp_read_watchpoint || |
7201 | bpt->type == bp_access_watchpoint) | |
7202 | { | |
7203 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); | |
7204 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); | |
7205 | ||
7206 | /* Hack around 'unused var' error for some targets here */ | |
7207 | (void) mem_cnt, i; | |
7208 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( | |
7209 | bpt->type, i + mem_cnt, other_type_used); | |
7210 | /* we can consider of type is bp_hardware_watchpoint, convert to | |
7211 | bp_watchpoint in the following condition */ | |
7212 | if (target_resources_ok < 0) | |
7213 | { | |
7214 | printf_filtered ("\ | |
c906108c SS |
7215 | Cannot enable watchpoint %d because target watch resources\n\ |
7216 | have been allocated for other watchpoints.\n", bpt->number); | |
b5de0fa7 | 7217 | bpt->enable_state = bp_disabled; |
c5aa993b JM |
7218 | value_free_to_mark (mark); |
7219 | return; | |
7220 | } | |
7221 | } | |
c906108c SS |
7222 | |
7223 | if (save_selected_frame_level >= 0) | |
0f7d239c | 7224 | select_frame (save_selected_frame); |
c906108c SS |
7225 | value_free_to_mark (mark); |
7226 | } | |
7227 | if (modify_breakpoint_hook) | |
7228 | modify_breakpoint_hook (bpt); | |
104c1213 | 7229 | breakpoint_modify_event (bpt->number); |
c906108c SS |
7230 | } |
7231 | ||
7232 | void | |
fba45db2 | 7233 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
7234 | { |
7235 | do_enable_breakpoint (bpt, bpt->disposition); | |
7236 | } | |
7237 | ||
7238 | /* The enable command enables the specified breakpoints (or all defined | |
7239 | breakpoints) so they once again become (or continue to be) effective | |
7240 | in stopping the inferior. */ | |
7241 | ||
7242 | /* ARGSUSED */ | |
7243 | static void | |
fba45db2 | 7244 | enable_command (char *args, int from_tty) |
c906108c SS |
7245 | { |
7246 | register struct breakpoint *bpt; | |
7247 | if (args == 0) | |
7248 | ALL_BREAKPOINTS (bpt) | |
7249 | switch (bpt->type) | |
c5aa993b JM |
7250 | { |
7251 | case bp_none: | |
53a5351d JM |
7252 | warning ("attempted to enable apparently deleted breakpoint #%d?", |
7253 | bpt->number); | |
c5aa993b JM |
7254 | continue; |
7255 | case bp_breakpoint: | |
7256 | case bp_catch_load: | |
7257 | case bp_catch_unload: | |
7258 | case bp_catch_fork: | |
7259 | case bp_catch_vfork: | |
7260 | case bp_catch_exec: | |
7261 | case bp_catch_catch: | |
7262 | case bp_catch_throw: | |
7263 | case bp_hardware_breakpoint: | |
7264 | case bp_watchpoint: | |
7265 | case bp_hardware_watchpoint: | |
7266 | case bp_read_watchpoint: | |
7267 | case bp_access_watchpoint: | |
7268 | enable_breakpoint (bpt); | |
7269 | default: | |
7270 | continue; | |
7271 | } | |
c906108c SS |
7272 | else |
7273 | map_breakpoint_numbers (args, enable_breakpoint); | |
7274 | } | |
7275 | ||
7276 | static void | |
fba45db2 | 7277 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 7278 | { |
b5de0fa7 | 7279 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
7280 | } |
7281 | ||
7282 | /* ARGSUSED */ | |
7283 | static void | |
fba45db2 | 7284 | enable_once_command (char *args, int from_tty) |
c906108c SS |
7285 | { |
7286 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
7287 | } | |
7288 | ||
7289 | static void | |
fba45db2 | 7290 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7291 | { |
b5de0fa7 | 7292 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
7293 | } |
7294 | ||
7295 | /* ARGSUSED */ | |
7296 | static void | |
fba45db2 | 7297 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
7298 | { |
7299 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
7300 | } | |
7301 | \f | |
7302 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ | |
7303 | ||
7304 | struct symtabs_and_lines | |
fba45db2 | 7305 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
7306 | { |
7307 | struct symtabs_and_lines sals; | |
7308 | if (string == 0) | |
7309 | error ("Empty line specification."); | |
7310 | if (default_breakpoint_valid) | |
7311 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
7312 | default_breakpoint_symtab, |
7313 | default_breakpoint_line, | |
c5aa993b | 7314 | (char ***) NULL); |
c906108c SS |
7315 | else |
7316 | sals = decode_line_1 (&string, funfirstline, | |
c5aa993b | 7317 | (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
7318 | if (*string) |
7319 | error ("Junk at end of line specification: %s", string); | |
7320 | return sals; | |
7321 | } | |
7322 | \f | |
7323 | void | |
fba45db2 | 7324 | _initialize_breakpoint (void) |
c906108c SS |
7325 | { |
7326 | struct cmd_list_element *c; | |
7327 | ||
7328 | breakpoint_chain = 0; | |
7329 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
7330 | before a breakpoint is set. */ | |
7331 | breakpoint_count = 0; | |
7332 | ||
7333 | add_com ("ignore", class_breakpoint, ignore_command, | |
7334 | "Set ignore-count of breakpoint number N to COUNT.\n\ | |
7335 | Usage is `ignore N COUNT'."); | |
7336 | if (xdb_commands) | |
c5aa993b | 7337 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c SS |
7338 | |
7339 | add_com ("commands", class_breakpoint, commands_command, | |
7340 | "Set commands to be executed when a breakpoint is hit.\n\ | |
7341 | Give breakpoint number as argument after \"commands\".\n\ | |
7342 | With no argument, the targeted breakpoint is the last one set.\n\ | |
7343 | The commands themselves follow starting on the next line.\n\ | |
7344 | Type a line containing \"end\" to indicate the end of them.\n\ | |
7345 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
7346 | then no output is printed when it is hit, except what the commands print."); | |
7347 | ||
7348 | add_com ("condition", class_breakpoint, condition_command, | |
7349 | "Specify breakpoint number N to break only if COND is true.\n\ | |
7350 | Usage is `condition N COND', where N is an integer and COND is an\n\ | |
d4654627 | 7351 | expression to be evaluated whenever breakpoint N is reached."); |
c906108c | 7352 | |
c94fdfd0 EZ |
7353 | c = add_com ("tbreak", class_breakpoint, tbreak_command, |
7354 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7355 | Like \"break\" except the breakpoint is only temporary,\n\ |
7356 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
7357 | by using \"enable delete\" on the breakpoint number."); | |
5ba2abeb | 7358 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 7359 | |
c94fdfd0 EZ |
7360 | c = add_com ("hbreak", class_breakpoint, hbreak_command, |
7361 | "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7362 | Like \"break\" except the breakpoint requires hardware support,\n\ |
7363 | some target hardware may not have this support."); | |
5ba2abeb | 7364 | set_cmd_completer (c, location_completer); |
c906108c | 7365 | |
c94fdfd0 EZ |
7366 | c = add_com ("thbreak", class_breakpoint, thbreak_command, |
7367 | "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ | |
c906108c SS |
7368 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
7369 | so it will be deleted when hit."); | |
5ba2abeb | 7370 | set_cmd_completer (c, location_completer); |
c906108c SS |
7371 | |
7372 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
7373 | "Enable some breakpoints.\n\ | |
7374 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
7375 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
7376 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7377 | With a subcommand you can enable temporarily.", | |
7378 | &enablelist, "enable ", 1, &cmdlist); | |
7379 | if (xdb_commands) | |
c5aa993b JM |
7380 | add_com ("ab", class_breakpoint, enable_command, |
7381 | "Enable some breakpoints.\n\ | |
c906108c SS |
7382 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
7383 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
7384 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7385 | With a subcommand you can enable temporarily."); | |
7386 | ||
7387 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
7388 | ||
7389 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
c5aa993b | 7390 | "Enable some breakpoints.\n\ |
c906108c SS |
7391 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
7392 | This is used to cancel the effect of the \"disable\" command.\n\ | |
7393 | May be abbreviated to simply \"enable\".\n", | |
c5aa993b | 7394 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c SS |
7395 | |
7396 | add_cmd ("once", no_class, enable_once_command, | |
7397 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
7398 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
7399 | &enablebreaklist); | |
7400 | ||
7401 | add_cmd ("delete", no_class, enable_delete_command, | |
7402 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
7403 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
7404 | &enablebreaklist); | |
7405 | ||
7406 | add_cmd ("delete", no_class, enable_delete_command, | |
7407 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
7408 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
7409 | &enablelist); | |
7410 | ||
7411 | add_cmd ("once", no_class, enable_once_command, | |
7412 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
7413 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
7414 | &enablelist); | |
7415 | ||
7416 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
c5aa993b | 7417 | "Disable some breakpoints.\n\ |
c906108c SS |
7418 | Arguments are breakpoint numbers with spaces in between.\n\ |
7419 | To disable all breakpoints, give no argument.\n\ | |
7420 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
7421 | &disablelist, "disable ", 1, &cmdlist); | |
7422 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
7423 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
7424 | if (xdb_commands) | |
c5aa993b JM |
7425 | add_com ("sb", class_breakpoint, disable_command, |
7426 | "Disable some breakpoints.\n\ | |
c906108c SS |
7427 | Arguments are breakpoint numbers with spaces in between.\n\ |
7428 | To disable all breakpoints, give no argument.\n\ | |
7429 | A disabled breakpoint is not forgotten, but has no effect until reenabled."); | |
7430 | ||
7431 | add_cmd ("breakpoints", class_alias, disable_command, | |
7432 | "Disable some breakpoints.\n\ | |
7433 | Arguments are breakpoint numbers with spaces in between.\n\ | |
7434 | To disable all breakpoints, give no argument.\n\ | |
7435 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
7436 | This command may be abbreviated \"disable\".", | |
7437 | &disablelist); | |
7438 | ||
7439 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
c5aa993b | 7440 | "Delete some breakpoints or auto-display expressions.\n\ |
c906108c SS |
7441 | Arguments are breakpoint numbers with spaces in between.\n\ |
7442 | To delete all breakpoints, give no argument.\n\ | |
7443 | \n\ | |
7444 | Also a prefix command for deletion of other GDB objects.\n\ | |
7445 | The \"unset\" command is also an alias for \"delete\".", | |
7446 | &deletelist, "delete ", 1, &cmdlist); | |
7447 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7448 | if (xdb_commands) | |
7449 | add_com ("db", class_breakpoint, delete_command, | |
c5aa993b | 7450 | "Delete some breakpoints.\n\ |
c906108c SS |
7451 | Arguments are breakpoint numbers with spaces in between.\n\ |
7452 | To delete all breakpoints, give no argument.\n"); | |
7453 | ||
7454 | add_cmd ("breakpoints", class_alias, delete_command, | |
7455 | "Delete some breakpoints or auto-display expressions.\n\ | |
7456 | Arguments are breakpoint numbers with spaces in between.\n\ | |
7457 | To delete all breakpoints, give no argument.\n\ | |
7458 | This command may be abbreviated \"delete\".", | |
7459 | &deletelist); | |
7460 | ||
7461 | add_com ("clear", class_breakpoint, clear_command, | |
7462 | concat ("Clear breakpoint at specified line or function.\n\ | |
7463 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
7464 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
7465 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
7466 | If an address is specified, breakpoints at that address are cleared.\n\n", | |
c5aa993b | 7467 | "With no argument, clears all breakpoints in the line that the selected frame\n\ |
c906108c SS |
7468 | is executing in.\n\ |
7469 | \n\ | |
7470 | See also the \"delete\" command which clears breakpoints by number.", NULL)); | |
7471 | ||
c94fdfd0 EZ |
7472 | c = add_com ("break", class_breakpoint, break_command, |
7473 | concat ("Set breakpoint at specified line or function.\n\ | |
c906108c SS |
7474 | Argument may be line number, function name, or \"*\" and an address.\n\ |
7475 | If line number is specified, break at start of code for that line.\n\ | |
7476 | If function is specified, break at start of code for that function.\n\ | |
7477 | If an address is specified, break at that exact address.\n", | |
c5aa993b | 7478 | "With no arg, uses current execution address of selected stack frame.\n\ |
c906108c SS |
7479 | This is useful for breaking on return to a stack frame.\n\ |
7480 | \n\ | |
7481 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
7482 | \n\ | |
7483 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); | |
5ba2abeb | 7484 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 7485 | |
c906108c SS |
7486 | add_com_alias ("b", "break", class_run, 1); |
7487 | add_com_alias ("br", "break", class_run, 1); | |
7488 | add_com_alias ("bre", "break", class_run, 1); | |
7489 | add_com_alias ("brea", "break", class_run, 1); | |
7490 | ||
502fd408 | 7491 | if (xdb_commands) |
c906108c SS |
7492 | { |
7493 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
7494 | add_com_alias ("bu", "ubreak", class_breakpoint, 1); | |
c906108c SS |
7495 | } |
7496 | ||
7497 | if (dbx_commands) | |
7498 | { | |
c5aa993b JM |
7499 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, |
7500 | "Break in function/address or break at a line in the current file.", | |
7501 | &stoplist, "stop ", 1, &cmdlist); | |
7502 | add_cmd ("in", class_breakpoint, stopin_command, | |
7503 | "Break in function or address.\n", &stoplist); | |
7504 | add_cmd ("at", class_breakpoint, stopat_command, | |
7505 | "Break at a line in the current file.\n", &stoplist); | |
7506 | add_com ("status", class_info, breakpoints_info, | |
7507 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
7508 | The \"Type\" column indicates one of:\n\ |
7509 | \tbreakpoint - normal breakpoint\n\ | |
7510 | \twatchpoint - watchpoint\n\ | |
7511 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7512 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7513 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7514 | address and file/line number respectively.\n\n", | |
c5aa993b | 7515 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7516 | are set to the address of the last breakpoint listed.\n\n\ |
7517 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7518 | breakpoint set.", NULL)); | |
7519 | } | |
7520 | ||
7521 | add_info ("breakpoints", breakpoints_info, | |
7522 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
7523 | The \"Type\" column indicates one of:\n\ | |
7524 | \tbreakpoint - normal breakpoint\n\ | |
7525 | \twatchpoint - watchpoint\n\ | |
7526 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7527 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7528 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7529 | address and file/line number respectively.\n\n", | |
c5aa993b | 7530 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7531 | are set to the address of the last breakpoint listed.\n\n\ |
7532 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7533 | breakpoint set.", NULL)); | |
7534 | ||
7535 | if (xdb_commands) | |
c5aa993b JM |
7536 | add_com ("lb", class_breakpoint, breakpoints_info, |
7537 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
7538 | The \"Type\" column indicates one of:\n\ |
7539 | \tbreakpoint - normal breakpoint\n\ | |
7540 | \twatchpoint - watchpoint\n\ | |
7541 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
7542 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
7543 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7544 | address and file/line number respectively.\n\n", | |
c5aa993b | 7545 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7546 | are set to the address of the last breakpoint listed.\n\n\ |
7547 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7548 | breakpoint set.", NULL)); | |
7549 | ||
c906108c | 7550 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, |
c5aa993b | 7551 | concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
7552 | The \"Type\" column indicates one of:\n\ |
7553 | \tbreakpoint - normal breakpoint\n\ | |
7554 | \twatchpoint - watchpoint\n\ | |
7555 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
7556 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
7557 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
7558 | \tfinish - internal breakpoint used by the \"finish\" command\n", | |
c5aa993b | 7559 | "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
c906108c SS |
7560 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
7561 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
7562 | address and file/line number respectively.\n\n", | |
c5aa993b | 7563 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
7564 | are set to the address of the last breakpoint listed.\n\n\ |
7565 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
7566 | breakpoint set.", NULL), | |
7567 | &maintenanceinfolist); | |
7568 | ||
c906108c | 7569 | add_com ("catch", class_breakpoint, catch_command, |
c5aa993b | 7570 | "Set catchpoints to catch events.\n\ |
c906108c SS |
7571 | Raised signals may be caught:\n\ |
7572 | \tcatch signal - all signals\n\ | |
7573 | \tcatch signal <signame> - a particular signal\n\ | |
7574 | Raised exceptions may be caught:\n\ | |
7575 | \tcatch throw - all exceptions, when thrown\n\ | |
7576 | \tcatch throw <exceptname> - a particular exception, when thrown\n\ | |
7577 | \tcatch catch - all exceptions, when caught\n\ | |
7578 | \tcatch catch <exceptname> - a particular exception, when caught\n\ | |
7579 | Thread or process events may be caught:\n\ | |
7580 | \tcatch thread_start - any threads, just after creation\n\ | |
7581 | \tcatch thread_exit - any threads, just before expiration\n\ | |
7582 | \tcatch thread_join - any threads, just after joins\n\ | |
7583 | Process events may be caught:\n\ | |
7584 | \tcatch start - any processes, just after creation\n\ | |
7585 | \tcatch exit - any processes, just before expiration\n\ | |
7586 | \tcatch fork - calls to fork()\n\ | |
7587 | \tcatch vfork - calls to vfork()\n\ | |
7588 | \tcatch exec - calls to exec()\n\ | |
7589 | Dynamically-linked library events may be caught:\n\ | |
7590 | \tcatch load - loads of any library\n\ | |
7591 | \tcatch load <libname> - loads of a particular library\n\ | |
7592 | \tcatch unload - unloads of any library\n\ | |
7593 | \tcatch unload <libname> - unloads of a particular library\n\ | |
7594 | The act of your program's execution stopping may also be caught:\n\ | |
7595 | \tcatch stop\n\n\ | |
7596 | C++ exceptions may be caught:\n\ | |
7597 | \tcatch throw - all exceptions, when thrown\n\ | |
7598 | \tcatch catch - all exceptions, when caught\n\ | |
7599 | \n\ | |
7600 | Do \"help set follow-fork-mode\" for info on debugging your program\n\ | |
7601 | after a fork or vfork is caught.\n\n\ | |
7602 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
c5aa993b | 7603 | |
c906108c | 7604 | add_com ("tcatch", class_breakpoint, tcatch_command, |
c5aa993b | 7605 | "Set temporary catchpoints to catch events.\n\ |
c906108c SS |
7606 | Args like \"catch\" command.\n\ |
7607 | Like \"catch\" except the catchpoint is only temporary,\n\ | |
7608 | so it will be deleted when hit. Equivalent to \"catch\" followed\n\ | |
7609 | by using \"enable delete\" on the catchpoint number."); | |
c5aa993b | 7610 | |
c94fdfd0 EZ |
7611 | c = add_com ("watch", class_breakpoint, watch_command, |
7612 | "Set a watchpoint for an expression.\n\ | |
c906108c SS |
7613 | A watchpoint stops execution of your program whenever the value of\n\ |
7614 | an expression changes."); | |
5ba2abeb | 7615 | set_cmd_completer (c, location_completer); |
c906108c | 7616 | |
c94fdfd0 EZ |
7617 | c = add_com ("rwatch", class_breakpoint, rwatch_command, |
7618 | "Set a read watchpoint for an expression.\n\ | |
c906108c SS |
7619 | A watchpoint stops execution of your program whenever the value of\n\ |
7620 | an expression is read."); | |
5ba2abeb | 7621 | set_cmd_completer (c, location_completer); |
c906108c | 7622 | |
c94fdfd0 EZ |
7623 | c = add_com ("awatch", class_breakpoint, awatch_command, |
7624 | "Set a watchpoint for an expression.\n\ | |
c906108c SS |
7625 | A watchpoint stops execution of your program whenever the value of\n\ |
7626 | an expression is either read or written."); | |
5ba2abeb | 7627 | set_cmd_completer (c, location_completer); |
c906108c SS |
7628 | |
7629 | add_info ("watchpoints", breakpoints_info, | |
7630 | "Synonym for ``info breakpoints''."); | |
7631 | ||
7632 | ||
7633 | c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger, | |
c5aa993b JM |
7634 | (char *) &can_use_hw_watchpoints, |
7635 | "Set debugger's willingness to use watchpoint hardware.\n\ | |
c906108c SS |
7636 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
7637 | such is available. (However, any hardware watchpoints that were\n\ | |
7638 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
7639 | hardware.)", | |
c5aa993b | 7640 | &setlist); |
c906108c SS |
7641 | add_show_from_set (c, &showlist); |
7642 | ||
7643 | can_use_hw_watchpoints = 1; | |
7644 | } |