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.
5 This file is part of GDB.
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
43 /* Prototypes for local functions. */
46 catch_command_1 PARAMS ((char *, int, int));
49 enable_delete_command PARAMS ((char *, int));
52 enable_delete_breakpoint PARAMS ((struct breakpoint *));
55 enable_once_command PARAMS ((char *, int));
58 enable_once_breakpoint PARAMS ((struct breakpoint *));
61 disable_command PARAMS ((char *, int));
64 enable_command PARAMS ((char *, int));
67 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
70 ignore_command PARAMS ((char *, int));
72 static int breakpoint_re_set_one PARAMS ((PTR));
75 clear_command PARAMS ((char *, int));
78 catch_command PARAMS ((char *, int));
81 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
83 static struct symtabs_and_lines
84 get_catch_sals PARAMS ((int));
87 watch_command PARAMS ((char *, int));
90 can_use_hardware_watchpoint PARAMS ((struct value *));
92 static void break_at_finish_command PARAMS ((char *, int));
93 static void break_at_finish_at_depth_command PARAMS ((char *, int));
96 tbreak_command PARAMS ((char *, int));
98 static void tbreak_at_finish_command PARAMS ((char *, int));
101 break_command_1 PARAMS ((char *, int, int));
104 mention PARAMS ((struct breakpoint *));
107 set_raw_breakpoint PARAMS ((struct symtab_and_line));
110 check_duplicates PARAMS ((CORE_ADDR, asection *));
113 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
116 breakpoints_info PARAMS ((char *, int));
119 breakpoint_1 PARAMS ((int, int));
122 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
124 static int breakpoint_cond_eval PARAMS ((PTR));
127 cleanup_executing_breakpoints PARAMS ((PTR));
130 commands_command PARAMS ((char *, int));
133 condition_command PARAMS ((char *, int));
136 get_number PARAMS ((char **));
139 set_breakpoint_count PARAMS ((int));
142 static struct breakpoint *
143 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
154 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
156 static int print_it_normal PARAMS ((bpstat));
160 enum exception_event_kind kind;
163 args_for_catchpoint_enable;
165 static int watchpoint_check PARAMS ((PTR));
167 static int cover_target_enable_exception_callback PARAMS ((PTR));
169 static int print_it_done PARAMS ((bpstat));
171 static int print_it_noop PARAMS ((bpstat));
173 static void maintenance_info_breakpoints PARAMS ((char *, int));
175 #ifdef GET_LONGJMP_TARGET
176 static void create_longjmp_breakpoint PARAMS ((char *));
179 static int hw_breakpoint_used_count PARAMS ((void));
181 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
183 static void hbreak_command PARAMS ((char *, int));
185 static void thbreak_command PARAMS ((char *, int));
187 static void watch_command_1 PARAMS ((char *, int, int));
189 static void rwatch_command PARAMS ((char *, int));
191 static void awatch_command PARAMS ((char *, int));
193 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
195 static void solib_load_unload_1 PARAMS ((char *hookname,
199 enum bptype bp_kind));
201 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
203 enum bptype bp_kind));
205 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
209 static void break_at_finish_command_1 PARAMS ((char *arg,
213 static void stop_command PARAMS ((char *arg, int from_tty));
215 static void stopin_command PARAMS ((char *arg, int from_tty));
217 static void stopat_command PARAMS ((char *arg, int from_tty));
219 static char *ep_find_event_name_end PARAMS ((char *arg));
221 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
223 static char *ep_parse_optional_filename PARAMS ((char **arg));
225 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
228 static void create_exception_catchpoint
229 PARAMS ((int tempflag, char *cond_string,
230 enum exception_event_kind ex_event,
231 struct symtab_and_line * sal));
233 static void catch_exception_command_1
234 PARAMS ((enum exception_event_kind ex_event,
235 char *arg, int tempflag, int from_tty));
237 static void tcatch_command PARAMS ((char *arg, int from_tty));
239 static void ep_skip_leading_whitespace PARAMS ((char **s));
241 /* Prototypes for exported functions. */
244 awatch_command PARAMS ((char *, int));
247 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
249 /* If FALSE, gdb will not use hardware support for watchpoints, even
250 if such is available. */
251 static int can_use_hw_watchpoints;
253 void delete_command PARAMS ((char *, int));
255 void _initialize_breakpoint PARAMS ((void));
257 void set_breakpoint_count PARAMS ((int));
259 extern int addressprint; /* Print machine addresses? */
261 #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
262 static int internal_breakpoint_number = -1;
265 /* Are we executing breakpoint commands? */
266 static int executing_breakpoint_commands;
268 /* Walk the following statement or block through all breakpoints.
269 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
272 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
274 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
275 for (b = breakpoint_chain; \
276 b? (tmp=b->next, 1): 0; \
279 /* True if SHIFT_INST_REGS defined, false otherwise. */
281 int must_shift_inst_regs =
282 #if defined(SHIFT_INST_REGS)
289 /* True if breakpoint hit counts should be displayed in breakpoint info. */
291 int show_breakpoint_hit_counts = 1;
293 /* Chain of all breakpoints defined. */
295 struct breakpoint *breakpoint_chain;
297 /* Number of last breakpoint made. */
299 int breakpoint_count;
301 /* Pointer to current exception event record */
302 static struct exception_event_record *current_exception_event;
304 /* Indicator of whether exception catchpoints should be nuked
305 between runs of a program */
306 int exception_catchpoints_are_fragile = 0;
308 /* Indicator of when exception catchpoints set-up should be
309 reinitialized -- e.g. when program is re-run */
310 int exception_support_initialized = 0;
312 /* This function returns a pointer to the string representation of the
313 pathname of the dynamically-linked library that has just been
316 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
317 or undefined results are guaranteed.
319 This string's contents are only valid immediately after the
320 inferior has stopped in the dynamic linker hook, and becomes
321 invalid as soon as the inferior is continued. Clients should make
322 a copy of this string if they wish to continue the inferior and
323 then access the string. */
325 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
326 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
329 /* This function returns a pointer to the string representation of the
330 pathname of the dynamically-linked library that has just been
333 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
334 TRUE, or undefined results are guaranteed.
336 This string's contents are only valid immediately after the
337 inferior has stopped in the dynamic linker hook, and becomes
338 invalid as soon as the inferior is continued. Clients should make
339 a copy of this string if they wish to continue the inferior and
340 then access the string. */
342 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
343 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
346 /* This function is called by the "catch load" command. It allows the
347 debugger to be notified by the dynamic linker when a specified
348 library file (or any library file, if filename is NULL) is loaded. */
350 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
351 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
352 error ("catch of library loads not yet implemented on this platform")
355 /* This function is called by the "catch unload" command. It allows
356 the debugger to be notified by the dynamic linker when a specified
357 library file (or any library file, if filename is NULL) is
360 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
361 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
362 error ("catch of library unloads not yet implemented on this platform")
365 /* Set breakpoint count to NUM. */
368 set_breakpoint_count (num)
371 breakpoint_count = num;
372 set_internalvar (lookup_internalvar ("bpnum"),
373 value_from_longest (builtin_type_int, (LONGEST) num));
376 /* Used in run_command to zero the hit count when a new run starts. */
379 clear_breakpoint_hit_counts ()
381 struct breakpoint *b;
387 /* Default address, symtab and line to put a breakpoint at
388 for "break" command with no arg.
389 if default_breakpoint_valid is zero, the other three are
390 not valid, and "break" with no arg is an error.
392 This set by print_stack_frame, which calls set_default_breakpoint. */
394 int default_breakpoint_valid;
395 CORE_ADDR default_breakpoint_address;
396 struct symtab *default_breakpoint_symtab;
397 int default_breakpoint_line;
399 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
400 Advance *PP after the string and any trailing whitespace.
402 Currently the string can either be a number or "$" followed by the name
403 of a convenience variable. Making it an expression wouldn't work well
404 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
413 /* Empty line means refer to the last breakpoint. */
414 return breakpoint_count;
417 /* Make a copy of the name, so we can null-terminate it
418 to pass to lookup_internalvar(). */
423 while (isalnum (*p) || *p == '_')
425 varname = (char *) alloca (p - start + 1);
426 strncpy (varname, start, p - start);
427 varname[p - start] = '\0';
428 val = value_of_internalvar (lookup_internalvar (varname));
429 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
431 "Convenience variables used to specify breakpoints must have integer values."
433 retval = (int) value_as_long (val);
439 while (*p >= '0' && *p <= '9')
442 /* There is no number here. (e.g. "cond a == b"). */
443 error_no_arg ("breakpoint number");
446 if (!(isspace (*p) || *p == '\0'))
447 error ("breakpoint number expected");
454 /* condition N EXP -- set break condition of breakpoint N to EXP. */
457 condition_command (arg, from_tty)
461 register struct breakpoint *b;
466 error_no_arg ("breakpoint number");
469 bnum = get_number (&p);
472 if (b->number == bnum)
476 free ((PTR) b->cond);
479 if (b->cond_string != NULL)
480 free ((PTR) b->cond_string);
485 b->cond_string = NULL;
487 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
492 /* I don't know if it matters whether this is the string the user
493 typed in or the decompiled expression. */
494 b->cond_string = savestring (arg, strlen (arg));
495 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
497 error ("Junk at end of expression");
499 breakpoints_changed ();
503 error ("No breakpoint number %d.", bnum);
508 commands_command (arg, from_tty)
512 register struct breakpoint *b;
515 struct command_line *l;
517 /* If we allowed this, we would have problems with when to
518 free the storage, if we change the commands currently
521 if (executing_breakpoint_commands)
522 error ("Can't use the \"commands\" command among a breakpoint's commands.");
525 bnum = get_number (&p);
527 error ("Unexpected extra arguments following breakpoint number.");
530 if (b->number == bnum)
534 "Type commands for when breakpoint %d is hit, one per line.",
536 l = read_command_lines (tmpbuf, from_tty);
537 free_command_lines (&b->commands);
539 breakpoints_changed ();
542 error ("No breakpoint number %d.", bnum);
545 /* Like target_read_memory() but if breakpoints are inserted, return
546 the shadow contents instead of the breakpoints themselves.
548 Read "memory data" from whatever target or inferior we have.
549 Returns zero if successful, errno value if not. EIO is used
550 for address out of bounds. If breakpoints are inserted, returns
551 shadow contents, not the breakpoints themselves. From breakpoint.c. */
554 read_memory_nobpt (memaddr, myaddr, len)
560 struct breakpoint *b;
561 CORE_ADDR bp_addr = 0;
564 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
565 /* No breakpoints on this machine. */
566 return target_read_memory (memaddr, myaddr, len);
570 if (b->type == bp_none)
571 warning ("reading through apparently deleted breakpoint #%d?",
574 /* memory breakpoint? */
575 if (b->type == bp_watchpoint
576 || b->type == bp_hardware_watchpoint
577 || b->type == bp_read_watchpoint
578 || b->type == bp_access_watchpoint)
583 /* Addresses and length of the part of the breakpoint that
585 /* XXXX The m68k, sh and h8300 have different local and remote
586 breakpoint values. BREAKPOINT_FROM_PC still manages to
587 correctly determine the breakpoints memory address and size
588 for these targets. */
589 bp_addr = b->address;
591 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
596 if (bp_addr + bp_size <= memaddr)
597 /* The breakpoint is entirely before the chunk of memory we
600 if (bp_addr >= memaddr + len)
601 /* The breakpoint is entirely after the chunk of memory we are
604 /* Copy the breakpoint from the shadow contents, and recurse for
605 the things before and after. */
607 /* Offset within shadow_contents. */
610 if (bp_addr < memaddr)
612 /* Only copy the second part of the breakpoint. */
613 bp_size -= memaddr - bp_addr;
614 bptoffset = memaddr - bp_addr;
618 if (bp_addr + bp_size > memaddr + len)
620 /* Only copy the first part of the breakpoint. */
621 bp_size -= (bp_addr + bp_size) - (memaddr + len);
624 memcpy (myaddr + bp_addr - memaddr,
625 b->shadow_contents + bptoffset, bp_size);
627 if (bp_addr > memaddr)
629 /* Copy the section of memory before the breakpoint. */
630 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
635 if (bp_addr + bp_size < memaddr + len)
637 /* Copy the section of memory after the breakpoint. */
638 status = read_memory_nobpt
640 myaddr + bp_addr + bp_size - memaddr,
641 memaddr + len - (bp_addr + bp_size));
648 /* Nothing overlaps. Just call read_memory_noerr. */
649 return target_read_memory (memaddr, myaddr, len);
653 /* insert_breakpoints is used when starting or continuing the program.
654 remove_breakpoints is used when the program stops.
655 Both return zero if successful,
656 or an `errno' value if could not write the inferior. */
659 insert_breakpoints ()
661 register struct breakpoint *b, *temp;
662 int return_val = 0; /* return success code. */
664 int disabled_breaks = 0;
666 static char message1[] = "Error inserting catchpoint %d:\n";
667 static char message[sizeof (message1) + 30];
670 ALL_BREAKPOINTS_SAFE (b, temp)
672 if (b->type != bp_watchpoint
673 && b->type != bp_hardware_watchpoint
674 && b->type != bp_read_watchpoint
675 && b->type != bp_access_watchpoint
676 && b->type != bp_catch_fork
677 && b->type != bp_catch_vfork
678 && b->type != bp_catch_exec
679 && b->type != bp_catch_throw
680 && b->type != bp_catch_catch
681 && b->enable != disabled
682 && b->enable != shlib_disabled
683 && b->enable != call_disabled
687 if (b->type == bp_hardware_breakpoint)
688 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
691 /* Check to see if breakpoint is in an overlay section;
692 if so, we should set the breakpoint at the LMA address.
693 Only if the section is currently mapped should we ALSO
694 set a break at the VMA address. */
695 if (overlay_debugging && b->section &&
696 section_is_overlay (b->section))
700 addr = overlay_unmapped_address (b->address, b->section);
701 val = target_insert_breakpoint (addr, b->shadow_contents);
702 /* This would be the time to check val, to see if the
703 breakpoint write to the load address succeeded.
704 However, this might be an ordinary occurrance, eg. if
705 the unmapped overlay is in ROM. */
706 val = 0; /* in case unmapped address failed */
707 if (section_is_mapped (b->section))
708 val = target_insert_breakpoint (b->address,
711 else /* ordinary (non-overlay) address */
712 val = target_insert_breakpoint (b->address, b->shadow_contents);
716 /* Can't set the breakpoint. */
717 #if defined (DISABLE_UNSETTABLE_BREAK)
718 if (DISABLE_UNSETTABLE_BREAK (b->address))
720 /* See also: disable_breakpoints_in_shlibs. */
722 b->enable = shlib_disabled;
723 if (!disabled_breaks)
725 target_terminal_ours_for_output ();
726 warning ("Cannot insert breakpoint %d:", b->number);
727 warning ("Temporarily disabling shared library breakpoints:");
730 warning ("breakpoint #%d ", b->number);
735 target_terminal_ours_for_output ();
736 warning ("Cannot insert breakpoint %d:", b->number);
737 #ifdef ONE_PROCESS_WRITETEXT
738 warning ("The same program may be running in another process.");
740 memory_error (val, b->address); /* which bombs us out */
747 return_val = val; /* remember failure */
749 else if (ep_is_exception_catchpoint (b)
750 && b->enable != disabled
751 && b->enable != shlib_disabled
752 && b->enable != call_disabled
757 /* If we get here, we must have a callback mechanism for exception
758 events -- with g++ style embedded label support, we insert
759 ordinary breakpoints and not catchpoints. */
760 /* Format possible error message */
761 sprintf (message, message1, b->number);
763 val = target_insert_breakpoint (b->address, b->shadow_contents);
766 /* Couldn't set breakpoint for some reason */
767 target_terminal_ours_for_output ();
768 warning ("Cannot insert catchpoint %d; disabling it.",
770 b->enable = disabled;
774 /* Bp set, now make sure callbacks are enabled */
776 args_for_catchpoint_enable args;
777 args.kind = b->type == bp_catch_catch ?
778 EX_EVENT_CATCH : EX_EVENT_THROW;
780 val = catch_errors (cover_target_enable_exception_callback,
782 message, RETURN_MASK_ALL);
783 if (val != 0 && val != -1)
787 /* Check if something went wrong; val == 0 can be ignored */
790 /* something went wrong */
791 target_terminal_ours_for_output ();
792 warning ("Cannot insert catchpoint %d; disabling it.",
794 b->enable = disabled;
799 return_val = val; /* remember failure */
802 else if ((b->type == bp_hardware_watchpoint ||
803 b->type == bp_read_watchpoint ||
804 b->type == bp_access_watchpoint)
805 && b->enable == enabled
809 struct frame_info *saved_frame;
810 int saved_level, within_current_scope;
811 value_ptr mark = value_mark ();
814 /* Save the current frame and level so we can restore it after
815 evaluating the watchpoint expression on its own frame. */
816 saved_frame = selected_frame;
817 saved_level = selected_frame_level;
819 /* Determine if the watchpoint is within scope. */
820 if (b->exp_valid_block == NULL)
821 within_current_scope = 1;
824 struct frame_info *fi;
826 /* There might be no current frame at this moment if we are
827 resuming from a step over a breakpoint.
828 Set up current frame before trying to find the watchpoint
830 get_current_frame ();
831 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
832 within_current_scope = (fi != NULL);
833 if (within_current_scope)
834 select_frame (fi, -1);
837 if (within_current_scope)
839 /* Evaluate the expression and cut the chain of values
840 produced off from the value chain. */
841 v = evaluate_expression (b->exp);
842 value_release_to_mark (mark);
847 /* Look at each value on the value chain. */
848 for (; v; v = v->next)
850 /* If it's a memory location, then we must watch it. */
851 if (v->lval == lval_memory)
855 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
856 len = TYPE_LENGTH (VALUE_TYPE (v));
858 if (b->type == bp_read_watchpoint)
860 else if (b->type == bp_access_watchpoint)
863 val = target_insert_watchpoint (addr, len, type);
872 /* Failure to insert a watchpoint on any memory value in the
873 value chain brings us here. */
876 remove_breakpoint (b, mark_uninserted);
877 warning ("Could not insert hardware watchpoint %d.",
884 printf_filtered ("Hardware watchpoint %d deleted", b->number);
885 printf_filtered ("because the program has left the block \n");
886 printf_filtered ("in which its expression is valid.\n");
887 if (b->related_breakpoint)
888 b->related_breakpoint->disposition = del_at_next_stop;
889 b->disposition = del_at_next_stop;
892 /* Restore the frame and level. */
893 if ((saved_frame != selected_frame) ||
894 (saved_level != selected_frame_level))
895 select_and_print_frame (saved_frame, saved_level);
898 return_val = val; /* remember failure */
900 else if ((b->type == bp_catch_fork
901 || b->type == bp_catch_vfork
902 || b->type == bp_catch_exec)
903 && b->enable == enabled
911 val = target_insert_fork_catchpoint (inferior_pid);
914 val = target_insert_vfork_catchpoint (inferior_pid);
917 val = target_insert_exec_catchpoint (inferior_pid);
920 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
925 target_terminal_ours_for_output ();
926 warning ("Cannot insert catchpoint %d.", b->number);
932 return_val = val; /* remember failure */
941 remove_breakpoints ()
943 register struct breakpoint *b;
950 val = remove_breakpoint (b, mark_uninserted);
959 reattach_breakpoints (pid)
962 register struct breakpoint *b;
964 int saved_inferior_pid = inferior_pid;
966 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
967 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
972 remove_breakpoint (b, mark_inserted);
973 if (b->type == bp_hardware_breakpoint)
974 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
976 val = target_insert_breakpoint (b->address, b->shadow_contents);
979 inferior_pid = saved_inferior_pid;
984 inferior_pid = saved_inferior_pid;
989 update_breakpoints_after_exec ()
991 struct breakpoint *b;
992 struct breakpoint *temp;
994 /* Doing this first prevents the badness of having delete_breakpoint()
995 write a breakpoint's current "shadow contents" to lift the bp. That
996 shadow is NOT valid after an exec()! */
997 mark_breakpoints_out ();
999 ALL_BREAKPOINTS_SAFE (b, temp)
1001 /* Solib breakpoints must be explicitly reset after an exec(). */
1002 if (b->type == bp_shlib_event)
1004 delete_breakpoint (b);
1008 /* Step-resume breakpoints are meaningless after an exec(). */
1009 if (b->type == bp_step_resume)
1011 delete_breakpoint (b);
1015 /* Ditto the sigtramp handler breakpoints. */
1016 if (b->type == bp_through_sigtramp)
1018 delete_breakpoint (b);
1022 /* Ditto the exception-handling catchpoints. */
1023 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1025 delete_breakpoint (b);
1029 /* Don't delete an exec catchpoint, because else the inferior
1030 won't stop when it ought!
1032 Similarly, we probably ought to keep vfork catchpoints, 'cause
1033 on this target, we may not be able to stop when the vfork is
1034 seen, but only when the subsequent exec is seen. (And because
1035 deleting fork catchpoints here but not vfork catchpoints will
1036 seem mysterious to users, keep those too.)
1038 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1039 target address field, if any, is sufficient to have it be reset
1040 automagically. Certainly on HP-UX that's true. */
1041 if ((b->type == bp_catch_exec) ||
1042 (b->type == bp_catch_vfork) ||
1043 (b->type == bp_catch_fork))
1045 b->address = (CORE_ADDR) NULL;
1049 /* bp_finish is a special case. The only way we ought to be able
1050 to see one of these when an exec() has happened, is if the user
1051 caught a vfork, and then said "finish". Ordinarily a finish just
1052 carries them to the call-site of the current callee, by setting
1053 a temporary bp there and resuming. But in this case, the finish
1054 will carry them entirely through the vfork & exec.
1056 We don't want to allow a bp_finish to remain inserted now. But
1057 we can't safely delete it, 'cause finish_command has a handle to
1058 the bp on a bpstat, and will later want to delete it. There's a
1059 chance (and I've seen it happen) that if we delete the bp_finish
1060 here, that its storage will get reused by the time finish_command
1061 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1062 We really must allow finish_command to delete a bp_finish.
1064 In the absense of a general solution for the "how do we know
1065 it's safe to delete something others may have handles to?"
1066 problem, what we'll do here is just uninsert the bp_finish, and
1067 let finish_command delete it.
1069 (We know the bp_finish is "doomed" in the sense that it's
1070 momentary, and will be deleted as soon as finish_command sees
1071 the inferior stopped. So it doesn't matter that the bp's
1072 address is probably bogus in the new a.out, unlike e.g., the
1073 solib breakpoints.) */
1075 if (b->type == bp_finish)
1080 /* Without a symbolic address, we have little hope of the
1081 pre-exec() address meaning the same thing in the post-exec()
1083 if (b->addr_string == NULL)
1085 delete_breakpoint (b);
1089 /* If this breakpoint has survived the above battery of checks, then
1090 it must have a symbolic address. Be sure that it gets reevaluated
1091 to a target address, rather than reusing the old evaluation. */
1092 b->address = (CORE_ADDR) NULL;
1097 detach_breakpoints (pid)
1100 register struct breakpoint *b;
1102 int saved_inferior_pid = inferior_pid;
1104 if (pid == inferior_pid)
1105 error ("Cannot detach breakpoints of inferior_pid");
1107 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1108 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1113 val = remove_breakpoint (b, mark_inserted);
1116 inferior_pid = saved_inferior_pid;
1121 inferior_pid = saved_inferior_pid;
1126 remove_breakpoint (b, is)
1127 struct breakpoint *b;
1128 insertion_state_t is;
1132 if (b->type == bp_none)
1133 warning ("attempted to remove apparently deleted breakpoint #%d?",
1136 if (b->type != bp_watchpoint
1137 && b->type != bp_hardware_watchpoint
1138 && b->type != bp_read_watchpoint
1139 && b->type != bp_access_watchpoint
1140 && b->type != bp_catch_fork
1141 && b->type != bp_catch_vfork
1142 && b->type != bp_catch_exec
1143 && b->type != bp_catch_catch
1144 && b->type != bp_catch_throw)
1147 if (b->type == bp_hardware_breakpoint)
1148 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1151 /* Check to see if breakpoint is in an overlay section;
1152 if so, we should remove the breakpoint at the LMA address.
1153 If that is not equal to the raw address, then we should
1154 presumable remove the breakpoint there as well. */
1155 if (overlay_debugging && b->section &&
1156 section_is_overlay (b->section))
1160 addr = overlay_unmapped_address (b->address, b->section);
1161 val = target_remove_breakpoint (addr, b->shadow_contents);
1162 /* This would be the time to check val, to see if the
1163 shadow breakpoint write to the load address succeeded.
1164 However, this might be an ordinary occurrance, eg. if
1165 the unmapped overlay is in ROM. */
1166 val = 0; /* in case unmapped address failed */
1167 if (section_is_mapped (b->section))
1168 val = target_remove_breakpoint (b->address,
1169 b->shadow_contents);
1171 else /* ordinary (non-overlay) address */
1172 val = target_remove_breakpoint (b->address, b->shadow_contents);
1176 b->inserted = (is == mark_inserted);
1178 else if ((b->type == bp_hardware_watchpoint ||
1179 b->type == bp_read_watchpoint ||
1180 b->type == bp_access_watchpoint)
1181 && b->enable == enabled
1186 b->inserted = (is == mark_inserted);
1187 /* Walk down the saved value chain. */
1188 for (v = b->val_chain; v; v = v->next)
1190 /* For each memory reference remove the watchpoint
1192 if (v->lval == lval_memory)
1194 int addr, len, type;
1196 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1197 len = TYPE_LENGTH (VALUE_TYPE (v));
1199 if (b->type == bp_read_watchpoint)
1201 else if (b->type == bp_access_watchpoint)
1204 val = target_remove_watchpoint (addr, len, type);
1210 /* Failure to remove any of the hardware watchpoints comes here. */
1211 if ((is == mark_uninserted) && (b->inserted))
1212 warning ("Could not remove hardware watchpoint %d.",
1215 /* Free the saved value chain. We will construct a new one
1216 the next time the watchpoint is inserted. */
1217 for (v = b->val_chain; v; v = n)
1222 b->val_chain = NULL;
1224 else if ((b->type == bp_catch_fork ||
1225 b->type == bp_catch_vfork ||
1226 b->type == bp_catch_exec)
1227 && b->enable == enabled
1234 val = target_remove_fork_catchpoint (inferior_pid);
1236 case bp_catch_vfork:
1237 val = target_remove_vfork_catchpoint (inferior_pid);
1240 val = target_remove_exec_catchpoint (inferior_pid);
1243 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1248 b->inserted = (is == mark_inserted);
1250 else if ((b->type == bp_catch_catch ||
1251 b->type == bp_catch_throw)
1252 && b->enable == enabled
1256 val = target_remove_breakpoint (b->address, b->shadow_contents);
1259 b->inserted = (is == mark_inserted);
1261 else if (ep_is_exception_catchpoint (b)
1262 && b->inserted /* sometimes previous insert doesn't happen */
1263 && b->enable == enabled
1267 val = target_remove_breakpoint (b->address, b->shadow_contents);
1271 b->inserted = (is == mark_inserted);
1277 /* Clear the "inserted" flag in all breakpoints. */
1280 mark_breakpoints_out ()
1282 register struct breakpoint *b;
1288 /* Clear the "inserted" flag in all breakpoints and delete any
1289 breakpoints which should go away between runs of the program.
1291 Plus other such housekeeping that has to be done for breakpoints
1294 Note: this function gets called at the end of a run (by
1295 generic_mourn_inferior) and when a run begins (by
1296 init_wait_for_inferior). */
1301 breakpoint_init_inferior (context)
1302 enum inf_context context;
1304 register struct breakpoint *b, *temp;
1305 static int warning_needed = 0;
1307 ALL_BREAKPOINTS_SAFE (b, temp)
1314 case bp_watchpoint_scope:
1316 /* If the call dummy breakpoint is at the entry point it will
1317 cause problems when the inferior is rerun, so we better
1320 Also get rid of scope breakpoints. */
1321 delete_breakpoint (b);
1325 case bp_hardware_watchpoint:
1326 case bp_read_watchpoint:
1327 case bp_access_watchpoint:
1329 /* Likewise for watchpoints on local expressions. */
1330 if (b->exp_valid_block != NULL)
1331 delete_breakpoint (b);
1334 /* Likewise for exception catchpoints in dynamic-linked
1335 executables where required */
1336 if (ep_is_exception_catchpoint (b) &&
1337 exception_catchpoints_are_fragile)
1340 delete_breakpoint (b);
1346 if (exception_catchpoints_are_fragile)
1347 exception_support_initialized = 0;
1349 /* Don't issue the warning unless it's really needed... */
1350 if (warning_needed && (context != inf_exited))
1352 warning ("Exception catchpoints from last run were deleted.");
1353 warning ("You must reinsert them explicitly.");
1358 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at
1359 PC. When continuing from a location with a breakpoint, we actually
1360 single step once before calling insert_breakpoints. */
1363 breakpoint_here_p (pc)
1366 register struct breakpoint *b;
1369 if (b->enable == enabled
1370 && b->enable != shlib_disabled
1371 && b->enable != call_disabled
1372 && b->address == pc) /* bp is enabled and matches pc */
1374 if (overlay_debugging &&
1375 section_is_overlay (b->section) &&
1376 !section_is_mapped (b->section))
1377 continue; /* unmapped overlay -- can't be a match */
1385 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1386 but it only returns true if there is actually a breakpoint inserted
1390 breakpoint_inserted_here_p (pc)
1393 register struct breakpoint *b;
1397 && b->address == pc) /* bp is inserted and matches pc */
1399 if (overlay_debugging &&
1400 section_is_overlay (b->section) &&
1401 !section_is_mapped (b->section))
1402 continue; /* unmapped overlay -- can't be a match */
1410 /* Return nonzero if FRAME is a dummy frame. We can't use
1411 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1412 much time, at least using get_saved_register on the 68k. This
1413 means that for this function to work right a port must use the
1414 bp_call_dummy breakpoint. */
1417 frame_in_dummy (frame)
1418 struct frame_info *frame;
1420 struct breakpoint *b;
1425 if (USE_GENERIC_DUMMY_FRAMES)
1426 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1430 if (b->type == bp_call_dummy
1431 && b->frame == frame->frame
1432 /* We need to check the PC as well as the frame on the sparc,
1433 for signals.exp in the testsuite. */
1436 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1437 && frame->pc <= b->address)
1443 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1444 is valid for process/thread PID. */
1447 breakpoint_thread_match (pc, pid)
1451 struct breakpoint *b;
1454 thread = pid_to_thread_id (pid);
1457 if (b->enable != disabled
1458 && b->enable != shlib_disabled
1459 && b->enable != call_disabled
1461 && (b->thread == -1 || b->thread == thread))
1463 if (overlay_debugging &&
1464 section_is_overlay (b->section) &&
1465 !section_is_mapped (b->section))
1466 continue; /* unmapped overlay -- can't be a match */
1475 /* bpstat stuff. External routines' interfaces are documented
1479 ep_is_catchpoint (ep)
1480 struct breakpoint *ep;
1483 (ep->type == bp_catch_load)
1484 || (ep->type == bp_catch_unload)
1485 || (ep->type == bp_catch_fork)
1486 || (ep->type == bp_catch_vfork)
1487 || (ep->type == bp_catch_exec)
1488 || (ep->type == bp_catch_catch)
1489 || (ep->type == bp_catch_throw)
1492 /* ??rehrauer: Add more kinds here, as are implemented... */
1497 ep_is_shlib_catchpoint (ep)
1498 struct breakpoint *ep;
1501 (ep->type == bp_catch_load)
1502 || (ep->type == bp_catch_unload)
1507 ep_is_exception_catchpoint (ep)
1508 struct breakpoint *ep;
1511 (ep->type == bp_catch_catch)
1512 || (ep->type == bp_catch_throw)
1516 /* Clear a bpstat so that it says we are not at any breakpoint.
1517 Also free any storage that is part of a bpstat. */
1532 if (p->old_val != NULL)
1533 value_free (p->old_val);
1540 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1541 is part of the bpstat is copied as well. */
1549 bpstat retval = NULL;
1554 for (; bs != NULL; bs = bs->next)
1556 tmp = (bpstat) xmalloc (sizeof (*tmp));
1557 memcpy (tmp, bs, sizeof (*tmp));
1559 /* This is the first thing in the chain. */
1569 /* Find the bpstat associated with this breakpoint */
1572 bpstat_find_breakpoint (bsp, breakpoint)
1574 struct breakpoint *breakpoint;
1579 for (; bsp != NULL; bsp = bsp->next)
1581 if (bsp->breakpoint_at == breakpoint)
1587 /* Find a step_resume breakpoint associated with this bpstat.
1588 (If there are multiple step_resume bp's on the list, this function
1589 will arbitrarily pick one.)
1591 It is an error to use this function if BPSTAT doesn't contain a
1592 step_resume breakpoint.
1594 See wait_for_inferior's use of this function. */
1596 bpstat_find_step_resume_breakpoint (bsp)
1600 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1602 for (; bsp != NULL; bsp = bsp->next)
1604 if ((bsp->breakpoint_at != NULL) &&
1605 (bsp->breakpoint_at->type == bp_step_resume))
1606 return bsp->breakpoint_at;
1609 error ("Internal error (no step_resume breakpoint found)");
1613 /* Return the breakpoint number of the first breakpoint we are stopped
1614 at. *BSP upon return is a bpstat which points to the remaining
1615 breakpoints stopped at (but which is not guaranteed to be good for
1616 anything but further calls to bpstat_num).
1617 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1623 struct breakpoint *b;
1626 return 0; /* No more breakpoint values */
1629 b = (*bsp)->breakpoint_at;
1630 *bsp = (*bsp)->next;
1632 return -1; /* breakpoint that's been deleted since */
1634 return b->number; /* We have its number */
1638 /* Modify BS so that the actions will not be performed. */
1641 bpstat_clear_actions (bs)
1644 for (; bs != NULL; bs = bs->next)
1646 bs->commands = NULL;
1647 if (bs->old_val != NULL)
1649 value_free (bs->old_val);
1655 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1658 cleanup_executing_breakpoints (ignore)
1661 executing_breakpoint_commands = 0;
1664 /* Execute all the commands associated with all the breakpoints at this
1665 location. Any of these commands could cause the process to proceed
1666 beyond this point, etc. We look out for such changes by checking
1667 the global "breakpoint_proceeded" after each command. */
1670 bpstat_do_actions (bsp)
1674 struct cleanup *old_chain;
1675 struct command_line *cmd;
1677 /* Avoid endless recursion if a `source' command is contained
1679 if (executing_breakpoint_commands)
1682 executing_breakpoint_commands = 1;
1683 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1686 /* Note that (as of this writing), our callers all appear to
1687 be passing us the address of global stop_bpstat. And, if
1688 our calls to execute_control_command cause the inferior to
1689 proceed, that global (and hence, *bsp) will change.
1691 We must be careful to not touch *bsp unless the inferior
1692 has not proceeded. */
1694 /* This pointer will iterate over the list of bpstat's. */
1697 breakpoint_proceeded = 0;
1698 for (; bs != NULL; bs = bs->next)
1703 execute_control_command (cmd);
1705 if (breakpoint_proceeded)
1710 if (breakpoint_proceeded)
1711 /* The inferior is proceeded by the command; bomb out now.
1712 The bpstat chain has been blown away by wait_for_inferior.
1713 But since execution has stopped again, there is a new bpstat
1714 to look at, so start over. */
1717 bs->commands = NULL;
1720 executing_breakpoint_commands = 0;
1721 discard_cleanups (old_chain);
1724 /* This is the normal print_it function for a bpstat. In the future,
1725 much of this logic could (should?) be moved to bpstat_stop_status,
1726 by having it set different print_it functions.
1728 Current scheme: When we stop, bpstat_print() is called.
1729 It loops through the bpstat list of things causing this stop,
1730 calling the print_it function for each one. The default
1731 print_it function, used for breakpoints, is print_it_normal().
1732 (Also see print_it_noop() and print_it_done()).
1734 Return values from this routine (used by bpstat_print() to
1736 1: Means we printed something, and we do *not* desire that
1737 something to be followed by a location.
1738 0: Means we printed something, and we *do* desire that
1739 something to be followed by a location.
1740 -1: Means we printed nothing. */
1743 print_it_normal (bs)
1746 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1747 which has since been deleted. */
1748 if (bs->breakpoint_at == NULL
1749 || (bs->breakpoint_at->type != bp_breakpoint
1750 && bs->breakpoint_at->type != bp_catch_load
1751 && bs->breakpoint_at->type != bp_catch_unload
1752 && bs->breakpoint_at->type != bp_catch_fork
1753 && bs->breakpoint_at->type != bp_catch_vfork
1754 && bs->breakpoint_at->type != bp_catch_exec
1755 && bs->breakpoint_at->type != bp_catch_catch
1756 && bs->breakpoint_at->type != bp_catch_throw
1757 && bs->breakpoint_at->type != bp_hardware_breakpoint
1758 && bs->breakpoint_at->type != bp_watchpoint
1759 && bs->breakpoint_at->type != bp_read_watchpoint
1760 && bs->breakpoint_at->type != bp_access_watchpoint
1761 && bs->breakpoint_at->type != bp_hardware_watchpoint))
1764 if (ep_is_shlib_catchpoint (bs->breakpoint_at))
1766 annotate_catchpoint (bs->breakpoint_at->number);
1767 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1768 if (bs->breakpoint_at->type == bp_catch_load)
1769 printf_filtered ("loaded");
1770 else if (bs->breakpoint_at->type == bp_catch_unload)
1771 printf_filtered ("unloaded");
1772 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1775 else if (bs->breakpoint_at->type == bp_catch_fork ||
1776 bs->breakpoint_at->type == bp_catch_vfork)
1778 annotate_catchpoint (bs->breakpoint_at->number);
1779 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1780 if (bs->breakpoint_at->type == bp_catch_fork)
1781 printf_filtered ("forked");
1782 else if (bs->breakpoint_at->type == bp_catch_vfork)
1783 printf_filtered ("vforked");
1784 printf_filtered (" process %d), ",
1785 bs->breakpoint_at->forked_inferior_pid);
1788 else if (bs->breakpoint_at->type == bp_catch_exec)
1790 annotate_catchpoint (bs->breakpoint_at->number);
1791 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1792 bs->breakpoint_at->number,
1793 bs->breakpoint_at->exec_pathname);
1796 else if (bs->breakpoint_at->type == bp_catch_catch)
1798 if (current_exception_event &&
1799 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1801 annotate_catchpoint (bs->breakpoint_at->number);
1802 printf_filtered ("\nCatchpoint %d (exception caught), ",
1803 bs->breakpoint_at->number);
1804 printf_filtered ("throw location ");
1805 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1806 printf_filtered ("%s:%d",
1807 CURRENT_EXCEPTION_THROW_FILE,
1808 CURRENT_EXCEPTION_THROW_LINE);
1810 printf_filtered ("unknown");
1812 printf_filtered (", catch location ");
1813 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1814 printf_filtered ("%s:%d",
1815 CURRENT_EXCEPTION_CATCH_FILE,
1816 CURRENT_EXCEPTION_CATCH_LINE);
1818 printf_filtered ("unknown");
1820 printf_filtered ("\n");
1821 return 1; /* don't bother to print location frame info */
1825 return -1; /* really throw, some other bpstat will handle it */
1828 else if (bs->breakpoint_at->type == bp_catch_throw)
1830 if (current_exception_event &&
1831 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1833 annotate_catchpoint (bs->breakpoint_at->number);
1834 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1835 bs->breakpoint_at->number);
1836 printf_filtered ("throw location ");
1837 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1838 printf_filtered ("%s:%d",
1839 CURRENT_EXCEPTION_THROW_FILE,
1840 CURRENT_EXCEPTION_THROW_LINE);
1842 printf_filtered ("unknown");
1844 printf_filtered (", catch location ");
1845 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1846 printf_filtered ("%s:%d",
1847 CURRENT_EXCEPTION_CATCH_FILE,
1848 CURRENT_EXCEPTION_CATCH_LINE);
1850 printf_filtered ("unknown");
1852 printf_filtered ("\n");
1853 return 1; /* don't bother to print location frame info */
1857 return -1; /* really catch, some other bpstat willhandle it */
1861 else if (bs->breakpoint_at->type == bp_breakpoint ||
1862 bs->breakpoint_at->type == bp_hardware_breakpoint)
1864 /* I think the user probably only wants to see one breakpoint
1865 number, not all of them. */
1866 annotate_breakpoint (bs->breakpoint_at->number);
1867 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1870 else if ((bs->old_val != NULL) &&
1871 (bs->breakpoint_at->type == bp_watchpoint ||
1872 bs->breakpoint_at->type == bp_access_watchpoint ||
1873 bs->breakpoint_at->type == bp_hardware_watchpoint))
1875 annotate_watchpoint (bs->breakpoint_at->number);
1876 mention (bs->breakpoint_at);
1877 printf_filtered ("\nOld value = ");
1878 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
1879 printf_filtered ("\nNew value = ");
1880 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1881 Val_pretty_default);
1882 printf_filtered ("\n");
1883 value_free (bs->old_val);
1885 /* More than one watchpoint may have been triggered. */
1888 else if (bs->breakpoint_at->type == bp_access_watchpoint ||
1889 bs->breakpoint_at->type == bp_read_watchpoint)
1891 mention (bs->breakpoint_at);
1892 printf_filtered ("\nValue = ");
1893 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1894 Val_pretty_default);
1895 printf_filtered ("\n");
1898 /* We can't deal with it.
1899 Maybe another member of the bpstat chain can. */
1903 /* Print a message indicating what happened.
1904 This is called from normal_stop().
1905 The input to this routine is the head of the bpstat list - a list
1906 of the eventpoints that caused this stop.
1907 This routine calls the "print_it" routine(s) associated
1908 with these eventpoints. This will print (for example)
1909 the "Breakpoint n," part of the output.
1910 The return value of this routine is one of:
1912 -1: Means we printed nothing
1913 0: Means we printed something, and expect subsequent
1914 code to print the location. An example is
1915 "Breakpoint 1, " which should be followed by
1917 1 : Means we printed something, but there is no need
1918 to also print the location part of the message.
1919 An example is the catch/throw messages, which
1920 don't require a location appended to the end. */
1931 val = (*bs->print_it) (bs);
1935 /* Maybe another breakpoint in the chain caused us to stop.
1936 (Currently all watchpoints go on the bpstat whether hit or not.
1937 That probably could (should) be changed, provided care is taken
1938 with respect to bpstat_explains_signal). */
1940 return bpstat_print (bs->next);
1942 /* We reached the end of the chain without printing anything. */
1946 /* Evaluate the expression EXP and return 1 if value is zero.
1947 This is used inside a catch_errors to evaluate the breakpoint condition.
1948 The argument is a "struct expression *" that has been cast to char * to
1949 make it pass through catch_errors. */
1952 breakpoint_cond_eval (exp)
1955 value_ptr mark = value_mark ();
1956 int i = !value_true (evaluate_expression ((struct expression *) exp));
1957 value_free_to_mark (mark);
1961 /* Allocate a new bpstat and chain it to the current one. */
1964 bpstat_alloc (b, cbs)
1965 register struct breakpoint *b;
1966 bpstat cbs; /* Current "bs" value */
1970 bs = (bpstat) xmalloc (sizeof (*bs));
1972 bs->breakpoint_at = b;
1973 /* If the condition is false, etc., don't do the commands. */
1974 bs->commands = NULL;
1976 bs->print_it = print_it_normal;
1980 /* Possible return values for watchpoint_check (this can't be an enum
1981 because of check_errors). */
1982 /* The watchpoint has been deleted. */
1983 #define WP_DELETED 1
1984 /* The value has changed. */
1985 #define WP_VALUE_CHANGED 2
1986 /* The value has not changed. */
1987 #define WP_VALUE_NOT_CHANGED 3
1989 #define BP_TEMPFLAG 1
1990 #define BP_HARDWAREFLAG 2
1992 /* Check watchpoint condition. */
1995 watchpoint_check (p)
1998 bpstat bs = (bpstat) p;
1999 struct breakpoint *b;
2000 struct frame_info *fr;
2001 int within_current_scope;
2003 b = bs->breakpoint_at;
2005 if (b->exp_valid_block == NULL)
2006 within_current_scope = 1;
2009 /* There is no current frame at this moment. If we're going to have
2010 any chance of handling watchpoints on local variables, we'll need
2011 the frame chain (so we can determine if we're in scope). */
2012 reinit_frame_cache ();
2013 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2014 within_current_scope = (fr != NULL);
2015 if (within_current_scope)
2016 /* If we end up stopping, the current frame will get selected
2017 in normal_stop. So this call to select_frame won't affect
2019 select_frame (fr, -1);
2022 if (within_current_scope)
2024 /* We use value_{,free_to_}mark because it could be a
2025 *long* time before we return to the command level and
2026 call free_all_values. We can't call free_all_values because
2027 we might be in the middle of evaluating a function call. */
2029 value_ptr mark = value_mark ();
2030 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2031 if (!value_equal (b->val, new_val))
2033 release_value (new_val);
2034 value_free_to_mark (mark);
2035 bs->old_val = b->val;
2037 /* We will stop here */
2038 return WP_VALUE_CHANGED;
2042 /* Nothing changed, don't do anything. */
2043 value_free_to_mark (mark);
2044 /* We won't stop here */
2045 return WP_VALUE_NOT_CHANGED;
2050 /* This seems like the only logical thing to do because
2051 if we temporarily ignored the watchpoint, then when
2052 we reenter the block in which it is valid it contains
2053 garbage (in the case of a function, it may have two
2054 garbage values, one before and one after the prologue).
2055 So we can't even detect the first assignment to it and
2056 watch after that (since the garbage may or may not equal
2057 the first value assigned). */
2059 Watchpoint %d deleted because the program has left the block in\n\
2060 which its expression is valid.\n", bs->breakpoint_at->number);
2061 if (b->related_breakpoint)
2062 b->related_breakpoint->disposition = del_at_next_stop;
2063 b->disposition = del_at_next_stop;
2069 /* This is used when everything which needs to be printed has
2070 already been printed. But we still want to print the frame. */
2072 /* Background: When we stop, bpstat_print() is called.
2073 It loops through the bpstat list of things causing this stop,
2074 calling the print_it function for each one. The default
2075 print_it function, used for breakpoints, is print_it_normal().
2076 Also see print_it_noop() and print_it_done() are the other
2077 two possibilities. See comments in bpstat_print() and
2078 in header of print_it_normal() for more detail. */
2087 /* This is used when nothing should be printed for this bpstat entry. */
2088 /* Background: When we stop, bpstat_print() is called.
2089 It loops through the bpstat list of things causing this stop,
2090 calling the print_it function for each one. The default
2091 print_it function, used for breakpoints, is print_it_normal().
2092 Also see print_it_noop() and print_it_done() are the other
2093 two possibilities. See comments in bpstat_print() and
2094 in header of print_it_normal() for more detail. */
2103 /* Get a bpstat associated with having just stopped at address *PC
2104 and frame address CORE_ADDRESS. Update *PC to point at the
2105 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2106 if this is known to not be a real breakpoint (it could still be a
2107 watchpoint, though). */
2109 /* Determine whether we stopped at a breakpoint, etc, or whether we
2110 don't understand this stop. Result is a chain of bpstat's such that:
2112 if we don't understand the stop, the result is a null pointer.
2114 if we understand why we stopped, the result is not null.
2116 Each element of the chain refers to a particular breakpoint or
2117 watchpoint at which we have stopped. (We may have stopped for
2118 several reasons concurrently.)
2120 Each element of the chain has valid next, breakpoint_at,
2121 commands, FIXME??? fields. */
2124 bpstat_stop_status (pc, not_a_breakpoint)
2126 int not_a_breakpoint;
2128 register struct breakpoint *b, *temp;
2130 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2131 int real_breakpoint = 0;
2132 /* Root of the chain of bpstat's */
2133 struct bpstats root_bs[1];
2134 /* Pointer to the last thing in the chain currently. */
2135 bpstat bs = root_bs;
2136 static char message1[] =
2137 "Error evaluating expression for watchpoint %d\n";
2138 char message[sizeof (message1) + 30 /* slop */ ];
2140 /* Get the address where the breakpoint would have been. */
2141 bp_addr = *pc - DECR_PC_AFTER_BREAK;
2143 ALL_BREAKPOINTS_SAFE (b, temp)
2145 if (b->enable == disabled
2146 || b->enable == shlib_disabled
2147 || b->enable == call_disabled)
2150 if (b->type != bp_watchpoint
2151 && b->type != bp_hardware_watchpoint
2152 && b->type != bp_read_watchpoint
2153 && b->type != bp_access_watchpoint
2154 && b->type != bp_hardware_breakpoint
2155 && b->type != bp_catch_fork
2156 && b->type != bp_catch_vfork
2157 && b->type != bp_catch_exec
2158 && b->type != bp_catch_catch
2159 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2160 if (b->address != bp_addr || /* address doesn't match or */
2161 (overlay_debugging && /* overlay doesn't match */
2162 section_is_overlay (b->section) &&
2163 !section_is_mapped (b->section)))
2166 if (b->type == bp_hardware_breakpoint
2167 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2170 if (b->type != bp_watchpoint
2171 && b->type != bp_hardware_watchpoint
2172 && b->type != bp_read_watchpoint
2173 && b->type != bp_access_watchpoint
2174 && not_a_breakpoint)
2177 /* Is this a catchpoint of a load or unload? If so, did we
2178 get a load or unload of the specified library? If not,
2180 if ((b->type == bp_catch_load)
2181 #if defined(SOLIB_HAVE_LOAD_EVENT)
2182 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2183 || ((b->dll_pathname != NULL)
2184 && (strcmp (b->dll_pathname,
2185 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2191 if ((b->type == bp_catch_unload)
2192 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2193 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2194 || ((b->dll_pathname != NULL)
2195 && (strcmp (b->dll_pathname,
2196 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2202 if ((b->type == bp_catch_fork)
2203 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2206 if ((b->type == bp_catch_vfork)
2207 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2210 if ((b->type == bp_catch_exec)
2211 && !target_has_execd (inferior_pid, &b->exec_pathname))
2214 if (ep_is_exception_catchpoint (b) &&
2215 !(current_exception_event = target_get_current_exception_event ()))
2218 /* Come here if it's a watchpoint, or if the break address matches */
2220 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2222 /* Watchpoints may change this, if not found to have triggered. */
2226 sprintf (message, message1, b->number);
2227 if (b->type == bp_watchpoint ||
2228 b->type == bp_hardware_watchpoint)
2230 switch (catch_errors (watchpoint_check, bs, message,
2234 /* We've already printed what needs to be printed. */
2235 bs->print_it = print_it_done;
2238 case WP_VALUE_CHANGED:
2242 case WP_VALUE_NOT_CHANGED:
2244 bs->print_it = print_it_noop;
2246 /* Don't consider this a hit. */
2253 /* Error from catch_errors. */
2254 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2255 if (b->related_breakpoint)
2256 b->related_breakpoint->disposition = del_at_next_stop;
2257 b->disposition = del_at_next_stop;
2258 /* We've already printed what needs to be printed. */
2259 bs->print_it = print_it_done;
2265 else if (b->type == bp_read_watchpoint ||
2266 b->type == bp_access_watchpoint)
2272 addr = target_stopped_data_address ();
2275 for (v = b->val_chain; v; v = v->next)
2277 if (v->lval == lval_memory)
2281 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2282 /* Exact match not required. Within range is sufficient.
2284 if (addr >= vaddr &&
2285 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2290 switch (catch_errors (watchpoint_check, bs, message,
2294 /* We've already printed what needs to be printed. */
2295 bs->print_it = print_it_done;
2298 case WP_VALUE_CHANGED:
2299 case WP_VALUE_NOT_CHANGED:
2306 /* Error from catch_errors. */
2307 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2308 if (b->related_breakpoint)
2309 b->related_breakpoint->disposition = del_at_next_stop;
2310 b->disposition = del_at_next_stop;
2311 /* We've already printed what needs to be printed. */
2312 bs->print_it = print_it_done;
2315 else /* found == 0 */
2317 /* This is a case where some watchpoint(s) triggered,
2318 but not at the address of this watchpoint (FOUND
2319 was left zero). So don't print anything for this
2321 bs->print_it = print_it_noop;
2328 /* By definition, an encountered breakpoint is a triggered
2332 real_breakpoint = 1;
2335 if (b->frame && b->frame != (get_current_frame ())->frame &&
2336 (b->type == bp_step_resume &&
2337 (INNER_THAN (get_current_frame ()->frame, b->frame))))
2341 int value_is_zero = 0;
2345 /* Need to select the frame, with all that implies
2346 so that the conditions will have the right context. */
2347 select_frame (get_current_frame (), 0);
2349 = catch_errors (breakpoint_cond_eval, (b->cond),
2350 "Error in testing breakpoint condition:\n",
2352 /* FIXME-someday, should give breakpoint # */
2355 if (b->cond && value_is_zero)
2358 /* Don't consider this a hit. */
2361 else if (b->ignore_count > 0)
2368 /* We will stop here */
2369 if (b->disposition == disable)
2370 b->enable = disabled;
2371 bs->commands = b->commands;
2375 (STREQ ("silent", bs->commands->line) ||
2376 (xdb_commands && STREQ ("Q", bs->commands->line))))
2378 bs->commands = bs->commands->next;
2383 /* Print nothing for this entry if we dont stop or if we dont print. */
2384 if (bs->stop == 0 || bs->print == 0)
2385 bs->print_it = print_it_noop;
2388 bs->next = NULL; /* Terminate the chain */
2389 bs = root_bs->next; /* Re-grab the head of the chain */
2391 if (real_breakpoint && bs)
2393 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2395 if (DECR_PC_AFTER_HW_BREAK != 0)
2397 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2403 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2406 #if defined (SHIFT_INST_REGS)
2408 #else /* No SHIFT_INST_REGS. */
2410 #endif /* No SHIFT_INST_REGS. */
2415 /* The value of a hardware watchpoint hasn't changed, but the
2416 intermediate memory locations we are watching may have. */
2417 if (bs && !bs->stop &&
2418 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2419 bs->breakpoint_at->type == bp_read_watchpoint ||
2420 bs->breakpoint_at->type == bp_access_watchpoint))
2422 remove_breakpoints ();
2423 insert_breakpoints ();
2428 /* Tell what to do about this bpstat. */
2433 /* Classify each bpstat as one of the following. */
2436 /* This bpstat element has no effect on the main_action. */
2439 /* There was a watchpoint, stop but don't print. */
2442 /* There was a watchpoint, stop and print. */
2445 /* There was a breakpoint but we're not stopping. */
2448 /* There was a breakpoint, stop but don't print. */
2451 /* There was a breakpoint, stop and print. */
2454 /* We hit the longjmp breakpoint. */
2457 /* We hit the longjmp_resume breakpoint. */
2460 /* We hit the step_resume breakpoint. */
2463 /* We hit the through_sigtramp breakpoint. */
2466 /* We hit the shared library event breakpoint. */
2469 /* We caught a shared library event. */
2472 /* This is just used to count how many enums there are. */
2476 /* Here is the table which drives this routine. So that we can
2477 format it pretty, we define some abbreviations for the
2478 enum bpstat_what codes. */
2479 #define kc BPSTAT_WHAT_KEEP_CHECKING
2480 #define ss BPSTAT_WHAT_STOP_SILENT
2481 #define sn BPSTAT_WHAT_STOP_NOISY
2482 #define sgl BPSTAT_WHAT_SINGLE
2483 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2484 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2485 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2486 #define sr BPSTAT_WHAT_STEP_RESUME
2487 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2488 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2489 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2491 /* "Can't happen." Might want to print an error message.
2492 abort() is not out of the question, but chances are GDB is just
2493 a bit confused, not unusable. */
2494 #define err BPSTAT_WHAT_STOP_NOISY
2496 /* Given an old action and a class, come up with a new action. */
2497 /* One interesting property of this table is that wp_silent is the same
2498 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2499 after stopping, the check for whether to step over a breakpoint
2500 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2501 reference to how we stopped. We retain separate wp_silent and
2502 bp_silent codes in case we want to change that someday.
2504 Another possibly interesting property of this table is that
2505 there's a partial ordering, priority-like, of the actions. Once
2506 you've decided that some action is appropriate, you'll never go
2507 back and decide something of a lower priority is better. The
2510 kc < clr sgl shl slr sn sr ss ts
2511 sgl < clrs shl shlr slr sn sr ss ts
2512 slr < err shl shlr sn sr ss ts
2513 clr < clrs err shl shlr sn sr ss ts
2514 clrs < err shl shlr sn sr ss ts
2515 ss < shl shlr sn sr ts
2522 What I think this means is that we don't need a damned table
2523 here. If you just put the rows and columns in the right order,
2524 it'd look awfully regular. We could simply walk the bpstat list
2525 and choose the highest priority action we find, with a little
2526 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2527 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2528 is messy anyway). */
2530 /* step_resume entries: a step resume breakpoint overrides another
2531 breakpoint of signal handling (see comment in wait_for_inferior
2532 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2533 /* We handle the through_sigtramp_breakpoint the same way; having both
2534 one of those and a step_resume_breakpoint is probably very rare (?). */
2536 static const enum bpstat_what_main_action
2537 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2540 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2543 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2545 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2547 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2549 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2551 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2553 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2555 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2557 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2559 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2561 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2563 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2565 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2580 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2581 struct bpstat_what retval;
2583 retval.call_dummy = 0;
2584 for (; bs != NULL; bs = bs->next)
2586 enum class bs_class = no_effect;
2587 if (bs->breakpoint_at == NULL)
2588 /* I suspect this can happen if it was a momentary breakpoint
2589 which has since been deleted. */
2591 switch (bs->breakpoint_at->type)
2597 case bp_hardware_breakpoint:
2603 bs_class = bp_noisy;
2605 bs_class = bp_silent;
2608 bs_class = bp_nostop;
2611 case bp_hardware_watchpoint:
2612 case bp_read_watchpoint:
2613 case bp_access_watchpoint:
2617 bs_class = wp_noisy;
2619 bs_class = wp_silent;
2622 /* There was a watchpoint, but we're not stopping.
2623 This requires no further action. */
2624 bs_class = no_effect;
2627 bs_class = long_jump;
2629 case bp_longjmp_resume:
2630 bs_class = long_resume;
2632 case bp_step_resume:
2635 bs_class = step_resume;
2638 /* It is for the wrong frame. */
2639 bs_class = bp_nostop;
2641 case bp_through_sigtramp:
2642 bs_class = through_sig;
2644 case bp_watchpoint_scope:
2645 bs_class = bp_nostop;
2647 case bp_shlib_event:
2648 bs_class = shlib_event;
2651 case bp_catch_unload:
2652 /* Only if this catchpoint triggered should we cause the
2653 step-out-of-dld behaviour. Otherwise, we ignore this
2656 bs_class = catch_shlib_event;
2658 bs_class = no_effect;
2661 case bp_catch_vfork:
2666 bs_class = bp_noisy;
2668 bs_class = bp_silent;
2671 /* There was a catchpoint, but we're not stopping.
2672 This requires no further action. */
2673 bs_class = no_effect;
2675 case bp_catch_catch:
2676 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2677 bs_class = bp_nostop;
2679 bs_class = bs->print ? bp_noisy : bp_silent;
2681 case bp_catch_throw:
2682 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2683 bs_class = bp_nostop;
2685 bs_class = bs->print ? bp_noisy : bp_silent;
2688 /* Make sure the action is stop (silent or noisy),
2689 so infrun.c pops the dummy frame. */
2690 bs_class = bp_silent;
2691 retval.call_dummy = 1;
2694 current_action = table[(int) bs_class][(int) current_action];
2696 retval.main_action = current_action;
2700 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2701 without hardware support). This isn't related to a specific bpstat,
2702 just to things like whether watchpoints are set. */
2705 bpstat_should_step ()
2707 struct breakpoint *b;
2709 if (b->enable == enabled && b->type == bp_watchpoint)
2714 /* Nonzero if there are enabled hardware watchpoints. */
2716 bpstat_have_active_hw_watchpoints ()
2718 struct breakpoint *b;
2720 if ((b->enable == enabled) &&
2722 ((b->type == bp_hardware_watchpoint) ||
2723 (b->type == bp_read_watchpoint) ||
2724 (b->type == bp_access_watchpoint)))
2730 /* Given a bpstat that records zero or more triggered eventpoints, this
2731 function returns another bpstat which contains only the catchpoints
2732 on that first list, if any. */
2734 bpstat_get_triggered_catchpoints (ep_list, cp_list)
2738 struct bpstats root_bs[1];
2739 bpstat bs = root_bs;
2740 struct breakpoint *ep;
2743 bpstat_clear (cp_list);
2744 root_bs->next = NULL;
2746 for (; ep_list != NULL; ep_list = ep_list->next)
2748 /* Is this eventpoint a catchpoint? If not, ignore it. */
2749 ep = ep_list->breakpoint_at;
2752 if ((ep->type != bp_catch_load) &&
2753 (ep->type != bp_catch_unload) &&
2754 (ep->type != bp_catch_catch) &&
2755 (ep->type != bp_catch_throw))
2756 /* pai: (temp) ADD fork/vfork here!! */
2759 /* Yes; add it to the list. */
2760 bs = bpstat_alloc (ep, bs);
2765 #if defined(SOLIB_ADD)
2766 /* Also, for each triggered catchpoint, tag it with the name of
2767 the library that caused this trigger. (We copy the name now,
2768 because it's only guaranteed to be available NOW, when the
2769 catchpoint triggers. Clients who may wish to know the name
2770 later must get it from the catchpoint itself.) */
2771 if (ep->triggered_dll_pathname != NULL)
2772 free (ep->triggered_dll_pathname);
2773 if (ep->type == bp_catch_load)
2774 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
2776 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
2778 dll_pathname = NULL;
2782 ep->triggered_dll_pathname = (char *)
2783 xmalloc (strlen (dll_pathname) + 1);
2784 strcpy (ep->triggered_dll_pathname, dll_pathname);
2787 ep->triggered_dll_pathname = NULL;
2793 /* Print information on breakpoint number BNUM, or -1 if all.
2794 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
2795 is nonzero, process only watchpoints. */
2802 ep_type_description_t;
2805 breakpoint_1 (bnum, allflag)
2809 register struct breakpoint *b;
2810 register struct command_line *l;
2811 register struct symbol *sym;
2812 CORE_ADDR last_addr = (CORE_ADDR) - 1;
2813 int found_a_breakpoint = 0;
2814 static ep_type_description_t bptypes[] =
2816 {bp_none, "?deleted?"},
2817 {bp_breakpoint, "breakpoint"},
2818 {bp_hardware_breakpoint, "hw breakpoint"},
2819 {bp_until, "until"},
2820 {bp_finish, "finish"},
2821 {bp_watchpoint, "watchpoint"},
2822 {bp_hardware_watchpoint, "hw watchpoint"},
2823 {bp_read_watchpoint, "read watchpoint"},
2824 {bp_access_watchpoint, "acc watchpoint"},
2825 {bp_longjmp, "longjmp"},
2826 {bp_longjmp_resume, "longjmp resume"},
2827 {bp_step_resume, "step resume"},
2828 {bp_through_sigtramp, "sigtramp"},
2829 {bp_watchpoint_scope, "watchpoint scope"},
2830 {bp_call_dummy, "call dummy"},
2831 {bp_shlib_event, "shlib events"},
2832 {bp_catch_load, "catch load"},
2833 {bp_catch_unload, "catch unload"},
2834 {bp_catch_fork, "catch fork"},
2835 {bp_catch_vfork, "catch vfork"},
2836 {bp_catch_exec, "catch exec"},
2837 {bp_catch_catch, "catch catch"},
2838 {bp_catch_throw, "catch throw"}
2841 static char *bpdisps[] =
2842 {"del", "dstp", "dis", "keep"};
2843 static char bpenables[] = "nyn";
2844 char wrap_indent[80];
2850 || bnum == b->number)
2852 /* We only print out user settable breakpoints unless the allflag is set. */
2854 && b->type != bp_breakpoint
2855 && b->type != bp_catch_load
2856 && b->type != bp_catch_unload
2857 && b->type != bp_catch_fork
2858 && b->type != bp_catch_vfork
2859 && b->type != bp_catch_exec
2860 && b->type != bp_catch_catch
2861 && b->type != bp_catch_throw
2862 && b->type != bp_hardware_breakpoint
2863 && b->type != bp_watchpoint
2864 && b->type != bp_read_watchpoint
2865 && b->type != bp_access_watchpoint
2866 && b->type != bp_hardware_watchpoint)
2869 if (!found_a_breakpoint++)
2871 annotate_breakpoints_headers ();
2874 printf_filtered ("Num ");
2876 printf_filtered ("Type ");
2878 printf_filtered ("Disp ");
2880 printf_filtered ("Enb ");
2884 printf_filtered ("Address ");
2887 printf_filtered ("What\n");
2889 annotate_breakpoints_table ();
2894 printf_filtered ("%-3d ", b->number);
2896 if ((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
2897 error ("bptypes table does not describe type #%d.", (int) b->type);
2898 if ((int) b->type != bptypes[(int) b->type].type)
2899 error ("bptypes table does not describe type #%d?", (int) b->type);
2900 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
2902 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
2904 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
2906 strcpy (wrap_indent, " ");
2908 strcat (wrap_indent, " ");
2912 case bp_hardware_watchpoint:
2913 case bp_read_watchpoint:
2914 case bp_access_watchpoint:
2915 /* Field 4, the address, is omitted (which makes the columns
2916 not line up too nicely with the headers, but the effect
2917 is relatively readable). */
2919 print_expression (b->exp, gdb_stdout);
2923 case bp_catch_unload:
2924 /* Field 4, the address, is omitted (which makes the columns
2925 not line up too nicely with the headers, but the effect
2926 is relatively readable). */
2928 if (b->dll_pathname == NULL)
2929 printf_filtered ("<any library> ");
2931 printf_filtered ("library \"%s\" ", b->dll_pathname);
2935 case bp_catch_vfork:
2936 /* Field 4, the address, is omitted (which makes the columns
2937 not line up too nicely with the headers, but the effect
2938 is relatively readable). */
2940 if (b->forked_inferior_pid != 0)
2941 printf_filtered ("process %d ", b->forked_inferior_pid);
2945 /* Field 4, the address, is omitted (which makes the columns
2946 not line up too nicely with the headers, but the effect
2947 is relatively readable). */
2949 if (b->exec_pathname != NULL)
2950 printf_filtered ("program \"%s\" ", b->exec_pathname);
2952 case bp_catch_catch:
2953 /* Field 4, the address, is omitted (which makes the columns
2954 not line up too nicely with the headers, but the effect
2955 is relatively readable). */
2957 printf_filtered ("exception catch ");
2959 case bp_catch_throw:
2960 /* Field 4, the address, is omitted (which makes the columns
2961 not line up too nicely with the headers, but the effect
2962 is relatively readable). */
2964 printf_filtered ("exception throw ");
2968 case bp_hardware_breakpoint:
2972 case bp_longjmp_resume:
2973 case bp_step_resume:
2974 case bp_through_sigtramp:
2975 case bp_watchpoint_scope:
2977 case bp_shlib_event:
2981 /* FIXME-32x64: need a print_address_numeric with
2985 local_hex_string_custom
2986 ((unsigned long) b->address, "08l"));
2991 last_addr = b->address;
2994 sym = find_pc_sect_function (b->address, b->section);
2997 fputs_filtered ("in ", gdb_stdout);
2998 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
2999 wrap_here (wrap_indent);
3000 fputs_filtered (" at ", gdb_stdout);
3002 fputs_filtered (b->source_file, gdb_stdout);
3003 printf_filtered (":%d", b->line_number);
3006 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3010 if (b->thread != -1)
3011 printf_filtered (" thread %d", b->thread);
3013 printf_filtered ("\n");
3019 printf_filtered ("\tstop only in stack frame at ");
3020 print_address_numeric (b->frame, 1, gdb_stdout);
3021 printf_filtered ("\n");
3028 printf_filtered ("\tstop only if ");
3029 print_expression (b->cond, gdb_stdout);
3030 printf_filtered ("\n");
3033 if (b->thread != -1)
3035 /* FIXME should make an annotation for this */
3036 printf_filtered ("\tstop only in thread %d\n", b->thread);
3039 if (show_breakpoint_hit_counts && b->hit_count)
3041 /* FIXME should make an annotation for this */
3042 if (ep_is_catchpoint (b))
3043 printf_filtered ("\tcatchpoint");
3045 printf_filtered ("\tbreakpoint");
3046 printf_filtered (" already hit %d time%s\n",
3047 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3050 if (b->ignore_count)
3054 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3057 if ((l = b->commands))
3063 print_command_line (l, 4, gdb_stdout);
3069 if (!found_a_breakpoint)
3072 printf_filtered ("No breakpoints or watchpoints.\n");
3074 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3077 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3078 that a comparison of an unsigned with -1 is always false. */
3079 if (last_addr != (CORE_ADDR) - 1)
3080 set_next_address (last_addr);
3082 annotate_breakpoints_table_end ();
3087 breakpoints_info (bnum_exp, from_tty)
3094 bnum = parse_and_eval_address (bnum_exp);
3096 breakpoint_1 (bnum, 0);
3101 maintenance_info_breakpoints (bnum_exp, from_tty)
3108 bnum = parse_and_eval_address (bnum_exp);
3110 breakpoint_1 (bnum, 1);
3113 /* Print a message describing any breakpoints set at PC. */
3116 describe_other_breakpoints (pc, section)
3120 register int others = 0;
3121 register struct breakpoint *b;
3124 if (b->address == pc)
3125 if (overlay_debugging == 0 ||
3126 b->section == section)
3130 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3132 if (b->address == pc)
3133 if (overlay_debugging == 0 ||
3134 b->section == section)
3140 ((b->enable == disabled ||
3141 b->enable == shlib_disabled ||
3142 b->enable == call_disabled)
3143 ? " (disabled)" : ""),
3144 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3146 printf_filtered ("also set at pc ");
3147 print_address_numeric (pc, 1, gdb_stdout);
3148 printf_filtered (".\n");
3152 /* Set the default place to put a breakpoint
3153 for the `break' command with no arguments. */
3156 set_default_breakpoint (valid, addr, symtab, line)
3159 struct symtab *symtab;
3162 default_breakpoint_valid = valid;
3163 default_breakpoint_address = addr;
3164 default_breakpoint_symtab = symtab;
3165 default_breakpoint_line = line;
3168 /* Rescan breakpoints at address ADDRESS,
3169 marking the first one as "first" and any others as "duplicates".
3170 This is so that the bpt instruction is only inserted once. */
3173 check_duplicates (address, section)
3177 register struct breakpoint *b;
3178 register int count = 0;
3180 if (address == 0) /* Watchpoints are uninteresting */
3184 if (b->enable != disabled
3185 && b->enable != shlib_disabled
3186 && b->enable != call_disabled
3187 && b->address == address
3188 && (overlay_debugging == 0 || b->section == section))
3191 b->duplicate = count > 1;
3195 /* Low level routine to set a breakpoint.
3196 Takes as args the three things that every breakpoint must have.
3197 Returns the breakpoint object so caller can set other things.
3198 Does not set the breakpoint number!
3199 Does not print anything.
3201 ==> This routine should not be called if there is a chance of later
3202 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3203 your arguments BEFORE calling this routine! */
3206 set_raw_breakpoint (sal)
3207 struct symtab_and_line sal;
3209 register struct breakpoint *b, *b1;
3211 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3212 memset (b, 0, sizeof (*b));
3213 b->address = sal.pc;
3214 if (sal.symtab == NULL)
3215 b->source_file = NULL;
3217 b->source_file = savestring (sal.symtab->filename,
3218 strlen (sal.symtab->filename));
3219 b->section = sal.section;
3220 b->language = current_language->la_language;
3221 b->input_radix = input_radix;
3223 b->line_number = sal.line;
3224 b->enable = enabled;
3227 b->ignore_count = 0;
3230 b->dll_pathname = NULL;
3231 b->triggered_dll_pathname = NULL;
3232 b->forked_inferior_pid = 0;
3233 b->exec_pathname = NULL;
3235 /* Add this breakpoint to the end of the chain
3236 so that a list of breakpoints will come out in order
3237 of increasing numbers. */
3239 b1 = breakpoint_chain;
3241 breakpoint_chain = b;
3249 check_duplicates (sal.pc, sal.section);
3250 breakpoints_changed ();
3255 #ifdef GET_LONGJMP_TARGET
3258 create_longjmp_breakpoint (func_name)
3261 struct symtab_and_line sal;
3262 struct breakpoint *b;
3264 INIT_SAL (&sal); /* initialize to zeroes */
3265 if (func_name != NULL)
3267 struct minimal_symbol *m;
3269 m = lookup_minimal_symbol_text (func_name, NULL,
3270 (struct objfile *) NULL);
3272 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3276 sal.section = find_pc_overlay (sal.pc);
3277 b = set_raw_breakpoint (sal);
3281 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3282 b->disposition = donttouch;
3283 b->enable = disabled;
3286 b->addr_string = strsave (func_name);
3287 b->number = internal_breakpoint_number--;
3290 #endif /* #ifdef GET_LONGJMP_TARGET */
3292 /* Call this routine when stepping and nexting to enable a breakpoint
3293 if we do a longjmp(). When we hit that breakpoint, call
3294 set_longjmp_resume_breakpoint() to figure out where we are going. */
3297 enable_longjmp_breakpoint ()
3299 register struct breakpoint *b;
3302 if (b->type == bp_longjmp)
3304 b->enable = enabled;
3305 check_duplicates (b->address, b->section);
3310 disable_longjmp_breakpoint ()
3312 register struct breakpoint *b;
3315 if (b->type == bp_longjmp
3316 || b->type == bp_longjmp_resume)
3318 b->enable = disabled;
3319 check_duplicates (b->address, b->section);
3325 remove_solib_event_breakpoints ()
3327 register struct breakpoint *b, *temp;
3329 ALL_BREAKPOINTS_SAFE (b, temp)
3330 if (b->type == bp_shlib_event)
3331 delete_breakpoint (b);
3335 create_solib_event_breakpoint (address)
3338 struct breakpoint *b;
3339 struct symtab_and_line sal;
3341 INIT_SAL (&sal); /* initialize to zeroes */
3343 sal.section = find_pc_overlay (sal.pc);
3344 b = set_raw_breakpoint (sal);
3345 b->number = internal_breakpoint_number--;
3346 b->disposition = donttouch;
3347 b->type = bp_shlib_event;
3351 disable_breakpoints_in_shlibs (silent)
3354 struct breakpoint *b;
3355 int disabled_shlib_breaks = 0;
3357 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3360 #if defined (PC_SOLIB)
3361 if (((b->type == bp_breakpoint) ||
3362 (b->type == bp_hardware_breakpoint)) &&
3363 (b->enable != shlib_disabled) &&
3364 (b->enable != call_disabled) &&
3366 PC_SOLIB (b->address))
3368 b->enable = shlib_disabled;
3371 if (!disabled_shlib_breaks)
3373 target_terminal_ours_for_output ();
3374 warning ("Temporarily disabling shared library breakpoints:");
3376 disabled_shlib_breaks = 1;
3377 warning ("breakpoint #%d ", b->number);
3384 /* Try to reenable any breakpoints in shared libraries. */
3386 re_enable_breakpoints_in_shlibs ()
3388 struct breakpoint *b;
3391 if (b->enable == shlib_disabled)
3395 /* Do not reenable the breakpoint if the shared library
3396 is still not mapped in. */
3397 if (target_read_memory (b->address, buf, 1) == 0)
3398 b->enable = enabled;
3405 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
3410 enum bptype bp_kind;
3412 struct breakpoint *b;
3413 struct symtabs_and_lines sals;
3414 struct symtab_and_line sal;
3415 struct cleanup *old_chain;
3416 struct cleanup *canonical_strings_chain = NULL;
3418 char *addr_start = hookname;
3419 char *addr_end = NULL;
3420 char **canonical = (char **) NULL;
3421 int thread = -1; /* All threads. */
3423 /* Set a breakpoint on the specified hook. */
3424 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3425 addr_end = hookname;
3427 if (sals.nelts == 0)
3429 warning ("Unable to set a breakpoint on dynamic linker callback.");
3430 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3431 warning ("GDB will be unable to track shl_load/shl_unload calls");
3434 if (sals.nelts != 1)
3436 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3437 warning ("GDB will be unable to track shl_load/shl_unload calls");
3441 /* Make sure that all storage allocated in decode_line_1 gets freed
3442 in case the following errors out. */
3443 old_chain = make_cleanup (free, sals.sals);
3444 if (canonical != (char **) NULL)
3446 make_cleanup (free, canonical);
3447 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3448 if (canonical[0] != NULL)
3449 make_cleanup (free, canonical[0]);
3452 resolve_sal_pc (&sals.sals[0]);
3454 /* Remove the canonical strings from the cleanup, they are needed below. */
3455 if (canonical != (char **) NULL)
3456 discard_cleanups (canonical_strings_chain);
3458 b = set_raw_breakpoint (sals.sals[0]);
3459 set_breakpoint_count (breakpoint_count + 1);
3460 b->number = breakpoint_count;
3462 b->cond_string = (cond_string == NULL) ?
3463 NULL : savestring (cond_string, strlen (cond_string));
3466 if (canonical != (char **) NULL && canonical[0] != NULL)
3467 b->addr_string = canonical[0];
3468 else if (addr_start)
3469 b->addr_string = savestring (addr_start, addr_end - addr_start);
3471 b->enable = enabled;
3472 b->disposition = tempflag ? del : donttouch;
3474 if (dll_pathname == NULL)
3475 b->dll_pathname = NULL;
3478 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3479 strcpy (b->dll_pathname, dll_pathname);
3484 do_cleanups (old_chain);
3488 create_solib_load_event_breakpoint (hookname, tempflag,
3489 dll_pathname, cond_string)
3495 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3496 cond_string, bp_catch_load);
3500 create_solib_unload_event_breakpoint (hookname, tempflag,
3501 dll_pathname, cond_string)
3507 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3508 cond_string, bp_catch_unload);
3512 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3515 enum bptype bp_kind;
3517 struct symtab_and_line sal;
3518 struct breakpoint *b;
3519 int thread = -1; /* All threads. */
3526 b = set_raw_breakpoint (sal);
3527 set_breakpoint_count (breakpoint_count + 1);
3528 b->number = breakpoint_count;
3530 b->cond_string = (cond_string == NULL) ?
3531 NULL : savestring (cond_string, strlen (cond_string));
3533 b->addr_string = NULL;
3534 b->enable = enabled;
3535 b->disposition = tempflag ? del : donttouch;
3536 b->forked_inferior_pid = 0;
3544 create_fork_event_catchpoint (tempflag, cond_string)
3548 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3552 create_vfork_event_catchpoint (tempflag, cond_string)
3556 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3560 create_exec_event_catchpoint (tempflag, cond_string)
3564 struct symtab_and_line sal;
3565 struct breakpoint *b;
3566 int thread = -1; /* All threads. */
3573 b = set_raw_breakpoint (sal);
3574 set_breakpoint_count (breakpoint_count + 1);
3575 b->number = breakpoint_count;
3577 b->cond_string = (cond_string == NULL) ?
3578 NULL : savestring (cond_string, strlen (cond_string));
3580 b->addr_string = NULL;
3581 b->enable = enabled;
3582 b->disposition = tempflag ? del : donttouch;
3584 b->type = bp_catch_exec;
3590 hw_breakpoint_used_count ()
3592 register struct breakpoint *b;
3597 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3605 hw_watchpoint_used_count (type, other_type_used)
3607 int *other_type_used;
3609 register struct breakpoint *b;
3612 *other_type_used = 0;
3615 if (b->enable == enabled)
3617 if (b->type == type)
3619 else if ((b->type == bp_hardware_watchpoint ||
3620 b->type == bp_read_watchpoint ||
3621 b->type == bp_access_watchpoint)
3622 && b->enable == enabled)
3623 *other_type_used = 1;
3629 /* Call this after hitting the longjmp() breakpoint. Use this to set
3630 a new breakpoint at the target of the jmp_buf.
3632 FIXME - This ought to be done by setting a temporary breakpoint
3633 that gets deleted automatically... */
3636 set_longjmp_resume_breakpoint (pc, frame)
3638 struct frame_info *frame;
3640 register struct breakpoint *b;
3643 if (b->type == bp_longjmp_resume)
3646 b->enable = enabled;
3648 b->frame = frame->frame;
3651 check_duplicates (b->address, b->section);
3657 disable_watchpoints_before_interactive_call_start ()
3659 struct breakpoint *b;
3663 if (((b->type == bp_watchpoint)
3664 || (b->type == bp_hardware_watchpoint)
3665 || (b->type == bp_read_watchpoint)
3666 || (b->type == bp_access_watchpoint)
3667 || ep_is_exception_catchpoint (b))
3668 && (b->enable == enabled))
3670 b->enable = call_disabled;
3671 check_duplicates (b->address, b->section);
3677 enable_watchpoints_after_interactive_call_stop ()
3679 struct breakpoint *b;
3683 if (((b->type == bp_watchpoint)
3684 || (b->type == bp_hardware_watchpoint)
3685 || (b->type == bp_read_watchpoint)
3686 || (b->type == bp_access_watchpoint)
3687 || ep_is_exception_catchpoint (b))
3688 && (b->enable == call_disabled))
3690 b->enable = enabled;
3691 check_duplicates (b->address, b->section);
3697 /* Set a breakpoint that will evaporate an end of command
3698 at address specified by SAL.
3699 Restrict it to frame FRAME if FRAME is nonzero. */
3702 set_momentary_breakpoint (sal, frame, type)
3703 struct symtab_and_line sal;
3704 struct frame_info *frame;
3707 register struct breakpoint *b;
3708 b = set_raw_breakpoint (sal);
3710 b->enable = enabled;
3711 b->disposition = donttouch;
3712 b->frame = (frame ? frame->frame : 0);
3714 /* If we're debugging a multi-threaded program, then we
3715 want momentary breakpoints to be active in only a
3716 single thread of control. */
3717 if (in_thread_list (inferior_pid))
3718 b->thread = pid_to_thread_id (inferior_pid);
3724 /* Tell the user we have just set a breakpoint B. */
3728 struct breakpoint *b;
3732 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3733 watchpoint) other than breakpoint creation. It should be possible to
3734 clean this up and at the same time replace the random calls to
3735 breakpoint_changed with this hook, as has already been done for
3736 delete_breakpoint_hook and so on. */
3737 if (create_breakpoint_hook)
3738 create_breakpoint_hook (b);
3743 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3746 printf_filtered ("Watchpoint %d: ", b->number);
3747 print_expression (b->exp, gdb_stdout);
3749 case bp_hardware_watchpoint:
3750 printf_filtered ("Hardware watchpoint %d: ", b->number);
3751 print_expression (b->exp, gdb_stdout);
3753 case bp_read_watchpoint:
3754 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3755 print_expression (b->exp, gdb_stdout);
3757 case bp_access_watchpoint:
3758 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3760 print_expression (b->exp, gdb_stdout);
3763 printf_filtered ("Breakpoint %d", b->number);
3766 case bp_hardware_breakpoint:
3767 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3771 case bp_catch_unload:
3772 printf_filtered ("Catchpoint %d (%s %s)",
3774 (b->type == bp_catch_load) ? "load" : "unload",
3775 (b->dll_pathname != NULL) ?
3776 b->dll_pathname : "<any library>");
3779 case bp_catch_vfork:
3780 printf_filtered ("Catchpoint %d (%s)",
3782 (b->type == bp_catch_fork) ? "fork" : "vfork");
3785 printf_filtered ("Catchpoint %d (exec)",
3788 case bp_catch_catch:
3789 case bp_catch_throw:
3790 printf_filtered ("Catchpoint %d (%s)",
3792 (b->type == bp_catch_catch) ? "catch" : "throw");
3798 case bp_longjmp_resume:
3799 case bp_step_resume:
3800 case bp_through_sigtramp:
3802 case bp_watchpoint_scope:
3803 case bp_shlib_event:
3808 if (addressprint || b->source_file == NULL)
3810 printf_filtered (" at ");
3811 print_address_numeric (b->address, 1, gdb_stdout);
3814 printf_filtered (": file %s, line %d.",
3815 b->source_file, b->line_number);
3816 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
3817 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
3819 printf_filtered ("\n");
3823 /* Set a breakpoint according to ARG (function, linenum or *address)
3824 flag: first bit : 0 non-temporary, 1 temporary.
3825 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
3828 break_command_1 (arg, flag, from_tty)
3832 int tempflag, hardwareflag;
3833 struct symtabs_and_lines sals;
3834 struct symtab_and_line sal;
3835 register struct expression *cond = 0;
3836 register struct breakpoint *b;
3838 /* Pointers in arg to the start, and one past the end, of the condition. */
3839 char *cond_start = NULL;
3840 char *cond_end = NULL;
3841 /* Pointers in arg to the start, and one past the end,
3842 of the address part. */
3843 char *addr_start = NULL;
3844 char *addr_end = NULL;
3845 struct cleanup *old_chain;
3846 struct cleanup *canonical_strings_chain = NULL;
3847 char **canonical = (char **) NULL;
3851 hardwareflag = flag & BP_HARDWAREFLAG;
3852 tempflag = flag & BP_TEMPFLAG;
3857 INIT_SAL (&sal); /* initialize to zeroes */
3859 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3861 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
3862 && (arg[2] == ' ' || arg[2] == '\t')))
3864 if (default_breakpoint_valid)
3866 sals.sals = (struct symtab_and_line *)
3867 xmalloc (sizeof (struct symtab_and_line));
3868 sal.pc = default_breakpoint_address;
3869 sal.line = default_breakpoint_line;
3870 sal.symtab = default_breakpoint_symtab;
3871 sal.section = find_pc_overlay (sal.pc);
3876 error ("No default breakpoint address now.");
3882 /* Force almost all breakpoints to be in terms of the
3883 current_source_symtab (which is decode_line_1's default). This
3884 should produce the results we want almost all of the time while
3885 leaving default_breakpoint_* alone. */
3886 if (default_breakpoint_valid
3887 && (!current_source_symtab
3888 || (arg && (*arg == '+' || *arg == '-'))))
3889 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3890 default_breakpoint_line, &canonical);
3892 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
3900 /* Make sure that all storage allocated in decode_line_1 gets freed
3901 in case the following `for' loop errors out. */
3902 old_chain = make_cleanup (free, sals.sals);
3903 if (canonical != (char **) NULL)
3905 make_cleanup (free, canonical);
3906 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3907 for (i = 0; i < sals.nelts; i++)
3909 if (canonical[i] != NULL)
3910 make_cleanup (free, canonical[i]);
3914 thread = -1; /* No specific thread yet */
3916 /* Resolve all line numbers to PC's, and verify that conditions
3917 can be parsed, before setting any breakpoints. */
3918 for (i = 0; i < sals.nelts; i++)
3920 char *tok, *end_tok;
3923 resolve_sal_pc (&sals.sals[i]);
3925 /* It's possible for the PC to be nonzero, but still an illegal
3926 value on some targets.
3928 For example, on HP-UX if you start gdb, and before running the
3929 inferior you try to set a breakpoint on a shared library function
3930 "foo" where the inferior doesn't call "foo" directly but does
3931 pass its address to another function call, then we do find a
3932 minimal symbol for the "foo", but it's address is invalid.
3933 (Appears to be an index into a table that the loader sets up
3934 when the inferior is run.)
3936 Give the target a chance to bless sals.sals[i].pc before we
3937 try to make a breakpoint for it. */
3938 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
3940 error ("Cannot break on %s without a running program.",
3948 while (*tok == ' ' || *tok == '\t')
3953 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3956 toklen = end_tok - tok;
3958 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3960 tok = cond_start = end_tok + 1;
3961 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3964 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3970 thread = strtol (tok, &tok, 0);
3972 error ("Junk after thread keyword.");
3973 if (!valid_thread_id (thread))
3974 error ("Unknown thread %d\n", thread);
3977 error ("Junk at end of arguments.");
3982 int i, target_resources_ok;
3984 i = hw_breakpoint_used_count ();
3985 target_resources_ok =
3986 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
3988 if (target_resources_ok == 0)
3989 error ("No hardware breakpoint support in the target.");
3990 else if (target_resources_ok < 0)
3991 error ("Hardware breakpoints used exceeds limit.");
3994 /* Remove the canonical strings from the cleanup, they are needed below. */
3995 if (canonical != (char **) NULL)
3996 discard_cleanups (canonical_strings_chain);
3998 /* Now set all the breakpoints. */
3999 for (i = 0; i < sals.nelts; i++)
4004 describe_other_breakpoints (sal.pc, sal.section);
4006 b = set_raw_breakpoint (sal);
4007 set_breakpoint_count (breakpoint_count + 1);
4008 b->number = breakpoint_count;
4009 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4013 /* If a canonical line spec is needed use that instead of the
4015 if (canonical != (char **) NULL && canonical[i] != NULL)
4016 b->addr_string = canonical[i];
4017 else if (addr_start)
4018 b->addr_string = savestring (addr_start, addr_end - addr_start);
4020 b->cond_string = savestring (cond_start, cond_end - cond_start);
4022 b->enable = enabled;
4023 b->disposition = tempflag ? del : donttouch;
4029 warning ("Multiple breakpoints were set.");
4030 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4032 do_cleanups (old_chain);
4036 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4041 struct frame_info *frame;
4042 CORE_ADDR low, high, selected_pc = 0;
4043 char *extra_args, *level_arg, *addr_string;
4044 int extra_args_len = 0, if_arg = 0;
4047 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4050 if (default_breakpoint_valid)
4054 selected_pc = selected_frame->pc;
4059 error ("No selected frame.");
4062 error ("No default breakpoint address now.");
4066 extra_args = strchr (arg, ' ');
4070 extra_args_len = strlen (extra_args);
4071 level_arg = (char *) xmalloc (extra_args - arg);
4072 strncpy (level_arg, arg, extra_args - arg - 1);
4073 level_arg[extra_args - arg - 1] = '\0';
4077 level_arg = (char *) xmalloc (strlen (arg) + 1);
4078 strcpy (level_arg, arg);
4081 frame = parse_frame_specification (level_arg);
4083 selected_pc = frame->pc;
4090 extra_args_len = strlen (arg);
4095 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4097 addr_string = (char *) xmalloc (26 + extra_args_len);
4099 sprintf (addr_string, "*0x%x %s", high, extra_args);
4101 sprintf (addr_string, "*0x%x", high);
4102 break_command_1 (addr_string, flag, from_tty);
4106 error ("No function contains the specified address");
4109 error ("Unable to set breakpoint at procedure exit");
4114 break_at_finish_command_1 (arg, flag, from_tty)
4119 char *addr_string, *break_string, *beg_addr_string;
4120 CORE_ADDR low, high;
4121 struct symtabs_and_lines sals;
4122 struct symtab_and_line sal;
4123 struct cleanup *old_chain;
4125 int extra_args_len = 0;
4129 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4131 if (default_breakpoint_valid)
4135 addr_string = (char *) xmalloc (15);
4136 sprintf (addr_string, "*0x%x", selected_frame->pc);
4141 error ("No selected frame.");
4144 error ("No default breakpoint address now.");
4148 addr_string = (char *) xmalloc (strlen (arg) + 1);
4149 strcpy (addr_string, arg);
4155 extra_args_len = strlen (arg);
4159 /* get the stuff after the function name or address */
4160 extra_args = strchr (arg, ' ');
4164 extra_args_len = strlen (extra_args);
4171 beg_addr_string = addr_string;
4172 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4175 free (beg_addr_string);
4176 old_chain = make_cleanup (free, sals.sals);
4177 for (i = 0; (i < sals.nelts); i++)
4180 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4182 break_string = (char *) xmalloc (extra_args_len + 26);
4184 sprintf (break_string, "*0x%x %s", high, extra_args);
4186 sprintf (break_string, "*0x%x", high);
4187 break_command_1 (break_string, flag, from_tty);
4188 free (break_string);
4191 error ("No function contains the specified address");
4195 warning ("Multiple breakpoints were set.\n");
4196 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4198 do_cleanups (old_chain);
4202 /* Helper function for break_command_1 and disassemble_command. */
4205 resolve_sal_pc (sal)
4206 struct symtab_and_line *sal;
4210 if (sal->pc == 0 && sal->symtab != NULL)
4212 if (!find_line_pc (sal->symtab, sal->line, &pc))
4213 error ("No line %d in file \"%s\".",
4214 sal->line, sal->symtab->filename);
4218 if (sal->section == 0 && sal->symtab != NULL)
4220 struct blockvector *bv;
4225 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4228 b = BLOCKVECTOR_BLOCK (bv, index);
4229 sym = block_function (b);
4232 fixup_symbol_section (sym, sal->symtab->objfile);
4233 sal->section = SYMBOL_BFD_SECTION (sym);
4237 /* It really is worthwhile to have the section, so we'll just
4238 have to look harder. This case can be executed if we have
4239 line numbers but no functions (as can happen in assembly
4242 struct minimal_symbol *msym;
4244 msym = lookup_minimal_symbol_by_pc (sal->pc);
4246 sal->section = SYMBOL_BFD_SECTION (msym);
4253 break_command (arg, from_tty)
4257 break_command_1 (arg, 0, from_tty);
4261 break_at_finish_command (arg, from_tty)
4265 break_at_finish_command_1 (arg, 0, from_tty);
4269 break_at_finish_at_depth_command (arg, from_tty)
4273 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4277 tbreak_command (arg, from_tty)
4281 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4285 tbreak_at_finish_command (arg, from_tty)
4289 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4293 hbreak_command (arg, from_tty)
4297 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4301 thbreak_command (arg, from_tty)
4305 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4309 stop_command (arg, from_tty)
4313 printf_filtered ("Specify the type of breakpoint to set.\n\
4314 Usage: stop in <function | address>\n\
4319 stopin_command (arg, from_tty)
4325 if (arg == (char *) NULL)
4327 else if (*arg != '*')
4332 /* look for a ':'. If this is a line number specification, then
4333 say it is bad, otherwise, it should be an address or
4334 function/method name */
4335 while (*argptr && !hasColon)
4337 hasColon = (*argptr == ':');
4342 badInput = (*argptr != ':'); /* Not a class::method */
4344 badInput = isdigit (*arg); /* a simple line number */
4348 printf_filtered ("Usage: stop in <function | address>\n");
4350 break_command_1 (arg, 0, from_tty);
4354 stopat_command (arg, from_tty)
4360 if (arg == (char *) NULL || *arg == '*') /* no line number */
4367 /* look for a ':'. If there is a '::' then get out, otherwise
4368 it is probably a line number. */
4369 while (*argptr && !hasColon)
4371 hasColon = (*argptr == ':');
4376 badInput = (*argptr == ':'); /* we have class::method */
4378 badInput = !isdigit (*arg); /* not a line number */
4382 printf_filtered ("Usage: stop at <line>\n");
4384 break_command_1 (arg, 0, from_tty);
4388 /* accessflag: hw_write: watch write,
4389 hw_read: watch read,
4390 hw_access: watch access (read or write) */
4392 watch_command_1 (arg, accessflag, from_tty)
4397 struct breakpoint *b;
4398 struct symtab_and_line sal;
4399 struct expression *exp;
4400 struct block *exp_valid_block;
4401 struct value *val, *mark;
4402 struct frame_info *frame;
4403 struct frame_info *prev_frame = NULL;
4404 char *exp_start = NULL;
4405 char *exp_end = NULL;
4406 char *tok, *end_tok;
4408 char *cond_start = NULL;
4409 char *cond_end = NULL;
4410 struct expression *cond = NULL;
4411 int i, other_type_used, target_resources_ok = 0;
4412 enum bptype bp_type;
4415 INIT_SAL (&sal); /* initialize to zeroes */
4417 /* Parse arguments. */
4418 innermost_block = NULL;
4420 exp = parse_exp_1 (&arg, 0, 0);
4422 exp_valid_block = innermost_block;
4423 mark = value_mark ();
4424 val = evaluate_expression (exp);
4425 release_value (val);
4426 if (VALUE_LAZY (val))
4427 value_fetch_lazy (val);
4430 while (*tok == ' ' || *tok == '\t')
4434 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4437 toklen = end_tok - tok;
4438 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4440 tok = cond_start = end_tok + 1;
4441 cond = parse_exp_1 (&tok, 0, 0);
4445 error ("Junk at end of command.");
4447 if (accessflag == hw_read)
4448 bp_type = bp_read_watchpoint;
4449 else if (accessflag == hw_access)
4450 bp_type = bp_access_watchpoint;
4452 bp_type = bp_hardware_watchpoint;
4454 mem_cnt = can_use_hardware_watchpoint (val);
4455 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4456 error ("Expression cannot be implemented with read/access watchpoint.");
4459 i = hw_watchpoint_used_count (bp_type, &other_type_used);
4460 target_resources_ok =
4461 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4463 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4464 error ("Target does not support this type of hardware watchpoint.");
4466 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4467 error ("Target can only support one kind of HW watchpoint at a time.");
4470 #if defined(HPUXHPPA)
4471 /* On HP-UX if you set a h/w
4472 watchpoint before the "run" command, the inferior dies with a e.g.,
4473 SIGILL once you start it. I initially believed this was due to a
4474 bad interaction between page protection traps and the initial
4475 startup sequence by the dynamic linker.
4477 However, I tried avoiding that by having HP-UX's implementation of
4478 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4479 yet, which forced slow watches before a "run" or "attach", and it
4480 still fails somewhere in the startup code.
4482 Until I figure out what's happening, I'm disallowing watches altogether
4483 before the "run" or "attach" command. We'll tell the user they must
4484 set watches after getting the program started. */
4485 if (!target_has_execution)
4487 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4490 #endif /* HPUXHPPA */
4492 /* Now set up the breakpoint. */
4493 b = set_raw_breakpoint (sal);
4494 set_breakpoint_count (breakpoint_count + 1);
4495 b->number = breakpoint_count;
4496 b->disposition = donttouch;
4498 b->exp_valid_block = exp_valid_block;
4499 b->exp_string = savestring (exp_start, exp_end - exp_start);
4503 b->cond_string = savestring (cond_start, cond_end - cond_start);
4507 frame = block_innermost_frame (exp_valid_block);
4510 prev_frame = get_prev_frame (frame);
4511 b->watchpoint_frame = frame->frame;
4514 b->watchpoint_frame = (CORE_ADDR) 0;
4516 if (mem_cnt && target_resources_ok > 0)
4519 b->type = bp_watchpoint;
4521 /* If the expression is "local", then set up a "watchpoint scope"
4522 breakpoint at the point where we've left the scope of the watchpoint
4524 if (innermost_block)
4528 struct breakpoint *scope_breakpoint;
4529 struct symtab_and_line scope_sal;
4531 INIT_SAL (&scope_sal); /* initialize to zeroes */
4532 scope_sal.pc = get_frame_pc (prev_frame);
4533 scope_sal.section = find_pc_overlay (scope_sal.pc);
4535 scope_breakpoint = set_raw_breakpoint (scope_sal);
4536 set_breakpoint_count (breakpoint_count + 1);
4537 scope_breakpoint->number = breakpoint_count;
4539 scope_breakpoint->type = bp_watchpoint_scope;
4540 scope_breakpoint->enable = enabled;
4542 /* Automatically delete the breakpoint when it hits. */
4543 scope_breakpoint->disposition = del;
4545 /* Only break in the proper frame (help with recursion). */
4546 scope_breakpoint->frame = prev_frame->frame;
4548 /* Set the address at which we will stop. */
4549 scope_breakpoint->address = get_frame_pc (prev_frame);
4551 /* The scope breakpoint is related to the watchpoint. We
4552 will need to act on them together. */
4553 b->related_breakpoint = scope_breakpoint;
4556 value_free_to_mark (mark);
4560 /* Return count of locations need to be watched and can be handled
4561 in hardware. If the watchpoint can not be handled
4562 in hardware return zero. */
4564 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4565 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4566 ((BYTE_SIZE) <= (REGISTER_SIZE))
4569 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4570 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4571 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
4575 can_use_hardware_watchpoint (v)
4578 int found_memory_cnt = 0;
4580 /* Did the user specifically forbid us to use hardware watchpoints? */
4581 if (!can_use_hw_watchpoints)
4584 /* Make sure all the intermediate values are in memory. Also make sure
4585 we found at least one memory expression. Guards against watch 0x12345,
4586 which is meaningless, but could cause errors if one tries to insert a
4587 hardware watchpoint for the constant expression. */
4588 for (; v; v = v->next)
4590 if (v->lval == lval_memory)
4592 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4593 int len = TYPE_LENGTH (VALUE_TYPE (v));
4595 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4600 else if (v->lval != not_lval && v->modifiable == 0)
4601 return 0; /* ??? What does this represent? */
4602 else if (v->lval == lval_register)
4603 return 0; /* cannot watch a register with a HW watchpoint */
4606 /* The expression itself looks suitable for using a hardware
4607 watchpoint, but give the target machine a chance to reject it. */
4608 return found_memory_cnt;
4612 watch_command (arg, from_tty)
4616 watch_command_1 (arg, hw_write, from_tty);
4620 rwatch_command (arg, from_tty)
4624 watch_command_1 (arg, hw_read, from_tty);
4628 awatch_command (arg, from_tty)
4632 watch_command_1 (arg, hw_access, from_tty);
4636 /* Helper routines for the until_command routine in infcmd.c. Here
4637 because it uses the mechanisms of breakpoints. */
4639 /* This function is called by fetch_inferior_event via the
4640 cmd_continuation pointer, to complete the until command. It takes
4641 care of cleaning up the temporary breakpoints set up by the until
4644 until_break_command_continuation (arg)
4645 struct continuation_arg *arg;
4647 /* Do all the exec cleanups, which at this point should only be the
4648 one set up in the first part of the until_break_command
4650 do_exec_cleanups (ALL_CLEANUPS);
4655 until_break_command (arg, from_tty)
4659 struct symtabs_and_lines sals;
4660 struct symtab_and_line sal;
4661 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4662 struct breakpoint *breakpoint;
4663 struct cleanup *old_chain;
4664 struct continuation_arg *arg1, *arg2;
4666 clear_proceed_status ();
4668 /* Set a breakpoint where the user wants it and at return from
4671 if (default_breakpoint_valid)
4672 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4673 default_breakpoint_line, (char ***) NULL);
4675 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4676 0, (char ***) NULL);
4678 if (sals.nelts != 1)
4679 error ("Couldn't get information on specified line.");
4682 free ((PTR) sals.sals); /* malloc'd, so freed */
4685 error ("Junk at end of arguments.");
4687 resolve_sal_pc (&sal);
4689 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
4691 if (!async_p || !target_has_async)
4692 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4695 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4697 /* If we are running asynchronously, and the target supports async
4698 execution, we are not waiting for the target to stop, in the call
4699 tp proceed, below. This means that we cannot delete the
4700 brekpoints until the target has actually stopped. The only place
4701 where we get a chance to do that is in fetch_inferior_event, so
4702 we must set things up for that. */
4704 if (async_p && target_has_async)
4706 /* In this case we don't need args for the continuation, because
4707 all it needs to do is do the cleanups in the
4708 exec_cleanup_chain, which will be only those inserted by this
4709 function. We can get away by using ALL_CLEANUPS. */
4710 add_continuation (until_break_command_continuation, NULL);
4713 /* Keep within the current frame */
4717 sal = find_pc_line (prev_frame->pc, 0);
4718 sal.pc = prev_frame->pc;
4719 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
4720 if (!async_p || !target_has_async)
4721 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4723 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4726 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
4727 /* Do the cleanups now, anly if we are not running asynchronously,
4728 of if we are, but the target is still synchronous. */
4729 if (!async_p || !target_has_async)
4730 do_cleanups (old_chain);
4734 /* These aren't used; I don't konw what they were for. */
4735 /* Set a breakpoint at the catch clause for NAME. */
4737 catch_breakpoint (name)
4743 disable_catch_breakpoint ()
4748 delete_catch_breakpoint ()
4753 enable_catch_breakpoint ()
4760 struct sal_chain *next;
4761 struct symtab_and_line sal;
4765 /* Not really used -- invocation in handle_gnu_4_16_catch_command
4766 had been commented out in the v.4.16 sources, and stays
4767 disabled there now because "catch NAME" syntax isn't allowed.
4769 /* This isn't used; I don't know what it was for. */
4770 /* For each catch clause identified in ARGS, run FUNCTION
4771 with that clause as an argument. */
4772 static struct symtabs_and_lines
4773 map_catch_names (args, function)
4777 register char *p = args;
4779 struct symtabs_and_lines sals;
4781 struct sal_chain *sal_chain = 0;
4785 error_no_arg ("one or more catch names");
4793 /* Don't swallow conditional part. */
4794 if (p1[0] == 'i' && p1[1] == 'f'
4795 && (p1[2] == ' ' || p1[2] == '\t'))
4801 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4805 if (*p1 && *p1 != ' ' && *p1 != '\t')
4806 error ("Arguments must be catch names.");
4812 struct sal_chain *next = (struct sal_chain *)
4813 alloca (sizeof (struct sal_chain));
4814 next->next = sal_chain;
4815 next->sal = get_catch_sal (p);
4820 printf_unfiltered ("No catch clause for exception %s.\n", p);
4825 while (*p == ' ' || *p == '\t')
4831 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4833 static struct symtabs_and_lines
4834 get_catch_sals (this_level_only)
4835 int this_level_only;
4837 register struct blockvector *bl;
4838 register struct block *block;
4839 int index, have_default = 0;
4841 struct symtabs_and_lines sals;
4842 struct sal_chain *sal_chain = 0;
4843 char *blocks_searched;
4845 /* Not sure whether an error message is always the correct response,
4846 but it's better than a core dump. */
4847 if (selected_frame == NULL)
4848 error ("No selected frame.");
4849 block = get_frame_block (selected_frame);
4850 pc = selected_frame->pc;
4856 error ("No symbol table info available.\n");
4858 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4859 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4860 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4864 CORE_ADDR end = BLOCK_END (block) - 4;
4867 if (bl != blockvector_for_pc (end, &index))
4868 error ("blockvector blotch");
4869 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4870 error ("blockvector botch");
4871 last_index = BLOCKVECTOR_NBLOCKS (bl);
4874 /* Don't print out blocks that have gone by. */
4875 while (index < last_index
4876 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4879 while (index < last_index
4880 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4882 if (blocks_searched[index] == 0)
4884 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4887 register struct symbol *sym;
4889 nsyms = BLOCK_NSYMS (b);
4891 for (i = 0; i < nsyms; i++)
4893 sym = BLOCK_SYM (b, i);
4894 if (STREQ (SYMBOL_NAME (sym), "default"))
4900 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4902 struct sal_chain *next = (struct sal_chain *)
4903 alloca (sizeof (struct sal_chain));
4904 next->next = sal_chain;
4905 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
4910 blocks_searched[index] = 1;
4916 if (sal_chain && this_level_only)
4919 /* After handling the function's top-level block, stop.
4920 Don't continue to its superblock, the block of
4921 per-file symbols. */
4922 if (BLOCK_FUNCTION (block))
4924 block = BLOCK_SUPERBLOCK (block);
4929 struct sal_chain *tmp_chain;
4931 /* Count the number of entries. */
4932 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4933 tmp_chain = tmp_chain->next)
4937 sals.sals = (struct symtab_and_line *)
4938 xmalloc (index * sizeof (struct symtab_and_line));
4939 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4940 sals.sals[index] = sal_chain->sal;
4947 ep_skip_leading_whitespace (s)
4950 if ((s == NULL) || (*s == NULL))
4952 while (isspace (**s))
4956 /* This function examines a string, and attempts to find a token
4957 that might be an event name in the leading characters. If a
4958 possible match is found, a pointer to the last character of
4959 the token is returned. Else, NULL is returned. */
4962 ep_find_event_name_end (arg)
4966 char *event_name_end = NULL;
4968 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4972 /* We break out of the loop when we find a token delimiter.
4973 Basically, we're looking for alphanumerics and underscores;
4974 anything else delimites the token. */
4977 if (!isalnum (*s) && (*s != '_'))
4983 return event_name_end;
4987 /* This function attempts to parse an optional "if <cond>" clause
4988 from the arg string. If one is not found, it returns NULL.
4990 Else, it returns a pointer to the condition string. (It does not
4991 attempt to evaluate the string against a particular block.) And,
4992 it updates arg to point to the first character following the parsed
4993 if clause in the arg string. */
4996 ep_parse_optional_if_clause (arg)
5001 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5004 /* Skip the "if" keyword. */
5007 /* Skip any extra leading whitespace, and record the start of the
5008 condition string. */
5009 ep_skip_leading_whitespace (arg);
5012 /* Assume that the condition occupies the remainder of the arg string. */
5013 (*arg) += strlen (cond_string);
5018 /* This function attempts to parse an optional filename from the arg
5019 string. If one is not found, it returns NULL.
5021 Else, it returns a pointer to the parsed filename. (This function
5022 makes no attempt to verify that a file of that name exists, or is
5023 accessible.) And, it updates arg to point to the first character
5024 following the parsed filename in the arg string.
5026 Note that clients needing to preserve the returned filename for
5027 future access should copy it to their own buffers. */
5029 ep_parse_optional_filename (arg)
5032 static char filename[1024];
5037 if ((*arg_p == '\0') || isspace (*arg_p))
5055 /* Commands to deal with catching events, such as signals, exceptions,
5056 process start/exit, etc. */
5060 catch_fork, catch_vfork
5064 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5070 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
5071 catch_fork_kind fork_kind;
5076 char *cond_string = NULL;
5078 ep_skip_leading_whitespace (&arg);
5080 /* The allowed syntax is:
5082 catch [v]fork if <cond>
5084 First, check if there's an if clause. */
5085 cond_string = ep_parse_optional_if_clause (&arg);
5087 if ((*arg != '\0') && !isspace (*arg))
5088 error ("Junk at end of arguments.");
5090 /* If this target supports it, create a fork or vfork catchpoint
5091 and enable reporting of such events. */
5095 create_fork_event_catchpoint (tempflag, cond_string);
5098 create_vfork_event_catchpoint (tempflag, cond_string);
5101 error ("unsupported or unknown fork kind; cannot catch it");
5107 catch_exec_command_1 (arg, tempflag, from_tty)
5112 char *cond_string = NULL;
5114 ep_skip_leading_whitespace (&arg);
5116 /* The allowed syntax is:
5118 catch exec if <cond>
5120 First, check if there's an if clause. */
5121 cond_string = ep_parse_optional_if_clause (&arg);
5123 if ((*arg != '\0') && !isspace (*arg))
5124 error ("Junk at end of arguments.");
5126 /* If this target supports it, create an exec catchpoint
5127 and enable reporting of such events. */
5128 create_exec_event_catchpoint (tempflag, cond_string);
5131 #if defined(SOLIB_ADD)
5133 catch_load_command_1 (arg, tempflag, from_tty)
5138 char *dll_pathname = NULL;
5139 char *cond_string = NULL;
5141 ep_skip_leading_whitespace (&arg);
5143 /* The allowed syntax is:
5145 catch load if <cond>
5146 catch load <filename>
5147 catch load <filename> if <cond>
5149 The user is not allowed to specify the <filename> after an
5152 We'll ignore the pathological case of a file named "if".
5154 First, check if there's an if clause. If so, then there
5155 cannot be a filename. */
5156 cond_string = ep_parse_optional_if_clause (&arg);
5158 /* If there was an if clause, then there cannot be a filename.
5159 Else, there might be a filename and an if clause. */
5160 if (cond_string == NULL)
5162 dll_pathname = ep_parse_optional_filename (&arg);
5163 ep_skip_leading_whitespace (&arg);
5164 cond_string = ep_parse_optional_if_clause (&arg);
5167 if ((*arg != '\0') && !isspace (*arg))
5168 error ("Junk at end of arguments.");
5170 /* Create a load breakpoint that only triggers when a load of
5171 the specified dll (or any dll, if no pathname was specified)
5173 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5174 dll_pathname, cond_string);
5178 catch_unload_command_1 (arg, tempflag, from_tty)
5183 char *dll_pathname = NULL;
5184 char *cond_string = NULL;
5186 ep_skip_leading_whitespace (&arg);
5188 /* The allowed syntax is:
5190 catch unload if <cond>
5191 catch unload <filename>
5192 catch unload <filename> if <cond>
5194 The user is not allowed to specify the <filename> after an
5197 We'll ignore the pathological case of a file named "if".
5199 First, check if there's an if clause. If so, then there
5200 cannot be a filename. */
5201 cond_string = ep_parse_optional_if_clause (&arg);
5203 /* If there was an if clause, then there cannot be a filename.
5204 Else, there might be a filename and an if clause. */
5205 if (cond_string == NULL)
5207 dll_pathname = ep_parse_optional_filename (&arg);
5208 ep_skip_leading_whitespace (&arg);
5209 cond_string = ep_parse_optional_if_clause (&arg);
5212 if ((*arg != '\0') && !isspace (*arg))
5213 error ("Junk at end of arguments.");
5215 /* Create an unload breakpoint that only triggers when an unload of
5216 the specified dll (or any dll, if no pathname was specified)
5218 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5219 dll_pathname, cond_string);
5221 #endif /* SOLIB_ADD */
5223 /* Commands to deal with catching exceptions. */
5225 /* Set a breakpoint at the specified callback routine for an
5226 exception event callback */
5229 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5232 enum exception_event_kind ex_event;
5233 struct symtab_and_line *sal;
5235 struct breakpoint *b;
5237 int thread = -1; /* All threads. */
5239 if (!sal) /* no exception support? */
5242 b = set_raw_breakpoint (*sal);
5243 set_breakpoint_count (breakpoint_count + 1);
5244 b->number = breakpoint_count;
5246 b->cond_string = (cond_string == NULL) ?
5247 NULL : savestring (cond_string, strlen (cond_string));
5249 b->addr_string = NULL;
5250 b->enable = enabled;
5251 b->disposition = tempflag ? del : donttouch;
5254 case EX_EVENT_THROW:
5255 b->type = bp_catch_throw;
5257 case EX_EVENT_CATCH:
5258 b->type = bp_catch_catch;
5260 default: /* error condition */
5262 b->enable = disabled;
5263 error ("Internal error -- invalid catchpoint kind");
5268 /* Deal with "catch catch" and "catch throw" commands */
5271 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5272 enum exception_event_kind ex_event;
5277 char *cond_string = NULL;
5278 struct symtab_and_line *sal = NULL;
5280 ep_skip_leading_whitespace (&arg);
5282 cond_string = ep_parse_optional_if_clause (&arg);
5284 if ((*arg != '\0') && !isspace (*arg))
5285 error ("Junk at end of arguments.");
5287 if ((ex_event != EX_EVENT_THROW) &&
5288 (ex_event != EX_EVENT_CATCH))
5289 error ("Unsupported or unknown exception event; cannot catch it");
5291 /* See if we can find a callback routine */
5292 sal = target_enable_exception_callback (ex_event, 1);
5296 /* We have callbacks from the runtime system for exceptions.
5297 Set a breakpoint on the sal found, if no errors */
5298 if (sal != (struct symtab_and_line *) -1)
5299 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5301 return; /* something went wrong with setting up callbacks */
5305 /* No callbacks from runtime system for exceptions.
5306 Try GNU C++ exception breakpoints using labels in debug info. */
5307 if (ex_event == EX_EVENT_CATCH)
5309 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5311 else if (ex_event == EX_EVENT_THROW)
5313 /* Set a breakpoint on __raise_exception () */
5315 warning ("Unsupported with this platform/compiler combination.");
5316 warning ("Perhaps you can achieve the effect you want by setting");
5317 warning ("a breakpoint on __raise_exception().");
5322 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5323 inside a catch_errors */
5326 cover_target_enable_exception_callback (arg)
5329 args_for_catchpoint_enable *args = arg;
5330 struct symtab_and_line *sal;
5331 sal = target_enable_exception_callback (args->kind, args->enable);
5334 else if (sal == (struct symtab_and_line *) -1)
5337 return 1; /*is valid */
5342 /* This is the original v.4.16 and earlier version of the
5343 catch_command_1() function. Now that other flavours of "catch"
5344 have been introduced, and since exception handling can be handled
5345 in other ways (through target ops) also, this is used only for the
5346 GNU C++ exception handling system.
5347 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5348 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5349 there was no code in GDB 4.16 for "catch throw".
5351 Called from catch_exception_command_1 () */
5355 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5360 /* First, translate ARG into something we can deal with in terms
5363 struct symtabs_and_lines sals;
5364 struct symtab_and_line sal;
5365 register struct expression *cond = 0;
5366 register struct breakpoint *b;
5370 INIT_SAL (&sal); /* initialize to zeroes */
5372 /* If no arg given, or if first arg is 'if ', all active catch clauses
5373 are breakpointed. */
5375 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5376 && (arg[2] == ' ' || arg[2] == '\t')))
5378 /* Grab all active catch clauses. */
5379 sals = get_catch_sals (0);
5383 /* Grab selected catch clauses. */
5384 error ("catch NAME not implemented");
5387 /* Not sure why this code has been disabled. I'm leaving
5388 it disabled. We can never come here now anyway
5389 since we don't allow the "catch NAME" syntax.
5392 /* This isn't used; I don't know what it was for. */
5393 sals = map_catch_names (arg, catch_breakpoint);
5401 for (i = 0; i < sals.nelts; i++)
5403 resolve_sal_pc (&sals.sals[i]);
5407 if (arg[0] == 'i' && arg[1] == 'f'
5408 && (arg[2] == ' ' || arg[2] == '\t'))
5409 cond = parse_exp_1 ((arg += 2, &arg),
5410 block_for_pc (sals.sals[i].pc), 0);
5412 error ("Junk at end of arguments.");
5417 for (i = 0; i < sals.nelts; i++)
5422 describe_other_breakpoints (sal.pc, sal.section);
5424 b = set_raw_breakpoint (sal);
5425 set_breakpoint_count (breakpoint_count + 1);
5426 b->number = breakpoint_count;
5428 /* Important -- this is an ordinary breakpoint. For platforms
5429 with callback support for exceptions,
5430 create_exception_catchpoint() will create special bp types
5431 (bp_catch_catch and bp_catch_throw), and there is code in
5432 insert_breakpoints() and elsewhere that depends on that. */
5433 b->type = bp_breakpoint;
5436 b->enable = enabled;
5437 b->disposition = tempflag ? del : donttouch;
5444 warning ("Multiple breakpoints were set.");
5445 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5447 free ((PTR) sals.sals);
5451 /* This creates a temporary internal breakpoint
5452 just to placate infrun */
5453 static struct breakpoint *
5454 create_temp_exception_breakpoint (pc)
5457 struct symtab_and_line sal;
5458 struct breakpoint *b;
5465 b = set_raw_breakpoint (sal);
5467 error ("Internal error -- couldn't set temp exception breakpoint");
5469 b->type = bp_breakpoint;
5470 b->disposition = del;
5471 b->enable = enabled;
5473 b->number = internal_breakpoint_number--;
5479 catch_command_1 (arg, tempflag, from_tty)
5485 /* The first argument may be an event name, such as "start" or "load".
5486 If so, then handle it as such. If it doesn't match an event name,
5487 then attempt to interpret it as an exception name. (This latter is
5488 the v4.16-and-earlier GDB meaning of the "catch" command.)
5490 First, try to find the bounds of what might be an event name. */
5491 char *arg1_start = arg;
5495 if (arg1_start == NULL)
5497 /* Old behaviour was to use pre-v-4.16 syntax */
5498 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5500 /* Now, this is not allowed */
5501 error ("Catch requires an event name.");
5504 arg1_end = ep_find_event_name_end (arg1_start);
5505 if (arg1_end == NULL)
5506 error ("catch requires an event");
5507 arg1_length = arg1_end + 1 - arg1_start;
5509 /* Try to match what we found against known event names. */
5510 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5512 error ("Catch of signal not yet implemented");
5514 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5516 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5517 tempflag, from_tty);
5519 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5521 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5522 tempflag, from_tty);
5524 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5526 error ("Catch of thread_start not yet implemented");
5528 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5530 error ("Catch of thread_exit not yet implemented");
5532 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5534 error ("Catch of thread_join not yet implemented");
5536 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5538 error ("Catch of start not yet implemented");
5540 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5542 error ("Catch of exit not yet implemented");
5544 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5546 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5547 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
5549 error ("Catch of fork not yet implemented");
5552 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5554 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5555 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
5557 error ("Catch of vfork not yet implemented");
5560 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5562 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5563 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
5565 error ("Catch of exec not yet implemented");
5568 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5570 #if defined(SOLIB_ADD)
5571 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
5573 error ("Catch of load not implemented");
5576 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5578 #if defined(SOLIB_ADD)
5579 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
5581 error ("Catch of load not implemented");
5584 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5586 error ("Catch of stop not yet implemented");
5589 /* This doesn't appear to be an event name */
5593 /* Pre-v.4.16 behaviour was to treat the argument
5594 as the name of an exception */
5595 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5596 /* Now this is not allowed */
5597 error ("Unknown event kind specified for catch");
5602 /* Used by the gui, could be made a worker for other things. */
5605 set_breakpoint_sal (sal)
5606 struct symtab_and_line sal;
5608 struct breakpoint *b;
5609 b = set_raw_breakpoint (sal);
5610 set_breakpoint_count (breakpoint_count + 1);
5611 b->number = breakpoint_count;
5612 b->type = bp_breakpoint;
5619 /* These aren't used; I don't know what they were for. */
5620 /* Disable breakpoints on all catch clauses described in ARGS. */
5622 disable_catch (args)
5625 /* Map the disable command to catch clauses described in ARGS. */
5628 /* Enable breakpoints on all catch clauses described in ARGS. */
5633 /* Map the disable command to catch clauses described in ARGS. */
5636 /* Delete breakpoints on all catch clauses in the active scope. */
5641 /* Map the delete command to catch clauses described in ARGS. */
5646 catch_command (arg, from_tty)
5650 catch_command_1 (arg, 0, from_tty);
5655 tcatch_command (arg, from_tty)
5659 catch_command_1 (arg, 1, from_tty);
5664 clear_command (arg, from_tty)
5668 register struct breakpoint *b, *b1;
5670 struct symtabs_and_lines sals;
5671 struct symtab_and_line sal;
5672 register struct breakpoint *found;
5677 sals = decode_line_spec (arg, 1);
5682 sals.sals = (struct symtab_and_line *)
5683 xmalloc (sizeof (struct symtab_and_line));
5684 INIT_SAL (&sal); /* initialize to zeroes */
5685 sal.line = default_breakpoint_line;
5686 sal.symtab = default_breakpoint_symtab;
5687 sal.pc = default_breakpoint_address;
5688 if (sal.symtab == 0)
5689 error ("No source file specified.");
5697 /* For each line spec given, delete bps which correspond
5698 to it. We do this in two loops: the first loop looks at
5699 the initial bp(s) in the chain which should be deleted,
5700 the second goes down the rest of the chain looking ahead
5701 one so it can take those bps off the chain without messing
5705 for (i = 0; i < sals.nelts; i++)
5707 /* If exact pc given, clear bpts at that pc.
5708 If line given (pc == 0), clear all bpts on specified line.
5709 If defaulting, clear all bpts on default line
5712 defaulting sal.pc != 0 tests to do
5717 1 0 <can't happen> */
5720 found = (struct breakpoint *) 0;
5723 while (breakpoint_chain
5724 /* Why don't we check here that this is not
5725 a watchpoint, etc., as we do below?
5726 I can't make it fail, but don't know
5727 what's stopping the failure: a watchpoint
5728 of the same address as "sal.pc" should
5729 wind up being deleted. */
5731 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5732 (overlay_debugging == 0 ||
5733 breakpoint_chain->section == sal.section))
5734 || ((default_match || (0 == sal.pc))
5735 && breakpoint_chain->source_file != NULL
5736 && sal.symtab != NULL
5737 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5738 && breakpoint_chain->line_number == sal.line)))
5741 b1 = breakpoint_chain;
5742 breakpoint_chain = b1->next;
5750 && b->next->type != bp_none
5751 && b->next->type != bp_watchpoint
5752 && b->next->type != bp_hardware_watchpoint
5753 && b->next->type != bp_read_watchpoint
5754 && b->next->type != bp_access_watchpoint
5755 && (((sal.pc && (b->next->address == sal.pc)) &&
5756 (overlay_debugging == 0 ||
5757 b->next->section == sal.section))
5758 || ((default_match || (0 == sal.pc))
5759 && b->next->source_file != NULL
5760 && sal.symtab != NULL
5761 && STREQ (b->next->source_file, sal.symtab->filename)
5762 && b->next->line_number == sal.line)))
5775 error ("No breakpoint at %s.", arg);
5777 error ("No breakpoint at this line.");
5781 from_tty = 1; /* Always report if deleted more than one */
5783 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
5784 breakpoints_changed ();
5788 printf_unfiltered ("%d ", found->number);
5790 delete_breakpoint (found);
5794 putchar_unfiltered ('\n');
5796 free ((PTR) sals.sals);
5799 /* Delete breakpoint in BS if they are `delete' breakpoints and
5800 all breakpoints that are marked for deletion, whether hit or not.
5801 This is called after any breakpoint is hit, or after errors. */
5804 breakpoint_auto_delete (bs)
5807 struct breakpoint *b, *temp;
5809 for (; bs; bs = bs->next)
5810 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
5812 delete_breakpoint (bs->breakpoint_at);
5814 ALL_BREAKPOINTS_SAFE (b, temp)
5816 if (b->disposition == del_at_next_stop)
5817 delete_breakpoint (b);
5821 /* Delete a breakpoint and clean up all traces of it in the data
5825 delete_breakpoint (bpt)
5826 struct breakpoint *bpt;
5828 register struct breakpoint *b;
5832 error ("Internal error (attempted to delete a NULL breakpoint)");
5835 /* Has this bp already been deleted? This can happen because multiple
5836 lists can hold pointers to bp's. bpstat lists are especial culprits.
5838 One example of this happening is a watchpoint's scope bp. When the
5839 scope bp triggers, we notice that the watchpoint is out of scope, and
5840 delete it. We also delete its scope bp. But the scope bp is marked
5841 "auto-deleting", and is already on a bpstat. That bpstat is then
5842 checked for auto-deleting bp's, which are deleted.
5844 A real solution to this problem might involve reference counts in bp's,
5845 and/or giving them pointers back to their referencing bpstat's, and
5846 teaching delete_breakpoint to only free a bp's storage when no more
5847 references were extent. A cheaper bandaid was chosen. */
5848 if (bpt->type == bp_none)
5851 if (delete_breakpoint_hook)
5852 delete_breakpoint_hook (bpt);
5855 remove_breakpoint (bpt, mark_uninserted);
5857 if (breakpoint_chain == bpt)
5858 breakpoint_chain = bpt->next;
5860 /* If we have callback-style exception catchpoints, don't go through
5861 the adjustments to the C++ runtime library etc. if the inferior
5862 isn't actually running. target_enable_exception_callback for a
5863 null target ops vector gives an undesirable error message, so we
5864 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
5865 exceptions are supported in this way, it's OK for now. FIXME */
5866 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5868 static char message1[] = "Error in deleting catchpoint %d:\n";
5869 static char message[sizeof (message1) + 30];
5870 args_for_catchpoint_enable args;
5872 /* Format possible error msg */
5873 sprintf (message, message1, bpt->number);
5874 args.kind = bpt->type == bp_catch_catch ?
5875 EX_EVENT_CATCH : EX_EVENT_THROW;
5877 catch_errors (cover_target_enable_exception_callback, &args,
5878 message, RETURN_MASK_ALL);
5885 b->next = bpt->next;
5889 /* Before turning off the visuals for the bp, check to see that
5890 there are no other bps at the same address. */
5897 clearIt = (b->address != bpt->address);
5904 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
5905 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
5909 check_duplicates (bpt->address, bpt->section);
5910 /* If this breakpoint was inserted, and there is another breakpoint
5911 at the same address, we need to insert the other breakpoint. */
5913 && bpt->type != bp_hardware_watchpoint
5914 && bpt->type != bp_read_watchpoint
5915 && bpt->type != bp_access_watchpoint
5916 && bpt->type != bp_catch_fork
5917 && bpt->type != bp_catch_vfork
5918 && bpt->type != bp_catch_exec)
5921 if (b->address == bpt->address
5922 && b->section == bpt->section
5924 && b->enable != disabled
5925 && b->enable != shlib_disabled
5926 && b->enable != call_disabled)
5930 if (b->type == bp_hardware_breakpoint)
5931 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
5933 val = target_insert_breakpoint (b->address, b->shadow_contents);
5937 target_terminal_ours_for_output ();
5938 warning ("Cannot insert breakpoint %d:", b->number);
5939 memory_error (val, b->address); /* which bombs us out */
5946 free_command_lines (&bpt->commands);
5949 if (bpt->cond_string != NULL)
5950 free (bpt->cond_string);
5951 if (bpt->addr_string != NULL)
5952 free (bpt->addr_string);
5953 if (bpt->exp != NULL)
5955 if (bpt->exp_string != NULL)
5956 free (bpt->exp_string);
5957 if (bpt->val != NULL)
5958 value_free (bpt->val);
5959 if (bpt->source_file != NULL)
5960 free (bpt->source_file);
5961 if (bpt->dll_pathname != NULL)
5962 free (bpt->dll_pathname);
5963 if (bpt->triggered_dll_pathname != NULL)
5964 free (bpt->triggered_dll_pathname);
5965 if (bpt->exec_pathname != NULL)
5966 free (bpt->exec_pathname);
5968 /* Be sure no bpstat's are pointing at it after it's been freed. */
5969 /* FIXME, how can we find all bpstat's?
5970 We just check stop_bpstat for now. */
5971 for (bs = stop_bpstat; bs; bs = bs->next)
5972 if (bs->breakpoint_at == bpt)
5974 bs->breakpoint_at = NULL;
5976 /* we'd call bpstat_clear_actions, but that free's stuff and due
5977 to the multiple pointers pointing to one item with no
5978 reference counts found anywhere through out the bpstat's (how
5979 do you spell fragile?), we don't want to free things twice --
5980 better a memory leak than a corrupt malloc pool! */
5981 bs->commands = NULL;
5984 /* On the chance that someone will soon try again to delete this same
5985 bp, we mark it as deleted before freeing its storage. */
5986 bpt->type = bp_none;
5992 delete_command (arg, from_tty)
5996 struct breakpoint *b, *temp;
6000 int breaks_to_delete = 0;
6002 /* Delete all breakpoints if no argument.
6003 Do not delete internal or call-dummy breakpoints, these
6004 have to be deleted with an explicit breakpoint number argument. */
6007 if (b->type != bp_call_dummy &&
6008 b->type != bp_shlib_event &&
6010 breaks_to_delete = 1;
6013 /* Ask user only if there are some breakpoints to delete. */
6015 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6017 ALL_BREAKPOINTS_SAFE (b, temp)
6019 if (b->type != bp_call_dummy &&
6020 b->type != bp_shlib_event &&
6022 delete_breakpoint (b);
6027 map_breakpoint_numbers (arg, delete_breakpoint);
6030 /* Reset a breakpoint given it's struct breakpoint * BINT.
6031 The value we return ends up being the return value from catch_errors.
6032 Unused in this case. */
6035 breakpoint_re_set_one (bint)
6038 /* get past catch_errs */
6039 struct breakpoint *b = (struct breakpoint *) bint;
6042 struct symtabs_and_lines sals;
6044 enum enable save_enable;
6049 warning ("attempted to reset apparently deleted breakpoint #%d?",
6053 case bp_hardware_breakpoint:
6055 case bp_catch_unload:
6056 if (b->addr_string == NULL)
6058 /* Anything without a string can't be re-set. */
6059 delete_breakpoint (b);
6062 /* In case we have a problem, disable this breakpoint. We'll restore
6063 its status if we succeed. */
6064 save_enable = b->enable;
6065 b->enable = disabled;
6067 set_language (b->language);
6068 input_radix = b->input_radix;
6070 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6071 for (i = 0; i < sals.nelts; i++)
6073 resolve_sal_pc (&sals.sals[i]);
6075 /* Reparse conditions, they might contain references to the
6077 if (b->cond_string != NULL)
6081 free ((PTR) b->cond);
6082 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6085 /* We need to re-set the breakpoint if the address changes... */
6086 if (b->address != sals.sals[i].pc
6087 /* ...or new and old breakpoints both have source files, and
6088 the source file name or the line number changes... */
6089 || (b->source_file != NULL
6090 && sals.sals[i].symtab != NULL
6091 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6092 || b->line_number != sals.sals[i].line)
6094 /* ...or we switch between having a source file and not having
6096 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6099 if (b->source_file != NULL)
6100 free (b->source_file);
6101 if (sals.sals[i].symtab == NULL)
6102 b->source_file = NULL;
6105 savestring (sals.sals[i].symtab->filename,
6106 strlen (sals.sals[i].symtab->filename));
6107 b->line_number = sals.sals[i].line;
6108 b->address = sals.sals[i].pc;
6110 /* Used to check for duplicates here, but that can
6111 cause trouble, as it doesn't check for disable
6116 /* Might be better to do this just once per breakpoint_re_set,
6117 rather than once for every breakpoint. */
6118 breakpoints_changed ();
6120 b->section = sals.sals[i].section;
6121 b->enable = save_enable; /* Restore it, this worked. */
6124 /* Now that this is re-enabled, check_duplicates
6126 check_duplicates (b->address, b->section);
6129 free ((PTR) sals.sals);
6133 case bp_hardware_watchpoint:
6134 case bp_read_watchpoint:
6135 case bp_access_watchpoint:
6136 innermost_block = NULL;
6137 /* The issue arises of what context to evaluate this in. The
6138 same one as when it was set, but what does that mean when
6139 symbols have been re-read? We could save the filename and
6140 functionname, but if the context is more local than that, the
6141 best we could do would be something like how many levels deep
6142 and which index at that particular level, but that's going to
6143 be less stable than filenames or function names. */
6145 /* So for now, just use a global context. */
6147 free ((PTR) b->exp);
6148 b->exp = parse_expression (b->exp_string);
6149 b->exp_valid_block = innermost_block;
6150 mark = value_mark ();
6152 value_free (b->val);
6153 b->val = evaluate_expression (b->exp);
6154 release_value (b->val);
6155 if (VALUE_LAZY (b->val))
6156 value_fetch_lazy (b->val);
6158 if (b->cond_string != NULL)
6162 free ((PTR) b->cond);
6163 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6165 if (b->enable == enabled)
6167 value_free_to_mark (mark);
6169 case bp_catch_catch:
6170 case bp_catch_throw:
6172 /* We needn't really do anything to reset these, since the mask
6173 that requests them is unaffected by e.g., new libraries being
6176 case bp_catch_vfork:
6181 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6183 /* Delete longjmp breakpoints, they will be reset later by
6184 breakpoint_re_set. */
6186 case bp_longjmp_resume:
6187 delete_breakpoint (b);
6190 /* This breakpoint is special, it's set up when the inferior
6191 starts and we really don't want to touch it. */
6192 case bp_shlib_event:
6194 /* Keep temporary breakpoints, which can be encountered when we step
6195 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6196 Otherwise these should have been blown away via the cleanup chain
6197 or by breakpoint_init_inferior when we rerun the executable. */
6200 case bp_watchpoint_scope:
6202 case bp_step_resume:
6209 /* Re-set all breakpoints after symbols have been re-loaded. */
6211 breakpoint_re_set ()
6213 struct breakpoint *b, *temp;
6214 enum language save_language;
6215 int save_input_radix;
6216 static char message1[] = "Error in re-setting breakpoint %d:\n";
6217 char message[sizeof (message1) + 30 /* slop */ ];
6219 save_language = current_language->la_language;
6220 save_input_radix = input_radix;
6221 ALL_BREAKPOINTS_SAFE (b, temp)
6223 /* Format possible error msg */
6224 sprintf (message, message1, b->number);
6225 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6227 set_language (save_language);
6228 input_radix = save_input_radix;
6230 #ifdef GET_LONGJMP_TARGET
6231 create_longjmp_breakpoint ("longjmp");
6232 create_longjmp_breakpoint ("_longjmp");
6233 create_longjmp_breakpoint ("siglongjmp");
6234 create_longjmp_breakpoint ("_siglongjmp");
6235 create_longjmp_breakpoint (NULL);
6239 /* Took this out (temporarily at least), since it produces an extra
6240 blank line at startup. This messes up the gdbtests. -PB */
6241 /* Blank line to finish off all those mention() messages we just printed. */
6242 printf_filtered ("\n");
6246 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6247 If from_tty is nonzero, it prints a message to that effect,
6248 which ends with a period (no newline). */
6250 /* Reset the thread number of this breakpoint:
6252 - If the breakpoint is for all threads, leave it as-is.
6253 - Else, reset it to the current thread for inferior_pid. */
6255 breakpoint_re_set_thread (b)
6256 struct breakpoint *b;
6258 if (b->thread != -1)
6260 if (in_thread_list (inferior_pid))
6261 b->thread = pid_to_thread_id (inferior_pid);
6266 set_ignore_count (bptnum, count, from_tty)
6267 int bptnum, count, from_tty;
6269 register struct breakpoint *b;
6275 if (b->number == bptnum)
6277 b->ignore_count = count;
6280 else if (count == 0)
6281 printf_filtered ("Will stop next time breakpoint %d is reached.",
6283 else if (count == 1)
6284 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6287 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6289 breakpoints_changed ();
6293 error ("No breakpoint number %d.", bptnum);
6296 /* Clear the ignore counts of all breakpoints. */
6298 breakpoint_clear_ignore_counts ()
6300 struct breakpoint *b;
6303 b->ignore_count = 0;
6306 /* Command to set ignore-count of breakpoint N to COUNT. */
6309 ignore_command (args, from_tty)
6317 error_no_arg ("a breakpoint number");
6319 num = get_number (&p);
6322 error ("Second argument (specified ignore-count) is missing.");
6324 set_ignore_count (num,
6325 longest_to_int (value_as_long (parse_and_eval (p))),
6327 printf_filtered ("\n");
6328 breakpoints_changed ();
6331 /* Call FUNCTION on each of the breakpoints
6332 whose numbers are given in ARGS. */
6335 map_breakpoint_numbers (args, function)
6337 void (*function) PARAMS ((struct breakpoint *));
6339 register char *p = args;
6342 register struct breakpoint *b;
6345 error_no_arg ("one or more breakpoint numbers");
6351 num = get_number (&p1);
6354 if (b->number == num)
6356 struct breakpoint *related_breakpoint = b->related_breakpoint;
6358 if (related_breakpoint)
6359 function (related_breakpoint);
6362 printf_unfiltered ("No breakpoint number %d.\n", num);
6369 disable_breakpoint (bpt)
6370 struct breakpoint *bpt;
6372 /* Never disable a watchpoint scope breakpoint; we want to
6373 hit them when we leave scope so we can delete both the
6374 watchpoint and its scope breakpoint at that time. */
6375 if (bpt->type == bp_watchpoint_scope)
6378 bpt->enable = disabled;
6380 check_duplicates (bpt->address, bpt->section);
6382 if (modify_breakpoint_hook)
6383 modify_breakpoint_hook (bpt);
6388 disable_command (args, from_tty)
6392 register struct breakpoint *bpt;
6394 ALL_BREAKPOINTS (bpt)
6398 warning ("attempted to disable apparently deleted breakpoint #%d?",
6403 case bp_catch_unload:
6405 case bp_catch_vfork:
6407 case bp_catch_catch:
6408 case bp_catch_throw:
6409 case bp_hardware_breakpoint:
6411 case bp_hardware_watchpoint:
6412 case bp_read_watchpoint:
6413 case bp_access_watchpoint:
6414 disable_breakpoint (bpt);
6419 map_breakpoint_numbers (args, disable_breakpoint);
6423 do_enable_breakpoint (bpt, disposition)
6424 struct breakpoint *bpt;
6425 enum bpdisp disposition;
6427 struct frame_info *save_selected_frame = NULL;
6428 int save_selected_frame_level = -1;
6429 int target_resources_ok, other_type_used;
6432 if (bpt->type == bp_hardware_breakpoint)
6435 i = hw_breakpoint_used_count ();
6436 target_resources_ok =
6437 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6439 if (target_resources_ok == 0)
6440 error ("No hardware breakpoint support in the target.");
6441 else if (target_resources_ok < 0)
6442 error ("Hardware breakpoints used exceeds limit.");
6445 bpt->enable = enabled;
6446 bpt->disposition = disposition;
6447 check_duplicates (bpt->address, bpt->section);
6448 breakpoints_changed ();
6450 if (bpt->type == bp_watchpoint ||
6451 bpt->type == bp_hardware_watchpoint ||
6452 bpt->type == bp_read_watchpoint ||
6453 bpt->type == bp_access_watchpoint)
6455 if (bpt->exp_valid_block != NULL)
6457 struct frame_info *fr =
6459 /* Ensure that we have the current frame. Else, this
6460 next query may pessimistically be answered as, "No,
6461 not within current scope". */
6462 get_current_frame ();
6463 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6467 Cannot enable watchpoint %d because the block in which its expression\n\
6468 is valid is not currently in scope.\n", bpt->number);
6469 bpt->enable = disabled;
6473 save_selected_frame = selected_frame;
6474 save_selected_frame_level = selected_frame_level;
6475 select_frame (fr, -1);
6478 value_free (bpt->val);
6479 mark = value_mark ();
6480 bpt->val = evaluate_expression (bpt->exp);
6481 release_value (bpt->val);
6482 if (VALUE_LAZY (bpt->val))
6483 value_fetch_lazy (bpt->val);
6485 if (bpt->type == bp_hardware_watchpoint ||
6486 bpt->type == bp_read_watchpoint ||
6487 bpt->type == bp_access_watchpoint)
6489 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6490 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6492 /* Hack around 'unused var' error for some targets here */
6494 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6495 bpt->type, i + mem_cnt, other_type_used);
6496 /* we can consider of type is bp_hardware_watchpoint, convert to
6497 bp_watchpoint in the following condition */
6498 if (target_resources_ok < 0)
6501 Cannot enable watchpoint %d because target watch resources\n\
6502 have been allocated for other watchpoints.\n", bpt->number);
6503 bpt->enable = disabled;
6504 value_free_to_mark (mark);
6509 if (save_selected_frame_level >= 0)
6510 select_and_print_frame (save_selected_frame,
6511 save_selected_frame_level);
6512 value_free_to_mark (mark);
6514 if (modify_breakpoint_hook)
6515 modify_breakpoint_hook (bpt);
6519 enable_breakpoint (bpt)
6520 struct breakpoint *bpt;
6522 do_enable_breakpoint (bpt, bpt->disposition);
6525 /* The enable command enables the specified breakpoints (or all defined
6526 breakpoints) so they once again become (or continue to be) effective
6527 in stopping the inferior. */
6531 enable_command (args, from_tty)
6535 register struct breakpoint *bpt;
6537 ALL_BREAKPOINTS (bpt)
6541 warning ("attempted to enable apparently deleted breakpoint #%d?",
6546 case bp_catch_unload:
6548 case bp_catch_vfork:
6550 case bp_catch_catch:
6551 case bp_catch_throw:
6552 case bp_hardware_breakpoint:
6554 case bp_hardware_watchpoint:
6555 case bp_read_watchpoint:
6556 case bp_access_watchpoint:
6557 enable_breakpoint (bpt);
6562 map_breakpoint_numbers (args, enable_breakpoint);
6566 enable_once_breakpoint (bpt)
6567 struct breakpoint *bpt;
6569 do_enable_breakpoint (bpt, disable);
6574 enable_once_command (args, from_tty)
6578 map_breakpoint_numbers (args, enable_once_breakpoint);
6582 enable_delete_breakpoint (bpt)
6583 struct breakpoint *bpt;
6585 do_enable_breakpoint (bpt, del);
6590 enable_delete_command (args, from_tty)
6594 map_breakpoint_numbers (args, enable_delete_breakpoint);
6597 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
6599 struct symtabs_and_lines
6600 decode_line_spec_1 (string, funfirstline)
6604 struct symtabs_and_lines sals;
6606 error ("Empty line specification.");
6607 if (default_breakpoint_valid)
6608 sals = decode_line_1 (&string, funfirstline,
6609 default_breakpoint_symtab,
6610 default_breakpoint_line,
6613 sals = decode_line_1 (&string, funfirstline,
6614 (struct symtab *) NULL, 0, (char ***) NULL);
6616 error ("Junk at end of line specification: %s", string);
6621 _initialize_breakpoint ()
6623 struct cmd_list_element *c;
6625 breakpoint_chain = 0;
6626 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6627 before a breakpoint is set. */
6628 breakpoint_count = 0;
6630 add_com ("ignore", class_breakpoint, ignore_command,
6631 "Set ignore-count of breakpoint number N to COUNT.\n\
6632 Usage is `ignore N COUNT'.");
6634 add_com_alias ("bc", "ignore", class_breakpoint, 1);
6636 add_com ("commands", class_breakpoint, commands_command,
6637 "Set commands to be executed when a breakpoint is hit.\n\
6638 Give breakpoint number as argument after \"commands\".\n\
6639 With no argument, the targeted breakpoint is the last one set.\n\
6640 The commands themselves follow starting on the next line.\n\
6641 Type a line containing \"end\" to indicate the end of them.\n\
6642 Give \"silent\" as the first line to make the breakpoint silent;\n\
6643 then no output is printed when it is hit, except what the commands print.");
6645 add_com ("condition", class_breakpoint, condition_command,
6646 "Specify breakpoint number N to break only if COND is true.\n\
6647 Usage is `condition N COND', where N is an integer and COND is an\n\
6648 expression to be evaluated whenever breakpoint N is reached. ");
6650 add_com ("tbreak", class_breakpoint, tbreak_command,
6651 "Set a temporary breakpoint. Args like \"break\" command.\n\
6652 Like \"break\" except the breakpoint is only temporary,\n\
6653 so it will be deleted when hit. Equivalent to \"break\" followed\n\
6654 by using \"enable delete\" on the breakpoint number.");
6655 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6656 "Set temporary breakpoint at procedure exit. Either there should\n\
6657 be no argument or the argument must be a depth.\n");
6659 add_com ("hbreak", class_breakpoint, hbreak_command,
6660 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6661 Like \"break\" except the breakpoint requires hardware support,\n\
6662 some target hardware may not have this support.");
6664 add_com ("thbreak", class_breakpoint, thbreak_command,
6665 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6666 Like \"hbreak\" except the breakpoint is only temporary,\n\
6667 so it will be deleted when hit.");
6669 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6670 "Enable some breakpoints.\n\
6671 Give breakpoint numbers (separated by spaces) as arguments.\n\
6672 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6673 This is used to cancel the effect of the \"disable\" command.\n\
6674 With a subcommand you can enable temporarily.",
6675 &enablelist, "enable ", 1, &cmdlist);
6677 add_com ("ab", class_breakpoint, enable_command,
6678 "Enable some breakpoints.\n\
6679 Give breakpoint numbers (separated by spaces) as arguments.\n\
6680 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6681 This is used to cancel the effect of the \"disable\" command.\n\
6682 With a subcommand you can enable temporarily.");
6684 add_com_alias ("en", "enable", class_breakpoint, 1);
6686 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
6687 "Enable some breakpoints.\n\
6688 Give breakpoint numbers (separated by spaces) as arguments.\n\
6689 This is used to cancel the effect of the \"disable\" command.\n\
6690 May be abbreviated to simply \"enable\".\n",
6691 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
6693 add_cmd ("once", no_class, enable_once_command,
6694 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6695 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6698 add_cmd ("delete", no_class, enable_delete_command,
6699 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6700 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6703 add_cmd ("delete", no_class, enable_delete_command,
6704 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6705 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6708 add_cmd ("once", no_class, enable_once_command,
6709 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6710 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6713 add_prefix_cmd ("disable", class_breakpoint, disable_command,
6714 "Disable some breakpoints.\n\
6715 Arguments are breakpoint numbers with spaces in between.\n\
6716 To disable all breakpoints, give no argument.\n\
6717 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6718 &disablelist, "disable ", 1, &cmdlist);
6719 add_com_alias ("dis", "disable", class_breakpoint, 1);
6720 add_com_alias ("disa", "disable", class_breakpoint, 1);
6722 add_com ("sb", class_breakpoint, disable_command,
6723 "Disable some breakpoints.\n\
6724 Arguments are breakpoint numbers with spaces in between.\n\
6725 To disable all breakpoints, give no argument.\n\
6726 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6728 add_cmd ("breakpoints", class_alias, disable_command,
6729 "Disable some breakpoints.\n\
6730 Arguments are breakpoint numbers with spaces in between.\n\
6731 To disable all breakpoints, give no argument.\n\
6732 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6733 This command may be abbreviated \"disable\".",
6736 add_prefix_cmd ("delete", class_breakpoint, delete_command,
6737 "Delete some breakpoints or auto-display expressions.\n\
6738 Arguments are breakpoint numbers with spaces in between.\n\
6739 To delete all breakpoints, give no argument.\n\
6741 Also a prefix command for deletion of other GDB objects.\n\
6742 The \"unset\" command is also an alias for \"delete\".",
6743 &deletelist, "delete ", 1, &cmdlist);
6744 add_com_alias ("d", "delete", class_breakpoint, 1);
6746 add_com ("db", class_breakpoint, delete_command,
6747 "Delete some breakpoints.\n\
6748 Arguments are breakpoint numbers with spaces in between.\n\
6749 To delete all breakpoints, give no argument.\n");
6751 add_cmd ("breakpoints", class_alias, delete_command,
6752 "Delete some breakpoints or auto-display expressions.\n\
6753 Arguments are breakpoint numbers with spaces in between.\n\
6754 To delete all breakpoints, give no argument.\n\
6755 This command may be abbreviated \"delete\".",
6758 add_com ("clear", class_breakpoint, clear_command,
6759 concat ("Clear breakpoint at specified line or function.\n\
6760 Argument may be line number, function name, or \"*\" and an address.\n\
6761 If line number is specified, all breakpoints in that line are cleared.\n\
6762 If function is specified, breakpoints at beginning of function are cleared.\n\
6763 If an address is specified, breakpoints at that address are cleared.\n\n",
6764 "With no argument, clears all breakpoints in the line that the selected frame\n\
6767 See also the \"delete\" command which clears breakpoints by number.", NULL));
6769 add_com ("break", class_breakpoint, break_command,
6770 concat ("Set breakpoint at specified line or function.\n\
6771 Argument may be line number, function name, or \"*\" and an address.\n\
6772 If line number is specified, break at start of code for that line.\n\
6773 If function is specified, break at start of code for that function.\n\
6774 If an address is specified, break at that exact address.\n",
6775 "With no arg, uses current execution address of selected stack frame.\n\
6776 This is useful for breaking on return to a stack frame.\n\
6778 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6780 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6781 add_com_alias ("b", "break", class_run, 1);
6782 add_com_alias ("br", "break", class_run, 1);
6783 add_com_alias ("bre", "break", class_run, 1);
6784 add_com_alias ("brea", "break", class_run, 1);
6786 add_com ("xbreak", class_breakpoint, break_at_finish_command,
6787 concat ("Set breakpoint at procedure exit. \n\
6788 Argument may be function name, or \"*\" and an address.\n\
6789 If function is specified, break at end of code for that function.\n\
6790 If an address is specified, break at the end of the function that contains \n\
6791 that exact address.\n",
6792 "With no arg, uses current execution address of selected stack frame.\n\
6793 This is useful for breaking on return to a stack frame.\n\
6795 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6797 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6798 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6799 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6800 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6801 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6805 add_com_alias ("ba", "break", class_breakpoint, 1);
6806 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6807 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
6808 "Set breakpoint at procedure exit. Either there should\n\
6809 be no argument or the argument must be a depth.\n");
6814 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
6815 "Break in function/address or break at a line in the current file.",
6816 &stoplist, "stop ", 1, &cmdlist);
6817 add_cmd ("in", class_breakpoint, stopin_command,
6818 "Break in function or address.\n", &stoplist);
6819 add_cmd ("at", class_breakpoint, stopat_command,
6820 "Break at a line in the current file.\n", &stoplist);
6821 add_com ("status", class_info, breakpoints_info,
6822 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6823 The \"Type\" column indicates one of:\n\
6824 \tbreakpoint - normal breakpoint\n\
6825 \twatchpoint - watchpoint\n\
6826 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6827 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6828 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6829 address and file/line number respectively.\n\n",
6830 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6831 are set to the address of the last breakpoint listed.\n\n\
6832 Convenience variable \"$bpnum\" contains the number of the last\n\
6833 breakpoint set.", NULL));
6836 add_info ("breakpoints", breakpoints_info,
6837 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6838 The \"Type\" column indicates one of:\n\
6839 \tbreakpoint - normal breakpoint\n\
6840 \twatchpoint - watchpoint\n\
6841 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6842 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6843 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6844 address and file/line number respectively.\n\n",
6845 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6846 are set to the address of the last breakpoint listed.\n\n\
6847 Convenience variable \"$bpnum\" contains the number of the last\n\
6848 breakpoint set.", NULL));
6851 add_com ("lb", class_breakpoint, breakpoints_info,
6852 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6853 The \"Type\" column indicates one of:\n\
6854 \tbreakpoint - normal breakpoint\n\
6855 \twatchpoint - watchpoint\n\
6856 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6857 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6858 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6859 address and file/line number respectively.\n\n",
6860 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6861 are set to the address of the last breakpoint listed.\n\n\
6862 Convenience variable \"$bpnum\" contains the number of the last\n\
6863 breakpoint set.", NULL));
6865 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
6866 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
6867 The \"Type\" column indicates one of:\n\
6868 \tbreakpoint - normal breakpoint\n\
6869 \twatchpoint - watchpoint\n\
6870 \tlongjmp - internal breakpoint used to step through longjmp()\n\
6871 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6872 \tuntil - internal breakpoint used by the \"until\" command\n\
6873 \tfinish - internal breakpoint used by the \"finish\" command\n",
6874 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6875 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6876 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6877 address and file/line number respectively.\n\n",
6878 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6879 are set to the address of the last breakpoint listed.\n\n\
6880 Convenience variable \"$bpnum\" contains the number of the last\n\
6881 breakpoint set.", NULL),
6882 &maintenanceinfolist);
6884 add_com ("catch", class_breakpoint, catch_command,
6885 "Set catchpoints to catch events.\n\
6886 Raised signals may be caught:\n\
6887 \tcatch signal - all signals\n\
6888 \tcatch signal <signame> - a particular signal\n\
6889 Raised exceptions may be caught:\n\
6890 \tcatch throw - all exceptions, when thrown\n\
6891 \tcatch throw <exceptname> - a particular exception, when thrown\n\
6892 \tcatch catch - all exceptions, when caught\n\
6893 \tcatch catch <exceptname> - a particular exception, when caught\n\
6894 Thread or process events may be caught:\n\
6895 \tcatch thread_start - any threads, just after creation\n\
6896 \tcatch thread_exit - any threads, just before expiration\n\
6897 \tcatch thread_join - any threads, just after joins\n\
6898 Process events may be caught:\n\
6899 \tcatch start - any processes, just after creation\n\
6900 \tcatch exit - any processes, just before expiration\n\
6901 \tcatch fork - calls to fork()\n\
6902 \tcatch vfork - calls to vfork()\n\
6903 \tcatch exec - calls to exec()\n\
6904 Dynamically-linked library events may be caught:\n\
6905 \tcatch load - loads of any library\n\
6906 \tcatch load <libname> - loads of a particular library\n\
6907 \tcatch unload - unloads of any library\n\
6908 \tcatch unload <libname> - unloads of a particular library\n\
6909 The act of your program's execution stopping may also be caught:\n\
6911 C++ exceptions may be caught:\n\
6912 \tcatch throw - all exceptions, when thrown\n\
6913 \tcatch catch - all exceptions, when caught\n\
6915 Do \"help set follow-fork-mode\" for info on debugging your program\n\
6916 after a fork or vfork is caught.\n\n\
6917 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
6919 add_com ("tcatch", class_breakpoint, tcatch_command,
6920 "Set temporary catchpoints to catch events.\n\
6921 Args like \"catch\" command.\n\
6922 Like \"catch\" except the catchpoint is only temporary,\n\
6923 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6924 by using \"enable delete\" on the catchpoint number.");
6926 add_com ("watch", class_breakpoint, watch_command,
6927 "Set a watchpoint for an expression.\n\
6928 A watchpoint stops execution of your program whenever the value of\n\
6929 an expression changes.");
6931 add_com ("rwatch", class_breakpoint, rwatch_command,
6932 "Set a read watchpoint for an expression.\n\
6933 A watchpoint stops execution of your program whenever the value of\n\
6934 an expression is read.");
6936 add_com ("awatch", class_breakpoint, awatch_command,
6937 "Set a watchpoint for an expression.\n\
6938 A watchpoint stops execution of your program whenever the value of\n\
6939 an expression is either read or written.");
6941 add_info ("watchpoints", breakpoints_info,
6942 "Synonym for ``info breakpoints''.");
6945 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
6946 (char *) &can_use_hw_watchpoints,
6947 "Set debugger's willingness to use watchpoint hardware.\n\
6948 If zero, gdb will not use hardware for new watchpoints, even if\n\
6949 such is available. (However, any hardware watchpoints that were\n\
6950 created before setting this to nonzero, will continue to use watchpoint\n\
6953 add_show_from_set (c, &showlist);
6955 can_use_hw_watchpoints = 1;