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