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