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