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 3 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, see <http://www.gnu.org/licenses/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg *arg);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint *);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint *);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value *);
93 static int break_command_1 (char *, int, int, struct breakpoint *);
95 static void mention (struct breakpoint *);
97 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
99 static void check_duplicates (struct breakpoint *);
101 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
103 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
106 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat bpstat_alloc (struct bp_location *, bpstat);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location *, insertion_state_t);
135 static enum print_stop_action print_it_typical (bpstat);
137 static enum print_stop_action print_bp_stop_message (bpstat bs);
141 enum exception_event_kind kind;
144 args_for_catchpoint_enable;
146 static int watchpoint_check (void *);
148 static int cover_target_enable_exception_callback (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
172 static void solib_load_unload_1 (char *hookname,
175 char *cond_string, enum bptype bp_kind);
177 static void create_fork_vfork_event_catchpoint (int tempflag,
179 enum bptype bp_kind);
181 static void stop_command (char *arg, int from_tty);
183 static void stopin_command (char *arg, int from_tty);
185 static void stopat_command (char *arg, int from_tty);
187 static char *ep_find_event_name_end (char *arg);
189 static char *ep_parse_optional_if_clause (char **arg);
191 static char *ep_parse_optional_filename (char **arg);
193 static void create_exception_catchpoint (int tempflag, char *cond_string,
194 enum exception_event_kind ex_event,
195 struct symtab_and_line *sal);
197 static void catch_exception_command_1 (enum exception_event_kind ex_event,
198 char *arg, int tempflag, int from_tty);
200 static void tcatch_command (char *arg, int from_tty);
202 static void ep_skip_leading_whitespace (char **s);
204 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
206 static void free_bp_location (struct bp_location *loc);
208 /* Prototypes for exported functions. */
210 /* If FALSE, gdb will not use hardware support for watchpoints, even
211 if such is available. */
212 static int can_use_hw_watchpoints;
215 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
216 struct cmd_list_element *c,
219 fprintf_filtered (file, _("\
220 Debugger's willingness to use watchpoint hardware is %s.\n"),
224 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
225 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
226 for unrecognized breakpoint locations.
227 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
228 static enum auto_boolean pending_break_support;
230 show_pending_break_support (struct ui_file *file, int from_tty,
231 struct cmd_list_element *c,
234 fprintf_filtered (file, _("\
235 Debugger's behavior regarding pending breakpoints is %s.\n"),
239 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
240 set with "break" but falling in read-only memory.
241 If 0, gdb will warn about such breakpoints, but won't automatically
242 use hardware breakpoints. */
243 static int automatic_hardware_breakpoints;
245 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
246 struct cmd_list_element *c,
249 fprintf_filtered (file, _("\
250 Automatic usage of hardware breakpoints is %s.\n"),
255 void _initialize_breakpoint (void);
257 extern int addressprint; /* Print machine addresses? */
259 /* Are we executing breakpoint commands? */
260 static int executing_breakpoint_commands;
262 /* Are overlay event breakpoints enabled? */
263 static int overlay_events_enabled;
265 /* Walk the following statement or block through all breakpoints.
266 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
269 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
271 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
272 for (B = breakpoint_chain; \
273 B ? (TMP=B->next, 1): 0; \
276 /* Similar iterators for the low-level breakpoints. */
278 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
280 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
281 for (B = bp_location_chain; \
282 B ? (TMP=B->global_next, 1): 0; \
285 /* True if breakpoint hit counts should be displayed in breakpoint info. */
287 int show_breakpoint_hit_counts = 1;
289 /* Chains of all breakpoints defined. */
291 struct breakpoint *breakpoint_chain;
293 struct bp_location *bp_location_chain;
295 /* Number of last breakpoint made. */
297 int breakpoint_count;
299 /* Pointer to current exception event record */
300 static struct exception_event_record *current_exception_event;
302 /* This function returns a pointer to the string representation of the
303 pathname of the dynamically-linked library that has just been
306 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
307 or undefined results are guaranteed.
309 This string's contents are only valid immediately after the
310 inferior has stopped in the dynamic linker hook, and becomes
311 invalid as soon as the inferior is continued. Clients should make
312 a copy of this string if they wish to continue the inferior and
313 then access the string. */
315 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
316 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
319 /* This function returns a pointer to the string representation of the
320 pathname of the dynamically-linked library that has just been
323 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
324 TRUE, or undefined results are guaranteed.
326 This string's contents are only valid immediately after the
327 inferior has stopped in the dynamic linker hook, and becomes
328 invalid as soon as the inferior is continued. Clients should make
329 a copy of this string if they wish to continue the inferior and
330 then access the string. */
332 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
333 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
336 /* This function is called by the "catch load" command. It allows the
337 debugger to be notified by the dynamic linker when a specified
338 library file (or any library file, if filename is NULL) is loaded. */
340 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
341 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
342 error (_("catch of library loads not yet implemented on this platform"))
345 /* This function is called by the "catch unload" command. It allows
346 the debugger to be notified by the dynamic linker when a specified
347 library file (or any library file, if filename is NULL) is
350 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
351 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
352 error (_("catch of library unloads not yet implemented on this platform"))
355 /* Return whether a breakpoint is an active enabled breakpoint. */
357 breakpoint_enabled (struct breakpoint *b)
359 return (b->enable_state == bp_enabled);
362 /* Set breakpoint count to NUM. */
365 set_breakpoint_count (int num)
367 breakpoint_count = num;
368 set_internalvar (lookup_internalvar ("bpnum"),
369 value_from_longest (builtin_type_int, (LONGEST) num));
372 /* Used in run_command to zero the hit count when a new run starts. */
375 clear_breakpoint_hit_counts (void)
377 struct breakpoint *b;
383 /* Default address, symtab and line to put a breakpoint at
384 for "break" command with no arg.
385 if default_breakpoint_valid is zero, the other three are
386 not valid, and "break" with no arg is an error.
388 This set by print_stack_frame, which calls set_default_breakpoint. */
390 int default_breakpoint_valid;
391 CORE_ADDR default_breakpoint_address;
392 struct symtab *default_breakpoint_symtab;
393 int default_breakpoint_line;
395 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
396 Advance *PP after the string and any trailing whitespace.
398 Currently the string can either be a number or "$" followed by the name
399 of a convenience variable. Making it an expression wouldn't work well
400 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
402 If the string is a NULL pointer, that denotes the last breakpoint.
404 TRAILER is a character which can be found after the number; most
405 commonly this is `-'. If you don't want a trailer, use \0. */
407 get_number_trailer (char **pp, int trailer)
409 int retval = 0; /* default */
413 /* Empty line means refer to the last breakpoint. */
414 return breakpoint_count;
417 /* Make a copy of the name, so we can null-terminate it
418 to pass to lookup_internalvar(). */
423 while (isalnum (*p) || *p == '_')
425 varname = (char *) alloca (p - start + 1);
426 strncpy (varname, start, p - start);
427 varname[p - start] = '\0';
428 val = value_of_internalvar (lookup_internalvar (varname));
429 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
430 retval = (int) value_as_long (val);
433 printf_filtered (_("Convenience variable must have integer value.\n"));
441 while (*p >= '0' && *p <= '9')
444 /* There is no number here. (e.g. "cond a == b"). */
446 /* Skip non-numeric token */
447 while (*p && !isspace((int) *p))
449 /* Return zero, which caller must interpret as error. */
455 if (!(isspace (*p) || *p == '\0' || *p == trailer))
457 /* Trailing junk: return 0 and let caller print error msg. */
458 while (!(isspace (*p) || *p == '\0' || *p == trailer))
469 /* Like get_number_trailer, but don't allow a trailer. */
471 get_number (char **pp)
473 return get_number_trailer (pp, '\0');
476 /* Parse a number or a range.
477 * A number will be of the form handled by get_number.
478 * A range will be of the form <number1> - <number2>, and
479 * will represent all the integers between number1 and number2,
482 * While processing a range, this fuction is called iteratively;
483 * At each call it will return the next value in the range.
485 * At the beginning of parsing a range, the char pointer PP will
486 * be advanced past <number1> and left pointing at the '-' token.
487 * Subsequent calls will not advance the pointer until the range
488 * is completed. The call that completes the range will advance
489 * pointer PP past <number2>.
493 get_number_or_range (char **pp)
495 static int last_retval, end_value;
496 static char *end_ptr;
497 static int in_range = 0;
501 /* Default case: pp is pointing either to a solo number,
502 or to the first number of a range. */
503 last_retval = get_number_trailer (pp, '-');
508 /* This is the start of a range (<number1> - <number2>).
509 Skip the '-', parse and remember the second number,
510 and also remember the end of the final token. */
514 while (isspace ((int) *end_ptr))
515 end_ptr++; /* skip white space */
516 end_value = get_number (temp);
517 if (end_value < last_retval)
519 error (_("inverted range"));
521 else if (end_value == last_retval)
523 /* degenerate range (number1 == number2). Advance the
524 token pointer so that the range will be treated as a
533 error (_("negative value"));
536 /* pp points to the '-' that betokens a range. All
537 number-parsing has already been done. Return the next
538 integer value (one greater than the saved previous value).
539 Do not advance the token pointer 'pp' until the end of range
542 if (++last_retval == end_value)
544 /* End of range reached; advance token pointer. */
554 /* condition N EXP -- set break condition of breakpoint N to EXP. */
557 condition_command (char *arg, int from_tty)
559 struct breakpoint *b;
564 error_no_arg (_("breakpoint number"));
567 bnum = get_number (&p);
569 error (_("Bad breakpoint argument: '%s'"), arg);
572 if (b->number == bnum)
574 struct bp_location *loc = b->loc;
575 for (; loc; loc = loc->next)
583 if (b->cond_string != NULL)
584 xfree (b->cond_string);
588 b->cond_string = NULL;
590 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
595 /* I don't know if it matters whether this is the string the user
596 typed in or the decompiled expression. */
597 b->cond_string = savestring (arg, strlen (arg));
598 b->condition_not_parsed = 0;
599 for (loc = b->loc; loc; loc = loc->next)
602 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
604 error (_("Junk at end of expression"));
607 breakpoints_changed ();
608 breakpoint_modify_event (b->number);
612 error (_("No breakpoint number %d."), bnum);
616 commands_command (char *arg, int from_tty)
618 struct breakpoint *b;
621 struct command_line *l;
623 /* If we allowed this, we would have problems with when to
624 free the storage, if we change the commands currently
627 if (executing_breakpoint_commands)
628 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
631 bnum = get_number (&p);
634 error (_("Unexpected extra arguments following breakpoint number."));
637 if (b->number == bnum)
639 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
641 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
642 l = read_command_lines (tmpbuf, from_tty);
643 do_cleanups (cleanups);
644 free_command_lines (&b->commands);
646 breakpoints_changed ();
647 breakpoint_modify_event (b->number);
650 error (_("No breakpoint number %d."), bnum);
653 /* Like commands_command, but instead of reading the commands from
654 input stream, takes them from an already parsed command structure.
656 This is used by cli-script.c to DTRT with breakpoint commands
657 that are part of if and while bodies. */
658 enum command_control_type
659 commands_from_control_command (char *arg, struct command_line *cmd)
661 struct breakpoint *b;
665 /* If we allowed this, we would have problems with when to
666 free the storage, if we change the commands currently
669 if (executing_breakpoint_commands)
670 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
672 /* An empty string for the breakpoint number means the last
673 breakpoint, but get_number expects a NULL pointer. */
678 bnum = get_number (&p);
681 error (_("Unexpected extra arguments following breakpoint number."));
684 if (b->number == bnum)
686 free_command_lines (&b->commands);
687 if (cmd->body_count != 1)
688 error (_("Invalid \"commands\" block structure."));
689 /* We need to copy the commands because if/while will free the
690 list after it finishes execution. */
691 b->commands = copy_command_lines (cmd->body_list[0]);
692 breakpoints_changed ();
693 breakpoint_modify_event (b->number);
694 return simple_control;
696 error (_("No breakpoint number %d."), bnum);
699 /* Like target_read_memory() but if breakpoints are inserted, return
700 the shadow contents instead of the breakpoints themselves.
702 Read "memory data" from whatever target or inferior we have.
703 Returns zero if successful, errno value if not. EIO is used
704 for address out of bounds. If breakpoints are inserted, returns
705 shadow contents, not the breakpoints themselves. From breakpoint.c. */
708 read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
711 struct bp_location *b;
712 CORE_ADDR bp_addr = 0;
715 if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
716 /* No breakpoints on this machine. */
717 return target_read_memory (memaddr, myaddr, len);
721 if (b->owner->type == bp_none)
722 warning (_("reading through apparently deleted breakpoint #%d?"),
725 if (b->loc_type != bp_loc_software_breakpoint)
729 /* Addresses and length of the part of the breakpoint that
731 bp_addr = b->target_info.placed_address;
732 bp_size = b->target_info.shadow_len;
734 /* bp isn't valid, or doesn't shadow memory. */
736 if (bp_addr + bp_size <= memaddr)
737 /* The breakpoint is entirely before the chunk of memory we
740 if (bp_addr >= memaddr + len)
741 /* The breakpoint is entirely after the chunk of memory we are
744 /* Copy the breakpoint from the shadow contents, and recurse for
745 the things before and after. */
747 /* Offset within shadow_contents. */
750 if (bp_addr < memaddr)
752 /* Only copy the second part of the breakpoint. */
753 bp_size -= memaddr - bp_addr;
754 bptoffset = memaddr - bp_addr;
758 if (bp_addr + bp_size > memaddr + len)
760 /* Only copy the first part of the breakpoint. */
761 bp_size -= (bp_addr + bp_size) - (memaddr + len);
764 memcpy (myaddr + bp_addr - memaddr,
765 b->target_info.shadow_contents + bptoffset, bp_size);
767 if (bp_addr > memaddr)
769 /* Copy the section of memory before the breakpoint. */
770 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
775 if (bp_addr + bp_size < memaddr + len)
777 /* Copy the section of memory after the breakpoint. */
778 status = read_memory_nobpt (bp_addr + bp_size,
779 myaddr + bp_addr + bp_size - memaddr,
780 memaddr + len - (bp_addr + bp_size));
787 /* Nothing overlaps. Just call read_memory_noerr. */
788 return target_read_memory (memaddr, myaddr, len);
792 /* A wrapper function for inserting catchpoints. */
794 insert_catchpoint (struct ui_out *uo, void *args)
796 struct breakpoint *b = (struct breakpoint *) args;
802 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
805 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
808 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
811 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
816 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
819 free_valchain (struct bp_location *b)
824 /* Free the saved value chain. We will construct a new one
825 the next time the watchpoint is inserted. */
826 for (v = b->owner->val_chain; v; v = n)
831 b->owner->val_chain = NULL;
834 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
835 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
836 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
838 NOTE drow/2003-09-09: This routine could be broken down to an object-style
839 method for each breakpoint or catchpoint type. */
841 insert_bp_location (struct bp_location *bpt,
842 struct ui_file *tmp_error_stream,
843 int *disabled_breaks, int *process_warning,
844 int *hw_breakpoint_error)
848 /* Permanent breakpoints cannot be inserted or removed. Disabled
849 breakpoints should not be inserted. */
850 if (!breakpoint_enabled (bpt->owner))
853 if (!bpt->enabled || bpt->shlib_disabled || bpt->inserted || bpt->duplicate)
856 /* Initialize the target-specific information. */
857 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
858 bpt->target_info.placed_address = bpt->address;
860 if (bpt->loc_type == bp_loc_software_breakpoint
861 || bpt->loc_type == bp_loc_hardware_breakpoint)
863 if (bpt->owner->type != bp_hardware_breakpoint)
865 /* If the explicitly specified breakpoint type
866 is not hardware breakpoint, check the memory map to see
867 if the breakpoint address is in read only memory or not.
868 Two important cases are:
869 - location type is not hardware breakpoint, memory
870 is readonly. We change the type of the location to
872 - location type is hardware breakpoint, memory is read-write.
873 This means we've previously made the location hardware one, but
874 then the memory map changed, so we undo.
876 When breakpoints are removed, remove_breakpoints will
877 use location types we've just set here, the only possible
878 problem is that memory map has changed during running program,
879 but it's not going to work anyway with current gdb. */
880 struct mem_region *mr
881 = lookup_mem_region (bpt->target_info.placed_address);
885 if (automatic_hardware_breakpoints)
888 enum bp_loc_type new_type;
890 if (mr->attrib.mode != MEM_RW)
891 new_type = bp_loc_hardware_breakpoint;
893 new_type = bp_loc_software_breakpoint;
895 if (new_type != bpt->loc_type)
898 bpt->loc_type = new_type;
901 fprintf_filtered (gdb_stdout, _("\
902 Note: automatically using hardware breakpoints for read-only addresses.\n"));
907 else if (bpt->loc_type == bp_loc_software_breakpoint
908 && mr->attrib.mode != MEM_RW)
909 warning (_("cannot set software breakpoint at readonly address %s"),
910 paddr (bpt->address));
914 /* First check to see if we have to handle an overlay. */
915 if (overlay_debugging == ovly_off
916 || bpt->section == NULL
917 || !(section_is_overlay (bpt->section)))
919 /* No overlay handling: just set the breakpoint. */
921 if (bpt->loc_type == bp_loc_hardware_breakpoint)
922 val = target_insert_hw_breakpoint (&bpt->target_info);
924 val = target_insert_breakpoint (&bpt->target_info);
928 /* This breakpoint is in an overlay section.
929 Shall we set a breakpoint at the LMA? */
930 if (!overlay_events_enabled)
932 /* Yes -- overlay event support is not active,
933 so we must try to set a breakpoint at the LMA.
934 This will not work for a hardware breakpoint. */
935 if (bpt->loc_type == bp_loc_hardware_breakpoint)
936 warning (_("hardware breakpoint %d not supported in overlay!"),
940 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
942 /* Set a software (trap) breakpoint at the LMA. */
943 bpt->overlay_target_info = bpt->target_info;
944 bpt->overlay_target_info.placed_address = addr;
945 val = target_insert_breakpoint (&bpt->overlay_target_info);
947 fprintf_unfiltered (tmp_error_stream,
948 "Overlay breakpoint %d failed: in ROM?",
952 /* Shall we set a breakpoint at the VMA? */
953 if (section_is_mapped (bpt->section))
955 /* Yes. This overlay section is mapped into memory. */
956 if (bpt->loc_type == bp_loc_hardware_breakpoint)
957 val = target_insert_hw_breakpoint (&bpt->target_info);
959 val = target_insert_breakpoint (&bpt->target_info);
963 /* No. This breakpoint will not be inserted.
964 No error, but do not mark the bp as 'inserted'. */
971 /* Can't set the breakpoint. */
972 if (solib_address (bpt->address))
974 /* See also: disable_breakpoints_in_shlibs. */
976 bpt->shlib_disabled = 1;
977 if (!*disabled_breaks)
979 fprintf_unfiltered (tmp_error_stream,
980 "Cannot insert breakpoint %d.\n",
982 fprintf_unfiltered (tmp_error_stream,
983 "Temporarily disabling shared library breakpoints:\n");
985 *disabled_breaks = 1;
986 fprintf_unfiltered (tmp_error_stream,
987 "breakpoint #%d\n", bpt->owner->number);
991 #ifdef ONE_PROCESS_WRITETEXT
992 *process_warning = 1;
994 if (bpt->loc_type == bp_loc_hardware_breakpoint)
996 *hw_breakpoint_error = 1;
997 fprintf_unfiltered (tmp_error_stream,
998 "Cannot insert hardware breakpoint %d.\n",
1003 fprintf_unfiltered (tmp_error_stream,
1004 "Cannot insert breakpoint %d.\n",
1005 bpt->owner->number);
1006 fprintf_filtered (tmp_error_stream,
1007 "Error accessing memory address ");
1008 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1009 fprintf_filtered (tmp_error_stream, ": %s.\n",
1010 safe_strerror (val));
1021 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1022 /* NOTE drow/2003-09-08: This state only exists for removing
1023 watchpoints. It's not clear that it's necessary... */
1024 && bpt->owner->disposition != disp_del_at_next_stop)
1026 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1027 based on the expression. Ideally this should happen at a higher level,
1028 and there should be one bp_location for each computed address we
1029 must watch. As soon as a many-to-one mapping is available I'll
1032 int within_current_scope;
1033 struct value *mark = value_mark ();
1035 struct frame_id saved_frame_id;
1037 /* Save the current frame's ID so we can restore it after
1038 evaluating the watchpoint expression on its own frame. */
1039 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1040 took a frame parameter, so that we didn't have to change the
1042 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1044 /* Determine if the watchpoint is within scope. */
1045 if (bpt->owner->exp_valid_block == NULL)
1046 within_current_scope = 1;
1049 struct frame_info *fi;
1050 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
1051 within_current_scope = (fi != NULL);
1052 if (within_current_scope)
1056 if (within_current_scope)
1058 free_valchain (bpt);
1060 /* Evaluate the expression and cut the chain of values
1061 produced off from the value chain.
1063 Make sure the value returned isn't lazy; we use
1064 laziness to determine what memory GDB actually needed
1065 in order to compute the value of the expression. */
1066 v = evaluate_expression (bpt->owner->exp);
1068 value_release_to_mark (mark);
1070 bpt->owner->val_chain = v;
1073 /* Look at each value on the value chain. */
1074 for (; v; v = value_next (v))
1076 /* If it's a memory location, and GDB actually needed
1077 its contents to evaluate the expression, then we
1079 if (VALUE_LVAL (v) == lval_memory
1080 && ! value_lazy (v))
1082 struct type *vtype = check_typedef (value_type (v));
1084 /* We only watch structs and arrays if user asked
1085 for it explicitly, never if they just happen to
1086 appear in the middle of some value chain. */
1087 if (v == bpt->owner->val_chain
1088 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1089 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1094 addr = VALUE_ADDRESS (v) + value_offset (v);
1095 len = TYPE_LENGTH (value_type (v));
1097 if (bpt->owner->type == bp_read_watchpoint)
1099 else if (bpt->owner->type == bp_access_watchpoint)
1102 val = target_insert_watchpoint (addr, len, type);
1105 /* Don't exit the loop, try to insert
1106 every value on the value chain. That's
1107 because we will be removing all the
1108 watches below, and removing a
1109 watchpoint we didn't insert could have
1117 /* Failure to insert a watchpoint on any memory value in the
1118 value chain brings us here. */
1121 remove_breakpoint (bpt, mark_uninserted);
1122 *hw_breakpoint_error = 1;
1123 fprintf_unfiltered (tmp_error_stream,
1124 "Could not insert hardware watchpoint %d.\n",
1125 bpt->owner->number);
1131 printf_filtered (_("\
1132 Hardware watchpoint %d deleted because the program has left the block \n\
1133 in which its expression is valid.\n"),
1134 bpt->owner->number);
1135 if (bpt->owner->related_breakpoint)
1136 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1137 bpt->owner->disposition = disp_del_at_next_stop;
1140 /* Restore the selected frame. */
1141 select_frame (frame_find_by_id (saved_frame_id));
1146 else if (ep_is_exception_catchpoint (bpt->owner))
1148 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1149 breakpoint. Once again, it would be better if this was represented
1150 as two bp_locations. */
1152 /* If we get here, we must have a callback mechanism for exception
1153 events -- with g++ style embedded label support, we insert
1154 ordinary breakpoints and not catchpoints. */
1155 val = target_insert_breakpoint (&bpt->target_info);
1158 /* Couldn't set breakpoint for some reason */
1159 fprintf_unfiltered (tmp_error_stream,
1160 "Cannot insert catchpoint %d; disabling it.\n",
1161 bpt->owner->number);
1162 fprintf_filtered (tmp_error_stream,
1163 "Error accessing memory address ");
1164 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1165 fprintf_filtered (tmp_error_stream, ": %s.\n",
1166 safe_strerror (val));
1167 bpt->owner->enable_state = bp_disabled;
1171 /* Bp set, now make sure callbacks are enabled */
1172 /* Format possible error msg */
1173 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1174 bpt->owner->number);
1175 struct cleanup *cleanups = make_cleanup (xfree, message);
1177 args_for_catchpoint_enable args;
1178 args.kind = bpt->owner->type == bp_catch_catch ?
1179 EX_EVENT_CATCH : EX_EVENT_THROW;
1181 val = catch_errors (cover_target_enable_exception_callback,
1182 &args, message, RETURN_MASK_ALL);
1183 do_cleanups (cleanups);
1184 if (val != 0 && val != -1)
1187 /* Check if something went wrong; val == 0 can be ignored */
1190 /* something went wrong */
1191 fprintf_unfiltered (tmp_error_stream,
1192 "Cannot insert catchpoint %d; disabling it.\n",
1193 bpt->owner->number);
1194 bpt->owner->enable_state = bp_disabled;
1201 else if (bpt->owner->type == bp_catch_fork
1202 || bpt->owner->type == bp_catch_vfork
1203 || bpt->owner->type == bp_catch_exec)
1205 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1206 bpt->owner, RETURN_MASK_ERROR);
1207 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1208 bpt->owner->number);
1210 bpt->owner->enable_state = bp_disabled;
1214 /* We've already printed an error message if there was a problem
1215 inserting this catchpoint, and we've disabled the catchpoint,
1216 so just return success. */
1223 /* insert_breakpoints is used when starting or continuing the program.
1224 remove_breakpoints is used when the program stops.
1225 Both return zero if successful,
1226 or an `errno' value if could not write the inferior. */
1229 insert_breakpoints (void)
1231 struct bp_location *b, *temp;
1232 int return_val = 0; /* return success code. */
1234 int disabled_breaks = 0;
1235 int hw_breakpoint_error = 0;
1236 int process_warning = 0;
1238 struct ui_file *tmp_error_stream = mem_fileopen ();
1239 make_cleanup_ui_file_delete (tmp_error_stream);
1241 /* Explicitly mark the warning -- this will only be printed if
1242 there was an error. */
1243 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1245 ALL_BP_LOCATIONS_SAFE (b, temp)
1247 /* Permanent breakpoints cannot be inserted or removed. Disabled
1248 breakpoints should not be inserted. */
1249 if (!breakpoint_enabled (b->owner))
1252 /* There is no point inserting thread-specific breakpoints if the
1253 thread no longer exists. */
1254 if (b->owner->thread != -1
1255 && !valid_thread_id (b->owner->thread))
1258 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1259 hardware watchpoints are split into multiple loc breakpoints. */
1260 if ((b->loc_type == bp_loc_hardware_watchpoint
1261 || b->owner->type == bp_watchpoint) && !b->owner->val)
1264 val = evaluate_expression (b->owner->exp);
1265 release_value (val);
1266 if (value_lazy (val))
1267 value_fetch_lazy (val);
1268 b->owner->val = val;
1271 val = insert_bp_location (b, tmp_error_stream,
1272 &disabled_breaks, &process_warning,
1273 &hw_breakpoint_error);
1280 /* If a hardware breakpoint or watchpoint was inserted, add a
1281 message about possibly exhausted resources. */
1282 if (hw_breakpoint_error)
1284 fprintf_unfiltered (tmp_error_stream,
1285 "Could not insert hardware breakpoints:\n\
1286 You may have requested too many hardware breakpoints/watchpoints.\n");
1288 #ifdef ONE_PROCESS_WRITETEXT
1289 if (process_warning)
1290 fprintf_unfiltered (tmp_error_stream,
1291 "The same program may be running in another process.");
1293 target_terminal_ours_for_output ();
1294 error_stream (tmp_error_stream);
1300 remove_breakpoints (void)
1302 struct bp_location *b;
1305 ALL_BP_LOCATIONS (b)
1309 val = remove_breakpoint (b, mark_uninserted);
1318 remove_hw_watchpoints (void)
1320 struct bp_location *b;
1323 ALL_BP_LOCATIONS (b)
1325 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1327 val = remove_breakpoint (b, mark_uninserted);
1336 reattach_breakpoints (int pid)
1338 struct bp_location *b;
1340 struct cleanup *old_chain = save_inferior_ptid ();
1341 struct ui_file *tmp_error_stream = mem_fileopen ();
1342 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1344 make_cleanup_ui_file_delete (tmp_error_stream);
1346 inferior_ptid = pid_to_ptid (pid);
1347 ALL_BP_LOCATIONS (b)
1352 val = insert_bp_location (b, tmp_error_stream,
1353 &dummy1, &dummy2, &dummy3);
1356 do_cleanups (old_chain);
1361 do_cleanups (old_chain);
1366 update_breakpoints_after_exec (void)
1368 struct breakpoint *b;
1369 struct breakpoint *temp;
1371 /* Doing this first prevents the badness of having delete_breakpoint()
1372 write a breakpoint's current "shadow contents" to lift the bp. That
1373 shadow is NOT valid after an exec()! */
1374 mark_breakpoints_out ();
1376 ALL_BREAKPOINTS_SAFE (b, temp)
1378 /* Solib breakpoints must be explicitly reset after an exec(). */
1379 if (b->type == bp_shlib_event)
1381 delete_breakpoint (b);
1385 /* Thread event breakpoints must be set anew after an exec(),
1386 as must overlay event breakpoints. */
1387 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1389 delete_breakpoint (b);
1393 /* Step-resume breakpoints are meaningless after an exec(). */
1394 if (b->type == bp_step_resume)
1396 delete_breakpoint (b);
1400 /* Ditto the exception-handling catchpoints. */
1401 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1403 delete_breakpoint (b);
1407 /* Don't delete an exec catchpoint, because else the inferior
1408 won't stop when it ought!
1410 Similarly, we probably ought to keep vfork catchpoints, 'cause
1411 on this target, we may not be able to stop when the vfork is
1412 seen, but only when the subsequent exec is seen. (And because
1413 deleting fork catchpoints here but not vfork catchpoints will
1414 seem mysterious to users, keep those too.) */
1415 if ((b->type == bp_catch_exec) ||
1416 (b->type == bp_catch_vfork) ||
1417 (b->type == bp_catch_fork))
1422 /* bp_finish is a special case. The only way we ought to be able
1423 to see one of these when an exec() has happened, is if the user
1424 caught a vfork, and then said "finish". Ordinarily a finish just
1425 carries them to the call-site of the current callee, by setting
1426 a temporary bp there and resuming. But in this case, the finish
1427 will carry them entirely through the vfork & exec.
1429 We don't want to allow a bp_finish to remain inserted now. But
1430 we can't safely delete it, 'cause finish_command has a handle to
1431 the bp on a bpstat, and will later want to delete it. There's a
1432 chance (and I've seen it happen) that if we delete the bp_finish
1433 here, that its storage will get reused by the time finish_command
1434 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1435 We really must allow finish_command to delete a bp_finish.
1437 In the absense of a general solution for the "how do we know
1438 it's safe to delete something others may have handles to?"
1439 problem, what we'll do here is just uninsert the bp_finish, and
1440 let finish_command delete it.
1442 (We know the bp_finish is "doomed" in the sense that it's
1443 momentary, and will be deleted as soon as finish_command sees
1444 the inferior stopped. So it doesn't matter that the bp's
1445 address is probably bogus in the new a.out, unlike e.g., the
1446 solib breakpoints.) */
1448 if (b->type == bp_finish)
1453 /* Without a symbolic address, we have little hope of the
1454 pre-exec() address meaning the same thing in the post-exec()
1456 if (b->addr_string == NULL)
1458 delete_breakpoint (b);
1462 /* FIXME what about longjmp breakpoints? Re-create them here? */
1463 create_overlay_event_breakpoint ("_ovly_debug_event");
1467 detach_breakpoints (int pid)
1469 struct bp_location *b;
1471 struct cleanup *old_chain = save_inferior_ptid ();
1473 if (pid == PIDGET (inferior_ptid))
1474 error (_("Cannot detach breakpoints of inferior_ptid"));
1476 /* Set inferior_ptid; remove_breakpoint uses this global. */
1477 inferior_ptid = pid_to_ptid (pid);
1478 ALL_BP_LOCATIONS (b)
1482 val = remove_breakpoint (b, mark_inserted);
1485 do_cleanups (old_chain);
1490 do_cleanups (old_chain);
1495 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1499 if (b->owner->enable_state == bp_permanent)
1500 /* Permanent breakpoints cannot be inserted or removed. */
1503 if (b->owner->type == bp_none)
1504 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1507 if (b->loc_type == bp_loc_software_breakpoint
1508 || b->loc_type == bp_loc_hardware_breakpoint)
1510 /* "Normal" instruction breakpoint: either the standard
1511 trap-instruction bp (bp_breakpoint), or a
1512 bp_hardware_breakpoint. */
1514 /* First check to see if we have to handle an overlay. */
1515 if (overlay_debugging == ovly_off
1516 || b->section == NULL
1517 || !(section_is_overlay (b->section)))
1519 /* No overlay handling: just remove the breakpoint. */
1521 if (b->loc_type == bp_loc_hardware_breakpoint)
1522 val = target_remove_hw_breakpoint (&b->target_info);
1524 val = target_remove_breakpoint (&b->target_info);
1528 /* This breakpoint is in an overlay section.
1529 Did we set a breakpoint at the LMA? */
1530 if (!overlay_events_enabled)
1532 /* Yes -- overlay event support is not active, so we
1533 should have set a breakpoint at the LMA. Remove it.
1535 /* Ignore any failures: if the LMA is in ROM, we will
1536 have already warned when we failed to insert it. */
1537 if (b->loc_type == bp_loc_hardware_breakpoint)
1538 target_remove_hw_breakpoint (&b->overlay_target_info);
1540 target_remove_breakpoint (&b->overlay_target_info);
1542 /* Did we set a breakpoint at the VMA?
1543 If so, we will have marked the breakpoint 'inserted'. */
1546 /* Yes -- remove it. Previously we did not bother to
1547 remove the breakpoint if the section had been
1548 unmapped, but let's not rely on that being safe. We
1549 don't know what the overlay manager might do. */
1550 if (b->loc_type == bp_loc_hardware_breakpoint)
1551 val = target_remove_hw_breakpoint (&b->target_info);
1553 /* However, we should remove *software* breakpoints only
1554 if the section is still mapped, or else we overwrite
1555 wrong code with the saved shadow contents. */
1556 else if (section_is_mapped (b->section))
1557 val = target_remove_breakpoint (&b->target_info);
1563 /* No -- not inserted, so no need to remove. No error. */
1569 b->inserted = (is == mark_inserted);
1571 else if (b->loc_type == bp_loc_hardware_watchpoint
1572 && breakpoint_enabled (b->owner)
1578 b->inserted = (is == mark_inserted);
1579 /* Walk down the saved value chain. */
1580 for (v = b->owner->val_chain; v; v = value_next (v))
1582 /* For each memory reference remove the watchpoint
1584 if (VALUE_LVAL (v) == lval_memory
1585 && ! value_lazy (v))
1587 struct type *vtype = check_typedef (value_type (v));
1589 if (v == b->owner->val_chain
1590 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1591 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1596 addr = VALUE_ADDRESS (v) + value_offset (v);
1597 len = TYPE_LENGTH (value_type (v));
1599 if (b->owner->type == bp_read_watchpoint)
1601 else if (b->owner->type == bp_access_watchpoint)
1604 val = target_remove_watchpoint (addr, len, type);
1611 /* Failure to remove any of the hardware watchpoints comes here. */
1612 if ((is == mark_uninserted) && (b->inserted))
1613 warning (_("Could not remove hardware watchpoint %d."),
1616 else if ((b->owner->type == bp_catch_fork ||
1617 b->owner->type == bp_catch_vfork ||
1618 b->owner->type == bp_catch_exec)
1619 && breakpoint_enabled (b->owner)
1623 switch (b->owner->type)
1626 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1628 case bp_catch_vfork:
1629 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1632 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1635 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1640 b->inserted = (is == mark_inserted);
1642 else if ((b->owner->type == bp_catch_catch ||
1643 b->owner->type == bp_catch_throw)
1644 && breakpoint_enabled (b->owner)
1647 val = target_remove_breakpoint (&b->target_info);
1650 b->inserted = (is == mark_inserted);
1656 /* Clear the "inserted" flag in all breakpoints. */
1659 mark_breakpoints_out (void)
1661 struct bp_location *bpt;
1663 ALL_BP_LOCATIONS (bpt)
1667 /* Clear the "inserted" flag in all breakpoints and delete any
1668 breakpoints which should go away between runs of the program.
1670 Plus other such housekeeping that has to be done for breakpoints
1673 Note: this function gets called at the end of a run (by
1674 generic_mourn_inferior) and when a run begins (by
1675 init_wait_for_inferior). */
1680 breakpoint_init_inferior (enum inf_context context)
1682 struct breakpoint *b, *temp;
1683 struct bp_location *bpt;
1685 ALL_BP_LOCATIONS (bpt)
1688 ALL_BREAKPOINTS_SAFE (b, temp)
1693 case bp_watchpoint_scope:
1695 /* If the call dummy breakpoint is at the entry point it will
1696 cause problems when the inferior is rerun, so we better
1699 Also get rid of scope breakpoints. */
1700 delete_breakpoint (b);
1704 case bp_hardware_watchpoint:
1705 case bp_read_watchpoint:
1706 case bp_access_watchpoint:
1708 /* Likewise for watchpoints on local expressions. */
1709 if (b->exp_valid_block != NULL)
1710 delete_breakpoint (b);
1711 else if (context == inf_starting)
1713 /* Reset val field to force reread of starting value
1714 in insert_breakpoints. */
1716 value_free (b->val);
1726 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1727 exists at PC. It returns ordinary_breakpoint_here if it's an
1728 ordinary breakpoint, or permanent_breakpoint_here if it's a
1729 permanent breakpoint.
1730 - When continuing from a location with an ordinary breakpoint, we
1731 actually single step once before calling insert_breakpoints.
1732 - When continuing from a localion with a permanent breakpoint, we
1733 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1734 the target, to advance the PC past the breakpoint. */
1736 enum breakpoint_here
1737 breakpoint_here_p (CORE_ADDR pc)
1739 struct bp_location *bpt;
1740 int any_breakpoint_here = 0;
1742 ALL_BP_LOCATIONS (bpt)
1744 if (bpt->loc_type != bp_loc_software_breakpoint
1745 && bpt->loc_type != bp_loc_hardware_breakpoint)
1748 if ((breakpoint_enabled (bpt->owner)
1749 || bpt->owner->enable_state == bp_permanent)
1750 && bpt->address == pc) /* bp is enabled and matches pc */
1752 if (overlay_debugging
1753 && section_is_overlay (bpt->section)
1754 && !section_is_mapped (bpt->section))
1755 continue; /* unmapped overlay -- can't be a match */
1756 else if (bpt->owner->enable_state == bp_permanent)
1757 return permanent_breakpoint_here;
1759 any_breakpoint_here = 1;
1763 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1767 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1768 but it only returns true if there is actually a breakpoint inserted
1772 breakpoint_inserted_here_p (CORE_ADDR pc)
1774 struct bp_location *bpt;
1776 ALL_BP_LOCATIONS (bpt)
1778 if (bpt->loc_type != bp_loc_software_breakpoint
1779 && bpt->loc_type != bp_loc_hardware_breakpoint)
1783 && bpt->address == pc) /* bp is inserted and matches pc */
1785 if (overlay_debugging
1786 && section_is_overlay (bpt->section)
1787 && !section_is_mapped (bpt->section))
1788 continue; /* unmapped overlay -- can't be a match */
1794 /* Also check for software single-step breakpoints. */
1795 if (single_step_breakpoint_inserted_here_p (pc))
1801 /* This function returns non-zero iff there is a software breakpoint
1805 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1807 struct bp_location *bpt;
1808 int any_breakpoint_here = 0;
1810 ALL_BP_LOCATIONS (bpt)
1812 if (bpt->loc_type != bp_loc_software_breakpoint)
1816 && bpt->address == pc) /* bp is enabled and matches pc */
1818 if (overlay_debugging
1819 && section_is_overlay (bpt->section)
1820 && !section_is_mapped (bpt->section))
1821 continue; /* unmapped overlay -- can't be a match */
1827 /* Also check for software single-step breakpoints. */
1828 if (single_step_breakpoint_inserted_here_p (pc))
1834 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1835 PC is valid for process/thread PTID. */
1838 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1840 struct bp_location *bpt;
1843 thread = pid_to_thread_id (ptid);
1845 ALL_BP_LOCATIONS (bpt)
1847 if (bpt->loc_type != bp_loc_software_breakpoint
1848 && bpt->loc_type != bp_loc_hardware_breakpoint)
1851 if ((breakpoint_enabled (bpt->owner)
1852 || bpt->owner->enable_state == bp_permanent)
1853 && bpt->address == pc
1854 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1856 if (overlay_debugging
1857 && section_is_overlay (bpt->section)
1858 && !section_is_mapped (bpt->section))
1859 continue; /* unmapped overlay -- can't be a match */
1869 /* bpstat stuff. External routines' interfaces are documented
1873 ep_is_catchpoint (struct breakpoint *ep)
1876 (ep->type == bp_catch_load)
1877 || (ep->type == bp_catch_unload)
1878 || (ep->type == bp_catch_fork)
1879 || (ep->type == bp_catch_vfork)
1880 || (ep->type == bp_catch_exec)
1881 || (ep->type == bp_catch_catch)
1882 || (ep->type == bp_catch_throw);
1884 /* ??rehrauer: Add more kinds here, as are implemented... */
1888 ep_is_shlib_catchpoint (struct breakpoint *ep)
1891 (ep->type == bp_catch_load)
1892 || (ep->type == bp_catch_unload);
1896 ep_is_exception_catchpoint (struct breakpoint *ep)
1899 (ep->type == bp_catch_catch)
1900 || (ep->type == bp_catch_throw);
1904 bpstat_free (bpstat bs)
1906 if (bs->old_val != NULL)
1907 value_free (bs->old_val);
1908 free_command_lines (&bs->commands);
1912 /* Clear a bpstat so that it says we are not at any breakpoint.
1913 Also free any storage that is part of a bpstat. */
1916 bpstat_clear (bpstat *bsp)
1933 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1934 is part of the bpstat is copied as well. */
1937 bpstat_copy (bpstat bs)
1941 bpstat retval = NULL;
1946 for (; bs != NULL; bs = bs->next)
1948 tmp = (bpstat) xmalloc (sizeof (*tmp));
1949 memcpy (tmp, bs, sizeof (*tmp));
1950 if (bs->commands != NULL)
1951 tmp->commands = copy_command_lines (bs->commands);
1952 if (bs->old_val != NULL)
1953 tmp->old_val = value_copy (bs->old_val);
1956 /* This is the first thing in the chain. */
1966 /* Find the bpstat associated with this breakpoint */
1969 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1974 for (; bsp != NULL; bsp = bsp->next)
1976 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
1982 /* Find a step_resume breakpoint associated with this bpstat.
1983 (If there are multiple step_resume bp's on the list, this function
1984 will arbitrarily pick one.)
1986 It is an error to use this function if BPSTAT doesn't contain a
1987 step_resume breakpoint.
1989 See wait_for_inferior's use of this function. */
1991 bpstat_find_step_resume_breakpoint (bpstat bsp)
1995 gdb_assert (bsp != NULL);
1997 current_thread = pid_to_thread_id (inferior_ptid);
1999 for (; bsp != NULL; bsp = bsp->next)
2001 if ((bsp->breakpoint_at != NULL) &&
2002 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2003 (bsp->breakpoint_at->owner->thread == current_thread ||
2004 bsp->breakpoint_at->owner->thread == -1))
2005 return bsp->breakpoint_at->owner;
2008 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2012 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2013 at. *BSP upon return is a bpstat which points to the remaining
2014 breakpoints stopped at (but which is not guaranteed to be good for
2015 anything but further calls to bpstat_num).
2016 Return 0 if passed a bpstat which does not indicate any breakpoints.
2017 Return -1 if stopped at a breakpoint that has been deleted since
2019 Return 1 otherwise. */
2022 bpstat_num (bpstat *bsp, int *num)
2024 struct breakpoint *b;
2027 return 0; /* No more breakpoint values */
2029 /* We assume we'll never have several bpstats that
2030 correspond to a single breakpoint -- otherwise,
2031 this function might return the same number more
2032 than once and this will look ugly. */
2033 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2034 *bsp = (*bsp)->next;
2036 return -1; /* breakpoint that's been deleted since */
2038 *num = b->number; /* We have its number */
2042 /* Modify BS so that the actions will not be performed. */
2045 bpstat_clear_actions (bpstat bs)
2047 for (; bs != NULL; bs = bs->next)
2049 free_command_lines (&bs->commands);
2050 if (bs->old_val != NULL)
2052 value_free (bs->old_val);
2058 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2060 cleanup_executing_breakpoints (void *ignore)
2062 executing_breakpoint_commands = 0;
2065 /* Execute all the commands associated with all the breakpoints at this
2066 location. Any of these commands could cause the process to proceed
2067 beyond this point, etc. We look out for such changes by checking
2068 the global "breakpoint_proceeded" after each command. */
2071 bpstat_do_actions (bpstat *bsp)
2074 struct cleanup *old_chain;
2076 /* Avoid endless recursion if a `source' command is contained
2078 if (executing_breakpoint_commands)
2081 executing_breakpoint_commands = 1;
2082 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2085 /* Note that (as of this writing), our callers all appear to
2086 be passing us the address of global stop_bpstat. And, if
2087 our calls to execute_control_command cause the inferior to
2088 proceed, that global (and hence, *bsp) will change.
2090 We must be careful to not touch *bsp unless the inferior
2091 has not proceeded. */
2093 /* This pointer will iterate over the list of bpstat's. */
2096 breakpoint_proceeded = 0;
2097 for (; bs != NULL; bs = bs->next)
2099 struct command_line *cmd;
2100 struct cleanup *this_cmd_tree_chain;
2102 /* Take ownership of the BSP's command tree, if it has one.
2104 The command tree could legitimately contain commands like
2105 'step' and 'next', which call clear_proceed_status, which
2106 frees stop_bpstat's command tree. To make sure this doesn't
2107 free the tree we're executing out from under us, we need to
2108 take ownership of the tree ourselves. Since a given bpstat's
2109 commands are only executed once, we don't need to copy it; we
2110 can clear the pointer in the bpstat, and make sure we free
2111 the tree when we're done. */
2114 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2118 execute_control_command (cmd);
2120 if (breakpoint_proceeded)
2126 /* We can free this command tree now. */
2127 do_cleanups (this_cmd_tree_chain);
2129 if (breakpoint_proceeded)
2130 /* The inferior is proceeded by the command; bomb out now.
2131 The bpstat chain has been blown away by wait_for_inferior.
2132 But since execution has stopped again, there is a new bpstat
2133 to look at, so start over. */
2136 do_cleanups (old_chain);
2139 /* This is the normal print function for a bpstat. In the future,
2140 much of this logic could (should?) be moved to bpstat_stop_status,
2141 by having it set different print_it values.
2143 Current scheme: When we stop, bpstat_print() is called. It loops
2144 through the bpstat list of things causing this stop, calling the
2145 print_bp_stop_message function on each one. The behavior of the
2146 print_bp_stop_message function depends on the print_it field of
2147 bpstat. If such field so indicates, call this function here.
2149 Return values from this routine (ultimately used by bpstat_print()
2150 and normal_stop() to decide what to do):
2151 PRINT_NOTHING: Means we already printed all we needed to print,
2152 don't print anything else.
2153 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2154 that something to be followed by a location.
2155 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2156 that something to be followed by a location.
2157 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2160 static enum print_stop_action
2161 print_it_typical (bpstat bs)
2163 struct cleanup *old_chain, *ui_out_chain;
2164 struct breakpoint *b;
2165 struct bp_location *bl;
2166 struct ui_stream *stb;
2167 stb = ui_out_stream_new (uiout);
2168 old_chain = make_cleanup_ui_out_stream_delete (stb);
2169 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2170 which has since been deleted. */
2171 if (bs->breakpoint_at == NULL)
2172 return PRINT_UNKNOWN;
2173 bl = bs->breakpoint_at;
2179 case bp_hardware_breakpoint:
2180 if (bl->address != bl->requested_address)
2181 breakpoint_adjustment_warning (bl->requested_address,
2184 annotate_breakpoint (b->number);
2185 ui_out_text (uiout, "\nBreakpoint ");
2186 if (ui_out_is_mi_like_p (uiout))
2187 ui_out_field_string (uiout, "reason",
2188 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2189 ui_out_field_int (uiout, "bkptno", b->number);
2190 ui_out_text (uiout, ", ");
2191 return PRINT_SRC_AND_LOC;
2194 case bp_shlib_event:
2195 /* Did we stop because the user set the stop_on_solib_events
2196 variable? (If so, we report this as a generic, "Stopped due
2197 to shlib event" message.) */
2198 printf_filtered (_("Stopped due to shared library event\n"));
2199 return PRINT_NOTHING;
2202 case bp_thread_event:
2203 /* Not sure how we will get here.
2204 GDB should not stop for these breakpoints. */
2205 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2206 return PRINT_NOTHING;
2209 case bp_overlay_event:
2210 /* By analogy with the thread event, GDB should not stop for these. */
2211 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2212 return PRINT_NOTHING;
2216 annotate_catchpoint (b->number);
2217 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2219 b->triggered_dll_pathname);
2220 return PRINT_SRC_AND_LOC;
2223 case bp_catch_unload:
2224 annotate_catchpoint (b->number);
2225 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2227 b->triggered_dll_pathname);
2228 return PRINT_SRC_AND_LOC;
2232 annotate_catchpoint (b->number);
2233 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2235 b->forked_inferior_pid);
2236 return PRINT_SRC_AND_LOC;
2239 case bp_catch_vfork:
2240 annotate_catchpoint (b->number);
2241 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2243 b->forked_inferior_pid);
2244 return PRINT_SRC_AND_LOC;
2248 annotate_catchpoint (b->number);
2249 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2252 return PRINT_SRC_AND_LOC;
2255 case bp_catch_catch:
2256 if (current_exception_event &&
2257 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2259 annotate_catchpoint (b->number);
2260 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2262 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2263 printf_filtered (_("throw location %s:%d, "),
2264 CURRENT_EXCEPTION_THROW_FILE,
2265 CURRENT_EXCEPTION_THROW_LINE);
2267 printf_filtered (_("throw location unknown, "));
2269 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2270 printf_filtered (_("catch location %s:%d\n"),
2271 CURRENT_EXCEPTION_CATCH_FILE,
2272 CURRENT_EXCEPTION_CATCH_LINE);
2274 printf_filtered (_("catch location unknown\n"));
2276 /* don't bother to print location frame info */
2277 return PRINT_SRC_ONLY;
2281 /* really throw, some other bpstat will handle it */
2282 return PRINT_UNKNOWN;
2286 case bp_catch_throw:
2287 if (current_exception_event &&
2288 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2290 annotate_catchpoint (b->number);
2291 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2293 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2294 printf_filtered (_("throw location %s:%d, "),
2295 CURRENT_EXCEPTION_THROW_FILE,
2296 CURRENT_EXCEPTION_THROW_LINE);
2298 printf_filtered (_("throw location unknown, "));
2300 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2301 printf_filtered (_("catch location %s:%d\n"),
2302 CURRENT_EXCEPTION_CATCH_FILE,
2303 CURRENT_EXCEPTION_CATCH_LINE);
2305 printf_filtered (_("catch location unknown\n"));
2307 /* don't bother to print location frame info */
2308 return PRINT_SRC_ONLY;
2312 /* really catch, some other bpstat will handle it */
2313 return PRINT_UNKNOWN;
2318 case bp_hardware_watchpoint:
2319 if (bs->old_val != NULL)
2321 annotate_watchpoint (b->number);
2322 if (ui_out_is_mi_like_p (uiout))
2325 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2327 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2328 ui_out_text (uiout, "\nOld value = ");
2329 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2330 ui_out_field_stream (uiout, "old", stb);
2331 ui_out_text (uiout, "\nNew value = ");
2332 value_print (b->val, stb->stream, 0, Val_pretty_default);
2333 ui_out_field_stream (uiout, "new", stb);
2334 do_cleanups (ui_out_chain);
2335 ui_out_text (uiout, "\n");
2336 value_free (bs->old_val);
2339 /* More than one watchpoint may have been triggered. */
2340 return PRINT_UNKNOWN;
2343 case bp_read_watchpoint:
2344 if (ui_out_is_mi_like_p (uiout))
2347 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2349 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2350 ui_out_text (uiout, "\nValue = ");
2351 value_print (b->val, stb->stream, 0, Val_pretty_default);
2352 ui_out_field_stream (uiout, "value", stb);
2353 do_cleanups (ui_out_chain);
2354 ui_out_text (uiout, "\n");
2355 return PRINT_UNKNOWN;
2358 case bp_access_watchpoint:
2359 if (bs->old_val != NULL)
2361 annotate_watchpoint (b->number);
2362 if (ui_out_is_mi_like_p (uiout))
2365 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2367 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2368 ui_out_text (uiout, "\nOld value = ");
2369 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2370 ui_out_field_stream (uiout, "old", stb);
2371 value_free (bs->old_val);
2373 ui_out_text (uiout, "\nNew value = ");
2378 if (ui_out_is_mi_like_p (uiout))
2381 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2382 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2383 ui_out_text (uiout, "\nValue = ");
2385 value_print (b->val, stb->stream, 0,Val_pretty_default);
2386 ui_out_field_stream (uiout, "new", stb);
2387 do_cleanups (ui_out_chain);
2388 ui_out_text (uiout, "\n");
2389 return PRINT_UNKNOWN;
2392 /* Fall through, we don't deal with these types of breakpoints
2396 if (ui_out_is_mi_like_p (uiout))
2399 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2400 return PRINT_UNKNOWN;
2404 if (ui_out_is_mi_like_p (uiout))
2407 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2408 return PRINT_UNKNOWN;
2413 case bp_longjmp_resume:
2414 case bp_step_resume:
2415 case bp_watchpoint_scope:
2418 return PRINT_UNKNOWN;
2422 /* Generic routine for printing messages indicating why we
2423 stopped. The behavior of this function depends on the value
2424 'print_it' in the bpstat structure. Under some circumstances we
2425 may decide not to print anything here and delegate the task to
2428 static enum print_stop_action
2429 print_bp_stop_message (bpstat bs)
2431 switch (bs->print_it)
2434 /* Nothing should be printed for this bpstat entry. */
2435 return PRINT_UNKNOWN;
2439 /* We still want to print the frame, but we already printed the
2440 relevant messages. */
2441 return PRINT_SRC_AND_LOC;
2444 case print_it_normal:
2446 struct bp_location *bl = bs->breakpoint_at;
2447 struct breakpoint *b = bl ? bl->owner : NULL;
2449 /* Normal case. Call the breakpoint's print_it method, or
2450 print_it_typical. */
2451 /* FIXME: how breakpoint can ever be NULL here? */
2452 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2453 return b->ops->print_it (b);
2455 return print_it_typical (bs);
2460 internal_error (__FILE__, __LINE__,
2461 _("print_bp_stop_message: unrecognized enum value"));
2466 /* Print a message indicating what happened. This is called from
2467 normal_stop(). The input to this routine is the head of the bpstat
2468 list - a list of the eventpoints that caused this stop. This
2469 routine calls the generic print routine for printing a message
2470 about reasons for stopping. This will print (for example) the
2471 "Breakpoint n," part of the output. The return value of this
2474 PRINT_UNKNOWN: Means we printed nothing
2475 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2476 code to print the location. An example is
2477 "Breakpoint 1, " which should be followed by
2479 PRINT_SRC_ONLY: Means we printed something, but there is no need
2480 to also print the location part of the message.
2481 An example is the catch/throw messages, which
2482 don't require a location appended to the end.
2483 PRINT_NOTHING: We have done some printing and we don't need any
2484 further info to be printed.*/
2486 enum print_stop_action
2487 bpstat_print (bpstat bs)
2491 /* Maybe another breakpoint in the chain caused us to stop.
2492 (Currently all watchpoints go on the bpstat whether hit or not.
2493 That probably could (should) be changed, provided care is taken
2494 with respect to bpstat_explains_signal). */
2495 for (; bs; bs = bs->next)
2497 val = print_bp_stop_message (bs);
2498 if (val == PRINT_SRC_ONLY
2499 || val == PRINT_SRC_AND_LOC
2500 || val == PRINT_NOTHING)
2504 /* We reached the end of the chain, or we got a null BS to start
2505 with and nothing was printed. */
2506 return PRINT_UNKNOWN;
2509 /* Evaluate the expression EXP and return 1 if value is zero.
2510 This is used inside a catch_errors to evaluate the breakpoint condition.
2511 The argument is a "struct expression *" that has been cast to char * to
2512 make it pass through catch_errors. */
2515 breakpoint_cond_eval (void *exp)
2517 struct value *mark = value_mark ();
2518 int i = !value_true (evaluate_expression ((struct expression *) exp));
2519 value_free_to_mark (mark);
2523 /* Allocate a new bpstat and chain it to the current one. */
2526 bpstat_alloc (struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2530 bs = (bpstat) xmalloc (sizeof (*bs));
2532 bs->breakpoint_at = bl;
2533 /* If the condition is false, etc., don't do the commands. */
2534 bs->commands = NULL;
2536 bs->print_it = print_it_normal;
2540 /* Possible return values for watchpoint_check (this can't be an enum
2541 because of check_errors). */
2542 /* The watchpoint has been deleted. */
2543 #define WP_DELETED 1
2544 /* The value has changed. */
2545 #define WP_VALUE_CHANGED 2
2546 /* The value has not changed. */
2547 #define WP_VALUE_NOT_CHANGED 3
2549 #define BP_TEMPFLAG 1
2550 #define BP_HARDWAREFLAG 2
2552 /* Check watchpoint condition. */
2555 watchpoint_check (void *p)
2557 bpstat bs = (bpstat) p;
2558 struct breakpoint *b;
2559 struct frame_info *fr;
2560 int within_current_scope;
2562 b = bs->breakpoint_at->owner;
2564 if (b->exp_valid_block == NULL)
2565 within_current_scope = 1;
2568 /* There is no current frame at this moment. If we're going to have
2569 any chance of handling watchpoints on local variables, we'll need
2570 the frame chain (so we can determine if we're in scope). */
2571 reinit_frame_cache ();
2572 fr = frame_find_by_id (b->watchpoint_frame);
2573 within_current_scope = (fr != NULL);
2575 /* If we've gotten confused in the unwinder, we might have
2576 returned a frame that can't describe this variable. */
2577 if (within_current_scope
2578 && block_function (b->exp_valid_block) != get_frame_function (fr))
2579 within_current_scope = 0;
2581 /* in_function_epilogue_p() returns a non-zero value if we're still
2582 in the function but the stack frame has already been invalidated.
2583 Since we can't rely on the values of local variables after the
2584 stack has been destroyed, we are treating the watchpoint in that
2585 state as `not changed' without further checking.
2587 vinschen/2003-09-04: The former implementation left out the case
2588 that the watchpoint frame couldn't be found by frame_find_by_id()
2589 because the current PC is currently in an epilogue. Calling
2590 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2591 if ((!within_current_scope || fr == get_current_frame ())
2592 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2593 return WP_VALUE_NOT_CHANGED;
2594 if (fr && within_current_scope)
2595 /* If we end up stopping, the current frame will get selected
2596 in normal_stop. So this call to select_frame won't affect
2601 if (within_current_scope)
2603 /* We use value_{,free_to_}mark because it could be a
2604 *long* time before we return to the command level and
2605 call free_all_values. We can't call free_all_values because
2606 we might be in the middle of evaluating a function call. */
2608 struct value *mark = value_mark ();
2609 struct value *new_val = evaluate_expression (b->exp);
2610 if (!value_equal (b->val, new_val))
2612 release_value (new_val);
2613 value_free_to_mark (mark);
2614 bs->old_val = b->val;
2616 /* We will stop here */
2617 return WP_VALUE_CHANGED;
2621 /* Nothing changed, don't do anything. */
2622 value_free_to_mark (mark);
2623 /* We won't stop here */
2624 return WP_VALUE_NOT_CHANGED;
2629 /* This seems like the only logical thing to do because
2630 if we temporarily ignored the watchpoint, then when
2631 we reenter the block in which it is valid it contains
2632 garbage (in the case of a function, it may have two
2633 garbage values, one before and one after the prologue).
2634 So we can't even detect the first assignment to it and
2635 watch after that (since the garbage may or may not equal
2636 the first value assigned). */
2637 /* We print all the stop information in print_it_typical(), but
2638 in this case, by the time we call print_it_typical() this bp
2639 will be deleted already. So we have no choice but print the
2640 information here. */
2641 if (ui_out_is_mi_like_p (uiout))
2643 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2644 ui_out_text (uiout, "\nWatchpoint ");
2645 ui_out_field_int (uiout, "wpnum", b->number);
2646 ui_out_text (uiout, " deleted because the program has left the block in\n\
2647 which its expression is valid.\n");
2649 if (b->related_breakpoint)
2650 b->related_breakpoint->disposition = disp_del_at_next_stop;
2651 b->disposition = disp_del_at_next_stop;
2657 /* Get a bpstat associated with having just stopped at address
2658 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2659 target thinks we stopped due to a hardware watchpoint, 0 if we
2660 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2662 /* Determine whether we stopped at a breakpoint, etc, or whether we
2663 don't understand this stop. Result is a chain of bpstat's such that:
2665 if we don't understand the stop, the result is a null pointer.
2667 if we understand why we stopped, the result is not null.
2669 Each element of the chain refers to a particular breakpoint or
2670 watchpoint at which we have stopped. (We may have stopped for
2671 several reasons concurrently.)
2673 Each element of the chain has valid next, breakpoint_at,
2674 commands, FIXME??? fields. */
2677 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
2679 struct breakpoint *b = NULL;
2680 struct bp_location *bl;
2681 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2682 int real_breakpoint = 0;
2683 /* Root of the chain of bpstat's */
2684 struct bpstats root_bs[1];
2685 /* Pointer to the last thing in the chain currently. */
2686 bpstat bs = root_bs;
2687 int thread_id = pid_to_thread_id (ptid);
2689 ALL_BP_LOCATIONS (bl)
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 (bl->address != bp_addr) /* address doesn't match */
2709 if (overlay_debugging /* unmapped overlay section */
2710 && section_is_overlay (bl->section)
2711 && !section_is_mapped (bl->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 (bl->address != bp_addr)
2731 if (overlay_debugging /* unmapped overlay section */
2732 && section_is_overlay (bl->section)
2733 && !section_is_mapped (bl->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 (bl, 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, (bl->cond),
2943 "Error in testing breakpoint condition:\n",
2945 /* FIXME-someday, should give breakpoint # */
2948 if (bl->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 (b->type == bp_hardware_watchpoint ||
2996 b->type == bp_read_watchpoint ||
2997 b->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->owner->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->owner;
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_list->breakpoint_at, 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 static void print_breakpoint_location (struct breakpoint *b,
3360 struct bp_location *loc,
3362 struct ui_stream *stb)
3367 = find_pc_sect_function (loc->address, loc->section);
3370 ui_out_text (uiout, "in ");
3371 ui_out_field_string (uiout, "func",
3372 SYMBOL_PRINT_NAME (sym));
3373 ui_out_wrap_hint (uiout, wrap_indent);
3374 ui_out_text (uiout, " at ");
3376 ui_out_field_string (uiout, "file", b->source_file);
3377 ui_out_text (uiout, ":");
3379 if (ui_out_is_mi_like_p (uiout))
3381 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3382 char *fullname = symtab_to_fullname (sal.symtab);
3385 ui_out_field_string (uiout, "fullname", fullname);
3388 ui_out_field_int (uiout, "line", b->line_number);
3392 ui_out_field_string (uiout, "pending", b->addr_string);
3396 print_address_symbolic (loc->address, stb->stream, demangle, "");
3397 ui_out_field_stream (uiout, "at", stb);
3401 /* Print B to gdb_stdout. */
3403 print_one_breakpoint_location (struct breakpoint *b,
3404 struct bp_location *loc,
3406 CORE_ADDR *last_addr)
3408 struct command_line *l;
3410 struct ep_type_description
3415 static struct ep_type_description bptypes[] =
3417 {bp_none, "?deleted?"},
3418 {bp_breakpoint, "breakpoint"},
3419 {bp_hardware_breakpoint, "hw breakpoint"},
3420 {bp_until, "until"},
3421 {bp_finish, "finish"},
3422 {bp_watchpoint, "watchpoint"},
3423 {bp_hardware_watchpoint, "hw watchpoint"},
3424 {bp_read_watchpoint, "read watchpoint"},
3425 {bp_access_watchpoint, "acc watchpoint"},
3426 {bp_longjmp, "longjmp"},
3427 {bp_longjmp_resume, "longjmp resume"},
3428 {bp_step_resume, "step resume"},
3429 {bp_watchpoint_scope, "watchpoint scope"},
3430 {bp_call_dummy, "call dummy"},
3431 {bp_shlib_event, "shlib events"},
3432 {bp_thread_event, "thread events"},
3433 {bp_overlay_event, "overlay events"},
3434 {bp_catch_load, "catch load"},
3435 {bp_catch_unload, "catch unload"},
3436 {bp_catch_fork, "catch fork"},
3437 {bp_catch_vfork, "catch vfork"},
3438 {bp_catch_exec, "catch exec"},
3439 {bp_catch_catch, "catch catch"},
3440 {bp_catch_throw, "catch throw"}
3443 static char *bpdisps[] =
3444 {"del", "dstp", "dis", "keep"};
3445 static char bpenables[] = "nynny";
3446 char wrap_indent[80];
3447 struct ui_stream *stb = ui_out_stream_new (uiout);
3448 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3449 struct cleanup *bkpt_chain;
3451 int header_of_multiple = 0;
3452 int part_of_multiple = (loc != NULL);
3454 gdb_assert (!loc || loc_number != 0);
3455 /* See comment in print_one_breakpoint concerning
3456 treatment of breakpoints with single disabled
3460 && (b->loc->next != NULL || !b->loc->enabled)))
3461 header_of_multiple = 1;
3466 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3470 if (part_of_multiple)
3473 asprintf (&formatted, "%d.%d", b->number, loc_number);
3474 ui_out_field_string (uiout, "number", formatted);
3479 ui_out_field_int (uiout, "number", b->number);
3484 if (part_of_multiple)
3485 ui_out_field_skip (uiout, "type");
3488 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3489 || ((int) b->type != bptypes[(int) b->type].type))
3490 internal_error (__FILE__, __LINE__,
3491 _("bptypes table does not describe type #%d."),
3493 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3498 if (part_of_multiple)
3499 ui_out_field_skip (uiout, "disp");
3501 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3506 if (part_of_multiple)
3507 ui_out_field_string (uiout, "enabled",
3509 ? (loc->enabled ? "y(p)" : "n(p)")
3510 : (loc->enabled ? "y" : "n"));
3513 int pending = (b->loc == NULL || b->loc->shlib_disabled);
3514 /* For header of multiple, there's no point showing pending
3515 state -- it will be apparent from the locations. */
3516 if (header_of_multiple)
3518 ui_out_field_fmt (uiout, "enabled", "%c%s",
3519 bpenables[(int) b->enable_state],
3520 pending ? "(p)" : "");
3522 ui_out_spaces (uiout, 3);
3527 strcpy (wrap_indent, " ");
3530 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3531 strcat (wrap_indent, " ");
3533 strcat (wrap_indent, " ");
3536 if (b->ops != NULL && b->ops->print_one != NULL)
3538 /* Although the print_one can possibly print
3539 all locations, calling it here is not likely
3540 to get any nice result. So, make sure there's
3541 just one location. */
3542 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3543 b->ops->print_one (b, last_addr);
3549 internal_error (__FILE__, __LINE__,
3550 _("print_one_breakpoint: bp_none encountered\n"));
3554 case bp_hardware_watchpoint:
3555 case bp_read_watchpoint:
3556 case bp_access_watchpoint:
3557 /* Field 4, the address, is omitted (which makes the columns
3558 not line up too nicely with the headers, but the effect
3559 is relatively readable). */
3561 ui_out_field_skip (uiout, "addr");
3563 print_expression (b->exp, stb->stream);
3564 ui_out_field_stream (uiout, "what", stb);
3568 case bp_catch_unload:
3569 /* Field 4, the address, is omitted (which makes the columns
3570 not line up too nicely with the headers, but the effect
3571 is relatively readable). */
3573 ui_out_field_skip (uiout, "addr");
3575 if (b->dll_pathname == NULL)
3577 ui_out_field_string (uiout, "what", "<any library>");
3578 ui_out_spaces (uiout, 1);
3582 ui_out_text (uiout, "library \"");
3583 ui_out_field_string (uiout, "what", b->dll_pathname);
3584 ui_out_text (uiout, "\" ");
3589 case bp_catch_vfork:
3590 /* Field 4, the address, is omitted (which makes the columns
3591 not line up too nicely with the headers, but the effect
3592 is relatively readable). */
3594 ui_out_field_skip (uiout, "addr");
3596 if (b->forked_inferior_pid != 0)
3598 ui_out_text (uiout, "process ");
3599 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3600 ui_out_spaces (uiout, 1);
3605 /* Field 4, the address, is omitted (which makes the columns
3606 not line up too nicely with the headers, but the effect
3607 is relatively readable). */
3609 ui_out_field_skip (uiout, "addr");
3611 if (b->exec_pathname != NULL)
3613 ui_out_text (uiout, "program \"");
3614 ui_out_field_string (uiout, "what", b->exec_pathname);
3615 ui_out_text (uiout, "\" ");
3619 case bp_catch_catch:
3620 /* Field 4, the address, is omitted (which makes the columns
3621 not line up too nicely with the headers, but the effect
3622 is relatively readable). */
3624 ui_out_field_skip (uiout, "addr");
3626 ui_out_field_string (uiout, "what", "exception catch");
3627 ui_out_spaces (uiout, 1);
3630 case bp_catch_throw:
3631 /* Field 4, the address, is omitted (which makes the columns
3632 not line up too nicely with the headers, but the effect
3633 is relatively readable). */
3635 ui_out_field_skip (uiout, "addr");
3637 ui_out_field_string (uiout, "what", "exception throw");
3638 ui_out_spaces (uiout, 1);
3642 case bp_hardware_breakpoint:
3646 case bp_longjmp_resume:
3647 case bp_step_resume:
3648 case bp_watchpoint_scope:
3650 case bp_shlib_event:
3651 case bp_thread_event:
3652 case bp_overlay_event:
3657 ui_out_field_string (uiout, "addr", "<PENDING>");
3658 else if (header_of_multiple)
3659 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3661 ui_out_field_core_addr (uiout, "addr", loc->address);
3664 if (!header_of_multiple)
3665 print_breakpoint_location (b, loc, wrap_indent, stb);
3667 *last_addr = b->loc->address;
3671 if (!part_of_multiple && b->thread != -1)
3673 /* FIXME: This seems to be redundant and lost here; see the
3674 "stop only in" line a little further down. */
3675 ui_out_text (uiout, " thread ");
3676 ui_out_field_int (uiout, "thread", b->thread);
3679 ui_out_text (uiout, "\n");
3681 if (part_of_multiple && frame_id_p (b->frame_id))
3684 ui_out_text (uiout, "\tstop only in stack frame at ");
3685 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3687 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3688 ui_out_text (uiout, "\n");
3691 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3693 /* We do not print the condition for Ada exception catchpoints
3694 because the condition is an internal implementation detail
3695 that we do not want to expose to the user. */
3697 ui_out_text (uiout, "\tstop only if ");
3698 ui_out_field_string (uiout, "cond", b->cond_string);
3699 ui_out_text (uiout, "\n");
3702 if (!part_of_multiple && b->thread != -1)
3704 /* FIXME should make an annotation for this */
3705 ui_out_text (uiout, "\tstop only in thread ");
3706 ui_out_field_int (uiout, "thread", b->thread);
3707 ui_out_text (uiout, "\n");
3710 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3712 /* FIXME should make an annotation for this */
3713 if (ep_is_catchpoint (b))
3714 ui_out_text (uiout, "\tcatchpoint");
3716 ui_out_text (uiout, "\tbreakpoint");
3717 ui_out_text (uiout, " already hit ");
3718 ui_out_field_int (uiout, "times", b->hit_count);
3719 if (b->hit_count == 1)
3720 ui_out_text (uiout, " time\n");
3722 ui_out_text (uiout, " times\n");
3725 /* Output the count also if it is zero, but only if this is
3726 mi. FIXME: Should have a better test for this. */
3727 if (ui_out_is_mi_like_p (uiout))
3728 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3729 ui_out_field_int (uiout, "times", b->hit_count);
3731 if (!part_of_multiple && b->ignore_count)
3734 ui_out_text (uiout, "\tignore next ");
3735 ui_out_field_int (uiout, "ignore", b->ignore_count);
3736 ui_out_text (uiout, " hits\n");
3739 if (!part_of_multiple && (l = b->commands))
3741 struct cleanup *script_chain;
3744 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3745 print_command_lines (uiout, l, 4);
3746 do_cleanups (script_chain);
3748 do_cleanups (bkpt_chain);
3749 do_cleanups (old_chain);
3753 print_one_breakpoint (struct breakpoint *b,
3754 CORE_ADDR *last_addr)
3756 print_one_breakpoint_location (b, NULL, 0, last_addr);
3758 /* If this breakpoint has custom print function,
3759 it's already printed. Otherwise, print individual
3760 locations, if any. */
3761 if (b->ops == NULL || b->ops->print_one == NULL)
3763 /* If breakpoint has a single location that is
3764 disabled, we print it as if it had
3765 several locations, since otherwise it's hard to
3766 represent "breakpoint enabled, location disabled"
3769 && (b->loc->next || !b->loc->enabled)
3770 && !ui_out_is_mi_like_p (uiout))
3772 struct bp_location *loc;
3774 for (loc = b->loc; loc; loc = loc->next, ++n)
3775 print_one_breakpoint_location (b, loc, n, last_addr);
3781 struct captured_breakpoint_query_args
3787 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3789 struct captured_breakpoint_query_args *args = data;
3790 struct breakpoint *b;
3791 CORE_ADDR dummy_addr = 0;
3794 if (args->bnum == b->number)
3796 print_one_breakpoint (b, &dummy_addr);
3804 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3806 struct captured_breakpoint_query_args args;
3808 /* For the moment we don't trust print_one_breakpoint() to not throw
3810 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3811 error_message, RETURN_MASK_ALL) < 0)
3817 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3818 catchpoints, et.al.). */
3821 user_settable_breakpoint (const struct breakpoint *b)
3823 return (b->type == bp_breakpoint
3824 || b->type == bp_catch_load
3825 || b->type == bp_catch_unload
3826 || b->type == bp_catch_fork
3827 || b->type == bp_catch_vfork
3828 || b->type == bp_catch_exec
3829 || b->type == bp_catch_catch
3830 || b->type == bp_catch_throw
3831 || b->type == bp_hardware_breakpoint
3832 || b->type == bp_watchpoint
3833 || b->type == bp_read_watchpoint
3834 || b->type == bp_access_watchpoint
3835 || b->type == bp_hardware_watchpoint);
3838 /* Print information on user settable breakpoint (watchpoint, etc)
3839 number BNUM. If BNUM is -1 print all user settable breakpoints.
3840 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3843 breakpoint_1 (int bnum, int allflag)
3845 struct breakpoint *b;
3846 CORE_ADDR last_addr = (CORE_ADDR) -1;
3847 int nr_printable_breakpoints;
3848 struct cleanup *bkpttbl_chain;
3850 /* Compute the number of rows in the table. */
3851 nr_printable_breakpoints = 0;
3854 || bnum == b->number)
3856 if (allflag || user_settable_breakpoint (b))
3857 nr_printable_breakpoints++;
3862 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3866 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3869 if (nr_printable_breakpoints > 0)
3870 annotate_breakpoints_headers ();
3871 if (nr_printable_breakpoints > 0)
3873 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3874 if (nr_printable_breakpoints > 0)
3876 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3877 if (nr_printable_breakpoints > 0)
3879 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3880 if (nr_printable_breakpoints > 0)
3882 ui_out_table_header (uiout, 4, ui_left, "enabled", "Enb"); /* 4 */
3885 if (nr_printable_breakpoints > 0)
3887 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3888 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3890 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3892 if (nr_printable_breakpoints > 0)
3894 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3895 ui_out_table_body (uiout);
3896 if (nr_printable_breakpoints > 0)
3897 annotate_breakpoints_table ();
3901 || bnum == b->number)
3903 /* We only print out user settable breakpoints unless the
3905 if (allflag || user_settable_breakpoint (b))
3906 print_one_breakpoint (b, &last_addr);
3909 do_cleanups (bkpttbl_chain);
3911 if (nr_printable_breakpoints == 0)
3914 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3916 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3921 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3922 that a comparison of an unsigned with -1 is always false. */
3923 if (last_addr != (CORE_ADDR) -1 && !server_command)
3924 set_next_address (last_addr);
3927 /* FIXME? Should this be moved up so that it is only called when
3928 there have been breakpoints? */
3929 annotate_breakpoints_table_end ();
3933 breakpoints_info (char *bnum_exp, int from_tty)
3938 bnum = parse_and_eval_long (bnum_exp);
3940 breakpoint_1 (bnum, 0);
3944 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3949 bnum = parse_and_eval_long (bnum_exp);
3951 breakpoint_1 (bnum, 1);
3955 breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
3957 struct bp_location *bl = b->loc;
3958 for (; bl; bl = bl->next)
3960 if (bl->address == pc
3961 && (!overlay_debugging || bl->section == section))
3967 /* Print a message describing any breakpoints set at PC. */
3970 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
3973 struct breakpoint *b;
3976 others += breakpoint_has_pc (b, pc, section);
3980 printf_filtered (_("Note: breakpoint "));
3981 else /* if (others == ???) */
3982 printf_filtered (_("Note: breakpoints "));
3984 if (breakpoint_has_pc (b, pc, section))
3987 printf_filtered ("%d", b->number);
3988 if (b->thread == -1 && thread != -1)
3989 printf_filtered (" (all threads)");
3990 else if (b->thread != -1)
3991 printf_filtered (" (thread %d)", b->thread);
3992 printf_filtered ("%s%s ",
3993 ((b->enable_state == bp_disabled ||
3994 b->enable_state == bp_call_disabled)
3996 : b->enable_state == bp_permanent
4000 : ((others == 1) ? " and" : ""));
4002 printf_filtered (_("also set at pc "));
4003 deprecated_print_address_numeric (pc, 1, gdb_stdout);
4004 printf_filtered (".\n");
4008 /* Set the default place to put a breakpoint
4009 for the `break' command with no arguments. */
4012 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4015 default_breakpoint_valid = valid;
4016 default_breakpoint_address = addr;
4017 default_breakpoint_symtab = symtab;
4018 default_breakpoint_line = line;
4021 /* Return true iff it is meaningful to use the address member of
4022 BPT. For some breakpoint types, the address member is irrelevant
4023 and it makes no sense to attempt to compare it to other addresses
4024 (or use it for any other purpose either).
4026 More specifically, each of the following breakpoint types will always
4027 have a zero valued address and we don't want check_duplicates() to mark
4028 breakpoints of any of these types to be a duplicate of an actual
4029 breakpoint at address zero:
4032 bp_hardware_watchpoint
4034 bp_access_watchpoint
4041 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4043 enum bptype type = bpt->type;
4045 return (type != bp_watchpoint
4046 && type != bp_hardware_watchpoint
4047 && type != bp_read_watchpoint
4048 && type != bp_access_watchpoint
4049 && type != bp_catch_exec
4050 && type != bp_longjmp_resume
4051 && type != bp_catch_fork
4052 && type != bp_catch_vfork);
4055 /* Rescan breakpoints at the same address and section as BPT,
4056 marking the first one as "first" and any others as "duplicates".
4057 This is so that the bpt instruction is only inserted once.
4058 If we have a permanent breakpoint at the same place as BPT, make
4059 that one the official one, and the rest as duplicates. */
4062 check_duplicates_for (CORE_ADDR address, asection *section)
4064 struct bp_location *b;
4066 struct bp_location *perm_bp = 0;
4068 ALL_BP_LOCATIONS (b)
4069 if (b->owner->enable_state != bp_disabled
4070 && b->owner->enable_state != bp_call_disabled
4072 && !b->shlib_disabled
4073 && b->address == address /* address / overlay match */
4074 && (!overlay_debugging || b->section == section)
4075 && breakpoint_address_is_meaningful (b->owner))
4077 /* Have we found a permanent breakpoint? */
4078 if (b->owner->enable_state == bp_permanent)
4085 b->duplicate = count > 1;
4088 /* If we found a permanent breakpoint at this address, go over the
4089 list again and declare all the other breakpoints there to be the
4093 perm_bp->duplicate = 0;
4095 /* Permanent breakpoint should always be inserted. */
4096 if (! perm_bp->inserted)
4097 internal_error (__FILE__, __LINE__,
4098 _("allegedly permanent breakpoint is not "
4099 "actually inserted"));
4101 ALL_BP_LOCATIONS (b)
4104 if (b->owner->enable_state != bp_disabled
4105 && b->owner->enable_state != bp_call_disabled
4106 && b->enabled && !b->shlib_disabled
4107 && b->address == address /* address / overlay match */
4108 && (!overlay_debugging || b->section == section)
4109 && breakpoint_address_is_meaningful (b->owner))
4112 internal_error (__FILE__, __LINE__,
4113 _("another breakpoint was inserted on top of "
4114 "a permanent breakpoint"));
4123 check_duplicates (struct breakpoint *bpt)
4125 struct bp_location *bl = bpt->loc;
4127 if (! breakpoint_address_is_meaningful (bpt))
4130 for (; bl; bl = bl->next)
4131 check_duplicates_for (bl->address, bl->section);
4135 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4136 int bnum, int have_bnum)
4141 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4142 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4144 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4145 bnum, astr1, astr2);
4147 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4150 /* Adjust a breakpoint's address to account for architectural constraints
4151 on breakpoint placement. Return the adjusted address. Note: Very
4152 few targets require this kind of adjustment. For most targets,
4153 this function is simply the identity function. */
4156 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4158 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4160 /* Very few targets need any kind of breakpoint adjustment. */
4163 else if (bptype == bp_watchpoint
4164 || bptype == bp_hardware_watchpoint
4165 || bptype == bp_read_watchpoint
4166 || bptype == bp_access_watchpoint
4167 || bptype == bp_catch_fork
4168 || bptype == bp_catch_vfork
4169 || bptype == bp_catch_exec)
4171 /* Watchpoints and the various bp_catch_* eventpoints should not
4172 have their addresses modified. */
4177 CORE_ADDR adjusted_bpaddr;
4179 /* Some targets have architectural constraints on the placement
4180 of breakpoint instructions. Obtain the adjusted address. */
4181 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4184 /* An adjusted breakpoint address can significantly alter
4185 a user's expectations. Print a warning if an adjustment
4187 if (adjusted_bpaddr != bpaddr)
4188 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4190 return adjusted_bpaddr;
4194 /* Allocate a struct bp_location. */
4196 static struct bp_location *
4197 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4199 struct bp_location *loc, *loc_p;
4201 loc = xmalloc (sizeof (struct bp_location));
4202 memset (loc, 0, sizeof (*loc));
4206 loc->shlib_disabled = 0;
4215 case bp_longjmp_resume:
4216 case bp_step_resume:
4217 case bp_watchpoint_scope:
4219 case bp_shlib_event:
4220 case bp_thread_event:
4221 case bp_overlay_event:
4223 case bp_catch_unload:
4224 loc->loc_type = bp_loc_software_breakpoint;
4226 case bp_hardware_breakpoint:
4227 loc->loc_type = bp_loc_hardware_breakpoint;
4229 case bp_hardware_watchpoint:
4230 case bp_read_watchpoint:
4231 case bp_access_watchpoint:
4232 loc->loc_type = bp_loc_hardware_watchpoint;
4236 case bp_catch_vfork:
4238 case bp_catch_catch:
4239 case bp_catch_throw:
4240 loc->loc_type = bp_loc_other;
4243 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4246 /* Add this breakpoint to the end of the chain. */
4248 loc_p = bp_location_chain;
4250 bp_location_chain = loc;
4253 while (loc_p->global_next)
4254 loc_p = loc_p->global_next;
4255 loc_p->global_next = loc;
4261 static void free_bp_location (struct bp_location *loc)
4268 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4269 that has type BPTYPE and has no locations as yet. */
4272 set_raw_breakpoint_without_location (enum bptype bptype)
4274 struct breakpoint *b, *b1;
4276 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4277 memset (b, 0, sizeof (*b));
4280 b->language = current_language->la_language;
4281 b->input_radix = input_radix;
4283 b->enable_state = bp_enabled;
4286 b->ignore_count = 0;
4288 b->frame_id = null_frame_id;
4289 b->dll_pathname = NULL;
4290 b->triggered_dll_pathname = NULL;
4291 b->forked_inferior_pid = 0;
4292 b->exec_pathname = NULL;
4294 b->condition_not_parsed = 0;
4296 /* Add this breakpoint to the end of the chain
4297 so that a list of breakpoints will come out in order
4298 of increasing numbers. */
4300 b1 = breakpoint_chain;
4302 breakpoint_chain = b;
4312 /* Initialize loc->function_name. */
4314 set_breakpoint_location_function (struct bp_location *loc)
4316 if (loc->owner->type == bp_breakpoint
4317 || loc->owner->type == bp_hardware_breakpoint)
4319 find_pc_partial_function (loc->address, &(loc->function_name),
4321 if (loc->function_name)
4322 loc->function_name = xstrdup (loc->function_name);
4326 /* set_raw_breakpoint is a low level routine for allocating and
4327 partially initializing a breakpoint of type BPTYPE. The newly
4328 created breakpoint's address, section, source file name, and line
4329 number are provided by SAL. The newly created and partially
4330 initialized breakpoint is added to the breakpoint chain and
4331 is also returned as the value of this function.
4333 It is expected that the caller will complete the initialization of
4334 the newly created breakpoint struct as well as output any status
4335 information regarding the creation of a new breakpoint. In
4336 particular, set_raw_breakpoint does NOT set the breakpoint
4337 number! Care should be taken to not allow an error to occur
4338 prior to completing the initialization of the breakpoint. If this
4339 should happen, a bogus breakpoint will be left on the chain. */
4342 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4344 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4345 CORE_ADDR adjusted_address;
4347 /* Adjust the breakpoint's address prior to allocating a location.
4348 Once we call allocate_bp_location(), that mostly uninitialized
4349 location will be placed on the location chain. Adjustment of the
4350 breakpoint may cause read_memory_nobpt() to be called and we do
4351 not want its scan of the location chain to find a breakpoint and
4352 location that's only been partially initialized. */
4353 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4355 b->loc = allocate_bp_location (b, bptype);
4356 b->loc->requested_address = sal.pc;
4357 b->loc->address = adjusted_address;
4359 if (sal.symtab == NULL)
4360 b->source_file = NULL;
4362 b->source_file = savestring (sal.symtab->filename,
4363 strlen (sal.symtab->filename));
4364 b->loc->section = sal.section;
4365 b->line_number = sal.line;
4367 set_breakpoint_location_function (b->loc);
4369 check_duplicates (b);
4370 breakpoints_changed ();
4376 /* Note that the breakpoint object B describes a permanent breakpoint
4377 instruction, hard-wired into the inferior's code. */
4379 make_breakpoint_permanent (struct breakpoint *b)
4381 struct bp_location *bl;
4382 b->enable_state = bp_permanent;
4384 /* By definition, permanent breakpoints are already present in the code.
4385 Mark all locations as inserted. For now, make_breakpoint_permanent
4386 is called in just one place, so it's hard to say if it's reasonable
4387 to have permanent breakpoint with multiple locations or not,
4388 but it's easy to implmement. */
4389 for (bl = b->loc; bl; bl = bl->next)
4393 static struct breakpoint *
4394 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4396 static int internal_breakpoint_number = -1;
4397 struct symtab_and_line sal;
4398 struct breakpoint *b;
4400 init_sal (&sal); /* initialize to zeroes */
4403 sal.section = find_pc_overlay (sal.pc);
4405 b = set_raw_breakpoint (sal, type);
4406 b->number = internal_breakpoint_number--;
4407 b->disposition = disp_donttouch;
4414 create_longjmp_breakpoint (char *func_name)
4416 struct breakpoint *b;
4417 struct minimal_symbol *m;
4419 if (func_name == NULL)
4420 b = create_internal_breakpoint (0, bp_longjmp_resume);
4423 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4426 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4429 b->enable_state = bp_disabled;
4432 b->addr_string = xstrdup (func_name);
4435 /* Call this routine when stepping and nexting to enable a breakpoint
4436 if we do a longjmp(). When we hit that breakpoint, call
4437 set_longjmp_resume_breakpoint() to figure out where we are going. */
4440 enable_longjmp_breakpoint (void)
4442 struct breakpoint *b;
4445 if (b->type == bp_longjmp)
4447 b->enable_state = bp_enabled;
4448 check_duplicates (b);
4453 disable_longjmp_breakpoint (void)
4455 struct breakpoint *b;
4458 if (b->type == bp_longjmp
4459 || b->type == bp_longjmp_resume)
4461 b->enable_state = bp_disabled;
4462 check_duplicates (b);
4467 create_overlay_event_breakpoint (char *func_name)
4469 struct breakpoint *b;
4470 struct minimal_symbol *m;
4472 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4475 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4477 b->addr_string = xstrdup (func_name);
4479 if (overlay_debugging == ovly_auto)
4481 b->enable_state = bp_enabled;
4482 overlay_events_enabled = 1;
4486 b->enable_state = bp_disabled;
4487 overlay_events_enabled = 0;
4492 enable_overlay_breakpoints (void)
4494 struct breakpoint *b;
4497 if (b->type == bp_overlay_event)
4499 b->enable_state = bp_enabled;
4500 check_duplicates (b);
4501 overlay_events_enabled = 1;
4506 disable_overlay_breakpoints (void)
4508 struct breakpoint *b;
4511 if (b->type == bp_overlay_event)
4513 b->enable_state = bp_disabled;
4514 check_duplicates (b);
4515 overlay_events_enabled = 0;
4520 create_thread_event_breakpoint (CORE_ADDR address)
4522 struct breakpoint *b;
4524 b = create_internal_breakpoint (address, bp_thread_event);
4526 b->enable_state = bp_enabled;
4527 /* addr_string has to be used or breakpoint_re_set will delete me. */
4528 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4534 remove_thread_event_breakpoints (void)
4536 struct breakpoint *b, *temp;
4538 ALL_BREAKPOINTS_SAFE (b, temp)
4539 if (b->type == bp_thread_event)
4540 delete_breakpoint (b);
4543 struct captured_parse_breakpoint_args
4546 struct symtabs_and_lines *sals_p;
4547 char ***addr_string_p;
4551 struct lang_and_radix
4559 remove_solib_event_breakpoints (void)
4561 struct breakpoint *b, *temp;
4563 ALL_BREAKPOINTS_SAFE (b, temp)
4564 if (b->type == bp_shlib_event)
4565 delete_breakpoint (b);
4569 create_solib_event_breakpoint (CORE_ADDR address)
4571 struct breakpoint *b;
4573 b = create_internal_breakpoint (address, bp_shlib_event);
4577 /* Disable any breakpoints that are on code in shared libraries. Only
4578 apply to enabled breakpoints, disabled ones can just stay disabled. */
4581 disable_breakpoints_in_shlibs (void)
4583 struct bp_location *loc;
4584 int disabled_shlib_breaks = 0;
4586 ALL_BP_LOCATIONS (loc)
4588 struct breakpoint *b = loc->owner;
4589 /* We apply the check to all breakpoints, including disabled
4590 for those with loc->duplicate set. This is so that when breakpoint
4591 becomes enabled, or the duplicate is removed, gdb will try to insert
4592 all breakpoints. If we don't set shlib_disabled here, we'll try
4593 to insert those breakpoints and fail. */
4594 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4595 && !loc->shlib_disabled
4597 && PC_SOLIB (loc->address)
4599 && solib_address (loc->address)
4603 loc->shlib_disabled = 1;
4608 /* Disable any breakpoints that are in in an unloaded shared library. Only
4609 apply to enabled breakpoints, disabled ones can just stay disabled. */
4612 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4614 struct bp_location *loc;
4615 int disabled_shlib_breaks = 0;
4617 ALL_BP_LOCATIONS (loc)
4619 struct breakpoint *b = loc->owner;
4620 if ((loc->loc_type == bp_loc_hardware_breakpoint
4621 || loc->loc_type == bp_loc_software_breakpoint)
4622 && !loc->shlib_disabled)
4625 char *so_name = PC_SOLIB (loc->address);
4627 char *so_name = solib_address (loc->address);
4629 if (so_name && !strcmp (so_name, solib->so_name))
4631 loc->shlib_disabled = 1;
4632 /* At this point, we cannot rely on remove_breakpoint
4633 succeeding so we must mark the breakpoint as not inserted
4634 to prevent future errors occurring in remove_breakpoints. */
4636 if (!disabled_shlib_breaks)
4638 target_terminal_ours_for_output ();
4639 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4642 disabled_shlib_breaks = 1;
4649 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4650 char *cond_string, enum bptype bp_kind)
4652 struct breakpoint *b;
4653 struct symtabs_and_lines sals;
4654 struct cleanup *old_chain;
4655 struct cleanup *canonical_strings_chain = NULL;
4656 char *addr_start = hookname;
4657 char *addr_end = NULL;
4658 char **canonical = (char **) NULL;
4659 int thread = -1; /* All threads. */
4661 /* Set a breakpoint on the specified hook. */
4662 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL,
4663 0, &canonical, NULL);
4664 addr_end = hookname;
4666 if (sals.nelts == 0)
4668 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4669 "Suggest linking with /opt/langtools/lib/end.o.\n"
4670 "GDB will be unable to track shl_load/shl_unload calls."));
4673 if (sals.nelts != 1)
4675 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4676 "GDB will be unable to track shl_load/shl_unload calls."));
4680 /* Make sure that all storage allocated in decode_line_1 gets freed
4681 in case the following errors out. */
4682 old_chain = make_cleanup (xfree, sals.sals);
4683 if (canonical != (char **) NULL)
4685 make_cleanup (xfree, canonical);
4686 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4687 if (canonical[0] != NULL)
4688 make_cleanup (xfree, canonical[0]);
4691 resolve_sal_pc (&sals.sals[0]);
4693 /* Remove the canonical strings from the cleanup, they are needed below. */
4694 if (canonical != (char **) NULL)
4695 discard_cleanups (canonical_strings_chain);
4697 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4698 set_breakpoint_count (breakpoint_count + 1);
4699 b->number = breakpoint_count;
4700 b->cond_string = (cond_string == NULL) ?
4701 NULL : savestring (cond_string, strlen (cond_string));
4704 if (canonical != (char **) NULL && canonical[0] != NULL)
4705 b->addr_string = canonical[0];
4706 else if (addr_start)
4707 b->addr_string = savestring (addr_start, addr_end - addr_start);
4709 b->enable_state = bp_enabled;
4710 b->disposition = tempflag ? disp_del : disp_donttouch;
4712 if (dll_pathname == NULL)
4713 b->dll_pathname = NULL;
4716 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4717 strcpy (b->dll_pathname, dll_pathname);
4721 do_cleanups (old_chain);
4725 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4726 char *dll_pathname, char *cond_string)
4728 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4729 cond_string, bp_catch_load);
4733 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4734 char *dll_pathname, char *cond_string)
4736 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4737 cond_string, bp_catch_unload);
4741 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4742 enum bptype bp_kind)
4744 struct symtab_and_line sal;
4745 struct breakpoint *b;
4746 int thread = -1; /* All threads. */
4753 b = set_raw_breakpoint (sal, bp_kind);
4754 set_breakpoint_count (breakpoint_count + 1);
4755 b->number = breakpoint_count;
4756 b->cond_string = (cond_string == NULL) ?
4757 NULL : savestring (cond_string, strlen (cond_string));
4759 b->addr_string = NULL;
4760 b->enable_state = bp_enabled;
4761 b->disposition = tempflag ? disp_del : disp_donttouch;
4762 b->forked_inferior_pid = 0;
4768 create_fork_event_catchpoint (int tempflag, char *cond_string)
4770 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4774 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4776 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4780 create_exec_event_catchpoint (int tempflag, char *cond_string)
4782 struct symtab_and_line sal;
4783 struct breakpoint *b;
4784 int thread = -1; /* All threads. */
4791 b = set_raw_breakpoint (sal, bp_catch_exec);
4792 set_breakpoint_count (breakpoint_count + 1);
4793 b->number = breakpoint_count;
4794 b->cond_string = (cond_string == NULL) ?
4795 NULL : savestring (cond_string, strlen (cond_string));
4797 b->addr_string = NULL;
4798 b->enable_state = bp_enabled;
4799 b->disposition = tempflag ? disp_del : disp_donttouch;
4805 hw_breakpoint_used_count (void)
4807 struct breakpoint *b;
4812 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4820 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4822 struct breakpoint *b;
4825 *other_type_used = 0;
4828 if (breakpoint_enabled (b))
4830 if (b->type == type)
4832 else if ((b->type == bp_hardware_watchpoint ||
4833 b->type == bp_read_watchpoint ||
4834 b->type == bp_access_watchpoint))
4835 *other_type_used = 1;
4841 /* Call this after hitting the longjmp() breakpoint. Use this to set
4842 a new breakpoint at the target of the jmp_buf.
4844 FIXME - This ought to be done by setting a temporary breakpoint
4845 that gets deleted automatically... */
4848 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4850 struct breakpoint *b;
4853 if (b->type == bp_longjmp_resume)
4855 b->loc->requested_address = pc;
4856 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4858 b->enable_state = bp_enabled;
4859 b->frame_id = frame_id;
4860 check_duplicates (b);
4866 disable_watchpoints_before_interactive_call_start (void)
4868 struct breakpoint *b;
4872 if (((b->type == bp_watchpoint)
4873 || (b->type == bp_hardware_watchpoint)
4874 || (b->type == bp_read_watchpoint)
4875 || (b->type == bp_access_watchpoint)
4876 || ep_is_exception_catchpoint (b))
4877 && breakpoint_enabled (b))
4879 b->enable_state = bp_call_disabled;
4880 check_duplicates (b);
4886 enable_watchpoints_after_interactive_call_stop (void)
4888 struct breakpoint *b;
4892 if (((b->type == bp_watchpoint)
4893 || (b->type == bp_hardware_watchpoint)
4894 || (b->type == bp_read_watchpoint)
4895 || (b->type == bp_access_watchpoint)
4896 || ep_is_exception_catchpoint (b))
4897 && (b->enable_state == bp_call_disabled))
4899 b->enable_state = bp_enabled;
4900 check_duplicates (b);
4906 /* Set a breakpoint that will evaporate an end of command
4907 at address specified by SAL.
4908 Restrict it to frame FRAME if FRAME is nonzero. */
4911 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4914 struct breakpoint *b;
4915 b = set_raw_breakpoint (sal, type);
4916 b->enable_state = bp_enabled;
4917 b->disposition = disp_donttouch;
4918 b->frame_id = frame_id;
4920 /* If we're debugging a multi-threaded program, then we
4921 want momentary breakpoints to be active in only a
4922 single thread of control. */
4923 if (in_thread_list (inferior_ptid))
4924 b->thread = pid_to_thread_id (inferior_ptid);
4930 /* Tell the user we have just set a breakpoint B. */
4933 mention (struct breakpoint *b)
4936 struct cleanup *old_chain, *ui_out_chain;
4937 struct ui_stream *stb;
4939 stb = ui_out_stream_new (uiout);
4940 old_chain = make_cleanup_ui_out_stream_delete (stb);
4942 /* FIXME: This is misplaced; mention() is called by things (like
4943 hitting a watchpoint) other than breakpoint creation. It should
4944 be possible to clean this up and at the same time replace the
4945 random calls to breakpoint_changed with this hook, as has already
4946 been done for deprecated_delete_breakpoint_hook and so on. */
4947 if (deprecated_create_breakpoint_hook)
4948 deprecated_create_breakpoint_hook (b);
4949 breakpoint_create_event (b->number);
4951 if (b->ops != NULL && b->ops->print_mention != NULL)
4952 b->ops->print_mention (b);
4957 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4960 ui_out_text (uiout, "Watchpoint ");
4961 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4962 ui_out_field_int (uiout, "number", b->number);
4963 ui_out_text (uiout, ": ");
4964 print_expression (b->exp, stb->stream);
4965 ui_out_field_stream (uiout, "exp", stb);
4966 do_cleanups (ui_out_chain);
4968 case bp_hardware_watchpoint:
4969 ui_out_text (uiout, "Hardware watchpoint ");
4970 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4971 ui_out_field_int (uiout, "number", b->number);
4972 ui_out_text (uiout, ": ");
4973 print_expression (b->exp, stb->stream);
4974 ui_out_field_stream (uiout, "exp", stb);
4975 do_cleanups (ui_out_chain);
4977 case bp_read_watchpoint:
4978 ui_out_text (uiout, "Hardware read watchpoint ");
4979 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4980 ui_out_field_int (uiout, "number", b->number);
4981 ui_out_text (uiout, ": ");
4982 print_expression (b->exp, stb->stream);
4983 ui_out_field_stream (uiout, "exp", stb);
4984 do_cleanups (ui_out_chain);
4986 case bp_access_watchpoint:
4987 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4988 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4989 ui_out_field_int (uiout, "number", b->number);
4990 ui_out_text (uiout, ": ");
4991 print_expression (b->exp, stb->stream);
4992 ui_out_field_stream (uiout, "exp", stb);
4993 do_cleanups (ui_out_chain);
4996 if (ui_out_is_mi_like_p (uiout))
5001 printf_filtered (_("Breakpoint %d"), b->number);
5004 case bp_hardware_breakpoint:
5005 if (ui_out_is_mi_like_p (uiout))
5010 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
5014 case bp_catch_unload:
5015 printf_filtered (_("Catchpoint %d (%s %s)"),
5017 (b->type == bp_catch_load) ? "load" : "unload",
5018 (b->dll_pathname != NULL) ?
5019 b->dll_pathname : "<any library>");
5022 case bp_catch_vfork:
5023 printf_filtered (_("Catchpoint %d (%s)"),
5025 (b->type == bp_catch_fork) ? "fork" : "vfork");
5028 printf_filtered (_("Catchpoint %d (exec)"),
5031 case bp_catch_catch:
5032 case bp_catch_throw:
5033 printf_filtered (_("Catchpoint %d (%s)"),
5035 (b->type == bp_catch_catch) ? "catch" : "throw");
5041 case bp_longjmp_resume:
5042 case bp_step_resume:
5044 case bp_watchpoint_scope:
5045 case bp_shlib_event:
5046 case bp_thread_event:
5047 case bp_overlay_event:
5053 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5057 printf_filtered (_(" (%s) pending."), b->addr_string);
5061 if (addressprint || b->source_file == NULL)
5063 printf_filtered (" at ");
5064 deprecated_print_address_numeric (b->loc->address, 1, gdb_stdout);
5067 printf_filtered (": file %s, line %d.",
5068 b->source_file, b->line_number);
5072 struct bp_location *loc = b->loc;
5074 for (; loc; loc = loc->next)
5076 printf_filtered (" (%d locations)", n);
5081 do_cleanups (old_chain);
5082 if (ui_out_is_mi_like_p (uiout))
5084 printf_filtered ("\n");
5088 static struct bp_location *
5089 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5090 const struct symtab_and_line *sal)
5092 struct bp_location *loc, **tmp;
5094 loc = allocate_bp_location (b, bptype);
5095 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5098 loc->requested_address = sal->pc;
5099 loc->address = adjust_breakpoint_address (loc->requested_address,
5101 loc->section = sal->section;
5103 set_breakpoint_location_function (loc);
5107 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5108 as textual description of the location, and COND_STRING
5109 as condition expression.
5111 The paramter PENDING_BP is same as for the
5112 create_breakpoints function. */
5115 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5117 enum bptype type, enum bpdisp disposition,
5118 int thread, int ignore_count, int from_tty,
5119 struct breakpoint *pending_bp)
5121 struct breakpoint *b = NULL;
5124 if (type == bp_hardware_breakpoint)
5126 int i = hw_breakpoint_used_count ();
5127 int target_resources_ok =
5128 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5130 if (target_resources_ok == 0)
5131 error (_("No hardware breakpoint support in the target."));
5132 else if (target_resources_ok < 0)
5133 error (_("Hardware breakpoints used exceeds limit."));
5136 for (i = 0; i < sals.nelts; ++i)
5138 struct symtab_and_line sal = sals.sals[i];
5139 struct bp_location *loc;
5142 describe_other_breakpoints (sal.pc, sal.section, thread);
5146 b = set_raw_breakpoint (sal, type);
5147 set_breakpoint_count (breakpoint_count + 1);
5148 b->number = breakpoint_count;
5151 b->cond_string = cond_string;
5152 b->ignore_count = ignore_count;
5153 b->enable_state = bp_enabled;
5154 b->disposition = disposition;
5160 loc = add_location_to_breakpoint (b, type, &sal);
5165 char *arg = b->cond_string;
5166 b->loc->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
5170 error (_("Junk at end of pending breakpoint condition expression"));
5172 error (_("Garbage %s follows condition"), arg);
5178 b->addr_string = addr_string;
5180 /* addr_string has to be used or breakpoint_re_set will delete
5182 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5187 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5188 elements to fill the void space. */
5189 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5191 int i = index_to_remove+1;
5192 int last_index = sal->nelts-1;
5194 for (;i <= last_index; ++i)
5195 sal->sals[i-1] = sal->sals[i];
5200 /* If appropriate, obtains all sals that correspond
5201 to the same file and line as SAL. This is done
5202 only if SAL does not have explicit PC and has
5203 line and file information. If we got just a single
5204 expanded sal, return the original.
5206 Otherwise, if SAL.explicit_line is not set, filter out
5207 all sals for which the name of enclosing function
5208 is different from SAL. This makes sure that if we have
5209 breakpoint originally set in template instantiation, say
5210 foo<int>(), we won't expand SAL to locations at the same
5211 line in all existing instantiations of 'foo'.
5214 struct symtabs_and_lines
5215 expand_line_sal_maybe (struct symtab_and_line sal)
5217 struct symtabs_and_lines expanded;
5218 CORE_ADDR original_pc = sal.pc;
5219 char *original_function = NULL;
5223 /* If we have explicit pc, don't expand.
5224 If we have no line number, we can't expand. */
5225 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5228 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5229 expanded.sals[0] = sal;
5234 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5236 expanded = expand_line_sal (sal);
5237 if (expanded.nelts == 1)
5239 /* We had one sal, we got one sal. Without futher
5240 processing, just return the original sal. */
5241 xfree (expanded.sals);
5243 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5244 sal.pc = original_pc;
5245 expanded.sals[0] = sal;
5249 if (!sal.explicit_line)
5251 CORE_ADDR func_addr, func_end;
5252 for (i = 0; i < expanded.nelts; ++i)
5254 CORE_ADDR pc = expanded.sals[i].pc;
5255 char *this_function;
5256 if (find_pc_partial_function (pc, &this_function,
5257 &func_addr, &func_end))
5259 if (this_function &&
5260 strcmp (this_function, original_function) != 0)
5262 remove_sal (&expanded, i);
5265 else if (func_addr == pc)
5267 /* We're at beginning of a function, and should
5269 struct symbol *sym = find_pc_function (pc);
5271 expanded.sals[i] = find_function_start_sal (sym, 1);
5274 = gdbarch_skip_prologue (current_gdbarch, pc);
5281 if (expanded.nelts <= 1)
5283 /* This is un ugly workaround. If we get zero
5284 expanded sals then something is really wrong.
5285 Fix that by returnign the original sal. */
5286 xfree (expanded.sals);
5288 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5289 sal.pc = original_pc;
5290 expanded.sals[0] = sal;
5297 for (i = 0; i < expanded.nelts; ++i)
5298 if (expanded.sals[i].pc == original_pc)
5309 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5310 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5311 value. COND_STRING, if not NULL, specified the condition to be
5312 used for all breakpoints. Essentially the only case where
5313 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5314 function. In that case, it's still not possible to specify
5315 separate conditions for different overloaded functions, so
5316 we take just a single condition string.
5318 The parameter PENDING_BP points to a pending breakpoint that is
5319 the basis of the breakpoints currently being created. The pending
5320 breakpoint may contain a separate condition string or commands
5321 that were added after the initial pending breakpoint was created.
5323 NOTE: If the function succeeds, the caller is expected to cleanup
5324 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5325 array contents). If the function fails (error() is called), the
5326 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5327 COND and SALS arrays and each of those arrays contents. */
5330 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5332 enum bptype type, enum bpdisp disposition,
5333 int thread, int ignore_count, int from_tty,
5334 struct breakpoint *pending_bp)
5337 for (i = 0; i < sals.nelts; ++i)
5339 struct symtabs_and_lines expanded =
5340 expand_line_sal_maybe (sals.sals[i]);
5342 create_breakpoint (expanded, addr_string[i],
5343 cond_string, type, disposition,
5344 thread, ignore_count, from_tty,
5349 /* Parse ARG which is assumed to be a SAL specification possibly
5350 followed by conditionals. On return, SALS contains an array of SAL
5351 addresses found. ADDR_STRING contains a vector of (canonical)
5352 address strings. ARG points to the end of the SAL. */
5355 parse_breakpoint_sals (char **address,
5356 struct symtabs_and_lines *sals,
5357 char ***addr_string,
5360 char *addr_start = *address;
5361 *addr_string = NULL;
5362 /* If no arg given, or if first arg is 'if ', use the default
5364 if ((*address) == NULL
5365 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5367 if (default_breakpoint_valid)
5369 struct symtab_and_line sal;
5370 init_sal (&sal); /* initialize to zeroes */
5371 sals->sals = (struct symtab_and_line *)
5372 xmalloc (sizeof (struct symtab_and_line));
5373 sal.pc = default_breakpoint_address;
5374 sal.line = default_breakpoint_line;
5375 sal.symtab = default_breakpoint_symtab;
5376 sal.section = find_pc_overlay (sal.pc);
5377 sals->sals[0] = sal;
5381 error (_("No default breakpoint address now."));
5385 /* Force almost all breakpoints to be in terms of the
5386 current_source_symtab (which is decode_line_1's default). This
5387 should produce the results we want almost all of the time while
5388 leaving default_breakpoint_* alone.
5389 ObjC: However, don't match an Objective-C method name which
5390 may have a '+' or '-' succeeded by a '[' */
5392 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5394 if (default_breakpoint_valid
5396 || ((strchr ("+-", (*address)[0]) != NULL)
5397 && ((*address)[1] != '['))))
5398 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5399 default_breakpoint_line, addr_string,
5402 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5403 addr_string, not_found_ptr);
5405 /* For any SAL that didn't have a canonical string, fill one in. */
5406 if (sals->nelts > 0 && *addr_string == NULL)
5407 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5408 if (addr_start != (*address))
5411 for (i = 0; i < sals->nelts; i++)
5413 /* Add the string if not present. */
5414 if ((*addr_string)[i] == NULL)
5415 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5421 /* Convert each SAL into a real PC. Verify that the PC can be
5422 inserted as a breakpoint. If it can't throw an error. */
5425 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5429 for (i = 0; i < sals->nelts; i++)
5431 resolve_sal_pc (&sals->sals[i]);
5433 /* It's possible for the PC to be nonzero, but still an illegal
5434 value on some targets.
5436 For example, on HP-UX if you start gdb, and before running the
5437 inferior you try to set a breakpoint on a shared library function
5438 "foo" where the inferior doesn't call "foo" directly but does
5439 pass its address to another function call, then we do find a
5440 minimal symbol for the "foo", but it's address is invalid.
5441 (Appears to be an index into a table that the loader sets up
5442 when the inferior is run.)
5444 Give the target a chance to bless sals.sals[i].pc before we
5445 try to make a breakpoint for it. */
5446 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5447 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5449 if (address == NULL)
5450 error (_("Cannot break without a running program."));
5452 error (_("Cannot break on %s without a running program."),
5460 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5462 struct captured_parse_breakpoint_args *args = data;
5464 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5465 args->not_found_ptr);
5468 /* Given TOK, a string specification of condition and thread, as
5469 accepted by the 'break' command, extract the condition
5470 string and thread number and set *COND_STRING and *THREAD.
5471 PC identifies the context at which the condition should be parsed.
5472 If no condition is found, *COND_STRING is set to NULL.
5473 If no thread is found, *THREAD is set to -1. */
5475 find_condition_and_thread (char *tok, CORE_ADDR pc,
5476 char **cond_string, int *thread)
5478 *cond_string = NULL;
5484 char *cond_start = NULL;
5485 char *cond_end = NULL;
5486 while (*tok == ' ' || *tok == '\t')
5491 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5494 toklen = end_tok - tok;
5496 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5498 tok = cond_start = end_tok + 1;
5499 parse_exp_1 (&tok, block_for_pc (pc), 0);
5501 *cond_string = savestring (cond_start,
5502 cond_end - cond_start);
5504 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5510 *thread = strtol (tok, &tok, 0);
5512 error (_("Junk after thread keyword."));
5513 if (!valid_thread_id (*thread))
5514 error (_("Unknown thread %d."), *thread);
5517 error (_("Junk at end of arguments."));
5521 /* Set a breakpoint according to ARG (function, linenum or *address)
5522 flag: first bit : 0 non-temporary, 1 temporary.
5523 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5525 PENDING_BP is non-NULL when this function is being called to resolve
5526 a pending breakpoint. */
5529 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5531 struct gdb_exception e;
5532 int tempflag, hardwareflag;
5533 struct symtabs_and_lines sals;
5534 struct symtab_and_line pending_sal;
5535 char *cond_string = NULL;
5538 char *addr_start = arg;
5540 struct cleanup *old_chain;
5541 struct cleanup *breakpoint_chain = NULL;
5542 struct captured_parse_breakpoint_args parse_args;
5546 int ignore_count = 0;
5549 hardwareflag = flag & BP_HARDWAREFLAG;
5550 tempflag = flag & BP_TEMPFLAG;
5556 parse_args.arg_p = &arg;
5557 parse_args.sals_p = &sals;
5558 parse_args.addr_string_p = &addr_string;
5559 parse_args.not_found_ptr = ¬_found;
5561 e = catch_exception (uiout, do_captured_parse_breakpoint,
5562 &parse_args, RETURN_MASK_ALL);
5564 /* If caller is interested in rc value from parse, set value. */
5568 exception_print (gdb_stderr, e);
5573 case NOT_FOUND_ERROR:
5574 /* If called to resolve pending breakpoint, just return
5579 exception_print (gdb_stderr, e);
5581 /* If pending breakpoint support is turned off, throw
5584 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5585 deprecated_throw_reason (RETURN_ERROR);
5587 /* If pending breakpoint support is auto query and the user
5588 selects no, then simply return the error code. */
5589 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5590 !nquery ("Make breakpoint pending on future shared library load? "))
5593 /* At this point, either the user was queried about setting
5594 a pending breakpoint and selected yes, or pending
5595 breakpoint behavior is on and thus a pending breakpoint
5596 is defaulted on behalf of the user. */
5597 copy_arg = xstrdup (addr_start);
5598 addr_string = ©_arg;
5600 sals.sals = &pending_sal;
5605 exception_print (gdb_stderr, e);
5613 /* Create a chain of things that always need to be cleaned up. */
5614 old_chain = make_cleanup (null_cleanup, 0);
5618 /* Make sure that all storage allocated to SALS gets freed. */
5619 make_cleanup (xfree, sals.sals);
5621 /* Cleanup the addr_string array but not its contents. */
5622 make_cleanup (xfree, addr_string);
5625 /* ----------------------------- SNIP -----------------------------
5626 Anything added to the cleanup chain beyond this point is assumed
5627 to be part of a breakpoint. If the breakpoint create succeeds
5628 then the memory is not reclaimed. */
5629 breakpoint_chain = make_cleanup (null_cleanup, 0);
5631 /* Mark the contents of the addr_string for cleanup. These go on
5632 the breakpoint_chain and only occure if the breakpoint create
5634 for (i = 0; i < sals.nelts; i++)
5636 if (addr_string[i] != NULL)
5637 make_cleanup (xfree, addr_string[i]);
5640 /* Resolve all line numbers to PC's and verify that the addresses
5641 are ok for the target. */
5643 breakpoint_sals_to_pc (&sals, addr_start);
5645 /* Verify that condition can be parsed, before setting any
5646 breakpoints. Allocate a separate condition expression for each
5650 /* Here we only parse 'arg' to separate condition
5651 from thread number, so parsing in context of first
5652 sal is OK. When setting the breakpoint we'll
5653 re-parse it in context of each sal. */
5654 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5656 make_cleanup (xfree, cond_string);
5657 create_breakpoints (sals, addr_string, cond_string,
5658 hardwareflag ? bp_hardware_breakpoint
5660 tempflag ? disp_del : disp_donttouch,
5661 thread, ignore_count, from_tty,
5666 struct symtab_and_line sal = {0};
5667 struct breakpoint *b;
5669 make_cleanup (xfree, copy_arg);
5671 b = set_raw_breakpoint_without_location (hardwareflag
5672 ? bp_hardware_breakpoint
5674 set_breakpoint_count (breakpoint_count + 1);
5675 b->number = breakpoint_count;
5677 b->addr_string = addr_string[0];
5678 b->cond_string = cond_string;
5679 b->ignore_count = ignore_count;
5680 b->disposition = tempflag ? disp_del : disp_donttouch;
5681 b->from_tty = from_tty;
5683 b->condition_not_parsed = 1;
5688 warning (_("Multiple breakpoints were set.\n"
5689 "Use the \"delete\" command to delete unwanted breakpoints."));
5690 /* That's it. Discard the cleanups for data inserted into the
5692 discard_cleanups (breakpoint_chain);
5693 /* But cleanup everything else. */
5694 do_cleanups (old_chain);
5699 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5700 linenum or *address) with COND and IGNORE_COUNT. */
5702 struct captured_breakpoint_args
5713 do_captured_breakpoint (struct ui_out *uiout, void *data)
5715 struct captured_breakpoint_args *args = data;
5716 struct symtabs_and_lines sals;
5717 struct expression **cond;
5718 struct cleanup *old_chain;
5719 struct cleanup *breakpoint_chain = NULL;
5722 char *cond_string = 0;
5726 /* Parse the source and lines spec. Delay check that the expression
5727 didn't contain trailing garbage until after cleanups are in
5731 address_end = args->address;
5733 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5738 /* Create a chain of things at always need to be cleaned up. */
5739 old_chain = make_cleanup (null_cleanup, 0);
5741 /* Always have a addr_string array, even if it is empty. */
5742 make_cleanup (xfree, addr_string);
5744 /* Make sure that all storage allocated to SALS gets freed. */
5745 make_cleanup (xfree, sals.sals);
5747 /* Allocate space for all the cond expressions. */
5748 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5749 make_cleanup (xfree, cond);
5751 /* ----------------------------- SNIP -----------------------------
5752 Anything added to the cleanup chain beyond this point is assumed
5753 to be part of a breakpoint. If the breakpoint create goes
5754 through then that memory is not cleaned up. */
5755 breakpoint_chain = make_cleanup (null_cleanup, 0);
5757 /* Mark the contents of the addr_string for cleanup. These go on
5758 the breakpoint_chain and only occure if the breakpoint create
5760 for (i = 0; i < sals.nelts; i++)
5762 if (addr_string[i] != NULL)
5763 make_cleanup (xfree, addr_string[i]);
5766 /* Wait until now before checking for garbage at the end of the
5767 address. That way cleanups can take care of freeing any
5769 if (*address_end != '\0')
5770 error (_("Garbage %s following breakpoint address"), address_end);
5772 /* Resolve all line numbers to PC's. */
5773 breakpoint_sals_to_pc (&sals, args->address);
5775 if (args->condition != NULL)
5777 cond_string = xstrdup (args->condition);
5778 make_cleanup (xfree, cond_string);
5781 create_breakpoints (sals, addr_string, args->condition,
5782 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5783 args->tempflag ? disp_del : disp_donttouch,
5784 args->thread, args->ignore_count, 0/*from-tty*/,
5785 NULL/*pending_bp*/);
5787 /* That's it. Discard the cleanups for data inserted into the
5789 discard_cleanups (breakpoint_chain);
5790 /* But cleanup everything else. */
5791 do_cleanups (old_chain);
5796 gdb_breakpoint (char *address, char *condition,
5797 int hardwareflag, int tempflag,
5798 int thread, int ignore_count,
5799 char **error_message)
5801 struct captured_breakpoint_args args;
5802 args.address = address;
5803 args.condition = condition;
5804 args.hardwareflag = hardwareflag;
5805 args.tempflag = tempflag;
5806 args.thread = thread;
5807 args.ignore_count = ignore_count;
5808 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5809 error_message, RETURN_MASK_ALL) < 0)
5816 /* Helper function for break_command_1 and disassemble_command. */
5819 resolve_sal_pc (struct symtab_and_line *sal)
5823 if (sal->pc == 0 && sal->symtab != NULL)
5825 if (!find_line_pc (sal->symtab, sal->line, &pc))
5826 error (_("No line %d in file \"%s\"."),
5827 sal->line, sal->symtab->filename);
5831 if (sal->section == 0 && sal->symtab != NULL)
5833 struct blockvector *bv;
5838 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5841 b = BLOCKVECTOR_BLOCK (bv, index);
5842 sym = block_function (b);
5845 fixup_symbol_section (sym, sal->symtab->objfile);
5846 sal->section = SYMBOL_BFD_SECTION (sym);
5850 /* It really is worthwhile to have the section, so we'll just
5851 have to look harder. This case can be executed if we have
5852 line numbers but no functions (as can happen in assembly
5855 struct minimal_symbol *msym;
5857 msym = lookup_minimal_symbol_by_pc (sal->pc);
5859 sal->section = SYMBOL_BFD_SECTION (msym);
5866 break_command (char *arg, int from_tty)
5868 break_command_1 (arg, 0, from_tty, NULL);
5872 tbreak_command (char *arg, int from_tty)
5874 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5878 hbreak_command (char *arg, int from_tty)
5880 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5884 thbreak_command (char *arg, int from_tty)
5886 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5890 stop_command (char *arg, int from_tty)
5892 printf_filtered (_("Specify the type of breakpoint to set.\n\
5893 Usage: stop in <function | address>\n\
5894 stop at <line>\n"));
5898 stopin_command (char *arg, int from_tty)
5902 if (arg == (char *) NULL)
5904 else if (*arg != '*')
5909 /* look for a ':'. If this is a line number specification, then
5910 say it is bad, otherwise, it should be an address or
5911 function/method name */
5912 while (*argptr && !hasColon)
5914 hasColon = (*argptr == ':');
5919 badInput = (*argptr != ':'); /* Not a class::method */
5921 badInput = isdigit (*arg); /* a simple line number */
5925 printf_filtered (_("Usage: stop in <function | address>\n"));
5927 break_command_1 (arg, 0, from_tty, NULL);
5931 stopat_command (char *arg, int from_tty)
5935 if (arg == (char *) NULL || *arg == '*') /* no line number */
5942 /* look for a ':'. If there is a '::' then get out, otherwise
5943 it is probably a line number. */
5944 while (*argptr && !hasColon)
5946 hasColon = (*argptr == ':');
5951 badInput = (*argptr == ':'); /* we have class::method */
5953 badInput = !isdigit (*arg); /* not a line number */
5957 printf_filtered (_("Usage: stop at <line>\n"));
5959 break_command_1 (arg, 0, from_tty, NULL);
5962 /* accessflag: hw_write: watch write,
5963 hw_read: watch read,
5964 hw_access: watch access (read or write) */
5966 watch_command_1 (char *arg, int accessflag, int from_tty)
5968 struct breakpoint *b;
5969 struct symtab_and_line sal;
5970 struct expression *exp;
5971 struct block *exp_valid_block;
5972 struct value *val, *mark;
5973 struct frame_info *frame;
5974 struct frame_info *prev_frame = NULL;
5975 char *exp_start = NULL;
5976 char *exp_end = NULL;
5977 char *tok, *end_tok;
5979 char *cond_start = NULL;
5980 char *cond_end = NULL;
5981 struct expression *cond = NULL;
5982 int i, other_type_used, target_resources_ok = 0;
5983 enum bptype bp_type;
5986 init_sal (&sal); /* initialize to zeroes */
5988 /* Parse arguments. */
5989 innermost_block = NULL;
5991 exp = parse_exp_1 (&arg, 0, 0);
5993 exp_valid_block = innermost_block;
5994 mark = value_mark ();
5995 val = evaluate_expression (exp);
5996 release_value (val);
5997 if (value_lazy (val))
5998 value_fetch_lazy (val);
6001 while (*tok == ' ' || *tok == '\t')
6005 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6008 toklen = end_tok - tok;
6009 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6011 tok = cond_start = end_tok + 1;
6012 cond = parse_exp_1 (&tok, 0, 0);
6016 error (_("Junk at end of command."));
6018 if (accessflag == hw_read)
6019 bp_type = bp_read_watchpoint;
6020 else if (accessflag == hw_access)
6021 bp_type = bp_access_watchpoint;
6023 bp_type = bp_hardware_watchpoint;
6025 mem_cnt = can_use_hardware_watchpoint (val);
6026 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
6027 error (_("Expression cannot be implemented with read/access watchpoint."));
6030 i = hw_watchpoint_used_count (bp_type, &other_type_used);
6031 target_resources_ok =
6032 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
6034 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
6035 error (_("Target does not support this type of hardware watchpoint."));
6037 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
6038 error (_("Target can only support one kind of HW watchpoint at a time."));
6041 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6042 watchpoint could not be set. */
6043 if (!mem_cnt || target_resources_ok <= 0)
6044 bp_type = bp_watchpoint;
6046 /* Now set up the breakpoint. */
6047 b = set_raw_breakpoint (sal, bp_type);
6048 set_breakpoint_count (breakpoint_count + 1);
6049 b->number = breakpoint_count;
6050 b->disposition = disp_donttouch;
6052 b->exp_valid_block = exp_valid_block;
6053 b->exp_string = savestring (exp_start, exp_end - exp_start);
6055 b->loc->cond = cond;
6057 b->cond_string = savestring (cond_start, cond_end - cond_start);
6061 frame = block_innermost_frame (exp_valid_block);
6064 prev_frame = get_prev_frame (frame);
6065 b->watchpoint_frame = get_frame_id (frame);
6069 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
6072 /* If the expression is "local", then set up a "watchpoint scope"
6073 breakpoint at the point where we've left the scope of the watchpoint
6075 if (innermost_block)
6079 struct breakpoint *scope_breakpoint;
6080 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
6081 bp_watchpoint_scope);
6083 scope_breakpoint->enable_state = bp_enabled;
6085 /* Automatically delete the breakpoint when it hits. */
6086 scope_breakpoint->disposition = disp_del;
6088 /* Only break in the proper frame (help with recursion). */
6089 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6091 /* Set the address at which we will stop. */
6092 scope_breakpoint->loc->requested_address
6093 = get_frame_pc (prev_frame);
6094 scope_breakpoint->loc->address
6095 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6096 scope_breakpoint->type);
6098 /* The scope breakpoint is related to the watchpoint. We
6099 will need to act on them together. */
6100 b->related_breakpoint = scope_breakpoint;
6103 value_free_to_mark (mark);
6107 /* Return count of locations need to be watched and can be handled
6108 in hardware. If the watchpoint can not be handled
6109 in hardware return zero. */
6112 can_use_hardware_watchpoint (struct value *v)
6114 int found_memory_cnt = 0;
6115 struct value *head = v;
6117 /* Did the user specifically forbid us to use hardware watchpoints? */
6118 if (!can_use_hw_watchpoints)
6121 /* Make sure that the value of the expression depends only upon
6122 memory contents, and values computed from them within GDB. If we
6123 find any register references or function calls, we can't use a
6124 hardware watchpoint.
6126 The idea here is that evaluating an expression generates a series
6127 of values, one holding the value of every subexpression. (The
6128 expression a*b+c has five subexpressions: a, b, a*b, c, and
6129 a*b+c.) GDB's values hold almost enough information to establish
6130 the criteria given above --- they identify memory lvalues,
6131 register lvalues, computed values, etcetera. So we can evaluate
6132 the expression, and then scan the chain of values that leaves
6133 behind to decide whether we can detect any possible change to the
6134 expression's final value using only hardware watchpoints.
6136 However, I don't think that the values returned by inferior
6137 function calls are special in any way. So this function may not
6138 notice that an expression involving an inferior function call
6139 can't be watched with hardware watchpoints. FIXME. */
6140 for (; v; v = value_next (v))
6142 if (VALUE_LVAL (v) == lval_memory)
6145 /* A lazy memory lvalue is one that GDB never needed to fetch;
6146 we either just used its address (e.g., `a' in `a.b') or
6147 we never needed it at all (e.g., `a' in `a,b'). */
6151 /* Ahh, memory we actually used! Check if we can cover
6152 it with hardware watchpoints. */
6153 struct type *vtype = check_typedef (value_type (v));
6155 /* We only watch structs and arrays if user asked for it
6156 explicitly, never if they just happen to appear in a
6157 middle of some value chain. */
6159 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6160 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6162 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6163 int len = TYPE_LENGTH (value_type (v));
6165 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6172 else if (VALUE_LVAL (v) != not_lval
6173 && deprecated_value_modifiable (v) == 0)
6174 return 0; /* ??? What does this represent? */
6175 else if (VALUE_LVAL (v) == lval_register)
6176 return 0; /* cannot watch a register with a HW watchpoint */
6179 /* The expression itself looks suitable for using a hardware
6180 watchpoint, but give the target machine a chance to reject it. */
6181 return found_memory_cnt;
6185 watch_command_wrapper (char *arg, int from_tty)
6187 watch_command (arg, from_tty);
6191 watch_command (char *arg, int from_tty)
6193 watch_command_1 (arg, hw_write, from_tty);
6197 rwatch_command_wrapper (char *arg, int from_tty)
6199 rwatch_command (arg, from_tty);
6203 rwatch_command (char *arg, int from_tty)
6205 watch_command_1 (arg, hw_read, from_tty);
6209 awatch_command_wrapper (char *arg, int from_tty)
6211 awatch_command (arg, from_tty);
6215 awatch_command (char *arg, int from_tty)
6217 watch_command_1 (arg, hw_access, from_tty);
6221 /* Helper routines for the until_command routine in infcmd.c. Here
6222 because it uses the mechanisms of breakpoints. */
6224 /* This function is called by fetch_inferior_event via the
6225 cmd_continuation pointer, to complete the until command. It takes
6226 care of cleaning up the temporary breakpoints set up by the until
6229 until_break_command_continuation (struct continuation_arg *arg)
6231 struct cleanup *cleanups;
6233 cleanups = (struct cleanup *) arg->data.pointer;
6234 do_exec_cleanups (cleanups);
6238 until_break_command (char *arg, int from_tty, int anywhere)
6240 struct symtabs_and_lines sals;
6241 struct symtab_and_line sal;
6242 struct frame_info *frame = get_selected_frame (NULL);
6243 struct frame_info *prev_frame = get_prev_frame (frame);
6244 struct breakpoint *breakpoint;
6245 struct cleanup *old_chain;
6246 struct continuation_arg *arg1;
6249 clear_proceed_status ();
6251 /* Set a breakpoint where the user wants it and at return from
6254 if (default_breakpoint_valid)
6255 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6256 default_breakpoint_line, (char ***) NULL, NULL);
6258 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6259 0, (char ***) NULL, NULL);
6261 if (sals.nelts != 1)
6262 error (_("Couldn't get information on specified line."));
6265 xfree (sals.sals); /* malloc'd, so freed */
6268 error (_("Junk at end of arguments."));
6270 resolve_sal_pc (&sal);
6273 /* If the user told us to continue until a specified location,
6274 we don't specify a frame at which we need to stop. */
6275 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6277 /* Otherwise, specify the current frame, because we want to stop only
6278 at the very same frame. */
6279 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6282 if (!target_can_async_p ())
6283 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6285 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6287 /* If we are running asynchronously, and the target supports async
6288 execution, we are not waiting for the target to stop, in the call
6289 tp proceed, below. This means that we cannot delete the
6290 brekpoints until the target has actually stopped. The only place
6291 where we get a chance to do that is in fetch_inferior_event, so
6292 we must set things up for that. */
6294 if (target_can_async_p ())
6296 /* In this case the arg for the continuation is just the point
6297 in the exec_cleanups chain from where to start doing
6298 cleanups, because all the continuation does is the cleanups in
6299 the exec_cleanup_chain. */
6301 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6303 arg1->data.pointer = old_chain;
6305 add_continuation (until_break_command_continuation, arg1);
6308 /* Keep within the current frame, or in frames called by the current
6312 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6313 sal.pc = get_frame_pc (prev_frame);
6314 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6316 if (!target_can_async_p ())
6317 make_cleanup_delete_breakpoint (breakpoint);
6319 make_exec_cleanup_delete_breakpoint (breakpoint);
6322 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6323 /* Do the cleanups now, anly if we are not running asynchronously,
6324 of if we are, but the target is still synchronous. */
6325 if (!target_can_async_p ())
6326 do_cleanups (old_chain);
6330 ep_skip_leading_whitespace (char **s)
6332 if ((s == NULL) || (*s == NULL))
6334 while (isspace (**s))
6338 /* This function examines a string, and attempts to find a token
6339 that might be an event name in the leading characters. If a
6340 possible match is found, a pointer to the last character of
6341 the token is returned. Else, NULL is returned. */
6344 ep_find_event_name_end (char *arg)
6347 char *event_name_end = NULL;
6349 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6353 /* We break out of the loop when we find a token delimiter.
6354 Basically, we're looking for alphanumerics and underscores;
6355 anything else delimites the token. */
6358 if (!isalnum (*s) && (*s != '_'))
6364 return event_name_end;
6368 /* This function attempts to parse an optional "if <cond>" clause
6369 from the arg string. If one is not found, it returns NULL.
6371 Else, it returns a pointer to the condition string. (It does not
6372 attempt to evaluate the string against a particular block.) And,
6373 it updates arg to point to the first character following the parsed
6374 if clause in the arg string. */
6377 ep_parse_optional_if_clause (char **arg)
6381 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6384 /* Skip the "if" keyword. */
6387 /* Skip any extra leading whitespace, and record the start of the
6388 condition string. */
6389 ep_skip_leading_whitespace (arg);
6392 /* Assume that the condition occupies the remainder of the arg string. */
6393 (*arg) += strlen (cond_string);
6398 /* This function attempts to parse an optional filename from the arg
6399 string. If one is not found, it returns NULL.
6401 Else, it returns a pointer to the parsed filename. (This function
6402 makes no attempt to verify that a file of that name exists, or is
6403 accessible.) And, it updates arg to point to the first character
6404 following the parsed filename in the arg string.
6406 Note that clients needing to preserve the returned filename for
6407 future access should copy it to their own buffers. */
6409 ep_parse_optional_filename (char **arg)
6411 static char filename[1024];
6416 if ((*arg_p == '\0') || isspace (*arg_p))
6434 /* Commands to deal with catching events, such as signals, exceptions,
6435 process start/exit, etc. */
6439 catch_fork, catch_vfork
6444 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6447 char *cond_string = NULL;
6449 ep_skip_leading_whitespace (&arg);
6451 /* The allowed syntax is:
6453 catch [v]fork if <cond>
6455 First, check if there's an if clause. */
6456 cond_string = ep_parse_optional_if_clause (&arg);
6458 if ((*arg != '\0') && !isspace (*arg))
6459 error (_("Junk at end of arguments."));
6461 /* If this target supports it, create a fork or vfork catchpoint
6462 and enable reporting of such events. */
6466 create_fork_event_catchpoint (tempflag, cond_string);
6469 create_vfork_event_catchpoint (tempflag, cond_string);
6472 error (_("unsupported or unknown fork kind; cannot catch it"));
6478 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6480 char *cond_string = NULL;
6482 ep_skip_leading_whitespace (&arg);
6484 /* The allowed syntax is:
6486 catch exec if <cond>
6488 First, check if there's an if clause. */
6489 cond_string = ep_parse_optional_if_clause (&arg);
6491 if ((*arg != '\0') && !isspace (*arg))
6492 error (_("Junk at end of arguments."));
6494 /* If this target supports it, create an exec catchpoint
6495 and enable reporting of such events. */
6496 create_exec_event_catchpoint (tempflag, cond_string);
6500 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6502 char *dll_pathname = NULL;
6503 char *cond_string = NULL;
6505 ep_skip_leading_whitespace (&arg);
6507 /* The allowed syntax is:
6509 catch load if <cond>
6510 catch load <filename>
6511 catch load <filename> if <cond>
6513 The user is not allowed to specify the <filename> after an
6516 We'll ignore the pathological case of a file named "if".
6518 First, check if there's an if clause. If so, then there
6519 cannot be a filename. */
6520 cond_string = ep_parse_optional_if_clause (&arg);
6522 /* If there was an if clause, then there cannot be a filename.
6523 Else, there might be a filename and an if clause. */
6524 if (cond_string == NULL)
6526 dll_pathname = ep_parse_optional_filename (&arg);
6527 ep_skip_leading_whitespace (&arg);
6528 cond_string = ep_parse_optional_if_clause (&arg);
6531 if ((*arg != '\0') && !isspace (*arg))
6532 error (_("Junk at end of arguments."));
6534 /* Create a load breakpoint that only triggers when a load of
6535 the specified dll (or any dll, if no pathname was specified)
6537 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6538 dll_pathname, cond_string);
6542 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6544 char *dll_pathname = NULL;
6545 char *cond_string = NULL;
6547 ep_skip_leading_whitespace (&arg);
6549 /* The allowed syntax is:
6551 catch unload if <cond>
6552 catch unload <filename>
6553 catch unload <filename> if <cond>
6555 The user is not allowed to specify the <filename> after an
6558 We'll ignore the pathological case of a file named "if".
6560 First, check if there's an if clause. If so, then there
6561 cannot be a filename. */
6562 cond_string = ep_parse_optional_if_clause (&arg);
6564 /* If there was an if clause, then there cannot be a filename.
6565 Else, there might be a filename and an if clause. */
6566 if (cond_string == NULL)
6568 dll_pathname = ep_parse_optional_filename (&arg);
6569 ep_skip_leading_whitespace (&arg);
6570 cond_string = ep_parse_optional_if_clause (&arg);
6573 if ((*arg != '\0') && !isspace (*arg))
6574 error (_("Junk at end of arguments."));
6576 /* Create an unload breakpoint that only triggers when an unload of
6577 the specified dll (or any dll, if no pathname was specified)
6579 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6580 dll_pathname, cond_string);
6583 /* Commands to deal with catching exceptions. */
6585 /* Set a breakpoint at the specified callback routine for an
6586 exception event callback */
6589 create_exception_catchpoint (int tempflag, char *cond_string,
6590 enum exception_event_kind ex_event,
6591 struct symtab_and_line *sal)
6593 struct breakpoint *b;
6594 int thread = -1; /* All threads. */
6597 if (!sal) /* no exception support? */
6602 case EX_EVENT_THROW:
6603 bptype = bp_catch_throw;
6605 case EX_EVENT_CATCH:
6606 bptype = bp_catch_catch;
6608 default: /* error condition */
6609 error (_("Internal error -- invalid catchpoint kind"));
6612 b = set_raw_breakpoint (*sal, bptype);
6613 set_breakpoint_count (breakpoint_count + 1);
6614 b->number = breakpoint_count;
6615 b->cond_string = (cond_string == NULL) ?
6616 NULL : savestring (cond_string, strlen (cond_string));
6618 b->addr_string = NULL;
6619 b->enable_state = bp_enabled;
6620 b->disposition = tempflag ? disp_del : disp_donttouch;
6624 static enum print_stop_action
6625 print_exception_catchpoint (struct breakpoint *b)
6627 annotate_catchpoint (b->number);
6629 if (strstr (b->addr_string, "throw") != NULL)
6630 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6633 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6636 return PRINT_SRC_AND_LOC;
6640 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6645 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6648 *last_addr = b->loc->address;
6649 if (strstr (b->addr_string, "throw") != NULL)
6650 ui_out_field_string (uiout, "what", "exception throw");
6652 ui_out_field_string (uiout, "what", "exception catch");
6656 print_mention_exception_catchpoint (struct breakpoint *b)
6658 if (strstr (b->addr_string, "throw") != NULL)
6659 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6661 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6664 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6665 print_exception_catchpoint,
6666 print_one_exception_catchpoint,
6667 print_mention_exception_catchpoint
6671 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6672 enum exception_event_kind ex_event, int from_tty)
6674 char *trigger_func_name, *nameptr;
6675 struct symtabs_and_lines sals;
6676 struct breakpoint *b;
6678 if (ex_event == EX_EVENT_CATCH)
6679 trigger_func_name = xstrdup ("__cxa_begin_catch");
6681 trigger_func_name = xstrdup ("__cxa_throw");
6683 nameptr = trigger_func_name;
6684 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6685 if (sals.nelts == 0)
6687 xfree (trigger_func_name);
6691 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6692 set_breakpoint_count (breakpoint_count + 1);
6693 b->number = breakpoint_count;
6694 b->cond_string = (cond_string == NULL) ?
6695 NULL : savestring (cond_string, strlen (cond_string));
6697 b->addr_string = trigger_func_name;
6698 b->enable_state = bp_enabled;
6699 b->disposition = tempflag ? disp_del : disp_donttouch;
6700 b->ops = &gnu_v3_exception_catchpoint_ops;
6707 /* Deal with "catch catch" and "catch throw" commands */
6710 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6711 int tempflag, int from_tty)
6713 char *cond_string = NULL;
6714 struct symtab_and_line *sal = NULL;
6716 ep_skip_leading_whitespace (&arg);
6718 cond_string = ep_parse_optional_if_clause (&arg);
6720 if ((*arg != '\0') && !isspace (*arg))
6721 error (_("Junk at end of arguments."));
6723 if ((ex_event != EX_EVENT_THROW) &&
6724 (ex_event != EX_EVENT_CATCH))
6725 error (_("Unsupported or unknown exception event; cannot catch it"));
6727 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6730 /* See if we can find a callback routine */
6731 sal = target_enable_exception_callback (ex_event, 1);
6735 /* We have callbacks from the runtime system for exceptions.
6736 Set a breakpoint on the sal found, if no errors */
6737 if (sal != (struct symtab_and_line *) -1)
6738 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6740 return; /* something went wrong with setting up callbacks */
6743 warning (_("Unsupported with this platform/compiler combination."));
6746 /* Create a breakpoint struct for Ada exception catchpoints. */
6749 create_ada_exception_breakpoint (struct symtab_and_line sal,
6753 struct expression *cond,
6754 struct breakpoint_ops *ops,
6758 struct breakpoint *b;
6762 describe_other_breakpoints (sal.pc, sal.section, -1);
6763 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6764 version for exception catchpoints, because two catchpoints
6765 used for different exception names will use the same address.
6766 In this case, a "breakpoint ... also set at..." warning is
6767 unproductive. Besides. the warning phrasing is also a bit
6768 inapropriate, we should use the word catchpoint, and tell
6769 the user what type of catchpoint it is. The above is good
6770 enough for now, though. */
6773 b = set_raw_breakpoint (sal, bp_breakpoint);
6774 set_breakpoint_count (breakpoint_count + 1);
6776 b->enable_state = bp_enabled;
6777 b->disposition = tempflag ? disp_del : disp_donttouch;
6778 b->number = breakpoint_count;
6779 b->ignore_count = 0;
6780 b->loc->cond = cond;
6781 b->addr_string = addr_string;
6782 b->language = language_ada;
6783 b->cond_string = cond_string;
6784 b->exp_string = exp_string;
6787 b->from_tty = from_tty;
6792 /* Implement the "catch exception" command. */
6795 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6797 struct symtab_and_line sal;
6799 char *addr_string = NULL;
6800 char *exp_string = NULL;
6801 char *cond_string = NULL;
6802 struct expression *cond = NULL;
6803 struct breakpoint_ops *ops = NULL;
6805 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6806 &cond_string, &cond, &ops);
6807 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6808 cond_string, cond, ops, tempflag,
6812 /* Implement the "catch assert" command. */
6815 catch_assert_command (char *arg, int tempflag, int from_tty)
6817 struct symtab_and_line sal;
6818 char *addr_string = NULL;
6819 struct breakpoint_ops *ops = NULL;
6821 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6822 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6823 tempflag, from_tty);
6826 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6827 inside a catch_errors */
6830 cover_target_enable_exception_callback (void *arg)
6832 args_for_catchpoint_enable *args = arg;
6833 struct symtab_and_line *sal;
6834 sal = target_enable_exception_callback (args->kind, args->enable_p);
6837 else if (sal == (struct symtab_and_line *) -1)
6840 return 1; /*is valid */
6844 catch_command_1 (char *arg, int tempflag, int from_tty)
6847 /* The first argument may be an event name, such as "start" or "load".
6848 If so, then handle it as such. If it doesn't match an event name,
6849 then attempt to interpret it as an exception name. (This latter is
6850 the v4.16-and-earlier GDB meaning of the "catch" command.)
6852 First, try to find the bounds of what might be an event name. */
6853 char *arg1_start = arg;
6857 if (arg1_start == NULL)
6859 /* Old behaviour was to use pre-v-4.16 syntax */
6860 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6862 /* Now, this is not allowed */
6863 error (_("Catch requires an event name."));
6866 arg1_end = ep_find_event_name_end (arg1_start);
6867 if (arg1_end == NULL)
6868 error (_("catch requires an event"));
6869 arg1_length = arg1_end + 1 - arg1_start;
6871 /* Try to match what we found against known event names. */
6872 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6874 error (_("Catch of signal not yet implemented"));
6876 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6878 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6879 tempflag, from_tty);
6881 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6883 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6884 tempflag, from_tty);
6886 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6888 error (_("Catch of thread_start not yet implemented"));
6890 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6892 error (_("Catch of thread_exit not yet implemented"));
6894 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6896 error (_("Catch of thread_join not yet implemented"));
6898 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6900 error (_("Catch of start not yet implemented"));
6902 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6904 error (_("Catch of exit not yet implemented"));
6906 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6908 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6910 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6912 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6914 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6916 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6918 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6920 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6922 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6924 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6926 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6928 error (_("Catch of stop not yet implemented"));
6930 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6932 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6935 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6937 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6940 /* This doesn't appear to be an event name */
6944 /* Pre-v.4.16 behaviour was to treat the argument
6945 as the name of an exception */
6946 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6947 /* Now this is not allowed */
6948 error (_("Unknown event kind specified for catch"));
6953 /* Used by the gui, could be made a worker for other things. */
6956 set_breakpoint_sal (struct symtab_and_line sal)
6958 struct breakpoint *b;
6959 b = set_raw_breakpoint (sal, bp_breakpoint);
6960 set_breakpoint_count (breakpoint_count + 1);
6961 b->number = breakpoint_count;
6967 catch_command (char *arg, int from_tty)
6969 catch_command_1 (arg, 0, from_tty);
6974 tcatch_command (char *arg, int from_tty)
6976 catch_command_1 (arg, 1, from_tty);
6979 /* Delete breakpoints by address or line. */
6982 clear_command (char *arg, int from_tty)
6984 struct breakpoint *b, *tmp, *prev, *found;
6986 struct symtabs_and_lines sals;
6987 struct symtab_and_line sal;
6992 sals = decode_line_spec (arg, 1);
6997 sals.sals = (struct symtab_and_line *)
6998 xmalloc (sizeof (struct symtab_and_line));
6999 make_cleanup (xfree, sals.sals);
7000 init_sal (&sal); /* initialize to zeroes */
7001 sal.line = default_breakpoint_line;
7002 sal.symtab = default_breakpoint_symtab;
7003 sal.pc = default_breakpoint_address;
7004 if (sal.symtab == 0)
7005 error (_("No source file specified."));
7013 /* We don't call resolve_sal_pc here. That's not
7014 as bad as it seems, because all existing breakpoints
7015 typically have both file/line and pc set. So, if
7016 clear is given file/line, we can match this to existing
7017 breakpoint without obtaining pc at all.
7019 We only support clearing given the address explicitly
7020 present in breakpoint table. Say, we've set breakpoint
7021 at file:line. There were several PC values for that file:line,
7022 due to optimization, all in one block.
7023 We've picked one PC value. If "clear" is issued with another
7024 PC corresponding to the same file:line, the breakpoint won't
7025 be cleared. We probably can still clear the breakpoint, but
7026 since the other PC value is never presented to user, user
7027 can only find it by guessing, and it does not seem important
7030 /* For each line spec given, delete bps which correspond
7031 to it. Do it in two passes, solely to preserve the current
7032 behavior that from_tty is forced true if we delete more than
7036 for (i = 0; i < sals.nelts; i++)
7038 /* If exact pc given, clear bpts at that pc.
7039 If line given (pc == 0), clear all bpts on specified line.
7040 If defaulting, clear all bpts on default line
7043 defaulting sal.pc != 0 tests to do
7048 1 0 <can't happen> */
7053 /* Find all matching breakpoints, remove them from the
7054 breakpoint chain, and add them to the 'found' chain. */
7055 ALL_BREAKPOINTS_SAFE (b, tmp)
7058 /* Are we going to delete b? */
7059 if (b->type != bp_none
7060 && b->type != bp_watchpoint
7061 && b->type != bp_hardware_watchpoint
7062 && b->type != bp_read_watchpoint
7063 && b->type != bp_access_watchpoint)
7065 struct bp_location *loc = b->loc;
7066 for (; loc; loc = loc->next)
7068 int pc_match = sal.pc
7069 && (loc->address == sal.pc)
7070 && (!section_is_overlay (loc->section)
7071 || loc->section == sal.section);
7072 int line_match = ((default_match || (0 == sal.pc))
7073 && b->source_file != NULL
7074 && sal.symtab != NULL
7075 && strcmp (b->source_file, sal.symtab->filename) == 0
7076 && b->line_number == sal.line);
7077 if (pc_match || line_match)
7087 /* Remove it from breakpoint_chain... */
7088 if (b == breakpoint_chain)
7090 /* b is at the head of the list */
7091 breakpoint_chain = b->next;
7095 prev->next = b->next;
7097 /* And add it to 'found' chain. */
7103 /* Keep b, and keep a pointer to it. */
7108 /* Now go thru the 'found' chain and delete them. */
7112 error (_("No breakpoint at %s."), arg);
7114 error (_("No breakpoint at this line."));
7118 from_tty = 1; /* Always report if deleted more than one */
7122 printf_unfiltered (_("Deleted breakpoint "));
7124 printf_unfiltered (_("Deleted breakpoints "));
7126 breakpoints_changed ();
7130 printf_unfiltered ("%d ", found->number);
7132 delete_breakpoint (found);
7136 putchar_unfiltered ('\n');
7139 /* Delete breakpoint in BS if they are `delete' breakpoints and
7140 all breakpoints that are marked for deletion, whether hit or not.
7141 This is called after any breakpoint is hit, or after errors. */
7144 breakpoint_auto_delete (bpstat bs)
7146 struct breakpoint *b, *temp;
7148 for (; bs; bs = bs->next)
7149 if (bs->breakpoint_at && bs->breakpoint_at->owner->disposition == disp_del
7151 delete_breakpoint (bs->breakpoint_at->owner);
7153 ALL_BREAKPOINTS_SAFE (b, temp)
7155 if (b->disposition == disp_del_at_next_stop)
7156 delete_breakpoint (b);
7160 /* Remove locations of breakpoint BPT from
7161 the global list of breakpoint locations. */
7164 unlink_locations_from_global_list (struct breakpoint *bpt)
7166 /* This code assumes that the locations
7167 of a breakpoint are found in the global list
7168 in the same order, but not necessary adjacent. */
7169 struct bp_location **tmp = &bp_location_chain;
7170 struct bp_location *here = bpt->loc;
7175 for (; *tmp && here;)
7179 *tmp = here->global_next;
7184 tmp = &((*tmp)->global_next);
7189 /* Delete a breakpoint and clean up all traces of it in the data
7193 delete_breakpoint (struct breakpoint *bpt)
7195 struct breakpoint *b;
7197 struct bp_location *loc;
7199 gdb_assert (bpt != NULL);
7201 /* Has this bp already been deleted? This can happen because multiple
7202 lists can hold pointers to bp's. bpstat lists are especial culprits.
7204 One example of this happening is a watchpoint's scope bp. When the
7205 scope bp triggers, we notice that the watchpoint is out of scope, and
7206 delete it. We also delete its scope bp. But the scope bp is marked
7207 "auto-deleting", and is already on a bpstat. That bpstat is then
7208 checked for auto-deleting bp's, which are deleted.
7210 A real solution to this problem might involve reference counts in bp's,
7211 and/or giving them pointers back to their referencing bpstat's, and
7212 teaching delete_breakpoint to only free a bp's storage when no more
7213 references were extent. A cheaper bandaid was chosen. */
7214 if (bpt->type == bp_none)
7217 if (deprecated_delete_breakpoint_hook)
7218 deprecated_delete_breakpoint_hook (bpt);
7219 breakpoint_delete_event (bpt->number);
7221 for (loc = bpt->loc; loc; loc = loc->next)
7224 remove_breakpoint (loc, mark_inserted);
7226 free_valchain (loc);
7231 if (loc->function_name)
7232 xfree (loc->function_name);
7235 if (breakpoint_chain == bpt)
7236 breakpoint_chain = bpt->next;
7238 /* If we have callback-style exception catchpoints, don't go through
7239 the adjustments to the C++ runtime library etc. if the inferior
7240 isn't actually running. target_enable_exception_callback for a
7241 null target ops vector gives an undesirable error message, so we
7242 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7243 exceptions are supported in this way, it's OK for now. FIXME */
7244 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
7246 /* Format possible error msg */
7247 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
7249 struct cleanup *cleanups = make_cleanup (xfree, message);
7250 args_for_catchpoint_enable args;
7251 args.kind = bpt->type == bp_catch_catch ?
7252 EX_EVENT_CATCH : EX_EVENT_THROW;
7254 catch_errors (cover_target_enable_exception_callback, &args,
7255 message, RETURN_MASK_ALL);
7256 do_cleanups (cleanups);
7263 b->next = bpt->next;
7267 unlink_locations_from_global_list (bpt);
7269 check_duplicates (bpt);
7271 if (bpt->type != bp_hardware_watchpoint
7272 && bpt->type != bp_read_watchpoint
7273 && bpt->type != bp_access_watchpoint
7274 && bpt->type != bp_catch_fork
7275 && bpt->type != bp_catch_vfork
7276 && bpt->type != bp_catch_exec)
7277 for (loc = bpt->loc; loc; loc = loc->next)
7279 /* If this breakpoint location was inserted, and there is
7280 another breakpoint at the same address, we need to
7281 insert the other breakpoint. */
7284 struct bp_location *loc2;
7285 ALL_BP_LOCATIONS (loc2)
7286 if (loc2->address == loc->address
7287 && loc2->section == loc->section
7289 && loc2->owner->enable_state != bp_disabled
7291 && !loc2->shlib_disabled
7292 && loc2->owner->enable_state != bp_call_disabled)
7296 /* We should never reach this point if there is a permanent
7297 breakpoint at the same address as the one being deleted.
7298 If there is a permanent breakpoint somewhere, it should
7299 always be the only one inserted. */
7300 if (loc2->owner->enable_state == bp_permanent)
7301 internal_error (__FILE__, __LINE__,
7302 _("another breakpoint was inserted on top of "
7303 "a permanent breakpoint"));
7305 memset (&loc2->target_info, 0, sizeof (loc2->target_info));
7306 loc2->target_info.placed_address = loc2->address;
7307 if (b->type == bp_hardware_breakpoint)
7308 val = target_insert_hw_breakpoint (&loc2->target_info);
7310 val = target_insert_breakpoint (&loc2->target_info);
7312 /* If there was an error in the insert, print a message, then stop execution. */
7315 struct ui_file *tmp_error_stream = mem_fileopen ();
7316 make_cleanup_ui_file_delete (tmp_error_stream);
7319 if (b->type == bp_hardware_breakpoint)
7321 fprintf_unfiltered (tmp_error_stream,
7322 "Cannot insert hardware breakpoint %d.\n"
7323 "You may have requested too many hardware breakpoints.\n",
7328 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
7329 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
7330 deprecated_print_address_numeric (loc2->address, 1, tmp_error_stream);
7331 fprintf_filtered (tmp_error_stream, ": %s.\n",
7332 safe_strerror (val));
7335 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
7336 target_terminal_ours_for_output ();
7337 error_stream(tmp_error_stream);
7345 free_command_lines (&bpt->commands);
7346 if (bpt->cond_string != NULL)
7347 xfree (bpt->cond_string);
7348 if (bpt->addr_string != NULL)
7349 xfree (bpt->addr_string);
7350 if (bpt->exp != NULL)
7352 if (bpt->exp_string != NULL)
7353 xfree (bpt->exp_string);
7354 if (bpt->val != NULL)
7355 value_free (bpt->val);
7356 if (bpt->source_file != NULL)
7357 xfree (bpt->source_file);
7358 if (bpt->dll_pathname != NULL)
7359 xfree (bpt->dll_pathname);
7360 if (bpt->triggered_dll_pathname != NULL)
7361 xfree (bpt->triggered_dll_pathname);
7362 if (bpt->exec_pathname != NULL)
7363 xfree (bpt->exec_pathname);
7365 /* Be sure no bpstat's are pointing at it after it's been freed. */
7366 /* FIXME, how can we find all bpstat's?
7367 We just check stop_bpstat for now. Note that we cannot just
7368 remove bpstats pointing at bpt from the stop_bpstat list
7369 entirely, as breakpoint commands are associated with the bpstat;
7370 if we remove it here, then the later call to
7371 bpstat_do_actions (&stop_bpstat);
7372 in event-top.c won't do anything, and temporary breakpoints
7373 with commands won't work. */
7374 for (bs = stop_bpstat; bs; bs = bs->next)
7375 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7377 bs->breakpoint_at = NULL;
7379 /* bs->commands will be freed later. */
7381 /* On the chance that someone will soon try again to delete this same
7382 bp, we mark it as deleted before freeing its storage. */
7383 bpt->type = bp_none;
7385 for (loc = bpt->loc; loc;)
7387 struct bp_location *loc_next = loc->next;
7395 do_delete_breakpoint_cleanup (void *b)
7397 delete_breakpoint (b);
7401 make_cleanup_delete_breakpoint (struct breakpoint *b)
7403 return make_cleanup (do_delete_breakpoint_cleanup, b);
7407 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7409 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7413 delete_command (char *arg, int from_tty)
7415 struct breakpoint *b, *temp;
7421 int breaks_to_delete = 0;
7423 /* Delete all breakpoints if no argument.
7424 Do not delete internal or call-dummy breakpoints, these
7425 have to be deleted with an explicit breakpoint number argument. */
7428 if (b->type != bp_call_dummy &&
7429 b->type != bp_shlib_event &&
7430 b->type != bp_thread_event &&
7431 b->type != bp_overlay_event &&
7434 breaks_to_delete = 1;
7439 /* Ask user only if there are some breakpoints to delete. */
7441 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7443 ALL_BREAKPOINTS_SAFE (b, temp)
7445 if (b->type != bp_call_dummy &&
7446 b->type != bp_shlib_event &&
7447 b->type != bp_thread_event &&
7448 b->type != bp_overlay_event &&
7450 delete_breakpoint (b);
7455 map_breakpoint_numbers (arg, delete_breakpoint);
7459 all_locations_are_pending (struct bp_location *loc)
7461 for (; loc; loc = loc->next)
7462 if (!loc->shlib_disabled)
7468 update_breakpoint_locations (struct breakpoint *b,
7469 struct symtabs_and_lines sals)
7473 struct bp_location *existing_locations = b->loc;
7475 /* If there's no new locations, and all existing locations
7476 are pending, don't do anything. This optimizes
7477 the common case where all locations are in the same
7478 shared library, that was unloaded. We'd like to
7479 retain the location, so that when the library
7480 is loaded again, we don't loose the enabled/disabled
7481 status of the individual locations. */
7482 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7485 unlink_locations_from_global_list (b);
7488 for (i = 0; i < sals.nelts; ++i)
7490 struct bp_location *new_loc =
7491 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7493 /* Reparse conditions, they might contain references to the
7495 if (b->cond_string != NULL)
7497 struct gdb_exception e;
7500 TRY_CATCH (e, RETURN_MASK_ERROR)
7502 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7507 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7508 b->number, e.message);
7509 new_loc->enabled = 0;
7513 if (b->source_file != NULL)
7514 xfree (b->source_file);
7515 if (sals.sals[i].symtab == NULL)
7516 b->source_file = NULL;
7519 savestring (sals.sals[i].symtab->filename,
7520 strlen (sals.sals[i].symtab->filename));
7522 if (b->line_number == 0)
7523 b->line_number = sals.sals[i].line;
7526 /* If possible, carry over 'disable' status from existing breakpoints. */
7528 struct bp_location *e = existing_locations;
7529 for (; e; e = e->next)
7531 if (!e->enabled && e->function_name)
7533 struct bp_location *l = b->loc;
7534 for (; l; l = l->next)
7535 if (l->function_name
7536 && strcmp (e->function_name, l->function_name) == 0)
7545 while (existing_locations)
7547 struct bp_location *next = existing_locations->next;
7548 free_bp_location (existing_locations);
7549 existing_locations = next;
7554 /* Reset a breakpoint given it's struct breakpoint * BINT.
7555 The value we return ends up being the return value from catch_errors.
7556 Unused in this case. */
7559 breakpoint_re_set_one (void *bint)
7561 /* get past catch_errs */
7562 struct breakpoint *b = (struct breakpoint *) bint;
7566 int *not_found_ptr = ¬_found;
7567 struct symtabs_and_lines sals = {};
7568 struct symtabs_and_lines expanded;
7570 enum enable_state save_enable;
7571 struct gdb_exception e;
7577 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7581 case bp_hardware_breakpoint:
7583 case bp_catch_unload:
7584 if (b->addr_string == NULL)
7586 /* Anything without a string can't be re-set. */
7587 delete_breakpoint (b);
7591 set_language (b->language);
7592 input_radix = b->input_radix;
7594 TRY_CATCH (e, RETURN_MASK_ERROR)
7596 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7601 int not_found_and_ok = 0;
7602 /* For pending breakpoints, it's expected that parsing
7603 will fail until the right shared library is loaded.
7604 User has already told to create pending breakpoints and
7605 don't need extra messages. If breakpoint is in bp_shlib_disabled
7606 state, then user already saw the message about that breakpoint
7607 being disabled, and don't want to see more errors. */
7609 && (b->condition_not_parsed
7610 || (b->loc && b->loc->shlib_disabled)
7611 || b->enable_state == bp_disabled))
7612 not_found_and_ok = 1;
7614 if (!not_found_and_ok)
7616 /* We surely don't want to warn about the same breakpoint
7617 10 times. One solution, implemented here, is disable
7618 the breakpoint on error. Another solution would be to
7619 have separate 'warning emitted' flag. Since this
7620 happens only when a binary has changed, I don't know
7621 which approach is better. */
7622 b->enable_state = bp_disabled;
7623 throw_exception (e);
7630 gdb_assert (sals.nelts == 1);
7631 resolve_sal_pc (&sals.sals[0]);
7632 if (b->condition_not_parsed && s && s[0])
7634 char *cond_string = 0;
7636 find_condition_and_thread (s, sals.sals[0].pc,
7637 &cond_string, &thread);
7639 b->cond_string = cond_string;
7641 b->condition_not_parsed = 0;
7643 expanded = expand_line_sal_maybe (sals.sals[0]);
7644 update_breakpoint_locations (b, expanded);
7646 /* Now that this is re-enabled, check_duplicates
7648 check_duplicates (b);
7654 case bp_hardware_watchpoint:
7655 case bp_read_watchpoint:
7656 case bp_access_watchpoint:
7657 innermost_block = NULL;
7658 /* The issue arises of what context to evaluate this in. The
7659 same one as when it was set, but what does that mean when
7660 symbols have been re-read? We could save the filename and
7661 functionname, but if the context is more local than that, the
7662 best we could do would be something like how many levels deep
7663 and which index at that particular level, but that's going to
7664 be less stable than filenames or function names. */
7666 /* So for now, just use a global context. */
7670 /* Avoid re-freeing b->exp if an error during the call to
7671 parse_expression. */
7674 b->exp = parse_expression (b->exp_string);
7675 b->exp_valid_block = innermost_block;
7676 mark = value_mark ();
7679 value_free (b->val);
7680 /* Avoid re-freeing b->val if an error during the call to
7681 evaluate_expression. */
7684 b->val = evaluate_expression (b->exp);
7685 release_value (b->val);
7686 if (value_lazy (b->val) && breakpoint_enabled (b))
7687 value_fetch_lazy (b->val);
7689 if (b->cond_string != NULL)
7694 xfree (b->loc->cond);
7695 /* Avoid re-freeing b->exp if an error during the call
7697 b->loc->cond = NULL;
7699 b->loc->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7701 if (breakpoint_enabled (b))
7703 value_free_to_mark (mark);
7705 case bp_catch_catch:
7706 case bp_catch_throw:
7708 /* We needn't really do anything to reset these, since the mask
7709 that requests them is unaffected by e.g., new libraries being
7712 case bp_catch_vfork:
7717 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7719 /* Delete longjmp and overlay event breakpoints; they will be
7720 reset later by breakpoint_re_set. */
7722 case bp_longjmp_resume:
7723 case bp_overlay_event:
7724 delete_breakpoint (b);
7727 /* This breakpoint is special, it's set up when the inferior
7728 starts and we really don't want to touch it. */
7729 case bp_shlib_event:
7731 /* Like bp_shlib_event, this breakpoint type is special.
7732 Once it is set up, we do not want to touch it. */
7733 case bp_thread_event:
7735 /* Keep temporary breakpoints, which can be encountered when we step
7736 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7737 Otherwise these should have been blown away via the cleanup chain
7738 or by breakpoint_init_inferior when we rerun the executable. */
7741 case bp_watchpoint_scope:
7743 case bp_step_resume:
7750 /* Re-set all breakpoints after symbols have been re-loaded. */
7752 breakpoint_re_set (void)
7754 struct breakpoint *b, *temp;
7755 enum language save_language;
7756 int save_input_radix;
7758 save_language = current_language->la_language;
7759 save_input_radix = input_radix;
7760 ALL_BREAKPOINTS_SAFE (b, temp)
7762 /* Format possible error msg */
7763 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7765 struct cleanup *cleanups = make_cleanup (xfree, message);
7766 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7767 do_cleanups (cleanups);
7769 set_language (save_language);
7770 input_radix = save_input_radix;
7772 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7774 create_longjmp_breakpoint ("longjmp");
7775 create_longjmp_breakpoint ("_longjmp");
7776 create_longjmp_breakpoint ("siglongjmp");
7777 create_longjmp_breakpoint ("_siglongjmp");
7778 create_longjmp_breakpoint (NULL);
7781 create_overlay_event_breakpoint ("_ovly_debug_event");
7784 /* Reset the thread number of this breakpoint:
7786 - If the breakpoint is for all threads, leave it as-is.
7787 - Else, reset it to the current thread for inferior_ptid. */
7789 breakpoint_re_set_thread (struct breakpoint *b)
7791 if (b->thread != -1)
7793 if (in_thread_list (inferior_ptid))
7794 b->thread = pid_to_thread_id (inferior_ptid);
7798 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7799 If from_tty is nonzero, it prints a message to that effect,
7800 which ends with a period (no newline). */
7803 set_ignore_count (int bptnum, int count, int from_tty)
7805 struct breakpoint *b;
7811 if (b->number == bptnum)
7813 b->ignore_count = count;
7817 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7819 else if (count == 1)
7820 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7823 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7826 breakpoints_changed ();
7827 breakpoint_modify_event (b->number);
7831 error (_("No breakpoint number %d."), bptnum);
7834 /* Clear the ignore counts of all breakpoints. */
7836 breakpoint_clear_ignore_counts (void)
7838 struct breakpoint *b;
7841 b->ignore_count = 0;
7844 /* Command to set ignore-count of breakpoint N to COUNT. */
7847 ignore_command (char *args, int from_tty)
7853 error_no_arg (_("a breakpoint number"));
7855 num = get_number (&p);
7857 error (_("bad breakpoint number: '%s'"), args);
7859 error (_("Second argument (specified ignore-count) is missing."));
7861 set_ignore_count (num,
7862 longest_to_int (value_as_long (parse_and_eval (p))),
7865 printf_filtered ("\n");
7868 /* Call FUNCTION on each of the breakpoints
7869 whose numbers are given in ARGS. */
7872 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7877 struct breakpoint *b, *tmp;
7881 error_no_arg (_("one or more breakpoint numbers"));
7888 num = get_number_or_range (&p1);
7891 warning (_("bad breakpoint number at or near '%s'"), p);
7895 ALL_BREAKPOINTS_SAFE (b, tmp)
7896 if (b->number == num)
7898 struct breakpoint *related_breakpoint = b->related_breakpoint;
7901 if (related_breakpoint)
7902 function (related_breakpoint);
7906 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7912 static struct bp_location *
7913 find_location_by_number (char *number)
7915 char *dot = strchr (number, '.');
7919 struct breakpoint *b;
7920 struct bp_location *loc;
7925 bp_num = get_number_or_range (&p1);
7927 error (_("Bad breakpoint number '%s'"), number);
7930 if (b->number == bp_num)
7935 if (!b || b->number != bp_num)
7936 error (_("Bad breakpoint number '%s'"), number);
7939 loc_num = get_number_or_range (&p1);
7941 error (_("Bad breakpoint location number '%s'"), number);
7945 for (;loc_num && loc; --loc_num, loc = loc->next)
7948 error (_("Bad breakpoint location number '%s'"), dot+1);
7954 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7955 If from_tty is nonzero, it prints a message to that effect,
7956 which ends with a period (no newline). */
7959 disable_breakpoint (struct breakpoint *bpt)
7961 /* Never disable a watchpoint scope breakpoint; we want to
7962 hit them when we leave scope so we can delete both the
7963 watchpoint and its scope breakpoint at that time. */
7964 if (bpt->type == bp_watchpoint_scope)
7967 /* You can't disable permanent breakpoints. */
7968 if (bpt->enable_state == bp_permanent)
7971 bpt->enable_state = bp_disabled;
7973 check_duplicates (bpt);
7975 if (deprecated_modify_breakpoint_hook)
7976 deprecated_modify_breakpoint_hook (bpt);
7977 breakpoint_modify_event (bpt->number);
7981 disable_command (char *args, int from_tty)
7983 struct breakpoint *bpt;
7985 ALL_BREAKPOINTS (bpt)
7989 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7994 case bp_catch_unload:
7996 case bp_catch_vfork:
7998 case bp_catch_catch:
7999 case bp_catch_throw:
8000 case bp_hardware_breakpoint:
8002 case bp_hardware_watchpoint:
8003 case bp_read_watchpoint:
8004 case bp_access_watchpoint:
8005 disable_breakpoint (bpt);
8009 else if (strchr (args, '.'))
8011 struct bp_location *loc = find_location_by_number (args);
8014 check_duplicates (loc->owner);
8017 map_breakpoint_numbers (args, disable_breakpoint);
8021 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
8023 int target_resources_ok, other_type_used;
8026 if (bpt->type == bp_hardware_breakpoint)
8029 i = hw_breakpoint_used_count ();
8030 target_resources_ok =
8031 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
8033 if (target_resources_ok == 0)
8034 error (_("No hardware breakpoint support in the target."));
8035 else if (target_resources_ok < 0)
8036 error (_("Hardware breakpoints used exceeds limit."));
8039 if (bpt->enable_state != bp_permanent)
8040 bpt->enable_state = bp_enabled;
8041 bpt->disposition = disposition;
8042 check_duplicates (bpt);
8043 breakpoints_changed ();
8045 if (bpt->type == bp_watchpoint ||
8046 bpt->type == bp_hardware_watchpoint ||
8047 bpt->type == bp_read_watchpoint ||
8048 bpt->type == bp_access_watchpoint)
8050 struct frame_id saved_frame_id;
8052 saved_frame_id = get_frame_id (get_selected_frame (NULL));
8053 if (bpt->exp_valid_block != NULL)
8055 struct frame_info *fr =
8056 fr = frame_find_by_id (bpt->watchpoint_frame);
8059 printf_filtered (_("\
8060 Cannot enable watchpoint %d because the block in which its expression\n\
8061 is valid is not currently in scope.\n"), bpt->number);
8062 bpt->enable_state = bp_disabled;
8068 value_free (bpt->val);
8069 mark = value_mark ();
8070 bpt->val = evaluate_expression (bpt->exp);
8071 release_value (bpt->val);
8072 if (value_lazy (bpt->val))
8073 value_fetch_lazy (bpt->val);
8075 if (bpt->type == bp_hardware_watchpoint ||
8076 bpt->type == bp_read_watchpoint ||
8077 bpt->type == bp_access_watchpoint)
8079 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
8080 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
8082 /* Hack around 'unused var' error for some targets here */
8083 (void) mem_cnt, (void) i;
8084 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
8085 bpt->type, i + mem_cnt, other_type_used);
8086 /* we can consider of type is bp_hardware_watchpoint, convert to
8087 bp_watchpoint in the following condition */
8088 if (target_resources_ok < 0)
8090 printf_filtered (_("\
8091 Cannot enable watchpoint %d because target watch resources\n\
8092 have been allocated for other watchpoints.\n"), bpt->number);
8093 bpt->enable_state = bp_disabled;
8094 value_free_to_mark (mark);
8099 select_frame (frame_find_by_id (saved_frame_id));
8100 value_free_to_mark (mark);
8103 if (deprecated_modify_breakpoint_hook)
8104 deprecated_modify_breakpoint_hook (bpt);
8105 breakpoint_modify_event (bpt->number);
8110 enable_breakpoint (struct breakpoint *bpt)
8112 do_enable_breakpoint (bpt, bpt->disposition);
8115 /* The enable command enables the specified breakpoints (or all defined
8116 breakpoints) so they once again become (or continue to be) effective
8117 in stopping the inferior. */
8120 enable_command (char *args, int from_tty)
8122 struct breakpoint *bpt;
8124 ALL_BREAKPOINTS (bpt)
8128 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8133 case bp_catch_unload:
8135 case bp_catch_vfork:
8137 case bp_catch_catch:
8138 case bp_catch_throw:
8139 case bp_hardware_breakpoint:
8141 case bp_hardware_watchpoint:
8142 case bp_read_watchpoint:
8143 case bp_access_watchpoint:
8144 enable_breakpoint (bpt);
8148 else if (strchr (args, '.'))
8150 struct bp_location *loc = find_location_by_number (args);
8153 check_duplicates (loc->owner);
8156 map_breakpoint_numbers (args, enable_breakpoint);
8160 enable_once_breakpoint (struct breakpoint *bpt)
8162 do_enable_breakpoint (bpt, disp_disable);
8166 enable_once_command (char *args, int from_tty)
8168 map_breakpoint_numbers (args, enable_once_breakpoint);
8172 enable_delete_breakpoint (struct breakpoint *bpt)
8174 do_enable_breakpoint (bpt, disp_del);
8178 enable_delete_command (char *args, int from_tty)
8180 map_breakpoint_numbers (args, enable_delete_breakpoint);
8184 set_breakpoint_cmd (char *args, int from_tty)
8189 show_breakpoint_cmd (char *args, int from_tty)
8193 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8195 struct symtabs_and_lines
8196 decode_line_spec_1 (char *string, int funfirstline)
8198 struct symtabs_and_lines sals;
8200 error (_("Empty line specification."));
8201 if (default_breakpoint_valid)
8202 sals = decode_line_1 (&string, funfirstline,
8203 default_breakpoint_symtab,
8204 default_breakpoint_line,
8205 (char ***) NULL, NULL);
8207 sals = decode_line_1 (&string, funfirstline,
8208 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8210 error (_("Junk at end of line specification: %s"), string);
8214 /* Create and insert a raw software breakpoint at PC. Return an
8215 identifier, which should be used to remove the breakpoint later.
8216 In general, places which call this should be using something on the
8217 breakpoint chain instead; this function should be eliminated
8221 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8223 struct bp_target_info *bp_tgt;
8225 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8226 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8228 bp_tgt->placed_address = pc;
8229 if (target_insert_breakpoint (bp_tgt) != 0)
8231 /* Could not insert the breakpoint. */
8239 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8242 deprecated_remove_raw_breakpoint (void *bp)
8244 struct bp_target_info *bp_tgt = bp;
8247 ret = target_remove_breakpoint (bp_tgt);
8253 /* One (or perhaps two) breakpoints used for software single stepping. */
8255 static void *single_step_breakpoints[2];
8257 /* Create and insert a breakpoint for software single step. */
8260 insert_single_step_breakpoint (CORE_ADDR next_pc)
8264 if (single_step_breakpoints[0] == NULL)
8265 bpt_p = &single_step_breakpoints[0];
8268 gdb_assert (single_step_breakpoints[1] == NULL);
8269 bpt_p = &single_step_breakpoints[1];
8272 /* NOTE drow/2006-04-11: A future improvement to this function would be
8273 to only create the breakpoints once, and actually put them on the
8274 breakpoint chain. That would let us use set_raw_breakpoint. We could
8275 adjust the addresses each time they were needed. Doing this requires
8276 corresponding changes elsewhere where single step breakpoints are
8277 handled, however. So, for now, we use this. */
8279 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8281 error (_("Could not insert single-step breakpoint at 0x%s"),
8282 paddr_nz (next_pc));
8285 /* Remove and delete any breakpoints used for software single step. */
8288 remove_single_step_breakpoints (void)
8290 gdb_assert (single_step_breakpoints[0] != NULL);
8292 /* See insert_single_step_breakpoint for more about this deprecated
8294 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8295 single_step_breakpoints[0] = NULL;
8297 if (single_step_breakpoints[1] != NULL)
8299 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8300 single_step_breakpoints[1] = NULL;
8304 /* Check whether a software single-step breakpoint is inserted at PC. */
8307 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8311 for (i = 0; i < 2; i++)
8313 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8314 if (bp_tgt && bp_tgt->placed_address == pc)
8322 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8323 It is defined as a macro to prevent duplication.
8324 COMMAND should be a string constant containing the name of the command. */
8325 #define BREAK_ARGS_HELP(command) \
8326 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8327 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8328 If a line number is specified, break at start of code for that line.\n\
8329 If a function is specified, break at start of code for that function.\n\
8330 If an address is specified, break at that exact address.\n\
8331 With no LOCATION, uses current execution address of selected stack frame.\n\
8332 This is useful for breaking on return to a stack frame.\n\
8334 THREADNUM is the number from \"info threads\".\n\
8335 CONDITION is a boolean expression.\n\
8337 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8339 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8342 _initialize_breakpoint (void)
8344 static struct cmd_list_element *breakpoint_set_cmdlist;
8345 static struct cmd_list_element *breakpoint_show_cmdlist;
8346 struct cmd_list_element *c;
8348 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8350 breakpoint_chain = 0;
8351 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8352 before a breakpoint is set. */
8353 breakpoint_count = 0;
8355 add_com ("ignore", class_breakpoint, ignore_command, _("\
8356 Set ignore-count of breakpoint number N to COUNT.\n\
8357 Usage is `ignore N COUNT'."));
8359 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8361 add_com ("commands", class_breakpoint, commands_command, _("\
8362 Set commands to be executed when a breakpoint is hit.\n\
8363 Give breakpoint number as argument after \"commands\".\n\
8364 With no argument, the targeted breakpoint is the last one set.\n\
8365 The commands themselves follow starting on the next line.\n\
8366 Type a line containing \"end\" to indicate the end of them.\n\
8367 Give \"silent\" as the first line to make the breakpoint silent;\n\
8368 then no output is printed when it is hit, except what the commands print."));
8370 add_com ("condition", class_breakpoint, condition_command, _("\
8371 Specify breakpoint number N to break only if COND is true.\n\
8372 Usage is `condition N COND', where N is an integer and COND is an\n\
8373 expression to be evaluated whenever breakpoint N is reached."));
8375 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8376 Set a temporary breakpoint.\n\
8377 Like \"break\" except the breakpoint is only temporary,\n\
8378 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8379 by using \"enable delete\" on the breakpoint number.\n\
8381 BREAK_ARGS_HELP ("tbreak")));
8382 set_cmd_completer (c, location_completer);
8384 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8385 Set a hardware assisted breakpoint.\n\
8386 Like \"break\" except the breakpoint requires hardware support,\n\
8387 some target hardware may not have this support.\n\
8389 BREAK_ARGS_HELP ("hbreak")));
8390 set_cmd_completer (c, location_completer);
8392 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8393 Set a temporary hardware assisted breakpoint.\n\
8394 Like \"hbreak\" except the breakpoint is only temporary,\n\
8395 so it will be deleted when hit.\n\
8397 BREAK_ARGS_HELP ("thbreak")));
8398 set_cmd_completer (c, location_completer);
8400 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8401 Enable some breakpoints.\n\
8402 Give breakpoint numbers (separated by spaces) as arguments.\n\
8403 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8404 This is used to cancel the effect of the \"disable\" command.\n\
8405 With a subcommand you can enable temporarily."),
8406 &enablelist, "enable ", 1, &cmdlist);
8408 add_com ("ab", class_breakpoint, enable_command, _("\
8409 Enable some breakpoints.\n\
8410 Give breakpoint numbers (separated by spaces) as arguments.\n\
8411 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8412 This is used to cancel the effect of the \"disable\" command.\n\
8413 With a subcommand you can enable temporarily."));
8415 add_com_alias ("en", "enable", class_breakpoint, 1);
8417 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8418 Enable some breakpoints.\n\
8419 Give breakpoint numbers (separated by spaces) as arguments.\n\
8420 This is used to cancel the effect of the \"disable\" command.\n\
8421 May be abbreviated to simply \"enable\".\n"),
8422 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8424 add_cmd ("once", no_class, enable_once_command, _("\
8425 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8426 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8429 add_cmd ("delete", no_class, enable_delete_command, _("\
8430 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8431 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8434 add_cmd ("delete", no_class, enable_delete_command, _("\
8435 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8436 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8439 add_cmd ("once", no_class, enable_once_command, _("\
8440 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8441 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8444 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8445 Disable some breakpoints.\n\
8446 Arguments are breakpoint numbers with spaces in between.\n\
8447 To disable all breakpoints, give no argument.\n\
8448 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8449 &disablelist, "disable ", 1, &cmdlist);
8450 add_com_alias ("dis", "disable", class_breakpoint, 1);
8451 add_com_alias ("disa", "disable", class_breakpoint, 1);
8453 add_com ("sb", class_breakpoint, disable_command, _("\
8454 Disable some breakpoints.\n\
8455 Arguments are breakpoint numbers with spaces in between.\n\
8456 To disable all breakpoints, give no argument.\n\
8457 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8459 add_cmd ("breakpoints", class_alias, disable_command, _("\
8460 Disable some breakpoints.\n\
8461 Arguments are breakpoint numbers with spaces in between.\n\
8462 To disable all breakpoints, give no argument.\n\
8463 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8464 This command may be abbreviated \"disable\"."),
8467 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8468 Delete some breakpoints or auto-display expressions.\n\
8469 Arguments are breakpoint numbers with spaces in between.\n\
8470 To delete all breakpoints, give no argument.\n\
8472 Also a prefix command for deletion of other GDB objects.\n\
8473 The \"unset\" command is also an alias for \"delete\"."),
8474 &deletelist, "delete ", 1, &cmdlist);
8475 add_com_alias ("d", "delete", class_breakpoint, 1);
8476 add_com_alias ("del", "delete", class_breakpoint, 1);
8478 add_com ("db", class_breakpoint, delete_command, _("\
8479 Delete some breakpoints.\n\
8480 Arguments are breakpoint numbers with spaces in between.\n\
8481 To delete all breakpoints, give no argument.\n"));
8483 add_cmd ("breakpoints", class_alias, delete_command, _("\
8484 Delete some breakpoints or auto-display expressions.\n\
8485 Arguments are breakpoint numbers with spaces in between.\n\
8486 To delete all breakpoints, give no argument.\n\
8487 This command may be abbreviated \"delete\"."),
8490 add_com ("clear", class_breakpoint, clear_command, _("\
8491 Clear breakpoint at specified line or function.\n\
8492 Argument may be line number, function name, or \"*\" and an address.\n\
8493 If line number is specified, all breakpoints in that line are cleared.\n\
8494 If function is specified, breakpoints at beginning of function are cleared.\n\
8495 If an address is specified, breakpoints at that address are cleared.\n\
8497 With no argument, clears all breakpoints in the line that the selected frame\n\
8500 See also the \"delete\" command which clears breakpoints by number."));
8502 c = add_com ("break", class_breakpoint, break_command, _("\
8503 Set breakpoint at specified line or function.\n"
8504 BREAK_ARGS_HELP ("break")));
8505 set_cmd_completer (c, location_completer);
8507 add_com_alias ("b", "break", class_run, 1);
8508 add_com_alias ("br", "break", class_run, 1);
8509 add_com_alias ("bre", "break", class_run, 1);
8510 add_com_alias ("brea", "break", class_run, 1);
8514 add_com_alias ("ba", "break", class_breakpoint, 1);
8515 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8520 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8521 Break in function/address or break at a line in the current file."),
8522 &stoplist, "stop ", 1, &cmdlist);
8523 add_cmd ("in", class_breakpoint, stopin_command,
8524 _("Break in function or address."), &stoplist);
8525 add_cmd ("at", class_breakpoint, stopat_command,
8526 _("Break at a line in the current file."), &stoplist);
8527 add_com ("status", class_info, breakpoints_info, _("\
8528 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8529 The \"Type\" column indicates one of:\n\
8530 \tbreakpoint - normal breakpoint\n\
8531 \twatchpoint - watchpoint\n\
8532 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8533 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8534 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8535 address and file/line number respectively.\n\
8537 Convenience variable \"$_\" and default examine address for \"x\"\n\
8538 are set to the address of the last breakpoint listed unless the command\n\
8539 is prefixed with \"server \".\n\n\
8540 Convenience variable \"$bpnum\" contains the number of the last\n\
8544 add_info ("breakpoints", breakpoints_info, _("\
8545 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8546 The \"Type\" column indicates one of:\n\
8547 \tbreakpoint - normal breakpoint\n\
8548 \twatchpoint - watchpoint\n\
8549 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8550 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8551 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8552 address and file/line number respectively.\n\
8554 Convenience variable \"$_\" and default examine address for \"x\"\n\
8555 are set to the address of the last breakpoint listed unless the command\n\
8556 is prefixed with \"server \".\n\n\
8557 Convenience variable \"$bpnum\" contains the number of the last\n\
8561 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8562 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8563 The \"Type\" column indicates one of:\n\
8564 \tbreakpoint - normal breakpoint\n\
8565 \twatchpoint - watchpoint\n\
8566 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8567 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8568 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8569 address and file/line number respectively.\n\
8571 Convenience variable \"$_\" and default examine address for \"x\"\n\
8572 are set to the address of the last breakpoint listed unless the command\n\
8573 is prefixed with \"server \".\n\n\
8574 Convenience variable \"$bpnum\" contains the number of the last\n\
8577 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8578 Status of all breakpoints, or breakpoint number NUMBER.\n\
8579 The \"Type\" column indicates one of:\n\
8580 \tbreakpoint - normal breakpoint\n\
8581 \twatchpoint - watchpoint\n\
8582 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8583 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8584 \tuntil - internal breakpoint used by the \"until\" command\n\
8585 \tfinish - internal breakpoint used by the \"finish\" command\n\
8586 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8587 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8588 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8589 address and file/line number respectively.\n\
8591 Convenience variable \"$_\" and default examine address for \"x\"\n\
8592 are set to the address of the last breakpoint listed unless the command\n\
8593 is prefixed with \"server \".\n\n\
8594 Convenience variable \"$bpnum\" contains the number of the last\n\
8596 &maintenanceinfolist);
8598 add_com ("catch", class_breakpoint, catch_command, _("\
8599 Set catchpoints to catch events.\n\
8600 Raised signals may be caught:\n\
8601 \tcatch signal - all signals\n\
8602 \tcatch signal <signame> - a particular signal\n\
8603 Raised exceptions may be caught:\n\
8604 \tcatch throw - all exceptions, when thrown\n\
8605 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8606 \tcatch catch - all exceptions, when caught\n\
8607 \tcatch catch <exceptname> - a particular exception, when caught\n\
8608 Thread or process events may be caught:\n\
8609 \tcatch thread_start - any threads, just after creation\n\
8610 \tcatch thread_exit - any threads, just before expiration\n\
8611 \tcatch thread_join - any threads, just after joins\n\
8612 Process events may be caught:\n\
8613 \tcatch start - any processes, just after creation\n\
8614 \tcatch exit - any processes, just before expiration\n\
8615 \tcatch fork - calls to fork()\n\
8616 \tcatch vfork - calls to vfork()\n\
8617 \tcatch exec - calls to exec()\n\
8618 Dynamically-linked library events may be caught:\n\
8619 \tcatch load - loads of any library\n\
8620 \tcatch load <libname> - loads of a particular library\n\
8621 \tcatch unload - unloads of any library\n\
8622 \tcatch unload <libname> - unloads of a particular library\n\
8623 The act of your program's execution stopping may also be caught:\n\
8625 C++ exceptions may be caught:\n\
8626 \tcatch throw - all exceptions, when thrown\n\
8627 \tcatch catch - all exceptions, when caught\n\
8628 Ada exceptions may be caught:\n\
8629 \tcatch exception - all exceptions, when raised\n\
8630 \tcatch exception <name> - a particular exception, when raised\n\
8631 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8632 \tcatch assert - all failed assertions, when raised\n\
8634 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8635 after a fork or vfork is caught.\n\n\
8636 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8638 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8639 Set temporary catchpoints to catch events.\n\
8640 Args like \"catch\" command.\n\
8641 Like \"catch\" except the catchpoint is only temporary,\n\
8642 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8643 by using \"enable delete\" on the catchpoint number."));
8645 c = add_com ("watch", class_breakpoint, watch_command, _("\
8646 Set a watchpoint for an expression.\n\
8647 A watchpoint stops execution of your program whenever the value of\n\
8648 an expression changes."));
8649 set_cmd_completer (c, location_completer);
8651 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8652 Set a read watchpoint for an expression.\n\
8653 A watchpoint stops execution of your program whenever the value of\n\
8654 an expression is read."));
8655 set_cmd_completer (c, location_completer);
8657 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8658 Set a watchpoint for an expression.\n\
8659 A watchpoint stops execution of your program whenever the value of\n\
8660 an expression is either read or written."));
8661 set_cmd_completer (c, location_completer);
8663 add_info ("watchpoints", breakpoints_info,
8664 _("Synonym for ``info breakpoints''."));
8667 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8668 respond to changes - contrary to the description. */
8669 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8670 &can_use_hw_watchpoints, _("\
8671 Set debugger's willingness to use watchpoint hardware."), _("\
8672 Show debugger's willingness to use watchpoint hardware."), _("\
8673 If zero, gdb will not use hardware for new watchpoints, even if\n\
8674 such is available. (However, any hardware watchpoints that were\n\
8675 created before setting this to nonzero, will continue to use watchpoint\n\
8678 show_can_use_hw_watchpoints,
8679 &setlist, &showlist);
8681 can_use_hw_watchpoints = 1;
8683 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8684 Breakpoint specific settings\n\
8685 Configure various breakpoint-specific variables such as\n\
8686 pending breakpoint behavior"),
8687 &breakpoint_set_cmdlist, "set breakpoint ",
8688 0/*allow-unknown*/, &setlist);
8689 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8690 Breakpoint specific settings\n\
8691 Configure various breakpoint-specific variables such as\n\
8692 pending breakpoint behavior"),
8693 &breakpoint_show_cmdlist, "show breakpoint ",
8694 0/*allow-unknown*/, &showlist);
8696 add_setshow_auto_boolean_cmd ("pending", no_class,
8697 &pending_break_support, _("\
8698 Set debugger's behavior regarding pending breakpoints."), _("\
8699 Show debugger's behavior regarding pending breakpoints."), _("\
8700 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8701 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8702 an error. If auto, an unrecognized breakpoint location results in a\n\
8703 user-query to see if a pending breakpoint should be created."),
8705 show_pending_break_support,
8706 &breakpoint_set_cmdlist,
8707 &breakpoint_show_cmdlist);
8709 pending_break_support = AUTO_BOOLEAN_AUTO;
8711 add_setshow_boolean_cmd ("auto-hw", no_class,
8712 &automatic_hardware_breakpoints, _("\
8713 Set automatic usage of hardware breakpoints."), _("\
8714 Show automatic usage of hardware breakpoints."), _("\
8715 If set, the debugger will automatically use hardware breakpoints for\n\
8716 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8717 a warning will be emitted for such breakpoints."),
8719 show_automatic_hardware_breakpoints,
8720 &breakpoint_set_cmdlist,
8721 &breakpoint_show_cmdlist);
8723 automatic_hardware_breakpoints = 1;