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, Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
27 #include "expression.h"
33 #include "gdbthread.h"
36 #include "gdb_string.h"
42 /* Prototypes for local functions. */
45 catch_command_1 PARAMS ((char *, int, int));
48 enable_delete_command PARAMS ((char *, int));
51 enable_delete_breakpoint PARAMS ((struct breakpoint *));
54 enable_once_command PARAMS ((char *, int));
57 enable_once_breakpoint PARAMS ((struct breakpoint *));
60 disable_command PARAMS ((char *, int));
63 enable_command PARAMS ((char *, int));
66 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
69 ignore_command PARAMS ((char *, int));
71 static int breakpoint_re_set_one PARAMS ((PTR));
74 clear_command PARAMS ((char *, int));
77 catch_command PARAMS ((char *, int));
80 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
82 static struct symtabs_and_lines
83 get_catch_sals PARAMS ((int));
86 watch_command PARAMS ((char *, int));
89 can_use_hardware_watchpoint PARAMS ((struct value *));
91 static void break_at_finish_command PARAMS ((char *, int));
92 static void break_at_finish_at_depth_command PARAMS ((char *, int));
95 tbreak_command PARAMS ((char *, int));
97 static void tbreak_at_finish_command PARAMS ((char *, int));
100 break_command_1 PARAMS ((char *, int, int));
103 mention PARAMS ((struct breakpoint *));
106 set_raw_breakpoint PARAMS ((struct symtab_and_line));
109 check_duplicates PARAMS ((CORE_ADDR, asection *));
112 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
115 breakpoints_info PARAMS ((char *, int));
118 breakpoint_1 PARAMS ((int, int));
121 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
123 static int breakpoint_cond_eval PARAMS ((PTR));
126 cleanup_executing_breakpoints PARAMS ((PTR));
129 commands_command PARAMS ((char *, int));
132 condition_command PARAMS ((char *, int));
135 get_number PARAMS ((char **));
138 set_breakpoint_count PARAMS ((int));
141 static struct breakpoint *
142 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
151 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
153 static int print_it_normal PARAMS ((bpstat));
156 enum exception_event_kind kind;
158 } args_for_catchpoint_enable;
160 static int watchpoint_check PARAMS ((PTR));
162 static int cover_target_enable_exception_callback PARAMS ((PTR));
164 static int print_it_done PARAMS ((bpstat));
166 static int print_it_noop PARAMS ((bpstat));
168 static void maintenance_info_breakpoints PARAMS ((char *, int));
170 #ifdef GET_LONGJMP_TARGET
171 static void create_longjmp_breakpoint PARAMS ((char *));
174 static int hw_breakpoint_used_count PARAMS ((void));
176 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
178 static void hbreak_command PARAMS ((char *, int));
180 static void thbreak_command PARAMS ((char *, int));
182 static void watch_command_1 PARAMS ((char *, int, int));
184 static void rwatch_command PARAMS ((char *, int));
186 static void awatch_command PARAMS ((char *, int));
188 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
190 static void create_solib_load_unload_event_breakpoint PARAMS ((char *hookname, int tempflag, char *dll_pathname, char *cond_string, enum bptype bp_kind));
192 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag, char * cond_string, enum bptype bp_kind));
194 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg, int flag, int from_tty));
196 static void break_at_finish_command_1 PARAMS ((char *arg, int flag, int from_tty));
198 static void stop_command PARAMS ((char *arg, int from_tty));
200 static void stopin_command PARAMS ((char *arg, int from_tty));
202 static void stopat_command PARAMS ((char *arg, int from_tty));
204 static char *ep_find_event_name_end PARAMS ((char *arg));
206 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
208 static char *ep_parse_optional_filename PARAMS ((char **arg));
210 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag, int from_tty));
212 static void create_exception_catchpoint PARAMS ((int tempflag, char *cond_string, enum exception_event_kind ex_event, struct symtab_and_line *sal));
214 static void catch_exception_command_1 PARAMS ((enum exception_event_kind ex_event, char *arg, int tempflag, int from_tty));
216 static void tcatch_command PARAMS ((char *arg, int from_tty));
218 static void ep_skip_leading_whitespace PARAMS ((char **s));
220 /* Prototypes for exported functions. */
223 awatch_command PARAMS ((char *, int));
226 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
228 /* If FALSE, gdb will not use hardware support for watchpoints, even
229 if such is available. */
230 static int can_use_hw_watchpoints;
232 void delete_command PARAMS ((char *, int));
234 void _initialize_breakpoint PARAMS ((void));
236 void set_breakpoint_count PARAMS ((int));
238 extern int addressprint; /* Print machine addresses? */
240 #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
241 static int internal_breakpoint_number = -1;
244 /* Are we executing breakpoint commands? */
245 static int executing_breakpoint_commands;
247 /* Walk the following statement or block through all breakpoints.
248 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
251 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
253 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
254 for (b = breakpoint_chain; \
255 b? (tmp=b->next, 1): 0; \
258 /* True if SHIFT_INST_REGS defined, false otherwise. */
260 int must_shift_inst_regs =
261 #if defined(SHIFT_INST_REGS)
268 /* True if breakpoint hit counts should be displayed in breakpoint info. */
270 int show_breakpoint_hit_counts = 1;
272 /* Chain of all breakpoints defined. */
274 struct breakpoint *breakpoint_chain;
276 /* Number of last breakpoint made. */
278 int breakpoint_count;
280 /* Pointer to current exception event record */
281 static struct exception_event_record * current_exception_event;
283 /* Indicator of whether exception catchpoints should be nuked
284 between runs of a program */
285 int exception_catchpoints_are_fragile = 0;
287 /* Indicator of when exception catchpoints set-up should be
288 reinitialized -- e.g. when program is re-run */
289 int exception_support_initialized = 0;
291 /* This function returns a pointer to the string representation of the
292 pathname of the dynamically-linked library that has just been
295 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
296 or undefined results are guaranteed.
298 This string's contents are only valid immediately after the
299 inferior has stopped in the dynamic linker hook, and becomes
300 invalid as soon as the inferior is continued. Clients should make
301 a copy of this string if they wish to continue the inferior and
302 then access the string. */
304 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
305 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
308 /* This function returns a pointer to the string representation of the
309 pathname of the dynamically-linked library that has just been
312 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
313 TRUE, or undefined results are guaranteed.
315 This string's contents are only valid immediately after the
316 inferior has stopped in the dynamic linker hook, and becomes
317 invalid as soon as the inferior is continued. Clients should make
318 a copy of this string if they wish to continue the inferior and
319 then access the string. */
321 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
322 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
325 /* This function is called by the "catch load" command. It allows the
326 debugger to be notified by the dynamic linker when a specified
327 library file (or any library file, if filename is NULL) is loaded. */
329 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
330 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
331 error ("catch of library loads not yet implemented on this platform")
334 /* This function is called by the "catch unload" command. It allows
335 the debugger to be notified by the dynamic linker when a specified
336 library file (or any library file, if filename is NULL) is
339 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
340 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
341 error ("catch of library unloads not yet implemented on this platform")
344 /* Set breakpoint count to NUM. */
347 set_breakpoint_count (num)
350 breakpoint_count = num;
351 set_internalvar (lookup_internalvar ("bpnum"),
352 value_from_longest (builtin_type_int, (LONGEST) num));
355 /* Used in run_command to zero the hit count when a new run starts. */
358 clear_breakpoint_hit_counts ()
360 struct breakpoint *b;
366 /* Default address, symtab and line to put a breakpoint at
367 for "break" command with no arg.
368 if default_breakpoint_valid is zero, the other three are
369 not valid, and "break" with no arg is an error.
371 This set by print_stack_frame, which calls set_default_breakpoint. */
373 int default_breakpoint_valid;
374 CORE_ADDR default_breakpoint_address;
375 struct symtab *default_breakpoint_symtab;
376 int default_breakpoint_line;
378 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
379 Advance *PP after the string and any trailing whitespace.
381 Currently the string can either be a number or "$" followed by the name
382 of a convenience variable. Making it an expression wouldn't work well
383 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
392 /* Empty line means refer to the last breakpoint. */
393 return breakpoint_count;
396 /* Make a copy of the name, so we can null-terminate it
397 to pass to lookup_internalvar(). */
402 while (isalnum (*p) || *p == '_')
404 varname = (char *) alloca (p - start + 1);
405 strncpy (varname, start, p - start);
406 varname[p - start] = '\0';
407 val = value_of_internalvar (lookup_internalvar (varname));
408 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
410 "Convenience variables used to specify breakpoints must have integer values."
412 retval = (int) value_as_long (val);
418 while (*p >= '0' && *p <= '9')
421 /* There is no number here. (e.g. "cond a == b"). */
422 error_no_arg ("breakpoint number");
425 if (!(isspace (*p) || *p == '\0'))
426 error ("breakpoint number expected");
433 /* condition N EXP -- set break condition of breakpoint N to EXP. */
436 condition_command (arg, from_tty)
440 register struct breakpoint *b;
445 error_no_arg ("breakpoint number");
448 bnum = get_number (&p);
451 if (b->number == bnum)
458 if (b->cond_string != NULL)
459 free ((PTR)b->cond_string);
464 b->cond_string = NULL;
466 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
471 /* I don't know if it matters whether this is the string the user
472 typed in or the decompiled expression. */
473 b->cond_string = savestring (arg, strlen (arg));
474 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
476 error ("Junk at end of expression");
478 breakpoints_changed ();
482 error ("No breakpoint number %d.", bnum);
487 commands_command (arg, from_tty)
491 register struct breakpoint *b;
494 struct command_line *l;
496 /* If we allowed this, we would have problems with when to
497 free the storage, if we change the commands currently
500 if (executing_breakpoint_commands)
501 error ("Can't use the \"commands\" command among a breakpoint's commands.");
504 bnum = get_number (&p);
506 error ("Unexpected extra arguments following breakpoint number.");
509 if (b->number == bnum)
512 sprintf (tmpbuf, "Type commands for when breakpoint %d is hit, one per line.", bnum);
513 l = read_command_lines (tmpbuf, from_tty);
514 free_command_lines (&b->commands);
516 breakpoints_changed ();
519 error ("No breakpoint number %d.", bnum);
522 /* Like target_read_memory() but if breakpoints are inserted, return
523 the shadow contents instead of the breakpoints themselves.
525 Read "memory data" from whatever target or inferior we have.
526 Returns zero if successful, errno value if not. EIO is used
527 for address out of bounds. If breakpoints are inserted, returns
528 shadow contents, not the breakpoints themselves. From breakpoint.c. */
531 read_memory_nobpt (memaddr, myaddr, len)
537 struct breakpoint *b;
538 CORE_ADDR bp_addr = 0;
541 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
542 /* No breakpoints on this machine. */
543 return target_read_memory (memaddr, myaddr, len);
547 if (b->type == bp_none)
548 warning ("attempted to read through apparently deleted breakpoint #%d?\n", b->number);
550 /* memory breakpoint? */
551 if (b->type == bp_watchpoint
552 || b->type == bp_hardware_watchpoint
553 || b->type == bp_read_watchpoint
554 || b->type == bp_access_watchpoint)
559 /* Addresses and length of the part of the breakpoint that
561 /* XXXX The m68k, sh and h8300 have different local and remote
562 breakpoint values. BREAKPOINT_FROM_PC still manages to
563 correctly determine the breakpoints memory address and size
564 for these targets. */
565 bp_addr = b->address;
567 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
572 if (bp_addr + bp_size <= memaddr)
573 /* The breakpoint is entirely before the chunk of memory we
576 if (bp_addr >= memaddr + len)
577 /* The breakpoint is entirely after the chunk of memory we are
580 /* Copy the breakpoint from the shadow contents, and recurse for
581 the things before and after. */
583 /* Offset within shadow_contents. */
586 if (bp_addr < memaddr)
588 /* Only copy the second part of the breakpoint. */
589 bp_size -= memaddr - bp_addr;
590 bptoffset = memaddr - bp_addr;
594 if (bp_addr + bp_size > memaddr + len)
596 /* Only copy the first part of the breakpoint. */
597 bp_size -= (bp_addr + bp_size) - (memaddr + len);
600 memcpy (myaddr + bp_addr - memaddr,
601 b->shadow_contents + bptoffset, bp_size);
603 if (bp_addr > memaddr)
605 /* Copy the section of memory before the breakpoint. */
606 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
611 if (bp_addr + bp_size < memaddr + len)
613 /* Copy the section of memory after the breakpoint. */
614 status = read_memory_nobpt
616 myaddr + bp_addr + bp_size - memaddr,
617 memaddr + len - (bp_addr + bp_size));
624 /* Nothing overlaps. Just call read_memory_noerr. */
625 return target_read_memory (memaddr, myaddr, len);
629 /* insert_breakpoints is used when starting or continuing the program.
630 remove_breakpoints is used when the program stops.
631 Both return zero if successful,
632 or an `errno' value if could not write the inferior. */
635 insert_breakpoints ()
637 register struct breakpoint *b, *temp;
639 int disabled_breaks = 0;
641 static char message1[] = "Error inserting catchpoint %d:\n";
642 static char message[sizeof (message1) + 30];
645 ALL_BREAKPOINTS_SAFE (b, temp)
647 if (b->type != bp_watchpoint
648 && b->type != bp_hardware_watchpoint
649 && b->type != bp_read_watchpoint
650 && b->type != bp_access_watchpoint
651 && b->type != bp_catch_fork
652 && b->type != bp_catch_vfork
653 && b->type != bp_catch_exec
654 && b->type != bp_catch_throw
655 && b->type != bp_catch_catch
656 && b->enable != disabled
657 && b->enable != shlib_disabled
658 && b->enable != call_disabled
662 if (b->type == bp_hardware_breakpoint)
663 val = target_insert_hw_breakpoint(b->address, b->shadow_contents);
666 /* Check to see if breakpoint is in an overlay section;
667 if so, we should set the breakpoint at the LMA address.
668 Only if the section is currently mapped should we ALSO
669 set a break at the VMA address. */
670 if (overlay_debugging && b->section &&
671 section_is_overlay (b->section))
675 addr = overlay_unmapped_address (b->address, b->section);
676 val = target_insert_breakpoint (addr, b->shadow_contents);
677 /* This would be the time to check val, to see if the
678 breakpoint write to the load address succeeded.
679 However, this might be an ordinary occurrance, eg. if
680 the unmapped overlay is in ROM. */
681 val = 0; /* in case unmapped address failed */
682 if (section_is_mapped (b->section))
683 val = target_insert_breakpoint (b->address,
686 else /* ordinary (non-overlay) address */
687 val = target_insert_breakpoint(b->address, b->shadow_contents);
691 /* Can't set the breakpoint. */
692 #if defined (DISABLE_UNSETTABLE_BREAK)
693 if (DISABLE_UNSETTABLE_BREAK (b->address))
695 /* See also: disable_breakpoints_in_shlibs. */
697 b->enable = shlib_disabled;
698 if (!disabled_breaks)
700 target_terminal_ours_for_output ();
701 fprintf_unfiltered (gdb_stderr,
702 "Cannot insert breakpoint %d:\n", b->number);
703 printf_filtered ("Temporarily disabling shared library breakpoints:\n");
706 printf_filtered ("%d ", b->number);
711 target_terminal_ours_for_output ();
712 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
713 #ifdef ONE_PROCESS_WRITETEXT
714 fprintf_unfiltered (gdb_stderr,
715 "The same program may be running in another process.\n");
717 memory_error (val, b->address); /* which bombs us out */
723 else if (ep_is_exception_catchpoint (b)
724 && b->enable != disabled
725 && b->enable != shlib_disabled
726 && b->enable != call_disabled
731 /* If we get here, we must have a callback mechanism for exception
732 events -- with g++ style embedded label support, we insert
733 ordinary breakpoints and not catchpoints. */
734 sprintf (message, message1, b->number); /* Format possible error message */
736 val = target_insert_breakpoint(b->address, b->shadow_contents);
739 /* Couldn't set breakpoint for some reason */
740 target_terminal_ours_for_output ();
741 fprintf_unfiltered (gdb_stderr,
742 "Cannot insert catchpoint %d; disabling it\n", b->number);
743 b->enable = disabled;
747 /* Bp set, now make sure callbacks are enabled */
749 args_for_catchpoint_enable args;
750 args.kind = b->type == bp_catch_catch ? EX_EVENT_CATCH : EX_EVENT_THROW;
752 val = catch_errors (cover_target_enable_exception_callback,
754 message, RETURN_MASK_ALL);
755 if (val != 0 && val != -1)
759 /* Check if something went wrong; val == 0 can be ignored */
762 /* something went wrong */
763 target_terminal_ours_for_output ();
764 fprintf_unfiltered (gdb_stderr, "Cannot insert catchpoint %d; disabling it\n", b->number);
765 b->enable = disabled;
770 else if ((b->type == bp_hardware_watchpoint ||
771 b->type == bp_read_watchpoint ||
772 b->type == bp_access_watchpoint)
773 && b->enable == enabled
777 struct frame_info *saved_frame;
778 int saved_level, within_current_scope;
779 value_ptr mark = value_mark ();
782 /* Save the current frame and level so we can restore it after
783 evaluating the watchpoint expression on its own frame. */
784 saved_frame = selected_frame;
785 saved_level = selected_frame_level;
787 /* Determine if the watchpoint is within scope. */
788 if (b->exp_valid_block == NULL)
789 within_current_scope = 1;
792 struct frame_info *fi;
794 /* There might be no current frame at this moment if we are
795 resuming from a step over a breakpoint.
796 Set up current frame before trying to find the watchpoint
798 get_current_frame ();
799 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
800 within_current_scope = (fi != NULL);
801 if (within_current_scope)
802 select_frame (fi, -1);
805 if (within_current_scope)
807 /* Evaluate the expression and cut the chain of values
808 produced off from the value chain. */
809 v = evaluate_expression (b->exp);
810 value_release_to_mark (mark);
815 /* Look at each value on the value chain. */
816 for ( ; v; v=v->next)
818 /* If it's a memory location, then we must watch it. */
819 if (v->lval == lval_memory)
823 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
824 len = TYPE_LENGTH (VALUE_TYPE (v));
826 if (b->type == bp_read_watchpoint)
828 else if (b->type == bp_access_watchpoint)
831 val = target_insert_watchpoint (addr, len, type);
840 /* Failure to insert a watchpoint on any memory value in the
841 value chain brings us here. */
843 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
849 Hardware watchpoint %d deleted because the program has left the block in\n\
850 which its expression is valid.\n", b->number);
851 if (b->related_breakpoint)
852 b->related_breakpoint->disposition = del_at_next_stop;
853 b->disposition = del_at_next_stop;
856 /* Restore the frame and level. */
857 if ((saved_frame != selected_frame) ||
858 (saved_level != selected_frame_level))
859 select_and_print_frame (saved_frame, saved_level);
861 else if ((b->type == bp_catch_fork
862 || b->type == bp_catch_vfork
863 || b->type == bp_catch_exec)
864 && b->enable == enabled
872 val = target_insert_fork_catchpoint (inferior_pid);
874 case bp_catch_vfork :
875 val = target_insert_vfork_catchpoint (inferior_pid);
878 val = target_insert_exec_catchpoint (inferior_pid);
883 target_terminal_ours_for_output ();
884 fprintf_unfiltered (gdb_stderr, "Cannot insert catchpoint %d:\n", b->number);
891 printf_filtered ("\n");
898 remove_breakpoints ()
900 register struct breakpoint *b;
907 val = remove_breakpoint (b, mark_uninserted);
916 reattach_breakpoints (pid)
919 register struct breakpoint *b;
921 int saved_inferior_pid = inferior_pid;
923 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
928 remove_breakpoint (b, mark_inserted);
929 if (b->type == bp_hardware_breakpoint)
930 val = target_insert_hw_breakpoint(b->address, b->shadow_contents);
932 val = target_insert_breakpoint(b->address, b->shadow_contents);
935 inferior_pid = saved_inferior_pid;
940 inferior_pid = saved_inferior_pid;
945 update_breakpoints_after_exec ()
947 struct breakpoint * b;
948 struct breakpoint * temp;
950 /* Doing this first prevents the badness of having delete_breakpoint()
951 write a breakpoint's current "shadow contents" to lift the bp. That
952 shadow is NOT valid after an exec()! */
953 mark_breakpoints_out ();
955 ALL_BREAKPOINTS_SAFE (b, temp)
957 /* Solib breakpoints must be explicitly reset after an exec(). */
958 if (b->type == bp_shlib_event)
960 delete_breakpoint (b);
964 /* Step-resume breakpoints are meaningless after an exec(). */
965 if (b->type == bp_step_resume)
967 delete_breakpoint (b);
971 /* Ditto the sigtramp handler breakpoints. */
972 if (b->type == bp_through_sigtramp)
974 delete_breakpoint (b);
978 /* Ditto the exception-handling catchpoints. */
979 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
981 delete_breakpoint (b);
985 /* Don't delete an exec catchpoint, because else the inferior
986 won't stop when it ought!
988 Similarly, we probably ought to keep vfork catchpoints, 'cause
989 on this target, we may not be able to stop when the vfork is seen,
990 but only when the subsequent exec is seen. (And because deleting
991 fork catchpoints here but not vfork catchpoints will seem mysterious
992 to users, keep those too.)
994 ??rehrauer: Let's hope that merely clearing out this catchpoint's
995 target address field, if any, is sufficient to have it be reset
996 automagically. Certainly on HP-UX that's true. */
997 if ((b->type == bp_catch_exec) ||
998 (b->type == bp_catch_vfork) ||
999 (b->type == bp_catch_fork))
1001 b->address = (CORE_ADDR) NULL;
1005 /* bp_finish is a special case. The only way we ought to be able
1006 to see one of these when an exec() has happened, is if the user
1007 caught a vfork, and then said "finish". Ordinarily a finish just
1008 carries them to the call-site of the current callee, by setting
1009 a temporary bp there and resuming. But in this case, the finish
1010 will carry them entirely through the vfork & exec.
1012 We don't want to allow a bp_finish to remain inserted now. But
1013 we can't safely delete it, 'cause finish_command has a handle to
1014 the bp on a bpstat, and will later want to delete it. There's a
1015 chance (and I've seen it happen) that if we delete the bp_finish
1016 here, that its storage will get reused by the time finish_command
1017 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1018 We really must allow finish_command to delete a bp_finish.
1020 In the absense of a general solution for the "how do we know it's
1021 safe to delete something others may have handles to?" problem, what
1022 we'll do here is just uninsert the bp_finish, and let finish_command
1025 (We know the bp_finish is "doomed" in the sense that it's momentary,
1026 and will be deleted as soon as finish_command sees the inferior stopped.
1027 So it doesn't matter that the bp's address is probably bogus in the
1028 new a.out, unlike e.g., the solib breakpoints.) */
1029 if (b->type == bp_finish)
1034 /* Without a symbolic address, we have little hope of the
1035 pre-exec() address meaning the same thing in the post-exec()
1037 if (b->addr_string == NULL)
1039 delete_breakpoint (b);
1043 /* If this breakpoint has survived the above battery of checks, then
1044 it must have a symbolic address. Be sure that it gets reevaluated
1045 to a target address, rather than reusing the old evaluation. */
1046 b->address = (CORE_ADDR) NULL;
1051 detach_breakpoints (pid)
1054 register struct breakpoint *b;
1056 int saved_inferior_pid = inferior_pid;
1058 if (pid == inferior_pid)
1059 error ("Cannot detach breakpoints of inferior_pid");
1061 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1066 val = remove_breakpoint (b, mark_inserted);
1069 inferior_pid = saved_inferior_pid;
1074 inferior_pid = saved_inferior_pid;
1079 remove_breakpoint (b, is)
1080 struct breakpoint *b;
1081 insertion_state_t is;
1085 if (b->type == bp_none)
1086 warning ("attempted to remove apparently deleted breakpoint #%d?\n", b->number);
1088 if (b->type != bp_watchpoint
1089 && b->type != bp_hardware_watchpoint
1090 && b->type != bp_read_watchpoint
1091 && b->type != bp_access_watchpoint
1092 && b->type != bp_catch_fork
1093 && b->type != bp_catch_vfork
1094 && b->type != bp_catch_exec
1095 && b->type != bp_catch_catch
1096 && b->type != bp_catch_throw)
1099 if (b->type == bp_hardware_breakpoint)
1100 val = target_remove_hw_breakpoint(b->address, b->shadow_contents);
1103 /* Check to see if breakpoint is in an overlay section;
1104 if so, we should remove the breakpoint at the LMA address.
1105 If that is not equal to the raw address, then we should
1106 presumable remove the breakpoint there as well. */
1107 if (overlay_debugging && b->section &&
1108 section_is_overlay (b->section))
1112 addr = overlay_unmapped_address (b->address, b->section);
1113 val = target_remove_breakpoint (addr, b->shadow_contents);
1114 /* This would be the time to check val, to see if the
1115 shadow breakpoint write to the load address succeeded.
1116 However, this might be an ordinary occurrance, eg. if
1117 the unmapped overlay is in ROM. */
1118 val = 0; /* in case unmapped address failed */
1119 if (section_is_mapped (b->section))
1120 val = target_remove_breakpoint (b->address,
1121 b->shadow_contents);
1123 else /* ordinary (non-overlay) address */
1124 val = target_remove_breakpoint(b->address, b->shadow_contents);
1128 b->inserted = (is == mark_inserted);
1130 else if ((b->type == bp_hardware_watchpoint ||
1131 b->type == bp_read_watchpoint ||
1132 b->type == bp_access_watchpoint)
1133 && b->enable == enabled
1138 b->inserted = (is == mark_inserted);
1139 /* Walk down the saved value chain. */
1140 for (v = b->val_chain; v; v = v->next)
1142 /* For each memory reference remove the watchpoint
1144 if (v->lval == lval_memory)
1146 int addr, len, type;
1148 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1149 len = TYPE_LENGTH (VALUE_TYPE (v));
1151 if (b->type == bp_read_watchpoint)
1153 else if (b->type == bp_access_watchpoint)
1156 val = target_remove_watchpoint (addr, len, type);
1162 /* Failure to remove any of the hardware watchpoints comes here. */
1163 if ((is == mark_uninserted) && (b->inserted))
1164 warning ("Hardware watchpoint %d: Could not remove watchpoint\n",
1167 /* Free the saved value chain. We will construct a new one
1168 the next time the watchpoint is inserted. */
1169 for (v = b->val_chain; v; v = n)
1174 b->val_chain = NULL;
1176 else if ((b->type == bp_catch_fork ||
1177 b->type == bp_catch_vfork ||
1178 b->type == bp_catch_exec)
1179 && b->enable == enabled
1186 val = target_remove_fork_catchpoint (inferior_pid);
1188 case bp_catch_vfork :
1189 val = target_remove_vfork_catchpoint (inferior_pid);
1191 case bp_catch_exec :
1192 val = target_remove_exec_catchpoint (inferior_pid);
1197 b->inserted = (is == mark_inserted);
1199 else if ((b->type == bp_catch_catch ||
1200 b->type == bp_catch_throw)
1201 && b->enable == enabled
1205 val = target_remove_breakpoint(b->address, b->shadow_contents);
1208 b->inserted = (is == mark_inserted);
1210 else if (ep_is_exception_catchpoint (b)
1211 && b->inserted /* sometimes previous insert doesn't happen */
1212 && b->enable == enabled
1216 val = target_remove_breakpoint(b->address, b->shadow_contents);
1220 b->inserted = (is == mark_inserted);
1226 /* Clear the "inserted" flag in all breakpoints. */
1229 mark_breakpoints_out ()
1231 register struct breakpoint *b;
1237 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
1238 which should go away between runs of the program.
1240 Plus other such housekeeping that has to be done for breakpoints
1243 Note: this function gets called at the end of a run (by generic_mourn_inferior)
1244 and when a run begins (by init_wait_for_inferior). */
1249 breakpoint_init_inferior (context)
1250 enum inf_context context;
1252 register struct breakpoint *b, *temp;
1253 static int warning_needed = 0;
1255 ALL_BREAKPOINTS_SAFE (b, temp)
1262 case bp_watchpoint_scope:
1264 /* If the call dummy breakpoint is at the entry point it will
1265 cause problems when the inferior is rerun, so we better
1268 Also get rid of scope breakpoints. */
1269 delete_breakpoint (b);
1273 case bp_hardware_watchpoint:
1274 case bp_read_watchpoint:
1275 case bp_access_watchpoint:
1277 /* Likewise for watchpoints on local expressions. */
1278 if (b->exp_valid_block != NULL)
1279 delete_breakpoint (b);
1282 /* Likewise for exception catchpoints in dynamic-linked
1283 executables where required */
1284 if (ep_is_exception_catchpoint (b) &&
1285 exception_catchpoints_are_fragile)
1288 delete_breakpoint (b);
1294 if (exception_catchpoints_are_fragile)
1295 exception_support_initialized = 0;
1297 /* Don't issue the warning unless it's really needed... */
1298 if (warning_needed && (context != inf_exited))
1300 warning ("Exception catchpoints from last run were deleted, you must reinsert them explicitly");
1305 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
1306 When continuing from a location with a breakpoint,
1307 we actually single step once before calling insert_breakpoints. */
1310 breakpoint_here_p (pc)
1313 register struct breakpoint *b;
1316 if (b->enable == enabled
1317 && b->enable != shlib_disabled
1318 && b->enable != call_disabled
1319 && b->address == pc) /* bp is enabled and matches pc */
1321 if (overlay_debugging &&
1322 section_is_overlay (b->section) &&
1323 !section_is_mapped (b->section))
1324 continue; /* unmapped overlay -- can't be a match */
1332 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), but it
1333 only returns true if there is actually a breakpoint inserted at PC. */
1336 breakpoint_inserted_here_p (pc)
1339 register struct breakpoint *b;
1343 && b->address == pc) /* bp is inserted and matches pc */
1345 if (overlay_debugging &&
1346 section_is_overlay (b->section) &&
1347 !section_is_mapped (b->section))
1348 continue; /* unmapped overlay -- can't be a match */
1356 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
1357 because figuring out the saved SP would take too much time, at least using
1358 get_saved_register on the 68k. This means that for this function to
1359 work right a port must use the bp_call_dummy breakpoint. */
1362 frame_in_dummy (frame)
1363 struct frame_info *frame;
1365 struct breakpoint *b;
1370 if (USE_GENERIC_DUMMY_FRAMES)
1371 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1375 if (b->type == bp_call_dummy
1376 && b->frame == frame->frame
1377 /* We need to check the PC as well as the frame on the sparc,
1378 for signals.exp in the testsuite. */
1381 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1382 && frame->pc <= b->address)
1388 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1389 is valid for process/thread PID. */
1392 breakpoint_thread_match (pc, pid)
1396 struct breakpoint *b;
1399 thread = pid_to_thread_id (pid);
1402 if (b->enable != disabled
1403 && b->enable != shlib_disabled
1404 && b->enable != call_disabled
1406 && (b->thread == -1 || b->thread == thread))
1408 if (overlay_debugging &&
1409 section_is_overlay (b->section) &&
1410 !section_is_mapped (b->section))
1411 continue; /* unmapped overlay -- can't be a match */
1420 /* bpstat stuff. External routines' interfaces are documented
1424 ep_is_catchpoint (ep)
1425 struct breakpoint * ep;
1428 (ep->type == bp_catch_load)
1429 || (ep->type == bp_catch_unload)
1430 || (ep->type == bp_catch_fork)
1431 || (ep->type == bp_catch_vfork)
1432 || (ep->type == bp_catch_exec)
1433 || (ep->type == bp_catch_catch)
1434 || (ep->type == bp_catch_throw)
1437 /* ??rehrauer: Add more kinds here, as are implemented... */
1442 ep_is_shlib_catchpoint (ep)
1443 struct breakpoint * ep;
1446 (ep->type == bp_catch_load)
1447 || (ep->type == bp_catch_unload)
1452 ep_is_exception_catchpoint (ep)
1453 struct breakpoint * ep;
1456 (ep->type == bp_catch_catch)
1457 || (ep->type == bp_catch_throw)
1461 /* Clear a bpstat so that it says we are not at any breakpoint.
1462 Also free any storage that is part of a bpstat. */
1477 if (p->old_val != NULL)
1478 value_free (p->old_val);
1485 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1486 is part of the bpstat is copied as well. */
1494 bpstat retval = NULL;
1499 for (; bs != NULL; bs = bs->next)
1501 tmp = (bpstat) xmalloc (sizeof (*tmp));
1502 memcpy (tmp, bs, sizeof (*tmp));
1504 /* This is the first thing in the chain. */
1514 /* Find the bpstat associated with this breakpoint */
1517 bpstat_find_breakpoint(bsp, breakpoint)
1519 struct breakpoint *breakpoint;
1521 if (bsp == NULL) return NULL;
1523 for (;bsp != NULL; bsp = bsp->next) {
1524 if (bsp->breakpoint_at == breakpoint) return bsp;
1529 /* Find a step_resume breakpoint associated with this bpstat.
1530 (If there are multiple step_resume bp's on the list, this function
1531 will arbitrarily pick one.)
1533 It is an error to use this function if BPSTAT doesn't contain a
1534 step_resume breakpoint.
1536 See wait_for_inferior's use of this function. */
1538 bpstat_find_step_resume_breakpoint (bsp)
1542 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1544 for (; bsp != NULL; bsp = bsp->next)
1546 if ((bsp->breakpoint_at != NULL) &&
1547 (bsp->breakpoint_at->type == bp_step_resume))
1548 return bsp->breakpoint_at;
1551 error ("Internal error (no step_resume breakpoint found)");
1555 /* Return the breakpoint number of the first breakpoint we are stopped
1556 at. *BSP upon return is a bpstat which points to the remaining
1557 breakpoints stopped at (but which is not guaranteed to be good for
1558 anything but further calls to bpstat_num).
1559 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1565 struct breakpoint *b;
1568 return 0; /* No more breakpoint values */
1571 b = (*bsp)->breakpoint_at;
1572 *bsp = (*bsp)->next;
1574 return -1; /* breakpoint that's been deleted since */
1576 return b->number; /* We have its number */
1580 /* Modify BS so that the actions will not be performed. */
1583 bpstat_clear_actions (bs)
1586 for (; bs != NULL; bs = bs->next)
1588 bs->commands = NULL;
1589 if (bs->old_val != NULL)
1591 value_free (bs->old_val);
1597 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1600 cleanup_executing_breakpoints (ignore)
1603 executing_breakpoint_commands = 0;
1606 /* Execute all the commands associated with all the breakpoints at this
1607 location. Any of these commands could cause the process to proceed
1608 beyond this point, etc. We look out for such changes by checking
1609 the global "breakpoint_proceeded" after each command. */
1612 bpstat_do_actions (bsp)
1616 struct cleanup *old_chain;
1617 struct command_line *cmd;
1619 /* Avoid endless recursion if a `source' command is contained
1621 if (executing_breakpoint_commands)
1624 executing_breakpoint_commands = 1;
1625 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1628 /* Note that (as of this writing), our callers all appear to
1629 be passing us the address of global stop_bpstat. And, if
1630 our calls to execute_control_command cause the inferior to
1631 proceed, that global (and hence, *bsp) will change.
1633 We must be careful to not touch *bsp unless the inferior
1634 has not proceeded. */
1636 /* This pointer will iterate over the list of bpstat's. */
1639 breakpoint_proceeded = 0;
1640 for (; bs != NULL; bs = bs->next)
1645 execute_control_command (cmd);
1647 if (breakpoint_proceeded)
1652 if (breakpoint_proceeded)
1653 /* The inferior is proceeded by the command; bomb out now.
1654 The bpstat chain has been blown away by wait_for_inferior.
1655 But since execution has stopped again, there is a new bpstat
1656 to look at, so start over. */
1659 bs->commands = NULL;
1662 executing_breakpoint_commands = 0;
1663 discard_cleanups (old_chain);
1666 /* This is the normal print_it function for a bpstat. In the future,
1667 much of this logic could (should?) be moved to bpstat_stop_status,
1668 by having it set different print_it functions.
1670 Current scheme: When we stop, bpstat_print() is called.
1671 It loops through the bpstat list of things causing this stop,
1672 calling the print_it function for each one. The default
1673 print_it function, used for breakpoints, is print_it_normal().
1674 (Also see print_it_noop() and print_it_done()).
1676 Return values from this routine (used by bpstat_print() to
1678 1: Means we printed something, and we do *not* desire that
1679 something to be followed by a location.
1680 0: Means we printed something, and we *do* desire that
1681 something to be followed by a location.
1682 -1: Means we printed nothing. */
1685 print_it_normal (bs)
1688 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1689 which has since been deleted. */
1690 if (bs->breakpoint_at == NULL
1691 || (bs->breakpoint_at->type != bp_breakpoint
1692 && bs->breakpoint_at->type != bp_catch_load
1693 && bs->breakpoint_at->type != bp_catch_unload
1694 && bs->breakpoint_at->type != bp_catch_fork
1695 && bs->breakpoint_at->type != bp_catch_vfork
1696 && bs->breakpoint_at->type != bp_catch_exec
1697 && bs->breakpoint_at->type != bp_catch_catch
1698 && bs->breakpoint_at->type != bp_catch_throw
1699 && bs->breakpoint_at->type != bp_hardware_breakpoint
1700 && bs->breakpoint_at->type != bp_watchpoint
1701 && bs->breakpoint_at->type != bp_read_watchpoint
1702 && bs->breakpoint_at->type != bp_access_watchpoint
1703 && bs->breakpoint_at->type != bp_hardware_watchpoint))
1706 if (ep_is_shlib_catchpoint (bs->breakpoint_at))
1708 annotate_catchpoint (bs->breakpoint_at->number);
1709 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1710 if (bs->breakpoint_at->type == bp_catch_load)
1711 printf_filtered ("loaded");
1712 else if (bs->breakpoint_at->type == bp_catch_unload)
1713 printf_filtered ("unloaded");
1714 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1717 else if (bs->breakpoint_at->type == bp_catch_fork ||
1718 bs->breakpoint_at->type == bp_catch_vfork)
1720 annotate_catchpoint (bs->breakpoint_at->number);
1721 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1722 if (bs->breakpoint_at->type == bp_catch_fork)
1723 printf_filtered ("forked");
1724 else if (bs->breakpoint_at->type == bp_catch_vfork)
1725 printf_filtered ("vforked");
1726 printf_filtered (" process %d), ", bs->breakpoint_at->forked_inferior_pid);
1729 else if (bs->breakpoint_at->type == bp_catch_exec)
1731 annotate_catchpoint (bs->breakpoint_at->number);
1732 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1733 bs->breakpoint_at->number,
1734 bs->breakpoint_at->exec_pathname);
1737 else if (bs->breakpoint_at->type == bp_catch_catch)
1739 if (current_exception_event && (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1741 annotate_catchpoint (bs->breakpoint_at->number);
1742 printf_filtered ("\nCatchpoint %d (exception caught), ", bs->breakpoint_at->number);
1743 printf_filtered ("throw location ");
1744 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1745 printf_filtered ("%s:%d",
1746 CURRENT_EXCEPTION_THROW_FILE,
1747 CURRENT_EXCEPTION_THROW_LINE);
1749 printf_filtered ("unknown");
1751 printf_filtered (", catch location ");
1752 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1753 printf_filtered ("%s:%d",
1754 CURRENT_EXCEPTION_CATCH_FILE,
1755 CURRENT_EXCEPTION_CATCH_LINE);
1757 printf_filtered ("unknown");
1759 printf_filtered ("\n");
1760 return 1; /* don't bother to print location frame info */
1764 return -1; /* really throw, some other bpstat will handle it */
1767 else if (bs->breakpoint_at->type == bp_catch_throw)
1769 if (current_exception_event && (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1771 annotate_catchpoint (bs->breakpoint_at->number);
1772 printf_filtered ("\nCatchpoint %d (exception thrown), ", bs->breakpoint_at->number);
1773 printf_filtered ("throw location ");
1774 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1775 printf_filtered ("%s:%d",
1776 CURRENT_EXCEPTION_THROW_FILE,
1777 CURRENT_EXCEPTION_THROW_LINE);
1779 printf_filtered ("unknown");
1781 printf_filtered (", catch location ");
1782 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1783 printf_filtered ("%s:%d",
1784 CURRENT_EXCEPTION_CATCH_FILE,
1785 CURRENT_EXCEPTION_CATCH_LINE);
1787 printf_filtered ("unknown");
1789 printf_filtered ("\n");
1790 return 1; /* don't bother to print location frame info */
1794 return -1; /* really catch, some other bpstat willhandle it */
1798 else if (bs->breakpoint_at->type == bp_breakpoint ||
1799 bs->breakpoint_at->type == bp_hardware_breakpoint)
1801 /* I think the user probably only wants to see one breakpoint
1802 number, not all of them. */
1803 annotate_breakpoint (bs->breakpoint_at->number);
1804 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1807 else if ((bs->old_val != NULL) &&
1808 (bs->breakpoint_at->type == bp_watchpoint ||
1809 bs->breakpoint_at->type == bp_access_watchpoint ||
1810 bs->breakpoint_at->type == bp_hardware_watchpoint))
1812 annotate_watchpoint (bs->breakpoint_at->number);
1813 mention (bs->breakpoint_at);
1814 printf_filtered ("\nOld value = ");
1815 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
1816 printf_filtered ("\nNew value = ");
1817 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1818 Val_pretty_default);
1819 printf_filtered ("\n");
1820 value_free (bs->old_val);
1822 /* More than one watchpoint may have been triggered. */
1825 else if (bs->breakpoint_at->type == bp_access_watchpoint ||
1826 bs->breakpoint_at->type == bp_read_watchpoint)
1828 mention (bs->breakpoint_at);
1829 printf_filtered ("\nValue = ");
1830 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1831 Val_pretty_default);
1832 printf_filtered ("\n");
1835 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1839 /* Print a message indicating what happened.
1840 This is called from normal_stop().
1841 The input to this routine is the head of the bpstat list - a list
1842 of the eventpoints that caused this stop.
1843 This routine calls the "print_it" routine(s) associated
1844 with these eventpoints. This will print (for example)
1845 the "Breakpoint n," part of the output.
1846 The return value of this routine is one of:
1848 -1: Means we printed nothing
1849 0: Means we printed something, and expect subsequent
1850 code to print the location. An example is
1851 "Breakpoint 1, " which should be followed by
1853 1 : Means we printed something, but there is no need
1854 to also print the location part of the message.
1855 An example is the catch/throw messages, which
1856 don't require a location appended to the end. */
1867 val = (*bs->print_it) (bs);
1871 /* Maybe another breakpoint in the chain caused us to stop.
1872 (Currently all watchpoints go on the bpstat whether hit or
1873 not. That probably could (should) be changed, provided care is taken
1874 with respect to bpstat_explains_signal). */
1876 return bpstat_print (bs->next);
1878 /* We reached the end of the chain without printing anything. */
1882 /* Evaluate the expression EXP and return 1 if value is zero.
1883 This is used inside a catch_errors to evaluate the breakpoint condition.
1884 The argument is a "struct expression *" that has been cast to char * to
1885 make it pass through catch_errors. */
1888 breakpoint_cond_eval (exp)
1891 value_ptr mark = value_mark ();
1892 int i = !value_true (evaluate_expression ((struct expression *)exp));
1893 value_free_to_mark (mark);
1897 /* Allocate a new bpstat and chain it to the current one. */
1900 bpstat_alloc (b, cbs)
1901 register struct breakpoint *b;
1902 bpstat cbs; /* Current "bs" value */
1906 bs = (bpstat) xmalloc (sizeof (*bs));
1908 bs->breakpoint_at = b;
1909 /* If the condition is false, etc., don't do the commands. */
1910 bs->commands = NULL;
1912 bs->print_it = print_it_normal;
1916 /* Possible return values for watchpoint_check (this can't be an enum
1917 because of check_errors). */
1918 /* The watchpoint has been deleted. */
1919 #define WP_DELETED 1
1920 /* The value has changed. */
1921 #define WP_VALUE_CHANGED 2
1922 /* The value has not changed. */
1923 #define WP_VALUE_NOT_CHANGED 3
1925 #define BP_TEMPFLAG 1
1926 #define BP_HARDWAREFLAG 2
1928 /* Check watchpoint condition. */
1931 watchpoint_check (p)
1934 bpstat bs = (bpstat) p;
1935 struct breakpoint *b;
1936 struct frame_info *fr;
1937 int within_current_scope;
1939 b = bs->breakpoint_at;
1941 if (b->exp_valid_block == NULL)
1942 within_current_scope = 1;
1945 /* There is no current frame at this moment. If we're going to have
1946 any chance of handling watchpoints on local variables, we'll need
1947 the frame chain (so we can determine if we're in scope). */
1948 reinit_frame_cache();
1949 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
1950 within_current_scope = (fr != NULL);
1951 if (within_current_scope)
1952 /* If we end up stopping, the current frame will get selected
1953 in normal_stop. So this call to select_frame won't affect
1955 select_frame (fr, -1);
1958 if (within_current_scope)
1960 /* We use value_{,free_to_}mark because it could be a
1961 *long* time before we return to the command level and
1962 call free_all_values. We can't call free_all_values because
1963 we might be in the middle of evaluating a function call. */
1965 value_ptr mark = value_mark ();
1966 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
1967 if (!value_equal (b->val, new_val))
1969 release_value (new_val);
1970 value_free_to_mark (mark);
1971 bs->old_val = b->val;
1973 /* We will stop here */
1974 return WP_VALUE_CHANGED;
1978 /* Nothing changed, don't do anything. */
1979 value_free_to_mark (mark);
1980 /* We won't stop here */
1981 return WP_VALUE_NOT_CHANGED;
1986 /* This seems like the only logical thing to do because
1987 if we temporarily ignored the watchpoint, then when
1988 we reenter the block in which it is valid it contains
1989 garbage (in the case of a function, it may have two
1990 garbage values, one before and one after the prologue).
1991 So we can't even detect the first assignment to it and
1992 watch after that (since the garbage may or may not equal
1993 the first value assigned). */
1995 Watchpoint %d deleted because the program has left the block in\n\
1996 which its expression is valid.\n", bs->breakpoint_at->number);
1997 if (b->related_breakpoint)
1998 b->related_breakpoint->disposition = del_at_next_stop;
1999 b->disposition = del_at_next_stop;
2005 /* This is used when everything which needs to be printed has
2006 already been printed. But we still want to print the frame. */
2008 /* Background: When we stop, bpstat_print() is called.
2009 It loops through the bpstat list of things causing this stop,
2010 calling the print_it function for each one. The default
2011 print_it function, used for breakpoints, is print_it_normal().
2012 Also see print_it_noop() and print_it_done() are the other
2013 two possibilities. See comments in bpstat_print() and
2014 in header of print_it_normal() for more detail. */
2023 /* This is used when nothing should be printed for this bpstat entry. */
2024 /* Background: When we stop, bpstat_print() is called.
2025 It loops through the bpstat list of things causing this stop,
2026 calling the print_it function for each one. The default
2027 print_it function, used for breakpoints, is print_it_normal().
2028 Also see print_it_noop() and print_it_done() are the other
2029 two possibilities. See comments in bpstat_print() and
2030 in header of print_it_normal() for more detail. */
2039 /* Get a bpstat associated with having just stopped at address *PC
2040 and frame address CORE_ADDRESS. Update *PC to point at the
2041 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2042 if this is known to not be a real breakpoint (it could still be a
2043 watchpoint, though). */
2045 /* Determine whether we stopped at a breakpoint, etc, or whether we
2046 don't understand this stop. Result is a chain of bpstat's such that:
2048 if we don't understand the stop, the result is a null pointer.
2050 if we understand why we stopped, the result is not null.
2052 Each element of the chain refers to a particular breakpoint or
2053 watchpoint at which we have stopped. (We may have stopped for
2054 several reasons concurrently.)
2056 Each element of the chain has valid next, breakpoint_at,
2057 commands, FIXME??? fields. */
2060 bpstat_stop_status (pc, not_a_breakpoint)
2062 int not_a_breakpoint;
2064 register struct breakpoint *b, *temp;
2066 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2067 int real_breakpoint = 0;
2068 /* Root of the chain of bpstat's */
2069 struct bpstats root_bs[1];
2070 /* Pointer to the last thing in the chain currently. */
2071 bpstat bs = root_bs;
2072 static char message1[] =
2073 "Error evaluating expression for watchpoint %d\n";
2074 char message[sizeof (message1) + 30 /* slop */];
2076 /* Get the address where the breakpoint would have been. */
2077 bp_addr = *pc - DECR_PC_AFTER_BREAK;
2079 ALL_BREAKPOINTS_SAFE (b, temp)
2081 if (b->enable == disabled
2082 || b->enable == shlib_disabled
2083 || b->enable == call_disabled)
2086 if (b->type != bp_watchpoint
2087 && b->type != bp_hardware_watchpoint
2088 && b->type != bp_read_watchpoint
2089 && b->type != bp_access_watchpoint
2090 && b->type != bp_hardware_breakpoint
2091 && b->type != bp_catch_fork
2092 && b->type != bp_catch_vfork
2093 && b->type != bp_catch_exec
2094 && b->type != bp_catch_catch
2095 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2096 if (b->address != bp_addr || /* address doesn't match or */
2097 (overlay_debugging && /* overlay doesn't match */
2098 section_is_overlay (b->section) &&
2099 !section_is_mapped (b->section)))
2102 if (b->type == bp_hardware_breakpoint
2103 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2106 if (b->type != bp_watchpoint
2107 && b->type != bp_hardware_watchpoint
2108 && b->type != bp_read_watchpoint
2109 && b->type != bp_access_watchpoint
2110 && not_a_breakpoint)
2113 /* Is this a catchpoint of a load or unload? If so, did we
2114 get a load or unload of the specified library? If not,
2116 if ((b->type == bp_catch_load)
2117 #if defined(SOLIB_HAVE_LOAD_EVENT)
2118 && (!SOLIB_HAVE_LOAD_EVENT(inferior_pid)
2119 || ((b->dll_pathname != NULL)
2120 && (strcmp (b->dll_pathname, SOLIB_LOADED_LIBRARY_PATHNAME(inferior_pid)) != 0)))
2125 if ((b->type == bp_catch_unload)
2126 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2127 && (!SOLIB_HAVE_UNLOAD_EVENT(inferior_pid)
2128 || ((b->dll_pathname != NULL)
2129 && (strcmp (b->dll_pathname, SOLIB_UNLOADED_LIBRARY_PATHNAME(inferior_pid)) != 0)))
2134 if ((b->type == bp_catch_fork)
2135 && ! target_has_forked (inferior_pid, &b->forked_inferior_pid))
2138 if ((b->type == bp_catch_vfork)
2139 && ! target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2142 if ((b->type == bp_catch_exec)
2143 && ! target_has_execd (inferior_pid, &b->exec_pathname))
2146 if (ep_is_exception_catchpoint (b) &&
2147 !(current_exception_event = target_get_current_exception_event ()))
2150 /* Come here if it's a watchpoint, or if the break address matches */
2152 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2154 /* Watchpoints may change this, if not found to have triggered. */
2158 sprintf (message, message1, b->number);
2159 if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
2161 switch (catch_errors (watchpoint_check, bs, message, RETURN_MASK_ALL))
2164 /* We've already printed what needs to be printed. */
2165 bs->print_it = print_it_done;
2168 case WP_VALUE_CHANGED:
2172 case WP_VALUE_NOT_CHANGED:
2174 bs->print_it = print_it_noop;
2176 /* Don't consider this a hit. */
2183 /* Error from catch_errors. */
2184 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2185 if (b->related_breakpoint)
2186 b->related_breakpoint->disposition = del_at_next_stop;
2187 b->disposition = del_at_next_stop;
2188 /* We've already printed what needs to be printed. */
2189 bs->print_it = print_it_done;
2195 else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint)
2201 addr = target_stopped_data_address();
2202 if (addr == 0) continue;
2203 for (v = b->val_chain; v; v = v->next)
2205 if (v->lval == lval_memory)
2209 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2215 switch (catch_errors (watchpoint_check, bs, message, RETURN_MASK_ALL))
2218 /* We've already printed what needs to be printed. */
2219 bs->print_it = print_it_done;
2222 case WP_VALUE_CHANGED:
2223 case WP_VALUE_NOT_CHANGED:
2230 /* Error from catch_errors. */
2231 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2232 if (b->related_breakpoint)
2233 b->related_breakpoint->disposition = del_at_next_stop;
2234 b->disposition = del_at_next_stop;
2235 /* We've already printed what needs to be printed. */
2236 bs->print_it = print_it_done;
2242 /* By definition, an encountered breakpoint is a triggered
2246 real_breakpoint = 1;
2249 if (b->frame && b->frame != (get_current_frame ())->frame &&
2250 (b->type == bp_step_resume &&
2251 (INNER_THAN (get_current_frame ()->frame, b->frame))))
2255 int value_is_zero = 0;
2259 /* Need to select the frame, with all that implies
2260 so that the conditions will have the right context. */
2261 select_frame (get_current_frame (), 0);
2263 = catch_errors (breakpoint_cond_eval, (b->cond),
2264 "Error in testing breakpoint condition:\n",
2266 /* FIXME-someday, should give breakpoint # */
2269 if (b->cond && value_is_zero)
2272 /* Don't consider this a hit. */
2275 else if (b->ignore_count > 0)
2282 /* We will stop here */
2283 if (b->disposition == disable)
2284 b->enable = disabled;
2285 bs->commands = b->commands;
2289 (STREQ ("silent", bs->commands->line) ||
2290 (xdb_commands && STREQ ("Q", bs->commands->line))))
2292 bs->commands = bs->commands->next;
2297 /* Print nothing for this entry if we dont stop or if we dont print. */
2298 if (bs->stop == 0 || bs->print == 0)
2299 bs->print_it = print_it_noop;
2302 bs->next = NULL; /* Terminate the chain */
2303 bs = root_bs->next; /* Re-grab the head of the chain */
2305 if (real_breakpoint && bs)
2307 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2309 if (DECR_PC_AFTER_HW_BREAK != 0)
2311 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2317 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2320 #if defined (SHIFT_INST_REGS)
2322 #else /* No SHIFT_INST_REGS. */
2324 #endif /* No SHIFT_INST_REGS. */
2329 /* The value of a hardware watchpoint hasn't changed, but the
2330 intermediate memory locations we are watching may have. */
2331 if (bs && ! bs->stop &&
2332 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2333 bs->breakpoint_at->type == bp_read_watchpoint ||
2334 bs->breakpoint_at->type == bp_access_watchpoint))
2336 remove_breakpoints ();
2337 insert_breakpoints ();
2342 /* Tell what to do about this bpstat. */
2347 /* Classify each bpstat as one of the following. */
2349 /* This bpstat element has no effect on the main_action. */
2352 /* There was a watchpoint, stop but don't print. */
2355 /* There was a watchpoint, stop and print. */
2358 /* There was a breakpoint but we're not stopping. */
2361 /* There was a breakpoint, stop but don't print. */
2364 /* There was a breakpoint, stop and print. */
2367 /* We hit the longjmp breakpoint. */
2370 /* We hit the longjmp_resume breakpoint. */
2373 /* We hit the step_resume breakpoint. */
2376 /* We hit the through_sigtramp breakpoint. */
2379 /* We hit the shared library event breakpoint. */
2382 /* We caught a shared library event. */
2385 /* This is just used to count how many enums there are. */
2389 /* Here is the table which drives this routine. So that we can
2390 format it pretty, we define some abbreviations for the
2391 enum bpstat_what codes. */
2392 #define kc BPSTAT_WHAT_KEEP_CHECKING
2393 #define ss BPSTAT_WHAT_STOP_SILENT
2394 #define sn BPSTAT_WHAT_STOP_NOISY
2395 #define sgl BPSTAT_WHAT_SINGLE
2396 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2397 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2398 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2399 #define sr BPSTAT_WHAT_STEP_RESUME
2400 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2401 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2402 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2404 /* "Can't happen." Might want to print an error message.
2405 abort() is not out of the question, but chances are GDB is just
2406 a bit confused, not unusable. */
2407 #define err BPSTAT_WHAT_STOP_NOISY
2409 /* Given an old action and a class, come up with a new action. */
2410 /* One interesting property of this table is that wp_silent is the same
2411 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2412 after stopping, the check for whether to step over a breakpoint
2413 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2414 reference to how we stopped. We retain separate wp_silent and bp_silent
2415 codes in case we want to change that someday. */
2417 /* step_resume entries: a step resume breakpoint overrides another
2418 breakpoint of signal handling (see comment in wait_for_inferior
2419 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2420 /* We handle the through_sigtramp_breakpoint the same way; having both
2421 one of those and a step_resume_breakpoint is probably very rare (?). */
2423 static const enum bpstat_what_main_action
2424 table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
2427 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2429 /*no_effect*/ {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2430 /*wp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2431 /*wp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2432 /*bp_nostop*/ {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2433 /*bp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2434 /*bp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2435 /*long_jump*/ {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2436 /*long_resume*/ {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2437 /*step_resume*/ {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2438 /*through_sig*/ {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2439 /*shlib*/ {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2440 /*catch_shlib*/ {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2455 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2456 struct bpstat_what retval;
2458 retval.call_dummy = 0;
2459 for (; bs != NULL; bs = bs->next)
2461 enum class bs_class = no_effect;
2462 if (bs->breakpoint_at == NULL)
2463 /* I suspect this can happen if it was a momentary breakpoint
2464 which has since been deleted. */
2466 switch (bs->breakpoint_at->type)
2472 case bp_hardware_breakpoint:
2478 bs_class = bp_noisy;
2480 bs_class = bp_silent;
2483 bs_class = bp_nostop;
2486 case bp_hardware_watchpoint:
2487 case bp_read_watchpoint:
2488 case bp_access_watchpoint:
2492 bs_class = wp_noisy;
2494 bs_class = wp_silent;
2497 /* There was a watchpoint, but we're not stopping. This requires
2498 no further action. */
2499 bs_class = no_effect;
2502 bs_class = long_jump;
2504 case bp_longjmp_resume:
2505 bs_class = long_resume;
2507 case bp_step_resume:
2510 bs_class = step_resume;
2513 /* It is for the wrong frame. */
2514 bs_class = bp_nostop;
2516 case bp_through_sigtramp:
2517 bs_class = through_sig;
2519 case bp_watchpoint_scope:
2520 bs_class = bp_nostop;
2522 case bp_shlib_event:
2523 bs_class = shlib_event;
2526 case bp_catch_unload:
2527 /* Only if this catchpoint triggered should we cause the
2528 step-out-of-dld behaviour. Otherwise, we ignore this
2531 bs_class = catch_shlib_event;
2533 bs_class = no_effect;
2536 case bp_catch_vfork:
2541 bs_class = bp_noisy;
2543 bs_class = bp_silent;
2546 /* There was a catchpoint, but we're not stopping. This requires
2547 no further action. */
2548 bs_class = no_effect;
2550 case bp_catch_catch:
2551 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2552 bs_class = bp_nostop;
2554 bs_class = bs->print ? bp_noisy : bp_silent;
2556 case bp_catch_throw:
2557 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2558 bs_class = bp_nostop;
2560 bs_class = bs->print ? bp_noisy : bp_silent;
2563 /* Make sure the action is stop (silent or noisy), so infrun.c
2564 pops the dummy frame. */
2565 bs_class = bp_silent;
2566 retval.call_dummy = 1;
2569 current_action = table[(int)bs_class][(int)current_action];
2571 retval.main_action = current_action;
2575 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2576 without hardware support). This isn't related to a specific bpstat,
2577 just to things like whether watchpoints are set. */
2580 bpstat_should_step ()
2582 struct breakpoint *b;
2584 if (b->enable == enabled && b->type == bp_watchpoint)
2589 /* Nonzero if there are enabled hardware watchpoints. */
2591 bpstat_have_active_hw_watchpoints ()
2593 struct breakpoint *b;
2595 if ((b->enable == enabled) &&
2597 ((b->type == bp_hardware_watchpoint) ||
2598 (b->type == bp_read_watchpoint) ||
2599 (b->type == bp_access_watchpoint)))
2605 /* Given a bpstat that records zero or more triggered eventpoints, this
2606 function returns another bpstat which contains only the catchpoints
2607 on that first list, if any. */
2609 bpstat_get_triggered_catchpoints (ep_list, cp_list)
2613 struct bpstats root_bs[1];
2614 bpstat bs = root_bs;
2615 struct breakpoint * ep;
2616 char * dll_pathname;
2618 bpstat_clear (cp_list);
2619 root_bs->next = NULL;
2621 for (; ep_list != NULL; ep_list = ep_list->next )
2623 /* Is this eventpoint a catchpoint? If not, ignore it. */
2624 ep = ep_list->breakpoint_at;
2627 if ((ep->type != bp_catch_load) &&
2628 (ep->type != bp_catch_unload) &&
2629 (ep->type != bp_catch_catch) &&
2630 (ep->type != bp_catch_throw)) /* pai: (temp) ADD fork/vfork here!! */
2633 /* Yes; add it to the list. */
2634 bs = bpstat_alloc (ep, bs);
2639 #if defined(SOLIB_ADD)
2640 /* Also, for each triggered catchpoint, tag it with the name of
2641 the library that caused this trigger. (We copy the name now,
2642 because it's only guaranteed to be available NOW, when the
2643 catchpoint triggers. Clients who may wish to know the name
2644 later must get it from the catchpoint itself.) */
2645 if (ep->triggered_dll_pathname != NULL)
2646 free (ep->triggered_dll_pathname);
2647 if (ep->type == bp_catch_load)
2648 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
2650 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
2652 dll_pathname = NULL;
2656 ep->triggered_dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
2657 strcpy (ep->triggered_dll_pathname, dll_pathname);
2660 ep->triggered_dll_pathname = NULL;
2666 /* Print information on breakpoint number BNUM, or -1 if all.
2667 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
2668 is nonzero, process only watchpoints. */
2673 } ep_type_description_t;
2676 breakpoint_1 (bnum, allflag)
2680 register struct breakpoint *b;
2681 register struct command_line *l;
2682 register struct symbol *sym;
2683 CORE_ADDR last_addr = (CORE_ADDR)-1;
2684 int found_a_breakpoint = 0;
2685 static ep_type_description_t bptypes[] =
2687 {bp_none, "?deleted?"},
2688 {bp_breakpoint, "breakpoint"},
2689 {bp_hardware_breakpoint, "hw breakpoint"},
2690 {bp_until, "until"},
2691 {bp_finish, "finish"},
2692 {bp_watchpoint, "watchpoint"},
2693 {bp_hardware_watchpoint, "hw watchpoint"},
2694 {bp_read_watchpoint, "read watchpoint"},
2695 {bp_access_watchpoint, "acc watchpoint"},
2696 {bp_longjmp, "longjmp"},
2697 {bp_longjmp_resume, "longjmp resume"},
2698 {bp_step_resume, "step resume"},
2699 {bp_through_sigtramp, "sigtramp"},
2700 {bp_watchpoint_scope, "watchpoint scope"},
2701 {bp_call_dummy, "call dummy"},
2702 {bp_shlib_event, "shlib events"},
2703 {bp_catch_load, "catch load"},
2704 {bp_catch_unload, "catch unload"},
2705 {bp_catch_fork, "catch fork"},
2706 {bp_catch_vfork, "catch vfork"},
2707 {bp_catch_exec, "catch exec"},
2708 {bp_catch_catch, "catch catch"},
2709 {bp_catch_throw, "catch throw"}
2712 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
2713 static char bpenables[] = "nyn";
2714 char wrap_indent[80];
2718 || bnum == b->number)
2720 /* We only print out user settable breakpoints unless the allflag is set. */
2722 && b->type != bp_breakpoint
2723 && b->type != bp_catch_load
2724 && b->type != bp_catch_unload
2725 && b->type != bp_catch_fork
2726 && b->type != bp_catch_vfork
2727 && b->type != bp_catch_exec
2728 && b->type != bp_catch_catch
2729 && b->type != bp_catch_throw
2730 && b->type != bp_hardware_breakpoint
2731 && b->type != bp_watchpoint
2732 && b->type != bp_read_watchpoint
2733 && b->type != bp_access_watchpoint
2734 && b->type != bp_hardware_watchpoint)
2737 if (!found_a_breakpoint++)
2739 annotate_breakpoints_headers ();
2742 printf_filtered ("Num ");
2744 printf_filtered ("Type ");
2746 printf_filtered ("Disp ");
2748 printf_filtered ("Enb ");
2752 printf_filtered ("Address ");
2755 printf_filtered ("What\n");
2757 annotate_breakpoints_table ();
2762 printf_filtered ("%-3d ", b->number);
2764 if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0])))
2765 error ("bptypes table does not describe type #%d.", (int)b->type);
2766 if ((int)b->type != bptypes[(int)b->type].type)
2767 error ("bptypes table does not describe type #%d?", (int)b->type);
2768 printf_filtered ("%-14s ", bptypes[(int)b->type].description);
2770 printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
2772 printf_filtered ("%-3c ", bpenables[(int)b->enable]);
2774 strcpy (wrap_indent, " ");
2776 strcat (wrap_indent, " ");
2780 case bp_hardware_watchpoint:
2781 case bp_read_watchpoint:
2782 case bp_access_watchpoint:
2783 /* Field 4, the address, is omitted (which makes the columns
2784 not line up too nicely with the headers, but the effect
2785 is relatively readable). */
2787 print_expression (b->exp, gdb_stdout);
2791 case bp_catch_unload:
2792 /* Field 4, the address, is omitted (which makes the columns
2793 not line up too nicely with the headers, but the effect
2794 is relatively readable). */
2796 if (b->dll_pathname == NULL)
2797 printf_filtered ("<any library> ");
2799 printf_filtered ("library \"%s\" ", b->dll_pathname);
2803 case bp_catch_vfork:
2804 /* Field 4, the address, is omitted (which makes the columns
2805 not line up too nicely with the headers, but the effect
2806 is relatively readable). */
2808 if (b->forked_inferior_pid != 0)
2809 printf_filtered ("process %d ", b->forked_inferior_pid);
2813 /* Field 4, the address, is omitted (which makes the columns
2814 not line up too nicely with the headers, but the effect
2815 is relatively readable). */
2817 if (b->exec_pathname != NULL)
2818 printf_filtered ("program \"%s\" ", b->exec_pathname);
2820 case bp_catch_catch:
2821 /* Field 4, the address, is omitted (which makes the columns
2822 not line up too nicely with the headers, but the effect
2823 is relatively readable). */
2825 printf_filtered ("exception catch ");
2827 case bp_catch_throw:
2828 /* Field 4, the address, is omitted (which makes the columns
2829 not line up too nicely with the headers, but the effect
2830 is relatively readable). */
2832 printf_filtered ("exception throw ");
2836 case bp_hardware_breakpoint:
2840 case bp_longjmp_resume:
2841 case bp_step_resume:
2842 case bp_through_sigtramp:
2843 case bp_watchpoint_scope:
2845 case bp_shlib_event:
2849 /* FIXME-32x64: need a print_address_numeric with
2853 local_hex_string_custom
2854 ((unsigned long) b->address, "08l"));
2859 last_addr = b->address;
2862 sym = find_pc_sect_function (b->address, b->section);
2865 fputs_filtered ("in ", gdb_stdout);
2866 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
2867 wrap_here (wrap_indent);
2868 fputs_filtered (" at ", gdb_stdout);
2870 fputs_filtered (b->source_file, gdb_stdout);
2871 printf_filtered (":%d", b->line_number);
2874 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
2878 if (b->thread != -1)
2879 printf_filtered (" thread %d", b->thread );
2881 printf_filtered ("\n");
2887 printf_filtered ("\tstop only in stack frame at ");
2888 print_address_numeric (b->frame, 1, gdb_stdout);
2889 printf_filtered ("\n");
2896 printf_filtered ("\tstop only if ");
2897 print_expression (b->cond, gdb_stdout);
2898 printf_filtered ("\n");
2901 if (b->thread != -1)
2903 /* FIXME should make an annotation for this */
2904 printf_filtered ("\tstop only in thread %d\n", b->thread);
2907 if (show_breakpoint_hit_counts && b->hit_count)
2909 /* FIXME should make an annotation for this */
2910 if (ep_is_catchpoint (b))
2911 printf_filtered ("\tcatchpoint");
2913 printf_filtered ("\tbreakpoint");
2914 printf_filtered (" already hit %d time%s\n",
2915 b->hit_count, (b->hit_count == 1 ? "" : "s"));
2918 if (b->ignore_count)
2922 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
2925 if ((l = b->commands))
2931 print_command_line (l, 4, gdb_stdout);
2937 if (!found_a_breakpoint)
2940 printf_filtered ("No breakpoints or watchpoints.\n");
2942 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
2945 /* Compare against (CORE_ADDR)-1 in case some compiler decides
2946 that a comparison of an unsigned with -1 is always false. */
2947 if (last_addr != (CORE_ADDR)-1)
2948 set_next_address (last_addr);
2950 annotate_breakpoints_table_end ();
2955 breakpoints_info (bnum_exp, from_tty)
2962 bnum = parse_and_eval_address (bnum_exp);
2964 breakpoint_1 (bnum, 0);
2969 maintenance_info_breakpoints (bnum_exp, from_tty)
2976 bnum = parse_and_eval_address (bnum_exp);
2978 breakpoint_1 (bnum, 1);
2981 /* Print a message describing any breakpoints set at PC. */
2984 describe_other_breakpoints (pc, section)
2988 register int others = 0;
2989 register struct breakpoint *b;
2992 if (b->address == pc)
2993 if (overlay_debugging == 0 ||
2994 b->section == section)
2998 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3000 if (b->address == pc)
3001 if (overlay_debugging == 0 ||
3002 b->section == section)
3008 ((b->enable == disabled || b->enable == shlib_disabled || b->enable == call_disabled)
3009 ? " (disabled)" : ""),
3010 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3012 printf_filtered ("also set at pc ");
3013 print_address_numeric (pc, 1, gdb_stdout);
3014 printf_filtered (".\n");
3018 /* Set the default place to put a breakpoint
3019 for the `break' command with no arguments. */
3022 set_default_breakpoint (valid, addr, symtab, line)
3025 struct symtab *symtab;
3028 default_breakpoint_valid = valid;
3029 default_breakpoint_address = addr;
3030 default_breakpoint_symtab = symtab;
3031 default_breakpoint_line = line;
3034 /* Rescan breakpoints at address ADDRESS,
3035 marking the first one as "first" and any others as "duplicates".
3036 This is so that the bpt instruction is only inserted once. */
3039 check_duplicates (address, section)
3043 register struct breakpoint *b;
3044 register int count = 0;
3046 if (address == 0) /* Watchpoints are uninteresting */
3050 if (b->enable != disabled
3051 && b->enable != shlib_disabled
3052 && b->enable != call_disabled
3053 && b->address == address
3054 && (overlay_debugging == 0 || b->section == section))
3057 b->duplicate = count > 1;
3061 /* Low level routine to set a breakpoint.
3062 Takes as args the three things that every breakpoint must have.
3063 Returns the breakpoint object so caller can set other things.
3064 Does not set the breakpoint number!
3065 Does not print anything.
3067 ==> This routine should not be called if there is a chance of later
3068 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3069 your arguments BEFORE calling this routine! */
3072 set_raw_breakpoint (sal)
3073 struct symtab_and_line sal;
3075 register struct breakpoint *b, *b1;
3077 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3078 memset (b, 0, sizeof (*b));
3079 b->address = sal.pc;
3080 if (sal.symtab == NULL)
3081 b->source_file = NULL;
3083 b->source_file = savestring (sal.symtab->filename,
3084 strlen (sal.symtab->filename));
3085 b->section = sal.section;
3086 b->language = current_language->la_language;
3087 b->input_radix = input_radix;
3089 b->line_number = sal.line;
3090 b->enable = enabled;
3093 b->ignore_count = 0;
3096 b->dll_pathname = NULL;
3097 b->triggered_dll_pathname = NULL;
3098 b->forked_inferior_pid = 0;
3099 b->exec_pathname = NULL;
3101 /* Add this breakpoint to the end of the chain
3102 so that a list of breakpoints will come out in order
3103 of increasing numbers. */
3105 b1 = breakpoint_chain;
3107 breakpoint_chain = b;
3115 check_duplicates (sal.pc, sal.section);
3116 breakpoints_changed ();
3121 #ifdef GET_LONGJMP_TARGET
3124 create_longjmp_breakpoint (func_name)
3127 struct symtab_and_line sal;
3128 struct breakpoint *b;
3130 INIT_SAL (&sal); /* initialize to zeroes */
3131 if (func_name != NULL)
3133 struct minimal_symbol *m;
3135 m = lookup_minimal_symbol_text (func_name, NULL, (struct objfile *)NULL);
3137 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3141 sal.section = find_pc_overlay (sal.pc);
3142 b = set_raw_breakpoint (sal);
3145 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3146 b->disposition = donttouch;
3147 b->enable = disabled;
3150 b->addr_string = strsave(func_name);
3151 b->number = internal_breakpoint_number--;
3154 #endif /* #ifdef GET_LONGJMP_TARGET */
3156 /* Call this routine when stepping and nexting to enable a breakpoint if we do
3157 a longjmp(). When we hit that breakpoint, call
3158 set_longjmp_resume_breakpoint() to figure out where we are going. */
3161 enable_longjmp_breakpoint()
3163 register struct breakpoint *b;
3166 if (b->type == bp_longjmp)
3168 b->enable = enabled;
3169 check_duplicates (b->address, b->section);
3174 disable_longjmp_breakpoint()
3176 register struct breakpoint *b;
3179 if ( b->type == bp_longjmp
3180 || b->type == bp_longjmp_resume)
3182 b->enable = disabled;
3183 check_duplicates (b->address, b->section);
3189 remove_solib_event_breakpoints ()
3191 register struct breakpoint *b, *temp;
3193 ALL_BREAKPOINTS_SAFE (b, temp)
3194 if (b->type == bp_shlib_event)
3195 delete_breakpoint (b);
3199 create_solib_event_breakpoint (address)
3202 struct breakpoint *b;
3203 struct symtab_and_line sal;
3205 INIT_SAL (&sal); /* initialize to zeroes */
3207 sal.section = find_pc_overlay (sal.pc);
3208 b = set_raw_breakpoint (sal);
3209 b->number = internal_breakpoint_number--;
3210 b->disposition = donttouch;
3211 b->type = bp_shlib_event;
3215 disable_breakpoints_in_shlibs (silent)
3218 struct breakpoint * b;
3219 int disabled_shlib_breaks = 0;
3221 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3224 #if defined (PC_SOLIB)
3225 if (((b->type == bp_breakpoint) ||
3226 (b->type == bp_hardware_breakpoint)) &&
3227 (b->enable != shlib_disabled) &&
3228 (b->enable != call_disabled) &&
3230 PC_SOLIB (b->address))
3232 b->enable = shlib_disabled;
3235 if (!disabled_shlib_breaks)
3237 target_terminal_ours_for_output ();
3238 printf_filtered ("Temporarily disabling shared library breakpoints:\n");
3240 disabled_shlib_breaks = 1;
3241 printf_filtered ("%d ", b->number);
3246 if (disabled_shlib_breaks && !silent)
3247 printf_filtered ("\n");
3250 /* Try to reenable any breakpoints in shared libraries. */
3252 re_enable_breakpoints_in_shlibs ()
3254 struct breakpoint *b;
3257 if (b->enable == shlib_disabled)
3261 /* Do not reenable the breakpoint if the shared library
3262 is still not mapped in. */
3263 if (target_read_memory (b->address, buf, 1) == 0)
3264 b->enable = enabled;
3271 create_solib_load_unload_event_breakpoint (hookname, tempflag, dll_pathname, cond_string, bp_kind)
3276 enum bptype bp_kind;
3278 struct breakpoint * b;
3279 struct symtabs_and_lines sals;
3280 struct symtab_and_line sal;
3281 struct cleanup * old_chain;
3282 struct cleanup * canonical_strings_chain = NULL;
3284 char * addr_start = hookname;
3285 char * addr_end = NULL;
3286 char ** canonical = (char **) NULL;
3287 int thread = -1; /* All threads. */
3289 /* Set a breakpoint on the specified hook. */
3290 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3291 addr_end = hookname;
3293 if (sals.nelts == 0)
3295 warning ("Unable to set a breakpoint on dynamic linker callback.");
3296 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3297 warning ("GDB will be unable to track shl_load/shl_unload calls");
3300 if (sals.nelts != 1)
3302 warning ("Unable to set a unique breakpoint on dynamic linker callback.");
3303 warning ("GDB will be unable to track shl_load/shl_unload calls");
3307 /* Make sure that all storage allocated in decode_line_1 gets freed in case
3308 the following errors out. */
3309 old_chain = make_cleanup (free, sals.sals);
3310 if (canonical != (char **)NULL)
3312 make_cleanup (free, canonical);
3313 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3314 if (canonical[0] != NULL)
3315 make_cleanup (free, canonical[0]);
3318 resolve_sal_pc (&sals.sals[0]);
3320 /* Remove the canonical strings from the cleanup, they are needed below. */
3321 if (canonical != (char **)NULL)
3322 discard_cleanups (canonical_strings_chain);
3324 b = set_raw_breakpoint (sals.sals[0]);
3325 set_breakpoint_count (breakpoint_count + 1);
3326 b->number = breakpoint_count;
3328 b->cond_string = (cond_string == NULL) ? NULL : savestring (cond_string, strlen (cond_string));
3331 if (canonical != (char **)NULL && canonical[0] != NULL)
3332 b->addr_string = canonical[0];
3333 else if (addr_start)
3334 b->addr_string = savestring (addr_start, addr_end - addr_start);
3336 b->enable = enabled;
3337 b->disposition = tempflag ? del : donttouch;
3339 if (dll_pathname == NULL)
3340 b->dll_pathname = NULL;
3343 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3344 strcpy (b->dll_pathname, dll_pathname);
3349 do_cleanups (old_chain);
3353 create_solib_load_event_breakpoint (hookname, tempflag, dll_pathname, cond_string)
3356 char * dll_pathname;
3359 create_solib_load_unload_event_breakpoint (hookname,
3367 create_solib_unload_event_breakpoint (hookname, tempflag, dll_pathname, cond_string)
3370 char * dll_pathname;
3373 create_solib_load_unload_event_breakpoint (hookname,
3381 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3384 enum bptype bp_kind;
3386 struct symtab_and_line sal;
3387 struct breakpoint * b;
3388 int thread = -1; /* All threads. */
3395 b = set_raw_breakpoint (sal);
3396 set_breakpoint_count (breakpoint_count + 1);
3397 b->number = breakpoint_count;
3399 b->cond_string = (cond_string == NULL) ? NULL : savestring (cond_string, strlen (cond_string));
3401 b->addr_string = NULL;
3402 b->enable = enabled;
3403 b->disposition = tempflag ? del : donttouch;
3404 b->forked_inferior_pid = 0;
3412 create_fork_event_catchpoint (tempflag, cond_string)
3416 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3420 create_vfork_event_catchpoint (tempflag, cond_string)
3424 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3428 create_exec_event_catchpoint (tempflag, cond_string)
3432 struct symtab_and_line sal;
3433 struct breakpoint * b;
3434 int thread = -1; /* All threads. */
3441 b = set_raw_breakpoint (sal);
3442 set_breakpoint_count (breakpoint_count + 1);
3443 b->number = breakpoint_count;
3445 b->cond_string = (cond_string == NULL) ? NULL : savestring (cond_string, strlen (cond_string));
3447 b->addr_string = NULL;
3448 b->enable = enabled;
3449 b->disposition = tempflag ? del : donttouch;
3451 b->type = bp_catch_exec;
3457 hw_breakpoint_used_count()
3459 register struct breakpoint *b;
3464 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3472 hw_watchpoint_used_count(type, other_type_used)
3474 int *other_type_used;
3476 register struct breakpoint *b;
3479 *other_type_used = 0;
3482 if (b->enable == enabled)
3484 if (b->type == type) i++;
3485 else if ((b->type == bp_hardware_watchpoint ||
3486 b->type == bp_read_watchpoint ||
3487 b->type == bp_access_watchpoint)
3488 && b->enable == enabled)
3489 *other_type_used = 1;
3495 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
3496 breakpoint at the target of the jmp_buf.
3498 FIXME - This ought to be done by setting a temporary breakpoint that gets
3499 deleted automatically... */
3502 set_longjmp_resume_breakpoint(pc, frame)
3504 struct frame_info *frame;
3506 register struct breakpoint *b;
3509 if (b->type == bp_longjmp_resume)
3512 b->enable = enabled;
3514 b->frame = frame->frame;
3517 check_duplicates (b->address, b->section);
3523 disable_watchpoints_before_interactive_call_start ()
3525 struct breakpoint * b;
3529 if (((b->type == bp_watchpoint)
3530 || (b->type == bp_hardware_watchpoint)
3531 || (b->type == bp_read_watchpoint)
3532 || (b->type == bp_access_watchpoint)
3533 || ep_is_exception_catchpoint (b))
3534 && (b->enable == enabled))
3536 b->enable = call_disabled;
3537 check_duplicates (b->address, b->section);
3543 enable_watchpoints_after_interactive_call_stop ()
3545 struct breakpoint * b;
3549 if (((b->type == bp_watchpoint)
3550 || (b->type == bp_hardware_watchpoint)
3551 || (b->type == bp_read_watchpoint)
3552 || (b->type == bp_access_watchpoint)
3553 || ep_is_exception_catchpoint (b))
3554 && (b->enable == call_disabled))
3556 b->enable = enabled;
3557 check_duplicates (b->address, b->section);
3563 /* Set a breakpoint that will evaporate an end of command
3564 at address specified by SAL.
3565 Restrict it to frame FRAME if FRAME is nonzero. */
3568 set_momentary_breakpoint (sal, frame, type)
3569 struct symtab_and_line sal;
3570 struct frame_info *frame;
3573 register struct breakpoint *b;
3574 b = set_raw_breakpoint (sal);
3576 b->enable = enabled;
3577 b->disposition = donttouch;
3578 b->frame = (frame ? frame->frame : 0);
3580 /* If we're debugging a multi-threaded program, then we
3581 want momentary breakpoints to be active in only a
3582 single thread of control. */
3583 if (in_thread_list (inferior_pid))
3584 b->thread = pid_to_thread_id (inferior_pid);
3590 /* Tell the user we have just set a breakpoint B. */
3594 struct breakpoint *b;
3598 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3599 watchpoint) other than breakpoint creation. It should be possible to
3600 clean this up and at the same time replace the random calls to
3601 breakpoint_changed with this hook, as has already been done for
3602 delete_breakpoint_hook and so on. */
3603 if (create_breakpoint_hook)
3604 create_breakpoint_hook (b);
3609 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3612 printf_filtered ("Watchpoint %d: ", b->number);
3613 print_expression (b->exp, gdb_stdout);
3615 case bp_hardware_watchpoint:
3616 printf_filtered ("Hardware watchpoint %d: ", b->number);
3617 print_expression (b->exp, gdb_stdout);
3619 case bp_read_watchpoint:
3620 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3621 print_expression (b->exp, gdb_stdout);
3623 case bp_access_watchpoint:
3624 printf_filtered ("Hardware access (read/write) watchpoint %d: ",b->number);
3625 print_expression (b->exp, gdb_stdout);
3628 printf_filtered ("Breakpoint %d", b->number);
3631 case bp_hardware_breakpoint:
3632 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3636 case bp_catch_unload:
3637 printf_filtered ("Catchpoint %d (%s %s)",
3639 (b->type == bp_catch_load) ? "load" : "unload",
3640 (b->dll_pathname != NULL) ? b->dll_pathname : "<any library>");
3643 case bp_catch_vfork:
3644 printf_filtered ("Catchpoint %d (%s)",
3646 (b->type == bp_catch_fork) ? "fork" : "vfork");
3649 printf_filtered ("Catchpoint %d (exec)",
3652 case bp_catch_catch:
3653 case bp_catch_throw:
3654 printf_filtered ("Catchpoint %d (%s)",
3656 (b->type == bp_catch_catch) ? "catch" : "throw");
3662 case bp_longjmp_resume:
3663 case bp_step_resume:
3664 case bp_through_sigtramp:
3666 case bp_watchpoint_scope:
3667 case bp_shlib_event:
3672 if (addressprint || b->source_file == NULL)
3674 printf_filtered (" at ");
3675 print_address_numeric (b->address, 1, gdb_stdout);
3678 printf_filtered (": file %s, line %d.",
3679 b->source_file, b->line_number);
3680 TUIDO(((TuiOpaqueFuncPtr)tui_vAllSetHasBreakAt, b, 1));
3681 TUIDO(((TuiOpaqueFuncPtr)tuiUpdateAllExecInfos));
3683 printf_filtered ("\n");
3687 /* Set a breakpoint according to ARG (function, linenum or *address)
3688 flag: first bit : 0 non-temporary, 1 temporary.
3689 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
3692 break_command_1 (arg, flag, from_tty)
3696 int tempflag, hardwareflag;
3697 struct symtabs_and_lines sals;
3698 struct symtab_and_line sal;
3699 register struct expression *cond = 0;
3700 register struct breakpoint *b;
3702 /* Pointers in arg to the start, and one past the end, of the condition. */
3703 char *cond_start = NULL;
3704 char *cond_end = NULL;
3705 /* Pointers in arg to the start, and one past the end,
3706 of the address part. */
3707 char *addr_start = NULL;
3708 char *addr_end = NULL;
3709 struct cleanup *old_chain;
3710 struct cleanup *canonical_strings_chain = NULL;
3711 char **canonical = (char **)NULL;
3715 hardwareflag = flag & BP_HARDWAREFLAG;
3716 tempflag = flag & BP_TEMPFLAG;
3721 INIT_SAL (&sal); /* initialize to zeroes */
3723 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3725 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
3726 && (arg[2] == ' ' || arg[2] == '\t')))
3728 if (default_breakpoint_valid)
3730 sals.sals = (struct symtab_and_line *)
3731 xmalloc (sizeof (struct symtab_and_line));
3732 sal.pc = default_breakpoint_address;
3733 sal.line = default_breakpoint_line;
3734 sal.symtab = default_breakpoint_symtab;
3735 sal.section = find_pc_overlay (sal.pc);
3740 error ("No default breakpoint address now.");
3746 /* Force almost all breakpoints to be in terms of the
3747 current_source_symtab (which is decode_line_1's default). This
3748 should produce the results we want almost all of the time while
3749 leaving default_breakpoint_* alone. */
3750 if (default_breakpoint_valid
3751 && (!current_source_symtab
3752 || (arg && (*arg == '+' || *arg == '-'))))
3753 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3754 default_breakpoint_line, &canonical);
3756 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
3764 /* Make sure that all storage allocated in decode_line_1 gets freed in case
3765 the following `for' loop errors out. */
3766 old_chain = make_cleanup (free, sals.sals);
3767 if (canonical != (char **)NULL)
3769 make_cleanup (free, canonical);
3770 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3771 for (i = 0; i < sals.nelts; i++)
3773 if (canonical[i] != NULL)
3774 make_cleanup (free, canonical[i]);
3778 thread = -1; /* No specific thread yet */
3780 /* Resolve all line numbers to PC's, and verify that conditions
3781 can be parsed, before setting any breakpoints. */
3782 for (i = 0; i < sals.nelts; i++)
3784 char *tok, *end_tok;
3787 resolve_sal_pc (&sals.sals[i]);
3789 /* It's possible for the PC to be nonzero, but still an illegal
3790 value on some targets.
3792 For example, on HP-UX if you start gdb, and before running the
3793 inferior you try to set a breakpoint on a shared library function
3794 "foo" where the inferior doesn't call "foo" directly but does
3795 pass its address to another function call, then we do find a
3796 minimal symbol for the "foo", but it's address is invalid.
3797 (Appears to be an index into a table that the loader sets up
3798 when the inferior is run.)
3800 Give the target a chance to bless sals.sals[i].pc before we
3801 try to make a breakpoint for it. */
3802 if (PC_REQUIRES_RUN_BEFORE_USE(sals.sals[i].pc))
3804 error ("Cannot break on %s without a running program.", addr_start);
3811 while (*tok == ' ' || *tok == '\t')
3816 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3819 toklen = end_tok - tok;
3821 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3823 tok = cond_start = end_tok + 1;
3824 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3827 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3833 thread = strtol (tok, &tok, 0);
3835 error ("Junk after thread keyword.");
3836 if (!valid_thread_id (thread))
3837 error ("Unknown thread %d\n", thread);
3840 error ("Junk at end of arguments.");
3845 int i, target_resources_ok;
3847 i = hw_breakpoint_used_count ();
3848 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
3849 bp_hardware_breakpoint, i + sals.nelts, 0);
3850 if (target_resources_ok == 0)
3851 error ("No hardware breakpoint support in the target.");
3852 else if (target_resources_ok < 0)
3853 error ("Hardware breakpoints used exceeds limit.");
3856 /* Remove the canonical strings from the cleanup, they are needed below. */
3857 if (canonical != (char **)NULL)
3858 discard_cleanups (canonical_strings_chain);
3860 /* Now set all the breakpoints. */
3861 for (i = 0; i < sals.nelts; i++)
3866 describe_other_breakpoints (sal.pc, sal.section);
3868 b = set_raw_breakpoint (sal);
3869 set_breakpoint_count (breakpoint_count + 1);
3870 b->number = breakpoint_count;
3871 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
3875 /* If a canonical line spec is needed use that instead of the
3877 if (canonical != (char **)NULL && canonical[i] != NULL)
3878 b->addr_string = canonical[i];
3879 else if (addr_start)
3880 b->addr_string = savestring (addr_start, addr_end - addr_start);
3882 b->cond_string = savestring (cond_start, cond_end - cond_start);
3884 b->enable = enabled;
3885 b->disposition = tempflag ? del : donttouch;
3891 printf_filtered ("Multiple breakpoints were set.\n");
3892 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3894 do_cleanups (old_chain);
3898 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
3903 struct frame_info *frame;
3904 CORE_ADDR low, high, selected_pc = 0;
3905 char *extra_args, *level_arg, *addr_string;
3906 int extra_args_len = 0, if_arg = 0;
3909 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
3912 if (default_breakpoint_valid)
3916 selected_pc = selected_frame->pc;
3921 error ("No selected frame.");
3924 error ("No default breakpoint address now.");
3928 extra_args = strchr (arg, ' ');
3932 extra_args_len = strlen (extra_args);
3933 level_arg = (char *) xmalloc (extra_args - arg);
3934 strncpy (level_arg, arg, extra_args - arg - 1);
3935 level_arg[extra_args - arg - 1] = '\0';
3939 level_arg = (char *) xmalloc (strlen (arg) + 1);
3940 strcpy (level_arg, arg);
3943 frame = parse_frame_specification (level_arg);
3945 selected_pc = frame->pc;
3952 extra_args_len = strlen (arg);
3957 if (find_pc_partial_function(selected_pc, (char **)NULL, &low, &high))
3959 addr_string = (char *) xmalloc (26 + extra_args_len);
3961 sprintf (addr_string, "*0x%x %s", high, extra_args);
3963 sprintf (addr_string, "*0x%x", high);
3964 break_command_1 (addr_string, flag, from_tty);
3968 error ("No function contains the specified address");
3971 error ("Unable to set breakpoint at procedure exit");
3976 break_at_finish_command_1 (arg, flag, from_tty)
3981 char *addr_string, *break_string, *beg_addr_string;
3982 CORE_ADDR low, high;
3983 struct symtabs_and_lines sals;
3984 struct symtab_and_line sal;
3985 struct cleanup *old_chain;
3987 int extra_args_len = 0;
3991 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
3993 if (default_breakpoint_valid)
3997 addr_string = (char *) xmalloc (15);
3998 sprintf (addr_string, "*0x%x", selected_frame->pc);
4003 error ("No selected frame.");
4006 error ("No default breakpoint address now.");
4010 addr_string = (char *) xmalloc (strlen (arg) + 1);
4011 strcpy (addr_string, arg);
4017 extra_args_len = strlen (arg);
4022 /* get the stuff after the function name or address */
4023 extra_args = strchr (arg, ' ');
4027 extra_args_len = strlen (extra_args);
4034 beg_addr_string = addr_string;
4035 sals = decode_line_1 (&addr_string, 1, (struct symtab *)NULL, 0,
4038 free (beg_addr_string);
4039 old_chain = make_cleanup (free, sals.sals);
4040 for (i = 0; (i < sals.nelts); i++)
4043 if (find_pc_partial_function (sal.pc, (char **)NULL, &low, &high))
4045 break_string = (char *) xmalloc (extra_args_len + 26);
4047 sprintf (break_string, "*0x%x %s", high, extra_args);
4049 sprintf (break_string, "*0x%x", high);
4050 break_command_1 (break_string, flag, from_tty);
4054 error ("No function contains the specified address");
4058 printf_filtered ("Multiple breakpoints were set.\n");
4059 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
4061 do_cleanups(old_chain);
4065 /* Helper function for break_command_1 and disassemble_command. */
4068 resolve_sal_pc (sal)
4069 struct symtab_and_line *sal;
4073 if (sal->pc == 0 && sal->symtab != NULL)
4075 if (!find_line_pc (sal->symtab, sal->line, &pc))
4076 error ("No line %d in file \"%s\".",
4077 sal->line, sal->symtab->filename);
4081 if (sal->section == 0 && sal->symtab != NULL)
4083 struct blockvector *bv;
4088 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4091 b = BLOCKVECTOR_BLOCK (bv, index);
4092 sym = block_function (b);
4095 fixup_symbol_section (sym, sal->symtab->objfile);
4096 sal->section = SYMBOL_BFD_SECTION (sym);
4100 /* It really is worthwhile to have the section, so we'll just
4101 have to look harder. This case can be executed if we have
4102 line numbers but no functions (as can happen in assembly
4105 struct minimal_symbol *msym;
4107 msym = lookup_minimal_symbol_by_pc (sal->pc);
4109 sal->section = SYMBOL_BFD_SECTION (msym);
4116 break_command (arg, from_tty)
4120 break_command_1 (arg, 0, from_tty);
4124 break_at_finish_command (arg, from_tty)
4128 break_at_finish_command_1 (arg, 0, from_tty);
4132 break_at_finish_at_depth_command (arg, from_tty)
4136 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4140 tbreak_command (arg, from_tty)
4144 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4148 tbreak_at_finish_command (arg, from_tty)
4152 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4156 hbreak_command (arg, from_tty)
4160 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4164 thbreak_command (arg, from_tty)
4168 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4172 stop_command (arg, from_tty)
4176 printf_filtered ("Specify the type of breakpoint to set.\n\
4177 Usage: stop in <function | address>\n\
4182 stopin_command (arg, from_tty)
4188 if (arg == (char *)NULL)
4190 else if (*arg != '*')
4195 /* look for a ':'. If this is a line number specification, then say
4196 it is bad, otherwise, it should be an address or function/method
4198 while (*argptr && !hasColon)
4200 hasColon = (*argptr == ':');
4205 badInput = (*argptr != ':'); /* Not a class::method */
4207 badInput = isdigit(*arg); /* a simple line number */
4211 printf_filtered("Usage: stop in <function | address>\n");
4213 break_command_1 (arg, 0, from_tty);
4217 stopat_command (arg, from_tty)
4223 if (arg == (char *)NULL || *arg == '*') /* no line number */
4230 /* look for a ':'. If there is a '::' then get out, otherwise
4231 it is probably a line number. */
4232 while (*argptr && !hasColon)
4234 hasColon = (*argptr == ':');
4239 badInput = (*argptr == ':'); /* we have class::method */
4241 badInput = !isdigit(*arg); /* not a line number */
4245 printf_filtered("Usage: stop at <line>\n");
4247 break_command_1 (arg, 0, from_tty);
4251 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write) */
4253 watch_command_1 (arg, accessflag, from_tty)
4258 struct breakpoint *b;
4259 struct symtab_and_line sal;
4260 struct expression *exp;
4261 struct block *exp_valid_block;
4262 struct value *val, *mark;
4263 struct frame_info *frame;
4264 struct frame_info *prev_frame = NULL;
4265 char *exp_start = NULL;
4266 char *exp_end = NULL;
4267 char *tok, *end_tok;
4269 char *cond_start = NULL;
4270 char *cond_end = NULL;
4271 struct expression *cond = NULL;
4272 int i, other_type_used, target_resources_ok = 0;
4273 enum bptype bp_type;
4276 INIT_SAL (&sal); /* initialize to zeroes */
4278 /* Parse arguments. */
4279 innermost_block = NULL;
4281 exp = parse_exp_1 (&arg, 0, 0);
4283 exp_valid_block = innermost_block;
4284 mark = value_mark ();
4285 val = evaluate_expression (exp);
4286 release_value (val);
4287 if (VALUE_LAZY (val))
4288 value_fetch_lazy (val);
4291 while (*tok == ' ' || *tok == '\t')
4295 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4298 toklen = end_tok - tok;
4299 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4301 tok = cond_start = end_tok + 1;
4302 cond = parse_exp_1 (&tok, 0, 0);
4306 error("Junk at end of command.");
4308 if (accessflag == 1) bp_type = bp_read_watchpoint;
4309 else if (accessflag == 2) bp_type = bp_access_watchpoint;
4310 else bp_type = bp_hardware_watchpoint;
4312 mem_cnt = can_use_hardware_watchpoint (val);
4313 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4314 error ("Expression cannot be implemented with read/access watchpoint.");
4316 i = hw_watchpoint_used_count (bp_type, &other_type_used);
4317 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
4318 bp_type, i + mem_cnt, other_type_used);
4319 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4320 error ("Target does not have this type of hardware watchpoint support.");
4321 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4322 error ("Target resources have been allocated for other types of watchpoints.");
4325 #if defined(HPUXHPPA)
4326 /* On HP-UX if you set a h/w
4327 watchpoint before the "run" command, the inferior dies with a e.g.,
4328 SIGILL once you start it. I initially believed this was due to a
4329 bad interaction between page protection traps and the initial
4330 startup sequence by the dynamic linker.
4332 However, I tried avoiding that by having HP-UX's implementation of
4333 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4334 yet, which forced slow watches before a "run" or "attach", and it
4335 still fails somewhere in the startup code.
4337 Until I figure out what's happening, I'm disallowing watches altogether
4338 before the "run" or "attach" command. We'll tell the user they must
4339 set watches after getting the program started. */
4340 if (! target_has_execution)
4342 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4345 #endif /* HPUXHPPA */
4347 /* Now set up the breakpoint. */
4348 b = set_raw_breakpoint (sal);
4349 set_breakpoint_count (breakpoint_count + 1);
4350 b->number = breakpoint_count;
4351 b->disposition = donttouch;
4353 b->exp_valid_block = exp_valid_block;
4354 b->exp_string = savestring (exp_start, exp_end - exp_start);
4358 b->cond_string = savestring (cond_start, cond_end - cond_start);
4362 frame = block_innermost_frame (exp_valid_block);
4365 prev_frame = get_prev_frame (frame);
4366 b->watchpoint_frame = frame->frame;
4369 b->watchpoint_frame = (CORE_ADDR)0;
4371 if (mem_cnt && target_resources_ok > 0)
4374 b->type = bp_watchpoint;
4376 /* If the expression is "local", then set up a "watchpoint scope"
4377 breakpoint at the point where we've left the scope of the watchpoint
4379 if (innermost_block)
4383 struct breakpoint *scope_breakpoint;
4384 struct symtab_and_line scope_sal;
4386 INIT_SAL (&scope_sal); /* initialize to zeroes */
4387 scope_sal.pc = get_frame_pc (prev_frame);
4388 scope_sal.section = find_pc_overlay (scope_sal.pc);
4390 scope_breakpoint = set_raw_breakpoint (scope_sal);
4391 set_breakpoint_count (breakpoint_count + 1);
4392 scope_breakpoint->number = breakpoint_count;
4394 scope_breakpoint->type = bp_watchpoint_scope;
4395 scope_breakpoint->enable = enabled;
4397 /* Automatically delete the breakpoint when it hits. */
4398 scope_breakpoint->disposition = del;
4400 /* Only break in the proper frame (help with recursion). */
4401 scope_breakpoint->frame = prev_frame->frame;
4403 /* Set the address at which we will stop. */
4404 scope_breakpoint->address = get_frame_pc (prev_frame);
4406 /* The scope breakpoint is related to the watchpoint. We
4407 will need to act on them together. */
4408 b->related_breakpoint = scope_breakpoint;
4411 value_free_to_mark (mark);
4415 /* Return count of locations need to be watched and can be handled
4416 in hardware. If the watchpoint can not be handled
4417 in hardware return zero. */
4419 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4420 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(byte_size) \
4421 ((byte_size) <= (REGISTER_SIZE))
4425 can_use_hardware_watchpoint (v)
4428 int found_memory_cnt = 0;
4430 /* Did the user specifically forbid us to use hardware watchpoints? */
4431 if (! can_use_hw_watchpoints)
4434 /* Make sure all the intermediate values are in memory. Also make sure
4435 we found at least one memory expression. Guards against watch 0x12345,
4436 which is meaningless, but could cause errors if one tries to insert a
4437 hardware watchpoint for the constant expression. */
4438 for ( ; v; v = v->next)
4440 if (v->lval == lval_memory)
4442 if (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (TYPE_LENGTH (VALUE_TYPE (v))))
4445 else if (v->lval != not_lval && v->modifiable == 0)
4449 /* The expression itself looks suitable for using a hardware
4450 watchpoint, but give the target machine a chance to reject it. */
4451 return found_memory_cnt;
4454 static void watch_command (arg, from_tty)
4458 watch_command_1 (arg, 0, from_tty);
4461 static void rwatch_command (arg, from_tty)
4465 watch_command_1 (arg, 1, from_tty);
4468 static void awatch_command (arg, from_tty)
4472 watch_command_1 (arg, 2, from_tty);
4476 /* Helper routine for the until_command routine in infcmd.c. Here
4477 because it uses the mechanisms of breakpoints. */
4481 until_break_command (arg, from_tty)
4485 struct symtabs_and_lines sals;
4486 struct symtab_and_line sal;
4487 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4488 struct breakpoint *breakpoint;
4489 struct cleanup *old_chain;
4491 clear_proceed_status ();
4493 /* Set a breakpoint where the user wants it and at return from
4496 if (default_breakpoint_valid)
4497 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4498 default_breakpoint_line, (char ***)NULL);
4500 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
4502 if (sals.nelts != 1)
4503 error ("Couldn't get information on specified line.");
4506 free ((PTR)sals.sals); /* malloc'd, so freed */
4509 error ("Junk at end of arguments.");
4511 resolve_sal_pc (&sal);
4513 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
4515 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4517 /* Keep within the current frame */
4521 sal = find_pc_line (prev_frame->pc, 0);
4522 sal.pc = prev_frame->pc;
4523 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
4524 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4527 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
4528 do_cleanups(old_chain);
4532 /* These aren't used; I don't konw what they were for. */
4533 /* Set a breakpoint at the catch clause for NAME. */
4535 catch_breakpoint (name)
4541 disable_catch_breakpoint ()
4546 delete_catch_breakpoint ()
4551 enable_catch_breakpoint ()
4558 struct sal_chain *next;
4559 struct symtab_and_line sal;
4563 /* Not really used -- invocation in handle_gnu_4_16_catch_command
4564 had been commented out in the v.4.16 sources, and stays
4565 disabled there now because "catch NAME" syntax isn't allowed.
4567 /* This isn't used; I don't know what it was for. */
4568 /* For each catch clause identified in ARGS, run FUNCTION
4569 with that clause as an argument. */
4570 static struct symtabs_and_lines
4571 map_catch_names (args, function)
4575 register char *p = args;
4577 struct symtabs_and_lines sals;
4579 struct sal_chain *sal_chain = 0;
4583 error_no_arg ("one or more catch names");
4591 /* Don't swallow conditional part. */
4592 if (p1[0] == 'i' && p1[1] == 'f'
4593 && (p1[2] == ' ' || p1[2] == '\t'))
4599 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4603 if (*p1 && *p1 != ' ' && *p1 != '\t')
4604 error ("Arguments must be catch names.");
4610 struct sal_chain *next = (struct sal_chain *)
4611 alloca (sizeof (struct sal_chain));
4612 next->next = sal_chain;
4613 next->sal = get_catch_sal (p);
4618 printf_unfiltered ("No catch clause for exception %s.\n", p);
4623 while (*p == ' ' || *p == '\t') p++;
4628 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4630 static struct symtabs_and_lines
4631 get_catch_sals (this_level_only)
4632 int this_level_only;
4634 register struct blockvector *bl;
4635 register struct block *block;
4636 int index, have_default = 0;
4638 struct symtabs_and_lines sals;
4639 struct sal_chain *sal_chain = 0;
4640 char *blocks_searched;
4642 /* Not sure whether an error message is always the correct response,
4643 but it's better than a core dump. */
4644 if (selected_frame == NULL)
4645 error ("No selected frame.");
4646 block = get_frame_block (selected_frame);
4647 pc = selected_frame->pc;
4653 error ("No symbol table info available.\n");
4655 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4656 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4657 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4661 CORE_ADDR end = BLOCK_END (block) - 4;
4664 if (bl != blockvector_for_pc (end, &index))
4665 error ("blockvector blotch");
4666 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4667 error ("blockvector botch");
4668 last_index = BLOCKVECTOR_NBLOCKS (bl);
4671 /* Don't print out blocks that have gone by. */
4672 while (index < last_index
4673 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4676 while (index < last_index
4677 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4679 if (blocks_searched[index] == 0)
4681 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4684 register struct symbol *sym;
4686 nsyms = BLOCK_NSYMS (b);
4688 for (i = 0; i < nsyms; i++)
4690 sym = BLOCK_SYM (b, i);
4691 if (STREQ (SYMBOL_NAME (sym), "default"))
4697 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4699 struct sal_chain *next = (struct sal_chain *)
4700 alloca (sizeof (struct sal_chain));
4701 next->next = sal_chain;
4702 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
4706 blocks_searched[index] = 1;
4712 if (sal_chain && this_level_only)
4715 /* After handling the function's top-level block, stop.
4716 Don't continue to its superblock, the block of
4717 per-file symbols. */
4718 if (BLOCK_FUNCTION (block))
4720 block = BLOCK_SUPERBLOCK (block);
4725 struct sal_chain *tmp_chain;
4727 /* Count the number of entries. */
4728 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4729 tmp_chain = tmp_chain->next)
4733 sals.sals = (struct symtab_and_line *)
4734 xmalloc (index * sizeof (struct symtab_and_line));
4735 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4736 sals.sals[index] = sal_chain->sal;
4743 ep_skip_leading_whitespace (s)
4746 if ((s == NULL) || (*s == NULL))
4748 while (isspace(**s))
4752 /* This function examines a string, and attempts to find a token
4753 that might be an event name in the leading characters. If a
4754 possible match is found, a pointer to the last character of
4755 the token is returned. Else, NULL is returned. */
4757 ep_find_event_name_end (arg)
4761 char * event_name_end = NULL;
4763 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4767 /* We break out of the loop when we find a token delimiter.
4768 Basically, we're looking for alphanumerics and underscores;
4769 anything else delimites the token. */
4772 if (! isalnum(*s) && (*s != '_'))
4778 return event_name_end;
4782 /* This function attempts to parse an optional "if <cond>" clause
4783 from the arg string. If one is not found, it returns NULL.
4785 Else, it returns a pointer to the condition string. (It does not
4786 attempt to evaluate the string against a particular block.) And,
4787 it updates arg to point to the first character following the parsed
4788 if clause in the arg string. */
4790 ep_parse_optional_if_clause (arg)
4795 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace((*arg)[2]))
4798 /* Skip the "if" keyword. */
4801 /* Skip any extra leading whitespace, and record the start of the
4802 condition string. */
4803 ep_skip_leading_whitespace (arg);
4806 /* Assume that the condition occupies the remainder of the arg string. */
4807 (*arg) += strlen (cond_string);
4812 /* This function attempts to parse an optional filename from the arg
4813 string. If one is not found, it returns NULL.
4815 Else, it returns a pointer to the parsed filename. (This function
4816 makes no attempt to verify that a file of that name exists, or is
4817 accessible.) And, it updates arg to point to the first character
4818 following the parsed filename in the arg string.
4820 Note that clients needing to preserve the returned filename for
4821 future access should copy it to their own buffers. */
4823 ep_parse_optional_filename (arg)
4826 static char filename [1024];
4827 char * arg_p = *arg;
4831 if ((*arg_p == '\0') || isspace (*arg_p))
4849 /* Commands to deal with catching events, such as signals, exceptions,
4850 process start/exit, etc. */
4852 typedef enum {catch_fork, catch_vfork} catch_fork_kind;
4854 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind, char *arg, int tempflag, int from_tty));
4857 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
4858 catch_fork_kind fork_kind;
4863 char * cond_string = NULL;
4865 ep_skip_leading_whitespace (&arg);
4867 /* The allowed syntax is:
4869 catch [v]fork if <cond>
4871 First, check if there's an if clause. */
4872 cond_string = ep_parse_optional_if_clause (&arg);
4874 if ((*arg != '\0') && !isspace (*arg))
4875 error ("Junk at end of arguments.");
4877 /* If this target supports it, create a fork or vfork catchpoint
4878 and enable reporting of such events. */
4879 switch (fork_kind) {
4881 create_fork_event_catchpoint (tempflag, cond_string);
4884 create_vfork_event_catchpoint (tempflag, cond_string);
4887 error ("unsupported or unknown fork kind; cannot catch it");
4893 catch_exec_command_1 (arg, tempflag, from_tty)
4898 char * cond_string = NULL;
4900 ep_skip_leading_whitespace (&arg);
4902 /* The allowed syntax is:
4904 catch exec if <cond>
4906 First, check if there's an if clause. */
4907 cond_string = ep_parse_optional_if_clause (&arg);
4909 if ((*arg != '\0') && !isspace (*arg))
4910 error ("Junk at end of arguments.");
4912 /* If this target supports it, create an exec catchpoint
4913 and enable reporting of such events. */
4914 create_exec_event_catchpoint (tempflag, cond_string);
4917 #if defined(SOLIB_ADD)
4919 catch_load_command_1 (arg, tempflag, from_tty)
4924 char * dll_pathname = NULL;
4925 char * cond_string = NULL;
4927 ep_skip_leading_whitespace (&arg);
4929 /* The allowed syntax is:
4931 catch load if <cond>
4932 catch load <filename>
4933 catch load <filename> if <cond>
4935 The user is not allowed to specify the <filename> after an
4938 We'll ignore the pathological case of a file named "if".
4940 First, check if there's an if clause. If so, then there
4941 cannot be a filename. */
4942 cond_string = ep_parse_optional_if_clause (&arg);
4944 /* If there was an if clause, then there cannot be a filename.
4945 Else, there might be a filename and an if clause. */
4946 if (cond_string == NULL)
4948 dll_pathname = ep_parse_optional_filename (&arg);
4949 ep_skip_leading_whitespace (&arg);
4950 cond_string = ep_parse_optional_if_clause (&arg);
4953 if ((*arg != '\0') && !isspace (*arg))
4954 error ("Junk at end of arguments.");
4956 /* Create a load breakpoint that only triggers when a load of
4957 the specified dll (or any dll, if no pathname was specified)
4959 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag, dll_pathname, cond_string);
4963 catch_unload_command_1 (arg, tempflag, from_tty)
4968 char * dll_pathname = NULL;
4969 char * cond_string = NULL;
4971 ep_skip_leading_whitespace (&arg);
4973 /* The allowed syntax is:
4975 catch unload if <cond>
4976 catch unload <filename>
4977 catch unload <filename> if <cond>
4979 The user is not allowed to specify the <filename> after an
4982 We'll ignore the pathological case of a file named "if".
4984 First, check if there's an if clause. If so, then there
4985 cannot be a filename. */
4986 cond_string = ep_parse_optional_if_clause (&arg);
4988 /* If there was an if clause, then there cannot be a filename.
4989 Else, there might be a filename and an if clause. */
4990 if (cond_string == NULL)
4992 dll_pathname = ep_parse_optional_filename (&arg);
4993 ep_skip_leading_whitespace (&arg);
4994 cond_string = ep_parse_optional_if_clause (&arg);
4997 if ((*arg != '\0') && !isspace (*arg))
4998 error ("Junk at end of arguments.");
5000 /* Create an unload breakpoint that only triggers when an unload of
5001 the specified dll (or any dll, if no pathname was specified)
5003 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag, dll_pathname, cond_string);
5005 #endif /* SOLIB_ADD */
5007 /* Commands to deal with catching exceptions. */
5009 /* Set a breakpoint at the specified callback routine for an
5010 exception event callback */
5013 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5016 enum exception_event_kind ex_event;
5017 struct symtab_and_line *sal;
5019 struct breakpoint * b;
5021 int thread = -1; /* All threads. */
5023 if (!sal) /* no exception support? */
5026 b = set_raw_breakpoint (*sal);
5027 set_breakpoint_count (breakpoint_count + 1);
5028 b->number = breakpoint_count;
5030 b->cond_string = (cond_string == NULL) ? NULL : savestring (cond_string, strlen (cond_string));
5032 b->addr_string = NULL;
5033 b->enable = enabled;
5034 b->disposition = tempflag ? del : donttouch;
5037 case EX_EVENT_THROW:
5038 b->type = bp_catch_throw;
5040 case EX_EVENT_CATCH:
5041 b->type = bp_catch_catch;
5043 default: /* error condition */
5045 b->enable = disabled;
5046 error ("Internal error -- invalid catchpoint kind");
5051 /* Deal with "catch catch" and "catch throw" commands */
5054 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5055 enum exception_event_kind ex_event;
5060 char * cond_string = NULL;
5061 struct symtab_and_line * sal = NULL;
5063 ep_skip_leading_whitespace (&arg);
5065 cond_string = ep_parse_optional_if_clause (&arg);
5067 if ((*arg != '\0') && !isspace (*arg))
5068 error ("Junk at end of arguments.");
5070 if ((ex_event != EX_EVENT_THROW) &&
5071 (ex_event != EX_EVENT_CATCH))
5072 error ("Unsupported or unknown exception event; cannot catch it");
5074 /* See if we can find a callback routine */
5075 sal = target_enable_exception_callback (ex_event, 1);
5079 /* We have callbacks from the runtime system for exceptions.
5080 Set a breakpoint on the sal found, if no errors */
5081 if (sal != (struct symtab_and_line *) -1)
5082 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5084 return; /* something went wrong with setting up callbacks */
5088 /* No callbacks from runtime system for exceptions.
5089 Try GNU C++ exception breakpoints using labels in debug info. */
5090 if (ex_event == EX_EVENT_CATCH)
5092 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5094 else if (ex_event == EX_EVENT_THROW)
5096 /* Set a breakpoint on __raise_exception () */
5098 fprintf_filtered (gdb_stderr, "Unsupported with this platform/compiler combination.\n");
5099 fprintf_filtered (gdb_stderr, "Perhaps you can achieve the effect you want by setting\n");
5100 fprintf_filtered (gdb_stderr, "a breakpoint on __raise_exception().\n");
5105 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5106 inside a catch_errors */
5109 cover_target_enable_exception_callback (arg)
5112 args_for_catchpoint_enable *args = arg;
5113 struct symtab_and_line *sal;
5114 sal = target_enable_exception_callback (args->kind, args->enable);
5117 else if (sal == (struct symtab_and_line *) -1)
5120 return 1; /*is valid*/
5125 /* This is the original v.4.16 and earlier version of the
5126 catch_command_1() function. Now that other flavours of "catch"
5127 have been introduced, and since exception handling can be handled
5128 in other ways (through target ops) also, this is used only for the
5129 GNU C++ exception handling system.
5130 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5131 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5132 there was no code in GDB 4.16 for "catch throw".
5134 Called from catch_exception_command_1 () */
5138 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5143 /* First, translate ARG into something we can deal with in terms
5146 struct symtabs_and_lines sals;
5147 struct symtab_and_line sal;
5148 register struct expression *cond = 0;
5149 register struct breakpoint *b;
5153 INIT_SAL (&sal); /* initialize to zeroes */
5155 /* If no arg given, or if first arg is 'if ', all active catch clauses
5156 are breakpointed. */
5158 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5159 && (arg[2] == ' ' || arg[2] == '\t')))
5161 /* Grab all active catch clauses. */
5162 sals = get_catch_sals (0);
5166 /* Grab selected catch clauses. */
5167 error ("catch NAME not implemented");
5170 /* Not sure why this code has been disabled. I'm leaving
5171 it disabled. We can never come here now anyway
5172 since we don't allow the "catch NAME" syntax.
5175 /* This isn't used; I don't know what it was for. */
5176 sals = map_catch_names (arg, catch_breakpoint);
5184 for (i = 0; i < sals.nelts; i++)
5186 resolve_sal_pc (&sals.sals[i]);
5190 if (arg[0] == 'i' && arg[1] == 'f'
5191 && (arg[2] == ' ' || arg[2] == '\t'))
5192 cond = parse_exp_1 ((arg += 2, &arg),
5193 block_for_pc (sals.sals[i].pc), 0);
5195 error ("Junk at end of arguments.");
5200 for (i = 0; i < sals.nelts; i++)
5205 describe_other_breakpoints (sal.pc, sal.section);
5207 b = set_raw_breakpoint (sal);
5208 set_breakpoint_count (breakpoint_count + 1);
5209 b->number = breakpoint_count;
5210 b->type = bp_breakpoint; /* Important -- this is an ordinary breakpoint.
5211 For platforms with callback support for exceptions,
5212 create_exception_catchpoint() will create special
5213 bp types (bp_catch_catch and bp_catch_throw), and
5214 there is code in insert_breakpoints() and elsewhere
5215 that depends on that. */
5218 b->enable = enabled;
5219 b->disposition = tempflag ? del : donttouch;
5226 printf_unfiltered ("Multiple breakpoints were set.\n");
5227 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
5229 free ((PTR)sals.sals);
5233 /* This creates a temporary internal breakpoint
5234 just to placate infrun */
5235 static struct breakpoint *
5236 create_temp_exception_breakpoint (pc)
5239 struct symtab_and_line sal;
5240 struct breakpoint *b;
5247 b = set_raw_breakpoint (sal);
5249 error ("Internal error -- couldn't set temp exception breakpoint");
5251 b->type = bp_breakpoint;
5252 b->disposition = del;
5253 b->enable = enabled;
5255 b->number = internal_breakpoint_number--;
5261 catch_command_1 (arg, tempflag, from_tty)
5267 /* The first argument may be an event name, such as "start" or "load".
5268 If so, then handle it as such. If it doesn't match an event name,
5269 then attempt to interpret it as an exception name. (This latter is
5270 the v4.16-and-earlier GDB meaning of the "catch" command.)
5272 First, try to find the bounds of what might be an event name. */
5273 char * arg1_start = arg;
5277 if (arg1_start == NULL)
5279 /* Old behaviour was to use pre-v-4.16 syntax */
5280 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5282 /* Now, this is not allowed */
5283 error ("Catch requires an event name.");
5286 arg1_end = ep_find_event_name_end (arg1_start);
5287 if (arg1_end == NULL)
5288 error ("catch requires an event");
5289 arg1_length = arg1_end + 1 - arg1_start;
5291 /* Try to match what we found against known event names. */
5292 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5294 error ("Catch of signal not yet implemented");
5296 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5298 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end+1, tempflag, from_tty);
5300 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5302 catch_exception_command_1 (EX_EVENT_THROW, arg1_end+1, tempflag, from_tty);
5304 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5306 error ("Catch of thread_start not yet implemented");
5308 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5310 error ("Catch of thread_exit not yet implemented");
5312 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5314 error ("Catch of thread_join not yet implemented");
5316 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5318 error ("Catch of start not yet implemented");
5320 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5322 error ("Catch of exit not yet implemented");
5324 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5326 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5327 catch_fork_command_1 (catch_fork, arg1_end+1, tempflag, from_tty);
5329 error ("Catch of fork not yet implemented");
5332 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5334 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5335 catch_fork_command_1 (catch_vfork, arg1_end+1, tempflag, from_tty);
5337 error ("Catch of vfork not yet implemented");
5340 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5342 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5343 catch_exec_command_1 (arg1_end+1, tempflag, from_tty);
5345 error ("Catch of exec not yet implemented");
5348 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5350 #if defined(SOLIB_ADD)
5351 catch_load_command_1 (arg1_end+1, tempflag, from_tty);
5353 error ("Catch of load not implemented");
5356 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5358 #if defined(SOLIB_ADD)
5359 catch_unload_command_1 (arg1_end+1, tempflag, from_tty);
5361 error ("Catch of load not implemented");
5364 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5366 error ("Catch of stop not yet implemented");
5369 /* This doesn't appear to be an event name */
5373 /* Pre-v.4.16 behaviour was to treat the argument
5374 as the name of an exception */
5375 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5376 /* Now this is not allowed */
5377 error ("Unknown event kind specified for catch");
5382 /* Used by the gui, could be made a worker for other things. */
5385 set_breakpoint_sal (sal)
5386 struct symtab_and_line sal;
5388 struct breakpoint *b;
5389 b = set_raw_breakpoint (sal);
5390 set_breakpoint_count (breakpoint_count + 1);
5391 b->number = breakpoint_count;
5392 b->type = bp_breakpoint;
5399 /* These aren't used; I don't know what they were for. */
5400 /* Disable breakpoints on all catch clauses described in ARGS. */
5402 disable_catch (args)
5405 /* Map the disable command to catch clauses described in ARGS. */
5408 /* Enable breakpoints on all catch clauses described in ARGS. */
5413 /* Map the disable command to catch clauses described in ARGS. */
5416 /* Delete breakpoints on all catch clauses in the active scope. */
5421 /* Map the delete command to catch clauses described in ARGS. */
5426 catch_command (arg, from_tty)
5430 catch_command_1 (arg, 0, from_tty);
5435 tcatch_command (arg, from_tty)
5439 catch_command_1 (arg, 1, from_tty);
5444 clear_command (arg, from_tty)
5448 register struct breakpoint *b, *b1;
5450 struct symtabs_and_lines sals;
5451 struct symtab_and_line sal;
5452 register struct breakpoint *found;
5457 sals = decode_line_spec (arg, 1);
5462 sals.sals = (struct symtab_and_line *)
5463 xmalloc (sizeof (struct symtab_and_line));
5464 INIT_SAL (&sal); /* initialize to zeroes */
5465 sal.line = default_breakpoint_line;
5466 sal.symtab = default_breakpoint_symtab;
5467 sal.pc = default_breakpoint_address;
5468 if (sal.symtab == 0)
5469 error ("No source file specified.");
5477 /* For each line spec given, delete bps which correspond
5478 to it. We do this in two loops: the first loop looks at
5479 the initial bp(s) in the chain which should be deleted,
5480 the second goes down the rest of the chain looking ahead
5481 one so it can take those bps off the chain without messing
5485 for (i = 0; i < sals.nelts; i++)
5487 /* If exact pc given, clear bpts at that pc.
5488 If line given (pc == 0), clear all bpts on specified line.
5489 If defaulting, clear all bpts on default line
5492 defaulting sal.pc != 0 tests to do
5497 1 0 <can't happen> */
5500 found = (struct breakpoint *) 0;
5503 while (breakpoint_chain
5504 /* Why don't we check here that this is not
5505 a watchpoint, etc., as we do below?
5506 I can't make it fail, but don't know
5507 what's stopping the failure: a watchpoint
5508 of the same address as "sal.pc" should
5509 wind up being deleted. */
5511 && ( ((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5512 (overlay_debugging == 0 ||
5513 breakpoint_chain->section == sal.section))
5514 || ((default_match || (0 == sal.pc))
5515 && breakpoint_chain->source_file != NULL
5516 && sal.symtab != NULL
5517 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5518 && breakpoint_chain->line_number == sal.line)))
5521 b1 = breakpoint_chain;
5522 breakpoint_chain = b1->next;
5530 && b->next->type != bp_none
5531 && b->next->type != bp_watchpoint
5532 && b->next->type != bp_hardware_watchpoint
5533 && b->next->type != bp_read_watchpoint
5534 && b->next->type != bp_access_watchpoint
5535 && ( ((sal.pc && (b->next->address == sal.pc)) &&
5536 (overlay_debugging == 0 ||
5537 b->next->section == sal.section))
5538 || ((default_match || (0 == sal.pc))
5539 && b->next->source_file != NULL
5540 && sal.symtab != NULL
5541 && STREQ (b->next->source_file, sal.symtab->filename)
5542 && b->next->line_number == sal.line)))
5555 error ("No breakpoint at %s.", arg);
5557 error ("No breakpoint at this line.");
5560 if (found->next) from_tty = 1; /* Always report if deleted more than one */
5561 if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
5562 breakpoints_changed ();
5565 if (from_tty) printf_unfiltered ("%d ", found->number);
5567 delete_breakpoint (found);
5570 if (from_tty) putchar_unfiltered ('\n');
5572 free ((PTR)sals.sals);
5575 /* Delete breakpoint in BS if they are `delete' breakpoints and
5576 all breakpoints that are marked for deletion, whether hit or not.
5577 This is called after any breakpoint is hit, or after errors. */
5580 breakpoint_auto_delete (bs)
5583 struct breakpoint *b, *temp;
5585 for (; bs; bs = bs->next)
5586 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
5588 delete_breakpoint (bs->breakpoint_at);
5590 ALL_BREAKPOINTS_SAFE (b, temp)
5592 if (b->disposition == del_at_next_stop)
5593 delete_breakpoint (b);
5597 /* Delete a breakpoint and clean up all traces of it in the data structures. */
5600 delete_breakpoint (bpt)
5601 struct breakpoint *bpt;
5603 register struct breakpoint *b;
5607 error ("Internal error (attempted to delete a NULL breakpoint)");
5610 /* Has this bp already been deleted? This can happen because multiple
5611 lists can hold pointers to bp's. bpstat lists are especial culprits.
5613 One example of this happening is a watchpoint's scope bp. When the
5614 scope bp triggers, we notice that the watchpoint is out of scope, and
5615 delete it. We also delete its scope bp. But the scope bp is marked
5616 "auto-deleting", and is already on a bpstat. That bpstat is then
5617 checked for auto-deleting bp's, which are deleted.
5619 A real solution to this problem might involve reference counts in bp's,
5620 and/or giving them pointers back to their referencing bpstat's, and
5621 teaching delete_breakpoint to only free a bp's storage when no more
5622 references were extent. A cheaper bandaid was chosen. */
5623 if (bpt->type == bp_none)
5626 if (delete_breakpoint_hook)
5627 delete_breakpoint_hook (bpt);
5630 remove_breakpoint (bpt, mark_uninserted);
5632 if (breakpoint_chain == bpt)
5633 breakpoint_chain = bpt->next;
5635 /* If we have callback-style exception catchpoints, don't go through
5636 the adjustments to the C++ runtime library etc. if the inferior
5637 isn't actually running. target_enable_exception_callback for a
5638 null target ops vector gives an undesirable error message, so we
5639 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
5640 exceptions are supported in this way, it's OK for now. FIXME */
5641 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5643 static char message1[] = "Error in deleting catchpoint %d:\n";
5644 static char message[sizeof (message1) + 30];
5645 args_for_catchpoint_enable args;
5647 sprintf (message, message1, bpt->number); /* Format possible error msg */
5648 args.kind = bpt->type == bp_catch_catch ? EX_EVENT_CATCH : EX_EVENT_THROW;
5650 catch_errors (cover_target_enable_exception_callback, &args,
5651 message, RETURN_MASK_ALL);
5658 b->next = bpt->next;
5662 /* Before turning off the visuals for the bp, check to see that
5663 there are no other bps at the same address. */
5670 clearIt = (b->address != bpt->address);
5677 TUIDO(((TuiOpaqueFuncPtr)tui_vAllSetHasBreakAt, bpt, 0));
5678 TUIDO(((TuiOpaqueFuncPtr)tuiUpdateAllExecInfos));
5682 check_duplicates (bpt->address, bpt->section);
5683 /* If this breakpoint was inserted, and there is another breakpoint
5684 at the same address, we need to insert the other breakpoint. */
5686 && bpt->type != bp_hardware_watchpoint
5687 && bpt->type != bp_read_watchpoint
5688 && bpt->type != bp_access_watchpoint
5689 && bpt->type != bp_catch_fork
5690 && bpt->type != bp_catch_vfork
5691 && bpt->type != bp_catch_exec)
5694 if (b->address == bpt->address
5695 && b->section == bpt->section
5697 && b->enable != disabled
5698 && b->enable != shlib_disabled
5699 && b->enable != call_disabled)
5702 val = target_insert_breakpoint (b->address, b->shadow_contents);
5705 target_terminal_ours_for_output ();
5706 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
5707 memory_error (val, b->address); /* which bombs us out */
5714 free_command_lines (&bpt->commands);
5717 if (bpt->cond_string != NULL)
5718 free (bpt->cond_string);
5719 if (bpt->addr_string != NULL)
5720 free (bpt->addr_string);
5721 if (bpt->exp != NULL)
5723 if (bpt->exp_string != NULL)
5724 free (bpt->exp_string);
5725 if (bpt->val != NULL)
5726 value_free (bpt->val);
5727 if (bpt->source_file != NULL)
5728 free (bpt->source_file);
5729 if (bpt->dll_pathname != NULL)
5730 free (bpt->dll_pathname);
5731 if (bpt->triggered_dll_pathname != NULL)
5732 free (bpt->triggered_dll_pathname);
5733 if (bpt->exec_pathname != NULL)
5734 free (bpt->exec_pathname);
5736 /* Be sure no bpstat's are pointing at it after it's been freed. */
5737 /* FIXME, how can we find all bpstat's?
5738 We just check stop_bpstat for now. */
5739 for (bs = stop_bpstat; bs; bs = bs->next)
5740 if (bs->breakpoint_at == bpt)
5742 bs->breakpoint_at = NULL;
5744 /* we'd call bpstat_clear_actions, but that free's stuff and due
5745 to the multiple pointers pointing to one item with no
5746 reference counts found anywhere through out the bpstat's (how
5747 do you spell fragile?), we don't want to free things twice --
5748 better a memory leak than a corrupt malloc pool! */
5749 bs->commands = NULL;
5752 /* On the chance that someone will soon try again to delete this same
5753 bp, we mark it as deleted before freeing its storage. */
5754 bpt->type = bp_none;
5760 delete_command (arg, from_tty)
5764 struct breakpoint *b, *temp;
5768 int breaks_to_delete = 0;
5770 /* Delete all breakpoints if no argument.
5771 Do not delete internal or call-dummy breakpoints, these
5772 have to be deleted with an explicit breakpoint number argument. */
5775 if (b->type != bp_call_dummy &&
5776 b->type != bp_shlib_event &&
5778 breaks_to_delete = 1;
5781 /* Ask user only if there are some breakpoints to delete. */
5783 || (breaks_to_delete && query ("Delete all breakpoints? ")))
5785 ALL_BREAKPOINTS_SAFE (b, temp)
5787 if (b->type != bp_call_dummy &&
5788 b->type != bp_shlib_event &&
5790 delete_breakpoint (b);
5795 map_breakpoint_numbers (arg, delete_breakpoint);
5798 /* Reset a breakpoint given it's struct breakpoint * BINT.
5799 The value we return ends up being the return value from catch_errors.
5800 Unused in this case. */
5803 breakpoint_re_set_one (bint)
5806 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
5809 struct symtabs_and_lines sals;
5811 enum enable save_enable;
5816 warning ("attempted to reset apparently deleted breakpoint #%d?\n", b->number);
5819 case bp_hardware_breakpoint:
5821 case bp_catch_unload:
5822 if (b->addr_string == NULL)
5824 /* Anything without a string can't be re-set. */
5825 delete_breakpoint (b);
5828 /* In case we have a problem, disable this breakpoint. We'll restore
5829 its status if we succeed. */
5830 save_enable = b->enable;
5831 b->enable = disabled;
5833 set_language (b->language);
5834 input_radix = b->input_radix;
5836 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
5837 for (i = 0; i < sals.nelts; i++)
5839 resolve_sal_pc (&sals.sals[i]);
5841 /* Reparse conditions, they might contain references to the
5843 if (b->cond_string != NULL)
5847 free ((PTR)b->cond);
5848 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
5851 /* We need to re-set the breakpoint if the address changes...*/
5852 if (b->address != sals.sals[i].pc
5853 /* ...or new and old breakpoints both have source files, and
5854 the source file name or the line number changes... */
5855 || (b->source_file != NULL
5856 && sals.sals[i].symtab != NULL
5857 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
5858 || b->line_number != sals.sals[i].line)
5860 /* ...or we switch between having a source file and not having
5862 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
5865 if (b->source_file != NULL)
5866 free (b->source_file);
5867 if (sals.sals[i].symtab == NULL)
5868 b->source_file = NULL;
5871 savestring (sals.sals[i].symtab->filename,
5872 strlen (sals.sals[i].symtab->filename));
5873 b->line_number = sals.sals[i].line;
5874 b->address = sals.sals[i].pc;
5876 /* Used to check for duplicates here, but that can
5877 cause trouble, as it doesn't check for disable
5882 /* Might be better to do this just once per breakpoint_re_set,
5883 rather than once for every breakpoint. */
5884 breakpoints_changed ();
5886 b->section = sals.sals[i].section;
5887 b->enable = save_enable; /* Restore it, this worked. */
5890 /* Now that this is re-enabled, check_duplicates
5892 check_duplicates (b->address, b->section);
5895 free ((PTR)sals.sals);
5899 case bp_hardware_watchpoint:
5900 case bp_read_watchpoint:
5901 case bp_access_watchpoint:
5902 innermost_block = NULL;
5903 /* The issue arises of what context to evaluate this in. The same
5904 one as when it was set, but what does that mean when symbols have
5905 been re-read? We could save the filename and functionname, but
5906 if the context is more local than that, the best we could do would
5907 be something like how many levels deep and which index at that
5908 particular level, but that's going to be less stable than filenames
5909 or functionnames. */
5910 /* So for now, just use a global context. */
5913 b->exp = parse_expression (b->exp_string);
5914 b->exp_valid_block = innermost_block;
5915 mark = value_mark ();
5917 value_free (b->val);
5918 b->val = evaluate_expression (b->exp);
5919 release_value (b->val);
5920 if (VALUE_LAZY (b->val))
5921 value_fetch_lazy (b->val);
5923 if (b->cond_string != NULL)
5927 free ((PTR)b->cond);
5928 b->cond = parse_exp_1 (&s, (struct block *)0, 0);
5930 if (b->enable == enabled)
5932 value_free_to_mark (mark);
5934 case bp_catch_catch:
5935 case bp_catch_throw:
5937 /* We needn't really do anything to reset these, since the mask
5938 that requests them is unaffected by e.g., new libraries being
5941 case bp_catch_vfork:
5946 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
5948 /* Delete longjmp breakpoints, they will be reset later by
5949 breakpoint_re_set. */
5951 case bp_longjmp_resume:
5952 delete_breakpoint (b);
5955 /* This breakpoint is special, it's set up when the inferior
5956 starts and we really don't want to touch it. */
5957 case bp_shlib_event:
5959 /* Keep temporary breakpoints, which can be encountered when we step
5960 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
5961 Otherwise these should have been blown away via the cleanup chain
5962 or by breakpoint_init_inferior when we rerun the executable. */
5965 case bp_watchpoint_scope:
5967 case bp_step_resume:
5974 /* Re-set all breakpoints after symbols have been re-loaded. */
5976 breakpoint_re_set ()
5978 struct breakpoint *b, *temp;
5979 enum language save_language;
5980 int save_input_radix;
5981 static char message1[] = "Error in re-setting breakpoint %d:\n";
5982 char message[sizeof (message1) + 30 /* slop */];
5984 save_language = current_language->la_language;
5985 save_input_radix = input_radix;
5986 ALL_BREAKPOINTS_SAFE (b, temp)
5988 sprintf (message, message1, b->number); /* Format possible error msg */
5989 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
5991 set_language (save_language);
5992 input_radix = save_input_radix;
5994 #ifdef GET_LONGJMP_TARGET
5995 create_longjmp_breakpoint ("longjmp");
5996 create_longjmp_breakpoint ("_longjmp");
5997 create_longjmp_breakpoint ("siglongjmp");
5998 create_longjmp_breakpoint ("_siglongjmp");
5999 create_longjmp_breakpoint (NULL);
6003 /* Took this out (temporarily at least), since it produces an extra
6004 blank line at startup. This messes up the gdbtests. -PB */
6005 /* Blank line to finish off all those mention() messages we just printed. */
6006 printf_filtered ("\n");
6010 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6011 If from_tty is nonzero, it prints a message to that effect,
6012 which ends with a period (no newline). */
6014 /* Reset the thread number of this breakpoint:
6016 - If the breakpoint is for all threads, leave it as-is.
6017 - Else, reset it to the current thread for inferior_pid. */
6019 breakpoint_re_set_thread (b)
6020 struct breakpoint * b;
6022 if (b->thread != -1)
6024 if (in_thread_list (inferior_pid))
6025 b->thread = pid_to_thread_id (inferior_pid);
6030 set_ignore_count (bptnum, count, from_tty)
6031 int bptnum, count, from_tty;
6033 register struct breakpoint *b;
6039 if (b->number == bptnum)
6041 b->ignore_count = count;
6044 else if (count == 0)
6045 printf_filtered ("Will stop next time breakpoint %d is reached.",
6047 else if (count == 1)
6048 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6051 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6053 breakpoints_changed ();
6057 error ("No breakpoint number %d.", bptnum);
6060 /* Clear the ignore counts of all breakpoints. */
6062 breakpoint_clear_ignore_counts ()
6064 struct breakpoint *b;
6067 b->ignore_count = 0;
6070 /* Command to set ignore-count of breakpoint N to COUNT. */
6073 ignore_command (args, from_tty)
6081 error_no_arg ("a breakpoint number");
6083 num = get_number (&p);
6086 error ("Second argument (specified ignore-count) is missing.");
6088 set_ignore_count (num,
6089 longest_to_int (value_as_long (parse_and_eval (p))),
6091 printf_filtered ("\n");
6092 breakpoints_changed ();
6095 /* Call FUNCTION on each of the breakpoints
6096 whose numbers are given in ARGS. */
6099 map_breakpoint_numbers (args, function)
6101 void (*function) PARAMS ((struct breakpoint *));
6103 register char *p = args;
6106 register struct breakpoint *b;
6109 error_no_arg ("one or more breakpoint numbers");
6115 num = get_number (&p1);
6118 if (b->number == num)
6120 struct breakpoint *related_breakpoint = b->related_breakpoint;
6122 if (related_breakpoint)
6123 function (related_breakpoint);
6126 printf_unfiltered ("No breakpoint number %d.\n", num);
6133 disable_breakpoint (bpt)
6134 struct breakpoint *bpt;
6136 /* Never disable a watchpoint scope breakpoint; we want to
6137 hit them when we leave scope so we can delete both the
6138 watchpoint and its scope breakpoint at that time. */
6139 if (bpt->type == bp_watchpoint_scope)
6142 bpt->enable = disabled;
6144 check_duplicates (bpt->address, bpt->section);
6146 if (modify_breakpoint_hook)
6147 modify_breakpoint_hook (bpt);
6152 disable_command (args, from_tty)
6156 register struct breakpoint *bpt;
6158 ALL_BREAKPOINTS (bpt)
6162 warning ("attempted to disable apparently deleted breakpoint #%d?\n", bpt->number);
6166 case bp_catch_unload:
6168 case bp_catch_vfork:
6170 case bp_catch_catch:
6171 case bp_catch_throw:
6172 case bp_hardware_breakpoint:
6174 case bp_hardware_watchpoint:
6175 case bp_read_watchpoint:
6176 case bp_access_watchpoint:
6177 disable_breakpoint (bpt);
6182 map_breakpoint_numbers (args, disable_breakpoint);
6186 do_enable_breakpoint (bpt, disposition)
6187 struct breakpoint *bpt;
6188 enum bpdisp disposition;
6190 struct frame_info *save_selected_frame = NULL;
6191 int save_selected_frame_level = -1;
6192 int target_resources_ok, other_type_used;
6195 if (bpt->type == bp_hardware_breakpoint)
6198 i = hw_breakpoint_used_count();
6199 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
6200 bp_hardware_breakpoint, i+1, 0);
6201 if (target_resources_ok == 0)
6202 error ("No hardware breakpoint support in the target.");
6203 else if (target_resources_ok < 0)
6204 error ("Hardware breakpoints used exceeds limit.");
6207 bpt->enable = enabled;
6208 bpt->disposition = disposition;
6209 check_duplicates (bpt->address, bpt->section);
6210 breakpoints_changed ();
6212 if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint ||
6213 bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint)
6215 if (bpt->exp_valid_block != NULL)
6217 struct frame_info *fr =
6219 /* Ensure that we have the current frame. Else, this
6220 next query may pessimistically be answered as, "No,
6221 not within current scope". */
6222 get_current_frame ();
6223 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6227 Cannot enable watchpoint %d because the block in which its expression\n\
6228 is valid is not currently in scope.\n", bpt->number);
6229 bpt->enable = disabled;
6233 save_selected_frame = selected_frame;
6234 save_selected_frame_level = selected_frame_level;
6235 select_frame (fr, -1);
6238 value_free (bpt->val);
6239 mark = value_mark ();
6240 bpt->val = evaluate_expression (bpt->exp);
6241 release_value (bpt->val);
6242 if (VALUE_LAZY (bpt->val))
6243 value_fetch_lazy (bpt->val);
6245 if (bpt->type == bp_hardware_watchpoint ||
6246 bpt->type == bp_read_watchpoint ||
6247 bpt->type == bp_access_watchpoint)
6249 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6250 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6252 /* Hack around 'unused var' error for some targets here */
6254 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
6255 bpt->type, i + mem_cnt, other_type_used);
6256 /* we can consider of type is bp_hardware_watchpoint, convert to
6257 bp_watchpoint in the following condition */
6258 if (target_resources_ok < 0)
6261 Cannot enable watchpoint %d because target watch resources\n\
6262 have been allocated for other watchpoints.\n", bpt->number);
6263 bpt->enable = disabled;
6264 value_free_to_mark (mark);
6269 if (save_selected_frame_level >= 0)
6270 select_and_print_frame (save_selected_frame, save_selected_frame_level);
6271 value_free_to_mark (mark);
6273 if (modify_breakpoint_hook)
6274 modify_breakpoint_hook (bpt);
6278 enable_breakpoint (bpt)
6279 struct breakpoint *bpt;
6281 do_enable_breakpoint (bpt, bpt->disposition);
6284 /* The enable command enables the specified breakpoints (or all defined
6285 breakpoints) so they once again become (or continue to be) effective
6286 in stopping the inferior. */
6290 enable_command (args, from_tty)
6294 register struct breakpoint *bpt;
6296 ALL_BREAKPOINTS (bpt)
6300 warning ("attempted to enable apparently deleted breakpoint #%d?\n", bpt->number);
6304 case bp_catch_unload:
6306 case bp_catch_vfork:
6308 case bp_catch_catch:
6309 case bp_catch_throw:
6310 case bp_hardware_breakpoint:
6312 case bp_hardware_watchpoint:
6313 case bp_read_watchpoint:
6314 case bp_access_watchpoint:
6315 enable_breakpoint (bpt);
6320 map_breakpoint_numbers (args, enable_breakpoint);
6324 enable_once_breakpoint (bpt)
6325 struct breakpoint *bpt;
6327 do_enable_breakpoint (bpt, disable);
6332 enable_once_command (args, from_tty)
6336 map_breakpoint_numbers (args, enable_once_breakpoint);
6340 enable_delete_breakpoint (bpt)
6341 struct breakpoint *bpt;
6343 do_enable_breakpoint (bpt, del);
6348 enable_delete_command (args, from_tty)
6352 map_breakpoint_numbers (args, enable_delete_breakpoint);
6355 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
6357 struct symtabs_and_lines
6358 decode_line_spec_1 (string, funfirstline)
6362 struct symtabs_and_lines sals;
6364 error ("Empty line specification.");
6365 if (default_breakpoint_valid)
6366 sals = decode_line_1 (&string, funfirstline,
6367 default_breakpoint_symtab, default_breakpoint_line,
6370 sals = decode_line_1 (&string, funfirstline,
6371 (struct symtab *)NULL, 0, (char ***)NULL);
6373 error ("Junk at end of line specification: %s", string);
6378 _initialize_breakpoint ()
6380 struct cmd_list_element *c;
6382 breakpoint_chain = 0;
6383 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6384 before a breakpoint is set. */
6385 breakpoint_count = 0;
6387 add_com ("ignore", class_breakpoint, ignore_command,
6388 "Set ignore-count of breakpoint number N to COUNT.\n\
6389 Usage is `ignore N COUNT'.");
6391 add_com_alias("bc", "ignore", class_breakpoint, 1);
6393 add_com ("commands", class_breakpoint, commands_command,
6394 "Set commands to be executed when a breakpoint is hit.\n\
6395 Give breakpoint number as argument after \"commands\".\n\
6396 With no argument, the targeted breakpoint is the last one set.\n\
6397 The commands themselves follow starting on the next line.\n\
6398 Type a line containing \"end\" to indicate the end of them.\n\
6399 Give \"silent\" as the first line to make the breakpoint silent;\n\
6400 then no output is printed when it is hit, except what the commands print.");
6402 add_com ("condition", class_breakpoint, condition_command,
6403 "Specify breakpoint number N to break only if COND is true.\n\
6404 Usage is `condition N COND', where N is an integer and COND is an\n\
6405 expression to be evaluated whenever breakpoint N is reached. ");
6407 add_com ("tbreak", class_breakpoint, tbreak_command,
6408 "Set a temporary breakpoint. Args like \"break\" command.\n\
6409 Like \"break\" except the breakpoint is only temporary,\n\
6410 so it will be deleted when hit. Equivalent to \"break\" followed\n\
6411 by using \"enable delete\" on the breakpoint number.");
6412 add_com("txbreak", class_breakpoint, tbreak_at_finish_command,
6413 "Set temporary breakpoint at procedure exit. Either there should\n\
6414 be no argument or the argument must be a depth.\n");
6416 add_com ("hbreak", class_breakpoint, hbreak_command,
6417 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6418 Like \"break\" except the breakpoint requires hardware support,\n\
6419 some target hardware may not have this support.");
6421 add_com ("thbreak", class_breakpoint, thbreak_command,
6422 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6423 Like \"hbreak\" except the breakpoint is only temporary,\n\
6424 so it will be deleted when hit.");
6426 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6427 "Enable some breakpoints.\n\
6428 Give breakpoint numbers (separated by spaces) as arguments.\n\
6429 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6430 This is used to cancel the effect of the \"disable\" command.\n\
6431 With a subcommand you can enable temporarily.",
6432 &enablelist, "enable ", 1, &cmdlist);
6434 add_com("ab", class_breakpoint, enable_command,
6435 "Enable some breakpoints.\n\
6436 Give breakpoint numbers (separated by spaces) as arguments.\n\
6437 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6438 This is used to cancel the effect of the \"disable\" command.\n\
6439 With a subcommand you can enable temporarily.");
6441 add_com_alias ("en", "enable", class_breakpoint, 1);
6443 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
6444 "Enable some breakpoints.\n\
6445 Give breakpoint numbers (separated by spaces) as arguments.\n\
6446 This is used to cancel the effect of the \"disable\" command.\n\
6447 May be abbreviated to simply \"enable\".\n",
6448 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
6450 add_cmd ("once", no_class, enable_once_command,
6451 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6452 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6455 add_cmd ("delete", no_class, enable_delete_command,
6456 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6457 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6460 add_cmd ("delete", no_class, enable_delete_command,
6461 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6462 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6465 add_cmd ("once", no_class, enable_once_command,
6466 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6467 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6470 add_prefix_cmd ("disable", class_breakpoint, disable_command,
6471 "Disable some breakpoints.\n\
6472 Arguments are breakpoint numbers with spaces in between.\n\
6473 To disable all breakpoints, give no argument.\n\
6474 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6475 &disablelist, "disable ", 1, &cmdlist);
6476 add_com_alias ("dis", "disable", class_breakpoint, 1);
6477 add_com_alias ("disa", "disable", class_breakpoint, 1);
6479 add_com("sb", class_breakpoint, disable_command,
6480 "Disable some breakpoints.\n\
6481 Arguments are breakpoint numbers with spaces in between.\n\
6482 To disable all breakpoints, give no argument.\n\
6483 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6485 add_cmd ("breakpoints", class_alias, disable_command,
6486 "Disable some breakpoints.\n\
6487 Arguments are breakpoint numbers with spaces in between.\n\
6488 To disable all breakpoints, give no argument.\n\
6489 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6490 This command may be abbreviated \"disable\".",
6493 add_prefix_cmd ("delete", class_breakpoint, delete_command,
6494 "Delete some breakpoints or auto-display expressions.\n\
6495 Arguments are breakpoint numbers with spaces in between.\n\
6496 To delete all breakpoints, give no argument.\n\
6498 Also a prefix command for deletion of other GDB objects.\n\
6499 The \"unset\" command is also an alias for \"delete\".",
6500 &deletelist, "delete ", 1, &cmdlist);
6501 add_com_alias ("d", "delete", class_breakpoint, 1);
6503 add_com ("db", class_breakpoint, delete_command,
6504 "Delete some breakpoints.\n\
6505 Arguments are breakpoint numbers with spaces in between.\n\
6506 To delete all breakpoints, give no argument.\n");
6508 add_cmd ("breakpoints", class_alias, delete_command,
6509 "Delete some breakpoints or auto-display expressions.\n\
6510 Arguments are breakpoint numbers with spaces in between.\n\
6511 To delete all breakpoints, give no argument.\n\
6512 This command may be abbreviated \"delete\".",
6515 add_com ("clear", class_breakpoint, clear_command,
6516 concat ("Clear breakpoint at specified line or function.\n\
6517 Argument may be line number, function name, or \"*\" and an address.\n\
6518 If line number is specified, all breakpoints in that line are cleared.\n\
6519 If function is specified, breakpoints at beginning of function are cleared.\n\
6520 If an address is specified, breakpoints at that address are cleared.\n\n",
6521 "With no argument, clears all breakpoints in the line that the selected frame\n\
6524 See also the \"delete\" command which clears breakpoints by number.", NULL));
6526 add_com ("break", class_breakpoint, break_command,
6527 concat ("Set breakpoint at specified line or function.\n\
6528 Argument may be line number, function name, or \"*\" and an address.\n\
6529 If line number is specified, break at start of code for that line.\n\
6530 If function is specified, break at start of code for that function.\n\
6531 If an address is specified, break at that exact address.\n",
6532 "With no arg, uses current execution address of selected stack frame.\n\
6533 This is useful for breaking on return to a stack frame.\n\
6535 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6537 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6538 add_com_alias ("b", "break", class_run, 1);
6539 add_com_alias ("br", "break", class_run, 1);
6540 add_com_alias ("bre", "break", class_run, 1);
6541 add_com_alias ("brea", "break", class_run, 1);
6543 add_com("xbreak", class_breakpoint, break_at_finish_command,
6544 concat("Set breakpoint at procedure exit. \n\
6545 Argument may be function name, or \"*\" and an address.\n\
6546 If function is specified, break at end of code for that function.\n\
6547 If an address is specified, break at the end of the function that contains \n\
6548 that exact address.\n",
6549 "With no arg, uses current execution address of selected stack frame.\n\
6550 This is useful for breaking on return to a stack frame.\n\
6552 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6554 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6555 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6556 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6557 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6558 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6562 add_com_alias ("ba", "break", class_breakpoint, 1);
6563 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6564 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
6565 "Set breakpoint at procedure exit. Either there should\n\
6566 be no argument or the argument must be a depth.\n");
6571 add_abbrev_prefix_cmd("stop", class_breakpoint, stop_command,
6572 "Break in function/address or break at a line in the current file.",
6573 &stoplist, "stop ", 1, &cmdlist);
6574 add_cmd("in", class_breakpoint, stopin_command,
6575 "Break in function or address.\n", &stoplist);
6576 add_cmd("at", class_breakpoint, stopat_command,
6577 "Break at a line in the current file.\n", &stoplist);
6578 add_com("status", class_info, breakpoints_info,
6579 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6580 The \"Type\" column indicates one of:\n\
6581 \tbreakpoint - normal breakpoint\n\
6582 \twatchpoint - watchpoint\n\
6583 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6584 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6585 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6586 address and file/line number respectively.\n\n",
6587 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6588 are set to the address of the last breakpoint listed.\n\n\
6589 Convenience variable \"$bpnum\" contains the number of the last\n\
6590 breakpoint set.", NULL));
6593 add_info ("breakpoints", breakpoints_info,
6594 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6595 The \"Type\" column indicates one of:\n\
6596 \tbreakpoint - normal breakpoint\n\
6597 \twatchpoint - watchpoint\n\
6598 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6599 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6600 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6601 address and file/line number respectively.\n\n",
6602 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6603 are set to the address of the last breakpoint listed.\n\n\
6604 Convenience variable \"$bpnum\" contains the number of the last\n\
6605 breakpoint set.", NULL));
6608 add_com("lb", class_breakpoint, breakpoints_info,
6609 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6610 The \"Type\" column indicates one of:\n\
6611 \tbreakpoint - normal breakpoint\n\
6612 \twatchpoint - watchpoint\n\
6613 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6614 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6615 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6616 address and file/line number respectively.\n\n",
6617 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6618 are set to the address of the last breakpoint listed.\n\n\
6619 Convenience variable \"$bpnum\" contains the number of the last\n\
6620 breakpoint set.", NULL));
6622 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
6623 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
6624 The \"Type\" column indicates one of:\n\
6625 \tbreakpoint - normal breakpoint\n\
6626 \twatchpoint - watchpoint\n\
6627 \tlongjmp - internal breakpoint used to step through longjmp()\n\
6628 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6629 \tuntil - internal breakpoint used by the \"until\" command\n\
6630 \tfinish - internal breakpoint used by the \"finish\" command\n",
6631 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6632 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6633 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6634 address and file/line number respectively.\n\n",
6635 "Convenience variable \"$_\" and default examine address for \"x\"\n\
6636 are set to the address of the last breakpoint listed.\n\n\
6637 Convenience variable \"$bpnum\" contains the number of the last\n\
6638 breakpoint set.", NULL),
6639 &maintenanceinfolist);
6641 add_com ("catch", class_breakpoint, catch_command,
6642 "Set catchpoints to catch events.\n\
6643 Raised signals may be caught:\n\
6644 \tcatch signal - all signals\n\
6645 \tcatch signal <signame> - a particular signal\n\
6646 Raised exceptions may be caught:\n\
6647 \tcatch throw - all exceptions, when thrown\n\
6648 \tcatch throw <exceptname> - a particular exception, when thrown\n\
6649 \tcatch catch - all exceptions, when caught\n\
6650 \tcatch catch <exceptname> - a particular exception, when caught\n\
6651 Thread or process events may be caught:\n\
6652 \tcatch thread_start - any threads, just after creation\n\
6653 \tcatch thread_exit - any threads, just before expiration\n\
6654 \tcatch thread_join - any threads, just after joins\n\
6655 Process events may be caught:\n\
6656 \tcatch start - any processes, just after creation\n\
6657 \tcatch exit - any processes, just before expiration\n\
6658 \tcatch fork - calls to fork()\n\
6659 \tcatch vfork - calls to vfork()\n\
6660 \tcatch exec - calls to exec()\n\
6661 Dynamically-linked library events may be caught:\n\
6662 \tcatch load - loads of any library\n\
6663 \tcatch load <libname> - loads of a particular library\n\
6664 \tcatch unload - unloads of any library\n\
6665 \tcatch unload <libname> - unloads of a particular library\n\
6666 The act of your program's execution stopping may also be caught:\n\
6668 C++ exceptions may be caught:\n\
6669 \tcatch throw - all exceptions, when thrown\n\
6670 \tcatch catch - all exceptions, when caught\n\
6672 Do \"help set follow-fork-mode\" for info on debugging your program\n\
6673 after a fork or vfork is caught.\n\n\
6674 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
6676 add_com ("tcatch", class_breakpoint, tcatch_command,
6677 "Set temporary catchpoints to catch events.\n\
6678 Args like \"catch\" command.\n\
6679 Like \"catch\" except the catchpoint is only temporary,\n\
6680 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6681 by using \"enable delete\" on the catchpoint number.");
6683 add_com ("watch", class_breakpoint, watch_command,
6685 "Set a watchpoint for an expression.\n\
6686 A watchpoint stops execution of your program whenever the value of\n\
6687 an expression changes.");
6689 add_com ("rwatch", class_breakpoint, rwatch_command,
6690 "Set a read watchpoint for an expression.\n\
6691 A watchpoint stops execution of your program whenever the value of\n\
6692 an expression is read.");
6694 add_com ("awatch", class_breakpoint, awatch_command,
6695 "Set a watchpoint for an expression.\n\
6696 A watchpoint stops execution of your program whenever the value of\n\
6697 an expression is either read or written.");
6699 add_info ("watchpoints", breakpoints_info,
6700 "Synonym for ``info breakpoints''.");
6703 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
6704 (char *) &can_use_hw_watchpoints,
6705 "Set debugger's willingness to use watchpoint hardware.\n\
6706 If zero, gdb will not use hardware for new watchpoints, even if\n\
6707 such is available. (However, any hardware watchpoints that were\n\
6708 created before setting this to nonzero, will continue to use watchpoint\n\
6711 add_show_from_set (c, &showlist);
6713 can_use_hw_watchpoints = 1;