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, 2005
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"
55 #include "exceptions.h"
57 #include "gdb-events.h"
59 /* Prototypes for local functions. */
61 static void until_break_command_continuation (struct continuation_arg *arg);
63 static void catch_command_1 (char *, int, int);
65 static void enable_delete_command (char *, int);
67 static void enable_delete_breakpoint (struct breakpoint *);
69 static void enable_once_command (char *, int);
71 static void enable_once_breakpoint (struct breakpoint *);
73 static void disable_command (char *, int);
75 static void enable_command (char *, int);
77 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
79 static void ignore_command (char *, int);
81 static int breakpoint_re_set_one (void *);
83 static void clear_command (char *, int);
85 static void catch_command (char *, int);
87 static void watch_command (char *, int);
89 static int can_use_hardware_watchpoint (struct value *);
91 static int break_command_1 (char *, int, int, struct breakpoint *);
93 static void mention (struct breakpoint *);
95 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
97 static void check_duplicates (struct breakpoint *);
99 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
101 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
104 static void describe_other_breakpoints (CORE_ADDR, asection *);
106 static void breakpoints_info (char *, int);
108 static void breakpoint_1 (int, int);
110 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
112 static int breakpoint_cond_eval (void *);
114 static void cleanup_executing_breakpoints (void *);
116 static void commands_command (char *, int);
118 static void condition_command (char *, int);
120 static int get_number_trailer (char **, int);
122 void set_breakpoint_count (int);
131 static int remove_breakpoint (struct bp_location *, insertion_state_t);
133 static enum print_stop_action print_it_typical (bpstat);
135 static enum print_stop_action print_bp_stop_message (bpstat bs);
139 enum exception_event_kind kind;
142 args_for_catchpoint_enable;
144 static int watchpoint_check (void *);
146 static int cover_target_enable_exception_callback (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
170 static void solib_load_unload_1 (char *hookname,
173 char *cond_string, enum bptype bp_kind);
175 static void create_fork_vfork_event_catchpoint (int tempflag,
177 enum bptype bp_kind);
179 static void stop_command (char *arg, int from_tty);
181 static void stopin_command (char *arg, int from_tty);
183 static void stopat_command (char *arg, int from_tty);
185 static char *ep_find_event_name_end (char *arg);
187 static char *ep_parse_optional_if_clause (char **arg);
189 static char *ep_parse_optional_filename (char **arg);
191 static void create_exception_catchpoint (int tempflag, char *cond_string,
192 enum exception_event_kind ex_event,
193 struct symtab_and_line *sal);
195 static void catch_exception_command_1 (enum exception_event_kind ex_event,
196 char *arg, int tempflag, int from_tty);
198 static void tcatch_command (char *arg, int from_tty);
200 static void ep_skip_leading_whitespace (char **s);
202 /* Prototypes for exported functions. */
204 /* If FALSE, gdb will not use hardware support for watchpoints, even
205 if such is available. */
206 static int can_use_hw_watchpoints;
209 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
210 struct cmd_list_element *c,
213 fprintf_filtered (file, _("\
214 Debugger's willingness to use watchpoint hardware is %s.\n"),
218 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
219 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
220 for unrecognized breakpoint locations.
221 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
222 static enum auto_boolean pending_break_support;
224 show_pending_break_support (struct ui_file *file, int from_tty,
225 struct cmd_list_element *c,
228 fprintf_filtered (file, _("\
229 Debugger's behavior regarding pending breakpoints is %s.\n"),
233 void _initialize_breakpoint (void);
235 extern int addressprint; /* Print machine addresses? */
237 /* Are we executing breakpoint commands? */
238 static int executing_breakpoint_commands;
240 /* Are overlay event breakpoints enabled? */
241 static int overlay_events_enabled;
243 /* Walk the following statement or block through all breakpoints.
244 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
247 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
249 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
250 for (B = breakpoint_chain; \
251 B ? (TMP=B->next, 1): 0; \
254 /* Similar iterators for the low-level breakpoints. */
256 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
258 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
259 for (B = bp_location_chain; \
260 B ? (TMP=B->next, 1): 0; \
263 /* True if breakpoint hit counts should be displayed in breakpoint info. */
265 int show_breakpoint_hit_counts = 1;
267 /* Chains of all breakpoints defined. */
269 struct breakpoint *breakpoint_chain;
271 struct bp_location *bp_location_chain;
273 /* Number of last breakpoint made. */
275 int breakpoint_count;
277 /* Pointer to current exception event record */
278 static struct exception_event_record *current_exception_event;
280 /* Indicator of whether exception catchpoints should be nuked between
281 runs of a program. */
282 int deprecated_exception_catchpoints_are_fragile = 0;
284 /* Indicator of when exception catchpoints set-up should be
285 reinitialized -- e.g. when program is re-run. */
286 int deprecated_exception_support_initialized = 0;
288 /* This function returns a pointer to the string representation of the
289 pathname of the dynamically-linked library that has just been
292 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
293 or undefined results are guaranteed.
295 This string's contents are only valid immediately after the
296 inferior has stopped in the dynamic linker hook, and becomes
297 invalid as soon as the inferior is continued. Clients should make
298 a copy of this string if they wish to continue the inferior and
299 then access the string. */
301 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
302 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
305 /* This function returns a pointer to the string representation of the
306 pathname of the dynamically-linked library that has just been
309 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
310 TRUE, or undefined results are guaranteed.
312 This string's contents are only valid immediately after the
313 inferior has stopped in the dynamic linker hook, and becomes
314 invalid as soon as the inferior is continued. Clients should make
315 a copy of this string if they wish to continue the inferior and
316 then access the string. */
318 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
319 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
322 /* This function is called by the "catch load" command. It allows the
323 debugger to be notified by the dynamic linker when a specified
324 library file (or any library file, if filename is NULL) is loaded. */
326 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
327 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
328 error (_("catch of library loads not yet implemented on this platform"))
331 /* This function is called by the "catch unload" command. It allows
332 the debugger to be notified by the dynamic linker when a specified
333 library file (or any library file, if filename is NULL) is
336 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
337 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
338 error (_("catch of library unloads not yet implemented on this platform"))
341 /* Return whether a breakpoint is an active enabled breakpoint. */
343 breakpoint_enabled (struct breakpoint *b)
345 return (b->enable_state == bp_enabled && !b->pending);
348 /* Set breakpoint count to NUM. */
351 set_breakpoint_count (int num)
353 breakpoint_count = num;
354 set_internalvar (lookup_internalvar ("bpnum"),
355 value_from_longest (builtin_type_int, (LONGEST) num));
358 /* Used in run_command to zero the hit count when a new run starts. */
361 clear_breakpoint_hit_counts (void)
363 struct breakpoint *b;
369 /* Default address, symtab and line to put a breakpoint at
370 for "break" command with no arg.
371 if default_breakpoint_valid is zero, the other three are
372 not valid, and "break" with no arg is an error.
374 This set by print_stack_frame, which calls set_default_breakpoint. */
376 int default_breakpoint_valid;
377 CORE_ADDR default_breakpoint_address;
378 struct symtab *default_breakpoint_symtab;
379 int default_breakpoint_line;
381 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
382 Advance *PP after the string and any trailing whitespace.
384 Currently the string can either be a number or "$" followed by the name
385 of a convenience variable. Making it an expression wouldn't work well
386 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
388 TRAILER is a character which can be found after the number; most
389 commonly this is `-'. If you don't want a trailer, use \0. */
391 get_number_trailer (char **pp, int trailer)
393 int retval = 0; /* default */
397 /* Empty line means refer to the last breakpoint. */
398 return breakpoint_count;
401 /* Make a copy of the name, so we can null-terminate it
402 to pass to lookup_internalvar(). */
407 while (isalnum (*p) || *p == '_')
409 varname = (char *) alloca (p - start + 1);
410 strncpy (varname, start, p - start);
411 varname[p - start] = '\0';
412 val = value_of_internalvar (lookup_internalvar (varname));
413 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
414 retval = (int) value_as_long (val);
417 printf_filtered (_("Convenience variable must have integer value.\n"));
425 while (*p >= '0' && *p <= '9')
428 /* There is no number here. (e.g. "cond a == b"). */
430 /* Skip non-numeric token */
431 while (*p && !isspace((int) *p))
433 /* Return zero, which caller must interpret as error. */
439 if (!(isspace (*p) || *p == '\0' || *p == trailer))
441 /* Trailing junk: return 0 and let caller print error msg. */
442 while (!(isspace (*p) || *p == '\0' || *p == trailer))
453 /* Like get_number_trailer, but don't allow a trailer. */
455 get_number (char **pp)
457 return get_number_trailer (pp, '\0');
460 /* Parse a number or a range.
461 * A number will be of the form handled by get_number.
462 * A range will be of the form <number1> - <number2>, and
463 * will represent all the integers between number1 and number2,
466 * While processing a range, this fuction is called iteratively;
467 * At each call it will return the next value in the range.
469 * At the beginning of parsing a range, the char pointer PP will
470 * be advanced past <number1> and left pointing at the '-' token.
471 * Subsequent calls will not advance the pointer until the range
472 * is completed. The call that completes the range will advance
473 * pointer PP past <number2>.
477 get_number_or_range (char **pp)
479 static int last_retval, end_value;
480 static char *end_ptr;
481 static int in_range = 0;
485 /* Default case: pp is pointing either to a solo number,
486 or to the first number of a range. */
487 last_retval = get_number_trailer (pp, '-');
492 /* This is the start of a range (<number1> - <number2>).
493 Skip the '-', parse and remember the second number,
494 and also remember the end of the final token. */
498 while (isspace ((int) *end_ptr))
499 end_ptr++; /* skip white space */
500 end_value = get_number (temp);
501 if (end_value < last_retval)
503 error (_("inverted range"));
505 else if (end_value == last_retval)
507 /* degenerate range (number1 == number2). Advance the
508 token pointer so that the range will be treated as a
517 error (_("negative value"));
520 /* pp points to the '-' that betokens a range. All
521 number-parsing has already been done. Return the next
522 integer value (one greater than the saved previous value).
523 Do not advance the token pointer 'pp' until the end of range
526 if (++last_retval == end_value)
528 /* End of range reached; advance token pointer. */
538 /* condition N EXP -- set break condition of breakpoint N to EXP. */
541 condition_command (char *arg, int from_tty)
543 struct breakpoint *b;
548 error_no_arg (_("breakpoint number"));
551 bnum = get_number (&p);
553 error (_("Bad breakpoint argument: '%s'"), arg);
556 if (b->number == bnum)
563 if (b->cond_string != NULL)
564 xfree (b->cond_string);
569 b->cond_string = NULL;
571 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
576 /* I don't know if it matters whether this is the string the user
577 typed in or the decompiled expression. */
578 b->cond_string = savestring (arg, strlen (arg));
581 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
583 error (_("Junk at end of expression"));
586 breakpoints_changed ();
587 breakpoint_modify_event (b->number);
591 error (_("No breakpoint number %d."), bnum);
595 commands_command (char *arg, int from_tty)
597 struct breakpoint *b;
600 struct command_line *l;
602 /* If we allowed this, we would have problems with when to
603 free the storage, if we change the commands currently
606 if (executing_breakpoint_commands)
607 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
610 bnum = get_number (&p);
613 error (_("Unexpected extra arguments following breakpoint number."));
616 if (b->number == bnum)
618 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
620 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
621 l = read_command_lines (tmpbuf, from_tty);
622 do_cleanups (cleanups);
623 free_command_lines (&b->commands);
625 breakpoints_changed ();
626 breakpoint_modify_event (b->number);
629 error (_("No breakpoint number %d."), bnum);
632 /* Like target_read_memory() but if breakpoints are inserted, return
633 the shadow contents instead of the breakpoints themselves.
635 Read "memory data" from whatever target or inferior we have.
636 Returns zero if successful, errno value if not. EIO is used
637 for address out of bounds. If breakpoints are inserted, returns
638 shadow contents, not the breakpoints themselves. From breakpoint.c. */
641 deprecated_read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr,
645 struct bp_location *b;
646 CORE_ADDR bp_addr = 0;
649 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
650 /* No breakpoints on this machine. */
651 return target_read_memory (memaddr, myaddr, len);
655 if (b->owner->type == bp_none)
656 warning (_("reading through apparently deleted breakpoint #%d?"),
659 if (b->loc_type != bp_loc_software_breakpoint)
663 /* Addresses and length of the part of the breakpoint that
665 /* XXXX The m68k, sh and h8300 have different local and remote
666 breakpoint values. BREAKPOINT_FROM_PC still manages to
667 correctly determine the breakpoints memory address and size
668 for these targets. */
669 bp_addr = b->address;
671 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
676 if (bp_addr + bp_size <= memaddr)
677 /* The breakpoint is entirely before the chunk of memory we
680 if (bp_addr >= memaddr + len)
681 /* The breakpoint is entirely after the chunk of memory we are
684 /* Copy the breakpoint from the shadow contents, and recurse for
685 the things before and after. */
687 /* Offset within shadow_contents. */
690 if (bp_addr < memaddr)
692 /* Only copy the second part of the breakpoint. */
693 bp_size -= memaddr - bp_addr;
694 bptoffset = memaddr - bp_addr;
698 if (bp_addr + bp_size > memaddr + len)
700 /* Only copy the first part of the breakpoint. */
701 bp_size -= (bp_addr + bp_size) - (memaddr + len);
704 memcpy (myaddr + bp_addr - memaddr,
705 b->shadow_contents + bptoffset, bp_size);
707 if (bp_addr > memaddr)
709 /* Copy the section of memory before the breakpoint. */
710 status = deprecated_read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
715 if (bp_addr + bp_size < memaddr + len)
717 /* Copy the section of memory after the breakpoint. */
718 status = deprecated_read_memory_nobpt (bp_addr + bp_size,
719 myaddr + bp_addr + bp_size - memaddr,
720 memaddr + len - (bp_addr + bp_size));
727 /* Nothing overlaps. Just call read_memory_noerr. */
728 return target_read_memory (memaddr, myaddr, len);
732 /* A wrapper function for inserting catchpoints. */
734 insert_catchpoint (struct ui_out *uo, void *args)
736 struct breakpoint *b = (struct breakpoint *) args;
742 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
745 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
748 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
751 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
756 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
758 static void free_valchain (struct bp_location *b)
763 /* Free the saved value chain. We will construct a new one
764 the next time the watchpoint is inserted. */
765 for (v = b->owner->val_chain; v; v = n)
770 b->owner->val_chain = NULL;
773 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
774 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
775 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
777 NOTE drow/2003-09-09: This routine could be broken down to an object-style
778 method for each breakpoint or catchpoint type. */
780 insert_bp_location (struct bp_location *bpt,
781 struct ui_file *tmp_error_stream,
782 int *disabled_breaks, int *process_warning,
783 int *hw_breakpoint_error)
787 /* Permanent breakpoints cannot be inserted or removed. Disabled
788 breakpoints should not be inserted. */
789 if (!breakpoint_enabled (bpt->owner))
792 if (bpt->inserted || bpt->duplicate)
795 if (bpt->loc_type == bp_loc_software_breakpoint
796 || bpt->loc_type == bp_loc_hardware_breakpoint)
798 /* First check to see if we have to handle an overlay. */
799 if (overlay_debugging == ovly_off
800 || bpt->section == NULL
801 || !(section_is_overlay (bpt->section)))
803 /* No overlay handling: just set the breakpoint. */
805 if (bpt->loc_type == bp_loc_hardware_breakpoint)
806 val = target_insert_hw_breakpoint (bpt->address,
807 bpt->shadow_contents);
809 val = target_insert_breakpoint (bpt->address,
810 bpt->shadow_contents);
814 /* This breakpoint is in an overlay section.
815 Shall we set a breakpoint at the LMA? */
816 if (!overlay_events_enabled)
818 /* Yes -- overlay event support is not active,
819 so we must try to set a breakpoint at the LMA.
820 This will not work for a hardware breakpoint. */
821 if (bpt->loc_type == bp_loc_hardware_breakpoint)
822 warning (_("hardware breakpoint %d not supported in overlay!"),
826 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
828 /* Set a software (trap) breakpoint at the LMA. */
829 val = target_insert_breakpoint (addr, bpt->shadow_contents);
831 fprintf_unfiltered (tmp_error_stream,
832 "Overlay breakpoint %d failed: in ROM?",
836 /* Shall we set a breakpoint at the VMA? */
837 if (section_is_mapped (bpt->section))
839 /* Yes. This overlay section is mapped into memory. */
840 if (bpt->loc_type == bp_loc_hardware_breakpoint)
841 val = target_insert_hw_breakpoint (bpt->address,
842 bpt->shadow_contents);
844 val = target_insert_breakpoint (bpt->address,
845 bpt->shadow_contents);
849 /* No. This breakpoint will not be inserted.
850 No error, but do not mark the bp as 'inserted'. */
857 /* Can't set the breakpoint. */
859 #if defined (DISABLE_UNSETTABLE_BREAK)
860 DISABLE_UNSETTABLE_BREAK (bpt->address)
862 solib_address (bpt->address)
866 /* See also: disable_breakpoints_in_shlibs. */
868 bpt->owner->enable_state = bp_shlib_disabled;
869 if (!*disabled_breaks)
871 fprintf_unfiltered (tmp_error_stream,
872 "Cannot insert breakpoint %d.\n",
874 fprintf_unfiltered (tmp_error_stream,
875 "Temporarily disabling shared library breakpoints:\n");
877 *disabled_breaks = 1;
878 fprintf_unfiltered (tmp_error_stream,
879 "breakpoint #%d\n", bpt->owner->number);
883 #ifdef ONE_PROCESS_WRITETEXT
884 *process_warning = 1;
886 if (bpt->loc_type == bp_loc_hardware_breakpoint)
888 *hw_breakpoint_error = 1;
889 fprintf_unfiltered (tmp_error_stream,
890 "Cannot insert hardware breakpoint %d.\n",
895 fprintf_unfiltered (tmp_error_stream,
896 "Cannot insert breakpoint %d.\n",
898 fprintf_filtered (tmp_error_stream,
899 "Error accessing memory address ");
900 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
901 fprintf_filtered (tmp_error_stream, ": %s.\n",
902 safe_strerror (val));
913 else if (bpt->loc_type == bp_loc_hardware_watchpoint
914 /* NOTE drow/2003-09-08: This state only exists for removing
915 watchpoints. It's not clear that it's necessary... */
916 && bpt->owner->disposition != disp_del_at_next_stop)
918 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
919 based on the expression. Ideally this should happen at a higher level,
920 and there should be one bp_location for each computed address we
921 must watch. As soon as a many-to-one mapping is available I'll
924 int within_current_scope;
925 struct value *mark = value_mark ();
927 struct frame_id saved_frame_id;
929 /* Save the current frame's ID so we can restore it after
930 evaluating the watchpoint expression on its own frame. */
931 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
932 took a frame parameter, so that we didn't have to change the
934 saved_frame_id = get_frame_id (deprecated_selected_frame);
936 /* Determine if the watchpoint is within scope. */
937 if (bpt->owner->exp_valid_block == NULL)
938 within_current_scope = 1;
941 struct frame_info *fi;
942 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
943 within_current_scope = (fi != NULL);
944 if (within_current_scope)
948 if (within_current_scope)
952 /* Evaluate the expression and cut the chain of values
953 produced off from the value chain.
955 Make sure the value returned isn't lazy; we use
956 laziness to determine what memory GDB actually needed
957 in order to compute the value of the expression. */
958 v = evaluate_expression (bpt->owner->exp);
960 value_release_to_mark (mark);
962 bpt->owner->val_chain = v;
965 /* Look at each value on the value chain. */
966 for (; v; v = value_next (v))
968 /* If it's a memory location, and GDB actually needed
969 its contents to evaluate the expression, then we
971 if (VALUE_LVAL (v) == lval_memory
974 struct type *vtype = check_typedef (value_type (v));
976 /* We only watch structs and arrays if user asked
977 for it explicitly, never if they just happen to
978 appear in the middle of some value chain. */
979 if (v == bpt->owner->val_chain
980 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
981 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
986 addr = VALUE_ADDRESS (v) + value_offset (v);
987 len = TYPE_LENGTH (value_type (v));
989 if (bpt->owner->type == bp_read_watchpoint)
991 else if (bpt->owner->type == bp_access_watchpoint)
994 val = target_insert_watchpoint (addr, len, type);
997 /* Don't exit the loop, try to insert
998 every value on the value chain. That's
999 because we will be removing all the
1000 watches below, and removing a
1001 watchpoint we didn't insert could have
1009 /* Failure to insert a watchpoint on any memory value in the
1010 value chain brings us here. */
1013 remove_breakpoint (bpt, mark_uninserted);
1014 *hw_breakpoint_error = 1;
1015 fprintf_unfiltered (tmp_error_stream,
1016 "Could not insert hardware watchpoint %d.\n",
1017 bpt->owner->number);
1023 printf_filtered (_("\
1024 Hardware watchpoint %d deleted because the program has left the block \n\
1025 in which its expression is valid.\n"),
1026 bpt->owner->number);
1027 if (bpt->owner->related_breakpoint)
1028 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1029 bpt->owner->disposition = disp_del_at_next_stop;
1032 /* Restore the selected frame. */
1033 select_frame (frame_find_by_id (saved_frame_id));
1038 else if (ep_is_exception_catchpoint (bpt->owner))
1040 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1041 breakpoint. Once again, it would be better if this was represented
1042 as two bp_locations. */
1044 /* If we get here, we must have a callback mechanism for exception
1045 events -- with g++ style embedded label support, we insert
1046 ordinary breakpoints and not catchpoints. */
1047 val = target_insert_breakpoint (bpt->address, bpt->shadow_contents);
1050 /* Couldn't set breakpoint for some reason */
1051 fprintf_unfiltered (tmp_error_stream,
1052 "Cannot insert catchpoint %d; disabling it.\n",
1053 bpt->owner->number);
1054 fprintf_filtered (tmp_error_stream,
1055 "Error accessing memory address ");
1056 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1057 fprintf_filtered (tmp_error_stream, ": %s.\n",
1058 safe_strerror (val));
1059 bpt->owner->enable_state = bp_disabled;
1063 /* Bp set, now make sure callbacks are enabled */
1064 /* Format possible error msg */
1065 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1066 bpt->owner->number);
1067 struct cleanup *cleanups = make_cleanup (xfree, message);
1069 args_for_catchpoint_enable args;
1070 args.kind = bpt->owner->type == bp_catch_catch ?
1071 EX_EVENT_CATCH : EX_EVENT_THROW;
1073 val = catch_errors (cover_target_enable_exception_callback,
1074 &args, message, RETURN_MASK_ALL);
1075 do_cleanups (cleanups);
1076 if (val != 0 && val != -1)
1079 /* Check if something went wrong; val == 0 can be ignored */
1082 /* something went wrong */
1083 fprintf_unfiltered (tmp_error_stream,
1084 "Cannot insert catchpoint %d; disabling it.\n",
1085 bpt->owner->number);
1086 bpt->owner->enable_state = bp_disabled;
1093 else if (bpt->owner->type == bp_catch_fork
1094 || bpt->owner->type == bp_catch_vfork
1095 || bpt->owner->type == bp_catch_exec)
1097 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1098 bpt->owner, RETURN_MASK_ERROR);
1099 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1100 bpt->owner->number);
1102 bpt->owner->enable_state = bp_disabled;
1106 /* We've already printed an error message if there was a problem
1107 inserting this catchpoint, and we've disabled the catchpoint,
1108 so just return success. */
1115 /* insert_breakpoints is used when starting or continuing the program.
1116 remove_breakpoints is used when the program stops.
1117 Both return zero if successful,
1118 or an `errno' value if could not write the inferior. */
1121 insert_breakpoints (void)
1123 struct bp_location *b, *temp;
1124 int return_val = 0; /* return success code. */
1126 int disabled_breaks = 0;
1127 int hw_breakpoint_error = 0;
1128 int process_warning = 0;
1130 struct ui_file *tmp_error_stream = mem_fileopen ();
1131 make_cleanup_ui_file_delete (tmp_error_stream);
1133 /* Explicitly mark the warning -- this will only be printed if
1134 there was an error. */
1135 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1137 ALL_BP_LOCATIONS_SAFE (b, temp)
1139 /* Permanent breakpoints cannot be inserted or removed. Disabled
1140 breakpoints should not be inserted. */
1141 if (!breakpoint_enabled (b->owner))
1144 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1145 hardware watchpoints are split into multiple loc breakpoints. */
1146 if ((b->loc_type == bp_loc_hardware_watchpoint
1147 || b->owner->type == bp_watchpoint) && !b->owner->val)
1150 val = evaluate_expression (b->owner->exp);
1151 release_value (val);
1152 if (value_lazy (val))
1153 value_fetch_lazy (val);
1154 b->owner->val = val;
1157 val = insert_bp_location (b, tmp_error_stream,
1158 &disabled_breaks, &process_warning,
1159 &hw_breakpoint_error);
1166 /* If a hardware breakpoint or watchpoint was inserted, add a
1167 message about possibly exhausted resources. */
1168 if (hw_breakpoint_error)
1170 fprintf_unfiltered (tmp_error_stream,
1171 "Could not insert hardware breakpoints:\n\
1172 You may have requested too many hardware breakpoints/watchpoints.\n");
1174 #ifdef ONE_PROCESS_WRITETEXT
1175 if (process_warning)
1176 fprintf_unfiltered (tmp_error_stream,
1177 "The same program may be running in another process.");
1179 target_terminal_ours_for_output ();
1180 error_stream (tmp_error_stream);
1186 remove_breakpoints (void)
1188 struct bp_location *b;
1191 ALL_BP_LOCATIONS (b)
1195 val = remove_breakpoint (b, mark_uninserted);
1204 remove_hw_watchpoints (void)
1206 struct bp_location *b;
1209 ALL_BP_LOCATIONS (b)
1211 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1213 val = remove_breakpoint (b, mark_uninserted);
1222 reattach_breakpoints (int pid)
1224 struct bp_location *b;
1226 struct cleanup *old_chain = save_inferior_ptid ();
1228 /* Set inferior_ptid; remove_breakpoint uses this global. */
1229 inferior_ptid = pid_to_ptid (pid);
1230 ALL_BP_LOCATIONS (b)
1234 remove_breakpoint (b, mark_inserted);
1235 if (b->loc_type == bp_loc_hardware_breakpoint)
1236 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1238 val = target_insert_breakpoint (b->address, b->shadow_contents);
1239 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1240 breakpoints. It's wrong for watchpoints, for example. */
1243 do_cleanups (old_chain);
1248 do_cleanups (old_chain);
1253 update_breakpoints_after_exec (void)
1255 struct breakpoint *b;
1256 struct breakpoint *temp;
1258 /* Doing this first prevents the badness of having delete_breakpoint()
1259 write a breakpoint's current "shadow contents" to lift the bp. That
1260 shadow is NOT valid after an exec()! */
1261 mark_breakpoints_out ();
1263 ALL_BREAKPOINTS_SAFE (b, temp)
1265 /* Solib breakpoints must be explicitly reset after an exec(). */
1266 if (b->type == bp_shlib_event)
1268 delete_breakpoint (b);
1272 /* Thread event breakpoints must be set anew after an exec(),
1273 as must overlay event breakpoints. */
1274 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1276 delete_breakpoint (b);
1280 /* Step-resume breakpoints are meaningless after an exec(). */
1281 if (b->type == bp_step_resume)
1283 delete_breakpoint (b);
1287 /* Ditto the sigtramp handler breakpoints. */
1288 if (b->type == bp_through_sigtramp)
1290 delete_breakpoint (b);
1294 /* Ditto the exception-handling catchpoints. */
1295 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1297 delete_breakpoint (b);
1301 /* Don't delete an exec catchpoint, because else the inferior
1302 won't stop when it ought!
1304 Similarly, we probably ought to keep vfork catchpoints, 'cause
1305 on this target, we may not be able to stop when the vfork is
1306 seen, but only when the subsequent exec is seen. (And because
1307 deleting fork catchpoints here but not vfork catchpoints will
1308 seem mysterious to users, keep those too.)
1310 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1311 target address field, if any, is sufficient to have it be reset
1312 automagically. Certainly on HP-UX that's true.
1314 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1315 valid code address on some platforms (like the mn10300
1316 simulators). We shouldn't assign any special interpretation to
1317 a breakpoint with a zero address. And in fact, GDB doesn't ---
1318 I can't see what that comment above is talking about. As far
1319 as I can tell, setting the address of a
1320 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1321 is meaningless, since those are implemented with HP-UX kernel
1322 hackery, not by storing breakpoint instructions somewhere. */
1323 if ((b->type == bp_catch_exec) ||
1324 (b->type == bp_catch_vfork) ||
1325 (b->type == bp_catch_fork))
1327 b->loc->address = (CORE_ADDR) NULL;
1331 /* bp_finish is a special case. The only way we ought to be able
1332 to see one of these when an exec() has happened, is if the user
1333 caught a vfork, and then said "finish". Ordinarily a finish just
1334 carries them to the call-site of the current callee, by setting
1335 a temporary bp there and resuming. But in this case, the finish
1336 will carry them entirely through the vfork & exec.
1338 We don't want to allow a bp_finish to remain inserted now. But
1339 we can't safely delete it, 'cause finish_command has a handle to
1340 the bp on a bpstat, and will later want to delete it. There's a
1341 chance (and I've seen it happen) that if we delete the bp_finish
1342 here, that its storage will get reused by the time finish_command
1343 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1344 We really must allow finish_command to delete a bp_finish.
1346 In the absense of a general solution for the "how do we know
1347 it's safe to delete something others may have handles to?"
1348 problem, what we'll do here is just uninsert the bp_finish, and
1349 let finish_command delete it.
1351 (We know the bp_finish is "doomed" in the sense that it's
1352 momentary, and will be deleted as soon as finish_command sees
1353 the inferior stopped. So it doesn't matter that the bp's
1354 address is probably bogus in the new a.out, unlike e.g., the
1355 solib breakpoints.) */
1357 if (b->type == bp_finish)
1362 /* Without a symbolic address, we have little hope of the
1363 pre-exec() address meaning the same thing in the post-exec()
1365 if (b->addr_string == NULL)
1367 delete_breakpoint (b);
1371 /* If this breakpoint has survived the above battery of checks, then
1372 it must have a symbolic address. Be sure that it gets reevaluated
1373 to a target address, rather than reusing the old evaluation.
1375 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1376 for bp_catch_exec and friends, I'm pretty sure this is entirely
1377 unnecessary. A call to breakpoint_re_set_one always recomputes
1378 the breakpoint's address from scratch, or deletes it if it can't.
1379 So I think this assignment could be deleted without effect. */
1380 b->loc->address = (CORE_ADDR) NULL;
1382 /* FIXME what about longjmp breakpoints? Re-create them here? */
1383 create_overlay_event_breakpoint ("_ovly_debug_event");
1387 detach_breakpoints (int pid)
1389 struct bp_location *b;
1391 struct cleanup *old_chain = save_inferior_ptid ();
1393 if (pid == PIDGET (inferior_ptid))
1394 error (_("Cannot detach breakpoints of inferior_ptid"));
1396 /* Set inferior_ptid; remove_breakpoint uses this global. */
1397 inferior_ptid = pid_to_ptid (pid);
1398 ALL_BP_LOCATIONS (b)
1402 val = remove_breakpoint (b, mark_inserted);
1405 do_cleanups (old_chain);
1410 do_cleanups (old_chain);
1415 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1419 if (b->owner->enable_state == bp_permanent)
1420 /* Permanent breakpoints cannot be inserted or removed. */
1423 if (b->owner->type == bp_none)
1424 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1427 if (b->loc_type == bp_loc_software_breakpoint
1428 || b->loc_type == bp_loc_hardware_breakpoint)
1430 /* "Normal" instruction breakpoint: either the standard
1431 trap-instruction bp (bp_breakpoint), or a
1432 bp_hardware_breakpoint. */
1434 /* First check to see if we have to handle an overlay. */
1435 if (overlay_debugging == ovly_off
1436 || b->section == NULL
1437 || !(section_is_overlay (b->section)))
1439 /* No overlay handling: just remove the breakpoint. */
1441 if (b->loc_type == bp_loc_hardware_breakpoint)
1442 val = target_remove_hw_breakpoint (b->address,
1443 b->shadow_contents);
1445 val = target_remove_breakpoint (b->address, b->shadow_contents);
1449 /* This breakpoint is in an overlay section.
1450 Did we set a breakpoint at the LMA? */
1451 if (!overlay_events_enabled)
1453 /* Yes -- overlay event support is not active, so we
1454 should have set a breakpoint at the LMA. Remove it.
1456 CORE_ADDR addr = overlay_unmapped_address (b->address,
1458 /* Ignore any failures: if the LMA is in ROM, we will
1459 have already warned when we failed to insert it. */
1460 if (b->loc_type == bp_loc_hardware_breakpoint)
1461 target_remove_hw_breakpoint (addr, b->shadow_contents);
1463 target_remove_breakpoint (addr, b->shadow_contents);
1465 /* Did we set a breakpoint at the VMA?
1466 If so, we will have marked the breakpoint 'inserted'. */
1469 /* Yes -- remove it. Previously we did not bother to
1470 remove the breakpoint if the section had been
1471 unmapped, but let's not rely on that being safe. We
1472 don't know what the overlay manager might do. */
1473 if (b->loc_type == bp_loc_hardware_breakpoint)
1474 val = target_remove_hw_breakpoint (b->address,
1475 b->shadow_contents);
1477 val = target_remove_breakpoint (b->address,
1478 b->shadow_contents);
1482 /* No -- not inserted, so no need to remove. No error. */
1488 b->inserted = (is == mark_inserted);
1490 else if (b->loc_type == bp_loc_hardware_watchpoint
1491 && breakpoint_enabled (b->owner)
1497 b->inserted = (is == mark_inserted);
1498 /* Walk down the saved value chain. */
1499 for (v = b->owner->val_chain; v; v = value_next (v))
1501 /* For each memory reference remove the watchpoint
1503 if (VALUE_LVAL (v) == lval_memory
1504 && ! value_lazy (v))
1506 struct type *vtype = check_typedef (value_type (v));
1508 if (v == b->owner->val_chain
1509 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1510 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1515 addr = VALUE_ADDRESS (v) + value_offset (v);
1516 len = TYPE_LENGTH (value_type (v));
1518 if (b->owner->type == bp_read_watchpoint)
1520 else if (b->owner->type == bp_access_watchpoint)
1523 val = target_remove_watchpoint (addr, len, type);
1530 /* Failure to remove any of the hardware watchpoints comes here. */
1531 if ((is == mark_uninserted) && (b->inserted))
1532 warning (_("Could not remove hardware watchpoint %d."),
1535 else if ((b->owner->type == bp_catch_fork ||
1536 b->owner->type == bp_catch_vfork ||
1537 b->owner->type == bp_catch_exec)
1538 && breakpoint_enabled (b->owner)
1542 switch (b->owner->type)
1545 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1547 case bp_catch_vfork:
1548 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1551 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1554 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1559 b->inserted = (is == mark_inserted);
1561 else if ((b->owner->type == bp_catch_catch ||
1562 b->owner->type == bp_catch_throw)
1563 && breakpoint_enabled (b->owner)
1567 val = target_remove_breakpoint (b->address, b->shadow_contents);
1570 b->inserted = (is == mark_inserted);
1572 else if (ep_is_exception_catchpoint (b->owner)
1573 && b->inserted /* sometimes previous insert doesn't happen */
1574 && breakpoint_enabled (b->owner)
1578 val = target_remove_breakpoint (b->address, b->shadow_contents);
1582 b->inserted = (is == mark_inserted);
1588 /* Clear the "inserted" flag in all breakpoints. */
1591 mark_breakpoints_out (void)
1593 struct bp_location *bpt;
1595 ALL_BP_LOCATIONS (bpt)
1599 /* Clear the "inserted" flag in all breakpoints and delete any
1600 breakpoints which should go away between runs of the program.
1602 Plus other such housekeeping that has to be done for breakpoints
1605 Note: this function gets called at the end of a run (by
1606 generic_mourn_inferior) and when a run begins (by
1607 init_wait_for_inferior). */
1612 breakpoint_init_inferior (enum inf_context context)
1614 struct breakpoint *b, *temp;
1615 struct bp_location *bpt;
1616 static int warning_needed = 0;
1618 ALL_BP_LOCATIONS (bpt)
1621 ALL_BREAKPOINTS_SAFE (b, temp)
1626 case bp_watchpoint_scope:
1628 /* If the call dummy breakpoint is at the entry point it will
1629 cause problems when the inferior is rerun, so we better
1632 Also get rid of scope breakpoints. */
1633 delete_breakpoint (b);
1637 case bp_hardware_watchpoint:
1638 case bp_read_watchpoint:
1639 case bp_access_watchpoint:
1641 /* Likewise for watchpoints on local expressions. */
1642 if (b->exp_valid_block != NULL)
1643 delete_breakpoint (b);
1644 if (context == inf_starting)
1646 /* Reset val field to force reread of starting value
1647 in insert_breakpoints. */
1649 value_free (b->val);
1654 /* Likewise for exception catchpoints in dynamic-linked
1655 executables where required */
1656 if (ep_is_exception_catchpoint (b)
1657 && deprecated_exception_catchpoints_are_fragile)
1660 delete_breakpoint (b);
1666 if (deprecated_exception_catchpoints_are_fragile)
1667 deprecated_exception_support_initialized = 0;
1669 /* Don't issue the warning unless it's really needed... */
1670 if (warning_needed && (context != inf_exited))
1672 warning (_("Exception catchpoints from last run were deleted.\n"
1673 "You must reinsert them explicitly."));
1678 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1679 exists at PC. It returns ordinary_breakpoint_here if it's an
1680 ordinary breakpoint, or permanent_breakpoint_here if it's a
1681 permanent breakpoint.
1682 - When continuing from a location with an ordinary breakpoint, we
1683 actually single step once before calling insert_breakpoints.
1684 - When continuing from a localion with a permanent breakpoint, we
1685 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1686 the target, to advance the PC past the breakpoint. */
1688 enum breakpoint_here
1689 breakpoint_here_p (CORE_ADDR pc)
1691 struct bp_location *bpt;
1692 int any_breakpoint_here = 0;
1694 ALL_BP_LOCATIONS (bpt)
1696 if (bpt->loc_type != bp_loc_software_breakpoint
1697 && bpt->loc_type != bp_loc_hardware_breakpoint)
1700 if ((breakpoint_enabled (bpt->owner)
1701 || bpt->owner->enable_state == bp_permanent)
1702 && bpt->address == pc) /* bp is enabled and matches pc */
1704 if (overlay_debugging
1705 && section_is_overlay (bpt->section)
1706 && !section_is_mapped (bpt->section))
1707 continue; /* unmapped overlay -- can't be a match */
1708 else if (bpt->owner->enable_state == bp_permanent)
1709 return permanent_breakpoint_here;
1711 any_breakpoint_here = 1;
1715 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1719 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1720 but it only returns true if there is actually a breakpoint inserted
1724 breakpoint_inserted_here_p (CORE_ADDR pc)
1726 struct bp_location *bpt;
1728 ALL_BP_LOCATIONS (bpt)
1730 if (bpt->loc_type != bp_loc_software_breakpoint
1731 && bpt->loc_type != bp_loc_hardware_breakpoint)
1735 && bpt->address == pc) /* bp is inserted and matches pc */
1737 if (overlay_debugging
1738 && section_is_overlay (bpt->section)
1739 && !section_is_mapped (bpt->section))
1740 continue; /* unmapped overlay -- can't be a match */
1749 /* This function returns non-zero iff there is a software breakpoint
1753 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1755 struct bp_location *bpt;
1756 int any_breakpoint_here = 0;
1758 ALL_BP_LOCATIONS (bpt)
1760 if (bpt->loc_type != bp_loc_software_breakpoint)
1763 if ((breakpoint_enabled (bpt->owner)
1764 || bpt->owner->enable_state == bp_permanent)
1766 && bpt->address == pc) /* bp is enabled and matches pc */
1768 if (overlay_debugging
1769 && section_is_overlay (bpt->section)
1770 && !section_is_mapped (bpt->section))
1771 continue; /* unmapped overlay -- can't be a match */
1780 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1781 PC is valid for process/thread PTID. */
1784 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1786 struct bp_location *bpt;
1789 thread = pid_to_thread_id (ptid);
1791 ALL_BP_LOCATIONS (bpt)
1793 if (bpt->loc_type != bp_loc_software_breakpoint
1794 && bpt->loc_type != bp_loc_hardware_breakpoint)
1797 if ((breakpoint_enabled (bpt->owner)
1798 || bpt->owner->enable_state == bp_permanent)
1799 && bpt->address == pc
1800 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1802 if (overlay_debugging
1803 && section_is_overlay (bpt->section)
1804 && !section_is_mapped (bpt->section))
1805 continue; /* unmapped overlay -- can't be a match */
1815 /* bpstat stuff. External routines' interfaces are documented
1819 ep_is_catchpoint (struct breakpoint *ep)
1822 (ep->type == bp_catch_load)
1823 || (ep->type == bp_catch_unload)
1824 || (ep->type == bp_catch_fork)
1825 || (ep->type == bp_catch_vfork)
1826 || (ep->type == bp_catch_exec)
1827 || (ep->type == bp_catch_catch)
1828 || (ep->type == bp_catch_throw);
1830 /* ??rehrauer: Add more kinds here, as are implemented... */
1834 ep_is_shlib_catchpoint (struct breakpoint *ep)
1837 (ep->type == bp_catch_load)
1838 || (ep->type == bp_catch_unload);
1842 ep_is_exception_catchpoint (struct breakpoint *ep)
1845 (ep->type == bp_catch_catch)
1846 || (ep->type == bp_catch_throw);
1849 /* Clear a bpstat so that it says we are not at any breakpoint.
1850 Also free any storage that is part of a bpstat. */
1853 bpstat_clear (bpstat *bsp)
1864 if (p->old_val != NULL)
1865 value_free (p->old_val);
1866 free_command_lines (&p->commands);
1873 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1874 is part of the bpstat is copied as well. */
1877 bpstat_copy (bpstat bs)
1881 bpstat retval = NULL;
1886 for (; bs != NULL; bs = bs->next)
1888 tmp = (bpstat) xmalloc (sizeof (*tmp));
1889 memcpy (tmp, bs, sizeof (*tmp));
1890 if (bs->commands != NULL)
1891 tmp->commands = copy_command_lines (bs->commands);
1892 if (bs->old_val != NULL)
1893 tmp->old_val = value_copy (bs->old_val);
1896 /* This is the first thing in the chain. */
1906 /* Find the bpstat associated with this breakpoint */
1909 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1914 for (; bsp != NULL; bsp = bsp->next)
1916 if (bsp->breakpoint_at == breakpoint)
1922 /* Find a step_resume breakpoint associated with this bpstat.
1923 (If there are multiple step_resume bp's on the list, this function
1924 will arbitrarily pick one.)
1926 It is an error to use this function if BPSTAT doesn't contain a
1927 step_resume breakpoint.
1929 See wait_for_inferior's use of this function. */
1931 bpstat_find_step_resume_breakpoint (bpstat bsp)
1935 gdb_assert (bsp != NULL);
1937 current_thread = pid_to_thread_id (inferior_ptid);
1939 for (; bsp != NULL; bsp = bsp->next)
1941 if ((bsp->breakpoint_at != NULL) &&
1942 (bsp->breakpoint_at->type == bp_step_resume) &&
1943 (bsp->breakpoint_at->thread == current_thread ||
1944 bsp->breakpoint_at->thread == -1))
1945 return bsp->breakpoint_at;
1948 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
1952 /* Return the breakpoint number of the first breakpoint we are stopped
1953 at. *BSP upon return is a bpstat which points to the remaining
1954 breakpoints stopped at (but which is not guaranteed to be good for
1955 anything but further calls to bpstat_num).
1956 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1959 bpstat_num (bpstat *bsp)
1961 struct breakpoint *b;
1964 return 0; /* No more breakpoint values */
1967 b = (*bsp)->breakpoint_at;
1968 *bsp = (*bsp)->next;
1970 return -1; /* breakpoint that's been deleted since */
1972 return b->number; /* We have its number */
1976 /* Modify BS so that the actions will not be performed. */
1979 bpstat_clear_actions (bpstat bs)
1981 for (; bs != NULL; bs = bs->next)
1983 free_command_lines (&bs->commands);
1984 if (bs->old_val != NULL)
1986 value_free (bs->old_val);
1992 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1994 cleanup_executing_breakpoints (void *ignore)
1996 executing_breakpoint_commands = 0;
1999 /* Execute all the commands associated with all the breakpoints at this
2000 location. Any of these commands could cause the process to proceed
2001 beyond this point, etc. We look out for such changes by checking
2002 the global "breakpoint_proceeded" after each command. */
2005 bpstat_do_actions (bpstat *bsp)
2008 struct cleanup *old_chain;
2010 /* Avoid endless recursion if a `source' command is contained
2012 if (executing_breakpoint_commands)
2015 executing_breakpoint_commands = 1;
2016 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2019 /* Note that (as of this writing), our callers all appear to
2020 be passing us the address of global stop_bpstat. And, if
2021 our calls to execute_control_command cause the inferior to
2022 proceed, that global (and hence, *bsp) will change.
2024 We must be careful to not touch *bsp unless the inferior
2025 has not proceeded. */
2027 /* This pointer will iterate over the list of bpstat's. */
2030 breakpoint_proceeded = 0;
2031 for (; bs != NULL; bs = bs->next)
2033 struct command_line *cmd;
2034 struct cleanup *this_cmd_tree_chain;
2036 /* Take ownership of the BSP's command tree, if it has one.
2038 The command tree could legitimately contain commands like
2039 'step' and 'next', which call clear_proceed_status, which
2040 frees stop_bpstat's command tree. To make sure this doesn't
2041 free the tree we're executing out from under us, we need to
2042 take ownership of the tree ourselves. Since a given bpstat's
2043 commands are only executed once, we don't need to copy it; we
2044 can clear the pointer in the bpstat, and make sure we free
2045 the tree when we're done. */
2048 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2052 execute_control_command (cmd);
2054 if (breakpoint_proceeded)
2060 /* We can free this command tree now. */
2061 do_cleanups (this_cmd_tree_chain);
2063 if (breakpoint_proceeded)
2064 /* The inferior is proceeded by the command; bomb out now.
2065 The bpstat chain has been blown away by wait_for_inferior.
2066 But since execution has stopped again, there is a new bpstat
2067 to look at, so start over. */
2070 do_cleanups (old_chain);
2073 /* This is the normal print function for a bpstat. In the future,
2074 much of this logic could (should?) be moved to bpstat_stop_status,
2075 by having it set different print_it values.
2077 Current scheme: When we stop, bpstat_print() is called. It loops
2078 through the bpstat list of things causing this stop, calling the
2079 print_bp_stop_message function on each one. The behavior of the
2080 print_bp_stop_message function depends on the print_it field of
2081 bpstat. If such field so indicates, call this function here.
2083 Return values from this routine (ultimately used by bpstat_print()
2084 and normal_stop() to decide what to do):
2085 PRINT_NOTHING: Means we already printed all we needed to print,
2086 don't print anything else.
2087 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2088 that something to be followed by a location.
2089 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2090 that something to be followed by a location.
2091 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2094 static enum print_stop_action
2095 print_it_typical (bpstat bs)
2097 struct cleanup *old_chain, *ui_out_chain;
2098 struct ui_stream *stb;
2099 stb = ui_out_stream_new (uiout);
2100 old_chain = make_cleanup_ui_out_stream_delete (stb);
2101 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2102 which has since been deleted. */
2103 if (bs->breakpoint_at == NULL)
2104 return PRINT_UNKNOWN;
2106 switch (bs->breakpoint_at->type)
2109 case bp_hardware_breakpoint:
2110 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2111 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2112 bs->breakpoint_at->loc->address,
2113 bs->breakpoint_at->number, 1);
2114 annotate_breakpoint (bs->breakpoint_at->number);
2115 ui_out_text (uiout, "\nBreakpoint ");
2116 if (ui_out_is_mi_like_p (uiout))
2117 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2118 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2119 ui_out_text (uiout, ", ");
2120 return PRINT_SRC_AND_LOC;
2123 case bp_shlib_event:
2124 /* Did we stop because the user set the stop_on_solib_events
2125 variable? (If so, we report this as a generic, "Stopped due
2126 to shlib event" message.) */
2127 printf_filtered (_("Stopped due to shared library event\n"));
2128 return PRINT_NOTHING;
2131 case bp_thread_event:
2132 /* Not sure how we will get here.
2133 GDB should not stop for these breakpoints. */
2134 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2135 return PRINT_NOTHING;
2138 case bp_overlay_event:
2139 /* By analogy with the thread event, GDB should not stop for these. */
2140 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2141 return PRINT_NOTHING;
2145 annotate_catchpoint (bs->breakpoint_at->number);
2146 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2147 bs->breakpoint_at->number,
2148 bs->breakpoint_at->triggered_dll_pathname);
2149 return PRINT_SRC_AND_LOC;
2152 case bp_catch_unload:
2153 annotate_catchpoint (bs->breakpoint_at->number);
2154 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2155 bs->breakpoint_at->number,
2156 bs->breakpoint_at->triggered_dll_pathname);
2157 return PRINT_SRC_AND_LOC;
2161 annotate_catchpoint (bs->breakpoint_at->number);
2162 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2163 bs->breakpoint_at->number,
2164 bs->breakpoint_at->forked_inferior_pid);
2165 return PRINT_SRC_AND_LOC;
2168 case bp_catch_vfork:
2169 annotate_catchpoint (bs->breakpoint_at->number);
2170 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2171 bs->breakpoint_at->number,
2172 bs->breakpoint_at->forked_inferior_pid);
2173 return PRINT_SRC_AND_LOC;
2177 annotate_catchpoint (bs->breakpoint_at->number);
2178 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2179 bs->breakpoint_at->number,
2180 bs->breakpoint_at->exec_pathname);
2181 return PRINT_SRC_AND_LOC;
2184 case bp_catch_catch:
2185 if (current_exception_event &&
2186 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2188 annotate_catchpoint (bs->breakpoint_at->number);
2189 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2190 bs->breakpoint_at->number);
2191 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2192 printf_filtered (_("throw location %s:%d, "),
2193 CURRENT_EXCEPTION_THROW_FILE,
2194 CURRENT_EXCEPTION_THROW_LINE);
2196 printf_filtered (_("throw location unknown, "));
2198 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2199 printf_filtered (_("catch location %s:%d\n"),
2200 CURRENT_EXCEPTION_CATCH_FILE,
2201 CURRENT_EXCEPTION_CATCH_LINE);
2203 printf_filtered (_("catch location unknown\n"));
2205 /* don't bother to print location frame info */
2206 return PRINT_SRC_ONLY;
2210 /* really throw, some other bpstat will handle it */
2211 return PRINT_UNKNOWN;
2215 case bp_catch_throw:
2216 if (current_exception_event &&
2217 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2219 annotate_catchpoint (bs->breakpoint_at->number);
2220 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2221 bs->breakpoint_at->number);
2222 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2223 printf_filtered (_("throw location %s:%d, "),
2224 CURRENT_EXCEPTION_THROW_FILE,
2225 CURRENT_EXCEPTION_THROW_LINE);
2227 printf_filtered (_("throw location unknown, "));
2229 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2230 printf_filtered (_("catch location %s:%d\n"),
2231 CURRENT_EXCEPTION_CATCH_FILE,
2232 CURRENT_EXCEPTION_CATCH_LINE);
2234 printf_filtered (_("catch location unknown\n"));
2236 /* don't bother to print location frame info */
2237 return PRINT_SRC_ONLY;
2241 /* really catch, some other bpstat will handle it */
2242 return PRINT_UNKNOWN;
2247 case bp_hardware_watchpoint:
2248 if (bs->old_val != NULL)
2250 annotate_watchpoint (bs->breakpoint_at->number);
2251 if (ui_out_is_mi_like_p (uiout))
2252 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2253 mention (bs->breakpoint_at);
2254 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2255 ui_out_text (uiout, "\nOld value = ");
2256 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2257 ui_out_field_stream (uiout, "old", stb);
2258 ui_out_text (uiout, "\nNew value = ");
2259 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2260 ui_out_field_stream (uiout, "new", stb);
2261 do_cleanups (ui_out_chain);
2262 ui_out_text (uiout, "\n");
2263 value_free (bs->old_val);
2266 /* More than one watchpoint may have been triggered. */
2267 return PRINT_UNKNOWN;
2270 case bp_read_watchpoint:
2271 if (ui_out_is_mi_like_p (uiout))
2272 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2273 mention (bs->breakpoint_at);
2274 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2275 ui_out_text (uiout, "\nValue = ");
2276 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2277 ui_out_field_stream (uiout, "value", stb);
2278 do_cleanups (ui_out_chain);
2279 ui_out_text (uiout, "\n");
2280 return PRINT_UNKNOWN;
2283 case bp_access_watchpoint:
2284 if (bs->old_val != NULL)
2286 annotate_watchpoint (bs->breakpoint_at->number);
2287 if (ui_out_is_mi_like_p (uiout))
2288 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2289 mention (bs->breakpoint_at);
2290 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2291 ui_out_text (uiout, "\nOld value = ");
2292 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2293 ui_out_field_stream (uiout, "old", stb);
2294 value_free (bs->old_val);
2296 ui_out_text (uiout, "\nNew value = ");
2300 mention (bs->breakpoint_at);
2301 if (ui_out_is_mi_like_p (uiout))
2302 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2303 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2304 ui_out_text (uiout, "\nValue = ");
2306 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2307 ui_out_field_stream (uiout, "new", stb);
2308 do_cleanups (ui_out_chain);
2309 ui_out_text (uiout, "\n");
2310 return PRINT_UNKNOWN;
2313 /* Fall through, we don't deal with these types of breakpoints
2317 if (ui_out_is_mi_like_p (uiout))
2318 ui_out_field_string (uiout, "reason", "function-finished");
2319 return PRINT_UNKNOWN;
2323 if (ui_out_is_mi_like_p (uiout))
2324 ui_out_field_string (uiout, "reason", "location-reached");
2325 return PRINT_UNKNOWN;
2330 case bp_longjmp_resume:
2331 case bp_step_resume:
2332 case bp_through_sigtramp:
2333 case bp_watchpoint_scope:
2336 return PRINT_UNKNOWN;
2340 /* Generic routine for printing messages indicating why we
2341 stopped. The behavior of this function depends on the value
2342 'print_it' in the bpstat structure. Under some circumstances we
2343 may decide not to print anything here and delegate the task to
2346 static enum print_stop_action
2347 print_bp_stop_message (bpstat bs)
2349 switch (bs->print_it)
2352 /* Nothing should be printed for this bpstat entry. */
2353 return PRINT_UNKNOWN;
2357 /* We still want to print the frame, but we already printed the
2358 relevant messages. */
2359 return PRINT_SRC_AND_LOC;
2362 case print_it_normal:
2363 /* Normal case. Call the breakpoint's print_it method, or
2364 print_it_typical. */
2365 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2366 && bs->breakpoint_at->ops->print_it != NULL)
2367 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2369 return print_it_typical (bs);
2373 internal_error (__FILE__, __LINE__,
2374 _("print_bp_stop_message: unrecognized enum value"));
2379 /* Print a message indicating what happened. This is called from
2380 normal_stop(). The input to this routine is the head of the bpstat
2381 list - a list of the eventpoints that caused this stop. This
2382 routine calls the generic print routine for printing a message
2383 about reasons for stopping. This will print (for example) the
2384 "Breakpoint n," part of the output. The return value of this
2387 PRINT_UNKNOWN: Means we printed nothing
2388 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2389 code to print the location. An example is
2390 "Breakpoint 1, " which should be followed by
2392 PRINT_SRC_ONLY: Means we printed something, but there is no need
2393 to also print the location part of the message.
2394 An example is the catch/throw messages, which
2395 don't require a location appended to the end.
2396 PRINT_NOTHING: We have done some printing and we don't need any
2397 further info to be printed.*/
2399 enum print_stop_action
2400 bpstat_print (bpstat bs)
2404 /* Maybe another breakpoint in the chain caused us to stop.
2405 (Currently all watchpoints go on the bpstat whether hit or not.
2406 That probably could (should) be changed, provided care is taken
2407 with respect to bpstat_explains_signal). */
2408 for (; bs; bs = bs->next)
2410 val = print_bp_stop_message (bs);
2411 if (val == PRINT_SRC_ONLY
2412 || val == PRINT_SRC_AND_LOC
2413 || val == PRINT_NOTHING)
2417 /* We reached the end of the chain, or we got a null BS to start
2418 with and nothing was printed. */
2419 return PRINT_UNKNOWN;
2422 /* Evaluate the expression EXP and return 1 if value is zero.
2423 This is used inside a catch_errors to evaluate the breakpoint condition.
2424 The argument is a "struct expression *" that has been cast to char * to
2425 make it pass through catch_errors. */
2428 breakpoint_cond_eval (void *exp)
2430 struct value *mark = value_mark ();
2431 int i = !value_true (evaluate_expression ((struct expression *) exp));
2432 value_free_to_mark (mark);
2436 /* Allocate a new bpstat and chain it to the current one. */
2439 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2443 bs = (bpstat) xmalloc (sizeof (*bs));
2445 bs->breakpoint_at = b;
2446 /* If the condition is false, etc., don't do the commands. */
2447 bs->commands = NULL;
2449 bs->print_it = print_it_normal;
2453 /* Possible return values for watchpoint_check (this can't be an enum
2454 because of check_errors). */
2455 /* The watchpoint has been deleted. */
2456 #define WP_DELETED 1
2457 /* The value has changed. */
2458 #define WP_VALUE_CHANGED 2
2459 /* The value has not changed. */
2460 #define WP_VALUE_NOT_CHANGED 3
2462 #define BP_TEMPFLAG 1
2463 #define BP_HARDWAREFLAG 2
2465 /* Check watchpoint condition. */
2468 watchpoint_check (void *p)
2470 bpstat bs = (bpstat) p;
2471 struct breakpoint *b;
2472 struct frame_info *fr;
2473 int within_current_scope;
2475 b = bs->breakpoint_at;
2477 if (b->exp_valid_block == NULL)
2478 within_current_scope = 1;
2481 /* There is no current frame at this moment. If we're going to have
2482 any chance of handling watchpoints on local variables, we'll need
2483 the frame chain (so we can determine if we're in scope). */
2484 reinit_frame_cache ();
2485 fr = frame_find_by_id (b->watchpoint_frame);
2486 within_current_scope = (fr != NULL);
2487 /* in_function_epilogue_p() returns a non-zero value if we're still
2488 in the function but the stack frame has already been invalidated.
2489 Since we can't rely on the values of local variables after the
2490 stack has been destroyed, we are treating the watchpoint in that
2491 state as `not changed' without further checking.
2493 vinschen/2003-09-04: The former implementation left out the case
2494 that the watchpoint frame couldn't be found by frame_find_by_id()
2495 because the current PC is currently in an epilogue. Calling
2496 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2497 if ((!within_current_scope || fr == get_current_frame ())
2498 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2499 return WP_VALUE_NOT_CHANGED;
2500 if (fr && within_current_scope)
2501 /* If we end up stopping, the current frame will get selected
2502 in normal_stop. So this call to select_frame won't affect
2507 if (within_current_scope)
2509 /* We use value_{,free_to_}mark because it could be a
2510 *long* time before we return to the command level and
2511 call free_all_values. We can't call free_all_values because
2512 we might be in the middle of evaluating a function call. */
2514 struct value *mark = value_mark ();
2515 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2516 if (!value_equal (b->val, new_val))
2518 release_value (new_val);
2519 value_free_to_mark (mark);
2520 bs->old_val = b->val;
2522 /* We will stop here */
2523 return WP_VALUE_CHANGED;
2527 /* Nothing changed, don't do anything. */
2528 value_free_to_mark (mark);
2529 /* We won't stop here */
2530 return WP_VALUE_NOT_CHANGED;
2535 /* This seems like the only logical thing to do because
2536 if we temporarily ignored the watchpoint, then when
2537 we reenter the block in which it is valid it contains
2538 garbage (in the case of a function, it may have two
2539 garbage values, one before and one after the prologue).
2540 So we can't even detect the first assignment to it and
2541 watch after that (since the garbage may or may not equal
2542 the first value assigned). */
2543 /* We print all the stop information in print_it_typical(), but
2544 in this case, by the time we call print_it_typical() this bp
2545 will be deleted already. So we have no choice but print the
2546 information here. */
2547 if (ui_out_is_mi_like_p (uiout))
2548 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2549 ui_out_text (uiout, "\nWatchpoint ");
2550 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2551 ui_out_text (uiout, " deleted because the program has left the block in\n\
2552 which its expression is valid.\n");
2554 if (b->related_breakpoint)
2555 b->related_breakpoint->disposition = disp_del_at_next_stop;
2556 b->disposition = disp_del_at_next_stop;
2562 /* Get a bpstat associated with having just stopped at address
2563 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2564 target thinks we stopped due to a hardware watchpoint, 0 if we
2565 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2567 /* Determine whether we stopped at a breakpoint, etc, or whether we
2568 don't understand this stop. Result is a chain of bpstat's such that:
2570 if we don't understand the stop, the result is a null pointer.
2572 if we understand why we stopped, the result is not null.
2574 Each element of the chain refers to a particular breakpoint or
2575 watchpoint at which we have stopped. (We may have stopped for
2576 several reasons concurrently.)
2578 Each element of the chain has valid next, breakpoint_at,
2579 commands, FIXME??? fields. */
2582 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
2584 struct breakpoint *b, *temp;
2585 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2586 int real_breakpoint = 0;
2587 /* Root of the chain of bpstat's */
2588 struct bpstats root_bs[1];
2589 /* Pointer to the last thing in the chain currently. */
2590 bpstat bs = root_bs;
2591 int thread_id = pid_to_thread_id (ptid);
2593 ALL_BREAKPOINTS_SAFE (b, temp)
2595 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2598 if (b->type != bp_watchpoint
2599 && b->type != bp_hardware_watchpoint
2600 && b->type != bp_read_watchpoint
2601 && b->type != bp_access_watchpoint
2602 && b->type != bp_hardware_breakpoint
2603 && b->type != bp_catch_fork
2604 && b->type != bp_catch_vfork
2605 && b->type != bp_catch_exec
2606 && b->type != bp_catch_catch
2607 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2609 if (b->loc->address != bp_addr) /* address doesn't match */
2611 if (overlay_debugging /* unmapped overlay section */
2612 && section_is_overlay (b->loc->section)
2613 && !section_is_mapped (b->loc->section))
2617 /* Continuable hardware watchpoints are treated as non-existent if the
2618 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2619 some data address). Otherwise gdb won't stop on a break instruction
2620 in the code (not from a breakpoint) when a hardware watchpoint has
2623 if ((b->type == bp_hardware_watchpoint
2624 || b->type == bp_read_watchpoint
2625 || b->type == bp_access_watchpoint)
2626 && !stopped_by_watchpoint)
2629 if (b->type == bp_hardware_breakpoint)
2631 if (b->loc->address != bp_addr)
2633 if (overlay_debugging /* unmapped overlay section */
2634 && section_is_overlay (b->loc->section)
2635 && !section_is_mapped (b->loc->section))
2639 /* Is this a catchpoint of a load or unload? If so, did we
2640 get a load or unload of the specified library? If not,
2642 if ((b->type == bp_catch_load)
2643 #if defined(SOLIB_HAVE_LOAD_EVENT)
2644 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2645 || ((b->dll_pathname != NULL)
2646 && (strcmp (b->dll_pathname,
2647 SOLIB_LOADED_LIBRARY_PATHNAME (
2648 PIDGET (inferior_ptid)))
2654 if ((b->type == bp_catch_unload)
2655 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2656 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2657 || ((b->dll_pathname != NULL)
2658 && (strcmp (b->dll_pathname,
2659 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2660 PIDGET (inferior_ptid)))
2666 if ((b->type == bp_catch_fork)
2667 && !inferior_has_forked (PIDGET (inferior_ptid),
2668 &b->forked_inferior_pid))
2671 if ((b->type == bp_catch_vfork)
2672 && !inferior_has_vforked (PIDGET (inferior_ptid),
2673 &b->forked_inferior_pid))
2676 if ((b->type == bp_catch_exec)
2677 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2680 if (ep_is_exception_catchpoint (b) &&
2681 !(current_exception_event = target_get_current_exception_event ()))
2684 /* Come here if it's a watchpoint, or if the break address matches */
2686 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2688 /* Watchpoints may change this, if not found to have triggered. */
2692 if (b->type == bp_watchpoint ||
2693 b->type == bp_hardware_watchpoint)
2695 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2697 struct cleanup *cleanups = make_cleanup (xfree, message);
2698 int e = catch_errors (watchpoint_check, bs, message,
2700 do_cleanups (cleanups);
2704 /* We've already printed what needs to be printed. */
2705 /* Actually this is superfluous, because by the time we
2706 call print_it_typical() the wp will be already deleted,
2707 and the function will return immediately. */
2708 bs->print_it = print_it_done;
2711 case WP_VALUE_CHANGED:
2715 case WP_VALUE_NOT_CHANGED:
2717 bs->print_it = print_it_noop;
2724 /* Error from catch_errors. */
2725 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2726 if (b->related_breakpoint)
2727 b->related_breakpoint->disposition = disp_del_at_next_stop;
2728 b->disposition = disp_del_at_next_stop;
2729 /* We've already printed what needs to be printed. */
2730 bs->print_it = print_it_done;
2736 else if (b->type == bp_read_watchpoint ||
2737 b->type == bp_access_watchpoint)
2743 if (!target_stopped_data_address (¤t_target, &addr))
2745 for (v = b->val_chain; v; v = value_next (v))
2747 if (VALUE_LVAL (v) == lval_memory
2748 && ! value_lazy (v))
2750 struct type *vtype = check_typedef (value_type (v));
2752 if (v == b->val_chain
2753 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2754 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2758 vaddr = VALUE_ADDRESS (v) + value_offset (v);
2759 /* Exact match not required. Within range is
2761 if (addr >= vaddr &&
2762 addr < vaddr + TYPE_LENGTH (value_type (v)))
2769 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2771 struct cleanup *cleanups = make_cleanup (xfree, message);
2772 int e = catch_errors (watchpoint_check, bs, message,
2774 do_cleanups (cleanups);
2778 /* We've already printed what needs to be printed. */
2779 bs->print_it = print_it_done;
2782 case WP_VALUE_CHANGED:
2783 if (b->type == bp_read_watchpoint)
2785 /* Don't stop: read watchpoints shouldn't fire if
2786 the value has changed. This is for targets
2787 which cannot set read-only watchpoints. */
2788 bs->print_it = print_it_noop;
2794 case WP_VALUE_NOT_CHANGED:
2801 /* Error from catch_errors. */
2802 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2803 if (b->related_breakpoint)
2804 b->related_breakpoint->disposition = disp_del_at_next_stop;
2805 b->disposition = disp_del_at_next_stop;
2806 /* We've already printed what needs to be printed. */
2807 bs->print_it = print_it_done;
2811 else /* found == 0 */
2813 /* This is a case where some watchpoint(s) triggered,
2814 but not at the address of this watchpoint (FOUND
2815 was left zero). So don't print anything for this
2817 bs->print_it = print_it_noop;
2824 /* By definition, an encountered breakpoint is a triggered
2828 real_breakpoint = 1;
2831 if (frame_id_p (b->frame_id)
2832 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2836 int value_is_zero = 0;
2840 /* Need to select the frame, with all that implies
2841 so that the conditions will have the right context. */
2842 select_frame (get_current_frame ());
2844 = catch_errors (breakpoint_cond_eval, (b->cond),
2845 "Error in testing breakpoint condition:\n",
2847 /* FIXME-someday, should give breakpoint # */
2850 if (b->cond && value_is_zero)
2853 /* Don't consider this a hit. */
2856 else if (b->thread != -1 && b->thread != thread_id)
2859 /* Don't consider this a hit. */
2862 else if (b->ignore_count > 0)
2865 annotate_ignore_count_change ();
2870 /* We will stop here */
2871 if (b->disposition == disp_disable)
2872 b->enable_state = bp_disabled;
2875 bs->commands = b->commands;
2877 (strcmp ("silent", bs->commands->line) == 0
2878 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2880 bs->commands = bs->commands->next;
2883 bs->commands = copy_command_lines (bs->commands);
2886 /* Print nothing for this entry if we dont stop or if we dont print. */
2887 if (bs->stop == 0 || bs->print == 0)
2888 bs->print_it = print_it_noop;
2891 bs->next = NULL; /* Terminate the chain */
2892 bs = root_bs->next; /* Re-grab the head of the chain */
2894 /* The value of a hardware watchpoint hasn't changed, but the
2895 intermediate memory locations we are watching may have. */
2896 if (bs && !bs->stop &&
2897 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2898 bs->breakpoint_at->type == bp_read_watchpoint ||
2899 bs->breakpoint_at->type == bp_access_watchpoint))
2901 remove_breakpoints ();
2902 insert_breakpoints ();
2907 /* Tell what to do about this bpstat. */
2909 bpstat_what (bpstat bs)
2911 /* Classify each bpstat as one of the following. */
2914 /* This bpstat element has no effect on the main_action. */
2917 /* There was a watchpoint, stop but don't print. */
2920 /* There was a watchpoint, stop and print. */
2923 /* There was a breakpoint but we're not stopping. */
2926 /* There was a breakpoint, stop but don't print. */
2929 /* There was a breakpoint, stop and print. */
2932 /* We hit the longjmp breakpoint. */
2935 /* We hit the longjmp_resume breakpoint. */
2938 /* We hit the step_resume breakpoint. */
2941 /* We hit the through_sigtramp breakpoint. */
2944 /* We hit the shared library event breakpoint. */
2947 /* We caught a shared library event. */
2950 /* This is just used to count how many enums there are. */
2954 /* Here is the table which drives this routine. So that we can
2955 format it pretty, we define some abbreviations for the
2956 enum bpstat_what codes. */
2957 #define kc BPSTAT_WHAT_KEEP_CHECKING
2958 #define ss BPSTAT_WHAT_STOP_SILENT
2959 #define sn BPSTAT_WHAT_STOP_NOISY
2960 #define sgl BPSTAT_WHAT_SINGLE
2961 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2962 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2963 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2964 #define sr BPSTAT_WHAT_STEP_RESUME
2965 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2966 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2967 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2969 /* "Can't happen." Might want to print an error message.
2970 abort() is not out of the question, but chances are GDB is just
2971 a bit confused, not unusable. */
2972 #define err BPSTAT_WHAT_STOP_NOISY
2974 /* Given an old action and a class, come up with a new action. */
2975 /* One interesting property of this table is that wp_silent is the same
2976 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2977 after stopping, the check for whether to step over a breakpoint
2978 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2979 reference to how we stopped. We retain separate wp_silent and
2980 bp_silent codes in case we want to change that someday.
2982 Another possibly interesting property of this table is that
2983 there's a partial ordering, priority-like, of the actions. Once
2984 you've decided that some action is appropriate, you'll never go
2985 back and decide something of a lower priority is better. The
2988 kc < clr sgl shl shlr slr sn sr ss ts
2989 sgl < clrs shl shlr slr sn sr ss ts
2990 slr < err shl shlr sn sr ss ts
2991 clr < clrs err shl shlr sn sr ss ts
2992 clrs < err shl shlr sn sr ss ts
2993 ss < shl shlr sn sr ts
3000 What I think this means is that we don't need a damned table
3001 here. If you just put the rows and columns in the right order,
3002 it'd look awfully regular. We could simply walk the bpstat list
3003 and choose the highest priority action we find, with a little
3004 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3005 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3006 is messy anyway). */
3008 /* step_resume entries: a step resume breakpoint overrides another
3009 breakpoint of signal handling (see comment in wait_for_inferior
3010 at where we set the step_resume breakpoint). */
3011 /* We handle the through_sigtramp_breakpoint the same way; having both
3012 one of those and a step_resume_breakpoint is probably very rare (?). */
3014 static const enum bpstat_what_main_action
3015 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3018 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3021 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
3023 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3025 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3027 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
3029 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
3031 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
3033 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
3035 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
3037 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
3039 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
3041 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
3043 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3058 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3059 struct bpstat_what retval;
3061 retval.call_dummy = 0;
3062 for (; bs != NULL; bs = bs->next)
3064 enum class bs_class = no_effect;
3065 if (bs->breakpoint_at == NULL)
3066 /* I suspect this can happen if it was a momentary breakpoint
3067 which has since been deleted. */
3069 switch (bs->breakpoint_at->type)
3075 case bp_hardware_breakpoint:
3081 bs_class = bp_noisy;
3083 bs_class = bp_silent;
3086 bs_class = bp_nostop;
3089 case bp_hardware_watchpoint:
3090 case bp_read_watchpoint:
3091 case bp_access_watchpoint:
3095 bs_class = wp_noisy;
3097 bs_class = wp_silent;
3100 /* There was a watchpoint, but we're not stopping.
3101 This requires no further action. */
3102 bs_class = no_effect;
3105 bs_class = long_jump;
3107 case bp_longjmp_resume:
3108 bs_class = long_resume;
3110 case bp_step_resume:
3113 bs_class = step_resume;
3116 /* It is for the wrong frame. */
3117 bs_class = bp_nostop;
3119 case bp_through_sigtramp:
3120 bs_class = through_sig;
3122 case bp_watchpoint_scope:
3123 bs_class = bp_nostop;
3125 case bp_shlib_event:
3126 bs_class = shlib_event;
3128 case bp_thread_event:
3129 case bp_overlay_event:
3130 bs_class = bp_nostop;
3133 case bp_catch_unload:
3134 /* Only if this catchpoint triggered should we cause the
3135 step-out-of-dld behaviour. Otherwise, we ignore this
3138 bs_class = catch_shlib_event;
3140 bs_class = no_effect;
3143 case bp_catch_vfork:
3148 bs_class = bp_noisy;
3150 bs_class = bp_silent;
3153 /* There was a catchpoint, but we're not stopping.
3154 This requires no further action. */
3155 bs_class = no_effect;
3157 case bp_catch_catch:
3158 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3159 bs_class = bp_nostop;
3161 bs_class = bs->print ? bp_noisy : bp_silent;
3163 case bp_catch_throw:
3164 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3165 bs_class = bp_nostop;
3167 bs_class = bs->print ? bp_noisy : bp_silent;
3170 /* Make sure the action is stop (silent or noisy),
3171 so infrun.c pops the dummy frame. */
3172 bs_class = bp_silent;
3173 retval.call_dummy = 1;
3176 current_action = table[(int) bs_class][(int) current_action];
3178 retval.main_action = current_action;
3182 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3183 without hardware support). This isn't related to a specific bpstat,
3184 just to things like whether watchpoints are set. */
3187 bpstat_should_step (void)
3189 struct breakpoint *b;
3191 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3196 /* Nonzero if there are enabled hardware watchpoints. */
3198 bpstat_have_active_hw_watchpoints (void)
3200 struct bp_location *bpt;
3201 ALL_BP_LOCATIONS (bpt)
3202 if (breakpoint_enabled (bpt->owner)
3204 && bpt->loc_type == bp_loc_hardware_watchpoint)
3210 /* Given a bpstat that records zero or more triggered eventpoints, this
3211 function returns another bpstat which contains only the catchpoints
3212 on that first list, if any. */
3214 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3216 struct bpstats root_bs[1];
3217 bpstat bs = root_bs;
3218 struct breakpoint *ep;
3221 bpstat_clear (cp_list);
3222 root_bs->next = NULL;
3224 for (; ep_list != NULL; ep_list = ep_list->next)
3226 /* Is this eventpoint a catchpoint? If not, ignore it. */
3227 ep = ep_list->breakpoint_at;
3230 if ((ep->type != bp_catch_load) &&
3231 (ep->type != bp_catch_unload) &&
3232 (ep->type != bp_catch_catch) &&
3233 (ep->type != bp_catch_throw))
3234 /* pai: (temp) ADD fork/vfork here!! */
3237 /* Yes; add it to the list. */
3238 bs = bpstat_alloc (ep, bs);
3243 #if defined(SOLIB_ADD)
3244 /* Also, for each triggered catchpoint, tag it with the name of
3245 the library that caused this trigger. (We copy the name now,
3246 because it's only guaranteed to be available NOW, when the
3247 catchpoint triggers. Clients who may wish to know the name
3248 later must get it from the catchpoint itself.) */
3249 if (ep->triggered_dll_pathname != NULL)
3250 xfree (ep->triggered_dll_pathname);
3251 if (ep->type == bp_catch_load)
3252 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3253 PIDGET (inferior_ptid));
3255 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3256 PIDGET (inferior_ptid));
3258 dll_pathname = NULL;
3262 ep->triggered_dll_pathname = (char *)
3263 xmalloc (strlen (dll_pathname) + 1);
3264 strcpy (ep->triggered_dll_pathname, dll_pathname);
3267 ep->triggered_dll_pathname = NULL;
3273 /* Print B to gdb_stdout. */
3275 print_one_breakpoint (struct breakpoint *b,
3276 CORE_ADDR *last_addr)
3278 struct command_line *l;
3280 struct ep_type_description
3285 static struct ep_type_description bptypes[] =
3287 {bp_none, "?deleted?"},
3288 {bp_breakpoint, "breakpoint"},
3289 {bp_hardware_breakpoint, "hw breakpoint"},
3290 {bp_until, "until"},
3291 {bp_finish, "finish"},
3292 {bp_watchpoint, "watchpoint"},
3293 {bp_hardware_watchpoint, "hw watchpoint"},
3294 {bp_read_watchpoint, "read watchpoint"},
3295 {bp_access_watchpoint, "acc watchpoint"},
3296 {bp_longjmp, "longjmp"},
3297 {bp_longjmp_resume, "longjmp resume"},
3298 {bp_step_resume, "step resume"},
3299 {bp_through_sigtramp, "sigtramp"},
3300 {bp_watchpoint_scope, "watchpoint scope"},
3301 {bp_call_dummy, "call dummy"},
3302 {bp_shlib_event, "shlib events"},
3303 {bp_thread_event, "thread events"},
3304 {bp_overlay_event, "overlay events"},
3305 {bp_catch_load, "catch load"},
3306 {bp_catch_unload, "catch unload"},
3307 {bp_catch_fork, "catch fork"},
3308 {bp_catch_vfork, "catch vfork"},
3309 {bp_catch_exec, "catch exec"},
3310 {bp_catch_catch, "catch catch"},
3311 {bp_catch_throw, "catch throw"}
3314 static char *bpdisps[] =
3315 {"del", "dstp", "dis", "keep"};
3316 static char bpenables[] = "nynny";
3317 char wrap_indent[80];
3318 struct ui_stream *stb = ui_out_stream_new (uiout);
3319 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3320 struct cleanup *bkpt_chain;
3323 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3327 ui_out_field_int (uiout, "number", b->number);
3331 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3332 || ((int) b->type != bptypes[(int) b->type].type))
3333 internal_error (__FILE__, __LINE__,
3334 _("bptypes table does not describe type #%d."),
3336 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3340 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3344 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3345 ui_out_spaces (uiout, 2);
3348 strcpy (wrap_indent, " ");
3351 if (TARGET_ADDR_BIT <= 32)
3352 strcat (wrap_indent, " ");
3354 strcat (wrap_indent, " ");
3357 if (b->ops != NULL && b->ops->print_one != NULL)
3358 b->ops->print_one (b, last_addr);
3363 internal_error (__FILE__, __LINE__,
3364 _("print_one_breakpoint: bp_none encountered\n"));
3368 case bp_hardware_watchpoint:
3369 case bp_read_watchpoint:
3370 case bp_access_watchpoint:
3371 /* Field 4, the address, is omitted (which makes the columns
3372 not line up too nicely with the headers, but the effect
3373 is relatively readable). */
3375 ui_out_field_skip (uiout, "addr");
3377 print_expression (b->exp, stb->stream);
3378 ui_out_field_stream (uiout, "what", stb);
3382 case bp_catch_unload:
3383 /* Field 4, the address, is omitted (which makes the columns
3384 not line up too nicely with the headers, but the effect
3385 is relatively readable). */
3387 ui_out_field_skip (uiout, "addr");
3389 if (b->dll_pathname == NULL)
3391 ui_out_field_string (uiout, "what", "<any library>");
3392 ui_out_spaces (uiout, 1);
3396 ui_out_text (uiout, "library \"");
3397 ui_out_field_string (uiout, "what", b->dll_pathname);
3398 ui_out_text (uiout, "\" ");
3403 case bp_catch_vfork:
3404 /* Field 4, the address, is omitted (which makes the columns
3405 not line up too nicely with the headers, but the effect
3406 is relatively readable). */
3408 ui_out_field_skip (uiout, "addr");
3410 if (b->forked_inferior_pid != 0)
3412 ui_out_text (uiout, "process ");
3413 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3414 ui_out_spaces (uiout, 1);
3418 /* Field 4, the address, is omitted (which makes the columns
3419 not line up too nicely with the headers, but the effect
3420 is relatively readable). */
3422 ui_out_field_skip (uiout, "addr");
3424 if (b->exec_pathname != NULL)
3426 ui_out_text (uiout, "program \"");
3427 ui_out_field_string (uiout, "what", b->exec_pathname);
3428 ui_out_text (uiout, "\" ");
3432 case bp_catch_catch:
3433 /* Field 4, the address, is omitted (which makes the columns
3434 not line up too nicely with the headers, but the effect
3435 is relatively readable). */
3437 ui_out_field_skip (uiout, "addr");
3439 ui_out_field_string (uiout, "what", "exception catch");
3440 ui_out_spaces (uiout, 1);
3443 case bp_catch_throw:
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 throw");
3451 ui_out_spaces (uiout, 1);
3455 case bp_hardware_breakpoint:
3459 case bp_longjmp_resume:
3460 case bp_step_resume:
3461 case bp_through_sigtramp:
3462 case bp_watchpoint_scope:
3464 case bp_shlib_event:
3465 case bp_thread_event:
3466 case bp_overlay_event:
3471 ui_out_field_string (uiout, "addr", "<PENDING>");
3473 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3476 *last_addr = b->loc->address;
3479 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3482 ui_out_text (uiout, "in ");
3483 ui_out_field_string (uiout, "func",
3484 SYMBOL_PRINT_NAME (sym));
3485 ui_out_wrap_hint (uiout, wrap_indent);
3486 ui_out_text (uiout, " at ");
3488 ui_out_field_string (uiout, "file", b->source_file);
3489 ui_out_text (uiout, ":");
3490 ui_out_field_int (uiout, "line", b->line_number);
3492 else if (b->pending)
3494 ui_out_field_string (uiout, "pending", b->addr_string);
3498 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3499 ui_out_field_stream (uiout, "at", stb);
3504 if (b->thread != -1)
3506 /* FIXME: This seems to be redundant and lost here; see the
3507 "stop only in" line a little further down. */
3508 ui_out_text (uiout, " thread ");
3509 ui_out_field_int (uiout, "thread", b->thread);
3512 ui_out_text (uiout, "\n");
3514 if (frame_id_p (b->frame_id))
3517 ui_out_text (uiout, "\tstop only in stack frame at ");
3518 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3520 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3521 ui_out_text (uiout, "\n");
3527 ui_out_text (uiout, "\tstop only if ");
3528 print_expression (b->cond, stb->stream);
3529 ui_out_field_stream (uiout, "cond", stb);
3530 ui_out_text (uiout, "\n");
3533 if (b->pending && b->cond_string)
3536 ui_out_text (uiout, "\tstop only if ");
3537 ui_out_field_string (uiout, "cond", b->cond_string);
3538 ui_out_text (uiout, "\n");
3541 if (b->thread != -1)
3543 /* FIXME should make an annotation for this */
3544 ui_out_text (uiout, "\tstop only in thread ");
3545 ui_out_field_int (uiout, "thread", b->thread);
3546 ui_out_text (uiout, "\n");
3549 if (show_breakpoint_hit_counts && b->hit_count)
3551 /* FIXME should make an annotation for this */
3552 if (ep_is_catchpoint (b))
3553 ui_out_text (uiout, "\tcatchpoint");
3555 ui_out_text (uiout, "\tbreakpoint");
3556 ui_out_text (uiout, " already hit ");
3557 ui_out_field_int (uiout, "times", b->hit_count);
3558 if (b->hit_count == 1)
3559 ui_out_text (uiout, " time\n");
3561 ui_out_text (uiout, " times\n");
3564 /* Output the count also if it is zero, but only if this is
3565 mi. FIXME: Should have a better test for this. */
3566 if (ui_out_is_mi_like_p (uiout))
3567 if (show_breakpoint_hit_counts && b->hit_count == 0)
3568 ui_out_field_int (uiout, "times", b->hit_count);
3570 if (b->ignore_count)
3573 ui_out_text (uiout, "\tignore next ");
3574 ui_out_field_int (uiout, "ignore", b->ignore_count);
3575 ui_out_text (uiout, " hits\n");
3578 if ((l = b->commands))
3580 struct cleanup *script_chain;
3583 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3584 print_command_lines (uiout, l, 4);
3585 do_cleanups (script_chain);
3587 do_cleanups (bkpt_chain);
3588 do_cleanups (old_chain);
3591 struct captured_breakpoint_query_args
3597 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3599 struct captured_breakpoint_query_args *args = data;
3600 struct breakpoint *b;
3601 CORE_ADDR dummy_addr = 0;
3604 if (args->bnum == b->number)
3606 print_one_breakpoint (b, &dummy_addr);
3614 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3616 struct captured_breakpoint_query_args args;
3618 /* For the moment we don't trust print_one_breakpoint() to not throw
3620 return catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3621 error_message, RETURN_MASK_ALL);
3624 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3625 catchpoints, et.al.). */
3628 user_settable_breakpoint (const struct breakpoint *b)
3630 return (b->type == bp_breakpoint
3631 || b->type == bp_catch_load
3632 || b->type == bp_catch_unload
3633 || b->type == bp_catch_fork
3634 || b->type == bp_catch_vfork
3635 || b->type == bp_catch_exec
3636 || b->type == bp_catch_catch
3637 || b->type == bp_catch_throw
3638 || b->type == bp_hardware_breakpoint
3639 || b->type == bp_watchpoint
3640 || b->type == bp_read_watchpoint
3641 || b->type == bp_access_watchpoint
3642 || b->type == bp_hardware_watchpoint);
3645 /* Print information on user settable breakpoint (watchpoint, etc)
3646 number BNUM. If BNUM is -1 print all user settable breakpoints.
3647 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3650 breakpoint_1 (int bnum, int allflag)
3652 struct breakpoint *b;
3653 CORE_ADDR last_addr = (CORE_ADDR) -1;
3654 int nr_printable_breakpoints;
3655 struct cleanup *bkpttbl_chain;
3657 /* Compute the number of rows in the table. */
3658 nr_printable_breakpoints = 0;
3661 || bnum == b->number)
3663 if (allflag || user_settable_breakpoint (b))
3664 nr_printable_breakpoints++;
3669 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3673 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3676 if (nr_printable_breakpoints > 0)
3677 annotate_breakpoints_headers ();
3678 if (nr_printable_breakpoints > 0)
3680 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3681 if (nr_printable_breakpoints > 0)
3683 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3684 if (nr_printable_breakpoints > 0)
3686 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3687 if (nr_printable_breakpoints > 0)
3689 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3692 if (nr_printable_breakpoints > 0)
3694 if (TARGET_ADDR_BIT <= 32)
3695 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3697 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3699 if (nr_printable_breakpoints > 0)
3701 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3702 ui_out_table_body (uiout);
3703 if (nr_printable_breakpoints > 0)
3704 annotate_breakpoints_table ();
3708 || bnum == b->number)
3710 /* We only print out user settable breakpoints unless the
3712 if (allflag || user_settable_breakpoint (b))
3713 print_one_breakpoint (b, &last_addr);
3716 do_cleanups (bkpttbl_chain);
3718 if (nr_printable_breakpoints == 0)
3721 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3723 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3728 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3729 that a comparison of an unsigned with -1 is always false. */
3730 if (last_addr != (CORE_ADDR) -1)
3731 set_next_address (last_addr);
3734 /* FIXME? Should this be moved up so that it is only called when
3735 there have been breakpoints? */
3736 annotate_breakpoints_table_end ();
3740 breakpoints_info (char *bnum_exp, int from_tty)
3745 bnum = parse_and_eval_long (bnum_exp);
3747 breakpoint_1 (bnum, 0);
3751 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3756 bnum = parse_and_eval_long (bnum_exp);
3758 breakpoint_1 (bnum, 1);
3761 /* Print a message describing any breakpoints set at PC. */
3764 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3767 struct breakpoint *b;
3770 if (b->loc->address == pc) /* address match / overlay match */
3771 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3776 printf_filtered (_("Note: breakpoint "));
3777 else /* if (others == ???) */
3778 printf_filtered (_("Note: breakpoints "));
3780 if (b->loc->address == pc) /* address match / overlay match */
3781 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3784 printf_filtered ("%d%s%s ",
3786 ((b->enable_state == bp_disabled ||
3787 b->enable_state == bp_shlib_disabled ||
3788 b->enable_state == bp_call_disabled)
3790 : b->enable_state == bp_permanent
3794 : ((others == 1) ? " and" : ""));
3796 printf_filtered (_("also set at pc "));
3797 deprecated_print_address_numeric (pc, 1, gdb_stdout);
3798 printf_filtered (".\n");
3802 /* Set the default place to put a breakpoint
3803 for the `break' command with no arguments. */
3806 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3809 default_breakpoint_valid = valid;
3810 default_breakpoint_address = addr;
3811 default_breakpoint_symtab = symtab;
3812 default_breakpoint_line = line;
3815 /* Return true iff it is meaningful to use the address member of
3816 BPT. For some breakpoint types, the address member is irrelevant
3817 and it makes no sense to attempt to compare it to other addresses
3818 (or use it for any other purpose either).
3820 More specifically, each of the following breakpoint types will always
3821 have a zero valued address and we don't want check_duplicates() to mark
3822 breakpoints of any of these types to be a duplicate of an actual
3823 breakpoint at address zero:
3826 bp_hardware_watchpoint
3828 bp_access_watchpoint
3835 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3837 enum bptype type = bpt->type;
3839 return (type != bp_watchpoint
3840 && type != bp_hardware_watchpoint
3841 && type != bp_read_watchpoint
3842 && type != bp_access_watchpoint
3843 && type != bp_catch_exec
3844 && type != bp_longjmp_resume
3845 && type != bp_catch_fork
3846 && type != bp_catch_vfork);
3849 /* Rescan breakpoints at the same address and section as BPT,
3850 marking the first one as "first" and any others as "duplicates".
3851 This is so that the bpt instruction is only inserted once.
3852 If we have a permanent breakpoint at the same place as BPT, make
3853 that one the official one, and the rest as duplicates. */
3856 check_duplicates (struct breakpoint *bpt)
3858 struct bp_location *b;
3860 struct bp_location *perm_bp = 0;
3861 CORE_ADDR address = bpt->loc->address;
3862 asection *section = bpt->loc->section;
3864 if (! breakpoint_address_is_meaningful (bpt))
3867 ALL_BP_LOCATIONS (b)
3868 if (b->owner->enable_state != bp_disabled
3869 && b->owner->enable_state != bp_shlib_disabled
3870 && !b->owner->pending
3871 && b->owner->enable_state != bp_call_disabled
3872 && b->address == address /* address / overlay match */
3873 && (!overlay_debugging || b->section == section)
3874 && breakpoint_address_is_meaningful (b->owner))
3876 /* Have we found a permanent breakpoint? */
3877 if (b->owner->enable_state == bp_permanent)
3884 b->duplicate = count > 1;
3887 /* If we found a permanent breakpoint at this address, go over the
3888 list again and declare all the other breakpoints there to be the
3892 perm_bp->duplicate = 0;
3894 /* Permanent breakpoint should always be inserted. */
3895 if (! perm_bp->inserted)
3896 internal_error (__FILE__, __LINE__,
3897 _("allegedly permanent breakpoint is not "
3898 "actually inserted"));
3900 ALL_BP_LOCATIONS (b)
3903 if (b->owner->enable_state != bp_disabled
3904 && b->owner->enable_state != bp_shlib_disabled
3905 && !b->owner->pending
3906 && b->owner->enable_state != bp_call_disabled
3907 && b->address == address /* address / overlay match */
3908 && (!overlay_debugging || b->section == section)
3909 && breakpoint_address_is_meaningful (b->owner))
3912 internal_error (__FILE__, __LINE__,
3913 _("another breakpoint was inserted on top of "
3914 "a permanent breakpoint"));
3923 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3924 int bnum, int have_bnum)
3929 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
3930 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
3932 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3933 bnum, astr1, astr2);
3935 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
3938 /* Adjust a breakpoint's address to account for architectural constraints
3939 on breakpoint placement. Return the adjusted address. Note: Very
3940 few targets require this kind of adjustment. For most targets,
3941 this function is simply the identity function. */
3944 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
3946 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3948 /* Very few targets need any kind of breakpoint adjustment. */
3951 else if (bptype == bp_watchpoint
3952 || bptype == bp_hardware_watchpoint
3953 || bptype == bp_read_watchpoint
3954 || bptype == bp_access_watchpoint
3955 || bptype == bp_catch_fork
3956 || bptype == bp_catch_vfork
3957 || bptype == bp_catch_exec)
3959 /* Watchpoints and the various bp_catch_* eventpoints should not
3960 have their addresses modified. */
3965 CORE_ADDR adjusted_bpaddr;
3967 /* Some targets have architectural constraints on the placement
3968 of breakpoint instructions. Obtain the adjusted address. */
3969 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3972 /* An adjusted breakpoint address can significantly alter
3973 a user's expectations. Print a warning if an adjustment
3975 if (adjusted_bpaddr != bpaddr)
3976 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3978 return adjusted_bpaddr;
3982 /* Allocate a struct bp_location. */
3984 static struct bp_location *
3985 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
3987 struct bp_location *loc, *loc_p;
3989 loc = xmalloc (sizeof (struct bp_location));
3990 memset (loc, 0, sizeof (*loc));
4000 case bp_longjmp_resume:
4001 case bp_step_resume:
4002 case bp_through_sigtramp:
4003 case bp_watchpoint_scope:
4005 case bp_shlib_event:
4006 case bp_thread_event:
4007 case bp_overlay_event:
4009 case bp_catch_unload:
4010 loc->loc_type = bp_loc_software_breakpoint;
4012 case bp_hardware_breakpoint:
4013 loc->loc_type = bp_loc_hardware_breakpoint;
4015 case bp_hardware_watchpoint:
4016 case bp_read_watchpoint:
4017 case bp_access_watchpoint:
4018 loc->loc_type = bp_loc_hardware_watchpoint;
4022 case bp_catch_vfork:
4024 case bp_catch_catch:
4025 case bp_catch_throw:
4026 loc->loc_type = bp_loc_other;
4029 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4032 /* Add this breakpoint to the end of the chain. */
4034 loc_p = bp_location_chain;
4036 bp_location_chain = loc;
4040 loc_p = loc_p->next;
4047 /* set_raw_breakpoint() is a low level routine for allocating and
4048 partially initializing a breakpoint of type BPTYPE. The newly
4049 created breakpoint's address, section, source file name, and line
4050 number are provided by SAL. The newly created and partially
4051 initialized breakpoint is added to the breakpoint chain and
4052 is also returned as the value of this function.
4054 It is expected that the caller will complete the initialization of
4055 the newly created breakpoint struct as well as output any status
4056 information regarding the creation of a new breakpoint. In
4057 particular, set_raw_breakpoint() does NOT set the breakpoint
4058 number! Care should be taken to not allow an error() to occur
4059 prior to completing the initialization of the breakpoint. If this
4060 should happen, a bogus breakpoint will be left on the chain. */
4063 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4065 struct breakpoint *b, *b1;
4067 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4068 memset (b, 0, sizeof (*b));
4069 b->loc = allocate_bp_location (b, bptype);
4070 b->loc->requested_address = sal.pc;
4071 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4073 if (sal.symtab == NULL)
4074 b->source_file = NULL;
4076 b->source_file = savestring (sal.symtab->filename,
4077 strlen (sal.symtab->filename));
4078 b->loc->section = sal.section;
4080 b->language = current_language->la_language;
4081 b->input_radix = input_radix;
4083 b->line_number = sal.line;
4084 b->enable_state = bp_enabled;
4087 b->ignore_count = 0;
4089 b->frame_id = null_frame_id;
4090 b->dll_pathname = NULL;
4091 b->triggered_dll_pathname = NULL;
4092 b->forked_inferior_pid = 0;
4093 b->exec_pathname = NULL;
4097 /* Add this breakpoint to the end of the chain
4098 so that a list of breakpoints will come out in order
4099 of increasing numbers. */
4101 b1 = breakpoint_chain;
4103 breakpoint_chain = b;
4111 check_duplicates (b);
4112 breakpoints_changed ();
4118 /* Note that the breakpoint object B describes a permanent breakpoint
4119 instruction, hard-wired into the inferior's code. */
4121 make_breakpoint_permanent (struct breakpoint *b)
4123 b->enable_state = bp_permanent;
4125 /* By definition, permanent breakpoints are already present in the code. */
4126 b->loc->inserted = 1;
4129 static struct breakpoint *
4130 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4132 static int internal_breakpoint_number = -1;
4133 struct symtab_and_line sal;
4134 struct breakpoint *b;
4136 init_sal (&sal); /* initialize to zeroes */
4139 sal.section = find_pc_overlay (sal.pc);
4141 b = set_raw_breakpoint (sal, type);
4142 b->number = internal_breakpoint_number--;
4143 b->disposition = disp_donttouch;
4150 create_longjmp_breakpoint (char *func_name)
4152 struct breakpoint *b;
4153 struct minimal_symbol *m;
4155 if (func_name == NULL)
4156 b = create_internal_breakpoint (0, bp_longjmp_resume);
4159 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4162 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4165 b->enable_state = bp_disabled;
4168 b->addr_string = xstrdup (func_name);
4171 /* Call this routine when stepping and nexting to enable a breakpoint
4172 if we do a longjmp(). When we hit that breakpoint, call
4173 set_longjmp_resume_breakpoint() to figure out where we are going. */
4176 enable_longjmp_breakpoint (void)
4178 struct breakpoint *b;
4181 if (b->type == bp_longjmp)
4183 b->enable_state = bp_enabled;
4184 check_duplicates (b);
4189 disable_longjmp_breakpoint (void)
4191 struct breakpoint *b;
4194 if (b->type == bp_longjmp
4195 || b->type == bp_longjmp_resume)
4197 b->enable_state = bp_disabled;
4198 check_duplicates (b);
4203 create_overlay_event_breakpoint (char *func_name)
4205 struct breakpoint *b;
4206 struct minimal_symbol *m;
4208 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4211 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4213 b->addr_string = xstrdup (func_name);
4215 if (overlay_debugging == ovly_auto)
4217 b->enable_state = bp_enabled;
4218 overlay_events_enabled = 1;
4222 b->enable_state = bp_disabled;
4223 overlay_events_enabled = 0;
4228 enable_overlay_breakpoints (void)
4230 struct breakpoint *b;
4233 if (b->type == bp_overlay_event)
4235 b->enable_state = bp_enabled;
4236 check_duplicates (b);
4237 overlay_events_enabled = 1;
4242 disable_overlay_breakpoints (void)
4244 struct breakpoint *b;
4247 if (b->type == bp_overlay_event)
4249 b->enable_state = bp_disabled;
4250 check_duplicates (b);
4251 overlay_events_enabled = 0;
4256 create_thread_event_breakpoint (CORE_ADDR address)
4258 struct breakpoint *b;
4260 b = create_internal_breakpoint (address, bp_thread_event);
4262 b->enable_state = bp_enabled;
4263 /* addr_string has to be used or breakpoint_re_set will delete me. */
4264 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4270 remove_thread_event_breakpoints (void)
4272 struct breakpoint *b, *temp;
4274 ALL_BREAKPOINTS_SAFE (b, temp)
4275 if (b->type == bp_thread_event)
4276 delete_breakpoint (b);
4279 struct captured_parse_breakpoint_args
4282 struct symtabs_and_lines *sals_p;
4283 char ***addr_string_p;
4287 struct lang_and_radix
4293 /* Cleanup helper routine to restore the current language and
4296 do_restore_lang_radix_cleanup (void *old)
4298 struct lang_and_radix *p = old;
4299 set_language (p->lang);
4300 input_radix = p->radix;
4303 /* Try and resolve a pending breakpoint. */
4305 resolve_pending_breakpoint (struct breakpoint *b)
4307 /* Try and reparse the breakpoint in case the shared library
4309 struct symtabs_and_lines sals;
4310 struct symtab_and_line pending_sal;
4311 char **cond_string = (char **) NULL;
4312 char *copy_arg = b->addr_string;
4317 struct ui_file *old_gdb_stderr;
4318 struct lang_and_radix old_lr;
4319 struct cleanup *old_chain;
4321 /* Set language, input-radix, then reissue breakpoint command.
4322 Ensure the language and input-radix are restored afterwards. */
4323 old_lr.lang = current_language->la_language;
4324 old_lr.radix = input_radix;
4325 old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr);
4327 set_language (b->language);
4328 input_radix = b->input_radix;
4329 rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b);
4331 if (rc == GDB_RC_OK)
4332 /* Pending breakpoint has been resolved. */
4333 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b->addr_string);
4335 do_cleanups (old_chain);
4340 remove_solib_event_breakpoints (void)
4342 struct breakpoint *b, *temp;
4344 ALL_BREAKPOINTS_SAFE (b, temp)
4345 if (b->type == bp_shlib_event)
4346 delete_breakpoint (b);
4350 create_solib_event_breakpoint (CORE_ADDR address)
4352 struct breakpoint *b;
4354 b = create_internal_breakpoint (address, bp_shlib_event);
4358 /* Disable any breakpoints that are on code in shared libraries. Only
4359 apply to enabled breakpoints, disabled ones can just stay disabled. */
4362 disable_breakpoints_in_shlibs (int silent)
4364 struct breakpoint *b;
4365 int disabled_shlib_breaks = 0;
4367 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4370 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4371 && breakpoint_enabled (b) && !b->loc->duplicate
4373 && PC_SOLIB (b->loc->address)
4375 && solib_address (b->loc->address)
4379 b->enable_state = bp_shlib_disabled;
4382 if (!disabled_shlib_breaks)
4384 target_terminal_ours_for_output ();
4385 warning (_("Temporarily disabling shared library breakpoints:"));
4387 disabled_shlib_breaks = 1;
4388 warning (_("breakpoint #%d "), b->number);
4394 /* Disable any breakpoints that are in in an unloaded shared library. Only
4395 apply to enabled breakpoints, disabled ones can just stay disabled. */
4398 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4400 struct breakpoint *b;
4401 int disabled_shlib_breaks = 0;
4403 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4406 if ((b->loc->loc_type == bp_loc_hardware_breakpoint
4407 || b->loc->loc_type == bp_loc_software_breakpoint)
4408 && breakpoint_enabled (b) && !b->loc->duplicate)
4411 char *so_name = PC_SOLIB (b->loc->address);
4413 char *so_name = solib_address (b->loc->address);
4415 if (so_name && !strcmp (so_name, solib->so_name))
4417 b->enable_state = bp_shlib_disabled;
4418 /* At this point, we cannot rely on remove_breakpoint
4419 succeeding so we must mark the breakpoint as not inserted
4420 to prevent future errors occurring in remove_breakpoints. */
4421 b->loc->inserted = 0;
4422 if (!disabled_shlib_breaks)
4424 target_terminal_ours_for_output ();
4425 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4428 disabled_shlib_breaks = 1;
4434 /* Try to reenable any breakpoints in shared libraries. */
4436 re_enable_breakpoints_in_shlibs (void)
4438 struct breakpoint *b, *tmp;
4440 ALL_BREAKPOINTS_SAFE (b, tmp)
4442 if (b->enable_state == bp_shlib_disabled)
4447 /* Do not reenable the breakpoint if the shared library is
4448 still not mapped in. */
4450 lib = PC_SOLIB (b->loc->address);
4452 lib = solib_address (b->loc->address);
4454 if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
4455 b->enable_state = bp_enabled;
4457 else if (b->pending && (b->enable_state == bp_enabled))
4459 if (resolve_pending_breakpoint (b) == GDB_RC_OK)
4460 delete_breakpoint (b);
4466 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4467 char *cond_string, enum bptype bp_kind)
4469 struct breakpoint *b;
4470 struct symtabs_and_lines sals;
4471 struct cleanup *old_chain;
4472 struct cleanup *canonical_strings_chain = NULL;
4473 char *addr_start = hookname;
4474 char *addr_end = NULL;
4475 char **canonical = (char **) NULL;
4476 int thread = -1; /* All threads. */
4478 /* Set a breakpoint on the specified hook. */
4479 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL,
4480 0, &canonical, NULL);
4481 addr_end = hookname;
4483 if (sals.nelts == 0)
4485 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4486 "Suggest linking with /opt/langtools/lib/end.o.\n"
4487 "GDB will be unable to track shl_load/shl_unload calls."));
4490 if (sals.nelts != 1)
4492 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4493 "GDB will be unable to track shl_load/shl_unload calls."));
4497 /* Make sure that all storage allocated in decode_line_1 gets freed
4498 in case the following errors out. */
4499 old_chain = make_cleanup (xfree, sals.sals);
4500 if (canonical != (char **) NULL)
4502 make_cleanup (xfree, canonical);
4503 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4504 if (canonical[0] != NULL)
4505 make_cleanup (xfree, canonical[0]);
4508 resolve_sal_pc (&sals.sals[0]);
4510 /* Remove the canonical strings from the cleanup, they are needed below. */
4511 if (canonical != (char **) NULL)
4512 discard_cleanups (canonical_strings_chain);
4514 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4515 set_breakpoint_count (breakpoint_count + 1);
4516 b->number = breakpoint_count;
4518 b->cond_string = (cond_string == NULL) ?
4519 NULL : savestring (cond_string, strlen (cond_string));
4522 if (canonical != (char **) NULL && canonical[0] != NULL)
4523 b->addr_string = canonical[0];
4524 else if (addr_start)
4525 b->addr_string = savestring (addr_start, addr_end - addr_start);
4527 b->enable_state = bp_enabled;
4528 b->disposition = tempflag ? disp_del : disp_donttouch;
4530 if (dll_pathname == NULL)
4531 b->dll_pathname = NULL;
4534 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4535 strcpy (b->dll_pathname, dll_pathname);
4539 do_cleanups (old_chain);
4543 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4544 char *dll_pathname, char *cond_string)
4546 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4547 cond_string, bp_catch_load);
4551 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4552 char *dll_pathname, char *cond_string)
4554 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4555 cond_string, bp_catch_unload);
4559 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4560 enum bptype bp_kind)
4562 struct symtab_and_line sal;
4563 struct breakpoint *b;
4564 int thread = -1; /* All threads. */
4571 b = set_raw_breakpoint (sal, bp_kind);
4572 set_breakpoint_count (breakpoint_count + 1);
4573 b->number = breakpoint_count;
4575 b->cond_string = (cond_string == NULL) ?
4576 NULL : savestring (cond_string, strlen (cond_string));
4578 b->addr_string = NULL;
4579 b->enable_state = bp_enabled;
4580 b->disposition = tempflag ? disp_del : disp_donttouch;
4581 b->forked_inferior_pid = 0;
4587 create_fork_event_catchpoint (int tempflag, char *cond_string)
4589 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4593 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4595 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4599 create_exec_event_catchpoint (int tempflag, char *cond_string)
4601 struct symtab_and_line sal;
4602 struct breakpoint *b;
4603 int thread = -1; /* All threads. */
4610 b = set_raw_breakpoint (sal, bp_catch_exec);
4611 set_breakpoint_count (breakpoint_count + 1);
4612 b->number = breakpoint_count;
4614 b->cond_string = (cond_string == NULL) ?
4615 NULL : savestring (cond_string, strlen (cond_string));
4617 b->addr_string = NULL;
4618 b->enable_state = bp_enabled;
4619 b->disposition = tempflag ? disp_del : disp_donttouch;
4625 hw_breakpoint_used_count (void)
4627 struct breakpoint *b;
4632 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4640 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4642 struct breakpoint *b;
4645 *other_type_used = 0;
4648 if (breakpoint_enabled (b))
4650 if (b->type == type)
4652 else if ((b->type == bp_hardware_watchpoint ||
4653 b->type == bp_read_watchpoint ||
4654 b->type == bp_access_watchpoint))
4655 *other_type_used = 1;
4661 /* Call this after hitting the longjmp() breakpoint. Use this to set
4662 a new breakpoint at the target of the jmp_buf.
4664 FIXME - This ought to be done by setting a temporary breakpoint
4665 that gets deleted automatically... */
4668 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4670 struct breakpoint *b;
4673 if (b->type == bp_longjmp_resume)
4675 b->loc->requested_address = pc;
4676 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4678 b->enable_state = bp_enabled;
4679 b->frame_id = frame_id;
4680 check_duplicates (b);
4686 disable_watchpoints_before_interactive_call_start (void)
4688 struct breakpoint *b;
4692 if (((b->type == bp_watchpoint)
4693 || (b->type == bp_hardware_watchpoint)
4694 || (b->type == bp_read_watchpoint)
4695 || (b->type == bp_access_watchpoint)
4696 || ep_is_exception_catchpoint (b))
4697 && breakpoint_enabled (b))
4699 b->enable_state = bp_call_disabled;
4700 check_duplicates (b);
4706 enable_watchpoints_after_interactive_call_stop (void)
4708 struct breakpoint *b;
4712 if (((b->type == bp_watchpoint)
4713 || (b->type == bp_hardware_watchpoint)
4714 || (b->type == bp_read_watchpoint)
4715 || (b->type == bp_access_watchpoint)
4716 || ep_is_exception_catchpoint (b))
4717 && (b->enable_state == bp_call_disabled))
4719 b->enable_state = bp_enabled;
4720 check_duplicates (b);
4726 /* Set a breakpoint that will evaporate an end of command
4727 at address specified by SAL.
4728 Restrict it to frame FRAME if FRAME is nonzero. */
4731 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4734 struct breakpoint *b;
4735 b = set_raw_breakpoint (sal, type);
4736 b->enable_state = bp_enabled;
4737 b->disposition = disp_donttouch;
4738 b->frame_id = frame_id;
4740 /* If we're debugging a multi-threaded program, then we
4741 want momentary breakpoints to be active in only a
4742 single thread of control. */
4743 if (in_thread_list (inferior_ptid))
4744 b->thread = pid_to_thread_id (inferior_ptid);
4750 /* Tell the user we have just set a breakpoint B. */
4753 mention (struct breakpoint *b)
4756 struct cleanup *old_chain, *ui_out_chain;
4757 struct ui_stream *stb;
4759 stb = ui_out_stream_new (uiout);
4760 old_chain = make_cleanup_ui_out_stream_delete (stb);
4762 /* FIXME: This is misplaced; mention() is called by things (like
4763 hitting a watchpoint) other than breakpoint creation. It should
4764 be possible to clean this up and at the same time replace the
4765 random calls to breakpoint_changed with this hook, as has already
4766 been done for deprecated_delete_breakpoint_hook and so on. */
4767 if (deprecated_create_breakpoint_hook)
4768 deprecated_create_breakpoint_hook (b);
4769 breakpoint_create_event (b->number);
4771 if (b->ops != NULL && b->ops->print_mention != NULL)
4772 b->ops->print_mention (b);
4777 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4780 ui_out_text (uiout, "Watchpoint ");
4781 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4782 ui_out_field_int (uiout, "number", b->number);
4783 ui_out_text (uiout, ": ");
4784 print_expression (b->exp, stb->stream);
4785 ui_out_field_stream (uiout, "exp", stb);
4786 do_cleanups (ui_out_chain);
4788 case bp_hardware_watchpoint:
4789 ui_out_text (uiout, "Hardware watchpoint ");
4790 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4791 ui_out_field_int (uiout, "number", b->number);
4792 ui_out_text (uiout, ": ");
4793 print_expression (b->exp, stb->stream);
4794 ui_out_field_stream (uiout, "exp", stb);
4795 do_cleanups (ui_out_chain);
4797 case bp_read_watchpoint:
4798 ui_out_text (uiout, "Hardware read watchpoint ");
4799 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4800 ui_out_field_int (uiout, "number", b->number);
4801 ui_out_text (uiout, ": ");
4802 print_expression (b->exp, stb->stream);
4803 ui_out_field_stream (uiout, "exp", stb);
4804 do_cleanups (ui_out_chain);
4806 case bp_access_watchpoint:
4807 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4808 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4809 ui_out_field_int (uiout, "number", b->number);
4810 ui_out_text (uiout, ": ");
4811 print_expression (b->exp, stb->stream);
4812 ui_out_field_stream (uiout, "exp", stb);
4813 do_cleanups (ui_out_chain);
4816 if (ui_out_is_mi_like_p (uiout))
4821 printf_filtered (_("Breakpoint %d"), b->number);
4824 case bp_hardware_breakpoint:
4825 if (ui_out_is_mi_like_p (uiout))
4830 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4834 case bp_catch_unload:
4835 printf_filtered (_("Catchpoint %d (%s %s)"),
4837 (b->type == bp_catch_load) ? "load" : "unload",
4838 (b->dll_pathname != NULL) ?
4839 b->dll_pathname : "<any library>");
4842 case bp_catch_vfork:
4843 printf_filtered (_("Catchpoint %d (%s)"),
4845 (b->type == bp_catch_fork) ? "fork" : "vfork");
4848 printf_filtered (_("Catchpoint %d (exec)"),
4851 case bp_catch_catch:
4852 case bp_catch_throw:
4853 printf_filtered (_("Catchpoint %d (%s)"),
4855 (b->type == bp_catch_catch) ? "catch" : "throw");
4861 case bp_longjmp_resume:
4862 case bp_step_resume:
4863 case bp_through_sigtramp:
4865 case bp_watchpoint_scope:
4866 case bp_shlib_event:
4867 case bp_thread_event:
4868 case bp_overlay_event:
4874 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4878 printf_filtered (_(" (%s) pending."), b->addr_string);
4882 if (addressprint || b->source_file == NULL)
4884 printf_filtered (" at ");
4885 deprecated_print_address_numeric (b->loc->address, 1, gdb_stdout);
4888 printf_filtered (": file %s, line %d.",
4889 b->source_file, b->line_number);
4892 do_cleanups (old_chain);
4893 if (ui_out_is_mi_like_p (uiout))
4895 printf_filtered ("\n");
4899 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4900 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4901 COND[i] and COND_STRING[i] values.
4903 The parameter PENDING_BP points to a pending breakpoint that is
4904 the basis of the breakpoints currently being created. The pending
4905 breakpoint may contain a separate condition string or commands
4906 that were added after the initial pending breakpoint was created.
4908 NOTE: If the function succeeds, the caller is expected to cleanup
4909 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4910 array contents). If the function fails (error() is called), the
4911 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4912 COND and SALS arrays and each of those arrays contents. */
4915 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4916 struct expression **cond, char **cond_string,
4917 enum bptype type, enum bpdisp disposition,
4918 int thread, int ignore_count, int from_tty,
4919 struct breakpoint *pending_bp)
4921 if (type == bp_hardware_breakpoint)
4923 int i = hw_breakpoint_used_count ();
4924 int target_resources_ok =
4925 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4927 if (target_resources_ok == 0)
4928 error (_("No hardware breakpoint support in the target."));
4929 else if (target_resources_ok < 0)
4930 error (_("Hardware breakpoints used exceeds limit."));
4933 /* Now set all the breakpoints. */
4936 for (i = 0; i < sals.nelts; i++)
4938 struct breakpoint *b;
4939 struct symtab_and_line sal = sals.sals[i];
4942 describe_other_breakpoints (sal.pc, sal.section);
4944 b = set_raw_breakpoint (sal, type);
4945 set_breakpoint_count (breakpoint_count + 1);
4946 b->number = breakpoint_count;
4950 b->addr_string = addr_string[i];
4952 /* addr_string has to be used or breakpoint_re_set will delete
4954 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4955 b->cond_string = cond_string[i];
4956 b->ignore_count = ignore_count;
4957 b->enable_state = bp_enabled;
4958 b->disposition = disposition;
4959 /* If resolving a pending breakpoint, a check must be made to see if
4960 the user has specified a new condition or commands for the
4961 breakpoint. A new condition will override any condition that was
4962 initially specified with the initial breakpoint command. */
4966 if (pending_bp->cond_string)
4968 arg = pending_bp->cond_string;
4969 b->cond_string = savestring (arg, strlen (arg));
4970 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
4972 error (_("Junk at end of pending breakpoint condition expression"));
4974 /* If there are commands associated with the breakpoint, they should
4976 if (pending_bp->commands)
4977 b->commands = copy_command_lines (pending_bp->commands);
4979 /* We have to copy over the ignore_count and thread as well. */
4980 b->ignore_count = pending_bp->ignore_count;
4981 b->thread = pending_bp->thread;
4988 /* Parse ARG which is assumed to be a SAL specification possibly
4989 followed by conditionals. On return, SALS contains an array of SAL
4990 addresses found. ADDR_STRING contains a vector of (canonical)
4991 address strings. ARG points to the end of the SAL. */
4994 parse_breakpoint_sals (char **address,
4995 struct symtabs_and_lines *sals,
4996 char ***addr_string,
4999 char *addr_start = *address;
5000 *addr_string = NULL;
5001 /* If no arg given, or if first arg is 'if ', use the default
5003 if ((*address) == NULL
5004 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5006 if (default_breakpoint_valid)
5008 struct symtab_and_line sal;
5009 init_sal (&sal); /* initialize to zeroes */
5010 sals->sals = (struct symtab_and_line *)
5011 xmalloc (sizeof (struct symtab_and_line));
5012 sal.pc = default_breakpoint_address;
5013 sal.line = default_breakpoint_line;
5014 sal.symtab = default_breakpoint_symtab;
5015 sal.section = find_pc_overlay (sal.pc);
5016 sals->sals[0] = sal;
5020 error (_("No default breakpoint address now."));
5024 /* Force almost all breakpoints to be in terms of the
5025 current_source_symtab (which is decode_line_1's default). This
5026 should produce the results we want almost all of the time while
5027 leaving default_breakpoint_* alone.
5028 ObjC: However, don't match an Objective-C method name which
5029 may have a '+' or '-' succeeded by a '[' */
5031 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5033 if (default_breakpoint_valid
5035 || ((strchr ("+-", (*address)[0]) != NULL)
5036 && ((*address)[1] != '['))))
5037 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5038 default_breakpoint_line, addr_string,
5041 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5042 addr_string, not_found_ptr);
5044 /* For any SAL that didn't have a canonical string, fill one in. */
5045 if (sals->nelts > 0 && *addr_string == NULL)
5046 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5047 if (addr_start != (*address))
5050 for (i = 0; i < sals->nelts; i++)
5052 /* Add the string if not present. */
5053 if ((*addr_string)[i] == NULL)
5054 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5060 /* Convert each SAL into a real PC. Verify that the PC can be
5061 inserted as a breakpoint. If it can't throw an error. */
5064 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5068 for (i = 0; i < sals->nelts; i++)
5070 resolve_sal_pc (&sals->sals[i]);
5072 /* It's possible for the PC to be nonzero, but still an illegal
5073 value on some targets.
5075 For example, on HP-UX if you start gdb, and before running the
5076 inferior you try to set a breakpoint on a shared library function
5077 "foo" where the inferior doesn't call "foo" directly but does
5078 pass its address to another function call, then we do find a
5079 minimal symbol for the "foo", but it's address is invalid.
5080 (Appears to be an index into a table that the loader sets up
5081 when the inferior is run.)
5083 Give the target a chance to bless sals.sals[i].pc before we
5084 try to make a breakpoint for it. */
5085 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5086 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5088 if (address == NULL)
5089 error (_("Cannot break without a running program."));
5091 error (_("Cannot break on %s without a running program."),
5099 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5101 struct captured_parse_breakpoint_args *args = data;
5103 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5104 args->not_found_ptr);
5107 /* Set a breakpoint according to ARG (function, linenum or *address)
5108 flag: first bit : 0 non-temporary, 1 temporary.
5109 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5111 PENDING_BP is non-NULL when this function is being called to resolve
5112 a pending breakpoint. */
5115 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5117 struct gdb_exception e;
5118 int tempflag, hardwareflag;
5119 struct symtabs_and_lines sals;
5120 struct expression **cond = 0;
5121 struct symtab_and_line pending_sal;
5122 char **cond_string = (char **) NULL;
5125 char *addr_start = arg;
5127 struct cleanup *old_chain;
5128 struct cleanup *breakpoint_chain = NULL;
5129 struct captured_parse_breakpoint_args parse_args;
5133 int ignore_count = 0;
5136 hardwareflag = flag & BP_HARDWAREFLAG;
5137 tempflag = flag & BP_TEMPFLAG;
5143 parse_args.arg_p = &arg;
5144 parse_args.sals_p = &sals;
5145 parse_args.addr_string_p = &addr_string;
5146 parse_args.not_found_ptr = ¬_found;
5148 e = catch_exception (uiout, do_captured_parse_breakpoint,
5149 &parse_args, RETURN_MASK_ALL);
5151 /* If caller is interested in rc value from parse, set value. */
5155 exception_print (gdb_stderr, e);
5160 case NOT_FOUND_ERROR:
5161 /* If called to resolve pending breakpoint, just return
5166 exception_print (gdb_stderr, e);
5168 /* If pending breakpoint support is turned off, throw
5171 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5172 deprecated_throw_reason (RETURN_ERROR);
5174 /* If pending breakpoint support is auto query and the user
5175 selects no, then simply return the error code. */
5176 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5177 !nquery ("Make breakpoint pending on future shared library load? "))
5180 /* At this point, either the user was queried about setting
5181 a pending breakpoint and selected yes, or pending
5182 breakpoint behavior is on and thus a pending breakpoint
5183 is defaulted on behalf of the user. */
5184 copy_arg = xstrdup (addr_start);
5185 addr_string = ©_arg;
5187 sals.sals = &pending_sal;
5192 exception_print (gdb_stderr, e);
5200 /* Create a chain of things that always need to be cleaned up. */
5201 old_chain = make_cleanup (null_cleanup, 0);
5205 /* Make sure that all storage allocated to SALS gets freed. */
5206 make_cleanup (xfree, sals.sals);
5208 /* Cleanup the addr_string array but not its contents. */
5209 make_cleanup (xfree, addr_string);
5212 /* Allocate space for all the cond expressions. */
5213 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5214 make_cleanup (xfree, cond);
5216 /* Allocate space for all the cond strings. */
5217 cond_string = xcalloc (sals.nelts, sizeof (char **));
5218 make_cleanup (xfree, cond_string);
5220 /* ----------------------------- SNIP -----------------------------
5221 Anything added to the cleanup chain beyond this point is assumed
5222 to be part of a breakpoint. If the breakpoint create succeeds
5223 then the memory is not reclaimed. */
5224 breakpoint_chain = make_cleanup (null_cleanup, 0);
5226 /* Mark the contents of the addr_string for cleanup. These go on
5227 the breakpoint_chain and only occure if the breakpoint create
5229 for (i = 0; i < sals.nelts; i++)
5231 if (addr_string[i] != NULL)
5232 make_cleanup (xfree, addr_string[i]);
5235 /* Resolve all line numbers to PC's and verify that the addresses
5236 are ok for the target. */
5238 breakpoint_sals_to_pc (&sals, addr_start);
5240 /* Verify that condition can be parsed, before setting any
5241 breakpoints. Allocate a separate condition expression for each
5243 thread = -1; /* No specific thread yet */
5246 for (i = 0; i < sals.nelts; i++)
5253 char *cond_start = NULL;
5254 char *cond_end = NULL;
5255 while (*tok == ' ' || *tok == '\t')
5260 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5263 toklen = end_tok - tok;
5265 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5267 tok = cond_start = end_tok + 1;
5268 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc),
5270 make_cleanup (xfree, cond[i]);
5272 cond_string[i] = savestring (cond_start,
5273 cond_end - cond_start);
5274 make_cleanup (xfree, cond_string[i]);
5276 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5282 thread = strtol (tok, &tok, 0);
5284 error (_("Junk after thread keyword."));
5285 if (!valid_thread_id (thread))
5286 error (_("Unknown thread %d."), thread);
5289 error (_("Junk at end of arguments."));
5292 create_breakpoints (sals, addr_string, cond, cond_string,
5293 hardwareflag ? bp_hardware_breakpoint
5295 tempflag ? disp_del : disp_donttouch,
5296 thread, ignore_count, from_tty,
5301 struct symtab_and_line sal;
5302 struct breakpoint *b;
5307 make_cleanup (xfree, copy_arg);
5309 b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint
5311 set_breakpoint_count (breakpoint_count + 1);
5312 b->number = breakpoint_count;
5315 b->addr_string = *addr_string;
5316 b->cond_string = *cond_string;
5317 b->ignore_count = ignore_count;
5319 b->disposition = tempflag ? disp_del : disp_donttouch;
5320 b->from_tty = from_tty;
5326 warning (_("Multiple breakpoints were set.\n"
5327 "Use the \"delete\" command to delete unwanted breakpoints."));
5328 /* That's it. Discard the cleanups for data inserted into the
5330 discard_cleanups (breakpoint_chain);
5331 /* But cleanup everything else. */
5332 do_cleanups (old_chain);
5337 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5338 linenum or *address) with COND and IGNORE_COUNT. */
5340 struct captured_breakpoint_args
5351 do_captured_breakpoint (struct ui_out *uiout, void *data)
5353 struct captured_breakpoint_args *args = data;
5354 struct symtabs_and_lines sals;
5355 struct expression **cond;
5356 struct cleanup *old_chain;
5357 struct cleanup *breakpoint_chain = NULL;
5364 /* Parse the source and lines spec. Delay check that the expression
5365 didn't contain trailing garbage until after cleanups are in
5369 address_end = args->address;
5371 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5376 /* Create a chain of things at always need to be cleaned up. */
5377 old_chain = make_cleanup (null_cleanup, 0);
5379 /* Always have a addr_string array, even if it is empty. */
5380 make_cleanup (xfree, addr_string);
5382 /* Make sure that all storage allocated to SALS gets freed. */
5383 make_cleanup (xfree, sals.sals);
5385 /* Allocate space for all the cond expressions. */
5386 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5387 make_cleanup (xfree, cond);
5389 /* Allocate space for all the cond strings. */
5390 cond_string = xcalloc (sals.nelts, sizeof (char **));
5391 make_cleanup (xfree, cond_string);
5393 /* ----------------------------- SNIP -----------------------------
5394 Anything added to the cleanup chain beyond this point is assumed
5395 to be part of a breakpoint. If the breakpoint create goes
5396 through then that memory is not cleaned up. */
5397 breakpoint_chain = make_cleanup (null_cleanup, 0);
5399 /* Mark the contents of the addr_string for cleanup. These go on
5400 the breakpoint_chain and only occure if the breakpoint create
5402 for (i = 0; i < sals.nelts; i++)
5404 if (addr_string[i] != NULL)
5405 make_cleanup (xfree, addr_string[i]);
5408 /* Wait until now before checking for garbage at the end of the
5409 address. That way cleanups can take care of freeing any
5411 if (*address_end != '\0')
5412 error (_("Garbage %s following breakpoint address"), address_end);
5414 /* Resolve all line numbers to PC's. */
5415 breakpoint_sals_to_pc (&sals, args->address);
5417 /* Verify that conditions can be parsed, before setting any
5419 for (i = 0; i < sals.nelts; i++)
5421 if (args->condition != NULL)
5423 char *tok = args->condition;
5424 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5426 error (_("Garbage %s follows condition"), tok);
5427 make_cleanup (xfree, cond[i]);
5428 cond_string[i] = xstrdup (args->condition);
5432 create_breakpoints (sals, addr_string, cond, cond_string,
5433 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5434 args->tempflag ? disp_del : disp_donttouch,
5435 args->thread, args->ignore_count, 0/*from-tty*/,
5436 NULL/*pending_bp*/);
5438 /* That's it. Discard the cleanups for data inserted into the
5440 discard_cleanups (breakpoint_chain);
5441 /* But cleanup everything else. */
5442 do_cleanups (old_chain);
5447 gdb_breakpoint (char *address, char *condition,
5448 int hardwareflag, int tempflag,
5449 int thread, int ignore_count,
5450 char **error_message)
5452 struct captured_breakpoint_args args;
5453 args.address = address;
5454 args.condition = condition;
5455 args.hardwareflag = hardwareflag;
5456 args.tempflag = tempflag;
5457 args.thread = thread;
5458 args.ignore_count = ignore_count;
5459 return catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5460 error_message, RETURN_MASK_ALL);
5464 /* Helper function for break_command_1 and disassemble_command. */
5467 resolve_sal_pc (struct symtab_and_line *sal)
5471 if (sal->pc == 0 && sal->symtab != NULL)
5473 if (!find_line_pc (sal->symtab, sal->line, &pc))
5474 error (_("No line %d in file \"%s\"."),
5475 sal->line, sal->symtab->filename);
5479 if (sal->section == 0 && sal->symtab != NULL)
5481 struct blockvector *bv;
5486 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5489 b = BLOCKVECTOR_BLOCK (bv, index);
5490 sym = block_function (b);
5493 fixup_symbol_section (sym, sal->symtab->objfile);
5494 sal->section = SYMBOL_BFD_SECTION (sym);
5498 /* It really is worthwhile to have the section, so we'll just
5499 have to look harder. This case can be executed if we have
5500 line numbers but no functions (as can happen in assembly
5503 struct minimal_symbol *msym;
5505 msym = lookup_minimal_symbol_by_pc (sal->pc);
5507 sal->section = SYMBOL_BFD_SECTION (msym);
5514 break_command (char *arg, int from_tty)
5516 break_command_1 (arg, 0, from_tty, NULL);
5520 tbreak_command (char *arg, int from_tty)
5522 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5526 hbreak_command (char *arg, int from_tty)
5528 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5532 thbreak_command (char *arg, int from_tty)
5534 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5538 stop_command (char *arg, int from_tty)
5540 printf_filtered (_("Specify the type of breakpoint to set.\n\
5541 Usage: stop in <function | address>\n\
5542 stop at <line>\n"));
5546 stopin_command (char *arg, int from_tty)
5550 if (arg == (char *) NULL)
5552 else if (*arg != '*')
5557 /* look for a ':'. If this is a line number specification, then
5558 say it is bad, otherwise, it should be an address or
5559 function/method name */
5560 while (*argptr && !hasColon)
5562 hasColon = (*argptr == ':');
5567 badInput = (*argptr != ':'); /* Not a class::method */
5569 badInput = isdigit (*arg); /* a simple line number */
5573 printf_filtered (_("Usage: stop in <function | address>\n"));
5575 break_command_1 (arg, 0, from_tty, NULL);
5579 stopat_command (char *arg, int from_tty)
5583 if (arg == (char *) NULL || *arg == '*') /* no line number */
5590 /* look for a ':'. If there is a '::' then get out, otherwise
5591 it is probably a line number. */
5592 while (*argptr && !hasColon)
5594 hasColon = (*argptr == ':');
5599 badInput = (*argptr == ':'); /* we have class::method */
5601 badInput = !isdigit (*arg); /* not a line number */
5605 printf_filtered (_("Usage: stop at <line>\n"));
5607 break_command_1 (arg, 0, from_tty, NULL);
5610 /* accessflag: hw_write: watch write,
5611 hw_read: watch read,
5612 hw_access: watch access (read or write) */
5614 watch_command_1 (char *arg, int accessflag, int from_tty)
5616 struct breakpoint *b;
5617 struct symtab_and_line sal;
5618 struct expression *exp;
5619 struct block *exp_valid_block;
5620 struct value *val, *mark;
5621 struct frame_info *frame;
5622 struct frame_info *prev_frame = NULL;
5623 char *exp_start = NULL;
5624 char *exp_end = NULL;
5625 char *tok, *end_tok;
5627 char *cond_start = NULL;
5628 char *cond_end = NULL;
5629 struct expression *cond = NULL;
5630 int i, other_type_used, target_resources_ok = 0;
5631 enum bptype bp_type;
5634 init_sal (&sal); /* initialize to zeroes */
5636 /* Parse arguments. */
5637 innermost_block = NULL;
5639 exp = parse_exp_1 (&arg, 0, 0);
5641 exp_valid_block = innermost_block;
5642 mark = value_mark ();
5643 val = evaluate_expression (exp);
5644 release_value (val);
5645 if (value_lazy (val))
5646 value_fetch_lazy (val);
5649 while (*tok == ' ' || *tok == '\t')
5653 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5656 toklen = end_tok - tok;
5657 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5659 tok = cond_start = end_tok + 1;
5660 cond = parse_exp_1 (&tok, 0, 0);
5664 error (_("Junk at end of command."));
5666 if (accessflag == hw_read)
5667 bp_type = bp_read_watchpoint;
5668 else if (accessflag == hw_access)
5669 bp_type = bp_access_watchpoint;
5671 bp_type = bp_hardware_watchpoint;
5673 mem_cnt = can_use_hardware_watchpoint (val);
5674 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5675 error (_("Expression cannot be implemented with read/access watchpoint."));
5678 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5679 target_resources_ok =
5680 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5682 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5683 error (_("Target does not support this type of hardware watchpoint."));
5685 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5686 error (_("Target can only support one kind of HW watchpoint at a time."));
5689 #if defined(HPUXHPPA)
5690 /* On HP-UX if you set a h/w
5691 watchpoint before the "run" command, the inferior dies with a e.g.,
5692 SIGILL once you start it. I initially believed this was due to a
5693 bad interaction between page protection traps and the initial
5694 startup sequence by the dynamic linker.
5696 However, I tried avoiding that by having HP-UX's implementation of
5697 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5698 yet, which forced slow watches before a "run" or "attach", and it
5699 still fails somewhere in the startup code.
5701 Until I figure out what's happening, I'm disallowing watches altogether
5702 before the "run" or "attach" command. We'll tell the user they must
5703 set watches after getting the program started. */
5704 if (!target_has_execution)
5706 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5709 #endif /* HPUXHPPA */
5711 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5712 watchpoint could not be set. */
5713 if (!mem_cnt || target_resources_ok <= 0)
5714 bp_type = bp_watchpoint;
5716 /* Now set up the breakpoint. */
5717 b = set_raw_breakpoint (sal, bp_type);
5718 set_breakpoint_count (breakpoint_count + 1);
5719 b->number = breakpoint_count;
5720 b->disposition = disp_donttouch;
5722 b->exp_valid_block = exp_valid_block;
5723 b->exp_string = savestring (exp_start, exp_end - exp_start);
5727 b->cond_string = savestring (cond_start, cond_end - cond_start);
5731 frame = block_innermost_frame (exp_valid_block);
5734 prev_frame = get_prev_frame (frame);
5735 b->watchpoint_frame = get_frame_id (frame);
5739 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5742 /* If the expression is "local", then set up a "watchpoint scope"
5743 breakpoint at the point where we've left the scope of the watchpoint
5745 if (innermost_block)
5749 struct breakpoint *scope_breakpoint;
5750 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5751 bp_watchpoint_scope);
5753 scope_breakpoint->enable_state = bp_enabled;
5755 /* Automatically delete the breakpoint when it hits. */
5756 scope_breakpoint->disposition = disp_del;
5758 /* Only break in the proper frame (help with recursion). */
5759 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5761 /* Set the address at which we will stop. */
5762 scope_breakpoint->loc->requested_address
5763 = get_frame_pc (prev_frame);
5764 scope_breakpoint->loc->address
5765 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5766 scope_breakpoint->type);
5768 /* The scope breakpoint is related to the watchpoint. We
5769 will need to act on them together. */
5770 b->related_breakpoint = scope_breakpoint;
5773 value_free_to_mark (mark);
5777 /* Return count of locations need to be watched and can be handled
5778 in hardware. If the watchpoint can not be handled
5779 in hardware return zero. */
5781 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5782 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5783 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5787 can_use_hardware_watchpoint (struct value *v)
5789 int found_memory_cnt = 0;
5790 struct value *head = v;
5792 /* Did the user specifically forbid us to use hardware watchpoints? */
5793 if (!can_use_hw_watchpoints)
5796 /* Make sure that the value of the expression depends only upon
5797 memory contents, and values computed from them within GDB. If we
5798 find any register references or function calls, we can't use a
5799 hardware watchpoint.
5801 The idea here is that evaluating an expression generates a series
5802 of values, one holding the value of every subexpression. (The
5803 expression a*b+c has five subexpressions: a, b, a*b, c, and
5804 a*b+c.) GDB's values hold almost enough information to establish
5805 the criteria given above --- they identify memory lvalues,
5806 register lvalues, computed values, etcetera. So we can evaluate
5807 the expression, and then scan the chain of values that leaves
5808 behind to decide whether we can detect any possible change to the
5809 expression's final value using only hardware watchpoints.
5811 However, I don't think that the values returned by inferior
5812 function calls are special in any way. So this function may not
5813 notice that an expression involving an inferior function call
5814 can't be watched with hardware watchpoints. FIXME. */
5815 for (; v; v = value_next (v))
5817 if (VALUE_LVAL (v) == lval_memory)
5820 /* A lazy memory lvalue is one that GDB never needed to fetch;
5821 we either just used its address (e.g., `a' in `a.b') or
5822 we never needed it at all (e.g., `a' in `a,b'). */
5826 /* Ahh, memory we actually used! Check if we can cover
5827 it with hardware watchpoints. */
5828 struct type *vtype = check_typedef (value_type (v));
5830 /* We only watch structs and arrays if user asked for it
5831 explicitly, never if they just happen to appear in a
5832 middle of some value chain. */
5834 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5835 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5837 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
5838 int len = TYPE_LENGTH (value_type (v));
5840 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5847 else if (VALUE_LVAL (v) != not_lval
5848 && deprecated_value_modifiable (v) == 0)
5849 return 0; /* ??? What does this represent? */
5850 else if (VALUE_LVAL (v) == lval_register)
5851 return 0; /* cannot watch a register with a HW watchpoint */
5854 /* The expression itself looks suitable for using a hardware
5855 watchpoint, but give the target machine a chance to reject it. */
5856 return found_memory_cnt;
5860 watch_command_wrapper (char *arg, int from_tty)
5862 watch_command (arg, from_tty);
5866 watch_command (char *arg, int from_tty)
5868 watch_command_1 (arg, hw_write, from_tty);
5872 rwatch_command_wrapper (char *arg, int from_tty)
5874 rwatch_command (arg, from_tty);
5878 rwatch_command (char *arg, int from_tty)
5880 watch_command_1 (arg, hw_read, from_tty);
5884 awatch_command_wrapper (char *arg, int from_tty)
5886 awatch_command (arg, from_tty);
5890 awatch_command (char *arg, int from_tty)
5892 watch_command_1 (arg, hw_access, from_tty);
5896 /* Helper routines for the until_command routine in infcmd.c. Here
5897 because it uses the mechanisms of breakpoints. */
5899 /* This function is called by fetch_inferior_event via the
5900 cmd_continuation pointer, to complete the until command. It takes
5901 care of cleaning up the temporary breakpoints set up by the until
5904 until_break_command_continuation (struct continuation_arg *arg)
5906 struct cleanup *cleanups;
5908 cleanups = (struct cleanup *) arg->data.pointer;
5909 do_exec_cleanups (cleanups);
5913 until_break_command (char *arg, int from_tty, int anywhere)
5915 struct symtabs_and_lines sals;
5916 struct symtab_and_line sal;
5917 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5918 struct breakpoint *breakpoint;
5919 struct cleanup *old_chain;
5920 struct continuation_arg *arg1;
5923 clear_proceed_status ();
5925 /* Set a breakpoint where the user wants it and at return from
5928 if (default_breakpoint_valid)
5929 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5930 default_breakpoint_line, (char ***) NULL, NULL);
5932 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5933 0, (char ***) NULL, NULL);
5935 if (sals.nelts != 1)
5936 error (_("Couldn't get information on specified line."));
5939 xfree (sals.sals); /* malloc'd, so freed */
5942 error (_("Junk at end of arguments."));
5944 resolve_sal_pc (&sal);
5947 /* If the user told us to continue until a specified location,
5948 we don't specify a frame at which we need to stop. */
5949 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5951 /* Otherwise, specify the current frame, because we want to stop only
5952 at the very same frame. */
5953 breakpoint = set_momentary_breakpoint (sal,
5954 get_frame_id (deprecated_selected_frame),
5957 if (!target_can_async_p ())
5958 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5960 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5962 /* If we are running asynchronously, and the target supports async
5963 execution, we are not waiting for the target to stop, in the call
5964 tp proceed, below. This means that we cannot delete the
5965 brekpoints until the target has actually stopped. The only place
5966 where we get a chance to do that is in fetch_inferior_event, so
5967 we must set things up for that. */
5969 if (target_can_async_p ())
5971 /* In this case the arg for the continuation is just the point
5972 in the exec_cleanups chain from where to start doing
5973 cleanups, because all the continuation does is the cleanups in
5974 the exec_cleanup_chain. */
5976 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5978 arg1->data.pointer = old_chain;
5980 add_continuation (until_break_command_continuation, arg1);
5983 /* Keep within the current frame, or in frames called by the current
5987 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5988 sal.pc = get_frame_pc (prev_frame);
5989 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5991 if (!target_can_async_p ())
5992 make_cleanup_delete_breakpoint (breakpoint);
5994 make_exec_cleanup_delete_breakpoint (breakpoint);
5997 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5998 /* Do the cleanups now, anly if we are not running asynchronously,
5999 of if we are, but the target is still synchronous. */
6000 if (!target_can_async_p ())
6001 do_cleanups (old_chain);
6005 ep_skip_leading_whitespace (char **s)
6007 if ((s == NULL) || (*s == NULL))
6009 while (isspace (**s))
6013 /* This function examines a string, and attempts to find a token
6014 that might be an event name in the leading characters. If a
6015 possible match is found, a pointer to the last character of
6016 the token is returned. Else, NULL is returned. */
6019 ep_find_event_name_end (char *arg)
6022 char *event_name_end = NULL;
6024 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6028 /* We break out of the loop when we find a token delimiter.
6029 Basically, we're looking for alphanumerics and underscores;
6030 anything else delimites the token. */
6033 if (!isalnum (*s) && (*s != '_'))
6039 return event_name_end;
6043 /* This function attempts to parse an optional "if <cond>" clause
6044 from the arg string. If one is not found, it returns NULL.
6046 Else, it returns a pointer to the condition string. (It does not
6047 attempt to evaluate the string against a particular block.) And,
6048 it updates arg to point to the first character following the parsed
6049 if clause in the arg string. */
6052 ep_parse_optional_if_clause (char **arg)
6056 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6059 /* Skip the "if" keyword. */
6062 /* Skip any extra leading whitespace, and record the start of the
6063 condition string. */
6064 ep_skip_leading_whitespace (arg);
6067 /* Assume that the condition occupies the remainder of the arg string. */
6068 (*arg) += strlen (cond_string);
6073 /* This function attempts to parse an optional filename from the arg
6074 string. If one is not found, it returns NULL.
6076 Else, it returns a pointer to the parsed filename. (This function
6077 makes no attempt to verify that a file of that name exists, or is
6078 accessible.) And, it updates arg to point to the first character
6079 following the parsed filename in the arg string.
6081 Note that clients needing to preserve the returned filename for
6082 future access should copy it to their own buffers. */
6084 ep_parse_optional_filename (char **arg)
6086 static char filename[1024];
6091 if ((*arg_p == '\0') || isspace (*arg_p))
6109 /* Commands to deal with catching events, such as signals, exceptions,
6110 process start/exit, etc. */
6114 catch_fork, catch_vfork
6119 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6122 char *cond_string = NULL;
6124 ep_skip_leading_whitespace (&arg);
6126 /* The allowed syntax is:
6128 catch [v]fork if <cond>
6130 First, check if there's an if clause. */
6131 cond_string = ep_parse_optional_if_clause (&arg);
6133 if ((*arg != '\0') && !isspace (*arg))
6134 error (_("Junk at end of arguments."));
6136 /* If this target supports it, create a fork or vfork catchpoint
6137 and enable reporting of such events. */
6141 create_fork_event_catchpoint (tempflag, cond_string);
6144 create_vfork_event_catchpoint (tempflag, cond_string);
6147 error (_("unsupported or unknown fork kind; cannot catch it"));
6153 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6155 char *cond_string = NULL;
6157 ep_skip_leading_whitespace (&arg);
6159 /* The allowed syntax is:
6161 catch exec if <cond>
6163 First, check if there's an if clause. */
6164 cond_string = ep_parse_optional_if_clause (&arg);
6166 if ((*arg != '\0') && !isspace (*arg))
6167 error (_("Junk at end of arguments."));
6169 /* If this target supports it, create an exec catchpoint
6170 and enable reporting of such events. */
6171 create_exec_event_catchpoint (tempflag, cond_string);
6175 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6177 char *dll_pathname = NULL;
6178 char *cond_string = NULL;
6180 ep_skip_leading_whitespace (&arg);
6182 /* The allowed syntax is:
6184 catch load if <cond>
6185 catch load <filename>
6186 catch load <filename> if <cond>
6188 The user is not allowed to specify the <filename> after an
6191 We'll ignore the pathological case of a file named "if".
6193 First, check if there's an if clause. If so, then there
6194 cannot be a filename. */
6195 cond_string = ep_parse_optional_if_clause (&arg);
6197 /* If there was an if clause, then there cannot be a filename.
6198 Else, there might be a filename and an if clause. */
6199 if (cond_string == NULL)
6201 dll_pathname = ep_parse_optional_filename (&arg);
6202 ep_skip_leading_whitespace (&arg);
6203 cond_string = ep_parse_optional_if_clause (&arg);
6206 if ((*arg != '\0') && !isspace (*arg))
6207 error (_("Junk at end of arguments."));
6209 /* Create a load breakpoint that only triggers when a load of
6210 the specified dll (or any dll, if no pathname was specified)
6212 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6213 dll_pathname, cond_string);
6217 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6219 char *dll_pathname = NULL;
6220 char *cond_string = NULL;
6222 ep_skip_leading_whitespace (&arg);
6224 /* The allowed syntax is:
6226 catch unload if <cond>
6227 catch unload <filename>
6228 catch unload <filename> if <cond>
6230 The user is not allowed to specify the <filename> after an
6233 We'll ignore the pathological case of a file named "if".
6235 First, check if there's an if clause. If so, then there
6236 cannot be a filename. */
6237 cond_string = ep_parse_optional_if_clause (&arg);
6239 /* If there was an if clause, then there cannot be a filename.
6240 Else, there might be a filename and an if clause. */
6241 if (cond_string == NULL)
6243 dll_pathname = ep_parse_optional_filename (&arg);
6244 ep_skip_leading_whitespace (&arg);
6245 cond_string = ep_parse_optional_if_clause (&arg);
6248 if ((*arg != '\0') && !isspace (*arg))
6249 error (_("Junk at end of arguments."));
6251 /* Create an unload breakpoint that only triggers when an unload of
6252 the specified dll (or any dll, if no pathname was specified)
6254 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6255 dll_pathname, cond_string);
6258 /* Commands to deal with catching exceptions. */
6260 /* Set a breakpoint at the specified callback routine for an
6261 exception event callback */
6264 create_exception_catchpoint (int tempflag, char *cond_string,
6265 enum exception_event_kind ex_event,
6266 struct symtab_and_line *sal)
6268 struct breakpoint *b;
6269 int thread = -1; /* All threads. */
6272 if (!sal) /* no exception support? */
6277 case EX_EVENT_THROW:
6278 bptype = bp_catch_throw;
6280 case EX_EVENT_CATCH:
6281 bptype = bp_catch_catch;
6283 default: /* error condition */
6284 error (_("Internal error -- invalid catchpoint kind"));
6287 b = set_raw_breakpoint (*sal, bptype);
6288 set_breakpoint_count (breakpoint_count + 1);
6289 b->number = breakpoint_count;
6291 b->cond_string = (cond_string == NULL) ?
6292 NULL : savestring (cond_string, strlen (cond_string));
6294 b->addr_string = NULL;
6295 b->enable_state = bp_enabled;
6296 b->disposition = tempflag ? disp_del : disp_donttouch;
6300 static enum print_stop_action
6301 print_exception_catchpoint (struct breakpoint *b)
6303 annotate_catchpoint (b->number);
6305 if (strstr (b->addr_string, "throw") != NULL)
6306 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6309 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6312 return PRINT_SRC_AND_LOC;
6316 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6321 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6324 *last_addr = b->loc->address;
6325 if (strstr (b->addr_string, "throw") != NULL)
6326 ui_out_field_string (uiout, "what", "exception throw");
6328 ui_out_field_string (uiout, "what", "exception catch");
6332 print_mention_exception_catchpoint (struct breakpoint *b)
6334 if (strstr (b->addr_string, "throw") != NULL)
6335 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6337 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6340 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6341 print_exception_catchpoint,
6342 print_one_exception_catchpoint,
6343 print_mention_exception_catchpoint
6347 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6348 enum exception_event_kind ex_event, int from_tty)
6350 char *trigger_func_name, *nameptr;
6351 struct symtabs_and_lines sals;
6352 struct breakpoint *b;
6354 if (ex_event == EX_EVENT_CATCH)
6355 trigger_func_name = xstrdup ("__cxa_begin_catch");
6357 trigger_func_name = xstrdup ("__cxa_throw");
6359 nameptr = trigger_func_name;
6360 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6361 if (sals.nelts == 0)
6363 xfree (trigger_func_name);
6367 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6368 set_breakpoint_count (breakpoint_count + 1);
6369 b->number = breakpoint_count;
6371 b->cond_string = (cond_string == NULL) ?
6372 NULL : savestring (cond_string, strlen (cond_string));
6374 b->addr_string = trigger_func_name;
6375 b->enable_state = bp_enabled;
6376 b->disposition = tempflag ? disp_del : disp_donttouch;
6377 b->ops = &gnu_v3_exception_catchpoint_ops;
6384 /* Deal with "catch catch" and "catch throw" commands */
6387 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6388 int tempflag, int from_tty)
6390 char *cond_string = NULL;
6391 struct symtab_and_line *sal = NULL;
6393 ep_skip_leading_whitespace (&arg);
6395 cond_string = ep_parse_optional_if_clause (&arg);
6397 if ((*arg != '\0') && !isspace (*arg))
6398 error (_("Junk at end of arguments."));
6400 if ((ex_event != EX_EVENT_THROW) &&
6401 (ex_event != EX_EVENT_CATCH))
6402 error (_("Unsupported or unknown exception event; cannot catch it"));
6404 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6407 /* See if we can find a callback routine */
6408 sal = target_enable_exception_callback (ex_event, 1);
6412 /* We have callbacks from the runtime system for exceptions.
6413 Set a breakpoint on the sal found, if no errors */
6414 if (sal != (struct symtab_and_line *) -1)
6415 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6417 return; /* something went wrong with setting up callbacks */
6420 warning (_("Unsupported with this platform/compiler combination."));
6423 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6424 inside a catch_errors */
6427 cover_target_enable_exception_callback (void *arg)
6429 args_for_catchpoint_enable *args = arg;
6430 struct symtab_and_line *sal;
6431 sal = target_enable_exception_callback (args->kind, args->enable_p);
6434 else if (sal == (struct symtab_and_line *) -1)
6437 return 1; /*is valid */
6441 catch_command_1 (char *arg, int tempflag, int from_tty)
6444 /* The first argument may be an event name, such as "start" or "load".
6445 If so, then handle it as such. If it doesn't match an event name,
6446 then attempt to interpret it as an exception name. (This latter is
6447 the v4.16-and-earlier GDB meaning of the "catch" command.)
6449 First, try to find the bounds of what might be an event name. */
6450 char *arg1_start = arg;
6454 if (arg1_start == NULL)
6456 /* Old behaviour was to use pre-v-4.16 syntax */
6457 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6459 /* Now, this is not allowed */
6460 error (_("Catch requires an event name."));
6463 arg1_end = ep_find_event_name_end (arg1_start);
6464 if (arg1_end == NULL)
6465 error (_("catch requires an event"));
6466 arg1_length = arg1_end + 1 - arg1_start;
6468 /* Try to match what we found against known event names. */
6469 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6471 error (_("Catch of signal not yet implemented"));
6473 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6475 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6476 tempflag, from_tty);
6478 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6480 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6481 tempflag, from_tty);
6483 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6485 error (_("Catch of thread_start not yet implemented"));
6487 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6489 error (_("Catch of thread_exit not yet implemented"));
6491 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6493 error (_("Catch of thread_join not yet implemented"));
6495 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6497 error (_("Catch of start not yet implemented"));
6499 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6501 error (_("Catch of exit not yet implemented"));
6503 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6505 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6507 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6509 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6511 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6513 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6515 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6517 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6519 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6521 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6523 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6525 error (_("Catch of stop not yet implemented"));
6528 /* This doesn't appear to be an event name */
6532 /* Pre-v.4.16 behaviour was to treat the argument
6533 as the name of an exception */
6534 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6535 /* Now this is not allowed */
6536 error (_("Unknown event kind specified for catch"));
6541 /* Used by the gui, could be made a worker for other things. */
6544 set_breakpoint_sal (struct symtab_and_line sal)
6546 struct breakpoint *b;
6547 b = set_raw_breakpoint (sal, bp_breakpoint);
6548 set_breakpoint_count (breakpoint_count + 1);
6549 b->number = breakpoint_count;
6556 catch_command (char *arg, int from_tty)
6558 catch_command_1 (arg, 0, from_tty);
6563 tcatch_command (char *arg, int from_tty)
6565 catch_command_1 (arg, 1, from_tty);
6568 /* Delete breakpoints by address or line. */
6571 clear_command (char *arg, int from_tty)
6573 struct breakpoint *b, *tmp, *prev, *found;
6575 struct symtabs_and_lines sals;
6576 struct symtab_and_line sal;
6581 sals = decode_line_spec (arg, 1);
6586 sals.sals = (struct symtab_and_line *)
6587 xmalloc (sizeof (struct symtab_and_line));
6588 make_cleanup (xfree, sals.sals);
6589 init_sal (&sal); /* initialize to zeroes */
6590 sal.line = default_breakpoint_line;
6591 sal.symtab = default_breakpoint_symtab;
6592 sal.pc = default_breakpoint_address;
6593 if (sal.symtab == 0)
6594 error (_("No source file specified."));
6602 /* For each line spec given, delete bps which correspond
6603 to it. Do it in two passes, solely to preserve the current
6604 behavior that from_tty is forced true if we delete more than
6608 for (i = 0; i < sals.nelts; i++)
6610 /* If exact pc given, clear bpts at that pc.
6611 If line given (pc == 0), clear all bpts on specified line.
6612 If defaulting, clear all bpts on default line
6615 defaulting sal.pc != 0 tests to do
6620 1 0 <can't happen> */
6625 /* Find all matching breakpoints, remove them from the
6626 breakpoint chain, and add them to the 'found' chain. */
6627 ALL_BREAKPOINTS_SAFE (b, tmp)
6629 /* Are we going to delete b? */
6630 if (b->type != bp_none
6631 && b->type != bp_watchpoint
6632 && b->type != bp_hardware_watchpoint
6633 && b->type != bp_read_watchpoint
6634 && b->type != bp_access_watchpoint
6635 /* Not if b is a watchpoint of any sort... */
6636 && (((sal.pc && (b->loc->address == sal.pc))
6637 && (!section_is_overlay (b->loc->section)
6638 || b->loc->section == sal.section))
6639 /* Yes, if sal.pc matches b (modulo overlays). */
6640 || ((default_match || (0 == sal.pc))
6641 && b->source_file != NULL
6642 && sal.symtab != NULL
6643 && strcmp (b->source_file, sal.symtab->filename) == 0
6644 && b->line_number == sal.line)))
6645 /* Yes, if sal source file and line matches b. */
6647 /* Remove it from breakpoint_chain... */
6648 if (b == breakpoint_chain)
6650 /* b is at the head of the list */
6651 breakpoint_chain = b->next;
6655 prev->next = b->next;
6657 /* And add it to 'found' chain. */
6663 /* Keep b, and keep a pointer to it. */
6668 /* Now go thru the 'found' chain and delete them. */
6672 error (_("No breakpoint at %s."), arg);
6674 error (_("No breakpoint at this line."));
6678 from_tty = 1; /* Always report if deleted more than one */
6682 printf_unfiltered (_("Deleted breakpoint "));
6684 printf_unfiltered (_("Deleted breakpoints "));
6686 breakpoints_changed ();
6690 printf_unfiltered ("%d ", found->number);
6692 delete_breakpoint (found);
6696 putchar_unfiltered ('\n');
6699 /* Delete breakpoint in BS if they are `delete' breakpoints and
6700 all breakpoints that are marked for deletion, whether hit or not.
6701 This is called after any breakpoint is hit, or after errors. */
6704 breakpoint_auto_delete (bpstat bs)
6706 struct breakpoint *b, *temp;
6708 for (; bs; bs = bs->next)
6709 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6711 delete_breakpoint (bs->breakpoint_at);
6713 ALL_BREAKPOINTS_SAFE (b, temp)
6715 if (b->disposition == disp_del_at_next_stop)
6716 delete_breakpoint (b);
6720 /* Delete a breakpoint and clean up all traces of it in the data
6724 delete_breakpoint (struct breakpoint *bpt)
6726 struct breakpoint *b;
6728 struct bp_location *loc;
6730 gdb_assert (bpt != NULL);
6732 /* Has this bp already been deleted? This can happen because multiple
6733 lists can hold pointers to bp's. bpstat lists are especial culprits.
6735 One example of this happening is a watchpoint's scope bp. When the
6736 scope bp triggers, we notice that the watchpoint is out of scope, and
6737 delete it. We also delete its scope bp. But the scope bp is marked
6738 "auto-deleting", and is already on a bpstat. That bpstat is then
6739 checked for auto-deleting bp's, which are deleted.
6741 A real solution to this problem might involve reference counts in bp's,
6742 and/or giving them pointers back to their referencing bpstat's, and
6743 teaching delete_breakpoint to only free a bp's storage when no more
6744 references were extent. A cheaper bandaid was chosen. */
6745 if (bpt->type == bp_none)
6748 if (deprecated_delete_breakpoint_hook)
6749 deprecated_delete_breakpoint_hook (bpt);
6750 breakpoint_delete_event (bpt->number);
6752 if (bpt->loc->inserted)
6753 remove_breakpoint (bpt->loc, mark_inserted);
6755 free_valchain (bpt->loc);
6757 if (breakpoint_chain == bpt)
6758 breakpoint_chain = bpt->next;
6760 if (bp_location_chain == bpt->loc)
6761 bp_location_chain = bpt->loc->next;
6763 /* If we have callback-style exception catchpoints, don't go through
6764 the adjustments to the C++ runtime library etc. if the inferior
6765 isn't actually running. target_enable_exception_callback for a
6766 null target ops vector gives an undesirable error message, so we
6767 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6768 exceptions are supported in this way, it's OK for now. FIXME */
6769 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6771 /* Format possible error msg */
6772 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6774 struct cleanup *cleanups = make_cleanup (xfree, message);
6775 args_for_catchpoint_enable args;
6776 args.kind = bpt->type == bp_catch_catch ?
6777 EX_EVENT_CATCH : EX_EVENT_THROW;
6779 catch_errors (cover_target_enable_exception_callback, &args,
6780 message, RETURN_MASK_ALL);
6781 do_cleanups (cleanups);
6788 b->next = bpt->next;
6792 ALL_BP_LOCATIONS (loc)
6793 if (loc->next == bpt->loc)
6795 loc->next = bpt->loc->next;
6799 check_duplicates (bpt);
6800 /* If this breakpoint was inserted, and there is another breakpoint
6801 at the same address, we need to insert the other breakpoint. */
6802 if (bpt->loc->inserted
6803 && bpt->type != bp_hardware_watchpoint
6804 && bpt->type != bp_read_watchpoint
6805 && bpt->type != bp_access_watchpoint
6806 && bpt->type != bp_catch_fork
6807 && bpt->type != bp_catch_vfork
6808 && bpt->type != bp_catch_exec)
6811 if (b->loc->address == bpt->loc->address
6812 && b->loc->section == bpt->loc->section
6813 && !b->loc->duplicate
6814 && b->enable_state != bp_disabled
6815 && b->enable_state != bp_shlib_disabled
6817 && b->enable_state != bp_call_disabled)
6821 /* We should never reach this point if there is a permanent
6822 breakpoint at the same address as the one being deleted.
6823 If there is a permanent breakpoint somewhere, it should
6824 always be the only one inserted. */
6825 if (b->enable_state == bp_permanent)
6826 internal_error (__FILE__, __LINE__,
6827 _("another breakpoint was inserted on top of "
6828 "a permanent breakpoint"));
6830 if (b->type == bp_hardware_breakpoint)
6831 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
6833 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
6835 /* If there was an error in the insert, print a message, then stop execution. */
6838 struct ui_file *tmp_error_stream = mem_fileopen ();
6839 make_cleanup_ui_file_delete (tmp_error_stream);
6842 if (b->type == bp_hardware_breakpoint)
6844 fprintf_unfiltered (tmp_error_stream,
6845 "Cannot insert hardware breakpoint %d.\n"
6846 "You may have requested too many hardware breakpoints.\n",
6851 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6852 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6853 deprecated_print_address_numeric (b->loc->address, 1, tmp_error_stream);
6854 fprintf_filtered (tmp_error_stream, ": %s.\n",
6855 safe_strerror (val));
6858 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6859 target_terminal_ours_for_output ();
6860 error_stream(tmp_error_stream);
6863 b->loc->inserted = 1;
6867 free_command_lines (&bpt->commands);
6870 if (bpt->cond_string != NULL)
6871 xfree (bpt->cond_string);
6872 if (bpt->addr_string != NULL)
6873 xfree (bpt->addr_string);
6874 if (bpt->exp != NULL)
6876 if (bpt->exp_string != NULL)
6877 xfree (bpt->exp_string);
6878 if (bpt->val != NULL)
6879 value_free (bpt->val);
6880 if (bpt->source_file != NULL)
6881 xfree (bpt->source_file);
6882 if (bpt->dll_pathname != NULL)
6883 xfree (bpt->dll_pathname);
6884 if (bpt->triggered_dll_pathname != NULL)
6885 xfree (bpt->triggered_dll_pathname);
6886 if (bpt->exec_pathname != NULL)
6887 xfree (bpt->exec_pathname);
6889 /* Be sure no bpstat's are pointing at it after it's been freed. */
6890 /* FIXME, how can we find all bpstat's?
6891 We just check stop_bpstat for now. */
6892 for (bs = stop_bpstat; bs; bs = bs->next)
6893 if (bs->breakpoint_at == bpt)
6895 bs->breakpoint_at = NULL;
6897 /* bs->commands will be freed later. */
6899 /* On the chance that someone will soon try again to delete this same
6900 bp, we mark it as deleted before freeing its storage. */
6901 bpt->type = bp_none;
6908 do_delete_breakpoint_cleanup (void *b)
6910 delete_breakpoint (b);
6914 make_cleanup_delete_breakpoint (struct breakpoint *b)
6916 return make_cleanup (do_delete_breakpoint_cleanup, b);
6920 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6922 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6926 delete_command (char *arg, int from_tty)
6928 struct breakpoint *b, *temp;
6934 int breaks_to_delete = 0;
6936 /* Delete all breakpoints if no argument.
6937 Do not delete internal or call-dummy breakpoints, these
6938 have to be deleted with an explicit breakpoint number argument. */
6941 if (b->type != bp_call_dummy &&
6942 b->type != bp_shlib_event &&
6943 b->type != bp_thread_event &&
6944 b->type != bp_overlay_event &&
6946 breaks_to_delete = 1;
6949 /* Ask user only if there are some breakpoints to delete. */
6951 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
6953 ALL_BREAKPOINTS_SAFE (b, temp)
6955 if (b->type != bp_call_dummy &&
6956 b->type != bp_shlib_event &&
6957 b->type != bp_thread_event &&
6958 b->type != bp_overlay_event &&
6960 delete_breakpoint (b);
6965 map_breakpoint_numbers (arg, delete_breakpoint);
6968 /* Reset a breakpoint given it's struct breakpoint * BINT.
6969 The value we return ends up being the return value from catch_errors.
6970 Unused in this case. */
6973 breakpoint_re_set_one (void *bint)
6975 /* get past catch_errs */
6976 struct breakpoint *b = (struct breakpoint *) bint;
6980 int *not_found_ptr = NULL;
6981 struct symtabs_and_lines sals;
6983 enum enable_state save_enable;
6988 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
6992 case bp_hardware_breakpoint:
6994 case bp_catch_unload:
6995 if (b->addr_string == NULL)
6997 /* Anything without a string can't be re-set. */
6998 delete_breakpoint (b);
7001 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7003 ``And a hack it is, although Apple's Darwin version of GDB
7004 contains an almost identical hack to implement a "future
7005 break" command. It seems to work in many real world cases,
7006 but it is easy to come up with a test case where the patch
7007 doesn't help at all.''
7009 ``It seems that the way GDB implements breakpoints - in -
7010 shared - libraries was designed for a.out shared library
7011 systems (SunOS 4) where shared libraries were loaded at a
7012 fixed address in memory. Since ELF shared libraries can (and
7013 will) be loaded at any address in memory, things break.
7014 Fixing this is not trivial. Therefore, I'm not sure whether
7015 we should add this hack to the branch only. I cannot
7016 guarantee that things will be fixed on the trunk in the near
7019 In case we have a problem, disable this breakpoint. We'll
7020 restore its status if we succeed. Don't disable a
7021 shlib_disabled breakpoint though. There's a fair chance we
7022 can't re-set it if the shared library it's in hasn't been
7028 save_enable = b->enable_state;
7029 if (b->enable_state != bp_shlib_disabled)
7030 b->enable_state = bp_disabled;
7032 /* If resetting a shlib-disabled breakpoint, we don't want to
7033 see an error message if it is not found since we will expect
7034 this to occur until the shared library is finally reloaded.
7035 We accomplish this by giving decode_line_1 a pointer to use
7036 for silent notification that the symbol is not found. */
7037 not_found_ptr = ¬_found;
7039 set_language (b->language);
7040 input_radix = b->input_radix;
7042 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7044 for (i = 0; i < sals.nelts; i++)
7046 resolve_sal_pc (&sals.sals[i]);
7048 /* Reparse conditions, they might contain references to the
7050 if (b->cond_string != NULL)
7056 /* Avoid re-freeing b->exp if an error during the call
7060 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7063 /* We need to re-set the breakpoint if the address changes... */
7064 if (b->loc->address != sals.sals[i].pc
7065 /* ...or new and old breakpoints both have source files, and
7066 the source file name or the line number changes... */
7067 || (b->source_file != NULL
7068 && sals.sals[i].symtab != NULL
7069 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
7070 || b->line_number != sals.sals[i].line)
7072 /* ...or we switch between having a source file and not having
7074 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7077 if (b->source_file != NULL)
7078 xfree (b->source_file);
7079 if (sals.sals[i].symtab == NULL)
7080 b->source_file = NULL;
7083 savestring (sals.sals[i].symtab->filename,
7084 strlen (sals.sals[i].symtab->filename));
7085 b->line_number = sals.sals[i].line;
7086 b->loc->requested_address = sals.sals[i].pc;
7088 = adjust_breakpoint_address (b->loc->requested_address,
7091 /* Used to check for duplicates here, but that can
7092 cause trouble, as it doesn't check for disabled
7097 /* Might be better to do this just once per breakpoint_re_set,
7098 rather than once for every breakpoint. */
7099 breakpoints_changed ();
7101 b->loc->section = sals.sals[i].section;
7102 b->enable_state = save_enable; /* Restore it, this worked. */
7105 /* Now that this is re-enabled, check_duplicates
7107 check_duplicates (b);
7114 case bp_hardware_watchpoint:
7115 case bp_read_watchpoint:
7116 case bp_access_watchpoint:
7117 innermost_block = NULL;
7118 /* The issue arises of what context to evaluate this in. The
7119 same one as when it was set, but what does that mean when
7120 symbols have been re-read? We could save the filename and
7121 functionname, but if the context is more local than that, the
7122 best we could do would be something like how many levels deep
7123 and which index at that particular level, but that's going to
7124 be less stable than filenames or function names. */
7126 /* So for now, just use a global context. */
7130 /* Avoid re-freeing b->exp if an error during the call to
7131 parse_expression. */
7134 b->exp = parse_expression (b->exp_string);
7135 b->exp_valid_block = innermost_block;
7136 mark = value_mark ();
7139 value_free (b->val);
7140 /* Avoid re-freeing b->val if an error during the call to
7141 evaluate_expression. */
7144 b->val = evaluate_expression (b->exp);
7145 release_value (b->val);
7146 if (value_lazy (b->val) && breakpoint_enabled (b))
7147 value_fetch_lazy (b->val);
7149 if (b->cond_string != NULL)
7155 /* Avoid re-freeing b->exp if an error during the call
7159 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7161 if (breakpoint_enabled (b))
7163 value_free_to_mark (mark);
7165 case bp_catch_catch:
7166 case bp_catch_throw:
7168 /* We needn't really do anything to reset these, since the mask
7169 that requests them is unaffected by e.g., new libraries being
7172 case bp_catch_vfork:
7177 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7179 /* Delete longjmp and overlay event breakpoints; they will be
7180 reset later by breakpoint_re_set. */
7182 case bp_longjmp_resume:
7183 case bp_overlay_event:
7184 delete_breakpoint (b);
7187 /* This breakpoint is special, it's set up when the inferior
7188 starts and we really don't want to touch it. */
7189 case bp_shlib_event:
7191 /* Like bp_shlib_event, this breakpoint type is special.
7192 Once it is set up, we do not want to touch it. */
7193 case bp_thread_event:
7195 /* Keep temporary breakpoints, which can be encountered when we step
7196 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7197 Otherwise these should have been blown away via the cleanup chain
7198 or by breakpoint_init_inferior when we rerun the executable. */
7201 case bp_watchpoint_scope:
7203 case bp_step_resume:
7210 /* Re-set all breakpoints after symbols have been re-loaded. */
7212 breakpoint_re_set (void)
7214 struct breakpoint *b, *temp;
7215 enum language save_language;
7216 int save_input_radix;
7218 save_language = current_language->la_language;
7219 save_input_radix = input_radix;
7220 ALL_BREAKPOINTS_SAFE (b, temp)
7222 /* Format possible error msg */
7223 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7225 struct cleanup *cleanups = make_cleanup (xfree, message);
7226 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7227 do_cleanups (cleanups);
7229 set_language (save_language);
7230 input_radix = save_input_radix;
7232 if (GET_LONGJMP_TARGET_P ())
7234 create_longjmp_breakpoint ("longjmp");
7235 create_longjmp_breakpoint ("_longjmp");
7236 create_longjmp_breakpoint ("siglongjmp");
7237 create_longjmp_breakpoint ("_siglongjmp");
7238 create_longjmp_breakpoint (NULL);
7241 create_overlay_event_breakpoint ("_ovly_debug_event");
7244 /* Reset the thread number of this breakpoint:
7246 - If the breakpoint is for all threads, leave it as-is.
7247 - Else, reset it to the current thread for inferior_ptid. */
7249 breakpoint_re_set_thread (struct breakpoint *b)
7251 if (b->thread != -1)
7253 if (in_thread_list (inferior_ptid))
7254 b->thread = pid_to_thread_id (inferior_ptid);
7258 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7259 If from_tty is nonzero, it prints a message to that effect,
7260 which ends with a period (no newline). */
7263 set_ignore_count (int bptnum, int count, int from_tty)
7265 struct breakpoint *b;
7271 if (b->number == bptnum)
7273 b->ignore_count = count;
7277 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7279 else if (count == 1)
7280 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7283 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7286 breakpoints_changed ();
7287 breakpoint_modify_event (b->number);
7291 error (_("No breakpoint number %d."), bptnum);
7294 /* Clear the ignore counts of all breakpoints. */
7296 breakpoint_clear_ignore_counts (void)
7298 struct breakpoint *b;
7301 b->ignore_count = 0;
7304 /* Command to set ignore-count of breakpoint N to COUNT. */
7307 ignore_command (char *args, int from_tty)
7313 error_no_arg (_("a breakpoint number"));
7315 num = get_number (&p);
7317 error (_("bad breakpoint number: '%s'"), args);
7319 error (_("Second argument (specified ignore-count) is missing."));
7321 set_ignore_count (num,
7322 longest_to_int (value_as_long (parse_and_eval (p))),
7325 printf_filtered ("\n");
7328 /* Call FUNCTION on each of the breakpoints
7329 whose numbers are given in ARGS. */
7332 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7337 struct breakpoint *b, *tmp;
7341 error_no_arg (_("one or more breakpoint numbers"));
7348 num = get_number_or_range (&p1);
7351 warning (_("bad breakpoint number at or near '%s'"), p);
7355 ALL_BREAKPOINTS_SAFE (b, tmp)
7356 if (b->number == num)
7358 struct breakpoint *related_breakpoint = b->related_breakpoint;
7361 if (related_breakpoint)
7362 function (related_breakpoint);
7366 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7372 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7373 If from_tty is nonzero, it prints a message to that effect,
7374 which ends with a period (no newline). */
7377 disable_breakpoint (struct breakpoint *bpt)
7379 /* Never disable a watchpoint scope breakpoint; we want to
7380 hit them when we leave scope so we can delete both the
7381 watchpoint and its scope breakpoint at that time. */
7382 if (bpt->type == bp_watchpoint_scope)
7385 /* You can't disable permanent breakpoints. */
7386 if (bpt->enable_state == bp_permanent)
7389 bpt->enable_state = bp_disabled;
7391 check_duplicates (bpt);
7393 if (deprecated_modify_breakpoint_hook)
7394 deprecated_modify_breakpoint_hook (bpt);
7395 breakpoint_modify_event (bpt->number);
7399 disable_command (char *args, int from_tty)
7401 struct breakpoint *bpt;
7403 ALL_BREAKPOINTS (bpt)
7407 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7412 case bp_catch_unload:
7414 case bp_catch_vfork:
7416 case bp_catch_catch:
7417 case bp_catch_throw:
7418 case bp_hardware_breakpoint:
7420 case bp_hardware_watchpoint:
7421 case bp_read_watchpoint:
7422 case bp_access_watchpoint:
7423 disable_breakpoint (bpt);
7428 map_breakpoint_numbers (args, disable_breakpoint);
7432 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7434 int target_resources_ok, other_type_used;
7437 if (bpt->type == bp_hardware_breakpoint)
7440 i = hw_breakpoint_used_count ();
7441 target_resources_ok =
7442 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7444 if (target_resources_ok == 0)
7445 error (_("No hardware breakpoint support in the target."));
7446 else if (target_resources_ok < 0)
7447 error (_("Hardware breakpoints used exceeds limit."));
7452 if (bpt->enable_state != bp_enabled)
7454 /* When enabling a pending breakpoint, we need to check if the breakpoint
7455 is resolvable since shared libraries could have been loaded
7456 after the breakpoint was disabled. */
7457 breakpoints_changed ();
7458 if (resolve_pending_breakpoint (bpt) == GDB_RC_OK)
7460 delete_breakpoint (bpt);
7463 bpt->enable_state = bp_enabled;
7464 bpt->disposition = disposition;
7467 else /* Not a pending breakpoint. */
7469 if (bpt->enable_state != bp_permanent)
7470 bpt->enable_state = bp_enabled;
7471 bpt->disposition = disposition;
7472 check_duplicates (bpt);
7473 breakpoints_changed ();
7475 if (bpt->type == bp_watchpoint ||
7476 bpt->type == bp_hardware_watchpoint ||
7477 bpt->type == bp_read_watchpoint ||
7478 bpt->type == bp_access_watchpoint)
7480 struct frame_id saved_frame_id;
7482 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7483 if (bpt->exp_valid_block != NULL)
7485 struct frame_info *fr =
7486 fr = frame_find_by_id (bpt->watchpoint_frame);
7489 printf_filtered (_("\
7490 Cannot enable watchpoint %d because the block in which its expression\n\
7491 is valid is not currently in scope.\n"), bpt->number);
7492 bpt->enable_state = bp_disabled;
7498 value_free (bpt->val);
7499 mark = value_mark ();
7500 bpt->val = evaluate_expression (bpt->exp);
7501 release_value (bpt->val);
7502 if (value_lazy (bpt->val))
7503 value_fetch_lazy (bpt->val);
7505 if (bpt->type == bp_hardware_watchpoint ||
7506 bpt->type == bp_read_watchpoint ||
7507 bpt->type == bp_access_watchpoint)
7509 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7510 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7512 /* Hack around 'unused var' error for some targets here */
7514 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7515 bpt->type, i + mem_cnt, other_type_used);
7516 /* we can consider of type is bp_hardware_watchpoint, convert to
7517 bp_watchpoint in the following condition */
7518 if (target_resources_ok < 0)
7520 printf_filtered (_("\
7521 Cannot enable watchpoint %d because target watch resources\n\
7522 have been allocated for other watchpoints.\n"), bpt->number);
7523 bpt->enable_state = bp_disabled;
7524 value_free_to_mark (mark);
7529 select_frame (frame_find_by_id (saved_frame_id));
7530 value_free_to_mark (mark);
7534 if (deprecated_modify_breakpoint_hook)
7535 deprecated_modify_breakpoint_hook (bpt);
7536 breakpoint_modify_event (bpt->number);
7540 enable_breakpoint (struct breakpoint *bpt)
7542 do_enable_breakpoint (bpt, bpt->disposition);
7545 /* The enable command enables the specified breakpoints (or all defined
7546 breakpoints) so they once again become (or continue to be) effective
7547 in stopping the inferior. */
7550 enable_command (char *args, int from_tty)
7552 struct breakpoint *bpt;
7554 ALL_BREAKPOINTS (bpt)
7558 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7563 case bp_catch_unload:
7565 case bp_catch_vfork:
7567 case bp_catch_catch:
7568 case bp_catch_throw:
7569 case bp_hardware_breakpoint:
7571 case bp_hardware_watchpoint:
7572 case bp_read_watchpoint:
7573 case bp_access_watchpoint:
7574 enable_breakpoint (bpt);
7579 map_breakpoint_numbers (args, enable_breakpoint);
7583 enable_once_breakpoint (struct breakpoint *bpt)
7585 do_enable_breakpoint (bpt, disp_disable);
7589 enable_once_command (char *args, int from_tty)
7591 map_breakpoint_numbers (args, enable_once_breakpoint);
7595 enable_delete_breakpoint (struct breakpoint *bpt)
7597 do_enable_breakpoint (bpt, disp_del);
7601 enable_delete_command (char *args, int from_tty)
7603 map_breakpoint_numbers (args, enable_delete_breakpoint);
7607 set_breakpoint_cmd (char *args, int from_tty)
7612 show_breakpoint_cmd (char *args, int from_tty)
7616 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7618 struct symtabs_and_lines
7619 decode_line_spec_1 (char *string, int funfirstline)
7621 struct symtabs_and_lines sals;
7623 error (_("Empty line specification."));
7624 if (default_breakpoint_valid)
7625 sals = decode_line_1 (&string, funfirstline,
7626 default_breakpoint_symtab,
7627 default_breakpoint_line,
7628 (char ***) NULL, NULL);
7630 sals = decode_line_1 (&string, funfirstline,
7631 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7633 error (_("Junk at end of line specification: %s"), string);
7638 _initialize_breakpoint (void)
7640 static struct cmd_list_element *breakpoint_set_cmdlist;
7641 static struct cmd_list_element *breakpoint_show_cmdlist;
7642 struct cmd_list_element *c;
7644 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
7646 breakpoint_chain = 0;
7647 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7648 before a breakpoint is set. */
7649 breakpoint_count = 0;
7651 add_com ("ignore", class_breakpoint, ignore_command, _("\
7652 Set ignore-count of breakpoint number N to COUNT.\n\
7653 Usage is `ignore N COUNT'."));
7655 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7657 add_com ("commands", class_breakpoint, commands_command, _("\
7658 Set commands to be executed when a breakpoint is hit.\n\
7659 Give breakpoint number as argument after \"commands\".\n\
7660 With no argument, the targeted breakpoint is the last one set.\n\
7661 The commands themselves follow starting on the next line.\n\
7662 Type a line containing \"end\" to indicate the end of them.\n\
7663 Give \"silent\" as the first line to make the breakpoint silent;\n\
7664 then no output is printed when it is hit, except what the commands print."));
7666 add_com ("condition", class_breakpoint, condition_command, _("\
7667 Specify breakpoint number N to break only if COND is true.\n\
7668 Usage is `condition N COND', where N is an integer and COND is an\n\
7669 expression to be evaluated whenever breakpoint N is reached."));
7671 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
7672 Set a temporary breakpoint. Args like \"break\" command.\n\
7673 Like \"break\" except the breakpoint is only temporary,\n\
7674 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7675 by using \"enable delete\" on the breakpoint number."));
7676 set_cmd_completer (c, location_completer);
7678 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
7679 Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7680 Like \"break\" except the breakpoint requires hardware support,\n\
7681 some target hardware may not have this support."));
7682 set_cmd_completer (c, location_completer);
7684 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
7685 Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7686 Like \"hbreak\" except the breakpoint is only temporary,\n\
7687 so it will be deleted when hit."));
7688 set_cmd_completer (c, location_completer);
7690 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
7691 Enable some breakpoints.\n\
7692 Give breakpoint numbers (separated by spaces) as arguments.\n\
7693 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7694 This is used to cancel the effect of the \"disable\" command.\n\
7695 With a subcommand you can enable temporarily."),
7696 &enablelist, "enable ", 1, &cmdlist);
7698 add_com ("ab", class_breakpoint, enable_command, _("\
7699 Enable some breakpoints.\n\
7700 Give breakpoint numbers (separated by spaces) as arguments.\n\
7701 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7702 This is used to cancel the effect of the \"disable\" command.\n\
7703 With a subcommand you can enable temporarily."));
7705 add_com_alias ("en", "enable", class_breakpoint, 1);
7707 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
7708 Enable some breakpoints.\n\
7709 Give breakpoint numbers (separated by spaces) as arguments.\n\
7710 This is used to cancel the effect of the \"disable\" command.\n\
7711 May be abbreviated to simply \"enable\".\n"),
7712 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7714 add_cmd ("once", no_class, enable_once_command, _("\
7715 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7716 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7719 add_cmd ("delete", no_class, enable_delete_command, _("\
7720 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7721 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7724 add_cmd ("delete", no_class, enable_delete_command, _("\
7725 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7726 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7729 add_cmd ("once", no_class, enable_once_command, _("\
7730 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7731 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7734 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
7735 Disable some breakpoints.\n\
7736 Arguments are breakpoint numbers with spaces in between.\n\
7737 To disable all breakpoints, give no argument.\n\
7738 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
7739 &disablelist, "disable ", 1, &cmdlist);
7740 add_com_alias ("dis", "disable", class_breakpoint, 1);
7741 add_com_alias ("disa", "disable", class_breakpoint, 1);
7743 add_com ("sb", class_breakpoint, disable_command, _("\
7744 Disable some breakpoints.\n\
7745 Arguments are breakpoint numbers with spaces in between.\n\
7746 To disable all breakpoints, give no argument.\n\
7747 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
7749 add_cmd ("breakpoints", class_alias, disable_command, _("\
7750 Disable some breakpoints.\n\
7751 Arguments are breakpoint numbers with spaces in between.\n\
7752 To disable all breakpoints, give no argument.\n\
7753 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7754 This command may be abbreviated \"disable\"."),
7757 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
7758 Delete some breakpoints or auto-display expressions.\n\
7759 Arguments are breakpoint numbers with spaces in between.\n\
7760 To delete all breakpoints, give no argument.\n\
7762 Also a prefix command for deletion of other GDB objects.\n\
7763 The \"unset\" command is also an alias for \"delete\"."),
7764 &deletelist, "delete ", 1, &cmdlist);
7765 add_com_alias ("d", "delete", class_breakpoint, 1);
7767 add_com ("db", class_breakpoint, delete_command, _("\
7768 Delete some breakpoints.\n\
7769 Arguments are breakpoint numbers with spaces in between.\n\
7770 To delete all breakpoints, give no argument.\n"));
7772 add_cmd ("breakpoints", class_alias, delete_command, _("\
7773 Delete some breakpoints or auto-display expressions.\n\
7774 Arguments are breakpoint numbers with spaces in between.\n\
7775 To delete all breakpoints, give no argument.\n\
7776 This command may be abbreviated \"delete\"."),
7779 add_com ("clear", class_breakpoint, clear_command, _("\
7780 Clear breakpoint at specified line or function.\n\
7781 Argument may be line number, function name, or \"*\" and an address.\n\
7782 If line number is specified, all breakpoints in that line are cleared.\n\
7783 If function is specified, breakpoints at beginning of function are cleared.\n\
7784 If an address is specified, breakpoints at that address are cleared.\n\
7786 With no argument, clears all breakpoints in the line that the selected frame\n\
7789 See also the \"delete\" command which clears breakpoints by number."));
7791 c = add_com ("break", class_breakpoint, break_command, _("\
7792 Set breakpoint at specified line or function.\n\
7793 Argument may be line number, function name, or \"*\" and an address.\n\
7794 If line number is specified, break at start of code for that line.\n\
7795 If function is specified, break at start of code for that function.\n\
7796 If an address is specified, break at that exact address.\n\
7797 With no arg, uses current execution address of selected stack frame.\n\
7798 This is useful for breaking on return to a stack frame.\n\
7800 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7802 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
7803 set_cmd_completer (c, location_completer);
7805 add_com_alias ("b", "break", class_run, 1);
7806 add_com_alias ("br", "break", class_run, 1);
7807 add_com_alias ("bre", "break", class_run, 1);
7808 add_com_alias ("brea", "break", class_run, 1);
7812 add_com_alias ("ba", "break", class_breakpoint, 1);
7813 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7818 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
7819 Break in function/address or break at a line in the current file."),
7820 &stoplist, "stop ", 1, &cmdlist);
7821 add_cmd ("in", class_breakpoint, stopin_command,
7822 _("Break in function or address."), &stoplist);
7823 add_cmd ("at", class_breakpoint, stopat_command,
7824 _("Break at a line in the current file."), &stoplist);
7825 add_com ("status", class_info, breakpoints_info, _("\
7826 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7827 The \"Type\" column indicates one of:\n\
7828 \tbreakpoint - normal breakpoint\n\
7829 \twatchpoint - watchpoint\n\
7830 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7831 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7832 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7833 address and file/line number respectively.\n\
7835 Convenience variable \"$_\" and default examine address for \"x\"\n\
7836 are set to the address of the last breakpoint listed.\n\n\
7837 Convenience variable \"$bpnum\" contains the number of the last\n\
7841 add_info ("breakpoints", breakpoints_info, _("\
7842 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7843 The \"Type\" column indicates one of:\n\
7844 \tbreakpoint - normal breakpoint\n\
7845 \twatchpoint - watchpoint\n\
7846 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7847 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7848 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7849 address and file/line number respectively.\n\
7851 Convenience variable \"$_\" and default examine address for \"x\"\n\
7852 are set to the address of the last breakpoint listed.\n\n\
7853 Convenience variable \"$bpnum\" contains the number of the last\n\
7857 add_com ("lb", class_breakpoint, breakpoints_info, _("\
7858 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7859 The \"Type\" column indicates one of:\n\
7860 \tbreakpoint - normal breakpoint\n\
7861 \twatchpoint - watchpoint\n\
7862 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7863 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7864 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7865 address and file/line number respectively.\n\
7867 Convenience variable \"$_\" and default examine address for \"x\"\n\
7868 are set to the address of the last breakpoint listed.\n\n\
7869 Convenience variable \"$bpnum\" contains the number of the last\n\
7872 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
7873 Status of all breakpoints, or breakpoint number NUMBER.\n\
7874 The \"Type\" column indicates one of:\n\
7875 \tbreakpoint - normal breakpoint\n\
7876 \twatchpoint - watchpoint\n\
7877 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7878 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7879 \tuntil - internal breakpoint used by the \"until\" command\n\
7880 \tfinish - internal breakpoint used by the \"finish\" command\n\
7881 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7882 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7883 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7884 address and file/line number respectively.\n\
7886 Convenience variable \"$_\" and default examine address for \"x\"\n\
7887 are set to the address of the last breakpoint listed.\n\
7889 Convenience variable \"$bpnum\" contains the number of the last\n\
7891 &maintenanceinfolist);
7893 add_com ("catch", class_breakpoint, catch_command, _("\
7894 Set catchpoints to catch events.\n\
7895 Raised signals may be caught:\n\
7896 \tcatch signal - all signals\n\
7897 \tcatch signal <signame> - a particular signal\n\
7898 Raised exceptions may be caught:\n\
7899 \tcatch throw - all exceptions, when thrown\n\
7900 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7901 \tcatch catch - all exceptions, when caught\n\
7902 \tcatch catch <exceptname> - a particular exception, when caught\n\
7903 Thread or process events may be caught:\n\
7904 \tcatch thread_start - any threads, just after creation\n\
7905 \tcatch thread_exit - any threads, just before expiration\n\
7906 \tcatch thread_join - any threads, just after joins\n\
7907 Process events may be caught:\n\
7908 \tcatch start - any processes, just after creation\n\
7909 \tcatch exit - any processes, just before expiration\n\
7910 \tcatch fork - calls to fork()\n\
7911 \tcatch vfork - calls to vfork()\n\
7912 \tcatch exec - calls to exec()\n\
7913 Dynamically-linked library events may be caught:\n\
7914 \tcatch load - loads of any library\n\
7915 \tcatch load <libname> - loads of a particular library\n\
7916 \tcatch unload - unloads of any library\n\
7917 \tcatch unload <libname> - unloads of a particular library\n\
7918 The act of your program's execution stopping may also be caught:\n\
7920 C++ exceptions may be caught:\n\
7921 \tcatch throw - all exceptions, when thrown\n\
7922 \tcatch catch - all exceptions, when caught\n\
7924 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7925 after a fork or vfork is caught.\n\n\
7926 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
7928 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
7929 Set temporary catchpoints to catch events.\n\
7930 Args like \"catch\" command.\n\
7931 Like \"catch\" except the catchpoint is only temporary,\n\
7932 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7933 by using \"enable delete\" on the catchpoint number."));
7935 c = add_com ("watch", class_breakpoint, watch_command, _("\
7936 Set a watchpoint for an expression.\n\
7937 A watchpoint stops execution of your program whenever the value of\n\
7938 an expression changes."));
7939 set_cmd_completer (c, location_completer);
7941 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
7942 Set a read watchpoint for an expression.\n\
7943 A watchpoint stops execution of your program whenever the value of\n\
7944 an expression is read."));
7945 set_cmd_completer (c, location_completer);
7947 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
7948 Set a watchpoint for an expression.\n\
7949 A watchpoint stops execution of your program whenever the value of\n\
7950 an expression is either read or written."));
7951 set_cmd_completer (c, location_completer);
7953 add_info ("watchpoints", breakpoints_info,
7954 _("Synonym for ``info breakpoints''."));
7957 /* XXX: cagney/2005-02-23: This should be a boolean, and should
7958 respond to changes - contrary to the description. */
7959 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
7960 &can_use_hw_watchpoints, _("\
7961 Set debugger's willingness to use watchpoint hardware."), _("\
7962 Show debugger's willingness to use watchpoint hardware."), _("\
7963 If zero, gdb will not use hardware for new watchpoints, even if\n\
7964 such is available. (However, any hardware watchpoints that were\n\
7965 created before setting this to nonzero, will continue to use watchpoint\n\
7968 show_can_use_hw_watchpoints,
7969 &setlist, &showlist);
7971 can_use_hw_watchpoints = 1;
7973 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
7974 Breakpoint specific settings\n\
7975 Configure various breakpoint-specific variables such as\n\
7976 pending breakpoint behavior"),
7977 &breakpoint_set_cmdlist, "set breakpoint ",
7978 0/*allow-unknown*/, &setlist);
7979 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
7980 Breakpoint specific settings\n\
7981 Configure various breakpoint-specific variables such as\n\
7982 pending breakpoint behavior"),
7983 &breakpoint_show_cmdlist, "show breakpoint ",
7984 0/*allow-unknown*/, &showlist);
7986 add_setshow_auto_boolean_cmd ("pending", no_class,
7987 &pending_break_support, _("\
7988 Set debugger's behavior regarding pending breakpoints."), _("\
7989 Show debugger's behavior regarding pending breakpoints."), _("\
7990 If on, an unrecognized breakpoint location will cause gdb to create a\n\
7991 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
7992 an error. If auto, an unrecognized breakpoint location results in a\n\
7993 user-query to see if a pending breakpoint should be created."),
7995 show_pending_break_support,
7996 &breakpoint_set_cmdlist,
7997 &breakpoint_show_cmdlist);
7999 pending_break_support = AUTO_BOOLEAN_AUTO;