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