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