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