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 #include "gdb-events.h"
45 /* Prototypes for local functions. */
48 catch_command_1 PARAMS ((char *, int, int));
51 enable_delete_command PARAMS ((char *, int));
54 enable_delete_breakpoint PARAMS ((struct breakpoint *));
57 enable_once_command PARAMS ((char *, int));
60 enable_once_breakpoint PARAMS ((struct breakpoint *));
63 disable_command PARAMS ((char *, int));
66 enable_command PARAMS ((char *, int));
69 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
72 ignore_command PARAMS ((char *, int));
74 static int breakpoint_re_set_one PARAMS ((PTR));
77 clear_command PARAMS ((char *, int));
80 catch_command PARAMS ((char *, int));
83 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
85 static struct symtabs_and_lines
86 get_catch_sals PARAMS ((int));
89 watch_command PARAMS ((char *, int));
92 can_use_hardware_watchpoint PARAMS ((struct value *));
94 static void break_at_finish_command PARAMS ((char *, int));
95 static void break_at_finish_at_depth_command PARAMS ((char *, int));
98 tbreak_command PARAMS ((char *, int));
100 static void tbreak_at_finish_command PARAMS ((char *, int));
103 break_command_1 PARAMS ((char *, int, int));
106 mention PARAMS ((struct breakpoint *));
109 set_raw_breakpoint PARAMS ((struct symtab_and_line));
112 check_duplicates PARAMS ((CORE_ADDR, asection *));
115 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
118 breakpoints_info PARAMS ((char *, int));
121 breakpoint_1 PARAMS ((int, int));
124 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
126 static int breakpoint_cond_eval PARAMS ((PTR));
129 cleanup_executing_breakpoints PARAMS ((PTR));
132 commands_command PARAMS ((char *, int));
135 condition_command PARAMS ((char *, int));
138 get_number PARAMS ((char **));
141 set_breakpoint_count PARAMS ((int));
144 static struct breakpoint *
145 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
156 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
158 static int print_it_normal PARAMS ((bpstat));
162 enum exception_event_kind kind;
165 args_for_catchpoint_enable;
167 static int watchpoint_check PARAMS ((PTR));
169 static int cover_target_enable_exception_callback PARAMS ((PTR));
171 static int print_it_done PARAMS ((bpstat));
173 static int print_it_noop PARAMS ((bpstat));
175 static void maintenance_info_breakpoints PARAMS ((char *, int));
177 #ifdef GET_LONGJMP_TARGET
178 static void create_longjmp_breakpoint PARAMS ((char *));
181 static int hw_breakpoint_used_count PARAMS ((void));
183 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
185 static void hbreak_command PARAMS ((char *, int));
187 static void thbreak_command PARAMS ((char *, int));
189 static void watch_command_1 PARAMS ((char *, int, int));
191 static void rwatch_command PARAMS ((char *, int));
193 static void awatch_command PARAMS ((char *, int));
195 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
197 static void solib_load_unload_1 PARAMS ((char *hookname,
201 enum bptype bp_kind));
203 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
205 enum bptype bp_kind));
207 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
211 static void break_at_finish_command_1 PARAMS ((char *arg,
215 static void stop_command PARAMS ((char *arg, int from_tty));
217 static void stopin_command PARAMS ((char *arg, int from_tty));
219 static void stopat_command PARAMS ((char *arg, int from_tty));
221 static char *ep_find_event_name_end PARAMS ((char *arg));
223 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
225 static char *ep_parse_optional_filename PARAMS ((char **arg));
227 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
230 static void create_exception_catchpoint
231 PARAMS ((int tempflag, char *cond_string,
232 enum exception_event_kind ex_event,
233 struct symtab_and_line * sal));
235 static void catch_exception_command_1
236 PARAMS ((enum exception_event_kind ex_event,
237 char *arg, int tempflag, int from_tty));
239 static void tcatch_command PARAMS ((char *arg, int from_tty));
241 static void ep_skip_leading_whitespace PARAMS ((char **s));
243 /* Prototypes for exported functions. */
246 awatch_command PARAMS ((char *, int));
249 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
251 /* If FALSE, gdb will not use hardware support for watchpoints, even
252 if such is available. */
253 static int can_use_hw_watchpoints;
255 void delete_command PARAMS ((char *, int));
257 void _initialize_breakpoint PARAMS ((void));
259 void set_breakpoint_count PARAMS ((int));
261 extern int addressprint; /* Print machine addresses? */
263 #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
264 static int internal_breakpoint_number = -1;
267 /* Are we executing breakpoint commands? */
268 static int executing_breakpoint_commands;
270 /* Walk the following statement or block through all breakpoints.
271 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
274 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
276 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
277 for (b = breakpoint_chain; \
278 b? (tmp=b->next, 1): 0; \
281 /* True if SHIFT_INST_REGS defined, false otherwise. */
283 int must_shift_inst_regs =
284 #if defined(SHIFT_INST_REGS)
291 /* True if breakpoint hit counts should be displayed in breakpoint info. */
293 int show_breakpoint_hit_counts = 1;
295 /* Chain of all breakpoints defined. */
297 struct breakpoint *breakpoint_chain;
299 /* Number of last breakpoint made. */
301 int breakpoint_count;
303 /* Pointer to current exception event record */
304 static struct exception_event_record *current_exception_event;
306 /* Indicator of whether exception catchpoints should be nuked
307 between runs of a program */
308 int exception_catchpoints_are_fragile = 0;
310 /* Indicator of when exception catchpoints set-up should be
311 reinitialized -- e.g. when program is re-run */
312 int exception_support_initialized = 0;
314 /* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
318 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
319 or undefined results are guaranteed.
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
327 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
328 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
331 /* This function returns a pointer to the string representation of the
332 pathname of the dynamically-linked library that has just been
335 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
336 TRUE, or undefined results are guaranteed.
338 This string's contents are only valid immediately after the
339 inferior has stopped in the dynamic linker hook, and becomes
340 invalid as soon as the inferior is continued. Clients should make
341 a copy of this string if they wish to continue the inferior and
342 then access the string. */
344 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
345 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
348 /* This function is called by the "catch load" command. It allows the
349 debugger to be notified by the dynamic linker when a specified
350 library file (or any library file, if filename is NULL) is loaded. */
352 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
353 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
354 error ("catch of library loads not yet implemented on this platform")
357 /* This function is called by the "catch unload" command. It allows
358 the debugger to be notified by the dynamic linker when a specified
359 library file (or any library file, if filename is NULL) is
362 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
363 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
364 error ("catch of library unloads not yet implemented on this platform")
367 /* Set breakpoint count to NUM. */
370 set_breakpoint_count (num)
373 breakpoint_count = num;
374 set_internalvar (lookup_internalvar ("bpnum"),
375 value_from_longest (builtin_type_int, (LONGEST) num));
378 /* Used in run_command to zero the hit count when a new run starts. */
381 clear_breakpoint_hit_counts ()
383 struct breakpoint *b;
389 /* Default address, symtab and line to put a breakpoint at
390 for "break" command with no arg.
391 if default_breakpoint_valid is zero, the other three are
392 not valid, and "break" with no arg is an error.
394 This set by print_stack_frame, which calls set_default_breakpoint. */
396 int default_breakpoint_valid;
397 CORE_ADDR default_breakpoint_address;
398 struct symtab *default_breakpoint_symtab;
399 int default_breakpoint_line;
401 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
402 Advance *PP after the string and any trailing whitespace.
404 Currently the string can either be a number or "$" followed by the name
405 of a convenience variable. Making it an expression wouldn't work well
406 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
415 /* Empty line means refer to the last breakpoint. */
416 return breakpoint_count;
419 /* Make a copy of the name, so we can null-terminate it
420 to pass to lookup_internalvar(). */
425 while (isalnum (*p) || *p == '_')
427 varname = (char *) alloca (p - start + 1);
428 strncpy (varname, start, p - start);
429 varname[p - start] = '\0';
430 val = value_of_internalvar (lookup_internalvar (varname));
431 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
433 "Convenience variables used to specify breakpoints must have integer values."
435 retval = (int) value_as_long (val);
441 while (*p >= '0' && *p <= '9')
444 /* There is no number here. (e.g. "cond a == b"). */
445 error_no_arg ("breakpoint number");
448 if (!(isspace (*p) || *p == '\0'))
449 error ("breakpoint number expected");
456 /* condition N EXP -- set break condition of breakpoint N to EXP. */
459 condition_command (arg, from_tty)
463 register struct breakpoint *b;
468 error_no_arg ("breakpoint number");
471 bnum = get_number (&p);
474 if (b->number == bnum)
478 free ((PTR) b->cond);
481 if (b->cond_string != NULL)
482 free ((PTR) b->cond_string);
487 b->cond_string = NULL;
489 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
494 /* I don't know if it matters whether this is the string the user
495 typed in or the decompiled expression. */
496 b->cond_string = savestring (arg, strlen (arg));
497 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
499 error ("Junk at end of expression");
501 breakpoints_changed ();
505 error ("No breakpoint number %d.", bnum);
510 commands_command (arg, from_tty)
514 register struct breakpoint *b;
517 struct command_line *l;
519 /* If we allowed this, we would have problems with when to
520 free the storage, if we change the commands currently
523 if (executing_breakpoint_commands)
524 error ("Can't use the \"commands\" command among a breakpoint's commands.");
527 bnum = get_number (&p);
529 error ("Unexpected extra arguments following breakpoint number.");
532 if (b->number == bnum)
536 "Type commands for when breakpoint %d is hit, one per line.",
538 l = read_command_lines (tmpbuf, from_tty);
539 free_command_lines (&b->commands);
541 breakpoints_changed ();
544 error ("No breakpoint number %d.", bnum);
547 /* Like target_read_memory() but if breakpoints are inserted, return
548 the shadow contents instead of the breakpoints themselves.
550 Read "memory data" from whatever target or inferior we have.
551 Returns zero if successful, errno value if not. EIO is used
552 for address out of bounds. If breakpoints are inserted, returns
553 shadow contents, not the breakpoints themselves. From breakpoint.c. */
556 read_memory_nobpt (memaddr, myaddr, len)
562 struct breakpoint *b;
563 CORE_ADDR bp_addr = 0;
566 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
567 /* No breakpoints on this machine. */
568 return target_read_memory (memaddr, myaddr, len);
572 if (b->type == bp_none)
573 warning ("reading through apparently deleted breakpoint #%d?",
576 /* memory breakpoint? */
577 if (b->type == bp_watchpoint
578 || b->type == bp_hardware_watchpoint
579 || b->type == bp_read_watchpoint
580 || b->type == bp_access_watchpoint)
585 /* Addresses and length of the part of the breakpoint that
587 /* XXXX The m68k, sh and h8300 have different local and remote
588 breakpoint values. BREAKPOINT_FROM_PC still manages to
589 correctly determine the breakpoints memory address and size
590 for these targets. */
591 bp_addr = b->address;
593 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
598 if (bp_addr + bp_size <= memaddr)
599 /* The breakpoint is entirely before the chunk of memory we
602 if (bp_addr >= memaddr + len)
603 /* The breakpoint is entirely after the chunk of memory we are
606 /* Copy the breakpoint from the shadow contents, and recurse for
607 the things before and after. */
609 /* Offset within shadow_contents. */
612 if (bp_addr < memaddr)
614 /* Only copy the second part of the breakpoint. */
615 bp_size -= memaddr - bp_addr;
616 bptoffset = memaddr - bp_addr;
620 if (bp_addr + bp_size > memaddr + len)
622 /* Only copy the first part of the breakpoint. */
623 bp_size -= (bp_addr + bp_size) - (memaddr + len);
626 memcpy (myaddr + bp_addr - memaddr,
627 b->shadow_contents + bptoffset, bp_size);
629 if (bp_addr > memaddr)
631 /* Copy the section of memory before the breakpoint. */
632 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
637 if (bp_addr + bp_size < memaddr + len)
639 /* Copy the section of memory after the breakpoint. */
640 status = read_memory_nobpt
642 myaddr + bp_addr + bp_size - memaddr,
643 memaddr + len - (bp_addr + bp_size));
650 /* Nothing overlaps. Just call read_memory_noerr. */
651 return target_read_memory (memaddr, myaddr, len);
655 /* insert_breakpoints is used when starting or continuing the program.
656 remove_breakpoints is used when the program stops.
657 Both return zero if successful,
658 or an `errno' value if could not write the inferior. */
661 insert_breakpoints ()
663 register struct breakpoint *b, *temp;
664 int return_val = 0; /* return success code. */
666 int disabled_breaks = 0;
668 static char message1[] = "Error inserting catchpoint %d:\n";
669 static char message[sizeof (message1) + 30];
672 ALL_BREAKPOINTS_SAFE (b, temp)
674 if (b->type != bp_watchpoint
675 && b->type != bp_hardware_watchpoint
676 && b->type != bp_read_watchpoint
677 && b->type != bp_access_watchpoint
678 && b->type != bp_catch_fork
679 && b->type != bp_catch_vfork
680 && b->type != bp_catch_exec
681 && b->type != bp_catch_throw
682 && b->type != bp_catch_catch
683 && b->enable != disabled
684 && b->enable != shlib_disabled
685 && b->enable != call_disabled
689 if (b->type == bp_hardware_breakpoint)
690 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
693 /* Check to see if breakpoint is in an overlay section;
694 if so, we should set the breakpoint at the LMA address.
695 Only if the section is currently mapped should we ALSO
696 set a break at the VMA address. */
697 if (overlay_debugging && b->section &&
698 section_is_overlay (b->section))
702 addr = overlay_unmapped_address (b->address, b->section);
703 val = target_insert_breakpoint (addr, b->shadow_contents);
704 /* This would be the time to check val, to see if the
705 breakpoint write to the load address succeeded.
706 However, this might be an ordinary occurrance, eg. if
707 the unmapped overlay is in ROM. */
708 val = 0; /* in case unmapped address failed */
709 if (section_is_mapped (b->section))
710 val = target_insert_breakpoint (b->address,
713 else /* ordinary (non-overlay) address */
714 val = target_insert_breakpoint (b->address, b->shadow_contents);
718 /* Can't set the breakpoint. */
719 #if defined (DISABLE_UNSETTABLE_BREAK)
720 if (DISABLE_UNSETTABLE_BREAK (b->address))
722 /* See also: disable_breakpoints_in_shlibs. */
724 b->enable = shlib_disabled;
725 if (!disabled_breaks)
727 target_terminal_ours_for_output ();
728 warning ("Cannot insert breakpoint %d:", b->number);
729 warning ("Temporarily disabling shared library breakpoints:");
732 warning ("breakpoint #%d ", b->number);
737 target_terminal_ours_for_output ();
738 warning ("Cannot insert breakpoint %d:", b->number);
739 #ifdef ONE_PROCESS_WRITETEXT
740 warning ("The same program may be running in another process.");
742 memory_error (val, b->address); /* which bombs us out */
749 return_val = val; /* remember failure */
751 else if (ep_is_exception_catchpoint (b)
752 && b->enable != disabled
753 && b->enable != shlib_disabled
754 && b->enable != call_disabled
759 /* If we get here, we must have a callback mechanism for exception
760 events -- with g++ style embedded label support, we insert
761 ordinary breakpoints and not catchpoints. */
762 /* Format possible error message */
763 sprintf (message, message1, b->number);
765 val = target_insert_breakpoint (b->address, b->shadow_contents);
768 /* Couldn't set breakpoint for some reason */
769 target_terminal_ours_for_output ();
770 warning ("Cannot insert catchpoint %d; disabling it.",
772 b->enable = disabled;
776 /* Bp set, now make sure callbacks are enabled */
778 args_for_catchpoint_enable args;
779 args.kind = b->type == bp_catch_catch ?
780 EX_EVENT_CATCH : EX_EVENT_THROW;
782 val = catch_errors (cover_target_enable_exception_callback,
784 message, RETURN_MASK_ALL);
785 if (val != 0 && val != -1)
789 /* Check if something went wrong; val == 0 can be ignored */
792 /* something went wrong */
793 target_terminal_ours_for_output ();
794 warning ("Cannot insert catchpoint %d; disabling it.",
796 b->enable = disabled;
801 return_val = val; /* remember failure */
804 else if ((b->type == bp_hardware_watchpoint ||
805 b->type == bp_read_watchpoint ||
806 b->type == bp_access_watchpoint)
807 && b->enable == enabled
811 struct frame_info *saved_frame;
812 int saved_level, within_current_scope;
813 value_ptr mark = value_mark ();
816 /* Save the current frame and level so we can restore it after
817 evaluating the watchpoint expression on its own frame. */
818 saved_frame = selected_frame;
819 saved_level = selected_frame_level;
821 /* Determine if the watchpoint is within scope. */
822 if (b->exp_valid_block == NULL)
823 within_current_scope = 1;
826 struct frame_info *fi;
828 /* There might be no current frame at this moment if we are
829 resuming from a step over a breakpoint.
830 Set up current frame before trying to find the watchpoint
832 get_current_frame ();
833 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
834 within_current_scope = (fi != NULL);
835 if (within_current_scope)
836 select_frame (fi, -1);
839 if (within_current_scope)
841 /* Evaluate the expression and cut the chain of values
842 produced off from the value chain. */
843 v = evaluate_expression (b->exp);
844 value_release_to_mark (mark);
849 /* Look at each value on the value chain. */
850 for (; v; v = v->next)
852 /* If it's a memory location, then we must watch it. */
853 if (v->lval == lval_memory)
857 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
858 len = TYPE_LENGTH (VALUE_TYPE (v));
860 if (b->type == bp_read_watchpoint)
862 else if (b->type == bp_access_watchpoint)
865 val = target_insert_watchpoint (addr, len, type);
874 /* Failure to insert a watchpoint on any memory value in the
875 value chain brings us here. */
878 remove_breakpoint (b, mark_uninserted);
879 warning ("Could not insert hardware watchpoint %d.",
886 printf_filtered ("Hardware watchpoint %d deleted", b->number);
887 printf_filtered ("because the program has left the block \n");
888 printf_filtered ("in which its expression is valid.\n");
889 if (b->related_breakpoint)
890 b->related_breakpoint->disposition = del_at_next_stop;
891 b->disposition = del_at_next_stop;
894 /* Restore the frame and level. */
895 if ((saved_frame != selected_frame) ||
896 (saved_level != selected_frame_level))
897 select_and_print_frame (saved_frame, saved_level);
900 return_val = val; /* remember failure */
902 else if ((b->type == bp_catch_fork
903 || b->type == bp_catch_vfork
904 || b->type == bp_catch_exec)
905 && b->enable == enabled
913 val = target_insert_fork_catchpoint (inferior_pid);
916 val = target_insert_vfork_catchpoint (inferior_pid);
919 val = target_insert_exec_catchpoint (inferior_pid);
922 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
927 target_terminal_ours_for_output ();
928 warning ("Cannot insert catchpoint %d.", b->number);
934 return_val = val; /* remember failure */
943 remove_breakpoints ()
945 register struct breakpoint *b;
952 val = remove_breakpoint (b, mark_uninserted);
961 reattach_breakpoints (pid)
964 register struct breakpoint *b;
966 int saved_inferior_pid = inferior_pid;
968 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
969 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
974 remove_breakpoint (b, mark_inserted);
975 if (b->type == bp_hardware_breakpoint)
976 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
978 val = target_insert_breakpoint (b->address, b->shadow_contents);
981 inferior_pid = saved_inferior_pid;
986 inferior_pid = saved_inferior_pid;
991 update_breakpoints_after_exec ()
993 struct breakpoint *b;
994 struct breakpoint *temp;
996 /* Doing this first prevents the badness of having delete_breakpoint()
997 write a breakpoint's current "shadow contents" to lift the bp. That
998 shadow is NOT valid after an exec()! */
999 mark_breakpoints_out ();
1001 ALL_BREAKPOINTS_SAFE (b, temp)
1003 /* Solib breakpoints must be explicitly reset after an exec(). */
1004 if (b->type == bp_shlib_event)
1006 delete_breakpoint (b);
1010 /* Step-resume breakpoints are meaningless after an exec(). */
1011 if (b->type == bp_step_resume)
1013 delete_breakpoint (b);
1017 /* Ditto the sigtramp handler breakpoints. */
1018 if (b->type == bp_through_sigtramp)
1020 delete_breakpoint (b);
1024 /* Ditto the exception-handling catchpoints. */
1025 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1027 delete_breakpoint (b);
1031 /* Don't delete an exec catchpoint, because else the inferior
1032 won't stop when it ought!
1034 Similarly, we probably ought to keep vfork catchpoints, 'cause
1035 on this target, we may not be able to stop when the vfork is
1036 seen, but only when the subsequent exec is seen. (And because
1037 deleting fork catchpoints here but not vfork catchpoints will
1038 seem mysterious to users, keep those too.)
1040 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1041 target address field, if any, is sufficient to have it be reset
1042 automagically. Certainly on HP-UX that's true. */
1043 if ((b->type == bp_catch_exec) ||
1044 (b->type == bp_catch_vfork) ||
1045 (b->type == bp_catch_fork))
1047 b->address = (CORE_ADDR) NULL;
1051 /* bp_finish is a special case. The only way we ought to be able
1052 to see one of these when an exec() has happened, is if the user
1053 caught a vfork, and then said "finish". Ordinarily a finish just
1054 carries them to the call-site of the current callee, by setting
1055 a temporary bp there and resuming. But in this case, the finish
1056 will carry them entirely through the vfork & exec.
1058 We don't want to allow a bp_finish to remain inserted now. But
1059 we can't safely delete it, 'cause finish_command has a handle to
1060 the bp on a bpstat, and will later want to delete it. There's a
1061 chance (and I've seen it happen) that if we delete the bp_finish
1062 here, that its storage will get reused by the time finish_command
1063 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1064 We really must allow finish_command to delete a bp_finish.
1066 In the absense of a general solution for the "how do we know
1067 it's safe to delete something others may have handles to?"
1068 problem, what we'll do here is just uninsert the bp_finish, and
1069 let finish_command delete it.
1071 (We know the bp_finish is "doomed" in the sense that it's
1072 momentary, and will be deleted as soon as finish_command sees
1073 the inferior stopped. So it doesn't matter that the bp's
1074 address is probably bogus in the new a.out, unlike e.g., the
1075 solib breakpoints.) */
1077 if (b->type == bp_finish)
1082 /* Without a symbolic address, we have little hope of the
1083 pre-exec() address meaning the same thing in the post-exec()
1085 if (b->addr_string == NULL)
1087 delete_breakpoint (b);
1091 /* If this breakpoint has survived the above battery of checks, then
1092 it must have a symbolic address. Be sure that it gets reevaluated
1093 to a target address, rather than reusing the old evaluation. */
1094 b->address = (CORE_ADDR) NULL;
1099 detach_breakpoints (pid)
1102 register struct breakpoint *b;
1104 int saved_inferior_pid = inferior_pid;
1106 if (pid == inferior_pid)
1107 error ("Cannot detach breakpoints of inferior_pid");
1109 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1110 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1115 val = remove_breakpoint (b, mark_inserted);
1118 inferior_pid = saved_inferior_pid;
1123 inferior_pid = saved_inferior_pid;
1128 remove_breakpoint (b, is)
1129 struct breakpoint *b;
1130 insertion_state_t is;
1134 if (b->type == bp_none)
1135 warning ("attempted to remove apparently deleted breakpoint #%d?",
1138 if (b->type != bp_watchpoint
1139 && b->type != bp_hardware_watchpoint
1140 && b->type != bp_read_watchpoint
1141 && b->type != bp_access_watchpoint
1142 && b->type != bp_catch_fork
1143 && b->type != bp_catch_vfork
1144 && b->type != bp_catch_exec
1145 && b->type != bp_catch_catch
1146 && b->type != bp_catch_throw)
1149 if (b->type == bp_hardware_breakpoint)
1150 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1153 /* Check to see if breakpoint is in an overlay section;
1154 if so, we should remove the breakpoint at the LMA address.
1155 If that is not equal to the raw address, then we should
1156 presumable remove the breakpoint there as well. */
1157 if (overlay_debugging && b->section &&
1158 section_is_overlay (b->section))
1162 addr = overlay_unmapped_address (b->address, b->section);
1163 val = target_remove_breakpoint (addr, b->shadow_contents);
1164 /* This would be the time to check val, to see if the
1165 shadow breakpoint write to the load address succeeded.
1166 However, this might be an ordinary occurrance, eg. if
1167 the unmapped overlay is in ROM. */
1168 val = 0; /* in case unmapped address failed */
1169 if (section_is_mapped (b->section))
1170 val = target_remove_breakpoint (b->address,
1171 b->shadow_contents);
1173 else /* ordinary (non-overlay) address */
1174 val = target_remove_breakpoint (b->address, b->shadow_contents);
1178 b->inserted = (is == mark_inserted);
1180 else if ((b->type == bp_hardware_watchpoint ||
1181 b->type == bp_read_watchpoint ||
1182 b->type == bp_access_watchpoint)
1183 && b->enable == enabled
1188 b->inserted = (is == mark_inserted);
1189 /* Walk down the saved value chain. */
1190 for (v = b->val_chain; v; v = v->next)
1192 /* For each memory reference remove the watchpoint
1194 if (v->lval == lval_memory)
1196 int addr, len, type;
1198 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1199 len = TYPE_LENGTH (VALUE_TYPE (v));
1201 if (b->type == bp_read_watchpoint)
1203 else if (b->type == bp_access_watchpoint)
1206 val = target_remove_watchpoint (addr, len, type);
1212 /* Failure to remove any of the hardware watchpoints comes here. */
1213 if ((is == mark_uninserted) && (b->inserted))
1214 warning ("Could not remove hardware watchpoint %d.",
1217 /* Free the saved value chain. We will construct a new one
1218 the next time the watchpoint is inserted. */
1219 for (v = b->val_chain; v; v = n)
1224 b->val_chain = NULL;
1226 else if ((b->type == bp_catch_fork ||
1227 b->type == bp_catch_vfork ||
1228 b->type == bp_catch_exec)
1229 && b->enable == enabled
1236 val = target_remove_fork_catchpoint (inferior_pid);
1238 case bp_catch_vfork:
1239 val = target_remove_vfork_catchpoint (inferior_pid);
1242 val = target_remove_exec_catchpoint (inferior_pid);
1245 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1250 b->inserted = (is == mark_inserted);
1252 else if ((b->type == bp_catch_catch ||
1253 b->type == bp_catch_throw)
1254 && b->enable == enabled
1258 val = target_remove_breakpoint (b->address, b->shadow_contents);
1261 b->inserted = (is == mark_inserted);
1263 else if (ep_is_exception_catchpoint (b)
1264 && b->inserted /* sometimes previous insert doesn't happen */
1265 && b->enable == enabled
1269 val = target_remove_breakpoint (b->address, b->shadow_contents);
1273 b->inserted = (is == mark_inserted);
1279 /* Clear the "inserted" flag in all breakpoints. */
1282 mark_breakpoints_out ()
1284 register struct breakpoint *b;
1290 /* Clear the "inserted" flag in all breakpoints and delete any
1291 breakpoints which should go away between runs of the program.
1293 Plus other such housekeeping that has to be done for breakpoints
1296 Note: this function gets called at the end of a run (by
1297 generic_mourn_inferior) and when a run begins (by
1298 init_wait_for_inferior). */
1303 breakpoint_init_inferior (context)
1304 enum inf_context context;
1306 register struct breakpoint *b, *temp;
1307 static int warning_needed = 0;
1309 ALL_BREAKPOINTS_SAFE (b, temp)
1316 case bp_watchpoint_scope:
1318 /* If the call dummy breakpoint is at the entry point it will
1319 cause problems when the inferior is rerun, so we better
1322 Also get rid of scope breakpoints. */
1323 delete_breakpoint (b);
1327 case bp_hardware_watchpoint:
1328 case bp_read_watchpoint:
1329 case bp_access_watchpoint:
1331 /* Likewise for watchpoints on local expressions. */
1332 if (b->exp_valid_block != NULL)
1333 delete_breakpoint (b);
1336 /* Likewise for exception catchpoints in dynamic-linked
1337 executables where required */
1338 if (ep_is_exception_catchpoint (b) &&
1339 exception_catchpoints_are_fragile)
1342 delete_breakpoint (b);
1348 if (exception_catchpoints_are_fragile)
1349 exception_support_initialized = 0;
1351 /* Don't issue the warning unless it's really needed... */
1352 if (warning_needed && (context != inf_exited))
1354 warning ("Exception catchpoints from last run were deleted.");
1355 warning ("You must reinsert them explicitly.");
1360 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at
1361 PC. When continuing from a location with a breakpoint, we actually
1362 single step once before calling insert_breakpoints. */
1365 breakpoint_here_p (pc)
1368 register struct breakpoint *b;
1371 if (b->enable == enabled
1372 && b->enable != shlib_disabled
1373 && b->enable != call_disabled
1374 && b->address == pc) /* bp is enabled and matches pc */
1376 if (overlay_debugging &&
1377 section_is_overlay (b->section) &&
1378 !section_is_mapped (b->section))
1379 continue; /* unmapped overlay -- can't be a match */
1387 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1388 but it only returns true if there is actually a breakpoint inserted
1392 breakpoint_inserted_here_p (pc)
1395 register struct breakpoint *b;
1399 && b->address == pc) /* bp is inserted and matches pc */
1401 if (overlay_debugging &&
1402 section_is_overlay (b->section) &&
1403 !section_is_mapped (b->section))
1404 continue; /* unmapped overlay -- can't be a match */
1412 /* Return nonzero if FRAME is a dummy frame. We can't use
1413 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1414 much time, at least using get_saved_register on the 68k. This
1415 means that for this function to work right a port must use the
1416 bp_call_dummy breakpoint. */
1419 frame_in_dummy (frame)
1420 struct frame_info *frame;
1422 struct breakpoint *b;
1427 if (USE_GENERIC_DUMMY_FRAMES)
1428 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1432 if (b->type == bp_call_dummy
1433 && b->frame == frame->frame
1434 /* We need to check the PC as well as the frame on the sparc,
1435 for signals.exp in the testsuite. */
1438 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1439 && frame->pc <= b->address)
1445 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1446 is valid for process/thread PID. */
1449 breakpoint_thread_match (pc, pid)
1453 struct breakpoint *b;
1456 thread = pid_to_thread_id (pid);
1459 if (b->enable != disabled
1460 && b->enable != shlib_disabled
1461 && b->enable != call_disabled
1463 && (b->thread == -1 || b->thread == thread))
1465 if (overlay_debugging &&
1466 section_is_overlay (b->section) &&
1467 !section_is_mapped (b->section))
1468 continue; /* unmapped overlay -- can't be a match */
1477 /* bpstat stuff. External routines' interfaces are documented
1481 ep_is_catchpoint (ep)
1482 struct breakpoint *ep;
1485 (ep->type == bp_catch_load)
1486 || (ep->type == bp_catch_unload)
1487 || (ep->type == bp_catch_fork)
1488 || (ep->type == bp_catch_vfork)
1489 || (ep->type == bp_catch_exec)
1490 || (ep->type == bp_catch_catch)
1491 || (ep->type == bp_catch_throw)
1494 /* ??rehrauer: Add more kinds here, as are implemented... */
1499 ep_is_shlib_catchpoint (ep)
1500 struct breakpoint *ep;
1503 (ep->type == bp_catch_load)
1504 || (ep->type == bp_catch_unload)
1509 ep_is_exception_catchpoint (ep)
1510 struct breakpoint *ep;
1513 (ep->type == bp_catch_catch)
1514 || (ep->type == bp_catch_throw)
1518 /* Clear a bpstat so that it says we are not at any breakpoint.
1519 Also free any storage that is part of a bpstat. */
1534 if (p->old_val != NULL)
1535 value_free (p->old_val);
1542 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1543 is part of the bpstat is copied as well. */
1551 bpstat retval = NULL;
1556 for (; bs != NULL; bs = bs->next)
1558 tmp = (bpstat) xmalloc (sizeof (*tmp));
1559 memcpy (tmp, bs, sizeof (*tmp));
1561 /* This is the first thing in the chain. */
1571 /* Find the bpstat associated with this breakpoint */
1574 bpstat_find_breakpoint (bsp, breakpoint)
1576 struct breakpoint *breakpoint;
1581 for (; bsp != NULL; bsp = bsp->next)
1583 if (bsp->breakpoint_at == breakpoint)
1589 /* Find a step_resume breakpoint associated with this bpstat.
1590 (If there are multiple step_resume bp's on the list, this function
1591 will arbitrarily pick one.)
1593 It is an error to use this function if BPSTAT doesn't contain a
1594 step_resume breakpoint.
1596 See wait_for_inferior's use of this function. */
1598 bpstat_find_step_resume_breakpoint (bsp)
1602 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1604 for (; bsp != NULL; bsp = bsp->next)
1606 if ((bsp->breakpoint_at != NULL) &&
1607 (bsp->breakpoint_at->type == bp_step_resume))
1608 return bsp->breakpoint_at;
1611 error ("Internal error (no step_resume breakpoint found)");
1615 /* Return the breakpoint number of the first breakpoint we are stopped
1616 at. *BSP upon return is a bpstat which points to the remaining
1617 breakpoints stopped at (but which is not guaranteed to be good for
1618 anything but further calls to bpstat_num).
1619 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1625 struct breakpoint *b;
1628 return 0; /* No more breakpoint values */
1631 b = (*bsp)->breakpoint_at;
1632 *bsp = (*bsp)->next;
1634 return -1; /* breakpoint that's been deleted since */
1636 return b->number; /* We have its number */
1640 /* Modify BS so that the actions will not be performed. */
1643 bpstat_clear_actions (bs)
1646 for (; bs != NULL; bs = bs->next)
1648 bs->commands = NULL;
1649 if (bs->old_val != NULL)
1651 value_free (bs->old_val);
1657 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1660 cleanup_executing_breakpoints (ignore)
1663 executing_breakpoint_commands = 0;
1666 /* Execute all the commands associated with all the breakpoints at this
1667 location. Any of these commands could cause the process to proceed
1668 beyond this point, etc. We look out for such changes by checking
1669 the global "breakpoint_proceeded" after each command. */
1672 bpstat_do_actions (bsp)
1676 struct cleanup *old_chain;
1677 struct command_line *cmd;
1679 /* Avoid endless recursion if a `source' command is contained
1681 if (executing_breakpoint_commands)
1684 executing_breakpoint_commands = 1;
1685 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1688 /* Note that (as of this writing), our callers all appear to
1689 be passing us the address of global stop_bpstat. And, if
1690 our calls to execute_control_command cause the inferior to
1691 proceed, that global (and hence, *bsp) will change.
1693 We must be careful to not touch *bsp unless the inferior
1694 has not proceeded. */
1696 /* This pointer will iterate over the list of bpstat's. */
1699 breakpoint_proceeded = 0;
1700 for (; bs != NULL; bs = bs->next)
1705 execute_control_command (cmd);
1707 if (breakpoint_proceeded)
1712 if (breakpoint_proceeded)
1713 /* The inferior is proceeded by the command; bomb out now.
1714 The bpstat chain has been blown away by wait_for_inferior.
1715 But since execution has stopped again, there is a new bpstat
1716 to look at, so start over. */
1719 bs->commands = NULL;
1722 executing_breakpoint_commands = 0;
1723 discard_cleanups (old_chain);
1726 /* This is the normal print_it function for a bpstat. In the future,
1727 much of this logic could (should?) be moved to bpstat_stop_status,
1728 by having it set different print_it functions.
1730 Current scheme: When we stop, bpstat_print() is called.
1731 It loops through the bpstat list of things causing this stop,
1732 calling the print_it function for each one. The default
1733 print_it function, used for breakpoints, is print_it_normal().
1734 (Also see print_it_noop() and print_it_done()).
1736 Return values from this routine (used by bpstat_print() to
1738 1: Means we printed something, and we do *not* desire that
1739 something to be followed by a location.
1740 0: Means we printed something, and we *do* desire that
1741 something to be followed by a location.
1742 -1: Means we printed nothing. */
1745 print_it_normal (bs)
1748 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1749 which has since been deleted. */
1750 if (bs->breakpoint_at == NULL
1751 || (bs->breakpoint_at->type != bp_breakpoint
1752 && bs->breakpoint_at->type != bp_catch_load
1753 && bs->breakpoint_at->type != bp_catch_unload
1754 && bs->breakpoint_at->type != bp_catch_fork
1755 && bs->breakpoint_at->type != bp_catch_vfork
1756 && bs->breakpoint_at->type != bp_catch_exec
1757 && bs->breakpoint_at->type != bp_catch_catch
1758 && bs->breakpoint_at->type != bp_catch_throw
1759 && bs->breakpoint_at->type != bp_hardware_breakpoint
1760 && bs->breakpoint_at->type != bp_watchpoint
1761 && bs->breakpoint_at->type != bp_read_watchpoint
1762 && bs->breakpoint_at->type != bp_access_watchpoint
1763 && bs->breakpoint_at->type != bp_hardware_watchpoint))
1766 if (ep_is_shlib_catchpoint (bs->breakpoint_at))
1768 annotate_catchpoint (bs->breakpoint_at->number);
1769 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1770 if (bs->breakpoint_at->type == bp_catch_load)
1771 printf_filtered ("loaded");
1772 else if (bs->breakpoint_at->type == bp_catch_unload)
1773 printf_filtered ("unloaded");
1774 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1777 else if (bs->breakpoint_at->type == bp_catch_fork ||
1778 bs->breakpoint_at->type == bp_catch_vfork)
1780 annotate_catchpoint (bs->breakpoint_at->number);
1781 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1782 if (bs->breakpoint_at->type == bp_catch_fork)
1783 printf_filtered ("forked");
1784 else if (bs->breakpoint_at->type == bp_catch_vfork)
1785 printf_filtered ("vforked");
1786 printf_filtered (" process %d), ",
1787 bs->breakpoint_at->forked_inferior_pid);
1790 else if (bs->breakpoint_at->type == bp_catch_exec)
1792 annotate_catchpoint (bs->breakpoint_at->number);
1793 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1794 bs->breakpoint_at->number,
1795 bs->breakpoint_at->exec_pathname);
1798 else if (bs->breakpoint_at->type == bp_catch_catch)
1800 if (current_exception_event &&
1801 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1803 annotate_catchpoint (bs->breakpoint_at->number);
1804 printf_filtered ("\nCatchpoint %d (exception caught), ",
1805 bs->breakpoint_at->number);
1806 printf_filtered ("throw location ");
1807 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1808 printf_filtered ("%s:%d",
1809 CURRENT_EXCEPTION_THROW_FILE,
1810 CURRENT_EXCEPTION_THROW_LINE);
1812 printf_filtered ("unknown");
1814 printf_filtered (", catch location ");
1815 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1816 printf_filtered ("%s:%d",
1817 CURRENT_EXCEPTION_CATCH_FILE,
1818 CURRENT_EXCEPTION_CATCH_LINE);
1820 printf_filtered ("unknown");
1822 printf_filtered ("\n");
1823 return 1; /* don't bother to print location frame info */
1827 return -1; /* really throw, some other bpstat will handle it */
1830 else if (bs->breakpoint_at->type == bp_catch_throw)
1832 if (current_exception_event &&
1833 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1835 annotate_catchpoint (bs->breakpoint_at->number);
1836 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1837 bs->breakpoint_at->number);
1838 printf_filtered ("throw location ");
1839 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1840 printf_filtered ("%s:%d",
1841 CURRENT_EXCEPTION_THROW_FILE,
1842 CURRENT_EXCEPTION_THROW_LINE);
1844 printf_filtered ("unknown");
1846 printf_filtered (", catch location ");
1847 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1848 printf_filtered ("%s:%d",
1849 CURRENT_EXCEPTION_CATCH_FILE,
1850 CURRENT_EXCEPTION_CATCH_LINE);
1852 printf_filtered ("unknown");
1854 printf_filtered ("\n");
1855 return 1; /* don't bother to print location frame info */
1859 return -1; /* really catch, some other bpstat willhandle it */
1863 else if (bs->breakpoint_at->type == bp_breakpoint ||
1864 bs->breakpoint_at->type == bp_hardware_breakpoint)
1866 /* I think the user probably only wants to see one breakpoint
1867 number, not all of them. */
1868 annotate_breakpoint (bs->breakpoint_at->number);
1869 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1872 else if ((bs->old_val != NULL) &&
1873 (bs->breakpoint_at->type == bp_watchpoint ||
1874 bs->breakpoint_at->type == bp_access_watchpoint ||
1875 bs->breakpoint_at->type == bp_hardware_watchpoint))
1877 annotate_watchpoint (bs->breakpoint_at->number);
1878 mention (bs->breakpoint_at);
1879 printf_filtered ("\nOld value = ");
1880 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
1881 printf_filtered ("\nNew value = ");
1882 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1883 Val_pretty_default);
1884 printf_filtered ("\n");
1885 value_free (bs->old_val);
1887 /* More than one watchpoint may have been triggered. */
1890 else if (bs->breakpoint_at->type == bp_access_watchpoint ||
1891 bs->breakpoint_at->type == bp_read_watchpoint)
1893 mention (bs->breakpoint_at);
1894 printf_filtered ("\nValue = ");
1895 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1896 Val_pretty_default);
1897 printf_filtered ("\n");
1900 /* We can't deal with it.
1901 Maybe another member of the bpstat chain can. */
1905 /* Print a message indicating what happened.
1906 This is called from normal_stop().
1907 The input to this routine is the head of the bpstat list - a list
1908 of the eventpoints that caused this stop.
1909 This routine calls the "print_it" routine(s) associated
1910 with these eventpoints. This will print (for example)
1911 the "Breakpoint n," part of the output.
1912 The return value of this routine is one of:
1914 -1: Means we printed nothing
1915 0: Means we printed something, and expect subsequent
1916 code to print the location. An example is
1917 "Breakpoint 1, " which should be followed by
1919 1 : Means we printed something, but there is no need
1920 to also print the location part of the message.
1921 An example is the catch/throw messages, which
1922 don't require a location appended to the end. */
1933 val = (*bs->print_it) (bs);
1937 /* Maybe another breakpoint in the chain caused us to stop.
1938 (Currently all watchpoints go on the bpstat whether hit or not.
1939 That probably could (should) be changed, provided care is taken
1940 with respect to bpstat_explains_signal). */
1942 return bpstat_print (bs->next);
1944 /* We reached the end of the chain without printing anything. */
1948 /* Evaluate the expression EXP and return 1 if value is zero.
1949 This is used inside a catch_errors to evaluate the breakpoint condition.
1950 The argument is a "struct expression *" that has been cast to char * to
1951 make it pass through catch_errors. */
1954 breakpoint_cond_eval (exp)
1957 value_ptr mark = value_mark ();
1958 int i = !value_true (evaluate_expression ((struct expression *) exp));
1959 value_free_to_mark (mark);
1963 /* Allocate a new bpstat and chain it to the current one. */
1966 bpstat_alloc (b, cbs)
1967 register struct breakpoint *b;
1968 bpstat cbs; /* Current "bs" value */
1972 bs = (bpstat) xmalloc (sizeof (*bs));
1974 bs->breakpoint_at = b;
1975 /* If the condition is false, etc., don't do the commands. */
1976 bs->commands = NULL;
1978 bs->print_it = print_it_normal;
1982 /* Possible return values for watchpoint_check (this can't be an enum
1983 because of check_errors). */
1984 /* The watchpoint has been deleted. */
1985 #define WP_DELETED 1
1986 /* The value has changed. */
1987 #define WP_VALUE_CHANGED 2
1988 /* The value has not changed. */
1989 #define WP_VALUE_NOT_CHANGED 3
1991 #define BP_TEMPFLAG 1
1992 #define BP_HARDWAREFLAG 2
1994 /* Check watchpoint condition. */
1997 watchpoint_check (p)
2000 bpstat bs = (bpstat) p;
2001 struct breakpoint *b;
2002 struct frame_info *fr;
2003 int within_current_scope;
2005 b = bs->breakpoint_at;
2007 if (b->exp_valid_block == NULL)
2008 within_current_scope = 1;
2011 /* There is no current frame at this moment. If we're going to have
2012 any chance of handling watchpoints on local variables, we'll need
2013 the frame chain (so we can determine if we're in scope). */
2014 reinit_frame_cache ();
2015 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2016 within_current_scope = (fr != NULL);
2017 if (within_current_scope)
2018 /* If we end up stopping, the current frame will get selected
2019 in normal_stop. So this call to select_frame won't affect
2021 select_frame (fr, -1);
2024 if (within_current_scope)
2026 /* We use value_{,free_to_}mark because it could be a
2027 *long* time before we return to the command level and
2028 call free_all_values. We can't call free_all_values because
2029 we might be in the middle of evaluating a function call. */
2031 value_ptr mark = value_mark ();
2032 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2033 if (!value_equal (b->val, new_val))
2035 release_value (new_val);
2036 value_free_to_mark (mark);
2037 bs->old_val = b->val;
2039 /* We will stop here */
2040 return WP_VALUE_CHANGED;
2044 /* Nothing changed, don't do anything. */
2045 value_free_to_mark (mark);
2046 /* We won't stop here */
2047 return WP_VALUE_NOT_CHANGED;
2052 /* This seems like the only logical thing to do because
2053 if we temporarily ignored the watchpoint, then when
2054 we reenter the block in which it is valid it contains
2055 garbage (in the case of a function, it may have two
2056 garbage values, one before and one after the prologue).
2057 So we can't even detect the first assignment to it and
2058 watch after that (since the garbage may or may not equal
2059 the first value assigned). */
2061 Watchpoint %d deleted because the program has left the block in\n\
2062 which its expression is valid.\n", bs->breakpoint_at->number);
2063 if (b->related_breakpoint)
2064 b->related_breakpoint->disposition = del_at_next_stop;
2065 b->disposition = del_at_next_stop;
2071 /* This is used when everything which needs to be printed has
2072 already been printed. But we still want to print the frame. */
2074 /* Background: When we stop, bpstat_print() is called.
2075 It loops through the bpstat list of things causing this stop,
2076 calling the print_it function for each one. The default
2077 print_it function, used for breakpoints, is print_it_normal().
2078 Also see print_it_noop() and print_it_done() are the other
2079 two possibilities. See comments in bpstat_print() and
2080 in header of print_it_normal() for more detail. */
2089 /* This is used when nothing should be printed for this bpstat entry. */
2090 /* Background: When we stop, bpstat_print() is called.
2091 It loops through the bpstat list of things causing this stop,
2092 calling the print_it function for each one. The default
2093 print_it function, used for breakpoints, is print_it_normal().
2094 Also see print_it_noop() and print_it_done() are the other
2095 two possibilities. See comments in bpstat_print() and
2096 in header of print_it_normal() for more detail. */
2105 /* Get a bpstat associated with having just stopped at address *PC
2106 and frame address CORE_ADDRESS. Update *PC to point at the
2107 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2108 if this is known to not be a real breakpoint (it could still be a
2109 watchpoint, though). */
2111 /* Determine whether we stopped at a breakpoint, etc, or whether we
2112 don't understand this stop. Result is a chain of bpstat's such that:
2114 if we don't understand the stop, the result is a null pointer.
2116 if we understand why we stopped, the result is not null.
2118 Each element of the chain refers to a particular breakpoint or
2119 watchpoint at which we have stopped. (We may have stopped for
2120 several reasons concurrently.)
2122 Each element of the chain has valid next, breakpoint_at,
2123 commands, FIXME??? fields. */
2126 bpstat_stop_status (pc, not_a_breakpoint)
2128 int not_a_breakpoint;
2130 register struct breakpoint *b, *temp;
2132 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2133 int real_breakpoint = 0;
2134 /* Root of the chain of bpstat's */
2135 struct bpstats root_bs[1];
2136 /* Pointer to the last thing in the chain currently. */
2137 bpstat bs = root_bs;
2138 static char message1[] =
2139 "Error evaluating expression for watchpoint %d\n";
2140 char message[sizeof (message1) + 30 /* slop */ ];
2142 /* Get the address where the breakpoint would have been. */
2143 bp_addr = *pc - DECR_PC_AFTER_BREAK;
2145 ALL_BREAKPOINTS_SAFE (b, temp)
2147 if (b->enable == disabled
2148 || b->enable == shlib_disabled
2149 || b->enable == call_disabled)
2152 if (b->type != bp_watchpoint
2153 && b->type != bp_hardware_watchpoint
2154 && b->type != bp_read_watchpoint
2155 && b->type != bp_access_watchpoint
2156 && b->type != bp_hardware_breakpoint
2157 && b->type != bp_catch_fork
2158 && b->type != bp_catch_vfork
2159 && b->type != bp_catch_exec
2160 && b->type != bp_catch_catch
2161 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2162 if (b->address != bp_addr || /* address doesn't match or */
2163 (overlay_debugging && /* overlay doesn't match */
2164 section_is_overlay (b->section) &&
2165 !section_is_mapped (b->section)))
2168 if (b->type == bp_hardware_breakpoint
2169 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2172 if (b->type != bp_watchpoint
2173 && b->type != bp_hardware_watchpoint
2174 && b->type != bp_read_watchpoint
2175 && b->type != bp_access_watchpoint
2176 && not_a_breakpoint)
2179 /* Is this a catchpoint of a load or unload? If so, did we
2180 get a load or unload of the specified library? If not,
2182 if ((b->type == bp_catch_load)
2183 #if defined(SOLIB_HAVE_LOAD_EVENT)
2184 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2185 || ((b->dll_pathname != NULL)
2186 && (strcmp (b->dll_pathname,
2187 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2193 if ((b->type == bp_catch_unload)
2194 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2195 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2196 || ((b->dll_pathname != NULL)
2197 && (strcmp (b->dll_pathname,
2198 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2204 if ((b->type == bp_catch_fork)
2205 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2208 if ((b->type == bp_catch_vfork)
2209 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2212 if ((b->type == bp_catch_exec)
2213 && !target_has_execd (inferior_pid, &b->exec_pathname))
2216 if (ep_is_exception_catchpoint (b) &&
2217 !(current_exception_event = target_get_current_exception_event ()))
2220 /* Come here if it's a watchpoint, or if the break address matches */
2222 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2224 /* Watchpoints may change this, if not found to have triggered. */
2228 sprintf (message, message1, b->number);
2229 if (b->type == bp_watchpoint ||
2230 b->type == bp_hardware_watchpoint)
2232 switch (catch_errors (watchpoint_check, bs, message,
2236 /* We've already printed what needs to be printed. */
2237 bs->print_it = print_it_done;
2240 case WP_VALUE_CHANGED:
2244 case WP_VALUE_NOT_CHANGED:
2246 bs->print_it = print_it_noop;
2248 /* Don't consider this a hit. */
2255 /* Error from catch_errors. */
2256 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2257 if (b->related_breakpoint)
2258 b->related_breakpoint->disposition = del_at_next_stop;
2259 b->disposition = del_at_next_stop;
2260 /* We've already printed what needs to be printed. */
2261 bs->print_it = print_it_done;
2267 else if (b->type == bp_read_watchpoint ||
2268 b->type == bp_access_watchpoint)
2274 addr = target_stopped_data_address ();
2277 for (v = b->val_chain; v; v = v->next)
2279 if (v->lval == lval_memory)
2283 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2284 /* Exact match not required. Within range is sufficient.
2286 if (addr >= vaddr &&
2287 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2292 switch (catch_errors (watchpoint_check, bs, message,
2296 /* We've already printed what needs to be printed. */
2297 bs->print_it = print_it_done;
2300 case WP_VALUE_CHANGED:
2301 case WP_VALUE_NOT_CHANGED:
2308 /* Error from catch_errors. */
2309 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2310 if (b->related_breakpoint)
2311 b->related_breakpoint->disposition = del_at_next_stop;
2312 b->disposition = del_at_next_stop;
2313 /* We've already printed what needs to be printed. */
2314 bs->print_it = print_it_done;
2317 else /* found == 0 */
2319 /* This is a case where some watchpoint(s) triggered,
2320 but not at the address of this watchpoint (FOUND
2321 was left zero). So don't print anything for this
2323 bs->print_it = print_it_noop;
2330 /* By definition, an encountered breakpoint is a triggered
2334 real_breakpoint = 1;
2337 if (b->frame && b->frame != (get_current_frame ())->frame &&
2338 (b->type == bp_step_resume &&
2339 (INNER_THAN (get_current_frame ()->frame, b->frame))))
2343 int value_is_zero = 0;
2347 /* Need to select the frame, with all that implies
2348 so that the conditions will have the right context. */
2349 select_frame (get_current_frame (), 0);
2351 = catch_errors (breakpoint_cond_eval, (b->cond),
2352 "Error in testing breakpoint condition:\n",
2354 /* FIXME-someday, should give breakpoint # */
2357 if (b->cond && value_is_zero)
2360 /* Don't consider this a hit. */
2363 else if (b->ignore_count > 0)
2370 /* We will stop here */
2371 if (b->disposition == disable)
2372 b->enable = disabled;
2373 bs->commands = b->commands;
2377 (STREQ ("silent", bs->commands->line) ||
2378 (xdb_commands && STREQ ("Q", bs->commands->line))))
2380 bs->commands = bs->commands->next;
2385 /* Print nothing for this entry if we dont stop or if we dont print. */
2386 if (bs->stop == 0 || bs->print == 0)
2387 bs->print_it = print_it_noop;
2390 bs->next = NULL; /* Terminate the chain */
2391 bs = root_bs->next; /* Re-grab the head of the chain */
2393 if (real_breakpoint && bs)
2395 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2397 if (DECR_PC_AFTER_HW_BREAK != 0)
2399 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2405 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2408 #if defined (SHIFT_INST_REGS)
2410 #else /* No SHIFT_INST_REGS. */
2412 #endif /* No SHIFT_INST_REGS. */
2417 /* The value of a hardware watchpoint hasn't changed, but the
2418 intermediate memory locations we are watching may have. */
2419 if (bs && !bs->stop &&
2420 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2421 bs->breakpoint_at->type == bp_read_watchpoint ||
2422 bs->breakpoint_at->type == bp_access_watchpoint))
2424 remove_breakpoints ();
2425 insert_breakpoints ();
2430 /* Tell what to do about this bpstat. */
2435 /* Classify each bpstat as one of the following. */
2438 /* This bpstat element has no effect on the main_action. */
2441 /* There was a watchpoint, stop but don't print. */
2444 /* There was a watchpoint, stop and print. */
2447 /* There was a breakpoint but we're not stopping. */
2450 /* There was a breakpoint, stop but don't print. */
2453 /* There was a breakpoint, stop and print. */
2456 /* We hit the longjmp breakpoint. */
2459 /* We hit the longjmp_resume breakpoint. */
2462 /* We hit the step_resume breakpoint. */
2465 /* We hit the through_sigtramp breakpoint. */
2468 /* We hit the shared library event breakpoint. */
2471 /* We caught a shared library event. */
2474 /* This is just used to count how many enums there are. */
2478 /* Here is the table which drives this routine. So that we can
2479 format it pretty, we define some abbreviations for the
2480 enum bpstat_what codes. */
2481 #define kc BPSTAT_WHAT_KEEP_CHECKING
2482 #define ss BPSTAT_WHAT_STOP_SILENT
2483 #define sn BPSTAT_WHAT_STOP_NOISY
2484 #define sgl BPSTAT_WHAT_SINGLE
2485 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2486 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2487 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2488 #define sr BPSTAT_WHAT_STEP_RESUME
2489 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2490 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2491 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2493 /* "Can't happen." Might want to print an error message.
2494 abort() is not out of the question, but chances are GDB is just
2495 a bit confused, not unusable. */
2496 #define err BPSTAT_WHAT_STOP_NOISY
2498 /* Given an old action and a class, come up with a new action. */
2499 /* One interesting property of this table is that wp_silent is the same
2500 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2501 after stopping, the check for whether to step over a breakpoint
2502 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2503 reference to how we stopped. We retain separate wp_silent and
2504 bp_silent codes in case we want to change that someday.
2506 Another possibly interesting property of this table is that
2507 there's a partial ordering, priority-like, of the actions. Once
2508 you've decided that some action is appropriate, you'll never go
2509 back and decide something of a lower priority is better. The
2512 kc < clr sgl shl slr sn sr ss ts
2513 sgl < clrs shl shlr slr sn sr ss ts
2514 slr < err shl shlr sn sr ss ts
2515 clr < clrs err shl shlr sn sr ss ts
2516 clrs < err shl shlr sn sr ss ts
2517 ss < shl shlr sn sr ts
2524 What I think this means is that we don't need a damned table
2525 here. If you just put the rows and columns in the right order,
2526 it'd look awfully regular. We could simply walk the bpstat list
2527 and choose the highest priority action we find, with a little
2528 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2529 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2530 is messy anyway). */
2532 /* step_resume entries: a step resume breakpoint overrides another
2533 breakpoint of signal handling (see comment in wait_for_inferior
2534 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2535 /* We handle the through_sigtramp_breakpoint the same way; having both
2536 one of those and a step_resume_breakpoint is probably very rare (?). */
2538 static const enum bpstat_what_main_action
2539 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2542 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2545 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2547 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2549 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2551 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2553 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2555 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2557 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2559 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2561 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2563 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2565 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2567 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2582 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2583 struct bpstat_what retval;
2585 retval.call_dummy = 0;
2586 for (; bs != NULL; bs = bs->next)
2588 enum class bs_class = no_effect;
2589 if (bs->breakpoint_at == NULL)
2590 /* I suspect this can happen if it was a momentary breakpoint
2591 which has since been deleted. */
2593 switch (bs->breakpoint_at->type)
2599 case bp_hardware_breakpoint:
2605 bs_class = bp_noisy;
2607 bs_class = bp_silent;
2610 bs_class = bp_nostop;
2613 case bp_hardware_watchpoint:
2614 case bp_read_watchpoint:
2615 case bp_access_watchpoint:
2619 bs_class = wp_noisy;
2621 bs_class = wp_silent;
2624 /* There was a watchpoint, but we're not stopping.
2625 This requires no further action. */
2626 bs_class = no_effect;
2629 bs_class = long_jump;
2631 case bp_longjmp_resume:
2632 bs_class = long_resume;
2634 case bp_step_resume:
2637 bs_class = step_resume;
2640 /* It is for the wrong frame. */
2641 bs_class = bp_nostop;
2643 case bp_through_sigtramp:
2644 bs_class = through_sig;
2646 case bp_watchpoint_scope:
2647 bs_class = bp_nostop;
2649 case bp_shlib_event:
2650 bs_class = shlib_event;
2653 case bp_catch_unload:
2654 /* Only if this catchpoint triggered should we cause the
2655 step-out-of-dld behaviour. Otherwise, we ignore this
2658 bs_class = catch_shlib_event;
2660 bs_class = no_effect;
2663 case bp_catch_vfork:
2668 bs_class = bp_noisy;
2670 bs_class = bp_silent;
2673 /* There was a catchpoint, but we're not stopping.
2674 This requires no further action. */
2675 bs_class = no_effect;
2677 case bp_catch_catch:
2678 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2679 bs_class = bp_nostop;
2681 bs_class = bs->print ? bp_noisy : bp_silent;
2683 case bp_catch_throw:
2684 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2685 bs_class = bp_nostop;
2687 bs_class = bs->print ? bp_noisy : bp_silent;
2690 /* Make sure the action is stop (silent or noisy),
2691 so infrun.c pops the dummy frame. */
2692 bs_class = bp_silent;
2693 retval.call_dummy = 1;
2696 current_action = table[(int) bs_class][(int) current_action];
2698 retval.main_action = current_action;
2702 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2703 without hardware support). This isn't related to a specific bpstat,
2704 just to things like whether watchpoints are set. */
2707 bpstat_should_step ()
2709 struct breakpoint *b;
2711 if (b->enable == enabled && b->type == bp_watchpoint)
2716 /* Nonzero if there are enabled hardware watchpoints. */
2718 bpstat_have_active_hw_watchpoints ()
2720 struct breakpoint *b;
2722 if ((b->enable == enabled) &&
2724 ((b->type == bp_hardware_watchpoint) ||
2725 (b->type == bp_read_watchpoint) ||
2726 (b->type == bp_access_watchpoint)))
2732 /* Given a bpstat that records zero or more triggered eventpoints, this
2733 function returns another bpstat which contains only the catchpoints
2734 on that first list, if any. */
2736 bpstat_get_triggered_catchpoints (ep_list, cp_list)
2740 struct bpstats root_bs[1];
2741 bpstat bs = root_bs;
2742 struct breakpoint *ep;
2745 bpstat_clear (cp_list);
2746 root_bs->next = NULL;
2748 for (; ep_list != NULL; ep_list = ep_list->next)
2750 /* Is this eventpoint a catchpoint? If not, ignore it. */
2751 ep = ep_list->breakpoint_at;
2754 if ((ep->type != bp_catch_load) &&
2755 (ep->type != bp_catch_unload) &&
2756 (ep->type != bp_catch_catch) &&
2757 (ep->type != bp_catch_throw))
2758 /* pai: (temp) ADD fork/vfork here!! */
2761 /* Yes; add it to the list. */
2762 bs = bpstat_alloc (ep, bs);
2767 #if defined(SOLIB_ADD)
2768 /* Also, for each triggered catchpoint, tag it with the name of
2769 the library that caused this trigger. (We copy the name now,
2770 because it's only guaranteed to be available NOW, when the
2771 catchpoint triggers. Clients who may wish to know the name
2772 later must get it from the catchpoint itself.) */
2773 if (ep->triggered_dll_pathname != NULL)
2774 free (ep->triggered_dll_pathname);
2775 if (ep->type == bp_catch_load)
2776 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
2778 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
2780 dll_pathname = NULL;
2784 ep->triggered_dll_pathname = (char *)
2785 xmalloc (strlen (dll_pathname) + 1);
2786 strcpy (ep->triggered_dll_pathname, dll_pathname);
2789 ep->triggered_dll_pathname = NULL;
2795 /* Print information on breakpoint number BNUM, or -1 if all.
2796 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
2797 is nonzero, process only watchpoints. */
2804 ep_type_description_t;
2807 breakpoint_1 (bnum, allflag)
2811 register struct breakpoint *b;
2812 register struct command_line *l;
2813 register struct symbol *sym;
2814 CORE_ADDR last_addr = (CORE_ADDR) - 1;
2815 int found_a_breakpoint = 0;
2816 static ep_type_description_t bptypes[] =
2818 {bp_none, "?deleted?"},
2819 {bp_breakpoint, "breakpoint"},
2820 {bp_hardware_breakpoint, "hw breakpoint"},
2821 {bp_until, "until"},
2822 {bp_finish, "finish"},
2823 {bp_watchpoint, "watchpoint"},
2824 {bp_hardware_watchpoint, "hw watchpoint"},
2825 {bp_read_watchpoint, "read watchpoint"},
2826 {bp_access_watchpoint, "acc watchpoint"},
2827 {bp_longjmp, "longjmp"},
2828 {bp_longjmp_resume, "longjmp resume"},
2829 {bp_step_resume, "step resume"},
2830 {bp_through_sigtramp, "sigtramp"},
2831 {bp_watchpoint_scope, "watchpoint scope"},
2832 {bp_call_dummy, "call dummy"},
2833 {bp_shlib_event, "shlib events"},
2834 {bp_catch_load, "catch load"},
2835 {bp_catch_unload, "catch unload"},
2836 {bp_catch_fork, "catch fork"},
2837 {bp_catch_vfork, "catch vfork"},
2838 {bp_catch_exec, "catch exec"},
2839 {bp_catch_catch, "catch catch"},
2840 {bp_catch_throw, "catch throw"}
2843 static char *bpdisps[] =
2844 {"del", "dstp", "dis", "keep"};
2845 static char bpenables[] = "nyn";
2846 char wrap_indent[80];
2852 || bnum == b->number)
2854 /* We only print out user settable breakpoints unless the allflag is set. */
2856 && b->type != bp_breakpoint
2857 && b->type != bp_catch_load
2858 && b->type != bp_catch_unload
2859 && b->type != bp_catch_fork
2860 && b->type != bp_catch_vfork
2861 && b->type != bp_catch_exec
2862 && b->type != bp_catch_catch
2863 && b->type != bp_catch_throw
2864 && b->type != bp_hardware_breakpoint
2865 && b->type != bp_watchpoint
2866 && b->type != bp_read_watchpoint
2867 && b->type != bp_access_watchpoint
2868 && b->type != bp_hardware_watchpoint)
2871 if (!found_a_breakpoint++)
2873 annotate_breakpoints_headers ();
2876 printf_filtered ("Num ");
2878 printf_filtered ("Type ");
2880 printf_filtered ("Disp ");
2882 printf_filtered ("Enb ");
2886 printf_filtered ("Address ");
2889 printf_filtered ("What\n");
2891 annotate_breakpoints_table ();
2896 printf_filtered ("%-3d ", b->number);
2898 if ((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
2899 error ("bptypes table does not describe type #%d.", (int) b->type);
2900 if ((int) b->type != bptypes[(int) b->type].type)
2901 error ("bptypes table does not describe type #%d?", (int) b->type);
2902 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
2904 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
2906 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
2908 strcpy (wrap_indent, " ");
2910 strcat (wrap_indent, " ");
2914 case bp_hardware_watchpoint:
2915 case bp_read_watchpoint:
2916 case bp_access_watchpoint:
2917 /* Field 4, the address, is omitted (which makes the columns
2918 not line up too nicely with the headers, but the effect
2919 is relatively readable). */
2921 print_expression (b->exp, gdb_stdout);
2925 case bp_catch_unload:
2926 /* Field 4, the address, is omitted (which makes the columns
2927 not line up too nicely with the headers, but the effect
2928 is relatively readable). */
2930 if (b->dll_pathname == NULL)
2931 printf_filtered ("<any library> ");
2933 printf_filtered ("library \"%s\" ", b->dll_pathname);
2937 case bp_catch_vfork:
2938 /* Field 4, the address, is omitted (which makes the columns
2939 not line up too nicely with the headers, but the effect
2940 is relatively readable). */
2942 if (b->forked_inferior_pid != 0)
2943 printf_filtered ("process %d ", b->forked_inferior_pid);
2947 /* Field 4, the address, is omitted (which makes the columns
2948 not line up too nicely with the headers, but the effect
2949 is relatively readable). */
2951 if (b->exec_pathname != NULL)
2952 printf_filtered ("program \"%s\" ", b->exec_pathname);
2954 case bp_catch_catch:
2955 /* Field 4, the address, is omitted (which makes the columns
2956 not line up too nicely with the headers, but the effect
2957 is relatively readable). */
2959 printf_filtered ("exception catch ");
2961 case bp_catch_throw:
2962 /* Field 4, the address, is omitted (which makes the columns
2963 not line up too nicely with the headers, but the effect
2964 is relatively readable). */
2966 printf_filtered ("exception throw ");
2970 case bp_hardware_breakpoint:
2974 case bp_longjmp_resume:
2975 case bp_step_resume:
2976 case bp_through_sigtramp:
2977 case bp_watchpoint_scope:
2979 case bp_shlib_event:
2983 /* FIXME-32x64: need a print_address_numeric with
2987 local_hex_string_custom
2988 ((unsigned long) b->address, "08l"));
2993 last_addr = b->address;
2996 sym = find_pc_sect_function (b->address, b->section);
2999 fputs_filtered ("in ", gdb_stdout);
3000 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3001 wrap_here (wrap_indent);
3002 fputs_filtered (" at ", gdb_stdout);
3004 fputs_filtered (b->source_file, gdb_stdout);
3005 printf_filtered (":%d", b->line_number);
3008 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3012 if (b->thread != -1)
3013 printf_filtered (" thread %d", b->thread);
3015 printf_filtered ("\n");
3021 printf_filtered ("\tstop only in stack frame at ");
3022 print_address_numeric (b->frame, 1, gdb_stdout);
3023 printf_filtered ("\n");
3030 printf_filtered ("\tstop only if ");
3031 print_expression (b->cond, gdb_stdout);
3032 printf_filtered ("\n");
3035 if (b->thread != -1)
3037 /* FIXME should make an annotation for this */
3038 printf_filtered ("\tstop only in thread %d\n", b->thread);
3041 if (show_breakpoint_hit_counts && b->hit_count)
3043 /* FIXME should make an annotation for this */
3044 if (ep_is_catchpoint (b))
3045 printf_filtered ("\tcatchpoint");
3047 printf_filtered ("\tbreakpoint");
3048 printf_filtered (" already hit %d time%s\n",
3049 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3052 if (b->ignore_count)
3056 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3059 if ((l = b->commands))
3065 print_command_line (l, 4, gdb_stdout);
3071 if (!found_a_breakpoint)
3074 printf_filtered ("No breakpoints or watchpoints.\n");
3076 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3079 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3080 that a comparison of an unsigned with -1 is always false. */
3081 if (last_addr != (CORE_ADDR) - 1)
3082 set_next_address (last_addr);
3084 annotate_breakpoints_table_end ();
3089 breakpoints_info (bnum_exp, from_tty)
3096 bnum = parse_and_eval_address (bnum_exp);
3098 breakpoint_1 (bnum, 0);
3103 maintenance_info_breakpoints (bnum_exp, from_tty)
3110 bnum = parse_and_eval_address (bnum_exp);
3112 breakpoint_1 (bnum, 1);
3115 /* Print a message describing any breakpoints set at PC. */
3118 describe_other_breakpoints (pc, section)
3122 register int others = 0;
3123 register struct breakpoint *b;
3126 if (b->address == pc)
3127 if (overlay_debugging == 0 ||
3128 b->section == section)
3132 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3134 if (b->address == pc)
3135 if (overlay_debugging == 0 ||
3136 b->section == section)
3142 ((b->enable == disabled ||
3143 b->enable == shlib_disabled ||
3144 b->enable == call_disabled)
3145 ? " (disabled)" : ""),
3146 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3148 printf_filtered ("also set at pc ");
3149 print_address_numeric (pc, 1, gdb_stdout);
3150 printf_filtered (".\n");
3154 /* Set the default place to put a breakpoint
3155 for the `break' command with no arguments. */
3158 set_default_breakpoint (valid, addr, symtab, line)
3161 struct symtab *symtab;
3164 default_breakpoint_valid = valid;
3165 default_breakpoint_address = addr;
3166 default_breakpoint_symtab = symtab;
3167 default_breakpoint_line = line;
3170 /* Rescan breakpoints at address ADDRESS,
3171 marking the first one as "first" and any others as "duplicates".
3172 This is so that the bpt instruction is only inserted once. */
3175 check_duplicates (address, section)
3179 register struct breakpoint *b;
3180 register int count = 0;
3182 if (address == 0) /* Watchpoints are uninteresting */
3186 if (b->enable != disabled
3187 && b->enable != shlib_disabled
3188 && b->enable != call_disabled
3189 && b->address == address
3190 && (overlay_debugging == 0 || b->section == section))
3193 b->duplicate = count > 1;
3197 /* Low level routine to set a breakpoint.
3198 Takes as args the three things that every breakpoint must have.
3199 Returns the breakpoint object so caller can set other things.
3200 Does not set the breakpoint number!
3201 Does not print anything.
3203 ==> This routine should not be called if there is a chance of later
3204 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3205 your arguments BEFORE calling this routine! */
3208 set_raw_breakpoint (sal)
3209 struct symtab_and_line sal;
3211 register struct breakpoint *b, *b1;
3213 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3214 memset (b, 0, sizeof (*b));
3215 b->address = sal.pc;
3216 if (sal.symtab == NULL)
3217 b->source_file = NULL;
3219 b->source_file = savestring (sal.symtab->filename,
3220 strlen (sal.symtab->filename));
3221 b->section = sal.section;
3222 b->language = current_language->la_language;
3223 b->input_radix = input_radix;
3225 b->line_number = sal.line;
3226 b->enable = enabled;
3229 b->ignore_count = 0;
3232 b->dll_pathname = NULL;
3233 b->triggered_dll_pathname = NULL;
3234 b->forked_inferior_pid = 0;
3235 b->exec_pathname = NULL;
3237 /* Add this breakpoint to the end of the chain
3238 so that a list of breakpoints will come out in order
3239 of increasing numbers. */
3241 b1 = breakpoint_chain;
3243 breakpoint_chain = b;
3251 check_duplicates (sal.pc, sal.section);
3252 breakpoints_changed ();
3257 #ifdef GET_LONGJMP_TARGET
3260 create_longjmp_breakpoint (func_name)
3263 struct symtab_and_line sal;
3264 struct breakpoint *b;
3266 INIT_SAL (&sal); /* initialize to zeroes */
3267 if (func_name != NULL)
3269 struct minimal_symbol *m;
3271 m = lookup_minimal_symbol_text (func_name, NULL,
3272 (struct objfile *) NULL);
3274 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3278 sal.section = find_pc_overlay (sal.pc);
3279 b = set_raw_breakpoint (sal);
3283 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3284 b->disposition = donttouch;
3285 b->enable = disabled;
3288 b->addr_string = strsave (func_name);
3289 b->number = internal_breakpoint_number--;
3292 #endif /* #ifdef GET_LONGJMP_TARGET */
3294 /* Call this routine when stepping and nexting to enable a breakpoint
3295 if we do a longjmp(). When we hit that breakpoint, call
3296 set_longjmp_resume_breakpoint() to figure out where we are going. */
3299 enable_longjmp_breakpoint ()
3301 register struct breakpoint *b;
3304 if (b->type == bp_longjmp)
3306 b->enable = enabled;
3307 check_duplicates (b->address, b->section);
3312 disable_longjmp_breakpoint ()
3314 register struct breakpoint *b;
3317 if (b->type == bp_longjmp
3318 || b->type == bp_longjmp_resume)
3320 b->enable = disabled;
3321 check_duplicates (b->address, b->section);
3327 remove_solib_event_breakpoints ()
3329 register struct breakpoint *b, *temp;
3331 ALL_BREAKPOINTS_SAFE (b, temp)
3332 if (b->type == bp_shlib_event)
3333 delete_breakpoint (b);
3337 create_solib_event_breakpoint (address)
3340 struct breakpoint *b;
3341 struct symtab_and_line sal;
3343 INIT_SAL (&sal); /* initialize to zeroes */
3345 sal.section = find_pc_overlay (sal.pc);
3346 b = set_raw_breakpoint (sal);
3347 b->number = internal_breakpoint_number--;
3348 b->disposition = donttouch;
3349 b->type = bp_shlib_event;
3352 /* Disable any breakpoints that are on code in shared libraries. Only
3353 apply to enabled breakpoints, disabled ones can just stay disabled. */
3356 disable_breakpoints_in_shlibs (silent)
3359 struct breakpoint *b;
3360 int disabled_shlib_breaks = 0;
3362 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3365 #if defined (PC_SOLIB)
3366 if (((b->type == bp_breakpoint) ||
3367 (b->type == bp_hardware_breakpoint)) &&
3368 b->enable == enabled &&
3370 PC_SOLIB (b->address))
3372 b->enable = shlib_disabled;
3375 if (!disabled_shlib_breaks)
3377 target_terminal_ours_for_output ();
3378 warning ("Temporarily disabling shared library breakpoints:");
3380 disabled_shlib_breaks = 1;
3381 warning ("breakpoint #%d ", b->number);
3388 /* Try to reenable any breakpoints in shared libraries. */
3390 re_enable_breakpoints_in_shlibs ()
3392 struct breakpoint *b;
3395 if (b->enable == shlib_disabled)
3399 /* Do not reenable the breakpoint if the shared library
3400 is still not mapped in. */
3401 if (target_read_memory (b->address, buf, 1) == 0)
3402 b->enable = enabled;
3409 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
3414 enum bptype bp_kind;
3416 struct breakpoint *b;
3417 struct symtabs_and_lines sals;
3418 struct cleanup *old_chain;
3419 struct cleanup *canonical_strings_chain = NULL;
3420 char *addr_start = hookname;
3421 char *addr_end = NULL;
3422 char **canonical = (char **) NULL;
3423 int thread = -1; /* All threads. */
3425 /* Set a breakpoint on the specified hook. */
3426 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3427 addr_end = hookname;
3429 if (sals.nelts == 0)
3431 warning ("Unable to set a breakpoint on dynamic linker callback.");
3432 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3433 warning ("GDB will be unable to track shl_load/shl_unload calls");
3436 if (sals.nelts != 1)
3438 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3439 warning ("GDB will be unable to track shl_load/shl_unload calls");
3443 /* Make sure that all storage allocated in decode_line_1 gets freed
3444 in case the following errors out. */
3445 old_chain = make_cleanup (free, sals.sals);
3446 if (canonical != (char **) NULL)
3448 make_cleanup (free, canonical);
3449 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3450 if (canonical[0] != NULL)
3451 make_cleanup (free, canonical[0]);
3454 resolve_sal_pc (&sals.sals[0]);
3456 /* Remove the canonical strings from the cleanup, they are needed below. */
3457 if (canonical != (char **) NULL)
3458 discard_cleanups (canonical_strings_chain);
3460 b = set_raw_breakpoint (sals.sals[0]);
3461 set_breakpoint_count (breakpoint_count + 1);
3462 b->number = breakpoint_count;
3464 b->cond_string = (cond_string == NULL) ?
3465 NULL : savestring (cond_string, strlen (cond_string));
3468 if (canonical != (char **) NULL && canonical[0] != NULL)
3469 b->addr_string = canonical[0];
3470 else if (addr_start)
3471 b->addr_string = savestring (addr_start, addr_end - addr_start);
3473 b->enable = enabled;
3474 b->disposition = tempflag ? del : donttouch;
3476 if (dll_pathname == NULL)
3477 b->dll_pathname = NULL;
3480 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3481 strcpy (b->dll_pathname, dll_pathname);
3486 do_cleanups (old_chain);
3490 create_solib_load_event_breakpoint (hookname, tempflag,
3491 dll_pathname, cond_string)
3497 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3498 cond_string, bp_catch_load);
3502 create_solib_unload_event_breakpoint (hookname, tempflag,
3503 dll_pathname, cond_string)
3509 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3510 cond_string, bp_catch_unload);
3514 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3517 enum bptype bp_kind;
3519 struct symtab_and_line sal;
3520 struct breakpoint *b;
3521 int thread = -1; /* All threads. */
3528 b = set_raw_breakpoint (sal);
3529 set_breakpoint_count (breakpoint_count + 1);
3530 b->number = breakpoint_count;
3532 b->cond_string = (cond_string == NULL) ?
3533 NULL : savestring (cond_string, strlen (cond_string));
3535 b->addr_string = NULL;
3536 b->enable = enabled;
3537 b->disposition = tempflag ? del : donttouch;
3538 b->forked_inferior_pid = 0;
3546 create_fork_event_catchpoint (tempflag, cond_string)
3550 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3554 create_vfork_event_catchpoint (tempflag, cond_string)
3558 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3562 create_exec_event_catchpoint (tempflag, cond_string)
3566 struct symtab_and_line sal;
3567 struct breakpoint *b;
3568 int thread = -1; /* All threads. */
3575 b = set_raw_breakpoint (sal);
3576 set_breakpoint_count (breakpoint_count + 1);
3577 b->number = breakpoint_count;
3579 b->cond_string = (cond_string == NULL) ?
3580 NULL : savestring (cond_string, strlen (cond_string));
3582 b->addr_string = NULL;
3583 b->enable = enabled;
3584 b->disposition = tempflag ? del : donttouch;
3586 b->type = bp_catch_exec;
3592 hw_breakpoint_used_count ()
3594 register struct breakpoint *b;
3599 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3607 hw_watchpoint_used_count (type, other_type_used)
3609 int *other_type_used;
3611 register struct breakpoint *b;
3614 *other_type_used = 0;
3617 if (b->enable == enabled)
3619 if (b->type == type)
3621 else if ((b->type == bp_hardware_watchpoint ||
3622 b->type == bp_read_watchpoint ||
3623 b->type == bp_access_watchpoint)
3624 && b->enable == enabled)
3625 *other_type_used = 1;
3631 /* Call this after hitting the longjmp() breakpoint. Use this to set
3632 a new breakpoint at the target of the jmp_buf.
3634 FIXME - This ought to be done by setting a temporary breakpoint
3635 that gets deleted automatically... */
3638 set_longjmp_resume_breakpoint (pc, frame)
3640 struct frame_info *frame;
3642 register struct breakpoint *b;
3645 if (b->type == bp_longjmp_resume)
3648 b->enable = enabled;
3650 b->frame = frame->frame;
3653 check_duplicates (b->address, b->section);
3659 disable_watchpoints_before_interactive_call_start ()
3661 struct breakpoint *b;
3665 if (((b->type == bp_watchpoint)
3666 || (b->type == bp_hardware_watchpoint)
3667 || (b->type == bp_read_watchpoint)
3668 || (b->type == bp_access_watchpoint)
3669 || ep_is_exception_catchpoint (b))
3670 && (b->enable == enabled))
3672 b->enable = call_disabled;
3673 check_duplicates (b->address, b->section);
3679 enable_watchpoints_after_interactive_call_stop ()
3681 struct breakpoint *b;
3685 if (((b->type == bp_watchpoint)
3686 || (b->type == bp_hardware_watchpoint)
3687 || (b->type == bp_read_watchpoint)
3688 || (b->type == bp_access_watchpoint)
3689 || ep_is_exception_catchpoint (b))
3690 && (b->enable == call_disabled))
3692 b->enable = enabled;
3693 check_duplicates (b->address, b->section);
3699 /* Set a breakpoint that will evaporate an end of command
3700 at address specified by SAL.
3701 Restrict it to frame FRAME if FRAME is nonzero. */
3704 set_momentary_breakpoint (sal, frame, type)
3705 struct symtab_and_line sal;
3706 struct frame_info *frame;
3709 register struct breakpoint *b;
3710 b = set_raw_breakpoint (sal);
3712 b->enable = enabled;
3713 b->disposition = donttouch;
3714 b->frame = (frame ? frame->frame : 0);
3716 /* If we're debugging a multi-threaded program, then we
3717 want momentary breakpoints to be active in only a
3718 single thread of control. */
3719 if (in_thread_list (inferior_pid))
3720 b->thread = pid_to_thread_id (inferior_pid);
3726 /* Tell the user we have just set a breakpoint B. */
3730 struct breakpoint *b;
3734 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3735 watchpoint) other than breakpoint creation. It should be possible to
3736 clean this up and at the same time replace the random calls to
3737 breakpoint_changed with this hook, as has already been done for
3738 delete_breakpoint_hook and so on. */
3739 if (create_breakpoint_hook)
3740 create_breakpoint_hook (b);
3741 breakpoint_create_event (b->number);
3746 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3749 printf_filtered ("Watchpoint %d: ", b->number);
3750 print_expression (b->exp, gdb_stdout);
3752 case bp_hardware_watchpoint:
3753 printf_filtered ("Hardware watchpoint %d: ", b->number);
3754 print_expression (b->exp, gdb_stdout);
3756 case bp_read_watchpoint:
3757 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3758 print_expression (b->exp, gdb_stdout);
3760 case bp_access_watchpoint:
3761 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3763 print_expression (b->exp, gdb_stdout);
3766 printf_filtered ("Breakpoint %d", b->number);
3769 case bp_hardware_breakpoint:
3770 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3774 case bp_catch_unload:
3775 printf_filtered ("Catchpoint %d (%s %s)",
3777 (b->type == bp_catch_load) ? "load" : "unload",
3778 (b->dll_pathname != NULL) ?
3779 b->dll_pathname : "<any library>");
3782 case bp_catch_vfork:
3783 printf_filtered ("Catchpoint %d (%s)",
3785 (b->type == bp_catch_fork) ? "fork" : "vfork");
3788 printf_filtered ("Catchpoint %d (exec)",
3791 case bp_catch_catch:
3792 case bp_catch_throw:
3793 printf_filtered ("Catchpoint %d (%s)",
3795 (b->type == bp_catch_catch) ? "catch" : "throw");
3801 case bp_longjmp_resume:
3802 case bp_step_resume:
3803 case bp_through_sigtramp:
3805 case bp_watchpoint_scope:
3806 case bp_shlib_event:
3811 if (addressprint || b->source_file == NULL)
3813 printf_filtered (" at ");
3814 print_address_numeric (b->address, 1, gdb_stdout);
3817 printf_filtered (": file %s, line %d.",
3818 b->source_file, b->line_number);
3819 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
3820 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
3822 printf_filtered ("\n");
3826 /* Set a breakpoint according to ARG (function, linenum or *address)
3827 flag: first bit : 0 non-temporary, 1 temporary.
3828 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
3831 break_command_1 (arg, flag, from_tty)
3835 int tempflag, hardwareflag;
3836 struct symtabs_and_lines sals;
3837 struct symtab_and_line sal;
3838 register struct expression *cond = 0;
3839 register struct breakpoint *b;
3841 /* Pointers in arg to the start, and one past the end, of the condition. */
3842 char *cond_start = NULL;
3843 char *cond_end = NULL;
3844 /* Pointers in arg to the start, and one past the end,
3845 of the address part. */
3846 char *addr_start = NULL;
3847 char *addr_end = NULL;
3848 struct cleanup *old_chain;
3849 struct cleanup *canonical_strings_chain = NULL;
3850 char **canonical = (char **) NULL;
3854 hardwareflag = flag & BP_HARDWAREFLAG;
3855 tempflag = flag & BP_TEMPFLAG;
3860 INIT_SAL (&sal); /* initialize to zeroes */
3862 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3864 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
3865 && (arg[2] == ' ' || arg[2] == '\t')))
3867 if (default_breakpoint_valid)
3869 sals.sals = (struct symtab_and_line *)
3870 xmalloc (sizeof (struct symtab_and_line));
3871 sal.pc = default_breakpoint_address;
3872 sal.line = default_breakpoint_line;
3873 sal.symtab = default_breakpoint_symtab;
3874 sal.section = find_pc_overlay (sal.pc);
3879 error ("No default breakpoint address now.");
3885 /* Force almost all breakpoints to be in terms of the
3886 current_source_symtab (which is decode_line_1's default). This
3887 should produce the results we want almost all of the time while
3888 leaving default_breakpoint_* alone. */
3889 if (default_breakpoint_valid
3890 && (!current_source_symtab
3891 || (arg && (*arg == '+' || *arg == '-'))))
3892 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3893 default_breakpoint_line, &canonical);
3895 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
3903 /* Make sure that all storage allocated in decode_line_1 gets freed
3904 in case the following `for' loop errors out. */
3905 old_chain = make_cleanup (free, sals.sals);
3906 if (canonical != (char **) NULL)
3908 make_cleanup (free, canonical);
3909 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3910 for (i = 0; i < sals.nelts; i++)
3912 if (canonical[i] != NULL)
3913 make_cleanup (free, canonical[i]);
3917 thread = -1; /* No specific thread yet */
3919 /* Resolve all line numbers to PC's, and verify that conditions
3920 can be parsed, before setting any breakpoints. */
3921 for (i = 0; i < sals.nelts; i++)
3923 char *tok, *end_tok;
3926 resolve_sal_pc (&sals.sals[i]);
3928 /* It's possible for the PC to be nonzero, but still an illegal
3929 value on some targets.
3931 For example, on HP-UX if you start gdb, and before running the
3932 inferior you try to set a breakpoint on a shared library function
3933 "foo" where the inferior doesn't call "foo" directly but does
3934 pass its address to another function call, then we do find a
3935 minimal symbol for the "foo", but it's address is invalid.
3936 (Appears to be an index into a table that the loader sets up
3937 when the inferior is run.)
3939 Give the target a chance to bless sals.sals[i].pc before we
3940 try to make a breakpoint for it. */
3941 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
3943 error ("Cannot break on %s without a running program.",
3951 while (*tok == ' ' || *tok == '\t')
3956 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3959 toklen = end_tok - tok;
3961 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3963 tok = cond_start = end_tok + 1;
3964 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3967 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3973 thread = strtol (tok, &tok, 0);
3975 error ("Junk after thread keyword.");
3976 if (!valid_thread_id (thread))
3977 error ("Unknown thread %d\n", thread);
3980 error ("Junk at end of arguments.");
3985 int i, target_resources_ok;
3987 i = hw_breakpoint_used_count ();
3988 target_resources_ok =
3989 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
3991 if (target_resources_ok == 0)
3992 error ("No hardware breakpoint support in the target.");
3993 else if (target_resources_ok < 0)
3994 error ("Hardware breakpoints used exceeds limit.");
3997 /* Remove the canonical strings from the cleanup, they are needed below. */
3998 if (canonical != (char **) NULL)
3999 discard_cleanups (canonical_strings_chain);
4001 /* Now set all the breakpoints. */
4002 for (i = 0; i < sals.nelts; i++)
4007 describe_other_breakpoints (sal.pc, sal.section);
4009 b = set_raw_breakpoint (sal);
4010 set_breakpoint_count (breakpoint_count + 1);
4011 b->number = breakpoint_count;
4012 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4016 /* If a canonical line spec is needed use that instead of the
4018 if (canonical != (char **) NULL && canonical[i] != NULL)
4019 b->addr_string = canonical[i];
4020 else if (addr_start)
4021 b->addr_string = savestring (addr_start, addr_end - addr_start);
4023 b->cond_string = savestring (cond_start, cond_end - cond_start);
4025 b->enable = enabled;
4026 b->disposition = tempflag ? del : donttouch;
4032 warning ("Multiple breakpoints were set.");
4033 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4035 do_cleanups (old_chain);
4039 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4044 struct frame_info *frame;
4045 CORE_ADDR low, high, selected_pc = 0;
4046 char *extra_args, *level_arg, *addr_string;
4047 int extra_args_len = 0, if_arg = 0;
4050 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4053 if (default_breakpoint_valid)
4057 selected_pc = selected_frame->pc;
4062 error ("No selected frame.");
4065 error ("No default breakpoint address now.");
4069 extra_args = strchr (arg, ' ');
4073 extra_args_len = strlen (extra_args);
4074 level_arg = (char *) xmalloc (extra_args - arg);
4075 strncpy (level_arg, arg, extra_args - arg - 1);
4076 level_arg[extra_args - arg - 1] = '\0';
4080 level_arg = (char *) xmalloc (strlen (arg) + 1);
4081 strcpy (level_arg, arg);
4084 frame = parse_frame_specification (level_arg);
4086 selected_pc = frame->pc;
4093 extra_args_len = strlen (arg);
4098 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4100 addr_string = (char *) xmalloc (26 + extra_args_len);
4102 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4104 sprintf (addr_string, "*0x%s", paddr_nz (high));
4105 break_command_1 (addr_string, flag, from_tty);
4109 error ("No function contains the specified address");
4112 error ("Unable to set breakpoint at procedure exit");
4117 break_at_finish_command_1 (arg, flag, from_tty)
4122 char *addr_string, *break_string, *beg_addr_string;
4123 CORE_ADDR low, high;
4124 struct symtabs_and_lines sals;
4125 struct symtab_and_line sal;
4126 struct cleanup *old_chain;
4128 int extra_args_len = 0;
4132 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4134 if (default_breakpoint_valid)
4138 addr_string = (char *) xmalloc (15);
4139 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
4144 error ("No selected frame.");
4147 error ("No default breakpoint address now.");
4151 addr_string = (char *) xmalloc (strlen (arg) + 1);
4152 strcpy (addr_string, arg);
4158 extra_args_len = strlen (arg);
4162 /* get the stuff after the function name or address */
4163 extra_args = strchr (arg, ' ');
4167 extra_args_len = strlen (extra_args);
4174 beg_addr_string = addr_string;
4175 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4178 free (beg_addr_string);
4179 old_chain = make_cleanup (free, sals.sals);
4180 for (i = 0; (i < sals.nelts); i++)
4183 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4185 break_string = (char *) xmalloc (extra_args_len + 26);
4187 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
4189 sprintf (break_string, "*0x%s", paddr_nz (high));
4190 break_command_1 (break_string, flag, from_tty);
4191 free (break_string);
4194 error ("No function contains the specified address");
4198 warning ("Multiple breakpoints were set.\n");
4199 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4201 do_cleanups (old_chain);
4205 /* Helper function for break_command_1 and disassemble_command. */
4208 resolve_sal_pc (sal)
4209 struct symtab_and_line *sal;
4213 if (sal->pc == 0 && sal->symtab != NULL)
4215 if (!find_line_pc (sal->symtab, sal->line, &pc))
4216 error ("No line %d in file \"%s\".",
4217 sal->line, sal->symtab->filename);
4221 if (sal->section == 0 && sal->symtab != NULL)
4223 struct blockvector *bv;
4228 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4231 b = BLOCKVECTOR_BLOCK (bv, index);
4232 sym = block_function (b);
4235 fixup_symbol_section (sym, sal->symtab->objfile);
4236 sal->section = SYMBOL_BFD_SECTION (sym);
4240 /* It really is worthwhile to have the section, so we'll just
4241 have to look harder. This case can be executed if we have
4242 line numbers but no functions (as can happen in assembly
4245 struct minimal_symbol *msym;
4247 msym = lookup_minimal_symbol_by_pc (sal->pc);
4249 sal->section = SYMBOL_BFD_SECTION (msym);
4256 break_command (arg, from_tty)
4260 break_command_1 (arg, 0, from_tty);
4264 break_at_finish_command (arg, from_tty)
4268 break_at_finish_command_1 (arg, 0, from_tty);
4272 break_at_finish_at_depth_command (arg, from_tty)
4276 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4280 tbreak_command (arg, from_tty)
4284 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4288 tbreak_at_finish_command (arg, from_tty)
4292 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4296 hbreak_command (arg, from_tty)
4300 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4304 thbreak_command (arg, from_tty)
4308 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4312 stop_command (arg, from_tty)
4316 printf_filtered ("Specify the type of breakpoint to set.\n\
4317 Usage: stop in <function | address>\n\
4322 stopin_command (arg, from_tty)
4328 if (arg == (char *) NULL)
4330 else if (*arg != '*')
4335 /* look for a ':'. If this is a line number specification, then
4336 say it is bad, otherwise, it should be an address or
4337 function/method name */
4338 while (*argptr && !hasColon)
4340 hasColon = (*argptr == ':');
4345 badInput = (*argptr != ':'); /* Not a class::method */
4347 badInput = isdigit (*arg); /* a simple line number */
4351 printf_filtered ("Usage: stop in <function | address>\n");
4353 break_command_1 (arg, 0, from_tty);
4357 stopat_command (arg, from_tty)
4363 if (arg == (char *) NULL || *arg == '*') /* no line number */
4370 /* look for a ':'. If there is a '::' then get out, otherwise
4371 it is probably a line number. */
4372 while (*argptr && !hasColon)
4374 hasColon = (*argptr == ':');
4379 badInput = (*argptr == ':'); /* we have class::method */
4381 badInput = !isdigit (*arg); /* not a line number */
4385 printf_filtered ("Usage: stop at <line>\n");
4387 break_command_1 (arg, 0, from_tty);
4391 /* accessflag: hw_write: watch write,
4392 hw_read: watch read,
4393 hw_access: watch access (read or write) */
4395 watch_command_1 (arg, accessflag, from_tty)
4400 struct breakpoint *b;
4401 struct symtab_and_line sal;
4402 struct expression *exp;
4403 struct block *exp_valid_block;
4404 struct value *val, *mark;
4405 struct frame_info *frame;
4406 struct frame_info *prev_frame = NULL;
4407 char *exp_start = NULL;
4408 char *exp_end = NULL;
4409 char *tok, *end_tok;
4411 char *cond_start = NULL;
4412 char *cond_end = NULL;
4413 struct expression *cond = NULL;
4414 int i, other_type_used, target_resources_ok = 0;
4415 enum bptype bp_type;
4418 INIT_SAL (&sal); /* initialize to zeroes */
4420 /* Parse arguments. */
4421 innermost_block = NULL;
4423 exp = parse_exp_1 (&arg, 0, 0);
4425 exp_valid_block = innermost_block;
4426 mark = value_mark ();
4427 val = evaluate_expression (exp);
4428 release_value (val);
4429 if (VALUE_LAZY (val))
4430 value_fetch_lazy (val);
4433 while (*tok == ' ' || *tok == '\t')
4437 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4440 toklen = end_tok - tok;
4441 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4443 tok = cond_start = end_tok + 1;
4444 cond = parse_exp_1 (&tok, 0, 0);
4448 error ("Junk at end of command.");
4450 if (accessflag == hw_read)
4451 bp_type = bp_read_watchpoint;
4452 else if (accessflag == hw_access)
4453 bp_type = bp_access_watchpoint;
4455 bp_type = bp_hardware_watchpoint;
4457 mem_cnt = can_use_hardware_watchpoint (val);
4458 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4459 error ("Expression cannot be implemented with read/access watchpoint.");
4462 i = hw_watchpoint_used_count (bp_type, &other_type_used);
4463 target_resources_ok =
4464 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4466 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4467 error ("Target does not support this type of hardware watchpoint.");
4469 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4470 error ("Target can only support one kind of HW watchpoint at a time.");
4473 #if defined(HPUXHPPA)
4474 /* On HP-UX if you set a h/w
4475 watchpoint before the "run" command, the inferior dies with a e.g.,
4476 SIGILL once you start it. I initially believed this was due to a
4477 bad interaction between page protection traps and the initial
4478 startup sequence by the dynamic linker.
4480 However, I tried avoiding that by having HP-UX's implementation of
4481 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4482 yet, which forced slow watches before a "run" or "attach", and it
4483 still fails somewhere in the startup code.
4485 Until I figure out what's happening, I'm disallowing watches altogether
4486 before the "run" or "attach" command. We'll tell the user they must
4487 set watches after getting the program started. */
4488 if (!target_has_execution)
4490 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4493 #endif /* HPUXHPPA */
4495 /* Now set up the breakpoint. */
4496 b = set_raw_breakpoint (sal);
4497 set_breakpoint_count (breakpoint_count + 1);
4498 b->number = breakpoint_count;
4499 b->disposition = donttouch;
4501 b->exp_valid_block = exp_valid_block;
4502 b->exp_string = savestring (exp_start, exp_end - exp_start);
4506 b->cond_string = savestring (cond_start, cond_end - cond_start);
4510 frame = block_innermost_frame (exp_valid_block);
4513 prev_frame = get_prev_frame (frame);
4514 b->watchpoint_frame = frame->frame;
4517 b->watchpoint_frame = (CORE_ADDR) 0;
4519 if (mem_cnt && target_resources_ok > 0)
4522 b->type = bp_watchpoint;
4524 /* If the expression is "local", then set up a "watchpoint scope"
4525 breakpoint at the point where we've left the scope of the watchpoint
4527 if (innermost_block)
4531 struct breakpoint *scope_breakpoint;
4532 struct symtab_and_line scope_sal;
4534 INIT_SAL (&scope_sal); /* initialize to zeroes */
4535 scope_sal.pc = get_frame_pc (prev_frame);
4536 scope_sal.section = find_pc_overlay (scope_sal.pc);
4538 scope_breakpoint = set_raw_breakpoint (scope_sal);
4539 set_breakpoint_count (breakpoint_count + 1);
4540 scope_breakpoint->number = breakpoint_count;
4542 scope_breakpoint->type = bp_watchpoint_scope;
4543 scope_breakpoint->enable = enabled;
4545 /* Automatically delete the breakpoint when it hits. */
4546 scope_breakpoint->disposition = del;
4548 /* Only break in the proper frame (help with recursion). */
4549 scope_breakpoint->frame = prev_frame->frame;
4551 /* Set the address at which we will stop. */
4552 scope_breakpoint->address = get_frame_pc (prev_frame);
4554 /* The scope breakpoint is related to the watchpoint. We
4555 will need to act on them together. */
4556 b->related_breakpoint = scope_breakpoint;
4559 value_free_to_mark (mark);
4563 /* Return count of locations need to be watched and can be handled
4564 in hardware. If the watchpoint can not be handled
4565 in hardware return zero. */
4567 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4568 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4569 ((BYTE_SIZE) <= (REGISTER_SIZE))
4572 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4573 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4574 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
4578 can_use_hardware_watchpoint (v)
4581 int found_memory_cnt = 0;
4583 /* Did the user specifically forbid us to use hardware watchpoints? */
4584 if (!can_use_hw_watchpoints)
4587 /* Make sure all the intermediate values are in memory. Also make sure
4588 we found at least one memory expression. Guards against watch 0x12345,
4589 which is meaningless, but could cause errors if one tries to insert a
4590 hardware watchpoint for the constant expression. */
4591 for (; v; v = v->next)
4593 if (v->lval == lval_memory)
4595 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4596 int len = TYPE_LENGTH (VALUE_TYPE (v));
4598 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4603 else if (v->lval != not_lval && v->modifiable == 0)
4604 return 0; /* ??? What does this represent? */
4605 else if (v->lval == lval_register)
4606 return 0; /* cannot watch a register with a HW watchpoint */
4609 /* The expression itself looks suitable for using a hardware
4610 watchpoint, but give the target machine a chance to reject it. */
4611 return found_memory_cnt;
4615 watch_command (arg, from_tty)
4619 watch_command_1 (arg, hw_write, from_tty);
4623 rwatch_command (arg, from_tty)
4627 watch_command_1 (arg, hw_read, from_tty);
4631 awatch_command (arg, from_tty)
4635 watch_command_1 (arg, hw_access, from_tty);
4639 /* Helper routines for the until_command routine in infcmd.c. Here
4640 because it uses the mechanisms of breakpoints. */
4642 /* This function is called by fetch_inferior_event via the
4643 cmd_continuation pointer, to complete the until command. It takes
4644 care of cleaning up the temporary breakpoints set up by the until
4647 until_break_command_continuation (arg)
4648 struct continuation_arg *arg;
4650 /* Do all the exec cleanups, which at this point should only be the
4651 one set up in the first part of the until_break_command
4653 do_exec_cleanups (ALL_CLEANUPS);
4658 until_break_command (arg, from_tty)
4662 struct symtabs_and_lines sals;
4663 struct symtab_and_line sal;
4664 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4665 struct breakpoint *breakpoint;
4666 struct cleanup *old_chain;
4668 clear_proceed_status ();
4670 /* Set a breakpoint where the user wants it and at return from
4673 if (default_breakpoint_valid)
4674 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4675 default_breakpoint_line, (char ***) NULL);
4677 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4678 0, (char ***) NULL);
4680 if (sals.nelts != 1)
4681 error ("Couldn't get information on specified line.");
4684 free ((PTR) sals.sals); /* malloc'd, so freed */
4687 error ("Junk at end of arguments.");
4689 resolve_sal_pc (&sal);
4691 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
4693 if (!async_p || !target_has_async)
4694 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4697 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4699 /* If we are running asynchronously, and the target supports async
4700 execution, we are not waiting for the target to stop, in the call
4701 tp proceed, below. This means that we cannot delete the
4702 brekpoints until the target has actually stopped. The only place
4703 where we get a chance to do that is in fetch_inferior_event, so
4704 we must set things up for that. */
4706 if (async_p && target_has_async)
4708 /* In this case we don't need args for the continuation, because
4709 all it needs to do is do the cleanups in the
4710 exec_cleanup_chain, which will be only those inserted by this
4711 function. We can get away by using ALL_CLEANUPS. */
4712 add_continuation (until_break_command_continuation, NULL);
4715 /* Keep within the current frame */
4719 sal = find_pc_line (prev_frame->pc, 0);
4720 sal.pc = prev_frame->pc;
4721 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
4722 if (!async_p || !target_has_async)
4723 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4725 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4728 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
4729 /* Do the cleanups now, anly if we are not running asynchronously,
4730 of if we are, but the target is still synchronous. */
4731 if (!async_p || !target_has_async)
4732 do_cleanups (old_chain);
4736 /* These aren't used; I don't konw what they were for. */
4737 /* Set a breakpoint at the catch clause for NAME. */
4739 catch_breakpoint (name)
4745 disable_catch_breakpoint ()
4750 delete_catch_breakpoint ()
4755 enable_catch_breakpoint ()
4762 struct sal_chain *next;
4763 struct symtab_and_line sal;
4767 /* Not really used -- invocation in handle_gnu_4_16_catch_command
4768 had been commented out in the v.4.16 sources, and stays
4769 disabled there now because "catch NAME" syntax isn't allowed.
4771 /* This isn't used; I don't know what it was for. */
4772 /* For each catch clause identified in ARGS, run FUNCTION
4773 with that clause as an argument. */
4774 static struct symtabs_and_lines
4775 map_catch_names (args, function)
4779 register char *p = args;
4781 struct symtabs_and_lines sals;
4783 struct sal_chain *sal_chain = 0;
4787 error_no_arg ("one or more catch names");
4795 /* Don't swallow conditional part. */
4796 if (p1[0] == 'i' && p1[1] == 'f'
4797 && (p1[2] == ' ' || p1[2] == '\t'))
4803 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4807 if (*p1 && *p1 != ' ' && *p1 != '\t')
4808 error ("Arguments must be catch names.");
4814 struct sal_chain *next = (struct sal_chain *)
4815 alloca (sizeof (struct sal_chain));
4816 next->next = sal_chain;
4817 next->sal = get_catch_sal (p);
4822 printf_unfiltered ("No catch clause for exception %s.\n", p);
4827 while (*p == ' ' || *p == '\t')
4833 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4835 static struct symtabs_and_lines
4836 get_catch_sals (this_level_only)
4837 int this_level_only;
4839 register struct blockvector *bl;
4840 register struct block *block;
4841 int index, have_default = 0;
4843 struct symtabs_and_lines sals;
4844 struct sal_chain *sal_chain = 0;
4845 char *blocks_searched;
4847 /* Not sure whether an error message is always the correct response,
4848 but it's better than a core dump. */
4849 if (selected_frame == NULL)
4850 error ("No selected frame.");
4851 block = get_frame_block (selected_frame);
4852 pc = selected_frame->pc;
4858 error ("No symbol table info available.\n");
4860 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4861 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4862 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4866 CORE_ADDR end = BLOCK_END (block) - 4;
4869 if (bl != blockvector_for_pc (end, &index))
4870 error ("blockvector blotch");
4871 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4872 error ("blockvector botch");
4873 last_index = BLOCKVECTOR_NBLOCKS (bl);
4876 /* Don't print out blocks that have gone by. */
4877 while (index < last_index
4878 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4881 while (index < last_index
4882 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4884 if (blocks_searched[index] == 0)
4886 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4889 register struct symbol *sym;
4891 nsyms = BLOCK_NSYMS (b);
4893 for (i = 0; i < nsyms; i++)
4895 sym = BLOCK_SYM (b, i);
4896 if (STREQ (SYMBOL_NAME (sym), "default"))
4902 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4904 struct sal_chain *next = (struct sal_chain *)
4905 alloca (sizeof (struct sal_chain));
4906 next->next = sal_chain;
4907 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
4912 blocks_searched[index] = 1;
4918 if (sal_chain && this_level_only)
4921 /* After handling the function's top-level block, stop.
4922 Don't continue to its superblock, the block of
4923 per-file symbols. */
4924 if (BLOCK_FUNCTION (block))
4926 block = BLOCK_SUPERBLOCK (block);
4931 struct sal_chain *tmp_chain;
4933 /* Count the number of entries. */
4934 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4935 tmp_chain = tmp_chain->next)
4939 sals.sals = (struct symtab_and_line *)
4940 xmalloc (index * sizeof (struct symtab_and_line));
4941 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4942 sals.sals[index] = sal_chain->sal;
4949 ep_skip_leading_whitespace (s)
4952 if ((s == NULL) || (*s == NULL))
4954 while (isspace (**s))
4958 /* This function examines a string, and attempts to find a token
4959 that might be an event name in the leading characters. If a
4960 possible match is found, a pointer to the last character of
4961 the token is returned. Else, NULL is returned. */
4964 ep_find_event_name_end (arg)
4968 char *event_name_end = NULL;
4970 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4974 /* We break out of the loop when we find a token delimiter.
4975 Basically, we're looking for alphanumerics and underscores;
4976 anything else delimites the token. */
4979 if (!isalnum (*s) && (*s != '_'))
4985 return event_name_end;
4989 /* This function attempts to parse an optional "if <cond>" clause
4990 from the arg string. If one is not found, it returns NULL.
4992 Else, it returns a pointer to the condition string. (It does not
4993 attempt to evaluate the string against a particular block.) And,
4994 it updates arg to point to the first character following the parsed
4995 if clause in the arg string. */
4998 ep_parse_optional_if_clause (arg)
5003 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5006 /* Skip the "if" keyword. */
5009 /* Skip any extra leading whitespace, and record the start of the
5010 condition string. */
5011 ep_skip_leading_whitespace (arg);
5014 /* Assume that the condition occupies the remainder of the arg string. */
5015 (*arg) += strlen (cond_string);
5020 /* This function attempts to parse an optional filename from the arg
5021 string. If one is not found, it returns NULL.
5023 Else, it returns a pointer to the parsed filename. (This function
5024 makes no attempt to verify that a file of that name exists, or is
5025 accessible.) And, it updates arg to point to the first character
5026 following the parsed filename in the arg string.
5028 Note that clients needing to preserve the returned filename for
5029 future access should copy it to their own buffers. */
5031 ep_parse_optional_filename (arg)
5034 static char filename[1024];
5039 if ((*arg_p == '\0') || isspace (*arg_p))
5057 /* Commands to deal with catching events, such as signals, exceptions,
5058 process start/exit, etc. */
5062 catch_fork, catch_vfork
5066 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5072 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
5073 catch_fork_kind fork_kind;
5078 char *cond_string = NULL;
5080 ep_skip_leading_whitespace (&arg);
5082 /* The allowed syntax is:
5084 catch [v]fork if <cond>
5086 First, check if there's an if clause. */
5087 cond_string = ep_parse_optional_if_clause (&arg);
5089 if ((*arg != '\0') && !isspace (*arg))
5090 error ("Junk at end of arguments.");
5092 /* If this target supports it, create a fork or vfork catchpoint
5093 and enable reporting of such events. */
5097 create_fork_event_catchpoint (tempflag, cond_string);
5100 create_vfork_event_catchpoint (tempflag, cond_string);
5103 error ("unsupported or unknown fork kind; cannot catch it");
5109 catch_exec_command_1 (arg, tempflag, from_tty)
5114 char *cond_string = NULL;
5116 ep_skip_leading_whitespace (&arg);
5118 /* The allowed syntax is:
5120 catch exec if <cond>
5122 First, check if there's an if clause. */
5123 cond_string = ep_parse_optional_if_clause (&arg);
5125 if ((*arg != '\0') && !isspace (*arg))
5126 error ("Junk at end of arguments.");
5128 /* If this target supports it, create an exec catchpoint
5129 and enable reporting of such events. */
5130 create_exec_event_catchpoint (tempflag, cond_string);
5133 #if defined(SOLIB_ADD)
5135 catch_load_command_1 (arg, tempflag, from_tty)
5140 char *dll_pathname = NULL;
5141 char *cond_string = NULL;
5143 ep_skip_leading_whitespace (&arg);
5145 /* The allowed syntax is:
5147 catch load if <cond>
5148 catch load <filename>
5149 catch load <filename> if <cond>
5151 The user is not allowed to specify the <filename> after an
5154 We'll ignore the pathological case of a file named "if".
5156 First, check if there's an if clause. If so, then there
5157 cannot be a filename. */
5158 cond_string = ep_parse_optional_if_clause (&arg);
5160 /* If there was an if clause, then there cannot be a filename.
5161 Else, there might be a filename and an if clause. */
5162 if (cond_string == NULL)
5164 dll_pathname = ep_parse_optional_filename (&arg);
5165 ep_skip_leading_whitespace (&arg);
5166 cond_string = ep_parse_optional_if_clause (&arg);
5169 if ((*arg != '\0') && !isspace (*arg))
5170 error ("Junk at end of arguments.");
5172 /* Create a load breakpoint that only triggers when a load of
5173 the specified dll (or any dll, if no pathname was specified)
5175 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5176 dll_pathname, cond_string);
5180 catch_unload_command_1 (arg, tempflag, from_tty)
5185 char *dll_pathname = NULL;
5186 char *cond_string = NULL;
5188 ep_skip_leading_whitespace (&arg);
5190 /* The allowed syntax is:
5192 catch unload if <cond>
5193 catch unload <filename>
5194 catch unload <filename> if <cond>
5196 The user is not allowed to specify the <filename> after an
5199 We'll ignore the pathological case of a file named "if".
5201 First, check if there's an if clause. If so, then there
5202 cannot be a filename. */
5203 cond_string = ep_parse_optional_if_clause (&arg);
5205 /* If there was an if clause, then there cannot be a filename.
5206 Else, there might be a filename and an if clause. */
5207 if (cond_string == NULL)
5209 dll_pathname = ep_parse_optional_filename (&arg);
5210 ep_skip_leading_whitespace (&arg);
5211 cond_string = ep_parse_optional_if_clause (&arg);
5214 if ((*arg != '\0') && !isspace (*arg))
5215 error ("Junk at end of arguments.");
5217 /* Create an unload breakpoint that only triggers when an unload of
5218 the specified dll (or any dll, if no pathname was specified)
5220 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5221 dll_pathname, cond_string);
5223 #endif /* SOLIB_ADD */
5225 /* Commands to deal with catching exceptions. */
5227 /* Set a breakpoint at the specified callback routine for an
5228 exception event callback */
5231 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5234 enum exception_event_kind ex_event;
5235 struct symtab_and_line *sal;
5237 struct breakpoint *b;
5238 int thread = -1; /* All threads. */
5240 if (!sal) /* no exception support? */
5243 b = set_raw_breakpoint (*sal);
5244 set_breakpoint_count (breakpoint_count + 1);
5245 b->number = breakpoint_count;
5247 b->cond_string = (cond_string == NULL) ?
5248 NULL : savestring (cond_string, strlen (cond_string));
5250 b->addr_string = NULL;
5251 b->enable = enabled;
5252 b->disposition = tempflag ? del : donttouch;
5255 case EX_EVENT_THROW:
5256 b->type = bp_catch_throw;
5258 case EX_EVENT_CATCH:
5259 b->type = bp_catch_catch;
5261 default: /* error condition */
5263 b->enable = disabled;
5264 error ("Internal error -- invalid catchpoint kind");
5269 /* Deal with "catch catch" and "catch throw" commands */
5272 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5273 enum exception_event_kind ex_event;
5278 char *cond_string = NULL;
5279 struct symtab_and_line *sal = NULL;
5281 ep_skip_leading_whitespace (&arg);
5283 cond_string = ep_parse_optional_if_clause (&arg);
5285 if ((*arg != '\0') && !isspace (*arg))
5286 error ("Junk at end of arguments.");
5288 if ((ex_event != EX_EVENT_THROW) &&
5289 (ex_event != EX_EVENT_CATCH))
5290 error ("Unsupported or unknown exception event; cannot catch it");
5292 /* See if we can find a callback routine */
5293 sal = target_enable_exception_callback (ex_event, 1);
5297 /* We have callbacks from the runtime system for exceptions.
5298 Set a breakpoint on the sal found, if no errors */
5299 if (sal != (struct symtab_and_line *) -1)
5300 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5302 return; /* something went wrong with setting up callbacks */
5306 /* No callbacks from runtime system for exceptions.
5307 Try GNU C++ exception breakpoints using labels in debug info. */
5308 if (ex_event == EX_EVENT_CATCH)
5310 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5312 else if (ex_event == EX_EVENT_THROW)
5314 /* Set a breakpoint on __raise_exception () */
5316 warning ("Unsupported with this platform/compiler combination.");
5317 warning ("Perhaps you can achieve the effect you want by setting");
5318 warning ("a breakpoint on __raise_exception().");
5323 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5324 inside a catch_errors */
5327 cover_target_enable_exception_callback (arg)
5330 args_for_catchpoint_enable *args = arg;
5331 struct symtab_and_line *sal;
5332 sal = target_enable_exception_callback (args->kind, args->enable);
5335 else if (sal == (struct symtab_and_line *) -1)
5338 return 1; /*is valid */
5343 /* This is the original v.4.16 and earlier version of the
5344 catch_command_1() function. Now that other flavours of "catch"
5345 have been introduced, and since exception handling can be handled
5346 in other ways (through target ops) also, this is used only for the
5347 GNU C++ exception handling system.
5348 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5349 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5350 there was no code in GDB 4.16 for "catch throw".
5352 Called from catch_exception_command_1 () */
5356 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5361 /* First, translate ARG into something we can deal with in terms
5364 struct symtabs_and_lines sals;
5365 struct symtab_and_line sal;
5366 register struct expression *cond = 0;
5367 register struct breakpoint *b;
5371 INIT_SAL (&sal); /* initialize to zeroes */
5373 /* If no arg given, or if first arg is 'if ', all active catch clauses
5374 are breakpointed. */
5376 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5377 && (arg[2] == ' ' || arg[2] == '\t')))
5379 /* Grab all active catch clauses. */
5380 sals = get_catch_sals (0);
5384 /* Grab selected catch clauses. */
5385 error ("catch NAME not implemented");
5388 /* Not sure why this code has been disabled. I'm leaving
5389 it disabled. We can never come here now anyway
5390 since we don't allow the "catch NAME" syntax.
5393 /* This isn't used; I don't know what it was for. */
5394 sals = map_catch_names (arg, catch_breakpoint);
5402 for (i = 0; i < sals.nelts; i++)
5404 resolve_sal_pc (&sals.sals[i]);
5408 if (arg[0] == 'i' && arg[1] == 'f'
5409 && (arg[2] == ' ' || arg[2] == '\t'))
5410 cond = parse_exp_1 ((arg += 2, &arg),
5411 block_for_pc (sals.sals[i].pc), 0);
5413 error ("Junk at end of arguments.");
5418 for (i = 0; i < sals.nelts; i++)
5423 describe_other_breakpoints (sal.pc, sal.section);
5425 b = set_raw_breakpoint (sal);
5426 set_breakpoint_count (breakpoint_count + 1);
5427 b->number = breakpoint_count;
5429 /* Important -- this is an ordinary breakpoint. For platforms
5430 with callback support for exceptions,
5431 create_exception_catchpoint() will create special bp types
5432 (bp_catch_catch and bp_catch_throw), and there is code in
5433 insert_breakpoints() and elsewhere that depends on that. */
5434 b->type = bp_breakpoint;
5437 b->enable = enabled;
5438 b->disposition = tempflag ? del : donttouch;
5445 warning ("Multiple breakpoints were set.");
5446 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5448 free ((PTR) sals.sals);
5452 /* This creates a temporary internal breakpoint
5453 just to placate infrun */
5454 static struct breakpoint *
5455 create_temp_exception_breakpoint (pc)
5458 struct symtab_and_line sal;
5459 struct breakpoint *b;
5466 b = set_raw_breakpoint (sal);
5468 error ("Internal error -- couldn't set temp exception breakpoint");
5470 b->type = bp_breakpoint;
5471 b->disposition = del;
5472 b->enable = enabled;
5474 b->number = internal_breakpoint_number--;
5480 catch_command_1 (arg, tempflag, from_tty)
5486 /* The first argument may be an event name, such as "start" or "load".
5487 If so, then handle it as such. If it doesn't match an event name,
5488 then attempt to interpret it as an exception name. (This latter is
5489 the v4.16-and-earlier GDB meaning of the "catch" command.)
5491 First, try to find the bounds of what might be an event name. */
5492 char *arg1_start = arg;
5496 if (arg1_start == NULL)
5498 /* Old behaviour was to use pre-v-4.16 syntax */
5499 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5501 /* Now, this is not allowed */
5502 error ("Catch requires an event name.");
5505 arg1_end = ep_find_event_name_end (arg1_start);
5506 if (arg1_end == NULL)
5507 error ("catch requires an event");
5508 arg1_length = arg1_end + 1 - arg1_start;
5510 /* Try to match what we found against known event names. */
5511 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5513 error ("Catch of signal not yet implemented");
5515 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5517 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5518 tempflag, from_tty);
5520 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5522 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5523 tempflag, from_tty);
5525 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5527 error ("Catch of thread_start not yet implemented");
5529 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5531 error ("Catch of thread_exit not yet implemented");
5533 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5535 error ("Catch of thread_join not yet implemented");
5537 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5539 error ("Catch of start not yet implemented");
5541 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5543 error ("Catch of exit not yet implemented");
5545 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5547 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5548 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
5550 error ("Catch of fork not yet implemented");
5553 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5555 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5556 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
5558 error ("Catch of vfork not yet implemented");
5561 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5563 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5564 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
5566 error ("Catch of exec not yet implemented");
5569 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5571 #if defined(SOLIB_ADD)
5572 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
5574 error ("Catch of load not implemented");
5577 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5579 #if defined(SOLIB_ADD)
5580 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
5582 error ("Catch of load not implemented");
5585 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5587 error ("Catch of stop not yet implemented");
5590 /* This doesn't appear to be an event name */
5594 /* Pre-v.4.16 behaviour was to treat the argument
5595 as the name of an exception */
5596 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5597 /* Now this is not allowed */
5598 error ("Unknown event kind specified for catch");
5603 /* Used by the gui, could be made a worker for other things. */
5606 set_breakpoint_sal (sal)
5607 struct symtab_and_line sal;
5609 struct breakpoint *b;
5610 b = set_raw_breakpoint (sal);
5611 set_breakpoint_count (breakpoint_count + 1);
5612 b->number = breakpoint_count;
5613 b->type = bp_breakpoint;
5620 /* These aren't used; I don't know what they were for. */
5621 /* Disable breakpoints on all catch clauses described in ARGS. */
5623 disable_catch (args)
5626 /* Map the disable command to catch clauses described in ARGS. */
5629 /* Enable breakpoints on all catch clauses described in ARGS. */
5634 /* Map the disable command to catch clauses described in ARGS. */
5637 /* Delete breakpoints on all catch clauses in the active scope. */
5642 /* Map the delete command to catch clauses described in ARGS. */
5647 catch_command (arg, from_tty)
5651 catch_command_1 (arg, 0, from_tty);
5656 tcatch_command (arg, from_tty)
5660 catch_command_1 (arg, 1, from_tty);
5665 clear_command (arg, from_tty)
5669 register struct breakpoint *b, *b1;
5671 struct symtabs_and_lines sals;
5672 struct symtab_and_line sal;
5673 register struct breakpoint *found;
5678 sals = decode_line_spec (arg, 1);
5683 sals.sals = (struct symtab_and_line *)
5684 xmalloc (sizeof (struct symtab_and_line));
5685 INIT_SAL (&sal); /* initialize to zeroes */
5686 sal.line = default_breakpoint_line;
5687 sal.symtab = default_breakpoint_symtab;
5688 sal.pc = default_breakpoint_address;
5689 if (sal.symtab == 0)
5690 error ("No source file specified.");
5698 /* For each line spec given, delete bps which correspond
5699 to it. We do this in two loops: the first loop looks at
5700 the initial bp(s) in the chain which should be deleted,
5701 the second goes down the rest of the chain looking ahead
5702 one so it can take those bps off the chain without messing
5706 for (i = 0; i < sals.nelts; i++)
5708 /* If exact pc given, clear bpts at that pc.
5709 If line given (pc == 0), clear all bpts on specified line.
5710 If defaulting, clear all bpts on default line
5713 defaulting sal.pc != 0 tests to do
5718 1 0 <can't happen> */
5721 found = (struct breakpoint *) 0;
5724 while (breakpoint_chain
5725 /* Why don't we check here that this is not
5726 a watchpoint, etc., as we do below?
5727 I can't make it fail, but don't know
5728 what's stopping the failure: a watchpoint
5729 of the same address as "sal.pc" should
5730 wind up being deleted. */
5732 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5733 (overlay_debugging == 0 ||
5734 breakpoint_chain->section == sal.section))
5735 || ((default_match || (0 == sal.pc))
5736 && breakpoint_chain->source_file != NULL
5737 && sal.symtab != NULL
5738 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5739 && breakpoint_chain->line_number == sal.line)))
5742 b1 = breakpoint_chain;
5743 breakpoint_chain = b1->next;
5751 && b->next->type != bp_none
5752 && b->next->type != bp_watchpoint
5753 && b->next->type != bp_hardware_watchpoint
5754 && b->next->type != bp_read_watchpoint
5755 && b->next->type != bp_access_watchpoint
5756 && (((sal.pc && (b->next->address == sal.pc)) &&
5757 (overlay_debugging == 0 ||
5758 b->next->section == sal.section))
5759 || ((default_match || (0 == sal.pc))
5760 && b->next->source_file != NULL
5761 && sal.symtab != NULL
5762 && STREQ (b->next->source_file, sal.symtab->filename)
5763 && b->next->line_number == sal.line)))
5776 error ("No breakpoint at %s.", arg);
5778 error ("No breakpoint at this line.");
5782 from_tty = 1; /* Always report if deleted more than one */
5784 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
5785 breakpoints_changed ();
5789 printf_unfiltered ("%d ", found->number);
5791 delete_breakpoint (found);
5795 putchar_unfiltered ('\n');
5797 free ((PTR) sals.sals);
5800 /* Delete breakpoint in BS if they are `delete' breakpoints and
5801 all breakpoints that are marked for deletion, whether hit or not.
5802 This is called after any breakpoint is hit, or after errors. */
5805 breakpoint_auto_delete (bs)
5808 struct breakpoint *b, *temp;
5810 for (; bs; bs = bs->next)
5811 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
5813 delete_breakpoint (bs->breakpoint_at);
5815 ALL_BREAKPOINTS_SAFE (b, temp)
5817 if (b->disposition == del_at_next_stop)
5818 delete_breakpoint (b);
5822 /* Delete a breakpoint and clean up all traces of it in the data
5826 delete_breakpoint (bpt)
5827 struct breakpoint *bpt;
5829 register struct breakpoint *b;
5833 error ("Internal error (attempted to delete a NULL breakpoint)");
5836 /* Has this bp already been deleted? This can happen because multiple
5837 lists can hold pointers to bp's. bpstat lists are especial culprits.
5839 One example of this happening is a watchpoint's scope bp. When the
5840 scope bp triggers, we notice that the watchpoint is out of scope, and
5841 delete it. We also delete its scope bp. But the scope bp is marked
5842 "auto-deleting", and is already on a bpstat. That bpstat is then
5843 checked for auto-deleting bp's, which are deleted.
5845 A real solution to this problem might involve reference counts in bp's,
5846 and/or giving them pointers back to their referencing bpstat's, and
5847 teaching delete_breakpoint to only free a bp's storage when no more
5848 references were extent. A cheaper bandaid was chosen. */
5849 if (bpt->type == bp_none)
5852 if (delete_breakpoint_hook)
5853 delete_breakpoint_hook (bpt);
5854 breakpoint_delete_event (bpt->number);
5857 remove_breakpoint (bpt, mark_uninserted);
5859 if (breakpoint_chain == bpt)
5860 breakpoint_chain = bpt->next;
5862 /* If we have callback-style exception catchpoints, don't go through
5863 the adjustments to the C++ runtime library etc. if the inferior
5864 isn't actually running. target_enable_exception_callback for a
5865 null target ops vector gives an undesirable error message, so we
5866 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
5867 exceptions are supported in this way, it's OK for now. FIXME */
5868 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5870 static char message1[] = "Error in deleting catchpoint %d:\n";
5871 static char message[sizeof (message1) + 30];
5872 args_for_catchpoint_enable args;
5874 /* Format possible error msg */
5875 sprintf (message, message1, bpt->number);
5876 args.kind = bpt->type == bp_catch_catch ?
5877 EX_EVENT_CATCH : EX_EVENT_THROW;
5879 catch_errors (cover_target_enable_exception_callback, &args,
5880 message, RETURN_MASK_ALL);
5887 b->next = bpt->next;
5891 /* Before turning off the visuals for the bp, check to see that
5892 there are no other bps at the same address. */
5899 clearIt = (b->address != bpt->address);
5906 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
5907 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
5911 check_duplicates (bpt->address, bpt->section);
5912 /* If this breakpoint was inserted, and there is another breakpoint
5913 at the same address, we need to insert the other breakpoint. */
5915 && bpt->type != bp_hardware_watchpoint
5916 && bpt->type != bp_read_watchpoint
5917 && bpt->type != bp_access_watchpoint
5918 && bpt->type != bp_catch_fork
5919 && bpt->type != bp_catch_vfork
5920 && bpt->type != bp_catch_exec)
5923 if (b->address == bpt->address
5924 && b->section == bpt->section
5926 && b->enable != disabled
5927 && b->enable != shlib_disabled
5928 && b->enable != call_disabled)
5932 if (b->type == bp_hardware_breakpoint)
5933 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
5935 val = target_insert_breakpoint (b->address, b->shadow_contents);
5939 target_terminal_ours_for_output ();
5940 warning ("Cannot insert breakpoint %d:", b->number);
5941 memory_error (val, b->address); /* which bombs us out */
5948 free_command_lines (&bpt->commands);
5951 if (bpt->cond_string != NULL)
5952 free (bpt->cond_string);
5953 if (bpt->addr_string != NULL)
5954 free (bpt->addr_string);
5955 if (bpt->exp != NULL)
5957 if (bpt->exp_string != NULL)
5958 free (bpt->exp_string);
5959 if (bpt->val != NULL)
5960 value_free (bpt->val);
5961 if (bpt->source_file != NULL)
5962 free (bpt->source_file);
5963 if (bpt->dll_pathname != NULL)
5964 free (bpt->dll_pathname);
5965 if (bpt->triggered_dll_pathname != NULL)
5966 free (bpt->triggered_dll_pathname);
5967 if (bpt->exec_pathname != NULL)
5968 free (bpt->exec_pathname);
5970 /* Be sure no bpstat's are pointing at it after it's been freed. */
5971 /* FIXME, how can we find all bpstat's?
5972 We just check stop_bpstat for now. */
5973 for (bs = stop_bpstat; bs; bs = bs->next)
5974 if (bs->breakpoint_at == bpt)
5976 bs->breakpoint_at = NULL;
5978 /* we'd call bpstat_clear_actions, but that free's stuff and due
5979 to the multiple pointers pointing to one item with no
5980 reference counts found anywhere through out the bpstat's (how
5981 do you spell fragile?), we don't want to free things twice --
5982 better a memory leak than a corrupt malloc pool! */
5983 bs->commands = NULL;
5986 /* On the chance that someone will soon try again to delete this same
5987 bp, we mark it as deleted before freeing its storage. */
5988 bpt->type = bp_none;
5994 delete_command (arg, from_tty)
5998 struct breakpoint *b, *temp;
6002 int breaks_to_delete = 0;
6004 /* Delete all breakpoints if no argument.
6005 Do not delete internal or call-dummy breakpoints, these
6006 have to be deleted with an explicit breakpoint number argument. */
6009 if (b->type != bp_call_dummy &&
6010 b->type != bp_shlib_event &&
6012 breaks_to_delete = 1;
6015 /* Ask user only if there are some breakpoints to delete. */
6017 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6019 ALL_BREAKPOINTS_SAFE (b, temp)
6021 if (b->type != bp_call_dummy &&
6022 b->type != bp_shlib_event &&
6024 delete_breakpoint (b);
6029 map_breakpoint_numbers (arg, delete_breakpoint);
6032 /* Reset a breakpoint given it's struct breakpoint * BINT.
6033 The value we return ends up being the return value from catch_errors.
6034 Unused in this case. */
6037 breakpoint_re_set_one (bint)
6040 /* get past catch_errs */
6041 struct breakpoint *b = (struct breakpoint *) bint;
6044 struct symtabs_and_lines sals;
6046 enum enable save_enable;
6051 warning ("attempted to reset apparently deleted breakpoint #%d?",
6055 case bp_hardware_breakpoint:
6057 case bp_catch_unload:
6058 if (b->addr_string == NULL)
6060 /* Anything without a string can't be re-set. */
6061 delete_breakpoint (b);
6064 /* In case we have a problem, disable this breakpoint. We'll restore
6065 its status if we succeed. */
6066 save_enable = b->enable;
6067 b->enable = disabled;
6069 set_language (b->language);
6070 input_radix = b->input_radix;
6072 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6073 for (i = 0; i < sals.nelts; i++)
6075 resolve_sal_pc (&sals.sals[i]);
6077 /* Reparse conditions, they might contain references to the
6079 if (b->cond_string != NULL)
6083 free ((PTR) b->cond);
6084 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6087 /* We need to re-set the breakpoint if the address changes... */
6088 if (b->address != sals.sals[i].pc
6089 /* ...or new and old breakpoints both have source files, and
6090 the source file name or the line number changes... */
6091 || (b->source_file != NULL
6092 && sals.sals[i].symtab != NULL
6093 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6094 || b->line_number != sals.sals[i].line)
6096 /* ...or we switch between having a source file and not having
6098 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6101 if (b->source_file != NULL)
6102 free (b->source_file);
6103 if (sals.sals[i].symtab == NULL)
6104 b->source_file = NULL;
6107 savestring (sals.sals[i].symtab->filename,
6108 strlen (sals.sals[i].symtab->filename));
6109 b->line_number = sals.sals[i].line;
6110 b->address = sals.sals[i].pc;
6112 /* Used to check for duplicates here, but that can
6113 cause trouble, as it doesn't check for disable
6118 /* Might be better to do this just once per breakpoint_re_set,
6119 rather than once for every breakpoint. */
6120 breakpoints_changed ();
6122 b->section = sals.sals[i].section;
6123 b->enable = save_enable; /* Restore it, this worked. */
6126 /* Now that this is re-enabled, check_duplicates
6128 check_duplicates (b->address, b->section);
6131 free ((PTR) sals.sals);
6135 case bp_hardware_watchpoint:
6136 case bp_read_watchpoint:
6137 case bp_access_watchpoint:
6138 innermost_block = NULL;
6139 /* The issue arises of what context to evaluate this in. The
6140 same one as when it was set, but what does that mean when
6141 symbols have been re-read? We could save the filename and
6142 functionname, but if the context is more local than that, the
6143 best we could do would be something like how many levels deep
6144 and which index at that particular level, but that's going to
6145 be less stable than filenames or function names. */
6147 /* So for now, just use a global context. */
6149 free ((PTR) b->exp);
6150 b->exp = parse_expression (b->exp_string);
6151 b->exp_valid_block = innermost_block;
6152 mark = value_mark ();
6154 value_free (b->val);
6155 b->val = evaluate_expression (b->exp);
6156 release_value (b->val);
6157 if (VALUE_LAZY (b->val))
6158 value_fetch_lazy (b->val);
6160 if (b->cond_string != NULL)
6164 free ((PTR) b->cond);
6165 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6167 if (b->enable == enabled)
6169 value_free_to_mark (mark);
6171 case bp_catch_catch:
6172 case bp_catch_throw:
6174 /* We needn't really do anything to reset these, since the mask
6175 that requests them is unaffected by e.g., new libraries being
6178 case bp_catch_vfork:
6183 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6185 /* Delete longjmp breakpoints, they will be reset later by
6186 breakpoint_re_set. */
6188 case bp_longjmp_resume:
6189 delete_breakpoint (b);
6192 /* This breakpoint is special, it's set up when the inferior
6193 starts and we really don't want to touch it. */
6194 case bp_shlib_event:
6196 /* Keep temporary breakpoints, which can be encountered when we step
6197 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6198 Otherwise these should have been blown away via the cleanup chain
6199 or by breakpoint_init_inferior when we rerun the executable. */
6202 case bp_watchpoint_scope:
6204 case bp_step_resume:
6211 /* Re-set all breakpoints after symbols have been re-loaded. */
6213 breakpoint_re_set ()
6215 struct breakpoint *b, *temp;
6216 enum language save_language;
6217 int save_input_radix;
6218 static char message1[] = "Error in re-setting breakpoint %d:\n";
6219 char message[sizeof (message1) + 30 /* slop */ ];
6221 save_language = current_language->la_language;
6222 save_input_radix = input_radix;
6223 ALL_BREAKPOINTS_SAFE (b, temp)
6225 /* Format possible error msg */
6226 sprintf (message, message1, b->number);
6227 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6229 set_language (save_language);
6230 input_radix = save_input_radix;
6232 #ifdef GET_LONGJMP_TARGET
6233 create_longjmp_breakpoint ("longjmp");
6234 create_longjmp_breakpoint ("_longjmp");
6235 create_longjmp_breakpoint ("siglongjmp");
6236 create_longjmp_breakpoint ("_siglongjmp");
6237 create_longjmp_breakpoint (NULL);
6241 /* Took this out (temporarily at least), since it produces an extra
6242 blank line at startup. This messes up the gdbtests. -PB */
6243 /* Blank line to finish off all those mention() messages we just printed. */
6244 printf_filtered ("\n");
6248 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6249 If from_tty is nonzero, it prints a message to that effect,
6250 which ends with a period (no newline). */
6252 /* Reset the thread number of this breakpoint:
6254 - If the breakpoint is for all threads, leave it as-is.
6255 - Else, reset it to the current thread for inferior_pid. */
6257 breakpoint_re_set_thread (b)
6258 struct breakpoint *b;
6260 if (b->thread != -1)
6262 if (in_thread_list (inferior_pid))
6263 b->thread = pid_to_thread_id (inferior_pid);
6268 set_ignore_count (bptnum, count, from_tty)
6269 int bptnum, count, from_tty;
6271 register struct breakpoint *b;
6277 if (b->number == bptnum)
6279 b->ignore_count = count;
6282 else if (count == 0)
6283 printf_filtered ("Will stop next time breakpoint %d is reached.",
6285 else if (count == 1)
6286 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6289 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6291 breakpoints_changed ();
6295 error ("No breakpoint number %d.", bptnum);
6298 /* Clear the ignore counts of all breakpoints. */
6300 breakpoint_clear_ignore_counts ()
6302 struct breakpoint *b;
6305 b->ignore_count = 0;
6308 /* Command to set ignore-count of breakpoint N to COUNT. */
6311 ignore_command (args, from_tty)
6319 error_no_arg ("a breakpoint number");
6321 num = get_number (&p);
6324 error ("Second argument (specified ignore-count) is missing.");
6326 set_ignore_count (num,
6327 longest_to_int (value_as_long (parse_and_eval (p))),
6329 printf_filtered ("\n");
6330 breakpoints_changed ();
6333 /* Call FUNCTION on each of the breakpoints
6334 whose numbers are given in ARGS. */
6337 map_breakpoint_numbers (args, function)
6339 void (*function) PARAMS ((struct breakpoint *));
6341 register char *p = args;
6344 register struct breakpoint *b;
6347 error_no_arg ("one or more breakpoint numbers");
6353 num = get_number (&p1);
6356 if (b->number == num)
6358 struct breakpoint *related_breakpoint = b->related_breakpoint;
6360 if (related_breakpoint)
6361 function (related_breakpoint);
6364 printf_unfiltered ("No breakpoint number %d.\n", num);
6371 disable_breakpoint (bpt)
6372 struct breakpoint *bpt;
6374 /* Never disable a watchpoint scope breakpoint; we want to
6375 hit them when we leave scope so we can delete both the
6376 watchpoint and its scope breakpoint at that time. */
6377 if (bpt->type == bp_watchpoint_scope)
6380 bpt->enable = disabled;
6382 check_duplicates (bpt->address, bpt->section);
6384 if (modify_breakpoint_hook)
6385 modify_breakpoint_hook (bpt);
6386 breakpoint_modify_event (bpt->number);
6391 disable_command (args, from_tty)
6395 register struct breakpoint *bpt;
6397 ALL_BREAKPOINTS (bpt)
6401 warning ("attempted to disable apparently deleted breakpoint #%d?",
6406 case bp_catch_unload:
6408 case bp_catch_vfork:
6410 case bp_catch_catch:
6411 case bp_catch_throw:
6412 case bp_hardware_breakpoint:
6414 case bp_hardware_watchpoint:
6415 case bp_read_watchpoint:
6416 case bp_access_watchpoint:
6417 disable_breakpoint (bpt);
6422 map_breakpoint_numbers (args, disable_breakpoint);
6426 do_enable_breakpoint (bpt, disposition)
6427 struct breakpoint *bpt;
6428 enum bpdisp disposition;
6430 struct frame_info *save_selected_frame = NULL;
6431 int save_selected_frame_level = -1;
6432 int target_resources_ok, other_type_used;
6435 if (bpt->type == bp_hardware_breakpoint)
6438 i = hw_breakpoint_used_count ();
6439 target_resources_ok =
6440 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6442 if (target_resources_ok == 0)
6443 error ("No hardware breakpoint support in the target.");
6444 else if (target_resources_ok < 0)
6445 error ("Hardware breakpoints used exceeds limit.");
6448 bpt->enable = enabled;
6449 bpt->disposition = disposition;
6450 check_duplicates (bpt->address, bpt->section);
6451 breakpoints_changed ();
6453 if (bpt->type == bp_watchpoint ||
6454 bpt->type == bp_hardware_watchpoint ||
6455 bpt->type == bp_read_watchpoint ||
6456 bpt->type == bp_access_watchpoint)
6458 if (bpt->exp_valid_block != NULL)
6460 struct frame_info *fr =
6462 /* Ensure that we have the current frame. Else, this
6463 next query may pessimistically be answered as, "No,
6464 not within current scope". */
6465 get_current_frame ();
6466 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6470 Cannot enable watchpoint %d because the block in which its expression\n\
6471 is valid is not currently in scope.\n", bpt->number);
6472 bpt->enable = disabled;
6476 save_selected_frame = selected_frame;
6477 save_selected_frame_level = selected_frame_level;
6478 select_frame (fr, -1);
6481 value_free (bpt->val);
6482 mark = value_mark ();
6483 bpt->val = evaluate_expression (bpt->exp);
6484 release_value (bpt->val);
6485 if (VALUE_LAZY (bpt->val))
6486 value_fetch_lazy (bpt->val);
6488 if (bpt->type == bp_hardware_watchpoint ||
6489 bpt->type == bp_read_watchpoint ||
6490 bpt->type == bp_access_watchpoint)
6492 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6493 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6495 /* Hack around 'unused var' error for some targets here */
6497 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6498 bpt->type, i + mem_cnt, other_type_used);
6499 /* we can consider of type is bp_hardware_watchpoint, convert to
6500 bp_watchpoint in the following condition */
6501 if (target_resources_ok < 0)
6504 Cannot enable watchpoint %d because target watch resources\n\
6505 have been allocated for other watchpoints.\n", bpt->number);
6506 bpt->enable = disabled;
6507 value_free_to_mark (mark);
6512 if (save_selected_frame_level >= 0)
6513 select_and_print_frame (save_selected_frame,
6514 save_selected_frame_level);
6515 value_free_to_mark (mark);
6517 if (modify_breakpoint_hook)
6518 modify_breakpoint_hook (bpt);
6519 breakpoint_modify_event (bpt->number);
6523 enable_breakpoint (bpt)
6524 struct breakpoint *bpt;
6526 do_enable_breakpoint (bpt, bpt->disposition);
6529 /* The enable command enables the specified breakpoints (or all defined
6530 breakpoints) so they once again become (or continue to be) effective
6531 in stopping the inferior. */
6535 enable_command (args, from_tty)
6539 register struct breakpoint *bpt;
6541 ALL_BREAKPOINTS (bpt)
6545 warning ("attempted to enable apparently deleted breakpoint #%d?",
6550 case bp_catch_unload:
6552 case bp_catch_vfork:
6554 case bp_catch_catch:
6555 case bp_catch_throw:
6556 case bp_hardware_breakpoint:
6558 case bp_hardware_watchpoint:
6559 case bp_read_watchpoint:
6560 case bp_access_watchpoint:
6561 enable_breakpoint (bpt);
6566 map_breakpoint_numbers (args, enable_breakpoint);
6570 enable_once_breakpoint (bpt)
6571 struct breakpoint *bpt;
6573 do_enable_breakpoint (bpt, disable);
6578 enable_once_command (args, from_tty)
6582 map_breakpoint_numbers (args, enable_once_breakpoint);
6586 enable_delete_breakpoint (bpt)
6587 struct breakpoint *bpt;
6589 do_enable_breakpoint (bpt, del);
6594 enable_delete_command (args, from_tty)
6598 map_breakpoint_numbers (args, enable_delete_breakpoint);
6601 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
6603 struct symtabs_and_lines
6604 decode_line_spec_1 (string, funfirstline)
6608 struct symtabs_and_lines sals;
6610 error ("Empty line specification.");
6611 if (default_breakpoint_valid)
6612 sals = decode_line_1 (&string, funfirstline,
6613 default_breakpoint_symtab,
6614 default_breakpoint_line,
6617 sals = decode_line_1 (&string, funfirstline,
6618 (struct symtab *) NULL, 0, (char ***) NULL);
6620 error ("Junk at end of line specification: %s", string);
6625 _initialize_breakpoint ()
6627 struct cmd_list_element *c;
6629 breakpoint_chain = 0;
6630 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6631 before a breakpoint is set. */
6632 breakpoint_count = 0;
6634 add_com ("ignore", class_breakpoint, ignore_command,
6635 "Set ignore-count of breakpoint number N to COUNT.\n\
6636 Usage is `ignore N COUNT'.");
6638 add_com_alias ("bc", "ignore", class_breakpoint, 1);
6640 add_com ("commands", class_breakpoint, commands_command,
6641 "Set commands to be executed when a breakpoint is hit.\n\
6642 Give breakpoint number as argument after \"commands\".\n\
6643 With no argument, the targeted breakpoint is the last one set.\n\
6644 The commands themselves follow starting on the next line.\n\
6645 Type a line containing \"end\" to indicate the end of them.\n\
6646 Give \"silent\" as the first line to make the breakpoint silent;\n\
6647 then no output is printed when it is hit, except what the commands print.");
6649 add_com ("condition", class_breakpoint, condition_command,
6650 "Specify breakpoint number N to break only if COND is true.\n\
6651 Usage is `condition N COND', where N is an integer and COND is an\n\
6652 expression to be evaluated whenever breakpoint N is reached. ");
6654 add_com ("tbreak", class_breakpoint, tbreak_command,
6655 "Set a temporary breakpoint. Args like \"break\" command.\n\
6656 Like \"break\" except the breakpoint is only temporary,\n\
6657 so it will be deleted when hit. Equivalent to \"break\" followed\n\
6658 by using \"enable delete\" on the breakpoint number.");
6659 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6660 "Set temporary breakpoint at procedure exit. Either there should\n\
6661 be no argument or the argument must be a depth.\n");
6663 add_com ("hbreak", class_breakpoint, hbreak_command,
6664 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6665 Like \"break\" except the breakpoint requires hardware support,\n\
6666 some target hardware may not have this support.");
6668 add_com ("thbreak", class_breakpoint, thbreak_command,
6669 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6670 Like \"hbreak\" except the breakpoint is only temporary,\n\
6671 so it will be deleted when hit.");
6673 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6674 "Enable some breakpoints.\n\
6675 Give breakpoint numbers (separated by spaces) as arguments.\n\
6676 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6677 This is used to cancel the effect of the \"disable\" command.\n\
6678 With a subcommand you can enable temporarily.",
6679 &enablelist, "enable ", 1, &cmdlist);
6681 add_com ("ab", class_breakpoint, enable_command,
6682 "Enable some breakpoints.\n\
6683 Give breakpoint numbers (separated by spaces) as arguments.\n\
6684 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6685 This is used to cancel the effect of the \"disable\" command.\n\
6686 With a subcommand you can enable temporarily.");
6688 add_com_alias ("en", "enable", class_breakpoint, 1);
6690 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
6691 "Enable some breakpoints.\n\
6692 Give breakpoint numbers (separated by spaces) as arguments.\n\
6693 This is used to cancel the effect of the \"disable\" command.\n\
6694 May be abbreviated to simply \"enable\".\n",
6695 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
6697 add_cmd ("once", no_class, enable_once_command,
6698 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6699 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6702 add_cmd ("delete", no_class, enable_delete_command,
6703 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6704 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6707 add_cmd ("delete", no_class, enable_delete_command,
6708 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6709 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6712 add_cmd ("once", no_class, enable_once_command,
6713 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6714 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6717 add_prefix_cmd ("disable", class_breakpoint, disable_command,
6718 "Disable some breakpoints.\n\
6719 Arguments are breakpoint numbers with spaces in between.\n\
6720 To disable all breakpoints, give no argument.\n\
6721 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6722 &disablelist, "disable ", 1, &cmdlist);
6723 add_com_alias ("dis", "disable", class_breakpoint, 1);
6724 add_com_alias ("disa", "disable", class_breakpoint, 1);
6726 add_com ("sb", class_breakpoint, disable_command,
6727 "Disable some breakpoints.\n\
6728 Arguments are breakpoint numbers with spaces in between.\n\
6729 To disable all breakpoints, give no argument.\n\
6730 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6732 add_cmd ("breakpoints", class_alias, disable_command,
6733 "Disable some breakpoints.\n\
6734 Arguments are breakpoint numbers with spaces in between.\n\
6735 To disable all breakpoints, give no argument.\n\
6736 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6737 This command may be abbreviated \"disable\".",
6740 add_prefix_cmd ("delete", class_breakpoint, delete_command,
6741 "Delete some breakpoints or auto-display expressions.\n\
6742 Arguments are breakpoint numbers with spaces in between.\n\
6743 To delete all breakpoints, give no argument.\n\
6745 Also a prefix command for deletion of other GDB objects.\n\
6746 The \"unset\" command is also an alias for \"delete\".",
6747 &deletelist, "delete ", 1, &cmdlist);
6748 add_com_alias ("d", "delete", class_breakpoint, 1);
6750 add_com ("db", class_breakpoint, delete_command,
6751 "Delete some breakpoints.\n\
6752 Arguments are breakpoint numbers with spaces in between.\n\
6753 To delete all breakpoints, give no argument.\n");
6755 add_cmd ("breakpoints", class_alias, delete_command,
6756 "Delete some breakpoints or auto-display expressions.\n\
6757 Arguments are breakpoint numbers with spaces in between.\n\
6758 To delete all breakpoints, give no argument.\n\
6759 This command may be abbreviated \"delete\".",
6762 add_com ("clear", class_breakpoint, clear_command,
6763 concat ("Clear breakpoint at specified line or function.\n\
6764 Argument may be line number, function name, or \"*\" and an address.\n\
6765 If line number is specified, all breakpoints in that line are cleared.\n\
6766 If function is specified, breakpoints at beginning of function are cleared.\n\
6767 If an address is specified, breakpoints at that address are cleared.\n\n",
6768 "With no argument, clears all breakpoints in the line that the selected frame\n\
6771 See also the \"delete\" command which clears breakpoints by number.", NULL));
6773 add_com ("break", class_breakpoint, break_command,
6774 concat ("Set breakpoint at specified line or function.\n\
6775 Argument may be line number, function name, or \"*\" and an address.\n\
6776 If line number is specified, break at start of code for that line.\n\
6777 If function is specified, break at start of code for that function.\n\
6778 If an address is specified, break at that exact address.\n",
6779 "With no arg, uses current execution address of selected stack frame.\n\
6780 This is useful for breaking on return to a stack frame.\n\
6782 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6784 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6785 add_com_alias ("b", "break", class_run, 1);
6786 add_com_alias ("br", "break", class_run, 1);
6787 add_com_alias ("bre", "break", class_run, 1);
6788 add_com_alias ("brea", "break", class_run, 1);
6790 add_com ("xbreak", class_breakpoint, break_at_finish_command,
6791 concat ("Set breakpoint at procedure exit. \n\
6792 Argument may be function name, or \"*\" and an address.\n\
6793 If function is specified, break at end of code for that function.\n\
6794 If an address is specified, break at the end of the function that contains \n\
6795 that exact address.\n",
6796 "With no arg, uses current execution address of selected stack frame.\n\
6797 This is useful for breaking on return to a stack frame.\n\
6799 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6801 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6802 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6803 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6804 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6805 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6809 add_com_alias ("ba", "break", class_breakpoint, 1);
6810 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6811 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
6812 "Set breakpoint at procedure exit. Either there should\n\
6813 be no argument or the argument must be a depth.\n");
6818 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
6819 "Break in function/address or break at a line in the current file.",
6820 &stoplist, "stop ", 1, &cmdlist);
6821 add_cmd ("in", class_breakpoint, stopin_command,
6822 "Break in function or address.\n", &stoplist);
6823 add_cmd ("at", class_breakpoint, stopat_command,
6824 "Break at a line in the current file.\n", &stoplist);
6825 add_com ("status", class_info, breakpoints_info,
6826 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6827 The \"Type\" column indicates one of:\n\
6828 \tbreakpoint - normal breakpoint\n\
6829 \twatchpoint - watchpoint\n\
6830 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6831 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6832 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6833 address and file/line number respectively.\n\n",
6834 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6835 are set to the address of the last breakpoint listed.\n\n\
6836 Convenience variable \"$bpnum\" contains the number of the last\n\
6837 breakpoint set.", NULL));
6840 add_info ("breakpoints", breakpoints_info,
6841 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6842 The \"Type\" column indicates one of:\n\
6843 \tbreakpoint - normal breakpoint\n\
6844 \twatchpoint - watchpoint\n\
6845 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6846 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6847 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6848 address and file/line number respectively.\n\n",
6849 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6850 are set to the address of the last breakpoint listed.\n\n\
6851 Convenience variable \"$bpnum\" contains the number of the last\n\
6852 breakpoint set.", NULL));
6855 add_com ("lb", class_breakpoint, breakpoints_info,
6856 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6857 The \"Type\" column indicates one of:\n\
6858 \tbreakpoint - normal breakpoint\n\
6859 \twatchpoint - watchpoint\n\
6860 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6861 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6862 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6863 address and file/line number respectively.\n\n",
6864 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6865 are set to the address of the last breakpoint listed.\n\n\
6866 Convenience variable \"$bpnum\" contains the number of the last\n\
6867 breakpoint set.", NULL));
6869 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
6870 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
6871 The \"Type\" column indicates one of:\n\
6872 \tbreakpoint - normal breakpoint\n\
6873 \twatchpoint - watchpoint\n\
6874 \tlongjmp - internal breakpoint used to step through longjmp()\n\
6875 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6876 \tuntil - internal breakpoint used by the \"until\" command\n\
6877 \tfinish - internal breakpoint used by the \"finish\" command\n",
6878 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6879 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6880 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6881 address and file/line number respectively.\n\n",
6882 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6883 are set to the address of the last breakpoint listed.\n\n\
6884 Convenience variable \"$bpnum\" contains the number of the last\n\
6885 breakpoint set.", NULL),
6886 &maintenanceinfolist);
6888 add_com ("catch", class_breakpoint, catch_command,
6889 "Set catchpoints to catch events.\n\
6890 Raised signals may be caught:\n\
6891 \tcatch signal - all signals\n\
6892 \tcatch signal <signame> - a particular signal\n\
6893 Raised exceptions may be caught:\n\
6894 \tcatch throw - all exceptions, when thrown\n\
6895 \tcatch throw <exceptname> - a particular exception, when thrown\n\
6896 \tcatch catch - all exceptions, when caught\n\
6897 \tcatch catch <exceptname> - a particular exception, when caught\n\
6898 Thread or process events may be caught:\n\
6899 \tcatch thread_start - any threads, just after creation\n\
6900 \tcatch thread_exit - any threads, just before expiration\n\
6901 \tcatch thread_join - any threads, just after joins\n\
6902 Process events may be caught:\n\
6903 \tcatch start - any processes, just after creation\n\
6904 \tcatch exit - any processes, just before expiration\n\
6905 \tcatch fork - calls to fork()\n\
6906 \tcatch vfork - calls to vfork()\n\
6907 \tcatch exec - calls to exec()\n\
6908 Dynamically-linked library events may be caught:\n\
6909 \tcatch load - loads of any library\n\
6910 \tcatch load <libname> - loads of a particular library\n\
6911 \tcatch unload - unloads of any library\n\
6912 \tcatch unload <libname> - unloads of a particular library\n\
6913 The act of your program's execution stopping may also be caught:\n\
6915 C++ exceptions may be caught:\n\
6916 \tcatch throw - all exceptions, when thrown\n\
6917 \tcatch catch - all exceptions, when caught\n\
6919 Do \"help set follow-fork-mode\" for info on debugging your program\n\
6920 after a fork or vfork is caught.\n\n\
6921 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
6923 add_com ("tcatch", class_breakpoint, tcatch_command,
6924 "Set temporary catchpoints to catch events.\n\
6925 Args like \"catch\" command.\n\
6926 Like \"catch\" except the catchpoint is only temporary,\n\
6927 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6928 by using \"enable delete\" on the catchpoint number.");
6930 add_com ("watch", class_breakpoint, watch_command,
6931 "Set a watchpoint for an expression.\n\
6932 A watchpoint stops execution of your program whenever the value of\n\
6933 an expression changes.");
6935 add_com ("rwatch", class_breakpoint, rwatch_command,
6936 "Set a read watchpoint for an expression.\n\
6937 A watchpoint stops execution of your program whenever the value of\n\
6938 an expression is read.");
6940 add_com ("awatch", class_breakpoint, awatch_command,
6941 "Set a watchpoint for an expression.\n\
6942 A watchpoint stops execution of your program whenever the value of\n\
6943 an expression is either read or written.");
6945 add_info ("watchpoints", breakpoints_info,
6946 "Synonym for ``info breakpoints''.");
6949 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
6950 (char *) &can_use_hw_watchpoints,
6951 "Set debugger's willingness to use watchpoint hardware.\n\
6952 If zero, gdb will not use hardware for new watchpoints, even if\n\
6953 such is available. (However, any hardware watchpoints that were\n\
6954 created before setting this to nonzero, will continue to use watchpoint\n\
6957 add_show_from_set (c, &showlist);
6959 can_use_hw_watchpoints = 1;