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