1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 /* Prototypes for local functions. */
65 static void until_break_command_continuation (struct continuation_arg *arg);
67 static void catch_command_1 (char *, int, int);
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint *);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint *);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value *);
95 static int break_command_1 (char *, int, int, struct breakpoint *);
97 static void mention (struct breakpoint *);
99 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
101 static void check_duplicates (struct breakpoint *);
103 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
105 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
108 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location *, insertion_state_t);
137 static enum print_stop_action print_it_typical (bpstat);
139 static enum print_stop_action print_bp_stop_message (bpstat bs);
143 enum exception_event_kind kind;
146 args_for_catchpoint_enable;
148 static int watchpoint_check (void *);
150 static int cover_target_enable_exception_callback (void *);
152 static void maintenance_info_breakpoints (char *, int);
154 static void create_longjmp_breakpoint (char *);
156 static void create_overlay_event_breakpoint (char *);
158 static int hw_breakpoint_used_count (void);
160 static int hw_watchpoint_used_count (enum bptype, int *);
162 static void hbreak_command (char *, int);
164 static void thbreak_command (char *, int);
166 static void watch_command_1 (char *, int, int);
168 static void rwatch_command (char *, int);
170 static void awatch_command (char *, int);
172 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
174 static void solib_load_unload_1 (char *hookname,
177 char *cond_string, enum bptype bp_kind);
179 static void create_fork_vfork_event_catchpoint (int tempflag,
181 enum bptype bp_kind);
183 static void stop_command (char *arg, int from_tty);
185 static void stopin_command (char *arg, int from_tty);
187 static void stopat_command (char *arg, int from_tty);
189 static char *ep_find_event_name_end (char *arg);
191 static char *ep_parse_optional_if_clause (char **arg);
193 static char *ep_parse_optional_filename (char **arg);
195 static void create_exception_catchpoint (int tempflag, char *cond_string,
196 enum exception_event_kind ex_event,
197 struct symtab_and_line *sal);
199 static void catch_exception_command_1 (enum exception_event_kind ex_event,
200 char *arg, int tempflag, int from_tty);
202 static void tcatch_command (char *arg, int from_tty);
204 static void ep_skip_leading_whitespace (char **s);
206 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
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->next)
280 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
281 for (B = bp_location_chain; \
282 B ? (TMP=B->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 && !b->pending);
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)
579 if (b->cond_string != NULL)
580 xfree (b->cond_string);
585 b->cond_string = NULL;
587 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
592 /* I don't know if it matters whether this is the string the user
593 typed in or the decompiled expression. */
594 b->cond_string = savestring (arg, strlen (arg));
597 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
599 error (_("Junk at end of expression"));
602 breakpoints_changed ();
603 breakpoint_modify_event (b->number);
607 error (_("No breakpoint number %d."), bnum);
611 commands_command (char *arg, int from_tty)
613 struct breakpoint *b;
616 struct command_line *l;
618 /* If we allowed this, we would have problems with when to
619 free the storage, if we change the commands currently
622 if (executing_breakpoint_commands)
623 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
626 bnum = get_number (&p);
629 error (_("Unexpected extra arguments following breakpoint number."));
632 if (b->number == bnum)
634 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
636 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
637 l = read_command_lines (tmpbuf, from_tty);
638 do_cleanups (cleanups);
639 free_command_lines (&b->commands);
641 breakpoints_changed ();
642 breakpoint_modify_event (b->number);
645 error (_("No breakpoint number %d."), bnum);
648 /* Like commands_command, but instead of reading the commands from
649 input stream, takes them from an already parsed command structure.
651 This is used by cli-script.c to DTRT with breakpoint commands
652 that are part of if and while bodies. */
653 enum command_control_type
654 commands_from_control_command (char *arg, struct command_line *cmd)
656 struct breakpoint *b;
660 /* If we allowed this, we would have problems with when to
661 free the storage, if we change the commands currently
664 if (executing_breakpoint_commands)
665 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
667 /* An empty string for the breakpoint number means the last
668 breakpoint, but get_number expects a NULL pointer. */
673 bnum = get_number (&p);
676 error (_("Unexpected extra arguments following breakpoint number."));
679 if (b->number == bnum)
681 free_command_lines (&b->commands);
682 if (cmd->body_count != 1)
683 error (_("Invalid \"commands\" block structure."));
684 /* We need to copy the commands because if/while will free the
685 list after it finishes execution. */
686 b->commands = copy_command_lines (cmd->body_list[0]);
687 breakpoints_changed ();
688 breakpoint_modify_event (b->number);
689 return simple_control;
691 error (_("No breakpoint number %d."), bnum);
694 /* Like target_read_memory() but if breakpoints are inserted, return
695 the shadow contents instead of the breakpoints themselves.
697 Read "memory data" from whatever target or inferior we have.
698 Returns zero if successful, errno value if not. EIO is used
699 for address out of bounds. If breakpoints are inserted, returns
700 shadow contents, not the breakpoints themselves. From breakpoint.c. */
703 read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
706 struct bp_location *b;
707 CORE_ADDR bp_addr = 0;
710 if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
711 /* No breakpoints on this machine. */
712 return target_read_memory (memaddr, myaddr, len);
716 if (b->owner->type == bp_none)
717 warning (_("reading through apparently deleted breakpoint #%d?"),
720 if (b->loc_type != bp_loc_software_breakpoint)
724 /* Addresses and length of the part of the breakpoint that
726 bp_addr = b->target_info.placed_address;
727 bp_size = b->target_info.shadow_len;
729 /* bp isn't valid, or doesn't shadow memory. */
731 if (bp_addr + bp_size <= memaddr)
732 /* The breakpoint is entirely before the chunk of memory we
735 if (bp_addr >= memaddr + len)
736 /* The breakpoint is entirely after the chunk of memory we are
739 /* Copy the breakpoint from the shadow contents, and recurse for
740 the things before and after. */
742 /* Offset within shadow_contents. */
745 if (bp_addr < memaddr)
747 /* Only copy the second part of the breakpoint. */
748 bp_size -= memaddr - bp_addr;
749 bptoffset = memaddr - bp_addr;
753 if (bp_addr + bp_size > memaddr + len)
755 /* Only copy the first part of the breakpoint. */
756 bp_size -= (bp_addr + bp_size) - (memaddr + len);
759 memcpy (myaddr + bp_addr - memaddr,
760 b->target_info.shadow_contents + bptoffset, bp_size);
762 if (bp_addr > memaddr)
764 /* Copy the section of memory before the breakpoint. */
765 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
770 if (bp_addr + bp_size < memaddr + len)
772 /* Copy the section of memory after the breakpoint. */
773 status = read_memory_nobpt (bp_addr + bp_size,
774 myaddr + bp_addr + bp_size - memaddr,
775 memaddr + len - (bp_addr + bp_size));
782 /* Nothing overlaps. Just call read_memory_noerr. */
783 return target_read_memory (memaddr, myaddr, len);
787 /* A wrapper function for inserting catchpoints. */
789 insert_catchpoint (struct ui_out *uo, void *args)
791 struct breakpoint *b = (struct breakpoint *) args;
797 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
800 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
803 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
806 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
811 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
814 free_valchain (struct bp_location *b)
819 /* Free the saved value chain. We will construct a new one
820 the next time the watchpoint is inserted. */
821 for (v = b->owner->val_chain; v; v = n)
826 b->owner->val_chain = NULL;
829 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
830 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
831 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
833 NOTE drow/2003-09-09: This routine could be broken down to an object-style
834 method for each breakpoint or catchpoint type. */
836 insert_bp_location (struct bp_location *bpt,
837 struct ui_file *tmp_error_stream,
838 int *disabled_breaks, int *process_warning,
839 int *hw_breakpoint_error)
843 /* Permanent breakpoints cannot be inserted or removed. Disabled
844 breakpoints should not be inserted. */
845 if (!breakpoint_enabled (bpt->owner))
848 if (bpt->inserted || bpt->duplicate)
851 /* Initialize the target-specific information. */
852 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
853 bpt->target_info.placed_address = bpt->address;
855 if (bpt->loc_type == bp_loc_software_breakpoint
856 || bpt->loc_type == bp_loc_hardware_breakpoint)
858 if (bpt->owner->type != bp_hardware_breakpoint)
860 /* If the explicitly specified breakpoint type
861 is not hardware breakpoint, check the memory map to see
862 if the breakpoint address is in read only memory or not.
863 Two important cases are:
864 - location type is not hardware breakpoint, memory
865 is readonly. We change the type of the location to
867 - location type is hardware breakpoint, memory is read-write.
868 This means we've previously made the location hardware one, but
869 then the memory map changed, so we undo.
871 When breakpoints are removed, remove_breakpoints will
872 use location types we've just set here, the only possible
873 problem is that memory map has changed during running program,
874 but it's not going to work anyway with current gdb. */
875 struct mem_region *mr
876 = lookup_mem_region (bpt->target_info.placed_address);
880 if (automatic_hardware_breakpoints)
883 enum bp_loc_type new_type;
885 if (mr->attrib.mode != MEM_RW)
886 new_type = bp_loc_hardware_breakpoint;
888 new_type = bp_loc_software_breakpoint;
890 if (new_type != bpt->loc_type)
893 bpt->loc_type = new_type;
896 fprintf_filtered (gdb_stdout, _("\
897 Note: automatically using hardware breakpoints for read-only addresses.\n"));
902 else if (bpt->loc_type == bp_loc_software_breakpoint
903 && mr->attrib.mode != MEM_RW)
904 warning (_("cannot set software breakpoint at readonly address %s"),
905 paddr (bpt->address));
909 /* First check to see if we have to handle an overlay. */
910 if (overlay_debugging == ovly_off
911 || bpt->section == NULL
912 || !(section_is_overlay (bpt->section)))
914 /* No overlay handling: just set the breakpoint. */
916 if (bpt->loc_type == bp_loc_hardware_breakpoint)
917 val = target_insert_hw_breakpoint (&bpt->target_info);
919 val = target_insert_breakpoint (&bpt->target_info);
923 /* This breakpoint is in an overlay section.
924 Shall we set a breakpoint at the LMA? */
925 if (!overlay_events_enabled)
927 /* Yes -- overlay event support is not active,
928 so we must try to set a breakpoint at the LMA.
929 This will not work for a hardware breakpoint. */
930 if (bpt->loc_type == bp_loc_hardware_breakpoint)
931 warning (_("hardware breakpoint %d not supported in overlay!"),
935 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
937 /* Set a software (trap) breakpoint at the LMA. */
938 bpt->overlay_target_info = bpt->target_info;
939 bpt->overlay_target_info.placed_address = addr;
940 val = target_insert_breakpoint (&bpt->overlay_target_info);
942 fprintf_unfiltered (tmp_error_stream,
943 "Overlay breakpoint %d failed: in ROM?",
947 /* Shall we set a breakpoint at the VMA? */
948 if (section_is_mapped (bpt->section))
950 /* Yes. This overlay section is mapped into memory. */
951 if (bpt->loc_type == bp_loc_hardware_breakpoint)
952 val = target_insert_hw_breakpoint (&bpt->target_info);
954 val = target_insert_breakpoint (&bpt->target_info);
958 /* No. This breakpoint will not be inserted.
959 No error, but do not mark the bp as 'inserted'. */
966 /* Can't set the breakpoint. */
967 if (solib_address (bpt->address))
969 /* See also: disable_breakpoints_in_shlibs. */
971 bpt->owner->enable_state = bp_shlib_disabled;
972 if (!*disabled_breaks)
974 fprintf_unfiltered (tmp_error_stream,
975 "Cannot insert breakpoint %d.\n",
977 fprintf_unfiltered (tmp_error_stream,
978 "Temporarily disabling shared library breakpoints:\n");
980 *disabled_breaks = 1;
981 fprintf_unfiltered (tmp_error_stream,
982 "breakpoint #%d\n", bpt->owner->number);
986 #ifdef ONE_PROCESS_WRITETEXT
987 *process_warning = 1;
989 if (bpt->loc_type == bp_loc_hardware_breakpoint)
991 *hw_breakpoint_error = 1;
992 fprintf_unfiltered (tmp_error_stream,
993 "Cannot insert hardware breakpoint %d.\n",
998 fprintf_unfiltered (tmp_error_stream,
999 "Cannot insert breakpoint %d.\n",
1000 bpt->owner->number);
1001 fprintf_filtered (tmp_error_stream,
1002 "Error accessing memory address ");
1003 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1004 fprintf_filtered (tmp_error_stream, ": %s.\n",
1005 safe_strerror (val));
1016 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1017 /* NOTE drow/2003-09-08: This state only exists for removing
1018 watchpoints. It's not clear that it's necessary... */
1019 && bpt->owner->disposition != disp_del_at_next_stop)
1021 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1022 based on the expression. Ideally this should happen at a higher level,
1023 and there should be one bp_location for each computed address we
1024 must watch. As soon as a many-to-one mapping is available I'll
1027 int within_current_scope;
1028 struct value *mark = value_mark ();
1030 struct frame_id saved_frame_id;
1032 /* Save the current frame's ID so we can restore it after
1033 evaluating the watchpoint expression on its own frame. */
1034 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1035 took a frame parameter, so that we didn't have to change the
1037 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1039 /* Determine if the watchpoint is within scope. */
1040 if (bpt->owner->exp_valid_block == NULL)
1041 within_current_scope = 1;
1044 struct frame_info *fi;
1045 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
1046 within_current_scope = (fi != NULL);
1047 if (within_current_scope)
1051 if (within_current_scope)
1053 free_valchain (bpt);
1055 /* Evaluate the expression and cut the chain of values
1056 produced off from the value chain.
1058 Make sure the value returned isn't lazy; we use
1059 laziness to determine what memory GDB actually needed
1060 in order to compute the value of the expression. */
1061 v = evaluate_expression (bpt->owner->exp);
1063 value_release_to_mark (mark);
1065 bpt->owner->val_chain = v;
1068 /* Look at each value on the value chain. */
1069 for (; v; v = value_next (v))
1071 /* If it's a memory location, and GDB actually needed
1072 its contents to evaluate the expression, then we
1074 if (VALUE_LVAL (v) == lval_memory
1075 && ! value_lazy (v))
1077 struct type *vtype = check_typedef (value_type (v));
1079 /* We only watch structs and arrays if user asked
1080 for it explicitly, never if they just happen to
1081 appear in the middle of some value chain. */
1082 if (v == bpt->owner->val_chain
1083 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1084 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1089 addr = VALUE_ADDRESS (v) + value_offset (v);
1090 len = TYPE_LENGTH (value_type (v));
1092 if (bpt->owner->type == bp_read_watchpoint)
1094 else if (bpt->owner->type == bp_access_watchpoint)
1097 val = target_insert_watchpoint (addr, len, type);
1100 /* Don't exit the loop, try to insert
1101 every value on the value chain. That's
1102 because we will be removing all the
1103 watches below, and removing a
1104 watchpoint we didn't insert could have
1112 /* Failure to insert a watchpoint on any memory value in the
1113 value chain brings us here. */
1116 remove_breakpoint (bpt, mark_uninserted);
1117 *hw_breakpoint_error = 1;
1118 fprintf_unfiltered (tmp_error_stream,
1119 "Could not insert hardware watchpoint %d.\n",
1120 bpt->owner->number);
1126 printf_filtered (_("\
1127 Hardware watchpoint %d deleted because the program has left the block \n\
1128 in which its expression is valid.\n"),
1129 bpt->owner->number);
1130 if (bpt->owner->related_breakpoint)
1131 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1132 bpt->owner->disposition = disp_del_at_next_stop;
1135 /* Restore the selected frame. */
1136 select_frame (frame_find_by_id (saved_frame_id));
1141 else if (ep_is_exception_catchpoint (bpt->owner))
1143 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1144 breakpoint. Once again, it would be better if this was represented
1145 as two bp_locations. */
1147 /* If we get here, we must have a callback mechanism for exception
1148 events -- with g++ style embedded label support, we insert
1149 ordinary breakpoints and not catchpoints. */
1150 val = target_insert_breakpoint (&bpt->target_info);
1153 /* Couldn't set breakpoint for some reason */
1154 fprintf_unfiltered (tmp_error_stream,
1155 "Cannot insert catchpoint %d; disabling it.\n",
1156 bpt->owner->number);
1157 fprintf_filtered (tmp_error_stream,
1158 "Error accessing memory address ");
1159 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1160 fprintf_filtered (tmp_error_stream, ": %s.\n",
1161 safe_strerror (val));
1162 bpt->owner->enable_state = bp_disabled;
1166 /* Bp set, now make sure callbacks are enabled */
1167 /* Format possible error msg */
1168 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1169 bpt->owner->number);
1170 struct cleanup *cleanups = make_cleanup (xfree, message);
1172 args_for_catchpoint_enable args;
1173 args.kind = bpt->owner->type == bp_catch_catch ?
1174 EX_EVENT_CATCH : EX_EVENT_THROW;
1176 val = catch_errors (cover_target_enable_exception_callback,
1177 &args, message, RETURN_MASK_ALL);
1178 do_cleanups (cleanups);
1179 if (val != 0 && val != -1)
1182 /* Check if something went wrong; val == 0 can be ignored */
1185 /* something went wrong */
1186 fprintf_unfiltered (tmp_error_stream,
1187 "Cannot insert catchpoint %d; disabling it.\n",
1188 bpt->owner->number);
1189 bpt->owner->enable_state = bp_disabled;
1196 else if (bpt->owner->type == bp_catch_fork
1197 || bpt->owner->type == bp_catch_vfork
1198 || bpt->owner->type == bp_catch_exec)
1200 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1201 bpt->owner, RETURN_MASK_ERROR);
1202 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1203 bpt->owner->number);
1205 bpt->owner->enable_state = bp_disabled;
1209 /* We've already printed an error message if there was a problem
1210 inserting this catchpoint, and we've disabled the catchpoint,
1211 so just return success. */
1218 /* insert_breakpoints is used when starting or continuing the program.
1219 remove_breakpoints is used when the program stops.
1220 Both return zero if successful,
1221 or an `errno' value if could not write the inferior. */
1224 insert_breakpoints (void)
1226 struct bp_location *b, *temp;
1227 int return_val = 0; /* return success code. */
1229 int disabled_breaks = 0;
1230 int hw_breakpoint_error = 0;
1231 int process_warning = 0;
1233 struct ui_file *tmp_error_stream = mem_fileopen ();
1234 make_cleanup_ui_file_delete (tmp_error_stream);
1236 /* Explicitly mark the warning -- this will only be printed if
1237 there was an error. */
1238 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1240 ALL_BP_LOCATIONS_SAFE (b, temp)
1242 /* Permanent breakpoints cannot be inserted or removed. Disabled
1243 breakpoints should not be inserted. */
1244 if (!breakpoint_enabled (b->owner))
1247 /* There is no point inserting thread-specific breakpoints if the
1248 thread no longer exists. */
1249 if (b->owner->thread != -1
1250 && !valid_thread_id (b->owner->thread))
1253 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1254 hardware watchpoints are split into multiple loc breakpoints. */
1255 if ((b->loc_type == bp_loc_hardware_watchpoint
1256 || b->owner->type == bp_watchpoint) && !b->owner->val)
1259 val = evaluate_expression (b->owner->exp);
1260 release_value (val);
1261 if (value_lazy (val))
1262 value_fetch_lazy (val);
1263 b->owner->val = val;
1266 val = insert_bp_location (b, tmp_error_stream,
1267 &disabled_breaks, &process_warning,
1268 &hw_breakpoint_error);
1275 /* If a hardware breakpoint or watchpoint was inserted, add a
1276 message about possibly exhausted resources. */
1277 if (hw_breakpoint_error)
1279 fprintf_unfiltered (tmp_error_stream,
1280 "Could not insert hardware breakpoints:\n\
1281 You may have requested too many hardware breakpoints/watchpoints.\n");
1283 #ifdef ONE_PROCESS_WRITETEXT
1284 if (process_warning)
1285 fprintf_unfiltered (tmp_error_stream,
1286 "The same program may be running in another process.");
1288 target_terminal_ours_for_output ();
1289 error_stream (tmp_error_stream);
1295 remove_breakpoints (void)
1297 struct bp_location *b;
1300 ALL_BP_LOCATIONS (b)
1304 val = remove_breakpoint (b, mark_uninserted);
1313 remove_hw_watchpoints (void)
1315 struct bp_location *b;
1318 ALL_BP_LOCATIONS (b)
1320 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1322 val = remove_breakpoint (b, mark_uninserted);
1331 reattach_breakpoints (int pid)
1333 struct bp_location *b;
1335 struct cleanup *old_chain = save_inferior_ptid ();
1336 struct ui_file *tmp_error_stream = mem_fileopen ();
1337 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1339 make_cleanup_ui_file_delete (tmp_error_stream);
1341 inferior_ptid = pid_to_ptid (pid);
1342 ALL_BP_LOCATIONS (b)
1347 val = insert_bp_location (b, tmp_error_stream,
1348 &dummy1, &dummy2, &dummy3);
1351 do_cleanups (old_chain);
1356 do_cleanups (old_chain);
1361 update_breakpoints_after_exec (void)
1363 struct breakpoint *b;
1364 struct breakpoint *temp;
1366 /* Doing this first prevents the badness of having delete_breakpoint()
1367 write a breakpoint's current "shadow contents" to lift the bp. That
1368 shadow is NOT valid after an exec()! */
1369 mark_breakpoints_out ();
1371 ALL_BREAKPOINTS_SAFE (b, temp)
1373 /* Solib breakpoints must be explicitly reset after an exec(). */
1374 if (b->type == bp_shlib_event)
1376 delete_breakpoint (b);
1380 /* Thread event breakpoints must be set anew after an exec(),
1381 as must overlay event breakpoints. */
1382 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1384 delete_breakpoint (b);
1388 /* Step-resume breakpoints are meaningless after an exec(). */
1389 if (b->type == bp_step_resume)
1391 delete_breakpoint (b);
1395 /* Ditto the exception-handling catchpoints. */
1396 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1398 delete_breakpoint (b);
1402 /* Don't delete an exec catchpoint, because else the inferior
1403 won't stop when it ought!
1405 Similarly, we probably ought to keep vfork catchpoints, 'cause
1406 on this target, we may not be able to stop when the vfork is
1407 seen, but only when the subsequent exec is seen. (And because
1408 deleting fork catchpoints here but not vfork catchpoints will
1409 seem mysterious to users, keep those too.) */
1410 if ((b->type == bp_catch_exec) ||
1411 (b->type == bp_catch_vfork) ||
1412 (b->type == bp_catch_fork))
1417 /* bp_finish is a special case. The only way we ought to be able
1418 to see one of these when an exec() has happened, is if the user
1419 caught a vfork, and then said "finish". Ordinarily a finish just
1420 carries them to the call-site of the current callee, by setting
1421 a temporary bp there and resuming. But in this case, the finish
1422 will carry them entirely through the vfork & exec.
1424 We don't want to allow a bp_finish to remain inserted now. But
1425 we can't safely delete it, 'cause finish_command has a handle to
1426 the bp on a bpstat, and will later want to delete it. There's a
1427 chance (and I've seen it happen) that if we delete the bp_finish
1428 here, that its storage will get reused by the time finish_command
1429 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1430 We really must allow finish_command to delete a bp_finish.
1432 In the absense of a general solution for the "how do we know
1433 it's safe to delete something others may have handles to?"
1434 problem, what we'll do here is just uninsert the bp_finish, and
1435 let finish_command delete it.
1437 (We know the bp_finish is "doomed" in the sense that it's
1438 momentary, and will be deleted as soon as finish_command sees
1439 the inferior stopped. So it doesn't matter that the bp's
1440 address is probably bogus in the new a.out, unlike e.g., the
1441 solib breakpoints.) */
1443 if (b->type == bp_finish)
1448 /* Without a symbolic address, we have little hope of the
1449 pre-exec() address meaning the same thing in the post-exec()
1451 if (b->addr_string == NULL)
1453 delete_breakpoint (b);
1457 /* FIXME what about longjmp breakpoints? Re-create them here? */
1458 create_overlay_event_breakpoint ("_ovly_debug_event");
1462 detach_breakpoints (int pid)
1464 struct bp_location *b;
1466 struct cleanup *old_chain = save_inferior_ptid ();
1468 if (pid == PIDGET (inferior_ptid))
1469 error (_("Cannot detach breakpoints of inferior_ptid"));
1471 /* Set inferior_ptid; remove_breakpoint uses this global. */
1472 inferior_ptid = pid_to_ptid (pid);
1473 ALL_BP_LOCATIONS (b)
1477 val = remove_breakpoint (b, mark_inserted);
1480 do_cleanups (old_chain);
1485 do_cleanups (old_chain);
1490 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1494 if (b->owner->enable_state == bp_permanent)
1495 /* Permanent breakpoints cannot be inserted or removed. */
1498 if (b->owner->type == bp_none)
1499 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1502 if (b->loc_type == bp_loc_software_breakpoint
1503 || b->loc_type == bp_loc_hardware_breakpoint)
1505 /* "Normal" instruction breakpoint: either the standard
1506 trap-instruction bp (bp_breakpoint), or a
1507 bp_hardware_breakpoint. */
1509 /* First check to see if we have to handle an overlay. */
1510 if (overlay_debugging == ovly_off
1511 || b->section == NULL
1512 || !(section_is_overlay (b->section)))
1514 /* No overlay handling: just remove the breakpoint. */
1516 if (b->loc_type == bp_loc_hardware_breakpoint)
1517 val = target_remove_hw_breakpoint (&b->target_info);
1519 val = target_remove_breakpoint (&b->target_info);
1523 /* This breakpoint is in an overlay section.
1524 Did we set a breakpoint at the LMA? */
1525 if (!overlay_events_enabled)
1527 /* Yes -- overlay event support is not active, so we
1528 should have set a breakpoint at the LMA. Remove it.
1530 /* Ignore any failures: if the LMA is in ROM, we will
1531 have already warned when we failed to insert it. */
1532 if (b->loc_type == bp_loc_hardware_breakpoint)
1533 target_remove_hw_breakpoint (&b->overlay_target_info);
1535 target_remove_breakpoint (&b->overlay_target_info);
1537 /* Did we set a breakpoint at the VMA?
1538 If so, we will have marked the breakpoint 'inserted'. */
1541 /* Yes -- remove it. Previously we did not bother to
1542 remove the breakpoint if the section had been
1543 unmapped, but let's not rely on that being safe. We
1544 don't know what the overlay manager might do. */
1545 if (b->loc_type == bp_loc_hardware_breakpoint)
1546 val = target_remove_hw_breakpoint (&b->target_info);
1548 /* However, we should remove *software* breakpoints only
1549 if the section is still mapped, or else we overwrite
1550 wrong code with the saved shadow contents. */
1551 else if (section_is_mapped (b->section))
1552 val = target_remove_breakpoint (&b->target_info);
1558 /* No -- not inserted, so no need to remove. No error. */
1564 b->inserted = (is == mark_inserted);
1566 else if (b->loc_type == bp_loc_hardware_watchpoint
1567 && breakpoint_enabled (b->owner)
1573 b->inserted = (is == mark_inserted);
1574 /* Walk down the saved value chain. */
1575 for (v = b->owner->val_chain; v; v = value_next (v))
1577 /* For each memory reference remove the watchpoint
1579 if (VALUE_LVAL (v) == lval_memory
1580 && ! value_lazy (v))
1582 struct type *vtype = check_typedef (value_type (v));
1584 if (v == b->owner->val_chain
1585 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1586 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1591 addr = VALUE_ADDRESS (v) + value_offset (v);
1592 len = TYPE_LENGTH (value_type (v));
1594 if (b->owner->type == bp_read_watchpoint)
1596 else if (b->owner->type == bp_access_watchpoint)
1599 val = target_remove_watchpoint (addr, len, type);
1606 /* Failure to remove any of the hardware watchpoints comes here. */
1607 if ((is == mark_uninserted) && (b->inserted))
1608 warning (_("Could not remove hardware watchpoint %d."),
1611 else if ((b->owner->type == bp_catch_fork ||
1612 b->owner->type == bp_catch_vfork ||
1613 b->owner->type == bp_catch_exec)
1614 && breakpoint_enabled (b->owner)
1618 switch (b->owner->type)
1621 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1623 case bp_catch_vfork:
1624 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1627 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1630 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1635 b->inserted = (is == mark_inserted);
1637 else if ((b->owner->type == bp_catch_catch ||
1638 b->owner->type == bp_catch_throw)
1639 && breakpoint_enabled (b->owner)
1642 val = target_remove_breakpoint (&b->target_info);
1645 b->inserted = (is == mark_inserted);
1651 /* Clear the "inserted" flag in all breakpoints. */
1654 mark_breakpoints_out (void)
1656 struct bp_location *bpt;
1658 ALL_BP_LOCATIONS (bpt)
1662 /* Clear the "inserted" flag in all breakpoints and delete any
1663 breakpoints which should go away between runs of the program.
1665 Plus other such housekeeping that has to be done for breakpoints
1668 Note: this function gets called at the end of a run (by
1669 generic_mourn_inferior) and when a run begins (by
1670 init_wait_for_inferior). */
1675 breakpoint_init_inferior (enum inf_context context)
1677 struct breakpoint *b, *temp;
1678 struct bp_location *bpt;
1680 ALL_BP_LOCATIONS (bpt)
1683 ALL_BREAKPOINTS_SAFE (b, temp)
1688 case bp_watchpoint_scope:
1690 /* If the call dummy breakpoint is at the entry point it will
1691 cause problems when the inferior is rerun, so we better
1694 Also get rid of scope breakpoints. */
1695 delete_breakpoint (b);
1699 case bp_hardware_watchpoint:
1700 case bp_read_watchpoint:
1701 case bp_access_watchpoint:
1703 /* Likewise for watchpoints on local expressions. */
1704 if (b->exp_valid_block != NULL)
1705 delete_breakpoint (b);
1706 else if (context == inf_starting)
1708 /* Reset val field to force reread of starting value
1709 in insert_breakpoints. */
1711 value_free (b->val);
1721 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1722 exists at PC. It returns ordinary_breakpoint_here if it's an
1723 ordinary breakpoint, or permanent_breakpoint_here if it's a
1724 permanent breakpoint.
1725 - When continuing from a location with an ordinary breakpoint, we
1726 actually single step once before calling insert_breakpoints.
1727 - When continuing from a localion with a permanent breakpoint, we
1728 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1729 the target, to advance the PC past the breakpoint. */
1731 enum breakpoint_here
1732 breakpoint_here_p (CORE_ADDR pc)
1734 struct bp_location *bpt;
1735 int any_breakpoint_here = 0;
1737 ALL_BP_LOCATIONS (bpt)
1739 if (bpt->loc_type != bp_loc_software_breakpoint
1740 && bpt->loc_type != bp_loc_hardware_breakpoint)
1743 if ((breakpoint_enabled (bpt->owner)
1744 || bpt->owner->enable_state == bp_permanent)
1745 && bpt->address == pc) /* bp is enabled and matches pc */
1747 if (overlay_debugging
1748 && section_is_overlay (bpt->section)
1749 && !section_is_mapped (bpt->section))
1750 continue; /* unmapped overlay -- can't be a match */
1751 else if (bpt->owner->enable_state == bp_permanent)
1752 return permanent_breakpoint_here;
1754 any_breakpoint_here = 1;
1758 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1762 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1763 but it only returns true if there is actually a breakpoint inserted
1767 breakpoint_inserted_here_p (CORE_ADDR pc)
1769 struct bp_location *bpt;
1771 ALL_BP_LOCATIONS (bpt)
1773 if (bpt->loc_type != bp_loc_software_breakpoint
1774 && bpt->loc_type != bp_loc_hardware_breakpoint)
1778 && bpt->address == pc) /* bp is inserted and matches pc */
1780 if (overlay_debugging
1781 && section_is_overlay (bpt->section)
1782 && !section_is_mapped (bpt->section))
1783 continue; /* unmapped overlay -- can't be a match */
1789 /* Also check for software single-step breakpoints. */
1790 if (single_step_breakpoint_inserted_here_p (pc))
1796 /* This function returns non-zero iff there is a software breakpoint
1800 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1802 struct bp_location *bpt;
1803 int any_breakpoint_here = 0;
1805 ALL_BP_LOCATIONS (bpt)
1807 if (bpt->loc_type != bp_loc_software_breakpoint)
1810 if ((breakpoint_enabled (bpt->owner)
1811 || bpt->owner->enable_state == bp_permanent)
1813 && bpt->address == pc) /* bp is enabled and matches pc */
1815 if (overlay_debugging
1816 && section_is_overlay (bpt->section)
1817 && !section_is_mapped (bpt->section))
1818 continue; /* unmapped overlay -- can't be a match */
1824 /* Also check for software single-step breakpoints. */
1825 if (single_step_breakpoint_inserted_here_p (pc))
1831 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1832 PC is valid for process/thread PTID. */
1835 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1837 struct bp_location *bpt;
1840 thread = pid_to_thread_id (ptid);
1842 ALL_BP_LOCATIONS (bpt)
1844 if (bpt->loc_type != bp_loc_software_breakpoint
1845 && bpt->loc_type != bp_loc_hardware_breakpoint)
1848 if ((breakpoint_enabled (bpt->owner)
1849 || bpt->owner->enable_state == bp_permanent)
1850 && bpt->address == pc
1851 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1853 if (overlay_debugging
1854 && section_is_overlay (bpt->section)
1855 && !section_is_mapped (bpt->section))
1856 continue; /* unmapped overlay -- can't be a match */
1866 /* bpstat stuff. External routines' interfaces are documented
1870 ep_is_catchpoint (struct breakpoint *ep)
1873 (ep->type == bp_catch_load)
1874 || (ep->type == bp_catch_unload)
1875 || (ep->type == bp_catch_fork)
1876 || (ep->type == bp_catch_vfork)
1877 || (ep->type == bp_catch_exec)
1878 || (ep->type == bp_catch_catch)
1879 || (ep->type == bp_catch_throw);
1881 /* ??rehrauer: Add more kinds here, as are implemented... */
1885 ep_is_shlib_catchpoint (struct breakpoint *ep)
1888 (ep->type == bp_catch_load)
1889 || (ep->type == bp_catch_unload);
1893 ep_is_exception_catchpoint (struct breakpoint *ep)
1896 (ep->type == bp_catch_catch)
1897 || (ep->type == bp_catch_throw);
1900 /* Clear a bpstat so that it says we are not at any breakpoint.
1901 Also free any storage that is part of a bpstat. */
1904 bpstat_clear (bpstat *bsp)
1915 if (p->old_val != NULL)
1916 value_free (p->old_val);
1917 free_command_lines (&p->commands);
1924 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1925 is part of the bpstat is copied as well. */
1928 bpstat_copy (bpstat bs)
1932 bpstat retval = NULL;
1937 for (; bs != NULL; bs = bs->next)
1939 tmp = (bpstat) xmalloc (sizeof (*tmp));
1940 memcpy (tmp, bs, sizeof (*tmp));
1941 if (bs->commands != NULL)
1942 tmp->commands = copy_command_lines (bs->commands);
1943 if (bs->old_val != NULL)
1944 tmp->old_val = value_copy (bs->old_val);
1947 /* This is the first thing in the chain. */
1957 /* Find the bpstat associated with this breakpoint */
1960 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1965 for (; bsp != NULL; bsp = bsp->next)
1967 if (bsp->breakpoint_at == breakpoint)
1973 /* Find a step_resume breakpoint associated with this bpstat.
1974 (If there are multiple step_resume bp's on the list, this function
1975 will arbitrarily pick one.)
1977 It is an error to use this function if BPSTAT doesn't contain a
1978 step_resume breakpoint.
1980 See wait_for_inferior's use of this function. */
1982 bpstat_find_step_resume_breakpoint (bpstat bsp)
1986 gdb_assert (bsp != NULL);
1988 current_thread = pid_to_thread_id (inferior_ptid);
1990 for (; bsp != NULL; bsp = bsp->next)
1992 if ((bsp->breakpoint_at != NULL) &&
1993 (bsp->breakpoint_at->type == bp_step_resume) &&
1994 (bsp->breakpoint_at->thread == current_thread ||
1995 bsp->breakpoint_at->thread == -1))
1996 return bsp->breakpoint_at;
1999 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2003 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2004 at. *BSP upon return is a bpstat which points to the remaining
2005 breakpoints stopped at (but which is not guaranteed to be good for
2006 anything but further calls to bpstat_num).
2007 Return 0 if passed a bpstat which does not indicate any breakpoints.
2008 Return -1 if stopped at a breakpoint that has been deleted since
2010 Return 1 otherwise. */
2013 bpstat_num (bpstat *bsp, int *num)
2015 struct breakpoint *b;
2018 return 0; /* No more breakpoint values */
2020 b = (*bsp)->breakpoint_at;
2021 *bsp = (*bsp)->next;
2023 return -1; /* breakpoint that's been deleted since */
2025 *num = b->number; /* We have its number */
2029 /* Modify BS so that the actions will not be performed. */
2032 bpstat_clear_actions (bpstat bs)
2034 for (; bs != NULL; bs = bs->next)
2036 free_command_lines (&bs->commands);
2037 if (bs->old_val != NULL)
2039 value_free (bs->old_val);
2045 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2047 cleanup_executing_breakpoints (void *ignore)
2049 executing_breakpoint_commands = 0;
2052 /* Execute all the commands associated with all the breakpoints at this
2053 location. Any of these commands could cause the process to proceed
2054 beyond this point, etc. We look out for such changes by checking
2055 the global "breakpoint_proceeded" after each command. */
2058 bpstat_do_actions (bpstat *bsp)
2061 struct cleanup *old_chain;
2063 /* Avoid endless recursion if a `source' command is contained
2065 if (executing_breakpoint_commands)
2068 executing_breakpoint_commands = 1;
2069 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2072 /* Note that (as of this writing), our callers all appear to
2073 be passing us the address of global stop_bpstat. And, if
2074 our calls to execute_control_command cause the inferior to
2075 proceed, that global (and hence, *bsp) will change.
2077 We must be careful to not touch *bsp unless the inferior
2078 has not proceeded. */
2080 /* This pointer will iterate over the list of bpstat's. */
2083 breakpoint_proceeded = 0;
2084 for (; bs != NULL; bs = bs->next)
2086 struct command_line *cmd;
2087 struct cleanup *this_cmd_tree_chain;
2089 /* Take ownership of the BSP's command tree, if it has one.
2091 The command tree could legitimately contain commands like
2092 'step' and 'next', which call clear_proceed_status, which
2093 frees stop_bpstat's command tree. To make sure this doesn't
2094 free the tree we're executing out from under us, we need to
2095 take ownership of the tree ourselves. Since a given bpstat's
2096 commands are only executed once, we don't need to copy it; we
2097 can clear the pointer in the bpstat, and make sure we free
2098 the tree when we're done. */
2101 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2105 execute_control_command (cmd);
2107 if (breakpoint_proceeded)
2113 /* We can free this command tree now. */
2114 do_cleanups (this_cmd_tree_chain);
2116 if (breakpoint_proceeded)
2117 /* The inferior is proceeded by the command; bomb out now.
2118 The bpstat chain has been blown away by wait_for_inferior.
2119 But since execution has stopped again, there is a new bpstat
2120 to look at, so start over. */
2123 do_cleanups (old_chain);
2126 /* This is the normal print function for a bpstat. In the future,
2127 much of this logic could (should?) be moved to bpstat_stop_status,
2128 by having it set different print_it values.
2130 Current scheme: When we stop, bpstat_print() is called. It loops
2131 through the bpstat list of things causing this stop, calling the
2132 print_bp_stop_message function on each one. The behavior of the
2133 print_bp_stop_message function depends on the print_it field of
2134 bpstat. If such field so indicates, call this function here.
2136 Return values from this routine (ultimately used by bpstat_print()
2137 and normal_stop() to decide what to do):
2138 PRINT_NOTHING: Means we already printed all we needed to print,
2139 don't print anything else.
2140 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2141 that something to be followed by a location.
2142 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2143 that something to be followed by a location.
2144 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2147 static enum print_stop_action
2148 print_it_typical (bpstat bs)
2150 struct cleanup *old_chain, *ui_out_chain;
2151 struct ui_stream *stb;
2152 stb = ui_out_stream_new (uiout);
2153 old_chain = make_cleanup_ui_out_stream_delete (stb);
2154 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2155 which has since been deleted. */
2156 if (bs->breakpoint_at == NULL)
2157 return PRINT_UNKNOWN;
2159 switch (bs->breakpoint_at->type)
2162 case bp_hardware_breakpoint:
2163 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2164 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2165 bs->breakpoint_at->loc->address,
2166 bs->breakpoint_at->number, 1);
2167 annotate_breakpoint (bs->breakpoint_at->number);
2168 ui_out_text (uiout, "\nBreakpoint ");
2169 if (ui_out_is_mi_like_p (uiout))
2170 ui_out_field_string (uiout, "reason",
2171 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2172 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2173 ui_out_text (uiout, ", ");
2174 return PRINT_SRC_AND_LOC;
2177 case bp_shlib_event:
2178 /* Did we stop because the user set the stop_on_solib_events
2179 variable? (If so, we report this as a generic, "Stopped due
2180 to shlib event" message.) */
2181 printf_filtered (_("Stopped due to shared library event\n"));
2182 return PRINT_NOTHING;
2185 case bp_thread_event:
2186 /* Not sure how we will get here.
2187 GDB should not stop for these breakpoints. */
2188 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2189 return PRINT_NOTHING;
2192 case bp_overlay_event:
2193 /* By analogy with the thread event, GDB should not stop for these. */
2194 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2195 return PRINT_NOTHING;
2199 annotate_catchpoint (bs->breakpoint_at->number);
2200 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2201 bs->breakpoint_at->number,
2202 bs->breakpoint_at->triggered_dll_pathname);
2203 return PRINT_SRC_AND_LOC;
2206 case bp_catch_unload:
2207 annotate_catchpoint (bs->breakpoint_at->number);
2208 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2209 bs->breakpoint_at->number,
2210 bs->breakpoint_at->triggered_dll_pathname);
2211 return PRINT_SRC_AND_LOC;
2215 annotate_catchpoint (bs->breakpoint_at->number);
2216 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2217 bs->breakpoint_at->number,
2218 bs->breakpoint_at->forked_inferior_pid);
2219 return PRINT_SRC_AND_LOC;
2222 case bp_catch_vfork:
2223 annotate_catchpoint (bs->breakpoint_at->number);
2224 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2225 bs->breakpoint_at->number,
2226 bs->breakpoint_at->forked_inferior_pid);
2227 return PRINT_SRC_AND_LOC;
2231 annotate_catchpoint (bs->breakpoint_at->number);
2232 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2233 bs->breakpoint_at->number,
2234 bs->breakpoint_at->exec_pathname);
2235 return PRINT_SRC_AND_LOC;
2238 case bp_catch_catch:
2239 if (current_exception_event &&
2240 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2242 annotate_catchpoint (bs->breakpoint_at->number);
2243 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2244 bs->breakpoint_at->number);
2245 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2246 printf_filtered (_("throw location %s:%d, "),
2247 CURRENT_EXCEPTION_THROW_FILE,
2248 CURRENT_EXCEPTION_THROW_LINE);
2250 printf_filtered (_("throw location unknown, "));
2252 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2253 printf_filtered (_("catch location %s:%d\n"),
2254 CURRENT_EXCEPTION_CATCH_FILE,
2255 CURRENT_EXCEPTION_CATCH_LINE);
2257 printf_filtered (_("catch location unknown\n"));
2259 /* don't bother to print location frame info */
2260 return PRINT_SRC_ONLY;
2264 /* really throw, some other bpstat will handle it */
2265 return PRINT_UNKNOWN;
2269 case bp_catch_throw:
2270 if (current_exception_event &&
2271 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2273 annotate_catchpoint (bs->breakpoint_at->number);
2274 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2275 bs->breakpoint_at->number);
2276 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2277 printf_filtered (_("throw location %s:%d, "),
2278 CURRENT_EXCEPTION_THROW_FILE,
2279 CURRENT_EXCEPTION_THROW_LINE);
2281 printf_filtered (_("throw location unknown, "));
2283 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2284 printf_filtered (_("catch location %s:%d\n"),
2285 CURRENT_EXCEPTION_CATCH_FILE,
2286 CURRENT_EXCEPTION_CATCH_LINE);
2288 printf_filtered (_("catch location unknown\n"));
2290 /* don't bother to print location frame info */
2291 return PRINT_SRC_ONLY;
2295 /* really catch, some other bpstat will handle it */
2296 return PRINT_UNKNOWN;
2301 case bp_hardware_watchpoint:
2302 if (bs->old_val != NULL)
2304 annotate_watchpoint (bs->breakpoint_at->number);
2305 if (ui_out_is_mi_like_p (uiout))
2308 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2309 mention (bs->breakpoint_at);
2310 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2311 ui_out_text (uiout, "\nOld value = ");
2312 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2313 ui_out_field_stream (uiout, "old", stb);
2314 ui_out_text (uiout, "\nNew value = ");
2315 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2316 ui_out_field_stream (uiout, "new", stb);
2317 do_cleanups (ui_out_chain);
2318 ui_out_text (uiout, "\n");
2319 value_free (bs->old_val);
2322 /* More than one watchpoint may have been triggered. */
2323 return PRINT_UNKNOWN;
2326 case bp_read_watchpoint:
2327 if (ui_out_is_mi_like_p (uiout))
2330 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2331 mention (bs->breakpoint_at);
2332 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2333 ui_out_text (uiout, "\nValue = ");
2334 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2335 ui_out_field_stream (uiout, "value", stb);
2336 do_cleanups (ui_out_chain);
2337 ui_out_text (uiout, "\n");
2338 return PRINT_UNKNOWN;
2341 case bp_access_watchpoint:
2342 if (bs->old_val != NULL)
2344 annotate_watchpoint (bs->breakpoint_at->number);
2345 if (ui_out_is_mi_like_p (uiout))
2348 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2349 mention (bs->breakpoint_at);
2350 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2351 ui_out_text (uiout, "\nOld value = ");
2352 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2353 ui_out_field_stream (uiout, "old", stb);
2354 value_free (bs->old_val);
2356 ui_out_text (uiout, "\nNew value = ");
2360 mention (bs->breakpoint_at);
2361 if (ui_out_is_mi_like_p (uiout))
2364 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2365 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2366 ui_out_text (uiout, "\nValue = ");
2368 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2369 ui_out_field_stream (uiout, "new", stb);
2370 do_cleanups (ui_out_chain);
2371 ui_out_text (uiout, "\n");
2372 return PRINT_UNKNOWN;
2375 /* Fall through, we don't deal with these types of breakpoints
2379 if (ui_out_is_mi_like_p (uiout))
2382 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2383 return PRINT_UNKNOWN;
2387 if (ui_out_is_mi_like_p (uiout))
2390 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2391 return PRINT_UNKNOWN;
2396 case bp_longjmp_resume:
2397 case bp_step_resume:
2398 case bp_watchpoint_scope:
2401 return PRINT_UNKNOWN;
2405 /* Generic routine for printing messages indicating why we
2406 stopped. The behavior of this function depends on the value
2407 'print_it' in the bpstat structure. Under some circumstances we
2408 may decide not to print anything here and delegate the task to
2411 static enum print_stop_action
2412 print_bp_stop_message (bpstat bs)
2414 switch (bs->print_it)
2417 /* Nothing should be printed for this bpstat entry. */
2418 return PRINT_UNKNOWN;
2422 /* We still want to print the frame, but we already printed the
2423 relevant messages. */
2424 return PRINT_SRC_AND_LOC;
2427 case print_it_normal:
2428 /* Normal case. Call the breakpoint's print_it method, or
2429 print_it_typical. */
2430 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2431 && bs->breakpoint_at->ops->print_it != NULL)
2432 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2434 return print_it_typical (bs);
2438 internal_error (__FILE__, __LINE__,
2439 _("print_bp_stop_message: unrecognized enum value"));
2444 /* Print a message indicating what happened. This is called from
2445 normal_stop(). The input to this routine is the head of the bpstat
2446 list - a list of the eventpoints that caused this stop. This
2447 routine calls the generic print routine for printing a message
2448 about reasons for stopping. This will print (for example) the
2449 "Breakpoint n," part of the output. The return value of this
2452 PRINT_UNKNOWN: Means we printed nothing
2453 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2454 code to print the location. An example is
2455 "Breakpoint 1, " which should be followed by
2457 PRINT_SRC_ONLY: Means we printed something, but there is no need
2458 to also print the location part of the message.
2459 An example is the catch/throw messages, which
2460 don't require a location appended to the end.
2461 PRINT_NOTHING: We have done some printing and we don't need any
2462 further info to be printed.*/
2464 enum print_stop_action
2465 bpstat_print (bpstat bs)
2469 /* Maybe another breakpoint in the chain caused us to stop.
2470 (Currently all watchpoints go on the bpstat whether hit or not.
2471 That probably could (should) be changed, provided care is taken
2472 with respect to bpstat_explains_signal). */
2473 for (; bs; bs = bs->next)
2475 val = print_bp_stop_message (bs);
2476 if (val == PRINT_SRC_ONLY
2477 || val == PRINT_SRC_AND_LOC
2478 || val == PRINT_NOTHING)
2482 /* We reached the end of the chain, or we got a null BS to start
2483 with and nothing was printed. */
2484 return PRINT_UNKNOWN;
2487 /* Evaluate the expression EXP and return 1 if value is zero.
2488 This is used inside a catch_errors to evaluate the breakpoint condition.
2489 The argument is a "struct expression *" that has been cast to char * to
2490 make it pass through catch_errors. */
2493 breakpoint_cond_eval (void *exp)
2495 struct value *mark = value_mark ();
2496 int i = !value_true (evaluate_expression ((struct expression *) exp));
2497 value_free_to_mark (mark);
2501 /* Allocate a new bpstat and chain it to the current one. */
2504 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2508 bs = (bpstat) xmalloc (sizeof (*bs));
2510 bs->breakpoint_at = b;
2511 /* If the condition is false, etc., don't do the commands. */
2512 bs->commands = NULL;
2514 bs->print_it = print_it_normal;
2518 /* Possible return values for watchpoint_check (this can't be an enum
2519 because of check_errors). */
2520 /* The watchpoint has been deleted. */
2521 #define WP_DELETED 1
2522 /* The value has changed. */
2523 #define WP_VALUE_CHANGED 2
2524 /* The value has not changed. */
2525 #define WP_VALUE_NOT_CHANGED 3
2527 #define BP_TEMPFLAG 1
2528 #define BP_HARDWAREFLAG 2
2530 /* Check watchpoint condition. */
2533 watchpoint_check (void *p)
2535 bpstat bs = (bpstat) p;
2536 struct breakpoint *b;
2537 struct frame_info *fr;
2538 int within_current_scope;
2540 b = bs->breakpoint_at;
2542 if (b->exp_valid_block == NULL)
2543 within_current_scope = 1;
2546 /* There is no current frame at this moment. If we're going to have
2547 any chance of handling watchpoints on local variables, we'll need
2548 the frame chain (so we can determine if we're in scope). */
2549 reinit_frame_cache ();
2550 fr = frame_find_by_id (b->watchpoint_frame);
2551 within_current_scope = (fr != NULL);
2553 /* If we've gotten confused in the unwinder, we might have
2554 returned a frame that can't describe this variable. */
2555 if (within_current_scope
2556 && block_function (b->exp_valid_block) != get_frame_function (fr))
2557 within_current_scope = 0;
2559 /* in_function_epilogue_p() returns a non-zero value if we're still
2560 in the function but the stack frame has already been invalidated.
2561 Since we can't rely on the values of local variables after the
2562 stack has been destroyed, we are treating the watchpoint in that
2563 state as `not changed' without further checking.
2565 vinschen/2003-09-04: The former implementation left out the case
2566 that the watchpoint frame couldn't be found by frame_find_by_id()
2567 because the current PC is currently in an epilogue. Calling
2568 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2569 if ((!within_current_scope || fr == get_current_frame ())
2570 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2571 return WP_VALUE_NOT_CHANGED;
2572 if (fr && within_current_scope)
2573 /* If we end up stopping, the current frame will get selected
2574 in normal_stop. So this call to select_frame won't affect
2579 if (within_current_scope)
2581 /* We use value_{,free_to_}mark because it could be a
2582 *long* time before we return to the command level and
2583 call free_all_values. We can't call free_all_values because
2584 we might be in the middle of evaluating a function call. */
2586 struct value *mark = value_mark ();
2587 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2588 if (!value_equal (b->val, new_val))
2590 release_value (new_val);
2591 value_free_to_mark (mark);
2592 bs->old_val = b->val;
2594 /* We will stop here */
2595 return WP_VALUE_CHANGED;
2599 /* Nothing changed, don't do anything. */
2600 value_free_to_mark (mark);
2601 /* We won't stop here */
2602 return WP_VALUE_NOT_CHANGED;
2607 /* This seems like the only logical thing to do because
2608 if we temporarily ignored the watchpoint, then when
2609 we reenter the block in which it is valid it contains
2610 garbage (in the case of a function, it may have two
2611 garbage values, one before and one after the prologue).
2612 So we can't even detect the first assignment to it and
2613 watch after that (since the garbage may or may not equal
2614 the first value assigned). */
2615 /* We print all the stop information in print_it_typical(), but
2616 in this case, by the time we call print_it_typical() this bp
2617 will be deleted already. So we have no choice but print the
2618 information here. */
2619 if (ui_out_is_mi_like_p (uiout))
2621 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2622 ui_out_text (uiout, "\nWatchpoint ");
2623 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2624 ui_out_text (uiout, " deleted because the program has left the block in\n\
2625 which its expression is valid.\n");
2627 if (b->related_breakpoint)
2628 b->related_breakpoint->disposition = disp_del_at_next_stop;
2629 b->disposition = disp_del_at_next_stop;
2635 /* Get a bpstat associated with having just stopped at address
2636 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2637 target thinks we stopped due to a hardware watchpoint, 0 if we
2638 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2640 /* Determine whether we stopped at a breakpoint, etc, or whether we
2641 don't understand this stop. Result is a chain of bpstat's such that:
2643 if we don't understand the stop, the result is a null pointer.
2645 if we understand why we stopped, the result is not null.
2647 Each element of the chain refers to a particular breakpoint or
2648 watchpoint at which we have stopped. (We may have stopped for
2649 several reasons concurrently.)
2651 Each element of the chain has valid next, breakpoint_at,
2652 commands, FIXME??? fields. */
2655 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
2657 struct breakpoint *b, *temp;
2658 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2659 int real_breakpoint = 0;
2660 /* Root of the chain of bpstat's */
2661 struct bpstats root_bs[1];
2662 /* Pointer to the last thing in the chain currently. */
2663 bpstat bs = root_bs;
2664 int thread_id = pid_to_thread_id (ptid);
2666 ALL_BREAKPOINTS_SAFE (b, temp)
2668 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2671 if (b->type != bp_watchpoint
2672 && b->type != bp_hardware_watchpoint
2673 && b->type != bp_read_watchpoint
2674 && b->type != bp_access_watchpoint
2675 && b->type != bp_hardware_breakpoint
2676 && b->type != bp_catch_fork
2677 && b->type != bp_catch_vfork
2678 && b->type != bp_catch_exec
2679 && b->type != bp_catch_catch
2680 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2682 if (b->loc->address != bp_addr) /* address doesn't match */
2684 if (overlay_debugging /* unmapped overlay section */
2685 && section_is_overlay (b->loc->section)
2686 && !section_is_mapped (b->loc->section))
2690 /* Continuable hardware watchpoints are treated as non-existent if the
2691 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2692 some data address). Otherwise gdb won't stop on a break instruction
2693 in the code (not from a breakpoint) when a hardware watchpoint has
2696 if ((b->type == bp_hardware_watchpoint
2697 || b->type == bp_read_watchpoint
2698 || b->type == bp_access_watchpoint)
2699 && !stopped_by_watchpoint)
2702 if (b->type == bp_hardware_breakpoint)
2704 if (b->loc->address != bp_addr)
2706 if (overlay_debugging /* unmapped overlay section */
2707 && section_is_overlay (b->loc->section)
2708 && !section_is_mapped (b->loc->section))
2712 /* Is this a catchpoint of a load or unload? If so, did we
2713 get a load or unload of the specified library? If not,
2715 if ((b->type == bp_catch_load)
2716 #if defined(SOLIB_HAVE_LOAD_EVENT)
2717 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2718 || ((b->dll_pathname != NULL)
2719 && (strcmp (b->dll_pathname,
2720 SOLIB_LOADED_LIBRARY_PATHNAME (
2721 PIDGET (inferior_ptid)))
2727 if ((b->type == bp_catch_unload)
2728 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2729 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2730 || ((b->dll_pathname != NULL)
2731 && (strcmp (b->dll_pathname,
2732 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2733 PIDGET (inferior_ptid)))
2739 if ((b->type == bp_catch_fork)
2740 && !inferior_has_forked (PIDGET (inferior_ptid),
2741 &b->forked_inferior_pid))
2744 if ((b->type == bp_catch_vfork)
2745 && !inferior_has_vforked (PIDGET (inferior_ptid),
2746 &b->forked_inferior_pid))
2749 if ((b->type == bp_catch_exec)
2750 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2753 if (ep_is_exception_catchpoint (b) &&
2754 !(current_exception_event = target_get_current_exception_event ()))
2757 /* Come here if it's a watchpoint, or if the break address matches */
2759 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2761 /* Watchpoints may change this, if not found to have triggered. */
2765 if (b->type == bp_watchpoint ||
2766 b->type == bp_hardware_watchpoint)
2768 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2770 struct cleanup *cleanups = make_cleanup (xfree, message);
2771 int e = catch_errors (watchpoint_check, bs, message,
2773 do_cleanups (cleanups);
2777 /* We've already printed what needs to be printed. */
2778 /* Actually this is superfluous, because by the time we
2779 call print_it_typical() the wp will be already deleted,
2780 and the function will return immediately. */
2781 bs->print_it = print_it_done;
2784 case WP_VALUE_CHANGED:
2788 case WP_VALUE_NOT_CHANGED:
2790 bs->print_it = print_it_noop;
2797 /* Error from catch_errors. */
2798 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2799 if (b->related_breakpoint)
2800 b->related_breakpoint->disposition = disp_del_at_next_stop;
2801 b->disposition = disp_del_at_next_stop;
2802 /* We've already printed what needs to be printed. */
2803 bs->print_it = print_it_done;
2809 else if (b->type == bp_read_watchpoint ||
2810 b->type == bp_access_watchpoint)
2816 if (!target_stopped_data_address (¤t_target, &addr))
2818 for (v = b->val_chain; v; v = value_next (v))
2820 if (VALUE_LVAL (v) == lval_memory
2821 && ! value_lazy (v))
2823 struct type *vtype = check_typedef (value_type (v));
2825 if (v == b->val_chain
2826 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2827 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2831 vaddr = VALUE_ADDRESS (v) + value_offset (v);
2832 /* Exact match not required. Within range is
2834 if (addr >= vaddr &&
2835 addr < vaddr + TYPE_LENGTH (value_type (v)))
2842 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2844 struct cleanup *cleanups = make_cleanup (xfree, message);
2845 int e = catch_errors (watchpoint_check, bs, message,
2847 do_cleanups (cleanups);
2851 /* We've already printed what needs to be printed. */
2852 bs->print_it = print_it_done;
2855 case WP_VALUE_CHANGED:
2856 if (b->type == bp_read_watchpoint)
2858 /* Don't stop: read watchpoints shouldn't fire if
2859 the value has changed. This is for targets
2860 which cannot set read-only watchpoints. */
2861 bs->print_it = print_it_noop;
2867 case WP_VALUE_NOT_CHANGED:
2874 /* Error from catch_errors. */
2875 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2876 if (b->related_breakpoint)
2877 b->related_breakpoint->disposition = disp_del_at_next_stop;
2878 b->disposition = disp_del_at_next_stop;
2879 /* We've already printed what needs to be printed. */
2880 bs->print_it = print_it_done;
2884 else /* found == 0 */
2886 /* This is a case where some watchpoint(s) triggered,
2887 but not at the address of this watchpoint (FOUND
2888 was left zero). So don't print anything for this
2890 bs->print_it = print_it_noop;
2897 /* By definition, an encountered breakpoint is a triggered
2901 real_breakpoint = 1;
2904 if (frame_id_p (b->frame_id)
2905 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2909 int value_is_zero = 0;
2913 /* Need to select the frame, with all that implies
2914 so that the conditions will have the right context. */
2915 select_frame (get_current_frame ());
2917 = catch_errors (breakpoint_cond_eval, (b->cond),
2918 "Error in testing breakpoint condition:\n",
2920 /* FIXME-someday, should give breakpoint # */
2923 if (b->cond && value_is_zero)
2926 /* Don't consider this a hit. */
2929 else if (b->thread != -1 && b->thread != thread_id)
2932 /* Don't consider this a hit. */
2935 else if (b->ignore_count > 0)
2938 annotate_ignore_count_change ();
2943 /* We will stop here */
2944 if (b->disposition == disp_disable)
2945 b->enable_state = bp_disabled;
2948 bs->commands = b->commands;
2950 (strcmp ("silent", bs->commands->line) == 0
2951 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
2953 bs->commands = bs->commands->next;
2956 bs->commands = copy_command_lines (bs->commands);
2959 /* Print nothing for this entry if we dont stop or if we dont print. */
2960 if (bs->stop == 0 || bs->print == 0)
2961 bs->print_it = print_it_noop;
2964 bs->next = NULL; /* Terminate the chain */
2965 bs = root_bs->next; /* Re-grab the head of the chain */
2967 /* The value of a hardware watchpoint hasn't changed, but the
2968 intermediate memory locations we are watching may have. */
2969 if (bs && !bs->stop &&
2970 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2971 bs->breakpoint_at->type == bp_read_watchpoint ||
2972 bs->breakpoint_at->type == bp_access_watchpoint))
2974 remove_breakpoints ();
2975 insert_breakpoints ();
2980 /* Tell what to do about this bpstat. */
2982 bpstat_what (bpstat bs)
2984 /* Classify each bpstat as one of the following. */
2987 /* This bpstat element has no effect on the main_action. */
2990 /* There was a watchpoint, stop but don't print. */
2993 /* There was a watchpoint, stop and print. */
2996 /* There was a breakpoint but we're not stopping. */
2999 /* There was a breakpoint, stop but don't print. */
3002 /* There was a breakpoint, stop and print. */
3005 /* We hit the longjmp breakpoint. */
3008 /* We hit the longjmp_resume breakpoint. */
3011 /* We hit the step_resume breakpoint. */
3014 /* We hit the shared library event breakpoint. */
3017 /* We caught a shared library event. */
3020 /* This is just used to count how many enums there are. */
3024 /* Here is the table which drives this routine. So that we can
3025 format it pretty, we define some abbreviations for the
3026 enum bpstat_what codes. */
3027 #define kc BPSTAT_WHAT_KEEP_CHECKING
3028 #define ss BPSTAT_WHAT_STOP_SILENT
3029 #define sn BPSTAT_WHAT_STOP_NOISY
3030 #define sgl BPSTAT_WHAT_SINGLE
3031 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3032 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3033 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3034 #define sr BPSTAT_WHAT_STEP_RESUME
3035 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3036 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3038 /* "Can't happen." Might want to print an error message.
3039 abort() is not out of the question, but chances are GDB is just
3040 a bit confused, not unusable. */
3041 #define err BPSTAT_WHAT_STOP_NOISY
3043 /* Given an old action and a class, come up with a new action. */
3044 /* One interesting property of this table is that wp_silent is the same
3045 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3046 after stopping, the check for whether to step over a breakpoint
3047 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3048 reference to how we stopped. We retain separate wp_silent and
3049 bp_silent codes in case we want to change that someday.
3051 Another possibly interesting property of this table is that
3052 there's a partial ordering, priority-like, of the actions. Once
3053 you've decided that some action is appropriate, you'll never go
3054 back and decide something of a lower priority is better. The
3057 kc < clr sgl shl shlr slr sn sr ss
3058 sgl < clrs shl shlr slr sn sr ss
3059 slr < err shl shlr sn sr ss
3060 clr < clrs err shl shlr sn sr ss
3061 clrs < err shl shlr sn sr ss
3068 What I think this means is that we don't need a damned table
3069 here. If you just put the rows and columns in the right order,
3070 it'd look awfully regular. We could simply walk the bpstat list
3071 and choose the highest priority action we find, with a little
3072 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3073 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3074 is messy anyway). */
3076 /* step_resume entries: a step resume breakpoint overrides another
3077 breakpoint of signal handling (see comment in wait_for_inferior
3078 at where we set the step_resume breakpoint). */
3080 static const enum bpstat_what_main_action
3081 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3084 /* kc ss sn sgl slr clr clrs sr shl shlr
3087 {kc, ss, sn, sgl, slr, clr, clrs, sr, shl, shlr},
3089 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3091 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3093 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, shl, shlr},
3095 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3097 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3099 {slr, ss, sn, slr, slr, err, err, sr, shl, shlr},
3101 {clr, ss, sn, clrs, err, err, err, sr, shl, shlr},
3103 {sr, sr, sr, sr, sr, sr, sr, sr, sr, sr},
3105 {shl, shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3107 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3122 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3123 struct bpstat_what retval;
3125 retval.call_dummy = 0;
3126 for (; bs != NULL; bs = bs->next)
3128 enum class bs_class = no_effect;
3129 if (bs->breakpoint_at == NULL)
3130 /* I suspect this can happen if it was a momentary breakpoint
3131 which has since been deleted. */
3133 switch (bs->breakpoint_at->type)
3139 case bp_hardware_breakpoint:
3145 bs_class = bp_noisy;
3147 bs_class = bp_silent;
3150 bs_class = bp_nostop;
3153 case bp_hardware_watchpoint:
3154 case bp_read_watchpoint:
3155 case bp_access_watchpoint:
3159 bs_class = wp_noisy;
3161 bs_class = wp_silent;
3164 /* There was a watchpoint, but we're not stopping.
3165 This requires no further action. */
3166 bs_class = no_effect;
3169 bs_class = long_jump;
3171 case bp_longjmp_resume:
3172 bs_class = long_resume;
3174 case bp_step_resume:
3177 bs_class = step_resume;
3180 /* It is for the wrong frame. */
3181 bs_class = bp_nostop;
3183 case bp_watchpoint_scope:
3184 bs_class = bp_nostop;
3186 case bp_shlib_event:
3187 bs_class = shlib_event;
3189 case bp_thread_event:
3190 case bp_overlay_event:
3191 bs_class = bp_nostop;
3194 case bp_catch_unload:
3195 /* Only if this catchpoint triggered should we cause the
3196 step-out-of-dld behaviour. Otherwise, we ignore this
3199 bs_class = catch_shlib_event;
3201 bs_class = no_effect;
3204 case bp_catch_vfork:
3209 bs_class = bp_noisy;
3211 bs_class = bp_silent;
3214 /* There was a catchpoint, but we're not stopping.
3215 This requires no further action. */
3216 bs_class = no_effect;
3218 case bp_catch_catch:
3219 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3220 bs_class = bp_nostop;
3222 bs_class = bs->print ? bp_noisy : bp_silent;
3224 case bp_catch_throw:
3225 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3226 bs_class = bp_nostop;
3228 bs_class = bs->print ? bp_noisy : bp_silent;
3231 /* Make sure the action is stop (silent or noisy),
3232 so infrun.c pops the dummy frame. */
3233 bs_class = bp_silent;
3234 retval.call_dummy = 1;
3237 current_action = table[(int) bs_class][(int) current_action];
3239 retval.main_action = current_action;
3243 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3244 without hardware support). This isn't related to a specific bpstat,
3245 just to things like whether watchpoints are set. */
3248 bpstat_should_step (void)
3250 struct breakpoint *b;
3252 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3257 /* Nonzero if there are enabled hardware watchpoints. */
3259 bpstat_have_active_hw_watchpoints (void)
3261 struct bp_location *bpt;
3262 ALL_BP_LOCATIONS (bpt)
3263 if (breakpoint_enabled (bpt->owner)
3265 && bpt->loc_type == bp_loc_hardware_watchpoint)
3271 /* Given a bpstat that records zero or more triggered eventpoints, this
3272 function returns another bpstat which contains only the catchpoints
3273 on that first list, if any. */
3275 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3277 struct bpstats root_bs[1];
3278 bpstat bs = root_bs;
3279 struct breakpoint *ep;
3282 bpstat_clear (cp_list);
3283 root_bs->next = NULL;
3285 for (; ep_list != NULL; ep_list = ep_list->next)
3287 /* Is this eventpoint a catchpoint? If not, ignore it. */
3288 ep = ep_list->breakpoint_at;
3291 if ((ep->type != bp_catch_load) &&
3292 (ep->type != bp_catch_unload) &&
3293 (ep->type != bp_catch_catch) &&
3294 (ep->type != bp_catch_throw))
3295 /* pai: (temp) ADD fork/vfork here!! */
3298 /* Yes; add it to the list. */
3299 bs = bpstat_alloc (ep, bs);
3304 #if defined(SOLIB_ADD)
3305 /* Also, for each triggered catchpoint, tag it with the name of
3306 the library that caused this trigger. (We copy the name now,
3307 because it's only guaranteed to be available NOW, when the
3308 catchpoint triggers. Clients who may wish to know the name
3309 later must get it from the catchpoint itself.) */
3310 if (ep->triggered_dll_pathname != NULL)
3311 xfree (ep->triggered_dll_pathname);
3312 if (ep->type == bp_catch_load)
3313 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3314 PIDGET (inferior_ptid));
3316 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3317 PIDGET (inferior_ptid));
3319 dll_pathname = NULL;
3323 ep->triggered_dll_pathname = (char *)
3324 xmalloc (strlen (dll_pathname) + 1);
3325 strcpy (ep->triggered_dll_pathname, dll_pathname);
3328 ep->triggered_dll_pathname = NULL;
3334 /* Print B to gdb_stdout. */
3336 print_one_breakpoint (struct breakpoint *b,
3337 CORE_ADDR *last_addr)
3339 struct command_line *l;
3341 struct ep_type_description
3346 static struct ep_type_description bptypes[] =
3348 {bp_none, "?deleted?"},
3349 {bp_breakpoint, "breakpoint"},
3350 {bp_hardware_breakpoint, "hw breakpoint"},
3351 {bp_until, "until"},
3352 {bp_finish, "finish"},
3353 {bp_watchpoint, "watchpoint"},
3354 {bp_hardware_watchpoint, "hw watchpoint"},
3355 {bp_read_watchpoint, "read watchpoint"},
3356 {bp_access_watchpoint, "acc watchpoint"},
3357 {bp_longjmp, "longjmp"},
3358 {bp_longjmp_resume, "longjmp resume"},
3359 {bp_step_resume, "step resume"},
3360 {bp_watchpoint_scope, "watchpoint scope"},
3361 {bp_call_dummy, "call dummy"},
3362 {bp_shlib_event, "shlib events"},
3363 {bp_thread_event, "thread events"},
3364 {bp_overlay_event, "overlay events"},
3365 {bp_catch_load, "catch load"},
3366 {bp_catch_unload, "catch unload"},
3367 {bp_catch_fork, "catch fork"},
3368 {bp_catch_vfork, "catch vfork"},
3369 {bp_catch_exec, "catch exec"},
3370 {bp_catch_catch, "catch catch"},
3371 {bp_catch_throw, "catch throw"}
3374 static char *bpdisps[] =
3375 {"del", "dstp", "dis", "keep"};
3376 static char bpenables[] = "nynny";
3377 char wrap_indent[80];
3378 struct ui_stream *stb = ui_out_stream_new (uiout);
3379 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3380 struct cleanup *bkpt_chain;
3383 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3387 ui_out_field_int (uiout, "number", b->number);
3391 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3392 || ((int) b->type != bptypes[(int) b->type].type))
3393 internal_error (__FILE__, __LINE__,
3394 _("bptypes table does not describe type #%d."),
3396 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3400 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3404 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3405 ui_out_spaces (uiout, 2);
3408 strcpy (wrap_indent, " ");
3411 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3412 strcat (wrap_indent, " ");
3414 strcat (wrap_indent, " ");
3417 if (b->ops != NULL && b->ops->print_one != NULL)
3418 b->ops->print_one (b, last_addr);
3423 internal_error (__FILE__, __LINE__,
3424 _("print_one_breakpoint: bp_none encountered\n"));
3428 case bp_hardware_watchpoint:
3429 case bp_read_watchpoint:
3430 case bp_access_watchpoint:
3431 /* Field 4, the address, is omitted (which makes the columns
3432 not line up too nicely with the headers, but the effect
3433 is relatively readable). */
3435 ui_out_field_skip (uiout, "addr");
3437 print_expression (b->exp, stb->stream);
3438 ui_out_field_stream (uiout, "what", stb);
3442 case bp_catch_unload:
3443 /* Field 4, the address, is omitted (which makes the columns
3444 not line up too nicely with the headers, but the effect
3445 is relatively readable). */
3447 ui_out_field_skip (uiout, "addr");
3449 if (b->dll_pathname == NULL)
3451 ui_out_field_string (uiout, "what", "<any library>");
3452 ui_out_spaces (uiout, 1);
3456 ui_out_text (uiout, "library \"");
3457 ui_out_field_string (uiout, "what", b->dll_pathname);
3458 ui_out_text (uiout, "\" ");
3463 case bp_catch_vfork:
3464 /* Field 4, the address, is omitted (which makes the columns
3465 not line up too nicely with the headers, but the effect
3466 is relatively readable). */
3468 ui_out_field_skip (uiout, "addr");
3470 if (b->forked_inferior_pid != 0)
3472 ui_out_text (uiout, "process ");
3473 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3474 ui_out_spaces (uiout, 1);
3479 /* Field 4, the address, is omitted (which makes the columns
3480 not line up too nicely with the headers, but the effect
3481 is relatively readable). */
3483 ui_out_field_skip (uiout, "addr");
3485 if (b->exec_pathname != NULL)
3487 ui_out_text (uiout, "program \"");
3488 ui_out_field_string (uiout, "what", b->exec_pathname);
3489 ui_out_text (uiout, "\" ");
3493 case bp_catch_catch:
3494 /* Field 4, the address, is omitted (which makes the columns
3495 not line up too nicely with the headers, but the effect
3496 is relatively readable). */
3498 ui_out_field_skip (uiout, "addr");
3500 ui_out_field_string (uiout, "what", "exception catch");
3501 ui_out_spaces (uiout, 1);
3504 case bp_catch_throw:
3505 /* Field 4, the address, is omitted (which makes the columns
3506 not line up too nicely with the headers, but the effect
3507 is relatively readable). */
3509 ui_out_field_skip (uiout, "addr");
3511 ui_out_field_string (uiout, "what", "exception throw");
3512 ui_out_spaces (uiout, 1);
3516 case bp_hardware_breakpoint:
3520 case bp_longjmp_resume:
3521 case bp_step_resume:
3522 case bp_watchpoint_scope:
3524 case bp_shlib_event:
3525 case bp_thread_event:
3526 case bp_overlay_event:
3531 ui_out_field_string (uiout, "addr", "<PENDING>");
3533 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3536 *last_addr = b->loc->address;
3539 sym = find_pc_sect_function (b->loc->address, b->loc->section);
3542 ui_out_text (uiout, "in ");
3543 ui_out_field_string (uiout, "func",
3544 SYMBOL_PRINT_NAME (sym));
3545 ui_out_wrap_hint (uiout, wrap_indent);
3546 ui_out_text (uiout, " at ");
3548 ui_out_field_string (uiout, "file", b->source_file);
3549 ui_out_text (uiout, ":");
3551 if (ui_out_is_mi_like_p (uiout))
3553 struct symtab_and_line sal = find_pc_line (b->loc->address, 0);
3554 char *fullname = symtab_to_fullname (sal.symtab);
3557 ui_out_field_string (uiout, "fullname", fullname);
3560 ui_out_field_int (uiout, "line", b->line_number);
3562 else if (b->pending)
3564 ui_out_field_string (uiout, "pending", b->addr_string);
3568 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3569 ui_out_field_stream (uiout, "at", stb);
3574 if (b->thread != -1)
3576 /* FIXME: This seems to be redundant and lost here; see the
3577 "stop only in" line a little further down. */
3578 ui_out_text (uiout, " thread ");
3579 ui_out_field_int (uiout, "thread", b->thread);
3582 ui_out_text (uiout, "\n");
3584 if (frame_id_p (b->frame_id))
3587 ui_out_text (uiout, "\tstop only in stack frame at ");
3588 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3590 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3591 ui_out_text (uiout, "\n");
3594 if (b->cond && !ada_exception_catchpoint_p (b))
3596 /* We do not print the condition for Ada exception catchpoints
3597 because the condition is an internal implementation detail
3598 that we do not want to expose to the user. */
3600 ui_out_text (uiout, "\tstop only if ");
3601 print_expression (b->cond, stb->stream);
3602 ui_out_field_stream (uiout, "cond", stb);
3603 ui_out_text (uiout, "\n");
3606 if (b->pending && b->cond_string)
3609 ui_out_text (uiout, "\tstop only if ");
3610 ui_out_field_string (uiout, "cond", b->cond_string);
3611 ui_out_text (uiout, "\n");
3614 if (b->thread != -1)
3616 /* FIXME should make an annotation for this */
3617 ui_out_text (uiout, "\tstop only in thread ");
3618 ui_out_field_int (uiout, "thread", b->thread);
3619 ui_out_text (uiout, "\n");
3622 if (show_breakpoint_hit_counts && b->hit_count)
3624 /* FIXME should make an annotation for this */
3625 if (ep_is_catchpoint (b))
3626 ui_out_text (uiout, "\tcatchpoint");
3628 ui_out_text (uiout, "\tbreakpoint");
3629 ui_out_text (uiout, " already hit ");
3630 ui_out_field_int (uiout, "times", b->hit_count);
3631 if (b->hit_count == 1)
3632 ui_out_text (uiout, " time\n");
3634 ui_out_text (uiout, " times\n");
3637 /* Output the count also if it is zero, but only if this is
3638 mi. FIXME: Should have a better test for this. */
3639 if (ui_out_is_mi_like_p (uiout))
3640 if (show_breakpoint_hit_counts && b->hit_count == 0)
3641 ui_out_field_int (uiout, "times", b->hit_count);
3643 if (b->ignore_count)
3646 ui_out_text (uiout, "\tignore next ");
3647 ui_out_field_int (uiout, "ignore", b->ignore_count);
3648 ui_out_text (uiout, " hits\n");
3651 if ((l = b->commands))
3653 struct cleanup *script_chain;
3656 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3657 print_command_lines (uiout, l, 4);
3658 do_cleanups (script_chain);
3660 do_cleanups (bkpt_chain);
3661 do_cleanups (old_chain);
3664 struct captured_breakpoint_query_args
3670 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3672 struct captured_breakpoint_query_args *args = data;
3673 struct breakpoint *b;
3674 CORE_ADDR dummy_addr = 0;
3677 if (args->bnum == b->number)
3679 print_one_breakpoint (b, &dummy_addr);
3687 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3689 struct captured_breakpoint_query_args args;
3691 /* For the moment we don't trust print_one_breakpoint() to not throw
3693 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3694 error_message, RETURN_MASK_ALL) < 0)
3700 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3701 catchpoints, et.al.). */
3704 user_settable_breakpoint (const struct breakpoint *b)
3706 return (b->type == bp_breakpoint
3707 || b->type == bp_catch_load
3708 || b->type == bp_catch_unload
3709 || b->type == bp_catch_fork
3710 || b->type == bp_catch_vfork
3711 || b->type == bp_catch_exec
3712 || b->type == bp_catch_catch
3713 || b->type == bp_catch_throw
3714 || b->type == bp_hardware_breakpoint
3715 || b->type == bp_watchpoint
3716 || b->type == bp_read_watchpoint
3717 || b->type == bp_access_watchpoint
3718 || b->type == bp_hardware_watchpoint);
3721 /* Print information on user settable breakpoint (watchpoint, etc)
3722 number BNUM. If BNUM is -1 print all user settable breakpoints.
3723 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3726 breakpoint_1 (int bnum, int allflag)
3728 struct breakpoint *b;
3729 CORE_ADDR last_addr = (CORE_ADDR) -1;
3730 int nr_printable_breakpoints;
3731 struct cleanup *bkpttbl_chain;
3733 /* Compute the number of rows in the table. */
3734 nr_printable_breakpoints = 0;
3737 || bnum == b->number)
3739 if (allflag || user_settable_breakpoint (b))
3740 nr_printable_breakpoints++;
3745 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3749 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3752 if (nr_printable_breakpoints > 0)
3753 annotate_breakpoints_headers ();
3754 if (nr_printable_breakpoints > 0)
3756 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3757 if (nr_printable_breakpoints > 0)
3759 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3760 if (nr_printable_breakpoints > 0)
3762 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3763 if (nr_printable_breakpoints > 0)
3765 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3768 if (nr_printable_breakpoints > 0)
3770 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3771 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3773 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3775 if (nr_printable_breakpoints > 0)
3777 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3778 ui_out_table_body (uiout);
3779 if (nr_printable_breakpoints > 0)
3780 annotate_breakpoints_table ();
3784 || bnum == b->number)
3786 /* We only print out user settable breakpoints unless the
3788 if (allflag || user_settable_breakpoint (b))
3789 print_one_breakpoint (b, &last_addr);
3792 do_cleanups (bkpttbl_chain);
3794 if (nr_printable_breakpoints == 0)
3797 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3799 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3804 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3805 that a comparison of an unsigned with -1 is always false. */
3806 if (last_addr != (CORE_ADDR) -1 && !server_command)
3807 set_next_address (last_addr);
3810 /* FIXME? Should this be moved up so that it is only called when
3811 there have been breakpoints? */
3812 annotate_breakpoints_table_end ();
3816 breakpoints_info (char *bnum_exp, int from_tty)
3821 bnum = parse_and_eval_long (bnum_exp);
3823 breakpoint_1 (bnum, 0);
3827 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3832 bnum = parse_and_eval_long (bnum_exp);
3834 breakpoint_1 (bnum, 1);
3837 /* Print a message describing any breakpoints set at PC. */
3840 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
3843 struct breakpoint *b;
3846 if (b->loc->address == pc) /* address match / overlay match */
3847 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3852 printf_filtered (_("Note: breakpoint "));
3853 else /* if (others == ???) */
3854 printf_filtered (_("Note: breakpoints "));
3856 if (b->loc->address == pc) /* address match / overlay match */
3857 if (!b->pending && (!overlay_debugging || b->loc->section == section))
3860 printf_filtered ("%d", b->number);
3861 if (b->thread == -1 && thread != -1)
3862 printf_filtered (" (all threads)");
3863 else if (b->thread != -1)
3864 printf_filtered (" (thread %d)", b->thread);
3865 printf_filtered ("%s%s ",
3866 ((b->enable_state == bp_disabled ||
3867 b->enable_state == bp_shlib_disabled ||
3868 b->enable_state == bp_call_disabled)
3870 : b->enable_state == bp_permanent
3874 : ((others == 1) ? " and" : ""));
3876 printf_filtered (_("also set at pc "));
3877 deprecated_print_address_numeric (pc, 1, gdb_stdout);
3878 printf_filtered (".\n");
3882 /* Set the default place to put a breakpoint
3883 for the `break' command with no arguments. */
3886 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3889 default_breakpoint_valid = valid;
3890 default_breakpoint_address = addr;
3891 default_breakpoint_symtab = symtab;
3892 default_breakpoint_line = line;
3895 /* Return true iff it is meaningful to use the address member of
3896 BPT. For some breakpoint types, the address member is irrelevant
3897 and it makes no sense to attempt to compare it to other addresses
3898 (or use it for any other purpose either).
3900 More specifically, each of the following breakpoint types will always
3901 have a zero valued address and we don't want check_duplicates() to mark
3902 breakpoints of any of these types to be a duplicate of an actual
3903 breakpoint at address zero:
3906 bp_hardware_watchpoint
3908 bp_access_watchpoint
3915 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3917 enum bptype type = bpt->type;
3919 return (type != bp_watchpoint
3920 && type != bp_hardware_watchpoint
3921 && type != bp_read_watchpoint
3922 && type != bp_access_watchpoint
3923 && type != bp_catch_exec
3924 && type != bp_longjmp_resume
3925 && type != bp_catch_fork
3926 && type != bp_catch_vfork);
3929 /* Rescan breakpoints at the same address and section as BPT,
3930 marking the first one as "first" and any others as "duplicates".
3931 This is so that the bpt instruction is only inserted once.
3932 If we have a permanent breakpoint at the same place as BPT, make
3933 that one the official one, and the rest as duplicates. */
3936 check_duplicates (struct breakpoint *bpt)
3938 struct bp_location *b;
3940 struct bp_location *perm_bp = 0;
3941 CORE_ADDR address = bpt->loc->address;
3942 asection *section = bpt->loc->section;
3944 if (! breakpoint_address_is_meaningful (bpt))
3947 ALL_BP_LOCATIONS (b)
3948 if (b->owner->enable_state != bp_disabled
3949 && b->owner->enable_state != bp_shlib_disabled
3950 && !b->owner->pending
3951 && b->owner->enable_state != bp_call_disabled
3952 && b->address == address /* address / overlay match */
3953 && (!overlay_debugging || b->section == section)
3954 && breakpoint_address_is_meaningful (b->owner))
3956 /* Have we found a permanent breakpoint? */
3957 if (b->owner->enable_state == bp_permanent)
3964 b->duplicate = count > 1;
3967 /* If we found a permanent breakpoint at this address, go over the
3968 list again and declare all the other breakpoints there to be the
3972 perm_bp->duplicate = 0;
3974 /* Permanent breakpoint should always be inserted. */
3975 if (! perm_bp->inserted)
3976 internal_error (__FILE__, __LINE__,
3977 _("allegedly permanent breakpoint is not "
3978 "actually inserted"));
3980 ALL_BP_LOCATIONS (b)
3983 if (b->owner->enable_state != bp_disabled
3984 && b->owner->enable_state != bp_shlib_disabled
3985 && !b->owner->pending
3986 && b->owner->enable_state != bp_call_disabled
3987 && b->address == address /* address / overlay match */
3988 && (!overlay_debugging || b->section == section)
3989 && breakpoint_address_is_meaningful (b->owner))
3992 internal_error (__FILE__, __LINE__,
3993 _("another breakpoint was inserted on top of "
3994 "a permanent breakpoint"));
4003 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4004 int bnum, int have_bnum)
4009 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4010 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4012 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4013 bnum, astr1, astr2);
4015 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4018 /* Adjust a breakpoint's address to account for architectural constraints
4019 on breakpoint placement. Return the adjusted address. Note: Very
4020 few targets require this kind of adjustment. For most targets,
4021 this function is simply the identity function. */
4024 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4026 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4028 /* Very few targets need any kind of breakpoint adjustment. */
4031 else if (bptype == bp_watchpoint
4032 || bptype == bp_hardware_watchpoint
4033 || bptype == bp_read_watchpoint
4034 || bptype == bp_access_watchpoint
4035 || bptype == bp_catch_fork
4036 || bptype == bp_catch_vfork
4037 || bptype == bp_catch_exec)
4039 /* Watchpoints and the various bp_catch_* eventpoints should not
4040 have their addresses modified. */
4045 CORE_ADDR adjusted_bpaddr;
4047 /* Some targets have architectural constraints on the placement
4048 of breakpoint instructions. Obtain the adjusted address. */
4049 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4052 /* An adjusted breakpoint address can significantly alter
4053 a user's expectations. Print a warning if an adjustment
4055 if (adjusted_bpaddr != bpaddr)
4056 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4058 return adjusted_bpaddr;
4062 /* Allocate a struct bp_location. */
4064 static struct bp_location *
4065 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4067 struct bp_location *loc, *loc_p;
4069 loc = xmalloc (sizeof (struct bp_location));
4070 memset (loc, 0, sizeof (*loc));
4080 case bp_longjmp_resume:
4081 case bp_step_resume:
4082 case bp_watchpoint_scope:
4084 case bp_shlib_event:
4085 case bp_thread_event:
4086 case bp_overlay_event:
4088 case bp_catch_unload:
4089 loc->loc_type = bp_loc_software_breakpoint;
4091 case bp_hardware_breakpoint:
4092 loc->loc_type = bp_loc_hardware_breakpoint;
4094 case bp_hardware_watchpoint:
4095 case bp_read_watchpoint:
4096 case bp_access_watchpoint:
4097 loc->loc_type = bp_loc_hardware_watchpoint;
4101 case bp_catch_vfork:
4103 case bp_catch_catch:
4104 case bp_catch_throw:
4105 loc->loc_type = bp_loc_other;
4108 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4111 /* Add this breakpoint to the end of the chain. */
4113 loc_p = bp_location_chain;
4115 bp_location_chain = loc;
4119 loc_p = loc_p->next;
4126 /* set_raw_breakpoint() is a low level routine for allocating and
4127 partially initializing a breakpoint of type BPTYPE. The newly
4128 created breakpoint's address, section, source file name, and line
4129 number are provided by SAL. The newly created and partially
4130 initialized breakpoint is added to the breakpoint chain and
4131 is also returned as the value of this function.
4133 It is expected that the caller will complete the initialization of
4134 the newly created breakpoint struct as well as output any status
4135 information regarding the creation of a new breakpoint. In
4136 particular, set_raw_breakpoint() does NOT set the breakpoint
4137 number! Care should be taken to not allow an error() to occur
4138 prior to completing the initialization of the breakpoint. If this
4139 should happen, a bogus breakpoint will be left on the chain. */
4142 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4144 struct breakpoint *b, *b1;
4145 CORE_ADDR adjusted_address;
4147 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4148 memset (b, 0, sizeof (*b));
4150 /* Adjust the breakpoint's address prior to allocating a location.
4151 Once we call allocate_bp_location(), that mostly uninitialized
4152 location will be placed on the location chain. Adjustment of the
4153 breakpoint may cause read_memory_nobpt() to be called and we do
4154 not want its scan of the location chain to find a breakpoint and
4155 location that's only been partially initialized. */
4156 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4158 b->loc = allocate_bp_location (b, bptype);
4159 b->loc->requested_address = sal.pc;
4160 b->loc->address = adjusted_address;
4162 if (sal.symtab == NULL)
4163 b->source_file = NULL;
4165 b->source_file = savestring (sal.symtab->filename,
4166 strlen (sal.symtab->filename));
4167 b->loc->section = sal.section;
4169 b->language = current_language->la_language;
4170 b->input_radix = input_radix;
4172 b->line_number = sal.line;
4173 b->enable_state = bp_enabled;
4176 b->ignore_count = 0;
4178 b->frame_id = null_frame_id;
4179 b->dll_pathname = NULL;
4180 b->triggered_dll_pathname = NULL;
4181 b->forked_inferior_pid = 0;
4182 b->exec_pathname = NULL;
4186 /* Add this breakpoint to the end of the chain
4187 so that a list of breakpoints will come out in order
4188 of increasing numbers. */
4190 b1 = breakpoint_chain;
4192 breakpoint_chain = b;
4200 check_duplicates (b);
4201 breakpoints_changed ();
4207 /* Note that the breakpoint object B describes a permanent breakpoint
4208 instruction, hard-wired into the inferior's code. */
4210 make_breakpoint_permanent (struct breakpoint *b)
4212 b->enable_state = bp_permanent;
4214 /* By definition, permanent breakpoints are already present in the code. */
4215 b->loc->inserted = 1;
4218 static struct breakpoint *
4219 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4221 static int internal_breakpoint_number = -1;
4222 struct symtab_and_line sal;
4223 struct breakpoint *b;
4225 init_sal (&sal); /* initialize to zeroes */
4228 sal.section = find_pc_overlay (sal.pc);
4230 b = set_raw_breakpoint (sal, type);
4231 b->number = internal_breakpoint_number--;
4232 b->disposition = disp_donttouch;
4239 create_longjmp_breakpoint (char *func_name)
4241 struct breakpoint *b;
4242 struct minimal_symbol *m;
4244 if (func_name == NULL)
4245 b = create_internal_breakpoint (0, bp_longjmp_resume);
4248 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4251 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4254 b->enable_state = bp_disabled;
4257 b->addr_string = xstrdup (func_name);
4260 /* Call this routine when stepping and nexting to enable a breakpoint
4261 if we do a longjmp(). When we hit that breakpoint, call
4262 set_longjmp_resume_breakpoint() to figure out where we are going. */
4265 enable_longjmp_breakpoint (void)
4267 struct breakpoint *b;
4270 if (b->type == bp_longjmp)
4272 b->enable_state = bp_enabled;
4273 check_duplicates (b);
4278 disable_longjmp_breakpoint (void)
4280 struct breakpoint *b;
4283 if (b->type == bp_longjmp
4284 || b->type == bp_longjmp_resume)
4286 b->enable_state = bp_disabled;
4287 check_duplicates (b);
4292 create_overlay_event_breakpoint (char *func_name)
4294 struct breakpoint *b;
4295 struct minimal_symbol *m;
4297 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4300 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4302 b->addr_string = xstrdup (func_name);
4304 if (overlay_debugging == ovly_auto)
4306 b->enable_state = bp_enabled;
4307 overlay_events_enabled = 1;
4311 b->enable_state = bp_disabled;
4312 overlay_events_enabled = 0;
4317 enable_overlay_breakpoints (void)
4319 struct breakpoint *b;
4322 if (b->type == bp_overlay_event)
4324 b->enable_state = bp_enabled;
4325 check_duplicates (b);
4326 overlay_events_enabled = 1;
4331 disable_overlay_breakpoints (void)
4333 struct breakpoint *b;
4336 if (b->type == bp_overlay_event)
4338 b->enable_state = bp_disabled;
4339 check_duplicates (b);
4340 overlay_events_enabled = 0;
4345 create_thread_event_breakpoint (CORE_ADDR address)
4347 struct breakpoint *b;
4349 b = create_internal_breakpoint (address, bp_thread_event);
4351 b->enable_state = bp_enabled;
4352 /* addr_string has to be used or breakpoint_re_set will delete me. */
4353 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4359 remove_thread_event_breakpoints (void)
4361 struct breakpoint *b, *temp;
4363 ALL_BREAKPOINTS_SAFE (b, temp)
4364 if (b->type == bp_thread_event)
4365 delete_breakpoint (b);
4368 struct captured_parse_breakpoint_args
4371 struct symtabs_and_lines *sals_p;
4372 char ***addr_string_p;
4376 struct lang_and_radix
4382 /* Cleanup helper routine to restore the current language and
4385 do_restore_lang_radix_cleanup (void *old)
4387 struct lang_and_radix *p = old;
4388 set_language (p->lang);
4389 input_radix = p->radix;
4392 /* Try and resolve a pending breakpoint. */
4394 resolve_pending_breakpoint (struct breakpoint *b)
4396 /* Try and reparse the breakpoint in case the shared library
4398 struct symtabs_and_lines sals;
4399 struct symtab_and_line pending_sal;
4400 char **cond_string = (char **) NULL;
4401 char *copy_arg = b->addr_string;
4406 struct ui_file *old_gdb_stderr;
4407 struct lang_and_radix old_lr;
4408 struct cleanup *old_chain;
4410 /* Set language, input-radix, then reissue breakpoint command.
4411 Ensure the language and input-radix are restored afterwards. */
4412 old_lr.lang = current_language->la_language;
4413 old_lr.radix = input_radix;
4414 old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr);
4416 set_language (b->language);
4417 input_radix = b->input_radix;
4418 rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b);
4420 if (rc == GDB_RC_OK)
4421 /* Pending breakpoint has been resolved. */
4422 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b->addr_string);
4424 do_cleanups (old_chain);
4429 remove_solib_event_breakpoints (void)
4431 struct breakpoint *b, *temp;
4433 ALL_BREAKPOINTS_SAFE (b, temp)
4434 if (b->type == bp_shlib_event)
4435 delete_breakpoint (b);
4439 create_solib_event_breakpoint (CORE_ADDR address)
4441 struct breakpoint *b;
4443 b = create_internal_breakpoint (address, bp_shlib_event);
4447 /* Disable any breakpoints that are on code in shared libraries. Only
4448 apply to enabled breakpoints, disabled ones can just stay disabled. */
4451 disable_breakpoints_in_shlibs (int silent)
4453 struct breakpoint *b;
4454 int disabled_shlib_breaks = 0;
4458 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4459 && breakpoint_enabled (b) && !b->loc->duplicate
4461 && PC_SOLIB (b->loc->address)
4463 && solib_address (b->loc->address)
4467 b->enable_state = bp_shlib_disabled;
4470 if (!disabled_shlib_breaks)
4472 target_terminal_ours_for_output ();
4473 warning (_("Temporarily disabling shared library breakpoints:"));
4475 disabled_shlib_breaks = 1;
4476 warning (_("breakpoint #%d "), b->number);
4482 /* Disable any breakpoints that are in in an unloaded shared library. Only
4483 apply to enabled breakpoints, disabled ones can just stay disabled. */
4486 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4488 struct breakpoint *b;
4489 int disabled_shlib_breaks = 0;
4493 if ((b->loc->loc_type == bp_loc_hardware_breakpoint
4494 || b->loc->loc_type == bp_loc_software_breakpoint)
4495 && breakpoint_enabled (b) && !b->loc->duplicate)
4498 char *so_name = PC_SOLIB (b->loc->address);
4500 char *so_name = solib_address (b->loc->address);
4502 if (so_name && !strcmp (so_name, solib->so_name))
4504 b->enable_state = bp_shlib_disabled;
4505 /* At this point, we cannot rely on remove_breakpoint
4506 succeeding so we must mark the breakpoint as not inserted
4507 to prevent future errors occurring in remove_breakpoints. */
4508 b->loc->inserted = 0;
4509 if (!disabled_shlib_breaks)
4511 target_terminal_ours_for_output ();
4512 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4515 disabled_shlib_breaks = 1;
4521 /* Try to reenable any breakpoints in shared libraries. */
4523 re_enable_breakpoints_in_shlibs (void)
4525 struct breakpoint *b, *tmp;
4527 ALL_BREAKPOINTS_SAFE (b, tmp)
4529 if (b->enable_state == bp_shlib_disabled)
4534 /* Do not reenable the breakpoint if the shared library is
4535 still not mapped in. */
4537 lib = PC_SOLIB (b->loc->address);
4539 lib = solib_address (b->loc->address);
4541 if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
4542 b->enable_state = bp_enabled;
4544 else if (b->pending && (b->enable_state == bp_enabled))
4546 if (resolve_pending_breakpoint (b) == GDB_RC_OK)
4547 delete_breakpoint (b);
4553 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4554 char *cond_string, enum bptype bp_kind)
4556 struct breakpoint *b;
4557 struct symtabs_and_lines sals;
4558 struct cleanup *old_chain;
4559 struct cleanup *canonical_strings_chain = NULL;
4560 char *addr_start = hookname;
4561 char *addr_end = NULL;
4562 char **canonical = (char **) NULL;
4563 int thread = -1; /* All threads. */
4565 /* Set a breakpoint on the specified hook. */
4566 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL,
4567 0, &canonical, NULL);
4568 addr_end = hookname;
4570 if (sals.nelts == 0)
4572 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4573 "Suggest linking with /opt/langtools/lib/end.o.\n"
4574 "GDB will be unable to track shl_load/shl_unload calls."));
4577 if (sals.nelts != 1)
4579 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4580 "GDB will be unable to track shl_load/shl_unload calls."));
4584 /* Make sure that all storage allocated in decode_line_1 gets freed
4585 in case the following errors out. */
4586 old_chain = make_cleanup (xfree, sals.sals);
4587 if (canonical != (char **) NULL)
4589 make_cleanup (xfree, canonical);
4590 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4591 if (canonical[0] != NULL)
4592 make_cleanup (xfree, canonical[0]);
4595 resolve_sal_pc (&sals.sals[0]);
4597 /* Remove the canonical strings from the cleanup, they are needed below. */
4598 if (canonical != (char **) NULL)
4599 discard_cleanups (canonical_strings_chain);
4601 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4602 set_breakpoint_count (breakpoint_count + 1);
4603 b->number = breakpoint_count;
4605 b->cond_string = (cond_string == NULL) ?
4606 NULL : savestring (cond_string, strlen (cond_string));
4609 if (canonical != (char **) NULL && canonical[0] != NULL)
4610 b->addr_string = canonical[0];
4611 else if (addr_start)
4612 b->addr_string = savestring (addr_start, addr_end - addr_start);
4614 b->enable_state = bp_enabled;
4615 b->disposition = tempflag ? disp_del : disp_donttouch;
4617 if (dll_pathname == NULL)
4618 b->dll_pathname = NULL;
4621 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4622 strcpy (b->dll_pathname, dll_pathname);
4626 do_cleanups (old_chain);
4630 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4631 char *dll_pathname, char *cond_string)
4633 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4634 cond_string, bp_catch_load);
4638 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4639 char *dll_pathname, char *cond_string)
4641 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4642 cond_string, bp_catch_unload);
4646 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4647 enum bptype bp_kind)
4649 struct symtab_and_line sal;
4650 struct breakpoint *b;
4651 int thread = -1; /* All threads. */
4658 b = set_raw_breakpoint (sal, bp_kind);
4659 set_breakpoint_count (breakpoint_count + 1);
4660 b->number = breakpoint_count;
4662 b->cond_string = (cond_string == NULL) ?
4663 NULL : savestring (cond_string, strlen (cond_string));
4665 b->addr_string = NULL;
4666 b->enable_state = bp_enabled;
4667 b->disposition = tempflag ? disp_del : disp_donttouch;
4668 b->forked_inferior_pid = 0;
4674 create_fork_event_catchpoint (int tempflag, char *cond_string)
4676 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4680 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4682 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4686 create_exec_event_catchpoint (int tempflag, char *cond_string)
4688 struct symtab_and_line sal;
4689 struct breakpoint *b;
4690 int thread = -1; /* All threads. */
4697 b = set_raw_breakpoint (sal, bp_catch_exec);
4698 set_breakpoint_count (breakpoint_count + 1);
4699 b->number = breakpoint_count;
4701 b->cond_string = (cond_string == NULL) ?
4702 NULL : savestring (cond_string, strlen (cond_string));
4704 b->addr_string = NULL;
4705 b->enable_state = bp_enabled;
4706 b->disposition = tempflag ? disp_del : disp_donttouch;
4712 hw_breakpoint_used_count (void)
4714 struct breakpoint *b;
4719 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4727 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4729 struct breakpoint *b;
4732 *other_type_used = 0;
4735 if (breakpoint_enabled (b))
4737 if (b->type == type)
4739 else if ((b->type == bp_hardware_watchpoint ||
4740 b->type == bp_read_watchpoint ||
4741 b->type == bp_access_watchpoint))
4742 *other_type_used = 1;
4748 /* Call this after hitting the longjmp() breakpoint. Use this to set
4749 a new breakpoint at the target of the jmp_buf.
4751 FIXME - This ought to be done by setting a temporary breakpoint
4752 that gets deleted automatically... */
4755 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4757 struct breakpoint *b;
4760 if (b->type == bp_longjmp_resume)
4762 b->loc->requested_address = pc;
4763 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4765 b->enable_state = bp_enabled;
4766 b->frame_id = frame_id;
4767 check_duplicates (b);
4773 disable_watchpoints_before_interactive_call_start (void)
4775 struct breakpoint *b;
4779 if (((b->type == bp_watchpoint)
4780 || (b->type == bp_hardware_watchpoint)
4781 || (b->type == bp_read_watchpoint)
4782 || (b->type == bp_access_watchpoint)
4783 || ep_is_exception_catchpoint (b))
4784 && breakpoint_enabled (b))
4786 b->enable_state = bp_call_disabled;
4787 check_duplicates (b);
4793 enable_watchpoints_after_interactive_call_stop (void)
4795 struct breakpoint *b;
4799 if (((b->type == bp_watchpoint)
4800 || (b->type == bp_hardware_watchpoint)
4801 || (b->type == bp_read_watchpoint)
4802 || (b->type == bp_access_watchpoint)
4803 || ep_is_exception_catchpoint (b))
4804 && (b->enable_state == bp_call_disabled))
4806 b->enable_state = bp_enabled;
4807 check_duplicates (b);
4813 /* Set a breakpoint that will evaporate an end of command
4814 at address specified by SAL.
4815 Restrict it to frame FRAME if FRAME is nonzero. */
4818 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4821 struct breakpoint *b;
4822 b = set_raw_breakpoint (sal, type);
4823 b->enable_state = bp_enabled;
4824 b->disposition = disp_donttouch;
4825 b->frame_id = frame_id;
4827 /* If we're debugging a multi-threaded program, then we
4828 want momentary breakpoints to be active in only a
4829 single thread of control. */
4830 if (in_thread_list (inferior_ptid))
4831 b->thread = pid_to_thread_id (inferior_ptid);
4837 /* Tell the user we have just set a breakpoint B. */
4840 mention (struct breakpoint *b)
4843 struct cleanup *old_chain, *ui_out_chain;
4844 struct ui_stream *stb;
4846 stb = ui_out_stream_new (uiout);
4847 old_chain = make_cleanup_ui_out_stream_delete (stb);
4849 /* FIXME: This is misplaced; mention() is called by things (like
4850 hitting a watchpoint) other than breakpoint creation. It should
4851 be possible to clean this up and at the same time replace the
4852 random calls to breakpoint_changed with this hook, as has already
4853 been done for deprecated_delete_breakpoint_hook and so on. */
4854 if (deprecated_create_breakpoint_hook)
4855 deprecated_create_breakpoint_hook (b);
4856 breakpoint_create_event (b->number);
4858 if (b->ops != NULL && b->ops->print_mention != NULL)
4859 b->ops->print_mention (b);
4864 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4867 ui_out_text (uiout, "Watchpoint ");
4868 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4869 ui_out_field_int (uiout, "number", b->number);
4870 ui_out_text (uiout, ": ");
4871 print_expression (b->exp, stb->stream);
4872 ui_out_field_stream (uiout, "exp", stb);
4873 do_cleanups (ui_out_chain);
4875 case bp_hardware_watchpoint:
4876 ui_out_text (uiout, "Hardware watchpoint ");
4877 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4878 ui_out_field_int (uiout, "number", b->number);
4879 ui_out_text (uiout, ": ");
4880 print_expression (b->exp, stb->stream);
4881 ui_out_field_stream (uiout, "exp", stb);
4882 do_cleanups (ui_out_chain);
4884 case bp_read_watchpoint:
4885 ui_out_text (uiout, "Hardware read watchpoint ");
4886 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4887 ui_out_field_int (uiout, "number", b->number);
4888 ui_out_text (uiout, ": ");
4889 print_expression (b->exp, stb->stream);
4890 ui_out_field_stream (uiout, "exp", stb);
4891 do_cleanups (ui_out_chain);
4893 case bp_access_watchpoint:
4894 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4895 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4896 ui_out_field_int (uiout, "number", b->number);
4897 ui_out_text (uiout, ": ");
4898 print_expression (b->exp, stb->stream);
4899 ui_out_field_stream (uiout, "exp", stb);
4900 do_cleanups (ui_out_chain);
4903 if (ui_out_is_mi_like_p (uiout))
4908 printf_filtered (_("Breakpoint %d"), b->number);
4911 case bp_hardware_breakpoint:
4912 if (ui_out_is_mi_like_p (uiout))
4917 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4921 case bp_catch_unload:
4922 printf_filtered (_("Catchpoint %d (%s %s)"),
4924 (b->type == bp_catch_load) ? "load" : "unload",
4925 (b->dll_pathname != NULL) ?
4926 b->dll_pathname : "<any library>");
4929 case bp_catch_vfork:
4930 printf_filtered (_("Catchpoint %d (%s)"),
4932 (b->type == bp_catch_fork) ? "fork" : "vfork");
4935 printf_filtered (_("Catchpoint %d (exec)"),
4938 case bp_catch_catch:
4939 case bp_catch_throw:
4940 printf_filtered (_("Catchpoint %d (%s)"),
4942 (b->type == bp_catch_catch) ? "catch" : "throw");
4948 case bp_longjmp_resume:
4949 case bp_step_resume:
4951 case bp_watchpoint_scope:
4952 case bp_shlib_event:
4953 case bp_thread_event:
4954 case bp_overlay_event:
4960 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4964 printf_filtered (_(" (%s) pending."), b->addr_string);
4968 if (addressprint || b->source_file == NULL)
4970 printf_filtered (" at ");
4971 deprecated_print_address_numeric (b->loc->address, 1, gdb_stdout);
4974 printf_filtered (": file %s, line %d.",
4975 b->source_file, b->line_number);
4978 do_cleanups (old_chain);
4979 if (ui_out_is_mi_like_p (uiout))
4981 printf_filtered ("\n");
4985 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4986 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4987 COND[i] and COND_STRING[i] values.
4989 The parameter PENDING_BP points to a pending breakpoint that is
4990 the basis of the breakpoints currently being created. The pending
4991 breakpoint may contain a separate condition string or commands
4992 that were added after the initial pending breakpoint was created.
4994 NOTE: If the function succeeds, the caller is expected to cleanup
4995 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4996 array contents). If the function fails (error() is called), the
4997 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4998 COND and SALS arrays and each of those arrays contents. */
5001 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5002 struct expression **cond, char **cond_string,
5003 enum bptype type, enum bpdisp disposition,
5004 int thread, int ignore_count, int from_tty,
5005 struct breakpoint *pending_bp)
5007 if (type == bp_hardware_breakpoint)
5009 int i = hw_breakpoint_used_count ();
5010 int target_resources_ok =
5011 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5013 if (target_resources_ok == 0)
5014 error (_("No hardware breakpoint support in the target."));
5015 else if (target_resources_ok < 0)
5016 error (_("Hardware breakpoints used exceeds limit."));
5019 /* Now set all the breakpoints. */
5022 for (i = 0; i < sals.nelts; i++)
5024 struct breakpoint *b;
5025 struct symtab_and_line sal = sals.sals[i];
5028 describe_other_breakpoints (sal.pc, sal.section, thread);
5030 b = set_raw_breakpoint (sal, type);
5031 set_breakpoint_count (breakpoint_count + 1);
5032 b->number = breakpoint_count;
5036 b->addr_string = addr_string[i];
5038 /* addr_string has to be used or breakpoint_re_set will delete
5040 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5041 b->cond_string = cond_string[i];
5042 b->ignore_count = ignore_count;
5043 b->enable_state = bp_enabled;
5044 b->disposition = disposition;
5045 /* If resolving a pending breakpoint, a check must be made to see if
5046 the user has specified a new condition or commands for the
5047 breakpoint. A new condition will override any condition that was
5048 initially specified with the initial breakpoint command. */
5052 if (pending_bp->cond_string)
5054 arg = pending_bp->cond_string;
5055 b->cond_string = savestring (arg, strlen (arg));
5056 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
5058 error (_("Junk at end of pending breakpoint condition expression"));
5060 /* If there are commands associated with the breakpoint, they should
5062 if (pending_bp->commands)
5063 b->commands = copy_command_lines (pending_bp->commands);
5065 /* We have to copy over the ignore_count and thread as well. */
5066 b->ignore_count = pending_bp->ignore_count;
5067 b->thread = pending_bp->thread;
5074 /* Parse ARG which is assumed to be a SAL specification possibly
5075 followed by conditionals. On return, SALS contains an array of SAL
5076 addresses found. ADDR_STRING contains a vector of (canonical)
5077 address strings. ARG points to the end of the SAL. */
5080 parse_breakpoint_sals (char **address,
5081 struct symtabs_and_lines *sals,
5082 char ***addr_string,
5085 char *addr_start = *address;
5086 *addr_string = NULL;
5087 /* If no arg given, or if first arg is 'if ', use the default
5089 if ((*address) == NULL
5090 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5092 if (default_breakpoint_valid)
5094 struct symtab_and_line sal;
5095 init_sal (&sal); /* initialize to zeroes */
5096 sals->sals = (struct symtab_and_line *)
5097 xmalloc (sizeof (struct symtab_and_line));
5098 sal.pc = default_breakpoint_address;
5099 sal.line = default_breakpoint_line;
5100 sal.symtab = default_breakpoint_symtab;
5101 sal.section = find_pc_overlay (sal.pc);
5102 sals->sals[0] = sal;
5106 error (_("No default breakpoint address now."));
5110 /* Force almost all breakpoints to be in terms of the
5111 current_source_symtab (which is decode_line_1's default). This
5112 should produce the results we want almost all of the time while
5113 leaving default_breakpoint_* alone.
5114 ObjC: However, don't match an Objective-C method name which
5115 may have a '+' or '-' succeeded by a '[' */
5117 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5119 if (default_breakpoint_valid
5121 || ((strchr ("+-", (*address)[0]) != NULL)
5122 && ((*address)[1] != '['))))
5123 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5124 default_breakpoint_line, addr_string,
5127 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5128 addr_string, not_found_ptr);
5130 /* For any SAL that didn't have a canonical string, fill one in. */
5131 if (sals->nelts > 0 && *addr_string == NULL)
5132 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5133 if (addr_start != (*address))
5136 for (i = 0; i < sals->nelts; i++)
5138 /* Add the string if not present. */
5139 if ((*addr_string)[i] == NULL)
5140 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5146 /* Convert each SAL into a real PC. Verify that the PC can be
5147 inserted as a breakpoint. If it can't throw an error. */
5150 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5154 for (i = 0; i < sals->nelts; i++)
5156 resolve_sal_pc (&sals->sals[i]);
5158 /* It's possible for the PC to be nonzero, but still an illegal
5159 value on some targets.
5161 For example, on HP-UX if you start gdb, and before running the
5162 inferior you try to set a breakpoint on a shared library function
5163 "foo" where the inferior doesn't call "foo" directly but does
5164 pass its address to another function call, then we do find a
5165 minimal symbol for the "foo", but it's address is invalid.
5166 (Appears to be an index into a table that the loader sets up
5167 when the inferior is run.)
5169 Give the target a chance to bless sals.sals[i].pc before we
5170 try to make a breakpoint for it. */
5171 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5172 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
5174 if (address == NULL)
5175 error (_("Cannot break without a running program."));
5177 error (_("Cannot break on %s without a running program."),
5185 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5187 struct captured_parse_breakpoint_args *args = data;
5189 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5190 args->not_found_ptr);
5193 /* Set a breakpoint according to ARG (function, linenum or *address)
5194 flag: first bit : 0 non-temporary, 1 temporary.
5195 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5197 PENDING_BP is non-NULL when this function is being called to resolve
5198 a pending breakpoint. */
5201 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
5203 struct gdb_exception e;
5204 int tempflag, hardwareflag;
5205 struct symtabs_and_lines sals;
5206 struct expression **cond = 0;
5207 struct symtab_and_line pending_sal;
5208 char **cond_string = (char **) NULL;
5211 char *addr_start = arg;
5213 struct cleanup *old_chain;
5214 struct cleanup *breakpoint_chain = NULL;
5215 struct captured_parse_breakpoint_args parse_args;
5219 int ignore_count = 0;
5222 hardwareflag = flag & BP_HARDWAREFLAG;
5223 tempflag = flag & BP_TEMPFLAG;
5229 parse_args.arg_p = &arg;
5230 parse_args.sals_p = &sals;
5231 parse_args.addr_string_p = &addr_string;
5232 parse_args.not_found_ptr = ¬_found;
5234 e = catch_exception (uiout, do_captured_parse_breakpoint,
5235 &parse_args, RETURN_MASK_ALL);
5237 /* If caller is interested in rc value from parse, set value. */
5241 exception_print (gdb_stderr, e);
5246 case NOT_FOUND_ERROR:
5247 /* If called to resolve pending breakpoint, just return
5252 exception_print (gdb_stderr, e);
5254 /* If pending breakpoint support is turned off, throw
5257 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5258 deprecated_throw_reason (RETURN_ERROR);
5260 /* If pending breakpoint support is auto query and the user
5261 selects no, then simply return the error code. */
5262 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5263 !nquery ("Make breakpoint pending on future shared library load? "))
5266 /* At this point, either the user was queried about setting
5267 a pending breakpoint and selected yes, or pending
5268 breakpoint behavior is on and thus a pending breakpoint
5269 is defaulted on behalf of the user. */
5270 copy_arg = xstrdup (addr_start);
5271 addr_string = ©_arg;
5273 sals.sals = &pending_sal;
5278 exception_print (gdb_stderr, e);
5286 /* Create a chain of things that always need to be cleaned up. */
5287 old_chain = make_cleanup (null_cleanup, 0);
5291 /* Make sure that all storage allocated to SALS gets freed. */
5292 make_cleanup (xfree, sals.sals);
5294 /* Cleanup the addr_string array but not its contents. */
5295 make_cleanup (xfree, addr_string);
5298 /* Allocate space for all the cond expressions. */
5299 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5300 make_cleanup (xfree, cond);
5302 /* Allocate space for all the cond strings. */
5303 cond_string = xcalloc (sals.nelts, sizeof (char **));
5304 make_cleanup (xfree, cond_string);
5306 /* ----------------------------- SNIP -----------------------------
5307 Anything added to the cleanup chain beyond this point is assumed
5308 to be part of a breakpoint. If the breakpoint create succeeds
5309 then the memory is not reclaimed. */
5310 breakpoint_chain = make_cleanup (null_cleanup, 0);
5312 /* Mark the contents of the addr_string for cleanup. These go on
5313 the breakpoint_chain and only occure if the breakpoint create
5315 for (i = 0; i < sals.nelts; i++)
5317 if (addr_string[i] != NULL)
5318 make_cleanup (xfree, addr_string[i]);
5321 /* Resolve all line numbers to PC's and verify that the addresses
5322 are ok for the target. */
5324 breakpoint_sals_to_pc (&sals, addr_start);
5326 /* Verify that condition can be parsed, before setting any
5327 breakpoints. Allocate a separate condition expression for each
5329 thread = -1; /* No specific thread yet */
5332 for (i = 0; i < sals.nelts; i++)
5339 char *cond_start = NULL;
5340 char *cond_end = NULL;
5341 while (*tok == ' ' || *tok == '\t')
5346 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5349 toklen = end_tok - tok;
5351 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5353 tok = cond_start = end_tok + 1;
5354 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc),
5356 make_cleanup (xfree, cond[i]);
5358 cond_string[i] = savestring (cond_start,
5359 cond_end - cond_start);
5360 make_cleanup (xfree, cond_string[i]);
5362 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5368 thread = strtol (tok, &tok, 0);
5370 error (_("Junk after thread keyword."));
5371 if (!valid_thread_id (thread))
5372 error (_("Unknown thread %d."), thread);
5375 error (_("Junk at end of arguments."));
5378 create_breakpoints (sals, addr_string, cond, cond_string,
5379 hardwareflag ? bp_hardware_breakpoint
5381 tempflag ? disp_del : disp_donttouch,
5382 thread, ignore_count, from_tty,
5387 struct symtab_and_line sal;
5388 struct breakpoint *b;
5393 make_cleanup (xfree, copy_arg);
5395 b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint
5397 set_breakpoint_count (breakpoint_count + 1);
5398 b->number = breakpoint_count;
5401 b->addr_string = *addr_string;
5402 b->cond_string = *cond_string;
5403 b->ignore_count = ignore_count;
5405 b->disposition = tempflag ? disp_del : disp_donttouch;
5406 b->from_tty = from_tty;
5412 warning (_("Multiple breakpoints were set.\n"
5413 "Use the \"delete\" command to delete unwanted breakpoints."));
5414 /* That's it. Discard the cleanups for data inserted into the
5416 discard_cleanups (breakpoint_chain);
5417 /* But cleanup everything else. */
5418 do_cleanups (old_chain);
5423 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5424 linenum or *address) with COND and IGNORE_COUNT. */
5426 struct captured_breakpoint_args
5437 do_captured_breakpoint (struct ui_out *uiout, void *data)
5439 struct captured_breakpoint_args *args = data;
5440 struct symtabs_and_lines sals;
5441 struct expression **cond;
5442 struct cleanup *old_chain;
5443 struct cleanup *breakpoint_chain = NULL;
5450 /* Parse the source and lines spec. Delay check that the expression
5451 didn't contain trailing garbage until after cleanups are in
5455 address_end = args->address;
5457 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5462 /* Create a chain of things at always need to be cleaned up. */
5463 old_chain = make_cleanup (null_cleanup, 0);
5465 /* Always have a addr_string array, even if it is empty. */
5466 make_cleanup (xfree, addr_string);
5468 /* Make sure that all storage allocated to SALS gets freed. */
5469 make_cleanup (xfree, sals.sals);
5471 /* Allocate space for all the cond expressions. */
5472 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5473 make_cleanup (xfree, cond);
5475 /* Allocate space for all the cond strings. */
5476 cond_string = xcalloc (sals.nelts, sizeof (char **));
5477 make_cleanup (xfree, cond_string);
5479 /* ----------------------------- SNIP -----------------------------
5480 Anything added to the cleanup chain beyond this point is assumed
5481 to be part of a breakpoint. If the breakpoint create goes
5482 through then that memory is not cleaned up. */
5483 breakpoint_chain = make_cleanup (null_cleanup, 0);
5485 /* Mark the contents of the addr_string for cleanup. These go on
5486 the breakpoint_chain and only occure if the breakpoint create
5488 for (i = 0; i < sals.nelts; i++)
5490 if (addr_string[i] != NULL)
5491 make_cleanup (xfree, addr_string[i]);
5494 /* Wait until now before checking for garbage at the end of the
5495 address. That way cleanups can take care of freeing any
5497 if (*address_end != '\0')
5498 error (_("Garbage %s following breakpoint address"), address_end);
5500 /* Resolve all line numbers to PC's. */
5501 breakpoint_sals_to_pc (&sals, args->address);
5503 /* Verify that conditions can be parsed, before setting any
5505 for (i = 0; i < sals.nelts; i++)
5507 if (args->condition != NULL)
5509 char *tok = args->condition;
5510 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5512 error (_("Garbage %s follows condition"), tok);
5513 make_cleanup (xfree, cond[i]);
5514 cond_string[i] = xstrdup (args->condition);
5518 create_breakpoints (sals, addr_string, cond, cond_string,
5519 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5520 args->tempflag ? disp_del : disp_donttouch,
5521 args->thread, args->ignore_count, 0/*from-tty*/,
5522 NULL/*pending_bp*/);
5524 /* That's it. Discard the cleanups for data inserted into the
5526 discard_cleanups (breakpoint_chain);
5527 /* But cleanup everything else. */
5528 do_cleanups (old_chain);
5533 gdb_breakpoint (char *address, char *condition,
5534 int hardwareflag, int tempflag,
5535 int thread, int ignore_count,
5536 char **error_message)
5538 struct captured_breakpoint_args args;
5539 args.address = address;
5540 args.condition = condition;
5541 args.hardwareflag = hardwareflag;
5542 args.tempflag = tempflag;
5543 args.thread = thread;
5544 args.ignore_count = ignore_count;
5545 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5546 error_message, RETURN_MASK_ALL) < 0)
5553 /* Helper function for break_command_1 and disassemble_command. */
5556 resolve_sal_pc (struct symtab_and_line *sal)
5560 if (sal->pc == 0 && sal->symtab != NULL)
5562 if (!find_line_pc (sal->symtab, sal->line, &pc))
5563 error (_("No line %d in file \"%s\"."),
5564 sal->line, sal->symtab->filename);
5568 if (sal->section == 0 && sal->symtab != NULL)
5570 struct blockvector *bv;
5575 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5578 b = BLOCKVECTOR_BLOCK (bv, index);
5579 sym = block_function (b);
5582 fixup_symbol_section (sym, sal->symtab->objfile);
5583 sal->section = SYMBOL_BFD_SECTION (sym);
5587 /* It really is worthwhile to have the section, so we'll just
5588 have to look harder. This case can be executed if we have
5589 line numbers but no functions (as can happen in assembly
5592 struct minimal_symbol *msym;
5594 msym = lookup_minimal_symbol_by_pc (sal->pc);
5596 sal->section = SYMBOL_BFD_SECTION (msym);
5603 break_command (char *arg, int from_tty)
5605 break_command_1 (arg, 0, from_tty, NULL);
5609 tbreak_command (char *arg, int from_tty)
5611 break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL);
5615 hbreak_command (char *arg, int from_tty)
5617 break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL);
5621 thbreak_command (char *arg, int from_tty)
5623 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL);
5627 stop_command (char *arg, int from_tty)
5629 printf_filtered (_("Specify the type of breakpoint to set.\n\
5630 Usage: stop in <function | address>\n\
5631 stop at <line>\n"));
5635 stopin_command (char *arg, int from_tty)
5639 if (arg == (char *) NULL)
5641 else if (*arg != '*')
5646 /* look for a ':'. If this is a line number specification, then
5647 say it is bad, otherwise, it should be an address or
5648 function/method name */
5649 while (*argptr && !hasColon)
5651 hasColon = (*argptr == ':');
5656 badInput = (*argptr != ':'); /* Not a class::method */
5658 badInput = isdigit (*arg); /* a simple line number */
5662 printf_filtered (_("Usage: stop in <function | address>\n"));
5664 break_command_1 (arg, 0, from_tty, NULL);
5668 stopat_command (char *arg, int from_tty)
5672 if (arg == (char *) NULL || *arg == '*') /* no line number */
5679 /* look for a ':'. If there is a '::' then get out, otherwise
5680 it is probably a line number. */
5681 while (*argptr && !hasColon)
5683 hasColon = (*argptr == ':');
5688 badInput = (*argptr == ':'); /* we have class::method */
5690 badInput = !isdigit (*arg); /* not a line number */
5694 printf_filtered (_("Usage: stop at <line>\n"));
5696 break_command_1 (arg, 0, from_tty, NULL);
5699 /* accessflag: hw_write: watch write,
5700 hw_read: watch read,
5701 hw_access: watch access (read or write) */
5703 watch_command_1 (char *arg, int accessflag, int from_tty)
5705 struct breakpoint *b;
5706 struct symtab_and_line sal;
5707 struct expression *exp;
5708 struct block *exp_valid_block;
5709 struct value *val, *mark;
5710 struct frame_info *frame;
5711 struct frame_info *prev_frame = NULL;
5712 char *exp_start = NULL;
5713 char *exp_end = NULL;
5714 char *tok, *end_tok;
5716 char *cond_start = NULL;
5717 char *cond_end = NULL;
5718 struct expression *cond = NULL;
5719 int i, other_type_used, target_resources_ok = 0;
5720 enum bptype bp_type;
5723 init_sal (&sal); /* initialize to zeroes */
5725 /* Parse arguments. */
5726 innermost_block = NULL;
5728 exp = parse_exp_1 (&arg, 0, 0);
5730 exp_valid_block = innermost_block;
5731 mark = value_mark ();
5732 val = evaluate_expression (exp);
5733 release_value (val);
5734 if (value_lazy (val))
5735 value_fetch_lazy (val);
5738 while (*tok == ' ' || *tok == '\t')
5742 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5745 toklen = end_tok - tok;
5746 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5748 tok = cond_start = end_tok + 1;
5749 cond = parse_exp_1 (&tok, 0, 0);
5753 error (_("Junk at end of command."));
5755 if (accessflag == hw_read)
5756 bp_type = bp_read_watchpoint;
5757 else if (accessflag == hw_access)
5758 bp_type = bp_access_watchpoint;
5760 bp_type = bp_hardware_watchpoint;
5762 mem_cnt = can_use_hardware_watchpoint (val);
5763 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5764 error (_("Expression cannot be implemented with read/access watchpoint."));
5767 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5768 target_resources_ok =
5769 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5771 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5772 error (_("Target does not support this type of hardware watchpoint."));
5774 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5775 error (_("Target can only support one kind of HW watchpoint at a time."));
5778 #if defined(HPUXHPPA)
5779 /* On HP-UX if you set a h/w
5780 watchpoint before the "run" command, the inferior dies with a e.g.,
5781 SIGILL once you start it. I initially believed this was due to a
5782 bad interaction between page protection traps and the initial
5783 startup sequence by the dynamic linker.
5785 However, I tried avoiding that by having HP-UX's implementation of
5786 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5787 yet, which forced slow watches before a "run" or "attach", and it
5788 still fails somewhere in the startup code.
5790 Until I figure out what's happening, I'm disallowing watches altogether
5791 before the "run" or "attach" command. We'll tell the user they must
5792 set watches after getting the program started. */
5793 if (!target_has_execution)
5795 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5798 #endif /* HPUXHPPA */
5800 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5801 watchpoint could not be set. */
5802 if (!mem_cnt || target_resources_ok <= 0)
5803 bp_type = bp_watchpoint;
5805 /* Now set up the breakpoint. */
5806 b = set_raw_breakpoint (sal, bp_type);
5807 set_breakpoint_count (breakpoint_count + 1);
5808 b->number = breakpoint_count;
5809 b->disposition = disp_donttouch;
5811 b->exp_valid_block = exp_valid_block;
5812 b->exp_string = savestring (exp_start, exp_end - exp_start);
5816 b->cond_string = savestring (cond_start, cond_end - cond_start);
5820 frame = block_innermost_frame (exp_valid_block);
5823 prev_frame = get_prev_frame (frame);
5824 b->watchpoint_frame = get_frame_id (frame);
5828 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5831 /* If the expression is "local", then set up a "watchpoint scope"
5832 breakpoint at the point where we've left the scope of the watchpoint
5834 if (innermost_block)
5838 struct breakpoint *scope_breakpoint;
5839 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5840 bp_watchpoint_scope);
5842 scope_breakpoint->enable_state = bp_enabled;
5844 /* Automatically delete the breakpoint when it hits. */
5845 scope_breakpoint->disposition = disp_del;
5847 /* Only break in the proper frame (help with recursion). */
5848 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5850 /* Set the address at which we will stop. */
5851 scope_breakpoint->loc->requested_address
5852 = get_frame_pc (prev_frame);
5853 scope_breakpoint->loc->address
5854 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5855 scope_breakpoint->type);
5857 /* The scope breakpoint is related to the watchpoint. We
5858 will need to act on them together. */
5859 b->related_breakpoint = scope_breakpoint;
5862 value_free_to_mark (mark);
5866 /* Return count of locations need to be watched and can be handled
5867 in hardware. If the watchpoint can not be handled
5868 in hardware return zero. */
5871 can_use_hardware_watchpoint (struct value *v)
5873 int found_memory_cnt = 0;
5874 struct value *head = v;
5876 /* Did the user specifically forbid us to use hardware watchpoints? */
5877 if (!can_use_hw_watchpoints)
5880 /* Make sure that the value of the expression depends only upon
5881 memory contents, and values computed from them within GDB. If we
5882 find any register references or function calls, we can't use a
5883 hardware watchpoint.
5885 The idea here is that evaluating an expression generates a series
5886 of values, one holding the value of every subexpression. (The
5887 expression a*b+c has five subexpressions: a, b, a*b, c, and
5888 a*b+c.) GDB's values hold almost enough information to establish
5889 the criteria given above --- they identify memory lvalues,
5890 register lvalues, computed values, etcetera. So we can evaluate
5891 the expression, and then scan the chain of values that leaves
5892 behind to decide whether we can detect any possible change to the
5893 expression's final value using only hardware watchpoints.
5895 However, I don't think that the values returned by inferior
5896 function calls are special in any way. So this function may not
5897 notice that an expression involving an inferior function call
5898 can't be watched with hardware watchpoints. FIXME. */
5899 for (; v; v = value_next (v))
5901 if (VALUE_LVAL (v) == lval_memory)
5904 /* A lazy memory lvalue is one that GDB never needed to fetch;
5905 we either just used its address (e.g., `a' in `a.b') or
5906 we never needed it at all (e.g., `a' in `a,b'). */
5910 /* Ahh, memory we actually used! Check if we can cover
5911 it with hardware watchpoints. */
5912 struct type *vtype = check_typedef (value_type (v));
5914 /* We only watch structs and arrays if user asked for it
5915 explicitly, never if they just happen to appear in a
5916 middle of some value chain. */
5918 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5919 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5921 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
5922 int len = TYPE_LENGTH (value_type (v));
5924 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5931 else if (VALUE_LVAL (v) != not_lval
5932 && deprecated_value_modifiable (v) == 0)
5933 return 0; /* ??? What does this represent? */
5934 else if (VALUE_LVAL (v) == lval_register)
5935 return 0; /* cannot watch a register with a HW watchpoint */
5938 /* The expression itself looks suitable for using a hardware
5939 watchpoint, but give the target machine a chance to reject it. */
5940 return found_memory_cnt;
5944 watch_command_wrapper (char *arg, int from_tty)
5946 watch_command (arg, from_tty);
5950 watch_command (char *arg, int from_tty)
5952 watch_command_1 (arg, hw_write, from_tty);
5956 rwatch_command_wrapper (char *arg, int from_tty)
5958 rwatch_command (arg, from_tty);
5962 rwatch_command (char *arg, int from_tty)
5964 watch_command_1 (arg, hw_read, from_tty);
5968 awatch_command_wrapper (char *arg, int from_tty)
5970 awatch_command (arg, from_tty);
5974 awatch_command (char *arg, int from_tty)
5976 watch_command_1 (arg, hw_access, from_tty);
5980 /* Helper routines for the until_command routine in infcmd.c. Here
5981 because it uses the mechanisms of breakpoints. */
5983 /* This function is called by fetch_inferior_event via the
5984 cmd_continuation pointer, to complete the until command. It takes
5985 care of cleaning up the temporary breakpoints set up by the until
5988 until_break_command_continuation (struct continuation_arg *arg)
5990 struct cleanup *cleanups;
5992 cleanups = (struct cleanup *) arg->data.pointer;
5993 do_exec_cleanups (cleanups);
5997 until_break_command (char *arg, int from_tty, int anywhere)
5999 struct symtabs_and_lines sals;
6000 struct symtab_and_line sal;
6001 struct frame_info *frame = get_selected_frame (NULL);
6002 struct frame_info *prev_frame = get_prev_frame (frame);
6003 struct breakpoint *breakpoint;
6004 struct cleanup *old_chain;
6005 struct continuation_arg *arg1;
6008 clear_proceed_status ();
6010 /* Set a breakpoint where the user wants it and at return from
6013 if (default_breakpoint_valid)
6014 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6015 default_breakpoint_line, (char ***) NULL, NULL);
6017 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6018 0, (char ***) NULL, NULL);
6020 if (sals.nelts != 1)
6021 error (_("Couldn't get information on specified line."));
6024 xfree (sals.sals); /* malloc'd, so freed */
6027 error (_("Junk at end of arguments."));
6029 resolve_sal_pc (&sal);
6032 /* If the user told us to continue until a specified location,
6033 we don't specify a frame at which we need to stop. */
6034 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6036 /* Otherwise, specify the current frame, because we want to stop only
6037 at the very same frame. */
6038 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6041 if (!target_can_async_p ())
6042 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6044 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6046 /* If we are running asynchronously, and the target supports async
6047 execution, we are not waiting for the target to stop, in the call
6048 tp proceed, below. This means that we cannot delete the
6049 brekpoints until the target has actually stopped. The only place
6050 where we get a chance to do that is in fetch_inferior_event, so
6051 we must set things up for that. */
6053 if (target_can_async_p ())
6055 /* In this case the arg for the continuation is just the point
6056 in the exec_cleanups chain from where to start doing
6057 cleanups, because all the continuation does is the cleanups in
6058 the exec_cleanup_chain. */
6060 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6062 arg1->data.pointer = old_chain;
6064 add_continuation (until_break_command_continuation, arg1);
6067 /* Keep within the current frame, or in frames called by the current
6071 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6072 sal.pc = get_frame_pc (prev_frame);
6073 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6075 if (!target_can_async_p ())
6076 make_cleanup_delete_breakpoint (breakpoint);
6078 make_exec_cleanup_delete_breakpoint (breakpoint);
6081 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6082 /* Do the cleanups now, anly if we are not running asynchronously,
6083 of if we are, but the target is still synchronous. */
6084 if (!target_can_async_p ())
6085 do_cleanups (old_chain);
6089 ep_skip_leading_whitespace (char **s)
6091 if ((s == NULL) || (*s == NULL))
6093 while (isspace (**s))
6097 /* This function examines a string, and attempts to find a token
6098 that might be an event name in the leading characters. If a
6099 possible match is found, a pointer to the last character of
6100 the token is returned. Else, NULL is returned. */
6103 ep_find_event_name_end (char *arg)
6106 char *event_name_end = NULL;
6108 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6112 /* We break out of the loop when we find a token delimiter.
6113 Basically, we're looking for alphanumerics and underscores;
6114 anything else delimites the token. */
6117 if (!isalnum (*s) && (*s != '_'))
6123 return event_name_end;
6127 /* This function attempts to parse an optional "if <cond>" clause
6128 from the arg string. If one is not found, it returns NULL.
6130 Else, it returns a pointer to the condition string. (It does not
6131 attempt to evaluate the string against a particular block.) And,
6132 it updates arg to point to the first character following the parsed
6133 if clause in the arg string. */
6136 ep_parse_optional_if_clause (char **arg)
6140 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6143 /* Skip the "if" keyword. */
6146 /* Skip any extra leading whitespace, and record the start of the
6147 condition string. */
6148 ep_skip_leading_whitespace (arg);
6151 /* Assume that the condition occupies the remainder of the arg string. */
6152 (*arg) += strlen (cond_string);
6157 /* This function attempts to parse an optional filename from the arg
6158 string. If one is not found, it returns NULL.
6160 Else, it returns a pointer to the parsed filename. (This function
6161 makes no attempt to verify that a file of that name exists, or is
6162 accessible.) And, it updates arg to point to the first character
6163 following the parsed filename in the arg string.
6165 Note that clients needing to preserve the returned filename for
6166 future access should copy it to their own buffers. */
6168 ep_parse_optional_filename (char **arg)
6170 static char filename[1024];
6175 if ((*arg_p == '\0') || isspace (*arg_p))
6193 /* Commands to deal with catching events, such as signals, exceptions,
6194 process start/exit, etc. */
6198 catch_fork, catch_vfork
6203 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6206 char *cond_string = NULL;
6208 ep_skip_leading_whitespace (&arg);
6210 /* The allowed syntax is:
6212 catch [v]fork if <cond>
6214 First, check if there's an if clause. */
6215 cond_string = ep_parse_optional_if_clause (&arg);
6217 if ((*arg != '\0') && !isspace (*arg))
6218 error (_("Junk at end of arguments."));
6220 /* If this target supports it, create a fork or vfork catchpoint
6221 and enable reporting of such events. */
6225 create_fork_event_catchpoint (tempflag, cond_string);
6228 create_vfork_event_catchpoint (tempflag, cond_string);
6231 error (_("unsupported or unknown fork kind; cannot catch it"));
6237 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6239 char *cond_string = NULL;
6241 ep_skip_leading_whitespace (&arg);
6243 /* The allowed syntax is:
6245 catch exec if <cond>
6247 First, check if there's an if clause. */
6248 cond_string = ep_parse_optional_if_clause (&arg);
6250 if ((*arg != '\0') && !isspace (*arg))
6251 error (_("Junk at end of arguments."));
6253 /* If this target supports it, create an exec catchpoint
6254 and enable reporting of such events. */
6255 create_exec_event_catchpoint (tempflag, cond_string);
6259 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6261 char *dll_pathname = NULL;
6262 char *cond_string = NULL;
6264 ep_skip_leading_whitespace (&arg);
6266 /* The allowed syntax is:
6268 catch load if <cond>
6269 catch load <filename>
6270 catch load <filename> if <cond>
6272 The user is not allowed to specify the <filename> after an
6275 We'll ignore the pathological case of a file named "if".
6277 First, check if there's an if clause. If so, then there
6278 cannot be a filename. */
6279 cond_string = ep_parse_optional_if_clause (&arg);
6281 /* If there was an if clause, then there cannot be a filename.
6282 Else, there might be a filename and an if clause. */
6283 if (cond_string == NULL)
6285 dll_pathname = ep_parse_optional_filename (&arg);
6286 ep_skip_leading_whitespace (&arg);
6287 cond_string = ep_parse_optional_if_clause (&arg);
6290 if ((*arg != '\0') && !isspace (*arg))
6291 error (_("Junk at end of arguments."));
6293 /* Create a load breakpoint that only triggers when a load of
6294 the specified dll (or any dll, if no pathname was specified)
6296 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6297 dll_pathname, cond_string);
6301 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6303 char *dll_pathname = NULL;
6304 char *cond_string = NULL;
6306 ep_skip_leading_whitespace (&arg);
6308 /* The allowed syntax is:
6310 catch unload if <cond>
6311 catch unload <filename>
6312 catch unload <filename> if <cond>
6314 The user is not allowed to specify the <filename> after an
6317 We'll ignore the pathological case of a file named "if".
6319 First, check if there's an if clause. If so, then there
6320 cannot be a filename. */
6321 cond_string = ep_parse_optional_if_clause (&arg);
6323 /* If there was an if clause, then there cannot be a filename.
6324 Else, there might be a filename and an if clause. */
6325 if (cond_string == NULL)
6327 dll_pathname = ep_parse_optional_filename (&arg);
6328 ep_skip_leading_whitespace (&arg);
6329 cond_string = ep_parse_optional_if_clause (&arg);
6332 if ((*arg != '\0') && !isspace (*arg))
6333 error (_("Junk at end of arguments."));
6335 /* Create an unload breakpoint that only triggers when an unload of
6336 the specified dll (or any dll, if no pathname was specified)
6338 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6339 dll_pathname, cond_string);
6342 /* Commands to deal with catching exceptions. */
6344 /* Set a breakpoint at the specified callback routine for an
6345 exception event callback */
6348 create_exception_catchpoint (int tempflag, char *cond_string,
6349 enum exception_event_kind ex_event,
6350 struct symtab_and_line *sal)
6352 struct breakpoint *b;
6353 int thread = -1; /* All threads. */
6356 if (!sal) /* no exception support? */
6361 case EX_EVENT_THROW:
6362 bptype = bp_catch_throw;
6364 case EX_EVENT_CATCH:
6365 bptype = bp_catch_catch;
6367 default: /* error condition */
6368 error (_("Internal error -- invalid catchpoint kind"));
6371 b = set_raw_breakpoint (*sal, bptype);
6372 set_breakpoint_count (breakpoint_count + 1);
6373 b->number = breakpoint_count;
6375 b->cond_string = (cond_string == NULL) ?
6376 NULL : savestring (cond_string, strlen (cond_string));
6378 b->addr_string = NULL;
6379 b->enable_state = bp_enabled;
6380 b->disposition = tempflag ? disp_del : disp_donttouch;
6384 static enum print_stop_action
6385 print_exception_catchpoint (struct breakpoint *b)
6387 annotate_catchpoint (b->number);
6389 if (strstr (b->addr_string, "throw") != NULL)
6390 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6393 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6396 return PRINT_SRC_AND_LOC;
6400 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6405 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6408 *last_addr = b->loc->address;
6409 if (strstr (b->addr_string, "throw") != NULL)
6410 ui_out_field_string (uiout, "what", "exception throw");
6412 ui_out_field_string (uiout, "what", "exception catch");
6416 print_mention_exception_catchpoint (struct breakpoint *b)
6418 if (strstr (b->addr_string, "throw") != NULL)
6419 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6421 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6424 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6425 print_exception_catchpoint,
6426 print_one_exception_catchpoint,
6427 print_mention_exception_catchpoint
6431 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6432 enum exception_event_kind ex_event, int from_tty)
6434 char *trigger_func_name, *nameptr;
6435 struct symtabs_and_lines sals;
6436 struct breakpoint *b;
6438 if (ex_event == EX_EVENT_CATCH)
6439 trigger_func_name = xstrdup ("__cxa_begin_catch");
6441 trigger_func_name = xstrdup ("__cxa_throw");
6443 nameptr = trigger_func_name;
6444 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6445 if (sals.nelts == 0)
6447 xfree (trigger_func_name);
6451 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6452 set_breakpoint_count (breakpoint_count + 1);
6453 b->number = breakpoint_count;
6455 b->cond_string = (cond_string == NULL) ?
6456 NULL : savestring (cond_string, strlen (cond_string));
6458 b->addr_string = trigger_func_name;
6459 b->enable_state = bp_enabled;
6460 b->disposition = tempflag ? disp_del : disp_donttouch;
6461 b->ops = &gnu_v3_exception_catchpoint_ops;
6468 /* Deal with "catch catch" and "catch throw" commands */
6471 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6472 int tempflag, int from_tty)
6474 char *cond_string = NULL;
6475 struct symtab_and_line *sal = NULL;
6477 ep_skip_leading_whitespace (&arg);
6479 cond_string = ep_parse_optional_if_clause (&arg);
6481 if ((*arg != '\0') && !isspace (*arg))
6482 error (_("Junk at end of arguments."));
6484 if ((ex_event != EX_EVENT_THROW) &&
6485 (ex_event != EX_EVENT_CATCH))
6486 error (_("Unsupported or unknown exception event; cannot catch it"));
6488 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6491 /* See if we can find a callback routine */
6492 sal = target_enable_exception_callback (ex_event, 1);
6496 /* We have callbacks from the runtime system for exceptions.
6497 Set a breakpoint on the sal found, if no errors */
6498 if (sal != (struct symtab_and_line *) -1)
6499 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6501 return; /* something went wrong with setting up callbacks */
6504 warning (_("Unsupported with this platform/compiler combination."));
6507 /* Create a breakpoint struct for Ada exception catchpoints. */
6510 create_ada_exception_breakpoint (struct symtab_and_line sal,
6514 struct expression *cond,
6515 struct breakpoint_ops *ops,
6519 struct breakpoint *b;
6523 describe_other_breakpoints (sal.pc, sal.section, -1);
6524 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6525 version for exception catchpoints, because two catchpoints
6526 used for different exception names will use the same address.
6527 In this case, a "breakpoint ... also set at..." warning is
6528 unproductive. Besides. the warning phrasing is also a bit
6529 inapropriate, we should use the word catchpoint, and tell
6530 the user what type of catchpoint it is. The above is good
6531 enough for now, though. */
6534 b = set_raw_breakpoint (sal, bp_breakpoint);
6535 set_breakpoint_count (breakpoint_count + 1);
6537 b->enable_state = bp_enabled;
6538 b->disposition = tempflag ? disp_del : disp_donttouch;
6539 b->number = breakpoint_count;
6540 b->ignore_count = 0;
6542 b->addr_string = addr_string;
6543 b->language = language_ada;
6544 b->cond_string = cond_string;
6545 b->exp_string = exp_string;
6548 b->from_tty = from_tty;
6553 /* Implement the "catch exception" command. */
6556 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6558 struct symtab_and_line sal;
6560 char *addr_string = NULL;
6561 char *exp_string = NULL;
6562 char *cond_string = NULL;
6563 struct expression *cond = NULL;
6564 struct breakpoint_ops *ops = NULL;
6566 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6567 &cond_string, &cond, &ops);
6568 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6569 cond_string, cond, ops, tempflag,
6573 /* Implement the "catch assert" command. */
6576 catch_assert_command (char *arg, int tempflag, int from_tty)
6578 struct symtab_and_line sal;
6579 char *addr_string = NULL;
6580 struct breakpoint_ops *ops = NULL;
6582 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6583 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6584 tempflag, from_tty);
6587 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6588 inside a catch_errors */
6591 cover_target_enable_exception_callback (void *arg)
6593 args_for_catchpoint_enable *args = arg;
6594 struct symtab_and_line *sal;
6595 sal = target_enable_exception_callback (args->kind, args->enable_p);
6598 else if (sal == (struct symtab_and_line *) -1)
6601 return 1; /*is valid */
6605 catch_command_1 (char *arg, int tempflag, int from_tty)
6608 /* The first argument may be an event name, such as "start" or "load".
6609 If so, then handle it as such. If it doesn't match an event name,
6610 then attempt to interpret it as an exception name. (This latter is
6611 the v4.16-and-earlier GDB meaning of the "catch" command.)
6613 First, try to find the bounds of what might be an event name. */
6614 char *arg1_start = arg;
6618 if (arg1_start == NULL)
6620 /* Old behaviour was to use pre-v-4.16 syntax */
6621 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6623 /* Now, this is not allowed */
6624 error (_("Catch requires an event name."));
6627 arg1_end = ep_find_event_name_end (arg1_start);
6628 if (arg1_end == NULL)
6629 error (_("catch requires an event"));
6630 arg1_length = arg1_end + 1 - arg1_start;
6632 /* Try to match what we found against known event names. */
6633 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6635 error (_("Catch of signal not yet implemented"));
6637 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6639 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6640 tempflag, from_tty);
6642 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6644 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6645 tempflag, from_tty);
6647 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6649 error (_("Catch of thread_start not yet implemented"));
6651 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6653 error (_("Catch of thread_exit not yet implemented"));
6655 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6657 error (_("Catch of thread_join not yet implemented"));
6659 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6661 error (_("Catch of start not yet implemented"));
6663 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6665 error (_("Catch of exit not yet implemented"));
6667 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6669 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6671 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6673 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6675 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6677 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6679 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6681 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6683 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6685 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6687 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6689 error (_("Catch of stop not yet implemented"));
6691 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6693 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6696 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6698 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6701 /* This doesn't appear to be an event name */
6705 /* Pre-v.4.16 behaviour was to treat the argument
6706 as the name of an exception */
6707 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6708 /* Now this is not allowed */
6709 error (_("Unknown event kind specified for catch"));
6714 /* Used by the gui, could be made a worker for other things. */
6717 set_breakpoint_sal (struct symtab_and_line sal)
6719 struct breakpoint *b;
6720 b = set_raw_breakpoint (sal, bp_breakpoint);
6721 set_breakpoint_count (breakpoint_count + 1);
6722 b->number = breakpoint_count;
6729 catch_command (char *arg, int from_tty)
6731 catch_command_1 (arg, 0, from_tty);
6736 tcatch_command (char *arg, int from_tty)
6738 catch_command_1 (arg, 1, from_tty);
6741 /* Delete breakpoints by address or line. */
6744 clear_command (char *arg, int from_tty)
6746 struct breakpoint *b, *tmp, *prev, *found;
6748 struct symtabs_and_lines sals;
6749 struct symtab_and_line sal;
6754 sals = decode_line_spec (arg, 1);
6759 sals.sals = (struct symtab_and_line *)
6760 xmalloc (sizeof (struct symtab_and_line));
6761 make_cleanup (xfree, sals.sals);
6762 init_sal (&sal); /* initialize to zeroes */
6763 sal.line = default_breakpoint_line;
6764 sal.symtab = default_breakpoint_symtab;
6765 sal.pc = default_breakpoint_address;
6766 if (sal.symtab == 0)
6767 error (_("No source file specified."));
6775 /* For each line spec given, delete bps which correspond
6776 to it. Do it in two passes, solely to preserve the current
6777 behavior that from_tty is forced true if we delete more than
6781 for (i = 0; i < sals.nelts; i++)
6783 /* If exact pc given, clear bpts at that pc.
6784 If line given (pc == 0), clear all bpts on specified line.
6785 If defaulting, clear all bpts on default line
6788 defaulting sal.pc != 0 tests to do
6793 1 0 <can't happen> */
6798 /* Find all matching breakpoints, remove them from the
6799 breakpoint chain, and add them to the 'found' chain. */
6800 ALL_BREAKPOINTS_SAFE (b, tmp)
6802 /* Are we going to delete b? */
6803 if (b->type != bp_none
6804 && b->type != bp_watchpoint
6805 && b->type != bp_hardware_watchpoint
6806 && b->type != bp_read_watchpoint
6807 && b->type != bp_access_watchpoint
6808 /* Not if b is a watchpoint of any sort... */
6809 && (((sal.pc && (b->loc->address == sal.pc))
6810 && (!section_is_overlay (b->loc->section)
6811 || b->loc->section == sal.section))
6812 /* Yes, if sal.pc matches b (modulo overlays). */
6813 || ((default_match || (0 == sal.pc))
6814 && b->source_file != NULL
6815 && sal.symtab != NULL
6816 && strcmp (b->source_file, sal.symtab->filename) == 0
6817 && b->line_number == sal.line)))
6818 /* Yes, if sal source file and line matches b. */
6820 /* Remove it from breakpoint_chain... */
6821 if (b == breakpoint_chain)
6823 /* b is at the head of the list */
6824 breakpoint_chain = b->next;
6828 prev->next = b->next;
6830 /* And add it to 'found' chain. */
6836 /* Keep b, and keep a pointer to it. */
6841 /* Now go thru the 'found' chain and delete them. */
6845 error (_("No breakpoint at %s."), arg);
6847 error (_("No breakpoint at this line."));
6851 from_tty = 1; /* Always report if deleted more than one */
6855 printf_unfiltered (_("Deleted breakpoint "));
6857 printf_unfiltered (_("Deleted breakpoints "));
6859 breakpoints_changed ();
6863 printf_unfiltered ("%d ", found->number);
6865 delete_breakpoint (found);
6869 putchar_unfiltered ('\n');
6872 /* Delete breakpoint in BS if they are `delete' breakpoints and
6873 all breakpoints that are marked for deletion, whether hit or not.
6874 This is called after any breakpoint is hit, or after errors. */
6877 breakpoint_auto_delete (bpstat bs)
6879 struct breakpoint *b, *temp;
6881 for (; bs; bs = bs->next)
6882 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6884 delete_breakpoint (bs->breakpoint_at);
6886 ALL_BREAKPOINTS_SAFE (b, temp)
6888 if (b->disposition == disp_del_at_next_stop)
6889 delete_breakpoint (b);
6893 /* Delete a breakpoint and clean up all traces of it in the data
6897 delete_breakpoint (struct breakpoint *bpt)
6899 struct breakpoint *b;
6901 struct bp_location *loc;
6903 gdb_assert (bpt != NULL);
6905 /* Has this bp already been deleted? This can happen because multiple
6906 lists can hold pointers to bp's. bpstat lists are especial culprits.
6908 One example of this happening is a watchpoint's scope bp. When the
6909 scope bp triggers, we notice that the watchpoint is out of scope, and
6910 delete it. We also delete its scope bp. But the scope bp is marked
6911 "auto-deleting", and is already on a bpstat. That bpstat is then
6912 checked for auto-deleting bp's, which are deleted.
6914 A real solution to this problem might involve reference counts in bp's,
6915 and/or giving them pointers back to their referencing bpstat's, and
6916 teaching delete_breakpoint to only free a bp's storage when no more
6917 references were extent. A cheaper bandaid was chosen. */
6918 if (bpt->type == bp_none)
6921 if (deprecated_delete_breakpoint_hook)
6922 deprecated_delete_breakpoint_hook (bpt);
6923 breakpoint_delete_event (bpt->number);
6925 if (bpt->loc->inserted)
6926 remove_breakpoint (bpt->loc, mark_inserted);
6928 free_valchain (bpt->loc);
6930 if (breakpoint_chain == bpt)
6931 breakpoint_chain = bpt->next;
6933 if (bp_location_chain == bpt->loc)
6934 bp_location_chain = bpt->loc->next;
6936 /* If we have callback-style exception catchpoints, don't go through
6937 the adjustments to the C++ runtime library etc. if the inferior
6938 isn't actually running. target_enable_exception_callback for a
6939 null target ops vector gives an undesirable error message, so we
6940 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6941 exceptions are supported in this way, it's OK for now. FIXME */
6942 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6944 /* Format possible error msg */
6945 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6947 struct cleanup *cleanups = make_cleanup (xfree, message);
6948 args_for_catchpoint_enable args;
6949 args.kind = bpt->type == bp_catch_catch ?
6950 EX_EVENT_CATCH : EX_EVENT_THROW;
6952 catch_errors (cover_target_enable_exception_callback, &args,
6953 message, RETURN_MASK_ALL);
6954 do_cleanups (cleanups);
6961 b->next = bpt->next;
6965 ALL_BP_LOCATIONS (loc)
6966 if (loc->next == bpt->loc)
6968 loc->next = bpt->loc->next;
6972 check_duplicates (bpt);
6973 /* If this breakpoint was inserted, and there is another breakpoint
6974 at the same address, we need to insert the other breakpoint. */
6975 if (bpt->loc->inserted
6976 && bpt->type != bp_hardware_watchpoint
6977 && bpt->type != bp_read_watchpoint
6978 && bpt->type != bp_access_watchpoint
6979 && bpt->type != bp_catch_fork
6980 && bpt->type != bp_catch_vfork
6981 && bpt->type != bp_catch_exec)
6984 if (b->loc->address == bpt->loc->address
6985 && b->loc->section == bpt->loc->section
6986 && !b->loc->duplicate
6987 && b->enable_state != bp_disabled
6988 && b->enable_state != bp_shlib_disabled
6990 && b->enable_state != bp_call_disabled)
6994 /* We should never reach this point if there is a permanent
6995 breakpoint at the same address as the one being deleted.
6996 If there is a permanent breakpoint somewhere, it should
6997 always be the only one inserted. */
6998 if (b->enable_state == bp_permanent)
6999 internal_error (__FILE__, __LINE__,
7000 _("another breakpoint was inserted on top of "
7001 "a permanent breakpoint"));
7003 memset (&b->loc->target_info, 0, sizeof (b->loc->target_info));
7004 b->loc->target_info.placed_address = b->loc->address;
7005 if (b->type == bp_hardware_breakpoint)
7006 val = target_insert_hw_breakpoint (&b->loc->target_info);
7008 val = target_insert_breakpoint (&b->loc->target_info);
7010 /* If there was an error in the insert, print a message, then stop execution. */
7013 struct ui_file *tmp_error_stream = mem_fileopen ();
7014 make_cleanup_ui_file_delete (tmp_error_stream);
7017 if (b->type == bp_hardware_breakpoint)
7019 fprintf_unfiltered (tmp_error_stream,
7020 "Cannot insert hardware breakpoint %d.\n"
7021 "You may have requested too many hardware breakpoints.\n",
7026 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
7027 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
7028 deprecated_print_address_numeric (b->loc->address, 1, tmp_error_stream);
7029 fprintf_filtered (tmp_error_stream, ": %s.\n",
7030 safe_strerror (val));
7033 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
7034 target_terminal_ours_for_output ();
7035 error_stream(tmp_error_stream);
7038 b->loc->inserted = 1;
7042 free_command_lines (&bpt->commands);
7045 if (bpt->cond_string != NULL)
7046 xfree (bpt->cond_string);
7047 if (bpt->addr_string != NULL)
7048 xfree (bpt->addr_string);
7049 if (bpt->exp != NULL)
7051 if (bpt->exp_string != NULL)
7052 xfree (bpt->exp_string);
7053 if (bpt->val != NULL)
7054 value_free (bpt->val);
7055 if (bpt->source_file != NULL)
7056 xfree (bpt->source_file);
7057 if (bpt->dll_pathname != NULL)
7058 xfree (bpt->dll_pathname);
7059 if (bpt->triggered_dll_pathname != NULL)
7060 xfree (bpt->triggered_dll_pathname);
7061 if (bpt->exec_pathname != NULL)
7062 xfree (bpt->exec_pathname);
7064 /* Be sure no bpstat's are pointing at it after it's been freed. */
7065 /* FIXME, how can we find all bpstat's?
7066 We just check stop_bpstat for now. */
7067 for (bs = stop_bpstat; bs; bs = bs->next)
7068 if (bs->breakpoint_at == bpt)
7070 bs->breakpoint_at = NULL;
7072 /* bs->commands will be freed later. */
7074 /* On the chance that someone will soon try again to delete this same
7075 bp, we mark it as deleted before freeing its storage. */
7076 bpt->type = bp_none;
7083 do_delete_breakpoint_cleanup (void *b)
7085 delete_breakpoint (b);
7089 make_cleanup_delete_breakpoint (struct breakpoint *b)
7091 return make_cleanup (do_delete_breakpoint_cleanup, b);
7095 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7097 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7101 delete_command (char *arg, int from_tty)
7103 struct breakpoint *b, *temp;
7109 int breaks_to_delete = 0;
7111 /* Delete all breakpoints if no argument.
7112 Do not delete internal or call-dummy breakpoints, these
7113 have to be deleted with an explicit breakpoint number argument. */
7116 if (b->type != bp_call_dummy &&
7117 b->type != bp_shlib_event &&
7118 b->type != bp_thread_event &&
7119 b->type != bp_overlay_event &&
7122 breaks_to_delete = 1;
7127 /* Ask user only if there are some breakpoints to delete. */
7129 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7131 ALL_BREAKPOINTS_SAFE (b, temp)
7133 if (b->type != bp_call_dummy &&
7134 b->type != bp_shlib_event &&
7135 b->type != bp_thread_event &&
7136 b->type != bp_overlay_event &&
7138 delete_breakpoint (b);
7143 map_breakpoint_numbers (arg, delete_breakpoint);
7146 /* Reset a breakpoint given it's struct breakpoint * BINT.
7147 The value we return ends up being the return value from catch_errors.
7148 Unused in this case. */
7151 breakpoint_re_set_one (void *bint)
7153 /* get past catch_errs */
7154 struct breakpoint *b = (struct breakpoint *) bint;
7158 int *not_found_ptr = NULL;
7159 struct symtabs_and_lines sals;
7161 enum enable_state save_enable;
7166 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7170 case bp_hardware_breakpoint:
7172 case bp_catch_unload:
7173 if (b->addr_string == NULL)
7175 /* Anything without a string can't be re-set. */
7176 delete_breakpoint (b);
7179 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7181 ``And a hack it is, although Apple's Darwin version of GDB
7182 contains an almost identical hack to implement a "future
7183 break" command. It seems to work in many real world cases,
7184 but it is easy to come up with a test case where the patch
7185 doesn't help at all.''
7187 ``It seems that the way GDB implements breakpoints - in -
7188 shared - libraries was designed for a.out shared library
7189 systems (SunOS 4) where shared libraries were loaded at a
7190 fixed address in memory. Since ELF shared libraries can (and
7191 will) be loaded at any address in memory, things break.
7192 Fixing this is not trivial. Therefore, I'm not sure whether
7193 we should add this hack to the branch only. I cannot
7194 guarantee that things will be fixed on the trunk in the near
7197 In case we have a problem, disable this breakpoint. We'll
7198 restore its status if we succeed. Don't disable a
7199 shlib_disabled breakpoint though. There's a fair chance we
7200 can't re-set it if the shared library it's in hasn't been
7206 save_enable = b->enable_state;
7207 if (b->enable_state != bp_shlib_disabled)
7208 b->enable_state = bp_disabled;
7210 /* If resetting a shlib-disabled breakpoint, we don't want to
7211 see an error message if it is not found since we will expect
7212 this to occur until the shared library is finally reloaded.
7213 We accomplish this by giving decode_line_1 a pointer to use
7214 for silent notification that the symbol is not found. */
7215 not_found_ptr = ¬_found;
7217 set_language (b->language);
7218 input_radix = b->input_radix;
7220 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7222 for (i = 0; i < sals.nelts; i++)
7224 resolve_sal_pc (&sals.sals[i]);
7226 /* Reparse conditions, they might contain references to the
7228 if (b->cond_string != NULL)
7234 /* Avoid re-freeing b->exp if an error during the call
7238 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7241 /* We need to re-set the breakpoint if the address changes... */
7242 if (b->loc->address != sals.sals[i].pc
7243 /* ...or new and old breakpoints both have source files, and
7244 the source file name or the line number changes... */
7245 || (b->source_file != NULL
7246 && sals.sals[i].symtab != NULL
7247 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
7248 || b->line_number != sals.sals[i].line)
7250 /* ...or we switch between having a source file and not having
7252 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7255 if (b->source_file != NULL)
7256 xfree (b->source_file);
7257 if (sals.sals[i].symtab == NULL)
7258 b->source_file = NULL;
7261 savestring (sals.sals[i].symtab->filename,
7262 strlen (sals.sals[i].symtab->filename));
7263 b->line_number = sals.sals[i].line;
7264 b->loc->requested_address = sals.sals[i].pc;
7266 = adjust_breakpoint_address (b->loc->requested_address,
7269 /* Used to check for duplicates here, but that can
7270 cause trouble, as it doesn't check for disabled
7275 /* Might be better to do this just once per breakpoint_re_set,
7276 rather than once for every breakpoint. */
7277 breakpoints_changed ();
7279 b->loc->section = sals.sals[i].section;
7280 b->enable_state = save_enable; /* Restore it, this worked. */
7283 /* Now that this is re-enabled, check_duplicates
7285 check_duplicates (b);
7292 case bp_hardware_watchpoint:
7293 case bp_read_watchpoint:
7294 case bp_access_watchpoint:
7295 innermost_block = NULL;
7296 /* The issue arises of what context to evaluate this in. The
7297 same one as when it was set, but what does that mean when
7298 symbols have been re-read? We could save the filename and
7299 functionname, but if the context is more local than that, the
7300 best we could do would be something like how many levels deep
7301 and which index at that particular level, but that's going to
7302 be less stable than filenames or function names. */
7304 /* So for now, just use a global context. */
7308 /* Avoid re-freeing b->exp if an error during the call to
7309 parse_expression. */
7312 b->exp = parse_expression (b->exp_string);
7313 b->exp_valid_block = innermost_block;
7314 mark = value_mark ();
7317 value_free (b->val);
7318 /* Avoid re-freeing b->val if an error during the call to
7319 evaluate_expression. */
7322 b->val = evaluate_expression (b->exp);
7323 release_value (b->val);
7324 if (value_lazy (b->val) && breakpoint_enabled (b))
7325 value_fetch_lazy (b->val);
7327 if (b->cond_string != NULL)
7333 /* Avoid re-freeing b->exp if an error during the call
7337 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7339 if (breakpoint_enabled (b))
7341 value_free_to_mark (mark);
7343 case bp_catch_catch:
7344 case bp_catch_throw:
7346 /* We needn't really do anything to reset these, since the mask
7347 that requests them is unaffected by e.g., new libraries being
7350 case bp_catch_vfork:
7355 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7357 /* Delete longjmp and overlay event breakpoints; they will be
7358 reset later by breakpoint_re_set. */
7360 case bp_longjmp_resume:
7361 case bp_overlay_event:
7362 delete_breakpoint (b);
7365 /* This breakpoint is special, it's set up when the inferior
7366 starts and we really don't want to touch it. */
7367 case bp_shlib_event:
7369 /* Like bp_shlib_event, this breakpoint type is special.
7370 Once it is set up, we do not want to touch it. */
7371 case bp_thread_event:
7373 /* Keep temporary breakpoints, which can be encountered when we step
7374 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7375 Otherwise these should have been blown away via the cleanup chain
7376 or by breakpoint_init_inferior when we rerun the executable. */
7379 case bp_watchpoint_scope:
7381 case bp_step_resume:
7388 /* Re-set all breakpoints after symbols have been re-loaded. */
7390 breakpoint_re_set (void)
7392 struct breakpoint *b, *temp;
7393 enum language save_language;
7394 int save_input_radix;
7396 save_language = current_language->la_language;
7397 save_input_radix = input_radix;
7398 ALL_BREAKPOINTS_SAFE (b, temp)
7400 /* Format possible error msg */
7401 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7403 struct cleanup *cleanups = make_cleanup (xfree, message);
7404 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7405 do_cleanups (cleanups);
7407 set_language (save_language);
7408 input_radix = save_input_radix;
7410 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7412 create_longjmp_breakpoint ("longjmp");
7413 create_longjmp_breakpoint ("_longjmp");
7414 create_longjmp_breakpoint ("siglongjmp");
7415 create_longjmp_breakpoint ("_siglongjmp");
7416 create_longjmp_breakpoint (NULL);
7419 create_overlay_event_breakpoint ("_ovly_debug_event");
7422 /* Reset the thread number of this breakpoint:
7424 - If the breakpoint is for all threads, leave it as-is.
7425 - Else, reset it to the current thread for inferior_ptid. */
7427 breakpoint_re_set_thread (struct breakpoint *b)
7429 if (b->thread != -1)
7431 if (in_thread_list (inferior_ptid))
7432 b->thread = pid_to_thread_id (inferior_ptid);
7436 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7437 If from_tty is nonzero, it prints a message to that effect,
7438 which ends with a period (no newline). */
7441 set_ignore_count (int bptnum, int count, int from_tty)
7443 struct breakpoint *b;
7449 if (b->number == bptnum)
7451 b->ignore_count = count;
7455 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7457 else if (count == 1)
7458 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7461 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7464 breakpoints_changed ();
7465 breakpoint_modify_event (b->number);
7469 error (_("No breakpoint number %d."), bptnum);
7472 /* Clear the ignore counts of all breakpoints. */
7474 breakpoint_clear_ignore_counts (void)
7476 struct breakpoint *b;
7479 b->ignore_count = 0;
7482 /* Command to set ignore-count of breakpoint N to COUNT. */
7485 ignore_command (char *args, int from_tty)
7491 error_no_arg (_("a breakpoint number"));
7493 num = get_number (&p);
7495 error (_("bad breakpoint number: '%s'"), args);
7497 error (_("Second argument (specified ignore-count) is missing."));
7499 set_ignore_count (num,
7500 longest_to_int (value_as_long (parse_and_eval (p))),
7503 printf_filtered ("\n");
7506 /* Call FUNCTION on each of the breakpoints
7507 whose numbers are given in ARGS. */
7510 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7515 struct breakpoint *b, *tmp;
7519 error_no_arg (_("one or more breakpoint numbers"));
7526 num = get_number_or_range (&p1);
7529 warning (_("bad breakpoint number at or near '%s'"), p);
7533 ALL_BREAKPOINTS_SAFE (b, tmp)
7534 if (b->number == num)
7536 struct breakpoint *related_breakpoint = b->related_breakpoint;
7539 if (related_breakpoint)
7540 function (related_breakpoint);
7544 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7550 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7551 If from_tty is nonzero, it prints a message to that effect,
7552 which ends with a period (no newline). */
7555 disable_breakpoint (struct breakpoint *bpt)
7557 /* Never disable a watchpoint scope breakpoint; we want to
7558 hit them when we leave scope so we can delete both the
7559 watchpoint and its scope breakpoint at that time. */
7560 if (bpt->type == bp_watchpoint_scope)
7563 /* You can't disable permanent breakpoints. */
7564 if (bpt->enable_state == bp_permanent)
7567 bpt->enable_state = bp_disabled;
7569 check_duplicates (bpt);
7571 if (deprecated_modify_breakpoint_hook)
7572 deprecated_modify_breakpoint_hook (bpt);
7573 breakpoint_modify_event (bpt->number);
7577 disable_command (char *args, int from_tty)
7579 struct breakpoint *bpt;
7581 ALL_BREAKPOINTS (bpt)
7585 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7590 case bp_catch_unload:
7592 case bp_catch_vfork:
7594 case bp_catch_catch:
7595 case bp_catch_throw:
7596 case bp_hardware_breakpoint:
7598 case bp_hardware_watchpoint:
7599 case bp_read_watchpoint:
7600 case bp_access_watchpoint:
7601 disable_breakpoint (bpt);
7606 map_breakpoint_numbers (args, disable_breakpoint);
7610 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7612 int target_resources_ok, other_type_used;
7615 if (bpt->type == bp_hardware_breakpoint)
7618 i = hw_breakpoint_used_count ();
7619 target_resources_ok =
7620 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7622 if (target_resources_ok == 0)
7623 error (_("No hardware breakpoint support in the target."));
7624 else if (target_resources_ok < 0)
7625 error (_("Hardware breakpoints used exceeds limit."));
7630 if (bpt->enable_state != bp_enabled)
7632 /* When enabling a pending breakpoint, we need to check if the breakpoint
7633 is resolvable since shared libraries could have been loaded
7634 after the breakpoint was disabled. */
7635 breakpoints_changed ();
7636 if (resolve_pending_breakpoint (bpt) == GDB_RC_OK)
7638 delete_breakpoint (bpt);
7641 bpt->enable_state = bp_enabled;
7642 bpt->disposition = disposition;
7645 else /* Not a pending breakpoint. */
7647 if (bpt->enable_state != bp_permanent)
7648 bpt->enable_state = bp_enabled;
7649 bpt->disposition = disposition;
7650 check_duplicates (bpt);
7651 breakpoints_changed ();
7653 if (bpt->type == bp_watchpoint ||
7654 bpt->type == bp_hardware_watchpoint ||
7655 bpt->type == bp_read_watchpoint ||
7656 bpt->type == bp_access_watchpoint)
7658 struct frame_id saved_frame_id;
7660 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7661 if (bpt->exp_valid_block != NULL)
7663 struct frame_info *fr =
7664 fr = frame_find_by_id (bpt->watchpoint_frame);
7667 printf_filtered (_("\
7668 Cannot enable watchpoint %d because the block in which its expression\n\
7669 is valid is not currently in scope.\n"), bpt->number);
7670 bpt->enable_state = bp_disabled;
7676 value_free (bpt->val);
7677 mark = value_mark ();
7678 bpt->val = evaluate_expression (bpt->exp);
7679 release_value (bpt->val);
7680 if (value_lazy (bpt->val))
7681 value_fetch_lazy (bpt->val);
7683 if (bpt->type == bp_hardware_watchpoint ||
7684 bpt->type == bp_read_watchpoint ||
7685 bpt->type == bp_access_watchpoint)
7687 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7688 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7690 /* Hack around 'unused var' error for some targets here */
7691 (void) mem_cnt, (void) i;
7692 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7693 bpt->type, i + mem_cnt, other_type_used);
7694 /* we can consider of type is bp_hardware_watchpoint, convert to
7695 bp_watchpoint in the following condition */
7696 if (target_resources_ok < 0)
7698 printf_filtered (_("\
7699 Cannot enable watchpoint %d because target watch resources\n\
7700 have been allocated for other watchpoints.\n"), bpt->number);
7701 bpt->enable_state = bp_disabled;
7702 value_free_to_mark (mark);
7707 select_frame (frame_find_by_id (saved_frame_id));
7708 value_free_to_mark (mark);
7712 if (deprecated_modify_breakpoint_hook)
7713 deprecated_modify_breakpoint_hook (bpt);
7714 breakpoint_modify_event (bpt->number);
7718 enable_breakpoint (struct breakpoint *bpt)
7720 do_enable_breakpoint (bpt, bpt->disposition);
7723 /* The enable command enables the specified breakpoints (or all defined
7724 breakpoints) so they once again become (or continue to be) effective
7725 in stopping the inferior. */
7728 enable_command (char *args, int from_tty)
7730 struct breakpoint *bpt;
7732 ALL_BREAKPOINTS (bpt)
7736 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7741 case bp_catch_unload:
7743 case bp_catch_vfork:
7745 case bp_catch_catch:
7746 case bp_catch_throw:
7747 case bp_hardware_breakpoint:
7749 case bp_hardware_watchpoint:
7750 case bp_read_watchpoint:
7751 case bp_access_watchpoint:
7752 enable_breakpoint (bpt);
7757 map_breakpoint_numbers (args, enable_breakpoint);
7761 enable_once_breakpoint (struct breakpoint *bpt)
7763 do_enable_breakpoint (bpt, disp_disable);
7767 enable_once_command (char *args, int from_tty)
7769 map_breakpoint_numbers (args, enable_once_breakpoint);
7773 enable_delete_breakpoint (struct breakpoint *bpt)
7775 do_enable_breakpoint (bpt, disp_del);
7779 enable_delete_command (char *args, int from_tty)
7781 map_breakpoint_numbers (args, enable_delete_breakpoint);
7785 set_breakpoint_cmd (char *args, int from_tty)
7790 show_breakpoint_cmd (char *args, int from_tty)
7794 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7796 struct symtabs_and_lines
7797 decode_line_spec_1 (char *string, int funfirstline)
7799 struct symtabs_and_lines sals;
7801 error (_("Empty line specification."));
7802 if (default_breakpoint_valid)
7803 sals = decode_line_1 (&string, funfirstline,
7804 default_breakpoint_symtab,
7805 default_breakpoint_line,
7806 (char ***) NULL, NULL);
7808 sals = decode_line_1 (&string, funfirstline,
7809 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
7811 error (_("Junk at end of line specification: %s"), string);
7815 /* Create and insert a raw software breakpoint at PC. Return an
7816 identifier, which should be used to remove the breakpoint later.
7817 In general, places which call this should be using something on the
7818 breakpoint chain instead; this function should be eliminated
7822 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
7824 struct bp_target_info *bp_tgt;
7826 bp_tgt = xmalloc (sizeof (struct bp_target_info));
7827 memset (bp_tgt, 0, sizeof (struct bp_target_info));
7829 bp_tgt->placed_address = pc;
7830 if (target_insert_breakpoint (bp_tgt) != 0)
7832 /* Could not insert the breakpoint. */
7840 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7843 deprecated_remove_raw_breakpoint (void *bp)
7845 struct bp_target_info *bp_tgt = bp;
7848 ret = target_remove_breakpoint (bp_tgt);
7854 /* One (or perhaps two) breakpoints used for software single stepping. */
7856 static void *single_step_breakpoints[2];
7858 /* Create and insert a breakpoint for software single step. */
7861 insert_single_step_breakpoint (CORE_ADDR next_pc)
7865 if (single_step_breakpoints[0] == NULL)
7866 bpt_p = &single_step_breakpoints[0];
7869 gdb_assert (single_step_breakpoints[1] == NULL);
7870 bpt_p = &single_step_breakpoints[1];
7873 /* NOTE drow/2006-04-11: A future improvement to this function would be
7874 to only create the breakpoints once, and actually put them on the
7875 breakpoint chain. That would let us use set_raw_breakpoint. We could
7876 adjust the addresses each time they were needed. Doing this requires
7877 corresponding changes elsewhere where single step breakpoints are
7878 handled, however. So, for now, we use this. */
7880 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
7882 error (_("Could not insert single-step breakpoint at 0x%s"),
7883 paddr_nz (next_pc));
7886 /* Remove and delete any breakpoints used for software single step. */
7889 remove_single_step_breakpoints (void)
7891 gdb_assert (single_step_breakpoints[0] != NULL);
7893 /* See insert_single_step_breakpoint for more about this deprecated
7895 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
7896 single_step_breakpoints[0] = NULL;
7898 if (single_step_breakpoints[1] != NULL)
7900 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
7901 single_step_breakpoints[1] = NULL;
7905 /* Check whether a software single-step breakpoint is inserted at PC. */
7908 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
7912 for (i = 0; i < 2; i++)
7914 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
7915 if (bp_tgt && bp_tgt->placed_address == pc)
7923 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7924 It is defined as a macro to prevent duplication.
7925 COMMAND should be a string constant containing the name of the command. */
7926 #define BREAK_ARGS_HELP(command) \
7927 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7928 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7929 If a line number is specified, break at start of code for that line.\n\
7930 If a function is specified, break at start of code for that function.\n\
7931 If an address is specified, break at that exact address.\n\
7932 With no LOCATION, uses current execution address of selected stack frame.\n\
7933 This is useful for breaking on return to a stack frame.\n\
7935 THREADNUM is the number from \"info threads\".\n\
7936 CONDITION is a boolean expression.\n\
7938 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7940 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7943 _initialize_breakpoint (void)
7945 static struct cmd_list_element *breakpoint_set_cmdlist;
7946 static struct cmd_list_element *breakpoint_show_cmdlist;
7947 struct cmd_list_element *c;
7949 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
7951 breakpoint_chain = 0;
7952 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7953 before a breakpoint is set. */
7954 breakpoint_count = 0;
7956 add_com ("ignore", class_breakpoint, ignore_command, _("\
7957 Set ignore-count of breakpoint number N to COUNT.\n\
7958 Usage is `ignore N COUNT'."));
7960 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7962 add_com ("commands", class_breakpoint, commands_command, _("\
7963 Set commands to be executed when a breakpoint is hit.\n\
7964 Give breakpoint number as argument after \"commands\".\n\
7965 With no argument, the targeted breakpoint is the last one set.\n\
7966 The commands themselves follow starting on the next line.\n\
7967 Type a line containing \"end\" to indicate the end of them.\n\
7968 Give \"silent\" as the first line to make the breakpoint silent;\n\
7969 then no output is printed when it is hit, except what the commands print."));
7971 add_com ("condition", class_breakpoint, condition_command, _("\
7972 Specify breakpoint number N to break only if COND is true.\n\
7973 Usage is `condition N COND', where N is an integer and COND is an\n\
7974 expression to be evaluated whenever breakpoint N is reached."));
7976 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
7977 Set a temporary breakpoint.\n\
7978 Like \"break\" except the breakpoint is only temporary,\n\
7979 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7980 by using \"enable delete\" on the breakpoint number.\n\
7982 BREAK_ARGS_HELP ("tbreak")));
7983 set_cmd_completer (c, location_completer);
7985 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
7986 Set a hardware assisted breakpoint.\n\
7987 Like \"break\" except the breakpoint requires hardware support,\n\
7988 some target hardware may not have this support.\n\
7990 BREAK_ARGS_HELP ("hbreak")));
7991 set_cmd_completer (c, location_completer);
7993 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
7994 Set a temporary hardware assisted breakpoint.\n\
7995 Like \"hbreak\" except the breakpoint is only temporary,\n\
7996 so it will be deleted when hit.\n\
7998 BREAK_ARGS_HELP ("thbreak")));
7999 set_cmd_completer (c, location_completer);
8001 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8002 Enable some breakpoints.\n\
8003 Give breakpoint numbers (separated by spaces) as arguments.\n\
8004 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8005 This is used to cancel the effect of the \"disable\" command.\n\
8006 With a subcommand you can enable temporarily."),
8007 &enablelist, "enable ", 1, &cmdlist);
8009 add_com ("ab", class_breakpoint, enable_command, _("\
8010 Enable some breakpoints.\n\
8011 Give breakpoint numbers (separated by spaces) as arguments.\n\
8012 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8013 This is used to cancel the effect of the \"disable\" command.\n\
8014 With a subcommand you can enable temporarily."));
8016 add_com_alias ("en", "enable", class_breakpoint, 1);
8018 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8019 Enable some breakpoints.\n\
8020 Give breakpoint numbers (separated by spaces) as arguments.\n\
8021 This is used to cancel the effect of the \"disable\" command.\n\
8022 May be abbreviated to simply \"enable\".\n"),
8023 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8025 add_cmd ("once", no_class, enable_once_command, _("\
8026 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8027 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8030 add_cmd ("delete", no_class, enable_delete_command, _("\
8031 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8032 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8035 add_cmd ("delete", no_class, enable_delete_command, _("\
8036 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8037 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8040 add_cmd ("once", no_class, enable_once_command, _("\
8041 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8042 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8045 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8046 Disable some breakpoints.\n\
8047 Arguments are breakpoint numbers with spaces in between.\n\
8048 To disable all breakpoints, give no argument.\n\
8049 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8050 &disablelist, "disable ", 1, &cmdlist);
8051 add_com_alias ("dis", "disable", class_breakpoint, 1);
8052 add_com_alias ("disa", "disable", class_breakpoint, 1);
8054 add_com ("sb", class_breakpoint, disable_command, _("\
8055 Disable some breakpoints.\n\
8056 Arguments are breakpoint numbers with spaces in between.\n\
8057 To disable all breakpoints, give no argument.\n\
8058 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8060 add_cmd ("breakpoints", class_alias, disable_command, _("\
8061 Disable some breakpoints.\n\
8062 Arguments are breakpoint numbers with spaces in between.\n\
8063 To disable all breakpoints, give no argument.\n\
8064 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8065 This command may be abbreviated \"disable\"."),
8068 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8069 Delete some breakpoints or auto-display expressions.\n\
8070 Arguments are breakpoint numbers with spaces in between.\n\
8071 To delete all breakpoints, give no argument.\n\
8073 Also a prefix command for deletion of other GDB objects.\n\
8074 The \"unset\" command is also an alias for \"delete\"."),
8075 &deletelist, "delete ", 1, &cmdlist);
8076 add_com_alias ("d", "delete", class_breakpoint, 1);
8077 add_com_alias ("del", "delete", class_breakpoint, 1);
8079 add_com ("db", class_breakpoint, delete_command, _("\
8080 Delete some breakpoints.\n\
8081 Arguments are breakpoint numbers with spaces in between.\n\
8082 To delete all breakpoints, give no argument.\n"));
8084 add_cmd ("breakpoints", class_alias, delete_command, _("\
8085 Delete some breakpoints or auto-display expressions.\n\
8086 Arguments are breakpoint numbers with spaces in between.\n\
8087 To delete all breakpoints, give no argument.\n\
8088 This command may be abbreviated \"delete\"."),
8091 add_com ("clear", class_breakpoint, clear_command, _("\
8092 Clear breakpoint at specified line or function.\n\
8093 Argument may be line number, function name, or \"*\" and an address.\n\
8094 If line number is specified, all breakpoints in that line are cleared.\n\
8095 If function is specified, breakpoints at beginning of function are cleared.\n\
8096 If an address is specified, breakpoints at that address are cleared.\n\
8098 With no argument, clears all breakpoints in the line that the selected frame\n\
8101 See also the \"delete\" command which clears breakpoints by number."));
8103 c = add_com ("break", class_breakpoint, break_command, _("\
8104 Set breakpoint at specified line or function.\n"
8105 BREAK_ARGS_HELP ("break")));
8106 set_cmd_completer (c, location_completer);
8108 add_com_alias ("b", "break", class_run, 1);
8109 add_com_alias ("br", "break", class_run, 1);
8110 add_com_alias ("bre", "break", class_run, 1);
8111 add_com_alias ("brea", "break", class_run, 1);
8115 add_com_alias ("ba", "break", class_breakpoint, 1);
8116 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8121 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8122 Break in function/address or break at a line in the current file."),
8123 &stoplist, "stop ", 1, &cmdlist);
8124 add_cmd ("in", class_breakpoint, stopin_command,
8125 _("Break in function or address."), &stoplist);
8126 add_cmd ("at", class_breakpoint, stopat_command,
8127 _("Break at a line in the current file."), &stoplist);
8128 add_com ("status", class_info, breakpoints_info, _("\
8129 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8130 The \"Type\" column indicates one of:\n\
8131 \tbreakpoint - normal breakpoint\n\
8132 \twatchpoint - watchpoint\n\
8133 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8134 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8135 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8136 address and file/line number respectively.\n\
8138 Convenience variable \"$_\" and default examine address for \"x\"\n\
8139 are set to the address of the last breakpoint listed unless the command\n\
8140 is prefixed with \"server \".\n\n\
8141 Convenience variable \"$bpnum\" contains the number of the last\n\
8145 add_info ("breakpoints", breakpoints_info, _("\
8146 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8147 The \"Type\" column indicates one of:\n\
8148 \tbreakpoint - normal breakpoint\n\
8149 \twatchpoint - watchpoint\n\
8150 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8151 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8152 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8153 address and file/line number respectively.\n\
8155 Convenience variable \"$_\" and default examine address for \"x\"\n\
8156 are set to the address of the last breakpoint listed unless the command\n\
8157 is prefixed with \"server \".\n\n\
8158 Convenience variable \"$bpnum\" contains the number of the last\n\
8162 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8163 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8164 The \"Type\" column indicates one of:\n\
8165 \tbreakpoint - normal breakpoint\n\
8166 \twatchpoint - watchpoint\n\
8167 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8168 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8169 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8170 address and file/line number respectively.\n\
8172 Convenience variable \"$_\" and default examine address for \"x\"\n\
8173 are set to the address of the last breakpoint listed unless the command\n\
8174 is prefixed with \"server \".\n\n\
8175 Convenience variable \"$bpnum\" contains the number of the last\n\
8178 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8179 Status of all breakpoints, or breakpoint number NUMBER.\n\
8180 The \"Type\" column indicates one of:\n\
8181 \tbreakpoint - normal breakpoint\n\
8182 \twatchpoint - watchpoint\n\
8183 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8184 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8185 \tuntil - internal breakpoint used by the \"until\" command\n\
8186 \tfinish - internal breakpoint used by the \"finish\" command\n\
8187 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8188 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8189 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8190 address and file/line number respectively.\n\
8192 Convenience variable \"$_\" and default examine address for \"x\"\n\
8193 are set to the address of the last breakpoint listed unless the command\n\
8194 is prefixed with \"server \".\n\n\
8195 Convenience variable \"$bpnum\" contains the number of the last\n\
8197 &maintenanceinfolist);
8199 add_com ("catch", class_breakpoint, catch_command, _("\
8200 Set catchpoints to catch events.\n\
8201 Raised signals may be caught:\n\
8202 \tcatch signal - all signals\n\
8203 \tcatch signal <signame> - a particular signal\n\
8204 Raised exceptions may be caught:\n\
8205 \tcatch throw - all exceptions, when thrown\n\
8206 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8207 \tcatch catch - all exceptions, when caught\n\
8208 \tcatch catch <exceptname> - a particular exception, when caught\n\
8209 Thread or process events may be caught:\n\
8210 \tcatch thread_start - any threads, just after creation\n\
8211 \tcatch thread_exit - any threads, just before expiration\n\
8212 \tcatch thread_join - any threads, just after joins\n\
8213 Process events may be caught:\n\
8214 \tcatch start - any processes, just after creation\n\
8215 \tcatch exit - any processes, just before expiration\n\
8216 \tcatch fork - calls to fork()\n\
8217 \tcatch vfork - calls to vfork()\n\
8218 \tcatch exec - calls to exec()\n\
8219 Dynamically-linked library events may be caught:\n\
8220 \tcatch load - loads of any library\n\
8221 \tcatch load <libname> - loads of a particular library\n\
8222 \tcatch unload - unloads of any library\n\
8223 \tcatch unload <libname> - unloads of a particular library\n\
8224 The act of your program's execution stopping may also be caught:\n\
8226 C++ exceptions may be caught:\n\
8227 \tcatch throw - all exceptions, when thrown\n\
8228 \tcatch catch - all exceptions, when caught\n\
8229 Ada exceptions may be caught:\n\
8230 \tcatch exception - all exceptions, when raised\n\
8231 \tcatch exception <name> - a particular exception, when raised\n\
8232 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8233 \tcatch assert - all failed assertions, when raised\n\
8235 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8236 after a fork or vfork is caught.\n\n\
8237 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8239 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8240 Set temporary catchpoints to catch events.\n\
8241 Args like \"catch\" command.\n\
8242 Like \"catch\" except the catchpoint is only temporary,\n\
8243 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8244 by using \"enable delete\" on the catchpoint number."));
8246 c = add_com ("watch", class_breakpoint, watch_command, _("\
8247 Set a watchpoint for an expression.\n\
8248 A watchpoint stops execution of your program whenever the value of\n\
8249 an expression changes."));
8250 set_cmd_completer (c, location_completer);
8252 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8253 Set a read watchpoint for an expression.\n\
8254 A watchpoint stops execution of your program whenever the value of\n\
8255 an expression is read."));
8256 set_cmd_completer (c, location_completer);
8258 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8259 Set a watchpoint for an expression.\n\
8260 A watchpoint stops execution of your program whenever the value of\n\
8261 an expression is either read or written."));
8262 set_cmd_completer (c, location_completer);
8264 add_info ("watchpoints", breakpoints_info,
8265 _("Synonym for ``info breakpoints''."));
8268 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8269 respond to changes - contrary to the description. */
8270 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8271 &can_use_hw_watchpoints, _("\
8272 Set debugger's willingness to use watchpoint hardware."), _("\
8273 Show debugger's willingness to use watchpoint hardware."), _("\
8274 If zero, gdb will not use hardware for new watchpoints, even if\n\
8275 such is available. (However, any hardware watchpoints that were\n\
8276 created before setting this to nonzero, will continue to use watchpoint\n\
8279 show_can_use_hw_watchpoints,
8280 &setlist, &showlist);
8282 can_use_hw_watchpoints = 1;
8284 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8285 Breakpoint specific settings\n\
8286 Configure various breakpoint-specific variables such as\n\
8287 pending breakpoint behavior"),
8288 &breakpoint_set_cmdlist, "set breakpoint ",
8289 0/*allow-unknown*/, &setlist);
8290 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8291 Breakpoint specific settings\n\
8292 Configure various breakpoint-specific variables such as\n\
8293 pending breakpoint behavior"),
8294 &breakpoint_show_cmdlist, "show breakpoint ",
8295 0/*allow-unknown*/, &showlist);
8297 add_setshow_auto_boolean_cmd ("pending", no_class,
8298 &pending_break_support, _("\
8299 Set debugger's behavior regarding pending breakpoints."), _("\
8300 Show debugger's behavior regarding pending breakpoints."), _("\
8301 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8302 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8303 an error. If auto, an unrecognized breakpoint location results in a\n\
8304 user-query to see if a pending breakpoint should be created."),
8306 show_pending_break_support,
8307 &breakpoint_set_cmdlist,
8308 &breakpoint_show_cmdlist);
8310 pending_break_support = AUTO_BOOLEAN_AUTO;
8312 add_setshow_boolean_cmd ("auto-hw", no_class,
8313 &automatic_hardware_breakpoints, _("\
8314 Set automatic usage of hardware breakpoints."), _("\
8315 Show automatic usage of hardware breakpoints."), _("\
8316 If set, the debugger will automatically use hardware breakpoints for\n\
8317 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8318 a warning will be emitted for such breakpoints."),
8320 show_automatic_hardware_breakpoints,
8321 &breakpoint_set_cmdlist,
8322 &breakpoint_show_cmdlist);
8324 automatic_hardware_breakpoints = 1;