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