1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, 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"
59 #include "gdb-events.h"
60 #include "mi/mi-common.h"
62 /* Prototypes for local functions. */
64 static void until_break_command_continuation (struct continuation_arg *arg);
66 static void catch_command_1 (char *, int, int);
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint *);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint *);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value *);
94 static int break_command_1 (char *, int, int, struct breakpoint *);
96 static void mention (struct breakpoint *);
98 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
100 static void check_duplicates (struct breakpoint *);
102 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
104 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
107 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location *, insertion_state_t);
136 static enum print_stop_action print_it_typical (bpstat);
138 static enum print_stop_action print_bp_stop_message (bpstat bs);
142 enum exception_event_kind kind;
145 args_for_catchpoint_enable;
147 static int watchpoint_check (void *);
149 static int cover_target_enable_exception_callback (void *);
151 static void maintenance_info_breakpoints (char *, int);
153 static void create_longjmp_breakpoint (char *);
155 static void create_overlay_event_breakpoint (char *);
157 static int hw_breakpoint_used_count (void);
159 static int hw_watchpoint_used_count (enum bptype, int *);
161 static void hbreak_command (char *, int);
163 static void thbreak_command (char *, int);
165 static void watch_command_1 (char *, int, int);
167 static void rwatch_command (char *, int);
169 static void awatch_command (char *, int);
171 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
173 static void solib_load_unload_1 (char *hookname,
176 char *cond_string, enum bptype bp_kind);
178 static void create_fork_vfork_event_catchpoint (int tempflag,
180 enum bptype bp_kind);
182 static void stop_command (char *arg, int from_tty);
184 static void stopin_command (char *arg, int from_tty);
186 static void stopat_command (char *arg, int from_tty);
188 static char *ep_find_event_name_end (char *arg);
190 static char *ep_parse_optional_if_clause (char **arg);
192 static char *ep_parse_optional_filename (char **arg);
194 static void create_exception_catchpoint (int tempflag, char *cond_string,
195 enum exception_event_kind ex_event,
196 struct symtab_and_line *sal);
198 static void catch_exception_command_1 (enum exception_event_kind ex_event,
199 char *arg, int tempflag, int from_tty);
201 static void tcatch_command (char *arg, int from_tty);
203 static void ep_skip_leading_whitespace (char **s);
205 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints;
214 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
215 struct cmd_list_element *c,
218 fprintf_filtered (file, _("\
219 Debugger's willingness to use watchpoint hardware is %s.\n"),
223 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
224 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
225 for unrecognized breakpoint locations.
226 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
227 static enum auto_boolean pending_break_support;
229 show_pending_break_support (struct ui_file *file, int from_tty,
230 struct cmd_list_element *c,
233 fprintf_filtered (file, _("\
234 Debugger's behavior regarding pending breakpoints is %s.\n"),
238 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
239 set with "break" but falling in read-only memory.
240 If 0, gdb will warn about such breakpoints, but won't automatically
241 use hardware breakpoints. */
242 static int automatic_hardware_breakpoints;
244 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
245 struct cmd_list_element *c,
248 fprintf_filtered (file, _("\
249 Automatic usage of hardware breakpoints is %s.\n"),
254 void _initialize_breakpoint (void);
256 extern int addressprint; /* Print machine addresses? */
258 /* Are we executing breakpoint commands? */
259 static int executing_breakpoint_commands;
261 /* Are overlay event breakpoints enabled? */
262 static int overlay_events_enabled;
264 /* Walk the following statement or block through all breakpoints.
265 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
268 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
270 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
271 for (B = breakpoint_chain; \
272 B ? (TMP=B->next, 1): 0; \
275 /* Similar iterators for the low-level breakpoints. */
277 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
279 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
280 for (B = bp_location_chain; \
281 B ? (TMP=B->next, 1): 0; \
284 /* True if breakpoint hit counts should be displayed in breakpoint info. */
286 int show_breakpoint_hit_counts = 1;
288 /* Chains of all breakpoints defined. */
290 struct breakpoint *breakpoint_chain;
292 struct bp_location *bp_location_chain;
294 /* Number of last breakpoint made. */
296 int breakpoint_count;
298 /* Pointer to current exception event record */
299 static struct exception_event_record *current_exception_event;
301 /* This function returns a pointer to the string representation of the
302 pathname of the dynamically-linked library that has just been
305 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
306 or undefined results are guaranteed.
308 This string's contents are only valid immediately after the
309 inferior has stopped in the dynamic linker hook, and becomes
310 invalid as soon as the inferior is continued. Clients should make
311 a copy of this string if they wish to continue the inferior and
312 then access the string. */
314 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
315 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
318 /* This function returns a pointer to the string representation of the
319 pathname of the dynamically-linked library that has just been
322 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
323 TRUE, or undefined results are guaranteed.
325 This string's contents are only valid immediately after the
326 inferior has stopped in the dynamic linker hook, and becomes
327 invalid as soon as the inferior is continued. Clients should make
328 a copy of this string if they wish to continue the inferior and
329 then access the string. */
331 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
332 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
335 /* This function is called by the "catch load" command. It allows the
336 debugger to be notified by the dynamic linker when a specified
337 library file (or any library file, if filename is NULL) is loaded. */
339 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
340 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
341 error (_("catch of library loads not yet implemented on this platform"))
344 /* This function is called by the "catch unload" command. It allows
345 the debugger to be notified by the dynamic linker when a specified
346 library file (or any library file, if filename is NULL) is
349 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
350 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
351 error (_("catch of library unloads not yet implemented on this platform"))
354 /* Return whether a breakpoint is an active enabled breakpoint. */
356 breakpoint_enabled (struct breakpoint *b)
358 return (b->enable_state == bp_enabled && !b->pending);
361 /* Set breakpoint count to NUM. */
364 set_breakpoint_count (int num)
366 breakpoint_count = num;
367 set_internalvar (lookup_internalvar ("bpnum"),
368 value_from_longest (builtin_type_int, (LONGEST) num));
371 /* Used in run_command to zero the hit count when a new run starts. */
374 clear_breakpoint_hit_counts (void)
376 struct breakpoint *b;
382 /* Default address, symtab and line to put a breakpoint at
383 for "break" command with no arg.
384 if default_breakpoint_valid is zero, the other three are
385 not valid, and "break" with no arg is an error.
387 This set by print_stack_frame, which calls set_default_breakpoint. */
389 int default_breakpoint_valid;
390 CORE_ADDR default_breakpoint_address;
391 struct symtab *default_breakpoint_symtab;
392 int default_breakpoint_line;
394 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
395 Advance *PP after the string and any trailing whitespace.
397 Currently the string can either be a number or "$" followed by the name
398 of a convenience variable. Making it an expression wouldn't work well
399 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
401 If the string is a NULL pointer, that denotes the last breakpoint.
403 TRAILER is a character which can be found after the number; most
404 commonly this is `-'. If you don't want a trailer, use \0. */
406 get_number_trailer (char **pp, int trailer)
408 int retval = 0; /* default */
412 /* Empty line means refer to the last breakpoint. */
413 return breakpoint_count;
416 /* Make a copy of the name, so we can null-terminate it
417 to pass to lookup_internalvar(). */
422 while (isalnum (*p) || *p == '_')
424 varname = (char *) alloca (p - start + 1);
425 strncpy (varname, start, p - start);
426 varname[p - start] = '\0';
427 val = value_of_internalvar (lookup_internalvar (varname));
428 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
429 retval = (int) value_as_long (val);
432 printf_filtered (_("Convenience variable must have integer value.\n"));
440 while (*p >= '0' && *p <= '9')
443 /* There is no number here. (e.g. "cond a == b"). */
445 /* Skip non-numeric token */
446 while (*p && !isspace((int) *p))
448 /* Return zero, which caller must interpret as error. */
454 if (!(isspace (*p) || *p == '\0' || *p == trailer))
456 /* Trailing junk: return 0 and let caller print error msg. */
457 while (!(isspace (*p) || *p == '\0' || *p == trailer))
468 /* Like get_number_trailer, but don't allow a trailer. */
470 get_number (char **pp)
472 return get_number_trailer (pp, '\0');
475 /* Parse a number or a range.
476 * A number will be of the form handled by get_number.
477 * A range will be of the form <number1> - <number2>, and
478 * will represent all the integers between number1 and number2,
481 * While processing a range, this fuction is called iteratively;
482 * At each call it will return the next value in the range.
484 * At the beginning of parsing a range, the char pointer PP will
485 * be advanced past <number1> and left pointing at the '-' token.
486 * Subsequent calls will not advance the pointer until the range
487 * is completed. The call that completes the range will advance
488 * pointer PP past <number2>.
492 get_number_or_range (char **pp)
494 static int last_retval, end_value;
495 static char *end_ptr;
496 static int in_range = 0;
500 /* Default case: pp is pointing either to a solo number,
501 or to the first number of a range. */
502 last_retval = get_number_trailer (pp, '-');
507 /* This is the start of a range (<number1> - <number2>).
508 Skip the '-', parse and remember the second number,
509 and also remember the end of the final token. */
513 while (isspace ((int) *end_ptr))
514 end_ptr++; /* skip white space */
515 end_value = get_number (temp);
516 if (end_value < last_retval)
518 error (_("inverted range"));
520 else if (end_value == last_retval)
522 /* degenerate range (number1 == number2). Advance the
523 token pointer so that the range will be treated as a
532 error (_("negative value"));
535 /* pp points to the '-' that betokens a range. All
536 number-parsing has already been done. Return the next
537 integer value (one greater than the saved previous value).
538 Do not advance the token pointer 'pp' until the end of range
541 if (++last_retval == end_value)
543 /* End of range reached; advance token pointer. */
553 /* condition N EXP -- set break condition of breakpoint N to EXP. */
556 condition_command (char *arg, int from_tty)
558 struct breakpoint *b;
563 error_no_arg (_("breakpoint number"));
566 bnum = get_number (&p);
568 error (_("Bad breakpoint argument: '%s'"), arg);
571 if (b->number == bnum)
578 if (b->cond_string != NULL)
579 xfree (b->cond_string);
584 b->cond_string = NULL;
586 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
591 /* I don't know if it matters whether this is the string the user
592 typed in or the decompiled expression. */
593 b->cond_string = savestring (arg, strlen (arg));
596 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
598 error (_("Junk at end of expression"));
601 breakpoints_changed ();
602 breakpoint_modify_event (b->number);
606 error (_("No breakpoint number %d."), bnum);
610 commands_command (char *arg, int from_tty)
612 struct breakpoint *b;
615 struct command_line *l;
617 /* If we allowed this, we would have problems with when to
618 free the storage, if we change the commands currently
621 if (executing_breakpoint_commands)
622 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
625 bnum = get_number (&p);
628 error (_("Unexpected extra arguments following breakpoint number."));
631 if (b->number == bnum)
633 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
635 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
636 l = read_command_lines (tmpbuf, from_tty);
637 do_cleanups (cleanups);
638 free_command_lines (&b->commands);
640 breakpoints_changed ();
641 breakpoint_modify_event (b->number);
644 error (_("No breakpoint number %d."), bnum);
647 /* Like commands_command, but instead of reading the commands from
648 input stream, takes them from an already parsed command structure.
650 This is used by cli-script.c to DTRT with breakpoint commands
651 that are part of if and while bodies. */
652 enum command_control_type
653 commands_from_control_command (char *arg, struct command_line *cmd)
655 struct breakpoint *b;
659 /* If we allowed this, we would have problems with when to
660 free the storage, if we change the commands currently
663 if (executing_breakpoint_commands)
664 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
666 /* An empty string for the breakpoint number means the last
667 breakpoint, but get_number expects a NULL pointer. */
672 bnum = get_number (&p);
675 error (_("Unexpected extra arguments following breakpoint number."));
678 if (b->number == bnum)
680 free_command_lines (&b->commands);
681 if (cmd->body_count != 1)
682 error (_("Invalid \"commands\" block structure."));
683 /* We need to copy the commands because if/while will free the
684 list after it finishes execution. */
685 b->commands = copy_command_lines (cmd->body_list[0]);
686 breakpoints_changed ();
687 breakpoint_modify_event (b->number);
688 return simple_control;
690 error (_("No breakpoint number %d."), bnum);
693 /* Like target_read_memory() but if breakpoints are inserted, return
694 the shadow contents instead of the breakpoints themselves.
696 Read "memory data" from whatever target or inferior we have.
697 Returns zero if successful, errno value if not. EIO is used
698 for address out of bounds. If breakpoints are inserted, returns
699 shadow contents, not the breakpoints themselves. From breakpoint.c. */
702 read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
705 struct bp_location *b;
706 CORE_ADDR bp_addr = 0;
709 if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
710 /* No breakpoints on this machine. */
711 return target_read_memory (memaddr, myaddr, len);
715 if (b->owner->type == bp_none)
716 warning (_("reading through apparently deleted breakpoint #%d?"),
719 if (b->loc_type != bp_loc_software_breakpoint)
723 /* Addresses and length of the part of the breakpoint that
725 bp_addr = b->target_info.placed_address;
726 bp_size = b->target_info.shadow_len;
728 /* bp isn't valid, or doesn't shadow memory. */
730 if (bp_addr + bp_size <= memaddr)
731 /* The breakpoint is entirely before the chunk of memory we
734 if (bp_addr >= memaddr + len)
735 /* The breakpoint is entirely after the chunk of memory we are
738 /* Copy the breakpoint from the shadow contents, and recurse for
739 the things before and after. */
741 /* Offset within shadow_contents. */
744 if (bp_addr < memaddr)
746 /* Only copy the second part of the breakpoint. */
747 bp_size -= memaddr - bp_addr;
748 bptoffset = memaddr - bp_addr;
752 if (bp_addr + bp_size > memaddr + len)
754 /* Only copy the first part of the breakpoint. */
755 bp_size -= (bp_addr + bp_size) - (memaddr + len);
758 memcpy (myaddr + bp_addr - memaddr,
759 b->target_info.shadow_contents + bptoffset, bp_size);
761 if (bp_addr > memaddr)
763 /* Copy the section of memory before the breakpoint. */
764 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
769 if (bp_addr + bp_size < memaddr + len)
771 /* Copy the section of memory after the breakpoint. */
772 status = read_memory_nobpt (bp_addr + bp_size,
773 myaddr + bp_addr + bp_size - memaddr,
774 memaddr + len - (bp_addr + bp_size));
781 /* Nothing overlaps. Just call read_memory_noerr. */
782 return target_read_memory (memaddr, myaddr, len);
786 /* A wrapper function for inserting catchpoints. */
788 insert_catchpoint (struct ui_out *uo, void *args)
790 struct breakpoint *b = (struct breakpoint *) args;
796 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
799 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
802 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
805 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
810 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
813 free_valchain (struct bp_location *b)
818 /* Free the saved value chain. We will construct a new one
819 the next time the watchpoint is inserted. */
820 for (v = b->owner->val_chain; v; v = n)
825 b->owner->val_chain = NULL;
828 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
829 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
830 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
832 NOTE drow/2003-09-09: This routine could be broken down to an object-style
833 method for each breakpoint or catchpoint type. */
835 insert_bp_location (struct bp_location *bpt,
836 struct ui_file *tmp_error_stream,
837 int *disabled_breaks, int *process_warning,
838 int *hw_breakpoint_error)
842 /* Permanent breakpoints cannot be inserted or removed. Disabled
843 breakpoints should not be inserted. */
844 if (!breakpoint_enabled (bpt->owner))
847 if (bpt->inserted || bpt->duplicate)
850 /* Initialize the target-specific information. */
851 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
852 bpt->target_info.placed_address = bpt->address;
854 if (bpt->loc_type == bp_loc_software_breakpoint
855 || bpt->loc_type == bp_loc_hardware_breakpoint)
857 if (bpt->owner->type != bp_hardware_breakpoint)
859 /* If the explicitly specified breakpoint type
860 is not hardware breakpoint, check the memory map to see
861 if the breakpoint address is in read only memory or not.
862 Two important cases are:
863 - location type is not hardware breakpoint, memory
864 is readonly. We change the type of the location to
866 - location type is hardware breakpoint, memory is read-write.
867 This means we've previously made the location hardware one, but
868 then the memory map changed, so we undo.
870 When breakpoints are removed, remove_breakpoints will
871 use location types we've just set here, the only possible
872 problem is that memory map has changed during running program,
873 but it's not going to work anyway with current gdb. */
874 struct mem_region *mr
875 = lookup_mem_region (bpt->target_info.placed_address);
879 if (automatic_hardware_breakpoints)
882 enum bp_loc_type new_type;
884 if (mr->attrib.mode != MEM_RW)
885 new_type = bp_loc_hardware_breakpoint;
887 new_type = bp_loc_software_breakpoint;
889 if (new_type != bpt->loc_type)
892 bpt->loc_type = new_type;
895 fprintf_filtered (gdb_stdout, _("\
896 Note: automatically using hardware breakpoints for read-only addresses.\n"));
901 else if (bpt->loc_type == bp_loc_software_breakpoint
902 && mr->attrib.mode != MEM_RW)
903 warning (_("cannot set software breakpoint at readonly address %s"),
904 paddr (bpt->address));
908 /* First check to see if we have to handle an overlay. */
909 if (overlay_debugging == ovly_off
910 || bpt->section == NULL
911 || !(section_is_overlay (bpt->section)))
913 /* No overlay handling: just set the breakpoint. */
915 if (bpt->loc_type == bp_loc_hardware_breakpoint)
916 val = target_insert_hw_breakpoint (&bpt->target_info);
918 val = target_insert_breakpoint (&bpt->target_info);
922 /* This breakpoint is in an overlay section.
923 Shall we set a breakpoint at the LMA? */
924 if (!overlay_events_enabled)
926 /* Yes -- overlay event support is not active,
927 so we must try to set a breakpoint at the LMA.
928 This will not work for a hardware breakpoint. */
929 if (bpt->loc_type == bp_loc_hardware_breakpoint)
930 warning (_("hardware breakpoint %d not supported in overlay!"),
934 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
936 /* Set a software (trap) breakpoint at the LMA. */
937 bpt->overlay_target_info = bpt->target_info;
938 bpt->overlay_target_info.placed_address = addr;
939 val = target_insert_breakpoint (&bpt->overlay_target_info);
941 fprintf_unfiltered (tmp_error_stream,
942 "Overlay breakpoint %d failed: in ROM?",
946 /* Shall we set a breakpoint at the VMA? */
947 if (section_is_mapped (bpt->section))
949 /* Yes. This overlay section is mapped into memory. */
950 if (bpt->loc_type == bp_loc_hardware_breakpoint)
951 val = target_insert_hw_breakpoint (&bpt->target_info);
953 val = target_insert_breakpoint (&bpt->target_info);
957 /* No. This breakpoint will not be inserted.
958 No error, but do not mark the bp as 'inserted'. */
965 /* Can't set the breakpoint. */
966 if (solib_address (bpt->address))
968 /* See also: disable_breakpoints_in_shlibs. */
970 bpt->owner->enable_state = bp_shlib_disabled;
971 if (!*disabled_breaks)
973 fprintf_unfiltered (tmp_error_stream,
974 "Cannot insert breakpoint %d.\n",
976 fprintf_unfiltered (tmp_error_stream,
977 "Temporarily disabling shared library breakpoints:\n");
979 *disabled_breaks = 1;
980 fprintf_unfiltered (tmp_error_stream,
981 "breakpoint #%d\n", bpt->owner->number);
985 #ifdef ONE_PROCESS_WRITETEXT
986 *process_warning = 1;
988 if (bpt->loc_type == bp_loc_hardware_breakpoint)
990 *hw_breakpoint_error = 1;
991 fprintf_unfiltered (tmp_error_stream,
992 "Cannot insert hardware breakpoint %d.\n",
997 fprintf_unfiltered (tmp_error_stream,
998 "Cannot insert breakpoint %d.\n",
1000 fprintf_filtered (tmp_error_stream,
1001 "Error accessing memory address ");
1002 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1003 fprintf_filtered (tmp_error_stream, ": %s.\n",
1004 safe_strerror (val));
1015 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1016 /* NOTE drow/2003-09-08: This state only exists for removing
1017 watchpoints. It's not clear that it's necessary... */
1018 && bpt->owner->disposition != disp_del_at_next_stop)
1020 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1021 based on the expression. Ideally this should happen at a higher level,
1022 and there should be one bp_location for each computed address we
1023 must watch. As soon as a many-to-one mapping is available I'll
1026 int within_current_scope;
1027 struct value *mark = value_mark ();
1029 struct frame_id saved_frame_id;
1031 /* Save the current frame's ID so we can restore it after
1032 evaluating the watchpoint expression on its own frame. */
1033 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1034 took a frame parameter, so that we didn't have to change the
1036 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1038 /* Determine if the watchpoint is within scope. */
1039 if (bpt->owner->exp_valid_block == NULL)
1040 within_current_scope = 1;
1043 struct frame_info *fi;
1044 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
1045 within_current_scope = (fi != NULL);
1046 if (within_current_scope)
1050 if (within_current_scope)
1052 free_valchain (bpt);
1054 /* Evaluate the expression and cut the chain of values
1055 produced off from the value chain.
1057 Make sure the value returned isn't lazy; we use
1058 laziness to determine what memory GDB actually needed
1059 in order to compute the value of the expression. */
1060 v = evaluate_expression (bpt->owner->exp);
1062 value_release_to_mark (mark);
1064 bpt->owner->val_chain = v;
1067 /* Look at each value on the value chain. */
1068 for (; v; v = value_next (v))
1070 /* If it's a memory location, and GDB actually needed
1071 its contents to evaluate the expression, then we
1073 if (VALUE_LVAL (v) == lval_memory
1074 && ! value_lazy (v))
1076 struct type *vtype = check_typedef (value_type (v));
1078 /* We only watch structs and arrays if user asked
1079 for it explicitly, never if they just happen to
1080 appear in the middle of some value chain. */
1081 if (v == bpt->owner->val_chain
1082 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1083 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1088 addr = VALUE_ADDRESS (v) + value_offset (v);
1089 len = TYPE_LENGTH (value_type (v));
1091 if (bpt->owner->type == bp_read_watchpoint)
1093 else if (bpt->owner->type == bp_access_watchpoint)
1096 val = target_insert_watchpoint (addr, len, type);
1099 /* Don't exit the loop, try to insert
1100 every value on the value chain. That's
1101 because we will be removing all the
1102 watches below, and removing a
1103 watchpoint we didn't insert could have
1111 /* Failure to insert a watchpoint on any memory value in the
1112 value chain brings us here. */
1115 remove_breakpoint (bpt, mark_uninserted);
1116 *hw_breakpoint_error = 1;
1117 fprintf_unfiltered (tmp_error_stream,
1118 "Could not insert hardware watchpoint %d.\n",
1119 bpt->owner->number);
1125 printf_filtered (_("\
1126 Hardware watchpoint %d deleted because the program has left the block \n\
1127 in which its expression is valid.\n"),
1128 bpt->owner->number);
1129 if (bpt->owner->related_breakpoint)
1130 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1131 bpt->owner->disposition = disp_del_at_next_stop;
1134 /* Restore the selected frame. */
1135 select_frame (frame_find_by_id (saved_frame_id));
1140 else if (ep_is_exception_catchpoint (bpt->owner))
1142 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1143 breakpoint. Once again, it would be better if this was represented
1144 as two bp_locations. */
1146 /* If we get here, we must have a callback mechanism for exception
1147 events -- with g++ style embedded label support, we insert
1148 ordinary breakpoints and not catchpoints. */
1149 val = target_insert_breakpoint (&bpt->target_info);
1152 /* Couldn't set breakpoint for some reason */
1153 fprintf_unfiltered (tmp_error_stream,
1154 "Cannot insert catchpoint %d; disabling it.\n",
1155 bpt->owner->number);
1156 fprintf_filtered (tmp_error_stream,
1157 "Error accessing memory address ");
1158 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1159 fprintf_filtered (tmp_error_stream, ": %s.\n",
1160 safe_strerror (val));
1161 bpt->owner->enable_state = bp_disabled;
1165 /* Bp set, now make sure callbacks are enabled */
1166 /* Format possible error msg */
1167 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1168 bpt->owner->number);
1169 struct cleanup *cleanups = make_cleanup (xfree, message);
1171 args_for_catchpoint_enable args;
1172 args.kind = bpt->owner->type == bp_catch_catch ?
1173 EX_EVENT_CATCH : EX_EVENT_THROW;
1175 val = catch_errors (cover_target_enable_exception_callback,
1176 &args, message, RETURN_MASK_ALL);
1177 do_cleanups (cleanups);
1178 if (val != 0 && val != -1)
1181 /* Check if something went wrong; val == 0 can be ignored */
1184 /* something went wrong */
1185 fprintf_unfiltered (tmp_error_stream,
1186 "Cannot insert catchpoint %d; disabling it.\n",
1187 bpt->owner->number);
1188 bpt->owner->enable_state = bp_disabled;
1195 else if (bpt->owner->type == bp_catch_fork
1196 || bpt->owner->type == bp_catch_vfork
1197 || bpt->owner->type == bp_catch_exec)
1199 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1200 bpt->owner, RETURN_MASK_ERROR);
1201 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1202 bpt->owner->number);
1204 bpt->owner->enable_state = bp_disabled;
1208 /* We've already printed an error message if there was a problem
1209 inserting this catchpoint, and we've disabled the catchpoint,
1210 so just return success. */
1217 /* insert_breakpoints is used when starting or continuing the program.
1218 remove_breakpoints is used when the program stops.
1219 Both return zero if successful,
1220 or an `errno' value if could not write the inferior. */
1223 insert_breakpoints (void)
1225 struct bp_location *b, *temp;
1226 int return_val = 0; /* return success code. */
1228 int disabled_breaks = 0;
1229 int hw_breakpoint_error = 0;
1230 int process_warning = 0;
1232 struct ui_file *tmp_error_stream = mem_fileopen ();
1233 make_cleanup_ui_file_delete (tmp_error_stream);
1235 /* Explicitly mark the warning -- this will only be printed if
1236 there was an error. */
1237 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1239 ALL_BP_LOCATIONS_SAFE (b, temp)
1241 /* Permanent breakpoints cannot be inserted or removed. Disabled
1242 breakpoints should not be inserted. */
1243 if (!breakpoint_enabled (b->owner))
1246 /* There is no point inserting thread-specific breakpoints if the
1247 thread no longer exists. */
1248 if (b->owner->thread != -1
1249 && !valid_thread_id (b->owner->thread))
1252 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1253 hardware watchpoints are split into multiple loc breakpoints. */
1254 if ((b->loc_type == bp_loc_hardware_watchpoint
1255 || b->owner->type == bp_watchpoint) && !b->owner->val)
1258 val = evaluate_expression (b->owner->exp);
1259 release_value (val);
1260 if (value_lazy (val))
1261 value_fetch_lazy (val);
1262 b->owner->val = val;
1265 val = insert_bp_location (b, tmp_error_stream,
1266 &disabled_breaks, &process_warning,
1267 &hw_breakpoint_error);
1274 /* If a hardware breakpoint or watchpoint was inserted, add a
1275 message about possibly exhausted resources. */
1276 if (hw_breakpoint_error)
1278 fprintf_unfiltered (tmp_error_stream,
1279 "Could not insert hardware breakpoints:\n\
1280 You may have requested too many hardware breakpoints/watchpoints.\n");
1282 #ifdef ONE_PROCESS_WRITETEXT
1283 if (process_warning)
1284 fprintf_unfiltered (tmp_error_stream,
1285 "The same program may be running in another process.");
1287 target_terminal_ours_for_output ();
1288 error_stream (tmp_error_stream);
1294 remove_breakpoints (void)
1296 struct bp_location *b;
1299 ALL_BP_LOCATIONS (b)
1303 val = remove_breakpoint (b, mark_uninserted);
1312 remove_hw_watchpoints (void)
1314 struct bp_location *b;
1317 ALL_BP_LOCATIONS (b)
1319 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1321 val = remove_breakpoint (b, mark_uninserted);
1330 reattach_breakpoints (int pid)
1332 struct bp_location *b;
1334 struct cleanup *old_chain = save_inferior_ptid ();
1335 struct ui_file *tmp_error_stream = mem_fileopen ();
1336 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1338 make_cleanup_ui_file_delete (tmp_error_stream);
1340 inferior_ptid = pid_to_ptid (pid);
1341 ALL_BP_LOCATIONS (b)
1346 val = insert_bp_location (b, tmp_error_stream,
1347 &dummy1, &dummy2, &dummy3);
1350 do_cleanups (old_chain);
1355 do_cleanups (old_chain);
1360 update_breakpoints_after_exec (void)
1362 struct breakpoint *b;
1363 struct breakpoint *temp;
1365 /* Doing this first prevents the badness of having delete_breakpoint()
1366 write a breakpoint's current "shadow contents" to lift the bp. That
1367 shadow is NOT valid after an exec()! */
1368 mark_breakpoints_out ();
1370 ALL_BREAKPOINTS_SAFE (b, temp)
1372 /* Solib breakpoints must be explicitly reset after an exec(). */
1373 if (b->type == bp_shlib_event)
1375 delete_breakpoint (b);
1379 /* Thread event breakpoints must be set anew after an exec(),
1380 as must overlay event breakpoints. */
1381 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1383 delete_breakpoint (b);
1387 /* Step-resume breakpoints are meaningless after an exec(). */
1388 if (b->type == bp_step_resume)
1390 delete_breakpoint (b);
1394 /* Ditto the exception-handling catchpoints. */
1395 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1397 delete_breakpoint (b);
1401 /* Don't delete an exec catchpoint, because else the inferior
1402 won't stop when it ought!
1404 Similarly, we probably ought to keep vfork catchpoints, 'cause
1405 on this target, we may not be able to stop when the vfork is
1406 seen, but only when the subsequent exec is seen. (And because
1407 deleting fork catchpoints here but not vfork catchpoints will
1408 seem mysterious to users, keep those too.)
1410 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1411 target address field, if any, is sufficient to have it be reset
1412 automagically. Certainly on HP-UX that's true.
1415 valid code address on some platforms (like the mn10300
1416 simulators). We shouldn't assign any special interpretation to
1417 a breakpoint with a zero address. And in fact, GDB doesn't ---
1418 I can't see what that comment above is talking about. As far
1419 as I can tell, setting the address of a
1420 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1421 is meaningless, since those are implemented with HP-UX kernel
1422 hackery, not by storing breakpoint instructions somewhere. */
1423 if ((b->type == bp_catch_exec) ||
1424 (b->type == bp_catch_vfork) ||
1425 (b->type == bp_catch_fork))
1427 b->loc->address = (CORE_ADDR) 0;
1431 /* bp_finish is a special case. The only way we ought to be able
1432 to see one of these when an exec() has happened, is if the user
1433 caught a vfork, and then said "finish". Ordinarily a finish just
1434 carries them to the call-site of the current callee, by setting
1435 a temporary bp there and resuming. But in this case, the finish
1436 will carry them entirely through the vfork & exec.
1438 We don't want to allow a bp_finish to remain inserted now. But
1439 we can't safely delete it, 'cause finish_command has a handle to
1440 the bp on a bpstat, and will later want to delete it. There's a
1441 chance (and I've seen it happen) that if we delete the bp_finish
1442 here, that its storage will get reused by the time finish_command
1443 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1444 We really must allow finish_command to delete a bp_finish.
1446 In the absense of a general solution for the "how do we know
1447 it's safe to delete something others may have handles to?"
1448 problem, what we'll do here is just uninsert the bp_finish, and
1449 let finish_command delete it.
1451 (We know the bp_finish is "doomed" in the sense that it's
1452 momentary, and will be deleted as soon as finish_command sees
1453 the inferior stopped. So it doesn't matter that the bp's
1454 address is probably bogus in the new a.out, unlike e.g., the
1455 solib breakpoints.) */
1457 if (b->type == bp_finish)
1462 /* Without a symbolic address, we have little hope of the
1463 pre-exec() address meaning the same thing in the post-exec()
1465 if (b->addr_string == NULL)
1467 delete_breakpoint (b);
1471 /* If this breakpoint has survived the above battery of checks, then
1472 it must have a symbolic address. Be sure that it gets reevaluated
1473 to a target address, rather than reusing the old evaluation.
1476 for bp_catch_exec and friends, I'm pretty sure this is entirely
1477 unnecessary. A call to breakpoint_re_set_one always recomputes
1478 the breakpoint's address from scratch, or deletes it if it can't.
1479 So I think this assignment could be deleted without effect. */
1480 b->loc->address = (CORE_ADDR) 0;
1482 /* FIXME what about longjmp breakpoints? Re-create them here? */
1483 create_overlay_event_breakpoint ("_ovly_debug_event");
1487 detach_breakpoints (int pid)
1489 struct bp_location *b;
1491 struct cleanup *old_chain = save_inferior_ptid ();
1493 if (pid == PIDGET (inferior_ptid))
1494 error (_("Cannot detach breakpoints of inferior_ptid"));
1496 /* Set inferior_ptid; remove_breakpoint uses this global. */
1497 inferior_ptid = pid_to_ptid (pid);
1498 ALL_BP_LOCATIONS (b)
1502 val = remove_breakpoint (b, mark_inserted);
1505 do_cleanups (old_chain);
1510 do_cleanups (old_chain);
1515 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1519 if (b->owner->enable_state == bp_permanent)
1520 /* Permanent breakpoints cannot be inserted or removed. */
1523 if (b->owner->type == bp_none)
1524 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1527 if (b->loc_type == bp_loc_software_breakpoint
1528 || b->loc_type == bp_loc_hardware_breakpoint)
1530 /* "Normal" instruction breakpoint: either the standard
1531 trap-instruction bp (bp_breakpoint), or a
1532 bp_hardware_breakpoint. */
1534 /* First check to see if we have to handle an overlay. */
1535 if (overlay_debugging == ovly_off
1536 || b->section == NULL
1537 || !(section_is_overlay (b->section)))
1539 /* No overlay handling: just remove the breakpoint. */
1541 if (b->loc_type == bp_loc_hardware_breakpoint)
1542 val = target_remove_hw_breakpoint (&b->target_info);
1544 val = target_remove_breakpoint (&b->target_info);
1548 /* This breakpoint is in an overlay section.
1549 Did we set a breakpoint at the LMA? */
1550 if (!overlay_events_enabled)
1552 /* Yes -- overlay event support is not active, so we
1553 should have set a breakpoint at the LMA. Remove it.
1555 /* Ignore any failures: if the LMA is in ROM, we will
1556 have already warned when we failed to insert it. */
1557 if (b->loc_type == bp_loc_hardware_breakpoint)
1558 target_remove_hw_breakpoint (&b->overlay_target_info);
1560 target_remove_breakpoint (&b->overlay_target_info);
1562 /* Did we set a breakpoint at the VMA?
1563 If so, we will have marked the breakpoint 'inserted'. */
1566 /* Yes -- remove it. Previously we did not bother to
1567 remove the breakpoint if the section had been
1568 unmapped, but let's not rely on that being safe. We
1569 don't know what the overlay manager might do. */
1570 if (b->loc_type == bp_loc_hardware_breakpoint)
1571 val = target_remove_hw_breakpoint (&b->target_info);
1573 /* However, we should remove *software* breakpoints only
1574 if the section is still mapped, or else we overwrite
1575 wrong code with the saved shadow contents. */
1576 else if (section_is_mapped (b->section))
1577 val = target_remove_breakpoint (&b->target_info);
1583 /* No -- not inserted, so no need to remove. No error. */
1589 b->inserted = (is == mark_inserted);
1591 else if (b->loc_type == bp_loc_hardware_watchpoint
1592 && breakpoint_enabled (b->owner)
1598 b->inserted = (is == mark_inserted);
1599 /* Walk down the saved value chain. */
1600 for (v = b->owner->val_chain; v; v = value_next (v))
1602 /* For each memory reference remove the watchpoint
1604 if (VALUE_LVAL (v) == lval_memory
1605 && ! value_lazy (v))
1607 struct type *vtype = check_typedef (value_type (v));
1609 if (v == b->owner->val_chain
1610 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1611 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1616 addr = VALUE_ADDRESS (v) + value_offset (v);
1617 len = TYPE_LENGTH (value_type (v));
1619 if (b->owner->type == bp_read_watchpoint)
1621 else if (b->owner->type == bp_access_watchpoint)
1624 val = target_remove_watchpoint (addr, len, type);
1631 /* Failure to remove any of the hardware watchpoints comes here. */
1632 if ((is == mark_uninserted) && (b->inserted))
1633 warning (_("Could not remove hardware watchpoint %d."),
1636 else if ((b->owner->type == bp_catch_fork ||
1637 b->owner->type == bp_catch_vfork ||
1638 b->owner->type == bp_catch_exec)
1639 && breakpoint_enabled (b->owner)
1643 switch (b->owner->type)
1646 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1648 case bp_catch_vfork:
1649 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1652 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1655 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1660 b->inserted = (is == mark_inserted);
1662 else if ((b->owner->type == bp_catch_catch ||
1663 b->owner->type == bp_catch_throw)
1664 && breakpoint_enabled (b->owner)
1667 val = target_remove_breakpoint (&b->target_info);
1670 b->inserted = (is == mark_inserted);
1676 /* Clear the "inserted" flag in all breakpoints. */
1679 mark_breakpoints_out (void)
1681 struct bp_location *bpt;
1683 ALL_BP_LOCATIONS (bpt)
1687 /* Clear the "inserted" flag in all breakpoints and delete any
1688 breakpoints which should go away between runs of the program.
1690 Plus other such housekeeping that has to be done for breakpoints
1693 Note: this function gets called at the end of a run (by
1694 generic_mourn_inferior) and when a run begins (by
1695 init_wait_for_inferior). */
1700 breakpoint_init_inferior (enum inf_context context)
1702 struct breakpoint *b, *temp;
1703 struct bp_location *bpt;
1705 ALL_BP_LOCATIONS (bpt)
1708 ALL_BREAKPOINTS_SAFE (b, temp)
1713 case bp_watchpoint_scope:
1715 /* If the call dummy breakpoint is at the entry point it will
1716 cause problems when the inferior is rerun, so we better
1719 Also get rid of scope breakpoints. */
1720 delete_breakpoint (b);
1724 case bp_hardware_watchpoint:
1725 case bp_read_watchpoint:
1726 case bp_access_watchpoint:
1728 /* Likewise for watchpoints on local expressions. */
1729 if (b->exp_valid_block != NULL)
1730 delete_breakpoint (b);
1731 if (context == inf_starting)
1733 /* Reset val field to force reread of starting value
1734 in insert_breakpoints. */
1736 value_free (b->val);
1746 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1747 exists at PC. It returns ordinary_breakpoint_here if it's an
1748 ordinary breakpoint, or permanent_breakpoint_here if it's a
1749 permanent breakpoint.
1750 - When continuing from a location with an ordinary breakpoint, we
1751 actually single step once before calling insert_breakpoints.
1752 - When continuing from a localion with a permanent breakpoint, we
1753 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1754 the target, to advance the PC past the breakpoint. */
1756 enum breakpoint_here
1757 breakpoint_here_p (CORE_ADDR pc)
1759 struct bp_location *bpt;
1760 int any_breakpoint_here = 0;
1762 ALL_BP_LOCATIONS (bpt)
1764 if (bpt->loc_type != bp_loc_software_breakpoint
1765 && bpt->loc_type != bp_loc_hardware_breakpoint)
1768 if ((breakpoint_enabled (bpt->owner)
1769 || bpt->owner->enable_state == bp_permanent)
1770 && bpt->address == pc) /* bp is enabled and matches pc */
1772 if (overlay_debugging
1773 && section_is_overlay (bpt->section)
1774 && !section_is_mapped (bpt->section))
1775 continue; /* unmapped overlay -- can't be a match */
1776 else if (bpt->owner->enable_state == bp_permanent)
1777 return permanent_breakpoint_here;
1779 any_breakpoint_here = 1;
1783 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1787 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1788 but it only returns true if there is actually a breakpoint inserted
1792 breakpoint_inserted_here_p (CORE_ADDR pc)
1794 struct bp_location *bpt;
1796 ALL_BP_LOCATIONS (bpt)
1798 if (bpt->loc_type != bp_loc_software_breakpoint
1799 && bpt->loc_type != bp_loc_hardware_breakpoint)
1803 && bpt->address == pc) /* bp is inserted and matches pc */
1805 if (overlay_debugging
1806 && section_is_overlay (bpt->section)
1807 && !section_is_mapped (bpt->section))
1808 continue; /* unmapped overlay -- can't be a match */
1814 /* Also check for software single-step breakpoints. */
1815 if (single_step_breakpoint_inserted_here_p (pc))
1821 /* This function returns non-zero iff there is a software breakpoint
1825 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1827 struct bp_location *bpt;
1828 int any_breakpoint_here = 0;
1830 ALL_BP_LOCATIONS (bpt)
1832 if (bpt->loc_type != bp_loc_software_breakpoint)
1835 if ((breakpoint_enabled (bpt->owner)
1836 || bpt->owner->enable_state == bp_permanent)
1838 && bpt->address == pc) /* bp is enabled and matches pc */
1840 if (overlay_debugging
1841 && section_is_overlay (bpt->section)
1842 && !section_is_mapped (bpt->section))
1843 continue; /* unmapped overlay -- can't be a match */
1849 /* Also check for software single-step breakpoints. */
1850 if (single_step_breakpoint_inserted_here_p (pc))
1856 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1857 PC is valid for process/thread PTID. */
1860 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1862 struct bp_location *bpt;
1865 thread = pid_to_thread_id (ptid);
1867 ALL_BP_LOCATIONS (bpt)
1869 if (bpt->loc_type != bp_loc_software_breakpoint
1870 && bpt->loc_type != bp_loc_hardware_breakpoint)
1873 if ((breakpoint_enabled (bpt->owner)
1874 || bpt->owner->enable_state == bp_permanent)
1875 && bpt->address == pc
1876 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1878 if (overlay_debugging
1879 && section_is_overlay (bpt->section)
1880 && !section_is_mapped (bpt->section))
1881 continue; /* unmapped overlay -- can't be a match */
1891 /* bpstat stuff. External routines' interfaces are documented
1895 ep_is_catchpoint (struct breakpoint *ep)
1898 (ep->type == bp_catch_load)
1899 || (ep->type == bp_catch_unload)
1900 || (ep->type == bp_catch_fork)
1901 || (ep->type == bp_catch_vfork)
1902 || (ep->type == bp_catch_exec)
1903 || (ep->type == bp_catch_catch)
1904 || (ep->type == bp_catch_throw);
1906 /* ??rehrauer: Add more kinds here, as are implemented... */
1910 ep_is_shlib_catchpoint (struct breakpoint *ep)
1913 (ep->type == bp_catch_load)
1914 || (ep->type == bp_catch_unload);
1918 ep_is_exception_catchpoint (struct breakpoint *ep)
1921 (ep->type == bp_catch_catch)
1922 || (ep->type == bp_catch_throw);
1925 /* Clear a bpstat so that it says we are not at any breakpoint.
1926 Also free any storage that is part of a bpstat. */
1929 bpstat_clear (bpstat *bsp)
1940 if (p->old_val != NULL)
1941 value_free (p->old_val);
1942 free_command_lines (&p->commands);
1949 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1950 is part of the bpstat is copied as well. */
1953 bpstat_copy (bpstat bs)
1957 bpstat retval = NULL;
1962 for (; bs != NULL; bs = bs->next)
1964 tmp = (bpstat) xmalloc (sizeof (*tmp));
1965 memcpy (tmp, bs, sizeof (*tmp));
1966 if (bs->commands != NULL)
1967 tmp->commands = copy_command_lines (bs->commands);
1968 if (bs->old_val != NULL)
1969 tmp->old_val = value_copy (bs->old_val);
1972 /* This is the first thing in the chain. */
1982 /* Find the bpstat associated with this breakpoint */
1985 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1990 for (; bsp != NULL; bsp = bsp->next)
1992 if (bsp->breakpoint_at == breakpoint)
1998 /* Find a step_resume breakpoint associated with this bpstat.
1999 (If there are multiple step_resume bp's on the list, this function
2000 will arbitrarily pick one.)
2002 It is an error to use this function if BPSTAT doesn't contain a
2003 step_resume breakpoint.
2005 See wait_for_inferior's use of this function. */
2007 bpstat_find_step_resume_breakpoint (bpstat bsp)
2011 gdb_assert (bsp != NULL);
2013 current_thread = pid_to_thread_id (inferior_ptid);
2015 for (; bsp != NULL; bsp = bsp->next)
2017 if ((bsp->breakpoint_at != NULL) &&
2018 (bsp->breakpoint_at->type == bp_step_resume) &&
2019 (bsp->breakpoint_at->thread == current_thread ||
2020 bsp->breakpoint_at->thread == -1))
2021 return bsp->breakpoint_at;
2024 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2028 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2029 at. *BSP upon return is a bpstat which points to the remaining
2030 breakpoints stopped at (but which is not guaranteed to be good for
2031 anything but further calls to bpstat_num).
2032 Return 0 if passed a bpstat which does not indicate any breakpoints.
2033 Return -1 if stopped at a breakpoint that has been deleted since
2035 Return 1 otherwise. */
2038 bpstat_num (bpstat *bsp, int *num)
2040 struct breakpoint *b;
2043 return 0; /* No more breakpoint values */
2045 b = (*bsp)->breakpoint_at;
2046 *bsp = (*bsp)->next;
2048 return -1; /* breakpoint that's been deleted since */
2050 *num = b->number; /* We have its number */
2054 /* Modify BS so that the actions will not be performed. */
2057 bpstat_clear_actions (bpstat bs)
2059 for (; bs != NULL; bs = bs->next)
2061 free_command_lines (&bs->commands);
2062 if (bs->old_val != NULL)
2064 value_free (bs->old_val);
2070 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2072 cleanup_executing_breakpoints (void *ignore)
2074 executing_breakpoint_commands = 0;
2077 /* Execute all the commands associated with all the breakpoints at this
2078 location. Any of these commands could cause the process to proceed
2079 beyond this point, etc. We look out for such changes by checking
2080 the global "breakpoint_proceeded" after each command. */
2083 bpstat_do_actions (bpstat *bsp)
2086 struct cleanup *old_chain;
2088 /* Avoid endless recursion if a `source' command is contained
2090 if (executing_breakpoint_commands)
2093 executing_breakpoint_commands = 1;
2094 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2097 /* Note that (as of this writing), our callers all appear to
2098 be passing us the address of global stop_bpstat. And, if
2099 our calls to execute_control_command cause the inferior to
2100 proceed, that global (and hence, *bsp) will change.
2102 We must be careful to not touch *bsp unless the inferior
2103 has not proceeded. */
2105 /* This pointer will iterate over the list of bpstat's. */
2108 breakpoint_proceeded = 0;
2109 for (; bs != NULL; bs = bs->next)
2111 struct command_line *cmd;
2112 struct cleanup *this_cmd_tree_chain;
2114 /* Take ownership of the BSP's command tree, if it has one.
2116 The command tree could legitimately contain commands like
2117 'step' and 'next', which call clear_proceed_status, which
2118 frees stop_bpstat's command tree. To make sure this doesn't
2119 free the tree we're executing out from under us, we need to
2120 take ownership of the tree ourselves. Since a given bpstat's
2121 commands are only executed once, we don't need to copy it; we
2122 can clear the pointer in the bpstat, and make sure we free
2123 the tree when we're done. */
2126 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2130 execute_control_command (cmd);
2132 if (breakpoint_proceeded)
2138 /* We can free this command tree now. */
2139 do_cleanups (this_cmd_tree_chain);
2141 if (breakpoint_proceeded)
2142 /* The inferior is proceeded by the command; bomb out now.
2143 The bpstat chain has been blown away by wait_for_inferior.
2144 But since execution has stopped again, there is a new bpstat
2145 to look at, so start over. */
2148 do_cleanups (old_chain);
2151 /* This is the normal print function for a bpstat. In the future,
2152 much of this logic could (should?) be moved to bpstat_stop_status,
2153 by having it set different print_it values.
2155 Current scheme: When we stop, bpstat_print() is called. It loops
2156 through the bpstat list of things causing this stop, calling the
2157 print_bp_stop_message function on each one. The behavior of the
2158 print_bp_stop_message function depends on the print_it field of
2159 bpstat. If such field so indicates, call this function here.
2161 Return values from this routine (ultimately used by bpstat_print()
2162 and normal_stop() to decide what to do):
2163 PRINT_NOTHING: Means we already printed all we needed to print,
2164 don't print anything else.
2165 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2166 that something to be followed by a location.
2167 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2168 that something to be followed by a location.
2169 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2172 static enum print_stop_action
2173 print_it_typical (bpstat bs)
2175 struct cleanup *old_chain, *ui_out_chain;
2176 struct ui_stream *stb;
2177 stb = ui_out_stream_new (uiout);
2178 old_chain = make_cleanup_ui_out_stream_delete (stb);
2179 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2180 which has since been deleted. */
2181 if (bs->breakpoint_at == NULL)
2182 return PRINT_UNKNOWN;
2184 switch (bs->breakpoint_at->type)
2187 case bp_hardware_breakpoint:
2188 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2189 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2190 bs->breakpoint_at->loc->address,
2191 bs->breakpoint_at->number, 1);
2192 annotate_breakpoint (bs->breakpoint_at->number);
2193 ui_out_text (uiout, "\nBreakpoint ");
2194 if (ui_out_is_mi_like_p (uiout))
2195 ui_out_field_string (uiout, "reason",
2196 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2197 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2198 ui_out_text (uiout, ", ");
2199 return PRINT_SRC_AND_LOC;
2202 case bp_shlib_event:
2203 /* Did we stop because the user set the stop_on_solib_events
2204 variable? (If so, we report this as a generic, "Stopped due
2205 to shlib event" message.) */
2206 printf_filtered (_("Stopped due to shared library event\n"));
2207 return PRINT_NOTHING;
2210 case bp_thread_event:
2211 /* Not sure how we will get here.
2212 GDB should not stop for these breakpoints. */
2213 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2214 return PRINT_NOTHING;
2217 case bp_overlay_event:
2218 /* By analogy with the thread event, GDB should not stop for these. */
2219 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2220 return PRINT_NOTHING;
2224 annotate_catchpoint (bs->breakpoint_at->number);
2225 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2226 bs->breakpoint_at->number,
2227 bs->breakpoint_at->triggered_dll_pathname);
2228 return PRINT_SRC_AND_LOC;
2231 case bp_catch_unload:
2232 annotate_catchpoint (bs->breakpoint_at->number);
2233 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2234 bs->breakpoint_at->number,
2235 bs->breakpoint_at->triggered_dll_pathname);
2236 return PRINT_SRC_AND_LOC;
2240 annotate_catchpoint (bs->breakpoint_at->number);
2241 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2242 bs->breakpoint_at->number,
2243 bs->breakpoint_at->forked_inferior_pid);
2244 return PRINT_SRC_AND_LOC;
2247 case bp_catch_vfork:
2248 annotate_catchpoint (bs->breakpoint_at->number);
2249 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2250 bs->breakpoint_at->number,
2251 bs->breakpoint_at->forked_inferior_pid);
2252 return PRINT_SRC_AND_LOC;
2256 annotate_catchpoint (bs->breakpoint_at->number);
2257 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2258 bs->breakpoint_at->number,
2259 bs->breakpoint_at->exec_pathname);
2260 return PRINT_SRC_AND_LOC;
2263 case bp_catch_catch:
2264 if (current_exception_event &&
2265 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2267 annotate_catchpoint (bs->breakpoint_at->number);
2268 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2269 bs->breakpoint_at->number);
2270 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2271 printf_filtered (_("throw location %s:%d, "),
2272 CURRENT_EXCEPTION_THROW_FILE,
2273 CURRENT_EXCEPTION_THROW_LINE);
2275 printf_filtered (_("throw location unknown, "));
2277 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2278 printf_filtered (_("catch location %s:%d\n"),
2279 CURRENT_EXCEPTION_CATCH_FILE,
2280 CURRENT_EXCEPTION_CATCH_LINE);
2282 printf_filtered (_("catch location unknown\n"));
2284 /* don't bother to print location frame info */
2285 return PRINT_SRC_ONLY;
2289 /* really throw, some other bpstat will handle it */
2290 return PRINT_UNKNOWN;
2294 case bp_catch_throw:
2295 if (current_exception_event &&
2296 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2298 annotate_catchpoint (bs->breakpoint_at->number);
2299 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2300 bs->breakpoint_at->number);
2301 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2302 printf_filtered (_("throw location %s:%d, "),
2303 CURRENT_EXCEPTION_THROW_FILE,
2304 CURRENT_EXCEPTION_THROW_LINE);
2306 printf_filtered (_("throw location unknown, "));
2308 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2309 printf_filtered (_("catch location %s:%d\n"),
2310 CURRENT_EXCEPTION_CATCH_FILE,
2311 CURRENT_EXCEPTION_CATCH_LINE);
2313 printf_filtered (_("catch location unknown\n"));
2315 /* don't bother to print location frame info */
2316 return PRINT_SRC_ONLY;
2320 /* really catch, some other bpstat will handle it */
2321 return PRINT_UNKNOWN;
2326 case bp_hardware_watchpoint:
2327 if (bs->old_val != NULL)
2329 annotate_watchpoint (bs->breakpoint_at->number);
2330 if (ui_out_is_mi_like_p (uiout))
2333 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2334 mention (bs->breakpoint_at);
2335 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2336 ui_out_text (uiout, "\nOld value = ");
2337 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2338 ui_out_field_stream (uiout, "old", stb);
2339 ui_out_text (uiout, "\nNew value = ");
2340 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2341 ui_out_field_stream (uiout, "new", stb);
2342 do_cleanups (ui_out_chain);
2343 ui_out_text (uiout, "\n");
2344 value_free (bs->old_val);
2347 /* More than one watchpoint may have been triggered. */
2348 return PRINT_UNKNOWN;
2351 case bp_read_watchpoint:
2352 if (ui_out_is_mi_like_p (uiout))
2355 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2356 mention (bs->breakpoint_at);
2357 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2358 ui_out_text (uiout, "\nValue = ");
2359 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2360 ui_out_field_stream (uiout, "value", stb);
2361 do_cleanups (ui_out_chain);
2362 ui_out_text (uiout, "\n");
2363 return PRINT_UNKNOWN;
2366 case bp_access_watchpoint:
2367 if (bs->old_val != NULL)
2369 annotate_watchpoint (bs->breakpoint_at->number);
2370 if (ui_out_is_mi_like_p (uiout))
2373 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2374 mention (bs->breakpoint_at);
2375 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2376 ui_out_text (uiout, "\nOld value = ");
2377 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2378 ui_out_field_stream (uiout, "old", stb);
2379 value_free (bs->old_val);
2381 ui_out_text (uiout, "\nNew value = ");
2385 mention (bs->breakpoint_at);
2386 if (ui_out_is_mi_like_p (uiout))
2389 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2390 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2391 ui_out_text (uiout, "\nValue = ");
2393 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2394 ui_out_field_stream (uiout, "new", stb);
2395 do_cleanups (ui_out_chain);
2396 ui_out_text (uiout, "\n");
2397 return PRINT_UNKNOWN;
2400 /* Fall through, we don't deal with these types of breakpoints
2404 if (ui_out_is_mi_like_p (uiout))
2407 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2408 return PRINT_UNKNOWN;
2412 if (ui_out_is_mi_like_p (uiout))
2415 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2416 return PRINT_UNKNOWN;
2421 case bp_longjmp_resume:
2422 case bp_step_resume:
2423 case bp_watchpoint_scope:
2426 return PRINT_UNKNOWN;
2430 /* Generic routine for printing messages indicating why we
2431 stopped. The behavior of this function depends on the value
2432 'print_it' in the bpstat structure. Under some circumstances we
2433 may decide not to print anything here and delegate the task to
2436 static enum print_stop_action
2437 print_bp_stop_message (bpstat bs)
2439 switch (bs->print_it)
2442 /* Nothing should be printed for this bpstat entry. */
2443 return PRINT_UNKNOWN;
2447 /* We still want to print the frame, but we already printed the
2448 relevant messages. */
2449 return PRINT_SRC_AND_LOC;
2452 case print_it_normal:
2453 /* Normal case. Call the breakpoint's print_it method, or
2454 print_it_typical. */
2455 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2456 && bs->breakpoint_at->ops->print_it != NULL)
2457 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2459 return print_it_typical (bs);
2463 internal_error (__FILE__, __LINE__,
2464 _("print_bp_stop_message: unrecognized enum value"));
2469 /* Print a message indicating what happened. This is called from
2470 normal_stop(). The input to this routine is the head of the bpstat
2471 list - a list of the eventpoints that caused this stop. This
2472 routine calls the generic print routine for printing a message
2473 about reasons for stopping. This will print (for example) the
2474 "Breakpoint n," part of the output. The return value of this
2477 PRINT_UNKNOWN: Means we printed nothing
2478 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2479 code to print the location. An example is
2480 "Breakpoint 1, " which should be followed by
2482 PRINT_SRC_ONLY: Means we printed something, but there is no need
2483 to also print the location part of the message.
2484 An example is the catch/throw messages, which
2485 don't require a location appended to the end.
2486 PRINT_NOTHING: We have done some printing and we don't need any
2487 further info to be printed.*/
2489 enum print_stop_action
2490 bpstat_print (bpstat bs)
2494 /* Maybe another breakpoint in the chain caused us to stop.
2495 (Currently all watchpoints go on the bpstat whether hit or not.
2496 That probably could (should) be changed, provided care is taken
2497 with respect to bpstat_explains_signal). */
2498 for (; bs; bs = bs->next)
2500 val = print_bp_stop_message (bs);
2501 if (val == PRINT_SRC_ONLY
2502 || val == PRINT_SRC_AND_LOC
2503 || val == PRINT_NOTHING)
2507 /* We reached the end of the chain, or we got a null BS to start
2508 with and nothing was printed. */
2509 return PRINT_UNKNOWN;
2512 /* Evaluate the expression EXP and return 1 if value is zero.
2513 This is used inside a catch_errors to evaluate the breakpoint condition.
2514 The argument is a "struct expression *" that has been cast to char * to
2515 make it pass through catch_errors. */
2518 breakpoint_cond_eval (void *exp)
2520 struct value *mark = value_mark ();
2521 int i = !value_true (evaluate_expression ((struct expression *) exp));
2522 value_free_to_mark (mark);
2526 /* Allocate a new bpstat and chain it to the current one. */
2529 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2533 bs = (bpstat) xmalloc (sizeof (*bs));
2535 bs->breakpoint_at = b;
2536 /* If the condition is false, etc., don't do the commands. */
2537 bs->commands = NULL;
2539 bs->print_it = print_it_normal;
2543 /* Possible return values for watchpoint_check (this can't be an enum
2544 because of check_errors). */
2545 /* The watchpoint has been deleted. */
2546 #define WP_DELETED 1
2547 /* The value has changed. */
2548 #define WP_VALUE_CHANGED 2
2549 /* The value has not changed. */
2550 #define WP_VALUE_NOT_CHANGED 3
2552 #define BP_TEMPFLAG 1
2553 #define BP_HARDWAREFLAG 2
2555 /* Check watchpoint condition. */
2558 watchpoint_check (void *p)
2560 bpstat bs = (bpstat) p;
2561 struct breakpoint *b;
2562 struct frame_info *fr;
2563 int within_current_scope;
2565 b = bs->breakpoint_at;
2567 if (b->exp_valid_block == NULL)
2568 within_current_scope = 1;
2571 /* There is no current frame at this moment. If we're going to have
2572 any chance of handling watchpoints on local variables, we'll need
2573 the frame chain (so we can determine if we're in scope). */
2574 reinit_frame_cache ();
2575 fr = frame_find_by_id (b->watchpoint_frame);
2576 within_current_scope = (fr != NULL);
2578 /* If we've gotten confused in the unwinder, we might have
2579 returned a frame that can't describe this variable. */
2580 if (within_current_scope
2581 && block_function (b->exp_valid_block) != get_frame_function (fr))
2582 within_current_scope = 0;
2584 /* in_function_epilogue_p() returns a non-zero value if we're still
2585 in the function but the stack frame has already been invalidated.
2586 Since we can't rely on the values of local variables after the
2587 stack has been destroyed, we are treating the watchpoint in that
2588 state as `not changed' without further checking.
2590 vinschen/2003-09-04: The former implementation left out the case
2591 that the watchpoint frame couldn't be found by frame_find_by_id()
2592 because the current PC is currently in an epilogue. Calling
2593 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2594 if ((!within_current_scope || fr == get_current_frame ())
2595 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2596 return WP_VALUE_NOT_CHANGED;
2597 if (fr && within_current_scope)
2598 /* If we end up stopping, the current frame will get selected
2599 in normal_stop. So this call to select_frame won't affect
2604 if (within_current_scope)
2606 /* We use value_{,free_to_}mark because it could be a
2607 *long* time before we return to the command level and
2608 call free_all_values. We can't call free_all_values because
2609 we might be in the middle of evaluating a function call. */
2611 struct value *mark = value_mark ();
2612 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2613 if (!value_equal (b->val, new_val))
2615 release_value (new_val);
2616 value_free_to_mark (mark);
2617 bs->old_val = b->val;
2619 /* We will stop here */
2620 return WP_VALUE_CHANGED;
2624 /* Nothing changed, don't do anything. */
2625 value_free_to_mark (mark);
2626 /* We won't stop here */
2627 return WP_VALUE_NOT_CHANGED;
2632 /* This seems like the only logical thing to do because
2633 if we temporarily ignored the watchpoint, then when
2634 we reenter the block in which it is valid it contains
2635 garbage (in the case of a function, it may have two
2636 garbage values, one before and one after the prologue).
2637 So we can't even detect the first assignment to it and
2638 watch after that (since the garbage may or may not equal
2639 the first value assigned). */
2640 /* We print all the stop information in print_it_typical(), but
2641 in this case, by the time we call print_it_typical() this bp
2642 will be deleted already. So we have no choice but print the
2643 information here. */
2644 if (ui_out_is_mi_like_p (uiout))
2646 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2647 ui_out_text (uiout, "\nWatchpoint ");
2648 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2649 ui_out_text (uiout, " deleted because the program has left the block in\n\
2650 which its expression is valid.\n");
2652 if (b->related_breakpoint)
2653 b->related_breakpoint->disposition = disp_del_at_next_stop;
2654 b->disposition = disp_del_at_next_stop;
2660 /* Get a bpstat associated with having just stopped at address
2661 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2662 target thinks we stopped due to a hardware watchpoint, 0 if we
2663 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2665 /* Determine whether we stopped at a breakpoint, etc, or whether we
2666 don't understand this stop. Result is a chain of bpstat's such that:
2668 if we don't understand the stop, the result is a null pointer.
2670 if we understand why we stopped, the result is not null.
2672 Each element of the chain refers to a particular breakpoint or
2673 watchpoint at which we have stopped. (We may have stopped for
2674 several reasons concurrently.)
2676 Each element of the chain has valid next, breakpoint_at,
2677 commands, FIXME??? fields. */
2680 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
2682 struct breakpoint *b, *temp;
2683 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2684 int real_breakpoint = 0;
2685 /* Root of the chain of bpstat's */
2686 struct bpstats root_bs[1];
2687 /* Pointer to the last thing in the chain currently. */
2688 bpstat bs = root_bs;
2689 int thread_id = pid_to_thread_id (ptid);
2691 ALL_BREAKPOINTS_SAFE (b, temp)
2693 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2696 if (b->type != bp_watchpoint
2697 && b->type != bp_hardware_watchpoint
2698 && b->type != bp_read_watchpoint
2699 && b->type != bp_access_watchpoint
2700 && b->type != bp_hardware_breakpoint
2701 && b->type != bp_catch_fork
2702 && b->type != bp_catch_vfork
2703 && b->type != bp_catch_exec
2704 && b->type != bp_catch_catch
2705 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2707 if (b->loc->address != bp_addr) /* address doesn't match */
2709 if (overlay_debugging /* unmapped overlay section */
2710 && section_is_overlay (b->loc->section)
2711 && !section_is_mapped (b->loc->section))
2715 /* Continuable hardware watchpoints are treated as non-existent if the
2716 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2717 some data address). Otherwise gdb won't stop on a break instruction
2718 in the code (not from a breakpoint) when a hardware watchpoint has
2721 if ((b->type == bp_hardware_watchpoint
2722 || b->type == bp_read_watchpoint
2723 || b->type == bp_access_watchpoint)
2724 && !stopped_by_watchpoint)
2727 if (b->type == bp_hardware_breakpoint)
2729 if (b->loc->address != bp_addr)
2731 if (overlay_debugging /* unmapped overlay section */
2732 && section_is_overlay (b->loc->section)
2733 && !section_is_mapped (b->loc->section))
2737 /* Is this a catchpoint of a load or unload? If so, did we
2738 get a load or unload of the specified library? If not,
2740 if ((b->type == bp_catch_load)
2741 #if defined(SOLIB_HAVE_LOAD_EVENT)
2742 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2743 || ((b->dll_pathname != NULL)
2744 && (strcmp (b->dll_pathname,
2745 SOLIB_LOADED_LIBRARY_PATHNAME (
2746 PIDGET (inferior_ptid)))
2752 if ((b->type == bp_catch_unload)
2753 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2754 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2755 || ((b->dll_pathname != NULL)
2756 && (strcmp (b->dll_pathname,
2757 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2758 PIDGET (inferior_ptid)))
2764 if ((b->type == bp_catch_fork)
2765 && !inferior_has_forked (PIDGET (inferior_ptid),
2766 &b->forked_inferior_pid))
2769 if ((b->type == bp_catch_vfork)
2770 && !inferior_has_vforked (PIDGET (inferior_ptid),
2771 &b->forked_inferior_pid))
2774 if ((b->type == bp_catch_exec)
2775 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2778 if (ep_is_exception_catchpoint (b) &&
2779 !(current_exception_event = target_get_current_exception_event ()))
2782 /* Come here if it's a watchpoint, or if the break address matches */
2784 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2786 /* Watchpoints may change this, if not found to have triggered. */
2790 if (b->type == bp_watchpoint ||
2791 b->type == bp_hardware_watchpoint)
2793 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2795 struct cleanup *cleanups = make_cleanup (xfree, message);
2796 int e = catch_errors (watchpoint_check, bs, message,
2798 do_cleanups (cleanups);
2802 /* We've already printed what needs to be printed. */
2803 /* Actually this is superfluous, because by the time we
2804 call print_it_typical() the wp will be already deleted,
2805 and the function will return immediately. */
2806 bs->print_it = print_it_done;
2809 case WP_VALUE_CHANGED:
2813 case WP_VALUE_NOT_CHANGED:
2815 bs->print_it = print_it_noop;
2822 /* Error from catch_errors. */
2823 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2824 if (b->related_breakpoint)
2825 b->related_breakpoint->disposition = disp_del_at_next_stop;
2826 b->disposition = disp_del_at_next_stop;
2827 /* We've already printed what needs to be printed. */
2828 bs->print_it = print_it_done;
2834 else if (b->type == bp_read_watchpoint ||
2835 b->type == bp_access_watchpoint)
2841 if (!target_stopped_data_address (¤t_target, &addr))
2843 for (v = b->val_chain; v; v = value_next (v))
2845 if (VALUE_LVAL (v) == lval_memory
2846 && ! value_lazy (v))
2848 struct type *vtype = check_typedef (value_type (v));
2850 if (v == b->val_chain
2851 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2852 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2856 vaddr = VALUE_ADDRESS (v) + value_offset (v);
2857 /* Exact match not required. Within range is
2859 if (addr >= vaddr &&
2860 addr < vaddr + TYPE_LENGTH (value_type (v)))
2867 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2869 struct cleanup *cleanups = make_cleanup (xfree, message);
2870 int e = catch_errors (watchpoint_check, bs, message,
2872 do_cleanups (cleanups);
2876 /* We've already printed what needs to be printed. */
2877 bs->print_it = print_it_done;
2880 case WP_VALUE_CHANGED:
2881 if (b->type == bp_read_watchpoint)
2883 /* Don't stop: read watchpoints shouldn't fire if
2884 the value has changed. This is for targets
2885 which cannot set read-only watchpoints. */
2886 bs->print_it = print_it_noop;
2892 case WP_VALUE_NOT_CHANGED:
2899 /* Error from catch_errors. */
2900 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2901 if (b->related_breakpoint)
2902 b->related_breakpoint->disposition = disp_del_at_next_stop;
2903 b->disposition = disp_del_at_next_stop;
2904 /* We've already printed what needs to be printed. */
2905 bs->print_it = print_it_done;
2909 else /* found == 0 */
2911 /* This is a case where some watchpoint(s) triggered,
2912 but not at the address of this watchpoint (FOUND
2913 was left zero). So don't print anything for this
2915 bs->print_it = print_it_noop;
2922 /* By definition, an encountered breakpoint is a triggered
2926 real_breakpoint = 1;
2929 if (frame_id_p (b->frame_id)
2930 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2934 int value_is_zero = 0;
2938 /* Need to select the frame, with all that implies
2939 so that the conditions will have the right context. */
2940 select_frame (get_current_frame ());
2942 = catch_errors (breakpoint_cond_eval, (b->cond),
2943 "Error in testing breakpoint condition:\n",
2945 /* FIXME-someday, should give breakpoint # */
2948 if (b->cond && value_is_zero)
2951 /* Don't consider this a hit. */
2954 else if (b->thread != -1 && b->thread != thread_id)
2957 /* Don't consider this a hit. */
2960 else if (b->ignore_count > 0)
2963 annotate_ignore_count_change ();
2968 /* We will stop here */
2969 if (b->disposition == disp_disable)
2970 b->enable_state = bp_disabled;
2973 bs->commands = b->commands;
2975 (strcmp ("silent", bs->commands->line) == 0
2976 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2978 bs->commands = bs->commands->next;
2981 bs->commands = copy_command_lines (bs->commands);
2984 /* Print nothing for this entry if we dont stop or if we dont print. */
2985 if (bs->stop == 0 || bs->print == 0)
2986 bs->print_it = print_it_noop;
2989 bs->next = NULL; /* Terminate the chain */
2990 bs = root_bs->next; /* Re-grab the head of the chain */
2992 /* The value of a hardware watchpoint hasn't changed, but the
2993 intermediate memory locations we are watching may have. */
2994 if (bs && !bs->stop &&
2995 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2996 bs->breakpoint_at->type == bp_read_watchpoint ||
2997 bs->breakpoint_at->type == bp_access_watchpoint))
2999 remove_breakpoints ();
3000 insert_breakpoints ();
3005 /* Tell what to do about this bpstat. */
3007 bpstat_what (bpstat bs)
3009 /* Classify each bpstat as one of the following. */
3012 /* This bpstat element has no effect on the main_action. */
3015 /* There was a watchpoint, stop but don't print. */
3018 /* There was a watchpoint, stop and print. */
3021 /* There was a breakpoint but we're not stopping. */
3024 /* There was a breakpoint, stop but don't print. */
3027 /* There was a breakpoint, stop and print. */
3030 /* We hit the longjmp breakpoint. */
3033 /* We hit the longjmp_resume breakpoint. */
3036 /* We hit the step_resume breakpoint. */
3039 /* We hit the shared library event breakpoint. */
3042 /* We caught a shared library event. */
3045 /* This is just used to count how many enums there are. */
3049 /* Here is the table which drives this routine. So that we can
3050 format it pretty, we define some abbreviations for the
3051 enum bpstat_what codes. */
3052 #define kc BPSTAT_WHAT_KEEP_CHECKING
3053 #define ss BPSTAT_WHAT_STOP_SILENT
3054 #define sn BPSTAT_WHAT_STOP_NOISY
3055 #define sgl BPSTAT_WHAT_SINGLE
3056 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3057 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3058 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3059 #define sr BPSTAT_WHAT_STEP_RESUME
3060 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3061 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3063 /* "Can't happen." Might want to print an error message.
3064 abort() is not out of the question, but chances are GDB is just
3065 a bit confused, not unusable. */
3066 #define err BPSTAT_WHAT_STOP_NOISY
3068 /* Given an old action and a class, come up with a new action. */
3069 /* One interesting property of this table is that wp_silent is the same
3070 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3071 after stopping, the check for whether to step over a breakpoint
3072 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3073 reference to how we stopped. We retain separate wp_silent and
3074 bp_silent codes in case we want to change that someday.
3076 Another possibly interesting property of this table is that
3077 there's a partial ordering, priority-like, of the actions. Once
3078 you've decided that some action is appropriate, you'll never go
3079 back and decide something of a lower priority is better. The
3082 kc < clr sgl shl shlr slr sn sr ss
3083 sgl < clrs shl shlr slr sn sr ss
3084 slr < err shl shlr sn sr ss
3085 clr < clrs err shl shlr sn sr ss
3086 clrs < err shl shlr sn sr ss
3093 What I think this means is that we don't need a damned table
3094 here. If you just put the rows and columns in the right order,
3095 it'd look awfully regular. We could simply walk the bpstat list
3096 and choose the highest priority action we find, with a little
3097 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3098 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3099 is messy anyway). */
3101 /* step_resume entries: a step resume breakpoint overrides another
3102 breakpoint of signal handling (see comment in wait_for_inferior
3103 at where we set the step_resume breakpoint). */
3105 static const enum bpstat_what_main_action
3106 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3109 /* kc ss sn sgl slr clr clrs sr shl shlr
3112 {kc, ss, sn, sgl, slr, clr, clrs, sr, shl, shlr},
3114 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3116 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3118 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, shl, shlr},
3120 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3122 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3124 {slr, ss, sn, slr, slr, err, err, sr, shl, shlr},
3126 {clr, ss, sn, clrs, err, err, err, sr, shl, shlr},
3128 {sr, sr, sr, sr, sr, sr, sr, sr, sr, sr},
3130 {shl, shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3132 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3147 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3148 struct bpstat_what retval;
3150 retval.call_dummy = 0;
3151 for (; bs != NULL; bs = bs->next)
3153 enum class bs_class = no_effect;
3154 if (bs->breakpoint_at == NULL)
3155 /* I suspect this can happen if it was a momentary breakpoint
3156 which has since been deleted. */
3158 switch (bs->breakpoint_at->type)
3164 case bp_hardware_breakpoint:
3170 bs_class = bp_noisy;
3172 bs_class = bp_silent;
3175 bs_class = bp_nostop;
3178 case bp_hardware_watchpoint:
3179 case bp_read_watchpoint:
3180 case bp_access_watchpoint:
3184 bs_class = wp_noisy;
3186 bs_class = wp_silent;
3189 /* There was a watchpoint, but we're not stopping.
3190 This requires no further action. */
3191 bs_class = no_effect;
3194 bs_class = long_jump;
3196 case bp_longjmp_resume:
3197 bs_class = long_resume;
3199 case bp_step_resume:
3202 bs_class = step_resume;
3205 /* It is for the wrong frame. */
3206 bs_class = bp_nostop;
3208 case bp_watchpoint_scope:
3209 bs_class = bp_nostop;
3211 case bp_shlib_event:
3212 bs_class = shlib_event;
3214 case bp_thread_event:
3215 case bp_overlay_event:
3216 bs_class = bp_nostop;
3219 case bp_catch_unload:
3220 /* Only if this catchpoint triggered should we cause the
3221 step-out-of-dld behaviour. Otherwise, we ignore this
3224 bs_class = catch_shlib_event;
3226 bs_class = no_effect;
3229 case bp_catch_vfork:
3234 bs_class = bp_noisy;
3236 bs_class = bp_silent;
3239 /* There was a catchpoint, but we're not stopping.
3240 This requires no further action. */
3241 bs_class = no_effect;
3243 case bp_catch_catch:
3244 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3245 bs_class = bp_nostop;
3247 bs_class = bs->print ? bp_noisy : bp_silent;
3249 case bp_catch_throw:
3250 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3251 bs_class = bp_nostop;
3253 bs_class = bs->print ? bp_noisy : bp_silent;
3256 /* Make sure the action is stop (silent or noisy),
3257 so infrun.c pops the dummy frame. */
3258 bs_class = bp_silent;
3259 retval.call_dummy = 1;
3262 current_action = table[(int) bs_class][(int) current_action];
3264 retval.main_action = current_action;
3268 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3269 without hardware support). This isn't related to a specific bpstat,
3270 just to things like whether watchpoints are set. */
3273 bpstat_should_step (void)
3275 struct breakpoint *b;
3277 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3282 /* Nonzero if there are enabled hardware watchpoints. */
3284 bpstat_have_active_hw_watchpoints (void)
3286 struct bp_location *bpt;
3287 ALL_BP_LOCATIONS (bpt)
3288 if (breakpoint_enabled (bpt->owner)
3290 && bpt->loc_type == bp_loc_hardware_watchpoint)
3296 /* Given a bpstat that records zero or more triggered eventpoints, this
3297 function returns another bpstat which contains only the catchpoints
3298 on that first list, if any. */
3300 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3302 struct bpstats root_bs[1];
3303 bpstat bs = root_bs;
3304 struct breakpoint *ep;
3307 bpstat_clear (cp_list);
3308 root_bs->next = NULL;
3310 for (; ep_list != NULL; ep_list = ep_list->next)
3312 /* Is this eventpoint a catchpoint? If not, ignore it. */
3313 ep = ep_list->breakpoint_at;
3316 if ((ep->type != bp_catch_load) &&
3317 (ep->type != bp_catch_unload) &&
3318 (ep->type != bp_catch_catch) &&
3319 (ep->type != bp_catch_throw))
3320 /* pai: (temp) ADD fork/vfork here!! */
3323 /* Yes; add it to the list. */
3324 bs = bpstat_alloc (ep, bs);
3329 #if defined(SOLIB_ADD)
3330 /* Also, for each triggered catchpoint, tag it with the name of
3331 the library that caused this trigger. (We copy the name now,
3332 because it's only guaranteed to be available NOW, when the
3333 catchpoint triggers. Clients who may wish to know the name
3334 later must get it from the catchpoint itself.) */
3335 if (ep->triggered_dll_pathname != NULL)
3336 xfree (ep->triggered_dll_pathname);
3337 if (ep->type == bp_catch_load)
3338 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3339 PIDGET (inferior_ptid));
3341 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3342 PIDGET (inferior_ptid));
3344 dll_pathname = NULL;
3348 ep->triggered_dll_pathname = (char *)
3349 xmalloc (strlen (dll_pathname) + 1);
3350 strcpy (ep->triggered_dll_pathname, dll_pathname);
3353 ep->triggered_dll_pathname = NULL;
3359 /* Print B to gdb_stdout. */
3361 print_one_breakpoint (struct breakpoint *b,
3362 CORE_ADDR *last_addr)
3364 struct command_line *l;
3366 struct ep_type_description
3371 static struct ep_type_description bptypes[] =
3373 {bp_none, "?deleted?"},
3374 {bp_breakpoint, "breakpoint"},
3375 {bp_hardware_breakpoint, "hw breakpoint"},
3376 {bp_until, "until"},
3377 {bp_finish, "finish"},
3378 {bp_watchpoint, "watchpoint"},
3379 {bp_hardware_watchpoint, "hw watchpoint"},
3380 {bp_read_watchpoint, "read watchpoint"},
3381 {bp_access_watchpoint, "acc watchpoint"},
3382 {bp_longjmp, "longjmp"},
3383 {bp_longjmp_resume, "longjmp resume"},
3384 {bp_step_resume, "step resume"},
3385 {bp_watchpoint_scope, "watchpoint scope"},
3386 {bp_call_dummy, "call dummy"},
3387 {bp_shlib_event, "shlib events"},
3388 {bp_thread_event, "thread events"},
3389 {bp_overlay_event, "overlay events"},
3390 {bp_catch_load, "catch load"},
3391 {bp_catch_unload, "catch unload"},
3392 {bp_catch_fork, "catch fork"},
3393 {bp_catch_vfork, "catch vfork"},
3394 {bp_catch_exec, "catch exec"},
3395 {bp_catch_catch, "catch catch"},
3396 {bp_catch_throw, "catch throw"}
3399 static char *bpdisps[] =
3400 {"del", "dstp", "dis", "keep"};
3401 static char bpenables[] = "nynny";
3402 char wrap_indent[80];
3403 struct ui_stream *stb = ui_out_stream_new (uiout);
3404 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3405 struct cleanup *bkpt_chain;
3408 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3412 ui_out_field_int (uiout, "number", b->number);
3416 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3417 || ((int) b->type != bptypes[(int) b->type].type))
3418 internal_error (__FILE__, __LINE__,
3419 _("bptypes table does not describe type #%d."),
3421 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3425 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3429 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3430 ui_out_spaces (uiout, 2);
3433 strcpy (wrap_indent, " ");
3436 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3437 strcat (wrap_indent, " ");
3439 strcat (wrap_indent, " ");
3442 if (b->ops != NULL && b->ops->print_one != NULL)
3443 b->ops->print_one (b, last_addr);
3448 internal_error (__FILE__, __LINE__,
3449 _("print_one_breakpoint: bp_none encountered\n"));
3453 case bp_hardware_watchpoint:
3454 case bp_read_watchpoint:
3455 case bp_access_watchpoint:
3456 /* Field 4, the address, is omitted (which makes the columns
3457 not line up too nicely with the headers, but the effect
3458 is relatively readable). */
3460 ui_out_field_skip (uiout, "addr");
3462 print_expression (b->exp, stb->stream);
3463 ui_out_field_stream (uiout, "what", stb);
3467 case bp_catch_unload:
3468 /* Field 4, the address, is omitted (which makes the columns
3469 not line up too nicely with the headers, but the effect
3470 is relatively readable). */
3472 ui_out_field_skip (uiout, "addr");
3474 if (b->dll_pathname == NULL)
3476 ui_out_field_string (uiout, "what", "<any library>");
3477 ui_out_spaces (uiout, 1);
3481 ui_out_text (uiout, "library \"");
3482 ui_out_field_string (uiout, "what", b->dll_pathname);
3483 ui_out_text (uiout, "\" ");
3488 case bp_catch_vfork:
3489 /* Field 4, the address, is omitted (which makes the columns
3490 not line up too nicely with the headers, but the effect
3491 is relatively readable). */
3493 ui_out_field_skip (uiout, "addr");
3495 if (b->forked_inferior_pid != 0)
3497 ui_out_text (uiout, "process ");
3498 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3499 ui_out_spaces (uiout, 1);
3504 /* Field 4, the address, is omitted (which makes the columns
3505 not line up too nicely with the headers, but the effect
3506 is relatively readable). */
3508 ui_out_field_skip (uiout, "addr");
3510 if (b->exec_pathname != NULL)
3512 ui_out_text (uiout, "program \"");
3513 ui_out_field_string (uiout, "what", b->exec_pathname);
3514 ui_out_text (uiout, "\" ");
3518 case bp_catch_catch:
3519 /* Field 4, the address, is omitted (which makes the columns
3520 not line up too nicely with the headers, but the effect
3521 is relatively readable). */
3523 ui_out_field_skip (uiout, "addr");
3525 ui_out_field_string (uiout, "what", "exception catch");
3526 ui_out_spaces (uiout, 1);
3529 case bp_catch_throw:
3530 /* Field 4, the address, is omitted (which makes the columns
3531 not line up too nicely with the headers, but the effect
3532 is relatively readable). */
3534 ui_out_field_skip (uiout, "addr");
3536 ui_out_field_string (uiout, "what", "exception throw");
3537 ui_out_spaces (uiout, 1);
3541 case bp_hardware_breakpoint:
3545 case bp_longjmp_resume:
3546 case bp_step_resume:
3547 case bp_watchpoint_scope:
3549 case bp_shlib_event:
3550 case bp_thread_event:
3551 case bp_overlay_event:
3556 ui_out_field_string (uiout, "addr", "<PENDING>");
3558 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3561 *last_addr = b->loc->address;
3564 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3567 ui_out_text (uiout, "in ");
3568 ui_out_field_string (uiout, "func",
3569 SYMBOL_PRINT_NAME (sym));
3570 ui_out_wrap_hint (uiout, wrap_indent);
3571 ui_out_text (uiout, " at ");
3573 ui_out_field_string (uiout, "file", b->source_file);
3574 ui_out_text (uiout, ":");
3576 if (ui_out_is_mi_like_p (uiout))
3578 struct symtab_and_line sal = find_pc_line (b->loc->address, 0);
3579 char *fullname = symtab_to_fullname (sal.symtab);
3582 ui_out_field_string (uiout, "fullname", fullname);
3585 ui_out_field_int (uiout, "line", b->line_number);
3587 else if (b->pending)
3589 ui_out_field_string (uiout, "pending", b->addr_string);
3593 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3594 ui_out_field_stream (uiout, "at", stb);
3599 if (b->thread != -1)
3601 /* FIXME: This seems to be redundant and lost here; see the
3602 "stop only in" line a little further down. */
3603 ui_out_text (uiout, " thread ");
3604 ui_out_field_int (uiout, "thread", b->thread);
3607 ui_out_text (uiout, "\n");
3609 if (frame_id_p (b->frame_id))
3612 ui_out_text (uiout, "\tstop only in stack frame at ");
3613 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3615 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3616 ui_out_text (uiout, "\n");
3619 if (b->cond && !ada_exception_catchpoint_p (b))
3621 /* We do not print the condition for Ada exception catchpoints
3622 because the condition is an internal implementation detail
3623 that we do not want to expose to the user. */
3625 ui_out_text (uiout, "\tstop only if ");
3626 print_expression (b->cond, stb->stream);
3627 ui_out_field_stream (uiout, "cond", stb);
3628 ui_out_text (uiout, "\n");
3631 if (b->pending && b->cond_string)
3634 ui_out_text (uiout, "\tstop only if ");
3635 ui_out_field_string (uiout, "cond", b->cond_string);
3636 ui_out_text (uiout, "\n");
3639 if (b->thread != -1)
3641 /* FIXME should make an annotation for this */
3642 ui_out_text (uiout, "\tstop only in thread ");
3643 ui_out_field_int (uiout, "thread", b->thread);
3644 ui_out_text (uiout, "\n");
3647 if (show_breakpoint_hit_counts && b->hit_count)
3649 /* FIXME should make an annotation for this */
3650 if (ep_is_catchpoint (b))
3651 ui_out_text (uiout, "\tcatchpoint");
3653 ui_out_text (uiout, "\tbreakpoint");
3654 ui_out_text (uiout, " already hit ");
3655 ui_out_field_int (uiout, "times", b->hit_count);
3656 if (b->hit_count == 1)
3657 ui_out_text (uiout, " time\n");
3659 ui_out_text (uiout, " times\n");
3662 /* Output the count also if it is zero, but only if this is
3663 mi. FIXME: Should have a better test for this. */
3664 if (ui_out_is_mi_like_p (uiout))
3665 if (show_breakpoint_hit_counts && b->hit_count == 0)
3666 ui_out_field_int (uiout, "times", b->hit_count);
3668 if (b->ignore_count)
3671 ui_out_text (uiout, "\tignore next ");
3672 ui_out_field_int (uiout, "ignore", b->ignore_count);
3673 ui_out_text (uiout, " hits\n");
3676 if ((l = b->commands))
3678 struct cleanup *script_chain;
3681 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3682 print_command_lines (uiout, l, 4);
3683 do_cleanups (script_chain);
3685 do_cleanups (bkpt_chain);
3686 do_cleanups (old_chain);
3689 struct captured_breakpoint_query_args
3695 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3697 struct captured_breakpoint_query_args *args = data;
3698 struct breakpoint *b;
3699 CORE_ADDR dummy_addr = 0;
3702 if (args->bnum == b->number)
3704 print_one_breakpoint (b, &dummy_addr);
3712 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3714 struct captured_breakpoint_query_args args;
3716 /* For the moment we don't trust print_one_breakpoint() to not throw
3718 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3719 error_message, RETURN_MASK_ALL) < 0)
3725 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3726 catchpoints, et.al.). */
3729 user_settable_breakpoint (const struct breakpoint *b)
3731 return (b->type == bp_breakpoint
3732 || b->type == bp_catch_load
3733 || b->type == bp_catch_unload
3734 || b->type == bp_catch_fork
3735 || b->type == bp_catch_vfork
3736 || b->type == bp_catch_exec
3737 || b->type == bp_catch_catch
3738 || b->type == bp_catch_throw
3739 || b->type == bp_hardware_breakpoint
3740 || b->type == bp_watchpoint
3741 || b->type == bp_read_watchpoint
3742 || b->type == bp_access_watchpoint
3743 || b->type == bp_hardware_watchpoint);
3746 /* Print information on user settable breakpoint (watchpoint, etc)
3747 number BNUM. If BNUM is -1 print all user settable breakpoints.
3748 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3751 breakpoint_1 (int bnum, int allflag)
3753 struct breakpoint *b;
3754 CORE_ADDR last_addr = (CORE_ADDR) -1;
3755 int nr_printable_breakpoints;
3756 struct cleanup *bkpttbl_chain;
3758 /* Compute the number of rows in the table. */
3759 nr_printable_breakpoints = 0;
3762 || bnum == b->number)
3764 if (allflag || user_settable_breakpoint (b))
3765 nr_printable_breakpoints++;
3770 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3774 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3777 if (nr_printable_breakpoints > 0)
3778 annotate_breakpoints_headers ();
3779 if (nr_printable_breakpoints > 0)
3781 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3782 if (nr_printable_breakpoints > 0)
3784 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3785 if (nr_printable_breakpoints > 0)
3787 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3788 if (nr_printable_breakpoints > 0)
3790 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3793 if (nr_printable_breakpoints > 0)
3795 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3796 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3798 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3800 if (nr_printable_breakpoints > 0)
3802 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3803 ui_out_table_body (uiout);
3804 if (nr_printable_breakpoints > 0)
3805 annotate_breakpoints_table ();
3809 || bnum == b->number)
3811 /* We only print out user settable breakpoints unless the
3813 if (allflag || user_settable_breakpoint (b))
3814 print_one_breakpoint (b, &last_addr);
3817 do_cleanups (bkpttbl_chain);
3819 if (nr_printable_breakpoints == 0)
3822 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3824 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3829 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3830 that a comparison of an unsigned with -1 is always false. */
3831 if (last_addr != (CORE_ADDR) -1)
3832 set_next_address (last_addr);
3835 /* FIXME? Should this be moved up so that it is only called when
3836 there have been breakpoints? */
3837 annotate_breakpoints_table_end ();
3841 breakpoints_info (char *bnum_exp, int from_tty)
3846 bnum = parse_and_eval_long (bnum_exp);
3848 breakpoint_1 (bnum, 0);
3852 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3857 bnum = parse_and_eval_long (bnum_exp);
3859 breakpoint_1 (bnum, 1);
3862 /* Print a message describing any breakpoints set at PC. */
3865 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
3868 struct breakpoint *b;
3871 if (b->loc->address == pc) /* address match / overlay match */
3872 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3877 printf_filtered (_("Note: breakpoint "));
3878 else /* if (others == ???) */
3879 printf_filtered (_("Note: breakpoints "));
3881 if (b->loc->address == pc) /* address match / overlay match */
3882 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3885 printf_filtered ("%d", b->number);
3886 if (b->thread == -1 && thread != -1)
3887 printf_filtered (" (all threads)");
3888 else if (b->thread != -1)
3889 printf_filtered (" (thread %d)", b->thread);
3890 printf_filtered ("%s%s ",
3891 ((b->enable_state == bp_disabled ||
3892 b->enable_state == bp_shlib_disabled ||
3893 b->enable_state == bp_call_disabled)
3895 : b->enable_state == bp_permanent
3899 : ((others == 1) ? " and" : ""));
3901 printf_filtered (_("also set at pc "));
3902 deprecated_print_address_numeric (pc, 1, gdb_stdout);
3903 printf_filtered (".\n");
3907 /* Set the default place to put a breakpoint
3908 for the `break' command with no arguments. */
3911 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3914 default_breakpoint_valid = valid;
3915 default_breakpoint_address = addr;
3916 default_breakpoint_symtab = symtab;
3917 default_breakpoint_line = line;
3920 /* Return true iff it is meaningful to use the address member of
3921 BPT. For some breakpoint types, the address member is irrelevant
3922 and it makes no sense to attempt to compare it to other addresses
3923 (or use it for any other purpose either).
3925 More specifically, each of the following breakpoint types will always
3926 have a zero valued address and we don't want check_duplicates() to mark
3927 breakpoints of any of these types to be a duplicate of an actual
3928 breakpoint at address zero:
3931 bp_hardware_watchpoint
3933 bp_access_watchpoint
3940 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3942 enum bptype type = bpt->type;
3944 return (type != bp_watchpoint
3945 && type != bp_hardware_watchpoint
3946 && type != bp_read_watchpoint
3947 && type != bp_access_watchpoint
3948 && type != bp_catch_exec
3949 && type != bp_longjmp_resume
3950 && type != bp_catch_fork
3951 && type != bp_catch_vfork);
3954 /* Rescan breakpoints at the same address and section as BPT,
3955 marking the first one as "first" and any others as "duplicates".
3956 This is so that the bpt instruction is only inserted once.
3957 If we have a permanent breakpoint at the same place as BPT, make
3958 that one the official one, and the rest as duplicates. */
3961 check_duplicates (struct breakpoint *bpt)
3963 struct bp_location *b;
3965 struct bp_location *perm_bp = 0;
3966 CORE_ADDR address = bpt->loc->address;
3967 asection *section = bpt->loc->section;
3969 if (! breakpoint_address_is_meaningful (bpt))
3972 ALL_BP_LOCATIONS (b)
3973 if (b->owner->enable_state != bp_disabled
3974 && b->owner->enable_state != bp_shlib_disabled
3975 && !b->owner->pending
3976 && b->owner->enable_state != bp_call_disabled
3977 && b->address == address /* address / overlay match */
3978 && (!overlay_debugging || b->section == section)
3979 && breakpoint_address_is_meaningful (b->owner))
3981 /* Have we found a permanent breakpoint? */
3982 if (b->owner->enable_state == bp_permanent)
3989 b->duplicate = count > 1;
3992 /* If we found a permanent breakpoint at this address, go over the
3993 list again and declare all the other breakpoints there to be the
3997 perm_bp->duplicate = 0;
3999 /* Permanent breakpoint should always be inserted. */
4000 if (! perm_bp->inserted)
4001 internal_error (__FILE__, __LINE__,
4002 _("allegedly permanent breakpoint is not "
4003 "actually inserted"));
4005 ALL_BP_LOCATIONS (b)
4008 if (b->owner->enable_state != bp_disabled
4009 && b->owner->enable_state != bp_shlib_disabled
4010 && !b->owner->pending
4011 && b->owner->enable_state != bp_call_disabled
4012 && b->address == address /* address / overlay match */
4013 && (!overlay_debugging || b->section == section)
4014 && breakpoint_address_is_meaningful (b->owner))
4017 internal_error (__FILE__, __LINE__,
4018 _("another breakpoint was inserted on top of "
4019 "a permanent breakpoint"));
4028 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4029 int bnum, int have_bnum)
4034 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4035 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4037 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4038 bnum, astr1, astr2);
4040 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4043 /* Adjust a breakpoint's address to account for architectural constraints
4044 on breakpoint placement. Return the adjusted address. Note: Very
4045 few targets require this kind of adjustment. For most targets,
4046 this function is simply the identity function. */
4049 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4051 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4053 /* Very few targets need any kind of breakpoint adjustment. */
4056 else if (bptype == bp_watchpoint
4057 || bptype == bp_hardware_watchpoint
4058 || bptype == bp_read_watchpoint
4059 || bptype == bp_access_watchpoint
4060 || bptype == bp_catch_fork
4061 || bptype == bp_catch_vfork
4062 || bptype == bp_catch_exec)
4064 /* Watchpoints and the various bp_catch_* eventpoints should not
4065 have their addresses modified. */
4070 CORE_ADDR adjusted_bpaddr;
4072 /* Some targets have architectural constraints on the placement
4073 of breakpoint instructions. Obtain the adjusted address. */
4074 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4077 /* An adjusted breakpoint address can significantly alter
4078 a user's expectations. Print a warning if an adjustment
4080 if (adjusted_bpaddr != bpaddr)
4081 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4083 return adjusted_bpaddr;
4087 /* Allocate a struct bp_location. */
4089 static struct bp_location *
4090 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4092 struct bp_location *loc, *loc_p;
4094 loc = xmalloc (sizeof (struct bp_location));
4095 memset (loc, 0, sizeof (*loc));
4105 case bp_longjmp_resume:
4106 case bp_step_resume:
4107 case bp_watchpoint_scope:
4109 case bp_shlib_event:
4110 case bp_thread_event:
4111 case bp_overlay_event:
4113 case bp_catch_unload:
4114 loc->loc_type = bp_loc_software_breakpoint;
4116 case bp_hardware_breakpoint:
4117 loc->loc_type = bp_loc_hardware_breakpoint;
4119 case bp_hardware_watchpoint:
4120 case bp_read_watchpoint:
4121 case bp_access_watchpoint:
4122 loc->loc_type = bp_loc_hardware_watchpoint;
4126 case bp_catch_vfork:
4128 case bp_catch_catch:
4129 case bp_catch_throw:
4130 loc->loc_type = bp_loc_other;
4133 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4136 /* Add this breakpoint to the end of the chain. */
4138 loc_p = bp_location_chain;
4140 bp_location_chain = loc;
4144 loc_p = loc_p->next;
4151 /* set_raw_breakpoint() is a low level routine for allocating and
4152 partially initializing a breakpoint of type BPTYPE. The newly
4153 created breakpoint's address, section, source file name, and line
4154 number are provided by SAL. The newly created and partially
4155 initialized breakpoint is added to the breakpoint chain and
4156 is also returned as the value of this function.
4158 It is expected that the caller will complete the initialization of
4159 the newly created breakpoint struct as well as output any status
4160 information regarding the creation of a new breakpoint. In
4161 particular, set_raw_breakpoint() does NOT set the breakpoint
4162 number! Care should be taken to not allow an error() to occur
4163 prior to completing the initialization of the breakpoint. If this
4164 should happen, a bogus breakpoint will be left on the chain. */
4167 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4169 struct breakpoint *b, *b1;
4170 CORE_ADDR adjusted_address;
4172 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4173 memset (b, 0, sizeof (*b));
4175 /* Adjust the breakpoint's address prior to allocating a location.
4176 Once we call allocate_bp_location(), that mostly uninitialized
4177 location will be placed on the location chain. Adjustment of the
4178 breakpoint may cause read_memory_nobpt() to be called and we do
4179 not want its scan of the location chain to find a breakpoint and
4180 location that's only been partially initialized. */
4181 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4183 b->loc = allocate_bp_location (b, bptype);
4184 b->loc->requested_address = sal.pc;
4185 b->loc->address = adjusted_address;
4187 if (sal.symtab == NULL)
4188 b->source_file = NULL;
4190 b->source_file = savestring (sal.symtab->filename,
4191 strlen (sal.symtab->filename));
4192 b->loc->section = sal.section;
4194 b->language = current_language->la_language;
4195 b->input_radix = input_radix;
4197 b->line_number = sal.line;
4198 b->enable_state = bp_enabled;
4201 b->ignore_count = 0;
4203 b->frame_id = null_frame_id;
4204 b->dll_pathname = NULL;
4205 b->triggered_dll_pathname = NULL;
4206 b->forked_inferior_pid = 0;
4207 b->exec_pathname = NULL;
4211 /* Add this breakpoint to the end of the chain
4212 so that a list of breakpoints will come out in order
4213 of increasing numbers. */
4215 b1 = breakpoint_chain;
4217 breakpoint_chain = b;
4225 check_duplicates (b);
4226 breakpoints_changed ();
4232 /* Note that the breakpoint object B describes a permanent breakpoint
4233 instruction, hard-wired into the inferior's code. */
4235 make_breakpoint_permanent (struct breakpoint *b)
4237 b->enable_state = bp_permanent;
4239 /* By definition, permanent breakpoints are already present in the code. */
4240 b->loc->inserted = 1;
4243 static struct breakpoint *
4244 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4246 static int internal_breakpoint_number = -1;
4247 struct symtab_and_line sal;
4248 struct breakpoint *b;
4250 init_sal (&sal); /* initialize to zeroes */
4253 sal.section = find_pc_overlay (sal.pc);
4255 b = set_raw_breakpoint (sal, type);
4256 b->number = internal_breakpoint_number--;
4257 b->disposition = disp_donttouch;
4264 create_longjmp_breakpoint (char *func_name)
4266 struct breakpoint *b;
4267 struct minimal_symbol *m;
4269 if (func_name == NULL)
4270 b = create_internal_breakpoint (0, bp_longjmp_resume);
4273 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4276 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4279 b->enable_state = bp_disabled;
4282 b->addr_string = xstrdup (func_name);
4285 /* Call this routine when stepping and nexting to enable a breakpoint
4286 if we do a longjmp(). When we hit that breakpoint, call
4287 set_longjmp_resume_breakpoint() to figure out where we are going. */
4290 enable_longjmp_breakpoint (void)
4292 struct breakpoint *b;
4295 if (b->type == bp_longjmp)
4297 b->enable_state = bp_enabled;
4298 check_duplicates (b);
4303 disable_longjmp_breakpoint (void)
4305 struct breakpoint *b;
4308 if (b->type == bp_longjmp
4309 || b->type == bp_longjmp_resume)
4311 b->enable_state = bp_disabled;
4312 check_duplicates (b);
4317 create_overlay_event_breakpoint (char *func_name)
4319 struct breakpoint *b;
4320 struct minimal_symbol *m;
4322 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4325 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4327 b->addr_string = xstrdup (func_name);
4329 if (overlay_debugging == ovly_auto)
4331 b->enable_state = bp_enabled;
4332 overlay_events_enabled = 1;
4336 b->enable_state = bp_disabled;
4337 overlay_events_enabled = 0;
4342 enable_overlay_breakpoints (void)
4344 struct breakpoint *b;
4347 if (b->type == bp_overlay_event)
4349 b->enable_state = bp_enabled;
4350 check_duplicates (b);
4351 overlay_events_enabled = 1;
4356 disable_overlay_breakpoints (void)
4358 struct breakpoint *b;
4361 if (b->type == bp_overlay_event)
4363 b->enable_state = bp_disabled;
4364 check_duplicates (b);
4365 overlay_events_enabled = 0;
4370 create_thread_event_breakpoint (CORE_ADDR address)
4372 struct breakpoint *b;
4374 b = create_internal_breakpoint (address, bp_thread_event);
4376 b->enable_state = bp_enabled;
4377 /* addr_string has to be used or breakpoint_re_set will delete me. */
4378 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4384 remove_thread_event_breakpoints (void)
4386 struct breakpoint *b, *temp;
4388 ALL_BREAKPOINTS_SAFE (b, temp)
4389 if (b->type == bp_thread_event)
4390 delete_breakpoint (b);
4393 struct captured_parse_breakpoint_args
4396 struct symtabs_and_lines *sals_p;
4397 char ***addr_string_p;
4401 struct lang_and_radix
4407 /* Cleanup helper routine to restore the current language and
4410 do_restore_lang_radix_cleanup (void *old)
4412 struct lang_and_radix *p = old;
4413 set_language (p->lang);
4414 input_radix = p->radix;
4417 /* Try and resolve a pending breakpoint. */
4419 resolve_pending_breakpoint (struct breakpoint *b)
4421 /* Try and reparse the breakpoint in case the shared library
4423 struct symtabs_and_lines sals;
4424 struct symtab_and_line pending_sal;
4425 char **cond_string = (char **) NULL;
4426 char *copy_arg = b->addr_string;
4431 struct ui_file *old_gdb_stderr;
4432 struct lang_and_radix old_lr;
4433 struct cleanup *old_chain;
4435 /* Set language, input-radix, then reissue breakpoint command.
4436 Ensure the language and input-radix are restored afterwards. */
4437 old_lr.lang = current_language->la_language;
4438 old_lr.radix = input_radix;
4439 old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr);
4441 set_language (b->language);
4442 input_radix = b->input_radix;
4443 rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b);
4445 if (rc == GDB_RC_OK)
4446 /* Pending breakpoint has been resolved. */
4447 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b->addr_string);
4449 do_cleanups (old_chain);
4454 remove_solib_event_breakpoints (void)
4456 struct breakpoint *b, *temp;
4458 ALL_BREAKPOINTS_SAFE (b, temp)
4459 if (b->type == bp_shlib_event)
4460 delete_breakpoint (b);
4464 create_solib_event_breakpoint (CORE_ADDR address)
4466 struct breakpoint *b;
4468 b = create_internal_breakpoint (address, bp_shlib_event);
4472 /* Disable any breakpoints that are on code in shared libraries. Only
4473 apply to enabled breakpoints, disabled ones can just stay disabled. */
4476 disable_breakpoints_in_shlibs (int silent)
4478 struct breakpoint *b;
4479 int disabled_shlib_breaks = 0;
4483 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4484 && breakpoint_enabled (b) && !b->loc->duplicate
4486 && PC_SOLIB (b->loc->address)
4488 && solib_address (b->loc->address)
4492 b->enable_state = bp_shlib_disabled;
4495 if (!disabled_shlib_breaks)
4497 target_terminal_ours_for_output ();
4498 warning (_("Temporarily disabling shared library breakpoints:"));
4500 disabled_shlib_breaks = 1;
4501 warning (_("breakpoint #%d "), b->number);
4507 /* Disable any breakpoints that are in in an unloaded shared library. Only
4508 apply to enabled breakpoints, disabled ones can just stay disabled. */
4511 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4513 struct breakpoint *b;
4514 int disabled_shlib_breaks = 0;
4518 if ((b->loc->loc_type == bp_loc_hardware_breakpoint
4519 || b->loc->loc_type == bp_loc_software_breakpoint)
4520 && breakpoint_enabled (b) && !b->loc->duplicate)
4523 char *so_name = PC_SOLIB (b->loc->address);
4525 char *so_name = solib_address (b->loc->address);
4527 if (so_name && !strcmp (so_name, solib->so_name))
4529 b->enable_state = bp_shlib_disabled;
4530 /* At this point, we cannot rely on remove_breakpoint
4531 succeeding so we must mark the breakpoint as not inserted
4532 to prevent future errors occurring in remove_breakpoints. */
4533 b->loc->inserted = 0;
4534 if (!disabled_shlib_breaks)
4536 target_terminal_ours_for_output ();
4537 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4540 disabled_shlib_breaks = 1;
4546 /* Try to reenable any breakpoints in shared libraries. */
4548 re_enable_breakpoints_in_shlibs (void)
4550 struct breakpoint *b, *tmp;
4552 ALL_BREAKPOINTS_SAFE (b, tmp)
4554 if (b->enable_state == bp_shlib_disabled)
4559 /* Do not reenable the breakpoint if the shared library is
4560 still not mapped in. */
4562 lib = PC_SOLIB (b->loc->address);
4564 lib = solib_address (b->loc->address);
4566 if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
4567 b->enable_state = bp_enabled;
4569 else if (b->pending && (b->enable_state == bp_enabled))
4571 if (resolve_pending_breakpoint (b) == GDB_RC_OK)
4572 delete_breakpoint (b);
4578 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4579 char *cond_string, enum bptype bp_kind)
4581 struct breakpoint *b;
4582 struct symtabs_and_lines sals;
4583 struct cleanup *old_chain;
4584 struct cleanup *canonical_strings_chain = NULL;
4585 char *addr_start = hookname;
4586 char *addr_end = NULL;
4587 char **canonical = (char **) NULL;
4588 int thread = -1; /* All threads. */
4590 /* Set a breakpoint on the specified hook. */
4591 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL,
4592 0, &canonical, NULL);
4593 addr_end = hookname;
4595 if (sals.nelts == 0)
4597 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4598 "Suggest linking with /opt/langtools/lib/end.o.\n"
4599 "GDB will be unable to track shl_load/shl_unload calls."));
4602 if (sals.nelts != 1)
4604 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4605 "GDB will be unable to track shl_load/shl_unload calls."));
4609 /* Make sure that all storage allocated in decode_line_1 gets freed
4610 in case the following errors out. */
4611 old_chain = make_cleanup (xfree, sals.sals);
4612 if (canonical != (char **) NULL)
4614 make_cleanup (xfree, canonical);
4615 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4616 if (canonical[0] != NULL)
4617 make_cleanup (xfree, canonical[0]);
4620 resolve_sal_pc (&sals.sals[0]);
4622 /* Remove the canonical strings from the cleanup, they are needed below. */
4623 if (canonical != (char **) NULL)
4624 discard_cleanups (canonical_strings_chain);
4626 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4627 set_breakpoint_count (breakpoint_count + 1);
4628 b->number = breakpoint_count;
4630 b->cond_string = (cond_string == NULL) ?
4631 NULL : savestring (cond_string, strlen (cond_string));
4634 if (canonical != (char **) NULL && canonical[0] != NULL)
4635 b->addr_string = canonical[0];
4636 else if (addr_start)
4637 b->addr_string = savestring (addr_start, addr_end - addr_start);
4639 b->enable_state = bp_enabled;
4640 b->disposition = tempflag ? disp_del : disp_donttouch;
4642 if (dll_pathname == NULL)
4643 b->dll_pathname = NULL;
4646 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4647 strcpy (b->dll_pathname, dll_pathname);
4651 do_cleanups (old_chain);
4655 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4656 char *dll_pathname, char *cond_string)
4658 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4659 cond_string, bp_catch_load);
4663 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4664 char *dll_pathname, char *cond_string)
4666 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4667 cond_string, bp_catch_unload);
4671 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4672 enum bptype bp_kind)
4674 struct symtab_and_line sal;
4675 struct breakpoint *b;
4676 int thread = -1; /* All threads. */
4683 b = set_raw_breakpoint (sal, bp_kind);
4684 set_breakpoint_count (breakpoint_count + 1);
4685 b->number = breakpoint_count;
4687 b->cond_string = (cond_string == NULL) ?
4688 NULL : savestring (cond_string, strlen (cond_string));
4690 b->addr_string = NULL;
4691 b->enable_state = bp_enabled;
4692 b->disposition = tempflag ? disp_del : disp_donttouch;
4693 b->forked_inferior_pid = 0;
4699 create_fork_event_catchpoint (int tempflag, char *cond_string)
4701 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4705 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4707 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4711 create_exec_event_catchpoint (int tempflag, char *cond_string)
4713 struct symtab_and_line sal;
4714 struct breakpoint *b;
4715 int thread = -1; /* All threads. */
4722 b = set_raw_breakpoint (sal, bp_catch_exec);
4723 set_breakpoint_count (breakpoint_count + 1);
4724 b->number = breakpoint_count;
4726 b->cond_string = (cond_string == NULL) ?
4727 NULL : savestring (cond_string, strlen (cond_string));
4729 b->addr_string = NULL;
4730 b->enable_state = bp_enabled;
4731 b->disposition = tempflag ? disp_del : disp_donttouch;
4737 hw_breakpoint_used_count (void)
4739 struct breakpoint *b;
4744 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4752 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4754 struct breakpoint *b;
4757 *other_type_used = 0;
4760 if (breakpoint_enabled (b))
4762 if (b->type == type)
4764 else if ((b->type == bp_hardware_watchpoint ||
4765 b->type == bp_read_watchpoint ||
4766 b->type == bp_access_watchpoint))
4767 *other_type_used = 1;
4773 /* Call this after hitting the longjmp() breakpoint. Use this to set
4774 a new breakpoint at the target of the jmp_buf.
4776 FIXME - This ought to be done by setting a temporary breakpoint
4777 that gets deleted automatically... */
4780 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4782 struct breakpoint *b;
4785 if (b->type == bp_longjmp_resume)
4787 b->loc->requested_address = pc;
4788 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4790 b->enable_state = bp_enabled;
4791 b->frame_id = frame_id;
4792 check_duplicates (b);
4798 disable_watchpoints_before_interactive_call_start (void)
4800 struct breakpoint *b;
4804 if (((b->type == bp_watchpoint)
4805 || (b->type == bp_hardware_watchpoint)
4806 || (b->type == bp_read_watchpoint)
4807 || (b->type == bp_access_watchpoint)
4808 || ep_is_exception_catchpoint (b))
4809 && breakpoint_enabled (b))
4811 b->enable_state = bp_call_disabled;
4812 check_duplicates (b);
4818 enable_watchpoints_after_interactive_call_stop (void)
4820 struct breakpoint *b;
4824 if (((b->type == bp_watchpoint)
4825 || (b->type == bp_hardware_watchpoint)
4826 || (b->type == bp_read_watchpoint)
4827 || (b->type == bp_access_watchpoint)
4828 || ep_is_exception_catchpoint (b))
4829 && (b->enable_state == bp_call_disabled))
4831 b->enable_state = bp_enabled;
4832 check_duplicates (b);
4838 /* Set a breakpoint that will evaporate an end of command
4839 at address specified by SAL.
4840 Restrict it to frame FRAME if FRAME is nonzero. */
4843 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4846 struct breakpoint *b;
4847 b = set_raw_breakpoint (sal, type);
4848 b->enable_state = bp_enabled;
4849 b->disposition = disp_donttouch;
4850 b->frame_id = frame_id;
4852 /* If we're debugging a multi-threaded program, then we
4853 want momentary breakpoints to be active in only a
4854 single thread of control. */
4855 if (in_thread_list (inferior_ptid))
4856 b->thread = pid_to_thread_id (inferior_ptid);
4862 /* Tell the user we have just set a breakpoint B. */
4865 mention (struct breakpoint *b)
4868 struct cleanup *old_chain, *ui_out_chain;
4869 struct ui_stream *stb;
4871 stb = ui_out_stream_new (uiout);
4872 old_chain = make_cleanup_ui_out_stream_delete (stb);
4874 /* FIXME: This is misplaced; mention() is called by things (like
4875 hitting a watchpoint) other than breakpoint creation. It should
4876 be possible to clean this up and at the same time replace the
4877 random calls to breakpoint_changed with this hook, as has already
4878 been done for deprecated_delete_breakpoint_hook and so on. */
4879 if (deprecated_create_breakpoint_hook)
4880 deprecated_create_breakpoint_hook (b);
4881 breakpoint_create_event (b->number);
4883 if (b->ops != NULL && b->ops->print_mention != NULL)
4884 b->ops->print_mention (b);
4889 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4892 ui_out_text (uiout, "Watchpoint ");
4893 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4894 ui_out_field_int (uiout, "number", b->number);
4895 ui_out_text (uiout, ": ");
4896 print_expression (b->exp, stb->stream);
4897 ui_out_field_stream (uiout, "exp", stb);
4898 do_cleanups (ui_out_chain);
4900 case bp_hardware_watchpoint:
4901 ui_out_text (uiout, "Hardware watchpoint ");
4902 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4903 ui_out_field_int (uiout, "number", b->number);
4904 ui_out_text (uiout, ": ");
4905 print_expression (b->exp, stb->stream);
4906 ui_out_field_stream (uiout, "exp", stb);
4907 do_cleanups (ui_out_chain);
4909 case bp_read_watchpoint:
4910 ui_out_text (uiout, "Hardware read watchpoint ");
4911 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4912 ui_out_field_int (uiout, "number", b->number);
4913 ui_out_text (uiout, ": ");
4914 print_expression (b->exp, stb->stream);
4915 ui_out_field_stream (uiout, "exp", stb);
4916 do_cleanups (ui_out_chain);
4918 case bp_access_watchpoint:
4919 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4920 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4921 ui_out_field_int (uiout, "number", b->number);
4922 ui_out_text (uiout, ": ");
4923 print_expression (b->exp, stb->stream);
4924 ui_out_field_stream (uiout, "exp", stb);
4925 do_cleanups (ui_out_chain);
4928 if (ui_out_is_mi_like_p (uiout))
4933 printf_filtered (_("Breakpoint %d"), b->number);
4936 case bp_hardware_breakpoint:
4937 if (ui_out_is_mi_like_p (uiout))
4942 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4946 case bp_catch_unload:
4947 printf_filtered (_("Catchpoint %d (%s %s)"),
4949 (b->type == bp_catch_load) ? "load" : "unload",
4950 (b->dll_pathname != NULL) ?
4951 b->dll_pathname : "<any library>");
4954 case bp_catch_vfork:
4955 printf_filtered (_("Catchpoint %d (%s)"),
4957 (b->type == bp_catch_fork) ? "fork" : "vfork");
4960 printf_filtered (_("Catchpoint %d (exec)"),
4963 case bp_catch_catch:
4964 case bp_catch_throw:
4965 printf_filtered (_("Catchpoint %d (%s)"),
4967 (b->type == bp_catch_catch) ? "catch" : "throw");
4973 case bp_longjmp_resume:
4974 case bp_step_resume:
4976 case bp_watchpoint_scope:
4977 case bp_shlib_event:
4978 case bp_thread_event:
4979 case bp_overlay_event:
4985 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4989 printf_filtered (_(" (%s) pending."), b->addr_string);
4993 if (addressprint || b->source_file == NULL)
4995 printf_filtered (" at ");
4996 deprecated_print_address_numeric (b->loc->address, 1, gdb_stdout);
4999 printf_filtered (": file %s, line %d.",
5000 b->source_file, b->line_number);
5003 do_cleanups (old_chain);
5004 if (ui_out_is_mi_like_p (uiout))
5006 printf_filtered ("\n");
5010 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5011 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
5012 COND[i] and COND_STRING[i] values.
5014 The parameter PENDING_BP points to a pending breakpoint that is
5015 the basis of the breakpoints currently being created. The pending
5016 breakpoint may contain a separate condition string or commands
5017 that were added after the initial pending breakpoint was created.
5019 NOTE: If the function succeeds, the caller is expected to cleanup
5020 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
5021 array contents). If the function fails (error() is called), the
5022 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5023 COND and SALS arrays and each of those arrays contents. */
5026 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5027 struct expression **cond, char **cond_string,
5028 enum bptype type, enum bpdisp disposition,
5029 int thread, int ignore_count, int from_tty,
5030 struct breakpoint *pending_bp)
5032 if (type == bp_hardware_breakpoint)
5034 int i = hw_breakpoint_used_count ();
5035 int target_resources_ok =
5036 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5038 if (target_resources_ok == 0)
5039 error (_("No hardware breakpoint support in the target."));
5040 else if (target_resources_ok < 0)
5041 error (_("Hardware breakpoints used exceeds limit."));
5044 /* Now set all the breakpoints. */
5047 for (i = 0; i < sals.nelts; i++)
5049 struct breakpoint *b;
5050 struct symtab_and_line sal = sals.sals[i];
5053 describe_other_breakpoints (sal.pc, sal.section, thread);
5055 b = set_raw_breakpoint (sal, type);
5056 set_breakpoint_count (breakpoint_count + 1);
5057 b->number = breakpoint_count;
5061 b->addr_string = addr_string[i];
5063 /* addr_string has to be used or breakpoint_re_set will delete
5065 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5066 b->cond_string = cond_string[i];
5067 b->ignore_count = ignore_count;
5068 b->enable_state = bp_enabled;
5069 b->disposition = disposition;
5070 /* If resolving a pending breakpoint, a check must be made to see if
5071 the user has specified a new condition or commands for the
5072 breakpoint. A new condition will override any condition that was
5073 initially specified with the initial breakpoint command. */
5077 if (pending_bp->cond_string)
5079 arg = pending_bp->cond_string;
5080 b->cond_string = savestring (arg, strlen (arg));
5081 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
5083 error (_("Junk at end of pending breakpoint condition expression"));
5085 /* If there are commands associated with the breakpoint, they should
5087 if (pending_bp->commands)
5088 b->commands = copy_command_lines (pending_bp->commands);
5090 /* We have to copy over the ignore_count and thread as well. */
5091 b->ignore_count = pending_bp->ignore_count;
5092 b->thread = pending_bp->thread;
5099 /* Parse ARG which is assumed to be a SAL specification possibly
5100 followed by conditionals. On return, SALS contains an array of SAL
5101 addresses found. ADDR_STRING contains a vector of (canonical)
5102 address strings. ARG points to the end of the SAL. */
5105 parse_breakpoint_sals (char **address,
5106 struct symtabs_and_lines *sals,
5107 char ***addr_string,
5110 char *addr_start = *address;
5111 *addr_string = NULL;
5112 /* If no arg given, or if first arg is 'if ', use the default
5114 if ((*address) == NULL
5115 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5117 if (default_breakpoint_valid)
5119 struct symtab_and_line sal;
5120 init_sal (&sal); /* initialize to zeroes */
5121 sals->sals = (struct symtab_and_line *)
5122 xmalloc (sizeof (struct symtab_and_line));
5123 sal.pc = default_breakpoint_address;
5124 sal.line = default_breakpoint_line;
5125 sal.symtab = default_breakpoint_symtab;
5126 sal.section = find_pc_overlay (sal.pc);
5127 sals->sals[0] = sal;
5131 error (_("No default breakpoint address now."));
5135 /* Force almost all breakpoints to be in terms of the
5136 current_source_symtab (which is decode_line_1's default). This
5137 should produce the results we want almost all of the time while
5138 leaving default_breakpoint_* alone.
5139 ObjC: However, don't match an Objective-C method name which
5140 may have a '+' or '-' succeeded by a '[' */
5142 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5144 if (default_breakpoint_valid
5146 || ((strchr ("+-", (*address)[0]) != NULL)
5147 && ((*address)[1] != '['))))
5148 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5149 default_breakpoint_line, addr_string,
5152 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5153 addr_string, not_found_ptr);
5155 /* For any SAL that didn't have a canonical string, fill one in. */
5156 if (sals->nelts > 0 && *addr_string == NULL)
5157 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5158 if (addr_start != (*address))
5161 for (i = 0; i < sals->nelts; i++)
5163 /* Add the string if not present. */
5164 if ((*addr_string)[i] == NULL)
5165 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5171 /* Convert each SAL into a real PC. Verify that the PC can be
5172 inserted as a breakpoint. If it can't throw an error. */
5175 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5179 for (i = 0; i < sals->nelts; i++)
5181 resolve_sal_pc (&sals->sals[i]);
5183 /* It's possible for the PC to be nonzero, but still an illegal
5184 value on some targets.
5186 For example, on HP-UX if you start gdb, and before running the
5187 inferior you try to set a breakpoint on a shared library function
5188 "foo" where the inferior doesn't call "foo" directly but does
5189 pass its address to another function call, then we do find a
5190 minimal symbol for the "foo", but it's address is invalid.
5191 (Appears to be an index into a table that the loader sets up
5192 when the inferior is run.)
5194 Give the target a chance to bless sals.sals[i].pc before we
5195 try to make a breakpoint for it. */
5196 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5197 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5199 if (address == NULL)
5200 error (_("Cannot break without a running program."));
5202 error (_("Cannot break on %s without a running program."),
5210 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5212 struct captured_parse_breakpoint_args *args = data;
5214 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5215 args->not_found_ptr);
5218 /* Set a breakpoint according to ARG (function, linenum or *address)
5219 flag: first bit : 0 non-temporary, 1 temporary.
5220 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5222 PENDING_BP is non-NULL when this function is being called to resolve
5223 a pending breakpoint. */
5226 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5228 struct gdb_exception e;
5229 int tempflag, hardwareflag;
5230 struct symtabs_and_lines sals;
5231 struct expression **cond = 0;
5232 struct symtab_and_line pending_sal;
5233 char **cond_string = (char **) NULL;
5236 char *addr_start = arg;
5238 struct cleanup *old_chain;
5239 struct cleanup *breakpoint_chain = NULL;
5240 struct captured_parse_breakpoint_args parse_args;
5244 int ignore_count = 0;
5247 hardwareflag = flag & BP_HARDWAREFLAG;
5248 tempflag = flag & BP_TEMPFLAG;
5254 parse_args.arg_p = &arg;
5255 parse_args.sals_p = &sals;
5256 parse_args.addr_string_p = &addr_string;
5257 parse_args.not_found_ptr = ¬_found;
5259 e = catch_exception (uiout, do_captured_parse_breakpoint,
5260 &parse_args, RETURN_MASK_ALL);
5262 /* If caller is interested in rc value from parse, set value. */
5266 exception_print (gdb_stderr, e);
5271 case NOT_FOUND_ERROR:
5272 /* If called to resolve pending breakpoint, just return
5277 exception_print (gdb_stderr, e);
5279 /* If pending breakpoint support is turned off, throw
5282 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5283 deprecated_throw_reason (RETURN_ERROR);
5285 /* If pending breakpoint support is auto query and the user
5286 selects no, then simply return the error code. */
5287 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5288 !nquery ("Make breakpoint pending on future shared library load? "))
5291 /* At this point, either the user was queried about setting
5292 a pending breakpoint and selected yes, or pending
5293 breakpoint behavior is on and thus a pending breakpoint
5294 is defaulted on behalf of the user. */
5295 copy_arg = xstrdup (addr_start);
5296 addr_string = ©_arg;
5298 sals.sals = &pending_sal;
5303 exception_print (gdb_stderr, e);
5311 /* Create a chain of things that always need to be cleaned up. */
5312 old_chain = make_cleanup (null_cleanup, 0);
5316 /* Make sure that all storage allocated to SALS gets freed. */
5317 make_cleanup (xfree, sals.sals);
5319 /* Cleanup the addr_string array but not its contents. */
5320 make_cleanup (xfree, addr_string);
5323 /* Allocate space for all the cond expressions. */
5324 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5325 make_cleanup (xfree, cond);
5327 /* Allocate space for all the cond strings. */
5328 cond_string = xcalloc (sals.nelts, sizeof (char **));
5329 make_cleanup (xfree, cond_string);
5331 /* ----------------------------- SNIP -----------------------------
5332 Anything added to the cleanup chain beyond this point is assumed
5333 to be part of a breakpoint. If the breakpoint create succeeds
5334 then the memory is not reclaimed. */
5335 breakpoint_chain = make_cleanup (null_cleanup, 0);
5337 /* Mark the contents of the addr_string for cleanup. These go on
5338 the breakpoint_chain and only occure if the breakpoint create
5340 for (i = 0; i < sals.nelts; i++)
5342 if (addr_string[i] != NULL)
5343 make_cleanup (xfree, addr_string[i]);
5346 /* Resolve all line numbers to PC's and verify that the addresses
5347 are ok for the target. */
5349 breakpoint_sals_to_pc (&sals, addr_start);
5351 /* Verify that condition can be parsed, before setting any
5352 breakpoints. Allocate a separate condition expression for each
5354 thread = -1; /* No specific thread yet */
5357 for (i = 0; i < sals.nelts; i++)
5364 char *cond_start = NULL;
5365 char *cond_end = NULL;
5366 while (*tok == ' ' || *tok == '\t')
5371 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5374 toklen = end_tok - tok;
5376 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5378 tok = cond_start = end_tok + 1;
5379 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc),
5381 make_cleanup (xfree, cond[i]);
5383 cond_string[i] = savestring (cond_start,
5384 cond_end - cond_start);
5385 make_cleanup (xfree, cond_string[i]);
5387 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5393 thread = strtol (tok, &tok, 0);
5395 error (_("Junk after thread keyword."));
5396 if (!valid_thread_id (thread))
5397 error (_("Unknown thread %d."), thread);
5400 error (_("Junk at end of arguments."));
5403 create_breakpoints (sals, addr_string, cond, cond_string,
5404 hardwareflag ? bp_hardware_breakpoint
5406 tempflag ? disp_del : disp_donttouch,
5407 thread, ignore_count, from_tty,
5412 struct symtab_and_line sal;
5413 struct breakpoint *b;
5418 make_cleanup (xfree, copy_arg);
5420 b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint
5422 set_breakpoint_count (breakpoint_count + 1);
5423 b->number = breakpoint_count;
5426 b->addr_string = *addr_string;
5427 b->cond_string = *cond_string;
5428 b->ignore_count = ignore_count;
5430 b->disposition = tempflag ? disp_del : disp_donttouch;
5431 b->from_tty = from_tty;
5437 warning (_("Multiple breakpoints were set.\n"
5438 "Use the \"delete\" command to delete unwanted breakpoints."));
5439 /* That's it. Discard the cleanups for data inserted into the
5441 discard_cleanups (breakpoint_chain);
5442 /* But cleanup everything else. */
5443 do_cleanups (old_chain);
5448 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5449 linenum or *address) with COND and IGNORE_COUNT. */
5451 struct captured_breakpoint_args
5462 do_captured_breakpoint (struct ui_out *uiout, void *data)
5464 struct captured_breakpoint_args *args = data;
5465 struct symtabs_and_lines sals;
5466 struct expression **cond;
5467 struct cleanup *old_chain;
5468 struct cleanup *breakpoint_chain = NULL;
5475 /* Parse the source and lines spec. Delay check that the expression
5476 didn't contain trailing garbage until after cleanups are in
5480 address_end = args->address;
5482 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5487 /* Create a chain of things at always need to be cleaned up. */
5488 old_chain = make_cleanup (null_cleanup, 0);
5490 /* Always have a addr_string array, even if it is empty. */
5491 make_cleanup (xfree, addr_string);
5493 /* Make sure that all storage allocated to SALS gets freed. */
5494 make_cleanup (xfree, sals.sals);
5496 /* Allocate space for all the cond expressions. */
5497 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5498 make_cleanup (xfree, cond);
5500 /* Allocate space for all the cond strings. */
5501 cond_string = xcalloc (sals.nelts, sizeof (char **));
5502 make_cleanup (xfree, cond_string);
5504 /* ----------------------------- SNIP -----------------------------
5505 Anything added to the cleanup chain beyond this point is assumed
5506 to be part of a breakpoint. If the breakpoint create goes
5507 through then that memory is not cleaned up. */
5508 breakpoint_chain = make_cleanup (null_cleanup, 0);
5510 /* Mark the contents of the addr_string for cleanup. These go on
5511 the breakpoint_chain and only occure if the breakpoint create
5513 for (i = 0; i < sals.nelts; i++)
5515 if (addr_string[i] != NULL)
5516 make_cleanup (xfree, addr_string[i]);
5519 /* Wait until now before checking for garbage at the end of the
5520 address. That way cleanups can take care of freeing any
5522 if (*address_end != '\0')
5523 error (_("Garbage %s following breakpoint address"), address_end);
5525 /* Resolve all line numbers to PC's. */
5526 breakpoint_sals_to_pc (&sals, args->address);
5528 /* Verify that conditions can be parsed, before setting any
5530 for (i = 0; i < sals.nelts; i++)
5532 if (args->condition != NULL)
5534 char *tok = args->condition;
5535 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5537 error (_("Garbage %s follows condition"), tok);
5538 make_cleanup (xfree, cond[i]);
5539 cond_string[i] = xstrdup (args->condition);
5543 create_breakpoints (sals, addr_string, cond, cond_string,
5544 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5545 args->tempflag ? disp_del : disp_donttouch,
5546 args->thread, args->ignore_count, 0/*from-tty*/,
5547 NULL/*pending_bp*/);
5549 /* That's it. Discard the cleanups for data inserted into the
5551 discard_cleanups (breakpoint_chain);
5552 /* But cleanup everything else. */
5553 do_cleanups (old_chain);
5558 gdb_breakpoint (char *address, char *condition,
5559 int hardwareflag, int tempflag,
5560 int thread, int ignore_count,
5561 char **error_message)
5563 struct captured_breakpoint_args args;
5564 args.address = address;
5565 args.condition = condition;
5566 args.hardwareflag = hardwareflag;
5567 args.tempflag = tempflag;
5568 args.thread = thread;
5569 args.ignore_count = ignore_count;
5570 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5571 error_message, RETURN_MASK_ALL) < 0)
5578 /* Helper function for break_command_1 and disassemble_command. */
5581 resolve_sal_pc (struct symtab_and_line *sal)
5585 if (sal->pc == 0 && sal->symtab != NULL)
5587 if (!find_line_pc (sal->symtab, sal->line, &pc))
5588 error (_("No line %d in file \"%s\"."),
5589 sal->line, sal->symtab->filename);
5593 if (sal->section == 0 && sal->symtab != NULL)
5595 struct blockvector *bv;
5600 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5603 b = BLOCKVECTOR_BLOCK (bv, index);
5604 sym = block_function (b);
5607 fixup_symbol_section (sym, sal->symtab->objfile);
5608 sal->section = SYMBOL_BFD_SECTION (sym);
5612 /* It really is worthwhile to have the section, so we'll just
5613 have to look harder. This case can be executed if we have
5614 line numbers but no functions (as can happen in assembly
5617 struct minimal_symbol *msym;
5619 msym = lookup_minimal_symbol_by_pc (sal->pc);
5621 sal->section = SYMBOL_BFD_SECTION (msym);
5628 break_command (char *arg, int from_tty)
5630 break_command_1 (arg, 0, from_tty, NULL);
5634 tbreak_command (char *arg, int from_tty)
5636 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5640 hbreak_command (char *arg, int from_tty)
5642 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5646 thbreak_command (char *arg, int from_tty)
5648 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5652 stop_command (char *arg, int from_tty)
5654 printf_filtered (_("Specify the type of breakpoint to set.\n\
5655 Usage: stop in <function | address>\n\
5656 stop at <line>\n"));
5660 stopin_command (char *arg, int from_tty)
5664 if (arg == (char *) NULL)
5666 else if (*arg != '*')
5671 /* look for a ':'. If this is a line number specification, then
5672 say it is bad, otherwise, it should be an address or
5673 function/method name */
5674 while (*argptr && !hasColon)
5676 hasColon = (*argptr == ':');
5681 badInput = (*argptr != ':'); /* Not a class::method */
5683 badInput = isdigit (*arg); /* a simple line number */
5687 printf_filtered (_("Usage: stop in <function | address>\n"));
5689 break_command_1 (arg, 0, from_tty, NULL);
5693 stopat_command (char *arg, int from_tty)
5697 if (arg == (char *) NULL || *arg == '*') /* no line number */
5704 /* look for a ':'. If there is a '::' then get out, otherwise
5705 it is probably a line number. */
5706 while (*argptr && !hasColon)
5708 hasColon = (*argptr == ':');
5713 badInput = (*argptr == ':'); /* we have class::method */
5715 badInput = !isdigit (*arg); /* not a line number */
5719 printf_filtered (_("Usage: stop at <line>\n"));
5721 break_command_1 (arg, 0, from_tty, NULL);
5724 /* accessflag: hw_write: watch write,
5725 hw_read: watch read,
5726 hw_access: watch access (read or write) */
5728 watch_command_1 (char *arg, int accessflag, int from_tty)
5730 struct breakpoint *b;
5731 struct symtab_and_line sal;
5732 struct expression *exp;
5733 struct block *exp_valid_block;
5734 struct value *val, *mark;
5735 struct frame_info *frame;
5736 struct frame_info *prev_frame = NULL;
5737 char *exp_start = NULL;
5738 char *exp_end = NULL;
5739 char *tok, *end_tok;
5741 char *cond_start = NULL;
5742 char *cond_end = NULL;
5743 struct expression *cond = NULL;
5744 int i, other_type_used, target_resources_ok = 0;
5745 enum bptype bp_type;
5748 init_sal (&sal); /* initialize to zeroes */
5750 /* Parse arguments. */
5751 innermost_block = NULL;
5753 exp = parse_exp_1 (&arg, 0, 0);
5755 exp_valid_block = innermost_block;
5756 mark = value_mark ();
5757 val = evaluate_expression (exp);
5758 release_value (val);
5759 if (value_lazy (val))
5760 value_fetch_lazy (val);
5763 while (*tok == ' ' || *tok == '\t')
5767 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5770 toklen = end_tok - tok;
5771 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5773 tok = cond_start = end_tok + 1;
5774 cond = parse_exp_1 (&tok, 0, 0);
5778 error (_("Junk at end of command."));
5780 if (accessflag == hw_read)
5781 bp_type = bp_read_watchpoint;
5782 else if (accessflag == hw_access)
5783 bp_type = bp_access_watchpoint;
5785 bp_type = bp_hardware_watchpoint;
5787 mem_cnt = can_use_hardware_watchpoint (val);
5788 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5789 error (_("Expression cannot be implemented with read/access watchpoint."));
5792 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5793 target_resources_ok =
5794 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5796 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5797 error (_("Target does not support this type of hardware watchpoint."));
5799 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5800 error (_("Target can only support one kind of HW watchpoint at a time."));
5803 #if defined(HPUXHPPA)
5804 /* On HP-UX if you set a h/w
5805 watchpoint before the "run" command, the inferior dies with a e.g.,
5806 SIGILL once you start it. I initially believed this was due to a
5807 bad interaction between page protection traps and the initial
5808 startup sequence by the dynamic linker.
5810 However, I tried avoiding that by having HP-UX's implementation of
5811 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5812 yet, which forced slow watches before a "run" or "attach", and it
5813 still fails somewhere in the startup code.
5815 Until I figure out what's happening, I'm disallowing watches altogether
5816 before the "run" or "attach" command. We'll tell the user they must
5817 set watches after getting the program started. */
5818 if (!target_has_execution)
5820 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5823 #endif /* HPUXHPPA */
5825 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5826 watchpoint could not be set. */
5827 if (!mem_cnt || target_resources_ok <= 0)
5828 bp_type = bp_watchpoint;
5830 /* Now set up the breakpoint. */
5831 b = set_raw_breakpoint (sal, bp_type);
5832 set_breakpoint_count (breakpoint_count + 1);
5833 b->number = breakpoint_count;
5834 b->disposition = disp_donttouch;
5836 b->exp_valid_block = exp_valid_block;
5837 b->exp_string = savestring (exp_start, exp_end - exp_start);
5841 b->cond_string = savestring (cond_start, cond_end - cond_start);
5845 frame = block_innermost_frame (exp_valid_block);
5848 prev_frame = get_prev_frame (frame);
5849 b->watchpoint_frame = get_frame_id (frame);
5853 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5856 /* If the expression is "local", then set up a "watchpoint scope"
5857 breakpoint at the point where we've left the scope of the watchpoint
5859 if (innermost_block)
5863 struct breakpoint *scope_breakpoint;
5864 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5865 bp_watchpoint_scope);
5867 scope_breakpoint->enable_state = bp_enabled;
5869 /* Automatically delete the breakpoint when it hits. */
5870 scope_breakpoint->disposition = disp_del;
5872 /* Only break in the proper frame (help with recursion). */
5873 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5875 /* Set the address at which we will stop. */
5876 scope_breakpoint->loc->requested_address
5877 = get_frame_pc (prev_frame);
5878 scope_breakpoint->loc->address
5879 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5880 scope_breakpoint->type);
5882 /* The scope breakpoint is related to the watchpoint. We
5883 will need to act on them together. */
5884 b->related_breakpoint = scope_breakpoint;
5887 value_free_to_mark (mark);
5891 /* Return count of locations need to be watched and can be handled
5892 in hardware. If the watchpoint can not be handled
5893 in hardware return zero. */
5896 can_use_hardware_watchpoint (struct value *v)
5898 int found_memory_cnt = 0;
5899 struct value *head = v;
5901 /* Did the user specifically forbid us to use hardware watchpoints? */
5902 if (!can_use_hw_watchpoints)
5905 /* Make sure that the value of the expression depends only upon
5906 memory contents, and values computed from them within GDB. If we
5907 find any register references or function calls, we can't use a
5908 hardware watchpoint.
5910 The idea here is that evaluating an expression generates a series
5911 of values, one holding the value of every subexpression. (The
5912 expression a*b+c has five subexpressions: a, b, a*b, c, and
5913 a*b+c.) GDB's values hold almost enough information to establish
5914 the criteria given above --- they identify memory lvalues,
5915 register lvalues, computed values, etcetera. So we can evaluate
5916 the expression, and then scan the chain of values that leaves
5917 behind to decide whether we can detect any possible change to the
5918 expression's final value using only hardware watchpoints.
5920 However, I don't think that the values returned by inferior
5921 function calls are special in any way. So this function may not
5922 notice that an expression involving an inferior function call
5923 can't be watched with hardware watchpoints. FIXME. */
5924 for (; v; v = value_next (v))
5926 if (VALUE_LVAL (v) == lval_memory)
5929 /* A lazy memory lvalue is one that GDB never needed to fetch;
5930 we either just used its address (e.g., `a' in `a.b') or
5931 we never needed it at all (e.g., `a' in `a,b'). */
5935 /* Ahh, memory we actually used! Check if we can cover
5936 it with hardware watchpoints. */
5937 struct type *vtype = check_typedef (value_type (v));
5939 /* We only watch structs and arrays if user asked for it
5940 explicitly, never if they just happen to appear in a
5941 middle of some value chain. */
5943 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5944 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5946 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
5947 int len = TYPE_LENGTH (value_type (v));
5949 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5956 else if (VALUE_LVAL (v) != not_lval
5957 && deprecated_value_modifiable (v) == 0)
5958 return 0; /* ??? What does this represent? */
5959 else if (VALUE_LVAL (v) == lval_register)
5960 return 0; /* cannot watch a register with a HW watchpoint */
5963 /* The expression itself looks suitable for using a hardware
5964 watchpoint, but give the target machine a chance to reject it. */
5965 return found_memory_cnt;
5969 watch_command_wrapper (char *arg, int from_tty)
5971 watch_command (arg, from_tty);
5975 watch_command (char *arg, int from_tty)
5977 watch_command_1 (arg, hw_write, from_tty);
5981 rwatch_command_wrapper (char *arg, int from_tty)
5983 rwatch_command (arg, from_tty);
5987 rwatch_command (char *arg, int from_tty)
5989 watch_command_1 (arg, hw_read, from_tty);
5993 awatch_command_wrapper (char *arg, int from_tty)
5995 awatch_command (arg, from_tty);
5999 awatch_command (char *arg, int from_tty)
6001 watch_command_1 (arg, hw_access, from_tty);
6005 /* Helper routines for the until_command routine in infcmd.c. Here
6006 because it uses the mechanisms of breakpoints. */
6008 /* This function is called by fetch_inferior_event via the
6009 cmd_continuation pointer, to complete the until command. It takes
6010 care of cleaning up the temporary breakpoints set up by the until
6013 until_break_command_continuation (struct continuation_arg *arg)
6015 struct cleanup *cleanups;
6017 cleanups = (struct cleanup *) arg->data.pointer;
6018 do_exec_cleanups (cleanups);
6022 until_break_command (char *arg, int from_tty, int anywhere)
6024 struct symtabs_and_lines sals;
6025 struct symtab_and_line sal;
6026 struct frame_info *frame = get_selected_frame (NULL);
6027 struct frame_info *prev_frame = get_prev_frame (frame);
6028 struct breakpoint *breakpoint;
6029 struct cleanup *old_chain;
6030 struct continuation_arg *arg1;
6033 clear_proceed_status ();
6035 /* Set a breakpoint where the user wants it and at return from
6038 if (default_breakpoint_valid)
6039 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6040 default_breakpoint_line, (char ***) NULL, NULL);
6042 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6043 0, (char ***) NULL, NULL);
6045 if (sals.nelts != 1)
6046 error (_("Couldn't get information on specified line."));
6049 xfree (sals.sals); /* malloc'd, so freed */
6052 error (_("Junk at end of arguments."));
6054 resolve_sal_pc (&sal);
6057 /* If the user told us to continue until a specified location,
6058 we don't specify a frame at which we need to stop. */
6059 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6061 /* Otherwise, specify the current frame, because we want to stop only
6062 at the very same frame. */
6063 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6066 if (!target_can_async_p ())
6067 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6069 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6071 /* If we are running asynchronously, and the target supports async
6072 execution, we are not waiting for the target to stop, in the call
6073 tp proceed, below. This means that we cannot delete the
6074 brekpoints until the target has actually stopped. The only place
6075 where we get a chance to do that is in fetch_inferior_event, so
6076 we must set things up for that. */
6078 if (target_can_async_p ())
6080 /* In this case the arg for the continuation is just the point
6081 in the exec_cleanups chain from where to start doing
6082 cleanups, because all the continuation does is the cleanups in
6083 the exec_cleanup_chain. */
6085 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6087 arg1->data.pointer = old_chain;
6089 add_continuation (until_break_command_continuation, arg1);
6092 /* Keep within the current frame, or in frames called by the current
6096 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6097 sal.pc = get_frame_pc (prev_frame);
6098 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6100 if (!target_can_async_p ())
6101 make_cleanup_delete_breakpoint (breakpoint);
6103 make_exec_cleanup_delete_breakpoint (breakpoint);
6106 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6107 /* Do the cleanups now, anly if we are not running asynchronously,
6108 of if we are, but the target is still synchronous. */
6109 if (!target_can_async_p ())
6110 do_cleanups (old_chain);
6114 ep_skip_leading_whitespace (char **s)
6116 if ((s == NULL) || (*s == NULL))
6118 while (isspace (**s))
6122 /* This function examines a string, and attempts to find a token
6123 that might be an event name in the leading characters. If a
6124 possible match is found, a pointer to the last character of
6125 the token is returned. Else, NULL is returned. */
6128 ep_find_event_name_end (char *arg)
6131 char *event_name_end = NULL;
6133 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6137 /* We break out of the loop when we find a token delimiter.
6138 Basically, we're looking for alphanumerics and underscores;
6139 anything else delimites the token. */
6142 if (!isalnum (*s) && (*s != '_'))
6148 return event_name_end;
6152 /* This function attempts to parse an optional "if <cond>" clause
6153 from the arg string. If one is not found, it returns NULL.
6155 Else, it returns a pointer to the condition string. (It does not
6156 attempt to evaluate the string against a particular block.) And,
6157 it updates arg to point to the first character following the parsed
6158 if clause in the arg string. */
6161 ep_parse_optional_if_clause (char **arg)
6165 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6168 /* Skip the "if" keyword. */
6171 /* Skip any extra leading whitespace, and record the start of the
6172 condition string. */
6173 ep_skip_leading_whitespace (arg);
6176 /* Assume that the condition occupies the remainder of the arg string. */
6177 (*arg) += strlen (cond_string);
6182 /* This function attempts to parse an optional filename from the arg
6183 string. If one is not found, it returns NULL.
6185 Else, it returns a pointer to the parsed filename. (This function
6186 makes no attempt to verify that a file of that name exists, or is
6187 accessible.) And, it updates arg to point to the first character
6188 following the parsed filename in the arg string.
6190 Note that clients needing to preserve the returned filename for
6191 future access should copy it to their own buffers. */
6193 ep_parse_optional_filename (char **arg)
6195 static char filename[1024];
6200 if ((*arg_p == '\0') || isspace (*arg_p))
6218 /* Commands to deal with catching events, such as signals, exceptions,
6219 process start/exit, etc. */
6223 catch_fork, catch_vfork
6228 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6231 char *cond_string = NULL;
6233 ep_skip_leading_whitespace (&arg);
6235 /* The allowed syntax is:
6237 catch [v]fork if <cond>
6239 First, check if there's an if clause. */
6240 cond_string = ep_parse_optional_if_clause (&arg);
6242 if ((*arg != '\0') && !isspace (*arg))
6243 error (_("Junk at end of arguments."));
6245 /* If this target supports it, create a fork or vfork catchpoint
6246 and enable reporting of such events. */
6250 create_fork_event_catchpoint (tempflag, cond_string);
6253 create_vfork_event_catchpoint (tempflag, cond_string);
6256 error (_("unsupported or unknown fork kind; cannot catch it"));
6262 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6264 char *cond_string = NULL;
6266 ep_skip_leading_whitespace (&arg);
6268 /* The allowed syntax is:
6270 catch exec if <cond>
6272 First, check if there's an if clause. */
6273 cond_string = ep_parse_optional_if_clause (&arg);
6275 if ((*arg != '\0') && !isspace (*arg))
6276 error (_("Junk at end of arguments."));
6278 /* If this target supports it, create an exec catchpoint
6279 and enable reporting of such events. */
6280 create_exec_event_catchpoint (tempflag, cond_string);
6284 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6286 char *dll_pathname = NULL;
6287 char *cond_string = NULL;
6289 ep_skip_leading_whitespace (&arg);
6291 /* The allowed syntax is:
6293 catch load if <cond>
6294 catch load <filename>
6295 catch load <filename> if <cond>
6297 The user is not allowed to specify the <filename> after an
6300 We'll ignore the pathological case of a file named "if".
6302 First, check if there's an if clause. If so, then there
6303 cannot be a filename. */
6304 cond_string = ep_parse_optional_if_clause (&arg);
6306 /* If there was an if clause, then there cannot be a filename.
6307 Else, there might be a filename and an if clause. */
6308 if (cond_string == NULL)
6310 dll_pathname = ep_parse_optional_filename (&arg);
6311 ep_skip_leading_whitespace (&arg);
6312 cond_string = ep_parse_optional_if_clause (&arg);
6315 if ((*arg != '\0') && !isspace (*arg))
6316 error (_("Junk at end of arguments."));
6318 /* Create a load breakpoint that only triggers when a load of
6319 the specified dll (or any dll, if no pathname was specified)
6321 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6322 dll_pathname, cond_string);
6326 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6328 char *dll_pathname = NULL;
6329 char *cond_string = NULL;
6331 ep_skip_leading_whitespace (&arg);
6333 /* The allowed syntax is:
6335 catch unload if <cond>
6336 catch unload <filename>
6337 catch unload <filename> if <cond>
6339 The user is not allowed to specify the <filename> after an
6342 We'll ignore the pathological case of a file named "if".
6344 First, check if there's an if clause. If so, then there
6345 cannot be a filename. */
6346 cond_string = ep_parse_optional_if_clause (&arg);
6348 /* If there was an if clause, then there cannot be a filename.
6349 Else, there might be a filename and an if clause. */
6350 if (cond_string == NULL)
6352 dll_pathname = ep_parse_optional_filename (&arg);
6353 ep_skip_leading_whitespace (&arg);
6354 cond_string = ep_parse_optional_if_clause (&arg);
6357 if ((*arg != '\0') && !isspace (*arg))
6358 error (_("Junk at end of arguments."));
6360 /* Create an unload breakpoint that only triggers when an unload of
6361 the specified dll (or any dll, if no pathname was specified)
6363 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6364 dll_pathname, cond_string);
6367 /* Commands to deal with catching exceptions. */
6369 /* Set a breakpoint at the specified callback routine for an
6370 exception event callback */
6373 create_exception_catchpoint (int tempflag, char *cond_string,
6374 enum exception_event_kind ex_event,
6375 struct symtab_and_line *sal)
6377 struct breakpoint *b;
6378 int thread = -1; /* All threads. */
6381 if (!sal) /* no exception support? */
6386 case EX_EVENT_THROW:
6387 bptype = bp_catch_throw;
6389 case EX_EVENT_CATCH:
6390 bptype = bp_catch_catch;
6392 default: /* error condition */
6393 error (_("Internal error -- invalid catchpoint kind"));
6396 b = set_raw_breakpoint (*sal, bptype);
6397 set_breakpoint_count (breakpoint_count + 1);
6398 b->number = breakpoint_count;
6400 b->cond_string = (cond_string == NULL) ?
6401 NULL : savestring (cond_string, strlen (cond_string));
6403 b->addr_string = NULL;
6404 b->enable_state = bp_enabled;
6405 b->disposition = tempflag ? disp_del : disp_donttouch;
6409 static enum print_stop_action
6410 print_exception_catchpoint (struct breakpoint *b)
6412 annotate_catchpoint (b->number);
6414 if (strstr (b->addr_string, "throw") != NULL)
6415 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6418 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6421 return PRINT_SRC_AND_LOC;
6425 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6430 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6433 *last_addr = b->loc->address;
6434 if (strstr (b->addr_string, "throw") != NULL)
6435 ui_out_field_string (uiout, "what", "exception throw");
6437 ui_out_field_string (uiout, "what", "exception catch");
6441 print_mention_exception_catchpoint (struct breakpoint *b)
6443 if (strstr (b->addr_string, "throw") != NULL)
6444 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6446 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6449 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6450 print_exception_catchpoint,
6451 print_one_exception_catchpoint,
6452 print_mention_exception_catchpoint
6456 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6457 enum exception_event_kind ex_event, int from_tty)
6459 char *trigger_func_name, *nameptr;
6460 struct symtabs_and_lines sals;
6461 struct breakpoint *b;
6463 if (ex_event == EX_EVENT_CATCH)
6464 trigger_func_name = xstrdup ("__cxa_begin_catch");
6466 trigger_func_name = xstrdup ("__cxa_throw");
6468 nameptr = trigger_func_name;
6469 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6470 if (sals.nelts == 0)
6472 xfree (trigger_func_name);
6476 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6477 set_breakpoint_count (breakpoint_count + 1);
6478 b->number = breakpoint_count;
6480 b->cond_string = (cond_string == NULL) ?
6481 NULL : savestring (cond_string, strlen (cond_string));
6483 b->addr_string = trigger_func_name;
6484 b->enable_state = bp_enabled;
6485 b->disposition = tempflag ? disp_del : disp_donttouch;
6486 b->ops = &gnu_v3_exception_catchpoint_ops;
6493 /* Deal with "catch catch" and "catch throw" commands */
6496 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6497 int tempflag, int from_tty)
6499 char *cond_string = NULL;
6500 struct symtab_and_line *sal = NULL;
6502 ep_skip_leading_whitespace (&arg);
6504 cond_string = ep_parse_optional_if_clause (&arg);
6506 if ((*arg != '\0') && !isspace (*arg))
6507 error (_("Junk at end of arguments."));
6509 if ((ex_event != EX_EVENT_THROW) &&
6510 (ex_event != EX_EVENT_CATCH))
6511 error (_("Unsupported or unknown exception event; cannot catch it"));
6513 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6516 /* See if we can find a callback routine */
6517 sal = target_enable_exception_callback (ex_event, 1);
6521 /* We have callbacks from the runtime system for exceptions.
6522 Set a breakpoint on the sal found, if no errors */
6523 if (sal != (struct symtab_and_line *) -1)
6524 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6526 return; /* something went wrong with setting up callbacks */
6529 warning (_("Unsupported with this platform/compiler combination."));
6532 /* Create a breakpoint struct for Ada exception catchpoints. */
6535 create_ada_exception_breakpoint (struct symtab_and_line sal,
6539 struct expression *cond,
6540 struct breakpoint_ops *ops,
6544 struct breakpoint *b;
6548 describe_other_breakpoints (sal.pc, sal.section, -1);
6549 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6550 version for exception catchpoints, because two catchpoints
6551 used for different exception names will use the same address.
6552 In this case, a "breakpoint ... also set at..." warning is
6553 unproductive. Besides. the warning phrasing is also a bit
6554 inapropriate, we should use the word catchpoint, and tell
6555 the user what type of catchpoint it is. The above is good
6556 enough for now, though. */
6559 b = set_raw_breakpoint (sal, bp_breakpoint);
6560 set_breakpoint_count (breakpoint_count + 1);
6562 b->enable_state = bp_enabled;
6563 b->disposition = tempflag ? disp_del : disp_donttouch;
6564 b->number = breakpoint_count;
6565 b->ignore_count = 0;
6567 b->addr_string = addr_string;
6568 b->language = language_ada;
6569 b->cond_string = cond_string;
6570 b->exp_string = exp_string;
6573 b->from_tty = from_tty;
6578 /* Implement the "catch exception" command. */
6581 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6583 struct symtab_and_line sal;
6585 char *addr_string = NULL;
6586 char *exp_string = NULL;
6587 char *cond_string = NULL;
6588 struct expression *cond = NULL;
6589 struct breakpoint_ops *ops = NULL;
6591 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6592 &cond_string, &cond, &ops);
6593 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6594 cond_string, cond, ops, tempflag,
6598 /* Implement the "catch assert" command. */
6601 catch_assert_command (char *arg, int tempflag, int from_tty)
6603 struct symtab_and_line sal;
6604 char *addr_string = NULL;
6605 struct breakpoint_ops *ops = NULL;
6607 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6608 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6609 tempflag, from_tty);
6612 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6613 inside a catch_errors */
6616 cover_target_enable_exception_callback (void *arg)
6618 args_for_catchpoint_enable *args = arg;
6619 struct symtab_and_line *sal;
6620 sal = target_enable_exception_callback (args->kind, args->enable_p);
6623 else if (sal == (struct symtab_and_line *) -1)
6626 return 1; /*is valid */
6630 catch_command_1 (char *arg, int tempflag, int from_tty)
6633 /* The first argument may be an event name, such as "start" or "load".
6634 If so, then handle it as such. If it doesn't match an event name,
6635 then attempt to interpret it as an exception name. (This latter is
6636 the v4.16-and-earlier GDB meaning of the "catch" command.)
6638 First, try to find the bounds of what might be an event name. */
6639 char *arg1_start = arg;
6643 if (arg1_start == NULL)
6645 /* Old behaviour was to use pre-v-4.16 syntax */
6646 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6648 /* Now, this is not allowed */
6649 error (_("Catch requires an event name."));
6652 arg1_end = ep_find_event_name_end (arg1_start);
6653 if (arg1_end == NULL)
6654 error (_("catch requires an event"));
6655 arg1_length = arg1_end + 1 - arg1_start;
6657 /* Try to match what we found against known event names. */
6658 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6660 error (_("Catch of signal not yet implemented"));
6662 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6664 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6665 tempflag, from_tty);
6667 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6669 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6670 tempflag, from_tty);
6672 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6674 error (_("Catch of thread_start not yet implemented"));
6676 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6678 error (_("Catch of thread_exit not yet implemented"));
6680 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6682 error (_("Catch of thread_join not yet implemented"));
6684 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6686 error (_("Catch of start not yet implemented"));
6688 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6690 error (_("Catch of exit not yet implemented"));
6692 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6694 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6696 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6698 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6700 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6702 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6704 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6706 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6708 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6710 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6712 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6714 error (_("Catch of stop not yet implemented"));
6716 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6718 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6721 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6723 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6726 /* This doesn't appear to be an event name */
6730 /* Pre-v.4.16 behaviour was to treat the argument
6731 as the name of an exception */
6732 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6733 /* Now this is not allowed */
6734 error (_("Unknown event kind specified for catch"));
6739 /* Used by the gui, could be made a worker for other things. */
6742 set_breakpoint_sal (struct symtab_and_line sal)
6744 struct breakpoint *b;
6745 b = set_raw_breakpoint (sal, bp_breakpoint);
6746 set_breakpoint_count (breakpoint_count + 1);
6747 b->number = breakpoint_count;
6754 catch_command (char *arg, int from_tty)
6756 catch_command_1 (arg, 0, from_tty);
6761 tcatch_command (char *arg, int from_tty)
6763 catch_command_1 (arg, 1, from_tty);
6766 /* Delete breakpoints by address or line. */
6769 clear_command (char *arg, int from_tty)
6771 struct breakpoint *b, *tmp, *prev, *found;
6773 struct symtabs_and_lines sals;
6774 struct symtab_and_line sal;
6779 sals = decode_line_spec (arg, 1);
6784 sals.sals = (struct symtab_and_line *)
6785 xmalloc (sizeof (struct symtab_and_line));
6786 make_cleanup (xfree, sals.sals);
6787 init_sal (&sal); /* initialize to zeroes */
6788 sal.line = default_breakpoint_line;
6789 sal.symtab = default_breakpoint_symtab;
6790 sal.pc = default_breakpoint_address;
6791 if (sal.symtab == 0)
6792 error (_("No source file specified."));
6800 /* For each line spec given, delete bps which correspond
6801 to it. Do it in two passes, solely to preserve the current
6802 behavior that from_tty is forced true if we delete more than
6806 for (i = 0; i < sals.nelts; i++)
6808 /* If exact pc given, clear bpts at that pc.
6809 If line given (pc == 0), clear all bpts on specified line.
6810 If defaulting, clear all bpts on default line
6813 defaulting sal.pc != 0 tests to do
6818 1 0 <can't happen> */
6823 /* Find all matching breakpoints, remove them from the
6824 breakpoint chain, and add them to the 'found' chain. */
6825 ALL_BREAKPOINTS_SAFE (b, tmp)
6827 /* Are we going to delete b? */
6828 if (b->type != bp_none
6829 && b->type != bp_watchpoint
6830 && b->type != bp_hardware_watchpoint
6831 && b->type != bp_read_watchpoint
6832 && b->type != bp_access_watchpoint
6833 /* Not if b is a watchpoint of any sort... */
6834 && (((sal.pc && (b->loc->address == sal.pc))
6835 && (!section_is_overlay (b->loc->section)
6836 || b->loc->section == sal.section))
6837 /* Yes, if sal.pc matches b (modulo overlays). */
6838 || ((default_match || (0 == sal.pc))
6839 && b->source_file != NULL
6840 && sal.symtab != NULL
6841 && strcmp (b->source_file, sal.symtab->filename) == 0
6842 && b->line_number == sal.line)))
6843 /* Yes, if sal source file and line matches b. */
6845 /* Remove it from breakpoint_chain... */
6846 if (b == breakpoint_chain)
6848 /* b is at the head of the list */
6849 breakpoint_chain = b->next;
6853 prev->next = b->next;
6855 /* And add it to 'found' chain. */
6861 /* Keep b, and keep a pointer to it. */
6866 /* Now go thru the 'found' chain and delete them. */
6870 error (_("No breakpoint at %s."), arg);
6872 error (_("No breakpoint at this line."));
6876 from_tty = 1; /* Always report if deleted more than one */
6880 printf_unfiltered (_("Deleted breakpoint "));
6882 printf_unfiltered (_("Deleted breakpoints "));
6884 breakpoints_changed ();
6888 printf_unfiltered ("%d ", found->number);
6890 delete_breakpoint (found);
6894 putchar_unfiltered ('\n');
6897 /* Delete breakpoint in BS if they are `delete' breakpoints and
6898 all breakpoints that are marked for deletion, whether hit or not.
6899 This is called after any breakpoint is hit, or after errors. */
6902 breakpoint_auto_delete (bpstat bs)
6904 struct breakpoint *b, *temp;
6906 for (; bs; bs = bs->next)
6907 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6909 delete_breakpoint (bs->breakpoint_at);
6911 ALL_BREAKPOINTS_SAFE (b, temp)
6913 if (b->disposition == disp_del_at_next_stop)
6914 delete_breakpoint (b);
6918 /* Delete a breakpoint and clean up all traces of it in the data
6922 delete_breakpoint (struct breakpoint *bpt)
6924 struct breakpoint *b;
6926 struct bp_location *loc;
6928 gdb_assert (bpt != NULL);
6930 /* Has this bp already been deleted? This can happen because multiple
6931 lists can hold pointers to bp's. bpstat lists are especial culprits.
6933 One example of this happening is a watchpoint's scope bp. When the
6934 scope bp triggers, we notice that the watchpoint is out of scope, and
6935 delete it. We also delete its scope bp. But the scope bp is marked
6936 "auto-deleting", and is already on a bpstat. That bpstat is then
6937 checked for auto-deleting bp's, which are deleted.
6939 A real solution to this problem might involve reference counts in bp's,
6940 and/or giving them pointers back to their referencing bpstat's, and
6941 teaching delete_breakpoint to only free a bp's storage when no more
6942 references were extent. A cheaper bandaid was chosen. */
6943 if (bpt->type == bp_none)
6946 if (deprecated_delete_breakpoint_hook)
6947 deprecated_delete_breakpoint_hook (bpt);
6948 breakpoint_delete_event (bpt->number);
6950 if (bpt->loc->inserted)
6951 remove_breakpoint (bpt->loc, mark_inserted);
6953 free_valchain (bpt->loc);
6955 if (breakpoint_chain == bpt)
6956 breakpoint_chain = bpt->next;
6958 if (bp_location_chain == bpt->loc)
6959 bp_location_chain = bpt->loc->next;
6961 /* If we have callback-style exception catchpoints, don't go through
6962 the adjustments to the C++ runtime library etc. if the inferior
6963 isn't actually running. target_enable_exception_callback for a
6964 null target ops vector gives an undesirable error message, so we
6965 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6966 exceptions are supported in this way, it's OK for now. FIXME */
6967 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6969 /* Format possible error msg */
6970 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6972 struct cleanup *cleanups = make_cleanup (xfree, message);
6973 args_for_catchpoint_enable args;
6974 args.kind = bpt->type == bp_catch_catch ?
6975 EX_EVENT_CATCH : EX_EVENT_THROW;
6977 catch_errors (cover_target_enable_exception_callback, &args,
6978 message, RETURN_MASK_ALL);
6979 do_cleanups (cleanups);
6986 b->next = bpt->next;
6990 ALL_BP_LOCATIONS (loc)
6991 if (loc->next == bpt->loc)
6993 loc->next = bpt->loc->next;
6997 check_duplicates (bpt);
6998 /* If this breakpoint was inserted, and there is another breakpoint
6999 at the same address, we need to insert the other breakpoint. */
7000 if (bpt->loc->inserted
7001 && bpt->type != bp_hardware_watchpoint
7002 && bpt->type != bp_read_watchpoint
7003 && bpt->type != bp_access_watchpoint
7004 && bpt->type != bp_catch_fork
7005 && bpt->type != bp_catch_vfork
7006 && bpt->type != bp_catch_exec)
7009 if (b->loc->address == bpt->loc->address
7010 && b->loc->section == bpt->loc->section
7011 && !b->loc->duplicate
7012 && b->enable_state != bp_disabled
7013 && b->enable_state != bp_shlib_disabled
7015 && b->enable_state != bp_call_disabled)
7019 /* We should never reach this point if there is a permanent
7020 breakpoint at the same address as the one being deleted.
7021 If there is a permanent breakpoint somewhere, it should
7022 always be the only one inserted. */
7023 if (b->enable_state == bp_permanent)
7024 internal_error (__FILE__, __LINE__,
7025 _("another breakpoint was inserted on top of "
7026 "a permanent breakpoint"));
7028 memset (&b->loc->target_info, 0, sizeof (b->loc->target_info));
7029 b->loc->target_info.placed_address = b->loc->address;
7030 if (b->type == bp_hardware_breakpoint)
7031 val = target_insert_hw_breakpoint (&b->loc->target_info);
7033 val = target_insert_breakpoint (&b->loc->target_info);
7035 /* If there was an error in the insert, print a message, then stop execution. */
7038 struct ui_file *tmp_error_stream = mem_fileopen ();
7039 make_cleanup_ui_file_delete (tmp_error_stream);
7042 if (b->type == bp_hardware_breakpoint)
7044 fprintf_unfiltered (tmp_error_stream,
7045 "Cannot insert hardware breakpoint %d.\n"
7046 "You may have requested too many hardware breakpoints.\n",
7051 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
7052 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
7053 deprecated_print_address_numeric (b->loc->address, 1, tmp_error_stream);
7054 fprintf_filtered (tmp_error_stream, ": %s.\n",
7055 safe_strerror (val));
7058 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
7059 target_terminal_ours_for_output ();
7060 error_stream(tmp_error_stream);
7063 b->loc->inserted = 1;
7067 free_command_lines (&bpt->commands);
7070 if (bpt->cond_string != NULL)
7071 xfree (bpt->cond_string);
7072 if (bpt->addr_string != NULL)
7073 xfree (bpt->addr_string);
7074 if (bpt->exp != NULL)
7076 if (bpt->exp_string != NULL)
7077 xfree (bpt->exp_string);
7078 if (bpt->val != NULL)
7079 value_free (bpt->val);
7080 if (bpt->source_file != NULL)
7081 xfree (bpt->source_file);
7082 if (bpt->dll_pathname != NULL)
7083 xfree (bpt->dll_pathname);
7084 if (bpt->triggered_dll_pathname != NULL)
7085 xfree (bpt->triggered_dll_pathname);
7086 if (bpt->exec_pathname != NULL)
7087 xfree (bpt->exec_pathname);
7089 /* Be sure no bpstat's are pointing at it after it's been freed. */
7090 /* FIXME, how can we find all bpstat's?
7091 We just check stop_bpstat for now. */
7092 for (bs = stop_bpstat; bs; bs = bs->next)
7093 if (bs->breakpoint_at == bpt)
7095 bs->breakpoint_at = NULL;
7097 /* bs->commands will be freed later. */
7099 /* On the chance that someone will soon try again to delete this same
7100 bp, we mark it as deleted before freeing its storage. */
7101 bpt->type = bp_none;
7108 do_delete_breakpoint_cleanup (void *b)
7110 delete_breakpoint (b);
7114 make_cleanup_delete_breakpoint (struct breakpoint *b)
7116 return make_cleanup (do_delete_breakpoint_cleanup, b);
7120 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7122 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7126 delete_command (char *arg, int from_tty)
7128 struct breakpoint *b, *temp;
7134 int breaks_to_delete = 0;
7136 /* Delete all breakpoints if no argument.
7137 Do not delete internal or call-dummy breakpoints, these
7138 have to be deleted with an explicit breakpoint number argument. */
7141 if (b->type != bp_call_dummy &&
7142 b->type != bp_shlib_event &&
7143 b->type != bp_thread_event &&
7144 b->type != bp_overlay_event &&
7147 breaks_to_delete = 1;
7152 /* Ask user only if there are some breakpoints to delete. */
7154 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7156 ALL_BREAKPOINTS_SAFE (b, temp)
7158 if (b->type != bp_call_dummy &&
7159 b->type != bp_shlib_event &&
7160 b->type != bp_thread_event &&
7161 b->type != bp_overlay_event &&
7163 delete_breakpoint (b);
7168 map_breakpoint_numbers (arg, delete_breakpoint);
7171 /* Reset a breakpoint given it's struct breakpoint * BINT.
7172 The value we return ends up being the return value from catch_errors.
7173 Unused in this case. */
7176 breakpoint_re_set_one (void *bint)
7178 /* get past catch_errs */
7179 struct breakpoint *b = (struct breakpoint *) bint;
7183 int *not_found_ptr = NULL;
7184 struct symtabs_and_lines sals;
7186 enum enable_state save_enable;
7191 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7195 case bp_hardware_breakpoint:
7197 case bp_catch_unload:
7198 if (b->addr_string == NULL)
7200 /* Anything without a string can't be re-set. */
7201 delete_breakpoint (b);
7204 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7206 ``And a hack it is, although Apple's Darwin version of GDB
7207 contains an almost identical hack to implement a "future
7208 break" command. It seems to work in many real world cases,
7209 but it is easy to come up with a test case where the patch
7210 doesn't help at all.''
7212 ``It seems that the way GDB implements breakpoints - in -
7213 shared - libraries was designed for a.out shared library
7214 systems (SunOS 4) where shared libraries were loaded at a
7215 fixed address in memory. Since ELF shared libraries can (and
7216 will) be loaded at any address in memory, things break.
7217 Fixing this is not trivial. Therefore, I'm not sure whether
7218 we should add this hack to the branch only. I cannot
7219 guarantee that things will be fixed on the trunk in the near
7222 In case we have a problem, disable this breakpoint. We'll
7223 restore its status if we succeed. Don't disable a
7224 shlib_disabled breakpoint though. There's a fair chance we
7225 can't re-set it if the shared library it's in hasn't been
7231 save_enable = b->enable_state;
7232 if (b->enable_state != bp_shlib_disabled)
7233 b->enable_state = bp_disabled;
7235 /* If resetting a shlib-disabled breakpoint, we don't want to
7236 see an error message if it is not found since we will expect
7237 this to occur until the shared library is finally reloaded.
7238 We accomplish this by giving decode_line_1 a pointer to use
7239 for silent notification that the symbol is not found. */
7240 not_found_ptr = ¬_found;
7242 set_language (b->language);
7243 input_radix = b->input_radix;
7245 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7247 for (i = 0; i < sals.nelts; i++)
7249 resolve_sal_pc (&sals.sals[i]);
7251 /* Reparse conditions, they might contain references to the
7253 if (b->cond_string != NULL)
7259 /* Avoid re-freeing b->exp if an error during the call
7263 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7266 /* We need to re-set the breakpoint if the address changes... */
7267 if (b->loc->address != sals.sals[i].pc
7268 /* ...or new and old breakpoints both have source files, and
7269 the source file name or the line number changes... */
7270 || (b->source_file != NULL
7271 && sals.sals[i].symtab != NULL
7272 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
7273 || b->line_number != sals.sals[i].line)
7275 /* ...or we switch between having a source file and not having
7277 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7280 if (b->source_file != NULL)
7281 xfree (b->source_file);
7282 if (sals.sals[i].symtab == NULL)
7283 b->source_file = NULL;
7286 savestring (sals.sals[i].symtab->filename,
7287 strlen (sals.sals[i].symtab->filename));
7288 b->line_number = sals.sals[i].line;
7289 b->loc->requested_address = sals.sals[i].pc;
7291 = adjust_breakpoint_address (b->loc->requested_address,
7294 /* Used to check for duplicates here, but that can
7295 cause trouble, as it doesn't check for disabled
7300 /* Might be better to do this just once per breakpoint_re_set,
7301 rather than once for every breakpoint. */
7302 breakpoints_changed ();
7304 b->loc->section = sals.sals[i].section;
7305 b->enable_state = save_enable; /* Restore it, this worked. */
7308 /* Now that this is re-enabled, check_duplicates
7310 check_duplicates (b);
7317 case bp_hardware_watchpoint:
7318 case bp_read_watchpoint:
7319 case bp_access_watchpoint:
7320 innermost_block = NULL;
7321 /* The issue arises of what context to evaluate this in. The
7322 same one as when it was set, but what does that mean when
7323 symbols have been re-read? We could save the filename and
7324 functionname, but if the context is more local than that, the
7325 best we could do would be something like how many levels deep
7326 and which index at that particular level, but that's going to
7327 be less stable than filenames or function names. */
7329 /* So for now, just use a global context. */
7333 /* Avoid re-freeing b->exp if an error during the call to
7334 parse_expression. */
7337 b->exp = parse_expression (b->exp_string);
7338 b->exp_valid_block = innermost_block;
7339 mark = value_mark ();
7342 value_free (b->val);
7343 /* Avoid re-freeing b->val if an error during the call to
7344 evaluate_expression. */
7347 b->val = evaluate_expression (b->exp);
7348 release_value (b->val);
7349 if (value_lazy (b->val) && breakpoint_enabled (b))
7350 value_fetch_lazy (b->val);
7352 if (b->cond_string != NULL)
7358 /* Avoid re-freeing b->exp if an error during the call
7362 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7364 if (breakpoint_enabled (b))
7366 value_free_to_mark (mark);
7368 case bp_catch_catch:
7369 case bp_catch_throw:
7371 /* We needn't really do anything to reset these, since the mask
7372 that requests them is unaffected by e.g., new libraries being
7375 case bp_catch_vfork:
7380 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7382 /* Delete longjmp and overlay event breakpoints; they will be
7383 reset later by breakpoint_re_set. */
7385 case bp_longjmp_resume:
7386 case bp_overlay_event:
7387 delete_breakpoint (b);
7390 /* This breakpoint is special, it's set up when the inferior
7391 starts and we really don't want to touch it. */
7392 case bp_shlib_event:
7394 /* Like bp_shlib_event, this breakpoint type is special.
7395 Once it is set up, we do not want to touch it. */
7396 case bp_thread_event:
7398 /* Keep temporary breakpoints, which can be encountered when we step
7399 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7400 Otherwise these should have been blown away via the cleanup chain
7401 or by breakpoint_init_inferior when we rerun the executable. */
7404 case bp_watchpoint_scope:
7406 case bp_step_resume:
7413 /* Re-set all breakpoints after symbols have been re-loaded. */
7415 breakpoint_re_set (void)
7417 struct breakpoint *b, *temp;
7418 enum language save_language;
7419 int save_input_radix;
7421 save_language = current_language->la_language;
7422 save_input_radix = input_radix;
7423 ALL_BREAKPOINTS_SAFE (b, temp)
7425 /* Format possible error msg */
7426 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7428 struct cleanup *cleanups = make_cleanup (xfree, message);
7429 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7430 do_cleanups (cleanups);
7432 set_language (save_language);
7433 input_radix = save_input_radix;
7435 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7437 create_longjmp_breakpoint ("longjmp");
7438 create_longjmp_breakpoint ("_longjmp");
7439 create_longjmp_breakpoint ("siglongjmp");
7440 create_longjmp_breakpoint ("_siglongjmp");
7441 create_longjmp_breakpoint (NULL);
7444 create_overlay_event_breakpoint ("_ovly_debug_event");
7447 /* Reset the thread number of this breakpoint:
7449 - If the breakpoint is for all threads, leave it as-is.
7450 - Else, reset it to the current thread for inferior_ptid. */
7452 breakpoint_re_set_thread (struct breakpoint *b)
7454 if (b->thread != -1)
7456 if (in_thread_list (inferior_ptid))
7457 b->thread = pid_to_thread_id (inferior_ptid);
7461 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7462 If from_tty is nonzero, it prints a message to that effect,
7463 which ends with a period (no newline). */
7466 set_ignore_count (int bptnum, int count, int from_tty)
7468 struct breakpoint *b;
7474 if (b->number == bptnum)
7476 b->ignore_count = count;
7480 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7482 else if (count == 1)
7483 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7486 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7489 breakpoints_changed ();
7490 breakpoint_modify_event (b->number);
7494 error (_("No breakpoint number %d."), bptnum);
7497 /* Clear the ignore counts of all breakpoints. */
7499 breakpoint_clear_ignore_counts (void)
7501 struct breakpoint *b;
7504 b->ignore_count = 0;
7507 /* Command to set ignore-count of breakpoint N to COUNT. */
7510 ignore_command (char *args, int from_tty)
7516 error_no_arg (_("a breakpoint number"));
7518 num = get_number (&p);
7520 error (_("bad breakpoint number: '%s'"), args);
7522 error (_("Second argument (specified ignore-count) is missing."));
7524 set_ignore_count (num,
7525 longest_to_int (value_as_long (parse_and_eval (p))),
7528 printf_filtered ("\n");
7531 /* Call FUNCTION on each of the breakpoints
7532 whose numbers are given in ARGS. */
7535 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7540 struct breakpoint *b, *tmp;
7544 error_no_arg (_("one or more breakpoint numbers"));
7551 num = get_number_or_range (&p1);
7554 warning (_("bad breakpoint number at or near '%s'"), p);
7558 ALL_BREAKPOINTS_SAFE (b, tmp)
7559 if (b->number == num)
7561 struct breakpoint *related_breakpoint = b->related_breakpoint;
7564 if (related_breakpoint)
7565 function (related_breakpoint);
7569 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7575 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7576 If from_tty is nonzero, it prints a message to that effect,
7577 which ends with a period (no newline). */
7580 disable_breakpoint (struct breakpoint *bpt)
7582 /* Never disable a watchpoint scope breakpoint; we want to
7583 hit them when we leave scope so we can delete both the
7584 watchpoint and its scope breakpoint at that time. */
7585 if (bpt->type == bp_watchpoint_scope)
7588 /* You can't disable permanent breakpoints. */
7589 if (bpt->enable_state == bp_permanent)
7592 bpt->enable_state = bp_disabled;
7594 check_duplicates (bpt);
7596 if (deprecated_modify_breakpoint_hook)
7597 deprecated_modify_breakpoint_hook (bpt);
7598 breakpoint_modify_event (bpt->number);
7602 disable_command (char *args, int from_tty)
7604 struct breakpoint *bpt;
7606 ALL_BREAKPOINTS (bpt)
7610 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7615 case bp_catch_unload:
7617 case bp_catch_vfork:
7619 case bp_catch_catch:
7620 case bp_catch_throw:
7621 case bp_hardware_breakpoint:
7623 case bp_hardware_watchpoint:
7624 case bp_read_watchpoint:
7625 case bp_access_watchpoint:
7626 disable_breakpoint (bpt);
7631 map_breakpoint_numbers (args, disable_breakpoint);
7635 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7637 int target_resources_ok, other_type_used;
7640 if (bpt->type == bp_hardware_breakpoint)
7643 i = hw_breakpoint_used_count ();
7644 target_resources_ok =
7645 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7647 if (target_resources_ok == 0)
7648 error (_("No hardware breakpoint support in the target."));
7649 else if (target_resources_ok < 0)
7650 error (_("Hardware breakpoints used exceeds limit."));
7655 if (bpt->enable_state != bp_enabled)
7657 /* When enabling a pending breakpoint, we need to check if the breakpoint
7658 is resolvable since shared libraries could have been loaded
7659 after the breakpoint was disabled. */
7660 breakpoints_changed ();
7661 if (resolve_pending_breakpoint (bpt) == GDB_RC_OK)
7663 delete_breakpoint (bpt);
7666 bpt->enable_state = bp_enabled;
7667 bpt->disposition = disposition;
7670 else /* Not a pending breakpoint. */
7672 if (bpt->enable_state != bp_permanent)
7673 bpt->enable_state = bp_enabled;
7674 bpt->disposition = disposition;
7675 check_duplicates (bpt);
7676 breakpoints_changed ();
7678 if (bpt->type == bp_watchpoint ||
7679 bpt->type == bp_hardware_watchpoint ||
7680 bpt->type == bp_read_watchpoint ||
7681 bpt->type == bp_access_watchpoint)
7683 struct frame_id saved_frame_id;
7685 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7686 if (bpt->exp_valid_block != NULL)
7688 struct frame_info *fr =
7689 fr = frame_find_by_id (bpt->watchpoint_frame);
7692 printf_filtered (_("\
7693 Cannot enable watchpoint %d because the block in which its expression\n\
7694 is valid is not currently in scope.\n"), bpt->number);
7695 bpt->enable_state = bp_disabled;
7701 value_free (bpt->val);
7702 mark = value_mark ();
7703 bpt->val = evaluate_expression (bpt->exp);
7704 release_value (bpt->val);
7705 if (value_lazy (bpt->val))
7706 value_fetch_lazy (bpt->val);
7708 if (bpt->type == bp_hardware_watchpoint ||
7709 bpt->type == bp_read_watchpoint ||
7710 bpt->type == bp_access_watchpoint)
7712 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7713 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7715 /* Hack around 'unused var' error for some targets here */
7716 (void) mem_cnt, (void) i;
7717 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7718 bpt->type, i + mem_cnt, other_type_used);
7719 /* we can consider of type is bp_hardware_watchpoint, convert to
7720 bp_watchpoint in the following condition */
7721 if (target_resources_ok < 0)
7723 printf_filtered (_("\
7724 Cannot enable watchpoint %d because target watch resources\n\
7725 have been allocated for other watchpoints.\n"), bpt->number);
7726 bpt->enable_state = bp_disabled;
7727 value_free_to_mark (mark);
7732 select_frame (frame_find_by_id (saved_frame_id));
7733 value_free_to_mark (mark);
7737 if (deprecated_modify_breakpoint_hook)
7738 deprecated_modify_breakpoint_hook (bpt);
7739 breakpoint_modify_event (bpt->number);
7743 enable_breakpoint (struct breakpoint *bpt)
7745 do_enable_breakpoint (bpt, bpt->disposition);
7748 /* The enable command enables the specified breakpoints (or all defined
7749 breakpoints) so they once again become (or continue to be) effective
7750 in stopping the inferior. */
7753 enable_command (char *args, int from_tty)
7755 struct breakpoint *bpt;
7757 ALL_BREAKPOINTS (bpt)
7761 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7766 case bp_catch_unload:
7768 case bp_catch_vfork:
7770 case bp_catch_catch:
7771 case bp_catch_throw:
7772 case bp_hardware_breakpoint:
7774 case bp_hardware_watchpoint:
7775 case bp_read_watchpoint:
7776 case bp_access_watchpoint:
7777 enable_breakpoint (bpt);
7782 map_breakpoint_numbers (args, enable_breakpoint);
7786 enable_once_breakpoint (struct breakpoint *bpt)
7788 do_enable_breakpoint (bpt, disp_disable);
7792 enable_once_command (char *args, int from_tty)
7794 map_breakpoint_numbers (args, enable_once_breakpoint);
7798 enable_delete_breakpoint (struct breakpoint *bpt)
7800 do_enable_breakpoint (bpt, disp_del);
7804 enable_delete_command (char *args, int from_tty)
7806 map_breakpoint_numbers (args, enable_delete_breakpoint);
7810 set_breakpoint_cmd (char *args, int from_tty)
7815 show_breakpoint_cmd (char *args, int from_tty)
7819 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7821 struct symtabs_and_lines
7822 decode_line_spec_1 (char *string, int funfirstline)
7824 struct symtabs_and_lines sals;
7826 error (_("Empty line specification."));
7827 if (default_breakpoint_valid)
7828 sals = decode_line_1 (&string, funfirstline,
7829 default_breakpoint_symtab,
7830 default_breakpoint_line,
7831 (char ***) NULL, NULL);
7833 sals = decode_line_1 (&string, funfirstline,
7834 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7836 error (_("Junk at end of line specification: %s"), string);
7840 /* Create and insert a raw software breakpoint at PC. Return an
7841 identifier, which should be used to remove the breakpoint later.
7842 In general, places which call this should be using something on the
7843 breakpoint chain instead; this function should be eliminated
7847 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
7849 struct bp_target_info *bp_tgt;
7851 bp_tgt = xmalloc (sizeof (struct bp_target_info));
7852 memset (bp_tgt, 0, sizeof (struct bp_target_info));
7854 bp_tgt->placed_address = pc;
7855 if (target_insert_breakpoint (bp_tgt) != 0)
7857 /* Could not insert the breakpoint. */
7865 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7868 deprecated_remove_raw_breakpoint (void *bp)
7870 struct bp_target_info *bp_tgt = bp;
7873 ret = target_remove_breakpoint (bp_tgt);
7879 /* One (or perhaps two) breakpoints used for software single stepping. */
7881 static void *single_step_breakpoints[2];
7883 /* Create and insert a breakpoint for software single step. */
7886 insert_single_step_breakpoint (CORE_ADDR next_pc)
7890 if (single_step_breakpoints[0] == NULL)
7891 bpt_p = &single_step_breakpoints[0];
7894 gdb_assert (single_step_breakpoints[1] == NULL);
7895 bpt_p = &single_step_breakpoints[1];
7898 /* NOTE drow/2006-04-11: A future improvement to this function would be
7899 to only create the breakpoints once, and actually put them on the
7900 breakpoint chain. That would let us use set_raw_breakpoint. We could
7901 adjust the addresses each time they were needed. Doing this requires
7902 corresponding changes elsewhere where single step breakpoints are
7903 handled, however. So, for now, we use this. */
7905 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
7907 error (_("Could not insert single-step breakpoint at 0x%s"),
7908 paddr_nz (next_pc));
7911 /* Remove and delete any breakpoints used for software single step. */
7914 remove_single_step_breakpoints (void)
7916 gdb_assert (single_step_breakpoints[0] != NULL);
7918 /* See insert_single_step_breakpoint for more about this deprecated
7920 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
7921 single_step_breakpoints[0] = NULL;
7923 if (single_step_breakpoints[1] != NULL)
7925 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
7926 single_step_breakpoints[1] = NULL;
7930 /* Check whether a software single-step breakpoint is inserted at PC. */
7933 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
7937 for (i = 0; i < 2; i++)
7939 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
7940 if (bp_tgt && bp_tgt->placed_address == pc)
7948 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7949 It is defined as a macro to prevent duplication.
7950 COMMAND should be a string constant containing the name of the command. */
7951 #define BREAK_ARGS_HELP(command) \
7952 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7953 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7954 If a line number is specified, break at start of code for that line.\n\
7955 If a function is specified, break at start of code for that function.\n\
7956 If an address is specified, break at that exact address.\n\
7957 With no LOCATION, uses current execution address of selected stack frame.\n\
7958 This is useful for breaking on return to a stack frame.\n\
7960 THREADNUM is the number from \"info threads\".\n\
7961 CONDITION is a boolean expression.\n\
7963 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7965 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7968 _initialize_breakpoint (void)
7970 static struct cmd_list_element *breakpoint_set_cmdlist;
7971 static struct cmd_list_element *breakpoint_show_cmdlist;
7972 struct cmd_list_element *c;
7974 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
7976 breakpoint_chain = 0;
7977 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7978 before a breakpoint is set. */
7979 breakpoint_count = 0;
7981 add_com ("ignore", class_breakpoint, ignore_command, _("\
7982 Set ignore-count of breakpoint number N to COUNT.\n\
7983 Usage is `ignore N COUNT'."));
7985 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7987 add_com ("commands", class_breakpoint, commands_command, _("\
7988 Set commands to be executed when a breakpoint is hit.\n\
7989 Give breakpoint number as argument after \"commands\".\n\
7990 With no argument, the targeted breakpoint is the last one set.\n\
7991 The commands themselves follow starting on the next line.\n\
7992 Type a line containing \"end\" to indicate the end of them.\n\
7993 Give \"silent\" as the first line to make the breakpoint silent;\n\
7994 then no output is printed when it is hit, except what the commands print."));
7996 add_com ("condition", class_breakpoint, condition_command, _("\
7997 Specify breakpoint number N to break only if COND is true.\n\
7998 Usage is `condition N COND', where N is an integer and COND is an\n\
7999 expression to be evaluated whenever breakpoint N is reached."));
8001 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8002 Set a temporary breakpoint.\n\
8003 Like \"break\" except the breakpoint is only temporary,\n\
8004 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8005 by using \"enable delete\" on the breakpoint number.\n\
8007 BREAK_ARGS_HELP ("tbreak")));
8008 set_cmd_completer (c, location_completer);
8010 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8011 Set a hardware assisted breakpoint.\n\
8012 Like \"break\" except the breakpoint requires hardware support,\n\
8013 some target hardware may not have this support.\n\
8015 BREAK_ARGS_HELP ("hbreak")));
8016 set_cmd_completer (c, location_completer);
8018 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8019 Set a temporary hardware assisted breakpoint.\n\
8020 Like \"hbreak\" except the breakpoint is only temporary,\n\
8021 so it will be deleted when hit.\n\
8023 BREAK_ARGS_HELP ("thbreak")));
8024 set_cmd_completer (c, location_completer);
8026 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8027 Enable some breakpoints.\n\
8028 Give breakpoint numbers (separated by spaces) as arguments.\n\
8029 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8030 This is used to cancel the effect of the \"disable\" command.\n\
8031 With a subcommand you can enable temporarily."),
8032 &enablelist, "enable ", 1, &cmdlist);
8034 add_com ("ab", class_breakpoint, enable_command, _("\
8035 Enable some breakpoints.\n\
8036 Give breakpoint numbers (separated by spaces) as arguments.\n\
8037 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8038 This is used to cancel the effect of the \"disable\" command.\n\
8039 With a subcommand you can enable temporarily."));
8041 add_com_alias ("en", "enable", class_breakpoint, 1);
8043 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8044 Enable some breakpoints.\n\
8045 Give breakpoint numbers (separated by spaces) as arguments.\n\
8046 This is used to cancel the effect of the \"disable\" command.\n\
8047 May be abbreviated to simply \"enable\".\n"),
8048 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8050 add_cmd ("once", no_class, enable_once_command, _("\
8051 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8052 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8055 add_cmd ("delete", no_class, enable_delete_command, _("\
8056 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8057 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8060 add_cmd ("delete", no_class, enable_delete_command, _("\
8061 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8062 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8065 add_cmd ("once", no_class, enable_once_command, _("\
8066 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8067 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8070 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8071 Disable some breakpoints.\n\
8072 Arguments are breakpoint numbers with spaces in between.\n\
8073 To disable all breakpoints, give no argument.\n\
8074 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8075 &disablelist, "disable ", 1, &cmdlist);
8076 add_com_alias ("dis", "disable", class_breakpoint, 1);
8077 add_com_alias ("disa", "disable", class_breakpoint, 1);
8079 add_com ("sb", class_breakpoint, disable_command, _("\
8080 Disable some breakpoints.\n\
8081 Arguments are breakpoint numbers with spaces in between.\n\
8082 To disable all breakpoints, give no argument.\n\
8083 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8085 add_cmd ("breakpoints", class_alias, disable_command, _("\
8086 Disable some breakpoints.\n\
8087 Arguments are breakpoint numbers with spaces in between.\n\
8088 To disable all breakpoints, give no argument.\n\
8089 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8090 This command may be abbreviated \"disable\"."),
8093 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8094 Delete some breakpoints or auto-display expressions.\n\
8095 Arguments are breakpoint numbers with spaces in between.\n\
8096 To delete all breakpoints, give no argument.\n\
8098 Also a prefix command for deletion of other GDB objects.\n\
8099 The \"unset\" command is also an alias for \"delete\"."),
8100 &deletelist, "delete ", 1, &cmdlist);
8101 add_com_alias ("d", "delete", class_breakpoint, 1);
8102 add_com_alias ("del", "delete", class_breakpoint, 1);
8104 add_com ("db", class_breakpoint, delete_command, _("\
8105 Delete some breakpoints.\n\
8106 Arguments are breakpoint numbers with spaces in between.\n\
8107 To delete all breakpoints, give no argument.\n"));
8109 add_cmd ("breakpoints", class_alias, delete_command, _("\
8110 Delete some breakpoints or auto-display expressions.\n\
8111 Arguments are breakpoint numbers with spaces in between.\n\
8112 To delete all breakpoints, give no argument.\n\
8113 This command may be abbreviated \"delete\"."),
8116 add_com ("clear", class_breakpoint, clear_command, _("\
8117 Clear breakpoint at specified line or function.\n\
8118 Argument may be line number, function name, or \"*\" and an address.\n\
8119 If line number is specified, all breakpoints in that line are cleared.\n\
8120 If function is specified, breakpoints at beginning of function are cleared.\n\
8121 If an address is specified, breakpoints at that address are cleared.\n\
8123 With no argument, clears all breakpoints in the line that the selected frame\n\
8126 See also the \"delete\" command which clears breakpoints by number."));
8128 c = add_com ("break", class_breakpoint, break_command, _("\
8129 Set breakpoint at specified line or function.\n"
8130 BREAK_ARGS_HELP ("break")));
8131 set_cmd_completer (c, location_completer);
8133 add_com_alias ("b", "break", class_run, 1);
8134 add_com_alias ("br", "break", class_run, 1);
8135 add_com_alias ("bre", "break", class_run, 1);
8136 add_com_alias ("brea", "break", class_run, 1);
8140 add_com_alias ("ba", "break", class_breakpoint, 1);
8141 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8146 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8147 Break in function/address or break at a line in the current file."),
8148 &stoplist, "stop ", 1, &cmdlist);
8149 add_cmd ("in", class_breakpoint, stopin_command,
8150 _("Break in function or address."), &stoplist);
8151 add_cmd ("at", class_breakpoint, stopat_command,
8152 _("Break at a line in the current file."), &stoplist);
8153 add_com ("status", class_info, breakpoints_info, _("\
8154 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8155 The \"Type\" column indicates one of:\n\
8156 \tbreakpoint - normal breakpoint\n\
8157 \twatchpoint - watchpoint\n\
8158 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8159 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8160 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8161 address and file/line number respectively.\n\
8163 Convenience variable \"$_\" and default examine address for \"x\"\n\
8164 are set to the address of the last breakpoint listed.\n\n\
8165 Convenience variable \"$bpnum\" contains the number of the last\n\
8169 add_info ("breakpoints", breakpoints_info, _("\
8170 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8171 The \"Type\" column indicates one of:\n\
8172 \tbreakpoint - normal breakpoint\n\
8173 \twatchpoint - watchpoint\n\
8174 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8175 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8176 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8177 address and file/line number respectively.\n\
8179 Convenience variable \"$_\" and default examine address for \"x\"\n\
8180 are set to the address of the last breakpoint listed.\n\n\
8181 Convenience variable \"$bpnum\" contains the number of the last\n\
8185 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8186 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8187 The \"Type\" column indicates one of:\n\
8188 \tbreakpoint - normal breakpoint\n\
8189 \twatchpoint - watchpoint\n\
8190 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8191 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8192 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8193 address and file/line number respectively.\n\
8195 Convenience variable \"$_\" and default examine address for \"x\"\n\
8196 are set to the address of the last breakpoint listed.\n\n\
8197 Convenience variable \"$bpnum\" contains the number of the last\n\
8200 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8201 Status of all breakpoints, or breakpoint number NUMBER.\n\
8202 The \"Type\" column indicates one of:\n\
8203 \tbreakpoint - normal breakpoint\n\
8204 \twatchpoint - watchpoint\n\
8205 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8206 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8207 \tuntil - internal breakpoint used by the \"until\" command\n\
8208 \tfinish - internal breakpoint used by the \"finish\" command\n\
8209 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8210 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8211 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8212 address and file/line number respectively.\n\
8214 Convenience variable \"$_\" and default examine address for \"x\"\n\
8215 are set to the address of the last breakpoint listed.\n\
8217 Convenience variable \"$bpnum\" contains the number of the last\n\
8219 &maintenanceinfolist);
8221 add_com ("catch", class_breakpoint, catch_command, _("\
8222 Set catchpoints to catch events.\n\
8223 Raised signals may be caught:\n\
8224 \tcatch signal - all signals\n\
8225 \tcatch signal <signame> - a particular signal\n\
8226 Raised exceptions may be caught:\n\
8227 \tcatch throw - all exceptions, when thrown\n\
8228 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8229 \tcatch catch - all exceptions, when caught\n\
8230 \tcatch catch <exceptname> - a particular exception, when caught\n\
8231 Thread or process events may be caught:\n\
8232 \tcatch thread_start - any threads, just after creation\n\
8233 \tcatch thread_exit - any threads, just before expiration\n\
8234 \tcatch thread_join - any threads, just after joins\n\
8235 Process events may be caught:\n\
8236 \tcatch start - any processes, just after creation\n\
8237 \tcatch exit - any processes, just before expiration\n\
8238 \tcatch fork - calls to fork()\n\
8239 \tcatch vfork - calls to vfork()\n\
8240 \tcatch exec - calls to exec()\n\
8241 Dynamically-linked library events may be caught:\n\
8242 \tcatch load - loads of any library\n\
8243 \tcatch load <libname> - loads of a particular library\n\
8244 \tcatch unload - unloads of any library\n\
8245 \tcatch unload <libname> - unloads of a particular library\n\
8246 The act of your program's execution stopping may also be caught:\n\
8248 C++ exceptions may be caught:\n\
8249 \tcatch throw - all exceptions, when thrown\n\
8250 \tcatch catch - all exceptions, when caught\n\
8251 Ada exceptions may be caught:\n\
8252 \tcatch exception - all exceptions, when raised\n\
8253 \tcatch exception <name> - a particular exception, when raised\n\
8254 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8255 \tcatch assert - all failed assertions, when raised\n\
8257 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8258 after a fork or vfork is caught.\n\n\
8259 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8261 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8262 Set temporary catchpoints to catch events.\n\
8263 Args like \"catch\" command.\n\
8264 Like \"catch\" except the catchpoint is only temporary,\n\
8265 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8266 by using \"enable delete\" on the catchpoint number."));
8268 c = add_com ("watch", class_breakpoint, watch_command, _("\
8269 Set a watchpoint for an expression.\n\
8270 A watchpoint stops execution of your program whenever the value of\n\
8271 an expression changes."));
8272 set_cmd_completer (c, location_completer);
8274 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8275 Set a read watchpoint for an expression.\n\
8276 A watchpoint stops execution of your program whenever the value of\n\
8277 an expression is read."));
8278 set_cmd_completer (c, location_completer);
8280 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8281 Set a watchpoint for an expression.\n\
8282 A watchpoint stops execution of your program whenever the value of\n\
8283 an expression is either read or written."));
8284 set_cmd_completer (c, location_completer);
8286 add_info ("watchpoints", breakpoints_info,
8287 _("Synonym for ``info breakpoints''."));
8290 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8291 respond to changes - contrary to the description. */
8292 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8293 &can_use_hw_watchpoints, _("\
8294 Set debugger's willingness to use watchpoint hardware."), _("\
8295 Show debugger's willingness to use watchpoint hardware."), _("\
8296 If zero, gdb will not use hardware for new watchpoints, even if\n\
8297 such is available. (However, any hardware watchpoints that were\n\
8298 created before setting this to nonzero, will continue to use watchpoint\n\
8301 show_can_use_hw_watchpoints,
8302 &setlist, &showlist);
8304 can_use_hw_watchpoints = 1;
8306 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8307 Breakpoint specific settings\n\
8308 Configure various breakpoint-specific variables such as\n\
8309 pending breakpoint behavior"),
8310 &breakpoint_set_cmdlist, "set breakpoint ",
8311 0/*allow-unknown*/, &setlist);
8312 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8313 Breakpoint specific settings\n\
8314 Configure various breakpoint-specific variables such as\n\
8315 pending breakpoint behavior"),
8316 &breakpoint_show_cmdlist, "show breakpoint ",
8317 0/*allow-unknown*/, &showlist);
8319 add_setshow_auto_boolean_cmd ("pending", no_class,
8320 &pending_break_support, _("\
8321 Set debugger's behavior regarding pending breakpoints."), _("\
8322 Show debugger's behavior regarding pending breakpoints."), _("\
8323 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8324 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8325 an error. If auto, an unrecognized breakpoint location results in a\n\
8326 user-query to see if a pending breakpoint should be created."),
8328 show_pending_break_support,
8329 &breakpoint_set_cmdlist,
8330 &breakpoint_show_cmdlist);
8332 pending_break_support = AUTO_BOOLEAN_AUTO;
8334 add_setshow_boolean_cmd ("auto-hw", no_class,
8335 &automatic_hardware_breakpoints, _("\
8336 Set automatic usage of hardware breakpoints."), _("\
8337 Show automatic usage of hardware breakpoints."), _("\
8338 If set, the debugger will automatically use hardware breakpoints for\n\
8339 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8340 a warning will be emitted for such breakpoints."),
8342 show_automatic_hardware_breakpoints,
8343 &breakpoint_set_cmdlist,
8344 &breakpoint_show_cmdlist);
8346 automatic_hardware_breakpoints = 1;