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