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, 2004
5 Free Software Foundation, Inc.
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 int break_command_1 (char *, int, int, struct breakpoint *);
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,
105 static void describe_other_breakpoints (CORE_ADDR, asection *);
107 static void breakpoints_info (char *, int);
109 static void breakpoint_1 (int, int);
111 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
113 static int breakpoint_cond_eval (void *);
115 static void cleanup_executing_breakpoints (void *);
117 static void commands_command (char *, int);
119 static void condition_command (char *, int);
121 static int get_number_trailer (char **, int);
123 static int do_captured_parse_breakpoint (struct ui_out *, void *);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location *, insertion_state_t);
136 static enum print_stop_action print_it_typical (bpstat);
138 static enum print_stop_action print_bp_stop_message (bpstat bs);
142 enum exception_event_kind kind;
145 args_for_catchpoint_enable;
147 static int watchpoint_check (void *);
149 static int cover_target_enable_exception_callback (void *);
151 static void maintenance_info_breakpoints (char *, int);
153 static void create_longjmp_breakpoint (char *);
155 static void create_overlay_event_breakpoint (char *);
157 static int hw_breakpoint_used_count (void);
159 static int hw_watchpoint_used_count (enum bptype, int *);
161 static void hbreak_command (char *, int);
163 static void thbreak_command (char *, int);
165 static void watch_command_1 (char *, int, int);
167 static void rwatch_command (char *, int);
169 static void awatch_command (char *, int);
171 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
173 static void solib_load_unload_1 (char *hookname,
176 char *cond_string, enum bptype bp_kind);
178 static void create_fork_vfork_event_catchpoint (int tempflag,
180 enum bptype bp_kind);
182 static void break_at_finish_at_depth_command_1 (char *arg,
183 int flag, int from_tty);
185 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
187 static void stop_command (char *arg, int from_tty);
189 static void stopin_command (char *arg, int from_tty);
191 static void stopat_command (char *arg, int from_tty);
193 static char *ep_find_event_name_end (char *arg);
195 static char *ep_parse_optional_if_clause (char **arg);
197 static char *ep_parse_optional_filename (char **arg);
199 static void create_exception_catchpoint (int tempflag, char *cond_string,
200 enum exception_event_kind ex_event,
201 struct symtab_and_line *sal);
203 static void catch_exception_command_1 (enum exception_event_kind ex_event,
204 char *arg, int tempflag, int from_tty);
206 static void tcatch_command (char *arg, int from_tty);
208 static void ep_skip_leading_whitespace (char **s);
210 /* Prototypes for exported functions. */
212 /* If FALSE, gdb will not use hardware support for watchpoints, even
213 if such is available. */
214 static int can_use_hw_watchpoints;
216 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
217 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
218 for unrecognized breakpoint locations.
219 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
220 static enum auto_boolean pending_break_support;
222 void _initialize_breakpoint (void);
224 extern int addressprint; /* Print machine addresses? */
226 /* Are we executing breakpoint commands? */
227 static int executing_breakpoint_commands;
229 /* Are overlay event breakpoints enabled? */
230 static int overlay_events_enabled;
232 /* Walk the following statement or block through all breakpoints.
233 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
236 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
238 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
239 for (B = breakpoint_chain; \
240 B ? (TMP=B->next, 1): 0; \
243 /* Similar iterators for the low-level breakpoints. */
245 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
247 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
248 for (B = bp_location_chain; \
249 B ? (TMP=B->next, 1): 0; \
252 /* True if breakpoint hit counts should be displayed in breakpoint info. */
254 int show_breakpoint_hit_counts = 1;
256 /* Chains of all breakpoints defined. */
258 struct breakpoint *breakpoint_chain;
260 struct bp_location *bp_location_chain;
262 /* Number of last breakpoint made. */
264 int breakpoint_count;
266 /* Pointer to current exception event record */
267 static struct exception_event_record *current_exception_event;
269 /* Indicator of whether exception catchpoints should be nuked between
270 runs of a program. */
271 int deprecated_exception_catchpoints_are_fragile = 0;
273 /* Indicator of when exception catchpoints set-up should be
274 reinitialized -- e.g. when program is re-run. */
275 int deprecated_exception_support_initialized = 0;
277 /* This function returns a pointer to the string representation of the
278 pathname of the dynamically-linked library that has just been
281 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
282 or undefined results are guaranteed.
284 This string's contents are only valid immediately after the
285 inferior has stopped in the dynamic linker hook, and becomes
286 invalid as soon as the inferior is continued. Clients should make
287 a copy of this string if they wish to continue the inferior and
288 then access the string. */
290 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
291 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
294 /* This function returns a pointer to the string representation of the
295 pathname of the dynamically-linked library that has just been
298 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
299 TRUE, or undefined results are guaranteed.
301 This string's contents are only valid immediately after the
302 inferior has stopped in the dynamic linker hook, and becomes
303 invalid as soon as the inferior is continued. Clients should make
304 a copy of this string if they wish to continue the inferior and
305 then access the string. */
307 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
308 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
311 /* This function is called by the "catch load" command. It allows the
312 debugger to be notified by the dynamic linker when a specified
313 library file (or any library file, if filename is NULL) is loaded. */
315 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
316 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library loads not yet implemented on this platform")
320 /* This function is called by the "catch unload" command. It allows
321 the debugger to be notified by the dynamic linker when a specified
322 library file (or any library file, if filename is NULL) is
325 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
326 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
327 error ("catch of library unloads not yet implemented on this platform")
330 /* Return whether a breakpoint is an active enabled breakpoint. */
332 breakpoint_enabled (struct breakpoint *b)
334 return (b->enable_state == bp_enabled && !b->pending);
337 /* Set breakpoint count to NUM. */
340 set_breakpoint_count (int num)
342 breakpoint_count = num;
343 set_internalvar (lookup_internalvar ("bpnum"),
344 value_from_longest (builtin_type_int, (LONGEST) num));
347 /* Used in run_command to zero the hit count when a new run starts. */
350 clear_breakpoint_hit_counts (void)
352 struct breakpoint *b;
358 /* Default address, symtab and line to put a breakpoint at
359 for "break" command with no arg.
360 if default_breakpoint_valid is zero, the other three are
361 not valid, and "break" with no arg is an error.
363 This set by print_stack_frame, which calls set_default_breakpoint. */
365 int default_breakpoint_valid;
366 CORE_ADDR default_breakpoint_address;
367 struct symtab *default_breakpoint_symtab;
368 int default_breakpoint_line;
370 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
371 Advance *PP after the string and any trailing whitespace.
373 Currently the string can either be a number or "$" followed by the name
374 of a convenience variable. Making it an expression wouldn't work well
375 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
377 TRAILER is a character which can be found after the number; most
378 commonly this is `-'. If you don't want a trailer, use \0. */
380 get_number_trailer (char **pp, int trailer)
382 int retval = 0; /* default */
386 /* Empty line means refer to the last breakpoint. */
387 return breakpoint_count;
390 /* Make a copy of the name, so we can null-terminate it
391 to pass to lookup_internalvar(). */
396 while (isalnum (*p) || *p == '_')
398 varname = (char *) alloca (p - start + 1);
399 strncpy (varname, start, p - start);
400 varname[p - start] = '\0';
401 val = value_of_internalvar (lookup_internalvar (varname));
402 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
403 retval = (int) value_as_long (val);
406 printf_filtered ("Convenience variable must have integer value.\n");
414 while (*p >= '0' && *p <= '9')
417 /* There is no number here. (e.g. "cond a == b"). */
419 /* Skip non-numeric token */
420 while (*p && !isspace((int) *p))
422 /* Return zero, which caller must interpret as error. */
428 if (!(isspace (*p) || *p == '\0' || *p == trailer))
430 /* Trailing junk: return 0 and let caller print error msg. */
431 while (!(isspace (*p) || *p == '\0' || *p == trailer))
442 /* Like get_number_trailer, but don't allow a trailer. */
444 get_number (char **pp)
446 return get_number_trailer (pp, '\0');
449 /* Parse a number or a range.
450 * A number will be of the form handled by get_number.
451 * A range will be of the form <number1> - <number2>, and
452 * will represent all the integers between number1 and number2,
455 * While processing a range, this fuction is called iteratively;
456 * At each call it will return the next value in the range.
458 * At the beginning of parsing a range, the char pointer PP will
459 * be advanced past <number1> and left pointing at the '-' token.
460 * Subsequent calls will not advance the pointer until the range
461 * is completed. The call that completes the range will advance
462 * pointer PP past <number2>.
466 get_number_or_range (char **pp)
468 static int last_retval, end_value;
469 static char *end_ptr;
470 static int in_range = 0;
474 /* Default case: pp is pointing either to a solo number,
475 or to the first number of a range. */
476 last_retval = get_number_trailer (pp, '-');
481 /* This is the start of a range (<number1> - <number2>).
482 Skip the '-', parse and remember the second number,
483 and also remember the end of the final token. */
487 while (isspace ((int) *end_ptr))
488 end_ptr++; /* skip white space */
489 end_value = get_number (temp);
490 if (end_value < last_retval)
492 error ("inverted range");
494 else if (end_value == last_retval)
496 /* degenerate range (number1 == number2). Advance the
497 token pointer so that the range will be treated as a
506 error ("negative value");
509 /* pp points to the '-' that betokens a range. All
510 number-parsing has already been done. Return the next
511 integer value (one greater than the saved previous value).
512 Do not advance the token pointer 'pp' until the end of range
515 if (++last_retval == end_value)
517 /* End of range reached; advance token pointer. */
527 /* condition N EXP -- set break condition of breakpoint N to EXP. */
530 condition_command (char *arg, int from_tty)
532 struct breakpoint *b;
537 error_no_arg ("breakpoint number");
540 bnum = get_number (&p);
542 error ("Bad breakpoint argument: '%s'", arg);
545 if (b->number == bnum)
552 if (b->cond_string != NULL)
553 xfree (b->cond_string);
558 b->cond_string = NULL;
560 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
565 /* I don't know if it matters whether this is the string the user
566 typed in or the decompiled expression. */
567 b->cond_string = savestring (arg, strlen (arg));
570 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
572 error ("Junk at end of expression");
575 breakpoints_changed ();
576 breakpoint_modify_event (b->number);
580 error ("No breakpoint number %d.", bnum);
584 commands_command (char *arg, int from_tty)
586 struct breakpoint *b;
589 struct command_line *l;
591 /* If we allowed this, we would have problems with when to
592 free the storage, if we change the commands currently
595 if (executing_breakpoint_commands)
596 error ("Can't use the \"commands\" command among a breakpoint's commands.");
599 bnum = get_number (&p);
602 error ("Unexpected extra arguments following breakpoint number.");
605 if (b->number == bnum)
607 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
609 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
610 l = read_command_lines (tmpbuf, from_tty);
611 do_cleanups (cleanups);
612 free_command_lines (&b->commands);
614 breakpoints_changed ();
615 breakpoint_modify_event (b->number);
618 error ("No breakpoint number %d.", bnum);
621 /* Like target_read_memory() but if breakpoints are inserted, return
622 the shadow contents instead of the breakpoints themselves.
624 Read "memory data" from whatever target or inferior we have.
625 Returns zero if successful, errno value if not. EIO is used
626 for address out of bounds. If breakpoints are inserted, returns
627 shadow contents, not the breakpoints themselves. From breakpoint.c. */
630 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
633 struct bp_location *b;
634 CORE_ADDR bp_addr = 0;
637 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
638 /* No breakpoints on this machine. */
639 return target_read_memory (memaddr, myaddr, len);
643 if (b->owner->type == bp_none)
644 warning ("reading through apparently deleted breakpoint #%d?",
647 if (b->loc_type != bp_loc_software_breakpoint)
651 /* Addresses and length of the part of the breakpoint that
653 /* XXXX The m68k, sh and h8300 have different local and remote
654 breakpoint values. BREAKPOINT_FROM_PC still manages to
655 correctly determine the breakpoints memory address and size
656 for these targets. */
657 bp_addr = b->address;
659 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
664 if (bp_addr + bp_size <= memaddr)
665 /* The breakpoint is entirely before the chunk of memory we
668 if (bp_addr >= memaddr + len)
669 /* The breakpoint is entirely after the chunk of memory we are
672 /* Copy the breakpoint from the shadow contents, and recurse for
673 the things before and after. */
675 /* Offset within shadow_contents. */
678 if (bp_addr < memaddr)
680 /* Only copy the second part of the breakpoint. */
681 bp_size -= memaddr - bp_addr;
682 bptoffset = memaddr - bp_addr;
686 if (bp_addr + bp_size > memaddr + len)
688 /* Only copy the first part of the breakpoint. */
689 bp_size -= (bp_addr + bp_size) - (memaddr + len);
692 memcpy (myaddr + bp_addr - memaddr,
693 b->shadow_contents + bptoffset, bp_size);
695 if (bp_addr > memaddr)
697 /* Copy the section of memory before the breakpoint. */
698 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
703 if (bp_addr + bp_size < memaddr + len)
705 /* Copy the section of memory after the breakpoint. */
706 status = read_memory_nobpt (bp_addr + bp_size,
707 myaddr + bp_addr + bp_size - memaddr,
708 memaddr + len - (bp_addr + bp_size));
715 /* Nothing overlaps. Just call read_memory_noerr. */
716 return target_read_memory (memaddr, myaddr, len);
720 /* A wrapper function for inserting catchpoints. */
722 insert_catchpoint (struct ui_out *uo, void *args)
724 struct breakpoint *b = (struct breakpoint *) args;
730 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
733 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
736 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
739 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
744 throw_exception (RETURN_ERROR);
749 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
750 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
751 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
753 NOTE drow/2003-09-09: This routine could be broken down to an object-style
754 method for each breakpoint or catchpoint type. */
756 insert_bp_location (struct bp_location *bpt,
757 struct ui_file *tmp_error_stream,
758 int *disabled_breaks, int *process_warning,
759 int *hw_breakpoint_error)
763 /* Permanent breakpoints cannot be inserted or removed. Disabled
764 breakpoints should not be inserted. */
765 if (!breakpoint_enabled (bpt->owner))
768 if (bpt->inserted || bpt->duplicate)
771 if (bpt->loc_type == bp_loc_software_breakpoint
772 || bpt->loc_type == bp_loc_hardware_breakpoint)
774 /* First check to see if we have to handle an overlay. */
775 if (overlay_debugging == ovly_off
776 || bpt->section == NULL
777 || !(section_is_overlay (bpt->section)))
779 /* No overlay handling: just set the breakpoint. */
781 if (bpt->loc_type == bp_loc_hardware_breakpoint)
782 val = target_insert_hw_breakpoint (bpt->address,
783 bpt->shadow_contents);
785 val = target_insert_breakpoint (bpt->address,
786 bpt->shadow_contents);
790 /* This breakpoint is in an overlay section.
791 Shall we set a breakpoint at the LMA? */
792 if (!overlay_events_enabled)
794 /* Yes -- overlay event support is not active,
795 so we must try to set a breakpoint at the LMA.
796 This will not work for a hardware breakpoint. */
797 if (bpt->loc_type == bp_loc_hardware_breakpoint)
798 warning ("hardware breakpoint %d not supported in overlay!\n",
802 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
804 /* Set a software (trap) breakpoint at the LMA. */
805 val = target_insert_breakpoint (addr, bpt->shadow_contents);
807 fprintf_unfiltered (tmp_error_stream,
808 "Overlay breakpoint %d failed: in ROM?",
812 /* Shall we set a breakpoint at the VMA? */
813 if (section_is_mapped (bpt->section))
815 /* Yes. This overlay section is mapped into memory. */
816 if (bpt->loc_type == bp_loc_hardware_breakpoint)
817 val = target_insert_hw_breakpoint (bpt->address,
818 bpt->shadow_contents);
820 val = target_insert_breakpoint (bpt->address,
821 bpt->shadow_contents);
825 /* No. This breakpoint will not be inserted.
826 No error, but do not mark the bp as 'inserted'. */
833 /* Can't set the breakpoint. */
834 #if defined (DISABLE_UNSETTABLE_BREAK)
835 if (DISABLE_UNSETTABLE_BREAK (bpt->address))
837 /* See also: disable_breakpoints_in_shlibs. */
839 bpt->owner->enable_state = bp_shlib_disabled;
840 if (!*disabled_breaks)
842 fprintf_unfiltered (tmp_error_stream,
843 "Cannot insert breakpoint %d.\n",
845 fprintf_unfiltered (tmp_error_stream,
846 "Temporarily disabling shared library breakpoints:\n");
848 *disabled_breaks = 1;
849 fprintf_unfiltered (tmp_error_stream,
850 "breakpoint #%d\n", bpt->owner->number);
855 #ifdef ONE_PROCESS_WRITETEXT
856 *process_warning = 1;
858 if (bpt->loc_type == bp_loc_hardware_breakpoint)
860 *hw_breakpoint_error = 1;
861 fprintf_unfiltered (tmp_error_stream,
862 "Cannot insert hardware breakpoint %d.\n",
867 fprintf_unfiltered (tmp_error_stream,
868 "Cannot insert breakpoint %d.\n",
870 fprintf_filtered (tmp_error_stream,
871 "Error accessing memory address ");
872 print_address_numeric (bpt->address, 1, tmp_error_stream);
873 fprintf_filtered (tmp_error_stream, ": %s.\n",
874 safe_strerror (val));
885 else if (bpt->loc_type == bp_loc_hardware_watchpoint
886 /* NOTE drow/2003-09-08: This state only exists for removing
887 watchpoints. It's not clear that it's necessary... */
888 && bpt->owner->disposition != disp_del_at_next_stop)
890 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
891 based on the expression. Ideally this should happen at a higher level,
892 and there should be one bp_location for each computed address we
893 must watch. As soon as a many-to-one mapping is available I'll
896 struct frame_info *saved_frame;
897 int saved_level, within_current_scope;
898 struct value *mark = value_mark ();
901 /* Save the current frame and level so we can restore it after
902 evaluating the watchpoint expression on its own frame. */
903 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
904 took a frame parameter, so that we didn't have to change the
906 saved_frame = deprecated_selected_frame;
907 saved_level = frame_relative_level (deprecated_selected_frame);
909 /* Determine if the watchpoint is within scope. */
910 if (bpt->owner->exp_valid_block == NULL)
911 within_current_scope = 1;
914 struct frame_info *fi;
915 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
916 within_current_scope = (fi != NULL);
917 if (within_current_scope)
921 if (within_current_scope)
923 /* Evaluate the expression and cut the chain of values
924 produced off from the value chain.
926 Make sure the value returned isn't lazy; we use
927 laziness to determine what memory GDB actually needed
928 in order to compute the value of the expression. */
929 v = evaluate_expression (bpt->owner->exp);
931 value_release_to_mark (mark);
933 bpt->owner->val_chain = v;
936 /* Look at each value on the value chain. */
937 for (; v; v = v->next)
939 /* If it's a memory location, and GDB actually needed
940 its contents to evaluate the expression, then we
942 if (VALUE_LVAL (v) == lval_memory
945 struct type *vtype = check_typedef (VALUE_TYPE (v));
947 /* We only watch structs and arrays if user asked
948 for it explicitly, never if they just happen to
949 appear in the middle of some value chain. */
950 if (v == bpt->owner->val_chain
951 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
952 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
957 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
958 len = TYPE_LENGTH (VALUE_TYPE (v));
960 if (bpt->owner->type == bp_read_watchpoint)
962 else if (bpt->owner->type == bp_access_watchpoint)
965 val = target_insert_watchpoint (addr, len, type);
968 /* Don't exit the loop, try to insert
969 every value on the value chain. That's
970 because we will be removing all the
971 watches below, and removing a
972 watchpoint we didn't insert could have
980 /* Failure to insert a watchpoint on any memory value in the
981 value chain brings us here. */
984 remove_breakpoint (bpt, mark_uninserted);
985 *hw_breakpoint_error = 1;
986 fprintf_unfiltered (tmp_error_stream,
987 "Could not insert hardware watchpoint %d.\n",
994 printf_filtered ("Hardware watchpoint %d deleted ", bpt->owner->number);
995 printf_filtered ("because the program has left the block \n");
996 printf_filtered ("in which its expression is valid.\n");
997 if (bpt->owner->related_breakpoint)
998 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
999 bpt->owner->disposition = disp_del_at_next_stop;
1002 /* Restore the frame and level. */
1003 if (saved_frame != deprecated_selected_frame
1004 || saved_level != frame_relative_level (deprecated_selected_frame))
1005 select_frame (saved_frame);
1010 else if (ep_is_exception_catchpoint (bpt->owner))
1012 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1013 breakpoint. Once again, it would be better if this was represented
1014 as two bp_locations. */
1016 /* If we get here, we must have a callback mechanism for exception
1017 events -- with g++ style embedded label support, we insert
1018 ordinary breakpoints and not catchpoints. */
1019 val = target_insert_breakpoint (bpt->address, bpt->shadow_contents);
1022 /* Couldn't set breakpoint for some reason */
1023 fprintf_unfiltered (tmp_error_stream,
1024 "Cannot insert catchpoint %d; disabling it.\n",
1025 bpt->owner->number);
1026 fprintf_filtered (tmp_error_stream,
1027 "Error accessing memory address ");
1028 print_address_numeric (bpt->address, 1, tmp_error_stream);
1029 fprintf_filtered (tmp_error_stream, ": %s.\n",
1030 safe_strerror (val));
1031 bpt->owner->enable_state = bp_disabled;
1035 /* Bp set, now make sure callbacks are enabled */
1036 /* Format possible error msg */
1037 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1038 bpt->owner->number);
1039 struct cleanup *cleanups = make_cleanup (xfree, message);
1041 args_for_catchpoint_enable args;
1042 args.kind = bpt->owner->type == bp_catch_catch ?
1043 EX_EVENT_CATCH : EX_EVENT_THROW;
1045 val = catch_errors (cover_target_enable_exception_callback,
1046 &args, message, RETURN_MASK_ALL);
1047 do_cleanups (cleanups);
1048 if (val != 0 && val != -1)
1051 /* Check if something went wrong; val == 0 can be ignored */
1054 /* something went wrong */
1055 fprintf_unfiltered (tmp_error_stream,
1056 "Cannot insert catchpoint %d; disabling it.\n",
1057 bpt->owner->number);
1058 bpt->owner->enable_state = bp_disabled;
1065 else if (bpt->owner->type == bp_catch_fork
1066 || bpt->owner->type == bp_catch_vfork
1067 || bpt->owner->type == bp_catch_exec)
1069 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
1070 bpt->owner->number);
1071 struct cleanup *cleanups = make_cleanup (xfree, prefix);
1072 val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix,
1074 do_cleanups (cleanups);
1076 bpt->owner->enable_state = bp_disabled;
1080 /* We've already printed an error message if there was a problem
1081 inserting this catchpoint, and we've disabled the catchpoint,
1082 so just return success. */
1089 /* insert_breakpoints is used when starting or continuing the program.
1090 remove_breakpoints is used when the program stops.
1091 Both return zero if successful,
1092 or an `errno' value if could not write the inferior. */
1095 insert_breakpoints (void)
1097 struct bp_location *b, *temp;
1098 int return_val = 0; /* return success code. */
1100 int disabled_breaks = 0;
1101 int hw_breakpoint_error = 0;
1102 int process_warning = 0;
1104 struct ui_file *tmp_error_stream = mem_fileopen ();
1105 make_cleanup_ui_file_delete (tmp_error_stream);
1107 /* Explicitly mark the warning -- this will only be printed if
1108 there was an error. */
1109 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1111 ALL_BP_LOCATIONS_SAFE (b, temp)
1113 /* Permanent breakpoints cannot be inserted or removed. Disabled
1114 breakpoints should not be inserted. */
1115 if (!breakpoint_enabled (b->owner))
1118 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1119 hardware watchpoints are split into multiple loc breakpoints. */
1120 if ((b->loc_type == bp_loc_hardware_watchpoint
1121 || b->owner->type == bp_watchpoint) && !b->owner->val)
1124 val = evaluate_expression (b->owner->exp);
1125 release_value (val);
1126 if (VALUE_LAZY (val))
1127 value_fetch_lazy (val);
1128 b->owner->val = val;
1131 val = insert_bp_location (b, tmp_error_stream,
1132 &disabled_breaks, &process_warning,
1133 &hw_breakpoint_error);
1140 /* If a hardware breakpoint or watchpoint was inserted, add a
1141 message about possibly exhausted resources. */
1142 if (hw_breakpoint_error)
1144 fprintf_unfiltered (tmp_error_stream,
1145 "Could not insert hardware breakpoints:\n\
1146 You may have requested too many hardware breakpoints/watchpoints.\n");
1148 #ifdef ONE_PROCESS_WRITETEXT
1149 if (process_warning)
1150 fprintf_unfiltered (tmp_error_stream,
1151 "The same program may be running in another process.");
1153 target_terminal_ours_for_output ();
1154 error_stream (tmp_error_stream);
1160 remove_breakpoints (void)
1162 struct bp_location *b;
1165 ALL_BP_LOCATIONS (b)
1169 val = remove_breakpoint (b, mark_uninserted);
1178 remove_hw_watchpoints (void)
1180 struct bp_location *b;
1183 ALL_BP_LOCATIONS (b)
1185 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1187 val = remove_breakpoint (b, mark_uninserted);
1196 reattach_breakpoints (int pid)
1198 struct bp_location *b;
1200 struct cleanup *old_chain = save_inferior_ptid ();
1202 /* Set inferior_ptid; remove_breakpoint uses this global. */
1203 inferior_ptid = pid_to_ptid (pid);
1204 ALL_BP_LOCATIONS (b)
1208 remove_breakpoint (b, mark_inserted);
1209 if (b->loc_type == bp_loc_hardware_breakpoint)
1210 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1212 val = target_insert_breakpoint (b->address, b->shadow_contents);
1213 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1214 breakpoints. It's wrong for watchpoints, for example. */
1217 do_cleanups (old_chain);
1222 do_cleanups (old_chain);
1227 update_breakpoints_after_exec (void)
1229 struct breakpoint *b;
1230 struct breakpoint *temp;
1232 /* Doing this first prevents the badness of having delete_breakpoint()
1233 write a breakpoint's current "shadow contents" to lift the bp. That
1234 shadow is NOT valid after an exec()! */
1235 mark_breakpoints_out ();
1237 ALL_BREAKPOINTS_SAFE (b, temp)
1239 /* Solib breakpoints must be explicitly reset after an exec(). */
1240 if (b->type == bp_shlib_event)
1242 delete_breakpoint (b);
1246 /* Thread event breakpoints must be set anew after an exec(),
1247 as must overlay event breakpoints. */
1248 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1250 delete_breakpoint (b);
1254 /* Step-resume breakpoints are meaningless after an exec(). */
1255 if (b->type == bp_step_resume)
1257 delete_breakpoint (b);
1261 /* Ditto the sigtramp handler breakpoints. */
1262 if (b->type == bp_through_sigtramp)
1264 delete_breakpoint (b);
1268 /* Ditto the exception-handling catchpoints. */
1269 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1271 delete_breakpoint (b);
1275 /* Don't delete an exec catchpoint, because else the inferior
1276 won't stop when it ought!
1278 Similarly, we probably ought to keep vfork catchpoints, 'cause
1279 on this target, we may not be able to stop when the vfork is
1280 seen, but only when the subsequent exec is seen. (And because
1281 deleting fork catchpoints here but not vfork catchpoints will
1282 seem mysterious to users, keep those too.)
1284 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1285 target address field, if any, is sufficient to have it be reset
1286 automagically. Certainly on HP-UX that's true.
1289 valid code address on some platforms (like the mn10300
1290 simulators). We shouldn't assign any special interpretation to
1291 a breakpoint with a zero address. And in fact, GDB doesn't ---
1292 I can't see what that comment above is talking about. As far
1293 as I can tell, setting the address of a
1294 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1295 is meaningless, since those are implemented with HP-UX kernel
1296 hackery, not by storing breakpoint instructions somewhere. */
1297 if ((b->type == bp_catch_exec) ||
1298 (b->type == bp_catch_vfork) ||
1299 (b->type == bp_catch_fork))
1301 b->loc->address = (CORE_ADDR) NULL;
1305 /* bp_finish is a special case. The only way we ought to be able
1306 to see one of these when an exec() has happened, is if the user
1307 caught a vfork, and then said "finish". Ordinarily a finish just
1308 carries them to the call-site of the current callee, by setting
1309 a temporary bp there and resuming. But in this case, the finish
1310 will carry them entirely through the vfork & exec.
1312 We don't want to allow a bp_finish to remain inserted now. But
1313 we can't safely delete it, 'cause finish_command has a handle to
1314 the bp on a bpstat, and will later want to delete it. There's a
1315 chance (and I've seen it happen) that if we delete the bp_finish
1316 here, that its storage will get reused by the time finish_command
1317 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1318 We really must allow finish_command to delete a bp_finish.
1320 In the absense of a general solution for the "how do we know
1321 it's safe to delete something others may have handles to?"
1322 problem, what we'll do here is just uninsert the bp_finish, and
1323 let finish_command delete it.
1325 (We know the bp_finish is "doomed" in the sense that it's
1326 momentary, and will be deleted as soon as finish_command sees
1327 the inferior stopped. So it doesn't matter that the bp's
1328 address is probably bogus in the new a.out, unlike e.g., the
1329 solib breakpoints.) */
1331 if (b->type == bp_finish)
1336 /* Without a symbolic address, we have little hope of the
1337 pre-exec() address meaning the same thing in the post-exec()
1339 if (b->addr_string == NULL)
1341 delete_breakpoint (b);
1345 /* If this breakpoint has survived the above battery of checks, then
1346 it must have a symbolic address. Be sure that it gets reevaluated
1347 to a target address, rather than reusing the old evaluation.
1350 for bp_catch_exec and friends, I'm pretty sure this is entirely
1351 unnecessary. A call to breakpoint_re_set_one always recomputes
1352 the breakpoint's address from scratch, or deletes it if it can't.
1353 So I think this assignment could be deleted without effect. */
1354 b->loc->address = (CORE_ADDR) NULL;
1356 /* FIXME what about longjmp breakpoints? Re-create them here? */
1357 create_overlay_event_breakpoint ("_ovly_debug_event");
1361 detach_breakpoints (int pid)
1363 struct bp_location *b;
1365 struct cleanup *old_chain = save_inferior_ptid ();
1367 if (pid == PIDGET (inferior_ptid))
1368 error ("Cannot detach breakpoints of inferior_ptid");
1370 /* Set inferior_ptid; remove_breakpoint uses this global. */
1371 inferior_ptid = pid_to_ptid (pid);
1372 ALL_BP_LOCATIONS (b)
1376 val = remove_breakpoint (b, mark_inserted);
1379 do_cleanups (old_chain);
1384 do_cleanups (old_chain);
1389 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1393 if (b->owner->enable_state == bp_permanent)
1394 /* Permanent breakpoints cannot be inserted or removed. */
1397 if (b->owner->type == bp_none)
1398 warning ("attempted to remove apparently deleted breakpoint #%d?",
1401 if (b->loc_type == bp_loc_software_breakpoint
1402 || b->loc_type == bp_loc_hardware_breakpoint)
1404 /* "Normal" instruction breakpoint: either the standard
1405 trap-instruction bp (bp_breakpoint), or a
1406 bp_hardware_breakpoint. */
1408 /* First check to see if we have to handle an overlay. */
1409 if (overlay_debugging == ovly_off
1410 || b->section == NULL
1411 || !(section_is_overlay (b->section)))
1413 /* No overlay handling: just remove the breakpoint. */
1415 if (b->loc_type == bp_loc_hardware_breakpoint)
1416 val = target_remove_hw_breakpoint (b->address,
1417 b->shadow_contents);
1419 val = target_remove_breakpoint (b->address, b->shadow_contents);
1423 /* This breakpoint is in an overlay section.
1424 Did we set a breakpoint at the LMA? */
1425 if (!overlay_events_enabled)
1427 /* Yes -- overlay event support is not active, so we
1428 should have set a breakpoint at the LMA. Remove it.
1430 CORE_ADDR addr = overlay_unmapped_address (b->address,
1432 /* Ignore any failures: if the LMA is in ROM, we will
1433 have already warned when we failed to insert it. */
1434 if (b->loc_type == bp_loc_hardware_breakpoint)
1435 target_remove_hw_breakpoint (addr, b->shadow_contents);
1437 target_remove_breakpoint (addr, b->shadow_contents);
1439 /* Did we set a breakpoint at the VMA?
1440 If so, we will have marked the breakpoint 'inserted'. */
1443 /* Yes -- remove it. Previously we did not bother to
1444 remove the breakpoint if the section had been
1445 unmapped, but let's not rely on that being safe. We
1446 don't know what the overlay manager might do. */
1447 if (b->loc_type == bp_loc_hardware_breakpoint)
1448 val = target_remove_hw_breakpoint (b->address,
1449 b->shadow_contents);
1451 val = target_remove_breakpoint (b->address,
1452 b->shadow_contents);
1456 /* No -- not inserted, so no need to remove. No error. */
1462 b->inserted = (is == mark_inserted);
1464 else if (b->loc_type == bp_loc_hardware_watchpoint
1465 && breakpoint_enabled (b->owner)
1471 b->inserted = (is == mark_inserted);
1472 /* Walk down the saved value chain. */
1473 for (v = b->owner->val_chain; v; v = v->next)
1475 /* For each memory reference remove the watchpoint
1477 if (VALUE_LVAL (v) == lval_memory
1478 && ! VALUE_LAZY (v))
1480 struct type *vtype = check_typedef (VALUE_TYPE (v));
1482 if (v == b->owner->val_chain
1483 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1484 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1489 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1490 len = TYPE_LENGTH (VALUE_TYPE (v));
1492 if (b->owner->type == bp_read_watchpoint)
1494 else if (b->owner->type == bp_access_watchpoint)
1497 val = target_remove_watchpoint (addr, len, type);
1504 /* Failure to remove any of the hardware watchpoints comes here. */
1505 if ((is == mark_uninserted) && (b->inserted))
1506 warning ("Could not remove hardware watchpoint %d.",
1509 /* Free the saved value chain. We will construct a new one
1510 the next time the watchpoint is inserted. */
1511 for (v = b->owner->val_chain; v; v = n)
1516 b->owner->val_chain = NULL;
1518 else if ((b->owner->type == bp_catch_fork ||
1519 b->owner->type == bp_catch_vfork ||
1520 b->owner->type == bp_catch_exec)
1521 && breakpoint_enabled (b->owner)
1525 switch (b->owner->type)
1528 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1530 case bp_catch_vfork:
1531 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1534 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1537 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1542 b->inserted = (is == mark_inserted);
1544 else if ((b->owner->type == bp_catch_catch ||
1545 b->owner->type == bp_catch_throw)
1546 && breakpoint_enabled (b->owner)
1550 val = target_remove_breakpoint (b->address, b->shadow_contents);
1553 b->inserted = (is == mark_inserted);
1555 else if (ep_is_exception_catchpoint (b->owner)
1556 && b->inserted /* sometimes previous insert doesn't happen */
1557 && breakpoint_enabled (b->owner)
1561 val = target_remove_breakpoint (b->address, b->shadow_contents);
1565 b->inserted = (is == mark_inserted);
1571 /* Clear the "inserted" flag in all breakpoints. */
1574 mark_breakpoints_out (void)
1576 struct bp_location *bpt;
1578 ALL_BP_LOCATIONS (bpt)
1582 /* Clear the "inserted" flag in all breakpoints and delete any
1583 breakpoints which should go away between runs of the program.
1585 Plus other such housekeeping that has to be done for breakpoints
1588 Note: this function gets called at the end of a run (by
1589 generic_mourn_inferior) and when a run begins (by
1590 init_wait_for_inferior). */
1595 breakpoint_init_inferior (enum inf_context context)
1597 struct breakpoint *b, *temp;
1598 struct bp_location *bpt;
1599 static int warning_needed = 0;
1601 ALL_BP_LOCATIONS (bpt)
1604 ALL_BREAKPOINTS_SAFE (b, temp)
1609 case bp_watchpoint_scope:
1611 /* If the call dummy breakpoint is at the entry point it will
1612 cause problems when the inferior is rerun, so we better
1615 Also get rid of scope breakpoints. */
1616 delete_breakpoint (b);
1620 case bp_hardware_watchpoint:
1621 case bp_read_watchpoint:
1622 case bp_access_watchpoint:
1624 /* Likewise for watchpoints on local expressions. */
1625 if (b->exp_valid_block != NULL)
1626 delete_breakpoint (b);
1627 if (context == inf_starting)
1629 /* Reset val field to force reread of starting value
1630 in insert_breakpoints. */
1632 value_free (b->val);
1637 /* Likewise for exception catchpoints in dynamic-linked
1638 executables where required */
1639 if (ep_is_exception_catchpoint (b)
1640 && deprecated_exception_catchpoints_are_fragile)
1643 delete_breakpoint (b);
1649 if (deprecated_exception_catchpoints_are_fragile)
1650 deprecated_exception_support_initialized = 0;
1652 /* Don't issue the warning unless it's really needed... */
1653 if (warning_needed && (context != inf_exited))
1655 warning ("Exception catchpoints from last run were deleted.");
1656 warning ("You must reinsert them explicitly.");
1661 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1662 exists at PC. It returns ordinary_breakpoint_here if it's an
1663 ordinary breakpoint, or permanent_breakpoint_here if it's a
1664 permanent breakpoint.
1665 - When continuing from a location with an ordinary breakpoint, we
1666 actually single step once before calling insert_breakpoints.
1667 - When continuing from a localion with a permanent breakpoint, we
1668 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1669 the target, to advance the PC past the breakpoint. */
1671 enum breakpoint_here
1672 breakpoint_here_p (CORE_ADDR pc)
1674 struct bp_location *bpt;
1675 int any_breakpoint_here = 0;
1677 ALL_BP_LOCATIONS (bpt)
1679 if (bpt->loc_type != bp_loc_software_breakpoint
1680 && bpt->loc_type != bp_loc_hardware_breakpoint)
1683 if ((breakpoint_enabled (bpt->owner)
1684 || bpt->owner->enable_state == bp_permanent)
1685 && bpt->address == pc) /* bp is enabled and matches pc */
1687 if (overlay_debugging
1688 && section_is_overlay (bpt->section)
1689 && !section_is_mapped (bpt->section))
1690 continue; /* unmapped overlay -- can't be a match */
1691 else if (bpt->owner->enable_state == bp_permanent)
1692 return permanent_breakpoint_here;
1694 any_breakpoint_here = 1;
1698 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1702 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1703 but it only returns true if there is actually a breakpoint inserted
1707 breakpoint_inserted_here_p (CORE_ADDR pc)
1709 struct bp_location *bpt;
1711 ALL_BP_LOCATIONS (bpt)
1713 if (bpt->loc_type != bp_loc_software_breakpoint
1714 && bpt->loc_type != bp_loc_hardware_breakpoint)
1718 && bpt->address == pc) /* bp is inserted and matches pc */
1720 if (overlay_debugging
1721 && section_is_overlay (bpt->section)
1722 && !section_is_mapped (bpt->section))
1723 continue; /* unmapped overlay -- can't be a match */
1732 /* This function returns non-zero iff there is a software breakpoint
1736 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1738 struct bp_location *bpt;
1739 int any_breakpoint_here = 0;
1741 ALL_BP_LOCATIONS (bpt)
1743 if (bpt->loc_type != bp_loc_software_breakpoint)
1746 if ((breakpoint_enabled (bpt->owner)
1747 || bpt->owner->enable_state == bp_permanent)
1749 && bpt->address == pc) /* bp is enabled and matches pc */
1751 if (overlay_debugging
1752 && section_is_overlay (bpt->section)
1753 && !section_is_mapped (bpt->section))
1754 continue; /* unmapped overlay -- can't be a match */
1763 /* Return nonzero if FRAME is a dummy frame. We can't use
1764 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1765 take too much time, at least using frame_register() on the 68k.
1766 This means that for this function to work right a port must use the
1767 bp_call_dummy breakpoint. */
1770 deprecated_frame_in_dummy (struct frame_info *frame)
1772 struct breakpoint *b;
1774 /* This function is used by two files: get_frame_type(), after first
1775 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1776 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1777 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1781 if (b->type == bp_call_dummy
1782 && frame_id_eq (b->frame_id, get_frame_id (frame))
1783 /* We need to check the PC as well as the frame on the sparc,
1784 for signals.exp in the testsuite. */
1785 && (get_frame_pc (frame)
1787 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1788 && get_frame_pc (frame) <= b->loc->address)
1794 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1795 PC is valid for process/thread PTID. */
1798 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1800 struct bp_location *bpt;
1803 thread = pid_to_thread_id (ptid);
1805 ALL_BP_LOCATIONS (bpt)
1807 if (bpt->loc_type != bp_loc_software_breakpoint
1808 && bpt->loc_type != bp_loc_hardware_breakpoint)
1811 if ((breakpoint_enabled (bpt->owner)
1812 || bpt->owner->enable_state == bp_permanent)
1813 && bpt->address == pc
1814 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1816 if (overlay_debugging
1817 && section_is_overlay (bpt->section)
1818 && !section_is_mapped (bpt->section))
1819 continue; /* unmapped overlay -- can't be a match */
1829 /* bpstat stuff. External routines' interfaces are documented
1833 ep_is_catchpoint (struct breakpoint *ep)
1836 (ep->type == bp_catch_load)
1837 || (ep->type == bp_catch_unload)
1838 || (ep->type == bp_catch_fork)
1839 || (ep->type == bp_catch_vfork)
1840 || (ep->type == bp_catch_exec)
1841 || (ep->type == bp_catch_catch)
1842 || (ep->type == bp_catch_throw);
1844 /* ??rehrauer: Add more kinds here, as are implemented... */
1848 ep_is_shlib_catchpoint (struct breakpoint *ep)
1851 (ep->type == bp_catch_load)
1852 || (ep->type == bp_catch_unload);
1856 ep_is_exception_catchpoint (struct breakpoint *ep)
1859 (ep->type == bp_catch_catch)
1860 || (ep->type == bp_catch_throw);
1863 /* Clear a bpstat so that it says we are not at any breakpoint.
1864 Also free any storage that is part of a bpstat. */
1867 bpstat_clear (bpstat *bsp)
1878 if (p->old_val != NULL)
1879 value_free (p->old_val);
1880 free_command_lines (&p->commands);
1887 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1888 is part of the bpstat is copied as well. */
1891 bpstat_copy (bpstat bs)
1895 bpstat retval = NULL;
1900 for (; bs != NULL; bs = bs->next)
1902 tmp = (bpstat) xmalloc (sizeof (*tmp));
1903 memcpy (tmp, bs, sizeof (*tmp));
1904 if (bs->commands != NULL)
1905 tmp->commands = copy_command_lines (bs->commands);
1906 if (bs->old_val != NULL)
1907 tmp->old_val = value_copy (bs->old_val);
1910 /* This is the first thing in the chain. */
1920 /* Find the bpstat associated with this breakpoint */
1923 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1928 for (; bsp != NULL; bsp = bsp->next)
1930 if (bsp->breakpoint_at == breakpoint)
1936 /* Find a step_resume breakpoint associated with this bpstat.
1937 (If there are multiple step_resume bp's on the list, this function
1938 will arbitrarily pick one.)
1940 It is an error to use this function if BPSTAT doesn't contain a
1941 step_resume breakpoint.
1943 See wait_for_inferior's use of this function. */
1945 bpstat_find_step_resume_breakpoint (bpstat bsp)
1950 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1952 current_thread = pid_to_thread_id (inferior_ptid);
1954 for (; bsp != NULL; bsp = bsp->next)
1956 if ((bsp->breakpoint_at != NULL) &&
1957 (bsp->breakpoint_at->type == bp_step_resume) &&
1958 (bsp->breakpoint_at->thread == current_thread ||
1959 bsp->breakpoint_at->thread == -1))
1960 return bsp->breakpoint_at;
1963 error ("Internal error (no step_resume breakpoint found)");
1967 /* Return the breakpoint number of the first breakpoint we are stopped
1968 at. *BSP upon return is a bpstat which points to the remaining
1969 breakpoints stopped at (but which is not guaranteed to be good for
1970 anything but further calls to bpstat_num).
1971 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1974 bpstat_num (bpstat *bsp)
1976 struct breakpoint *b;
1979 return 0; /* No more breakpoint values */
1982 b = (*bsp)->breakpoint_at;
1983 *bsp = (*bsp)->next;
1985 return -1; /* breakpoint that's been deleted since */
1987 return b->number; /* We have its number */
1991 /* Modify BS so that the actions will not be performed. */
1994 bpstat_clear_actions (bpstat bs)
1996 for (; bs != NULL; bs = bs->next)
1998 free_command_lines (&bs->commands);
1999 if (bs->old_val != NULL)
2001 value_free (bs->old_val);
2007 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2009 cleanup_executing_breakpoints (void *ignore)
2011 executing_breakpoint_commands = 0;
2014 /* Execute all the commands associated with all the breakpoints at this
2015 location. Any of these commands could cause the process to proceed
2016 beyond this point, etc. We look out for such changes by checking
2017 the global "breakpoint_proceeded" after each command. */
2020 bpstat_do_actions (bpstat *bsp)
2023 struct cleanup *old_chain;
2025 /* Avoid endless recursion if a `source' command is contained
2027 if (executing_breakpoint_commands)
2030 executing_breakpoint_commands = 1;
2031 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2034 /* Note that (as of this writing), our callers all appear to
2035 be passing us the address of global stop_bpstat. And, if
2036 our calls to execute_control_command cause the inferior to
2037 proceed, that global (and hence, *bsp) will change.
2039 We must be careful to not touch *bsp unless the inferior
2040 has not proceeded. */
2042 /* This pointer will iterate over the list of bpstat's. */
2045 breakpoint_proceeded = 0;
2046 for (; bs != NULL; bs = bs->next)
2048 struct command_line *cmd;
2049 struct cleanup *this_cmd_tree_chain;
2051 /* Take ownership of the BSP's command tree, if it has one.
2053 The command tree could legitimately contain commands like
2054 'step' and 'next', which call clear_proceed_status, which
2055 frees stop_bpstat's command tree. To make sure this doesn't
2056 free the tree we're executing out from under us, we need to
2057 take ownership of the tree ourselves. Since a given bpstat's
2058 commands are only executed once, we don't need to copy it; we
2059 can clear the pointer in the bpstat, and make sure we free
2060 the tree when we're done. */
2063 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2067 execute_control_command (cmd);
2069 if (breakpoint_proceeded)
2075 /* We can free this command tree now. */
2076 do_cleanups (this_cmd_tree_chain);
2078 if (breakpoint_proceeded)
2079 /* The inferior is proceeded by the command; bomb out now.
2080 The bpstat chain has been blown away by wait_for_inferior.
2081 But since execution has stopped again, there is a new bpstat
2082 to look at, so start over. */
2085 do_cleanups (old_chain);
2088 /* This is the normal print function for a bpstat. In the future,
2089 much of this logic could (should?) be moved to bpstat_stop_status,
2090 by having it set different print_it values.
2092 Current scheme: When we stop, bpstat_print() is called. It loops
2093 through the bpstat list of things causing this stop, calling the
2094 print_bp_stop_message function on each one. The behavior of the
2095 print_bp_stop_message function depends on the print_it field of
2096 bpstat. If such field so indicates, call this function here.
2098 Return values from this routine (ultimately used by bpstat_print()
2099 and normal_stop() to decide what to do):
2100 PRINT_NOTHING: Means we already printed all we needed to print,
2101 don't print anything else.
2102 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2103 that something to be followed by a location.
2104 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2105 that something to be followed by a location.
2106 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2109 static enum print_stop_action
2110 print_it_typical (bpstat bs)
2112 struct cleanup *old_chain, *ui_out_chain;
2113 struct ui_stream *stb;
2114 stb = ui_out_stream_new (uiout);
2115 old_chain = make_cleanup_ui_out_stream_delete (stb);
2116 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2117 which has since been deleted. */
2118 if (bs->breakpoint_at == NULL)
2119 return PRINT_UNKNOWN;
2121 switch (bs->breakpoint_at->type)
2124 case bp_hardware_breakpoint:
2125 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2126 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2127 bs->breakpoint_at->loc->address,
2128 bs->breakpoint_at->number, 1);
2129 annotate_breakpoint (bs->breakpoint_at->number);
2130 ui_out_text (uiout, "\nBreakpoint ");
2131 if (ui_out_is_mi_like_p (uiout))
2132 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2133 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2134 ui_out_text (uiout, ", ");
2135 return PRINT_SRC_AND_LOC;
2138 case bp_shlib_event:
2139 /* Did we stop because the user set the stop_on_solib_events
2140 variable? (If so, we report this as a generic, "Stopped due
2141 to shlib event" message.) */
2142 printf_filtered ("Stopped due to shared library event\n");
2143 return PRINT_NOTHING;
2146 case bp_thread_event:
2147 /* Not sure how we will get here.
2148 GDB should not stop for these breakpoints. */
2149 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2150 return PRINT_NOTHING;
2153 case bp_overlay_event:
2154 /* By analogy with the thread event, GDB should not stop for these. */
2155 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2156 return PRINT_NOTHING;
2160 annotate_catchpoint (bs->breakpoint_at->number);
2161 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2162 printf_filtered ("loaded");
2163 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2164 return PRINT_SRC_AND_LOC;
2167 case bp_catch_unload:
2168 annotate_catchpoint (bs->breakpoint_at->number);
2169 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2170 printf_filtered ("unloaded");
2171 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2172 return PRINT_SRC_AND_LOC;
2176 annotate_catchpoint (bs->breakpoint_at->number);
2177 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2178 printf_filtered ("forked");
2179 printf_filtered (" process %d), ",
2180 bs->breakpoint_at->forked_inferior_pid);
2181 return PRINT_SRC_AND_LOC;
2184 case bp_catch_vfork:
2185 annotate_catchpoint (bs->breakpoint_at->number);
2186 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2187 printf_filtered ("vforked");
2188 printf_filtered (" process %d), ",
2189 bs->breakpoint_at->forked_inferior_pid);
2190 return PRINT_SRC_AND_LOC;
2194 annotate_catchpoint (bs->breakpoint_at->number);
2195 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2196 bs->breakpoint_at->number,
2197 bs->breakpoint_at->exec_pathname);
2198 return PRINT_SRC_AND_LOC;
2201 case bp_catch_catch:
2202 if (current_exception_event &&
2203 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2205 annotate_catchpoint (bs->breakpoint_at->number);
2206 printf_filtered ("\nCatchpoint %d (exception caught), ",
2207 bs->breakpoint_at->number);
2208 printf_filtered ("throw location ");
2209 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2210 printf_filtered ("%s:%d",
2211 CURRENT_EXCEPTION_THROW_FILE,
2212 CURRENT_EXCEPTION_THROW_LINE);
2214 printf_filtered ("unknown");
2216 printf_filtered (", catch location ");
2217 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2218 printf_filtered ("%s:%d",
2219 CURRENT_EXCEPTION_CATCH_FILE,
2220 CURRENT_EXCEPTION_CATCH_LINE);
2222 printf_filtered ("unknown");
2224 printf_filtered ("\n");
2225 /* don't bother to print location frame info */
2226 return PRINT_SRC_ONLY;
2230 /* really throw, some other bpstat will handle it */
2231 return PRINT_UNKNOWN;
2235 case bp_catch_throw:
2236 if (current_exception_event &&
2237 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2239 annotate_catchpoint (bs->breakpoint_at->number);
2240 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2241 bs->breakpoint_at->number);
2242 printf_filtered ("throw location ");
2243 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2244 printf_filtered ("%s:%d",
2245 CURRENT_EXCEPTION_THROW_FILE,
2246 CURRENT_EXCEPTION_THROW_LINE);
2248 printf_filtered ("unknown");
2250 printf_filtered (", catch location ");
2251 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2252 printf_filtered ("%s:%d",
2253 CURRENT_EXCEPTION_CATCH_FILE,
2254 CURRENT_EXCEPTION_CATCH_LINE);
2256 printf_filtered ("unknown");
2258 printf_filtered ("\n");
2259 /* don't bother to print location frame info */
2260 return PRINT_SRC_ONLY;
2264 /* really catch, some other bpstat will handle it */
2265 return PRINT_UNKNOWN;
2270 case bp_hardware_watchpoint:
2271 if (bs->old_val != NULL)
2273 annotate_watchpoint (bs->breakpoint_at->number);
2274 if (ui_out_is_mi_like_p (uiout))
2275 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2276 mention (bs->breakpoint_at);
2277 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2278 ui_out_text (uiout, "\nOld value = ");
2279 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2280 ui_out_field_stream (uiout, "old", stb);
2281 ui_out_text (uiout, "\nNew value = ");
2282 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2283 ui_out_field_stream (uiout, "new", stb);
2284 do_cleanups (ui_out_chain);
2285 ui_out_text (uiout, "\n");
2286 value_free (bs->old_val);
2289 /* More than one watchpoint may have been triggered. */
2290 return PRINT_UNKNOWN;
2293 case bp_read_watchpoint:
2294 if (ui_out_is_mi_like_p (uiout))
2295 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2296 mention (bs->breakpoint_at);
2297 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2298 ui_out_text (uiout, "\nValue = ");
2299 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2300 ui_out_field_stream (uiout, "value", stb);
2301 do_cleanups (ui_out_chain);
2302 ui_out_text (uiout, "\n");
2303 return PRINT_UNKNOWN;
2306 case bp_access_watchpoint:
2307 if (bs->old_val != NULL)
2309 annotate_watchpoint (bs->breakpoint_at->number);
2310 if (ui_out_is_mi_like_p (uiout))
2311 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2312 mention (bs->breakpoint_at);
2313 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2314 ui_out_text (uiout, "\nOld value = ");
2315 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2316 ui_out_field_stream (uiout, "old", stb);
2317 value_free (bs->old_val);
2319 ui_out_text (uiout, "\nNew value = ");
2323 mention (bs->breakpoint_at);
2324 if (ui_out_is_mi_like_p (uiout))
2325 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2326 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2327 ui_out_text (uiout, "\nValue = ");
2329 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2330 ui_out_field_stream (uiout, "new", stb);
2331 do_cleanups (ui_out_chain);
2332 ui_out_text (uiout, "\n");
2333 return PRINT_UNKNOWN;
2336 /* Fall through, we don't deal with these types of breakpoints
2340 if (ui_out_is_mi_like_p (uiout))
2341 ui_out_field_string (uiout, "reason", "function-finished");
2342 return PRINT_UNKNOWN;
2346 if (ui_out_is_mi_like_p (uiout))
2347 ui_out_field_string (uiout, "reason", "location-reached");
2348 return PRINT_UNKNOWN;
2353 case bp_longjmp_resume:
2354 case bp_step_resume:
2355 case bp_through_sigtramp:
2356 case bp_watchpoint_scope:
2359 return PRINT_UNKNOWN;
2363 /* Generic routine for printing messages indicating why we
2364 stopped. The behavior of this function depends on the value
2365 'print_it' in the bpstat structure. Under some circumstances we
2366 may decide not to print anything here and delegate the task to
2369 static enum print_stop_action
2370 print_bp_stop_message (bpstat bs)
2372 switch (bs->print_it)
2375 /* Nothing should be printed for this bpstat entry. */
2376 return PRINT_UNKNOWN;
2380 /* We still want to print the frame, but we already printed the
2381 relevant messages. */
2382 return PRINT_SRC_AND_LOC;
2385 case print_it_normal:
2386 /* Normal case. Call the breakpoint's print_it method, or
2387 print_it_typical. */
2388 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2389 && bs->breakpoint_at->ops->print_it != NULL)
2390 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2392 return print_it_typical (bs);
2396 internal_error (__FILE__, __LINE__,
2397 "print_bp_stop_message: unrecognized enum value");
2402 /* Print a message indicating what happened. This is called from
2403 normal_stop(). The input to this routine is the head of the bpstat
2404 list - a list of the eventpoints that caused this stop. This
2405 routine calls the generic print routine for printing a message
2406 about reasons for stopping. This will print (for example) the
2407 "Breakpoint n," part of the output. The return value of this
2410 PRINT_UNKNOWN: Means we printed nothing
2411 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2412 code to print the location. An example is
2413 "Breakpoint 1, " which should be followed by
2415 PRINT_SRC_ONLY: Means we printed something, but there is no need
2416 to also print the location part of the message.
2417 An example is the catch/throw messages, which
2418 don't require a location appended to the end.
2419 PRINT_NOTHING: We have done some printing and we don't need any
2420 further info to be printed.*/
2422 enum print_stop_action
2423 bpstat_print (bpstat bs)
2427 /* Maybe another breakpoint in the chain caused us to stop.
2428 (Currently all watchpoints go on the bpstat whether hit or not.
2429 That probably could (should) be changed, provided care is taken
2430 with respect to bpstat_explains_signal). */
2431 for (; bs; bs = bs->next)
2433 val = print_bp_stop_message (bs);
2434 if (val == PRINT_SRC_ONLY
2435 || val == PRINT_SRC_AND_LOC
2436 || val == PRINT_NOTHING)
2440 /* We reached the end of the chain, or we got a null BS to start
2441 with and nothing was printed. */
2442 return PRINT_UNKNOWN;
2445 /* Evaluate the expression EXP and return 1 if value is zero.
2446 This is used inside a catch_errors to evaluate the breakpoint condition.
2447 The argument is a "struct expression *" that has been cast to char * to
2448 make it pass through catch_errors. */
2451 breakpoint_cond_eval (void *exp)
2453 struct value *mark = value_mark ();
2454 int i = !value_true (evaluate_expression ((struct expression *) exp));
2455 value_free_to_mark (mark);
2459 /* Allocate a new bpstat and chain it to the current one. */
2462 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2466 bs = (bpstat) xmalloc (sizeof (*bs));
2468 bs->breakpoint_at = b;
2469 /* If the condition is false, etc., don't do the commands. */
2470 bs->commands = NULL;
2472 bs->print_it = print_it_normal;
2476 /* Possible return values for watchpoint_check (this can't be an enum
2477 because of check_errors). */
2478 /* The watchpoint has been deleted. */
2479 #define WP_DELETED 1
2480 /* The value has changed. */
2481 #define WP_VALUE_CHANGED 2
2482 /* The value has not changed. */
2483 #define WP_VALUE_NOT_CHANGED 3
2485 #define BP_TEMPFLAG 1
2486 #define BP_HARDWAREFLAG 2
2488 /* Check watchpoint condition. */
2491 watchpoint_check (void *p)
2493 bpstat bs = (bpstat) p;
2494 struct breakpoint *b;
2495 struct frame_info *fr;
2496 int within_current_scope;
2498 b = bs->breakpoint_at;
2500 if (b->exp_valid_block == NULL)
2501 within_current_scope = 1;
2504 /* There is no current frame at this moment. If we're going to have
2505 any chance of handling watchpoints on local variables, we'll need
2506 the frame chain (so we can determine if we're in scope). */
2507 reinit_frame_cache ();
2508 fr = frame_find_by_id (b->watchpoint_frame);
2509 within_current_scope = (fr != NULL);
2510 /* in_function_epilogue_p() returns a non-zero value if we're still
2511 in the function but the stack frame has already been invalidated.
2512 Since we can't rely on the values of local variables after the
2513 stack has been destroyed, we are treating the watchpoint in that
2514 state as `not changed' without further checking.
2516 vinschen/2003-09-04: The former implementation left out the case
2517 that the watchpoint frame couldn't be found by frame_find_by_id()
2518 because the current PC is currently in an epilogue. Calling
2519 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2520 if ((!within_current_scope || fr == get_current_frame ())
2521 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2522 return WP_VALUE_NOT_CHANGED;
2523 if (fr && within_current_scope)
2524 /* If we end up stopping, the current frame will get selected
2525 in normal_stop. So this call to select_frame won't affect
2530 if (within_current_scope)
2532 /* We use value_{,free_to_}mark because it could be a
2533 *long* time before we return to the command level and
2534 call free_all_values. We can't call free_all_values because
2535 we might be in the middle of evaluating a function call. */
2537 struct value *mark = value_mark ();
2538 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2539 if (!value_equal (b->val, new_val))
2541 release_value (new_val);
2542 value_free_to_mark (mark);
2543 bs->old_val = b->val;
2545 /* We will stop here */
2546 return WP_VALUE_CHANGED;
2550 /* Nothing changed, don't do anything. */
2551 value_free_to_mark (mark);
2552 /* We won't stop here */
2553 return WP_VALUE_NOT_CHANGED;
2558 /* This seems like the only logical thing to do because
2559 if we temporarily ignored the watchpoint, then when
2560 we reenter the block in which it is valid it contains
2561 garbage (in the case of a function, it may have two
2562 garbage values, one before and one after the prologue).
2563 So we can't even detect the first assignment to it and
2564 watch after that (since the garbage may or may not equal
2565 the first value assigned). */
2566 /* We print all the stop information in print_it_typical(), but
2567 in this case, by the time we call print_it_typical() this bp
2568 will be deleted already. So we have no choice but print the
2569 information here. */
2570 if (ui_out_is_mi_like_p (uiout))
2571 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2572 ui_out_text (uiout, "\nWatchpoint ");
2573 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2574 ui_out_text (uiout, " deleted because the program has left the block in\n\
2575 which its expression is valid.\n");
2577 if (b->related_breakpoint)
2578 b->related_breakpoint->disposition = disp_del_at_next_stop;
2579 b->disposition = disp_del_at_next_stop;
2585 /* Get a bpstat associated with having just stopped at address
2588 /* Determine whether we stopped at a breakpoint, etc, or whether we
2589 don't understand this stop. Result is a chain of bpstat's such that:
2591 if we don't understand the stop, the result is a null pointer.
2593 if we understand why we stopped, the result is not null.
2595 Each element of the chain refers to a particular breakpoint or
2596 watchpoint at which we have stopped. (We may have stopped for
2597 several reasons concurrently.)
2599 Each element of the chain has valid next, breakpoint_at,
2600 commands, FIXME??? fields. */
2603 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
2605 struct breakpoint *b, *temp;
2606 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2607 int real_breakpoint = 0;
2608 /* Root of the chain of bpstat's */
2609 struct bpstats root_bs[1];
2610 /* Pointer to the last thing in the chain currently. */
2611 bpstat bs = root_bs;
2612 int thread_id = pid_to_thread_id (ptid);
2614 ALL_BREAKPOINTS_SAFE (b, temp)
2616 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2619 if (b->type != bp_watchpoint
2620 && b->type != bp_hardware_watchpoint
2621 && b->type != bp_read_watchpoint
2622 && b->type != bp_access_watchpoint
2623 && b->type != bp_hardware_breakpoint
2624 && b->type != bp_catch_fork
2625 && b->type != bp_catch_vfork
2626 && b->type != bp_catch_exec
2627 && b->type != bp_catch_catch
2628 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2630 if (b->loc->address != bp_addr) /* address doesn't match */
2632 if (overlay_debugging /* unmapped overlay section */
2633 && section_is_overlay (b->loc->section)
2634 && !section_is_mapped (b->loc->section))
2638 if (b->type == bp_hardware_breakpoint)
2640 if (b->loc->address != bp_addr)
2642 if (overlay_debugging /* unmapped overlay section */
2643 && section_is_overlay (b->loc->section)
2644 && !section_is_mapped (b->loc->section))
2648 /* Is this a catchpoint of a load or unload? If so, did we
2649 get a load or unload of the specified library? If not,
2651 if ((b->type == bp_catch_load)
2652 #if defined(SOLIB_HAVE_LOAD_EVENT)
2653 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2654 || ((b->dll_pathname != NULL)
2655 && (strcmp (b->dll_pathname,
2656 SOLIB_LOADED_LIBRARY_PATHNAME (
2657 PIDGET (inferior_ptid)))
2663 if ((b->type == bp_catch_unload)
2664 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2665 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2666 || ((b->dll_pathname != NULL)
2667 && (strcmp (b->dll_pathname,
2668 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2669 PIDGET (inferior_ptid)))
2675 if ((b->type == bp_catch_fork)
2676 && !inferior_has_forked (PIDGET (inferior_ptid),
2677 &b->forked_inferior_pid))
2680 if ((b->type == bp_catch_vfork)
2681 && !inferior_has_vforked (PIDGET (inferior_ptid),
2682 &b->forked_inferior_pid))
2685 if ((b->type == bp_catch_exec)
2686 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2689 if (ep_is_exception_catchpoint (b) &&
2690 !(current_exception_event = target_get_current_exception_event ()))
2693 /* Come here if it's a watchpoint, or if the break address matches */
2695 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2697 /* Watchpoints may change this, if not found to have triggered. */
2701 if (b->type == bp_watchpoint ||
2702 b->type == bp_hardware_watchpoint)
2704 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2706 struct cleanup *cleanups = make_cleanup (xfree, message);
2707 int e = catch_errors (watchpoint_check, bs, message,
2709 do_cleanups (cleanups);
2713 /* We've already printed what needs to be printed. */
2714 /* Actually this is superfluous, because by the time we
2715 call print_it_typical() the wp will be already deleted,
2716 and the function will return immediately. */
2717 bs->print_it = print_it_done;
2720 case WP_VALUE_CHANGED:
2724 case WP_VALUE_NOT_CHANGED:
2726 bs->print_it = print_it_noop;
2733 /* Error from catch_errors. */
2734 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2735 if (b->related_breakpoint)
2736 b->related_breakpoint->disposition = disp_del_at_next_stop;
2737 b->disposition = disp_del_at_next_stop;
2738 /* We've already printed what needs to be printed. */
2739 bs->print_it = print_it_done;
2745 else if (b->type == bp_read_watchpoint ||
2746 b->type == bp_access_watchpoint)
2752 addr = target_stopped_data_address ();
2755 for (v = b->val_chain; v; v = v->next)
2757 if (VALUE_LVAL (v) == lval_memory
2758 && ! VALUE_LAZY (v))
2760 struct type *vtype = check_typedef (VALUE_TYPE (v));
2762 if (v == b->val_chain
2763 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2764 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2768 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2769 /* Exact match not required. Within range is
2771 if (addr >= vaddr &&
2772 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2779 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2781 struct cleanup *cleanups = make_cleanup (xfree, message);
2782 int e = catch_errors (watchpoint_check, bs, message,
2784 do_cleanups (cleanups);
2788 /* We've already printed what needs to be printed. */
2789 bs->print_it = print_it_done;
2792 case WP_VALUE_CHANGED:
2793 if (b->type == bp_read_watchpoint)
2795 /* Don't stop: read watchpoints shouldn't fire if
2796 the value has changed. This is for targets
2797 which cannot set read-only watchpoints. */
2798 bs->print_it = print_it_noop;
2804 case WP_VALUE_NOT_CHANGED:
2811 /* Error from catch_errors. */
2812 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2813 if (b->related_breakpoint)
2814 b->related_breakpoint->disposition = disp_del_at_next_stop;
2815 b->disposition = disp_del_at_next_stop;
2816 /* We've already printed what needs to be printed. */
2817 bs->print_it = print_it_done;
2821 else /* found == 0 */
2823 /* This is a case where some watchpoint(s) triggered,
2824 but not at the address of this watchpoint (FOUND
2825 was left zero). So don't print anything for this
2827 bs->print_it = print_it_noop;
2834 /* By definition, an encountered breakpoint is a triggered
2838 real_breakpoint = 1;
2841 if (frame_id_p (b->frame_id)
2842 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2846 int value_is_zero = 0;
2850 /* Need to select the frame, with all that implies
2851 so that the conditions will have the right context. */
2852 select_frame (get_current_frame ());
2854 = catch_errors (breakpoint_cond_eval, (b->cond),
2855 "Error in testing breakpoint condition:\n",
2857 /* FIXME-someday, should give breakpoint # */
2860 if (b->cond && value_is_zero)
2863 /* Don't consider this a hit. */
2866 else if (b->thread != -1 && b->thread != thread_id)
2869 /* Don't consider this a hit. */
2872 else if (b->ignore_count > 0)
2875 annotate_ignore_count_change ();
2880 /* We will stop here */
2881 if (b->disposition == disp_disable)
2882 b->enable_state = bp_disabled;
2885 bs->commands = b->commands;
2887 (strcmp ("silent", bs->commands->line) == 0
2888 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2890 bs->commands = bs->commands->next;
2893 bs->commands = copy_command_lines (bs->commands);
2896 /* Print nothing for this entry if we dont stop or if we dont print. */
2897 if (bs->stop == 0 || bs->print == 0)
2898 bs->print_it = print_it_noop;
2901 bs->next = NULL; /* Terminate the chain */
2902 bs = root_bs->next; /* Re-grab the head of the chain */
2904 /* The value of a hardware watchpoint hasn't changed, but the
2905 intermediate memory locations we are watching may have. */
2906 if (bs && !bs->stop &&
2907 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2908 bs->breakpoint_at->type == bp_read_watchpoint ||
2909 bs->breakpoint_at->type == bp_access_watchpoint))
2911 remove_breakpoints ();
2912 insert_breakpoints ();
2917 /* Tell what to do about this bpstat. */
2919 bpstat_what (bpstat bs)
2921 /* Classify each bpstat as one of the following. */
2924 /* This bpstat element has no effect on the main_action. */
2927 /* There was a watchpoint, stop but don't print. */
2930 /* There was a watchpoint, stop and print. */
2933 /* There was a breakpoint but we're not stopping. */
2936 /* There was a breakpoint, stop but don't print. */
2939 /* There was a breakpoint, stop and print. */
2942 /* We hit the longjmp breakpoint. */
2945 /* We hit the longjmp_resume breakpoint. */
2948 /* We hit the step_resume breakpoint. */
2951 /* We hit the through_sigtramp breakpoint. */
2954 /* We hit the shared library event breakpoint. */
2957 /* We caught a shared library event. */
2960 /* This is just used to count how many enums there are. */
2964 /* Here is the table which drives this routine. So that we can
2965 format it pretty, we define some abbreviations for the
2966 enum bpstat_what codes. */
2967 #define kc BPSTAT_WHAT_KEEP_CHECKING
2968 #define ss BPSTAT_WHAT_STOP_SILENT
2969 #define sn BPSTAT_WHAT_STOP_NOISY
2970 #define sgl BPSTAT_WHAT_SINGLE
2971 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2972 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2973 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2974 #define sr BPSTAT_WHAT_STEP_RESUME
2975 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2976 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2977 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2979 /* "Can't happen." Might want to print an error message.
2980 abort() is not out of the question, but chances are GDB is just
2981 a bit confused, not unusable. */
2982 #define err BPSTAT_WHAT_STOP_NOISY
2984 /* Given an old action and a class, come up with a new action. */
2985 /* One interesting property of this table is that wp_silent is the same
2986 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2987 after stopping, the check for whether to step over a breakpoint
2988 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2989 reference to how we stopped. We retain separate wp_silent and
2990 bp_silent codes in case we want to change that someday.
2992 Another possibly interesting property of this table is that
2993 there's a partial ordering, priority-like, of the actions. Once
2994 you've decided that some action is appropriate, you'll never go
2995 back and decide something of a lower priority is better. The
2998 kc < clr sgl shl shlr slr sn sr ss ts
2999 sgl < clrs shl shlr slr sn sr ss ts
3000 slr < err shl shlr sn sr ss ts
3001 clr < clrs err shl shlr sn sr ss ts
3002 clrs < err shl shlr sn sr ss ts
3003 ss < shl shlr sn sr ts
3010 What I think this means is that we don't need a damned table
3011 here. If you just put the rows and columns in the right order,
3012 it'd look awfully regular. We could simply walk the bpstat list
3013 and choose the highest priority action we find, with a little
3014 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3015 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3016 is messy anyway). */
3018 /* step_resume entries: a step resume breakpoint overrides another
3019 breakpoint of signal handling (see comment in wait_for_inferior
3020 at first DEPRECATED_PC_IN_SIGTRAMP where we set the step_resume
3022 /* We handle the through_sigtramp_breakpoint the same way; having both
3023 one of those and a step_resume_breakpoint is probably very rare (?). */
3025 static const enum bpstat_what_main_action
3026 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3029 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3032 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
3034 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3036 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3038 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
3040 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3042 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3044 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
3046 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
3048 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
3050 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
3052 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
3054 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3069 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3070 struct bpstat_what retval;
3072 retval.call_dummy = 0;
3073 for (; bs != NULL; bs = bs->next)
3075 enum class bs_class = no_effect;
3076 if (bs->breakpoint_at == NULL)
3077 /* I suspect this can happen if it was a momentary breakpoint
3078 which has since been deleted. */
3080 switch (bs->breakpoint_at->type)
3086 case bp_hardware_breakpoint:
3092 bs_class = bp_noisy;
3094 bs_class = bp_silent;
3097 bs_class = bp_nostop;
3100 case bp_hardware_watchpoint:
3101 case bp_read_watchpoint:
3102 case bp_access_watchpoint:
3106 bs_class = wp_noisy;
3108 bs_class = wp_silent;
3111 /* There was a watchpoint, but we're not stopping.
3112 This requires no further action. */
3113 bs_class = no_effect;
3116 bs_class = long_jump;
3118 case bp_longjmp_resume:
3119 bs_class = long_resume;
3121 case bp_step_resume:
3124 bs_class = step_resume;
3127 /* It is for the wrong frame. */
3128 bs_class = bp_nostop;
3130 case bp_through_sigtramp:
3131 bs_class = through_sig;
3133 case bp_watchpoint_scope:
3134 bs_class = bp_nostop;
3136 case bp_shlib_event:
3137 bs_class = shlib_event;
3139 case bp_thread_event:
3140 case bp_overlay_event:
3141 bs_class = bp_nostop;
3144 case bp_catch_unload:
3145 /* Only if this catchpoint triggered should we cause the
3146 step-out-of-dld behaviour. Otherwise, we ignore this
3149 bs_class = catch_shlib_event;
3151 bs_class = no_effect;
3154 case bp_catch_vfork:
3159 bs_class = bp_noisy;
3161 bs_class = bp_silent;
3164 /* There was a catchpoint, but we're not stopping.
3165 This requires no further action. */
3166 bs_class = no_effect;
3168 case bp_catch_catch:
3169 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3170 bs_class = bp_nostop;
3172 bs_class = bs->print ? bp_noisy : bp_silent;
3174 case bp_catch_throw:
3175 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3176 bs_class = bp_nostop;
3178 bs_class = bs->print ? bp_noisy : bp_silent;
3181 /* Make sure the action is stop (silent or noisy),
3182 so infrun.c pops the dummy frame. */
3183 bs_class = bp_silent;
3184 retval.call_dummy = 1;
3187 current_action = table[(int) bs_class][(int) current_action];
3189 retval.main_action = current_action;
3193 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3194 without hardware support). This isn't related to a specific bpstat,
3195 just to things like whether watchpoints are set. */
3198 bpstat_should_step (void)
3200 struct breakpoint *b;
3202 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3207 /* Nonzero if there are enabled hardware watchpoints. */
3209 bpstat_have_active_hw_watchpoints (void)
3211 struct bp_location *bpt;
3212 ALL_BP_LOCATIONS (bpt)
3213 if (breakpoint_enabled (bpt->owner)
3215 && bpt->loc_type == bp_loc_hardware_watchpoint)
3221 /* Given a bpstat that records zero or more triggered eventpoints, this
3222 function returns another bpstat which contains only the catchpoints
3223 on that first list, if any. */
3225 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3227 struct bpstats root_bs[1];
3228 bpstat bs = root_bs;
3229 struct breakpoint *ep;
3232 bpstat_clear (cp_list);
3233 root_bs->next = NULL;
3235 for (; ep_list != NULL; ep_list = ep_list->next)
3237 /* Is this eventpoint a catchpoint? If not, ignore it. */
3238 ep = ep_list->breakpoint_at;
3241 if ((ep->type != bp_catch_load) &&
3242 (ep->type != bp_catch_unload) &&
3243 (ep->type != bp_catch_catch) &&
3244 (ep->type != bp_catch_throw))
3245 /* pai: (temp) ADD fork/vfork here!! */
3248 /* Yes; add it to the list. */
3249 bs = bpstat_alloc (ep, bs);
3254 #if defined(SOLIB_ADD)
3255 /* Also, for each triggered catchpoint, tag it with the name of
3256 the library that caused this trigger. (We copy the name now,
3257 because it's only guaranteed to be available NOW, when the
3258 catchpoint triggers. Clients who may wish to know the name
3259 later must get it from the catchpoint itself.) */
3260 if (ep->triggered_dll_pathname != NULL)
3261 xfree (ep->triggered_dll_pathname);
3262 if (ep->type == bp_catch_load)
3263 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3264 PIDGET (inferior_ptid));
3266 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3267 PIDGET (inferior_ptid));
3269 dll_pathname = NULL;
3273 ep->triggered_dll_pathname = (char *)
3274 xmalloc (strlen (dll_pathname) + 1);
3275 strcpy (ep->triggered_dll_pathname, dll_pathname);
3278 ep->triggered_dll_pathname = NULL;
3284 /* Print B to gdb_stdout. */
3286 print_one_breakpoint (struct breakpoint *b,
3287 CORE_ADDR *last_addr)
3289 struct command_line *l;
3291 struct ep_type_description
3296 static struct ep_type_description bptypes[] =
3298 {bp_none, "?deleted?"},
3299 {bp_breakpoint, "breakpoint"},
3300 {bp_hardware_breakpoint, "hw breakpoint"},
3301 {bp_until, "until"},
3302 {bp_finish, "finish"},
3303 {bp_watchpoint, "watchpoint"},
3304 {bp_hardware_watchpoint, "hw watchpoint"},
3305 {bp_read_watchpoint, "read watchpoint"},
3306 {bp_access_watchpoint, "acc watchpoint"},
3307 {bp_longjmp, "longjmp"},
3308 {bp_longjmp_resume, "longjmp resume"},
3309 {bp_step_resume, "step resume"},
3310 {bp_through_sigtramp, "sigtramp"},
3311 {bp_watchpoint_scope, "watchpoint scope"},
3312 {bp_call_dummy, "call dummy"},
3313 {bp_shlib_event, "shlib events"},
3314 {bp_thread_event, "thread events"},
3315 {bp_overlay_event, "overlay events"},
3316 {bp_catch_load, "catch load"},
3317 {bp_catch_unload, "catch unload"},
3318 {bp_catch_fork, "catch fork"},
3319 {bp_catch_vfork, "catch vfork"},
3320 {bp_catch_exec, "catch exec"},
3321 {bp_catch_catch, "catch catch"},
3322 {bp_catch_throw, "catch throw"}
3325 static char *bpdisps[] =
3326 {"del", "dstp", "dis", "keep"};
3327 static char bpenables[] = "nynny";
3328 char wrap_indent[80];
3329 struct ui_stream *stb = ui_out_stream_new (uiout);
3330 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3331 struct cleanup *bkpt_chain;
3334 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3338 ui_out_field_int (uiout, "number", b->number);
3342 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3343 || ((int) b->type != bptypes[(int) b->type].type))
3344 internal_error (__FILE__, __LINE__,
3345 "bptypes table does not describe type #%d.",
3347 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3351 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3355 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3356 ui_out_spaces (uiout, 2);
3359 strcpy (wrap_indent, " ");
3362 if (TARGET_ADDR_BIT <= 32)
3363 strcat (wrap_indent, " ");
3365 strcat (wrap_indent, " ");
3368 if (b->ops != NULL && b->ops->print_one != NULL)
3369 b->ops->print_one (b, last_addr);
3374 internal_error (__FILE__, __LINE__,
3375 "print_one_breakpoint: bp_none encountered\n");
3379 case bp_hardware_watchpoint:
3380 case bp_read_watchpoint:
3381 case bp_access_watchpoint:
3382 /* Field 4, the address, is omitted (which makes the columns
3383 not line up too nicely with the headers, but the effect
3384 is relatively readable). */
3386 ui_out_field_skip (uiout, "addr");
3388 print_expression (b->exp, stb->stream);
3389 ui_out_field_stream (uiout, "what", stb);
3393 case bp_catch_unload:
3394 /* Field 4, the address, is omitted (which makes the columns
3395 not line up too nicely with the headers, but the effect
3396 is relatively readable). */
3398 ui_out_field_skip (uiout, "addr");
3400 if (b->dll_pathname == NULL)
3402 ui_out_field_string (uiout, "what", "<any library>");
3403 ui_out_spaces (uiout, 1);
3407 ui_out_text (uiout, "library \"");
3408 ui_out_field_string (uiout, "what", b->dll_pathname);
3409 ui_out_text (uiout, "\" ");
3414 case bp_catch_vfork:
3415 /* Field 4, the address, is omitted (which makes the columns
3416 not line up too nicely with the headers, but the effect
3417 is relatively readable). */
3419 ui_out_field_skip (uiout, "addr");
3421 if (b->forked_inferior_pid != 0)
3423 ui_out_text (uiout, "process ");
3424 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3425 ui_out_spaces (uiout, 1);
3429 /* Field 4, the address, is omitted (which makes the columns
3430 not line up too nicely with the headers, but the effect
3431 is relatively readable). */
3433 ui_out_field_skip (uiout, "addr");
3435 if (b->exec_pathname != NULL)
3437 ui_out_text (uiout, "program \"");
3438 ui_out_field_string (uiout, "what", b->exec_pathname);
3439 ui_out_text (uiout, "\" ");
3443 case bp_catch_catch:
3444 /* Field 4, the address, is omitted (which makes the columns
3445 not line up too nicely with the headers, but the effect
3446 is relatively readable). */
3448 ui_out_field_skip (uiout, "addr");
3450 ui_out_field_string (uiout, "what", "exception catch");
3451 ui_out_spaces (uiout, 1);
3454 case bp_catch_throw:
3455 /* Field 4, the address, is omitted (which makes the columns
3456 not line up too nicely with the headers, but the effect
3457 is relatively readable). */
3459 ui_out_field_skip (uiout, "addr");
3461 ui_out_field_string (uiout, "what", "exception throw");
3462 ui_out_spaces (uiout, 1);
3466 case bp_hardware_breakpoint:
3470 case bp_longjmp_resume:
3471 case bp_step_resume:
3472 case bp_through_sigtramp:
3473 case bp_watchpoint_scope:
3475 case bp_shlib_event:
3476 case bp_thread_event:
3477 case bp_overlay_event:
3482 ui_out_field_string (uiout, "addr", "<PENDING>");
3484 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3487 *last_addr = b->loc->address;
3490 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3493 ui_out_text (uiout, "in ");
3494 ui_out_field_string (uiout, "func",
3495 SYMBOL_PRINT_NAME (sym));
3496 ui_out_wrap_hint (uiout, wrap_indent);
3497 ui_out_text (uiout, " at ");
3499 ui_out_field_string (uiout, "file", b->source_file);
3500 ui_out_text (uiout, ":");
3501 ui_out_field_int (uiout, "line", b->line_number);
3503 else if (b->pending)
3505 ui_out_field_string (uiout, "pending", b->addr_string);
3509 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3510 ui_out_field_stream (uiout, "at", stb);
3515 if (b->thread != -1)
3517 /* FIXME: This seems to be redundant and lost here; see the
3518 "stop only in" line a little further down. */
3519 ui_out_text (uiout, " thread ");
3520 ui_out_field_int (uiout, "thread", b->thread);
3523 ui_out_text (uiout, "\n");
3525 if (frame_id_p (b->frame_id))
3528 ui_out_text (uiout, "\tstop only in stack frame at ");
3529 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3531 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3532 ui_out_text (uiout, "\n");
3538 ui_out_text (uiout, "\tstop only if ");
3539 print_expression (b->cond, stb->stream);
3540 ui_out_field_stream (uiout, "cond", stb);
3541 ui_out_text (uiout, "\n");
3544 if (b->pending && b->cond_string)
3547 ui_out_text (uiout, "\tstop only if ");
3548 ui_out_field_string (uiout, "cond", b->cond_string);
3549 ui_out_text (uiout, "\n");
3552 if (b->thread != -1)
3554 /* FIXME should make an annotation for this */
3555 ui_out_text (uiout, "\tstop only in thread ");
3556 ui_out_field_int (uiout, "thread", b->thread);
3557 ui_out_text (uiout, "\n");
3560 if (show_breakpoint_hit_counts && b->hit_count)
3562 /* FIXME should make an annotation for this */
3563 if (ep_is_catchpoint (b))
3564 ui_out_text (uiout, "\tcatchpoint");
3566 ui_out_text (uiout, "\tbreakpoint");
3567 ui_out_text (uiout, " already hit ");
3568 ui_out_field_int (uiout, "times", b->hit_count);
3569 if (b->hit_count == 1)
3570 ui_out_text (uiout, " time\n");
3572 ui_out_text (uiout, " times\n");
3575 /* Output the count also if it is zero, but only if this is
3576 mi. FIXME: Should have a better test for this. */
3577 if (ui_out_is_mi_like_p (uiout))
3578 if (show_breakpoint_hit_counts && b->hit_count == 0)
3579 ui_out_field_int (uiout, "times", b->hit_count);
3581 if (b->ignore_count)
3584 ui_out_text (uiout, "\tignore next ");
3585 ui_out_field_int (uiout, "ignore", b->ignore_count);
3586 ui_out_text (uiout, " hits\n");
3589 if ((l = b->commands))
3591 struct cleanup *script_chain;
3594 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3595 print_command_lines (uiout, l, 4);
3596 do_cleanups (script_chain);
3598 do_cleanups (bkpt_chain);
3599 do_cleanups (old_chain);
3602 struct captured_breakpoint_query_args
3608 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3610 struct captured_breakpoint_query_args *args = data;
3611 struct breakpoint *b;
3612 CORE_ADDR dummy_addr = 0;
3615 if (args->bnum == b->number)
3617 print_one_breakpoint (b, &dummy_addr);
3625 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3627 struct captured_breakpoint_query_args args;
3629 /* For the moment we don't trust print_one_breakpoint() to not throw
3631 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3632 NULL, RETURN_MASK_ALL);
3635 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3636 catchpoints, et.al.). */
3639 user_settable_breakpoint (const struct breakpoint *b)
3641 return (b->type == bp_breakpoint
3642 || b->type == bp_catch_load
3643 || b->type == bp_catch_unload
3644 || b->type == bp_catch_fork
3645 || b->type == bp_catch_vfork
3646 || b->type == bp_catch_exec
3647 || b->type == bp_catch_catch
3648 || b->type == bp_catch_throw
3649 || b->type == bp_hardware_breakpoint
3650 || b->type == bp_watchpoint
3651 || b->type == bp_read_watchpoint
3652 || b->type == bp_access_watchpoint
3653 || b->type == bp_hardware_watchpoint);
3656 /* Print information on user settable breakpoint (watchpoint, etc)
3657 number BNUM. If BNUM is -1 print all user settable breakpoints.
3658 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3661 breakpoint_1 (int bnum, int allflag)
3663 struct breakpoint *b;
3664 CORE_ADDR last_addr = (CORE_ADDR) -1;
3665 int nr_printable_breakpoints;
3666 struct cleanup *bkpttbl_chain;
3668 /* Compute the number of rows in the table. */
3669 nr_printable_breakpoints = 0;
3672 || bnum == b->number)
3674 if (allflag || user_settable_breakpoint (b))
3675 nr_printable_breakpoints++;
3680 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3684 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3687 if (nr_printable_breakpoints > 0)
3688 annotate_breakpoints_headers ();
3689 if (nr_printable_breakpoints > 0)
3691 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3692 if (nr_printable_breakpoints > 0)
3694 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3695 if (nr_printable_breakpoints > 0)
3697 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3698 if (nr_printable_breakpoints > 0)
3700 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3703 if (nr_printable_breakpoints > 0)
3705 if (TARGET_ADDR_BIT <= 32)
3706 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3708 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3710 if (nr_printable_breakpoints > 0)
3712 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3713 ui_out_table_body (uiout);
3714 if (nr_printable_breakpoints > 0)
3715 annotate_breakpoints_table ();
3719 || bnum == b->number)
3721 /* We only print out user settable breakpoints unless the
3723 if (allflag || user_settable_breakpoint (b))
3724 print_one_breakpoint (b, &last_addr);
3727 do_cleanups (bkpttbl_chain);
3729 if (nr_printable_breakpoints == 0)
3732 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3734 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3739 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3740 that a comparison of an unsigned with -1 is always false. */
3741 if (last_addr != (CORE_ADDR) -1)
3742 set_next_address (last_addr);
3745 /* FIXME? Should this be moved up so that it is only called when
3746 there have been breakpoints? */
3747 annotate_breakpoints_table_end ();
3751 breakpoints_info (char *bnum_exp, int from_tty)
3756 bnum = parse_and_eval_long (bnum_exp);
3758 breakpoint_1 (bnum, 0);
3762 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3767 bnum = parse_and_eval_long (bnum_exp);
3769 breakpoint_1 (bnum, 1);
3772 /* Print a message describing any breakpoints set at PC. */
3775 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3778 struct breakpoint *b;
3781 if (b->loc->address == pc) /* address match / overlay match */
3782 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3786 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3788 if (b->loc->address == pc) /* address match / overlay match */
3789 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3792 printf_filtered ("%d%s%s ",
3794 ((b->enable_state == bp_disabled ||
3795 b->enable_state == bp_shlib_disabled ||
3796 b->enable_state == bp_call_disabled)
3798 : b->enable_state == bp_permanent
3802 : ((others == 1) ? " and" : ""));
3804 printf_filtered ("also set at pc ");
3805 print_address_numeric (pc, 1, gdb_stdout);
3806 printf_filtered (".\n");
3810 /* Set the default place to put a breakpoint
3811 for the `break' command with no arguments. */
3814 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3817 default_breakpoint_valid = valid;
3818 default_breakpoint_address = addr;
3819 default_breakpoint_symtab = symtab;
3820 default_breakpoint_line = line;
3823 /* Return true iff it is meaningful to use the address member of
3824 BPT. For some breakpoint types, the address member is irrelevant
3825 and it makes no sense to attempt to compare it to other addresses
3826 (or use it for any other purpose either).
3828 More specifically, each of the following breakpoint types will always
3829 have a zero valued address and we don't want check_duplicates() to mark
3830 breakpoints of any of these types to be a duplicate of an actual
3831 breakpoint at address zero:
3834 bp_hardware_watchpoint
3836 bp_access_watchpoint
3843 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3845 enum bptype type = bpt->type;
3847 return (type != bp_watchpoint
3848 && type != bp_hardware_watchpoint
3849 && type != bp_read_watchpoint
3850 && type != bp_access_watchpoint
3851 && type != bp_catch_exec
3852 && type != bp_longjmp_resume
3853 && type != bp_catch_fork
3854 && type != bp_catch_vfork);
3857 /* Rescan breakpoints at the same address and section as BPT,
3858 marking the first one as "first" and any others as "duplicates".
3859 This is so that the bpt instruction is only inserted once.
3860 If we have a permanent breakpoint at the same place as BPT, make
3861 that one the official one, and the rest as duplicates. */
3864 check_duplicates (struct breakpoint *bpt)
3866 struct bp_location *b;
3868 struct bp_location *perm_bp = 0;
3869 CORE_ADDR address = bpt->loc->address;
3870 asection *section = bpt->loc->section;
3872 if (! breakpoint_address_is_meaningful (bpt))
3875 ALL_BP_LOCATIONS (b)
3876 if (b->owner->enable_state != bp_disabled
3877 && b->owner->enable_state != bp_shlib_disabled
3878 && !b->owner->pending
3879 && b->owner->enable_state != bp_call_disabled
3880 && b->address == address /* address / overlay match */
3881 && (!overlay_debugging || b->section == section)
3882 && breakpoint_address_is_meaningful (b->owner))
3884 /* Have we found a permanent breakpoint? */
3885 if (b->owner->enable_state == bp_permanent)
3892 b->duplicate = count > 1;
3895 /* If we found a permanent breakpoint at this address, go over the
3896 list again and declare all the other breakpoints there to be the
3900 perm_bp->duplicate = 0;
3902 /* Permanent breakpoint should always be inserted. */
3903 if (! perm_bp->inserted)
3904 internal_error (__FILE__, __LINE__,
3905 "allegedly permanent breakpoint is not "
3906 "actually inserted");
3908 ALL_BP_LOCATIONS (b)
3911 if (b->owner->enable_state != bp_disabled
3912 && b->owner->enable_state != bp_shlib_disabled
3913 && !b->owner->pending
3914 && b->owner->enable_state != bp_call_disabled
3915 && b->address == address /* address / overlay match */
3916 && (!overlay_debugging || b->section == section)
3917 && breakpoint_address_is_meaningful (b->owner))
3920 internal_error (__FILE__, __LINE__,
3921 "another breakpoint was inserted on top of "
3922 "a permanent breakpoint");
3931 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3932 int bnum, int have_bnum)
3937 strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l"));
3938 strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l"));
3940 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3941 bnum, astr1, astr2);
3943 warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2);
3946 /* Adjust a breakpoint's address to account for architectural constraints
3947 on breakpoint placement. Return the adjusted address. Note: Very
3948 few targets require this kind of adjustment. For most targets,
3949 this function is simply the identity function. */
3952 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
3954 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3956 /* Very few targets need any kind of breakpoint adjustment. */
3959 else if (bptype == bp_watchpoint
3960 || bptype == bp_hardware_watchpoint
3961 || bptype == bp_read_watchpoint
3962 || bptype == bp_access_watchpoint
3963 || bptype == bp_catch_fork
3964 || bptype == bp_catch_vfork
3965 || bptype == bp_catch_exec)
3967 /* Watchpoints and the various bp_catch_* eventpoints should not
3968 have their addresses modified. */
3973 CORE_ADDR adjusted_bpaddr;
3975 /* Some targets have architectural constraints on the placement
3976 of breakpoint instructions. Obtain the adjusted address. */
3977 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3980 /* An adjusted breakpoint address can significantly alter
3981 a user's expectations. Print a warning if an adjustment
3983 if (adjusted_bpaddr != bpaddr)
3984 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3986 return adjusted_bpaddr;
3990 /* Allocate a struct bp_location. */
3992 static struct bp_location *
3993 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
3995 struct bp_location *loc, *loc_p;
3997 loc = xmalloc (sizeof (struct bp_location));
3998 memset (loc, 0, sizeof (*loc));
4008 case bp_longjmp_resume:
4009 case bp_step_resume:
4010 case bp_through_sigtramp:
4011 case bp_watchpoint_scope:
4013 case bp_shlib_event:
4014 case bp_thread_event:
4015 case bp_overlay_event:
4017 case bp_catch_unload:
4018 loc->loc_type = bp_loc_software_breakpoint;
4020 case bp_hardware_breakpoint:
4021 loc->loc_type = bp_loc_hardware_breakpoint;
4023 case bp_hardware_watchpoint:
4024 case bp_read_watchpoint:
4025 case bp_access_watchpoint:
4026 loc->loc_type = bp_loc_hardware_watchpoint;
4030 case bp_catch_vfork:
4032 case bp_catch_catch:
4033 case bp_catch_throw:
4034 loc->loc_type = bp_loc_other;
4037 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
4040 /* Add this breakpoint to the end of the chain. */
4042 loc_p = bp_location_chain;
4044 bp_location_chain = loc;
4048 loc_p = loc_p->next;
4055 /* set_raw_breakpoint() is a low level routine for allocating and
4056 partially initializing a breakpoint of type BPTYPE. The newly
4057 created breakpoint's address, section, source file name, and line
4058 number are provided by SAL. The newly created and partially
4059 initialized breakpoint is added to the breakpoint chain and
4060 is also returned as the value of this function.
4062 It is expected that the caller will complete the initialization of
4063 the newly created breakpoint struct as well as output any status
4064 information regarding the creation of a new breakpoint. In
4065 particular, set_raw_breakpoint() does NOT set the breakpoint
4066 number! Care should be taken to not allow an error() to occur
4067 prior to completing the initialization of the breakpoint. If this
4068 should happen, a bogus breakpoint will be left on the chain. */
4071 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4073 struct breakpoint *b, *b1;
4075 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4076 memset (b, 0, sizeof (*b));
4077 b->loc = allocate_bp_location (b, bptype);
4078 b->loc->requested_address = sal.pc;
4079 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4081 if (sal.symtab == NULL)
4082 b->source_file = NULL;
4084 b->source_file = savestring (sal.symtab->filename,
4085 strlen (sal.symtab->filename));
4086 b->loc->section = sal.section;
4088 b->language = current_language->la_language;
4089 b->input_radix = input_radix;
4091 b->line_number = sal.line;
4092 b->enable_state = bp_enabled;
4095 b->ignore_count = 0;
4097 b->frame_id = null_frame_id;
4098 b->dll_pathname = NULL;
4099 b->triggered_dll_pathname = NULL;
4100 b->forked_inferior_pid = 0;
4101 b->exec_pathname = NULL;
4105 /* Add this breakpoint to the end of the chain
4106 so that a list of breakpoints will come out in order
4107 of increasing numbers. */
4109 b1 = breakpoint_chain;
4111 breakpoint_chain = b;
4119 check_duplicates (b);
4120 breakpoints_changed ();
4126 /* Note that the breakpoint object B describes a permanent breakpoint
4127 instruction, hard-wired into the inferior's code. */
4129 make_breakpoint_permanent (struct breakpoint *b)
4131 b->enable_state = bp_permanent;
4133 /* By definition, permanent breakpoints are already present in the code. */
4134 b->loc->inserted = 1;
4137 static struct breakpoint *
4138 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4140 static int internal_breakpoint_number = -1;
4141 struct symtab_and_line sal;
4142 struct breakpoint *b;
4144 init_sal (&sal); /* initialize to zeroes */
4147 sal.section = find_pc_overlay (sal.pc);
4149 b = set_raw_breakpoint (sal, type);
4150 b->number = internal_breakpoint_number--;
4151 b->disposition = disp_donttouch;
4158 create_longjmp_breakpoint (char *func_name)
4160 struct breakpoint *b;
4161 struct minimal_symbol *m;
4163 if (func_name == NULL)
4164 b = create_internal_breakpoint (0, bp_longjmp_resume);
4167 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4170 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4173 b->enable_state = bp_disabled;
4176 b->addr_string = xstrdup (func_name);
4179 /* Call this routine when stepping and nexting to enable a breakpoint
4180 if we do a longjmp(). When we hit that breakpoint, call
4181 set_longjmp_resume_breakpoint() to figure out where we are going. */
4184 enable_longjmp_breakpoint (void)
4186 struct breakpoint *b;
4189 if (b->type == bp_longjmp)
4191 b->enable_state = bp_enabled;
4192 check_duplicates (b);
4197 disable_longjmp_breakpoint (void)
4199 struct breakpoint *b;
4202 if (b->type == bp_longjmp
4203 || b->type == bp_longjmp_resume)
4205 b->enable_state = bp_disabled;
4206 check_duplicates (b);
4211 create_overlay_event_breakpoint (char *func_name)
4213 struct breakpoint *b;
4214 struct minimal_symbol *m;
4216 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4219 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4221 b->addr_string = xstrdup (func_name);
4223 if (overlay_debugging == ovly_auto)
4225 b->enable_state = bp_enabled;
4226 overlay_events_enabled = 1;
4230 b->enable_state = bp_disabled;
4231 overlay_events_enabled = 0;
4236 enable_overlay_breakpoints (void)
4238 struct breakpoint *b;
4241 if (b->type == bp_overlay_event)
4243 b->enable_state = bp_enabled;
4244 check_duplicates (b);
4245 overlay_events_enabled = 1;
4250 disable_overlay_breakpoints (void)
4252 struct breakpoint *b;
4255 if (b->type == bp_overlay_event)
4257 b->enable_state = bp_disabled;
4258 check_duplicates (b);
4259 overlay_events_enabled = 0;
4264 create_thread_event_breakpoint (CORE_ADDR address)
4266 struct breakpoint *b;
4268 b = create_internal_breakpoint (address, bp_thread_event);
4270 b->enable_state = bp_enabled;
4271 /* addr_string has to be used or breakpoint_re_set will delete me. */
4272 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4278 remove_thread_event_breakpoints (void)
4280 struct breakpoint *b, *temp;
4282 ALL_BREAKPOINTS_SAFE (b, temp)
4283 if (b->type == bp_thread_event)
4284 delete_breakpoint (b);
4287 struct captured_parse_breakpoint_args
4290 struct symtabs_and_lines *sals_p;
4291 char ***addr_string_p;
4295 struct lang_and_radix
4301 /* Cleanup helper routine to restore the current language and
4304 do_restore_lang_radix_cleanup (void *old)
4306 struct lang_and_radix *p = old;
4307 set_language (p->lang);
4308 input_radix = p->radix;
4311 /* Try and resolve a pending breakpoint. */
4313 resolve_pending_breakpoint (struct breakpoint *b)
4315 /* Try and reparse the breakpoint in case the shared library
4317 struct symtabs_and_lines sals;
4318 struct symtab_and_line pending_sal;
4319 char **cond_string = (char **) NULL;
4320 char *copy_arg = b->addr_string;
4325 struct ui_file *old_gdb_stderr;
4326 struct lang_and_radix old_lr;
4327 struct cleanup *old_chain;
4329 /* Set language, input-radix, then reissue breakpoint command.
4330 Ensure the language and input-radix are restored afterwards. */
4331 old_lr.lang = current_language->la_language;
4332 old_lr.radix = input_radix;
4333 old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr);
4335 set_language (b->language);
4336 input_radix = b->input_radix;
4337 rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b);
4339 if (rc == GDB_RC_OK)
4340 /* Pending breakpoint has been resolved. */
4341 printf_filtered ("Pending breakpoint \"%s\" resolved\n", b->addr_string);
4343 do_cleanups (old_chain);
4349 remove_solib_event_breakpoints (void)
4351 struct breakpoint *b, *temp;
4353 ALL_BREAKPOINTS_SAFE (b, temp)
4354 if (b->type == bp_shlib_event)
4355 delete_breakpoint (b);
4359 create_solib_event_breakpoint (CORE_ADDR address)
4361 struct breakpoint *b;
4363 b = create_internal_breakpoint (address, bp_shlib_event);
4367 /* Disable any breakpoints that are on code in shared libraries. Only
4368 apply to enabled breakpoints, disabled ones can just stay disabled. */
4371 disable_breakpoints_in_shlibs (int silent)
4373 struct breakpoint *b;
4374 int disabled_shlib_breaks = 0;
4376 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4379 #if defined (PC_SOLIB)
4380 if (((b->type == bp_breakpoint) ||
4381 (b->type == bp_hardware_breakpoint)) &&
4382 breakpoint_enabled (b) &&
4383 !b->loc->duplicate &&
4384 PC_SOLIB (b->loc->address))
4386 b->enable_state = bp_shlib_disabled;
4389 if (!disabled_shlib_breaks)
4391 target_terminal_ours_for_output ();
4392 warning ("Temporarily disabling shared library breakpoints:");
4394 disabled_shlib_breaks = 1;
4395 warning ("breakpoint #%d ", b->number);
4402 /* Try to reenable any breakpoints in shared libraries. */
4404 re_enable_breakpoints_in_shlibs (void)
4406 struct breakpoint *b, *tmp;
4408 ALL_BREAKPOINTS_SAFE (b, tmp)
4410 if (b->enable_state == bp_shlib_disabled)
4414 /* Do not reenable the breakpoint if the shared library
4415 is still not mapped in. */
4416 lib = PC_SOLIB (b->loc->address);
4417 if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
4418 b->enable_state = bp_enabled;
4420 else if (b->pending && (b->enable_state == bp_enabled))
4422 if (resolve_pending_breakpoint (b) == GDB_RC_OK)
4423 delete_breakpoint (b);
4431 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4432 char *cond_string, enum bptype bp_kind)
4434 struct breakpoint *b;
4435 struct symtabs_and_lines sals;
4436 struct cleanup *old_chain;
4437 struct cleanup *canonical_strings_chain = NULL;
4438 char *addr_start = hookname;
4439 char *addr_end = NULL;
4440 char **canonical = (char **) NULL;
4441 int thread = -1; /* All threads. */
4443 /* Set a breakpoint on the specified hook. */
4444 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical, NULL);
4445 addr_end = hookname;
4447 if (sals.nelts == 0)
4449 warning ("Unable to set a breakpoint on dynamic linker callback.");
4450 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4451 warning ("GDB will be unable to track shl_load/shl_unload calls");
4454 if (sals.nelts != 1)
4456 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4457 warning ("GDB will be unable to track shl_load/shl_unload calls");
4461 /* Make sure that all storage allocated in decode_line_1 gets freed
4462 in case the following errors out. */
4463 old_chain = make_cleanup (xfree, sals.sals);
4464 if (canonical != (char **) NULL)
4466 make_cleanup (xfree, canonical);
4467 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4468 if (canonical[0] != NULL)
4469 make_cleanup (xfree, canonical[0]);
4472 resolve_sal_pc (&sals.sals[0]);
4474 /* Remove the canonical strings from the cleanup, they are needed below. */
4475 if (canonical != (char **) NULL)
4476 discard_cleanups (canonical_strings_chain);
4478 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4479 set_breakpoint_count (breakpoint_count + 1);
4480 b->number = breakpoint_count;
4482 b->cond_string = (cond_string == NULL) ?
4483 NULL : savestring (cond_string, strlen (cond_string));
4486 if (canonical != (char **) NULL && canonical[0] != NULL)
4487 b->addr_string = canonical[0];
4488 else if (addr_start)
4489 b->addr_string = savestring (addr_start, addr_end - addr_start);
4491 b->enable_state = bp_enabled;
4492 b->disposition = tempflag ? disp_del : disp_donttouch;
4494 if (dll_pathname == NULL)
4495 b->dll_pathname = NULL;
4498 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4499 strcpy (b->dll_pathname, dll_pathname);
4503 do_cleanups (old_chain);
4507 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4508 char *dll_pathname, char *cond_string)
4510 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4511 cond_string, bp_catch_load);
4515 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4516 char *dll_pathname, char *cond_string)
4518 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4519 cond_string, bp_catch_unload);
4523 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4524 enum bptype bp_kind)
4526 struct symtab_and_line sal;
4527 struct breakpoint *b;
4528 int thread = -1; /* All threads. */
4535 b = set_raw_breakpoint (sal, bp_kind);
4536 set_breakpoint_count (breakpoint_count + 1);
4537 b->number = breakpoint_count;
4539 b->cond_string = (cond_string == NULL) ?
4540 NULL : savestring (cond_string, strlen (cond_string));
4542 b->addr_string = NULL;
4543 b->enable_state = bp_enabled;
4544 b->disposition = tempflag ? disp_del : disp_donttouch;
4545 b->forked_inferior_pid = 0;
4551 create_fork_event_catchpoint (int tempflag, char *cond_string)
4553 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4557 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4559 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4563 create_exec_event_catchpoint (int tempflag, char *cond_string)
4565 struct symtab_and_line sal;
4566 struct breakpoint *b;
4567 int thread = -1; /* All threads. */
4574 b = set_raw_breakpoint (sal, bp_catch_exec);
4575 set_breakpoint_count (breakpoint_count + 1);
4576 b->number = breakpoint_count;
4578 b->cond_string = (cond_string == NULL) ?
4579 NULL : savestring (cond_string, strlen (cond_string));
4581 b->addr_string = NULL;
4582 b->enable_state = bp_enabled;
4583 b->disposition = tempflag ? disp_del : disp_donttouch;
4589 hw_breakpoint_used_count (void)
4591 struct breakpoint *b;
4596 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4604 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4606 struct breakpoint *b;
4609 *other_type_used = 0;
4612 if (breakpoint_enabled (b))
4614 if (b->type == type)
4616 else if ((b->type == bp_hardware_watchpoint ||
4617 b->type == bp_read_watchpoint ||
4618 b->type == bp_access_watchpoint))
4619 *other_type_used = 1;
4625 /* Call this after hitting the longjmp() breakpoint. Use this to set
4626 a new breakpoint at the target of the jmp_buf.
4628 FIXME - This ought to be done by setting a temporary breakpoint
4629 that gets deleted automatically... */
4632 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4634 struct breakpoint *b;
4637 if (b->type == bp_longjmp_resume)
4639 b->loc->requested_address = pc;
4640 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4642 b->enable_state = bp_enabled;
4643 b->frame_id = frame_id;
4644 check_duplicates (b);
4650 disable_watchpoints_before_interactive_call_start (void)
4652 struct breakpoint *b;
4656 if (((b->type == bp_watchpoint)
4657 || (b->type == bp_hardware_watchpoint)
4658 || (b->type == bp_read_watchpoint)
4659 || (b->type == bp_access_watchpoint)
4660 || ep_is_exception_catchpoint (b))
4661 && breakpoint_enabled (b))
4663 b->enable_state = bp_call_disabled;
4664 check_duplicates (b);
4670 enable_watchpoints_after_interactive_call_stop (void)
4672 struct breakpoint *b;
4676 if (((b->type == bp_watchpoint)
4677 || (b->type == bp_hardware_watchpoint)
4678 || (b->type == bp_read_watchpoint)
4679 || (b->type == bp_access_watchpoint)
4680 || ep_is_exception_catchpoint (b))
4681 && (b->enable_state == bp_call_disabled))
4683 b->enable_state = bp_enabled;
4684 check_duplicates (b);
4690 /* Set a breakpoint that will evaporate an end of command
4691 at address specified by SAL.
4692 Restrict it to frame FRAME if FRAME is nonzero. */
4695 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4698 struct breakpoint *b;
4699 b = set_raw_breakpoint (sal, type);
4700 b->enable_state = bp_enabled;
4701 b->disposition = disp_donttouch;
4702 b->frame_id = frame_id;
4704 /* If we're debugging a multi-threaded program, then we
4705 want momentary breakpoints to be active in only a
4706 single thread of control. */
4707 if (in_thread_list (inferior_ptid))
4708 b->thread = pid_to_thread_id (inferior_ptid);
4714 /* Tell the user we have just set a breakpoint B. */
4717 mention (struct breakpoint *b)
4720 struct cleanup *old_chain, *ui_out_chain;
4721 struct ui_stream *stb;
4723 stb = ui_out_stream_new (uiout);
4724 old_chain = make_cleanup_ui_out_stream_delete (stb);
4726 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4727 watchpoint) other than breakpoint creation. It should be possible to
4728 clean this up and at the same time replace the random calls to
4729 breakpoint_changed with this hook, as has already been done for
4730 delete_breakpoint_hook and so on. */
4731 if (create_breakpoint_hook)
4732 create_breakpoint_hook (b);
4733 breakpoint_create_event (b->number);
4735 if (b->ops != NULL && b->ops->print_mention != NULL)
4736 b->ops->print_mention (b);
4741 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4744 ui_out_text (uiout, "Watchpoint ");
4745 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4746 ui_out_field_int (uiout, "number", b->number);
4747 ui_out_text (uiout, ": ");
4748 print_expression (b->exp, stb->stream);
4749 ui_out_field_stream (uiout, "exp", stb);
4750 do_cleanups (ui_out_chain);
4752 case bp_hardware_watchpoint:
4753 ui_out_text (uiout, "Hardware watchpoint ");
4754 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4755 ui_out_field_int (uiout, "number", b->number);
4756 ui_out_text (uiout, ": ");
4757 print_expression (b->exp, stb->stream);
4758 ui_out_field_stream (uiout, "exp", stb);
4759 do_cleanups (ui_out_chain);
4761 case bp_read_watchpoint:
4762 ui_out_text (uiout, "Hardware read watchpoint ");
4763 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4764 ui_out_field_int (uiout, "number", b->number);
4765 ui_out_text (uiout, ": ");
4766 print_expression (b->exp, stb->stream);
4767 ui_out_field_stream (uiout, "exp", stb);
4768 do_cleanups (ui_out_chain);
4770 case bp_access_watchpoint:
4771 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4772 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4773 ui_out_field_int (uiout, "number", b->number);
4774 ui_out_text (uiout, ": ");
4775 print_expression (b->exp, stb->stream);
4776 ui_out_field_stream (uiout, "exp", stb);
4777 do_cleanups (ui_out_chain);
4780 if (ui_out_is_mi_like_p (uiout))
4785 printf_filtered ("Breakpoint %d", b->number);
4788 case bp_hardware_breakpoint:
4789 if (ui_out_is_mi_like_p (uiout))
4794 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4798 case bp_catch_unload:
4799 printf_filtered ("Catchpoint %d (%s %s)",
4801 (b->type == bp_catch_load) ? "load" : "unload",
4802 (b->dll_pathname != NULL) ?
4803 b->dll_pathname : "<any library>");
4806 case bp_catch_vfork:
4807 printf_filtered ("Catchpoint %d (%s)",
4809 (b->type == bp_catch_fork) ? "fork" : "vfork");
4812 printf_filtered ("Catchpoint %d (exec)",
4815 case bp_catch_catch:
4816 case bp_catch_throw:
4817 printf_filtered ("Catchpoint %d (%s)",
4819 (b->type == bp_catch_catch) ? "catch" : "throw");
4825 case bp_longjmp_resume:
4826 case bp_step_resume:
4827 case bp_through_sigtramp:
4829 case bp_watchpoint_scope:
4830 case bp_shlib_event:
4831 case bp_thread_event:
4832 case bp_overlay_event:
4840 printf_filtered (" (%s) pending.", b->addr_string);
4844 if (addressprint || b->source_file == NULL)
4846 printf_filtered (" at ");
4847 print_address_numeric (b->loc->address, 1, gdb_stdout);
4850 printf_filtered (": file %s, line %d.",
4851 b->source_file, b->line_number);
4854 do_cleanups (old_chain);
4855 if (ui_out_is_mi_like_p (uiout))
4857 printf_filtered ("\n");
4861 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4862 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4863 COND[i] and COND_STRING[i] values.
4865 The parameter PENDING_BP points to a pending breakpoint that is
4866 the basis of the breakpoints currently being created. The pending
4867 breakpoint may contain a separate condition string or commands
4868 that were added after the initial pending breakpoint was created.
4870 NOTE: If the function succeeds, the caller is expected to cleanup
4871 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4872 array contents). If the function fails (error() is called), the
4873 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4874 COND and SALS arrays and each of those arrays contents. */
4877 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4878 struct expression **cond, char **cond_string,
4879 enum bptype type, enum bpdisp disposition,
4880 int thread, int ignore_count, int from_tty,
4881 struct breakpoint *pending_bp)
4883 if (type == bp_hardware_breakpoint)
4885 int i = hw_breakpoint_used_count ();
4886 int target_resources_ok =
4887 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4889 if (target_resources_ok == 0)
4890 error ("No hardware breakpoint support in the target.");
4891 else if (target_resources_ok < 0)
4892 error ("Hardware breakpoints used exceeds limit.");
4895 /* Now set all the breakpoints. */
4898 for (i = 0; i < sals.nelts; i++)
4900 struct breakpoint *b;
4901 struct symtab_and_line sal = sals.sals[i];
4904 describe_other_breakpoints (sal.pc, sal.section);
4906 b = set_raw_breakpoint (sal, type);
4907 set_breakpoint_count (breakpoint_count + 1);
4908 b->number = breakpoint_count;
4912 b->addr_string = addr_string[i];
4914 /* addr_string has to be used or breakpoint_re_set will delete
4916 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4917 b->cond_string = cond_string[i];
4918 b->ignore_count = ignore_count;
4919 b->enable_state = bp_enabled;
4920 b->disposition = disposition;
4921 /* If resolving a pending breakpoint, a check must be made to see if
4922 the user has specified a new condition or commands for the
4923 breakpoint. A new condition will override any condition that was
4924 initially specified with the initial breakpoint command. */
4928 if (pending_bp->cond_string)
4930 arg = pending_bp->cond_string;
4931 b->cond_string = savestring (arg, strlen (arg));
4932 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
4934 error ("Junk at end of pending breakpoint condition expression");
4936 /* If there are commands associated with the breakpoint, they should
4938 if (pending_bp->commands)
4939 b->commands = copy_command_lines (pending_bp->commands);
4946 /* Parse ARG which is assumed to be a SAL specification possibly
4947 followed by conditionals. On return, SALS contains an array of SAL
4948 addresses found. ADDR_STRING contains a vector of (canonical)
4949 address strings. ARG points to the end of the SAL. */
4952 parse_breakpoint_sals (char **address,
4953 struct symtabs_and_lines *sals,
4954 char ***addr_string,
4957 char *addr_start = *address;
4958 *addr_string = NULL;
4959 /* If no arg given, or if first arg is 'if ', use the default
4961 if ((*address) == NULL
4962 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4964 if (default_breakpoint_valid)
4966 struct symtab_and_line sal;
4967 init_sal (&sal); /* initialize to zeroes */
4968 sals->sals = (struct symtab_and_line *)
4969 xmalloc (sizeof (struct symtab_and_line));
4970 sal.pc = default_breakpoint_address;
4971 sal.line = default_breakpoint_line;
4972 sal.symtab = default_breakpoint_symtab;
4973 sal.section = find_pc_overlay (sal.pc);
4974 sals->sals[0] = sal;
4978 error ("No default breakpoint address now.");
4982 /* Force almost all breakpoints to be in terms of the
4983 current_source_symtab (which is decode_line_1's default). This
4984 should produce the results we want almost all of the time while
4985 leaving default_breakpoint_* alone.
4986 ObjC: However, don't match an Objective-C method name which
4987 may have a '+' or '-' succeeded by a '[' */
4989 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4991 if (default_breakpoint_valid
4993 || ((strchr ("+-", (*address)[0]) != NULL)
4994 && ((*address)[1] != '['))))
4995 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4996 default_breakpoint_line, addr_string,
4999 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5000 addr_string, not_found_ptr);
5002 /* For any SAL that didn't have a canonical string, fill one in. */
5003 if (sals->nelts > 0 && *addr_string == NULL)
5004 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5005 if (addr_start != (*address))
5008 for (i = 0; i < sals->nelts; i++)
5010 /* Add the string if not present. */
5011 if ((*addr_string)[i] == NULL)
5012 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5018 /* Convert each SAL into a real PC. Verify that the PC can be
5019 inserted as a breakpoint. If it can't throw an error. */
5022 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5026 for (i = 0; i < sals->nelts; i++)
5028 resolve_sal_pc (&sals->sals[i]);
5030 /* It's possible for the PC to be nonzero, but still an illegal
5031 value on some targets.
5033 For example, on HP-UX if you start gdb, and before running the
5034 inferior you try to set a breakpoint on a shared library function
5035 "foo" where the inferior doesn't call "foo" directly but does
5036 pass its address to another function call, then we do find a
5037 minimal symbol for the "foo", but it's address is invalid.
5038 (Appears to be an index into a table that the loader sets up
5039 when the inferior is run.)
5041 Give the target a chance to bless sals.sals[i].pc before we
5042 try to make a breakpoint for it. */
5043 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5045 if (address == NULL)
5046 error ("Cannot break without a running program.");
5048 error ("Cannot break on %s without a running program.",
5055 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5057 struct captured_parse_breakpoint_args *args = data;
5059 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5060 args->not_found_ptr);
5065 /* Set a breakpoint according to ARG (function, linenum or *address)
5066 flag: first bit : 0 non-temporary, 1 temporary.
5067 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5069 PENDING_BP is non-NULL when this function is being called to resolve
5070 a pending breakpoint. */
5073 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5075 int tempflag, hardwareflag;
5076 struct symtabs_and_lines sals;
5077 struct expression **cond = 0;
5078 struct symtab_and_line pending_sal;
5079 char **cond_string = (char **) NULL;
5082 char *addr_start = arg;
5084 struct cleanup *old_chain;
5085 struct cleanup *breakpoint_chain = NULL;
5086 struct captured_parse_breakpoint_args parse_args;
5090 int ignore_count = 0;
5093 hardwareflag = flag & BP_HARDWAREFLAG;
5094 tempflag = flag & BP_TEMPFLAG;
5100 parse_args.arg_p = &arg;
5101 parse_args.sals_p = &sals;
5102 parse_args.addr_string_p = &addr_string;
5103 parse_args.not_found_ptr = ¬_found;
5105 rc = catch_exceptions_with_msg (uiout, do_captured_parse_breakpoint,
5106 &parse_args, NULL, &err_msg,
5109 /* If caller is interested in rc value from parse, set value. */
5111 if (rc != GDB_RC_OK)
5113 /* Check for file or function not found. */
5116 /* If called to resolve pending breakpoint, just return error code. */
5120 error_output_message (NULL, err_msg);
5123 /* If pending breakpoint support is turned off, throw error. */
5125 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5126 throw_exception (RETURN_ERROR);
5128 /* If pending breakpoint support is auto query and the user selects
5129 no, then simply return the error code. */
5130 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5131 !nquery ("Make breakpoint pending on future shared library load? "))
5134 /* At this point, either the user was queried about setting a
5135 pending breakpoint and selected yes, or pending breakpoint
5136 behavior is on and thus a pending breakpoint is defaulted
5137 on behalf of the user. */
5138 copy_arg = xstrdup (addr_start);
5139 addr_string = ©_arg;
5141 sals.sals = &pending_sal;
5148 else if (!sals.nelts)
5151 /* Create a chain of things that always need to be cleaned up. */
5152 old_chain = make_cleanup (null_cleanup, 0);
5156 /* Make sure that all storage allocated to SALS gets freed. */
5157 make_cleanup (xfree, sals.sals);
5159 /* Cleanup the addr_string array but not its contents. */
5160 make_cleanup (xfree, addr_string);
5163 /* Allocate space for all the cond expressions. */
5164 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5165 make_cleanup (xfree, cond);
5167 /* Allocate space for all the cond strings. */
5168 cond_string = xcalloc (sals.nelts, sizeof (char **));
5169 make_cleanup (xfree, cond_string);
5171 /* ----------------------------- SNIP -----------------------------
5172 Anything added to the cleanup chain beyond this point is assumed
5173 to be part of a breakpoint. If the breakpoint create succeeds
5174 then the memory is not reclaimed. */
5175 breakpoint_chain = make_cleanup (null_cleanup, 0);
5177 /* Mark the contents of the addr_string for cleanup. These go on
5178 the breakpoint_chain and only occure if the breakpoint create
5180 for (i = 0; i < sals.nelts; i++)
5182 if (addr_string[i] != NULL)
5183 make_cleanup (xfree, addr_string[i]);
5186 /* Resolve all line numbers to PC's and verify that the addresses
5187 are ok for the target. */
5189 breakpoint_sals_to_pc (&sals, addr_start);
5191 /* Verify that condition can be parsed, before setting any
5192 breakpoints. Allocate a separate condition expression for each
5194 thread = -1; /* No specific thread yet */
5197 for (i = 0; i < sals.nelts; i++)
5204 char *cond_start = NULL;
5205 char *cond_end = NULL;
5206 while (*tok == ' ' || *tok == '\t')
5211 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5214 toklen = end_tok - tok;
5216 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5218 tok = cond_start = end_tok + 1;
5219 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc),
5221 make_cleanup (xfree, cond[i]);
5223 cond_string[i] = savestring (cond_start,
5224 cond_end - cond_start);
5225 make_cleanup (xfree, cond_string[i]);
5227 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5233 thread = strtol (tok, &tok, 0);
5235 error ("Junk after thread keyword.");
5236 if (!valid_thread_id (thread))
5237 error ("Unknown thread %d\n", thread);
5240 error ("Junk at end of arguments.");
5243 create_breakpoints (sals, addr_string, cond, cond_string,
5244 hardwareflag ? bp_hardware_breakpoint
5246 tempflag ? disp_del : disp_donttouch,
5247 thread, ignore_count, from_tty,
5252 struct symtab_and_line sal;
5253 struct breakpoint *b;
5258 make_cleanup (xfree, copy_arg);
5260 b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint
5262 set_breakpoint_count (breakpoint_count + 1);
5263 b->number = breakpoint_count;
5266 b->addr_string = *addr_string;
5267 b->cond_string = *cond_string;
5268 b->ignore_count = ignore_count;
5270 b->disposition = tempflag ? disp_del : disp_donttouch;
5271 b->from_tty = from_tty;
5278 warning ("Multiple breakpoints were set.");
5279 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5281 /* That's it. Discard the cleanups for data inserted into the
5283 discard_cleanups (breakpoint_chain);
5284 /* But cleanup everything else. */
5285 do_cleanups (old_chain);
5290 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5291 linenum or *address) with COND and IGNORE_COUNT. */
5293 struct captured_breakpoint_args
5304 do_captured_breakpoint (void *data)
5306 struct captured_breakpoint_args *args = data;
5307 struct symtabs_and_lines sals;
5308 struct expression **cond;
5309 struct cleanup *old_chain;
5310 struct cleanup *breakpoint_chain = NULL;
5317 /* Parse the source and lines spec. Delay check that the expression
5318 didn't contain trailing garbage until after cleanups are in
5322 address_end = args->address;
5324 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5329 /* Create a chain of things at always need to be cleaned up. */
5330 old_chain = make_cleanup (null_cleanup, 0);
5332 /* Always have a addr_string array, even if it is empty. */
5333 make_cleanup (xfree, addr_string);
5335 /* Make sure that all storage allocated to SALS gets freed. */
5336 make_cleanup (xfree, sals.sals);
5338 /* Allocate space for all the cond expressions. */
5339 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5340 make_cleanup (xfree, cond);
5342 /* Allocate space for all the cond strings. */
5343 cond_string = xcalloc (sals.nelts, sizeof (char **));
5344 make_cleanup (xfree, cond_string);
5346 /* ----------------------------- SNIP -----------------------------
5347 Anything added to the cleanup chain beyond this point is assumed
5348 to be part of a breakpoint. If the breakpoint create goes
5349 through then that memory is not cleaned up. */
5350 breakpoint_chain = make_cleanup (null_cleanup, 0);
5352 /* Mark the contents of the addr_string for cleanup. These go on
5353 the breakpoint_chain and only occure if the breakpoint create
5355 for (i = 0; i < sals.nelts; i++)
5357 if (addr_string[i] != NULL)
5358 make_cleanup (xfree, addr_string[i]);
5361 /* Wait until now before checking for garbage at the end of the
5362 address. That way cleanups can take care of freeing any
5364 if (*address_end != '\0')
5365 error ("Garbage %s following breakpoint address", address_end);
5367 /* Resolve all line numbers to PC's. */
5368 breakpoint_sals_to_pc (&sals, args->address);
5370 /* Verify that conditions can be parsed, before setting any
5372 for (i = 0; i < sals.nelts; i++)
5374 if (args->condition != NULL)
5376 char *tok = args->condition;
5377 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5379 error ("Garbage %s follows condition", tok);
5380 make_cleanup (xfree, cond[i]);
5381 cond_string[i] = xstrdup (args->condition);
5385 create_breakpoints (sals, addr_string, cond, cond_string,
5386 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5387 args->tempflag ? disp_del : disp_donttouch,
5388 args->thread, args->ignore_count, 0/*from-tty*/,
5389 NULL/*pending_bp*/);
5391 /* That's it. Discard the cleanups for data inserted into the
5393 discard_cleanups (breakpoint_chain);
5394 /* But cleanup everything else. */
5395 do_cleanups (old_chain);
5400 gdb_breakpoint (char *address, char *condition,
5401 int hardwareflag, int tempflag,
5402 int thread, int ignore_count)
5404 struct captured_breakpoint_args args;
5405 args.address = address;
5406 args.condition = condition;
5407 args.hardwareflag = hardwareflag;
5408 args.tempflag = tempflag;
5409 args.thread = thread;
5410 args.ignore_count = ignore_count;
5411 return catch_errors (do_captured_breakpoint, &args,
5412 NULL, RETURN_MASK_ALL);
5417 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
5419 struct frame_info *frame;
5420 CORE_ADDR low, high, selected_pc = 0;
5421 char *extra_args = NULL;
5423 int extra_args_len = 0, if_arg = 0;
5426 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5429 if (default_breakpoint_valid)
5431 if (deprecated_selected_frame)
5433 selected_pc = get_frame_pc (deprecated_selected_frame);
5438 error ("No selected frame.");
5441 error ("No default breakpoint address now.");
5445 extra_args = strchr (arg, ' ');
5449 extra_args_len = strlen (extra_args);
5450 level_arg = (char *) xmalloc (extra_args - arg);
5451 strncpy (level_arg, arg, extra_args - arg - 1);
5452 level_arg[extra_args - arg - 1] = '\0';
5456 level_arg = (char *) xmalloc (strlen (arg) + 1);
5457 strcpy (level_arg, arg);
5460 frame = parse_frame_specification (level_arg);
5462 selected_pc = get_frame_pc (frame);
5469 extra_args_len = strlen (arg);
5474 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5478 addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args);
5480 addr_string = xstrprintf ("*0x%s", paddr_nz (high));
5481 break_command_1 (addr_string, flag, from_tty, NULL);
5482 xfree (addr_string);
5485 error ("No function contains the specified address");
5488 error ("Unable to set breakpoint at procedure exit");
5493 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5495 char *addr_string, *break_string, *beg_addr_string;
5496 CORE_ADDR low, high;
5497 struct symtabs_and_lines sals;
5498 struct symtab_and_line sal;
5499 struct cleanup *old_chain;
5500 char *extra_args = NULL;
5501 int extra_args_len = 0;
5505 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5507 if (default_breakpoint_valid)
5509 if (deprecated_selected_frame)
5511 addr_string = xstrprintf ("*0x%s",
5512 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5517 error ("No selected frame.");
5520 error ("No default breakpoint address now.");
5524 addr_string = (char *) xmalloc (strlen (arg) + 1);
5525 strcpy (addr_string, arg);
5531 extra_args_len = strlen (arg);
5535 /* get the stuff after the function name or address */
5536 extra_args = strchr (arg, ' ');
5540 extra_args_len = strlen (extra_args);
5547 beg_addr_string = addr_string;
5548 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5549 (char ***) NULL, NULL);
5551 xfree (beg_addr_string);
5552 old_chain = make_cleanup (xfree, sals.sals);
5553 for (i = 0; (i < sals.nelts); i++)
5556 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5560 break_string = xstrprintf ("*0x%s %s", paddr_nz (high),
5563 break_string = xstrprintf ("*0x%s", paddr_nz (high));
5564 break_command_1 (break_string, flag, from_tty, NULL);
5565 xfree (break_string);
5568 error ("No function contains the specified address");
5572 warning ("Multiple breakpoints were set.\n");
5573 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5575 do_cleanups (old_chain);
5579 /* Helper function for break_command_1 and disassemble_command. */
5582 resolve_sal_pc (struct symtab_and_line *sal)
5586 if (sal->pc == 0 && sal->symtab != NULL)
5588 if (!find_line_pc (sal->symtab, sal->line, &pc))
5589 error ("No line %d in file \"%s\".",
5590 sal->line, sal->symtab->filename);
5594 if (sal->section == 0 && sal->symtab != NULL)
5596 struct blockvector *bv;
5601 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5604 b = BLOCKVECTOR_BLOCK (bv, index);
5605 sym = block_function (b);
5608 fixup_symbol_section (sym, sal->symtab->objfile);
5609 sal->section = SYMBOL_BFD_SECTION (sym);
5613 /* It really is worthwhile to have the section, so we'll just
5614 have to look harder. This case can be executed if we have
5615 line numbers but no functions (as can happen in assembly
5618 struct minimal_symbol *msym;
5620 msym = lookup_minimal_symbol_by_pc (sal->pc);
5622 sal->section = SYMBOL_BFD_SECTION (msym);
5629 break_command (char *arg, int from_tty)
5631 break_command_1 (arg, 0, from_tty, NULL);
5635 break_at_finish_command (char *arg, int from_tty)
5637 break_at_finish_command_1 (arg, 0, from_tty);
5641 break_at_finish_at_depth_command (char *arg, int from_tty)
5643 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5647 tbreak_command (char *arg, int from_tty)
5649 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5653 tbreak_at_finish_command (char *arg, int from_tty)
5655 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5659 hbreak_command (char *arg, int from_tty)
5661 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5665 thbreak_command (char *arg, int from_tty)
5667 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5671 stop_command (char *arg, int from_tty)
5673 printf_filtered ("Specify the type of breakpoint to set.\n\
5674 Usage: stop in <function | address>\n\
5679 stopin_command (char *arg, int from_tty)
5683 if (arg == (char *) NULL)
5685 else if (*arg != '*')
5690 /* look for a ':'. If this is a line number specification, then
5691 say it is bad, otherwise, it should be an address or
5692 function/method name */
5693 while (*argptr && !hasColon)
5695 hasColon = (*argptr == ':');
5700 badInput = (*argptr != ':'); /* Not a class::method */
5702 badInput = isdigit (*arg); /* a simple line number */
5706 printf_filtered ("Usage: stop in <function | address>\n");
5708 break_command_1 (arg, 0, from_tty, NULL);
5712 stopat_command (char *arg, int from_tty)
5716 if (arg == (char *) NULL || *arg == '*') /* no line number */
5723 /* look for a ':'. If there is a '::' then get out, otherwise
5724 it is probably a line number. */
5725 while (*argptr && !hasColon)
5727 hasColon = (*argptr == ':');
5732 badInput = (*argptr == ':'); /* we have class::method */
5734 badInput = !isdigit (*arg); /* not a line number */
5738 printf_filtered ("Usage: stop at <line>\n");
5740 break_command_1 (arg, 0, from_tty, NULL);
5743 /* accessflag: hw_write: watch write,
5744 hw_read: watch read,
5745 hw_access: watch access (read or write) */
5747 watch_command_1 (char *arg, int accessflag, int from_tty)
5749 struct breakpoint *b;
5750 struct symtab_and_line sal;
5751 struct expression *exp;
5752 struct block *exp_valid_block;
5753 struct value *val, *mark;
5754 struct frame_info *frame;
5755 struct frame_info *prev_frame = NULL;
5756 char *exp_start = NULL;
5757 char *exp_end = NULL;
5758 char *tok, *end_tok;
5760 char *cond_start = NULL;
5761 char *cond_end = NULL;
5762 struct expression *cond = NULL;
5763 int i, other_type_used, target_resources_ok = 0;
5764 enum bptype bp_type;
5767 init_sal (&sal); /* initialize to zeroes */
5769 /* Parse arguments. */
5770 innermost_block = NULL;
5772 exp = parse_exp_1 (&arg, 0, 0);
5774 exp_valid_block = innermost_block;
5775 mark = value_mark ();
5776 val = evaluate_expression (exp);
5777 release_value (val);
5778 if (VALUE_LAZY (val))
5779 value_fetch_lazy (val);
5782 while (*tok == ' ' || *tok == '\t')
5786 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5789 toklen = end_tok - tok;
5790 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5792 tok = cond_start = end_tok + 1;
5793 cond = parse_exp_1 (&tok, 0, 0);
5797 error ("Junk at end of command.");
5799 if (accessflag == hw_read)
5800 bp_type = bp_read_watchpoint;
5801 else if (accessflag == hw_access)
5802 bp_type = bp_access_watchpoint;
5804 bp_type = bp_hardware_watchpoint;
5806 mem_cnt = can_use_hardware_watchpoint (val);
5807 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5808 error ("Expression cannot be implemented with read/access watchpoint.");
5811 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5812 target_resources_ok =
5813 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5815 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5816 error ("Target does not support this type of hardware watchpoint.");
5818 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5819 error ("Target can only support one kind of HW watchpoint at a time.");
5822 #if defined(HPUXHPPA)
5823 /* On HP-UX if you set a h/w
5824 watchpoint before the "run" command, the inferior dies with a e.g.,
5825 SIGILL once you start it. I initially believed this was due to a
5826 bad interaction between page protection traps and the initial
5827 startup sequence by the dynamic linker.
5829 However, I tried avoiding that by having HP-UX's implementation of
5830 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5831 yet, which forced slow watches before a "run" or "attach", and it
5832 still fails somewhere in the startup code.
5834 Until I figure out what's happening, I'm disallowing watches altogether
5835 before the "run" or "attach" command. We'll tell the user they must
5836 set watches after getting the program started. */
5837 if (!target_has_execution)
5839 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5842 #endif /* HPUXHPPA */
5844 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5845 watchpoint could not be set. */
5846 if (!mem_cnt || target_resources_ok <= 0)
5847 bp_type = bp_watchpoint;
5849 /* Now set up the breakpoint. */
5850 b = set_raw_breakpoint (sal, bp_type);
5851 set_breakpoint_count (breakpoint_count + 1);
5852 b->number = breakpoint_count;
5853 b->disposition = disp_donttouch;
5855 b->exp_valid_block = exp_valid_block;
5856 b->exp_string = savestring (exp_start, exp_end - exp_start);
5860 b->cond_string = savestring (cond_start, cond_end - cond_start);
5864 frame = block_innermost_frame (exp_valid_block);
5867 prev_frame = get_prev_frame (frame);
5868 b->watchpoint_frame = get_frame_id (frame);
5872 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5875 /* If the expression is "local", then set up a "watchpoint scope"
5876 breakpoint at the point where we've left the scope of the watchpoint
5878 if (innermost_block)
5882 struct breakpoint *scope_breakpoint;
5883 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5884 bp_watchpoint_scope);
5886 scope_breakpoint->enable_state = bp_enabled;
5888 /* Automatically delete the breakpoint when it hits. */
5889 scope_breakpoint->disposition = disp_del;
5891 /* Only break in the proper frame (help with recursion). */
5892 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5894 /* Set the address at which we will stop. */
5895 scope_breakpoint->loc->requested_address
5896 = get_frame_pc (prev_frame);
5897 scope_breakpoint->loc->address
5898 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5899 scope_breakpoint->type);
5901 /* The scope breakpoint is related to the watchpoint. We
5902 will need to act on them together. */
5903 b->related_breakpoint = scope_breakpoint;
5906 value_free_to_mark (mark);
5910 /* Return count of locations need to be watched and can be handled
5911 in hardware. If the watchpoint can not be handled
5912 in hardware return zero. */
5914 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5915 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5916 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5920 can_use_hardware_watchpoint (struct value *v)
5922 int found_memory_cnt = 0;
5923 struct value *head = v;
5925 /* Did the user specifically forbid us to use hardware watchpoints? */
5926 if (!can_use_hw_watchpoints)
5929 /* Make sure that the value of the expression depends only upon
5930 memory contents, and values computed from them within GDB. If we
5931 find any register references or function calls, we can't use a
5932 hardware watchpoint.
5934 The idea here is that evaluating an expression generates a series
5935 of values, one holding the value of every subexpression. (The
5936 expression a*b+c has five subexpressions: a, b, a*b, c, and
5937 a*b+c.) GDB's values hold almost enough information to establish
5938 the criteria given above --- they identify memory lvalues,
5939 register lvalues, computed values, etcetera. So we can evaluate
5940 the expression, and then scan the chain of values that leaves
5941 behind to decide whether we can detect any possible change to the
5942 expression's final value using only hardware watchpoints.
5944 However, I don't think that the values returned by inferior
5945 function calls are special in any way. So this function may not
5946 notice that an expression involving an inferior function call
5947 can't be watched with hardware watchpoints. FIXME. */
5948 for (; v; v = v->next)
5950 if (VALUE_LVAL (v) == lval_memory)
5953 /* A lazy memory lvalue is one that GDB never needed to fetch;
5954 we either just used its address (e.g., `a' in `a.b') or
5955 we never needed it at all (e.g., `a' in `a,b'). */
5959 /* Ahh, memory we actually used! Check if we can cover
5960 it with hardware watchpoints. */
5961 struct type *vtype = check_typedef (VALUE_TYPE (v));
5963 /* We only watch structs and arrays if user asked for it
5964 explicitly, never if they just happen to appear in a
5965 middle of some value chain. */
5967 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5968 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5970 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5971 int len = TYPE_LENGTH (VALUE_TYPE (v));
5973 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5980 else if (v->lval != not_lval && v->modifiable == 0)
5981 return 0; /* ??? What does this represent? */
5982 else if (v->lval == lval_register)
5983 return 0; /* cannot watch a register with a HW watchpoint */
5986 /* The expression itself looks suitable for using a hardware
5987 watchpoint, but give the target machine a chance to reject it. */
5988 return found_memory_cnt;
5992 watch_command_wrapper (char *arg, int from_tty)
5994 watch_command (arg, from_tty);
5998 watch_command (char *arg, int from_tty)
6000 watch_command_1 (arg, hw_write, from_tty);
6004 rwatch_command_wrapper (char *arg, int from_tty)
6006 rwatch_command (arg, from_tty);
6010 rwatch_command (char *arg, int from_tty)
6012 watch_command_1 (arg, hw_read, from_tty);
6016 awatch_command_wrapper (char *arg, int from_tty)
6018 awatch_command (arg, from_tty);
6022 awatch_command (char *arg, int from_tty)
6024 watch_command_1 (arg, hw_access, from_tty);
6028 /* Helper routines for the until_command routine in infcmd.c. Here
6029 because it uses the mechanisms of breakpoints. */
6031 /* This function is called by fetch_inferior_event via the
6032 cmd_continuation pointer, to complete the until command. It takes
6033 care of cleaning up the temporary breakpoints set up by the until
6036 until_break_command_continuation (struct continuation_arg *arg)
6038 struct cleanup *cleanups;
6040 cleanups = (struct cleanup *) arg->data.pointer;
6041 do_exec_cleanups (cleanups);
6045 until_break_command (char *arg, int from_tty, int anywhere)
6047 struct symtabs_and_lines sals;
6048 struct symtab_and_line sal;
6049 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
6050 struct breakpoint *breakpoint;
6051 struct cleanup *old_chain;
6052 struct continuation_arg *arg1;
6055 clear_proceed_status ();
6057 /* Set a breakpoint where the user wants it and at return from
6060 if (default_breakpoint_valid)
6061 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6062 default_breakpoint_line, (char ***) NULL, NULL);
6064 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6065 0, (char ***) NULL, NULL);
6067 if (sals.nelts != 1)
6068 error ("Couldn't get information on specified line.");
6071 xfree (sals.sals); /* malloc'd, so freed */
6074 error ("Junk at end of arguments.");
6076 resolve_sal_pc (&sal);
6079 /* If the user told us to continue until a specified location,
6080 we don't specify a frame at which we need to stop. */
6081 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6083 /* Otherwise, specify the current frame, because we want to stop only
6084 at the very same frame. */
6085 breakpoint = set_momentary_breakpoint (sal,
6086 get_frame_id (deprecated_selected_frame),
6089 if (!event_loop_p || !target_can_async_p ())
6090 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6092 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6094 /* If we are running asynchronously, and the target supports async
6095 execution, we are not waiting for the target to stop, in the call
6096 tp proceed, below. This means that we cannot delete the
6097 brekpoints until the target has actually stopped. The only place
6098 where we get a chance to do that is in fetch_inferior_event, so
6099 we must set things up for that. */
6101 if (event_loop_p && target_can_async_p ())
6103 /* In this case the arg for the continuation is just the point
6104 in the exec_cleanups chain from where to start doing
6105 cleanups, because all the continuation does is the cleanups in
6106 the exec_cleanup_chain. */
6108 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6110 arg1->data.pointer = old_chain;
6112 add_continuation (until_break_command_continuation, arg1);
6115 /* Keep within the current frame, or in frames called by the current
6119 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6120 sal.pc = get_frame_pc (prev_frame);
6121 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6123 if (!event_loop_p || !target_can_async_p ())
6124 make_cleanup_delete_breakpoint (breakpoint);
6126 make_exec_cleanup_delete_breakpoint (breakpoint);
6129 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6130 /* Do the cleanups now, anly if we are not running asynchronously,
6131 of if we are, but the target is still synchronous. */
6132 if (!event_loop_p || !target_can_async_p ())
6133 do_cleanups (old_chain);
6137 ep_skip_leading_whitespace (char **s)
6139 if ((s == NULL) || (*s == NULL))
6141 while (isspace (**s))
6145 /* This function examines a string, and attempts to find a token
6146 that might be an event name in the leading characters. If a
6147 possible match is found, a pointer to the last character of
6148 the token is returned. Else, NULL is returned. */
6151 ep_find_event_name_end (char *arg)
6154 char *event_name_end = NULL;
6156 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6160 /* We break out of the loop when we find a token delimiter.
6161 Basically, we're looking for alphanumerics and underscores;
6162 anything else delimites the token. */
6165 if (!isalnum (*s) && (*s != '_'))
6171 return event_name_end;
6175 /* This function attempts to parse an optional "if <cond>" clause
6176 from the arg string. If one is not found, it returns NULL.
6178 Else, it returns a pointer to the condition string. (It does not
6179 attempt to evaluate the string against a particular block.) And,
6180 it updates arg to point to the first character following the parsed
6181 if clause in the arg string. */
6184 ep_parse_optional_if_clause (char **arg)
6188 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6191 /* Skip the "if" keyword. */
6194 /* Skip any extra leading whitespace, and record the start of the
6195 condition string. */
6196 ep_skip_leading_whitespace (arg);
6199 /* Assume that the condition occupies the remainder of the arg string. */
6200 (*arg) += strlen (cond_string);
6205 /* This function attempts to parse an optional filename from the arg
6206 string. If one is not found, it returns NULL.
6208 Else, it returns a pointer to the parsed filename. (This function
6209 makes no attempt to verify that a file of that name exists, or is
6210 accessible.) And, it updates arg to point to the first character
6211 following the parsed filename in the arg string.
6213 Note that clients needing to preserve the returned filename for
6214 future access should copy it to their own buffers. */
6216 ep_parse_optional_filename (char **arg)
6218 static char filename[1024];
6223 if ((*arg_p == '\0') || isspace (*arg_p))
6241 /* Commands to deal with catching events, such as signals, exceptions,
6242 process start/exit, etc. */
6246 catch_fork, catch_vfork
6251 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6254 char *cond_string = NULL;
6256 ep_skip_leading_whitespace (&arg);
6258 /* The allowed syntax is:
6260 catch [v]fork if <cond>
6262 First, check if there's an if clause. */
6263 cond_string = ep_parse_optional_if_clause (&arg);
6265 if ((*arg != '\0') && !isspace (*arg))
6266 error ("Junk at end of arguments.");
6268 /* If this target supports it, create a fork or vfork catchpoint
6269 and enable reporting of such events. */
6273 create_fork_event_catchpoint (tempflag, cond_string);
6276 create_vfork_event_catchpoint (tempflag, cond_string);
6279 error ("unsupported or unknown fork kind; cannot catch it");
6285 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6287 char *cond_string = NULL;
6289 ep_skip_leading_whitespace (&arg);
6291 /* The allowed syntax is:
6293 catch exec if <cond>
6295 First, check if there's an if clause. */
6296 cond_string = ep_parse_optional_if_clause (&arg);
6298 if ((*arg != '\0') && !isspace (*arg))
6299 error ("Junk at end of arguments.");
6301 /* If this target supports it, create an exec catchpoint
6302 and enable reporting of such events. */
6303 create_exec_event_catchpoint (tempflag, cond_string);
6307 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6309 char *dll_pathname = NULL;
6310 char *cond_string = NULL;
6312 ep_skip_leading_whitespace (&arg);
6314 /* The allowed syntax is:
6316 catch load if <cond>
6317 catch load <filename>
6318 catch load <filename> if <cond>
6320 The user is not allowed to specify the <filename> after an
6323 We'll ignore the pathological case of a file named "if".
6325 First, check if there's an if clause. If so, then there
6326 cannot be a filename. */
6327 cond_string = ep_parse_optional_if_clause (&arg);
6329 /* If there was an if clause, then there cannot be a filename.
6330 Else, there might be a filename and an if clause. */
6331 if (cond_string == NULL)
6333 dll_pathname = ep_parse_optional_filename (&arg);
6334 ep_skip_leading_whitespace (&arg);
6335 cond_string = ep_parse_optional_if_clause (&arg);
6338 if ((*arg != '\0') && !isspace (*arg))
6339 error ("Junk at end of arguments.");
6341 /* Create a load breakpoint that only triggers when a load of
6342 the specified dll (or any dll, if no pathname was specified)
6344 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6345 dll_pathname, cond_string);
6349 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6351 char *dll_pathname = NULL;
6352 char *cond_string = NULL;
6354 ep_skip_leading_whitespace (&arg);
6356 /* The allowed syntax is:
6358 catch unload if <cond>
6359 catch unload <filename>
6360 catch unload <filename> if <cond>
6362 The user is not allowed to specify the <filename> after an
6365 We'll ignore the pathological case of a file named "if".
6367 First, check if there's an if clause. If so, then there
6368 cannot be a filename. */
6369 cond_string = ep_parse_optional_if_clause (&arg);
6371 /* If there was an if clause, then there cannot be a filename.
6372 Else, there might be a filename and an if clause. */
6373 if (cond_string == NULL)
6375 dll_pathname = ep_parse_optional_filename (&arg);
6376 ep_skip_leading_whitespace (&arg);
6377 cond_string = ep_parse_optional_if_clause (&arg);
6380 if ((*arg != '\0') && !isspace (*arg))
6381 error ("Junk at end of arguments.");
6383 /* Create an unload breakpoint that only triggers when an unload of
6384 the specified dll (or any dll, if no pathname was specified)
6386 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6387 dll_pathname, cond_string);
6390 /* Commands to deal with catching exceptions. */
6392 /* Set a breakpoint at the specified callback routine for an
6393 exception event callback */
6396 create_exception_catchpoint (int tempflag, char *cond_string,
6397 enum exception_event_kind ex_event,
6398 struct symtab_and_line *sal)
6400 struct breakpoint *b;
6401 int thread = -1; /* All threads. */
6404 if (!sal) /* no exception support? */
6409 case EX_EVENT_THROW:
6410 bptype = bp_catch_throw;
6412 case EX_EVENT_CATCH:
6413 bptype = bp_catch_catch;
6415 default: /* error condition */
6416 error ("Internal error -- invalid catchpoint kind");
6419 b = set_raw_breakpoint (*sal, bptype);
6420 set_breakpoint_count (breakpoint_count + 1);
6421 b->number = breakpoint_count;
6423 b->cond_string = (cond_string == NULL) ?
6424 NULL : savestring (cond_string, strlen (cond_string));
6426 b->addr_string = NULL;
6427 b->enable_state = bp_enabled;
6428 b->disposition = tempflag ? disp_del : disp_donttouch;
6432 static enum print_stop_action
6433 print_exception_catchpoint (struct breakpoint *b)
6435 annotate_catchpoint (b->number);
6437 if (strstr (b->addr_string, "throw") != NULL)
6438 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6441 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6444 return PRINT_SRC_AND_LOC;
6448 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6453 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6456 *last_addr = b->loc->address;
6457 if (strstr (b->addr_string, "throw") != NULL)
6458 ui_out_field_string (uiout, "what", "exception throw");
6460 ui_out_field_string (uiout, "what", "exception catch");
6464 print_mention_exception_catchpoint (struct breakpoint *b)
6466 if (strstr (b->addr_string, "throw") != NULL)
6467 printf_filtered ("Catchpoint %d (throw)", b->number);
6469 printf_filtered ("Catchpoint %d (catch)", b->number);
6472 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6473 print_exception_catchpoint,
6474 print_one_exception_catchpoint,
6475 print_mention_exception_catchpoint
6479 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6480 enum exception_event_kind ex_event, int from_tty)
6482 char *trigger_func_name, *nameptr;
6483 struct symtabs_and_lines sals;
6484 struct breakpoint *b;
6486 if (ex_event == EX_EVENT_CATCH)
6487 trigger_func_name = xstrdup ("__cxa_begin_catch");
6489 trigger_func_name = xstrdup ("__cxa_throw");
6491 nameptr = trigger_func_name;
6492 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6493 if (sals.nelts == 0)
6495 xfree (trigger_func_name);
6499 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6500 set_breakpoint_count (breakpoint_count + 1);
6501 b->number = breakpoint_count;
6503 b->cond_string = (cond_string == NULL) ?
6504 NULL : savestring (cond_string, strlen (cond_string));
6506 b->addr_string = trigger_func_name;
6507 b->enable_state = bp_enabled;
6508 b->disposition = tempflag ? disp_del : disp_donttouch;
6509 b->ops = &gnu_v3_exception_catchpoint_ops;
6516 /* Deal with "catch catch" and "catch throw" commands */
6519 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6520 int tempflag, int from_tty)
6522 char *cond_string = NULL;
6523 struct symtab_and_line *sal = NULL;
6525 ep_skip_leading_whitespace (&arg);
6527 cond_string = ep_parse_optional_if_clause (&arg);
6529 if ((*arg != '\0') && !isspace (*arg))
6530 error ("Junk at end of arguments.");
6532 if ((ex_event != EX_EVENT_THROW) &&
6533 (ex_event != EX_EVENT_CATCH))
6534 error ("Unsupported or unknown exception event; cannot catch it");
6536 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6539 /* See if we can find a callback routine */
6540 sal = target_enable_exception_callback (ex_event, 1);
6544 /* We have callbacks from the runtime system for exceptions.
6545 Set a breakpoint on the sal found, if no errors */
6546 if (sal != (struct symtab_and_line *) -1)
6547 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6549 return; /* something went wrong with setting up callbacks */
6552 warning ("Unsupported with this platform/compiler combination.");
6555 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6556 inside a catch_errors */
6559 cover_target_enable_exception_callback (void *arg)
6561 args_for_catchpoint_enable *args = arg;
6562 struct symtab_and_line *sal;
6563 sal = target_enable_exception_callback (args->kind, args->enable_p);
6566 else if (sal == (struct symtab_and_line *) -1)
6569 return 1; /*is valid */
6573 catch_command_1 (char *arg, int tempflag, int from_tty)
6576 /* The first argument may be an event name, such as "start" or "load".
6577 If so, then handle it as such. If it doesn't match an event name,
6578 then attempt to interpret it as an exception name. (This latter is
6579 the v4.16-and-earlier GDB meaning of the "catch" command.)
6581 First, try to find the bounds of what might be an event name. */
6582 char *arg1_start = arg;
6586 if (arg1_start == NULL)
6588 /* Old behaviour was to use pre-v-4.16 syntax */
6589 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6591 /* Now, this is not allowed */
6592 error ("Catch requires an event name.");
6595 arg1_end = ep_find_event_name_end (arg1_start);
6596 if (arg1_end == NULL)
6597 error ("catch requires an event");
6598 arg1_length = arg1_end + 1 - arg1_start;
6600 /* Try to match what we found against known event names. */
6601 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6603 error ("Catch of signal not yet implemented");
6605 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6607 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6608 tempflag, from_tty);
6610 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6612 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6613 tempflag, from_tty);
6615 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6617 error ("Catch of thread_start not yet implemented");
6619 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6621 error ("Catch of thread_exit not yet implemented");
6623 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6625 error ("Catch of thread_join not yet implemented");
6627 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6629 error ("Catch of start not yet implemented");
6631 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6633 error ("Catch of exit not yet implemented");
6635 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6637 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6639 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6641 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6643 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6645 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6647 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6649 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6651 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6653 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6655 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6657 error ("Catch of stop not yet implemented");
6660 /* This doesn't appear to be an event name */
6664 /* Pre-v.4.16 behaviour was to treat the argument
6665 as the name of an exception */
6666 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6667 /* Now this is not allowed */
6668 error ("Unknown event kind specified for catch");
6673 /* Used by the gui, could be made a worker for other things. */
6676 set_breakpoint_sal (struct symtab_and_line sal)
6678 struct breakpoint *b;
6679 b = set_raw_breakpoint (sal, bp_breakpoint);
6680 set_breakpoint_count (breakpoint_count + 1);
6681 b->number = breakpoint_count;
6688 catch_command (char *arg, int from_tty)
6690 catch_command_1 (arg, 0, from_tty);
6695 tcatch_command (char *arg, int from_tty)
6697 catch_command_1 (arg, 1, from_tty);
6700 /* Delete breakpoints by address or line. */
6703 clear_command (char *arg, int from_tty)
6705 struct breakpoint *b, *tmp, *prev, *found;
6707 struct symtabs_and_lines sals;
6708 struct symtab_and_line sal;
6713 sals = decode_line_spec (arg, 1);
6718 sals.sals = (struct symtab_and_line *)
6719 xmalloc (sizeof (struct symtab_and_line));
6720 make_cleanup (xfree, sals.sals);
6721 init_sal (&sal); /* initialize to zeroes */
6722 sal.line = default_breakpoint_line;
6723 sal.symtab = default_breakpoint_symtab;
6724 sal.pc = default_breakpoint_address;
6725 if (sal.symtab == 0)
6726 error ("No source file specified.");
6734 /* For each line spec given, delete bps which correspond
6735 to it. Do it in two passes, solely to preserve the current
6736 behavior that from_tty is forced true if we delete more than
6740 for (i = 0; i < sals.nelts; i++)
6742 /* If exact pc given, clear bpts at that pc.
6743 If line given (pc == 0), clear all bpts on specified line.
6744 If defaulting, clear all bpts on default line
6747 defaulting sal.pc != 0 tests to do
6752 1 0 <can't happen> */
6757 /* Find all matching breakpoints, remove them from the
6758 breakpoint chain, and add them to the 'found' chain. */
6759 ALL_BREAKPOINTS_SAFE (b, tmp)
6761 /* Are we going to delete b? */
6762 if (b->type != bp_none
6763 && b->type != bp_watchpoint
6764 && b->type != bp_hardware_watchpoint
6765 && b->type != bp_read_watchpoint
6766 && b->type != bp_access_watchpoint
6767 /* Not if b is a watchpoint of any sort... */
6768 && (((sal.pc && (b->loc->address == sal.pc))
6769 && (!section_is_overlay (b->loc->section)
6770 || b->loc->section == sal.section))
6771 /* Yes, if sal.pc matches b (modulo overlays). */
6772 || ((default_match || (0 == sal.pc))
6773 && b->source_file != NULL
6774 && sal.symtab != NULL
6775 && strcmp (b->source_file, sal.symtab->filename) == 0
6776 && b->line_number == sal.line)))
6777 /* Yes, if sal source file and line matches b. */
6779 /* Remove it from breakpoint_chain... */
6780 if (b == breakpoint_chain)
6782 /* b is at the head of the list */
6783 breakpoint_chain = b->next;
6787 prev->next = b->next;
6789 /* And add it to 'found' chain. */
6795 /* Keep b, and keep a pointer to it. */
6800 /* Now go thru the 'found' chain and delete them. */
6804 error ("No breakpoint at %s.", arg);
6806 error ("No breakpoint at this line.");
6810 from_tty = 1; /* Always report if deleted more than one */
6812 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6813 breakpoints_changed ();
6817 printf_unfiltered ("%d ", found->number);
6819 delete_breakpoint (found);
6823 putchar_unfiltered ('\n');
6826 /* Delete breakpoint in BS if they are `delete' breakpoints and
6827 all breakpoints that are marked for deletion, whether hit or not.
6828 This is called after any breakpoint is hit, or after errors. */
6831 breakpoint_auto_delete (bpstat bs)
6833 struct breakpoint *b, *temp;
6835 for (; bs; bs = bs->next)
6836 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6838 delete_breakpoint (bs->breakpoint_at);
6840 ALL_BREAKPOINTS_SAFE (b, temp)
6842 if (b->disposition == disp_del_at_next_stop)
6843 delete_breakpoint (b);
6847 /* Delete a breakpoint and clean up all traces of it in the data
6851 delete_breakpoint (struct breakpoint *bpt)
6853 struct breakpoint *b;
6855 struct bp_location *loc;
6858 error ("Internal error (attempted to delete a NULL breakpoint)");
6861 /* Has this bp already been deleted? This can happen because multiple
6862 lists can hold pointers to bp's. bpstat lists are especial culprits.
6864 One example of this happening is a watchpoint's scope bp. When the
6865 scope bp triggers, we notice that the watchpoint is out of scope, and
6866 delete it. We also delete its scope bp. But the scope bp is marked
6867 "auto-deleting", and is already on a bpstat. That bpstat is then
6868 checked for auto-deleting bp's, which are deleted.
6870 A real solution to this problem might involve reference counts in bp's,
6871 and/or giving them pointers back to their referencing bpstat's, and
6872 teaching delete_breakpoint to only free a bp's storage when no more
6873 references were extent. A cheaper bandaid was chosen. */
6874 if (bpt->type == bp_none)
6877 if (delete_breakpoint_hook)
6878 delete_breakpoint_hook (bpt);
6879 breakpoint_delete_event (bpt->number);
6881 if (bpt->loc->inserted)
6882 remove_breakpoint (bpt->loc, mark_inserted);
6884 if (breakpoint_chain == bpt)
6885 breakpoint_chain = bpt->next;
6887 if (bp_location_chain == bpt->loc)
6888 bp_location_chain = bpt->loc->next;
6890 /* If we have callback-style exception catchpoints, don't go through
6891 the adjustments to the C++ runtime library etc. if the inferior
6892 isn't actually running. target_enable_exception_callback for a
6893 null target ops vector gives an undesirable error message, so we
6894 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6895 exceptions are supported in this way, it's OK for now. FIXME */
6896 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6898 /* Format possible error msg */
6899 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6901 struct cleanup *cleanups = make_cleanup (xfree, message);
6902 args_for_catchpoint_enable args;
6903 args.kind = bpt->type == bp_catch_catch ?
6904 EX_EVENT_CATCH : EX_EVENT_THROW;
6906 catch_errors (cover_target_enable_exception_callback, &args,
6907 message, RETURN_MASK_ALL);
6908 do_cleanups (cleanups);
6915 b->next = bpt->next;
6919 ALL_BP_LOCATIONS (loc)
6920 if (loc->next == bpt->loc)
6922 loc->next = bpt->loc->next;
6926 check_duplicates (bpt);
6927 /* If this breakpoint was inserted, and there is another breakpoint
6928 at the same address, we need to insert the other breakpoint. */
6929 if (bpt->loc->inserted
6930 && bpt->type != bp_hardware_watchpoint
6931 && bpt->type != bp_read_watchpoint
6932 && bpt->type != bp_access_watchpoint
6933 && bpt->type != bp_catch_fork
6934 && bpt->type != bp_catch_vfork
6935 && bpt->type != bp_catch_exec)
6938 if (b->loc->address == bpt->loc->address
6939 && b->loc->section == bpt->loc->section
6940 && !b->loc->duplicate
6941 && b->enable_state != bp_disabled
6942 && b->enable_state != bp_shlib_disabled
6944 && b->enable_state != bp_call_disabled)
6948 /* We should never reach this point if there is a permanent
6949 breakpoint at the same address as the one being deleted.
6950 If there is a permanent breakpoint somewhere, it should
6951 always be the only one inserted. */
6952 if (b->enable_state == bp_permanent)
6953 internal_error (__FILE__, __LINE__,
6954 "another breakpoint was inserted on top of "
6955 "a permanent breakpoint");
6957 if (b->type == bp_hardware_breakpoint)
6958 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
6960 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
6962 /* If there was an error in the insert, print a message, then stop execution. */
6965 struct ui_file *tmp_error_stream = mem_fileopen ();
6966 make_cleanup_ui_file_delete (tmp_error_stream);
6969 if (b->type == bp_hardware_breakpoint)
6971 fprintf_unfiltered (tmp_error_stream,
6972 "Cannot insert hardware breakpoint %d.\n"
6973 "You may have requested too many hardware breakpoints.\n",
6978 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6979 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6980 print_address_numeric (b->loc->address, 1, tmp_error_stream);
6981 fprintf_filtered (tmp_error_stream, ": %s.\n",
6982 safe_strerror (val));
6985 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6986 target_terminal_ours_for_output ();
6987 error_stream(tmp_error_stream);
6990 b->loc->inserted = 1;
6994 free_command_lines (&bpt->commands);
6997 if (bpt->cond_string != NULL)
6998 xfree (bpt->cond_string);
6999 if (bpt->addr_string != NULL)
7000 xfree (bpt->addr_string);
7001 if (bpt->exp != NULL)
7003 if (bpt->exp_string != NULL)
7004 xfree (bpt->exp_string);
7005 if (bpt->val != NULL)
7006 value_free (bpt->val);
7007 if (bpt->source_file != NULL)
7008 xfree (bpt->source_file);
7009 if (bpt->dll_pathname != NULL)
7010 xfree (bpt->dll_pathname);
7011 if (bpt->triggered_dll_pathname != NULL)
7012 xfree (bpt->triggered_dll_pathname);
7013 if (bpt->exec_pathname != NULL)
7014 xfree (bpt->exec_pathname);
7016 /* Be sure no bpstat's are pointing at it after it's been freed. */
7017 /* FIXME, how can we find all bpstat's?
7018 We just check stop_bpstat for now. */
7019 for (bs = stop_bpstat; bs; bs = bs->next)
7020 if (bs->breakpoint_at == bpt)
7022 bs->breakpoint_at = NULL;
7024 /* bs->commands will be freed later. */
7026 /* On the chance that someone will soon try again to delete this same
7027 bp, we mark it as deleted before freeing its storage. */
7028 bpt->type = bp_none;
7035 do_delete_breakpoint_cleanup (void *b)
7037 delete_breakpoint (b);
7041 make_cleanup_delete_breakpoint (struct breakpoint *b)
7043 return make_cleanup (do_delete_breakpoint_cleanup, b);
7047 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7049 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7053 delete_command (char *arg, int from_tty)
7055 struct breakpoint *b, *temp;
7061 int breaks_to_delete = 0;
7063 /* Delete all breakpoints if no argument.
7064 Do not delete internal or call-dummy breakpoints, these
7065 have to be deleted with an explicit breakpoint number argument. */
7068 if (b->type != bp_call_dummy &&
7069 b->type != bp_shlib_event &&
7070 b->type != bp_thread_event &&
7071 b->type != bp_overlay_event &&
7073 breaks_to_delete = 1;
7076 /* Ask user only if there are some breakpoints to delete. */
7078 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7080 ALL_BREAKPOINTS_SAFE (b, temp)
7082 if (b->type != bp_call_dummy &&
7083 b->type != bp_shlib_event &&
7084 b->type != bp_thread_event &&
7085 b->type != bp_overlay_event &&
7087 delete_breakpoint (b);
7092 map_breakpoint_numbers (arg, delete_breakpoint);
7095 /* Reset a breakpoint given it's struct breakpoint * BINT.
7096 The value we return ends up being the return value from catch_errors.
7097 Unused in this case. */
7100 breakpoint_re_set_one (void *bint)
7102 /* get past catch_errs */
7103 struct breakpoint *b = (struct breakpoint *) bint;
7106 struct symtabs_and_lines sals;
7108 enum enable_state save_enable;
7113 warning ("attempted to reset apparently deleted breakpoint #%d?",
7117 case bp_hardware_breakpoint:
7119 case bp_catch_unload:
7120 if (b->addr_string == NULL)
7122 /* Anything without a string can't be re-set. */
7123 delete_breakpoint (b);
7126 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7128 ``And a hack it is, although Apple's Darwin version of GDB
7129 contains an almost identical hack to implement a "future
7130 break" command. It seems to work in many real world cases,
7131 but it is easy to come up with a test case where the patch
7132 doesn't help at all.''
7134 ``It seems that the way GDB implements breakpoints - in -
7135 shared - libraries was designed for a.out shared library
7136 systems (SunOS 4) where shared libraries were loaded at a
7137 fixed address in memory. Since ELF shared libraries can (and
7138 will) be loaded at any address in memory, things break.
7139 Fixing this is not trivial. Therefore, I'm not sure whether
7140 we should add this hack to the branch only. I cannot
7141 guarantee that things will be fixed on the trunk in the near
7144 In case we have a problem, disable this breakpoint. We'll
7145 restore its status if we succeed. Don't disable a
7146 shlib_disabled breakpoint though. There's a fair chance we
7147 can't re-set it if the shared library it's in hasn't been
7153 save_enable = b->enable_state;
7154 if (b->enable_state != bp_shlib_disabled)
7155 b->enable_state = bp_disabled;
7157 set_language (b->language);
7158 input_radix = b->input_radix;
7160 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7161 for (i = 0; i < sals.nelts; i++)
7163 resolve_sal_pc (&sals.sals[i]);
7165 /* Reparse conditions, they might contain references to the
7167 if (b->cond_string != NULL)
7173 /* Avoid re-freeing b->exp if an error during the call
7177 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7180 /* We need to re-set the breakpoint if the address changes... */
7181 if (b->loc->address != sals.sals[i].pc
7182 /* ...or new and old breakpoints both have source files, and
7183 the source file name or the line number changes... */
7184 || (b->source_file != NULL
7185 && sals.sals[i].symtab != NULL
7186 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
7187 || b->line_number != sals.sals[i].line)
7189 /* ...or we switch between having a source file and not having
7191 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7194 if (b->source_file != NULL)
7195 xfree (b->source_file);
7196 if (sals.sals[i].symtab == NULL)
7197 b->source_file = NULL;
7200 savestring (sals.sals[i].symtab->filename,
7201 strlen (sals.sals[i].symtab->filename));
7202 b->line_number = sals.sals[i].line;
7203 b->loc->requested_address = sals.sals[i].pc;
7205 = adjust_breakpoint_address (b->loc->requested_address,
7208 /* Used to check for duplicates here, but that can
7209 cause trouble, as it doesn't check for disabled
7214 /* Might be better to do this just once per breakpoint_re_set,
7215 rather than once for every breakpoint. */
7216 breakpoints_changed ();
7218 b->loc->section = sals.sals[i].section;
7219 b->enable_state = save_enable; /* Restore it, this worked. */
7222 /* Now that this is re-enabled, check_duplicates
7224 check_duplicates (b);
7231 case bp_hardware_watchpoint:
7232 case bp_read_watchpoint:
7233 case bp_access_watchpoint:
7234 innermost_block = NULL;
7235 /* The issue arises of what context to evaluate this in. The
7236 same one as when it was set, but what does that mean when
7237 symbols have been re-read? We could save the filename and
7238 functionname, but if the context is more local than that, the
7239 best we could do would be something like how many levels deep
7240 and which index at that particular level, but that's going to
7241 be less stable than filenames or function names. */
7243 /* So for now, just use a global context. */
7247 /* Avoid re-freeing b->exp if an error during the call to
7248 parse_expression. */
7251 b->exp = parse_expression (b->exp_string);
7252 b->exp_valid_block = innermost_block;
7253 mark = value_mark ();
7256 value_free (b->val);
7257 /* Avoid re-freeing b->val if an error during the call to
7258 evaluate_expression. */
7261 b->val = evaluate_expression (b->exp);
7262 release_value (b->val);
7263 if (VALUE_LAZY (b->val) && breakpoint_enabled (b))
7264 value_fetch_lazy (b->val);
7266 if (b->cond_string != NULL)
7272 /* Avoid re-freeing b->exp if an error during the call
7276 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7278 if (breakpoint_enabled (b))
7280 value_free_to_mark (mark);
7282 case bp_catch_catch:
7283 case bp_catch_throw:
7285 /* We needn't really do anything to reset these, since the mask
7286 that requests them is unaffected by e.g., new libraries being
7289 case bp_catch_vfork:
7294 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7296 /* Delete longjmp and overlay event breakpoints; they will be
7297 reset later by breakpoint_re_set. */
7299 case bp_longjmp_resume:
7300 case bp_overlay_event:
7301 delete_breakpoint (b);
7304 /* This breakpoint is special, it's set up when the inferior
7305 starts and we really don't want to touch it. */
7306 case bp_shlib_event:
7308 /* Like bp_shlib_event, this breakpoint type is special.
7309 Once it is set up, we do not want to touch it. */
7310 case bp_thread_event:
7312 /* Keep temporary breakpoints, which can be encountered when we step
7313 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7314 Otherwise these should have been blown away via the cleanup chain
7315 or by breakpoint_init_inferior when we rerun the executable. */
7318 case bp_watchpoint_scope:
7320 case bp_step_resume:
7327 /* Re-set all breakpoints after symbols have been re-loaded. */
7329 breakpoint_re_set (void)
7331 struct breakpoint *b, *temp;
7332 enum language save_language;
7333 int save_input_radix;
7335 save_language = current_language->la_language;
7336 save_input_radix = input_radix;
7337 ALL_BREAKPOINTS_SAFE (b, temp)
7339 /* Format possible error msg */
7340 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7342 struct cleanup *cleanups = make_cleanup (xfree, message);
7343 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7344 do_cleanups (cleanups);
7346 set_language (save_language);
7347 input_radix = save_input_radix;
7349 if (GET_LONGJMP_TARGET_P ())
7351 create_longjmp_breakpoint ("longjmp");
7352 create_longjmp_breakpoint ("_longjmp");
7353 create_longjmp_breakpoint ("siglongjmp");
7354 create_longjmp_breakpoint ("_siglongjmp");
7355 create_longjmp_breakpoint (NULL);
7358 create_overlay_event_breakpoint ("_ovly_debug_event");
7361 /* Reset the thread number of this breakpoint:
7363 - If the breakpoint is for all threads, leave it as-is.
7364 - Else, reset it to the current thread for inferior_ptid. */
7366 breakpoint_re_set_thread (struct breakpoint *b)
7368 if (b->thread != -1)
7370 if (in_thread_list (inferior_ptid))
7371 b->thread = pid_to_thread_id (inferior_ptid);
7375 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7376 If from_tty is nonzero, it prints a message to that effect,
7377 which ends with a period (no newline). */
7380 set_ignore_count (int bptnum, int count, int from_tty)
7382 struct breakpoint *b;
7388 if (b->number == bptnum)
7390 b->ignore_count = count;
7394 printf_filtered ("Will stop next time breakpoint %d is reached.",
7396 else if (count == 1)
7397 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7400 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7403 breakpoints_changed ();
7404 breakpoint_modify_event (b->number);
7408 error ("No breakpoint number %d.", bptnum);
7411 /* Clear the ignore counts of all breakpoints. */
7413 breakpoint_clear_ignore_counts (void)
7415 struct breakpoint *b;
7418 b->ignore_count = 0;
7421 /* Command to set ignore-count of breakpoint N to COUNT. */
7424 ignore_command (char *args, int from_tty)
7430 error_no_arg ("a breakpoint number");
7432 num = get_number (&p);
7434 error ("bad breakpoint number: '%s'", args);
7436 error ("Second argument (specified ignore-count) is missing.");
7438 set_ignore_count (num,
7439 longest_to_int (value_as_long (parse_and_eval (p))),
7442 printf_filtered ("\n");
7445 /* Call FUNCTION on each of the breakpoints
7446 whose numbers are given in ARGS. */
7449 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7454 struct breakpoint *b, *tmp;
7458 error_no_arg ("one or more breakpoint numbers");
7465 num = get_number_or_range (&p1);
7468 warning ("bad breakpoint number at or near '%s'", p);
7472 ALL_BREAKPOINTS_SAFE (b, tmp)
7473 if (b->number == num)
7475 struct breakpoint *related_breakpoint = b->related_breakpoint;
7478 if (related_breakpoint)
7479 function (related_breakpoint);
7483 printf_unfiltered ("No breakpoint number %d.\n", num);
7489 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7490 If from_tty is nonzero, it prints a message to that effect,
7491 which ends with a period (no newline). */
7494 disable_breakpoint (struct breakpoint *bpt)
7496 /* Never disable a watchpoint scope breakpoint; we want to
7497 hit them when we leave scope so we can delete both the
7498 watchpoint and its scope breakpoint at that time. */
7499 if (bpt->type == bp_watchpoint_scope)
7502 /* You can't disable permanent breakpoints. */
7503 if (bpt->enable_state == bp_permanent)
7506 bpt->enable_state = bp_disabled;
7508 check_duplicates (bpt);
7510 if (modify_breakpoint_hook)
7511 modify_breakpoint_hook (bpt);
7512 breakpoint_modify_event (bpt->number);
7516 disable_command (char *args, int from_tty)
7518 struct breakpoint *bpt;
7520 ALL_BREAKPOINTS (bpt)
7524 warning ("attempted to disable apparently deleted breakpoint #%d?",
7529 case bp_catch_unload:
7531 case bp_catch_vfork:
7533 case bp_catch_catch:
7534 case bp_catch_throw:
7535 case bp_hardware_breakpoint:
7537 case bp_hardware_watchpoint:
7538 case bp_read_watchpoint:
7539 case bp_access_watchpoint:
7540 disable_breakpoint (bpt);
7545 map_breakpoint_numbers (args, disable_breakpoint);
7549 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7551 struct frame_info *save_selected_frame = NULL;
7552 int save_selected_frame_level = -1;
7553 int target_resources_ok, other_type_used;
7556 if (bpt->type == bp_hardware_breakpoint)
7559 i = hw_breakpoint_used_count ();
7560 target_resources_ok =
7561 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7563 if (target_resources_ok == 0)
7564 error ("No hardware breakpoint support in the target.");
7565 else if (target_resources_ok < 0)
7566 error ("Hardware breakpoints used exceeds limit.");
7571 if (bpt->enable_state != bp_enabled)
7573 /* When enabling a pending breakpoint, we need to check if the breakpoint
7574 is resolvable since shared libraries could have been loaded
7575 after the breakpoint was disabled. */
7576 breakpoints_changed ();
7577 if (resolve_pending_breakpoint (bpt) == GDB_RC_OK)
7579 delete_breakpoint (bpt);
7582 bpt->enable_state = bp_enabled;
7583 bpt->disposition = disposition;
7586 else /* Not a pending breakpoint. */
7588 if (bpt->enable_state != bp_permanent)
7589 bpt->enable_state = bp_enabled;
7590 bpt->disposition = disposition;
7591 check_duplicates (bpt);
7592 breakpoints_changed ();
7594 if (bpt->type == bp_watchpoint ||
7595 bpt->type == bp_hardware_watchpoint ||
7596 bpt->type == bp_read_watchpoint ||
7597 bpt->type == bp_access_watchpoint)
7599 if (bpt->exp_valid_block != NULL)
7601 struct frame_info *fr =
7602 fr = frame_find_by_id (bpt->watchpoint_frame);
7606 Cannot enable watchpoint %d because the block in which its expression\n\
7607 is valid is not currently in scope.\n", bpt->number);
7608 bpt->enable_state = bp_disabled;
7612 save_selected_frame = deprecated_selected_frame;
7613 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7617 value_free (bpt->val);
7618 mark = value_mark ();
7619 bpt->val = evaluate_expression (bpt->exp);
7620 release_value (bpt->val);
7621 if (VALUE_LAZY (bpt->val))
7622 value_fetch_lazy (bpt->val);
7624 if (bpt->type == bp_hardware_watchpoint ||
7625 bpt->type == bp_read_watchpoint ||
7626 bpt->type == bp_access_watchpoint)
7628 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7629 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7631 /* Hack around 'unused var' error for some targets here */
7633 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7634 bpt->type, i + mem_cnt, other_type_used);
7635 /* we can consider of type is bp_hardware_watchpoint, convert to
7636 bp_watchpoint in the following condition */
7637 if (target_resources_ok < 0)
7640 Cannot enable watchpoint %d because target watch resources\n\
7641 have been allocated for other watchpoints.\n", bpt->number);
7642 bpt->enable_state = bp_disabled;
7643 value_free_to_mark (mark);
7648 if (save_selected_frame_level >= 0)
7649 select_frame (save_selected_frame);
7650 value_free_to_mark (mark);
7654 if (modify_breakpoint_hook)
7655 modify_breakpoint_hook (bpt);
7656 breakpoint_modify_event (bpt->number);
7660 enable_breakpoint (struct breakpoint *bpt)
7662 do_enable_breakpoint (bpt, bpt->disposition);
7665 /* The enable command enables the specified breakpoints (or all defined
7666 breakpoints) so they once again become (or continue to be) effective
7667 in stopping the inferior. */
7670 enable_command (char *args, int from_tty)
7672 struct breakpoint *bpt;
7674 ALL_BREAKPOINTS (bpt)
7678 warning ("attempted to enable apparently deleted breakpoint #%d?",
7683 case bp_catch_unload:
7685 case bp_catch_vfork:
7687 case bp_catch_catch:
7688 case bp_catch_throw:
7689 case bp_hardware_breakpoint:
7691 case bp_hardware_watchpoint:
7692 case bp_read_watchpoint:
7693 case bp_access_watchpoint:
7694 enable_breakpoint (bpt);
7699 map_breakpoint_numbers (args, enable_breakpoint);
7703 enable_once_breakpoint (struct breakpoint *bpt)
7705 do_enable_breakpoint (bpt, disp_disable);
7709 enable_once_command (char *args, int from_tty)
7711 map_breakpoint_numbers (args, enable_once_breakpoint);
7715 enable_delete_breakpoint (struct breakpoint *bpt)
7717 do_enable_breakpoint (bpt, disp_del);
7721 enable_delete_command (char *args, int from_tty)
7723 map_breakpoint_numbers (args, enable_delete_breakpoint);
7727 set_breakpoint_cmd (char *args, int from_tty)
7732 show_breakpoint_cmd (char *args, int from_tty)
7736 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7738 struct symtabs_and_lines
7739 decode_line_spec_1 (char *string, int funfirstline)
7741 struct symtabs_and_lines sals;
7743 error ("Empty line specification.");
7744 if (default_breakpoint_valid)
7745 sals = decode_line_1 (&string, funfirstline,
7746 default_breakpoint_symtab,
7747 default_breakpoint_line,
7748 (char ***) NULL, NULL);
7750 sals = decode_line_1 (&string, funfirstline,
7751 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7753 error ("Junk at end of line specification: %s", string);
7758 _initialize_breakpoint (void)
7760 static struct cmd_list_element *breakpoint_set_cmdlist;
7761 static struct cmd_list_element *breakpoint_show_cmdlist;
7762 struct cmd_list_element *c;
7764 breakpoint_chain = 0;
7765 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7766 before a breakpoint is set. */
7767 breakpoint_count = 0;
7769 add_com ("ignore", class_breakpoint, ignore_command,
7770 "Set ignore-count of breakpoint number N to COUNT.\n\
7771 Usage is `ignore N COUNT'.");
7773 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7775 add_com ("commands", class_breakpoint, commands_command,
7776 "Set commands to be executed when a breakpoint is hit.\n\
7777 Give breakpoint number as argument after \"commands\".\n\
7778 With no argument, the targeted breakpoint is the last one set.\n\
7779 The commands themselves follow starting on the next line.\n\
7780 Type a line containing \"end\" to indicate the end of them.\n\
7781 Give \"silent\" as the first line to make the breakpoint silent;\n\
7782 then no output is printed when it is hit, except what the commands print.");
7784 add_com ("condition", class_breakpoint, condition_command,
7785 "Specify breakpoint number N to break only if COND is true.\n\
7786 Usage is `condition N COND', where N is an integer and COND is an\n\
7787 expression to be evaluated whenever breakpoint N is reached.");
7789 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7790 "Set a temporary breakpoint. Args like \"break\" command.\n\
7791 Like \"break\" except the breakpoint is only temporary,\n\
7792 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7793 by using \"enable delete\" on the breakpoint number.");
7794 set_cmd_completer (c, location_completer);
7796 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7797 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7798 Like \"break\" except the breakpoint requires hardware support,\n\
7799 some target hardware may not have this support.");
7800 set_cmd_completer (c, location_completer);
7802 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7803 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7804 Like \"hbreak\" except the breakpoint is only temporary,\n\
7805 so it will be deleted when hit.");
7806 set_cmd_completer (c, location_completer);
7808 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7809 "Enable some breakpoints.\n\
7810 Give breakpoint numbers (separated by spaces) as arguments.\n\
7811 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7812 This is used to cancel the effect of the \"disable\" command.\n\
7813 With a subcommand you can enable temporarily.",
7814 &enablelist, "enable ", 1, &cmdlist);
7816 add_com ("ab", class_breakpoint, enable_command,
7817 "Enable some breakpoints.\n\
7818 Give breakpoint numbers (separated by spaces) as arguments.\n\
7819 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7820 This is used to cancel the effect of the \"disable\" command.\n\
7821 With a subcommand you can enable temporarily.");
7823 add_com_alias ("en", "enable", class_breakpoint, 1);
7825 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7826 "Enable some breakpoints.\n\
7827 Give breakpoint numbers (separated by spaces) as arguments.\n\
7828 This is used to cancel the effect of the \"disable\" command.\n\
7829 May be abbreviated to simply \"enable\".\n",
7830 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7832 add_cmd ("once", no_class, enable_once_command,
7833 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7834 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7837 add_cmd ("delete", no_class, enable_delete_command,
7838 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7839 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7842 add_cmd ("delete", no_class, enable_delete_command,
7843 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7844 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7847 add_cmd ("once", no_class, enable_once_command,
7848 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7849 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7852 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7853 "Disable some breakpoints.\n\
7854 Arguments are breakpoint numbers with spaces in between.\n\
7855 To disable all breakpoints, give no argument.\n\
7856 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7857 &disablelist, "disable ", 1, &cmdlist);
7858 add_com_alias ("dis", "disable", class_breakpoint, 1);
7859 add_com_alias ("disa", "disable", class_breakpoint, 1);
7861 add_com ("sb", class_breakpoint, disable_command,
7862 "Disable some breakpoints.\n\
7863 Arguments are breakpoint numbers with spaces in between.\n\
7864 To disable all breakpoints, give no argument.\n\
7865 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7867 add_cmd ("breakpoints", class_alias, disable_command,
7868 "Disable some breakpoints.\n\
7869 Arguments are breakpoint numbers with spaces in between.\n\
7870 To disable all breakpoints, give no argument.\n\
7871 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7872 This command may be abbreviated \"disable\".",
7875 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7876 "Delete some breakpoints or auto-display expressions.\n\
7877 Arguments are breakpoint numbers with spaces in between.\n\
7878 To delete all breakpoints, give no argument.\n\
7880 Also a prefix command for deletion of other GDB objects.\n\
7881 The \"unset\" command is also an alias for \"delete\".",
7882 &deletelist, "delete ", 1, &cmdlist);
7883 add_com_alias ("d", "delete", class_breakpoint, 1);
7885 add_com ("db", class_breakpoint, delete_command,
7886 "Delete some breakpoints.\n\
7887 Arguments are breakpoint numbers with spaces in between.\n\
7888 To delete all breakpoints, give no argument.\n");
7890 add_cmd ("breakpoints", class_alias, delete_command,
7891 "Delete some breakpoints or auto-display expressions.\n\
7892 Arguments are breakpoint numbers with spaces in between.\n\
7893 To delete all breakpoints, give no argument.\n\
7894 This command may be abbreviated \"delete\".",
7897 add_com ("clear", class_breakpoint, clear_command,
7898 concat ("Clear breakpoint at specified line or function.\n\
7899 Argument may be line number, function name, or \"*\" and an address.\n\
7900 If line number is specified, all breakpoints in that line are cleared.\n\
7901 If function is specified, breakpoints at beginning of function are cleared.\n\
7902 If an address is specified, breakpoints at that address are cleared.\n\n",
7903 "With no argument, clears all breakpoints in the line that the selected frame\n\
7906 See also the \"delete\" command which clears breakpoints by number.", NULL));
7908 c = add_com ("break", class_breakpoint, break_command,
7909 concat ("Set breakpoint at specified line or function.\n\
7910 Argument may be line number, function name, or \"*\" and an address.\n\
7911 If line number is specified, break at start of code for that line.\n\
7912 If function is specified, break at start of code for that function.\n\
7913 If an address is specified, break at that exact address.\n",
7914 "With no arg, uses current execution address of selected stack frame.\n\
7915 This is useful for breaking on return to a stack frame.\n\
7917 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7919 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7920 set_cmd_completer (c, location_completer);
7922 add_com_alias ("b", "break", class_run, 1);
7923 add_com_alias ("br", "break", class_run, 1);
7924 add_com_alias ("bre", "break", class_run, 1);
7925 add_com_alias ("brea", "break", class_run, 1);
7929 add_com_alias ("ba", "break", class_breakpoint, 1);
7930 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7935 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7936 "Break in function/address or break at a line in the current file.",
7937 &stoplist, "stop ", 1, &cmdlist);
7938 add_cmd ("in", class_breakpoint, stopin_command,
7939 "Break in function or address.\n", &stoplist);
7940 add_cmd ("at", class_breakpoint, stopat_command,
7941 "Break at a line in the current file.\n", &stoplist);
7942 add_com ("status", class_info, breakpoints_info,
7943 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7944 The \"Type\" column indicates one of:\n\
7945 \tbreakpoint - normal breakpoint\n\
7946 \twatchpoint - watchpoint\n\
7947 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7948 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7949 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7950 address and file/line number respectively.\n\n",
7951 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7952 are set to the address of the last breakpoint listed.\n\n\
7953 Convenience variable \"$bpnum\" contains the number of the last\n\
7954 breakpoint set.", NULL));
7957 add_info ("breakpoints", breakpoints_info,
7958 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7959 The \"Type\" column indicates one of:\n\
7960 \tbreakpoint - normal breakpoint\n\
7961 \twatchpoint - watchpoint\n\
7962 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7963 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7964 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7965 address and file/line number respectively.\n\n",
7966 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7967 are set to the address of the last breakpoint listed.\n\n\
7968 Convenience variable \"$bpnum\" contains the number of the last\n\
7969 breakpoint set.", NULL));
7972 add_com ("lb", class_breakpoint, breakpoints_info,
7973 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7974 The \"Type\" column indicates one of:\n\
7975 \tbreakpoint - normal breakpoint\n\
7976 \twatchpoint - watchpoint\n\
7977 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7978 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7979 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7980 address and file/line number respectively.\n\n",
7981 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7982 are set to the address of the last breakpoint listed.\n\n\
7983 Convenience variable \"$bpnum\" contains the number of the last\n\
7984 breakpoint set.", NULL));
7986 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7987 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7988 The \"Type\" column indicates one of:\n\
7989 \tbreakpoint - normal breakpoint\n\
7990 \twatchpoint - watchpoint\n\
7991 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7992 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7993 \tuntil - internal breakpoint used by the \"until\" command\n\
7994 \tfinish - internal breakpoint used by the \"finish\" command\n",
7995 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7996 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7997 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7998 address and file/line number respectively.\n\n",
7999 "Convenience variable \"$_\" and default examine address for \"x\"\n\
8000 are set to the address of the last breakpoint listed.\n\n\
8001 Convenience variable \"$bpnum\" contains the number of the last\n\
8002 breakpoint set.", NULL),
8003 &maintenanceinfolist);
8005 add_com ("catch", class_breakpoint, catch_command,
8006 "Set catchpoints to catch events.\n\
8007 Raised signals may be caught:\n\
8008 \tcatch signal - all signals\n\
8009 \tcatch signal <signame> - a particular signal\n\
8010 Raised exceptions may be caught:\n\
8011 \tcatch throw - all exceptions, when thrown\n\
8012 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8013 \tcatch catch - all exceptions, when caught\n\
8014 \tcatch catch <exceptname> - a particular exception, when caught\n\
8015 Thread or process events may be caught:\n\
8016 \tcatch thread_start - any threads, just after creation\n\
8017 \tcatch thread_exit - any threads, just before expiration\n\
8018 \tcatch thread_join - any threads, just after joins\n\
8019 Process events may be caught:\n\
8020 \tcatch start - any processes, just after creation\n\
8021 \tcatch exit - any processes, just before expiration\n\
8022 \tcatch fork - calls to fork()\n\
8023 \tcatch vfork - calls to vfork()\n\
8024 \tcatch exec - calls to exec()\n\
8025 Dynamically-linked library events may be caught:\n\
8026 \tcatch load - loads of any library\n\
8027 \tcatch load <libname> - loads of a particular library\n\
8028 \tcatch unload - unloads of any library\n\
8029 \tcatch unload <libname> - unloads of a particular library\n\
8030 The act of your program's execution stopping may also be caught:\n\
8032 C++ exceptions may be caught:\n\
8033 \tcatch throw - all exceptions, when thrown\n\
8034 \tcatch catch - all exceptions, when caught\n\
8036 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8037 after a fork or vfork is caught.\n\n\
8038 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
8040 add_com ("tcatch", class_breakpoint, tcatch_command,
8041 "Set temporary catchpoints to catch events.\n\
8042 Args like \"catch\" command.\n\
8043 Like \"catch\" except the catchpoint is only temporary,\n\
8044 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8045 by using \"enable delete\" on the catchpoint number.");
8047 c = add_com ("watch", class_breakpoint, watch_command,
8048 "Set a watchpoint for an expression.\n\
8049 A watchpoint stops execution of your program whenever the value of\n\
8050 an expression changes.");
8051 set_cmd_completer (c, location_completer);
8053 c = add_com ("rwatch", class_breakpoint, rwatch_command,
8054 "Set a read watchpoint for an expression.\n\
8055 A watchpoint stops execution of your program whenever the value of\n\
8056 an expression is read.");
8057 set_cmd_completer (c, location_completer);
8059 c = add_com ("awatch", class_breakpoint, awatch_command,
8060 "Set a watchpoint for an expression.\n\
8061 A watchpoint stops execution of your program whenever the value of\n\
8062 an expression is either read or written.");
8063 set_cmd_completer (c, location_completer);
8065 add_info ("watchpoints", breakpoints_info,
8066 "Synonym for ``info breakpoints''.");
8069 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
8070 (char *) &can_use_hw_watchpoints,
8071 "Set debugger's willingness to use watchpoint hardware.\n\
8072 If zero, gdb will not use hardware for new watchpoints, even if\n\
8073 such is available. (However, any hardware watchpoints that were\n\
8074 created before setting this to nonzero, will continue to use watchpoint\n\
8077 add_show_from_set (c, &showlist);
8079 can_use_hw_watchpoints = 1;
8081 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, "\
8082 Breakpoint specific settings\n\
8083 Configure various breakpoint-specific variables such as\n\
8084 pending breakpoint behavior",
8085 &breakpoint_set_cmdlist, "set breakpoint ",
8086 0/*allow-unknown*/, &setlist);
8087 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, "\
8088 Breakpoint specific settings\n\
8089 Configure various breakpoint-specific variables such as\n\
8090 pending breakpoint behavior",
8091 &breakpoint_show_cmdlist, "show breakpoint ",
8092 0/*allow-unknown*/, &showlist);
8094 add_setshow_auto_boolean_cmd ("pending", no_class, &pending_break_support, "\
8095 Set debugger's behavior regarding pending breakpoints.\n\
8096 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8097 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8098 an error. If auto, an unrecognized breakpoint location results in a\n\
8099 user-query to see if a pending breakpoint should be created.","\
8100 Show debugger's behavior regarding pending breakpoints.\n\
8101 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8102 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8103 an error. If auto, an unrecognized breakpoint location results in a\n\
8104 user-query to see if a pending breakpoint should be created.",
8106 &breakpoint_set_cmdlist,
8107 &breakpoint_show_cmdlist);
8109 pending_break_support = AUTO_BOOLEAN_AUTO;