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