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