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 symtab_and_line sal;
3419 struct cleanup *old_chain;
3420 struct cleanup *canonical_strings_chain = NULL;
3422 char *addr_start = hookname;
3423 char *addr_end = NULL;
3424 char **canonical = (char **) NULL;
3425 int thread = -1; /* All threads. */
3427 /* Set a breakpoint on the specified hook. */
3428 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3429 addr_end = hookname;
3431 if (sals.nelts == 0)
3433 warning ("Unable to set a breakpoint on dynamic linker callback.");
3434 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3435 warning ("GDB will be unable to track shl_load/shl_unload calls");
3438 if (sals.nelts != 1)
3440 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3441 warning ("GDB will be unable to track shl_load/shl_unload calls");
3445 /* Make sure that all storage allocated in decode_line_1 gets freed
3446 in case the following errors out. */
3447 old_chain = make_cleanup (free, sals.sals);
3448 if (canonical != (char **) NULL)
3450 make_cleanup (free, canonical);
3451 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3452 if (canonical[0] != NULL)
3453 make_cleanup (free, canonical[0]);
3456 resolve_sal_pc (&sals.sals[0]);
3458 /* Remove the canonical strings from the cleanup, they are needed below. */
3459 if (canonical != (char **) NULL)
3460 discard_cleanups (canonical_strings_chain);
3462 b = set_raw_breakpoint (sals.sals[0]);
3463 set_breakpoint_count (breakpoint_count + 1);
3464 b->number = breakpoint_count;
3466 b->cond_string = (cond_string == NULL) ?
3467 NULL : savestring (cond_string, strlen (cond_string));
3470 if (canonical != (char **) NULL && canonical[0] != NULL)
3471 b->addr_string = canonical[0];
3472 else if (addr_start)
3473 b->addr_string = savestring (addr_start, addr_end - addr_start);
3475 b->enable = enabled;
3476 b->disposition = tempflag ? del : donttouch;
3478 if (dll_pathname == NULL)
3479 b->dll_pathname = NULL;
3482 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3483 strcpy (b->dll_pathname, dll_pathname);
3488 do_cleanups (old_chain);
3492 create_solib_load_event_breakpoint (hookname, tempflag,
3493 dll_pathname, cond_string)
3499 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3500 cond_string, bp_catch_load);
3504 create_solib_unload_event_breakpoint (hookname, tempflag,
3505 dll_pathname, cond_string)
3511 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3512 cond_string, bp_catch_unload);
3516 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3519 enum bptype bp_kind;
3521 struct symtab_and_line sal;
3522 struct breakpoint *b;
3523 int thread = -1; /* All threads. */
3530 b = set_raw_breakpoint (sal);
3531 set_breakpoint_count (breakpoint_count + 1);
3532 b->number = breakpoint_count;
3534 b->cond_string = (cond_string == NULL) ?
3535 NULL : savestring (cond_string, strlen (cond_string));
3537 b->addr_string = NULL;
3538 b->enable = enabled;
3539 b->disposition = tempflag ? del : donttouch;
3540 b->forked_inferior_pid = 0;
3548 create_fork_event_catchpoint (tempflag, cond_string)
3552 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3556 create_vfork_event_catchpoint (tempflag, cond_string)
3560 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3564 create_exec_event_catchpoint (tempflag, cond_string)
3568 struct symtab_and_line sal;
3569 struct breakpoint *b;
3570 int thread = -1; /* All threads. */
3577 b = set_raw_breakpoint (sal);
3578 set_breakpoint_count (breakpoint_count + 1);
3579 b->number = breakpoint_count;
3581 b->cond_string = (cond_string == NULL) ?
3582 NULL : savestring (cond_string, strlen (cond_string));
3584 b->addr_string = NULL;
3585 b->enable = enabled;
3586 b->disposition = tempflag ? del : donttouch;
3588 b->type = bp_catch_exec;
3594 hw_breakpoint_used_count ()
3596 register struct breakpoint *b;
3601 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3609 hw_watchpoint_used_count (type, other_type_used)
3611 int *other_type_used;
3613 register struct breakpoint *b;
3616 *other_type_used = 0;
3619 if (b->enable == enabled)
3621 if (b->type == type)
3623 else if ((b->type == bp_hardware_watchpoint ||
3624 b->type == bp_read_watchpoint ||
3625 b->type == bp_access_watchpoint)
3626 && b->enable == enabled)
3627 *other_type_used = 1;
3633 /* Call this after hitting the longjmp() breakpoint. Use this to set
3634 a new breakpoint at the target of the jmp_buf.
3636 FIXME - This ought to be done by setting a temporary breakpoint
3637 that gets deleted automatically... */
3640 set_longjmp_resume_breakpoint (pc, frame)
3642 struct frame_info *frame;
3644 register struct breakpoint *b;
3647 if (b->type == bp_longjmp_resume)
3650 b->enable = enabled;
3652 b->frame = frame->frame;
3655 check_duplicates (b->address, b->section);
3661 disable_watchpoints_before_interactive_call_start ()
3663 struct breakpoint *b;
3667 if (((b->type == bp_watchpoint)
3668 || (b->type == bp_hardware_watchpoint)
3669 || (b->type == bp_read_watchpoint)
3670 || (b->type == bp_access_watchpoint)
3671 || ep_is_exception_catchpoint (b))
3672 && (b->enable == enabled))
3674 b->enable = call_disabled;
3675 check_duplicates (b->address, b->section);
3681 enable_watchpoints_after_interactive_call_stop ()
3683 struct breakpoint *b;
3687 if (((b->type == bp_watchpoint)
3688 || (b->type == bp_hardware_watchpoint)
3689 || (b->type == bp_read_watchpoint)
3690 || (b->type == bp_access_watchpoint)
3691 || ep_is_exception_catchpoint (b))
3692 && (b->enable == call_disabled))
3694 b->enable = enabled;
3695 check_duplicates (b->address, b->section);
3701 /* Set a breakpoint that will evaporate an end of command
3702 at address specified by SAL.
3703 Restrict it to frame FRAME if FRAME is nonzero. */
3706 set_momentary_breakpoint (sal, frame, type)
3707 struct symtab_and_line sal;
3708 struct frame_info *frame;
3711 register struct breakpoint *b;
3712 b = set_raw_breakpoint (sal);
3714 b->enable = enabled;
3715 b->disposition = donttouch;
3716 b->frame = (frame ? frame->frame : 0);
3718 /* If we're debugging a multi-threaded program, then we
3719 want momentary breakpoints to be active in only a
3720 single thread of control. */
3721 if (in_thread_list (inferior_pid))
3722 b->thread = pid_to_thread_id (inferior_pid);
3728 /* Tell the user we have just set a breakpoint B. */
3732 struct breakpoint *b;
3736 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3737 watchpoint) other than breakpoint creation. It should be possible to
3738 clean this up and at the same time replace the random calls to
3739 breakpoint_changed with this hook, as has already been done for
3740 delete_breakpoint_hook and so on. */
3741 if (create_breakpoint_hook)
3742 create_breakpoint_hook (b);
3743 breakpoint_create_event (b->number);
3748 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3751 printf_filtered ("Watchpoint %d: ", b->number);
3752 print_expression (b->exp, gdb_stdout);
3754 case bp_hardware_watchpoint:
3755 printf_filtered ("Hardware watchpoint %d: ", b->number);
3756 print_expression (b->exp, gdb_stdout);
3758 case bp_read_watchpoint:
3759 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3760 print_expression (b->exp, gdb_stdout);
3762 case bp_access_watchpoint:
3763 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3765 print_expression (b->exp, gdb_stdout);
3768 printf_filtered ("Breakpoint %d", b->number);
3771 case bp_hardware_breakpoint:
3772 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3776 case bp_catch_unload:
3777 printf_filtered ("Catchpoint %d (%s %s)",
3779 (b->type == bp_catch_load) ? "load" : "unload",
3780 (b->dll_pathname != NULL) ?
3781 b->dll_pathname : "<any library>");
3784 case bp_catch_vfork:
3785 printf_filtered ("Catchpoint %d (%s)",
3787 (b->type == bp_catch_fork) ? "fork" : "vfork");
3790 printf_filtered ("Catchpoint %d (exec)",
3793 case bp_catch_catch:
3794 case bp_catch_throw:
3795 printf_filtered ("Catchpoint %d (%s)",
3797 (b->type == bp_catch_catch) ? "catch" : "throw");
3803 case bp_longjmp_resume:
3804 case bp_step_resume:
3805 case bp_through_sigtramp:
3807 case bp_watchpoint_scope:
3808 case bp_shlib_event:
3813 if (addressprint || b->source_file == NULL)
3815 printf_filtered (" at ");
3816 print_address_numeric (b->address, 1, gdb_stdout);
3819 printf_filtered (": file %s, line %d.",
3820 b->source_file, b->line_number);
3821 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
3822 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
3824 printf_filtered ("\n");
3828 /* Set a breakpoint according to ARG (function, linenum or *address)
3829 flag: first bit : 0 non-temporary, 1 temporary.
3830 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
3833 break_command_1 (arg, flag, from_tty)
3837 int tempflag, hardwareflag;
3838 struct symtabs_and_lines sals;
3839 struct symtab_and_line sal;
3840 register struct expression *cond = 0;
3841 register struct breakpoint *b;
3843 /* Pointers in arg to the start, and one past the end, of the condition. */
3844 char *cond_start = NULL;
3845 char *cond_end = NULL;
3846 /* Pointers in arg to the start, and one past the end,
3847 of the address part. */
3848 char *addr_start = NULL;
3849 char *addr_end = NULL;
3850 struct cleanup *old_chain;
3851 struct cleanup *canonical_strings_chain = NULL;
3852 char **canonical = (char **) NULL;
3856 hardwareflag = flag & BP_HARDWAREFLAG;
3857 tempflag = flag & BP_TEMPFLAG;
3862 INIT_SAL (&sal); /* initialize to zeroes */
3864 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3866 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
3867 && (arg[2] == ' ' || arg[2] == '\t')))
3869 if (default_breakpoint_valid)
3871 sals.sals = (struct symtab_and_line *)
3872 xmalloc (sizeof (struct symtab_and_line));
3873 sal.pc = default_breakpoint_address;
3874 sal.line = default_breakpoint_line;
3875 sal.symtab = default_breakpoint_symtab;
3876 sal.section = find_pc_overlay (sal.pc);
3881 error ("No default breakpoint address now.");
3887 /* Force almost all breakpoints to be in terms of the
3888 current_source_symtab (which is decode_line_1's default). This
3889 should produce the results we want almost all of the time while
3890 leaving default_breakpoint_* alone. */
3891 if (default_breakpoint_valid
3892 && (!current_source_symtab
3893 || (arg && (*arg == '+' || *arg == '-'))))
3894 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3895 default_breakpoint_line, &canonical);
3897 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
3905 /* Make sure that all storage allocated in decode_line_1 gets freed
3906 in case the following `for' loop errors out. */
3907 old_chain = make_cleanup (free, sals.sals);
3908 if (canonical != (char **) NULL)
3910 make_cleanup (free, canonical);
3911 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3912 for (i = 0; i < sals.nelts; i++)
3914 if (canonical[i] != NULL)
3915 make_cleanup (free, canonical[i]);
3919 thread = -1; /* No specific thread yet */
3921 /* Resolve all line numbers to PC's, and verify that conditions
3922 can be parsed, before setting any breakpoints. */
3923 for (i = 0; i < sals.nelts; i++)
3925 char *tok, *end_tok;
3928 resolve_sal_pc (&sals.sals[i]);
3930 /* It's possible for the PC to be nonzero, but still an illegal
3931 value on some targets.
3933 For example, on HP-UX if you start gdb, and before running the
3934 inferior you try to set a breakpoint on a shared library function
3935 "foo" where the inferior doesn't call "foo" directly but does
3936 pass its address to another function call, then we do find a
3937 minimal symbol for the "foo", but it's address is invalid.
3938 (Appears to be an index into a table that the loader sets up
3939 when the inferior is run.)
3941 Give the target a chance to bless sals.sals[i].pc before we
3942 try to make a breakpoint for it. */
3943 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
3945 error ("Cannot break on %s without a running program.",
3953 while (*tok == ' ' || *tok == '\t')
3958 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3961 toklen = end_tok - tok;
3963 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3965 tok = cond_start = end_tok + 1;
3966 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3969 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3975 thread = strtol (tok, &tok, 0);
3977 error ("Junk after thread keyword.");
3978 if (!valid_thread_id (thread))
3979 error ("Unknown thread %d\n", thread);
3982 error ("Junk at end of arguments.");
3987 int i, target_resources_ok;
3989 i = hw_breakpoint_used_count ();
3990 target_resources_ok =
3991 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
3993 if (target_resources_ok == 0)
3994 error ("No hardware breakpoint support in the target.");
3995 else if (target_resources_ok < 0)
3996 error ("Hardware breakpoints used exceeds limit.");
3999 /* Remove the canonical strings from the cleanup, they are needed below. */
4000 if (canonical != (char **) NULL)
4001 discard_cleanups (canonical_strings_chain);
4003 /* Now set all the breakpoints. */
4004 for (i = 0; i < sals.nelts; i++)
4009 describe_other_breakpoints (sal.pc, sal.section);
4011 b = set_raw_breakpoint (sal);
4012 set_breakpoint_count (breakpoint_count + 1);
4013 b->number = breakpoint_count;
4014 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4018 /* If a canonical line spec is needed use that instead of the
4020 if (canonical != (char **) NULL && canonical[i] != NULL)
4021 b->addr_string = canonical[i];
4022 else if (addr_start)
4023 b->addr_string = savestring (addr_start, addr_end - addr_start);
4025 b->cond_string = savestring (cond_start, cond_end - cond_start);
4027 b->enable = enabled;
4028 b->disposition = tempflag ? del : donttouch;
4034 warning ("Multiple breakpoints were set.");
4035 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4037 do_cleanups (old_chain);
4041 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4046 struct frame_info *frame;
4047 CORE_ADDR low, high, selected_pc = 0;
4048 char *extra_args, *level_arg, *addr_string;
4049 int extra_args_len = 0, if_arg = 0;
4052 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4055 if (default_breakpoint_valid)
4059 selected_pc = selected_frame->pc;
4064 error ("No selected frame.");
4067 error ("No default breakpoint address now.");
4071 extra_args = strchr (arg, ' ');
4075 extra_args_len = strlen (extra_args);
4076 level_arg = (char *) xmalloc (extra_args - arg);
4077 strncpy (level_arg, arg, extra_args - arg - 1);
4078 level_arg[extra_args - arg - 1] = '\0';
4082 level_arg = (char *) xmalloc (strlen (arg) + 1);
4083 strcpy (level_arg, arg);
4086 frame = parse_frame_specification (level_arg);
4088 selected_pc = frame->pc;
4095 extra_args_len = strlen (arg);
4100 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4102 addr_string = (char *) xmalloc (26 + extra_args_len);
4104 sprintf (addr_string, "*0x%x %s", high, extra_args);
4106 sprintf (addr_string, "*0x%x", high);
4107 break_command_1 (addr_string, flag, from_tty);
4111 error ("No function contains the specified address");
4114 error ("Unable to set breakpoint at procedure exit");
4119 break_at_finish_command_1 (arg, flag, from_tty)
4124 char *addr_string, *break_string, *beg_addr_string;
4125 CORE_ADDR low, high;
4126 struct symtabs_and_lines sals;
4127 struct symtab_and_line sal;
4128 struct cleanup *old_chain;
4130 int extra_args_len = 0;
4134 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4136 if (default_breakpoint_valid)
4140 addr_string = (char *) xmalloc (15);
4141 sprintf (addr_string, "*0x%x", selected_frame->pc);
4146 error ("No selected frame.");
4149 error ("No default breakpoint address now.");
4153 addr_string = (char *) xmalloc (strlen (arg) + 1);
4154 strcpy (addr_string, arg);
4160 extra_args_len = strlen (arg);
4164 /* get the stuff after the function name or address */
4165 extra_args = strchr (arg, ' ');
4169 extra_args_len = strlen (extra_args);
4176 beg_addr_string = addr_string;
4177 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4180 free (beg_addr_string);
4181 old_chain = make_cleanup (free, sals.sals);
4182 for (i = 0; (i < sals.nelts); i++)
4185 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4187 break_string = (char *) xmalloc (extra_args_len + 26);
4189 sprintf (break_string, "*0x%x %s", high, extra_args);
4191 sprintf (break_string, "*0x%x", high);
4192 break_command_1 (break_string, flag, from_tty);
4193 free (break_string);
4196 error ("No function contains the specified address");
4200 warning ("Multiple breakpoints were set.\n");
4201 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4203 do_cleanups (old_chain);
4207 /* Helper function for break_command_1 and disassemble_command. */
4210 resolve_sal_pc (sal)
4211 struct symtab_and_line *sal;
4215 if (sal->pc == 0 && sal->symtab != NULL)
4217 if (!find_line_pc (sal->symtab, sal->line, &pc))
4218 error ("No line %d in file \"%s\".",
4219 sal->line, sal->symtab->filename);
4223 if (sal->section == 0 && sal->symtab != NULL)
4225 struct blockvector *bv;
4230 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4233 b = BLOCKVECTOR_BLOCK (bv, index);
4234 sym = block_function (b);
4237 fixup_symbol_section (sym, sal->symtab->objfile);
4238 sal->section = SYMBOL_BFD_SECTION (sym);
4242 /* It really is worthwhile to have the section, so we'll just
4243 have to look harder. This case can be executed if we have
4244 line numbers but no functions (as can happen in assembly
4247 struct minimal_symbol *msym;
4249 msym = lookup_minimal_symbol_by_pc (sal->pc);
4251 sal->section = SYMBOL_BFD_SECTION (msym);
4258 break_command (arg, from_tty)
4262 break_command_1 (arg, 0, from_tty);
4266 break_at_finish_command (arg, from_tty)
4270 break_at_finish_command_1 (arg, 0, from_tty);
4274 break_at_finish_at_depth_command (arg, from_tty)
4278 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4282 tbreak_command (arg, from_tty)
4286 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4290 tbreak_at_finish_command (arg, from_tty)
4294 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4298 hbreak_command (arg, from_tty)
4302 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4306 thbreak_command (arg, from_tty)
4310 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4314 stop_command (arg, from_tty)
4318 printf_filtered ("Specify the type of breakpoint to set.\n\
4319 Usage: stop in <function | address>\n\
4324 stopin_command (arg, from_tty)
4330 if (arg == (char *) NULL)
4332 else if (*arg != '*')
4337 /* look for a ':'. If this is a line number specification, then
4338 say it is bad, otherwise, it should be an address or
4339 function/method name */
4340 while (*argptr && !hasColon)
4342 hasColon = (*argptr == ':');
4347 badInput = (*argptr != ':'); /* Not a class::method */
4349 badInput = isdigit (*arg); /* a simple line number */
4353 printf_filtered ("Usage: stop in <function | address>\n");
4355 break_command_1 (arg, 0, from_tty);
4359 stopat_command (arg, from_tty)
4365 if (arg == (char *) NULL || *arg == '*') /* no line number */
4372 /* look for a ':'. If there is a '::' then get out, otherwise
4373 it is probably a line number. */
4374 while (*argptr && !hasColon)
4376 hasColon = (*argptr == ':');
4381 badInput = (*argptr == ':'); /* we have class::method */
4383 badInput = !isdigit (*arg); /* not a line number */
4387 printf_filtered ("Usage: stop at <line>\n");
4389 break_command_1 (arg, 0, from_tty);
4393 /* accessflag: hw_write: watch write,
4394 hw_read: watch read,
4395 hw_access: watch access (read or write) */
4397 watch_command_1 (arg, accessflag, from_tty)
4402 struct breakpoint *b;
4403 struct symtab_and_line sal;
4404 struct expression *exp;
4405 struct block *exp_valid_block;
4406 struct value *val, *mark;
4407 struct frame_info *frame;
4408 struct frame_info *prev_frame = NULL;
4409 char *exp_start = NULL;
4410 char *exp_end = NULL;
4411 char *tok, *end_tok;
4413 char *cond_start = NULL;
4414 char *cond_end = NULL;
4415 struct expression *cond = NULL;
4416 int i, other_type_used, target_resources_ok = 0;
4417 enum bptype bp_type;
4420 INIT_SAL (&sal); /* initialize to zeroes */
4422 /* Parse arguments. */
4423 innermost_block = NULL;
4425 exp = parse_exp_1 (&arg, 0, 0);
4427 exp_valid_block = innermost_block;
4428 mark = value_mark ();
4429 val = evaluate_expression (exp);
4430 release_value (val);
4431 if (VALUE_LAZY (val))
4432 value_fetch_lazy (val);
4435 while (*tok == ' ' || *tok == '\t')
4439 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4442 toklen = end_tok - tok;
4443 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4445 tok = cond_start = end_tok + 1;
4446 cond = parse_exp_1 (&tok, 0, 0);
4450 error ("Junk at end of command.");
4452 if (accessflag == hw_read)
4453 bp_type = bp_read_watchpoint;
4454 else if (accessflag == hw_access)
4455 bp_type = bp_access_watchpoint;
4457 bp_type = bp_hardware_watchpoint;
4459 mem_cnt = can_use_hardware_watchpoint (val);
4460 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4461 error ("Expression cannot be implemented with read/access watchpoint.");
4464 i = hw_watchpoint_used_count (bp_type, &other_type_used);
4465 target_resources_ok =
4466 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4468 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4469 error ("Target does not support this type of hardware watchpoint.");
4471 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4472 error ("Target can only support one kind of HW watchpoint at a time.");
4475 #if defined(HPUXHPPA)
4476 /* On HP-UX if you set a h/w
4477 watchpoint before the "run" command, the inferior dies with a e.g.,
4478 SIGILL once you start it. I initially believed this was due to a
4479 bad interaction between page protection traps and the initial
4480 startup sequence by the dynamic linker.
4482 However, I tried avoiding that by having HP-UX's implementation of
4483 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4484 yet, which forced slow watches before a "run" or "attach", and it
4485 still fails somewhere in the startup code.
4487 Until I figure out what's happening, I'm disallowing watches altogether
4488 before the "run" or "attach" command. We'll tell the user they must
4489 set watches after getting the program started. */
4490 if (!target_has_execution)
4492 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4495 #endif /* HPUXHPPA */
4497 /* Now set up the breakpoint. */
4498 b = set_raw_breakpoint (sal);
4499 set_breakpoint_count (breakpoint_count + 1);
4500 b->number = breakpoint_count;
4501 b->disposition = donttouch;
4503 b->exp_valid_block = exp_valid_block;
4504 b->exp_string = savestring (exp_start, exp_end - exp_start);
4508 b->cond_string = savestring (cond_start, cond_end - cond_start);
4512 frame = block_innermost_frame (exp_valid_block);
4515 prev_frame = get_prev_frame (frame);
4516 b->watchpoint_frame = frame->frame;
4519 b->watchpoint_frame = (CORE_ADDR) 0;
4521 if (mem_cnt && target_resources_ok > 0)
4524 b->type = bp_watchpoint;
4526 /* If the expression is "local", then set up a "watchpoint scope"
4527 breakpoint at the point where we've left the scope of the watchpoint
4529 if (innermost_block)
4533 struct breakpoint *scope_breakpoint;
4534 struct symtab_and_line scope_sal;
4536 INIT_SAL (&scope_sal); /* initialize to zeroes */
4537 scope_sal.pc = get_frame_pc (prev_frame);
4538 scope_sal.section = find_pc_overlay (scope_sal.pc);
4540 scope_breakpoint = set_raw_breakpoint (scope_sal);
4541 set_breakpoint_count (breakpoint_count + 1);
4542 scope_breakpoint->number = breakpoint_count;
4544 scope_breakpoint->type = bp_watchpoint_scope;
4545 scope_breakpoint->enable = enabled;
4547 /* Automatically delete the breakpoint when it hits. */
4548 scope_breakpoint->disposition = del;
4550 /* Only break in the proper frame (help with recursion). */
4551 scope_breakpoint->frame = prev_frame->frame;
4553 /* Set the address at which we will stop. */
4554 scope_breakpoint->address = get_frame_pc (prev_frame);
4556 /* The scope breakpoint is related to the watchpoint. We
4557 will need to act on them together. */
4558 b->related_breakpoint = scope_breakpoint;
4561 value_free_to_mark (mark);
4565 /* Return count of locations need to be watched and can be handled
4566 in hardware. If the watchpoint can not be handled
4567 in hardware return zero. */
4569 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4570 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4571 ((BYTE_SIZE) <= (REGISTER_SIZE))
4574 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4575 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4576 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
4580 can_use_hardware_watchpoint (v)
4583 int found_memory_cnt = 0;
4585 /* Did the user specifically forbid us to use hardware watchpoints? */
4586 if (!can_use_hw_watchpoints)
4589 /* Make sure all the intermediate values are in memory. Also make sure
4590 we found at least one memory expression. Guards against watch 0x12345,
4591 which is meaningless, but could cause errors if one tries to insert a
4592 hardware watchpoint for the constant expression. */
4593 for (; v; v = v->next)
4595 if (v->lval == lval_memory)
4597 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4598 int len = TYPE_LENGTH (VALUE_TYPE (v));
4600 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4605 else if (v->lval != not_lval && v->modifiable == 0)
4606 return 0; /* ??? What does this represent? */
4607 else if (v->lval == lval_register)
4608 return 0; /* cannot watch a register with a HW watchpoint */
4611 /* The expression itself looks suitable for using a hardware
4612 watchpoint, but give the target machine a chance to reject it. */
4613 return found_memory_cnt;
4617 watch_command (arg, from_tty)
4621 watch_command_1 (arg, hw_write, from_tty);
4625 rwatch_command (arg, from_tty)
4629 watch_command_1 (arg, hw_read, from_tty);
4633 awatch_command (arg, from_tty)
4637 watch_command_1 (arg, hw_access, from_tty);
4641 /* Helper routines for the until_command routine in infcmd.c. Here
4642 because it uses the mechanisms of breakpoints. */
4644 /* This function is called by fetch_inferior_event via the
4645 cmd_continuation pointer, to complete the until command. It takes
4646 care of cleaning up the temporary breakpoints set up by the until
4649 until_break_command_continuation (arg)
4650 struct continuation_arg *arg;
4652 /* Do all the exec cleanups, which at this point should only be the
4653 one set up in the first part of the until_break_command
4655 do_exec_cleanups (ALL_CLEANUPS);
4660 until_break_command (arg, from_tty)
4664 struct symtabs_and_lines sals;
4665 struct symtab_and_line sal;
4666 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4667 struct breakpoint *breakpoint;
4668 struct cleanup *old_chain;
4669 struct continuation_arg *arg1, *arg2;
4671 clear_proceed_status ();
4673 /* Set a breakpoint where the user wants it and at return from
4676 if (default_breakpoint_valid)
4677 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4678 default_breakpoint_line, (char ***) NULL);
4680 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4681 0, (char ***) NULL);
4683 if (sals.nelts != 1)
4684 error ("Couldn't get information on specified line.");
4687 free ((PTR) sals.sals); /* malloc'd, so freed */
4690 error ("Junk at end of arguments.");
4692 resolve_sal_pc (&sal);
4694 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
4696 if (!async_p || !target_has_async)
4697 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4700 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4702 /* If we are running asynchronously, and the target supports async
4703 execution, we are not waiting for the target to stop, in the call
4704 tp proceed, below. This means that we cannot delete the
4705 brekpoints until the target has actually stopped. The only place
4706 where we get a chance to do that is in fetch_inferior_event, so
4707 we must set things up for that. */
4709 if (async_p && target_has_async)
4711 /* In this case we don't need args for the continuation, because
4712 all it needs to do is do the cleanups in the
4713 exec_cleanup_chain, which will be only those inserted by this
4714 function. We can get away by using ALL_CLEANUPS. */
4715 add_continuation (until_break_command_continuation, NULL);
4718 /* Keep within the current frame */
4722 sal = find_pc_line (prev_frame->pc, 0);
4723 sal.pc = prev_frame->pc;
4724 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
4725 if (!async_p || !target_has_async)
4726 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4728 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4731 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
4732 /* Do the cleanups now, anly if we are not running asynchronously,
4733 of if we are, but the target is still synchronous. */
4734 if (!async_p || !target_has_async)
4735 do_cleanups (old_chain);
4739 /* These aren't used; I don't konw what they were for. */
4740 /* Set a breakpoint at the catch clause for NAME. */
4742 catch_breakpoint (name)
4748 disable_catch_breakpoint ()
4753 delete_catch_breakpoint ()
4758 enable_catch_breakpoint ()
4765 struct sal_chain *next;
4766 struct symtab_and_line sal;
4770 /* Not really used -- invocation in handle_gnu_4_16_catch_command
4771 had been commented out in the v.4.16 sources, and stays
4772 disabled there now because "catch NAME" syntax isn't allowed.
4774 /* This isn't used; I don't know what it was for. */
4775 /* For each catch clause identified in ARGS, run FUNCTION
4776 with that clause as an argument. */
4777 static struct symtabs_and_lines
4778 map_catch_names (args, function)
4782 register char *p = args;
4784 struct symtabs_and_lines sals;
4786 struct sal_chain *sal_chain = 0;
4790 error_no_arg ("one or more catch names");
4798 /* Don't swallow conditional part. */
4799 if (p1[0] == 'i' && p1[1] == 'f'
4800 && (p1[2] == ' ' || p1[2] == '\t'))
4806 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4810 if (*p1 && *p1 != ' ' && *p1 != '\t')
4811 error ("Arguments must be catch names.");
4817 struct sal_chain *next = (struct sal_chain *)
4818 alloca (sizeof (struct sal_chain));
4819 next->next = sal_chain;
4820 next->sal = get_catch_sal (p);
4825 printf_unfiltered ("No catch clause for exception %s.\n", p);
4830 while (*p == ' ' || *p == '\t')
4836 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4838 static struct symtabs_and_lines
4839 get_catch_sals (this_level_only)
4840 int this_level_only;
4842 register struct blockvector *bl;
4843 register struct block *block;
4844 int index, have_default = 0;
4846 struct symtabs_and_lines sals;
4847 struct sal_chain *sal_chain = 0;
4848 char *blocks_searched;
4850 /* Not sure whether an error message is always the correct response,
4851 but it's better than a core dump. */
4852 if (selected_frame == NULL)
4853 error ("No selected frame.");
4854 block = get_frame_block (selected_frame);
4855 pc = selected_frame->pc;
4861 error ("No symbol table info available.\n");
4863 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4864 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4865 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4869 CORE_ADDR end = BLOCK_END (block) - 4;
4872 if (bl != blockvector_for_pc (end, &index))
4873 error ("blockvector blotch");
4874 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4875 error ("blockvector botch");
4876 last_index = BLOCKVECTOR_NBLOCKS (bl);
4879 /* Don't print out blocks that have gone by. */
4880 while (index < last_index
4881 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4884 while (index < last_index
4885 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4887 if (blocks_searched[index] == 0)
4889 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4892 register struct symbol *sym;
4894 nsyms = BLOCK_NSYMS (b);
4896 for (i = 0; i < nsyms; i++)
4898 sym = BLOCK_SYM (b, i);
4899 if (STREQ (SYMBOL_NAME (sym), "default"))
4905 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4907 struct sal_chain *next = (struct sal_chain *)
4908 alloca (sizeof (struct sal_chain));
4909 next->next = sal_chain;
4910 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
4915 blocks_searched[index] = 1;
4921 if (sal_chain && this_level_only)
4924 /* After handling the function's top-level block, stop.
4925 Don't continue to its superblock, the block of
4926 per-file symbols. */
4927 if (BLOCK_FUNCTION (block))
4929 block = BLOCK_SUPERBLOCK (block);
4934 struct sal_chain *tmp_chain;
4936 /* Count the number of entries. */
4937 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4938 tmp_chain = tmp_chain->next)
4942 sals.sals = (struct symtab_and_line *)
4943 xmalloc (index * sizeof (struct symtab_and_line));
4944 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4945 sals.sals[index] = sal_chain->sal;
4952 ep_skip_leading_whitespace (s)
4955 if ((s == NULL) || (*s == NULL))
4957 while (isspace (**s))
4961 /* This function examines a string, and attempts to find a token
4962 that might be an event name in the leading characters. If a
4963 possible match is found, a pointer to the last character of
4964 the token is returned. Else, NULL is returned. */
4967 ep_find_event_name_end (arg)
4971 char *event_name_end = NULL;
4973 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4977 /* We break out of the loop when we find a token delimiter.
4978 Basically, we're looking for alphanumerics and underscores;
4979 anything else delimites the token. */
4982 if (!isalnum (*s) && (*s != '_'))
4988 return event_name_end;
4992 /* This function attempts to parse an optional "if <cond>" clause
4993 from the arg string. If one is not found, it returns NULL.
4995 Else, it returns a pointer to the condition string. (It does not
4996 attempt to evaluate the string against a particular block.) And,
4997 it updates arg to point to the first character following the parsed
4998 if clause in the arg string. */
5001 ep_parse_optional_if_clause (arg)
5006 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5009 /* Skip the "if" keyword. */
5012 /* Skip any extra leading whitespace, and record the start of the
5013 condition string. */
5014 ep_skip_leading_whitespace (arg);
5017 /* Assume that the condition occupies the remainder of the arg string. */
5018 (*arg) += strlen (cond_string);
5023 /* This function attempts to parse an optional filename from the arg
5024 string. If one is not found, it returns NULL.
5026 Else, it returns a pointer to the parsed filename. (This function
5027 makes no attempt to verify that a file of that name exists, or is
5028 accessible.) And, it updates arg to point to the first character
5029 following the parsed filename in the arg string.
5031 Note that clients needing to preserve the returned filename for
5032 future access should copy it to their own buffers. */
5034 ep_parse_optional_filename (arg)
5037 static char filename[1024];
5042 if ((*arg_p == '\0') || isspace (*arg_p))
5060 /* Commands to deal with catching events, such as signals, exceptions,
5061 process start/exit, etc. */
5065 catch_fork, catch_vfork
5069 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5075 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
5076 catch_fork_kind fork_kind;
5081 char *cond_string = NULL;
5083 ep_skip_leading_whitespace (&arg);
5085 /* The allowed syntax is:
5087 catch [v]fork if <cond>
5089 First, check if there's an if clause. */
5090 cond_string = ep_parse_optional_if_clause (&arg);
5092 if ((*arg != '\0') && !isspace (*arg))
5093 error ("Junk at end of arguments.");
5095 /* If this target supports it, create a fork or vfork catchpoint
5096 and enable reporting of such events. */
5100 create_fork_event_catchpoint (tempflag, cond_string);
5103 create_vfork_event_catchpoint (tempflag, cond_string);
5106 error ("unsupported or unknown fork kind; cannot catch it");
5112 catch_exec_command_1 (arg, tempflag, from_tty)
5117 char *cond_string = NULL;
5119 ep_skip_leading_whitespace (&arg);
5121 /* The allowed syntax is:
5123 catch exec if <cond>
5125 First, check if there's an if clause. */
5126 cond_string = ep_parse_optional_if_clause (&arg);
5128 if ((*arg != '\0') && !isspace (*arg))
5129 error ("Junk at end of arguments.");
5131 /* If this target supports it, create an exec catchpoint
5132 and enable reporting of such events. */
5133 create_exec_event_catchpoint (tempflag, cond_string);
5136 #if defined(SOLIB_ADD)
5138 catch_load_command_1 (arg, tempflag, from_tty)
5143 char *dll_pathname = NULL;
5144 char *cond_string = NULL;
5146 ep_skip_leading_whitespace (&arg);
5148 /* The allowed syntax is:
5150 catch load if <cond>
5151 catch load <filename>
5152 catch load <filename> if <cond>
5154 The user is not allowed to specify the <filename> after an
5157 We'll ignore the pathological case of a file named "if".
5159 First, check if there's an if clause. If so, then there
5160 cannot be a filename. */
5161 cond_string = ep_parse_optional_if_clause (&arg);
5163 /* If there was an if clause, then there cannot be a filename.
5164 Else, there might be a filename and an if clause. */
5165 if (cond_string == NULL)
5167 dll_pathname = ep_parse_optional_filename (&arg);
5168 ep_skip_leading_whitespace (&arg);
5169 cond_string = ep_parse_optional_if_clause (&arg);
5172 if ((*arg != '\0') && !isspace (*arg))
5173 error ("Junk at end of arguments.");
5175 /* Create a load breakpoint that only triggers when a load of
5176 the specified dll (or any dll, if no pathname was specified)
5178 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5179 dll_pathname, cond_string);
5183 catch_unload_command_1 (arg, tempflag, from_tty)
5188 char *dll_pathname = NULL;
5189 char *cond_string = NULL;
5191 ep_skip_leading_whitespace (&arg);
5193 /* The allowed syntax is:
5195 catch unload if <cond>
5196 catch unload <filename>
5197 catch unload <filename> if <cond>
5199 The user is not allowed to specify the <filename> after an
5202 We'll ignore the pathological case of a file named "if".
5204 First, check if there's an if clause. If so, then there
5205 cannot be a filename. */
5206 cond_string = ep_parse_optional_if_clause (&arg);
5208 /* If there was an if clause, then there cannot be a filename.
5209 Else, there might be a filename and an if clause. */
5210 if (cond_string == NULL)
5212 dll_pathname = ep_parse_optional_filename (&arg);
5213 ep_skip_leading_whitespace (&arg);
5214 cond_string = ep_parse_optional_if_clause (&arg);
5217 if ((*arg != '\0') && !isspace (*arg))
5218 error ("Junk at end of arguments.");
5220 /* Create an unload breakpoint that only triggers when an unload of
5221 the specified dll (or any dll, if no pathname was specified)
5223 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5224 dll_pathname, cond_string);
5226 #endif /* SOLIB_ADD */
5228 /* Commands to deal with catching exceptions. */
5230 /* Set a breakpoint at the specified callback routine for an
5231 exception event callback */
5234 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5237 enum exception_event_kind ex_event;
5238 struct symtab_and_line *sal;
5240 struct breakpoint *b;
5242 int thread = -1; /* All threads. */
5244 if (!sal) /* no exception support? */
5247 b = set_raw_breakpoint (*sal);
5248 set_breakpoint_count (breakpoint_count + 1);
5249 b->number = breakpoint_count;
5251 b->cond_string = (cond_string == NULL) ?
5252 NULL : savestring (cond_string, strlen (cond_string));
5254 b->addr_string = NULL;
5255 b->enable = enabled;
5256 b->disposition = tempflag ? del : donttouch;
5259 case EX_EVENT_THROW:
5260 b->type = bp_catch_throw;
5262 case EX_EVENT_CATCH:
5263 b->type = bp_catch_catch;
5265 default: /* error condition */
5267 b->enable = disabled;
5268 error ("Internal error -- invalid catchpoint kind");
5273 /* Deal with "catch catch" and "catch throw" commands */
5276 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5277 enum exception_event_kind ex_event;
5282 char *cond_string = NULL;
5283 struct symtab_and_line *sal = NULL;
5285 ep_skip_leading_whitespace (&arg);
5287 cond_string = ep_parse_optional_if_clause (&arg);
5289 if ((*arg != '\0') && !isspace (*arg))
5290 error ("Junk at end of arguments.");
5292 if ((ex_event != EX_EVENT_THROW) &&
5293 (ex_event != EX_EVENT_CATCH))
5294 error ("Unsupported or unknown exception event; cannot catch it");
5296 /* See if we can find a callback routine */
5297 sal = target_enable_exception_callback (ex_event, 1);
5301 /* We have callbacks from the runtime system for exceptions.
5302 Set a breakpoint on the sal found, if no errors */
5303 if (sal != (struct symtab_and_line *) -1)
5304 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5306 return; /* something went wrong with setting up callbacks */
5310 /* No callbacks from runtime system for exceptions.
5311 Try GNU C++ exception breakpoints using labels in debug info. */
5312 if (ex_event == EX_EVENT_CATCH)
5314 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5316 else if (ex_event == EX_EVENT_THROW)
5318 /* Set a breakpoint on __raise_exception () */
5320 warning ("Unsupported with this platform/compiler combination.");
5321 warning ("Perhaps you can achieve the effect you want by setting");
5322 warning ("a breakpoint on __raise_exception().");
5327 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5328 inside a catch_errors */
5331 cover_target_enable_exception_callback (arg)
5334 args_for_catchpoint_enable *args = arg;
5335 struct symtab_and_line *sal;
5336 sal = target_enable_exception_callback (args->kind, args->enable);
5339 else if (sal == (struct symtab_and_line *) -1)
5342 return 1; /*is valid */
5347 /* This is the original v.4.16 and earlier version of the
5348 catch_command_1() function. Now that other flavours of "catch"
5349 have been introduced, and since exception handling can be handled
5350 in other ways (through target ops) also, this is used only for the
5351 GNU C++ exception handling system.
5352 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5353 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5354 there was no code in GDB 4.16 for "catch throw".
5356 Called from catch_exception_command_1 () */
5360 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5365 /* First, translate ARG into something we can deal with in terms
5368 struct symtabs_and_lines sals;
5369 struct symtab_and_line sal;
5370 register struct expression *cond = 0;
5371 register struct breakpoint *b;
5375 INIT_SAL (&sal); /* initialize to zeroes */
5377 /* If no arg given, or if first arg is 'if ', all active catch clauses
5378 are breakpointed. */
5380 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5381 && (arg[2] == ' ' || arg[2] == '\t')))
5383 /* Grab all active catch clauses. */
5384 sals = get_catch_sals (0);
5388 /* Grab selected catch clauses. */
5389 error ("catch NAME not implemented");
5392 /* Not sure why this code has been disabled. I'm leaving
5393 it disabled. We can never come here now anyway
5394 since we don't allow the "catch NAME" syntax.
5397 /* This isn't used; I don't know what it was for. */
5398 sals = map_catch_names (arg, catch_breakpoint);
5406 for (i = 0; i < sals.nelts; i++)
5408 resolve_sal_pc (&sals.sals[i]);
5412 if (arg[0] == 'i' && arg[1] == 'f'
5413 && (arg[2] == ' ' || arg[2] == '\t'))
5414 cond = parse_exp_1 ((arg += 2, &arg),
5415 block_for_pc (sals.sals[i].pc), 0);
5417 error ("Junk at end of arguments.");
5422 for (i = 0; i < sals.nelts; i++)
5427 describe_other_breakpoints (sal.pc, sal.section);
5429 b = set_raw_breakpoint (sal);
5430 set_breakpoint_count (breakpoint_count + 1);
5431 b->number = breakpoint_count;
5433 /* Important -- this is an ordinary breakpoint. For platforms
5434 with callback support for exceptions,
5435 create_exception_catchpoint() will create special bp types
5436 (bp_catch_catch and bp_catch_throw), and there is code in
5437 insert_breakpoints() and elsewhere that depends on that. */
5438 b->type = bp_breakpoint;
5441 b->enable = enabled;
5442 b->disposition = tempflag ? del : donttouch;
5449 warning ("Multiple breakpoints were set.");
5450 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5452 free ((PTR) sals.sals);
5456 /* This creates a temporary internal breakpoint
5457 just to placate infrun */
5458 static struct breakpoint *
5459 create_temp_exception_breakpoint (pc)
5462 struct symtab_and_line sal;
5463 struct breakpoint *b;
5470 b = set_raw_breakpoint (sal);
5472 error ("Internal error -- couldn't set temp exception breakpoint");
5474 b->type = bp_breakpoint;
5475 b->disposition = del;
5476 b->enable = enabled;
5478 b->number = internal_breakpoint_number--;
5484 catch_command_1 (arg, tempflag, from_tty)
5490 /* The first argument may be an event name, such as "start" or "load".
5491 If so, then handle it as such. If it doesn't match an event name,
5492 then attempt to interpret it as an exception name. (This latter is
5493 the v4.16-and-earlier GDB meaning of the "catch" command.)
5495 First, try to find the bounds of what might be an event name. */
5496 char *arg1_start = arg;
5500 if (arg1_start == NULL)
5502 /* Old behaviour was to use pre-v-4.16 syntax */
5503 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5505 /* Now, this is not allowed */
5506 error ("Catch requires an event name.");
5509 arg1_end = ep_find_event_name_end (arg1_start);
5510 if (arg1_end == NULL)
5511 error ("catch requires an event");
5512 arg1_length = arg1_end + 1 - arg1_start;
5514 /* Try to match what we found against known event names. */
5515 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5517 error ("Catch of signal not yet implemented");
5519 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5521 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5522 tempflag, from_tty);
5524 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5526 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5527 tempflag, from_tty);
5529 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5531 error ("Catch of thread_start not yet implemented");
5533 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5535 error ("Catch of thread_exit not yet implemented");
5537 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5539 error ("Catch of thread_join not yet implemented");
5541 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5543 error ("Catch of start not yet implemented");
5545 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5547 error ("Catch of exit not yet implemented");
5549 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5551 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5552 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
5554 error ("Catch of fork not yet implemented");
5557 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5559 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5560 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
5562 error ("Catch of vfork not yet implemented");
5565 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5567 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5568 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
5570 error ("Catch of exec not yet implemented");
5573 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5575 #if defined(SOLIB_ADD)
5576 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
5578 error ("Catch of load not implemented");
5581 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5583 #if defined(SOLIB_ADD)
5584 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
5586 error ("Catch of load not implemented");
5589 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5591 error ("Catch of stop not yet implemented");
5594 /* This doesn't appear to be an event name */
5598 /* Pre-v.4.16 behaviour was to treat the argument
5599 as the name of an exception */
5600 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5601 /* Now this is not allowed */
5602 error ("Unknown event kind specified for catch");
5607 /* Used by the gui, could be made a worker for other things. */
5610 set_breakpoint_sal (sal)
5611 struct symtab_and_line sal;
5613 struct breakpoint *b;
5614 b = set_raw_breakpoint (sal);
5615 set_breakpoint_count (breakpoint_count + 1);
5616 b->number = breakpoint_count;
5617 b->type = bp_breakpoint;
5624 /* These aren't used; I don't know what they were for. */
5625 /* Disable breakpoints on all catch clauses described in ARGS. */
5627 disable_catch (args)
5630 /* Map the disable command to catch clauses described in ARGS. */
5633 /* Enable breakpoints on all catch clauses described in ARGS. */
5638 /* Map the disable command to catch clauses described in ARGS. */
5641 /* Delete breakpoints on all catch clauses in the active scope. */
5646 /* Map the delete command to catch clauses described in ARGS. */
5651 catch_command (arg, from_tty)
5655 catch_command_1 (arg, 0, from_tty);
5660 tcatch_command (arg, from_tty)
5664 catch_command_1 (arg, 1, from_tty);
5669 clear_command (arg, from_tty)
5673 register struct breakpoint *b, *b1;
5675 struct symtabs_and_lines sals;
5676 struct symtab_and_line sal;
5677 register struct breakpoint *found;
5682 sals = decode_line_spec (arg, 1);
5687 sals.sals = (struct symtab_and_line *)
5688 xmalloc (sizeof (struct symtab_and_line));
5689 INIT_SAL (&sal); /* initialize to zeroes */
5690 sal.line = default_breakpoint_line;
5691 sal.symtab = default_breakpoint_symtab;
5692 sal.pc = default_breakpoint_address;
5693 if (sal.symtab == 0)
5694 error ("No source file specified.");
5702 /* For each line spec given, delete bps which correspond
5703 to it. We do this in two loops: the first loop looks at
5704 the initial bp(s) in the chain which should be deleted,
5705 the second goes down the rest of the chain looking ahead
5706 one so it can take those bps off the chain without messing
5710 for (i = 0; i < sals.nelts; i++)
5712 /* If exact pc given, clear bpts at that pc.
5713 If line given (pc == 0), clear all bpts on specified line.
5714 If defaulting, clear all bpts on default line
5717 defaulting sal.pc != 0 tests to do
5722 1 0 <can't happen> */
5725 found = (struct breakpoint *) 0;
5728 while (breakpoint_chain
5729 /* Why don't we check here that this is not
5730 a watchpoint, etc., as we do below?
5731 I can't make it fail, but don't know
5732 what's stopping the failure: a watchpoint
5733 of the same address as "sal.pc" should
5734 wind up being deleted. */
5736 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5737 (overlay_debugging == 0 ||
5738 breakpoint_chain->section == sal.section))
5739 || ((default_match || (0 == sal.pc))
5740 && breakpoint_chain->source_file != NULL
5741 && sal.symtab != NULL
5742 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5743 && breakpoint_chain->line_number == sal.line)))
5746 b1 = breakpoint_chain;
5747 breakpoint_chain = b1->next;
5755 && b->next->type != bp_none
5756 && b->next->type != bp_watchpoint
5757 && b->next->type != bp_hardware_watchpoint
5758 && b->next->type != bp_read_watchpoint
5759 && b->next->type != bp_access_watchpoint
5760 && (((sal.pc && (b->next->address == sal.pc)) &&
5761 (overlay_debugging == 0 ||
5762 b->next->section == sal.section))
5763 || ((default_match || (0 == sal.pc))
5764 && b->next->source_file != NULL
5765 && sal.symtab != NULL
5766 && STREQ (b->next->source_file, sal.symtab->filename)
5767 && b->next->line_number == sal.line)))
5780 error ("No breakpoint at %s.", arg);
5782 error ("No breakpoint at this line.");
5786 from_tty = 1; /* Always report if deleted more than one */
5788 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
5789 breakpoints_changed ();
5793 printf_unfiltered ("%d ", found->number);
5795 delete_breakpoint (found);
5799 putchar_unfiltered ('\n');
5801 free ((PTR) sals.sals);
5804 /* Delete breakpoint in BS if they are `delete' breakpoints and
5805 all breakpoints that are marked for deletion, whether hit or not.
5806 This is called after any breakpoint is hit, or after errors. */
5809 breakpoint_auto_delete (bs)
5812 struct breakpoint *b, *temp;
5814 for (; bs; bs = bs->next)
5815 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
5817 delete_breakpoint (bs->breakpoint_at);
5819 ALL_BREAKPOINTS_SAFE (b, temp)
5821 if (b->disposition == del_at_next_stop)
5822 delete_breakpoint (b);
5826 /* Delete a breakpoint and clean up all traces of it in the data
5830 delete_breakpoint (bpt)
5831 struct breakpoint *bpt;
5833 register struct breakpoint *b;
5837 error ("Internal error (attempted to delete a NULL breakpoint)");
5840 /* Has this bp already been deleted? This can happen because multiple
5841 lists can hold pointers to bp's. bpstat lists are especial culprits.
5843 One example of this happening is a watchpoint's scope bp. When the
5844 scope bp triggers, we notice that the watchpoint is out of scope, and
5845 delete it. We also delete its scope bp. But the scope bp is marked
5846 "auto-deleting", and is already on a bpstat. That bpstat is then
5847 checked for auto-deleting bp's, which are deleted.
5849 A real solution to this problem might involve reference counts in bp's,
5850 and/or giving them pointers back to their referencing bpstat's, and
5851 teaching delete_breakpoint to only free a bp's storage when no more
5852 references were extent. A cheaper bandaid was chosen. */
5853 if (bpt->type == bp_none)
5856 if (delete_breakpoint_hook)
5857 delete_breakpoint_hook (bpt);
5858 breakpoint_delete_event (bpt->number);
5861 remove_breakpoint (bpt, mark_uninserted);
5863 if (breakpoint_chain == bpt)
5864 breakpoint_chain = bpt->next;
5866 /* If we have callback-style exception catchpoints, don't go through
5867 the adjustments to the C++ runtime library etc. if the inferior
5868 isn't actually running. target_enable_exception_callback for a
5869 null target ops vector gives an undesirable error message, so we
5870 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
5871 exceptions are supported in this way, it's OK for now. FIXME */
5872 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5874 static char message1[] = "Error in deleting catchpoint %d:\n";
5875 static char message[sizeof (message1) + 30];
5876 args_for_catchpoint_enable args;
5878 /* Format possible error msg */
5879 sprintf (message, message1, bpt->number);
5880 args.kind = bpt->type == bp_catch_catch ?
5881 EX_EVENT_CATCH : EX_EVENT_THROW;
5883 catch_errors (cover_target_enable_exception_callback, &args,
5884 message, RETURN_MASK_ALL);
5891 b->next = bpt->next;
5895 /* Before turning off the visuals for the bp, check to see that
5896 there are no other bps at the same address. */
5903 clearIt = (b->address != bpt->address);
5910 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
5911 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
5915 check_duplicates (bpt->address, bpt->section);
5916 /* If this breakpoint was inserted, and there is another breakpoint
5917 at the same address, we need to insert the other breakpoint. */
5919 && bpt->type != bp_hardware_watchpoint
5920 && bpt->type != bp_read_watchpoint
5921 && bpt->type != bp_access_watchpoint
5922 && bpt->type != bp_catch_fork
5923 && bpt->type != bp_catch_vfork
5924 && bpt->type != bp_catch_exec)
5927 if (b->address == bpt->address
5928 && b->section == bpt->section
5930 && b->enable != disabled
5931 && b->enable != shlib_disabled
5932 && b->enable != call_disabled)
5936 if (b->type == bp_hardware_breakpoint)
5937 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
5939 val = target_insert_breakpoint (b->address, b->shadow_contents);
5943 target_terminal_ours_for_output ();
5944 warning ("Cannot insert breakpoint %d:", b->number);
5945 memory_error (val, b->address); /* which bombs us out */
5952 free_command_lines (&bpt->commands);
5955 if (bpt->cond_string != NULL)
5956 free (bpt->cond_string);
5957 if (bpt->addr_string != NULL)
5958 free (bpt->addr_string);
5959 if (bpt->exp != NULL)
5961 if (bpt->exp_string != NULL)
5962 free (bpt->exp_string);
5963 if (bpt->val != NULL)
5964 value_free (bpt->val);
5965 if (bpt->source_file != NULL)
5966 free (bpt->source_file);
5967 if (bpt->dll_pathname != NULL)
5968 free (bpt->dll_pathname);
5969 if (bpt->triggered_dll_pathname != NULL)
5970 free (bpt->triggered_dll_pathname);
5971 if (bpt->exec_pathname != NULL)
5972 free (bpt->exec_pathname);
5974 /* Be sure no bpstat's are pointing at it after it's been freed. */
5975 /* FIXME, how can we find all bpstat's?
5976 We just check stop_bpstat for now. */
5977 for (bs = stop_bpstat; bs; bs = bs->next)
5978 if (bs->breakpoint_at == bpt)
5980 bs->breakpoint_at = NULL;
5982 /* we'd call bpstat_clear_actions, but that free's stuff and due
5983 to the multiple pointers pointing to one item with no
5984 reference counts found anywhere through out the bpstat's (how
5985 do you spell fragile?), we don't want to free things twice --
5986 better a memory leak than a corrupt malloc pool! */
5987 bs->commands = NULL;
5990 /* On the chance that someone will soon try again to delete this same
5991 bp, we mark it as deleted before freeing its storage. */
5992 bpt->type = bp_none;
5998 delete_command (arg, from_tty)
6002 struct breakpoint *b, *temp;
6006 int breaks_to_delete = 0;
6008 /* Delete all breakpoints if no argument.
6009 Do not delete internal or call-dummy breakpoints, these
6010 have to be deleted with an explicit breakpoint number argument. */
6013 if (b->type != bp_call_dummy &&
6014 b->type != bp_shlib_event &&
6016 breaks_to_delete = 1;
6019 /* Ask user only if there are some breakpoints to delete. */
6021 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6023 ALL_BREAKPOINTS_SAFE (b, temp)
6025 if (b->type != bp_call_dummy &&
6026 b->type != bp_shlib_event &&
6028 delete_breakpoint (b);
6033 map_breakpoint_numbers (arg, delete_breakpoint);
6036 /* Reset a breakpoint given it's struct breakpoint * BINT.
6037 The value we return ends up being the return value from catch_errors.
6038 Unused in this case. */
6041 breakpoint_re_set_one (bint)
6044 /* get past catch_errs */
6045 struct breakpoint *b = (struct breakpoint *) bint;
6048 struct symtabs_and_lines sals;
6050 enum enable save_enable;
6055 warning ("attempted to reset apparently deleted breakpoint #%d?",
6059 case bp_hardware_breakpoint:
6061 case bp_catch_unload:
6062 if (b->addr_string == NULL)
6064 /* Anything without a string can't be re-set. */
6065 delete_breakpoint (b);
6068 /* In case we have a problem, disable this breakpoint. We'll restore
6069 its status if we succeed. */
6070 save_enable = b->enable;
6071 b->enable = disabled;
6073 set_language (b->language);
6074 input_radix = b->input_radix;
6076 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6077 for (i = 0; i < sals.nelts; i++)
6079 resolve_sal_pc (&sals.sals[i]);
6081 /* Reparse conditions, they might contain references to the
6083 if (b->cond_string != NULL)
6087 free ((PTR) b->cond);
6088 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6091 /* We need to re-set the breakpoint if the address changes... */
6092 if (b->address != sals.sals[i].pc
6093 /* ...or new and old breakpoints both have source files, and
6094 the source file name or the line number changes... */
6095 || (b->source_file != NULL
6096 && sals.sals[i].symtab != NULL
6097 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6098 || b->line_number != sals.sals[i].line)
6100 /* ...or we switch between having a source file and not having
6102 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6105 if (b->source_file != NULL)
6106 free (b->source_file);
6107 if (sals.sals[i].symtab == NULL)
6108 b->source_file = NULL;
6111 savestring (sals.sals[i].symtab->filename,
6112 strlen (sals.sals[i].symtab->filename));
6113 b->line_number = sals.sals[i].line;
6114 b->address = sals.sals[i].pc;
6116 /* Used to check for duplicates here, but that can
6117 cause trouble, as it doesn't check for disable
6122 /* Might be better to do this just once per breakpoint_re_set,
6123 rather than once for every breakpoint. */
6124 breakpoints_changed ();
6126 b->section = sals.sals[i].section;
6127 b->enable = save_enable; /* Restore it, this worked. */
6130 /* Now that this is re-enabled, check_duplicates
6132 check_duplicates (b->address, b->section);
6135 free ((PTR) sals.sals);
6139 case bp_hardware_watchpoint:
6140 case bp_read_watchpoint:
6141 case bp_access_watchpoint:
6142 innermost_block = NULL;
6143 /* The issue arises of what context to evaluate this in. The
6144 same one as when it was set, but what does that mean when
6145 symbols have been re-read? We could save the filename and
6146 functionname, but if the context is more local than that, the
6147 best we could do would be something like how many levels deep
6148 and which index at that particular level, but that's going to
6149 be less stable than filenames or function names. */
6151 /* So for now, just use a global context. */
6153 free ((PTR) b->exp);
6154 b->exp = parse_expression (b->exp_string);
6155 b->exp_valid_block = innermost_block;
6156 mark = value_mark ();
6158 value_free (b->val);
6159 b->val = evaluate_expression (b->exp);
6160 release_value (b->val);
6161 if (VALUE_LAZY (b->val))
6162 value_fetch_lazy (b->val);
6164 if (b->cond_string != NULL)
6168 free ((PTR) b->cond);
6169 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6171 if (b->enable == enabled)
6173 value_free_to_mark (mark);
6175 case bp_catch_catch:
6176 case bp_catch_throw:
6178 /* We needn't really do anything to reset these, since the mask
6179 that requests them is unaffected by e.g., new libraries being
6182 case bp_catch_vfork:
6187 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6189 /* Delete longjmp breakpoints, they will be reset later by
6190 breakpoint_re_set. */
6192 case bp_longjmp_resume:
6193 delete_breakpoint (b);
6196 /* This breakpoint is special, it's set up when the inferior
6197 starts and we really don't want to touch it. */
6198 case bp_shlib_event:
6200 /* Keep temporary breakpoints, which can be encountered when we step
6201 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6202 Otherwise these should have been blown away via the cleanup chain
6203 or by breakpoint_init_inferior when we rerun the executable. */
6206 case bp_watchpoint_scope:
6208 case bp_step_resume:
6215 /* Re-set all breakpoints after symbols have been re-loaded. */
6217 breakpoint_re_set ()
6219 struct breakpoint *b, *temp;
6220 enum language save_language;
6221 int save_input_radix;
6222 static char message1[] = "Error in re-setting breakpoint %d:\n";
6223 char message[sizeof (message1) + 30 /* slop */ ];
6225 save_language = current_language->la_language;
6226 save_input_radix = input_radix;
6227 ALL_BREAKPOINTS_SAFE (b, temp)
6229 /* Format possible error msg */
6230 sprintf (message, message1, b->number);
6231 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6233 set_language (save_language);
6234 input_radix = save_input_radix;
6236 #ifdef GET_LONGJMP_TARGET
6237 create_longjmp_breakpoint ("longjmp");
6238 create_longjmp_breakpoint ("_longjmp");
6239 create_longjmp_breakpoint ("siglongjmp");
6240 create_longjmp_breakpoint ("_siglongjmp");
6241 create_longjmp_breakpoint (NULL);
6245 /* Took this out (temporarily at least), since it produces an extra
6246 blank line at startup. This messes up the gdbtests. -PB */
6247 /* Blank line to finish off all those mention() messages we just printed. */
6248 printf_filtered ("\n");
6252 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6253 If from_tty is nonzero, it prints a message to that effect,
6254 which ends with a period (no newline). */
6256 /* Reset the thread number of this breakpoint:
6258 - If the breakpoint is for all threads, leave it as-is.
6259 - Else, reset it to the current thread for inferior_pid. */
6261 breakpoint_re_set_thread (b)
6262 struct breakpoint *b;
6264 if (b->thread != -1)
6266 if (in_thread_list (inferior_pid))
6267 b->thread = pid_to_thread_id (inferior_pid);
6272 set_ignore_count (bptnum, count, from_tty)
6273 int bptnum, count, from_tty;
6275 register struct breakpoint *b;
6281 if (b->number == bptnum)
6283 b->ignore_count = count;
6286 else if (count == 0)
6287 printf_filtered ("Will stop next time breakpoint %d is reached.",
6289 else if (count == 1)
6290 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6293 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6295 breakpoints_changed ();
6299 error ("No breakpoint number %d.", bptnum);
6302 /* Clear the ignore counts of all breakpoints. */
6304 breakpoint_clear_ignore_counts ()
6306 struct breakpoint *b;
6309 b->ignore_count = 0;
6312 /* Command to set ignore-count of breakpoint N to COUNT. */
6315 ignore_command (args, from_tty)
6323 error_no_arg ("a breakpoint number");
6325 num = get_number (&p);
6328 error ("Second argument (specified ignore-count) is missing.");
6330 set_ignore_count (num,
6331 longest_to_int (value_as_long (parse_and_eval (p))),
6333 printf_filtered ("\n");
6334 breakpoints_changed ();
6337 /* Call FUNCTION on each of the breakpoints
6338 whose numbers are given in ARGS. */
6341 map_breakpoint_numbers (args, function)
6343 void (*function) PARAMS ((struct breakpoint *));
6345 register char *p = args;
6348 register struct breakpoint *b;
6351 error_no_arg ("one or more breakpoint numbers");
6357 num = get_number (&p1);
6360 if (b->number == num)
6362 struct breakpoint *related_breakpoint = b->related_breakpoint;
6364 if (related_breakpoint)
6365 function (related_breakpoint);
6368 printf_unfiltered ("No breakpoint number %d.\n", num);
6375 disable_breakpoint (bpt)
6376 struct breakpoint *bpt;
6378 /* Never disable a watchpoint scope breakpoint; we want to
6379 hit them when we leave scope so we can delete both the
6380 watchpoint and its scope breakpoint at that time. */
6381 if (bpt->type == bp_watchpoint_scope)
6384 bpt->enable = disabled;
6386 check_duplicates (bpt->address, bpt->section);
6388 if (modify_breakpoint_hook)
6389 modify_breakpoint_hook (bpt);
6390 breakpoint_modify_event (bpt->number);
6395 disable_command (args, from_tty)
6399 register struct breakpoint *bpt;
6401 ALL_BREAKPOINTS (bpt)
6405 warning ("attempted to disable apparently deleted breakpoint #%d?",
6410 case bp_catch_unload:
6412 case bp_catch_vfork:
6414 case bp_catch_catch:
6415 case bp_catch_throw:
6416 case bp_hardware_breakpoint:
6418 case bp_hardware_watchpoint:
6419 case bp_read_watchpoint:
6420 case bp_access_watchpoint:
6421 disable_breakpoint (bpt);
6426 map_breakpoint_numbers (args, disable_breakpoint);
6430 do_enable_breakpoint (bpt, disposition)
6431 struct breakpoint *bpt;
6432 enum bpdisp disposition;
6434 struct frame_info *save_selected_frame = NULL;
6435 int save_selected_frame_level = -1;
6436 int target_resources_ok, other_type_used;
6439 if (bpt->type == bp_hardware_breakpoint)
6442 i = hw_breakpoint_used_count ();
6443 target_resources_ok =
6444 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6446 if (target_resources_ok == 0)
6447 error ("No hardware breakpoint support in the target.");
6448 else if (target_resources_ok < 0)
6449 error ("Hardware breakpoints used exceeds limit.");
6452 bpt->enable = enabled;
6453 bpt->disposition = disposition;
6454 check_duplicates (bpt->address, bpt->section);
6455 breakpoints_changed ();
6457 if (bpt->type == bp_watchpoint ||
6458 bpt->type == bp_hardware_watchpoint ||
6459 bpt->type == bp_read_watchpoint ||
6460 bpt->type == bp_access_watchpoint)
6462 if (bpt->exp_valid_block != NULL)
6464 struct frame_info *fr =
6466 /* Ensure that we have the current frame. Else, this
6467 next query may pessimistically be answered as, "No,
6468 not within current scope". */
6469 get_current_frame ();
6470 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6474 Cannot enable watchpoint %d because the block in which its expression\n\
6475 is valid is not currently in scope.\n", bpt->number);
6476 bpt->enable = disabled;
6480 save_selected_frame = selected_frame;
6481 save_selected_frame_level = selected_frame_level;
6482 select_frame (fr, -1);
6485 value_free (bpt->val);
6486 mark = value_mark ();
6487 bpt->val = evaluate_expression (bpt->exp);
6488 release_value (bpt->val);
6489 if (VALUE_LAZY (bpt->val))
6490 value_fetch_lazy (bpt->val);
6492 if (bpt->type == bp_hardware_watchpoint ||
6493 bpt->type == bp_read_watchpoint ||
6494 bpt->type == bp_access_watchpoint)
6496 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6497 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6499 /* Hack around 'unused var' error for some targets here */
6501 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6502 bpt->type, i + mem_cnt, other_type_used);
6503 /* we can consider of type is bp_hardware_watchpoint, convert to
6504 bp_watchpoint in the following condition */
6505 if (target_resources_ok < 0)
6508 Cannot enable watchpoint %d because target watch resources\n\
6509 have been allocated for other watchpoints.\n", bpt->number);
6510 bpt->enable = disabled;
6511 value_free_to_mark (mark);
6516 if (save_selected_frame_level >= 0)
6517 select_and_print_frame (save_selected_frame,
6518 save_selected_frame_level);
6519 value_free_to_mark (mark);
6521 if (modify_breakpoint_hook)
6522 modify_breakpoint_hook (bpt);
6523 breakpoint_modify_event (bpt->number);
6527 enable_breakpoint (bpt)
6528 struct breakpoint *bpt;
6530 do_enable_breakpoint (bpt, bpt->disposition);
6533 /* The enable command enables the specified breakpoints (or all defined
6534 breakpoints) so they once again become (or continue to be) effective
6535 in stopping the inferior. */
6539 enable_command (args, from_tty)
6543 register struct breakpoint *bpt;
6545 ALL_BREAKPOINTS (bpt)
6549 warning ("attempted to enable apparently deleted breakpoint #%d?",
6554 case bp_catch_unload:
6556 case bp_catch_vfork:
6558 case bp_catch_catch:
6559 case bp_catch_throw:
6560 case bp_hardware_breakpoint:
6562 case bp_hardware_watchpoint:
6563 case bp_read_watchpoint:
6564 case bp_access_watchpoint:
6565 enable_breakpoint (bpt);
6570 map_breakpoint_numbers (args, enable_breakpoint);
6574 enable_once_breakpoint (bpt)
6575 struct breakpoint *bpt;
6577 do_enable_breakpoint (bpt, disable);
6582 enable_once_command (args, from_tty)
6586 map_breakpoint_numbers (args, enable_once_breakpoint);
6590 enable_delete_breakpoint (bpt)
6591 struct breakpoint *bpt;
6593 do_enable_breakpoint (bpt, del);
6598 enable_delete_command (args, from_tty)
6602 map_breakpoint_numbers (args, enable_delete_breakpoint);
6605 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
6607 struct symtabs_and_lines
6608 decode_line_spec_1 (string, funfirstline)
6612 struct symtabs_and_lines sals;
6614 error ("Empty line specification.");
6615 if (default_breakpoint_valid)
6616 sals = decode_line_1 (&string, funfirstline,
6617 default_breakpoint_symtab,
6618 default_breakpoint_line,
6621 sals = decode_line_1 (&string, funfirstline,
6622 (struct symtab *) NULL, 0, (char ***) NULL);
6624 error ("Junk at end of line specification: %s", string);
6629 _initialize_breakpoint ()
6631 struct cmd_list_element *c;
6633 breakpoint_chain = 0;
6634 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6635 before a breakpoint is set. */
6636 breakpoint_count = 0;
6638 add_com ("ignore", class_breakpoint, ignore_command,
6639 "Set ignore-count of breakpoint number N to COUNT.\n\
6640 Usage is `ignore N COUNT'.");
6642 add_com_alias ("bc", "ignore", class_breakpoint, 1);
6644 add_com ("commands", class_breakpoint, commands_command,
6645 "Set commands to be executed when a breakpoint is hit.\n\
6646 Give breakpoint number as argument after \"commands\".\n\
6647 With no argument, the targeted breakpoint is the last one set.\n\
6648 The commands themselves follow starting on the next line.\n\
6649 Type a line containing \"end\" to indicate the end of them.\n\
6650 Give \"silent\" as the first line to make the breakpoint silent;\n\
6651 then no output is printed when it is hit, except what the commands print.");
6653 add_com ("condition", class_breakpoint, condition_command,
6654 "Specify breakpoint number N to break only if COND is true.\n\
6655 Usage is `condition N COND', where N is an integer and COND is an\n\
6656 expression to be evaluated whenever breakpoint N is reached. ");
6658 add_com ("tbreak", class_breakpoint, tbreak_command,
6659 "Set a temporary breakpoint. Args like \"break\" command.\n\
6660 Like \"break\" except the breakpoint is only temporary,\n\
6661 so it will be deleted when hit. Equivalent to \"break\" followed\n\
6662 by using \"enable delete\" on the breakpoint number.");
6663 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6664 "Set temporary breakpoint at procedure exit. Either there should\n\
6665 be no argument or the argument must be a depth.\n");
6667 add_com ("hbreak", class_breakpoint, hbreak_command,
6668 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6669 Like \"break\" except the breakpoint requires hardware support,\n\
6670 some target hardware may not have this support.");
6672 add_com ("thbreak", class_breakpoint, thbreak_command,
6673 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6674 Like \"hbreak\" except the breakpoint is only temporary,\n\
6675 so it will be deleted when hit.");
6677 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6678 "Enable some breakpoints.\n\
6679 Give breakpoint numbers (separated by spaces) as arguments.\n\
6680 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6681 This is used to cancel the effect of the \"disable\" command.\n\
6682 With a subcommand you can enable temporarily.",
6683 &enablelist, "enable ", 1, &cmdlist);
6685 add_com ("ab", class_breakpoint, enable_command,
6686 "Enable some breakpoints.\n\
6687 Give breakpoint numbers (separated by spaces) as arguments.\n\
6688 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6689 This is used to cancel the effect of the \"disable\" command.\n\
6690 With a subcommand you can enable temporarily.");
6692 add_com_alias ("en", "enable", class_breakpoint, 1);
6694 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
6695 "Enable some breakpoints.\n\
6696 Give breakpoint numbers (separated by spaces) as arguments.\n\
6697 This is used to cancel the effect of the \"disable\" command.\n\
6698 May be abbreviated to simply \"enable\".\n",
6699 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
6701 add_cmd ("once", no_class, enable_once_command,
6702 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6703 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6706 add_cmd ("delete", no_class, enable_delete_command,
6707 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6708 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6711 add_cmd ("delete", no_class, enable_delete_command,
6712 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6713 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6716 add_cmd ("once", no_class, enable_once_command,
6717 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6718 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6721 add_prefix_cmd ("disable", class_breakpoint, disable_command,
6722 "Disable some breakpoints.\n\
6723 Arguments are breakpoint numbers with spaces in between.\n\
6724 To disable all breakpoints, give no argument.\n\
6725 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6726 &disablelist, "disable ", 1, &cmdlist);
6727 add_com_alias ("dis", "disable", class_breakpoint, 1);
6728 add_com_alias ("disa", "disable", class_breakpoint, 1);
6730 add_com ("sb", class_breakpoint, disable_command,
6731 "Disable some breakpoints.\n\
6732 Arguments are breakpoint numbers with spaces in between.\n\
6733 To disable all breakpoints, give no argument.\n\
6734 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6736 add_cmd ("breakpoints", class_alias, disable_command,
6737 "Disable some breakpoints.\n\
6738 Arguments are breakpoint numbers with spaces in between.\n\
6739 To disable all breakpoints, give no argument.\n\
6740 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6741 This command may be abbreviated \"disable\".",
6744 add_prefix_cmd ("delete", class_breakpoint, delete_command,
6745 "Delete some breakpoints or auto-display expressions.\n\
6746 Arguments are breakpoint numbers with spaces in between.\n\
6747 To delete all breakpoints, give no argument.\n\
6749 Also a prefix command for deletion of other GDB objects.\n\
6750 The \"unset\" command is also an alias for \"delete\".",
6751 &deletelist, "delete ", 1, &cmdlist);
6752 add_com_alias ("d", "delete", class_breakpoint, 1);
6754 add_com ("db", class_breakpoint, delete_command,
6755 "Delete some breakpoints.\n\
6756 Arguments are breakpoint numbers with spaces in between.\n\
6757 To delete all breakpoints, give no argument.\n");
6759 add_cmd ("breakpoints", class_alias, delete_command,
6760 "Delete some breakpoints or auto-display expressions.\n\
6761 Arguments are breakpoint numbers with spaces in between.\n\
6762 To delete all breakpoints, give no argument.\n\
6763 This command may be abbreviated \"delete\".",
6766 add_com ("clear", class_breakpoint, clear_command,
6767 concat ("Clear breakpoint at specified line or function.\n\
6768 Argument may be line number, function name, or \"*\" and an address.\n\
6769 If line number is specified, all breakpoints in that line are cleared.\n\
6770 If function is specified, breakpoints at beginning of function are cleared.\n\
6771 If an address is specified, breakpoints at that address are cleared.\n\n",
6772 "With no argument, clears all breakpoints in the line that the selected frame\n\
6775 See also the \"delete\" command which clears breakpoints by number.", NULL));
6777 add_com ("break", class_breakpoint, break_command,
6778 concat ("Set breakpoint at specified line or function.\n\
6779 Argument may be line number, function name, or \"*\" and an address.\n\
6780 If line number is specified, break at start of code for that line.\n\
6781 If function is specified, break at start of code for that function.\n\
6782 If an address is specified, break at that exact address.\n",
6783 "With no arg, uses current execution address of selected stack frame.\n\
6784 This is useful for breaking on return to a stack frame.\n\
6786 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6788 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6789 add_com_alias ("b", "break", class_run, 1);
6790 add_com_alias ("br", "break", class_run, 1);
6791 add_com_alias ("bre", "break", class_run, 1);
6792 add_com_alias ("brea", "break", class_run, 1);
6794 add_com ("xbreak", class_breakpoint, break_at_finish_command,
6795 concat ("Set breakpoint at procedure exit. \n\
6796 Argument may be function name, or \"*\" and an address.\n\
6797 If function is specified, break at end of code for that function.\n\
6798 If an address is specified, break at the end of the function that contains \n\
6799 that exact address.\n",
6800 "With no arg, uses current execution address of selected stack frame.\n\
6801 This is useful for breaking on return to a stack frame.\n\
6803 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6805 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6806 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6807 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6808 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6809 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6813 add_com_alias ("ba", "break", class_breakpoint, 1);
6814 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6815 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
6816 "Set breakpoint at procedure exit. Either there should\n\
6817 be no argument or the argument must be a depth.\n");
6822 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
6823 "Break in function/address or break at a line in the current file.",
6824 &stoplist, "stop ", 1, &cmdlist);
6825 add_cmd ("in", class_breakpoint, stopin_command,
6826 "Break in function or address.\n", &stoplist);
6827 add_cmd ("at", class_breakpoint, stopat_command,
6828 "Break at a line in the current file.\n", &stoplist);
6829 add_com ("status", class_info, breakpoints_info,
6830 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6831 The \"Type\" column indicates one of:\n\
6832 \tbreakpoint - normal breakpoint\n\
6833 \twatchpoint - watchpoint\n\
6834 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6835 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6836 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6837 address and file/line number respectively.\n\n",
6838 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6839 are set to the address of the last breakpoint listed.\n\n\
6840 Convenience variable \"$bpnum\" contains the number of the last\n\
6841 breakpoint set.", NULL));
6844 add_info ("breakpoints", breakpoints_info,
6845 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6846 The \"Type\" column indicates one of:\n\
6847 \tbreakpoint - normal breakpoint\n\
6848 \twatchpoint - watchpoint\n\
6849 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6850 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6851 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6852 address and file/line number respectively.\n\n",
6853 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6854 are set to the address of the last breakpoint listed.\n\n\
6855 Convenience variable \"$bpnum\" contains the number of the last\n\
6856 breakpoint set.", NULL));
6859 add_com ("lb", class_breakpoint, breakpoints_info,
6860 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6861 The \"Type\" column indicates one of:\n\
6862 \tbreakpoint - normal breakpoint\n\
6863 \twatchpoint - watchpoint\n\
6864 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6865 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6866 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6867 address and file/line number respectively.\n\n",
6868 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6869 are set to the address of the last breakpoint listed.\n\n\
6870 Convenience variable \"$bpnum\" contains the number of the last\n\
6871 breakpoint set.", NULL));
6873 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
6874 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
6875 The \"Type\" column indicates one of:\n\
6876 \tbreakpoint - normal breakpoint\n\
6877 \twatchpoint - watchpoint\n\
6878 \tlongjmp - internal breakpoint used to step through longjmp()\n\
6879 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6880 \tuntil - internal breakpoint used by the \"until\" command\n\
6881 \tfinish - internal breakpoint used by the \"finish\" command\n",
6882 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6883 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6884 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6885 address and file/line number respectively.\n\n",
6886 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6887 are set to the address of the last breakpoint listed.\n\n\
6888 Convenience variable \"$bpnum\" contains the number of the last\n\
6889 breakpoint set.", NULL),
6890 &maintenanceinfolist);
6892 add_com ("catch", class_breakpoint, catch_command,
6893 "Set catchpoints to catch events.\n\
6894 Raised signals may be caught:\n\
6895 \tcatch signal - all signals\n\
6896 \tcatch signal <signame> - a particular signal\n\
6897 Raised exceptions may be caught:\n\
6898 \tcatch throw - all exceptions, when thrown\n\
6899 \tcatch throw <exceptname> - a particular exception, when thrown\n\
6900 \tcatch catch - all exceptions, when caught\n\
6901 \tcatch catch <exceptname> - a particular exception, when caught\n\
6902 Thread or process events may be caught:\n\
6903 \tcatch thread_start - any threads, just after creation\n\
6904 \tcatch thread_exit - any threads, just before expiration\n\
6905 \tcatch thread_join - any threads, just after joins\n\
6906 Process events may be caught:\n\
6907 \tcatch start - any processes, just after creation\n\
6908 \tcatch exit - any processes, just before expiration\n\
6909 \tcatch fork - calls to fork()\n\
6910 \tcatch vfork - calls to vfork()\n\
6911 \tcatch exec - calls to exec()\n\
6912 Dynamically-linked library events may be caught:\n\
6913 \tcatch load - loads of any library\n\
6914 \tcatch load <libname> - loads of a particular library\n\
6915 \tcatch unload - unloads of any library\n\
6916 \tcatch unload <libname> - unloads of a particular library\n\
6917 The act of your program's execution stopping may also be caught:\n\
6919 C++ exceptions may be caught:\n\
6920 \tcatch throw - all exceptions, when thrown\n\
6921 \tcatch catch - all exceptions, when caught\n\
6923 Do \"help set follow-fork-mode\" for info on debugging your program\n\
6924 after a fork or vfork is caught.\n\n\
6925 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
6927 add_com ("tcatch", class_breakpoint, tcatch_command,
6928 "Set temporary catchpoints to catch events.\n\
6929 Args like \"catch\" command.\n\
6930 Like \"catch\" except the catchpoint is only temporary,\n\
6931 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6932 by using \"enable delete\" on the catchpoint number.");
6934 add_com ("watch", class_breakpoint, watch_command,
6935 "Set a watchpoint for an expression.\n\
6936 A watchpoint stops execution of your program whenever the value of\n\
6937 an expression changes.");
6939 add_com ("rwatch", class_breakpoint, rwatch_command,
6940 "Set a read watchpoint for an expression.\n\
6941 A watchpoint stops execution of your program whenever the value of\n\
6942 an expression is read.");
6944 add_com ("awatch", class_breakpoint, awatch_command,
6945 "Set a watchpoint for an expression.\n\
6946 A watchpoint stops execution of your program whenever the value of\n\
6947 an expression is either read or written.");
6949 add_info ("watchpoints", breakpoints_info,
6950 "Synonym for ``info breakpoints''.");
6953 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
6954 (char *) &can_use_hw_watchpoints,
6955 "Set debugger's willingness to use watchpoint hardware.\n\
6956 If zero, gdb will not use hardware for new watchpoints, even if\n\
6957 such is available. (However, any hardware watchpoints that were\n\
6958 created before setting this to nonzero, will continue to use watchpoint\n\
6961 add_show_from_set (c, &showlist);
6963 can_use_hw_watchpoints = 1;