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