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