1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg *arg);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint *);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint *);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value *);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint *);
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
98 static void check_duplicates (struct breakpoint *);
100 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
102 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr);
104 static void describe_other_breakpoints (CORE_ADDR, asection *);
106 static void breakpoints_info (char *, int);
108 static void breakpoint_1 (int, int);
110 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
112 static int breakpoint_cond_eval (void *);
114 static void cleanup_executing_breakpoints (void *);
116 static void commands_command (char *, int);
118 static void condition_command (char *, int);
120 static int get_number_trailer (char **, int);
122 void set_breakpoint_count (int);
131 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
133 static enum print_stop_action print_it_typical (bpstat);
135 static enum print_stop_action print_bp_stop_message (bpstat bs);
139 enum exception_event_kind kind;
142 args_for_catchpoint_enable;
144 static int watchpoint_check (void *);
146 static int cover_target_enable_exception_callback (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
170 static void solib_load_unload_1 (char *hookname,
173 char *cond_string, enum bptype bp_kind);
175 static void create_fork_vfork_event_catchpoint (int tempflag,
177 enum bptype bp_kind);
179 static void break_at_finish_at_depth_command_1 (char *arg,
180 int flag, int from_tty);
182 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_find_event_name_end (char *arg);
192 static char *ep_parse_optional_if_clause (char **arg);
194 static char *ep_parse_optional_filename (char **arg);
196 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
197 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
200 static void create_exception_catchpoint (int tempflag, char *cond_string,
201 enum exception_event_kind ex_event,
202 struct symtab_and_line *sal);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event,
205 char *arg, int tempflag, int from_tty);
207 static void tcatch_command (char *arg, int from_tty);
209 static void ep_skip_leading_whitespace (char **s);
211 /* Prototypes for exported functions. */
213 /* If FALSE, gdb will not use hardware support for watchpoints, even
214 if such is available. */
215 static int can_use_hw_watchpoints;
217 void _initialize_breakpoint (void);
219 extern int addressprint; /* Print machine addresses? */
221 /* Are we executing breakpoint commands? */
222 static int executing_breakpoint_commands;
224 /* Are overlay event breakpoints enabled? */
225 static int overlay_events_enabled;
227 /* Walk the following statement or block through all breakpoints.
228 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
231 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
233 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
234 for (B = breakpoint_chain; \
235 B ? (TMP=B->next, 1): 0; \
238 /* True if SHIFT_INST_REGS defined, false otherwise. */
240 int must_shift_inst_regs =
241 #if defined(SHIFT_INST_REGS)
248 /* True if breakpoint hit counts should be displayed in breakpoint info. */
250 int show_breakpoint_hit_counts = 1;
252 /* Chain of all breakpoints defined. */
254 struct breakpoint *breakpoint_chain;
256 /* Number of last breakpoint made. */
258 int breakpoint_count;
260 /* Pointer to current exception event record */
261 static struct exception_event_record *current_exception_event;
263 /* Indicator of whether exception catchpoints should be nuked
264 between runs of a program */
265 int exception_catchpoints_are_fragile = 0;
267 /* Indicator of when exception catchpoints set-up should be
268 reinitialized -- e.g. when program is re-run */
269 int exception_support_initialized = 0;
271 /* This function returns a pointer to the string representation of the
272 pathname of the dynamically-linked library that has just been
275 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
276 or undefined results are guaranteed.
278 This string's contents are only valid immediately after the
279 inferior has stopped in the dynamic linker hook, and becomes
280 invalid as soon as the inferior is continued. Clients should make
281 a copy of this string if they wish to continue the inferior and
282 then access the string. */
284 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
285 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
288 /* This function returns a pointer to the string representation of the
289 pathname of the dynamically-linked library that has just been
292 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
293 TRUE, or undefined results are guaranteed.
295 This string's contents are only valid immediately after the
296 inferior has stopped in the dynamic linker hook, and becomes
297 invalid as soon as the inferior is continued. Clients should make
298 a copy of this string if they wish to continue the inferior and
299 then access the string. */
301 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
302 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
305 /* This function is called by the "catch load" command. It allows the
306 debugger to be notified by the dynamic linker when a specified
307 library file (or any library file, if filename is NULL) is loaded. */
309 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
310 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
311 error ("catch of library loads not yet implemented on this platform")
314 /* This function is called by the "catch unload" command. It allows
315 the debugger to be notified by the dynamic linker when a specified
316 library file (or any library file, if filename is NULL) is
319 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
320 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
321 error ("catch of library unloads not yet implemented on this platform")
324 /* Set breakpoint count to NUM. */
327 set_breakpoint_count (int num)
329 breakpoint_count = num;
330 set_internalvar (lookup_internalvar ("bpnum"),
331 value_from_longest (builtin_type_int, (LONGEST) num));
334 /* Used in run_command to zero the hit count when a new run starts. */
337 clear_breakpoint_hit_counts (void)
339 struct breakpoint *b;
345 /* Default address, symtab and line to put a breakpoint at
346 for "break" command with no arg.
347 if default_breakpoint_valid is zero, the other three are
348 not valid, and "break" with no arg is an error.
350 This set by print_stack_frame, which calls set_default_breakpoint. */
352 int default_breakpoint_valid;
353 CORE_ADDR default_breakpoint_address;
354 struct symtab *default_breakpoint_symtab;
355 int default_breakpoint_line;
357 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
358 Advance *PP after the string and any trailing whitespace.
360 Currently the string can either be a number or "$" followed by the name
361 of a convenience variable. Making it an expression wouldn't work well
362 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
364 TRAILER is a character which can be found after the number; most
365 commonly this is `-'. If you don't want a trailer, use \0. */
367 get_number_trailer (char **pp, int trailer)
369 int retval = 0; /* default */
373 /* Empty line means refer to the last breakpoint. */
374 return breakpoint_count;
377 /* Make a copy of the name, so we can null-terminate it
378 to pass to lookup_internalvar(). */
383 while (isalnum (*p) || *p == '_')
385 varname = (char *) alloca (p - start + 1);
386 strncpy (varname, start, p - start);
387 varname[p - start] = '\0';
388 val = value_of_internalvar (lookup_internalvar (varname));
389 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
390 retval = (int) value_as_long (val);
393 printf_filtered ("Convenience variable must have integer value.\n");
401 while (*p >= '0' && *p <= '9')
404 /* There is no number here. (e.g. "cond a == b"). */
406 /* Skip non-numeric token */
407 while (*p && !isspace((int) *p))
409 /* Return zero, which caller must interpret as error. */
415 if (!(isspace (*p) || *p == '\0' || *p == trailer))
417 /* Trailing junk: return 0 and let caller print error msg. */
418 while (!(isspace (*p) || *p == '\0' || *p == trailer))
429 /* Like get_number_trailer, but don't allow a trailer. */
431 get_number (char **pp)
433 return get_number_trailer (pp, '\0');
436 /* Parse a number or a range.
437 * A number will be of the form handled by get_number.
438 * A range will be of the form <number1> - <number2>, and
439 * will represent all the integers between number1 and number2,
442 * While processing a range, this fuction is called iteratively;
443 * At each call it will return the next value in the range.
445 * At the beginning of parsing a range, the char pointer PP will
446 * be advanced past <number1> and left pointing at the '-' token.
447 * Subsequent calls will not advance the pointer until the range
448 * is completed. The call that completes the range will advance
449 * pointer PP past <number2>.
453 get_number_or_range (char **pp)
455 static int last_retval, end_value;
456 static char *end_ptr;
457 static int in_range = 0;
461 /* Default case: pp is pointing either to a solo number,
462 or to the first number of a range. */
463 last_retval = get_number_trailer (pp, '-');
468 /* This is the start of a range (<number1> - <number2>).
469 Skip the '-', parse and remember the second number,
470 and also remember the end of the final token. */
474 while (isspace ((int) *end_ptr))
475 end_ptr++; /* skip white space */
476 end_value = get_number (temp);
477 if (end_value < last_retval)
479 error ("inverted range");
481 else if (end_value == last_retval)
483 /* degenerate range (number1 == number2). Advance the
484 token pointer so that the range will be treated as a
493 error ("negative value");
496 /* pp points to the '-' that betokens a range. All
497 number-parsing has already been done. Return the next
498 integer value (one greater than the saved previous value).
499 Do not advance the token pointer 'pp' until the end of range
502 if (++last_retval == end_value)
504 /* End of range reached; advance token pointer. */
514 /* condition N EXP -- set break condition of breakpoint N to EXP. */
517 condition_command (char *arg, int from_tty)
519 struct breakpoint *b;
524 error_no_arg ("breakpoint number");
527 bnum = get_number (&p);
529 error ("Bad breakpoint argument: '%s'", arg);
532 if (b->number == bnum)
539 if (b->cond_string != NULL)
540 xfree (b->cond_string);
545 b->cond_string = NULL;
547 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
552 /* I don't know if it matters whether this is the string the user
553 typed in or the decompiled expression. */
554 b->cond_string = savestring (arg, strlen (arg));
555 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
557 error ("Junk at end of expression");
559 breakpoints_changed ();
560 breakpoint_modify_event (b->number);
564 error ("No breakpoint number %d.", bnum);
568 commands_command (char *arg, int from_tty)
570 struct breakpoint *b;
573 struct command_line *l;
575 /* If we allowed this, we would have problems with when to
576 free the storage, if we change the commands currently
579 if (executing_breakpoint_commands)
580 error ("Can't use the \"commands\" command among a breakpoint's commands.");
583 bnum = get_number (&p);
586 error ("Unexpected extra arguments following breakpoint number.");
589 if (b->number == bnum)
591 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
593 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
594 l = read_command_lines (tmpbuf, from_tty);
595 do_cleanups (cleanups);
596 free_command_lines (&b->commands);
598 breakpoints_changed ();
599 breakpoint_modify_event (b->number);
602 error ("No breakpoint number %d.", bnum);
605 /* Like target_read_memory() but if breakpoints are inserted, return
606 the shadow contents instead of the breakpoints themselves.
608 Read "memory data" from whatever target or inferior we have.
609 Returns zero if successful, errno value if not. EIO is used
610 for address out of bounds. If breakpoints are inserted, returns
611 shadow contents, not the breakpoints themselves. From breakpoint.c. */
614 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
617 struct breakpoint *b;
618 CORE_ADDR bp_addr = 0;
621 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
622 /* No breakpoints on this machine. */
623 return target_read_memory (memaddr, myaddr, len);
627 if (b->type == bp_none)
628 warning ("reading through apparently deleted breakpoint #%d?",
631 /* memory breakpoint? */
632 if (b->type == bp_watchpoint
633 || b->type == bp_hardware_watchpoint
634 || b->type == bp_read_watchpoint
635 || b->type == bp_access_watchpoint)
640 /* Addresses and length of the part of the breakpoint that
642 /* XXXX The m68k, sh and h8300 have different local and remote
643 breakpoint values. BREAKPOINT_FROM_PC still manages to
644 correctly determine the breakpoints memory address and size
645 for these targets. */
646 bp_addr = b->address;
648 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
653 if (bp_addr + bp_size <= memaddr)
654 /* The breakpoint is entirely before the chunk of memory we
657 if (bp_addr >= memaddr + len)
658 /* The breakpoint is entirely after the chunk of memory we are
661 /* Copy the breakpoint from the shadow contents, and recurse for
662 the things before and after. */
664 /* Offset within shadow_contents. */
667 if (bp_addr < memaddr)
669 /* Only copy the second part of the breakpoint. */
670 bp_size -= memaddr - bp_addr;
671 bptoffset = memaddr - bp_addr;
675 if (bp_addr + bp_size > memaddr + len)
677 /* Only copy the first part of the breakpoint. */
678 bp_size -= (bp_addr + bp_size) - (memaddr + len);
681 memcpy (myaddr + bp_addr - memaddr,
682 b->shadow_contents + bptoffset, bp_size);
684 if (bp_addr > memaddr)
686 /* Copy the section of memory before the breakpoint. */
687 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
692 if (bp_addr + bp_size < memaddr + len)
694 /* Copy the section of memory after the breakpoint. */
695 status = read_memory_nobpt (bp_addr + bp_size,
696 myaddr + bp_addr + bp_size - memaddr,
697 memaddr + len - (bp_addr + bp_size));
704 /* Nothing overlaps. Just call read_memory_noerr. */
705 return target_read_memory (memaddr, myaddr, len);
709 /* A wrapper function for inserting catchpoints. */
711 insert_catchpoint (struct ui_out *uo, void *args)
713 struct breakpoint *b = (struct breakpoint *) args;
719 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
722 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
725 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
728 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
733 throw_exception (RETURN_ERROR);
738 /* insert_breakpoints is used when starting or continuing the program.
739 remove_breakpoints is used when the program stops.
740 Both return zero if successful,
741 or an `errno' value if could not write the inferior. */
744 insert_breakpoints (void)
746 struct breakpoint *b, *temp;
747 int return_val = 0; /* return success code. */
749 int disabled_breaks = 0;
750 int hw_breakpoint_error = 0;
751 #ifdef ONE_PROCESS_WRITETEXT
752 int process_warning = 0;
755 struct ui_file *tmp_error_stream = mem_fileopen ();
756 make_cleanup_ui_file_delete (tmp_error_stream);
758 /* Explicitly mark the warning -- this will only be printed if
759 there was an error. */
760 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
762 ALL_BREAKPOINTS_SAFE (b, temp)
764 /* Permanent breakpoints cannot be inserted or removed. Disabled
765 breakpoints should not be inserted. */
766 if (b->enable_state != bp_enabled)
769 if ((b->type == bp_watchpoint
770 || b->type == bp_hardware_watchpoint
771 || b->type == bp_read_watchpoint
772 || b->type == bp_access_watchpoint) && (!b->val))
775 val = evaluate_expression (b->exp);
777 if (VALUE_LAZY (val))
778 value_fetch_lazy (val);
781 if (b->type != bp_watchpoint
782 && b->type != bp_hardware_watchpoint
783 && b->type != bp_read_watchpoint
784 && b->type != bp_access_watchpoint
785 && b->type != bp_catch_fork
786 && b->type != bp_catch_vfork
787 && b->type != bp_catch_exec
788 && b->type != bp_catch_throw
789 && b->type != bp_catch_catch
793 /* "Normal" instruction breakpoint: either the standard
794 trap-instruction bp (bp_breakpoint), or a
795 bp_hardware_breakpoint. */
797 /* First check to see if we have to handle an overlay. */
798 if (overlay_debugging == ovly_off
799 || b->section == NULL
800 || !(section_is_overlay (b->section)))
802 /* No overlay handling: just set the breakpoint. */
804 if (b->type == bp_hardware_breakpoint)
805 val = target_insert_hw_breakpoint (b->address,
808 val = target_insert_breakpoint (b->address, b->shadow_contents);
812 /* This breakpoint is in an overlay section.
813 Shall we set a breakpoint at the LMA? */
814 if (!overlay_events_enabled)
816 /* Yes -- overlay event support is not active,
817 so we must try to set a breakpoint at the LMA.
818 This will not work for a hardware breakpoint. */
819 if (b->type == bp_hardware_breakpoint)
820 warning ("hardware breakpoint %d not supported in overlay!\n",
824 CORE_ADDR addr = overlay_unmapped_address (b->address,
826 /* Set a software (trap) breakpoint at the LMA. */
827 val = target_insert_breakpoint (addr, b->shadow_contents);
829 fprintf_unfiltered (tmp_error_stream,
830 "Overlay breakpoint %d failed: in ROM?",
834 /* Shall we set a breakpoint at the VMA? */
835 if (section_is_mapped (b->section))
837 /* Yes. This overlay section is mapped into memory. */
838 if (b->type == bp_hardware_breakpoint)
839 val = target_insert_hw_breakpoint (b->address,
842 val = target_insert_breakpoint (b->address,
847 /* No. This breakpoint will not be inserted.
848 No error, but do not mark the bp as 'inserted'. */
855 /* Can't set the breakpoint. */
856 #if defined (DISABLE_UNSETTABLE_BREAK)
857 if (DISABLE_UNSETTABLE_BREAK (b->address))
859 /* See also: disable_breakpoints_in_shlibs. */
861 b->enable_state = bp_shlib_disabled;
862 if (!disabled_breaks)
864 fprintf_unfiltered (tmp_error_stream,
865 "Cannot insert breakpoint %d.\n",
867 fprintf_unfiltered (tmp_error_stream,
868 "Temporarily disabling shared library breakpoints:\n");
871 fprintf_unfiltered (tmp_error_stream,
872 "breakpoint #%d\n", b->number);
877 #ifdef ONE_PROCESS_WRITETEXT
880 if (b->type == bp_hardware_breakpoint)
882 hw_breakpoint_error = 1;
883 fprintf_unfiltered (tmp_error_stream,
884 "Cannot insert hardware breakpoint %d.\n",
889 fprintf_unfiltered (tmp_error_stream,
890 "Cannot insert breakpoint %d.\n",
892 fprintf_filtered (tmp_error_stream,
893 "Error accessing memory address ");
894 print_address_numeric (b->address, 1, tmp_error_stream);
895 fprintf_filtered (tmp_error_stream, ": %s.\n",
896 safe_strerror (val));
905 return_val = val; /* remember failure */
907 else if (ep_is_exception_catchpoint (b)
912 /* If we get here, we must have a callback mechanism for exception
913 events -- with g++ style embedded label support, we insert
914 ordinary breakpoints and not catchpoints. */
915 val = target_insert_breakpoint (b->address, b->shadow_contents);
918 /* Couldn't set breakpoint for some reason */
919 fprintf_unfiltered (tmp_error_stream,
920 "Cannot insert catchpoint %d; disabling it.\n",
922 fprintf_filtered (tmp_error_stream,
923 "Error accessing memory address ");
924 print_address_numeric (b->address, 1, tmp_error_stream);
925 fprintf_filtered (tmp_error_stream, ": %s.\n",
926 safe_strerror (val));
927 b->enable_state = bp_disabled;
931 /* Bp set, now make sure callbacks are enabled */
932 /* Format possible error msg */
933 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
935 struct cleanup *cleanups = make_cleanup (xfree, message);
937 args_for_catchpoint_enable args;
938 args.kind = b->type == bp_catch_catch ?
939 EX_EVENT_CATCH : EX_EVENT_THROW;
941 val = catch_errors (cover_target_enable_exception_callback,
942 &args, message, RETURN_MASK_ALL);
943 do_cleanups (cleanups);
944 if (val != 0 && val != -1)
948 /* Check if something went wrong; val == 0 can be ignored */
951 /* something went wrong */
952 fprintf_unfiltered (tmp_error_stream,
953 "Cannot insert catchpoint %d; disabling it.\n",
955 b->enable_state = bp_disabled;
960 return_val = val; /* remember failure */
963 else if ((b->type == bp_hardware_watchpoint ||
964 b->type == bp_read_watchpoint ||
965 b->type == bp_access_watchpoint)
966 && b->disposition != disp_del_at_next_stop
970 struct frame_info *saved_frame;
971 int saved_level, within_current_scope;
972 struct value *mark = value_mark ();
975 /* Save the current frame and level so we can restore it after
976 evaluating the watchpoint expression on its own frame. */
977 saved_frame = deprecated_selected_frame;
978 saved_level = frame_relative_level (deprecated_selected_frame);
980 /* Determine if the watchpoint is within scope. */
981 if (b->exp_valid_block == NULL)
982 within_current_scope = 1;
985 struct frame_info *fi;
986 fi = frame_find_by_id (b->watchpoint_frame);
987 within_current_scope = (fi != NULL);
988 if (within_current_scope)
992 if (within_current_scope)
994 /* Evaluate the expression and cut the chain of values
995 produced off from the value chain.
997 Make sure the value returned isn't lazy; we use
998 laziness to determine what memory GDB actually needed
999 in order to compute the value of the expression. */
1000 v = evaluate_expression (b->exp);
1002 value_release_to_mark (mark);
1007 /* Look at each value on the value chain. */
1008 for (; v; v = v->next)
1010 /* If it's a memory location, and GDB actually needed
1011 its contents to evaluate the expression, then we
1013 if (VALUE_LVAL (v) == lval_memory
1014 && ! VALUE_LAZY (v))
1016 struct type *vtype = check_typedef (VALUE_TYPE (v));
1018 /* We only watch structs and arrays if user asked
1019 for it explicitly, never if they just happen to
1020 appear in the middle of some value chain. */
1021 if (v == b->val_chain
1022 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1023 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1028 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1029 len = TYPE_LENGTH (VALUE_TYPE (v));
1031 if (b->type == bp_read_watchpoint)
1033 else if (b->type == bp_access_watchpoint)
1036 val = target_insert_watchpoint (addr, len, type);
1039 /* Don't exit the loop, try to insert
1040 every value on the value chain. That's
1041 because we will be removing all the
1042 watches below, and removing a
1043 watchpoint we didn't insert could have
1051 /* Failure to insert a watchpoint on any memory value in the
1052 value chain brings us here. */
1055 remove_breakpoint (b, mark_uninserted);
1056 hw_breakpoint_error = 1;
1057 fprintf_unfiltered (tmp_error_stream,
1058 "Could not insert hardware watchpoint %d.\n",
1065 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1066 printf_filtered ("because the program has left the block \n");
1067 printf_filtered ("in which its expression is valid.\n");
1068 if (b->related_breakpoint)
1069 b->related_breakpoint->disposition = disp_del_at_next_stop;
1070 b->disposition = disp_del_at_next_stop;
1073 /* Restore the frame and level. */
1074 if ((saved_frame != deprecated_selected_frame) ||
1075 (saved_level != frame_relative_level (deprecated_selected_frame)))
1076 select_frame (saved_frame);
1079 return_val = val; /* remember failure */
1081 else if ((b->type == bp_catch_fork
1082 || b->type == bp_catch_vfork
1083 || b->type == bp_catch_exec)
1087 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
1089 struct cleanup *cleanups = make_cleanup (xfree, prefix);
1090 val = catch_exceptions (uiout, insert_catchpoint, b, prefix,
1092 do_cleanups (cleanups);
1094 b->enable_state = bp_disabled;
1102 /* If a hardware breakpoint or watchpoint was inserted, add a
1103 message about possibly exhausted resources. */
1104 if (hw_breakpoint_error)
1106 fprintf_unfiltered (tmp_error_stream,
1107 "Could not insert hardware breakpoints:\n\
1108 You may have requested too many hardware breakpoints/watchpoints.\n");
1110 #ifdef ONE_PROCESS_WRITETEXT
1111 if (process_warning)
1112 fprintf_unfiltered (tmp_error_stream,
1113 "The same program may be running in another process.");
1115 target_terminal_ours_for_output ();
1116 error_stream (tmp_error_stream);
1122 remove_breakpoints (void)
1124 struct breakpoint *b;
1131 val = remove_breakpoint (b, mark_uninserted);
1140 remove_hw_watchpoints (void)
1142 struct breakpoint *b;
1148 && (b->type == bp_hardware_watchpoint
1149 || b->type == bp_read_watchpoint
1150 || b->type == bp_access_watchpoint))
1152 val = remove_breakpoint (b, mark_uninserted);
1161 reattach_breakpoints (int pid)
1163 struct breakpoint *b;
1165 struct cleanup *old_chain = save_inferior_ptid ();
1167 /* Set inferior_ptid; remove_breakpoint uses this global. */
1168 inferior_ptid = pid_to_ptid (pid);
1173 remove_breakpoint (b, mark_inserted);
1174 if (b->type == bp_hardware_breakpoint)
1175 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1177 val = target_insert_breakpoint (b->address, b->shadow_contents);
1180 do_cleanups (old_chain);
1185 do_cleanups (old_chain);
1190 update_breakpoints_after_exec (void)
1192 struct breakpoint *b;
1193 struct breakpoint *temp;
1195 /* Doing this first prevents the badness of having delete_breakpoint()
1196 write a breakpoint's current "shadow contents" to lift the bp. That
1197 shadow is NOT valid after an exec()! */
1198 mark_breakpoints_out ();
1200 ALL_BREAKPOINTS_SAFE (b, temp)
1202 /* Solib breakpoints must be explicitly reset after an exec(). */
1203 if (b->type == bp_shlib_event)
1205 delete_breakpoint (b);
1209 /* Thread event breakpoints must be set anew after an exec(),
1210 as must overlay event breakpoints. */
1211 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1213 delete_breakpoint (b);
1217 /* Step-resume breakpoints are meaningless after an exec(). */
1218 if (b->type == bp_step_resume)
1220 delete_breakpoint (b);
1224 /* Ditto the sigtramp handler breakpoints. */
1225 if (b->type == bp_through_sigtramp)
1227 delete_breakpoint (b);
1231 /* Ditto the exception-handling catchpoints. */
1232 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1234 delete_breakpoint (b);
1238 /* Don't delete an exec catchpoint, because else the inferior
1239 won't stop when it ought!
1241 Similarly, we probably ought to keep vfork catchpoints, 'cause
1242 on this target, we may not be able to stop when the vfork is
1243 seen, but only when the subsequent exec is seen. (And because
1244 deleting fork catchpoints here but not vfork catchpoints will
1245 seem mysterious to users, keep those too.)
1247 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1248 target address field, if any, is sufficient to have it be reset
1249 automagically. Certainly on HP-UX that's true.
1251 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1252 valid code address on some platforms (like the mn10300
1253 simulators). We shouldn't assign any special interpretation to
1254 a breakpoint with a zero address. And in fact, GDB doesn't ---
1255 I can't see what that comment above is talking about. As far
1256 as I can tell, setting the address of a
1257 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1258 is meaningless, since those are implemented with HP-UX kernel
1259 hackery, not by storing breakpoint instructions somewhere. */
1260 if ((b->type == bp_catch_exec) ||
1261 (b->type == bp_catch_vfork) ||
1262 (b->type == bp_catch_fork))
1264 b->address = (CORE_ADDR) NULL;
1268 /* bp_finish is a special case. The only way we ought to be able
1269 to see one of these when an exec() has happened, is if the user
1270 caught a vfork, and then said "finish". Ordinarily a finish just
1271 carries them to the call-site of the current callee, by setting
1272 a temporary bp there and resuming. But in this case, the finish
1273 will carry them entirely through the vfork & exec.
1275 We don't want to allow a bp_finish to remain inserted now. But
1276 we can't safely delete it, 'cause finish_command has a handle to
1277 the bp on a bpstat, and will later want to delete it. There's a
1278 chance (and I've seen it happen) that if we delete the bp_finish
1279 here, that its storage will get reused by the time finish_command
1280 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1281 We really must allow finish_command to delete a bp_finish.
1283 In the absense of a general solution for the "how do we know
1284 it's safe to delete something others may have handles to?"
1285 problem, what we'll do here is just uninsert the bp_finish, and
1286 let finish_command delete it.
1288 (We know the bp_finish is "doomed" in the sense that it's
1289 momentary, and will be deleted as soon as finish_command sees
1290 the inferior stopped. So it doesn't matter that the bp's
1291 address is probably bogus in the new a.out, unlike e.g., the
1292 solib breakpoints.) */
1294 if (b->type == bp_finish)
1299 /* Without a symbolic address, we have little hope of the
1300 pre-exec() address meaning the same thing in the post-exec()
1302 if (b->addr_string == NULL)
1304 delete_breakpoint (b);
1308 /* If this breakpoint has survived the above battery of checks, then
1309 it must have a symbolic address. Be sure that it gets reevaluated
1310 to a target address, rather than reusing the old evaluation.
1312 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1313 for bp_catch_exec and friends, I'm pretty sure this is entirely
1314 unnecessary. A call to breakpoint_re_set_one always recomputes
1315 the breakpoint's address from scratch, or deletes it if it can't.
1316 So I think this assignment could be deleted without effect. */
1317 b->address = (CORE_ADDR) NULL;
1319 /* FIXME what about longjmp breakpoints? Re-create them here? */
1320 create_overlay_event_breakpoint ("_ovly_debug_event");
1324 detach_breakpoints (int pid)
1326 struct breakpoint *b;
1328 struct cleanup *old_chain = save_inferior_ptid ();
1330 if (pid == PIDGET (inferior_ptid))
1331 error ("Cannot detach breakpoints of inferior_ptid");
1333 /* Set inferior_ptid; remove_breakpoint uses this global. */
1334 inferior_ptid = pid_to_ptid (pid);
1339 val = remove_breakpoint (b, mark_inserted);
1342 do_cleanups (old_chain);
1347 do_cleanups (old_chain);
1352 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1356 if (b->enable_state == bp_permanent)
1357 /* Permanent breakpoints cannot be inserted or removed. */
1360 if (b->type == bp_none)
1361 warning ("attempted to remove apparently deleted breakpoint #%d?",
1364 if (b->type != bp_watchpoint
1365 && b->type != bp_hardware_watchpoint
1366 && b->type != bp_read_watchpoint
1367 && b->type != bp_access_watchpoint
1368 && b->type != bp_catch_fork
1369 && b->type != bp_catch_vfork
1370 && b->type != bp_catch_exec
1371 && b->type != bp_catch_catch
1372 && b->type != bp_catch_throw)
1374 /* "Normal" instruction breakpoint: either the standard
1375 trap-instruction bp (bp_breakpoint), or a
1376 bp_hardware_breakpoint. */
1378 /* First check to see if we have to handle an overlay. */
1379 if (overlay_debugging == ovly_off
1380 || b->section == NULL
1381 || !(section_is_overlay (b->section)))
1383 /* No overlay handling: just remove the breakpoint. */
1385 if (b->type == bp_hardware_breakpoint)
1386 val = target_remove_hw_breakpoint (b->address,
1387 b->shadow_contents);
1389 val = target_remove_breakpoint (b->address, b->shadow_contents);
1393 /* This breakpoint is in an overlay section.
1394 Did we set a breakpoint at the LMA? */
1395 if (!overlay_events_enabled)
1397 /* Yes -- overlay event support is not active, so we
1398 should have set a breakpoint at the LMA. Remove it.
1400 CORE_ADDR addr = overlay_unmapped_address (b->address,
1402 /* Ignore any failures: if the LMA is in ROM, we will
1403 have already warned when we failed to insert it. */
1404 if (b->type != bp_hardware_breakpoint)
1405 target_remove_hw_breakpoint (addr, b->shadow_contents);
1407 target_remove_breakpoint (addr, b->shadow_contents);
1409 /* Did we set a breakpoint at the VMA?
1410 If so, we will have marked the breakpoint 'inserted'. */
1413 /* Yes -- remove it. Previously we did not bother to
1414 remove the breakpoint if the section had been
1415 unmapped, but let's not rely on that being safe. We
1416 don't know what the overlay manager might do. */
1417 if (b->type == bp_hardware_breakpoint)
1418 val = target_remove_hw_breakpoint (b->address,
1419 b->shadow_contents);
1421 val = target_remove_breakpoint (b->address,
1422 b->shadow_contents);
1426 /* No -- not inserted, so no need to remove. No error. */
1432 b->inserted = (is == mark_inserted);
1434 else if ((b->type == bp_hardware_watchpoint ||
1435 b->type == bp_read_watchpoint ||
1436 b->type == bp_access_watchpoint)
1437 && b->enable_state == bp_enabled
1443 b->inserted = (is == mark_inserted);
1444 /* Walk down the saved value chain. */
1445 for (v = b->val_chain; v; v = v->next)
1447 /* For each memory reference remove the watchpoint
1449 if (VALUE_LVAL (v) == lval_memory
1450 && ! VALUE_LAZY (v))
1452 struct type *vtype = check_typedef (VALUE_TYPE (v));
1454 if (v == b->val_chain
1455 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1456 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1461 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1462 len = TYPE_LENGTH (VALUE_TYPE (v));
1464 if (b->type == bp_read_watchpoint)
1466 else if (b->type == bp_access_watchpoint)
1469 val = target_remove_watchpoint (addr, len, type);
1476 /* Failure to remove any of the hardware watchpoints comes here. */
1477 if ((is == mark_uninserted) && (b->inserted))
1478 warning ("Could not remove hardware watchpoint %d.",
1481 /* Free the saved value chain. We will construct a new one
1482 the next time the watchpoint is inserted. */
1483 for (v = b->val_chain; v; v = n)
1488 b->val_chain = NULL;
1490 else if ((b->type == bp_catch_fork ||
1491 b->type == bp_catch_vfork ||
1492 b->type == bp_catch_exec)
1493 && b->enable_state == bp_enabled
1500 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1502 case bp_catch_vfork:
1503 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1506 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1509 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1514 b->inserted = (is == mark_inserted);
1516 else if ((b->type == bp_catch_catch ||
1517 b->type == bp_catch_throw)
1518 && b->enable_state == bp_enabled
1522 val = target_remove_breakpoint (b->address, b->shadow_contents);
1525 b->inserted = (is == mark_inserted);
1527 else if (ep_is_exception_catchpoint (b)
1528 && b->inserted /* sometimes previous insert doesn't happen */
1529 && b->enable_state == bp_enabled
1533 val = target_remove_breakpoint (b->address, b->shadow_contents);
1537 b->inserted = (is == mark_inserted);
1543 /* Clear the "inserted" flag in all breakpoints. */
1546 mark_breakpoints_out (void)
1548 struct breakpoint *b;
1554 /* Clear the "inserted" flag in all breakpoints and delete any
1555 breakpoints which should go away between runs of the program.
1557 Plus other such housekeeping that has to be done for breakpoints
1560 Note: this function gets called at the end of a run (by
1561 generic_mourn_inferior) and when a run begins (by
1562 init_wait_for_inferior). */
1567 breakpoint_init_inferior (enum inf_context context)
1569 struct breakpoint *b, *temp;
1570 static int warning_needed = 0;
1572 ALL_BREAKPOINTS_SAFE (b, temp)
1579 case bp_watchpoint_scope:
1581 /* If the call dummy breakpoint is at the entry point it will
1582 cause problems when the inferior is rerun, so we better
1585 Also get rid of scope breakpoints. */
1586 delete_breakpoint (b);
1590 case bp_hardware_watchpoint:
1591 case bp_read_watchpoint:
1592 case bp_access_watchpoint:
1594 /* Likewise for watchpoints on local expressions. */
1595 if (b->exp_valid_block != NULL)
1596 delete_breakpoint (b);
1597 if (context == inf_starting)
1599 /* Reset val field to force reread of starting value
1600 in insert_breakpoints. */
1602 value_free (b->val);
1607 /* Likewise for exception catchpoints in dynamic-linked
1608 executables where required */
1609 if (ep_is_exception_catchpoint (b) &&
1610 exception_catchpoints_are_fragile)
1613 delete_breakpoint (b);
1619 if (exception_catchpoints_are_fragile)
1620 exception_support_initialized = 0;
1622 /* Don't issue the warning unless it's really needed... */
1623 if (warning_needed && (context != inf_exited))
1625 warning ("Exception catchpoints from last run were deleted.");
1626 warning ("You must reinsert them explicitly.");
1631 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1632 exists at PC. It returns ordinary_breakpoint_here if it's an
1633 ordinary breakpoint, or permanent_breakpoint_here if it's a
1634 permanent breakpoint.
1635 - When continuing from a location with an ordinary breakpoint, we
1636 actually single step once before calling insert_breakpoints.
1637 - When continuing from a localion with a permanent breakpoint, we
1638 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1639 the target, to advance the PC past the breakpoint. */
1641 enum breakpoint_here
1642 breakpoint_here_p (CORE_ADDR pc)
1644 struct breakpoint *b;
1645 int any_breakpoint_here = 0;
1648 if ((b->enable_state == bp_enabled
1649 || b->enable_state == bp_permanent)
1650 && b->address == pc) /* bp is enabled and matches pc */
1652 if (overlay_debugging
1653 && section_is_overlay (b->section)
1654 && !section_is_mapped (b->section))
1655 continue; /* unmapped overlay -- can't be a match */
1656 else if (b->enable_state == bp_permanent)
1657 return permanent_breakpoint_here;
1659 any_breakpoint_here = 1;
1662 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1666 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1667 but it only returns true if there is actually a breakpoint inserted
1671 breakpoint_inserted_here_p (CORE_ADDR pc)
1673 struct breakpoint *b;
1677 && b->address == pc) /* bp is inserted and matches pc */
1679 if (overlay_debugging
1680 && section_is_overlay (b->section)
1681 && !section_is_mapped (b->section))
1682 continue; /* unmapped overlay -- can't be a match */
1690 /* Return nonzero if FRAME is a dummy frame. We can't use
1691 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1692 take too much time, at least using frame_register() on the 68k.
1693 This means that for this function to work right a port must use the
1694 bp_call_dummy breakpoint. */
1697 deprecated_frame_in_dummy (struct frame_info *frame)
1699 struct breakpoint *b;
1701 /* This function is used by two files: get_frame_type(), after first
1702 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1703 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1704 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1708 if (b->type == bp_call_dummy
1709 && frame_id_eq (b->frame_id, get_frame_id (frame))
1710 /* We need to check the PC as well as the frame on the sparc,
1711 for signals.exp in the testsuite. */
1712 && (get_frame_pc (frame)
1714 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1715 && get_frame_pc (frame) <= b->address)
1721 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1722 PC is valid for process/thread PID. */
1725 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1727 struct breakpoint *b;
1730 thread = pid_to_thread_id (ptid);
1733 if (b->enable_state != bp_disabled
1734 && b->enable_state != bp_shlib_disabled
1735 && b->enable_state != bp_call_disabled
1737 && (b->thread == -1 || b->thread == thread))
1739 if (overlay_debugging
1740 && section_is_overlay (b->section)
1741 && !section_is_mapped (b->section))
1742 continue; /* unmapped overlay -- can't be a match */
1751 /* bpstat stuff. External routines' interfaces are documented
1755 ep_is_catchpoint (struct breakpoint *ep)
1758 (ep->type == bp_catch_load)
1759 || (ep->type == bp_catch_unload)
1760 || (ep->type == bp_catch_fork)
1761 || (ep->type == bp_catch_vfork)
1762 || (ep->type == bp_catch_exec)
1763 || (ep->type == bp_catch_catch)
1764 || (ep->type == bp_catch_throw);
1766 /* ??rehrauer: Add more kinds here, as are implemented... */
1770 ep_is_shlib_catchpoint (struct breakpoint *ep)
1773 (ep->type == bp_catch_load)
1774 || (ep->type == bp_catch_unload);
1778 ep_is_exception_catchpoint (struct breakpoint *ep)
1781 (ep->type == bp_catch_catch)
1782 || (ep->type == bp_catch_throw);
1785 /* Clear a bpstat so that it says we are not at any breakpoint.
1786 Also free any storage that is part of a bpstat. */
1789 bpstat_clear (bpstat *bsp)
1800 if (p->old_val != NULL)
1801 value_free (p->old_val);
1802 free_command_lines (&p->commands);
1809 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1810 is part of the bpstat is copied as well. */
1813 bpstat_copy (bpstat bs)
1817 bpstat retval = NULL;
1822 for (; bs != NULL; bs = bs->next)
1824 tmp = (bpstat) xmalloc (sizeof (*tmp));
1825 memcpy (tmp, bs, sizeof (*tmp));
1826 if (bs->commands != NULL)
1827 tmp->commands = copy_command_lines (bs->commands);
1828 if (bs->old_val != NULL)
1829 tmp->old_val = value_copy (bs->old_val);
1832 /* This is the first thing in the chain. */
1842 /* Find the bpstat associated with this breakpoint */
1845 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1850 for (; bsp != NULL; bsp = bsp->next)
1852 if (bsp->breakpoint_at == breakpoint)
1858 /* Find a step_resume breakpoint associated with this bpstat.
1859 (If there are multiple step_resume bp's on the list, this function
1860 will arbitrarily pick one.)
1862 It is an error to use this function if BPSTAT doesn't contain a
1863 step_resume breakpoint.
1865 See wait_for_inferior's use of this function. */
1867 bpstat_find_step_resume_breakpoint (bpstat bsp)
1872 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1874 current_thread = pid_to_thread_id (inferior_ptid);
1876 for (; bsp != NULL; bsp = bsp->next)
1878 if ((bsp->breakpoint_at != NULL) &&
1879 (bsp->breakpoint_at->type == bp_step_resume) &&
1880 (bsp->breakpoint_at->thread == current_thread ||
1881 bsp->breakpoint_at->thread == -1))
1882 return bsp->breakpoint_at;
1885 error ("Internal error (no step_resume breakpoint found)");
1889 /* Return the breakpoint number of the first breakpoint we are stopped
1890 at. *BSP upon return is a bpstat which points to the remaining
1891 breakpoints stopped at (but which is not guaranteed to be good for
1892 anything but further calls to bpstat_num).
1893 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1896 bpstat_num (bpstat *bsp)
1898 struct breakpoint *b;
1901 return 0; /* No more breakpoint values */
1904 b = (*bsp)->breakpoint_at;
1905 *bsp = (*bsp)->next;
1907 return -1; /* breakpoint that's been deleted since */
1909 return b->number; /* We have its number */
1913 /* Modify BS so that the actions will not be performed. */
1916 bpstat_clear_actions (bpstat bs)
1918 for (; bs != NULL; bs = bs->next)
1920 free_command_lines (&bs->commands);
1921 if (bs->old_val != NULL)
1923 value_free (bs->old_val);
1929 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1931 cleanup_executing_breakpoints (void *ignore)
1933 executing_breakpoint_commands = 0;
1936 /* Execute all the commands associated with all the breakpoints at this
1937 location. Any of these commands could cause the process to proceed
1938 beyond this point, etc. We look out for such changes by checking
1939 the global "breakpoint_proceeded" after each command. */
1942 bpstat_do_actions (bpstat *bsp)
1945 struct cleanup *old_chain;
1946 struct command_line *cmd;
1948 /* Avoid endless recursion if a `source' command is contained
1950 if (executing_breakpoint_commands)
1953 executing_breakpoint_commands = 1;
1954 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1957 /* Note that (as of this writing), our callers all appear to
1958 be passing us the address of global stop_bpstat. And, if
1959 our calls to execute_control_command cause the inferior to
1960 proceed, that global (and hence, *bsp) will change.
1962 We must be careful to not touch *bsp unless the inferior
1963 has not proceeded. */
1965 /* This pointer will iterate over the list of bpstat's. */
1968 breakpoint_proceeded = 0;
1969 for (; bs != NULL; bs = bs->next)
1974 execute_control_command (cmd);
1976 if (breakpoint_proceeded)
1981 if (breakpoint_proceeded)
1982 /* The inferior is proceeded by the command; bomb out now.
1983 The bpstat chain has been blown away by wait_for_inferior.
1984 But since execution has stopped again, there is a new bpstat
1985 to look at, so start over. */
1988 free_command_lines (&bs->commands);
1990 do_cleanups (old_chain);
1993 /* This is the normal print function for a bpstat. In the future,
1994 much of this logic could (should?) be moved to bpstat_stop_status,
1995 by having it set different print_it values.
1997 Current scheme: When we stop, bpstat_print() is called. It loops
1998 through the bpstat list of things causing this stop, calling the
1999 print_bp_stop_message function on each one. The behavior of the
2000 print_bp_stop_message function depends on the print_it field of
2001 bpstat. If such field so indicates, call this function here.
2003 Return values from this routine (ultimately used by bpstat_print()
2004 and normal_stop() to decide what to do):
2005 PRINT_NOTHING: Means we already printed all we needed to print,
2006 don't print anything else.
2007 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2008 that something to be followed by a location.
2009 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2010 that something to be followed by a location.
2011 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2014 static enum print_stop_action
2015 print_it_typical (bpstat bs)
2017 struct cleanup *old_chain, *ui_out_chain;
2018 struct ui_stream *stb;
2019 stb = ui_out_stream_new (uiout);
2020 old_chain = make_cleanup_ui_out_stream_delete (stb);
2021 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2022 which has since been deleted. */
2023 if (bs->breakpoint_at == NULL)
2024 return PRINT_UNKNOWN;
2026 switch (bs->breakpoint_at->type)
2029 case bp_hardware_breakpoint:
2030 if (bs->breakpoint_at->address != bs->breakpoint_at->requested_address)
2031 breakpoint_adjustment_warning (bs->breakpoint_at->requested_address,
2032 bs->breakpoint_at->address,
2033 bs->breakpoint_at->number, 1);
2034 annotate_breakpoint (bs->breakpoint_at->number);
2035 ui_out_text (uiout, "\nBreakpoint ");
2036 if (ui_out_is_mi_like_p (uiout))
2037 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2038 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2039 ui_out_text (uiout, ", ");
2040 return PRINT_SRC_AND_LOC;
2043 case bp_shlib_event:
2044 /* Did we stop because the user set the stop_on_solib_events
2045 variable? (If so, we report this as a generic, "Stopped due
2046 to shlib event" message.) */
2047 printf_filtered ("Stopped due to shared library event\n");
2048 return PRINT_NOTHING;
2051 case bp_thread_event:
2052 /* Not sure how we will get here.
2053 GDB should not stop for these breakpoints. */
2054 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2055 return PRINT_NOTHING;
2058 case bp_overlay_event:
2059 /* By analogy with the thread event, GDB should not stop for these. */
2060 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2061 return PRINT_NOTHING;
2065 annotate_catchpoint (bs->breakpoint_at->number);
2066 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2067 printf_filtered ("loaded");
2068 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2069 return PRINT_SRC_AND_LOC;
2072 case bp_catch_unload:
2073 annotate_catchpoint (bs->breakpoint_at->number);
2074 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2075 printf_filtered ("unloaded");
2076 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2077 return PRINT_SRC_AND_LOC;
2081 annotate_catchpoint (bs->breakpoint_at->number);
2082 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2083 printf_filtered ("forked");
2084 printf_filtered (" process %d), ",
2085 bs->breakpoint_at->forked_inferior_pid);
2086 return PRINT_SRC_AND_LOC;
2089 case bp_catch_vfork:
2090 annotate_catchpoint (bs->breakpoint_at->number);
2091 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2092 printf_filtered ("vforked");
2093 printf_filtered (" process %d), ",
2094 bs->breakpoint_at->forked_inferior_pid);
2095 return PRINT_SRC_AND_LOC;
2099 annotate_catchpoint (bs->breakpoint_at->number);
2100 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2101 bs->breakpoint_at->number,
2102 bs->breakpoint_at->exec_pathname);
2103 return PRINT_SRC_AND_LOC;
2106 case bp_catch_catch:
2107 if (current_exception_event &&
2108 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2110 annotate_catchpoint (bs->breakpoint_at->number);
2111 printf_filtered ("\nCatchpoint %d (exception caught), ",
2112 bs->breakpoint_at->number);
2113 printf_filtered ("throw location ");
2114 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2115 printf_filtered ("%s:%d",
2116 CURRENT_EXCEPTION_THROW_FILE,
2117 CURRENT_EXCEPTION_THROW_LINE);
2119 printf_filtered ("unknown");
2121 printf_filtered (", catch location ");
2122 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2123 printf_filtered ("%s:%d",
2124 CURRENT_EXCEPTION_CATCH_FILE,
2125 CURRENT_EXCEPTION_CATCH_LINE);
2127 printf_filtered ("unknown");
2129 printf_filtered ("\n");
2130 /* don't bother to print location frame info */
2131 return PRINT_SRC_ONLY;
2135 /* really throw, some other bpstat will handle it */
2136 return PRINT_UNKNOWN;
2140 case bp_catch_throw:
2141 if (current_exception_event &&
2142 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2144 annotate_catchpoint (bs->breakpoint_at->number);
2145 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2146 bs->breakpoint_at->number);
2147 printf_filtered ("throw location ");
2148 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2149 printf_filtered ("%s:%d",
2150 CURRENT_EXCEPTION_THROW_FILE,
2151 CURRENT_EXCEPTION_THROW_LINE);
2153 printf_filtered ("unknown");
2155 printf_filtered (", catch location ");
2156 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2157 printf_filtered ("%s:%d",
2158 CURRENT_EXCEPTION_CATCH_FILE,
2159 CURRENT_EXCEPTION_CATCH_LINE);
2161 printf_filtered ("unknown");
2163 printf_filtered ("\n");
2164 /* don't bother to print location frame info */
2165 return PRINT_SRC_ONLY;
2169 /* really catch, some other bpstat will handle it */
2170 return PRINT_UNKNOWN;
2175 case bp_hardware_watchpoint:
2176 if (bs->old_val != NULL)
2178 annotate_watchpoint (bs->breakpoint_at->number);
2179 if (ui_out_is_mi_like_p (uiout))
2180 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2181 mention (bs->breakpoint_at);
2182 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2183 ui_out_text (uiout, "\nOld value = ");
2184 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2185 ui_out_field_stream (uiout, "old", stb);
2186 ui_out_text (uiout, "\nNew value = ");
2187 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2188 ui_out_field_stream (uiout, "new", stb);
2189 do_cleanups (ui_out_chain);
2190 ui_out_text (uiout, "\n");
2191 value_free (bs->old_val);
2194 /* More than one watchpoint may have been triggered. */
2195 return PRINT_UNKNOWN;
2198 case bp_read_watchpoint:
2199 if (ui_out_is_mi_like_p (uiout))
2200 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2201 mention (bs->breakpoint_at);
2202 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2203 ui_out_text (uiout, "\nValue = ");
2204 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2205 ui_out_field_stream (uiout, "value", stb);
2206 do_cleanups (ui_out_chain);
2207 ui_out_text (uiout, "\n");
2208 return PRINT_UNKNOWN;
2211 case bp_access_watchpoint:
2212 if (bs->old_val != NULL)
2214 annotate_watchpoint (bs->breakpoint_at->number);
2215 if (ui_out_is_mi_like_p (uiout))
2216 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2217 mention (bs->breakpoint_at);
2218 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2219 ui_out_text (uiout, "\nOld value = ");
2220 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2221 ui_out_field_stream (uiout, "old", stb);
2222 value_free (bs->old_val);
2224 ui_out_text (uiout, "\nNew value = ");
2228 mention (bs->breakpoint_at);
2229 if (ui_out_is_mi_like_p (uiout))
2230 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2231 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2232 ui_out_text (uiout, "\nValue = ");
2234 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2235 ui_out_field_stream (uiout, "new", stb);
2236 do_cleanups (ui_out_chain);
2237 ui_out_text (uiout, "\n");
2238 return PRINT_UNKNOWN;
2241 /* Fall through, we don't deal with these types of breakpoints
2245 if (ui_out_is_mi_like_p (uiout))
2246 ui_out_field_string (uiout, "reason", "function-finished");
2247 return PRINT_UNKNOWN;
2251 if (ui_out_is_mi_like_p (uiout))
2252 ui_out_field_string (uiout, "reason", "location-reached");
2253 return PRINT_UNKNOWN;
2258 case bp_longjmp_resume:
2259 case bp_step_resume:
2260 case bp_through_sigtramp:
2261 case bp_watchpoint_scope:
2264 return PRINT_UNKNOWN;
2268 /* Generic routine for printing messages indicating why we
2269 stopped. The behavior of this function depends on the value
2270 'print_it' in the bpstat structure. Under some circumstances we
2271 may decide not to print anything here and delegate the task to
2274 static enum print_stop_action
2275 print_bp_stop_message (bpstat bs)
2277 switch (bs->print_it)
2280 /* Nothing should be printed for this bpstat entry. */
2281 return PRINT_UNKNOWN;
2285 /* We still want to print the frame, but we already printed the
2286 relevant messages. */
2287 return PRINT_SRC_AND_LOC;
2290 case print_it_normal:
2291 /* Normal case. Call the breakpoint's print_it method, or
2292 print_it_typical. */
2293 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2294 && bs->breakpoint_at->ops->print_it != NULL)
2295 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2297 return print_it_typical (bs);
2301 internal_error (__FILE__, __LINE__,
2302 "print_bp_stop_message: unrecognized enum value");
2307 /* Print a message indicating what happened. This is called from
2308 normal_stop(). The input to this routine is the head of the bpstat
2309 list - a list of the eventpoints that caused this stop. This
2310 routine calls the generic print routine for printing a message
2311 about reasons for stopping. This will print (for example) the
2312 "Breakpoint n," part of the output. The return value of this
2315 PRINT_UNKNOWN: Means we printed nothing
2316 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2317 code to print the location. An example is
2318 "Breakpoint 1, " which should be followed by
2320 PRINT_SRC_ONLY: Means we printed something, but there is no need
2321 to also print the location part of the message.
2322 An example is the catch/throw messages, which
2323 don't require a location appended to the end.
2324 PRINT_NOTHING: We have done some printing and we don't need any
2325 further info to be printed.*/
2327 enum print_stop_action
2328 bpstat_print (bpstat bs)
2332 /* Maybe another breakpoint in the chain caused us to stop.
2333 (Currently all watchpoints go on the bpstat whether hit or not.
2334 That probably could (should) be changed, provided care is taken
2335 with respect to bpstat_explains_signal). */
2336 for (; bs; bs = bs->next)
2338 val = print_bp_stop_message (bs);
2339 if (val == PRINT_SRC_ONLY
2340 || val == PRINT_SRC_AND_LOC
2341 || val == PRINT_NOTHING)
2345 /* We reached the end of the chain, or we got a null BS to start
2346 with and nothing was printed. */
2347 return PRINT_UNKNOWN;
2350 /* Evaluate the expression EXP and return 1 if value is zero.
2351 This is used inside a catch_errors to evaluate the breakpoint condition.
2352 The argument is a "struct expression *" that has been cast to char * to
2353 make it pass through catch_errors. */
2356 breakpoint_cond_eval (void *exp)
2358 struct value *mark = value_mark ();
2359 int i = !value_true (evaluate_expression ((struct expression *) exp));
2360 value_free_to_mark (mark);
2364 /* Allocate a new bpstat and chain it to the current one. */
2367 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2371 bs = (bpstat) xmalloc (sizeof (*bs));
2373 bs->breakpoint_at = b;
2374 /* If the condition is false, etc., don't do the commands. */
2375 bs->commands = NULL;
2377 bs->print_it = print_it_normal;
2381 /* Possible return values for watchpoint_check (this can't be an enum
2382 because of check_errors). */
2383 /* The watchpoint has been deleted. */
2384 #define WP_DELETED 1
2385 /* The value has changed. */
2386 #define WP_VALUE_CHANGED 2
2387 /* The value has not changed. */
2388 #define WP_VALUE_NOT_CHANGED 3
2390 #define BP_TEMPFLAG 1
2391 #define BP_HARDWAREFLAG 2
2393 /* Check watchpoint condition. */
2396 watchpoint_check (void *p)
2398 bpstat bs = (bpstat) p;
2399 struct breakpoint *b;
2400 struct frame_info *fr;
2401 int within_current_scope;
2403 struct frame_id current_frame_id;
2406 b = bs->breakpoint_at;
2408 if (b->exp_valid_block == NULL)
2409 within_current_scope = 1;
2412 /* There is no current frame at this moment. If we're going to have
2413 any chance of handling watchpoints on local variables, we'll need
2414 the frame chain (so we can determine if we're in scope). */
2415 reinit_frame_cache ();
2416 fr = frame_find_by_id (b->watchpoint_frame);
2417 within_current_scope = (fr != NULL);
2418 /* in_function_epilogue_p() returns a non-zero value if we're still
2419 in the function but the stack frame has already been invalidated.
2420 Since we can't rely on the values of local variables after the
2421 stack has been destroyed, we are treating the watchpoint in that
2422 state as `not changed' without further checking.
2424 vinschen/2003-09-04: The former implementation left out the case
2425 that the watchpoint frame couldn't be found by frame_find_by_id()
2426 because the current PC is currently in an epilogue. Calling
2427 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2428 if ((!within_current_scope || fr == get_current_frame ())
2429 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2430 return WP_VALUE_NOT_CHANGED;
2431 if (fr && within_current_scope)
2432 /* If we end up stopping, the current frame will get selected
2433 in normal_stop. So this call to select_frame won't affect
2438 if (within_current_scope)
2440 /* We use value_{,free_to_}mark because it could be a
2441 *long* time before we return to the command level and
2442 call free_all_values. We can't call free_all_values because
2443 we might be in the middle of evaluating a function call. */
2445 struct value *mark = value_mark ();
2446 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2447 if (!value_equal (b->val, new_val))
2449 release_value (new_val);
2450 value_free_to_mark (mark);
2451 bs->old_val = b->val;
2453 /* We will stop here */
2454 return WP_VALUE_CHANGED;
2458 /* Nothing changed, don't do anything. */
2459 value_free_to_mark (mark);
2460 /* We won't stop here */
2461 return WP_VALUE_NOT_CHANGED;
2466 /* This seems like the only logical thing to do because
2467 if we temporarily ignored the watchpoint, then when
2468 we reenter the block in which it is valid it contains
2469 garbage (in the case of a function, it may have two
2470 garbage values, one before and one after the prologue).
2471 So we can't even detect the first assignment to it and
2472 watch after that (since the garbage may or may not equal
2473 the first value assigned). */
2474 /* We print all the stop information in print_it_typical(), but
2475 in this case, by the time we call print_it_typical() this bp
2476 will be deleted already. So we have no choice but print the
2477 information here. */
2478 if (ui_out_is_mi_like_p (uiout))
2479 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2480 ui_out_text (uiout, "\nWatchpoint ");
2481 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2482 ui_out_text (uiout, " deleted because the program has left the block in\n\
2483 which its expression is valid.\n");
2485 if (b->related_breakpoint)
2486 b->related_breakpoint->disposition = disp_del_at_next_stop;
2487 b->disposition = disp_del_at_next_stop;
2493 /* Get a bpstat associated with having just stopped at address *PC
2494 and frame address CORE_ADDRESS. Update *PC to point at the
2495 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2496 if this is known to not be a real breakpoint (it could still be a
2497 watchpoint, though). */
2499 /* Determine whether we stopped at a breakpoint, etc, or whether we
2500 don't understand this stop. Result is a chain of bpstat's such that:
2502 if we don't understand the stop, the result is a null pointer.
2504 if we understand why we stopped, the result is not null.
2506 Each element of the chain refers to a particular breakpoint or
2507 watchpoint at which we have stopped. (We may have stopped for
2508 several reasons concurrently.)
2510 Each element of the chain has valid next, breakpoint_at,
2511 commands, FIXME??? fields. */
2514 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2516 struct breakpoint *b, *temp;
2518 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2519 int real_breakpoint = 0;
2520 /* Root of the chain of bpstat's */
2521 struct bpstats root_bs[1];
2522 /* Pointer to the last thing in the chain currently. */
2523 bpstat bs = root_bs;
2525 /* Get the address where the breakpoint would have been. The
2526 "not_a_sw_breakpoint" argument is meant to distinguish between a
2527 breakpoint trap event and a trace/singlestep trap event. For a
2528 trace/singlestep trap event, we would not want to subtract
2529 DECR_PC_AFTER_BREAK from the PC. */
2531 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2533 ALL_BREAKPOINTS_SAFE (b, temp)
2535 if (b->enable_state == bp_disabled
2536 || b->enable_state == bp_shlib_disabled
2537 || b->enable_state == bp_call_disabled)
2540 if (b->type != bp_watchpoint
2541 && b->type != bp_hardware_watchpoint
2542 && b->type != bp_read_watchpoint
2543 && b->type != bp_access_watchpoint
2544 && b->type != bp_hardware_breakpoint
2545 && b->type != bp_catch_fork
2546 && b->type != bp_catch_vfork
2547 && b->type != bp_catch_exec
2548 && b->type != bp_catch_catch
2549 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2551 if (b->address != bp_addr) /* address doesn't match */
2553 if (overlay_debugging /* unmapped overlay section */
2554 && section_is_overlay (b->section)
2555 && !section_is_mapped (b->section))
2559 if (b->type == bp_hardware_breakpoint)
2561 if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2563 if (overlay_debugging /* unmapped overlay section */
2564 && section_is_overlay (b->section)
2565 && !section_is_mapped (b->section))
2569 /* Is this a catchpoint of a load or unload? If so, did we
2570 get a load or unload of the specified library? If not,
2572 if ((b->type == bp_catch_load)
2573 #if defined(SOLIB_HAVE_LOAD_EVENT)
2574 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2575 || ((b->dll_pathname != NULL)
2576 && (strcmp (b->dll_pathname,
2577 SOLIB_LOADED_LIBRARY_PATHNAME (
2578 PIDGET (inferior_ptid)))
2584 if ((b->type == bp_catch_unload)
2585 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2586 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2587 || ((b->dll_pathname != NULL)
2588 && (strcmp (b->dll_pathname,
2589 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2590 PIDGET (inferior_ptid)))
2596 if ((b->type == bp_catch_fork)
2597 && !inferior_has_forked (PIDGET (inferior_ptid),
2598 &b->forked_inferior_pid))
2601 if ((b->type == bp_catch_vfork)
2602 && !inferior_has_vforked (PIDGET (inferior_ptid),
2603 &b->forked_inferior_pid))
2606 if ((b->type == bp_catch_exec)
2607 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2610 if (ep_is_exception_catchpoint (b) &&
2611 !(current_exception_event = target_get_current_exception_event ()))
2614 /* Come here if it's a watchpoint, or if the break address matches */
2616 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2618 /* Watchpoints may change this, if not found to have triggered. */
2622 if (b->type == bp_watchpoint ||
2623 b->type == bp_hardware_watchpoint)
2625 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2627 struct cleanup *cleanups = make_cleanup (xfree, message);
2628 int e = catch_errors (watchpoint_check, bs, message,
2630 do_cleanups (cleanups);
2634 /* We've already printed what needs to be printed. */
2635 /* Actually this is superfluous, because by the time we
2636 call print_it_typical() the wp will be already deleted,
2637 and the function will return immediately. */
2638 bs->print_it = print_it_done;
2641 case WP_VALUE_CHANGED:
2645 case WP_VALUE_NOT_CHANGED:
2647 bs->print_it = print_it_noop;
2654 /* Error from catch_errors. */
2655 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2656 if (b->related_breakpoint)
2657 b->related_breakpoint->disposition = disp_del_at_next_stop;
2658 b->disposition = disp_del_at_next_stop;
2659 /* We've already printed what needs to be printed. */
2660 bs->print_it = print_it_done;
2666 else if (b->type == bp_read_watchpoint ||
2667 b->type == bp_access_watchpoint)
2673 addr = target_stopped_data_address ();
2676 for (v = b->val_chain; v; v = v->next)
2678 if (VALUE_LVAL (v) == lval_memory
2679 && ! VALUE_LAZY (v))
2681 struct type *vtype = check_typedef (VALUE_TYPE (v));
2683 if (v == b->val_chain
2684 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2685 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2689 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2690 /* Exact match not required. Within range is
2692 if (addr >= vaddr &&
2693 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2700 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2702 struct cleanup *cleanups = make_cleanup (xfree, message);
2703 int e = catch_errors (watchpoint_check, bs, message,
2705 do_cleanups (cleanups);
2709 /* We've already printed what needs to be printed. */
2710 bs->print_it = print_it_done;
2713 case WP_VALUE_CHANGED:
2714 if (b->type == bp_read_watchpoint)
2716 /* Don't stop: read watchpoints shouldn't fire if
2717 the value has changed. This is for targets
2718 which cannot set read-only watchpoints. */
2719 bs->print_it = print_it_noop;
2725 case WP_VALUE_NOT_CHANGED:
2732 /* Error from catch_errors. */
2733 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2734 if (b->related_breakpoint)
2735 b->related_breakpoint->disposition = disp_del_at_next_stop;
2736 b->disposition = disp_del_at_next_stop;
2737 /* We've already printed what needs to be printed. */
2738 bs->print_it = print_it_done;
2742 else /* found == 0 */
2744 /* This is a case where some watchpoint(s) triggered,
2745 but not at the address of this watchpoint (FOUND
2746 was left zero). So don't print anything for this
2748 bs->print_it = print_it_noop;
2755 /* By definition, an encountered breakpoint is a triggered
2759 real_breakpoint = 1;
2762 if (frame_id_p (b->frame_id)
2763 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2767 int value_is_zero = 0;
2771 /* Need to select the frame, with all that implies
2772 so that the conditions will have the right context. */
2773 select_frame (get_current_frame ());
2775 = catch_errors (breakpoint_cond_eval, (b->cond),
2776 "Error in testing breakpoint condition:\n",
2778 /* FIXME-someday, should give breakpoint # */
2781 if (b->cond && value_is_zero)
2784 /* Don't consider this a hit. */
2787 else if (b->ignore_count > 0)
2790 annotate_ignore_count_change ();
2795 /* We will stop here */
2796 if (b->disposition == disp_disable)
2797 b->enable_state = bp_disabled;
2800 bs->commands = b->commands;
2802 (STREQ ("silent", bs->commands->line) ||
2803 (xdb_commands && STREQ ("Q", bs->commands->line))))
2805 bs->commands = bs->commands->next;
2808 bs->commands = copy_command_lines (bs->commands);
2811 /* Print nothing for this entry if we dont stop or if we dont print. */
2812 if (bs->stop == 0 || bs->print == 0)
2813 bs->print_it = print_it_noop;
2816 bs->next = NULL; /* Terminate the chain */
2817 bs = root_bs->next; /* Re-grab the head of the chain */
2819 if (real_breakpoint && bs)
2821 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2823 if (DECR_PC_AFTER_HW_BREAK != 0)
2825 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2831 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2834 #if defined (SHIFT_INST_REGS)
2836 #else /* No SHIFT_INST_REGS. */
2838 #endif /* No SHIFT_INST_REGS. */
2843 /* The value of a hardware watchpoint hasn't changed, but the
2844 intermediate memory locations we are watching may have. */
2845 if (bs && !bs->stop &&
2846 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2847 bs->breakpoint_at->type == bp_read_watchpoint ||
2848 bs->breakpoint_at->type == bp_access_watchpoint))
2850 remove_breakpoints ();
2851 insert_breakpoints ();
2856 /* Tell what to do about this bpstat. */
2858 bpstat_what (bpstat bs)
2860 /* Classify each bpstat as one of the following. */
2863 /* This bpstat element has no effect on the main_action. */
2866 /* There was a watchpoint, stop but don't print. */
2869 /* There was a watchpoint, stop and print. */
2872 /* There was a breakpoint but we're not stopping. */
2875 /* There was a breakpoint, stop but don't print. */
2878 /* There was a breakpoint, stop and print. */
2881 /* We hit the longjmp breakpoint. */
2884 /* We hit the longjmp_resume breakpoint. */
2887 /* We hit the step_resume breakpoint. */
2890 /* We hit the through_sigtramp breakpoint. */
2893 /* We hit the shared library event breakpoint. */
2896 /* We caught a shared library event. */
2899 /* This is just used to count how many enums there are. */
2903 /* Here is the table which drives this routine. So that we can
2904 format it pretty, we define some abbreviations for the
2905 enum bpstat_what codes. */
2906 #define kc BPSTAT_WHAT_KEEP_CHECKING
2907 #define ss BPSTAT_WHAT_STOP_SILENT
2908 #define sn BPSTAT_WHAT_STOP_NOISY
2909 #define sgl BPSTAT_WHAT_SINGLE
2910 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2911 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2912 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2913 #define sr BPSTAT_WHAT_STEP_RESUME
2914 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2915 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2916 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2918 /* "Can't happen." Might want to print an error message.
2919 abort() is not out of the question, but chances are GDB is just
2920 a bit confused, not unusable. */
2921 #define err BPSTAT_WHAT_STOP_NOISY
2923 /* Given an old action and a class, come up with a new action. */
2924 /* One interesting property of this table is that wp_silent is the same
2925 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2926 after stopping, the check for whether to step over a breakpoint
2927 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2928 reference to how we stopped. We retain separate wp_silent and
2929 bp_silent codes in case we want to change that someday.
2931 Another possibly interesting property of this table is that
2932 there's a partial ordering, priority-like, of the actions. Once
2933 you've decided that some action is appropriate, you'll never go
2934 back and decide something of a lower priority is better. The
2937 kc < clr sgl shl shlr slr sn sr ss ts
2938 sgl < clrs shl shlr slr sn sr ss ts
2939 slr < err shl shlr sn sr ss ts
2940 clr < clrs err shl shlr sn sr ss ts
2941 clrs < err shl shlr sn sr ss ts
2942 ss < shl shlr sn sr ts
2949 What I think this means is that we don't need a damned table
2950 here. If you just put the rows and columns in the right order,
2951 it'd look awfully regular. We could simply walk the bpstat list
2952 and choose the highest priority action we find, with a little
2953 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2954 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2955 is messy anyway). */
2957 /* step_resume entries: a step resume breakpoint overrides another
2958 breakpoint of signal handling (see comment in wait_for_inferior
2959 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2960 /* We handle the through_sigtramp_breakpoint the same way; having both
2961 one of those and a step_resume_breakpoint is probably very rare (?). */
2963 static const enum bpstat_what_main_action
2964 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2967 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2970 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2972 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2974 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2976 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2978 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2980 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2982 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2984 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2986 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2988 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2990 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2992 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3007 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3008 struct bpstat_what retval;
3010 retval.call_dummy = 0;
3011 for (; bs != NULL; bs = bs->next)
3013 enum class bs_class = no_effect;
3014 if (bs->breakpoint_at == NULL)
3015 /* I suspect this can happen if it was a momentary breakpoint
3016 which has since been deleted. */
3018 switch (bs->breakpoint_at->type)
3024 case bp_hardware_breakpoint:
3030 bs_class = bp_noisy;
3032 bs_class = bp_silent;
3035 bs_class = bp_nostop;
3038 case bp_hardware_watchpoint:
3039 case bp_read_watchpoint:
3040 case bp_access_watchpoint:
3044 bs_class = wp_noisy;
3046 bs_class = wp_silent;
3049 /* There was a watchpoint, but we're not stopping.
3050 This requires no further action. */
3051 bs_class = no_effect;
3054 bs_class = long_jump;
3056 case bp_longjmp_resume:
3057 bs_class = long_resume;
3059 case bp_step_resume:
3062 bs_class = step_resume;
3065 /* It is for the wrong frame. */
3066 bs_class = bp_nostop;
3068 case bp_through_sigtramp:
3069 bs_class = through_sig;
3071 case bp_watchpoint_scope:
3072 bs_class = bp_nostop;
3074 case bp_shlib_event:
3075 bs_class = shlib_event;
3077 case bp_thread_event:
3078 case bp_overlay_event:
3079 bs_class = bp_nostop;
3082 case bp_catch_unload:
3083 /* Only if this catchpoint triggered should we cause the
3084 step-out-of-dld behaviour. Otherwise, we ignore this
3087 bs_class = catch_shlib_event;
3089 bs_class = no_effect;
3092 case bp_catch_vfork:
3097 bs_class = bp_noisy;
3099 bs_class = bp_silent;
3102 /* There was a catchpoint, but we're not stopping.
3103 This requires no further action. */
3104 bs_class = no_effect;
3106 case bp_catch_catch:
3107 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3108 bs_class = bp_nostop;
3110 bs_class = bs->print ? bp_noisy : bp_silent;
3112 case bp_catch_throw:
3113 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3114 bs_class = bp_nostop;
3116 bs_class = bs->print ? bp_noisy : bp_silent;
3119 /* Make sure the action is stop (silent or noisy),
3120 so infrun.c pops the dummy frame. */
3121 bs_class = bp_silent;
3122 retval.call_dummy = 1;
3125 current_action = table[(int) bs_class][(int) current_action];
3127 retval.main_action = current_action;
3131 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3132 without hardware support). This isn't related to a specific bpstat,
3133 just to things like whether watchpoints are set. */
3136 bpstat_should_step (void)
3138 struct breakpoint *b;
3140 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3145 /* Nonzero if there are enabled hardware watchpoints. */
3147 bpstat_have_active_hw_watchpoints (void)
3149 struct breakpoint *b;
3151 if ((b->enable_state == bp_enabled) &&
3153 ((b->type == bp_hardware_watchpoint) ||
3154 (b->type == bp_read_watchpoint) ||
3155 (b->type == bp_access_watchpoint)))
3161 /* Given a bpstat that records zero or more triggered eventpoints, this
3162 function returns another bpstat which contains only the catchpoints
3163 on that first list, if any. */
3165 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3167 struct bpstats root_bs[1];
3168 bpstat bs = root_bs;
3169 struct breakpoint *ep;
3172 bpstat_clear (cp_list);
3173 root_bs->next = NULL;
3175 for (; ep_list != NULL; ep_list = ep_list->next)
3177 /* Is this eventpoint a catchpoint? If not, ignore it. */
3178 ep = ep_list->breakpoint_at;
3181 if ((ep->type != bp_catch_load) &&
3182 (ep->type != bp_catch_unload) &&
3183 (ep->type != bp_catch_catch) &&
3184 (ep->type != bp_catch_throw))
3185 /* pai: (temp) ADD fork/vfork here!! */
3188 /* Yes; add it to the list. */
3189 bs = bpstat_alloc (ep, bs);
3194 #if defined(SOLIB_ADD)
3195 /* Also, for each triggered catchpoint, tag it with the name of
3196 the library that caused this trigger. (We copy the name now,
3197 because it's only guaranteed to be available NOW, when the
3198 catchpoint triggers. Clients who may wish to know the name
3199 later must get it from the catchpoint itself.) */
3200 if (ep->triggered_dll_pathname != NULL)
3201 xfree (ep->triggered_dll_pathname);
3202 if (ep->type == bp_catch_load)
3203 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3204 PIDGET (inferior_ptid));
3206 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3207 PIDGET (inferior_ptid));
3209 dll_pathname = NULL;
3213 ep->triggered_dll_pathname = (char *)
3214 xmalloc (strlen (dll_pathname) + 1);
3215 strcpy (ep->triggered_dll_pathname, dll_pathname);
3218 ep->triggered_dll_pathname = NULL;
3224 /* Print B to gdb_stdout. */
3226 print_one_breakpoint (struct breakpoint *b,
3227 CORE_ADDR *last_addr)
3229 struct command_line *l;
3231 struct ep_type_description
3236 static struct ep_type_description bptypes[] =
3238 {bp_none, "?deleted?"},
3239 {bp_breakpoint, "breakpoint"},
3240 {bp_hardware_breakpoint, "hw breakpoint"},
3241 {bp_until, "until"},
3242 {bp_finish, "finish"},
3243 {bp_watchpoint, "watchpoint"},
3244 {bp_hardware_watchpoint, "hw watchpoint"},
3245 {bp_read_watchpoint, "read watchpoint"},
3246 {bp_access_watchpoint, "acc watchpoint"},
3247 {bp_longjmp, "longjmp"},
3248 {bp_longjmp_resume, "longjmp resume"},
3249 {bp_step_resume, "step resume"},
3250 {bp_through_sigtramp, "sigtramp"},
3251 {bp_watchpoint_scope, "watchpoint scope"},
3252 {bp_call_dummy, "call dummy"},
3253 {bp_shlib_event, "shlib events"},
3254 {bp_thread_event, "thread events"},
3255 {bp_overlay_event, "overlay events"},
3256 {bp_catch_load, "catch load"},
3257 {bp_catch_unload, "catch unload"},
3258 {bp_catch_fork, "catch fork"},
3259 {bp_catch_vfork, "catch vfork"},
3260 {bp_catch_exec, "catch exec"},
3261 {bp_catch_catch, "catch catch"},
3262 {bp_catch_throw, "catch throw"}
3265 static char *bpdisps[] =
3266 {"del", "dstp", "dis", "keep"};
3267 static char bpenables[] = "nynny";
3268 char wrap_indent[80];
3269 struct ui_stream *stb = ui_out_stream_new (uiout);
3270 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3271 struct cleanup *bkpt_chain;
3274 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3278 ui_out_field_int (uiout, "number", b->number);
3282 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3283 || ((int) b->type != bptypes[(int) b->type].type))
3284 internal_error (__FILE__, __LINE__,
3285 "bptypes table does not describe type #%d.",
3287 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3291 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3295 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3296 ui_out_spaces (uiout, 2);
3299 strcpy (wrap_indent, " ");
3302 if (TARGET_ADDR_BIT <= 32)
3303 strcat (wrap_indent, " ");
3305 strcat (wrap_indent, " ");
3308 if (b->ops != NULL && b->ops->print_one != NULL)
3309 b->ops->print_one (b, last_addr);
3314 internal_error (__FILE__, __LINE__,
3315 "print_one_breakpoint: bp_none encountered\n");
3319 case bp_hardware_watchpoint:
3320 case bp_read_watchpoint:
3321 case bp_access_watchpoint:
3322 /* Field 4, the address, is omitted (which makes the columns
3323 not line up too nicely with the headers, but the effect
3324 is relatively readable). */
3326 ui_out_field_skip (uiout, "addr");
3328 print_expression (b->exp, stb->stream);
3329 ui_out_field_stream (uiout, "what", stb);
3333 case bp_catch_unload:
3334 /* Field 4, the address, is omitted (which makes the columns
3335 not line up too nicely with the headers, but the effect
3336 is relatively readable). */
3338 ui_out_field_skip (uiout, "addr");
3340 if (b->dll_pathname == NULL)
3342 ui_out_field_string (uiout, "what", "<any library>");
3343 ui_out_spaces (uiout, 1);
3347 ui_out_text (uiout, "library \"");
3348 ui_out_field_string (uiout, "what", b->dll_pathname);
3349 ui_out_text (uiout, "\" ");
3354 case bp_catch_vfork:
3355 /* Field 4, the address, is omitted (which makes the columns
3356 not line up too nicely with the headers, but the effect
3357 is relatively readable). */
3359 ui_out_field_skip (uiout, "addr");
3361 if (b->forked_inferior_pid != 0)
3363 ui_out_text (uiout, "process ");
3364 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3365 ui_out_spaces (uiout, 1);
3369 /* Field 4, the address, is omitted (which makes the columns
3370 not line up too nicely with the headers, but the effect
3371 is relatively readable). */
3373 ui_out_field_skip (uiout, "addr");
3375 if (b->exec_pathname != NULL)
3377 ui_out_text (uiout, "program \"");
3378 ui_out_field_string (uiout, "what", b->exec_pathname);
3379 ui_out_text (uiout, "\" ");
3383 case bp_catch_catch:
3384 /* Field 4, the address, is omitted (which makes the columns
3385 not line up too nicely with the headers, but the effect
3386 is relatively readable). */
3388 ui_out_field_skip (uiout, "addr");
3390 ui_out_field_string (uiout, "what", "exception catch");
3391 ui_out_spaces (uiout, 1);
3394 case bp_catch_throw:
3395 /* Field 4, the address, is omitted (which makes the columns
3396 not line up too nicely with the headers, but the effect
3397 is relatively readable). */
3399 ui_out_field_skip (uiout, "addr");
3401 ui_out_field_string (uiout, "what", "exception throw");
3402 ui_out_spaces (uiout, 1);
3406 case bp_hardware_breakpoint:
3410 case bp_longjmp_resume:
3411 case bp_step_resume:
3412 case bp_through_sigtramp:
3413 case bp_watchpoint_scope:
3415 case bp_shlib_event:
3416 case bp_thread_event:
3417 case bp_overlay_event:
3421 ui_out_field_core_addr (uiout, "addr", b->address);
3424 *last_addr = b->address;
3427 sym = find_pc_sect_function (b->address, b->section);
3430 ui_out_text (uiout, "in ");
3431 ui_out_field_string (uiout, "func",
3432 SYMBOL_PRINT_NAME (sym));
3433 ui_out_wrap_hint (uiout, wrap_indent);
3434 ui_out_text (uiout, " at ");
3436 ui_out_field_string (uiout, "file", b->source_file);
3437 ui_out_text (uiout, ":");
3438 ui_out_field_int (uiout, "line", b->line_number);
3442 print_address_symbolic (b->address, stb->stream, demangle, "");
3443 ui_out_field_stream (uiout, "at", stb);
3448 if (b->thread != -1)
3450 /* FIXME: This seems to be redundant and lost here; see the
3451 "stop only in" line a little further down. */
3452 ui_out_text (uiout, " thread ");
3453 ui_out_field_int (uiout, "thread", b->thread);
3456 ui_out_text (uiout, "\n");
3458 if (frame_id_p (b->frame_id))
3461 ui_out_text (uiout, "\tstop only in stack frame at ");
3462 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3464 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3465 ui_out_text (uiout, "\n");
3471 ui_out_text (uiout, "\tstop only if ");
3472 print_expression (b->cond, stb->stream);
3473 ui_out_field_stream (uiout, "cond", stb);
3474 ui_out_text (uiout, "\n");
3477 if (b->thread != -1)
3479 /* FIXME should make an annotation for this */
3480 ui_out_text (uiout, "\tstop only in thread ");
3481 ui_out_field_int (uiout, "thread", b->thread);
3482 ui_out_text (uiout, "\n");
3485 if (show_breakpoint_hit_counts && b->hit_count)
3487 /* FIXME should make an annotation for this */
3488 if (ep_is_catchpoint (b))
3489 ui_out_text (uiout, "\tcatchpoint");
3491 ui_out_text (uiout, "\tbreakpoint");
3492 ui_out_text (uiout, " already hit ");
3493 ui_out_field_int (uiout, "times", b->hit_count);
3494 if (b->hit_count == 1)
3495 ui_out_text (uiout, " time\n");
3497 ui_out_text (uiout, " times\n");
3500 /* Output the count also if it is zero, but only if this is
3501 mi. FIXME: Should have a better test for this. */
3502 if (ui_out_is_mi_like_p (uiout))
3503 if (show_breakpoint_hit_counts && b->hit_count == 0)
3504 ui_out_field_int (uiout, "times", b->hit_count);
3506 if (b->ignore_count)
3509 ui_out_text (uiout, "\tignore next ");
3510 ui_out_field_int (uiout, "ignore", b->ignore_count);
3511 ui_out_text (uiout, " hits\n");
3514 if ((l = b->commands))
3516 struct cleanup *script_chain;
3519 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3520 print_command_lines (uiout, l, 4);
3521 do_cleanups (script_chain);
3523 do_cleanups (bkpt_chain);
3524 do_cleanups (old_chain);
3527 struct captured_breakpoint_query_args
3533 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3535 struct captured_breakpoint_query_args *args = data;
3536 struct breakpoint *b;
3537 CORE_ADDR dummy_addr = 0;
3540 if (args->bnum == b->number)
3542 print_one_breakpoint (b, &dummy_addr);
3550 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3552 struct captured_breakpoint_query_args args;
3554 /* For the moment we don't trust print_one_breakpoint() to not throw
3556 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3557 NULL, RETURN_MASK_ALL);
3560 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3561 catchpoints, et.al.). */
3564 user_settable_breakpoint (const struct breakpoint *b)
3566 return (b->type == bp_breakpoint
3567 || b->type == bp_catch_load
3568 || b->type == bp_catch_unload
3569 || b->type == bp_catch_fork
3570 || b->type == bp_catch_vfork
3571 || b->type == bp_catch_exec
3572 || b->type == bp_catch_catch
3573 || b->type == bp_catch_throw
3574 || b->type == bp_hardware_breakpoint
3575 || b->type == bp_watchpoint
3576 || b->type == bp_read_watchpoint
3577 || b->type == bp_access_watchpoint
3578 || b->type == bp_hardware_watchpoint);
3581 /* Print information on user settable breakpoint (watchpoint, etc)
3582 number BNUM. If BNUM is -1 print all user settable breakpoints.
3583 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3586 breakpoint_1 (int bnum, int allflag)
3588 struct breakpoint *b;
3589 CORE_ADDR last_addr = (CORE_ADDR) -1;
3590 int nr_printable_breakpoints;
3591 struct cleanup *bkpttbl_chain;
3593 /* Compute the number of rows in the table. */
3594 nr_printable_breakpoints = 0;
3597 || bnum == b->number)
3599 if (allflag || user_settable_breakpoint (b))
3600 nr_printable_breakpoints++;
3605 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3609 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3612 if (nr_printable_breakpoints > 0)
3613 annotate_breakpoints_headers ();
3614 if (nr_printable_breakpoints > 0)
3616 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3617 if (nr_printable_breakpoints > 0)
3619 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3620 if (nr_printable_breakpoints > 0)
3622 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3623 if (nr_printable_breakpoints > 0)
3625 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3628 if (nr_printable_breakpoints > 0)
3630 if (TARGET_ADDR_BIT <= 32)
3631 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3633 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3635 if (nr_printable_breakpoints > 0)
3637 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3638 ui_out_table_body (uiout);
3639 if (nr_printable_breakpoints > 0)
3640 annotate_breakpoints_table ();
3644 || bnum == b->number)
3646 /* We only print out user settable breakpoints unless the
3648 if (allflag || user_settable_breakpoint (b))
3649 print_one_breakpoint (b, &last_addr);
3652 do_cleanups (bkpttbl_chain);
3654 if (nr_printable_breakpoints == 0)
3657 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3659 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3664 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3665 that a comparison of an unsigned with -1 is always false. */
3666 if (last_addr != (CORE_ADDR) -1)
3667 set_next_address (last_addr);
3670 /* FIXME? Should this be moved up so that it is only called when
3671 there have been breakpoints? */
3672 annotate_breakpoints_table_end ();
3676 breakpoints_info (char *bnum_exp, int from_tty)
3681 bnum = parse_and_eval_long (bnum_exp);
3683 breakpoint_1 (bnum, 0);
3687 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3692 bnum = parse_and_eval_long (bnum_exp);
3694 breakpoint_1 (bnum, 1);
3697 /* Print a message describing any breakpoints set at PC. */
3700 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3703 struct breakpoint *b;
3706 if (b->address == pc) /* address match / overlay match */
3707 if (!overlay_debugging || b->section == section)
3711 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3713 if (b->address == pc) /* address match / overlay match */
3714 if (!overlay_debugging || b->section == section)
3717 printf_filtered ("%d%s%s ",
3719 ((b->enable_state == bp_disabled ||
3720 b->enable_state == bp_shlib_disabled ||
3721 b->enable_state == bp_call_disabled)
3723 : b->enable_state == bp_permanent
3727 : ((others == 1) ? " and" : ""));
3729 printf_filtered ("also set at pc ");
3730 print_address_numeric (pc, 1, gdb_stdout);
3731 printf_filtered (".\n");
3735 /* Set the default place to put a breakpoint
3736 for the `break' command with no arguments. */
3739 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3742 default_breakpoint_valid = valid;
3743 default_breakpoint_address = addr;
3744 default_breakpoint_symtab = symtab;
3745 default_breakpoint_line = line;
3748 /* Return true iff it is meaningful to use the address member of
3749 BPT. For some breakpoint types, the address member is irrelevant
3750 and it makes no sense to attempt to compare it to other addresses
3751 (or use it for any other purpose either).
3753 More specifically, each of the following breakpoint types will always
3754 have a zero valued address and we don't want check_duplicates() to mark
3755 breakpoints of any of these types to be a duplicate of an actual
3756 breakpoint at address zero:
3759 bp_hardware_watchpoint
3761 bp_access_watchpoint
3768 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3770 enum bptype type = bpt->type;
3772 return (type != bp_watchpoint
3773 && type != bp_hardware_watchpoint
3774 && type != bp_read_watchpoint
3775 && type != bp_access_watchpoint
3776 && type != bp_catch_exec
3777 && type != bp_longjmp_resume
3778 && type != bp_catch_fork
3779 && type != bp_catch_vfork);
3782 /* Rescan breakpoints at the same address and section as BPT,
3783 marking the first one as "first" and any others as "duplicates".
3784 This is so that the bpt instruction is only inserted once.
3785 If we have a permanent breakpoint at the same place as BPT, make
3786 that one the official one, and the rest as duplicates. */
3789 check_duplicates (struct breakpoint *bpt)
3791 struct breakpoint *b;
3793 struct breakpoint *perm_bp = 0;
3794 CORE_ADDR address = bpt->address;
3795 asection *section = bpt->section;
3797 if (! breakpoint_address_is_meaningful (bpt))
3801 if (b->enable_state != bp_disabled
3802 && b->enable_state != bp_shlib_disabled
3803 && b->enable_state != bp_call_disabled
3804 && b->address == address /* address / overlay match */
3805 && (!overlay_debugging || b->section == section)
3806 && breakpoint_address_is_meaningful (b))
3808 /* Have we found a permanent breakpoint? */
3809 if (b->enable_state == bp_permanent)
3816 b->duplicate = count > 1;
3819 /* If we found a permanent breakpoint at this address, go over the
3820 list again and declare all the other breakpoints there to be the
3824 perm_bp->duplicate = 0;
3826 /* Permanent breakpoint should always be inserted. */
3827 if (! perm_bp->inserted)
3828 internal_error (__FILE__, __LINE__,
3829 "allegedly permanent breakpoint is not "
3830 "actually inserted");
3836 internal_error (__FILE__, __LINE__,
3837 "another breakpoint was inserted on top of "
3838 "a permanent breakpoint");
3840 if (b->enable_state != bp_disabled
3841 && b->enable_state != bp_shlib_disabled
3842 && b->enable_state != bp_call_disabled
3843 && b->address == address /* address / overlay match */
3844 && (!overlay_debugging || b->section == section)
3845 && breakpoint_address_is_meaningful (b))
3852 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3853 int bnum, int have_bnum)
3858 strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l"));
3859 strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l"));
3861 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3862 bnum, astr1, astr2);
3864 warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2);
3867 /* Adjust a breakpoint's address to account for architectural constraints
3868 on breakpoint placement. Return the adjusted address. Note: Very
3869 few targets require this kind of adjustment. For most targets,
3870 this function is simply the identity function. */
3873 adjust_breakpoint_address (CORE_ADDR bpaddr)
3875 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3877 /* Very few targets need any kind of breakpoint adjustment. */
3882 CORE_ADDR adjusted_bpaddr;
3884 /* Some targets have architectural constraints on the placement
3885 of breakpoint instructions. Obtain the adjusted address. */
3886 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3889 /* An adjusted breakpoint address can significantly alter
3890 a user's expectations. Print a warning if an adjustment
3892 if (adjusted_bpaddr != bpaddr)
3893 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3895 return adjusted_bpaddr;
3899 /* set_raw_breakpoint() is a low level routine for allocating and
3900 partially initializing a breakpoint of type BPTYPE. The newly
3901 created breakpoint's address, section, source file name, and line
3902 number are provided by SAL. The newly created and partially
3903 initialized breakpoint is added to the breakpoint chain and
3904 is also returned as the value of this function.
3906 It is expected that the caller will complete the initialization of
3907 the newly created breakpoint struct as well as output any status
3908 information regarding the creation of a new breakpoint. In
3909 particular, set_raw_breakpoint() does NOT set the breakpoint
3910 number! Care should be taken to not allow an error() to occur
3911 prior to completing the initialization of the breakpoint. If this
3912 should happen, a bogus breakpoint will be left on the chain. */
3915 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3917 struct breakpoint *b, *b1;
3919 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3920 memset (b, 0, sizeof (*b));
3921 b->requested_address = sal.pc;
3922 b->address = adjust_breakpoint_address (b->requested_address);
3923 if (sal.symtab == NULL)
3924 b->source_file = NULL;
3926 b->source_file = savestring (sal.symtab->filename,
3927 strlen (sal.symtab->filename));
3928 b->section = sal.section;
3930 b->language = current_language->la_language;
3931 b->input_radix = input_radix;
3933 b->line_number = sal.line;
3934 b->enable_state = bp_enabled;
3937 b->ignore_count = 0;
3939 b->frame_id = null_frame_id;
3940 b->dll_pathname = NULL;
3941 b->triggered_dll_pathname = NULL;
3942 b->forked_inferior_pid = 0;
3943 b->exec_pathname = NULL;
3946 /* Add this breakpoint to the end of the chain
3947 so that a list of breakpoints will come out in order
3948 of increasing numbers. */
3950 b1 = breakpoint_chain;
3952 breakpoint_chain = b;
3960 check_duplicates (b);
3961 breakpoints_changed ();
3967 /* Note that the breakpoint object B describes a permanent breakpoint
3968 instruction, hard-wired into the inferior's code. */
3970 make_breakpoint_permanent (struct breakpoint *b)
3972 b->enable_state = bp_permanent;
3974 /* By definition, permanent breakpoints are already present in the code. */
3978 static struct breakpoint *
3979 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3981 static int internal_breakpoint_number = -1;
3982 struct symtab_and_line sal;
3983 struct breakpoint *b;
3985 init_sal (&sal); /* initialize to zeroes */
3988 sal.section = find_pc_overlay (sal.pc);
3990 b = set_raw_breakpoint (sal, type);
3991 b->number = internal_breakpoint_number--;
3992 b->disposition = disp_donttouch;
3999 create_longjmp_breakpoint (char *func_name)
4001 struct breakpoint *b;
4002 struct minimal_symbol *m;
4004 if (func_name == NULL)
4005 b = create_internal_breakpoint (0, bp_longjmp_resume);
4008 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
4011 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4014 b->enable_state = bp_disabled;
4017 b->addr_string = xstrdup (func_name);
4020 /* Call this routine when stepping and nexting to enable a breakpoint
4021 if we do a longjmp(). When we hit that breakpoint, call
4022 set_longjmp_resume_breakpoint() to figure out where we are going. */
4025 enable_longjmp_breakpoint (void)
4027 struct breakpoint *b;
4030 if (b->type == bp_longjmp)
4032 b->enable_state = bp_enabled;
4033 check_duplicates (b);
4038 disable_longjmp_breakpoint (void)
4040 struct breakpoint *b;
4043 if (b->type == bp_longjmp
4044 || b->type == bp_longjmp_resume)
4046 b->enable_state = bp_disabled;
4047 check_duplicates (b);
4052 create_overlay_event_breakpoint (char *func_name)
4054 struct breakpoint *b;
4055 struct minimal_symbol *m;
4057 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
4060 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4062 b->addr_string = xstrdup (func_name);
4064 if (overlay_debugging == ovly_auto)
4066 b->enable_state = bp_enabled;
4067 overlay_events_enabled = 1;
4071 b->enable_state = bp_disabled;
4072 overlay_events_enabled = 0;
4077 enable_overlay_breakpoints (void)
4079 struct breakpoint *b;
4082 if (b->type == bp_overlay_event)
4084 b->enable_state = bp_enabled;
4085 check_duplicates (b);
4086 overlay_events_enabled = 1;
4091 disable_overlay_breakpoints (void)
4093 struct breakpoint *b;
4096 if (b->type == bp_overlay_event)
4098 b->enable_state = bp_disabled;
4099 check_duplicates (b);
4100 overlay_events_enabled = 0;
4105 create_thread_event_breakpoint (CORE_ADDR address)
4107 struct breakpoint *b;
4109 b = create_internal_breakpoint (address, bp_thread_event);
4111 b->enable_state = bp_enabled;
4112 /* addr_string has to be used or breakpoint_re_set will delete me. */
4113 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4119 remove_thread_event_breakpoints (void)
4121 struct breakpoint *b, *temp;
4123 ALL_BREAKPOINTS_SAFE (b, temp)
4124 if (b->type == bp_thread_event)
4125 delete_breakpoint (b);
4130 remove_solib_event_breakpoints (void)
4132 struct breakpoint *b, *temp;
4134 ALL_BREAKPOINTS_SAFE (b, temp)
4135 if (b->type == bp_shlib_event)
4136 delete_breakpoint (b);
4140 create_solib_event_breakpoint (CORE_ADDR address)
4142 struct breakpoint *b;
4144 b = create_internal_breakpoint (address, bp_shlib_event);
4148 /* Disable any breakpoints that are on code in shared libraries. Only
4149 apply to enabled breakpoints, disabled ones can just stay disabled. */
4152 disable_breakpoints_in_shlibs (int silent)
4154 struct breakpoint *b;
4155 int disabled_shlib_breaks = 0;
4157 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4160 #if defined (PC_SOLIB)
4161 if (((b->type == bp_breakpoint) ||
4162 (b->type == bp_hardware_breakpoint)) &&
4163 b->enable_state == bp_enabled &&
4165 PC_SOLIB (b->address))
4167 b->enable_state = bp_shlib_disabled;
4170 if (!disabled_shlib_breaks)
4172 target_terminal_ours_for_output ();
4173 warning ("Temporarily disabling shared library breakpoints:");
4175 disabled_shlib_breaks = 1;
4176 warning ("breakpoint #%d ", b->number);
4183 /* Try to reenable any breakpoints in shared libraries. */
4185 re_enable_breakpoints_in_shlibs (void)
4187 struct breakpoint *b;
4190 if (b->enable_state == bp_shlib_disabled)
4194 /* Do not reenable the breakpoint if the shared library
4195 is still not mapped in. */
4196 if (target_read_memory (b->address, buf, 1) == 0)
4197 b->enable_state = bp_enabled;
4204 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4205 char *cond_string, enum bptype bp_kind)
4207 struct breakpoint *b;
4208 struct symtabs_and_lines sals;
4209 struct cleanup *old_chain;
4210 struct cleanup *canonical_strings_chain = NULL;
4211 char *addr_start = hookname;
4212 char *addr_end = NULL;
4213 char **canonical = (char **) NULL;
4214 int thread = -1; /* All threads. */
4216 /* Set a breakpoint on the specified hook. */
4217 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4218 addr_end = hookname;
4220 if (sals.nelts == 0)
4222 warning ("Unable to set a breakpoint on dynamic linker callback.");
4223 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4224 warning ("GDB will be unable to track shl_load/shl_unload calls");
4227 if (sals.nelts != 1)
4229 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4230 warning ("GDB will be unable to track shl_load/shl_unload calls");
4234 /* Make sure that all storage allocated in decode_line_1 gets freed
4235 in case the following errors out. */
4236 old_chain = make_cleanup (xfree, sals.sals);
4237 if (canonical != (char **) NULL)
4239 make_cleanup (xfree, canonical);
4240 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4241 if (canonical[0] != NULL)
4242 make_cleanup (xfree, canonical[0]);
4245 resolve_sal_pc (&sals.sals[0]);
4247 /* Remove the canonical strings from the cleanup, they are needed below. */
4248 if (canonical != (char **) NULL)
4249 discard_cleanups (canonical_strings_chain);
4251 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4252 set_breakpoint_count (breakpoint_count + 1);
4253 b->number = breakpoint_count;
4255 b->cond_string = (cond_string == NULL) ?
4256 NULL : savestring (cond_string, strlen (cond_string));
4259 if (canonical != (char **) NULL && canonical[0] != NULL)
4260 b->addr_string = canonical[0];
4261 else if (addr_start)
4262 b->addr_string = savestring (addr_start, addr_end - addr_start);
4264 b->enable_state = bp_enabled;
4265 b->disposition = tempflag ? disp_del : disp_donttouch;
4267 if (dll_pathname == NULL)
4268 b->dll_pathname = NULL;
4271 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4272 strcpy (b->dll_pathname, dll_pathname);
4276 do_cleanups (old_chain);
4280 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4281 char *dll_pathname, char *cond_string)
4283 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4284 cond_string, bp_catch_load);
4288 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4289 char *dll_pathname, char *cond_string)
4291 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4292 cond_string, bp_catch_unload);
4296 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4297 enum bptype bp_kind)
4299 struct symtab_and_line sal;
4300 struct breakpoint *b;
4301 int thread = -1; /* All threads. */
4308 b = set_raw_breakpoint (sal, bp_kind);
4309 set_breakpoint_count (breakpoint_count + 1);
4310 b->number = breakpoint_count;
4312 b->cond_string = (cond_string == NULL) ?
4313 NULL : savestring (cond_string, strlen (cond_string));
4315 b->addr_string = NULL;
4316 b->enable_state = bp_enabled;
4317 b->disposition = tempflag ? disp_del : disp_donttouch;
4318 b->forked_inferior_pid = 0;
4324 create_fork_event_catchpoint (int tempflag, char *cond_string)
4326 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4330 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4332 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4336 create_exec_event_catchpoint (int tempflag, char *cond_string)
4338 struct symtab_and_line sal;
4339 struct breakpoint *b;
4340 int thread = -1; /* All threads. */
4347 b = set_raw_breakpoint (sal, bp_catch_exec);
4348 set_breakpoint_count (breakpoint_count + 1);
4349 b->number = breakpoint_count;
4351 b->cond_string = (cond_string == NULL) ?
4352 NULL : savestring (cond_string, strlen (cond_string));
4354 b->addr_string = NULL;
4355 b->enable_state = bp_enabled;
4356 b->disposition = tempflag ? disp_del : disp_donttouch;
4362 hw_breakpoint_used_count (void)
4364 struct breakpoint *b;
4369 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4377 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4379 struct breakpoint *b;
4382 *other_type_used = 0;
4385 if (b->enable_state == bp_enabled)
4387 if (b->type == type)
4389 else if ((b->type == bp_hardware_watchpoint ||
4390 b->type == bp_read_watchpoint ||
4391 b->type == bp_access_watchpoint)
4392 && b->enable_state == bp_enabled)
4393 *other_type_used = 1;
4399 /* Call this after hitting the longjmp() breakpoint. Use this to set
4400 a new breakpoint at the target of the jmp_buf.
4402 FIXME - This ought to be done by setting a temporary breakpoint
4403 that gets deleted automatically... */
4406 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4408 struct breakpoint *b;
4411 if (b->type == bp_longjmp_resume)
4413 b->requested_address = pc;
4414 b->address = adjust_breakpoint_address (b->requested_address);
4415 b->enable_state = bp_enabled;
4416 b->frame_id = frame_id;
4417 check_duplicates (b);
4423 disable_watchpoints_before_interactive_call_start (void)
4425 struct breakpoint *b;
4429 if (((b->type == bp_watchpoint)
4430 || (b->type == bp_hardware_watchpoint)
4431 || (b->type == bp_read_watchpoint)
4432 || (b->type == bp_access_watchpoint)
4433 || ep_is_exception_catchpoint (b))
4434 && (b->enable_state == bp_enabled))
4436 b->enable_state = bp_call_disabled;
4437 check_duplicates (b);
4443 enable_watchpoints_after_interactive_call_stop (void)
4445 struct breakpoint *b;
4449 if (((b->type == bp_watchpoint)
4450 || (b->type == bp_hardware_watchpoint)
4451 || (b->type == bp_read_watchpoint)
4452 || (b->type == bp_access_watchpoint)
4453 || ep_is_exception_catchpoint (b))
4454 && (b->enable_state == bp_call_disabled))
4456 b->enable_state = bp_enabled;
4457 check_duplicates (b);
4463 /* Set a breakpoint that will evaporate an end of command
4464 at address specified by SAL.
4465 Restrict it to frame FRAME if FRAME is nonzero. */
4468 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4471 struct breakpoint *b;
4472 b = set_raw_breakpoint (sal, type);
4473 b->enable_state = bp_enabled;
4474 b->disposition = disp_donttouch;
4475 b->frame_id = frame_id;
4477 /* If we're debugging a multi-threaded program, then we
4478 want momentary breakpoints to be active in only a
4479 single thread of control. */
4480 if (in_thread_list (inferior_ptid))
4481 b->thread = pid_to_thread_id (inferior_ptid);
4487 /* Tell the user we have just set a breakpoint B. */
4490 mention (struct breakpoint *b)
4493 struct cleanup *old_chain, *ui_out_chain;
4494 struct ui_stream *stb;
4496 stb = ui_out_stream_new (uiout);
4497 old_chain = make_cleanup_ui_out_stream_delete (stb);
4499 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4500 watchpoint) other than breakpoint creation. It should be possible to
4501 clean this up and at the same time replace the random calls to
4502 breakpoint_changed with this hook, as has already been done for
4503 delete_breakpoint_hook and so on. */
4504 if (create_breakpoint_hook)
4505 create_breakpoint_hook (b);
4506 breakpoint_create_event (b->number);
4508 if (b->ops != NULL && b->ops->print_mention != NULL)
4509 b->ops->print_mention (b);
4514 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4517 ui_out_text (uiout, "Watchpoint ");
4518 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4519 ui_out_field_int (uiout, "number", b->number);
4520 ui_out_text (uiout, ": ");
4521 print_expression (b->exp, stb->stream);
4522 ui_out_field_stream (uiout, "exp", stb);
4523 do_cleanups (ui_out_chain);
4525 case bp_hardware_watchpoint:
4526 ui_out_text (uiout, "Hardware watchpoint ");
4527 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4528 ui_out_field_int (uiout, "number", b->number);
4529 ui_out_text (uiout, ": ");
4530 print_expression (b->exp, stb->stream);
4531 ui_out_field_stream (uiout, "exp", stb);
4532 do_cleanups (ui_out_chain);
4534 case bp_read_watchpoint:
4535 ui_out_text (uiout, "Hardware read watchpoint ");
4536 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4537 ui_out_field_int (uiout, "number", b->number);
4538 ui_out_text (uiout, ": ");
4539 print_expression (b->exp, stb->stream);
4540 ui_out_field_stream (uiout, "exp", stb);
4541 do_cleanups (ui_out_chain);
4543 case bp_access_watchpoint:
4544 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4545 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4546 ui_out_field_int (uiout, "number", b->number);
4547 ui_out_text (uiout, ": ");
4548 print_expression (b->exp, stb->stream);
4549 ui_out_field_stream (uiout, "exp", stb);
4550 do_cleanups (ui_out_chain);
4553 if (ui_out_is_mi_like_p (uiout))
4558 printf_filtered ("Breakpoint %d", b->number);
4561 case bp_hardware_breakpoint:
4562 if (ui_out_is_mi_like_p (uiout))
4567 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4571 case bp_catch_unload:
4572 printf_filtered ("Catchpoint %d (%s %s)",
4574 (b->type == bp_catch_load) ? "load" : "unload",
4575 (b->dll_pathname != NULL) ?
4576 b->dll_pathname : "<any library>");
4579 case bp_catch_vfork:
4580 printf_filtered ("Catchpoint %d (%s)",
4582 (b->type == bp_catch_fork) ? "fork" : "vfork");
4585 printf_filtered ("Catchpoint %d (exec)",
4588 case bp_catch_catch:
4589 case bp_catch_throw:
4590 printf_filtered ("Catchpoint %d (%s)",
4592 (b->type == bp_catch_catch) ? "catch" : "throw");
4598 case bp_longjmp_resume:
4599 case bp_step_resume:
4600 case bp_through_sigtramp:
4602 case bp_watchpoint_scope:
4603 case bp_shlib_event:
4604 case bp_thread_event:
4605 case bp_overlay_event:
4611 if (addressprint || b->source_file == NULL)
4613 printf_filtered (" at ");
4614 print_address_numeric (b->address, 1, gdb_stdout);
4617 printf_filtered (": file %s, line %d.",
4618 b->source_file, b->line_number);
4620 do_cleanups (old_chain);
4621 if (ui_out_is_mi_like_p (uiout))
4623 printf_filtered ("\n");
4627 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4628 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4629 COND[i] and COND_STRING[i] values.
4631 NOTE: If the function succeeds, the caller is expected to cleanup
4632 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4633 array contents). If the function fails (error() is called), the
4634 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4635 COND and SALS arrays and each of those arrays contents. */
4638 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4639 struct expression **cond, char **cond_string,
4640 enum bptype type, enum bpdisp disposition,
4641 int thread, int ignore_count, int from_tty)
4643 if (type == bp_hardware_breakpoint)
4645 int i = hw_breakpoint_used_count ();
4646 int target_resources_ok =
4647 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4649 if (target_resources_ok == 0)
4650 error ("No hardware breakpoint support in the target.");
4651 else if (target_resources_ok < 0)
4652 error ("Hardware breakpoints used exceeds limit.");
4655 /* Now set all the breakpoints. */
4658 for (i = 0; i < sals.nelts; i++)
4660 struct breakpoint *b;
4661 struct symtab_and_line sal = sals.sals[i];
4664 describe_other_breakpoints (sal.pc, sal.section);
4666 b = set_raw_breakpoint (sal, type);
4667 set_breakpoint_count (breakpoint_count + 1);
4668 b->number = breakpoint_count;
4672 b->addr_string = addr_string[i];
4674 /* addr_string has to be used or breakpoint_re_set will delete
4676 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4677 b->cond_string = cond_string[i];
4678 b->ignore_count = ignore_count;
4679 b->enable_state = bp_enabled;
4680 b->disposition = disposition;
4686 /* Parse ARG which is assumed to be a SAL specification possibly
4687 followed by conditionals. On return, SALS contains an array of SAL
4688 addresses found. ADDR_STRING contains a vector of (canonical)
4689 address strings. ARG points to the end of the SAL. */
4692 parse_breakpoint_sals (char **address,
4693 struct symtabs_and_lines *sals,
4694 char ***addr_string)
4696 char *addr_start = *address;
4697 *addr_string = NULL;
4698 /* If no arg given, or if first arg is 'if ', use the default
4700 if ((*address) == NULL
4701 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4703 if (default_breakpoint_valid)
4705 struct symtab_and_line sal;
4706 init_sal (&sal); /* initialize to zeroes */
4707 sals->sals = (struct symtab_and_line *)
4708 xmalloc (sizeof (struct symtab_and_line));
4709 sal.pc = default_breakpoint_address;
4710 sal.line = default_breakpoint_line;
4711 sal.symtab = default_breakpoint_symtab;
4712 sal.section = find_pc_overlay (sal.pc);
4713 sals->sals[0] = sal;
4717 error ("No default breakpoint address now.");
4721 /* Force almost all breakpoints to be in terms of the
4722 current_source_symtab (which is decode_line_1's default). This
4723 should produce the results we want almost all of the time while
4724 leaving default_breakpoint_* alone.
4725 ObjC: However, don't match an Objective-C method name which
4726 may have a '+' or '-' succeeded by a '[' */
4728 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4730 if (default_breakpoint_valid
4732 || ((strchr ("+-", (*address)[0]) != NULL)
4733 && ((*address)[1] != '['))))
4734 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4735 default_breakpoint_line, addr_string);
4737 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4739 /* For any SAL that didn't have a canonical string, fill one in. */
4740 if (sals->nelts > 0 && *addr_string == NULL)
4741 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4742 if (addr_start != (*address))
4745 for (i = 0; i < sals->nelts; i++)
4747 /* Add the string if not present. */
4748 if ((*addr_string)[i] == NULL)
4749 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4755 /* Convert each SAL into a real PC. Verify that the PC can be
4756 inserted as a breakpoint. If it can't throw an error. */
4759 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4763 for (i = 0; i < sals->nelts; i++)
4765 resolve_sal_pc (&sals->sals[i]);
4767 /* It's possible for the PC to be nonzero, but still an illegal
4768 value on some targets.
4770 For example, on HP-UX if you start gdb, and before running the
4771 inferior you try to set a breakpoint on a shared library function
4772 "foo" where the inferior doesn't call "foo" directly but does
4773 pass its address to another function call, then we do find a
4774 minimal symbol for the "foo", but it's address is invalid.
4775 (Appears to be an index into a table that the loader sets up
4776 when the inferior is run.)
4778 Give the target a chance to bless sals.sals[i].pc before we
4779 try to make a breakpoint for it. */
4780 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4782 if (address == NULL)
4783 error ("Cannot break without a running program.");
4785 error ("Cannot break on %s without a running program.",
4791 /* Set a breakpoint according to ARG (function, linenum or *address)
4792 flag: first bit : 0 non-temporary, 1 temporary.
4793 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4796 break_command_1 (char *arg, int flag, int from_tty)
4798 int tempflag, hardwareflag;
4799 struct symtabs_and_lines sals;
4800 struct expression **cond = 0;
4801 /* Pointers in arg to the start, and one past the end, of the
4803 char **cond_string = (char **) NULL;
4804 char *addr_start = arg;
4806 struct cleanup *old_chain;
4807 struct cleanup *breakpoint_chain = NULL;
4810 int ignore_count = 0;
4812 hardwareflag = flag & BP_HARDWAREFLAG;
4813 tempflag = flag & BP_TEMPFLAG;
4818 parse_breakpoint_sals (&arg, &sals, &addr_string);
4823 /* Create a chain of things that always need to be cleaned up. */
4824 old_chain = make_cleanup (null_cleanup, 0);
4826 /* Make sure that all storage allocated to SALS gets freed. */
4827 make_cleanup (xfree, sals.sals);
4829 /* Cleanup the addr_string array but not its contents. */
4830 make_cleanup (xfree, addr_string);
4832 /* Allocate space for all the cond expressions. */
4833 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4834 make_cleanup (xfree, cond);
4836 /* Allocate space for all the cond strings. */
4837 cond_string = xcalloc (sals.nelts, sizeof (char **));
4838 make_cleanup (xfree, cond_string);
4840 /* ----------------------------- SNIP -----------------------------
4841 Anything added to the cleanup chain beyond this point is assumed
4842 to be part of a breakpoint. If the breakpoint create succeeds
4843 then the memory is not reclaimed. */
4844 breakpoint_chain = make_cleanup (null_cleanup, 0);
4846 /* Mark the contents of the addr_string for cleanup. These go on
4847 the breakpoint_chain and only occure if the breakpoint create
4849 for (i = 0; i < sals.nelts; i++)
4851 if (addr_string[i] != NULL)
4852 make_cleanup (xfree, addr_string[i]);
4855 /* Resolve all line numbers to PC's and verify that the addresses
4856 are ok for the target. */
4857 breakpoint_sals_to_pc (&sals, addr_start);
4859 /* Verify that condition can be parsed, before setting any
4860 breakpoints. Allocate a separate condition expression for each
4862 thread = -1; /* No specific thread yet */
4863 for (i = 0; i < sals.nelts; i++)
4870 char *cond_start = NULL;
4871 char *cond_end = NULL;
4872 while (*tok == ' ' || *tok == '\t')
4877 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4880 toklen = end_tok - tok;
4882 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4884 tok = cond_start = end_tok + 1;
4885 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4886 make_cleanup (xfree, cond[i]);
4888 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4889 make_cleanup (xfree, cond_string[i]);
4891 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4897 thread = strtol (tok, &tok, 0);
4899 error ("Junk after thread keyword.");
4900 if (!valid_thread_id (thread))
4901 error ("Unknown thread %d\n", thread);
4904 error ("Junk at end of arguments.");
4908 create_breakpoints (sals, addr_string, cond, cond_string,
4909 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4910 tempflag ? disp_del : disp_donttouch,
4911 thread, ignore_count, from_tty);
4915 warning ("Multiple breakpoints were set.");
4916 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4918 /* That's it. Discard the cleanups for data inserted into the
4920 discard_cleanups (breakpoint_chain);
4921 /* But cleanup everything else. */
4922 do_cleanups (old_chain);
4925 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4926 linenum or *address) with COND and IGNORE_COUNT. */
4928 struct captured_breakpoint_args
4939 do_captured_breakpoint (void *data)
4941 struct captured_breakpoint_args *args = data;
4942 struct symtabs_and_lines sals;
4943 struct expression **cond;
4944 struct cleanup *old_chain;
4945 struct cleanup *breakpoint_chain = NULL;
4952 /* Parse the source and lines spec. Delay check that the expression
4953 didn't contain trailing garbage until after cleanups are in
4957 address_end = args->address;
4959 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4964 /* Create a chain of things at always need to be cleaned up. */
4965 old_chain = make_cleanup (null_cleanup, 0);
4967 /* Always have a addr_string array, even if it is empty. */
4968 make_cleanup (xfree, addr_string);
4970 /* Make sure that all storage allocated to SALS gets freed. */
4971 make_cleanup (xfree, sals.sals);
4973 /* Allocate space for all the cond expressions. */
4974 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4975 make_cleanup (xfree, cond);
4977 /* Allocate space for all the cond strings. */
4978 cond_string = xcalloc (sals.nelts, sizeof (char **));
4979 make_cleanup (xfree, cond_string);
4981 /* ----------------------------- SNIP -----------------------------
4982 Anything added to the cleanup chain beyond this point is assumed
4983 to be part of a breakpoint. If the breakpoint create goes
4984 through then that memory is not cleaned up. */
4985 breakpoint_chain = make_cleanup (null_cleanup, 0);
4987 /* Mark the contents of the addr_string for cleanup. These go on
4988 the breakpoint_chain and only occure if the breakpoint create
4990 for (i = 0; i < sals.nelts; i++)
4992 if (addr_string[i] != NULL)
4993 make_cleanup (xfree, addr_string[i]);
4996 /* Wait until now before checking for garbage at the end of the
4997 address. That way cleanups can take care of freeing any
4999 if (*address_end != '\0')
5000 error ("Garbage %s following breakpoint address", address_end);
5002 /* Resolve all line numbers to PC's. */
5003 breakpoint_sals_to_pc (&sals, args->address);
5005 /* Verify that conditions can be parsed, before setting any
5007 for (i = 0; i < sals.nelts; i++)
5009 if (args->condition != NULL)
5011 char *tok = args->condition;
5012 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5014 error ("Garbage %s follows condition", tok);
5015 make_cleanup (xfree, cond[i]);
5016 cond_string[i] = xstrdup (args->condition);
5020 create_breakpoints (sals, addr_string, cond, cond_string,
5021 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5022 args->tempflag ? disp_del : disp_donttouch,
5023 args->thread, args->ignore_count, 0/*from-tty*/);
5025 /* That's it. Discard the cleanups for data inserted into the
5027 discard_cleanups (breakpoint_chain);
5028 /* But cleanup everything else. */
5029 do_cleanups (old_chain);
5034 gdb_breakpoint (char *address, char *condition,
5035 int hardwareflag, int tempflag,
5036 int thread, int ignore_count)
5038 struct captured_breakpoint_args args;
5039 args.address = address;
5040 args.condition = condition;
5041 args.hardwareflag = hardwareflag;
5042 args.tempflag = tempflag;
5043 args.thread = thread;
5044 args.ignore_count = ignore_count;
5045 return catch_errors (do_captured_breakpoint, &args,
5046 NULL, RETURN_MASK_ALL);
5051 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
5053 struct frame_info *frame;
5054 CORE_ADDR low, high, selected_pc = 0;
5055 char *extra_args = NULL;
5057 int extra_args_len = 0, if_arg = 0;
5060 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5063 if (default_breakpoint_valid)
5065 if (deprecated_selected_frame)
5067 selected_pc = get_frame_pc (deprecated_selected_frame);
5072 error ("No selected frame.");
5075 error ("No default breakpoint address now.");
5079 extra_args = strchr (arg, ' ');
5083 extra_args_len = strlen (extra_args);
5084 level_arg = (char *) xmalloc (extra_args - arg);
5085 strncpy (level_arg, arg, extra_args - arg - 1);
5086 level_arg[extra_args - arg - 1] = '\0';
5090 level_arg = (char *) xmalloc (strlen (arg) + 1);
5091 strcpy (level_arg, arg);
5094 frame = parse_frame_specification (level_arg);
5096 selected_pc = get_frame_pc (frame);
5103 extra_args_len = strlen (arg);
5108 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5112 addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args);
5114 addr_string = xstrprintf ("*0x%s", paddr_nz (high));
5115 break_command_1 (addr_string, flag, from_tty);
5116 xfree (addr_string);
5119 error ("No function contains the specified address");
5122 error ("Unable to set breakpoint at procedure exit");
5127 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5129 char *addr_string, *break_string, *beg_addr_string;
5130 CORE_ADDR low, high;
5131 struct symtabs_and_lines sals;
5132 struct symtab_and_line sal;
5133 struct cleanup *old_chain;
5134 char *extra_args = NULL;
5135 int extra_args_len = 0;
5139 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5141 if (default_breakpoint_valid)
5143 if (deprecated_selected_frame)
5145 addr_string = xstrprintf ("*0x%s",
5146 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5151 error ("No selected frame.");
5154 error ("No default breakpoint address now.");
5158 addr_string = (char *) xmalloc (strlen (arg) + 1);
5159 strcpy (addr_string, arg);
5165 extra_args_len = strlen (arg);
5169 /* get the stuff after the function name or address */
5170 extra_args = strchr (arg, ' ');
5174 extra_args_len = strlen (extra_args);
5181 beg_addr_string = addr_string;
5182 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5185 xfree (beg_addr_string);
5186 old_chain = make_cleanup (xfree, sals.sals);
5187 for (i = 0; (i < sals.nelts); i++)
5190 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5194 break_string = xstrprintf ("*0x%s %s", paddr_nz (high),
5197 break_string = xstrprintf ("*0x%s", paddr_nz (high));
5198 break_command_1 (break_string, flag, from_tty);
5199 xfree (break_string);
5202 error ("No function contains the specified address");
5206 warning ("Multiple breakpoints were set.\n");
5207 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5209 do_cleanups (old_chain);
5213 /* Helper function for break_command_1 and disassemble_command. */
5216 resolve_sal_pc (struct symtab_and_line *sal)
5220 if (sal->pc == 0 && sal->symtab != NULL)
5222 if (!find_line_pc (sal->symtab, sal->line, &pc))
5223 error ("No line %d in file \"%s\".",
5224 sal->line, sal->symtab->filename);
5228 if (sal->section == 0 && sal->symtab != NULL)
5230 struct blockvector *bv;
5235 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5238 b = BLOCKVECTOR_BLOCK (bv, index);
5239 sym = block_function (b);
5242 fixup_symbol_section (sym, sal->symtab->objfile);
5243 sal->section = SYMBOL_BFD_SECTION (sym);
5247 /* It really is worthwhile to have the section, so we'll just
5248 have to look harder. This case can be executed if we have
5249 line numbers but no functions (as can happen in assembly
5252 struct minimal_symbol *msym;
5254 msym = lookup_minimal_symbol_by_pc (sal->pc);
5256 sal->section = SYMBOL_BFD_SECTION (msym);
5263 break_command (char *arg, int from_tty)
5265 break_command_1 (arg, 0, from_tty);
5269 break_at_finish_command (char *arg, int from_tty)
5271 break_at_finish_command_1 (arg, 0, from_tty);
5275 break_at_finish_at_depth_command (char *arg, int from_tty)
5277 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5281 tbreak_command (char *arg, int from_tty)
5283 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5287 tbreak_at_finish_command (char *arg, int from_tty)
5289 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5293 hbreak_command (char *arg, int from_tty)
5295 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5299 thbreak_command (char *arg, int from_tty)
5301 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5305 stop_command (char *arg, int from_tty)
5307 printf_filtered ("Specify the type of breakpoint to set.\n\
5308 Usage: stop in <function | address>\n\
5313 stopin_command (char *arg, int from_tty)
5317 if (arg == (char *) NULL)
5319 else if (*arg != '*')
5324 /* look for a ':'. If this is a line number specification, then
5325 say it is bad, otherwise, it should be an address or
5326 function/method name */
5327 while (*argptr && !hasColon)
5329 hasColon = (*argptr == ':');
5334 badInput = (*argptr != ':'); /* Not a class::method */
5336 badInput = isdigit (*arg); /* a simple line number */
5340 printf_filtered ("Usage: stop in <function | address>\n");
5342 break_command_1 (arg, 0, from_tty);
5346 stopat_command (char *arg, int from_tty)
5350 if (arg == (char *) NULL || *arg == '*') /* no line number */
5357 /* look for a ':'. If there is a '::' then get out, otherwise
5358 it is probably a line number. */
5359 while (*argptr && !hasColon)
5361 hasColon = (*argptr == ':');
5366 badInput = (*argptr == ':'); /* we have class::method */
5368 badInput = !isdigit (*arg); /* not a line number */
5372 printf_filtered ("Usage: stop at <line>\n");
5374 break_command_1 (arg, 0, from_tty);
5377 /* accessflag: hw_write: watch write,
5378 hw_read: watch read,
5379 hw_access: watch access (read or write) */
5381 watch_command_1 (char *arg, int accessflag, int from_tty)
5383 struct breakpoint *b;
5384 struct symtab_and_line sal;
5385 struct expression *exp;
5386 struct block *exp_valid_block;
5387 struct value *val, *mark;
5388 struct frame_info *frame;
5389 struct frame_info *prev_frame = NULL;
5390 char *exp_start = NULL;
5391 char *exp_end = NULL;
5392 char *tok, *end_tok;
5394 char *cond_start = NULL;
5395 char *cond_end = NULL;
5396 struct expression *cond = NULL;
5397 int i, other_type_used, target_resources_ok = 0;
5398 enum bptype bp_type;
5401 init_sal (&sal); /* initialize to zeroes */
5403 /* Parse arguments. */
5404 innermost_block = NULL;
5406 exp = parse_exp_1 (&arg, 0, 0);
5408 exp_valid_block = innermost_block;
5409 mark = value_mark ();
5410 val = evaluate_expression (exp);
5411 release_value (val);
5412 if (VALUE_LAZY (val))
5413 value_fetch_lazy (val);
5416 while (*tok == ' ' || *tok == '\t')
5420 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5423 toklen = end_tok - tok;
5424 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5426 tok = cond_start = end_tok + 1;
5427 cond = parse_exp_1 (&tok, 0, 0);
5431 error ("Junk at end of command.");
5433 if (accessflag == hw_read)
5434 bp_type = bp_read_watchpoint;
5435 else if (accessflag == hw_access)
5436 bp_type = bp_access_watchpoint;
5438 bp_type = bp_hardware_watchpoint;
5440 mem_cnt = can_use_hardware_watchpoint (val);
5441 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5442 error ("Expression cannot be implemented with read/access watchpoint.");
5445 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5446 target_resources_ok =
5447 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5449 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5450 error ("Target does not support this type of hardware watchpoint.");
5452 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5453 error ("Target can only support one kind of HW watchpoint at a time.");
5456 #if defined(HPUXHPPA)
5457 /* On HP-UX if you set a h/w
5458 watchpoint before the "run" command, the inferior dies with a e.g.,
5459 SIGILL once you start it. I initially believed this was due to a
5460 bad interaction between page protection traps and the initial
5461 startup sequence by the dynamic linker.
5463 However, I tried avoiding that by having HP-UX's implementation of
5464 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5465 yet, which forced slow watches before a "run" or "attach", and it
5466 still fails somewhere in the startup code.
5468 Until I figure out what's happening, I'm disallowing watches altogether
5469 before the "run" or "attach" command. We'll tell the user they must
5470 set watches after getting the program started. */
5471 if (!target_has_execution)
5473 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5476 #endif /* HPUXHPPA */
5478 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5479 watchpoint could not be set. */
5480 if (!mem_cnt || target_resources_ok <= 0)
5481 bp_type = bp_watchpoint;
5483 /* Now set up the breakpoint. */
5484 b = set_raw_breakpoint (sal, bp_type);
5485 set_breakpoint_count (breakpoint_count + 1);
5486 b->number = breakpoint_count;
5487 b->disposition = disp_donttouch;
5489 b->exp_valid_block = exp_valid_block;
5490 b->exp_string = savestring (exp_start, exp_end - exp_start);
5494 b->cond_string = savestring (cond_start, cond_end - cond_start);
5498 frame = block_innermost_frame (exp_valid_block);
5501 prev_frame = get_prev_frame (frame);
5502 b->watchpoint_frame = get_frame_id (frame);
5506 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5509 /* If the expression is "local", then set up a "watchpoint scope"
5510 breakpoint at the point where we've left the scope of the watchpoint
5512 if (innermost_block)
5516 struct breakpoint *scope_breakpoint;
5517 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5518 bp_watchpoint_scope);
5520 scope_breakpoint->enable_state = bp_enabled;
5522 /* Automatically delete the breakpoint when it hits. */
5523 scope_breakpoint->disposition = disp_del;
5525 /* Only break in the proper frame (help with recursion). */
5526 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5528 /* Set the address at which we will stop. */
5529 scope_breakpoint->requested_address = get_frame_pc (prev_frame);
5530 scope_breakpoint->address =
5531 adjust_breakpoint_address (scope_breakpoint->requested_address);
5533 /* The scope breakpoint is related to the watchpoint. We
5534 will need to act on them together. */
5535 b->related_breakpoint = scope_breakpoint;
5538 value_free_to_mark (mark);
5542 /* Return count of locations need to be watched and can be handled
5543 in hardware. If the watchpoint can not be handled
5544 in hardware return zero. */
5546 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5547 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5548 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5551 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5552 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5553 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5557 can_use_hardware_watchpoint (struct value *v)
5559 int found_memory_cnt = 0;
5560 struct value *head = v;
5562 /* Did the user specifically forbid us to use hardware watchpoints? */
5563 if (!can_use_hw_watchpoints)
5566 /* Make sure that the value of the expression depends only upon
5567 memory contents, and values computed from them within GDB. If we
5568 find any register references or function calls, we can't use a
5569 hardware watchpoint.
5571 The idea here is that evaluating an expression generates a series
5572 of values, one holding the value of every subexpression. (The
5573 expression a*b+c has five subexpressions: a, b, a*b, c, and
5574 a*b+c.) GDB's values hold almost enough information to establish
5575 the criteria given above --- they identify memory lvalues,
5576 register lvalues, computed values, etcetera. So we can evaluate
5577 the expression, and then scan the chain of values that leaves
5578 behind to decide whether we can detect any possible change to the
5579 expression's final value using only hardware watchpoints.
5581 However, I don't think that the values returned by inferior
5582 function calls are special in any way. So this function may not
5583 notice that an expression involving an inferior function call
5584 can't be watched with hardware watchpoints. FIXME. */
5585 for (; v; v = v->next)
5587 if (VALUE_LVAL (v) == lval_memory)
5590 /* A lazy memory lvalue is one that GDB never needed to fetch;
5591 we either just used its address (e.g., `a' in `a.b') or
5592 we never needed it at all (e.g., `a' in `a,b'). */
5596 /* Ahh, memory we actually used! Check if we can cover
5597 it with hardware watchpoints. */
5598 struct type *vtype = check_typedef (VALUE_TYPE (v));
5600 /* We only watch structs and arrays if user asked for it
5601 explicitly, never if they just happen to appear in a
5602 middle of some value chain. */
5604 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5605 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5607 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5608 int len = TYPE_LENGTH (VALUE_TYPE (v));
5610 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5617 else if (v->lval != not_lval && v->modifiable == 0)
5618 return 0; /* ??? What does this represent? */
5619 else if (v->lval == lval_register)
5620 return 0; /* cannot watch a register with a HW watchpoint */
5623 /* The expression itself looks suitable for using a hardware
5624 watchpoint, but give the target machine a chance to reject it. */
5625 return found_memory_cnt;
5629 watch_command_wrapper (char *arg, int from_tty)
5631 watch_command (arg, from_tty);
5635 watch_command (char *arg, int from_tty)
5637 watch_command_1 (arg, hw_write, from_tty);
5641 rwatch_command_wrapper (char *arg, int from_tty)
5643 rwatch_command (arg, from_tty);
5647 rwatch_command (char *arg, int from_tty)
5649 watch_command_1 (arg, hw_read, from_tty);
5653 awatch_command_wrapper (char *arg, int from_tty)
5655 awatch_command (arg, from_tty);
5659 awatch_command (char *arg, int from_tty)
5661 watch_command_1 (arg, hw_access, from_tty);
5665 /* Helper routines for the until_command routine in infcmd.c. Here
5666 because it uses the mechanisms of breakpoints. */
5668 /* This function is called by fetch_inferior_event via the
5669 cmd_continuation pointer, to complete the until command. It takes
5670 care of cleaning up the temporary breakpoints set up by the until
5673 until_break_command_continuation (struct continuation_arg *arg)
5675 struct cleanup *cleanups;
5677 cleanups = (struct cleanup *) arg->data.pointer;
5678 do_exec_cleanups (cleanups);
5682 until_break_command (char *arg, int from_tty, int anywhere)
5684 struct symtabs_and_lines sals;
5685 struct symtab_and_line sal;
5686 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5687 struct breakpoint *breakpoint;
5688 struct cleanup *old_chain;
5689 struct continuation_arg *arg1;
5692 clear_proceed_status ();
5694 /* Set a breakpoint where the user wants it and at return from
5697 if (default_breakpoint_valid)
5698 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5699 default_breakpoint_line, (char ***) NULL);
5701 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5702 0, (char ***) NULL);
5704 if (sals.nelts != 1)
5705 error ("Couldn't get information on specified line.");
5708 xfree (sals.sals); /* malloc'd, so freed */
5711 error ("Junk at end of arguments.");
5713 resolve_sal_pc (&sal);
5716 /* If the user told us to continue until a specified location,
5717 we don't specify a frame at which we need to stop. */
5718 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5720 /* Otherwise, specify the current frame, because we want to stop only
5721 at the very same frame. */
5722 breakpoint = set_momentary_breakpoint (sal,
5723 get_frame_id (deprecated_selected_frame),
5726 if (!event_loop_p || !target_can_async_p ())
5727 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5729 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5731 /* If we are running asynchronously, and the target supports async
5732 execution, we are not waiting for the target to stop, in the call
5733 tp proceed, below. This means that we cannot delete the
5734 brekpoints until the target has actually stopped. The only place
5735 where we get a chance to do that is in fetch_inferior_event, so
5736 we must set things up for that. */
5738 if (event_loop_p && target_can_async_p ())
5740 /* In this case the arg for the continuation is just the point
5741 in the exec_cleanups chain from where to start doing
5742 cleanups, because all the continuation does is the cleanups in
5743 the exec_cleanup_chain. */
5745 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5747 arg1->data.pointer = old_chain;
5749 add_continuation (until_break_command_continuation, arg1);
5752 /* Keep within the current frame, or in frames called by the current
5756 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5757 sal.pc = get_frame_pc (prev_frame);
5758 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5760 if (!event_loop_p || !target_can_async_p ())
5761 make_cleanup_delete_breakpoint (breakpoint);
5763 make_exec_cleanup_delete_breakpoint (breakpoint);
5766 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5767 /* Do the cleanups now, anly if we are not running asynchronously,
5768 of if we are, but the target is still synchronous. */
5769 if (!event_loop_p || !target_can_async_p ())
5770 do_cleanups (old_chain);
5774 /* These aren't used; I don't konw what they were for. */
5775 /* Set a breakpoint at the catch clause for NAME. */
5777 catch_breakpoint (char *name)
5782 disable_catch_breakpoint (void)
5787 delete_catch_breakpoint (void)
5792 enable_catch_breakpoint (void)
5798 ep_skip_leading_whitespace (char **s)
5800 if ((s == NULL) || (*s == NULL))
5802 while (isspace (**s))
5806 /* This function examines a string, and attempts to find a token
5807 that might be an event name in the leading characters. If a
5808 possible match is found, a pointer to the last character of
5809 the token is returned. Else, NULL is returned. */
5812 ep_find_event_name_end (char *arg)
5815 char *event_name_end = NULL;
5817 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5821 /* We break out of the loop when we find a token delimiter.
5822 Basically, we're looking for alphanumerics and underscores;
5823 anything else delimites the token. */
5826 if (!isalnum (*s) && (*s != '_'))
5832 return event_name_end;
5836 /* This function attempts to parse an optional "if <cond>" clause
5837 from the arg string. If one is not found, it returns NULL.
5839 Else, it returns a pointer to the condition string. (It does not
5840 attempt to evaluate the string against a particular block.) And,
5841 it updates arg to point to the first character following the parsed
5842 if clause in the arg string. */
5845 ep_parse_optional_if_clause (char **arg)
5849 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5852 /* Skip the "if" keyword. */
5855 /* Skip any extra leading whitespace, and record the start of the
5856 condition string. */
5857 ep_skip_leading_whitespace (arg);
5860 /* Assume that the condition occupies the remainder of the arg string. */
5861 (*arg) += strlen (cond_string);
5866 /* This function attempts to parse an optional filename from the arg
5867 string. If one is not found, it returns NULL.
5869 Else, it returns a pointer to the parsed filename. (This function
5870 makes no attempt to verify that a file of that name exists, or is
5871 accessible.) And, it updates arg to point to the first character
5872 following the parsed filename in the arg string.
5874 Note that clients needing to preserve the returned filename for
5875 future access should copy it to their own buffers. */
5877 ep_parse_optional_filename (char **arg)
5879 static char filename[1024];
5884 if ((*arg_p == '\0') || isspace (*arg_p))
5902 /* Commands to deal with catching events, such as signals, exceptions,
5903 process start/exit, etc. */
5907 catch_fork, catch_vfork
5911 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5912 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5913 char *arg, int tempflag, int from_tty);
5916 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5919 char *cond_string = NULL;
5921 ep_skip_leading_whitespace (&arg);
5923 /* The allowed syntax is:
5925 catch [v]fork if <cond>
5927 First, check if there's an if clause. */
5928 cond_string = ep_parse_optional_if_clause (&arg);
5930 if ((*arg != '\0') && !isspace (*arg))
5931 error ("Junk at end of arguments.");
5933 /* If this target supports it, create a fork or vfork catchpoint
5934 and enable reporting of such events. */
5938 create_fork_event_catchpoint (tempflag, cond_string);
5941 create_vfork_event_catchpoint (tempflag, cond_string);
5944 error ("unsupported or unknown fork kind; cannot catch it");
5950 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5952 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5954 char *cond_string = NULL;
5956 ep_skip_leading_whitespace (&arg);
5958 /* The allowed syntax is:
5960 catch exec if <cond>
5962 First, check if there's an if clause. */
5963 cond_string = ep_parse_optional_if_clause (&arg);
5965 if ((*arg != '\0') && !isspace (*arg))
5966 error ("Junk at end of arguments.");
5968 /* If this target supports it, create an exec catchpoint
5969 and enable reporting of such events. */
5970 create_exec_event_catchpoint (tempflag, cond_string);
5974 #if defined(SOLIB_ADD)
5976 catch_load_command_1 (char *arg, int tempflag, int from_tty)
5978 char *dll_pathname = NULL;
5979 char *cond_string = NULL;
5981 ep_skip_leading_whitespace (&arg);
5983 /* The allowed syntax is:
5985 catch load if <cond>
5986 catch load <filename>
5987 catch load <filename> if <cond>
5989 The user is not allowed to specify the <filename> after an
5992 We'll ignore the pathological case of a file named "if".
5994 First, check if there's an if clause. If so, then there
5995 cannot be a filename. */
5996 cond_string = ep_parse_optional_if_clause (&arg);
5998 /* If there was an if clause, then there cannot be a filename.
5999 Else, there might be a filename and an if clause. */
6000 if (cond_string == NULL)
6002 dll_pathname = ep_parse_optional_filename (&arg);
6003 ep_skip_leading_whitespace (&arg);
6004 cond_string = ep_parse_optional_if_clause (&arg);
6007 if ((*arg != '\0') && !isspace (*arg))
6008 error ("Junk at end of arguments.");
6010 /* Create a load breakpoint that only triggers when a load of
6011 the specified dll (or any dll, if no pathname was specified)
6013 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6014 dll_pathname, cond_string);
6018 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6020 char *dll_pathname = NULL;
6021 char *cond_string = NULL;
6023 ep_skip_leading_whitespace (&arg);
6025 /* The allowed syntax is:
6027 catch unload if <cond>
6028 catch unload <filename>
6029 catch unload <filename> if <cond>
6031 The user is not allowed to specify the <filename> after an
6034 We'll ignore the pathological case of a file named "if".
6036 First, check if there's an if clause. If so, then there
6037 cannot be a filename. */
6038 cond_string = ep_parse_optional_if_clause (&arg);
6040 /* If there was an if clause, then there cannot be a filename.
6041 Else, there might be a filename and an if clause. */
6042 if (cond_string == NULL)
6044 dll_pathname = ep_parse_optional_filename (&arg);
6045 ep_skip_leading_whitespace (&arg);
6046 cond_string = ep_parse_optional_if_clause (&arg);
6049 if ((*arg != '\0') && !isspace (*arg))
6050 error ("Junk at end of arguments.");
6052 /* Create an unload breakpoint that only triggers when an unload of
6053 the specified dll (or any dll, if no pathname was specified)
6055 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6056 dll_pathname, cond_string);
6058 #endif /* SOLIB_ADD */
6060 /* Commands to deal with catching exceptions. */
6062 /* Set a breakpoint at the specified callback routine for an
6063 exception event callback */
6066 create_exception_catchpoint (int tempflag, char *cond_string,
6067 enum exception_event_kind ex_event,
6068 struct symtab_and_line *sal)
6070 struct breakpoint *b;
6071 int thread = -1; /* All threads. */
6074 if (!sal) /* no exception support? */
6079 case EX_EVENT_THROW:
6080 bptype = bp_catch_throw;
6082 case EX_EVENT_CATCH:
6083 bptype = bp_catch_catch;
6085 default: /* error condition */
6086 error ("Internal error -- invalid catchpoint kind");
6089 b = set_raw_breakpoint (*sal, bptype);
6090 set_breakpoint_count (breakpoint_count + 1);
6091 b->number = breakpoint_count;
6093 b->cond_string = (cond_string == NULL) ?
6094 NULL : savestring (cond_string, strlen (cond_string));
6096 b->addr_string = NULL;
6097 b->enable_state = bp_enabled;
6098 b->disposition = tempflag ? disp_del : disp_donttouch;
6102 static enum print_stop_action
6103 print_exception_catchpoint (struct breakpoint *b)
6105 annotate_catchpoint (b->number);
6107 if (strstr (b->addr_string, "throw") != NULL)
6108 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6111 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6114 return PRINT_SRC_AND_LOC;
6118 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6123 ui_out_field_core_addr (uiout, "addr", b->address);
6126 *last_addr = b->address;
6127 if (strstr (b->addr_string, "throw") != NULL)
6128 ui_out_field_string (uiout, "what", "exception throw");
6130 ui_out_field_string (uiout, "what", "exception catch");
6134 print_mention_exception_catchpoint (struct breakpoint *b)
6136 if (strstr (b->addr_string, "throw") != NULL)
6137 printf_filtered ("Catchpoint %d (throw)", b->number);
6139 printf_filtered ("Catchpoint %d (catch)", b->number);
6142 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6143 print_exception_catchpoint,
6144 print_one_exception_catchpoint,
6145 print_mention_exception_catchpoint
6149 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6150 enum exception_event_kind ex_event, int from_tty)
6152 char *trigger_func_name, *nameptr;
6153 struct symtabs_and_lines sals;
6154 struct breakpoint *b;
6156 if (ex_event == EX_EVENT_CATCH)
6157 trigger_func_name = xstrdup ("__cxa_begin_catch");
6159 trigger_func_name = xstrdup ("__cxa_throw");
6161 nameptr = trigger_func_name;
6162 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL);
6163 if (sals.nelts == 0)
6165 xfree (trigger_func_name);
6169 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6170 set_breakpoint_count (breakpoint_count + 1);
6171 b->number = breakpoint_count;
6173 b->cond_string = (cond_string == NULL) ?
6174 NULL : savestring (cond_string, strlen (cond_string));
6176 b->addr_string = trigger_func_name;
6177 b->enable_state = bp_enabled;
6178 b->disposition = tempflag ? disp_del : disp_donttouch;
6179 b->ops = &gnu_v3_exception_catchpoint_ops;
6186 /* Deal with "catch catch" and "catch throw" commands */
6189 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6190 int tempflag, int from_tty)
6192 char *cond_string = NULL;
6193 struct symtab_and_line *sal = NULL;
6195 ep_skip_leading_whitespace (&arg);
6197 cond_string = ep_parse_optional_if_clause (&arg);
6199 if ((*arg != '\0') && !isspace (*arg))
6200 error ("Junk at end of arguments.");
6202 if ((ex_event != EX_EVENT_THROW) &&
6203 (ex_event != EX_EVENT_CATCH))
6204 error ("Unsupported or unknown exception event; cannot catch it");
6206 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6209 /* See if we can find a callback routine */
6210 sal = target_enable_exception_callback (ex_event, 1);
6214 /* We have callbacks from the runtime system for exceptions.
6215 Set a breakpoint on the sal found, if no errors */
6216 if (sal != (struct symtab_and_line *) -1)
6217 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6219 return; /* something went wrong with setting up callbacks */
6222 warning ("Unsupported with this platform/compiler combination.");
6225 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6226 inside a catch_errors */
6229 cover_target_enable_exception_callback (void *arg)
6231 args_for_catchpoint_enable *args = arg;
6232 struct symtab_and_line *sal;
6233 sal = target_enable_exception_callback (args->kind, args->enable_p);
6236 else if (sal == (struct symtab_and_line *) -1)
6239 return 1; /*is valid */
6243 catch_command_1 (char *arg, int tempflag, int from_tty)
6246 /* The first argument may be an event name, such as "start" or "load".
6247 If so, then handle it as such. If it doesn't match an event name,
6248 then attempt to interpret it as an exception name. (This latter is
6249 the v4.16-and-earlier GDB meaning of the "catch" command.)
6251 First, try to find the bounds of what might be an event name. */
6252 char *arg1_start = arg;
6256 if (arg1_start == NULL)
6258 /* Old behaviour was to use pre-v-4.16 syntax */
6259 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6261 /* Now, this is not allowed */
6262 error ("Catch requires an event name.");
6265 arg1_end = ep_find_event_name_end (arg1_start);
6266 if (arg1_end == NULL)
6267 error ("catch requires an event");
6268 arg1_length = arg1_end + 1 - arg1_start;
6270 /* Try to match what we found against known event names. */
6271 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6273 error ("Catch of signal not yet implemented");
6275 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6277 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6278 tempflag, from_tty);
6280 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6282 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6283 tempflag, from_tty);
6285 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6287 error ("Catch of thread_start not yet implemented");
6289 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6291 error ("Catch of thread_exit not yet implemented");
6293 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6295 error ("Catch of thread_join not yet implemented");
6297 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6299 error ("Catch of start not yet implemented");
6301 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6303 error ("Catch of exit not yet implemented");
6305 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6307 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6308 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6310 error ("Catch of fork not yet implemented");
6313 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6315 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6316 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6318 error ("Catch of vfork not yet implemented");
6321 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6323 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6324 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6326 error ("Catch of exec not yet implemented");
6329 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6331 #if defined(SOLIB_ADD)
6332 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6334 error ("Catch of load not implemented");
6337 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6339 #if defined(SOLIB_ADD)
6340 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6342 error ("Catch of load not implemented");
6345 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6347 error ("Catch of stop not yet implemented");
6350 /* This doesn't appear to be an event name */
6354 /* Pre-v.4.16 behaviour was to treat the argument
6355 as the name of an exception */
6356 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6357 /* Now this is not allowed */
6358 error ("Unknown event kind specified for catch");
6363 /* Used by the gui, could be made a worker for other things. */
6366 set_breakpoint_sal (struct symtab_and_line sal)
6368 struct breakpoint *b;
6369 b = set_raw_breakpoint (sal, bp_breakpoint);
6370 set_breakpoint_count (breakpoint_count + 1);
6371 b->number = breakpoint_count;
6378 /* These aren't used; I don't know what they were for. */
6379 /* Disable breakpoints on all catch clauses described in ARGS. */
6381 disable_catch (char *args)
6383 /* Map the disable command to catch clauses described in ARGS. */
6386 /* Enable breakpoints on all catch clauses described in ARGS. */
6388 enable_catch (char *args)
6390 /* Map the disable command to catch clauses described in ARGS. */
6393 /* Delete breakpoints on all catch clauses in the active scope. */
6395 delete_catch (char *args)
6397 /* Map the delete command to catch clauses described in ARGS. */
6402 catch_command (char *arg, int from_tty)
6404 catch_command_1 (arg, 0, from_tty);
6409 tcatch_command (char *arg, int from_tty)
6411 catch_command_1 (arg, 1, from_tty);
6414 /* Delete breakpoints by address or line. */
6417 clear_command (char *arg, int from_tty)
6419 struct breakpoint *b, *tmp, *prev, *found;
6421 struct symtabs_and_lines sals;
6422 struct symtab_and_line sal;
6427 sals = decode_line_spec (arg, 1);
6432 sals.sals = (struct symtab_and_line *)
6433 xmalloc (sizeof (struct symtab_and_line));
6434 make_cleanup (xfree, sals.sals);
6435 init_sal (&sal); /* initialize to zeroes */
6436 sal.line = default_breakpoint_line;
6437 sal.symtab = default_breakpoint_symtab;
6438 sal.pc = default_breakpoint_address;
6439 if (sal.symtab == 0)
6440 error ("No source file specified.");
6448 /* For each line spec given, delete bps which correspond
6449 to it. Do it in two passes, solely to preserve the current
6450 behavior that from_tty is forced true if we delete more than
6454 for (i = 0; i < sals.nelts; i++)
6456 /* If exact pc given, clear bpts at that pc.
6457 If line given (pc == 0), clear all bpts on specified line.
6458 If defaulting, clear all bpts on default line
6461 defaulting sal.pc != 0 tests to do
6466 1 0 <can't happen> */
6471 /* Find all matching breakpoints, remove them from the
6472 breakpoint chain, and add them to the 'found' chain. */
6473 ALL_BREAKPOINTS_SAFE (b, tmp)
6475 /* Are we going to delete b? */
6476 if (b->type != bp_none
6477 && b->type != bp_watchpoint
6478 && b->type != bp_hardware_watchpoint
6479 && b->type != bp_read_watchpoint
6480 && b->type != bp_access_watchpoint
6481 /* Not if b is a watchpoint of any sort... */
6482 && (((sal.pc && (b->address == sal.pc))
6483 && (!section_is_overlay (b->section)
6484 || b->section == sal.section))
6485 /* Yes, if sal.pc matches b (modulo overlays). */
6486 || ((default_match || (0 == sal.pc))
6487 && b->source_file != NULL
6488 && sal.symtab != NULL
6489 && STREQ (b->source_file, sal.symtab->filename)
6490 && b->line_number == sal.line)))
6491 /* Yes, if sal source file and line matches b. */
6493 /* Remove it from breakpoint_chain... */
6494 if (b == breakpoint_chain)
6496 /* b is at the head of the list */
6497 breakpoint_chain = b->next;
6501 prev->next = b->next;
6503 /* And add it to 'found' chain. */
6509 /* Keep b, and keep a pointer to it. */
6514 /* Now go thru the 'found' chain and delete them. */
6518 error ("No breakpoint at %s.", arg);
6520 error ("No breakpoint at this line.");
6524 from_tty = 1; /* Always report if deleted more than one */
6526 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6527 breakpoints_changed ();
6531 printf_unfiltered ("%d ", found->number);
6533 delete_breakpoint (found);
6537 putchar_unfiltered ('\n');
6540 /* Delete breakpoint in BS if they are `delete' breakpoints and
6541 all breakpoints that are marked for deletion, whether hit or not.
6542 This is called after any breakpoint is hit, or after errors. */
6545 breakpoint_auto_delete (bpstat bs)
6547 struct breakpoint *b, *temp;
6549 for (; bs; bs = bs->next)
6550 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6552 delete_breakpoint (bs->breakpoint_at);
6554 ALL_BREAKPOINTS_SAFE (b, temp)
6556 if (b->disposition == disp_del_at_next_stop)
6557 delete_breakpoint (b);
6561 /* Delete a breakpoint and clean up all traces of it in the data
6565 delete_breakpoint (struct breakpoint *bpt)
6567 struct breakpoint *b;
6571 error ("Internal error (attempted to delete a NULL breakpoint)");
6574 /* Has this bp already been deleted? This can happen because multiple
6575 lists can hold pointers to bp's. bpstat lists are especial culprits.
6577 One example of this happening is a watchpoint's scope bp. When the
6578 scope bp triggers, we notice that the watchpoint is out of scope, and
6579 delete it. We also delete its scope bp. But the scope bp is marked
6580 "auto-deleting", and is already on a bpstat. That bpstat is then
6581 checked for auto-deleting bp's, which are deleted.
6583 A real solution to this problem might involve reference counts in bp's,
6584 and/or giving them pointers back to their referencing bpstat's, and
6585 teaching delete_breakpoint to only free a bp's storage when no more
6586 references were extent. A cheaper bandaid was chosen. */
6587 if (bpt->type == bp_none)
6590 if (delete_breakpoint_hook)
6591 delete_breakpoint_hook (bpt);
6592 breakpoint_delete_event (bpt->number);
6595 remove_breakpoint (bpt, mark_inserted);
6597 if (breakpoint_chain == bpt)
6598 breakpoint_chain = bpt->next;
6600 /* If we have callback-style exception catchpoints, don't go through
6601 the adjustments to the C++ runtime library etc. if the inferior
6602 isn't actually running. target_enable_exception_callback for a
6603 null target ops vector gives an undesirable error message, so we
6604 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6605 exceptions are supported in this way, it's OK for now. FIXME */
6606 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6608 /* Format possible error msg */
6609 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6611 struct cleanup *cleanups = make_cleanup (xfree, message);
6612 args_for_catchpoint_enable args;
6613 args.kind = bpt->type == bp_catch_catch ?
6614 EX_EVENT_CATCH : EX_EVENT_THROW;
6616 catch_errors (cover_target_enable_exception_callback, &args,
6617 message, RETURN_MASK_ALL);
6618 do_cleanups (cleanups);
6625 b->next = bpt->next;
6629 check_duplicates (bpt);
6630 /* If this breakpoint was inserted, and there is another breakpoint
6631 at the same address, we need to insert the other breakpoint. */
6633 && bpt->type != bp_hardware_watchpoint
6634 && bpt->type != bp_read_watchpoint
6635 && bpt->type != bp_access_watchpoint
6636 && bpt->type != bp_catch_fork
6637 && bpt->type != bp_catch_vfork
6638 && bpt->type != bp_catch_exec)
6641 if (b->address == bpt->address
6642 && b->section == bpt->section
6644 && b->enable_state != bp_disabled
6645 && b->enable_state != bp_shlib_disabled
6646 && b->enable_state != bp_call_disabled)
6650 /* We should never reach this point if there is a permanent
6651 breakpoint at the same address as the one being deleted.
6652 If there is a permanent breakpoint somewhere, it should
6653 always be the only one inserted. */
6654 if (b->enable_state == bp_permanent)
6655 internal_error (__FILE__, __LINE__,
6656 "another breakpoint was inserted on top of "
6657 "a permanent breakpoint");
6659 if (b->type == bp_hardware_breakpoint)
6660 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6662 val = target_insert_breakpoint (b->address, b->shadow_contents);
6664 /* If there was an error in the insert, print a message, then stop execution. */
6667 struct ui_file *tmp_error_stream = mem_fileopen ();
6668 make_cleanup_ui_file_delete (tmp_error_stream);
6671 if (b->type == bp_hardware_breakpoint)
6673 fprintf_unfiltered (tmp_error_stream,
6674 "Cannot insert hardware breakpoint %d.\n"
6675 "You may have requested too many hardware breakpoints.\n",
6680 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6681 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6682 print_address_numeric (b->address, 1, tmp_error_stream);
6683 fprintf_filtered (tmp_error_stream, ": %s.\n",
6684 safe_strerror (val));
6687 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6688 target_terminal_ours_for_output ();
6689 error_stream(tmp_error_stream);
6696 free_command_lines (&bpt->commands);
6699 if (bpt->cond_string != NULL)
6700 xfree (bpt->cond_string);
6701 if (bpt->addr_string != NULL)
6702 xfree (bpt->addr_string);
6703 if (bpt->exp != NULL)
6705 if (bpt->exp_string != NULL)
6706 xfree (bpt->exp_string);
6707 if (bpt->val != NULL)
6708 value_free (bpt->val);
6709 if (bpt->source_file != NULL)
6710 xfree (bpt->source_file);
6711 if (bpt->dll_pathname != NULL)
6712 xfree (bpt->dll_pathname);
6713 if (bpt->triggered_dll_pathname != NULL)
6714 xfree (bpt->triggered_dll_pathname);
6715 if (bpt->exec_pathname != NULL)
6716 xfree (bpt->exec_pathname);
6718 /* Be sure no bpstat's are pointing at it after it's been freed. */
6719 /* FIXME, how can we find all bpstat's?
6720 We just check stop_bpstat for now. */
6721 for (bs = stop_bpstat; bs; bs = bs->next)
6722 if (bs->breakpoint_at == bpt)
6724 bs->breakpoint_at = NULL;
6726 /* bs->commands will be freed later. */
6728 /* On the chance that someone will soon try again to delete this same
6729 bp, we mark it as deleted before freeing its storage. */
6730 bpt->type = bp_none;
6736 do_delete_breakpoint_cleanup (void *b)
6738 delete_breakpoint (b);
6742 make_cleanup_delete_breakpoint (struct breakpoint *b)
6744 return make_cleanup (do_delete_breakpoint_cleanup, b);
6748 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6750 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6754 delete_command (char *arg, int from_tty)
6756 struct breakpoint *b, *temp;
6762 int breaks_to_delete = 0;
6764 /* Delete all breakpoints if no argument.
6765 Do not delete internal or call-dummy breakpoints, these
6766 have to be deleted with an explicit breakpoint number argument. */
6769 if (b->type != bp_call_dummy &&
6770 b->type != bp_shlib_event &&
6771 b->type != bp_thread_event &&
6772 b->type != bp_overlay_event &&
6774 breaks_to_delete = 1;
6777 /* Ask user only if there are some breakpoints to delete. */
6779 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6781 ALL_BREAKPOINTS_SAFE (b, temp)
6783 if (b->type != bp_call_dummy &&
6784 b->type != bp_shlib_event &&
6785 b->type != bp_thread_event &&
6786 b->type != bp_overlay_event &&
6788 delete_breakpoint (b);
6793 map_breakpoint_numbers (arg, delete_breakpoint);
6796 /* Reset a breakpoint given it's struct breakpoint * BINT.
6797 The value we return ends up being the return value from catch_errors.
6798 Unused in this case. */
6801 breakpoint_re_set_one (void *bint)
6803 /* get past catch_errs */
6804 struct breakpoint *b = (struct breakpoint *) bint;
6807 struct symtabs_and_lines sals;
6809 enum enable_state save_enable;
6814 warning ("attempted to reset apparently deleted breakpoint #%d?",
6818 case bp_hardware_breakpoint:
6820 case bp_catch_unload:
6821 if (b->addr_string == NULL)
6823 /* Anything without a string can't be re-set. */
6824 delete_breakpoint (b);
6827 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6829 ``And a hack it is, although Apple's Darwin version of GDB
6830 contains an almost identical hack to implement a "future
6831 break" command. It seems to work in many real world cases,
6832 but it is easy to come up with a test case where the patch
6833 doesn't help at all.''
6835 ``It seems that the way GDB implements breakpoints - in -
6836 shared - libraries was designed for a.out shared library
6837 systems (SunOS 4) where shared libraries were loaded at a
6838 fixed address in memory. Since ELF shared libraries can (and
6839 will) be loaded at any address in memory, things break.
6840 Fixing this is not trivial. Therefore, I'm not sure whether
6841 we should add this hack to the branch only. I cannot
6842 guarantee that things will be fixed on the trunk in the near
6845 In case we have a problem, disable this breakpoint. We'll
6846 restore its status if we succeed. Don't disable a
6847 shlib_disabled breakpoint though. There's a fair chance we
6848 can't re-set it if the shared library it's in hasn't been
6850 save_enable = b->enable_state;
6851 if (b->enable_state != bp_shlib_disabled)
6852 b->enable_state = bp_disabled;
6854 set_language (b->language);
6855 input_radix = b->input_radix;
6857 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6858 for (i = 0; i < sals.nelts; i++)
6860 resolve_sal_pc (&sals.sals[i]);
6862 /* Reparse conditions, they might contain references to the
6864 if (b->cond_string != NULL)
6869 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6872 /* We need to re-set the breakpoint if the address changes... */
6873 if (b->address != sals.sals[i].pc
6874 /* ...or new and old breakpoints both have source files, and
6875 the source file name or the line number changes... */
6876 || (b->source_file != NULL
6877 && sals.sals[i].symtab != NULL
6878 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6879 || b->line_number != sals.sals[i].line)
6881 /* ...or we switch between having a source file and not having
6883 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6886 if (b->source_file != NULL)
6887 xfree (b->source_file);
6888 if (sals.sals[i].symtab == NULL)
6889 b->source_file = NULL;
6892 savestring (sals.sals[i].symtab->filename,
6893 strlen (sals.sals[i].symtab->filename));
6894 b->line_number = sals.sals[i].line;
6895 b->requested_address = sals.sals[i].pc;
6896 b->address = adjust_breakpoint_address (b->requested_address);
6898 /* Used to check for duplicates here, but that can
6899 cause trouble, as it doesn't check for disabled
6904 /* Might be better to do this just once per breakpoint_re_set,
6905 rather than once for every breakpoint. */
6906 breakpoints_changed ();
6908 b->section = sals.sals[i].section;
6909 b->enable_state = save_enable; /* Restore it, this worked. */
6912 /* Now that this is re-enabled, check_duplicates
6914 check_duplicates (b);
6921 case bp_hardware_watchpoint:
6922 case bp_read_watchpoint:
6923 case bp_access_watchpoint:
6924 innermost_block = NULL;
6925 /* The issue arises of what context to evaluate this in. The
6926 same one as when it was set, but what does that mean when
6927 symbols have been re-read? We could save the filename and
6928 functionname, but if the context is more local than that, the
6929 best we could do would be something like how many levels deep
6930 and which index at that particular level, but that's going to
6931 be less stable than filenames or function names. */
6933 /* So for now, just use a global context. */
6936 b->exp = parse_expression (b->exp_string);
6937 b->exp_valid_block = innermost_block;
6938 mark = value_mark ();
6940 value_free (b->val);
6941 b->val = evaluate_expression (b->exp);
6942 release_value (b->val);
6943 if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled)
6944 value_fetch_lazy (b->val);
6946 if (b->cond_string != NULL)
6951 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6953 if (b->enable_state == bp_enabled)
6955 value_free_to_mark (mark);
6957 case bp_catch_catch:
6958 case bp_catch_throw:
6960 /* We needn't really do anything to reset these, since the mask
6961 that requests them is unaffected by e.g., new libraries being
6964 case bp_catch_vfork:
6969 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6971 /* Delete longjmp and overlay event breakpoints; they will be
6972 reset later by breakpoint_re_set. */
6974 case bp_longjmp_resume:
6975 case bp_overlay_event:
6976 delete_breakpoint (b);
6979 /* This breakpoint is special, it's set up when the inferior
6980 starts and we really don't want to touch it. */
6981 case bp_shlib_event:
6983 /* Like bp_shlib_event, this breakpoint type is special.
6984 Once it is set up, we do not want to touch it. */
6985 case bp_thread_event:
6987 /* Keep temporary breakpoints, which can be encountered when we step
6988 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6989 Otherwise these should have been blown away via the cleanup chain
6990 or by breakpoint_init_inferior when we rerun the executable. */
6993 case bp_watchpoint_scope:
6995 case bp_step_resume:
7002 /* Re-set all breakpoints after symbols have been re-loaded. */
7004 breakpoint_re_set (void)
7006 struct breakpoint *b, *temp;
7007 enum language save_language;
7008 int save_input_radix;
7010 save_language = current_language->la_language;
7011 save_input_radix = input_radix;
7012 ALL_BREAKPOINTS_SAFE (b, temp)
7014 /* Format possible error msg */
7015 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7017 struct cleanup *cleanups = make_cleanup (xfree, message);
7018 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7019 do_cleanups (cleanups);
7021 set_language (save_language);
7022 input_radix = save_input_radix;
7024 if (GET_LONGJMP_TARGET_P ())
7026 create_longjmp_breakpoint ("longjmp");
7027 create_longjmp_breakpoint ("_longjmp");
7028 create_longjmp_breakpoint ("siglongjmp");
7029 create_longjmp_breakpoint ("_siglongjmp");
7030 create_longjmp_breakpoint (NULL);
7033 create_overlay_event_breakpoint ("_ovly_debug_event");
7036 /* Reset the thread number of this breakpoint:
7038 - If the breakpoint is for all threads, leave it as-is.
7039 - Else, reset it to the current thread for inferior_ptid. */
7041 breakpoint_re_set_thread (struct breakpoint *b)
7043 if (b->thread != -1)
7045 if (in_thread_list (inferior_ptid))
7046 b->thread = pid_to_thread_id (inferior_ptid);
7050 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7051 If from_tty is nonzero, it prints a message to that effect,
7052 which ends with a period (no newline). */
7055 set_ignore_count (int bptnum, int count, int from_tty)
7057 struct breakpoint *b;
7063 if (b->number == bptnum)
7065 b->ignore_count = count;
7069 printf_filtered ("Will stop next time breakpoint %d is reached.",
7071 else if (count == 1)
7072 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7075 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7078 breakpoints_changed ();
7079 breakpoint_modify_event (b->number);
7083 error ("No breakpoint number %d.", bptnum);
7086 /* Clear the ignore counts of all breakpoints. */
7088 breakpoint_clear_ignore_counts (void)
7090 struct breakpoint *b;
7093 b->ignore_count = 0;
7096 /* Command to set ignore-count of breakpoint N to COUNT. */
7099 ignore_command (char *args, int from_tty)
7105 error_no_arg ("a breakpoint number");
7107 num = get_number (&p);
7109 error ("bad breakpoint number: '%s'", args);
7111 error ("Second argument (specified ignore-count) is missing.");
7113 set_ignore_count (num,
7114 longest_to_int (value_as_long (parse_and_eval (p))),
7117 printf_filtered ("\n");
7120 /* Call FUNCTION on each of the breakpoints
7121 whose numbers are given in ARGS. */
7124 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7129 struct breakpoint *b, *tmp;
7133 error_no_arg ("one or more breakpoint numbers");
7140 num = get_number_or_range (&p1);
7143 warning ("bad breakpoint number at or near '%s'", p);
7147 ALL_BREAKPOINTS_SAFE (b, tmp)
7148 if (b->number == num)
7150 struct breakpoint *related_breakpoint = b->related_breakpoint;
7153 if (related_breakpoint)
7154 function (related_breakpoint);
7158 printf_unfiltered ("No breakpoint number %d.\n", num);
7164 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7165 If from_tty is nonzero, it prints a message to that effect,
7166 which ends with a period (no newline). */
7169 disable_breakpoint (struct breakpoint *bpt)
7171 /* Never disable a watchpoint scope breakpoint; we want to
7172 hit them when we leave scope so we can delete both the
7173 watchpoint and its scope breakpoint at that time. */
7174 if (bpt->type == bp_watchpoint_scope)
7177 /* You can't disable permanent breakpoints. */
7178 if (bpt->enable_state == bp_permanent)
7181 bpt->enable_state = bp_disabled;
7183 check_duplicates (bpt);
7185 if (modify_breakpoint_hook)
7186 modify_breakpoint_hook (bpt);
7187 breakpoint_modify_event (bpt->number);
7191 disable_command (char *args, int from_tty)
7193 struct breakpoint *bpt;
7195 ALL_BREAKPOINTS (bpt)
7199 warning ("attempted to disable apparently deleted breakpoint #%d?",
7204 case bp_catch_unload:
7206 case bp_catch_vfork:
7208 case bp_catch_catch:
7209 case bp_catch_throw:
7210 case bp_hardware_breakpoint:
7212 case bp_hardware_watchpoint:
7213 case bp_read_watchpoint:
7214 case bp_access_watchpoint:
7215 disable_breakpoint (bpt);
7220 map_breakpoint_numbers (args, disable_breakpoint);
7224 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7226 struct frame_info *save_selected_frame = NULL;
7227 int save_selected_frame_level = -1;
7228 int target_resources_ok, other_type_used;
7231 if (bpt->type == bp_hardware_breakpoint)
7234 i = hw_breakpoint_used_count ();
7235 target_resources_ok =
7236 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7238 if (target_resources_ok == 0)
7239 error ("No hardware breakpoint support in the target.");
7240 else if (target_resources_ok < 0)
7241 error ("Hardware breakpoints used exceeds limit.");
7244 if (bpt->enable_state != bp_permanent)
7245 bpt->enable_state = bp_enabled;
7246 bpt->disposition = disposition;
7247 check_duplicates (bpt);
7248 breakpoints_changed ();
7250 if (bpt->type == bp_watchpoint ||
7251 bpt->type == bp_hardware_watchpoint ||
7252 bpt->type == bp_read_watchpoint ||
7253 bpt->type == bp_access_watchpoint)
7255 if (bpt->exp_valid_block != NULL)
7257 struct frame_info *fr =
7258 fr = frame_find_by_id (bpt->watchpoint_frame);
7262 Cannot enable watchpoint %d because the block in which its expression\n\
7263 is valid is not currently in scope.\n", bpt->number);
7264 bpt->enable_state = bp_disabled;
7268 save_selected_frame = deprecated_selected_frame;
7269 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7273 value_free (bpt->val);
7274 mark = value_mark ();
7275 bpt->val = evaluate_expression (bpt->exp);
7276 release_value (bpt->val);
7277 if (VALUE_LAZY (bpt->val))
7278 value_fetch_lazy (bpt->val);
7280 if (bpt->type == bp_hardware_watchpoint ||
7281 bpt->type == bp_read_watchpoint ||
7282 bpt->type == bp_access_watchpoint)
7284 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7285 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7287 /* Hack around 'unused var' error for some targets here */
7289 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7290 bpt->type, i + mem_cnt, other_type_used);
7291 /* we can consider of type is bp_hardware_watchpoint, convert to
7292 bp_watchpoint in the following condition */
7293 if (target_resources_ok < 0)
7296 Cannot enable watchpoint %d because target watch resources\n\
7297 have been allocated for other watchpoints.\n", bpt->number);
7298 bpt->enable_state = bp_disabled;
7299 value_free_to_mark (mark);
7304 if (save_selected_frame_level >= 0)
7305 select_frame (save_selected_frame);
7306 value_free_to_mark (mark);
7308 if (modify_breakpoint_hook)
7309 modify_breakpoint_hook (bpt);
7310 breakpoint_modify_event (bpt->number);
7314 enable_breakpoint (struct breakpoint *bpt)
7316 do_enable_breakpoint (bpt, bpt->disposition);
7319 /* The enable command enables the specified breakpoints (or all defined
7320 breakpoints) so they once again become (or continue to be) effective
7321 in stopping the inferior. */
7324 enable_command (char *args, int from_tty)
7326 struct breakpoint *bpt;
7328 ALL_BREAKPOINTS (bpt)
7332 warning ("attempted to enable apparently deleted breakpoint #%d?",
7337 case bp_catch_unload:
7339 case bp_catch_vfork:
7341 case bp_catch_catch:
7342 case bp_catch_throw:
7343 case bp_hardware_breakpoint:
7345 case bp_hardware_watchpoint:
7346 case bp_read_watchpoint:
7347 case bp_access_watchpoint:
7348 enable_breakpoint (bpt);
7353 map_breakpoint_numbers (args, enable_breakpoint);
7357 enable_once_breakpoint (struct breakpoint *bpt)
7359 do_enable_breakpoint (bpt, disp_disable);
7363 enable_once_command (char *args, int from_tty)
7365 map_breakpoint_numbers (args, enable_once_breakpoint);
7369 enable_delete_breakpoint (struct breakpoint *bpt)
7371 do_enable_breakpoint (bpt, disp_del);
7375 enable_delete_command (char *args, int from_tty)
7377 map_breakpoint_numbers (args, enable_delete_breakpoint);
7380 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7382 struct symtabs_and_lines
7383 decode_line_spec_1 (char *string, int funfirstline)
7385 struct symtabs_and_lines sals;
7387 error ("Empty line specification.");
7388 if (default_breakpoint_valid)
7389 sals = decode_line_1 (&string, funfirstline,
7390 default_breakpoint_symtab,
7391 default_breakpoint_line,
7394 sals = decode_line_1 (&string, funfirstline,
7395 (struct symtab *) NULL, 0, (char ***) NULL);
7397 error ("Junk at end of line specification: %s", string);
7402 _initialize_breakpoint (void)
7404 struct cmd_list_element *c;
7406 breakpoint_chain = 0;
7407 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7408 before a breakpoint is set. */
7409 breakpoint_count = 0;
7411 add_com ("ignore", class_breakpoint, ignore_command,
7412 "Set ignore-count of breakpoint number N to COUNT.\n\
7413 Usage is `ignore N COUNT'.");
7415 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7417 add_com ("commands", class_breakpoint, commands_command,
7418 "Set commands to be executed when a breakpoint is hit.\n\
7419 Give breakpoint number as argument after \"commands\".\n\
7420 With no argument, the targeted breakpoint is the last one set.\n\
7421 The commands themselves follow starting on the next line.\n\
7422 Type a line containing \"end\" to indicate the end of them.\n\
7423 Give \"silent\" as the first line to make the breakpoint silent;\n\
7424 then no output is printed when it is hit, except what the commands print.");
7426 add_com ("condition", class_breakpoint, condition_command,
7427 "Specify breakpoint number N to break only if COND is true.\n\
7428 Usage is `condition N COND', where N is an integer and COND is an\n\
7429 expression to be evaluated whenever breakpoint N is reached.");
7431 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7432 "Set a temporary breakpoint. Args like \"break\" command.\n\
7433 Like \"break\" except the breakpoint is only temporary,\n\
7434 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7435 by using \"enable delete\" on the breakpoint number.");
7436 set_cmd_completer (c, location_completer);
7438 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7439 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7440 Like \"break\" except the breakpoint requires hardware support,\n\
7441 some target hardware may not have this support.");
7442 set_cmd_completer (c, location_completer);
7444 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7445 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7446 Like \"hbreak\" except the breakpoint is only temporary,\n\
7447 so it will be deleted when hit.");
7448 set_cmd_completer (c, location_completer);
7450 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7451 "Enable some breakpoints.\n\
7452 Give breakpoint numbers (separated by spaces) as arguments.\n\
7453 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7454 This is used to cancel the effect of the \"disable\" command.\n\
7455 With a subcommand you can enable temporarily.",
7456 &enablelist, "enable ", 1, &cmdlist);
7458 add_com ("ab", class_breakpoint, enable_command,
7459 "Enable some breakpoints.\n\
7460 Give breakpoint numbers (separated by spaces) as arguments.\n\
7461 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7462 This is used to cancel the effect of the \"disable\" command.\n\
7463 With a subcommand you can enable temporarily.");
7465 add_com_alias ("en", "enable", class_breakpoint, 1);
7467 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7468 "Enable some breakpoints.\n\
7469 Give breakpoint numbers (separated by spaces) as arguments.\n\
7470 This is used to cancel the effect of the \"disable\" command.\n\
7471 May be abbreviated to simply \"enable\".\n",
7472 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7474 add_cmd ("once", no_class, enable_once_command,
7475 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7476 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7479 add_cmd ("delete", no_class, enable_delete_command,
7480 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7481 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7484 add_cmd ("delete", no_class, enable_delete_command,
7485 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7486 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7489 add_cmd ("once", no_class, enable_once_command,
7490 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7491 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7494 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7495 "Disable some breakpoints.\n\
7496 Arguments are breakpoint numbers with spaces in between.\n\
7497 To disable all breakpoints, give no argument.\n\
7498 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7499 &disablelist, "disable ", 1, &cmdlist);
7500 add_com_alias ("dis", "disable", class_breakpoint, 1);
7501 add_com_alias ("disa", "disable", class_breakpoint, 1);
7503 add_com ("sb", class_breakpoint, disable_command,
7504 "Disable some breakpoints.\n\
7505 Arguments are breakpoint numbers with spaces in between.\n\
7506 To disable all breakpoints, give no argument.\n\
7507 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7509 add_cmd ("breakpoints", class_alias, disable_command,
7510 "Disable some breakpoints.\n\
7511 Arguments are breakpoint numbers with spaces in between.\n\
7512 To disable all breakpoints, give no argument.\n\
7513 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7514 This command may be abbreviated \"disable\".",
7517 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7518 "Delete some breakpoints or auto-display expressions.\n\
7519 Arguments are breakpoint numbers with spaces in between.\n\
7520 To delete all breakpoints, give no argument.\n\
7522 Also a prefix command for deletion of other GDB objects.\n\
7523 The \"unset\" command is also an alias for \"delete\".",
7524 &deletelist, "delete ", 1, &cmdlist);
7525 add_com_alias ("d", "delete", class_breakpoint, 1);
7527 add_com ("db", class_breakpoint, delete_command,
7528 "Delete some breakpoints.\n\
7529 Arguments are breakpoint numbers with spaces in between.\n\
7530 To delete all breakpoints, give no argument.\n");
7532 add_cmd ("breakpoints", class_alias, delete_command,
7533 "Delete some breakpoints or auto-display expressions.\n\
7534 Arguments are breakpoint numbers with spaces in between.\n\
7535 To delete all breakpoints, give no argument.\n\
7536 This command may be abbreviated \"delete\".",
7539 add_com ("clear", class_breakpoint, clear_command,
7540 concat ("Clear breakpoint at specified line or function.\n\
7541 Argument may be line number, function name, or \"*\" and an address.\n\
7542 If line number is specified, all breakpoints in that line are cleared.\n\
7543 If function is specified, breakpoints at beginning of function are cleared.\n\
7544 If an address is specified, breakpoints at that address are cleared.\n\n",
7545 "With no argument, clears all breakpoints in the line that the selected frame\n\
7548 See also the \"delete\" command which clears breakpoints by number.", NULL));
7550 c = add_com ("break", class_breakpoint, break_command,
7551 concat ("Set breakpoint at specified line or function.\n\
7552 Argument may be line number, function name, or \"*\" and an address.\n\
7553 If line number is specified, break at start of code for that line.\n\
7554 If function is specified, break at start of code for that function.\n\
7555 If an address is specified, break at that exact address.\n",
7556 "With no arg, uses current execution address of selected stack frame.\n\
7557 This is useful for breaking on return to a stack frame.\n\
7559 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7561 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7562 set_cmd_completer (c, location_completer);
7564 add_com_alias ("b", "break", class_run, 1);
7565 add_com_alias ("br", "break", class_run, 1);
7566 add_com_alias ("bre", "break", class_run, 1);
7567 add_com_alias ("brea", "break", class_run, 1);
7571 add_com_alias ("ba", "break", class_breakpoint, 1);
7572 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7577 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7578 "Break in function/address or break at a line in the current file.",
7579 &stoplist, "stop ", 1, &cmdlist);
7580 add_cmd ("in", class_breakpoint, stopin_command,
7581 "Break in function or address.\n", &stoplist);
7582 add_cmd ("at", class_breakpoint, stopat_command,
7583 "Break at a line in the current file.\n", &stoplist);
7584 add_com ("status", class_info, breakpoints_info,
7585 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7586 The \"Type\" column indicates one of:\n\
7587 \tbreakpoint - normal breakpoint\n\
7588 \twatchpoint - watchpoint\n\
7589 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7590 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7591 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7592 address and file/line number respectively.\n\n",
7593 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7594 are set to the address of the last breakpoint listed.\n\n\
7595 Convenience variable \"$bpnum\" contains the number of the last\n\
7596 breakpoint set.", NULL));
7599 add_info ("breakpoints", breakpoints_info,
7600 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7601 The \"Type\" column indicates one of:\n\
7602 \tbreakpoint - normal breakpoint\n\
7603 \twatchpoint - watchpoint\n\
7604 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7605 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7606 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7607 address and file/line number respectively.\n\n",
7608 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7609 are set to the address of the last breakpoint listed.\n\n\
7610 Convenience variable \"$bpnum\" contains the number of the last\n\
7611 breakpoint set.", NULL));
7614 add_com ("lb", class_breakpoint, breakpoints_info,
7615 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7616 The \"Type\" column indicates one of:\n\
7617 \tbreakpoint - normal breakpoint\n\
7618 \twatchpoint - watchpoint\n\
7619 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7620 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7621 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7622 address and file/line number respectively.\n\n",
7623 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7624 are set to the address of the last breakpoint listed.\n\n\
7625 Convenience variable \"$bpnum\" contains the number of the last\n\
7626 breakpoint set.", NULL));
7628 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7629 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7630 The \"Type\" column indicates one of:\n\
7631 \tbreakpoint - normal breakpoint\n\
7632 \twatchpoint - watchpoint\n\
7633 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7634 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7635 \tuntil - internal breakpoint used by the \"until\" command\n\
7636 \tfinish - internal breakpoint used by the \"finish\" command\n",
7637 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7638 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7639 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7640 address and file/line number respectively.\n\n",
7641 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7642 are set to the address of the last breakpoint listed.\n\n\
7643 Convenience variable \"$bpnum\" contains the number of the last\n\
7644 breakpoint set.", NULL),
7645 &maintenanceinfolist);
7647 add_com ("catch", class_breakpoint, catch_command,
7648 "Set catchpoints to catch events.\n\
7649 Raised signals may be caught:\n\
7650 \tcatch signal - all signals\n\
7651 \tcatch signal <signame> - a particular signal\n\
7652 Raised exceptions may be caught:\n\
7653 \tcatch throw - all exceptions, when thrown\n\
7654 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7655 \tcatch catch - all exceptions, when caught\n\
7656 \tcatch catch <exceptname> - a particular exception, when caught\n\
7657 Thread or process events may be caught:\n\
7658 \tcatch thread_start - any threads, just after creation\n\
7659 \tcatch thread_exit - any threads, just before expiration\n\
7660 \tcatch thread_join - any threads, just after joins\n\
7661 Process events may be caught:\n\
7662 \tcatch start - any processes, just after creation\n\
7663 \tcatch exit - any processes, just before expiration\n\
7664 \tcatch fork - calls to fork()\n\
7665 \tcatch vfork - calls to vfork()\n\
7666 \tcatch exec - calls to exec()\n\
7667 Dynamically-linked library events may be caught:\n\
7668 \tcatch load - loads of any library\n\
7669 \tcatch load <libname> - loads of a particular library\n\
7670 \tcatch unload - unloads of any library\n\
7671 \tcatch unload <libname> - unloads of a particular library\n\
7672 The act of your program's execution stopping may also be caught:\n\
7674 C++ exceptions may be caught:\n\
7675 \tcatch throw - all exceptions, when thrown\n\
7676 \tcatch catch - all exceptions, when caught\n\
7678 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7679 after a fork or vfork is caught.\n\n\
7680 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7682 add_com ("tcatch", class_breakpoint, tcatch_command,
7683 "Set temporary catchpoints to catch events.\n\
7684 Args like \"catch\" command.\n\
7685 Like \"catch\" except the catchpoint is only temporary,\n\
7686 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7687 by using \"enable delete\" on the catchpoint number.");
7689 c = add_com ("watch", class_breakpoint, watch_command,
7690 "Set a watchpoint for an expression.\n\
7691 A watchpoint stops execution of your program whenever the value of\n\
7692 an expression changes.");
7693 set_cmd_completer (c, location_completer);
7695 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7696 "Set a read watchpoint for an expression.\n\
7697 A watchpoint stops execution of your program whenever the value of\n\
7698 an expression is read.");
7699 set_cmd_completer (c, location_completer);
7701 c = add_com ("awatch", class_breakpoint, awatch_command,
7702 "Set a watchpoint for an expression.\n\
7703 A watchpoint stops execution of your program whenever the value of\n\
7704 an expression is either read or written.");
7705 set_cmd_completer (c, location_completer);
7707 add_info ("watchpoints", breakpoints_info,
7708 "Synonym for ``info breakpoints''.");
7711 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7712 (char *) &can_use_hw_watchpoints,
7713 "Set debugger's willingness to use watchpoint hardware.\n\
7714 If zero, gdb will not use hardware for new watchpoints, even if\n\
7715 such is available. (However, any hardware watchpoints that were\n\
7716 created before setting this to nonzero, will continue to use watchpoint\n\
7719 add_show_from_set (c, &showlist);
7721 can_use_hw_watchpoints = 1;