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 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 #include "gdb_stdint.h"
65 /* Prototypes for local functions. */
67 static void until_break_command_continuation (struct continuation_arg *arg,
70 static void catch_command_1 (char *, int, int);
72 static void enable_delete_command (char *, int);
74 static void enable_delete_breakpoint (struct breakpoint *);
76 static void enable_once_command (char *, int);
78 static void enable_once_breakpoint (struct breakpoint *);
80 static void disable_command (char *, int);
82 static void enable_command (char *, int);
84 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
86 static void ignore_command (char *, int);
88 static int breakpoint_re_set_one (void *);
90 static void clear_command (char *, int);
92 static void catch_command (char *, int);
94 static void watch_command (char *, int);
96 static int can_use_hardware_watchpoint (struct value *);
98 static void break_command_1 (char *, int, int);
100 static void mention (struct breakpoint *);
102 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
104 static void check_duplicates (struct breakpoint *);
106 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
108 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
111 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
113 static void breakpoints_info (char *, int);
115 static void breakpoint_1 (int, int);
117 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
119 static int breakpoint_cond_eval (void *);
121 static void cleanup_executing_breakpoints (void *);
123 static void commands_command (char *, int);
125 static void condition_command (char *, int);
127 static int get_number_trailer (char **, int);
129 void set_breakpoint_count (int);
138 static int remove_breakpoint (struct bp_location *, insertion_state_t);
140 static enum print_stop_action print_it_typical (bpstat);
142 static enum print_stop_action print_bp_stop_message (bpstat bs);
146 enum exception_event_kind kind;
149 args_for_catchpoint_enable;
151 static int watchpoint_check (void *);
153 static void maintenance_info_breakpoints (char *, int);
155 static void create_longjmp_breakpoint (char *);
157 static void create_overlay_event_breakpoint (char *);
159 static int hw_breakpoint_used_count (void);
161 static int hw_watchpoint_used_count (enum bptype, int *);
163 static void hbreak_command (char *, int);
165 static void thbreak_command (char *, int);
167 static void watch_command_1 (char *, int, int);
169 static void rwatch_command (char *, int);
171 static void awatch_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
175 static void create_fork_vfork_event_catchpoint (int tempflag,
177 enum bptype bp_kind);
179 static void stop_command (char *arg, int from_tty);
181 static void stopin_command (char *arg, int from_tty);
183 static void stopat_command (char *arg, int from_tty);
185 static char *ep_find_event_name_end (char *arg);
187 static char *ep_parse_optional_if_clause (char **arg);
189 static char *ep_parse_optional_filename (char **arg);
191 static void create_exception_catchpoint (int tempflag, char *cond_string,
192 enum exception_event_kind ex_event,
193 struct symtab_and_line *sal);
195 static void catch_exception_command_1 (enum exception_event_kind ex_event,
196 char *arg, int tempflag, int from_tty);
198 static void tcatch_command (char *arg, int from_tty);
200 static void ep_skip_leading_whitespace (char **s);
202 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
204 static void free_bp_location (struct bp_location *loc);
206 static void mark_breakpoints_out (void);
208 static struct bp_location *
209 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type);
211 static void update_global_location_list (void);
213 static void update_global_location_list_nothrow (void);
215 static int is_hardware_watchpoint (struct breakpoint *bpt);
217 static void insert_breakpoint_locations (void);
220 bpdisp_text (enum bpdisp disp)
222 /* NOTE: the following values are a part of MI protocol and represent
223 values of 'disp' field returned when inferior stops at a breakpoint. */
224 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
225 return bpdisps[(int) disp];
228 /* Prototypes for exported functions. */
229 /* If FALSE, gdb will not use hardware support for watchpoints, even
230 if such is available. */
231 static int can_use_hw_watchpoints;
234 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
235 struct cmd_list_element *c,
238 fprintf_filtered (file, _("\
239 Debugger's willingness to use watchpoint hardware is %s.\n"),
243 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
244 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
245 for unrecognized breakpoint locations.
246 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
247 static enum auto_boolean pending_break_support;
249 show_pending_break_support (struct ui_file *file, int from_tty,
250 struct cmd_list_element *c,
253 fprintf_filtered (file, _("\
254 Debugger's behavior regarding pending breakpoints is %s.\n"),
258 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
259 set with "break" but falling in read-only memory.
260 If 0, gdb will warn about such breakpoints, but won't automatically
261 use hardware breakpoints. */
262 static int automatic_hardware_breakpoints;
264 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
265 struct cmd_list_element *c,
268 fprintf_filtered (file, _("\
269 Automatic usage of hardware breakpoints is %s.\n"),
273 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
274 and immediately insert any new breakpoints. If 0, gdb will insert
275 breakpoints into inferior only when resuming it, and will remove
276 breakpoints upon stop. */
277 static int always_inserted_mode = 0;
279 show_always_inserted_mode (struct ui_file *file, int from_tty,
280 struct cmd_list_element *c, const char *value)
282 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
286 void _initialize_breakpoint (void);
288 extern int addressprint; /* Print machine addresses? */
290 /* Are we executing breakpoint commands? */
291 static int executing_breakpoint_commands;
293 /* Are overlay event breakpoints enabled? */
294 static int overlay_events_enabled;
296 /* Walk the following statement or block through all breakpoints.
297 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
300 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
302 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
303 for (B = breakpoint_chain; \
304 B ? (TMP=B->next, 1): 0; \
307 /* Similar iterators for the low-level breakpoints. */
309 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
311 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
312 for (B = bp_location_chain; \
313 B ? (TMP=B->global_next, 1): 0; \
316 /* True if breakpoint hit counts should be displayed in breakpoint info. */
318 int show_breakpoint_hit_counts = 1;
320 /* Chains of all breakpoints defined. */
322 struct breakpoint *breakpoint_chain;
324 struct bp_location *bp_location_chain;
326 /* Number of last breakpoint made. */
328 int breakpoint_count;
330 /* Pointer to current exception event record */
331 static struct exception_event_record *current_exception_event;
333 /* This function returns a pointer to the string representation of the
334 pathname of the dynamically-linked library that has just been
337 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
338 or undefined results are guaranteed.
340 This string's contents are only valid immediately after the
341 inferior has stopped in the dynamic linker hook, and becomes
342 invalid as soon as the inferior is continued. Clients should make
343 a copy of this string if they wish to continue the inferior and
344 then access the string. */
346 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
347 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
350 /* This function returns a pointer to the string representation of the
351 pathname of the dynamically-linked library that has just been
354 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
355 TRUE, or undefined results are guaranteed.
357 This string's contents are only valid immediately after the
358 inferior has stopped in the dynamic linker hook, and becomes
359 invalid as soon as the inferior is continued. Clients should make
360 a copy of this string if they wish to continue the inferior and
361 then access the string. */
363 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
364 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
367 /* This function is called by the "catch load" command. It allows the
368 debugger to be notified by the dynamic linker when a specified
369 library file (or any library file, if filename is NULL) is loaded. */
371 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
372 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
373 error (_("catch of library loads not yet implemented on this platform"))
376 /* This function is called by the "catch unload" command. It allows
377 the debugger to be notified by the dynamic linker when a specified
378 library file (or any library file, if filename is NULL) is
381 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
382 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
383 error (_("catch of library unloads not yet implemented on this platform"))
386 /* Return whether a breakpoint is an active enabled breakpoint. */
388 breakpoint_enabled (struct breakpoint *b)
390 return (b->enable_state == bp_enabled);
393 /* Set breakpoint count to NUM. */
396 set_breakpoint_count (int num)
398 breakpoint_count = num;
399 set_internalvar (lookup_internalvar ("bpnum"),
400 value_from_longest (builtin_type_int, (LONGEST) num));
403 /* Used in run_command to zero the hit count when a new run starts. */
406 clear_breakpoint_hit_counts (void)
408 struct breakpoint *b;
414 /* Default address, symtab and line to put a breakpoint at
415 for "break" command with no arg.
416 if default_breakpoint_valid is zero, the other three are
417 not valid, and "break" with no arg is an error.
419 This set by print_stack_frame, which calls set_default_breakpoint. */
421 int default_breakpoint_valid;
422 CORE_ADDR default_breakpoint_address;
423 struct symtab *default_breakpoint_symtab;
424 int default_breakpoint_line;
426 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
427 Advance *PP after the string and any trailing whitespace.
429 Currently the string can either be a number or "$" followed by the name
430 of a convenience variable. Making it an expression wouldn't work well
431 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
433 If the string is a NULL pointer, that denotes the last breakpoint.
435 TRAILER is a character which can be found after the number; most
436 commonly this is `-'. If you don't want a trailer, use \0. */
438 get_number_trailer (char **pp, int trailer)
440 int retval = 0; /* default */
444 /* Empty line means refer to the last breakpoint. */
445 return breakpoint_count;
448 /* Make a copy of the name, so we can null-terminate it
449 to pass to lookup_internalvar(). */
454 while (isalnum (*p) || *p == '_')
456 varname = (char *) alloca (p - start + 1);
457 strncpy (varname, start, p - start);
458 varname[p - start] = '\0';
459 val = value_of_internalvar (lookup_internalvar (varname));
460 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
461 retval = (int) value_as_long (val);
464 printf_filtered (_("Convenience variable must have integer value.\n"));
472 while (*p >= '0' && *p <= '9')
475 /* There is no number here. (e.g. "cond a == b"). */
477 /* Skip non-numeric token */
478 while (*p && !isspace((int) *p))
480 /* Return zero, which caller must interpret as error. */
486 if (!(isspace (*p) || *p == '\0' || *p == trailer))
488 /* Trailing junk: return 0 and let caller print error msg. */
489 while (!(isspace (*p) || *p == '\0' || *p == trailer))
500 /* Like get_number_trailer, but don't allow a trailer. */
502 get_number (char **pp)
504 return get_number_trailer (pp, '\0');
507 /* Parse a number or a range.
508 * A number will be of the form handled by get_number.
509 * A range will be of the form <number1> - <number2>, and
510 * will represent all the integers between number1 and number2,
513 * While processing a range, this fuction is called iteratively;
514 * At each call it will return the next value in the range.
516 * At the beginning of parsing a range, the char pointer PP will
517 * be advanced past <number1> and left pointing at the '-' token.
518 * Subsequent calls will not advance the pointer until the range
519 * is completed. The call that completes the range will advance
520 * pointer PP past <number2>.
524 get_number_or_range (char **pp)
526 static int last_retval, end_value;
527 static char *end_ptr;
528 static int in_range = 0;
532 /* Default case: pp is pointing either to a solo number,
533 or to the first number of a range. */
534 last_retval = get_number_trailer (pp, '-');
539 /* This is the start of a range (<number1> - <number2>).
540 Skip the '-', parse and remember the second number,
541 and also remember the end of the final token. */
545 while (isspace ((int) *end_ptr))
546 end_ptr++; /* skip white space */
547 end_value = get_number (temp);
548 if (end_value < last_retval)
550 error (_("inverted range"));
552 else if (end_value == last_retval)
554 /* degenerate range (number1 == number2). Advance the
555 token pointer so that the range will be treated as a
564 error (_("negative value"));
567 /* pp points to the '-' that betokens a range. All
568 number-parsing has already been done. Return the next
569 integer value (one greater than the saved previous value).
570 Do not advance the token pointer 'pp' until the end of range
573 if (++last_retval == end_value)
575 /* End of range reached; advance token pointer. */
585 /* condition N EXP -- set break condition of breakpoint N to EXP. */
588 condition_command (char *arg, int from_tty)
590 struct breakpoint *b;
595 error_no_arg (_("breakpoint number"));
598 bnum = get_number (&p);
600 error (_("Bad breakpoint argument: '%s'"), arg);
603 if (b->number == bnum)
605 struct bp_location *loc = b->loc;
606 for (; loc; loc = loc->next)
614 if (b->cond_string != NULL)
615 xfree (b->cond_string);
619 b->cond_string = NULL;
621 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
626 /* I don't know if it matters whether this is the string the user
627 typed in or the decompiled expression. */
628 b->cond_string = savestring (arg, strlen (arg));
629 b->condition_not_parsed = 0;
630 for (loc = b->loc; loc; loc = loc->next)
634 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
636 error (_("Junk at end of expression"));
639 breakpoints_changed ();
640 breakpoint_modify_event (b->number);
644 error (_("No breakpoint number %d."), bnum);
648 commands_command (char *arg, int from_tty)
650 struct breakpoint *b;
653 struct command_line *l;
655 /* If we allowed this, we would have problems with when to
656 free the storage, if we change the commands currently
659 if (executing_breakpoint_commands)
660 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
663 bnum = get_number (&p);
666 error (_("Unexpected extra arguments following breakpoint number."));
669 if (b->number == bnum)
671 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
673 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
674 l = read_command_lines (tmpbuf, from_tty);
675 do_cleanups (cleanups);
676 free_command_lines (&b->commands);
678 breakpoints_changed ();
679 breakpoint_modify_event (b->number);
682 error (_("No breakpoint number %d."), bnum);
685 /* Like commands_command, but instead of reading the commands from
686 input stream, takes them from an already parsed command structure.
688 This is used by cli-script.c to DTRT with breakpoint commands
689 that are part of if and while bodies. */
690 enum command_control_type
691 commands_from_control_command (char *arg, struct command_line *cmd)
693 struct breakpoint *b;
697 /* If we allowed this, we would have problems with when to
698 free the storage, if we change the commands currently
701 if (executing_breakpoint_commands)
702 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
704 /* An empty string for the breakpoint number means the last
705 breakpoint, but get_number expects a NULL pointer. */
710 bnum = get_number (&p);
713 error (_("Unexpected extra arguments following breakpoint number."));
716 if (b->number == bnum)
718 free_command_lines (&b->commands);
719 if (cmd->body_count != 1)
720 error (_("Invalid \"commands\" block structure."));
721 /* We need to copy the commands because if/while will free the
722 list after it finishes execution. */
723 b->commands = copy_command_lines (cmd->body_list[0]);
724 breakpoints_changed ();
725 breakpoint_modify_event (b->number);
726 return simple_control;
728 error (_("No breakpoint number %d."), bnum);
731 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
732 by replacing any memory breakpoints with their shadowed contents. */
735 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
737 struct bp_location *b;
738 CORE_ADDR bp_addr = 0;
744 if (b->owner->type == bp_none)
745 warning (_("reading through apparently deleted breakpoint #%d?"),
748 if (b->loc_type != bp_loc_software_breakpoint)
752 /* Addresses and length of the part of the breakpoint that
754 bp_addr = b->target_info.placed_address;
755 bp_size = b->target_info.shadow_len;
757 /* bp isn't valid, or doesn't shadow memory. */
760 if (bp_addr + bp_size <= memaddr)
761 /* The breakpoint is entirely before the chunk of memory we
765 if (bp_addr >= memaddr + len)
766 /* The breakpoint is entirely after the chunk of memory we are
770 /* Offset within shadow_contents. */
771 if (bp_addr < memaddr)
773 /* Only copy the second part of the breakpoint. */
774 bp_size -= memaddr - bp_addr;
775 bptoffset = memaddr - bp_addr;
779 if (bp_addr + bp_size > memaddr + len)
781 /* Only copy the first part of the breakpoint. */
782 bp_size -= (bp_addr + bp_size) - (memaddr + len);
785 memcpy (buf + bp_addr - memaddr,
786 b->target_info.shadow_contents + bptoffset, bp_size);
791 /* A wrapper function for inserting catchpoints. */
793 insert_catchpoint (struct ui_out *uo, void *args)
795 struct breakpoint *b = (struct breakpoint *) args;
801 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
804 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
807 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
810 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
816 is_hardware_watchpoint (struct breakpoint *bpt)
818 return (bpt->type == bp_hardware_watchpoint
819 || bpt->type == bp_read_watchpoint
820 || bpt->type == bp_access_watchpoint);
823 /* Find the current value of a watchpoint on EXP. Return the value in
824 *VALP and *RESULTP and the chain of intermediate and final values
825 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
828 If an error occurs while evaluating the expression, *RESULTP will
829 be set to NULL. *RESULTP may be a lazy value, if the result could
830 not be read from memory. It is used to determine whether a value
831 is user-specified (we should watch the whole value) or intermediate
832 (we should watch only the bit used to locate the final value).
834 If the final value, or any intermediate value, could not be read
835 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
836 set to any referenced values. *VALP will never be a lazy value.
837 This is the value which we store in struct breakpoint.
839 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
840 value chain. The caller must free the values individually. If
841 VAL_CHAIN is NULL, all generated values will be left on the value
845 fetch_watchpoint_value (struct expression *exp, struct value **valp,
846 struct value **resultp, struct value **val_chain)
848 struct value *mark, *new_mark, *result;
856 /* Evaluate the expression. */
857 mark = value_mark ();
859 gdb_evaluate_expression (exp, &result);
860 new_mark = value_mark ();
861 if (mark == new_mark)
866 /* Make sure it's not lazy, so that after the target stops again we
867 have a non-lazy previous value to compare with. */
869 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
874 /* Return the chain of intermediate values. We use this to
875 decide which addresses to watch. */
876 *val_chain = new_mark;
877 value_release_to_mark (mark);
881 /* Assuming that B is a hardware watchpoint:
882 - Reparse watchpoint expression, is REPARSE is non-zero
883 - Evaluate expression and store the result in B->val
884 - Update the list of values that must be watched in B->loc.
886 If the watchpoint is disabled, do nothing. If this is
887 local watchpoint that is out of scope, delete it. */
889 update_watchpoint (struct breakpoint *b, int reparse)
891 int within_current_scope;
892 struct frame_id saved_frame_id;
893 struct bp_location *loc;
896 /* We don't free locations. They are stored in
897 bp_location_chain and update_global_locations will
898 eventually delete them and remove breakpoints if
902 if (b->disposition == disp_del_at_next_stop)
905 /* Save the current frame's ID so we can restore it after
906 evaluating the watchpoint expression on its own frame. */
907 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
908 took a frame parameter, so that we didn't have to change the
910 saved_frame_id = get_frame_id (get_selected_frame (NULL));
912 /* Determine if the watchpoint is within scope. */
913 if (b->exp_valid_block == NULL)
914 within_current_scope = 1;
917 struct frame_info *fi;
918 fi = frame_find_by_id (b->watchpoint_frame);
919 within_current_scope = (fi != NULL);
920 if (within_current_scope)
924 if (within_current_scope && reparse)
933 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
934 /* If the meaning of expression itself changed, the old value is
935 no longer relevant. We don't want to report a watchpoint hit
936 to the user when the old value and the new value may actually
937 be completely different objects. */
943 /* If we failed to parse the expression, for example because
944 it refers to a global variable in a not-yet-loaded shared library,
945 don't try to insert watchpoint. We don't automatically delete
946 such watchpoint, though, since failure to parse expression
947 is different from out-of-scope watchpoint. */
948 if (within_current_scope && b->exp)
950 struct value *val_chain, *v, *result, *next;
952 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
954 /* Avoid setting b->val if it's already set. The meaning of
955 b->val is 'the last value' user saw, and we should update
956 it only if we reported that last value to user. As it
957 happens, the code that reports it updates b->val directly. */
964 /* Look at each value on the value chain. */
965 for (v = val_chain; v; v = next)
967 /* If it's a memory location, and GDB actually needed
968 its contents to evaluate the expression, then we
969 must watch it. If the first value returned is
970 still lazy, that means an error occurred reading it;
971 watch it anyway in case it becomes readable. */
972 if (VALUE_LVAL (v) == lval_memory
973 && (v == val_chain || ! value_lazy (v)))
975 struct type *vtype = check_typedef (value_type (v));
977 /* We only watch structs and arrays if user asked
978 for it explicitly, never if they just happen to
979 appear in the middle of some value chain. */
981 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
982 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
986 struct bp_location *loc, **tmp;
988 addr = VALUE_ADDRESS (v) + value_offset (v);
989 len = TYPE_LENGTH (value_type (v));
991 if (b->type == bp_read_watchpoint)
993 else if (b->type == bp_access_watchpoint)
996 loc = allocate_bp_location (b, bp_hardware_watchpoint);
997 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1000 loc->address = addr;
1002 loc->watchpoint_type = type;
1006 next = value_next (v);
1011 /* We just regenerated the list of breakpoint locations.
1012 The new location does not have its condition field set to anything
1013 and therefore, we must always reparse the cond_string, independently
1014 of the value of the reparse flag. */
1015 if (b->cond_string != NULL)
1017 char *s = b->cond_string;
1018 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1021 else if (!within_current_scope)
1023 printf_filtered (_("\
1024 Hardware watchpoint %d deleted because the program has left the block \n\
1025 in which its expression is valid.\n"),
1027 if (b->related_breakpoint)
1028 b->related_breakpoint->disposition = disp_del_at_next_stop;
1029 b->disposition = disp_del_at_next_stop;
1032 /* Restore the selected frame. */
1033 select_frame (frame_find_by_id (saved_frame_id));
1037 /* Returns 1 iff breakpoint location should be
1038 inserted in the inferior. */
1040 should_be_inserted (struct bp_location *bpt)
1042 if (!breakpoint_enabled (bpt->owner))
1045 if (bpt->owner->disposition == disp_del_at_next_stop)
1048 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1054 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1055 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1056 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1058 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1059 method for each breakpoint or catchpoint type. */
1061 insert_bp_location (struct bp_location *bpt,
1062 struct ui_file *tmp_error_stream,
1063 int *disabled_breaks, int *process_warning,
1064 int *hw_breakpoint_error)
1068 if (!should_be_inserted (bpt) || bpt->inserted)
1071 /* Initialize the target-specific information. */
1072 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1073 bpt->target_info.placed_address = bpt->address;
1075 if (bpt->loc_type == bp_loc_software_breakpoint
1076 || bpt->loc_type == bp_loc_hardware_breakpoint)
1078 if (bpt->owner->type != bp_hardware_breakpoint)
1080 /* If the explicitly specified breakpoint type
1081 is not hardware breakpoint, check the memory map to see
1082 if the breakpoint address is in read only memory or not.
1083 Two important cases are:
1084 - location type is not hardware breakpoint, memory
1085 is readonly. We change the type of the location to
1086 hardware breakpoint.
1087 - location type is hardware breakpoint, memory is read-write.
1088 This means we've previously made the location hardware one, but
1089 then the memory map changed, so we undo.
1091 When breakpoints are removed, remove_breakpoints will
1092 use location types we've just set here, the only possible
1093 problem is that memory map has changed during running program,
1094 but it's not going to work anyway with current gdb. */
1095 struct mem_region *mr
1096 = lookup_mem_region (bpt->target_info.placed_address);
1100 if (automatic_hardware_breakpoints)
1103 enum bp_loc_type new_type;
1105 if (mr->attrib.mode != MEM_RW)
1106 new_type = bp_loc_hardware_breakpoint;
1108 new_type = bp_loc_software_breakpoint;
1110 if (new_type != bpt->loc_type)
1112 static int said = 0;
1113 bpt->loc_type = new_type;
1116 fprintf_filtered (gdb_stdout, _("\
1117 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1122 else if (bpt->loc_type == bp_loc_software_breakpoint
1123 && mr->attrib.mode != MEM_RW)
1124 warning (_("cannot set software breakpoint at readonly address %s"),
1125 paddr (bpt->address));
1129 /* First check to see if we have to handle an overlay. */
1130 if (overlay_debugging == ovly_off
1131 || bpt->section == NULL
1132 || !(section_is_overlay (bpt->section)))
1134 /* No overlay handling: just set the breakpoint. */
1136 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1137 val = target_insert_hw_breakpoint (&bpt->target_info);
1139 val = target_insert_breakpoint (&bpt->target_info);
1143 /* This breakpoint is in an overlay section.
1144 Shall we set a breakpoint at the LMA? */
1145 if (!overlay_events_enabled)
1147 /* Yes -- overlay event support is not active,
1148 so we must try to set a breakpoint at the LMA.
1149 This will not work for a hardware breakpoint. */
1150 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1151 warning (_("hardware breakpoint %d not supported in overlay!"),
1152 bpt->owner->number);
1155 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1157 /* Set a software (trap) breakpoint at the LMA. */
1158 bpt->overlay_target_info = bpt->target_info;
1159 bpt->overlay_target_info.placed_address = addr;
1160 val = target_insert_breakpoint (&bpt->overlay_target_info);
1162 fprintf_unfiltered (tmp_error_stream,
1163 "Overlay breakpoint %d failed: in ROM?",
1164 bpt->owner->number);
1167 /* Shall we set a breakpoint at the VMA? */
1168 if (section_is_mapped (bpt->section))
1170 /* Yes. This overlay section is mapped into memory. */
1171 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1172 val = target_insert_hw_breakpoint (&bpt->target_info);
1174 val = target_insert_breakpoint (&bpt->target_info);
1178 /* No. This breakpoint will not be inserted.
1179 No error, but do not mark the bp as 'inserted'. */
1186 /* Can't set the breakpoint. */
1187 if (solib_address (bpt->address))
1189 /* See also: disable_breakpoints_in_shlibs. */
1191 bpt->shlib_disabled = 1;
1192 if (!*disabled_breaks)
1194 fprintf_unfiltered (tmp_error_stream,
1195 "Cannot insert breakpoint %d.\n",
1196 bpt->owner->number);
1197 fprintf_unfiltered (tmp_error_stream,
1198 "Temporarily disabling shared library breakpoints:\n");
1200 *disabled_breaks = 1;
1201 fprintf_unfiltered (tmp_error_stream,
1202 "breakpoint #%d\n", bpt->owner->number);
1206 #ifdef ONE_PROCESS_WRITETEXT
1207 *process_warning = 1;
1209 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1211 *hw_breakpoint_error = 1;
1212 fprintf_unfiltered (tmp_error_stream,
1213 "Cannot insert hardware breakpoint %d.\n",
1214 bpt->owner->number);
1218 fprintf_unfiltered (tmp_error_stream,
1219 "Cannot insert breakpoint %d.\n",
1220 bpt->owner->number);
1221 fprintf_filtered (tmp_error_stream,
1222 "Error accessing memory address ");
1223 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1224 fprintf_filtered (tmp_error_stream, ": %s.\n",
1225 safe_strerror (val));
1236 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1237 /* NOTE drow/2003-09-08: This state only exists for removing
1238 watchpoints. It's not clear that it's necessary... */
1239 && bpt->owner->disposition != disp_del_at_next_stop)
1241 val = target_insert_watchpoint (bpt->address,
1243 bpt->watchpoint_type);
1244 bpt->inserted = (val != -1);
1247 else if (bpt->owner->type == bp_catch_fork
1248 || bpt->owner->type == bp_catch_vfork
1249 || bpt->owner->type == bp_catch_exec)
1251 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1252 bpt->owner, RETURN_MASK_ERROR);
1253 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1254 bpt->owner->number);
1256 bpt->owner->enable_state = bp_disabled;
1260 /* We've already printed an error message if there was a problem
1261 inserting this catchpoint, and we've disabled the catchpoint,
1262 so just return success. */
1269 /* Make sure all breakpoints are inserted in inferior.
1270 Throws exception on any error.
1271 A breakpoint that is already inserted won't be inserted
1272 again, so calling this function twice is safe. */
1274 insert_breakpoints (void)
1276 struct breakpoint *bpt;
1278 ALL_BREAKPOINTS (bpt)
1279 if (is_hardware_watchpoint (bpt))
1280 update_watchpoint (bpt, 0 /* don't reparse. */);
1282 update_global_location_list ();
1284 if (!always_inserted_mode && target_has_execution)
1285 /* update_global_location_list does not insert breakpoints
1286 when always_inserted_mode is not enabled. Explicitly
1288 insert_breakpoint_locations ();
1291 /* insert_breakpoints is used when starting or continuing the program.
1292 remove_breakpoints is used when the program stops.
1293 Both return zero if successful,
1294 or an `errno' value if could not write the inferior. */
1297 insert_breakpoint_locations (void)
1299 struct breakpoint *bpt;
1300 struct bp_location *b, *temp;
1303 int disabled_breaks = 0;
1304 int hw_breakpoint_error = 0;
1305 int process_warning = 0;
1307 struct ui_file *tmp_error_stream = mem_fileopen ();
1308 make_cleanup_ui_file_delete (tmp_error_stream);
1310 /* Explicitly mark the warning -- this will only be printed if
1311 there was an error. */
1312 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1314 ALL_BP_LOCATIONS_SAFE (b, temp)
1316 if (!should_be_inserted (b) || b->inserted)
1319 /* There is no point inserting thread-specific breakpoints if the
1320 thread no longer exists. */
1321 if (b->owner->thread != -1
1322 && !valid_thread_id (b->owner->thread))
1325 val = insert_bp_location (b, tmp_error_stream,
1326 &disabled_breaks, &process_warning,
1327 &hw_breakpoint_error);
1332 /* If we failed to insert all locations of a watchpoint,
1333 remove them, as half-inserted watchpoint is of limited use. */
1334 ALL_BREAKPOINTS (bpt)
1336 int some_failed = 0;
1337 struct bp_location *loc;
1339 if (!is_hardware_watchpoint (bpt))
1342 if (bpt->enable_state != bp_enabled)
1345 if (bpt->disposition == disp_del_at_next_stop)
1348 for (loc = bpt->loc; loc; loc = loc->next)
1356 for (loc = bpt->loc; loc; loc = loc->next)
1358 remove_breakpoint (loc, mark_uninserted);
1360 hw_breakpoint_error = 1;
1361 fprintf_unfiltered (tmp_error_stream,
1362 "Could not insert hardware watchpoint %d.\n",
1370 /* If a hardware breakpoint or watchpoint was inserted, add a
1371 message about possibly exhausted resources. */
1372 if (hw_breakpoint_error)
1374 fprintf_unfiltered (tmp_error_stream,
1375 "Could not insert hardware breakpoints:\n\
1376 You may have requested too many hardware breakpoints/watchpoints.\n");
1378 #ifdef ONE_PROCESS_WRITETEXT
1379 if (process_warning)
1380 fprintf_unfiltered (tmp_error_stream,
1381 "The same program may be running in another process.");
1383 target_terminal_ours_for_output ();
1384 error_stream (tmp_error_stream);
1389 remove_breakpoints (void)
1391 struct bp_location *b;
1394 ALL_BP_LOCATIONS (b)
1398 val = remove_breakpoint (b, mark_uninserted);
1407 remove_hw_watchpoints (void)
1409 struct bp_location *b;
1412 ALL_BP_LOCATIONS (b)
1414 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1416 val = remove_breakpoint (b, mark_uninserted);
1425 reattach_breakpoints (int pid)
1427 struct bp_location *b;
1429 struct cleanup *old_chain = save_inferior_ptid ();
1430 struct ui_file *tmp_error_stream = mem_fileopen ();
1431 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1433 make_cleanup_ui_file_delete (tmp_error_stream);
1435 inferior_ptid = pid_to_ptid (pid);
1436 ALL_BP_LOCATIONS (b)
1441 val = insert_bp_location (b, tmp_error_stream,
1442 &dummy1, &dummy2, &dummy3);
1445 do_cleanups (old_chain);
1450 do_cleanups (old_chain);
1455 restore_always_inserted_mode (void *p)
1457 always_inserted_mode = (uintptr_t) p;
1461 update_breakpoints_after_exec (void)
1463 struct breakpoint *b;
1464 struct breakpoint *temp;
1465 struct cleanup *cleanup;
1467 /* Doing this first prevents the badness of having delete_breakpoint()
1468 write a breakpoint's current "shadow contents" to lift the bp. That
1469 shadow is NOT valid after an exec()! */
1470 mark_breakpoints_out ();
1472 /* The binary we used to debug is now gone, and we're updating
1473 breakpoints for the new binary. Until we're done, we should not
1474 try to insert breakpoints. */
1475 cleanup = make_cleanup (restore_always_inserted_mode,
1476 (void *) (uintptr_t) always_inserted_mode);
1477 always_inserted_mode = 0;
1479 ALL_BREAKPOINTS_SAFE (b, temp)
1481 /* Solib breakpoints must be explicitly reset after an exec(). */
1482 if (b->type == bp_shlib_event)
1484 delete_breakpoint (b);
1488 /* Thread event breakpoints must be set anew after an exec(),
1489 as must overlay event breakpoints. */
1490 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1492 delete_breakpoint (b);
1496 /* Step-resume breakpoints are meaningless after an exec(). */
1497 if (b->type == bp_step_resume)
1499 delete_breakpoint (b);
1503 /* Don't delete an exec catchpoint, because else the inferior
1504 won't stop when it ought!
1506 Similarly, we probably ought to keep vfork catchpoints, 'cause
1507 on this target, we may not be able to stop when the vfork is
1508 seen, but only when the subsequent exec is seen. (And because
1509 deleting fork catchpoints here but not vfork catchpoints will
1510 seem mysterious to users, keep those too.) */
1511 if ((b->type == bp_catch_exec) ||
1512 (b->type == bp_catch_vfork) ||
1513 (b->type == bp_catch_fork))
1518 /* bp_finish is a special case. The only way we ought to be able
1519 to see one of these when an exec() has happened, is if the user
1520 caught a vfork, and then said "finish". Ordinarily a finish just
1521 carries them to the call-site of the current callee, by setting
1522 a temporary bp there and resuming. But in this case, the finish
1523 will carry them entirely through the vfork & exec.
1525 We don't want to allow a bp_finish to remain inserted now. But
1526 we can't safely delete it, 'cause finish_command has a handle to
1527 the bp on a bpstat, and will later want to delete it. There's a
1528 chance (and I've seen it happen) that if we delete the bp_finish
1529 here, that its storage will get reused by the time finish_command
1530 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1531 We really must allow finish_command to delete a bp_finish.
1533 In the absense of a general solution for the "how do we know
1534 it's safe to delete something others may have handles to?"
1535 problem, what we'll do here is just uninsert the bp_finish, and
1536 let finish_command delete it.
1538 (We know the bp_finish is "doomed" in the sense that it's
1539 momentary, and will be deleted as soon as finish_command sees
1540 the inferior stopped. So it doesn't matter that the bp's
1541 address is probably bogus in the new a.out, unlike e.g., the
1542 solib breakpoints.) */
1544 if (b->type == bp_finish)
1549 /* Without a symbolic address, we have little hope of the
1550 pre-exec() address meaning the same thing in the post-exec()
1552 if (b->addr_string == NULL)
1554 delete_breakpoint (b);
1558 /* FIXME what about longjmp breakpoints? Re-create them here? */
1559 create_overlay_event_breakpoint ("_ovly_debug_event");
1560 do_cleanups (cleanup);
1564 detach_breakpoints (int pid)
1566 struct bp_location *b;
1568 struct cleanup *old_chain = save_inferior_ptid ();
1570 if (pid == PIDGET (inferior_ptid))
1571 error (_("Cannot detach breakpoints of inferior_ptid"));
1573 /* Set inferior_ptid; remove_breakpoint uses this global. */
1574 inferior_ptid = pid_to_ptid (pid);
1575 ALL_BP_LOCATIONS (b)
1579 val = remove_breakpoint (b, mark_inserted);
1582 do_cleanups (old_chain);
1587 do_cleanups (old_chain);
1592 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1596 if (b->owner->enable_state == bp_permanent)
1597 /* Permanent breakpoints cannot be inserted or removed. */
1600 /* The type of none suggests that owner is actually deleted.
1601 This should not ever happen. */
1602 gdb_assert (b->owner->type != bp_none);
1604 if (b->loc_type == bp_loc_software_breakpoint
1605 || b->loc_type == bp_loc_hardware_breakpoint)
1607 /* "Normal" instruction breakpoint: either the standard
1608 trap-instruction bp (bp_breakpoint), or a
1609 bp_hardware_breakpoint. */
1611 /* First check to see if we have to handle an overlay. */
1612 if (overlay_debugging == ovly_off
1613 || b->section == NULL
1614 || !(section_is_overlay (b->section)))
1616 /* No overlay handling: just remove the breakpoint. */
1618 if (b->loc_type == bp_loc_hardware_breakpoint)
1619 val = target_remove_hw_breakpoint (&b->target_info);
1621 val = target_remove_breakpoint (&b->target_info);
1625 /* This breakpoint is in an overlay section.
1626 Did we set a breakpoint at the LMA? */
1627 if (!overlay_events_enabled)
1629 /* Yes -- overlay event support is not active, so we
1630 should have set a breakpoint at the LMA. Remove it.
1632 /* Ignore any failures: if the LMA is in ROM, we will
1633 have already warned when we failed to insert it. */
1634 if (b->loc_type == bp_loc_hardware_breakpoint)
1635 target_remove_hw_breakpoint (&b->overlay_target_info);
1637 target_remove_breakpoint (&b->overlay_target_info);
1639 /* Did we set a breakpoint at the VMA?
1640 If so, we will have marked the breakpoint 'inserted'. */
1643 /* Yes -- remove it. Previously we did not bother to
1644 remove the breakpoint if the section had been
1645 unmapped, but let's not rely on that being safe. We
1646 don't know what the overlay manager might do. */
1647 if (b->loc_type == bp_loc_hardware_breakpoint)
1648 val = target_remove_hw_breakpoint (&b->target_info);
1650 /* However, we should remove *software* breakpoints only
1651 if the section is still mapped, or else we overwrite
1652 wrong code with the saved shadow contents. */
1653 else if (section_is_mapped (b->section))
1654 val = target_remove_breakpoint (&b->target_info);
1660 /* No -- not inserted, so no need to remove. No error. */
1666 b->inserted = (is == mark_inserted);
1668 else if (b->loc_type == bp_loc_hardware_watchpoint)
1673 b->inserted = (is == mark_inserted);
1674 val = target_remove_watchpoint (b->address, b->length,
1675 b->watchpoint_type);
1677 /* Failure to remove any of the hardware watchpoints comes here. */
1678 if ((is == mark_uninserted) && (b->inserted))
1679 warning (_("Could not remove hardware watchpoint %d."),
1682 else if ((b->owner->type == bp_catch_fork ||
1683 b->owner->type == bp_catch_vfork ||
1684 b->owner->type == bp_catch_exec)
1685 && breakpoint_enabled (b->owner)
1689 switch (b->owner->type)
1692 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1694 case bp_catch_vfork:
1695 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1698 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1701 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1706 b->inserted = (is == mark_inserted);
1712 /* Clear the "inserted" flag in all breakpoints. */
1715 mark_breakpoints_out (void)
1717 struct bp_location *bpt;
1719 ALL_BP_LOCATIONS (bpt)
1723 /* Clear the "inserted" flag in all breakpoints and delete any
1724 breakpoints which should go away between runs of the program.
1726 Plus other such housekeeping that has to be done for breakpoints
1729 Note: this function gets called at the end of a run (by
1730 generic_mourn_inferior) and when a run begins (by
1731 init_wait_for_inferior). */
1736 breakpoint_init_inferior (enum inf_context context)
1738 struct breakpoint *b, *temp;
1739 struct bp_location *bpt;
1741 ALL_BP_LOCATIONS (bpt)
1744 ALL_BREAKPOINTS_SAFE (b, temp)
1749 case bp_watchpoint_scope:
1751 /* If the call dummy breakpoint is at the entry point it will
1752 cause problems when the inferior is rerun, so we better
1755 Also get rid of scope breakpoints. */
1756 delete_breakpoint (b);
1760 case bp_hardware_watchpoint:
1761 case bp_read_watchpoint:
1762 case bp_access_watchpoint:
1764 /* Likewise for watchpoints on local expressions. */
1765 if (b->exp_valid_block != NULL)
1766 delete_breakpoint (b);
1767 else if (context == inf_starting)
1769 /* Reset val field to force reread of starting value
1770 in insert_breakpoints. */
1772 value_free (b->val);
1783 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1784 exists at PC. It returns ordinary_breakpoint_here if it's an
1785 ordinary breakpoint, or permanent_breakpoint_here if it's a
1786 permanent breakpoint.
1787 - When continuing from a location with an ordinary breakpoint, we
1788 actually single step once before calling insert_breakpoints.
1789 - When continuing from a localion with a permanent breakpoint, we
1790 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1791 the target, to advance the PC past the breakpoint. */
1793 enum breakpoint_here
1794 breakpoint_here_p (CORE_ADDR pc)
1796 const struct bp_location *bpt;
1797 int any_breakpoint_here = 0;
1799 ALL_BP_LOCATIONS (bpt)
1801 if (bpt->loc_type != bp_loc_software_breakpoint
1802 && bpt->loc_type != bp_loc_hardware_breakpoint)
1805 if ((breakpoint_enabled (bpt->owner)
1806 || bpt->owner->enable_state == bp_permanent)
1807 && bpt->address == pc) /* bp is enabled and matches pc */
1809 if (overlay_debugging
1810 && section_is_overlay (bpt->section)
1811 && !section_is_mapped (bpt->section))
1812 continue; /* unmapped overlay -- can't be a match */
1813 else if (bpt->owner->enable_state == bp_permanent)
1814 return permanent_breakpoint_here;
1816 any_breakpoint_here = 1;
1820 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1824 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1825 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1826 This does not check for single-step breakpoints, which are
1827 inserted and removed using direct target manipulation. */
1830 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1832 const struct bp_location *bpt;
1834 ALL_BP_LOCATIONS (bpt)
1836 if (bpt->loc_type != bp_loc_software_breakpoint
1837 && bpt->loc_type != bp_loc_hardware_breakpoint)
1841 && bpt->address == pc) /* bp is inserted and matches pc */
1843 if (overlay_debugging
1844 && section_is_overlay (bpt->section)
1845 && !section_is_mapped (bpt->section))
1846 continue; /* unmapped overlay -- can't be a match */
1854 /* Returns non-zero iff there's either regular breakpoint
1855 or a single step breakpoint inserted at PC. */
1858 breakpoint_inserted_here_p (CORE_ADDR pc)
1860 if (regular_breakpoint_inserted_here_p (pc))
1863 if (single_step_breakpoint_inserted_here_p (pc))
1869 /* This function returns non-zero iff there is a software breakpoint
1873 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1875 const struct bp_location *bpt;
1876 int any_breakpoint_here = 0;
1878 ALL_BP_LOCATIONS (bpt)
1880 if (bpt->loc_type != bp_loc_software_breakpoint)
1884 && bpt->address == pc) /* bp is enabled and matches pc */
1886 if (overlay_debugging
1887 && section_is_overlay (bpt->section)
1888 && !section_is_mapped (bpt->section))
1889 continue; /* unmapped overlay -- can't be a match */
1895 /* Also check for software single-step breakpoints. */
1896 if (single_step_breakpoint_inserted_here_p (pc))
1902 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1903 PC is valid for process/thread PTID. */
1906 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1908 const struct bp_location *bpt;
1911 thread = pid_to_thread_id (ptid);
1913 ALL_BP_LOCATIONS (bpt)
1915 if (bpt->loc_type != bp_loc_software_breakpoint
1916 && bpt->loc_type != bp_loc_hardware_breakpoint)
1919 if ((breakpoint_enabled (bpt->owner)
1920 || bpt->owner->enable_state == bp_permanent)
1921 && bpt->address == pc
1922 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1924 if (overlay_debugging
1925 && section_is_overlay (bpt->section)
1926 && !section_is_mapped (bpt->section))
1927 continue; /* unmapped overlay -- can't be a match */
1937 /* bpstat stuff. External routines' interfaces are documented
1941 ep_is_catchpoint (struct breakpoint *ep)
1944 (ep->type == bp_catch_load)
1945 || (ep->type == bp_catch_unload)
1946 || (ep->type == bp_catch_fork)
1947 || (ep->type == bp_catch_vfork)
1948 || (ep->type == bp_catch_exec);
1950 /* ??rehrauer: Add more kinds here, as are implemented... */
1954 ep_is_shlib_catchpoint (struct breakpoint *ep)
1957 (ep->type == bp_catch_load)
1958 || (ep->type == bp_catch_unload);
1962 bpstat_free (bpstat bs)
1964 if (bs->old_val != NULL)
1965 value_free (bs->old_val);
1966 free_command_lines (&bs->commands);
1970 /* Clear a bpstat so that it says we are not at any breakpoint.
1971 Also free any storage that is part of a bpstat. */
1974 bpstat_clear (bpstat *bsp)
1991 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1992 is part of the bpstat is copied as well. */
1995 bpstat_copy (bpstat bs)
1999 bpstat retval = NULL;
2004 for (; bs != NULL; bs = bs->next)
2006 tmp = (bpstat) xmalloc (sizeof (*tmp));
2007 memcpy (tmp, bs, sizeof (*tmp));
2008 if (bs->commands != NULL)
2009 tmp->commands = copy_command_lines (bs->commands);
2010 if (bs->old_val != NULL)
2011 tmp->old_val = value_copy (bs->old_val);
2014 /* This is the first thing in the chain. */
2024 /* Find the bpstat associated with this breakpoint */
2027 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2032 for (; bsp != NULL; bsp = bsp->next)
2034 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2040 /* Find a step_resume breakpoint associated with this bpstat.
2041 (If there are multiple step_resume bp's on the list, this function
2042 will arbitrarily pick one.)
2044 It is an error to use this function if BPSTAT doesn't contain a
2045 step_resume breakpoint.
2047 See wait_for_inferior's use of this function. */
2049 bpstat_find_step_resume_breakpoint (bpstat bsp)
2053 gdb_assert (bsp != NULL);
2055 current_thread = pid_to_thread_id (inferior_ptid);
2057 for (; bsp != NULL; bsp = bsp->next)
2059 if ((bsp->breakpoint_at != NULL) &&
2060 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2061 (bsp->breakpoint_at->owner->thread == current_thread ||
2062 bsp->breakpoint_at->owner->thread == -1))
2063 return bsp->breakpoint_at->owner;
2066 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2070 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2071 at. *BSP upon return is a bpstat which points to the remaining
2072 breakpoints stopped at (but which is not guaranteed to be good for
2073 anything but further calls to bpstat_num).
2074 Return 0 if passed a bpstat which does not indicate any breakpoints.
2075 Return -1 if stopped at a breakpoint that has been deleted since
2077 Return 1 otherwise. */
2080 bpstat_num (bpstat *bsp, int *num)
2082 struct breakpoint *b;
2085 return 0; /* No more breakpoint values */
2087 /* We assume we'll never have several bpstats that
2088 correspond to a single breakpoint -- otherwise,
2089 this function might return the same number more
2090 than once and this will look ugly. */
2091 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2092 *bsp = (*bsp)->next;
2094 return -1; /* breakpoint that's been deleted since */
2096 *num = b->number; /* We have its number */
2100 /* Modify BS so that the actions will not be performed. */
2103 bpstat_clear_actions (bpstat bs)
2105 for (; bs != NULL; bs = bs->next)
2107 free_command_lines (&bs->commands);
2108 if (bs->old_val != NULL)
2110 value_free (bs->old_val);
2116 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2118 cleanup_executing_breakpoints (void *ignore)
2120 executing_breakpoint_commands = 0;
2123 /* Execute all the commands associated with all the breakpoints at this
2124 location. Any of these commands could cause the process to proceed
2125 beyond this point, etc. We look out for such changes by checking
2126 the global "breakpoint_proceeded" after each command. */
2129 bpstat_do_actions (bpstat *bsp)
2132 struct cleanup *old_chain;
2134 /* Avoid endless recursion if a `source' command is contained
2136 if (executing_breakpoint_commands)
2139 executing_breakpoint_commands = 1;
2140 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2143 /* Note that (as of this writing), our callers all appear to
2144 be passing us the address of global stop_bpstat. And, if
2145 our calls to execute_control_command cause the inferior to
2146 proceed, that global (and hence, *bsp) will change.
2148 We must be careful to not touch *bsp unless the inferior
2149 has not proceeded. */
2151 /* This pointer will iterate over the list of bpstat's. */
2154 breakpoint_proceeded = 0;
2155 for (; bs != NULL; bs = bs->next)
2157 struct command_line *cmd;
2158 struct cleanup *this_cmd_tree_chain;
2160 /* Take ownership of the BSP's command tree, if it has one.
2162 The command tree could legitimately contain commands like
2163 'step' and 'next', which call clear_proceed_status, which
2164 frees stop_bpstat's command tree. To make sure this doesn't
2165 free the tree we're executing out from under us, we need to
2166 take ownership of the tree ourselves. Since a given bpstat's
2167 commands are only executed once, we don't need to copy it; we
2168 can clear the pointer in the bpstat, and make sure we free
2169 the tree when we're done. */
2172 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2176 execute_control_command (cmd);
2178 if (breakpoint_proceeded)
2184 /* We can free this command tree now. */
2185 do_cleanups (this_cmd_tree_chain);
2187 if (breakpoint_proceeded)
2189 if (target_can_async_p ())
2190 /* If we are in async mode, then the target might
2191 be still running, not stopped at any breakpoint,
2192 so nothing for us to do here -- just return to
2196 /* In sync mode, when execute_control_command returns
2197 we're already standing on the next breakpoint.
2198 Breakpoint commands for that stop were not run,
2199 since execute_command does not run breakpoint
2200 commands -- only command_line_handler does, but
2201 that one is not involved in execution of breakpoint
2202 commands. So, we can now execute breakpoint commands.
2203 There's an implicit assumption that we're called with
2204 stop_bpstat, so our parameter is the new bpstat to
2206 It should be noted that making execute_command do
2207 bpstat actions is not an option -- in this case we'll
2208 have recursive invocation of bpstat for each breakpoint
2209 with a command, and can easily blow up GDB stack. */
2213 do_cleanups (old_chain);
2216 /* Print out the (old or new) value associated with a watchpoint. */
2219 watchpoint_value_print (struct value *val, struct ui_file *stream)
2222 fprintf_unfiltered (stream, _("<unreadable>"));
2224 value_print (val, stream, 0, Val_pretty_default);
2227 /* This is the normal print function for a bpstat. In the future,
2228 much of this logic could (should?) be moved to bpstat_stop_status,
2229 by having it set different print_it values.
2231 Current scheme: When we stop, bpstat_print() is called. It loops
2232 through the bpstat list of things causing this stop, calling the
2233 print_bp_stop_message function on each one. The behavior of the
2234 print_bp_stop_message function depends on the print_it field of
2235 bpstat. If such field so indicates, call this function here.
2237 Return values from this routine (ultimately used by bpstat_print()
2238 and normal_stop() to decide what to do):
2239 PRINT_NOTHING: Means we already printed all we needed to print,
2240 don't print anything else.
2241 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2242 that something to be followed by a location.
2243 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2244 that something to be followed by a location.
2245 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2248 static enum print_stop_action
2249 print_it_typical (bpstat bs)
2251 struct cleanup *old_chain, *ui_out_chain;
2252 struct breakpoint *b;
2253 const struct bp_location *bl;
2254 struct ui_stream *stb;
2256 stb = ui_out_stream_new (uiout);
2257 old_chain = make_cleanup_ui_out_stream_delete (stb);
2258 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2259 which has since been deleted. */
2260 if (bs->breakpoint_at == NULL)
2261 return PRINT_UNKNOWN;
2262 bl = bs->breakpoint_at;
2268 case bp_hardware_breakpoint:
2269 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2270 if (bl->address != bl->requested_address)
2271 breakpoint_adjustment_warning (bl->requested_address,
2274 annotate_breakpoint (b->number);
2276 ui_out_text (uiout, "\nTemporary breakpoint ");
2278 ui_out_text (uiout, "\nBreakpoint ");
2279 if (ui_out_is_mi_like_p (uiout))
2281 ui_out_field_string (uiout, "reason",
2282 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2283 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2285 ui_out_field_int (uiout, "bkptno", b->number);
2286 ui_out_text (uiout, ", ");
2287 return PRINT_SRC_AND_LOC;
2290 case bp_shlib_event:
2291 /* Did we stop because the user set the stop_on_solib_events
2292 variable? (If so, we report this as a generic, "Stopped due
2293 to shlib event" message.) */
2294 printf_filtered (_("Stopped due to shared library event\n"));
2295 return PRINT_NOTHING;
2298 case bp_thread_event:
2299 /* Not sure how we will get here.
2300 GDB should not stop for these breakpoints. */
2301 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2302 return PRINT_NOTHING;
2305 case bp_overlay_event:
2306 /* By analogy with the thread event, GDB should not stop for these. */
2307 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2308 return PRINT_NOTHING;
2312 annotate_catchpoint (b->number);
2313 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2315 b->triggered_dll_pathname);
2316 return PRINT_SRC_AND_LOC;
2319 case bp_catch_unload:
2320 annotate_catchpoint (b->number);
2321 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2323 b->triggered_dll_pathname);
2324 return PRINT_SRC_AND_LOC;
2328 annotate_catchpoint (b->number);
2329 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2331 b->forked_inferior_pid);
2332 return PRINT_SRC_AND_LOC;
2335 case bp_catch_vfork:
2336 annotate_catchpoint (b->number);
2337 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2339 b->forked_inferior_pid);
2340 return PRINT_SRC_AND_LOC;
2344 annotate_catchpoint (b->number);
2345 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2348 return PRINT_SRC_AND_LOC;
2352 case bp_hardware_watchpoint:
2353 annotate_watchpoint (b->number);
2354 if (ui_out_is_mi_like_p (uiout))
2357 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2359 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2360 ui_out_text (uiout, "\nOld value = ");
2361 watchpoint_value_print (bs->old_val, stb->stream);
2362 ui_out_field_stream (uiout, "old", stb);
2363 ui_out_text (uiout, "\nNew value = ");
2364 watchpoint_value_print (b->val, stb->stream);
2365 ui_out_field_stream (uiout, "new", stb);
2366 do_cleanups (ui_out_chain);
2367 ui_out_text (uiout, "\n");
2368 /* More than one watchpoint may have been triggered. */
2369 return PRINT_UNKNOWN;
2372 case bp_read_watchpoint:
2373 if (ui_out_is_mi_like_p (uiout))
2376 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2378 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2379 ui_out_text (uiout, "\nValue = ");
2380 watchpoint_value_print (b->val, stb->stream);
2381 ui_out_field_stream (uiout, "value", stb);
2382 do_cleanups (ui_out_chain);
2383 ui_out_text (uiout, "\n");
2384 return PRINT_UNKNOWN;
2387 case bp_access_watchpoint:
2388 if (bs->old_val != NULL)
2390 annotate_watchpoint (b->number);
2391 if (ui_out_is_mi_like_p (uiout))
2394 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2396 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2397 ui_out_text (uiout, "\nOld value = ");
2398 watchpoint_value_print (bs->old_val, stb->stream);
2399 ui_out_field_stream (uiout, "old", stb);
2400 ui_out_text (uiout, "\nNew value = ");
2405 if (ui_out_is_mi_like_p (uiout))
2408 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2409 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2410 ui_out_text (uiout, "\nValue = ");
2412 watchpoint_value_print (b->val, stb->stream);
2413 ui_out_field_stream (uiout, "new", stb);
2414 do_cleanups (ui_out_chain);
2415 ui_out_text (uiout, "\n");
2416 return PRINT_UNKNOWN;
2419 /* Fall through, we don't deal with these types of breakpoints
2423 if (ui_out_is_mi_like_p (uiout))
2426 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2427 return PRINT_UNKNOWN;
2431 if (ui_out_is_mi_like_p (uiout))
2434 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2435 return PRINT_UNKNOWN;
2440 case bp_longjmp_resume:
2441 case bp_step_resume:
2442 case bp_watchpoint_scope:
2445 return PRINT_UNKNOWN;
2449 /* Generic routine for printing messages indicating why we
2450 stopped. The behavior of this function depends on the value
2451 'print_it' in the bpstat structure. Under some circumstances we
2452 may decide not to print anything here and delegate the task to
2455 static enum print_stop_action
2456 print_bp_stop_message (bpstat bs)
2458 switch (bs->print_it)
2461 /* Nothing should be printed for this bpstat entry. */
2462 return PRINT_UNKNOWN;
2466 /* We still want to print the frame, but we already printed the
2467 relevant messages. */
2468 return PRINT_SRC_AND_LOC;
2471 case print_it_normal:
2473 const struct bp_location *bl = bs->breakpoint_at;
2474 struct breakpoint *b = bl ? bl->owner : NULL;
2476 /* Normal case. Call the breakpoint's print_it method, or
2477 print_it_typical. */
2478 /* FIXME: how breakpoint can ever be NULL here? */
2479 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2480 return b->ops->print_it (b);
2482 return print_it_typical (bs);
2487 internal_error (__FILE__, __LINE__,
2488 _("print_bp_stop_message: unrecognized enum value"));
2493 /* Print a message indicating what happened. This is called from
2494 normal_stop(). The input to this routine is the head of the bpstat
2495 list - a list of the eventpoints that caused this stop. This
2496 routine calls the generic print routine for printing a message
2497 about reasons for stopping. This will print (for example) the
2498 "Breakpoint n," part of the output. The return value of this
2501 PRINT_UNKNOWN: Means we printed nothing
2502 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2503 code to print the location. An example is
2504 "Breakpoint 1, " which should be followed by
2506 PRINT_SRC_ONLY: Means we printed something, but there is no need
2507 to also print the location part of the message.
2508 An example is the catch/throw messages, which
2509 don't require a location appended to the end.
2510 PRINT_NOTHING: We have done some printing and we don't need any
2511 further info to be printed.*/
2513 enum print_stop_action
2514 bpstat_print (bpstat bs)
2518 /* Maybe another breakpoint in the chain caused us to stop.
2519 (Currently all watchpoints go on the bpstat whether hit or not.
2520 That probably could (should) be changed, provided care is taken
2521 with respect to bpstat_explains_signal). */
2522 for (; bs; bs = bs->next)
2524 val = print_bp_stop_message (bs);
2525 if (val == PRINT_SRC_ONLY
2526 || val == PRINT_SRC_AND_LOC
2527 || val == PRINT_NOTHING)
2531 /* We reached the end of the chain, or we got a null BS to start
2532 with and nothing was printed. */
2533 return PRINT_UNKNOWN;
2536 /* Evaluate the expression EXP and return 1 if value is zero.
2537 This is used inside a catch_errors to evaluate the breakpoint condition.
2538 The argument is a "struct expression *" that has been cast to char * to
2539 make it pass through catch_errors. */
2542 breakpoint_cond_eval (void *exp)
2544 struct value *mark = value_mark ();
2545 int i = !value_true (evaluate_expression ((struct expression *) exp));
2546 value_free_to_mark (mark);
2550 /* Allocate a new bpstat and chain it to the current one. */
2553 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2557 bs = (bpstat) xmalloc (sizeof (*bs));
2559 bs->breakpoint_at = bl;
2560 /* If the condition is false, etc., don't do the commands. */
2561 bs->commands = NULL;
2563 bs->print_it = print_it_normal;
2567 /* The target has stopped with waitstatus WS. Check if any hardware
2568 watchpoints have triggered, according to the target. */
2571 watchpoints_triggered (struct target_waitstatus *ws)
2573 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2575 struct breakpoint *b;
2577 if (!stopped_by_watchpoint)
2579 /* We were not stopped by a watchpoint. Mark all watchpoints
2580 as not triggered. */
2582 if (b->type == bp_hardware_watchpoint
2583 || b->type == bp_read_watchpoint
2584 || b->type == bp_access_watchpoint)
2585 b->watchpoint_triggered = watch_triggered_no;
2590 if (!target_stopped_data_address (¤t_target, &addr))
2592 /* We were stopped by a watchpoint, but we don't know where.
2593 Mark all watchpoints as unknown. */
2595 if (b->type == bp_hardware_watchpoint
2596 || b->type == bp_read_watchpoint
2597 || b->type == bp_access_watchpoint)
2598 b->watchpoint_triggered = watch_triggered_unknown;
2600 return stopped_by_watchpoint;
2603 /* The target could report the data address. Mark watchpoints
2604 affected by this data address as triggered, and all others as not
2608 if (b->type == bp_hardware_watchpoint
2609 || b->type == bp_read_watchpoint
2610 || b->type == bp_access_watchpoint)
2612 struct bp_location *loc;
2615 b->watchpoint_triggered = watch_triggered_no;
2616 for (loc = b->loc; loc; loc = loc->next)
2617 /* Exact match not required. Within range is
2619 if (addr >= loc->address
2620 && addr < loc->address + loc->length)
2622 b->watchpoint_triggered = watch_triggered_yes;
2630 /* Possible return values for watchpoint_check (this can't be an enum
2631 because of check_errors). */
2632 /* The watchpoint has been deleted. */
2633 #define WP_DELETED 1
2634 /* The value has changed. */
2635 #define WP_VALUE_CHANGED 2
2636 /* The value has not changed. */
2637 #define WP_VALUE_NOT_CHANGED 3
2639 #define BP_TEMPFLAG 1
2640 #define BP_HARDWAREFLAG 2
2642 /* Check watchpoint condition. */
2645 watchpoint_check (void *p)
2647 bpstat bs = (bpstat) p;
2648 struct breakpoint *b;
2649 struct frame_info *fr;
2650 int within_current_scope;
2652 b = bs->breakpoint_at->owner;
2654 if (b->exp_valid_block == NULL)
2655 within_current_scope = 1;
2658 /* There is no current frame at this moment. If we're going to have
2659 any chance of handling watchpoints on local variables, we'll need
2660 the frame chain (so we can determine if we're in scope). */
2661 reinit_frame_cache ();
2662 fr = frame_find_by_id (b->watchpoint_frame);
2663 within_current_scope = (fr != NULL);
2665 /* If we've gotten confused in the unwinder, we might have
2666 returned a frame that can't describe this variable. */
2667 if (within_current_scope
2668 && block_function (b->exp_valid_block) != get_frame_function (fr))
2669 within_current_scope = 0;
2671 /* in_function_epilogue_p() returns a non-zero value if we're still
2672 in the function but the stack frame has already been invalidated.
2673 Since we can't rely on the values of local variables after the
2674 stack has been destroyed, we are treating the watchpoint in that
2675 state as `not changed' without further checking.
2677 vinschen/2003-09-04: The former implementation left out the case
2678 that the watchpoint frame couldn't be found by frame_find_by_id()
2679 because the current PC is currently in an epilogue. Calling
2680 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2681 if ((!within_current_scope || fr == get_current_frame ())
2682 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2683 return WP_VALUE_NOT_CHANGED;
2684 if (fr && within_current_scope)
2685 /* If we end up stopping, the current frame will get selected
2686 in normal_stop. So this call to select_frame won't affect
2691 if (within_current_scope)
2693 /* We use value_{,free_to_}mark because it could be a
2694 *long* time before we return to the command level and
2695 call free_all_values. We can't call free_all_values because
2696 we might be in the middle of evaluating a function call. */
2698 struct value *mark = value_mark ();
2699 struct value *new_val;
2701 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2702 if ((b->val != NULL) != (new_val != NULL)
2703 || (b->val != NULL && !value_equal (b->val, new_val)))
2705 if (new_val != NULL)
2707 release_value (new_val);
2708 value_free_to_mark (mark);
2710 bs->old_val = b->val;
2713 /* We will stop here */
2714 return WP_VALUE_CHANGED;
2718 /* Nothing changed, don't do anything. */
2719 value_free_to_mark (mark);
2720 /* We won't stop here */
2721 return WP_VALUE_NOT_CHANGED;
2726 /* This seems like the only logical thing to do because
2727 if we temporarily ignored the watchpoint, then when
2728 we reenter the block in which it is valid it contains
2729 garbage (in the case of a function, it may have two
2730 garbage values, one before and one after the prologue).
2731 So we can't even detect the first assignment to it and
2732 watch after that (since the garbage may or may not equal
2733 the first value assigned). */
2734 /* We print all the stop information in print_it_typical(), but
2735 in this case, by the time we call print_it_typical() this bp
2736 will be deleted already. So we have no choice but print the
2737 information here. */
2738 if (ui_out_is_mi_like_p (uiout))
2740 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2741 ui_out_text (uiout, "\nWatchpoint ");
2742 ui_out_field_int (uiout, "wpnum", b->number);
2743 ui_out_text (uiout, " deleted because the program has left the block in\n\
2744 which its expression is valid.\n");
2746 if (b->related_breakpoint)
2747 b->related_breakpoint->disposition = disp_del_at_next_stop;
2748 b->disposition = disp_del_at_next_stop;
2754 /* Return true if it looks like target has stopped due to hitting
2755 breakpoint location BL. This function does not check if we
2756 should stop, only if BL explains the stop. */
2758 bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2760 struct breakpoint *b = bl->owner;
2762 if (b->type != bp_watchpoint
2763 && b->type != bp_hardware_watchpoint
2764 && b->type != bp_read_watchpoint
2765 && b->type != bp_access_watchpoint
2766 && b->type != bp_hardware_breakpoint
2767 && b->type != bp_catch_fork
2768 && b->type != bp_catch_vfork
2769 && b->type != bp_catch_exec) /* a non-watchpoint bp */
2771 if (bl->address != bp_addr) /* address doesn't match */
2773 if (overlay_debugging /* unmapped overlay section */
2774 && section_is_overlay (bl->section)
2775 && !section_is_mapped (bl->section))
2779 /* Continuable hardware watchpoints are treated as non-existent if the
2780 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2781 some data address). Otherwise gdb won't stop on a break instruction
2782 in the code (not from a breakpoint) when a hardware watchpoint has
2783 been defined. Also skip watchpoints which we know did not trigger
2784 (did not match the data address). */
2786 if ((b->type == bp_hardware_watchpoint
2787 || b->type == bp_read_watchpoint
2788 || b->type == bp_access_watchpoint)
2789 && b->watchpoint_triggered == watch_triggered_no)
2792 if (b->type == bp_hardware_breakpoint)
2794 if (bl->address != bp_addr)
2796 if (overlay_debugging /* unmapped overlay section */
2797 && section_is_overlay (bl->section)
2798 && !section_is_mapped (bl->section))
2802 /* Is this a catchpoint of a load or unload? If so, did we
2803 get a load or unload of the specified library? If not,
2805 if ((b->type == bp_catch_load)
2806 #if defined(SOLIB_HAVE_LOAD_EVENT)
2807 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2808 || ((b->dll_pathname != NULL)
2809 && (strcmp (b->dll_pathname,
2810 SOLIB_LOADED_LIBRARY_PATHNAME (
2811 PIDGET (inferior_ptid)))
2817 if ((b->type == bp_catch_unload)
2818 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2819 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2820 || ((b->dll_pathname != NULL)
2821 && (strcmp (b->dll_pathname,
2822 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2823 PIDGET (inferior_ptid)))
2829 if ((b->type == bp_catch_fork)
2830 && !inferior_has_forked (PIDGET (inferior_ptid),
2831 &b->forked_inferior_pid))
2834 if ((b->type == bp_catch_vfork)
2835 && !inferior_has_vforked (PIDGET (inferior_ptid),
2836 &b->forked_inferior_pid))
2839 if ((b->type == bp_catch_exec)
2840 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2846 /* If BS refers to a watchpoint, determine if the watched values
2847 has actually changed, and we should stop. If not, set BS->stop
2850 bpstat_check_watchpoint (bpstat bs)
2852 const struct bp_location *bl = bs->breakpoint_at;
2853 struct breakpoint *b = bl->owner;
2855 if (b->type == bp_watchpoint
2856 || b->type == bp_read_watchpoint
2857 || b->type == bp_access_watchpoint
2858 || b->type == bp_hardware_watchpoint)
2862 int must_check_value = 0;
2864 if (b->type == bp_watchpoint)
2865 /* For a software watchpoint, we must always check the
2867 must_check_value = 1;
2868 else if (b->watchpoint_triggered == watch_triggered_yes)
2869 /* We have a hardware watchpoint (read, write, or access)
2870 and the target earlier reported an address watched by
2872 must_check_value = 1;
2873 else if (b->watchpoint_triggered == watch_triggered_unknown
2874 && b->type == bp_hardware_watchpoint)
2875 /* We were stopped by a hardware watchpoint, but the target could
2876 not report the data address. We must check the watchpoint's
2877 value. Access and read watchpoints are out of luck; without
2878 a data address, we can't figure it out. */
2879 must_check_value = 1;
2881 if (must_check_value)
2883 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2885 struct cleanup *cleanups = make_cleanup (xfree, message);
2886 int e = catch_errors (watchpoint_check, bs, message,
2888 do_cleanups (cleanups);
2892 /* We've already printed what needs to be printed. */
2893 bs->print_it = print_it_done;
2896 case WP_VALUE_CHANGED:
2897 if (b->type == bp_read_watchpoint)
2899 /* Don't stop: read watchpoints shouldn't fire if
2900 the value has changed. This is for targets
2901 which cannot set read-only watchpoints. */
2902 bs->print_it = print_it_noop;
2906 case WP_VALUE_NOT_CHANGED:
2907 if (b->type == bp_hardware_watchpoint
2908 || b->type == bp_watchpoint)
2910 /* Don't stop: write watchpoints shouldn't fire if
2911 the value hasn't changed. */
2912 bs->print_it = print_it_noop;
2920 /* Error from catch_errors. */
2921 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2922 if (b->related_breakpoint)
2923 b->related_breakpoint->disposition = disp_del_at_next_stop;
2924 b->disposition = disp_del_at_next_stop;
2925 /* We've already printed what needs to be printed. */
2926 bs->print_it = print_it_done;
2930 else /* must_check_value == 0 */
2932 /* This is a case where some watchpoint(s) triggered, but
2933 not at the address of this watchpoint, or else no
2934 watchpoint triggered after all. So don't print
2935 anything for this watchpoint. */
2936 bs->print_it = print_it_noop;
2943 /* Check conditions (condition proper, frame, thread and ignore count)
2944 of breakpoint referred to by BS. If we should not stop for this
2945 breakpoint, set BS->stop to 0. */
2947 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
2949 int thread_id = pid_to_thread_id (ptid);
2950 const struct bp_location *bl = bs->breakpoint_at;
2951 struct breakpoint *b = bl->owner;
2953 if (frame_id_p (b->frame_id)
2954 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2958 int value_is_zero = 0;
2960 /* If this is a scope breakpoint, mark the associated
2961 watchpoint as triggered so that we will handle the
2962 out-of-scope event. We'll get to the watchpoint next
2964 if (b->type == bp_watchpoint_scope)
2965 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2967 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2969 /* Need to select the frame, with all that implies
2970 so that the conditions will have the right context. */
2971 select_frame (get_current_frame ());
2973 = catch_errors (breakpoint_cond_eval, (bl->cond),
2974 "Error in testing breakpoint condition:\n",
2976 /* FIXME-someday, should give breakpoint # */
2979 if (bl->cond && value_is_zero)
2983 else if (b->thread != -1 && b->thread != thread_id)
2987 else if (b->ignore_count > 0)
2990 annotate_ignore_count_change ();
2992 /* Increase the hit count even though we don't
3000 /* Get a bpstat associated with having just stopped at address
3001 BP_ADDR in thread PTID.
3003 Determine whether we stopped at a breakpoint, etc, or whether we
3004 don't understand this stop. Result is a chain of bpstat's such that:
3006 if we don't understand the stop, the result is a null pointer.
3008 if we understand why we stopped, the result is not null.
3010 Each element of the chain refers to a particular breakpoint or
3011 watchpoint at which we have stopped. (We may have stopped for
3012 several reasons concurrently.)
3014 Each element of the chain has valid next, breakpoint_at,
3015 commands, FIXME??? fields. */
3018 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3020 struct breakpoint *b = NULL;
3021 const struct bp_location *bl;
3022 /* Root of the chain of bpstat's */
3023 struct bpstats root_bs[1];
3024 /* Pointer to the last thing in the chain currently. */
3025 bpstat bs = root_bs;
3027 ALL_BP_LOCATIONS (bl)
3031 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3034 /* For hardware watchpoints, we look only at the first location.
3035 The watchpoint_check function will work on entire expression,
3036 not the individual locations. For read watchopints, the
3037 watchpoints_triggered function have checked all locations
3040 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3043 if (!bpstat_check_location (bl, bp_addr))
3046 /* Come here if it's a watchpoint, or if the break address matches */
3048 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3050 /* Assume we stop. Should we find watchpoint that is not actually
3051 triggered, or if condition of breakpoint is false, we'll reset
3056 bpstat_check_watchpoint (bs);
3060 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3061 /* We do not stop for these. */
3064 bpstat_check_breakpoint_conditions (bs, ptid);
3070 /* We will stop here */
3071 if (b->disposition == disp_disable)
3073 b->enable_state = bp_disabled;
3074 update_global_location_list ();
3078 bs->commands = b->commands;
3080 (strcmp ("silent", bs->commands->line) == 0
3081 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3083 bs->commands = bs->commands->next;
3086 bs->commands = copy_command_lines (bs->commands);
3089 /* Print nothing for this entry if we dont stop or if we dont print. */
3090 if (bs->stop == 0 || bs->print == 0)
3091 bs->print_it = print_it_noop;
3094 bs->next = NULL; /* Terminate the chain */
3095 bs = root_bs->next; /* Re-grab the head of the chain */
3097 /* If we aren't stopping, the value of some hardware watchpoint may
3098 not have changed, but the intermediate memory locations we are
3099 watching may have. Don't bother if we're stopping; this will get
3101 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3106 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3108 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3109 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3110 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3112 /* remove/insert can invalidate bs->breakpoint_at, if this
3113 location is no longer used by the watchpoint. Prevent
3114 further code from trying to use it. */
3115 bs->breakpoint_at = NULL;
3116 remove_breakpoints ();
3117 insert_breakpoints ();
3121 return root_bs->next;
3124 /* Tell what to do about this bpstat. */
3126 bpstat_what (bpstat bs)
3128 /* Classify each bpstat as one of the following. */
3131 /* This bpstat element has no effect on the main_action. */
3134 /* There was a watchpoint, stop but don't print. */
3137 /* There was a watchpoint, stop and print. */
3140 /* There was a breakpoint but we're not stopping. */
3143 /* There was a breakpoint, stop but don't print. */
3146 /* There was a breakpoint, stop and print. */
3149 /* We hit the longjmp breakpoint. */
3152 /* We hit the longjmp_resume breakpoint. */
3155 /* We hit the step_resume breakpoint. */
3158 /* We hit the shared library event breakpoint. */
3161 /* We caught a shared library event. */
3164 /* This is just used to count how many enums there are. */
3168 /* Here is the table which drives this routine. So that we can
3169 format it pretty, we define some abbreviations for the
3170 enum bpstat_what codes. */
3171 #define kc BPSTAT_WHAT_KEEP_CHECKING
3172 #define ss BPSTAT_WHAT_STOP_SILENT
3173 #define sn BPSTAT_WHAT_STOP_NOISY
3174 #define sgl BPSTAT_WHAT_SINGLE
3175 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3176 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3177 #define sr BPSTAT_WHAT_STEP_RESUME
3178 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3179 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3181 /* "Can't happen." Might want to print an error message.
3182 abort() is not out of the question, but chances are GDB is just
3183 a bit confused, not unusable. */
3184 #define err BPSTAT_WHAT_STOP_NOISY
3186 /* Given an old action and a class, come up with a new action. */
3187 /* One interesting property of this table is that wp_silent is the same
3188 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3189 after stopping, the check for whether to step over a breakpoint
3190 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3191 reference to how we stopped. We retain separate wp_silent and
3192 bp_silent codes in case we want to change that someday.
3194 Another possibly interesting property of this table is that
3195 there's a partial ordering, priority-like, of the actions. Once
3196 you've decided that some action is appropriate, you'll never go
3197 back and decide something of a lower priority is better. The
3200 kc < clr sgl shl shlr slr sn sr ss
3201 sgl < shl shlr slr sn sr ss
3202 slr < err shl shlr sn sr ss
3203 clr < err shl shlr sn sr ss
3210 What I think this means is that we don't need a damned table
3211 here. If you just put the rows and columns in the right order,
3212 it'd look awfully regular. We could simply walk the bpstat list
3213 and choose the highest priority action we find, with a little
3214 logic to handle the 'err' cases. */
3216 /* step_resume entries: a step resume breakpoint overrides another
3217 breakpoint of signal handling (see comment in wait_for_inferior
3218 at where we set the step_resume breakpoint). */
3220 static const enum bpstat_what_main_action
3221 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3224 /* kc ss sn sgl slr clr sr shl shlr
3227 {kc, ss, sn, sgl, slr, clr, sr, shl, shlr},
3229 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3231 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3233 {sgl, ss, sn, sgl, slr, slr, sr, shl, shlr},
3235 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3237 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3239 {slr, ss, sn, slr, slr, err, sr, shl, shlr},
3241 {clr, ss, sn, err, err, err, sr, shl, shlr},
3243 {sr, sr, sr, sr, sr, sr, sr, sr, sr},
3245 {shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3247 {shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3261 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3262 struct bpstat_what retval;
3264 retval.call_dummy = 0;
3265 for (; bs != NULL; bs = bs->next)
3267 enum class bs_class = no_effect;
3268 if (bs->breakpoint_at == NULL)
3269 /* I suspect this can happen if it was a momentary breakpoint
3270 which has since been deleted. */
3272 switch (bs->breakpoint_at->owner->type)
3278 case bp_hardware_breakpoint:
3284 bs_class = bp_noisy;
3286 bs_class = bp_silent;
3289 bs_class = bp_nostop;
3292 case bp_hardware_watchpoint:
3293 case bp_read_watchpoint:
3294 case bp_access_watchpoint:
3298 bs_class = wp_noisy;
3300 bs_class = wp_silent;
3303 /* There was a watchpoint, but we're not stopping.
3304 This requires no further action. */
3305 bs_class = no_effect;
3308 bs_class = long_jump;
3310 case bp_longjmp_resume:
3311 bs_class = long_resume;
3313 case bp_step_resume:
3316 bs_class = step_resume;
3319 /* It is for the wrong frame. */
3320 bs_class = bp_nostop;
3322 case bp_watchpoint_scope:
3323 bs_class = bp_nostop;
3325 case bp_shlib_event:
3326 bs_class = shlib_event;
3328 case bp_thread_event:
3329 case bp_overlay_event:
3330 bs_class = bp_nostop;
3333 case bp_catch_unload:
3334 /* Only if this catchpoint triggered should we cause the
3335 step-out-of-dld behaviour. Otherwise, we ignore this
3338 bs_class = catch_shlib_event;
3340 bs_class = no_effect;
3343 case bp_catch_vfork:
3348 bs_class = bp_noisy;
3350 bs_class = bp_silent;
3353 /* There was a catchpoint, but we're not stopping.
3354 This requires no further action. */
3355 bs_class = no_effect;
3358 /* Make sure the action is stop (silent or noisy),
3359 so infrun.c pops the dummy frame. */
3360 bs_class = bp_silent;
3361 retval.call_dummy = 1;
3364 current_action = table[(int) bs_class][(int) current_action];
3366 retval.main_action = current_action;
3370 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3371 without hardware support). This isn't related to a specific bpstat,
3372 just to things like whether watchpoints are set. */
3375 bpstat_should_step (void)
3377 struct breakpoint *b;
3379 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3386 /* Given a bpstat that records zero or more triggered eventpoints, this
3387 function returns another bpstat which contains only the catchpoints
3388 on that first list, if any. */
3390 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3392 struct bpstats root_bs[1];
3393 bpstat bs = root_bs;
3394 struct breakpoint *ep;
3397 bpstat_clear (cp_list);
3398 root_bs->next = NULL;
3400 for (; ep_list != NULL; ep_list = ep_list->next)
3402 /* Is this eventpoint a catchpoint? If not, ignore it. */
3403 ep = ep_list->breakpoint_at->owner;
3406 if ((ep->type != bp_catch_load) &&
3407 (ep->type != bp_catch_unload))
3408 /* pai: (temp) ADD fork/vfork here!! */
3411 /* Yes; add it to the list. */
3412 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3417 #if defined(SOLIB_ADD)
3418 /* Also, for each triggered catchpoint, tag it with the name of
3419 the library that caused this trigger. (We copy the name now,
3420 because it's only guaranteed to be available NOW, when the
3421 catchpoint triggers. Clients who may wish to know the name
3422 later must get it from the catchpoint itself.) */
3423 if (ep->triggered_dll_pathname != NULL)
3424 xfree (ep->triggered_dll_pathname);
3425 if (ep->type == bp_catch_load)
3426 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3427 PIDGET (inferior_ptid));
3429 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3430 PIDGET (inferior_ptid));
3432 dll_pathname = NULL;
3436 ep->triggered_dll_pathname = (char *)
3437 xmalloc (strlen (dll_pathname) + 1);
3438 strcpy (ep->triggered_dll_pathname, dll_pathname);
3441 ep->triggered_dll_pathname = NULL;
3447 static void print_breakpoint_location (struct breakpoint *b,
3448 struct bp_location *loc,
3450 struct ui_stream *stb)
3455 = find_pc_sect_function (loc->address, loc->section);
3458 ui_out_text (uiout, "in ");
3459 ui_out_field_string (uiout, "func",
3460 SYMBOL_PRINT_NAME (sym));
3461 ui_out_wrap_hint (uiout, wrap_indent);
3462 ui_out_text (uiout, " at ");
3464 ui_out_field_string (uiout, "file", b->source_file);
3465 ui_out_text (uiout, ":");
3467 if (ui_out_is_mi_like_p (uiout))
3469 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3470 char *fullname = symtab_to_fullname (sal.symtab);
3473 ui_out_field_string (uiout, "fullname", fullname);
3476 ui_out_field_int (uiout, "line", b->line_number);
3480 ui_out_field_string (uiout, "pending", b->addr_string);
3484 print_address_symbolic (loc->address, stb->stream, demangle, "");
3485 ui_out_field_stream (uiout, "at", stb);
3489 /* Print B to gdb_stdout. */
3491 print_one_breakpoint_location (struct breakpoint *b,
3492 struct bp_location *loc,
3494 CORE_ADDR *last_addr)
3496 struct command_line *l;
3498 struct ep_type_description
3503 static struct ep_type_description bptypes[] =
3505 {bp_none, "?deleted?"},
3506 {bp_breakpoint, "breakpoint"},
3507 {bp_hardware_breakpoint, "hw breakpoint"},
3508 {bp_until, "until"},
3509 {bp_finish, "finish"},
3510 {bp_watchpoint, "watchpoint"},
3511 {bp_hardware_watchpoint, "hw watchpoint"},
3512 {bp_read_watchpoint, "read watchpoint"},
3513 {bp_access_watchpoint, "acc watchpoint"},
3514 {bp_longjmp, "longjmp"},
3515 {bp_longjmp_resume, "longjmp resume"},
3516 {bp_step_resume, "step resume"},
3517 {bp_watchpoint_scope, "watchpoint scope"},
3518 {bp_call_dummy, "call dummy"},
3519 {bp_shlib_event, "shlib events"},
3520 {bp_thread_event, "thread events"},
3521 {bp_overlay_event, "overlay events"},
3522 {bp_catch_load, "catch load"},
3523 {bp_catch_unload, "catch unload"},
3524 {bp_catch_fork, "catch fork"},
3525 {bp_catch_vfork, "catch vfork"},
3526 {bp_catch_exec, "catch exec"}
3529 static char bpenables[] = "nynny";
3530 char wrap_indent[80];
3531 struct ui_stream *stb = ui_out_stream_new (uiout);
3532 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3533 struct cleanup *bkpt_chain;
3535 int header_of_multiple = 0;
3536 int part_of_multiple = (loc != NULL);
3538 gdb_assert (!loc || loc_number != 0);
3539 /* See comment in print_one_breakpoint concerning
3540 treatment of breakpoints with single disabled
3544 && (b->loc->next != NULL || !b->loc->enabled)))
3545 header_of_multiple = 1;
3550 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3554 if (part_of_multiple)
3557 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3558 ui_out_field_string (uiout, "number", formatted);
3563 ui_out_field_int (uiout, "number", b->number);
3568 if (part_of_multiple)
3569 ui_out_field_skip (uiout, "type");
3572 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3573 || ((int) b->type != bptypes[(int) b->type].type))
3574 internal_error (__FILE__, __LINE__,
3575 _("bptypes table does not describe type #%d."),
3577 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3582 if (part_of_multiple)
3583 ui_out_field_skip (uiout, "disp");
3585 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3590 if (part_of_multiple)
3591 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3593 ui_out_field_fmt (uiout, "enabled", "%c",
3594 bpenables[(int) b->enable_state]);
3595 ui_out_spaces (uiout, 2);
3599 strcpy (wrap_indent, " ");
3602 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3603 strcat (wrap_indent, " ");
3605 strcat (wrap_indent, " ");
3608 if (b->ops != NULL && b->ops->print_one != NULL)
3610 /* Although the print_one can possibly print
3611 all locations, calling it here is not likely
3612 to get any nice result. So, make sure there's
3613 just one location. */
3614 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3615 b->ops->print_one (b, last_addr);
3621 internal_error (__FILE__, __LINE__,
3622 _("print_one_breakpoint: bp_none encountered\n"));
3626 case bp_hardware_watchpoint:
3627 case bp_read_watchpoint:
3628 case bp_access_watchpoint:
3629 /* Field 4, the address, is omitted (which makes the columns
3630 not line up too nicely with the headers, but the effect
3631 is relatively readable). */
3633 ui_out_field_skip (uiout, "addr");
3635 print_expression (b->exp, stb->stream);
3636 ui_out_field_stream (uiout, "what", stb);
3640 case bp_catch_unload:
3641 /* Field 4, the address, is omitted (which makes the columns
3642 not line up too nicely with the headers, but the effect
3643 is relatively readable). */
3645 ui_out_field_skip (uiout, "addr");
3647 if (b->dll_pathname == NULL)
3649 ui_out_field_string (uiout, "what", "<any library>");
3650 ui_out_spaces (uiout, 1);
3654 ui_out_text (uiout, "library \"");
3655 ui_out_field_string (uiout, "what", b->dll_pathname);
3656 ui_out_text (uiout, "\" ");
3661 case bp_catch_vfork:
3662 /* Field 4, the address, is omitted (which makes the columns
3663 not line up too nicely with the headers, but the effect
3664 is relatively readable). */
3666 ui_out_field_skip (uiout, "addr");
3668 if (b->forked_inferior_pid != 0)
3670 ui_out_text (uiout, "process ");
3671 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3672 ui_out_spaces (uiout, 1);
3677 /* Field 4, the address, is omitted (which makes the columns
3678 not line up too nicely with the headers, but the effect
3679 is relatively readable). */
3681 ui_out_field_skip (uiout, "addr");
3683 if (b->exec_pathname != NULL)
3685 ui_out_text (uiout, "program \"");
3686 ui_out_field_string (uiout, "what", b->exec_pathname);
3687 ui_out_text (uiout, "\" ");
3692 case bp_hardware_breakpoint:
3696 case bp_longjmp_resume:
3697 case bp_step_resume:
3698 case bp_watchpoint_scope:
3700 case bp_shlib_event:
3701 case bp_thread_event:
3702 case bp_overlay_event:
3706 if (header_of_multiple)
3707 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3708 else if (b->loc == NULL || loc->shlib_disabled)
3709 ui_out_field_string (uiout, "addr", "<PENDING>");
3711 ui_out_field_core_addr (uiout, "addr", loc->address);
3714 if (!header_of_multiple)
3715 print_breakpoint_location (b, loc, wrap_indent, stb);
3717 *last_addr = b->loc->address;
3721 if (!part_of_multiple && b->thread != -1)
3723 /* FIXME: This seems to be redundant and lost here; see the
3724 "stop only in" line a little further down. */
3725 ui_out_text (uiout, " thread ");
3726 ui_out_field_int (uiout, "thread", b->thread);
3729 ui_out_text (uiout, "\n");
3731 if (part_of_multiple && frame_id_p (b->frame_id))
3734 ui_out_text (uiout, "\tstop only in stack frame at ");
3735 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3737 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3738 ui_out_text (uiout, "\n");
3741 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3743 /* We do not print the condition for Ada exception catchpoints
3744 because the condition is an internal implementation detail
3745 that we do not want to expose to the user. */
3747 ui_out_text (uiout, "\tstop only if ");
3748 ui_out_field_string (uiout, "cond", b->cond_string);
3749 ui_out_text (uiout, "\n");
3752 if (!part_of_multiple && b->thread != -1)
3754 /* FIXME should make an annotation for this */
3755 ui_out_text (uiout, "\tstop only in thread ");
3756 ui_out_field_int (uiout, "thread", b->thread);
3757 ui_out_text (uiout, "\n");
3760 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3762 /* FIXME should make an annotation for this */
3763 if (ep_is_catchpoint (b))
3764 ui_out_text (uiout, "\tcatchpoint");
3766 ui_out_text (uiout, "\tbreakpoint");
3767 ui_out_text (uiout, " already hit ");
3768 ui_out_field_int (uiout, "times", b->hit_count);
3769 if (b->hit_count == 1)
3770 ui_out_text (uiout, " time\n");
3772 ui_out_text (uiout, " times\n");
3775 /* Output the count also if it is zero, but only if this is
3776 mi. FIXME: Should have a better test for this. */
3777 if (ui_out_is_mi_like_p (uiout))
3778 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3779 ui_out_field_int (uiout, "times", b->hit_count);
3781 if (!part_of_multiple && b->ignore_count)
3784 ui_out_text (uiout, "\tignore next ");
3785 ui_out_field_int (uiout, "ignore", b->ignore_count);
3786 ui_out_text (uiout, " hits\n");
3789 if (!part_of_multiple && (l = b->commands))
3791 struct cleanup *script_chain;
3794 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3795 print_command_lines (uiout, l, 4);
3796 do_cleanups (script_chain);
3799 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3802 ui_out_field_string (uiout, "original-location", b->addr_string);
3803 else if (b->exp_string)
3804 ui_out_field_string (uiout, "original-location", b->exp_string);
3807 do_cleanups (bkpt_chain);
3808 do_cleanups (old_chain);
3812 print_one_breakpoint (struct breakpoint *b,
3813 CORE_ADDR *last_addr)
3815 print_one_breakpoint_location (b, NULL, 0, last_addr);
3817 /* If this breakpoint has custom print function,
3818 it's already printed. Otherwise, print individual
3819 locations, if any. */
3820 if (b->ops == NULL || b->ops->print_one == NULL)
3822 /* If breakpoint has a single location that is
3823 disabled, we print it as if it had
3824 several locations, since otherwise it's hard to
3825 represent "breakpoint enabled, location disabled"
3827 Note that while hardware watchpoints have
3828 several locations internally, that's no a property
3831 && !is_hardware_watchpoint (b)
3832 && (b->loc->next || !b->loc->enabled)
3833 && !ui_out_is_mi_like_p (uiout))
3835 struct bp_location *loc;
3837 for (loc = b->loc; loc; loc = loc->next, ++n)
3838 print_one_breakpoint_location (b, loc, n, last_addr);
3844 struct captured_breakpoint_query_args
3850 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3852 struct captured_breakpoint_query_args *args = data;
3853 struct breakpoint *b;
3854 CORE_ADDR dummy_addr = 0;
3857 if (args->bnum == b->number)
3859 print_one_breakpoint (b, &dummy_addr);
3867 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3869 struct captured_breakpoint_query_args args;
3871 /* For the moment we don't trust print_one_breakpoint() to not throw
3873 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3874 error_message, RETURN_MASK_ALL) < 0)
3880 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3881 catchpoints, et.al.). */
3884 user_settable_breakpoint (const struct breakpoint *b)
3886 return (b->type == bp_breakpoint
3887 || b->type == bp_catch_load
3888 || b->type == bp_catch_unload
3889 || b->type == bp_catch_fork
3890 || b->type == bp_catch_vfork
3891 || b->type == bp_catch_exec
3892 || b->type == bp_hardware_breakpoint
3893 || b->type == bp_watchpoint
3894 || b->type == bp_read_watchpoint
3895 || b->type == bp_access_watchpoint
3896 || b->type == bp_hardware_watchpoint);
3899 /* Print information on user settable breakpoint (watchpoint, etc)
3900 number BNUM. If BNUM is -1 print all user settable breakpoints.
3901 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3904 breakpoint_1 (int bnum, int allflag)
3906 struct breakpoint *b;
3907 CORE_ADDR last_addr = (CORE_ADDR) -1;
3908 int nr_printable_breakpoints;
3909 struct cleanup *bkpttbl_chain;
3911 /* Compute the number of rows in the table. */
3912 nr_printable_breakpoints = 0;
3915 || bnum == b->number)
3917 if (allflag || user_settable_breakpoint (b))
3918 nr_printable_breakpoints++;
3923 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3927 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3930 if (nr_printable_breakpoints > 0)
3931 annotate_breakpoints_headers ();
3932 if (nr_printable_breakpoints > 0)
3934 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3935 if (nr_printable_breakpoints > 0)
3937 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3938 if (nr_printable_breakpoints > 0)
3940 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3941 if (nr_printable_breakpoints > 0)
3943 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3946 if (nr_printable_breakpoints > 0)
3948 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3949 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3951 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3953 if (nr_printable_breakpoints > 0)
3955 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3956 ui_out_table_body (uiout);
3957 if (nr_printable_breakpoints > 0)
3958 annotate_breakpoints_table ();
3962 || bnum == b->number)
3964 /* We only print out user settable breakpoints unless the
3966 if (allflag || user_settable_breakpoint (b))
3967 print_one_breakpoint (b, &last_addr);
3970 do_cleanups (bkpttbl_chain);
3972 if (nr_printable_breakpoints == 0)
3975 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3977 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3982 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3983 that a comparison of an unsigned with -1 is always false. */
3984 if (last_addr != (CORE_ADDR) -1 && !server_command)
3985 set_next_address (last_addr);
3988 /* FIXME? Should this be moved up so that it is only called when
3989 there have been breakpoints? */
3990 annotate_breakpoints_table_end ();
3994 breakpoints_info (char *bnum_exp, int from_tty)
3999 bnum = parse_and_eval_long (bnum_exp);
4001 breakpoint_1 (bnum, 0);
4005 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4010 bnum = parse_and_eval_long (bnum_exp);
4012 breakpoint_1 (bnum, 1);
4016 breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
4018 struct bp_location *bl = b->loc;
4019 for (; bl; bl = bl->next)
4021 if (bl->address == pc
4022 && (!overlay_debugging || bl->section == section))
4028 /* Print a message describing any breakpoints set at PC. */
4031 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
4034 struct breakpoint *b;
4037 others += breakpoint_has_pc (b, pc, section);
4041 printf_filtered (_("Note: breakpoint "));
4042 else /* if (others == ???) */
4043 printf_filtered (_("Note: breakpoints "));
4045 if (breakpoint_has_pc (b, pc, section))
4048 printf_filtered ("%d", b->number);
4049 if (b->thread == -1 && thread != -1)
4050 printf_filtered (" (all threads)");
4051 else if (b->thread != -1)
4052 printf_filtered (" (thread %d)", b->thread);
4053 printf_filtered ("%s%s ",
4054 ((b->enable_state == bp_disabled ||
4055 b->enable_state == bp_call_disabled)
4057 : b->enable_state == bp_permanent
4061 : ((others == 1) ? " and" : ""));
4063 printf_filtered (_("also set at pc "));
4064 fputs_filtered (paddress (pc), gdb_stdout);
4065 printf_filtered (".\n");
4069 /* Set the default place to put a breakpoint
4070 for the `break' command with no arguments. */
4073 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4076 default_breakpoint_valid = valid;
4077 default_breakpoint_address = addr;
4078 default_breakpoint_symtab = symtab;
4079 default_breakpoint_line = line;
4082 /* Return true iff it is meaningful to use the address member of
4083 BPT. For some breakpoint types, the address member is irrelevant
4084 and it makes no sense to attempt to compare it to other addresses
4085 (or use it for any other purpose either).
4087 More specifically, each of the following breakpoint types will always
4088 have a zero valued address and we don't want check_duplicates() to mark
4089 breakpoints of any of these types to be a duplicate of an actual
4090 breakpoint at address zero:
4093 bp_hardware_watchpoint
4095 bp_access_watchpoint
4102 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4104 enum bptype type = bpt->type;
4106 return (type != bp_watchpoint
4107 && type != bp_hardware_watchpoint
4108 && type != bp_read_watchpoint
4109 && type != bp_access_watchpoint
4110 && type != bp_catch_exec
4111 && type != bp_longjmp_resume
4112 && type != bp_catch_fork
4113 && type != bp_catch_vfork);
4116 /* Rescan breakpoints at the same address and section as BPT,
4117 marking the first one as "first" and any others as "duplicates".
4118 This is so that the bpt instruction is only inserted once.
4119 If we have a permanent breakpoint at the same place as BPT, make
4120 that one the official one, and the rest as duplicates. */
4123 check_duplicates_for (CORE_ADDR address, asection *section)
4125 struct bp_location *b;
4127 struct bp_location *perm_bp = 0;
4129 ALL_BP_LOCATIONS (b)
4130 if (b->owner->enable_state != bp_disabled
4131 && b->owner->enable_state != bp_call_disabled
4133 && !b->shlib_disabled
4134 && b->address == address /* address / overlay match */
4135 && (!overlay_debugging || b->section == section)
4136 && breakpoint_address_is_meaningful (b->owner))
4138 /* Have we found a permanent breakpoint? */
4139 if (b->owner->enable_state == bp_permanent)
4146 b->duplicate = count > 1;
4149 /* If we found a permanent breakpoint at this address, go over the
4150 list again and declare all the other breakpoints there to be the
4154 perm_bp->duplicate = 0;
4156 /* Permanent breakpoint should always be inserted. */
4157 if (! perm_bp->inserted)
4158 internal_error (__FILE__, __LINE__,
4159 _("allegedly permanent breakpoint is not "
4160 "actually inserted"));
4162 ALL_BP_LOCATIONS (b)
4165 if (b->owner->enable_state != bp_disabled
4166 && b->owner->enable_state != bp_call_disabled
4167 && b->enabled && !b->shlib_disabled
4168 && b->address == address /* address / overlay match */
4169 && (!overlay_debugging || b->section == section)
4170 && breakpoint_address_is_meaningful (b->owner))
4173 internal_error (__FILE__, __LINE__,
4174 _("another breakpoint was inserted on top of "
4175 "a permanent breakpoint"));
4184 check_duplicates (struct breakpoint *bpt)
4186 struct bp_location *bl = bpt->loc;
4188 if (! breakpoint_address_is_meaningful (bpt))
4191 for (; bl; bl = bl->next)
4192 check_duplicates_for (bl->address, bl->section);
4196 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4197 int bnum, int have_bnum)
4202 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4203 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4205 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4206 bnum, astr1, astr2);
4208 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4211 /* Adjust a breakpoint's address to account for architectural constraints
4212 on breakpoint placement. Return the adjusted address. Note: Very
4213 few targets require this kind of adjustment. For most targets,
4214 this function is simply the identity function. */
4217 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4219 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4221 /* Very few targets need any kind of breakpoint adjustment. */
4224 else if (bptype == bp_watchpoint
4225 || bptype == bp_hardware_watchpoint
4226 || bptype == bp_read_watchpoint
4227 || bptype == bp_access_watchpoint
4228 || bptype == bp_catch_fork
4229 || bptype == bp_catch_vfork
4230 || bptype == bp_catch_exec)
4232 /* Watchpoints and the various bp_catch_* eventpoints should not
4233 have their addresses modified. */
4238 CORE_ADDR adjusted_bpaddr;
4240 /* Some targets have architectural constraints on the placement
4241 of breakpoint instructions. Obtain the adjusted address. */
4242 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4245 /* An adjusted breakpoint address can significantly alter
4246 a user's expectations. Print a warning if an adjustment
4248 if (adjusted_bpaddr != bpaddr)
4249 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4251 return adjusted_bpaddr;
4255 /* Allocate a struct bp_location. */
4257 static struct bp_location *
4258 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4260 struct bp_location *loc, *loc_p;
4262 loc = xmalloc (sizeof (struct bp_location));
4263 memset (loc, 0, sizeof (*loc));
4267 loc->shlib_disabled = 0;
4276 case bp_longjmp_resume:
4277 case bp_step_resume:
4278 case bp_watchpoint_scope:
4280 case bp_shlib_event:
4281 case bp_thread_event:
4282 case bp_overlay_event:
4284 case bp_catch_unload:
4285 loc->loc_type = bp_loc_software_breakpoint;
4287 case bp_hardware_breakpoint:
4288 loc->loc_type = bp_loc_hardware_breakpoint;
4290 case bp_hardware_watchpoint:
4291 case bp_read_watchpoint:
4292 case bp_access_watchpoint:
4293 loc->loc_type = bp_loc_hardware_watchpoint;
4297 case bp_catch_vfork:
4299 loc->loc_type = bp_loc_other;
4302 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4308 static void free_bp_location (struct bp_location *loc)
4313 if (loc->function_name)
4314 xfree (loc->function_name);
4319 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4320 that has type BPTYPE and has no locations as yet. */
4322 static struct breakpoint *
4323 set_raw_breakpoint_without_location (enum bptype bptype)
4325 struct breakpoint *b, *b1;
4327 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4328 memset (b, 0, sizeof (*b));
4331 b->language = current_language->la_language;
4332 b->input_radix = input_radix;
4334 b->enable_state = bp_enabled;
4337 b->ignore_count = 0;
4339 b->frame_id = null_frame_id;
4340 b->dll_pathname = NULL;
4341 b->triggered_dll_pathname = NULL;
4342 b->forked_inferior_pid = 0;
4343 b->exec_pathname = NULL;
4345 b->condition_not_parsed = 0;
4347 /* Add this breakpoint to the end of the chain
4348 so that a list of breakpoints will come out in order
4349 of increasing numbers. */
4351 b1 = breakpoint_chain;
4353 breakpoint_chain = b;
4363 /* Initialize loc->function_name. */
4365 set_breakpoint_location_function (struct bp_location *loc)
4367 if (loc->owner->type == bp_breakpoint
4368 || loc->owner->type == bp_hardware_breakpoint)
4370 find_pc_partial_function (loc->address, &(loc->function_name),
4372 if (loc->function_name)
4373 loc->function_name = xstrdup (loc->function_name);
4377 /* set_raw_breakpoint is a low level routine for allocating and
4378 partially initializing a breakpoint of type BPTYPE. The newly
4379 created breakpoint's address, section, source file name, and line
4380 number are provided by SAL. The newly created and partially
4381 initialized breakpoint is added to the breakpoint chain and
4382 is also returned as the value of this function.
4384 It is expected that the caller will complete the initialization of
4385 the newly created breakpoint struct as well as output any status
4386 information regarding the creation of a new breakpoint. In
4387 particular, set_raw_breakpoint does NOT set the breakpoint
4388 number! Care should be taken to not allow an error to occur
4389 prior to completing the initialization of the breakpoint. If this
4390 should happen, a bogus breakpoint will be left on the chain. */
4393 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4395 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4396 CORE_ADDR adjusted_address;
4398 /* Adjust the breakpoint's address prior to allocating a location.
4399 Once we call allocate_bp_location(), that mostly uninitialized
4400 location will be placed on the location chain. Adjustment of the
4401 breakpoint may cause target_read_memory() to be called and we do
4402 not want its scan of the location chain to find a breakpoint and
4403 location that's only been partially initialized. */
4404 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4406 b->loc = allocate_bp_location (b, bptype);
4407 b->loc->requested_address = sal.pc;
4408 b->loc->address = adjusted_address;
4410 if (sal.symtab == NULL)
4411 b->source_file = NULL;
4413 b->source_file = savestring (sal.symtab->filename,
4414 strlen (sal.symtab->filename));
4415 b->loc->section = sal.section;
4416 b->line_number = sal.line;
4418 set_breakpoint_location_function (b->loc);
4420 breakpoints_changed ();
4426 /* Note that the breakpoint object B describes a permanent breakpoint
4427 instruction, hard-wired into the inferior's code. */
4429 make_breakpoint_permanent (struct breakpoint *b)
4431 struct bp_location *bl;
4432 b->enable_state = bp_permanent;
4434 /* By definition, permanent breakpoints are already present in the code.
4435 Mark all locations as inserted. For now, make_breakpoint_permanent
4436 is called in just one place, so it's hard to say if it's reasonable
4437 to have permanent breakpoint with multiple locations or not,
4438 but it's easy to implmement. */
4439 for (bl = b->loc; bl; bl = bl->next)
4443 static struct breakpoint *
4444 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4446 static int internal_breakpoint_number = -1;
4447 struct symtab_and_line sal;
4448 struct breakpoint *b;
4450 init_sal (&sal); /* initialize to zeroes */
4453 sal.section = find_pc_overlay (sal.pc);
4455 b = set_raw_breakpoint (sal, type);
4456 b->number = internal_breakpoint_number--;
4457 b->disposition = disp_donttouch;
4464 create_longjmp_breakpoint (char *func_name)
4466 struct breakpoint *b;
4467 struct minimal_symbol *m;
4469 if (func_name == NULL)
4470 b = create_internal_breakpoint (0, bp_longjmp_resume);
4473 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4476 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4479 b->enable_state = bp_disabled;
4482 b->addr_string = xstrdup (func_name);
4483 update_global_location_list ();
4486 /* Call this routine when stepping and nexting to enable a breakpoint
4487 if we do a longjmp(). When we hit that breakpoint, call
4488 set_longjmp_resume_breakpoint() to figure out where we are going. */
4491 enable_longjmp_breakpoint (void)
4493 struct breakpoint *b;
4496 if (b->type == bp_longjmp)
4498 b->enable_state = bp_enabled;
4499 update_global_location_list ();
4504 disable_longjmp_breakpoint (void)
4506 struct breakpoint *b;
4509 if (b->type == bp_longjmp
4510 || b->type == bp_longjmp_resume)
4512 b->enable_state = bp_disabled;
4513 update_global_location_list ();
4518 create_overlay_event_breakpoint (char *func_name)
4520 struct breakpoint *b;
4521 struct minimal_symbol *m;
4523 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4526 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4528 b->addr_string = xstrdup (func_name);
4530 if (overlay_debugging == ovly_auto)
4532 b->enable_state = bp_enabled;
4533 overlay_events_enabled = 1;
4537 b->enable_state = bp_disabled;
4538 overlay_events_enabled = 0;
4540 update_global_location_list ();
4544 enable_overlay_breakpoints (void)
4546 struct breakpoint *b;
4549 if (b->type == bp_overlay_event)
4551 b->enable_state = bp_enabled;
4552 update_global_location_list ();
4553 overlay_events_enabled = 1;
4558 disable_overlay_breakpoints (void)
4560 struct breakpoint *b;
4563 if (b->type == bp_overlay_event)
4565 b->enable_state = bp_disabled;
4566 update_global_location_list ();
4567 overlay_events_enabled = 0;
4572 create_thread_event_breakpoint (CORE_ADDR address)
4574 struct breakpoint *b;
4576 b = create_internal_breakpoint (address, bp_thread_event);
4578 b->enable_state = bp_enabled;
4579 /* addr_string has to be used or breakpoint_re_set will delete me. */
4580 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4582 update_global_location_list_nothrow ();
4588 remove_thread_event_breakpoints (void)
4590 struct breakpoint *b, *temp;
4592 ALL_BREAKPOINTS_SAFE (b, temp)
4593 if (b->type == bp_thread_event)
4594 delete_breakpoint (b);
4597 struct captured_parse_breakpoint_args
4600 struct symtabs_and_lines *sals_p;
4601 char ***addr_string_p;
4605 struct lang_and_radix
4613 remove_solib_event_breakpoints (void)
4615 struct breakpoint *b, *temp;
4617 ALL_BREAKPOINTS_SAFE (b, temp)
4618 if (b->type == bp_shlib_event)
4619 delete_breakpoint (b);
4623 create_solib_event_breakpoint (CORE_ADDR address)
4625 struct breakpoint *b;
4627 b = create_internal_breakpoint (address, bp_shlib_event);
4628 update_global_location_list_nothrow ();
4632 /* Disable any breakpoints that are on code in shared libraries. Only
4633 apply to enabled breakpoints, disabled ones can just stay disabled. */
4636 disable_breakpoints_in_shlibs (void)
4638 struct bp_location *loc;
4639 int disabled_shlib_breaks = 0;
4641 ALL_BP_LOCATIONS (loc)
4643 struct breakpoint *b = loc->owner;
4644 /* We apply the check to all breakpoints, including disabled
4645 for those with loc->duplicate set. This is so that when breakpoint
4646 becomes enabled, or the duplicate is removed, gdb will try to insert
4647 all breakpoints. If we don't set shlib_disabled here, we'll try
4648 to insert those breakpoints and fail. */
4649 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4650 && !loc->shlib_disabled
4652 && PC_SOLIB (loc->address)
4654 && solib_address (loc->address)
4658 loc->shlib_disabled = 1;
4663 /* Disable any breakpoints that are in in an unloaded shared library. Only
4664 apply to enabled breakpoints, disabled ones can just stay disabled. */
4667 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4669 struct bp_location *loc;
4670 int disabled_shlib_breaks = 0;
4672 ALL_BP_LOCATIONS (loc)
4674 struct breakpoint *b = loc->owner;
4675 if ((loc->loc_type == bp_loc_hardware_breakpoint
4676 || loc->loc_type == bp_loc_software_breakpoint)
4677 && !loc->shlib_disabled)
4680 char *so_name = PC_SOLIB (loc->address);
4682 char *so_name = solib_address (loc->address);
4684 if (so_name && !strcmp (so_name, solib->so_name))
4686 loc->shlib_disabled = 1;
4687 /* At this point, we cannot rely on remove_breakpoint
4688 succeeding so we must mark the breakpoint as not inserted
4689 to prevent future errors occurring in remove_breakpoints. */
4691 if (!disabled_shlib_breaks)
4693 target_terminal_ours_for_output ();
4694 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4697 disabled_shlib_breaks = 1;
4704 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4705 enum bptype bp_kind)
4707 struct symtab_and_line sal;
4708 struct breakpoint *b;
4709 int thread = -1; /* All threads. */
4716 b = set_raw_breakpoint (sal, bp_kind);
4717 set_breakpoint_count (breakpoint_count + 1);
4718 b->number = breakpoint_count;
4719 b->cond_string = (cond_string == NULL) ?
4720 NULL : savestring (cond_string, strlen (cond_string));
4722 b->addr_string = NULL;
4723 b->enable_state = bp_enabled;
4724 b->disposition = tempflag ? disp_del : disp_donttouch;
4725 b->forked_inferior_pid = 0;
4726 update_global_location_list ();
4733 create_fork_event_catchpoint (int tempflag, char *cond_string)
4735 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4739 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4741 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4745 create_exec_event_catchpoint (int tempflag, char *cond_string)
4747 struct symtab_and_line sal;
4748 struct breakpoint *b;
4749 int thread = -1; /* All threads. */
4756 b = set_raw_breakpoint (sal, bp_catch_exec);
4757 set_breakpoint_count (breakpoint_count + 1);
4758 b->number = breakpoint_count;
4759 b->cond_string = (cond_string == NULL) ?
4760 NULL : savestring (cond_string, strlen (cond_string));
4762 b->addr_string = NULL;
4763 b->enable_state = bp_enabled;
4764 b->disposition = tempflag ? disp_del : disp_donttouch;
4765 update_global_location_list ();
4771 hw_breakpoint_used_count (void)
4773 struct breakpoint *b;
4778 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4786 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4788 struct breakpoint *b;
4791 *other_type_used = 0;
4794 if (breakpoint_enabled (b))
4796 if (b->type == type)
4798 else if ((b->type == bp_hardware_watchpoint ||
4799 b->type == bp_read_watchpoint ||
4800 b->type == bp_access_watchpoint))
4801 *other_type_used = 1;
4807 /* Call this after hitting the longjmp() breakpoint. Use this to set
4808 a new breakpoint at the target of the jmp_buf.
4810 FIXME - This ought to be done by setting a temporary breakpoint
4811 that gets deleted automatically... */
4814 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4816 struct breakpoint *b;
4819 if (b->type == bp_longjmp_resume)
4821 b->loc->requested_address = pc;
4822 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4824 b->enable_state = bp_enabled;
4825 b->frame_id = frame_id;
4826 update_global_location_list ();
4832 disable_watchpoints_before_interactive_call_start (void)
4834 struct breakpoint *b;
4838 if (((b->type == bp_watchpoint)
4839 || (b->type == bp_hardware_watchpoint)
4840 || (b->type == bp_read_watchpoint)
4841 || (b->type == bp_access_watchpoint))
4842 && breakpoint_enabled (b))
4844 b->enable_state = bp_call_disabled;
4845 update_global_location_list ();
4851 enable_watchpoints_after_interactive_call_stop (void)
4853 struct breakpoint *b;
4857 if (((b->type == bp_watchpoint)
4858 || (b->type == bp_hardware_watchpoint)
4859 || (b->type == bp_read_watchpoint)
4860 || (b->type == bp_access_watchpoint))
4861 && (b->enable_state == bp_call_disabled))
4863 b->enable_state = bp_enabled;
4864 update_global_location_list ();
4870 /* Set a breakpoint that will evaporate an end of command
4871 at address specified by SAL.
4872 Restrict it to frame FRAME if FRAME is nonzero. */
4875 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4878 struct breakpoint *b;
4879 b = set_raw_breakpoint (sal, type);
4880 b->enable_state = bp_enabled;
4881 b->disposition = disp_donttouch;
4882 b->frame_id = frame_id;
4884 /* If we're debugging a multi-threaded program, then we
4885 want momentary breakpoints to be active in only a
4886 single thread of control. */
4887 if (in_thread_list (inferior_ptid))
4888 b->thread = pid_to_thread_id (inferior_ptid);
4890 update_global_location_list_nothrow ();
4896 /* Tell the user we have just set a breakpoint B. */
4899 mention (struct breakpoint *b)
4902 struct cleanup *old_chain, *ui_out_chain;
4903 struct ui_stream *stb;
4905 stb = ui_out_stream_new (uiout);
4906 old_chain = make_cleanup_ui_out_stream_delete (stb);
4908 /* FIXME: This is misplaced; mention() is called by things (like
4909 hitting a watchpoint) other than breakpoint creation. It should
4910 be possible to clean this up and at the same time replace the
4911 random calls to breakpoint_changed with this hook, as has already
4912 been done for deprecated_delete_breakpoint_hook and so on. */
4913 if (deprecated_create_breakpoint_hook)
4914 deprecated_create_breakpoint_hook (b);
4915 breakpoint_create_event (b->number);
4917 if (b->ops != NULL && b->ops->print_mention != NULL)
4918 b->ops->print_mention (b);
4923 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4926 ui_out_text (uiout, "Watchpoint ");
4927 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4928 ui_out_field_int (uiout, "number", b->number);
4929 ui_out_text (uiout, ": ");
4930 print_expression (b->exp, stb->stream);
4931 ui_out_field_stream (uiout, "exp", stb);
4932 do_cleanups (ui_out_chain);
4934 case bp_hardware_watchpoint:
4935 ui_out_text (uiout, "Hardware watchpoint ");
4936 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4937 ui_out_field_int (uiout, "number", b->number);
4938 ui_out_text (uiout, ": ");
4939 print_expression (b->exp, stb->stream);
4940 ui_out_field_stream (uiout, "exp", stb);
4941 do_cleanups (ui_out_chain);
4943 case bp_read_watchpoint:
4944 ui_out_text (uiout, "Hardware read watchpoint ");
4945 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4946 ui_out_field_int (uiout, "number", b->number);
4947 ui_out_text (uiout, ": ");
4948 print_expression (b->exp, stb->stream);
4949 ui_out_field_stream (uiout, "exp", stb);
4950 do_cleanups (ui_out_chain);
4952 case bp_access_watchpoint:
4953 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4954 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4955 ui_out_field_int (uiout, "number", b->number);
4956 ui_out_text (uiout, ": ");
4957 print_expression (b->exp, stb->stream);
4958 ui_out_field_stream (uiout, "exp", stb);
4959 do_cleanups (ui_out_chain);
4962 if (ui_out_is_mi_like_p (uiout))
4967 if (b->disposition == disp_del)
4968 printf_filtered (_("Temporary breakpoint"));
4970 printf_filtered (_("Breakpoint"));
4971 printf_filtered (_(" %d"), b->number);
4974 case bp_hardware_breakpoint:
4975 if (ui_out_is_mi_like_p (uiout))
4980 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4984 case bp_catch_unload:
4985 printf_filtered (_("Catchpoint %d (%s %s)"),
4987 (b->type == bp_catch_load) ? "load" : "unload",
4988 (b->dll_pathname != NULL) ?
4989 b->dll_pathname : "<any library>");
4992 case bp_catch_vfork:
4993 printf_filtered (_("Catchpoint %d (%s)"),
4995 (b->type == bp_catch_fork) ? "fork" : "vfork");
4998 printf_filtered (_("Catchpoint %d (exec)"),
5005 case bp_longjmp_resume:
5006 case bp_step_resume:
5008 case bp_watchpoint_scope:
5009 case bp_shlib_event:
5010 case bp_thread_event:
5011 case bp_overlay_event:
5017 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5021 printf_filtered (_(" (%s) pending."), b->addr_string);
5025 if (addressprint || b->source_file == NULL)
5027 printf_filtered (" at ");
5028 fputs_filtered (paddress (b->loc->address), gdb_stdout);
5031 printf_filtered (": file %s, line %d.",
5032 b->source_file, b->line_number);
5036 struct bp_location *loc = b->loc;
5038 for (; loc; loc = loc->next)
5040 printf_filtered (" (%d locations)", n);
5045 do_cleanups (old_chain);
5046 if (ui_out_is_mi_like_p (uiout))
5048 printf_filtered ("\n");
5052 static struct bp_location *
5053 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5054 const struct symtab_and_line *sal)
5056 struct bp_location *loc, **tmp;
5058 loc = allocate_bp_location (b, bptype);
5059 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5062 loc->requested_address = sal->pc;
5063 loc->address = adjust_breakpoint_address (loc->requested_address,
5065 loc->section = sal->section;
5067 set_breakpoint_location_function (loc);
5071 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5072 as textual description of the location, and COND_STRING
5073 as condition expression. */
5076 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5078 enum bptype type, enum bpdisp disposition,
5079 int thread, int ignore_count,
5080 struct breakpoint_ops *ops, int from_tty)
5082 struct breakpoint *b = NULL;
5085 if (type == bp_hardware_breakpoint)
5087 int i = hw_breakpoint_used_count ();
5088 int target_resources_ok =
5089 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5091 if (target_resources_ok == 0)
5092 error (_("No hardware breakpoint support in the target."));
5093 else if (target_resources_ok < 0)
5094 error (_("Hardware breakpoints used exceeds limit."));
5097 for (i = 0; i < sals.nelts; ++i)
5099 struct symtab_and_line sal = sals.sals[i];
5100 struct bp_location *loc;
5103 describe_other_breakpoints (sal.pc, sal.section, thread);
5107 b = set_raw_breakpoint (sal, type);
5108 set_breakpoint_count (breakpoint_count + 1);
5109 b->number = breakpoint_count;
5112 b->cond_string = cond_string;
5113 b->ignore_count = ignore_count;
5114 b->enable_state = bp_enabled;
5115 b->disposition = disposition;
5121 loc = add_location_to_breakpoint (b, type, &sal);
5126 char *arg = b->cond_string;
5127 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5129 error (_("Garbage %s follows condition"), arg);
5134 b->addr_string = addr_string;
5136 /* addr_string has to be used or breakpoint_re_set will delete
5138 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5144 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5145 elements to fill the void space. */
5146 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5148 int i = index_to_remove+1;
5149 int last_index = sal->nelts-1;
5151 for (;i <= last_index; ++i)
5152 sal->sals[i-1] = sal->sals[i];
5157 /* If appropriate, obtains all sals that correspond
5158 to the same file and line as SAL. This is done
5159 only if SAL does not have explicit PC and has
5160 line and file information. If we got just a single
5161 expanded sal, return the original.
5163 Otherwise, if SAL.explicit_line is not set, filter out
5164 all sals for which the name of enclosing function
5165 is different from SAL. This makes sure that if we have
5166 breakpoint originally set in template instantiation, say
5167 foo<int>(), we won't expand SAL to locations at the same
5168 line in all existing instantiations of 'foo'.
5171 struct symtabs_and_lines
5172 expand_line_sal_maybe (struct symtab_and_line sal)
5174 struct symtabs_and_lines expanded;
5175 CORE_ADDR original_pc = sal.pc;
5176 char *original_function = NULL;
5180 /* If we have explicit pc, don't expand.
5181 If we have no line number, we can't expand. */
5182 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5185 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5186 expanded.sals[0] = sal;
5191 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5193 expanded = expand_line_sal (sal);
5194 if (expanded.nelts == 1)
5196 /* We had one sal, we got one sal. Without futher
5197 processing, just return the original sal. */
5198 xfree (expanded.sals);
5200 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5201 sal.pc = original_pc;
5202 expanded.sals[0] = sal;
5206 if (!sal.explicit_line)
5208 CORE_ADDR func_addr, func_end;
5209 for (i = 0; i < expanded.nelts; ++i)
5211 CORE_ADDR pc = expanded.sals[i].pc;
5212 char *this_function;
5213 if (find_pc_partial_function (pc, &this_function,
5214 &func_addr, &func_end))
5216 if (this_function &&
5217 strcmp (this_function, original_function) != 0)
5219 remove_sal (&expanded, i);
5222 else if (func_addr == pc)
5224 /* We're at beginning of a function, and should
5226 struct symbol *sym = find_pc_function (pc);
5228 expanded.sals[i] = find_function_start_sal (sym, 1);
5231 = gdbarch_skip_prologue (current_gdbarch, pc);
5238 if (expanded.nelts <= 1)
5240 /* This is un ugly workaround. If we get zero
5241 expanded sals then something is really wrong.
5242 Fix that by returnign the original sal. */
5243 xfree (expanded.sals);
5245 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5246 sal.pc = original_pc;
5247 expanded.sals[0] = sal;
5254 for (i = 0; i < expanded.nelts; ++i)
5255 if (expanded.sals[i].pc == original_pc)
5266 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5267 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5268 value. COND_STRING, if not NULL, specified the condition to be
5269 used for all breakpoints. Essentially the only case where
5270 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5271 function. In that case, it's still not possible to specify
5272 separate conditions for different overloaded functions, so
5273 we take just a single condition string.
5275 NOTE: If the function succeeds, the caller is expected to cleanup
5276 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5277 array contents). If the function fails (error() is called), the
5278 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5279 COND and SALS arrays and each of those arrays contents. */
5282 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5284 enum bptype type, enum bpdisp disposition,
5285 int thread, int ignore_count,
5286 struct breakpoint_ops *ops, int from_tty)
5289 for (i = 0; i < sals.nelts; ++i)
5291 struct symtabs_and_lines expanded =
5292 expand_line_sal_maybe (sals.sals[i]);
5294 create_breakpoint (expanded, addr_string[i],
5295 cond_string, type, disposition,
5296 thread, ignore_count, ops, from_tty);
5299 update_global_location_list ();
5302 /* Parse ARG which is assumed to be a SAL specification possibly
5303 followed by conditionals. On return, SALS contains an array of SAL
5304 addresses found. ADDR_STRING contains a vector of (canonical)
5305 address strings. ARG points to the end of the SAL. */
5308 parse_breakpoint_sals (char **address,
5309 struct symtabs_and_lines *sals,
5310 char ***addr_string,
5313 char *addr_start = *address;
5314 *addr_string = NULL;
5315 /* If no arg given, or if first arg is 'if ', use the default
5317 if ((*address) == NULL
5318 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5320 if (default_breakpoint_valid)
5322 struct symtab_and_line sal;
5323 init_sal (&sal); /* initialize to zeroes */
5324 sals->sals = (struct symtab_and_line *)
5325 xmalloc (sizeof (struct symtab_and_line));
5326 sal.pc = default_breakpoint_address;
5327 sal.line = default_breakpoint_line;
5328 sal.symtab = default_breakpoint_symtab;
5329 sal.section = find_pc_overlay (sal.pc);
5330 sals->sals[0] = sal;
5334 error (_("No default breakpoint address now."));
5338 /* Force almost all breakpoints to be in terms of the
5339 current_source_symtab (which is decode_line_1's default). This
5340 should produce the results we want almost all of the time while
5341 leaving default_breakpoint_* alone.
5342 ObjC: However, don't match an Objective-C method name which
5343 may have a '+' or '-' succeeded by a '[' */
5345 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5347 if (default_breakpoint_valid
5349 || ((strchr ("+-", (*address)[0]) != NULL)
5350 && ((*address)[1] != '['))))
5351 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5352 default_breakpoint_line, addr_string,
5355 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5356 addr_string, not_found_ptr);
5358 /* For any SAL that didn't have a canonical string, fill one in. */
5359 if (sals->nelts > 0 && *addr_string == NULL)
5360 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5361 if (addr_start != (*address))
5364 for (i = 0; i < sals->nelts; i++)
5366 /* Add the string if not present. */
5367 if ((*addr_string)[i] == NULL)
5368 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5374 /* Convert each SAL into a real PC. Verify that the PC can be
5375 inserted as a breakpoint. If it can't throw an error. */
5378 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5382 for (i = 0; i < sals->nelts; i++)
5383 resolve_sal_pc (&sals->sals[i]);
5387 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5389 struct captured_parse_breakpoint_args *args = data;
5391 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5392 args->not_found_ptr);
5395 /* Given TOK, a string specification of condition and thread, as
5396 accepted by the 'break' command, extract the condition
5397 string and thread number and set *COND_STRING and *THREAD.
5398 PC identifies the context at which the condition should be parsed.
5399 If no condition is found, *COND_STRING is set to NULL.
5400 If no thread is found, *THREAD is set to -1. */
5402 find_condition_and_thread (char *tok, CORE_ADDR pc,
5403 char **cond_string, int *thread)
5405 *cond_string = NULL;
5411 char *cond_start = NULL;
5412 char *cond_end = NULL;
5413 while (*tok == ' ' || *tok == '\t')
5418 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5421 toklen = end_tok - tok;
5423 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5425 tok = cond_start = end_tok + 1;
5426 parse_exp_1 (&tok, block_for_pc (pc), 0);
5428 *cond_string = savestring (cond_start,
5429 cond_end - cond_start);
5431 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5437 *thread = strtol (tok, &tok, 0);
5439 error (_("Junk after thread keyword."));
5440 if (!valid_thread_id (*thread))
5441 error (_("Unknown thread %d."), *thread);
5444 error (_("Junk at end of arguments."));
5448 /* Set a breakpoint. This function is shared between
5449 CLI and MI functions for setting a breakpoint.
5450 This function has two major modes of operations,
5451 selected by the PARSE_CONDITION_AND_THREAD parameter.
5452 If non-zero, the function will parse arg, extracting
5453 breakpoint location, address and thread. Otherwise,
5454 ARG is just the location of breakpoint, with condition
5455 and thread specified by the COND_STRING and THREAD
5459 break_command_really (char *arg, char *cond_string, int thread,
5460 int parse_condition_and_thread,
5461 int tempflag, int hardwareflag,
5463 enum auto_boolean pending_break_support,
5464 struct breakpoint_ops *ops,
5467 struct gdb_exception e;
5468 struct symtabs_and_lines sals;
5469 struct symtab_and_line pending_sal;
5472 char *addr_start = arg;
5474 struct cleanup *old_chain;
5475 struct cleanup *breakpoint_chain = NULL;
5476 struct captured_parse_breakpoint_args parse_args;
5485 parse_args.arg_p = &arg;
5486 parse_args.sals_p = &sals;
5487 parse_args.addr_string_p = &addr_string;
5488 parse_args.not_found_ptr = ¬_found;
5490 e = catch_exception (uiout, do_captured_parse_breakpoint,
5491 &parse_args, RETURN_MASK_ALL);
5493 /* If caller is interested in rc value from parse, set value. */
5497 throw_exception (e);
5501 case NOT_FOUND_ERROR:
5503 /* If pending breakpoint support is turned off, throw
5506 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5507 throw_exception (e);
5509 exception_print (gdb_stderr, e);
5511 /* If pending breakpoint support is auto query and the user
5512 selects no, then simply return the error code. */
5513 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5514 !nquery ("Make breakpoint pending on future shared library load? "))
5517 /* At this point, either the user was queried about setting
5518 a pending breakpoint and selected yes, or pending
5519 breakpoint behavior is on and thus a pending breakpoint
5520 is defaulted on behalf of the user. */
5521 copy_arg = xstrdup (addr_start);
5522 addr_string = ©_arg;
5524 sals.sals = &pending_sal;
5529 throw_exception (e);
5536 /* Create a chain of things that always need to be cleaned up. */
5537 old_chain = make_cleanup (null_cleanup, 0);
5541 /* Make sure that all storage allocated to SALS gets freed. */
5542 make_cleanup (xfree, sals.sals);
5544 /* Cleanup the addr_string array but not its contents. */
5545 make_cleanup (xfree, addr_string);
5548 /* ----------------------------- SNIP -----------------------------
5549 Anything added to the cleanup chain beyond this point is assumed
5550 to be part of a breakpoint. If the breakpoint create succeeds
5551 then the memory is not reclaimed. */
5552 breakpoint_chain = make_cleanup (null_cleanup, 0);
5554 /* Mark the contents of the addr_string for cleanup. These go on
5555 the breakpoint_chain and only occure if the breakpoint create
5557 for (i = 0; i < sals.nelts; i++)
5559 if (addr_string[i] != NULL)
5560 make_cleanup (xfree, addr_string[i]);
5563 /* Resolve all line numbers to PC's and verify that the addresses
5564 are ok for the target. */
5566 breakpoint_sals_to_pc (&sals, addr_start);
5568 /* Verify that condition can be parsed, before setting any
5569 breakpoints. Allocate a separate condition expression for each
5573 if (parse_condition_and_thread)
5575 /* Here we only parse 'arg' to separate condition
5576 from thread number, so parsing in context of first
5577 sal is OK. When setting the breakpoint we'll
5578 re-parse it in context of each sal. */
5581 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5583 make_cleanup (xfree, cond_string);
5587 /* Create a private copy of condition string. */
5590 cond_string = xstrdup (cond_string);
5591 make_cleanup (xfree, cond_string);
5594 create_breakpoints (sals, addr_string, cond_string,
5595 hardwareflag ? bp_hardware_breakpoint
5597 tempflag ? disp_del : disp_donttouch,
5598 thread, ignore_count, ops, from_tty);
5602 struct symtab_and_line sal = {0};
5603 struct breakpoint *b;
5605 make_cleanup (xfree, copy_arg);
5607 b = set_raw_breakpoint_without_location (hardwareflag
5608 ? bp_hardware_breakpoint
5610 set_breakpoint_count (breakpoint_count + 1);
5611 b->number = breakpoint_count;
5613 b->addr_string = addr_string[0];
5614 b->cond_string = NULL;
5615 b->ignore_count = ignore_count;
5616 b->disposition = tempflag ? disp_del : disp_donttouch;
5617 b->condition_not_parsed = 1;
5620 update_global_location_list ();
5625 warning (_("Multiple breakpoints were set.\n"
5626 "Use the \"delete\" command to delete unwanted breakpoints."));
5627 /* That's it. Discard the cleanups for data inserted into the
5629 discard_cleanups (breakpoint_chain);
5630 /* But cleanup everything else. */
5631 do_cleanups (old_chain);
5634 /* Set a breakpoint.
5635 ARG is a string describing breakpoint address,
5636 condition, and thread.
5637 FLAG specifies if a breakpoint is hardware on,
5638 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5642 break_command_1 (char *arg, int flag, int from_tty)
5644 int hardwareflag = flag & BP_HARDWAREFLAG;
5645 int tempflag = flag & BP_TEMPFLAG;
5647 break_command_really (arg,
5648 NULL, 0, 1 /* parse arg */,
5649 tempflag, hardwareflag,
5650 0 /* Ignore count */,
5651 pending_break_support,
5652 NULL /* breakpoint_ops */,
5658 set_breakpoint (char *address, char *condition,
5659 int hardwareflag, int tempflag,
5660 int thread, int ignore_count,
5663 break_command_really (address, condition, thread,
5664 0 /* condition and thread are valid. */,
5665 tempflag, hardwareflag,
5668 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5672 /* Adjust SAL to the first instruction past the function prologue.
5673 The end of the prologue is determined using the line table from
5674 the debugging information.
5676 If SAL is already past the prologue, then do nothing. */
5679 skip_prologue_sal (struct symtab_and_line *sal)
5681 struct symbol *sym = find_pc_function (sal->pc);
5682 struct symtab_and_line start_sal;
5687 start_sal = find_function_start_sal (sym, 1);
5688 if (sal->pc < start_sal.pc)
5692 /* Helper function for break_command_1 and disassemble_command. */
5695 resolve_sal_pc (struct symtab_and_line *sal)
5699 if (sal->pc == 0 && sal->symtab != NULL)
5701 if (!find_line_pc (sal->symtab, sal->line, &pc))
5702 error (_("No line %d in file \"%s\"."),
5703 sal->line, sal->symtab->filename);
5706 /* If this SAL corresponds to a breakpoint inserted using
5707 a line number, then skip the function prologue if necessary. */
5708 if (sal->explicit_line)
5709 skip_prologue_sal (sal);
5712 if (sal->section == 0 && sal->symtab != NULL)
5714 struct blockvector *bv;
5718 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5721 sym = block_function (b);
5724 fixup_symbol_section (sym, sal->symtab->objfile);
5725 sal->section = SYMBOL_BFD_SECTION (sym);
5729 /* It really is worthwhile to have the section, so we'll just
5730 have to look harder. This case can be executed if we have
5731 line numbers but no functions (as can happen in assembly
5734 struct minimal_symbol *msym;
5736 msym = lookup_minimal_symbol_by_pc (sal->pc);
5738 sal->section = SYMBOL_BFD_SECTION (msym);
5745 break_command (char *arg, int from_tty)
5747 break_command_1 (arg, 0, from_tty);
5751 tbreak_command (char *arg, int from_tty)
5753 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5757 hbreak_command (char *arg, int from_tty)
5759 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5763 thbreak_command (char *arg, int from_tty)
5765 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5769 stop_command (char *arg, int from_tty)
5771 printf_filtered (_("Specify the type of breakpoint to set.\n\
5772 Usage: stop in <function | address>\n\
5773 stop at <line>\n"));
5777 stopin_command (char *arg, int from_tty)
5781 if (arg == (char *) NULL)
5783 else if (*arg != '*')
5788 /* look for a ':'. If this is a line number specification, then
5789 say it is bad, otherwise, it should be an address or
5790 function/method name */
5791 while (*argptr && !hasColon)
5793 hasColon = (*argptr == ':');
5798 badInput = (*argptr != ':'); /* Not a class::method */
5800 badInput = isdigit (*arg); /* a simple line number */
5804 printf_filtered (_("Usage: stop in <function | address>\n"));
5806 break_command_1 (arg, 0, from_tty);
5810 stopat_command (char *arg, int from_tty)
5814 if (arg == (char *) NULL || *arg == '*') /* no line number */
5821 /* look for a ':'. If there is a '::' then get out, otherwise
5822 it is probably a line number. */
5823 while (*argptr && !hasColon)
5825 hasColon = (*argptr == ':');
5830 badInput = (*argptr == ':'); /* we have class::method */
5832 badInput = !isdigit (*arg); /* not a line number */
5836 printf_filtered (_("Usage: stop at <line>\n"));
5838 break_command_1 (arg, 0, from_tty);
5841 /* accessflag: hw_write: watch write,
5842 hw_read: watch read,
5843 hw_access: watch access (read or write) */
5845 watch_command_1 (char *arg, int accessflag, int from_tty)
5847 struct breakpoint *b, *scope_breakpoint = NULL;
5848 struct symtab_and_line sal;
5849 struct expression *exp;
5850 struct block *exp_valid_block;
5851 struct value *val, *mark;
5852 struct frame_info *frame;
5853 struct frame_info *prev_frame = NULL;
5854 char *exp_start = NULL;
5855 char *exp_end = NULL;
5856 char *tok, *id_tok_start, *end_tok;
5858 char *cond_start = NULL;
5859 char *cond_end = NULL;
5860 struct expression *cond = NULL;
5861 int i, other_type_used, target_resources_ok = 0;
5862 enum bptype bp_type;
5866 init_sal (&sal); /* initialize to zeroes */
5868 /* Make sure that we actually have parameters to parse. */
5869 if (arg != NULL && arg[0] != '\0')
5871 toklen = strlen (arg); /* Size of argument list. */
5873 /* Points tok to the end of the argument list. */
5874 tok = arg + toklen - 1;
5876 /* Go backwards in the parameters list. Skip the last parameter.
5877 If we're expecting a 'thread <thread_num>' parameter, this should
5878 be the thread identifier. */
5879 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5881 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5884 /* Points end_tok to the beginning of the last token. */
5885 id_tok_start = tok + 1;
5887 /* Go backwards in the parameters list. Skip one more parameter.
5888 If we're expecting a 'thread <thread_num>' parameter, we should
5889 reach a "thread" token. */
5890 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5895 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5898 /* Move the pointer forward to skip the whitespace and
5899 calculate the length of the token. */
5901 toklen = end_tok - tok;
5903 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5905 /* At this point we've found a "thread" token, which means
5906 the user is trying to set a watchpoint that triggers
5907 only in a specific thread. */
5910 /* Extract the thread ID from the next token. */
5911 thread = strtol (id_tok_start, &endp, 0);
5913 /* Check if the user provided a valid numeric value for the
5915 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
5916 error (_("Invalid thread ID specification %s."), id_tok_start);
5918 /* Check if the thread actually exists. */
5919 if (!valid_thread_id (thread))
5920 error (_("Unknown thread %d."), thread);
5922 /* Truncate the string and get rid of the thread <thread_num>
5923 parameter before the parameter list is parsed by the
5924 evaluate_expression() function. */
5929 /* Parse the rest of the arguments. */
5930 innermost_block = NULL;
5932 exp = parse_exp_1 (&arg, 0, 0);
5934 exp_valid_block = innermost_block;
5935 mark = value_mark ();
5936 fetch_watchpoint_value (exp, &val, NULL, NULL);
5938 release_value (val);
5941 while (*tok == ' ' || *tok == '\t')
5945 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5948 toklen = end_tok - tok;
5949 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5951 tok = cond_start = end_tok + 1;
5952 cond = parse_exp_1 (&tok, 0, 0);
5956 error (_("Junk at end of command."));
5958 if (accessflag == hw_read)
5959 bp_type = bp_read_watchpoint;
5960 else if (accessflag == hw_access)
5961 bp_type = bp_access_watchpoint;
5963 bp_type = bp_hardware_watchpoint;
5965 mem_cnt = can_use_hardware_watchpoint (val);
5966 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5967 error (_("Expression cannot be implemented with read/access watchpoint."));
5970 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5971 target_resources_ok =
5972 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5974 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5975 error (_("Target does not support this type of hardware watchpoint."));
5977 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5978 error (_("Target can only support one kind of HW watchpoint at a time."));
5981 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5982 watchpoint could not be set. */
5983 if (!mem_cnt || target_resources_ok <= 0)
5984 bp_type = bp_watchpoint;
5986 frame = block_innermost_frame (exp_valid_block);
5988 prev_frame = get_prev_frame (frame);
5992 /* If the expression is "local", then set up a "watchpoint scope"
5993 breakpoint at the point where we've left the scope of the watchpoint
5994 expression. Create the scope breakpoint before the watchpoint, so
5995 that we will encounter it first in bpstat_stop_status. */
5996 if (innermost_block && prev_frame)
5998 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5999 bp_watchpoint_scope);
6001 scope_breakpoint->enable_state = bp_enabled;
6003 /* Automatically delete the breakpoint when it hits. */
6004 scope_breakpoint->disposition = disp_del;
6006 /* Only break in the proper frame (help with recursion). */
6007 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6009 /* Set the address at which we will stop. */
6010 scope_breakpoint->loc->requested_address
6011 = get_frame_pc (prev_frame);
6012 scope_breakpoint->loc->address
6013 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6014 scope_breakpoint->type);
6017 /* Now set up the breakpoint. */
6018 b = set_raw_breakpoint (sal, bp_type);
6019 set_breakpoint_count (breakpoint_count + 1);
6020 b->number = breakpoint_count;
6022 b->disposition = disp_donttouch;
6024 b->exp_valid_block = exp_valid_block;
6025 b->exp_string = savestring (exp_start, exp_end - exp_start);
6028 b->loc->cond = cond;
6030 b->cond_string = savestring (cond_start, cond_end - cond_start);
6035 b->watchpoint_frame = get_frame_id (frame);
6037 b->watchpoint_frame = null_frame_id;
6039 if (scope_breakpoint != NULL)
6041 /* The scope breakpoint is related to the watchpoint. We will
6042 need to act on them together. */
6043 b->related_breakpoint = scope_breakpoint;
6044 scope_breakpoint->related_breakpoint = b;
6047 value_free_to_mark (mark);
6049 update_global_location_list ();
6052 /* Return count of locations need to be watched and can be handled
6053 in hardware. If the watchpoint can not be handled
6054 in hardware return zero. */
6057 can_use_hardware_watchpoint (struct value *v)
6059 int found_memory_cnt = 0;
6060 struct value *head = v;
6062 /* Did the user specifically forbid us to use hardware watchpoints? */
6063 if (!can_use_hw_watchpoints)
6066 /* Make sure that the value of the expression depends only upon
6067 memory contents, and values computed from them within GDB. If we
6068 find any register references or function calls, we can't use a
6069 hardware watchpoint.
6071 The idea here is that evaluating an expression generates a series
6072 of values, one holding the value of every subexpression. (The
6073 expression a*b+c has five subexpressions: a, b, a*b, c, and
6074 a*b+c.) GDB's values hold almost enough information to establish
6075 the criteria given above --- they identify memory lvalues,
6076 register lvalues, computed values, etcetera. So we can evaluate
6077 the expression, and then scan the chain of values that leaves
6078 behind to decide whether we can detect any possible change to the
6079 expression's final value using only hardware watchpoints.
6081 However, I don't think that the values returned by inferior
6082 function calls are special in any way. So this function may not
6083 notice that an expression involving an inferior function call
6084 can't be watched with hardware watchpoints. FIXME. */
6085 for (; v; v = value_next (v))
6087 if (VALUE_LVAL (v) == lval_memory)
6090 /* A lazy memory lvalue is one that GDB never needed to fetch;
6091 we either just used its address (e.g., `a' in `a.b') or
6092 we never needed it at all (e.g., `a' in `a,b'). */
6096 /* Ahh, memory we actually used! Check if we can cover
6097 it with hardware watchpoints. */
6098 struct type *vtype = check_typedef (value_type (v));
6100 /* We only watch structs and arrays if user asked for it
6101 explicitly, never if they just happen to appear in a
6102 middle of some value chain. */
6104 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6105 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6107 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6108 int len = TYPE_LENGTH (value_type (v));
6110 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6117 else if (VALUE_LVAL (v) != not_lval
6118 && deprecated_value_modifiable (v) == 0)
6119 return 0; /* ??? What does this represent? */
6120 else if (VALUE_LVAL (v) == lval_register)
6121 return 0; /* cannot watch a register with a HW watchpoint */
6124 /* The expression itself looks suitable for using a hardware
6125 watchpoint, but give the target machine a chance to reject it. */
6126 return found_memory_cnt;
6130 watch_command_wrapper (char *arg, int from_tty)
6132 watch_command (arg, from_tty);
6136 watch_command (char *arg, int from_tty)
6138 watch_command_1 (arg, hw_write, from_tty);
6142 rwatch_command_wrapper (char *arg, int from_tty)
6144 rwatch_command (arg, from_tty);
6148 rwatch_command (char *arg, int from_tty)
6150 watch_command_1 (arg, hw_read, from_tty);
6154 awatch_command_wrapper (char *arg, int from_tty)
6156 awatch_command (arg, from_tty);
6160 awatch_command (char *arg, int from_tty)
6162 watch_command_1 (arg, hw_access, from_tty);
6166 /* Helper routines for the until_command routine in infcmd.c. Here
6167 because it uses the mechanisms of breakpoints. */
6169 /* This function is called by fetch_inferior_event via the
6170 cmd_continuation pointer, to complete the until command. It takes
6171 care of cleaning up the temporary breakpoints set up by the until
6174 until_break_command_continuation (struct continuation_arg *arg, int error)
6176 delete_breakpoint ((struct breakpoint *)(arg->data.pointer));
6178 delete_breakpoint ((struct breakpoint *)(arg->next->data.pointer));
6182 until_break_command (char *arg, int from_tty, int anywhere)
6184 struct symtabs_and_lines sals;
6185 struct symtab_and_line sal;
6186 struct frame_info *frame = get_selected_frame (NULL);
6187 struct frame_info *prev_frame = get_prev_frame (frame);
6188 struct breakpoint *breakpoint;
6189 struct breakpoint *breakpoint2 = NULL;
6190 struct cleanup *old_chain;
6191 struct continuation_arg *arg1;
6192 struct continuation_arg *arg2;
6195 clear_proceed_status ();
6197 /* Set a breakpoint where the user wants it and at return from
6200 if (default_breakpoint_valid)
6201 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6202 default_breakpoint_line, (char ***) NULL, NULL);
6204 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6205 0, (char ***) NULL, NULL);
6207 if (sals.nelts != 1)
6208 error (_("Couldn't get information on specified line."));
6211 xfree (sals.sals); /* malloc'd, so freed */
6214 error (_("Junk at end of arguments."));
6216 resolve_sal_pc (&sal);
6219 /* If the user told us to continue until a specified location,
6220 we don't specify a frame at which we need to stop. */
6221 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6223 /* Otherwise, specify the current frame, because we want to stop only
6224 at the very same frame. */
6225 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6228 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6230 /* Keep within the current frame, or in frames called by the current
6234 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6235 sal.pc = get_frame_pc (prev_frame);
6236 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6238 make_cleanup_delete_breakpoint (breakpoint2);
6241 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6243 /* If we are running asynchronously, and proceed call above has actually
6244 managed to start the target, arrange for breakpoints to be
6245 deleted when the target stops. Otherwise, we're already stopped and
6246 delete breakpoints via cleanup chain. */
6248 if (target_can_async_p () && target_executing)
6251 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6253 arg1->data.pointer = breakpoint;
6257 arg2 = (struct continuation_arg *)
6258 xmalloc ( sizeof (struct continuation_arg));
6260 arg2->data.pointer = breakpoint2;
6264 discard_cleanups (old_chain);
6265 add_continuation (until_break_command_continuation, arg1);
6268 do_cleanups (old_chain);
6272 ep_skip_leading_whitespace (char **s)
6274 if ((s == NULL) || (*s == NULL))
6276 while (isspace (**s))
6280 /* This function examines a string, and attempts to find a token
6281 that might be an event name in the leading characters. If a
6282 possible match is found, a pointer to the last character of
6283 the token is returned. Else, NULL is returned. */
6286 ep_find_event_name_end (char *arg)
6289 char *event_name_end = NULL;
6291 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6295 /* We break out of the loop when we find a token delimiter.
6296 Basically, we're looking for alphanumerics and underscores;
6297 anything else delimites the token. */
6300 if (!isalnum (*s) && (*s != '_'))
6306 return event_name_end;
6310 /* This function attempts to parse an optional "if <cond>" clause
6311 from the arg string. If one is not found, it returns NULL.
6313 Else, it returns a pointer to the condition string. (It does not
6314 attempt to evaluate the string against a particular block.) And,
6315 it updates arg to point to the first character following the parsed
6316 if clause in the arg string. */
6319 ep_parse_optional_if_clause (char **arg)
6323 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6326 /* Skip the "if" keyword. */
6329 /* Skip any extra leading whitespace, and record the start of the
6330 condition string. */
6331 ep_skip_leading_whitespace (arg);
6334 /* Assume that the condition occupies the remainder of the arg string. */
6335 (*arg) += strlen (cond_string);
6340 /* This function attempts to parse an optional filename from the arg
6341 string. If one is not found, it returns NULL.
6343 Else, it returns a pointer to the parsed filename. (This function
6344 makes no attempt to verify that a file of that name exists, or is
6345 accessible.) And, it updates arg to point to the first character
6346 following the parsed filename in the arg string.
6348 Note that clients needing to preserve the returned filename for
6349 future access should copy it to their own buffers. */
6351 ep_parse_optional_filename (char **arg)
6353 static char filename[1024];
6358 if ((*arg_p == '\0') || isspace (*arg_p))
6376 /* Commands to deal with catching events, such as signals, exceptions,
6377 process start/exit, etc. */
6381 catch_fork, catch_vfork
6386 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6389 char *cond_string = NULL;
6391 ep_skip_leading_whitespace (&arg);
6393 /* The allowed syntax is:
6395 catch [v]fork if <cond>
6397 First, check if there's an if clause. */
6398 cond_string = ep_parse_optional_if_clause (&arg);
6400 if ((*arg != '\0') && !isspace (*arg))
6401 error (_("Junk at end of arguments."));
6403 /* If this target supports it, create a fork or vfork catchpoint
6404 and enable reporting of such events. */
6408 create_fork_event_catchpoint (tempflag, cond_string);
6411 create_vfork_event_catchpoint (tempflag, cond_string);
6414 error (_("unsupported or unknown fork kind; cannot catch it"));
6420 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6422 char *cond_string = NULL;
6424 ep_skip_leading_whitespace (&arg);
6426 /* The allowed syntax is:
6428 catch exec if <cond>
6430 First, check if there's an if clause. */
6431 cond_string = ep_parse_optional_if_clause (&arg);
6433 if ((*arg != '\0') && !isspace (*arg))
6434 error (_("Junk at end of arguments."));
6436 /* If this target supports it, create an exec catchpoint
6437 and enable reporting of such events. */
6438 create_exec_event_catchpoint (tempflag, cond_string);
6442 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6444 char *dll_pathname = NULL;
6445 char *cond_string = NULL;
6447 ep_skip_leading_whitespace (&arg);
6449 /* The allowed syntax is:
6451 catch load if <cond>
6452 catch load <filename>
6453 catch load <filename> if <cond>
6455 The user is not allowed to specify the <filename> after an
6458 We'll ignore the pathological case of a file named "if".
6460 First, check if there's an if clause. If so, then there
6461 cannot be a filename. */
6462 cond_string = ep_parse_optional_if_clause (&arg);
6464 /* If there was an if clause, then there cannot be a filename.
6465 Else, there might be a filename and an if clause. */
6466 if (cond_string == NULL)
6468 dll_pathname = ep_parse_optional_filename (&arg);
6469 ep_skip_leading_whitespace (&arg);
6470 cond_string = ep_parse_optional_if_clause (&arg);
6473 if ((*arg != '\0') && !isspace (*arg))
6474 error (_("Junk at end of arguments."));
6476 /* Create a load breakpoint that only triggers when a load of
6477 the specified dll (or any dll, if no pathname was specified)
6479 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6480 dll_pathname, cond_string);
6484 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6486 char *dll_pathname = NULL;
6487 char *cond_string = NULL;
6489 ep_skip_leading_whitespace (&arg);
6491 /* The allowed syntax is:
6493 catch unload if <cond>
6494 catch unload <filename>
6495 catch unload <filename> if <cond>
6497 The user is not allowed to specify the <filename> after an
6500 We'll ignore the pathological case of a file named "if".
6502 First, check if there's an if clause. If so, then there
6503 cannot be a filename. */
6504 cond_string = ep_parse_optional_if_clause (&arg);
6506 /* If there was an if clause, then there cannot be a filename.
6507 Else, there might be a filename and an if clause. */
6508 if (cond_string == NULL)
6510 dll_pathname = ep_parse_optional_filename (&arg);
6511 ep_skip_leading_whitespace (&arg);
6512 cond_string = ep_parse_optional_if_clause (&arg);
6515 if ((*arg != '\0') && !isspace (*arg))
6516 error (_("Junk at end of arguments."));
6518 /* Create an unload breakpoint that only triggers when an unload of
6519 the specified dll (or any dll, if no pathname was specified)
6521 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6522 dll_pathname, cond_string);
6525 static enum print_stop_action
6526 print_exception_catchpoint (struct breakpoint *b)
6528 annotate_catchpoint (b->number);
6530 if (strstr (b->addr_string, "throw") != NULL)
6531 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6534 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6537 return PRINT_SRC_AND_LOC;
6541 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6546 if (b->loc == NULL || b->loc->shlib_disabled)
6547 ui_out_field_string (uiout, "addr", "<PENDING>");
6549 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6553 *last_addr = b->loc->address;
6554 if (strstr (b->addr_string, "throw") != NULL)
6555 ui_out_field_string (uiout, "what", "exception throw");
6557 ui_out_field_string (uiout, "what", "exception catch");
6561 print_mention_exception_catchpoint (struct breakpoint *b)
6563 if (strstr (b->addr_string, "throw") != NULL)
6564 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6566 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6569 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6570 print_exception_catchpoint,
6571 print_one_exception_catchpoint,
6572 print_mention_exception_catchpoint
6576 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6577 enum exception_event_kind ex_event, int from_tty)
6579 char *trigger_func_name;
6581 if (ex_event == EX_EVENT_CATCH)
6582 trigger_func_name = "__cxa_begin_catch";
6584 trigger_func_name = "__cxa_throw";
6586 break_command_really (trigger_func_name, cond_string, -1,
6587 0 /* condition and thread are valid. */,
6590 AUTO_BOOLEAN_TRUE /* pending */,
6591 &gnu_v3_exception_catchpoint_ops, from_tty);
6596 /* Deal with "catch catch" and "catch throw" commands */
6599 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6600 int tempflag, int from_tty)
6602 char *cond_string = NULL;
6603 struct symtab_and_line *sal = NULL;
6605 ep_skip_leading_whitespace (&arg);
6607 cond_string = ep_parse_optional_if_clause (&arg);
6609 if ((*arg != '\0') && !isspace (*arg))
6610 error (_("Junk at end of arguments."));
6612 if ((ex_event != EX_EVENT_THROW) &&
6613 (ex_event != EX_EVENT_CATCH))
6614 error (_("Unsupported or unknown exception event; cannot catch it"));
6616 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6619 warning (_("Unsupported with this platform/compiler combination."));
6622 /* Create a breakpoint struct for Ada exception catchpoints. */
6625 create_ada_exception_breakpoint (struct symtab_and_line sal,
6629 struct expression *cond,
6630 struct breakpoint_ops *ops,
6634 struct breakpoint *b;
6638 describe_other_breakpoints (sal.pc, sal.section, -1);
6639 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6640 version for exception catchpoints, because two catchpoints
6641 used for different exception names will use the same address.
6642 In this case, a "breakpoint ... also set at..." warning is
6643 unproductive. Besides. the warning phrasing is also a bit
6644 inapropriate, we should use the word catchpoint, and tell
6645 the user what type of catchpoint it is. The above is good
6646 enough for now, though. */
6649 b = set_raw_breakpoint (sal, bp_breakpoint);
6650 set_breakpoint_count (breakpoint_count + 1);
6652 b->enable_state = bp_enabled;
6653 b->disposition = tempflag ? disp_del : disp_donttouch;
6654 b->number = breakpoint_count;
6655 b->ignore_count = 0;
6656 b->loc->cond = cond;
6657 b->addr_string = addr_string;
6658 b->language = language_ada;
6659 b->cond_string = cond_string;
6660 b->exp_string = exp_string;
6665 update_global_location_list ();
6668 /* Implement the "catch exception" command. */
6671 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6673 struct symtab_and_line sal;
6675 char *addr_string = NULL;
6676 char *exp_string = NULL;
6677 char *cond_string = NULL;
6678 struct expression *cond = NULL;
6679 struct breakpoint_ops *ops = NULL;
6681 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6682 &cond_string, &cond, &ops);
6683 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6684 cond_string, cond, ops, tempflag,
6688 /* Implement the "catch assert" command. */
6691 catch_assert_command (char *arg, int tempflag, int from_tty)
6693 struct symtab_and_line sal;
6694 char *addr_string = NULL;
6695 struct breakpoint_ops *ops = NULL;
6697 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6698 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6699 tempflag, from_tty);
6703 catch_command_1 (char *arg, int tempflag, int from_tty)
6706 /* The first argument may be an event name, such as "start" or "load".
6707 If so, then handle it as such. If it doesn't match an event name,
6708 then attempt to interpret it as an exception name. (This latter is
6709 the v4.16-and-earlier GDB meaning of the "catch" command.)
6711 First, try to find the bounds of what might be an event name. */
6712 char *arg1_start = arg;
6716 if (arg1_start == NULL)
6718 /* Old behaviour was to use pre-v-4.16 syntax */
6719 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6721 /* Now, this is not allowed */
6722 error (_("Catch requires an event name."));
6725 arg1_end = ep_find_event_name_end (arg1_start);
6726 if (arg1_end == NULL)
6727 error (_("catch requires an event"));
6728 arg1_length = arg1_end + 1 - arg1_start;
6730 /* Try to match what we found against known event names. */
6731 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6733 error (_("Catch of signal not yet implemented"));
6735 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6737 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6738 tempflag, from_tty);
6740 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6742 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6743 tempflag, from_tty);
6745 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6747 error (_("Catch of thread_start not yet implemented"));
6749 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6751 error (_("Catch of thread_exit not yet implemented"));
6753 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6755 error (_("Catch of thread_join not yet implemented"));
6757 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6759 error (_("Catch of start not yet implemented"));
6761 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6763 error (_("Catch of exit not yet implemented"));
6765 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6767 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6769 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6771 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6773 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6775 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6777 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6779 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6781 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6783 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6785 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6787 error (_("Catch of stop not yet implemented"));
6789 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6791 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6794 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6796 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6799 /* This doesn't appear to be an event name */
6803 /* Pre-v.4.16 behaviour was to treat the argument
6804 as the name of an exception */
6805 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6806 /* Now this is not allowed */
6807 error (_("Unknown event kind specified for catch"));
6813 catch_command (char *arg, int from_tty)
6815 catch_command_1 (arg, 0, from_tty);
6820 tcatch_command (char *arg, int from_tty)
6822 catch_command_1 (arg, 1, from_tty);
6825 /* Delete breakpoints by address or line. */
6828 clear_command (char *arg, int from_tty)
6830 struct breakpoint *b;
6831 VEC(breakpoint_p) *found = 0;
6834 struct symtabs_and_lines sals;
6835 struct symtab_and_line sal;
6840 sals = decode_line_spec (arg, 1);
6845 sals.sals = (struct symtab_and_line *)
6846 xmalloc (sizeof (struct symtab_and_line));
6847 make_cleanup (xfree, sals.sals);
6848 init_sal (&sal); /* initialize to zeroes */
6849 sal.line = default_breakpoint_line;
6850 sal.symtab = default_breakpoint_symtab;
6851 sal.pc = default_breakpoint_address;
6852 if (sal.symtab == 0)
6853 error (_("No source file specified."));
6861 /* We don't call resolve_sal_pc here. That's not
6862 as bad as it seems, because all existing breakpoints
6863 typically have both file/line and pc set. So, if
6864 clear is given file/line, we can match this to existing
6865 breakpoint without obtaining pc at all.
6867 We only support clearing given the address explicitly
6868 present in breakpoint table. Say, we've set breakpoint
6869 at file:line. There were several PC values for that file:line,
6870 due to optimization, all in one block.
6871 We've picked one PC value. If "clear" is issued with another
6872 PC corresponding to the same file:line, the breakpoint won't
6873 be cleared. We probably can still clear the breakpoint, but
6874 since the other PC value is never presented to user, user
6875 can only find it by guessing, and it does not seem important
6878 /* For each line spec given, delete bps which correspond
6879 to it. Do it in two passes, solely to preserve the current
6880 behavior that from_tty is forced true if we delete more than
6884 for (i = 0; i < sals.nelts; i++)
6886 /* If exact pc given, clear bpts at that pc.
6887 If line given (pc == 0), clear all bpts on specified line.
6888 If defaulting, clear all bpts on default line
6891 defaulting sal.pc != 0 tests to do
6896 1 0 <can't happen> */
6900 /* Find all matching breakpoints and add them to
6905 /* Are we going to delete b? */
6906 if (b->type != bp_none
6907 && b->type != bp_watchpoint
6908 && b->type != bp_hardware_watchpoint
6909 && b->type != bp_read_watchpoint
6910 && b->type != bp_access_watchpoint)
6912 struct bp_location *loc = b->loc;
6913 for (; loc; loc = loc->next)
6915 int pc_match = sal.pc
6916 && (loc->address == sal.pc)
6917 && (!section_is_overlay (loc->section)
6918 || loc->section == sal.section);
6919 int line_match = ((default_match || (0 == sal.pc))
6920 && b->source_file != NULL
6921 && sal.symtab != NULL
6922 && strcmp (b->source_file, sal.symtab->filename) == 0
6923 && b->line_number == sal.line);
6924 if (pc_match || line_match)
6933 VEC_safe_push(breakpoint_p, found, b);
6936 /* Now go thru the 'found' chain and delete them. */
6937 if (VEC_empty(breakpoint_p, found))
6940 error (_("No breakpoint at %s."), arg);
6942 error (_("No breakpoint at this line."));
6945 if (VEC_length(breakpoint_p, found) > 1)
6946 from_tty = 1; /* Always report if deleted more than one */
6949 if (VEC_length(breakpoint_p, found) == 1)
6950 printf_unfiltered (_("Deleted breakpoint "));
6952 printf_unfiltered (_("Deleted breakpoints "));
6954 breakpoints_changed ();
6956 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
6959 printf_unfiltered ("%d ", b->number);
6960 delete_breakpoint (b);
6963 putchar_unfiltered ('\n');
6966 /* Delete breakpoint in BS if they are `delete' breakpoints and
6967 all breakpoints that are marked for deletion, whether hit or not.
6968 This is called after any breakpoint is hit, or after errors. */
6971 breakpoint_auto_delete (bpstat bs)
6973 struct breakpoint *b, *temp;
6975 for (; bs; bs = bs->next)
6976 if (bs->breakpoint_at && bs->breakpoint_at->owner->disposition == disp_del
6978 delete_breakpoint (bs->breakpoint_at->owner);
6980 ALL_BREAKPOINTS_SAFE (b, temp)
6982 if (b->disposition == disp_del_at_next_stop)
6983 delete_breakpoint (b);
6988 update_global_location_list (void)
6990 struct breakpoint *b;
6991 struct bp_location **next = &bp_location_chain;
6992 struct bp_location *loc;
6993 struct bp_location *loc2;
6994 struct gdb_exception e;
6995 VEC(bp_location_p) *old_locations = NULL;
6999 /* Store old locations for future reference. */
7000 for (loc = bp_location_chain; loc; loc = loc->global_next)
7001 VEC_safe_push (bp_location_p, old_locations, loc);
7003 bp_location_chain = NULL;
7006 for (loc = b->loc; loc; loc = loc->next)
7009 next = &(loc->global_next);
7014 /* Identify bp_location instances that are no longer present in the new
7015 list, and therefore should be freed. Note that it's not necessary that
7016 those locations should be removed from inferior -- if there's another
7017 location at the same address (previously marked as duplicate),
7018 we don't need to remove/insert the location. */
7019 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7021 /* Tells if 'loc' is found amoung the new locations. If not, we
7023 int found_object = 0;
7024 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7031 /* If this location is no longer present, and inserted, look if there's
7032 maybe a new location at the same address. If so, mark that one
7033 inserted, and don't remove this one. This is needed so that we
7034 don't have a time window where a breakpoint at certain location is not
7039 /* If the location is inserted now, we might have to remove it. */
7042 if (found_object && should_be_inserted (loc))
7044 /* The location is still present in the location list, and still
7045 should be inserted. Don't do anything. */
7050 /* The location is either no longer present, or got disabled.
7051 See if there's another location at the same address, in which
7052 case we don't need to remove this one from the target. */
7053 if (breakpoint_address_is_meaningful (loc->owner))
7054 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7056 /* For the sake of should_insert_location. The
7057 call to check_duplicates will fix up this later. */
7058 loc2->duplicate = 0;
7059 if (should_be_inserted (loc2)
7060 && loc2 != loc && loc2->address == loc->address)
7063 loc2->target_info = loc->target_info;
7071 if (remove_breakpoint (loc, mark_uninserted))
7073 /* This is just about all we can do. We could keep this
7074 location on the global list, and try to remove it next
7075 time, but there's no particular reason why we will
7078 Note that at this point, loc->owner is still valid,
7079 as delete_breakpoint frees the breakpoint only
7080 after calling us. */
7081 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7082 loc->owner->number);
7087 free_bp_location (loc);
7092 check_duplicates (b);
7095 if (always_inserted_mode && target_has_execution)
7096 insert_breakpoint_locations ();
7100 update_global_location_list_nothrow (void)
7102 struct gdb_exception e;
7103 TRY_CATCH (e, RETURN_MASK_ERROR)
7104 update_global_location_list ();
7107 /* Delete a breakpoint and clean up all traces of it in the data
7111 delete_breakpoint (struct breakpoint *bpt)
7113 struct breakpoint *b;
7115 struct bp_location *loc, *next;
7117 gdb_assert (bpt != NULL);
7119 /* Has this bp already been deleted? This can happen because multiple
7120 lists can hold pointers to bp's. bpstat lists are especial culprits.
7122 One example of this happening is a watchpoint's scope bp. When the
7123 scope bp triggers, we notice that the watchpoint is out of scope, and
7124 delete it. We also delete its scope bp. But the scope bp is marked
7125 "auto-deleting", and is already on a bpstat. That bpstat is then
7126 checked for auto-deleting bp's, which are deleted.
7128 A real solution to this problem might involve reference counts in bp's,
7129 and/or giving them pointers back to their referencing bpstat's, and
7130 teaching delete_breakpoint to only free a bp's storage when no more
7131 references were extent. A cheaper bandaid was chosen. */
7132 if (bpt->type == bp_none)
7135 if (deprecated_delete_breakpoint_hook)
7136 deprecated_delete_breakpoint_hook (bpt);
7137 breakpoint_delete_event (bpt->number);
7139 if (breakpoint_chain == bpt)
7140 breakpoint_chain = bpt->next;
7145 b->next = bpt->next;
7149 free_command_lines (&bpt->commands);
7150 if (bpt->cond_string != NULL)
7151 xfree (bpt->cond_string);
7152 if (bpt->addr_string != NULL)
7153 xfree (bpt->addr_string);
7154 if (bpt->exp != NULL)
7156 if (bpt->exp_string != NULL)
7157 xfree (bpt->exp_string);
7158 if (bpt->val != NULL)
7159 value_free (bpt->val);
7160 if (bpt->source_file != NULL)
7161 xfree (bpt->source_file);
7162 if (bpt->dll_pathname != NULL)
7163 xfree (bpt->dll_pathname);
7164 if (bpt->triggered_dll_pathname != NULL)
7165 xfree (bpt->triggered_dll_pathname);
7166 if (bpt->exec_pathname != NULL)
7167 xfree (bpt->exec_pathname);
7169 /* Be sure no bpstat's are pointing at it after it's been freed. */
7170 /* FIXME, how can we find all bpstat's?
7171 We just check stop_bpstat for now. Note that we cannot just
7172 remove bpstats pointing at bpt from the stop_bpstat list
7173 entirely, as breakpoint commands are associated with the bpstat;
7174 if we remove it here, then the later call to
7175 bpstat_do_actions (&stop_bpstat);
7176 in event-top.c won't do anything, and temporary breakpoints
7177 with commands won't work. */
7178 for (bs = stop_bpstat; bs; bs = bs->next)
7179 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7181 bs->breakpoint_at = NULL;
7183 /* bs->commands will be freed later. */
7186 /* Now that breakpoint is removed from breakpoint
7187 list, update the global location list. This
7188 will remove locations that used to belong to
7189 this breakpoint. Do this before freeing
7190 the breakpoint itself, since remove_breakpoint
7191 looks at location's owner. It might be better
7192 design to have location completely self-contained,
7193 but it's not the case now. */
7194 update_global_location_list ();
7197 /* On the chance that someone will soon try again to delete this same
7198 bp, we mark it as deleted before freeing its storage. */
7199 bpt->type = bp_none;
7205 do_delete_breakpoint_cleanup (void *b)
7207 delete_breakpoint (b);
7211 make_cleanup_delete_breakpoint (struct breakpoint *b)
7213 return make_cleanup (do_delete_breakpoint_cleanup, b);
7217 delete_command (char *arg, int from_tty)
7219 struct breakpoint *b, *temp;
7225 int breaks_to_delete = 0;
7227 /* Delete all breakpoints if no argument.
7228 Do not delete internal or call-dummy breakpoints, these
7229 have to be deleted with an explicit breakpoint number argument. */
7232 if (b->type != bp_call_dummy &&
7233 b->type != bp_shlib_event &&
7234 b->type != bp_thread_event &&
7235 b->type != bp_overlay_event &&
7238 breaks_to_delete = 1;
7243 /* Ask user only if there are some breakpoints to delete. */
7245 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7247 ALL_BREAKPOINTS_SAFE (b, temp)
7249 if (b->type != bp_call_dummy &&
7250 b->type != bp_shlib_event &&
7251 b->type != bp_thread_event &&
7252 b->type != bp_overlay_event &&
7254 delete_breakpoint (b);
7259 map_breakpoint_numbers (arg, delete_breakpoint);
7263 all_locations_are_pending (struct bp_location *loc)
7265 for (; loc; loc = loc->next)
7266 if (!loc->shlib_disabled)
7271 /* Subroutine of update_breakpoint_locations to simplify it.
7272 Return non-zero if multiple fns in list LOC have the same name.
7273 Null names are ignored. */
7276 ambiguous_names_p (struct bp_location *loc)
7278 struct bp_location *l;
7279 htab_t htab = htab_create_alloc (13, htab_hash_string,
7280 (int (*) (const void *, const void *)) streq,
7281 NULL, xcalloc, xfree);
7283 for (l = loc; l != NULL; l = l->next)
7286 const char *name = l->function_name;
7288 /* Allow for some names to be NULL, ignore them. */
7292 slot = (const char **) htab_find_slot (htab, (const void *) name,
7294 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7309 update_breakpoint_locations (struct breakpoint *b,
7310 struct symtabs_and_lines sals)
7314 struct bp_location *existing_locations = b->loc;
7316 /* If there's no new locations, and all existing locations
7317 are pending, don't do anything. This optimizes
7318 the common case where all locations are in the same
7319 shared library, that was unloaded. We'd like to
7320 retain the location, so that when the library
7321 is loaded again, we don't loose the enabled/disabled
7322 status of the individual locations. */
7323 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7328 for (i = 0; i < sals.nelts; ++i)
7330 struct bp_location *new_loc =
7331 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7333 /* Reparse conditions, they might contain references to the
7335 if (b->cond_string != NULL)
7337 struct gdb_exception e;
7340 TRY_CATCH (e, RETURN_MASK_ERROR)
7342 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7347 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7348 b->number, e.message);
7349 new_loc->enabled = 0;
7353 if (b->source_file != NULL)
7354 xfree (b->source_file);
7355 if (sals.sals[i].symtab == NULL)
7356 b->source_file = NULL;
7359 savestring (sals.sals[i].symtab->filename,
7360 strlen (sals.sals[i].symtab->filename));
7362 if (b->line_number == 0)
7363 b->line_number = sals.sals[i].line;
7366 /* If possible, carry over 'disable' status from existing breakpoints. */
7368 struct bp_location *e = existing_locations;
7369 /* If there are multiple breakpoints with the same function name,
7370 e.g. for inline functions, comparing function names won't work.
7371 Instead compare pc addresses; this is just a heuristic as things
7372 may have moved, but in practice it gives the correct answer
7373 often enough until a better solution is found. */
7374 int have_ambiguous_names = ambiguous_names_p (b->loc);
7376 for (; e; e = e->next)
7378 if (!e->enabled && e->function_name)
7380 struct bp_location *l = b->loc;
7381 if (have_ambiguous_names)
7383 for (; l; l = l->next)
7384 if (e->address == l->address)
7392 for (; l; l = l->next)
7393 if (l->function_name
7394 && strcmp (e->function_name, l->function_name) == 0)
7404 update_global_location_list ();
7408 /* Reset a breakpoint given it's struct breakpoint * BINT.
7409 The value we return ends up being the return value from catch_errors.
7410 Unused in this case. */
7413 breakpoint_re_set_one (void *bint)
7415 /* get past catch_errs */
7416 struct breakpoint *b = (struct breakpoint *) bint;
7420 int *not_found_ptr = ¬_found;
7421 struct symtabs_and_lines sals = {};
7422 struct symtabs_and_lines expanded;
7424 enum enable_state save_enable;
7425 struct gdb_exception e;
7431 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7435 case bp_hardware_breakpoint:
7437 case bp_catch_unload:
7438 if (b->addr_string == NULL)
7440 /* Anything without a string can't be re-set. */
7441 delete_breakpoint (b);
7445 set_language (b->language);
7446 input_radix = b->input_radix;
7448 TRY_CATCH (e, RETURN_MASK_ERROR)
7450 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7455 int not_found_and_ok = 0;
7456 /* For pending breakpoints, it's expected that parsing
7457 will fail until the right shared library is loaded.
7458 User has already told to create pending breakpoints and
7459 don't need extra messages. If breakpoint is in bp_shlib_disabled
7460 state, then user already saw the message about that breakpoint
7461 being disabled, and don't want to see more errors. */
7463 && (b->condition_not_parsed
7464 || (b->loc && b->loc->shlib_disabled)
7465 || b->enable_state == bp_disabled))
7466 not_found_and_ok = 1;
7468 if (!not_found_and_ok)
7470 /* We surely don't want to warn about the same breakpoint
7471 10 times. One solution, implemented here, is disable
7472 the breakpoint on error. Another solution would be to
7473 have separate 'warning emitted' flag. Since this
7474 happens only when a binary has changed, I don't know
7475 which approach is better. */
7476 b->enable_state = bp_disabled;
7477 throw_exception (e);
7484 gdb_assert (sals.nelts == 1);
7485 resolve_sal_pc (&sals.sals[0]);
7486 if (b->condition_not_parsed && s && s[0])
7488 char *cond_string = 0;
7490 find_condition_and_thread (s, sals.sals[0].pc,
7491 &cond_string, &thread);
7493 b->cond_string = cond_string;
7495 b->condition_not_parsed = 0;
7497 expanded = expand_line_sal_maybe (sals.sals[0]);
7498 update_breakpoint_locations (b, expanded);
7504 case bp_hardware_watchpoint:
7505 case bp_read_watchpoint:
7506 case bp_access_watchpoint:
7507 /* Watchpoint can be either on expression using entirely global variables,
7508 or it can be on local variables.
7510 Watchpoints of the first kind are never auto-deleted, and even persist
7511 across program restarts. Since they can use variables from shared
7512 libraries, we need to reparse expression as libraries are loaded
7515 Watchpoints on local variables can also change meaning as result
7516 of solib event. For example, if a watchpoint uses both a local and
7517 a global variables in expression, it's a local watchpoint, but
7518 unloading of a shared library will make the expression invalid.
7519 This is not a very common use case, but we still re-evaluate
7520 expression, to avoid surprises to the user.
7522 Note that for local watchpoints, we re-evaluate it only if
7523 watchpoints frame id is still valid. If it's not, it means
7524 the watchpoint is out of scope and will be deleted soon. In fact,
7525 I'm not sure we'll ever be called in this case.
7527 If a local watchpoint's frame id is still valid, then
7528 b->exp_valid_block is likewise valid, and we can safely use it.
7530 Don't do anything about disabled watchpoints, since they will
7531 be reevaluated again when enabled. */
7532 update_watchpoint (b, 1 /* reparse */);
7534 /* We needn't really do anything to reset these, since the mask
7535 that requests them is unaffected by e.g., new libraries being
7538 case bp_catch_vfork:
7543 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7545 /* Delete longjmp and overlay event breakpoints; they will be
7546 reset later by breakpoint_re_set. */
7548 case bp_longjmp_resume:
7549 case bp_overlay_event:
7550 delete_breakpoint (b);
7553 /* This breakpoint is special, it's set up when the inferior
7554 starts and we really don't want to touch it. */
7555 case bp_shlib_event:
7557 /* Like bp_shlib_event, this breakpoint type is special.
7558 Once it is set up, we do not want to touch it. */
7559 case bp_thread_event:
7561 /* Keep temporary breakpoints, which can be encountered when we step
7562 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7563 Otherwise these should have been blown away via the cleanup chain
7564 or by breakpoint_init_inferior when we rerun the executable. */
7567 case bp_watchpoint_scope:
7569 case bp_step_resume:
7576 /* Re-set all breakpoints after symbols have been re-loaded. */
7578 breakpoint_re_set (void)
7580 struct breakpoint *b, *temp;
7581 enum language save_language;
7582 int save_input_radix;
7584 save_language = current_language->la_language;
7585 save_input_radix = input_radix;
7586 ALL_BREAKPOINTS_SAFE (b, temp)
7588 /* Format possible error msg */
7589 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7591 struct cleanup *cleanups = make_cleanup (xfree, message);
7592 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7593 do_cleanups (cleanups);
7595 set_language (save_language);
7596 input_radix = save_input_radix;
7598 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7600 create_longjmp_breakpoint ("longjmp");
7601 create_longjmp_breakpoint ("_longjmp");
7602 create_longjmp_breakpoint ("siglongjmp");
7603 create_longjmp_breakpoint ("_siglongjmp");
7604 create_longjmp_breakpoint (NULL);
7607 create_overlay_event_breakpoint ("_ovly_debug_event");
7610 /* Reset the thread number of this breakpoint:
7612 - If the breakpoint is for all threads, leave it as-is.
7613 - Else, reset it to the current thread for inferior_ptid. */
7615 breakpoint_re_set_thread (struct breakpoint *b)
7617 if (b->thread != -1)
7619 if (in_thread_list (inferior_ptid))
7620 b->thread = pid_to_thread_id (inferior_ptid);
7624 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7625 If from_tty is nonzero, it prints a message to that effect,
7626 which ends with a period (no newline). */
7629 set_ignore_count (int bptnum, int count, int from_tty)
7631 struct breakpoint *b;
7637 if (b->number == bptnum)
7639 b->ignore_count = count;
7643 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7645 else if (count == 1)
7646 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7649 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7652 breakpoints_changed ();
7653 breakpoint_modify_event (b->number);
7657 error (_("No breakpoint number %d."), bptnum);
7660 /* Clear the ignore counts of all breakpoints. */
7662 breakpoint_clear_ignore_counts (void)
7664 struct breakpoint *b;
7667 b->ignore_count = 0;
7670 /* Command to set ignore-count of breakpoint N to COUNT. */
7673 ignore_command (char *args, int from_tty)
7679 error_no_arg (_("a breakpoint number"));
7681 num = get_number (&p);
7683 error (_("bad breakpoint number: '%s'"), args);
7685 error (_("Second argument (specified ignore-count) is missing."));
7687 set_ignore_count (num,
7688 longest_to_int (value_as_long (parse_and_eval (p))),
7691 printf_filtered ("\n");
7694 /* Call FUNCTION on each of the breakpoints
7695 whose numbers are given in ARGS. */
7698 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7703 struct breakpoint *b, *tmp;
7707 error_no_arg (_("one or more breakpoint numbers"));
7714 num = get_number_or_range (&p1);
7717 warning (_("bad breakpoint number at or near '%s'"), p);
7721 ALL_BREAKPOINTS_SAFE (b, tmp)
7722 if (b->number == num)
7724 struct breakpoint *related_breakpoint = b->related_breakpoint;
7727 if (related_breakpoint)
7728 function (related_breakpoint);
7732 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7738 static struct bp_location *
7739 find_location_by_number (char *number)
7741 char *dot = strchr (number, '.');
7745 struct breakpoint *b;
7746 struct bp_location *loc;
7751 bp_num = get_number_or_range (&p1);
7753 error (_("Bad breakpoint number '%s'"), number);
7756 if (b->number == bp_num)
7761 if (!b || b->number != bp_num)
7762 error (_("Bad breakpoint number '%s'"), number);
7765 loc_num = get_number_or_range (&p1);
7767 error (_("Bad breakpoint location number '%s'"), number);
7771 for (;loc_num && loc; --loc_num, loc = loc->next)
7774 error (_("Bad breakpoint location number '%s'"), dot+1);
7780 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7781 If from_tty is nonzero, it prints a message to that effect,
7782 which ends with a period (no newline). */
7785 disable_breakpoint (struct breakpoint *bpt)
7787 /* Never disable a watchpoint scope breakpoint; we want to
7788 hit them when we leave scope so we can delete both the
7789 watchpoint and its scope breakpoint at that time. */
7790 if (bpt->type == bp_watchpoint_scope)
7793 /* You can't disable permanent breakpoints. */
7794 if (bpt->enable_state == bp_permanent)
7797 bpt->enable_state = bp_disabled;
7799 update_global_location_list ();
7801 if (deprecated_modify_breakpoint_hook)
7802 deprecated_modify_breakpoint_hook (bpt);
7803 breakpoint_modify_event (bpt->number);
7807 disable_command (char *args, int from_tty)
7809 struct breakpoint *bpt;
7811 ALL_BREAKPOINTS (bpt)
7815 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7820 case bp_catch_unload:
7822 case bp_catch_vfork:
7824 case bp_hardware_breakpoint:
7826 case bp_hardware_watchpoint:
7827 case bp_read_watchpoint:
7828 case bp_access_watchpoint:
7829 disable_breakpoint (bpt);
7833 else if (strchr (args, '.'))
7835 struct bp_location *loc = find_location_by_number (args);
7838 update_global_location_list ();
7841 map_breakpoint_numbers (args, disable_breakpoint);
7845 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7847 int target_resources_ok, other_type_used;
7850 if (bpt->type == bp_hardware_breakpoint)
7853 i = hw_breakpoint_used_count ();
7854 target_resources_ok =
7855 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7857 if (target_resources_ok == 0)
7858 error (_("No hardware breakpoint support in the target."));
7859 else if (target_resources_ok < 0)
7860 error (_("Hardware breakpoints used exceeds limit."));
7863 if (bpt->type == bp_watchpoint ||
7864 bpt->type == bp_hardware_watchpoint ||
7865 bpt->type == bp_read_watchpoint ||
7866 bpt->type == bp_access_watchpoint)
7868 struct frame_id saved_frame_id;
7870 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7871 if (bpt->exp_valid_block != NULL)
7873 struct frame_info *fr =
7874 fr = frame_find_by_id (bpt->watchpoint_frame);
7877 printf_filtered (_("\
7878 Cannot enable watchpoint %d because the block in which its expression\n\
7879 is valid is not currently in scope.\n"), bpt->number);
7886 value_free (bpt->val);
7887 mark = value_mark ();
7888 fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL);
7890 release_value (bpt->val);
7893 if (bpt->type == bp_hardware_watchpoint ||
7894 bpt->type == bp_read_watchpoint ||
7895 bpt->type == bp_access_watchpoint)
7897 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7898 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7900 /* Hack around 'unused var' error for some targets here */
7901 (void) mem_cnt, (void) i;
7902 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7903 bpt->type, i + mem_cnt, other_type_used);
7904 /* we can consider of type is bp_hardware_watchpoint, convert to
7905 bp_watchpoint in the following condition */
7906 if (target_resources_ok < 0)
7908 printf_filtered (_("\
7909 Cannot enable watchpoint %d because target watch resources\n\
7910 have been allocated for other watchpoints.\n"), bpt->number);
7911 value_free_to_mark (mark);
7916 select_frame (frame_find_by_id (saved_frame_id));
7917 value_free_to_mark (mark);
7920 if (bpt->enable_state != bp_permanent)
7921 bpt->enable_state = bp_enabled;
7922 bpt->disposition = disposition;
7923 update_global_location_list ();
7924 breakpoints_changed ();
7926 if (deprecated_modify_breakpoint_hook)
7927 deprecated_modify_breakpoint_hook (bpt);
7928 breakpoint_modify_event (bpt->number);
7933 enable_breakpoint (struct breakpoint *bpt)
7935 do_enable_breakpoint (bpt, bpt->disposition);
7938 /* The enable command enables the specified breakpoints (or all defined
7939 breakpoints) so they once again become (or continue to be) effective
7940 in stopping the inferior. */
7943 enable_command (char *args, int from_tty)
7945 struct breakpoint *bpt;
7947 ALL_BREAKPOINTS (bpt)
7951 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7956 case bp_catch_unload:
7958 case bp_catch_vfork:
7960 case bp_hardware_breakpoint:
7962 case bp_hardware_watchpoint:
7963 case bp_read_watchpoint:
7964 case bp_access_watchpoint:
7965 enable_breakpoint (bpt);
7969 else if (strchr (args, '.'))
7971 struct bp_location *loc = find_location_by_number (args);
7974 update_global_location_list ();
7977 map_breakpoint_numbers (args, enable_breakpoint);
7981 enable_once_breakpoint (struct breakpoint *bpt)
7983 do_enable_breakpoint (bpt, disp_disable);
7987 enable_once_command (char *args, int from_tty)
7989 map_breakpoint_numbers (args, enable_once_breakpoint);
7993 enable_delete_breakpoint (struct breakpoint *bpt)
7995 do_enable_breakpoint (bpt, disp_del);
7999 enable_delete_command (char *args, int from_tty)
8001 map_breakpoint_numbers (args, enable_delete_breakpoint);
8005 set_breakpoint_cmd (char *args, int from_tty)
8010 show_breakpoint_cmd (char *args, int from_tty)
8014 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8016 struct symtabs_and_lines
8017 decode_line_spec_1 (char *string, int funfirstline)
8019 struct symtabs_and_lines sals;
8021 error (_("Empty line specification."));
8022 if (default_breakpoint_valid)
8023 sals = decode_line_1 (&string, funfirstline,
8024 default_breakpoint_symtab,
8025 default_breakpoint_line,
8026 (char ***) NULL, NULL);
8028 sals = decode_line_1 (&string, funfirstline,
8029 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8031 error (_("Junk at end of line specification: %s"), string);
8035 /* Create and insert a raw software breakpoint at PC. Return an
8036 identifier, which should be used to remove the breakpoint later.
8037 In general, places which call this should be using something on the
8038 breakpoint chain instead; this function should be eliminated
8042 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8044 struct bp_target_info *bp_tgt;
8046 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8047 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8049 bp_tgt->placed_address = pc;
8050 if (target_insert_breakpoint (bp_tgt) != 0)
8052 /* Could not insert the breakpoint. */
8060 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8063 deprecated_remove_raw_breakpoint (void *bp)
8065 struct bp_target_info *bp_tgt = bp;
8068 ret = target_remove_breakpoint (bp_tgt);
8074 /* One (or perhaps two) breakpoints used for software single stepping. */
8076 static void *single_step_breakpoints[2];
8078 /* Create and insert a breakpoint for software single step. */
8081 insert_single_step_breakpoint (CORE_ADDR next_pc)
8085 if (single_step_breakpoints[0] == NULL)
8086 bpt_p = &single_step_breakpoints[0];
8089 gdb_assert (single_step_breakpoints[1] == NULL);
8090 bpt_p = &single_step_breakpoints[1];
8093 /* NOTE drow/2006-04-11: A future improvement to this function would be
8094 to only create the breakpoints once, and actually put them on the
8095 breakpoint chain. That would let us use set_raw_breakpoint. We could
8096 adjust the addresses each time they were needed. Doing this requires
8097 corresponding changes elsewhere where single step breakpoints are
8098 handled, however. So, for now, we use this. */
8100 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8102 error (_("Could not insert single-step breakpoint at 0x%s"),
8103 paddr_nz (next_pc));
8106 /* Remove and delete any breakpoints used for software single step. */
8109 remove_single_step_breakpoints (void)
8111 gdb_assert (single_step_breakpoints[0] != NULL);
8113 /* See insert_single_step_breakpoint for more about this deprecated
8115 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8116 single_step_breakpoints[0] = NULL;
8118 if (single_step_breakpoints[1] != NULL)
8120 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8121 single_step_breakpoints[1] = NULL;
8125 /* Check whether a software single-step breakpoint is inserted at PC. */
8128 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8132 for (i = 0; i < 2; i++)
8134 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8135 if (bp_tgt && bp_tgt->placed_address == pc)
8142 int breakpoints_always_inserted_mode (void)
8144 return always_inserted_mode;
8148 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8149 It is defined as a macro to prevent duplication.
8150 COMMAND should be a string constant containing the name of the command. */
8151 #define BREAK_ARGS_HELP(command) \
8152 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8153 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8154 If a line number is specified, break at start of code for that line.\n\
8155 If a function is specified, break at start of code for that function.\n\
8156 If an address is specified, break at that exact address.\n\
8157 With no LOCATION, uses current execution address of selected stack frame.\n\
8158 This is useful for breaking on return to a stack frame.\n\
8160 THREADNUM is the number from \"info threads\".\n\
8161 CONDITION is a boolean expression.\n\
8163 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8165 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8168 _initialize_breakpoint (void)
8170 static struct cmd_list_element *breakpoint_set_cmdlist;
8171 static struct cmd_list_element *breakpoint_show_cmdlist;
8172 struct cmd_list_element *c;
8174 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8176 breakpoint_chain = 0;
8177 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8178 before a breakpoint is set. */
8179 breakpoint_count = 0;
8181 add_com ("ignore", class_breakpoint, ignore_command, _("\
8182 Set ignore-count of breakpoint number N to COUNT.\n\
8183 Usage is `ignore N COUNT'."));
8185 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8187 add_com ("commands", class_breakpoint, commands_command, _("\
8188 Set commands to be executed when a breakpoint is hit.\n\
8189 Give breakpoint number as argument after \"commands\".\n\
8190 With no argument, the targeted breakpoint is the last one set.\n\
8191 The commands themselves follow starting on the next line.\n\
8192 Type a line containing \"end\" to indicate the end of them.\n\
8193 Give \"silent\" as the first line to make the breakpoint silent;\n\
8194 then no output is printed when it is hit, except what the commands print."));
8196 add_com ("condition", class_breakpoint, condition_command, _("\
8197 Specify breakpoint number N to break only if COND is true.\n\
8198 Usage is `condition N COND', where N is an integer and COND is an\n\
8199 expression to be evaluated whenever breakpoint N is reached."));
8201 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8202 Set a temporary breakpoint.\n\
8203 Like \"break\" except the breakpoint is only temporary,\n\
8204 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8205 by using \"enable delete\" on the breakpoint number.\n\
8207 BREAK_ARGS_HELP ("tbreak")));
8208 set_cmd_completer (c, location_completer);
8210 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8211 Set a hardware assisted breakpoint.\n\
8212 Like \"break\" except the breakpoint requires hardware support,\n\
8213 some target hardware may not have this support.\n\
8215 BREAK_ARGS_HELP ("hbreak")));
8216 set_cmd_completer (c, location_completer);
8218 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8219 Set a temporary hardware assisted breakpoint.\n\
8220 Like \"hbreak\" except the breakpoint is only temporary,\n\
8221 so it will be deleted when hit.\n\
8223 BREAK_ARGS_HELP ("thbreak")));
8224 set_cmd_completer (c, location_completer);
8226 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8227 Enable some breakpoints.\n\
8228 Give breakpoint numbers (separated by spaces) as arguments.\n\
8229 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8230 This is used to cancel the effect of the \"disable\" command.\n\
8231 With a subcommand you can enable temporarily."),
8232 &enablelist, "enable ", 1, &cmdlist);
8234 add_com ("ab", class_breakpoint, enable_command, _("\
8235 Enable some breakpoints.\n\
8236 Give breakpoint numbers (separated by spaces) as arguments.\n\
8237 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8238 This is used to cancel the effect of the \"disable\" command.\n\
8239 With a subcommand you can enable temporarily."));
8241 add_com_alias ("en", "enable", class_breakpoint, 1);
8243 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8244 Enable some breakpoints.\n\
8245 Give breakpoint numbers (separated by spaces) as arguments.\n\
8246 This is used to cancel the effect of the \"disable\" command.\n\
8247 May be abbreviated to simply \"enable\".\n"),
8248 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8250 add_cmd ("once", no_class, enable_once_command, _("\
8251 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8252 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8255 add_cmd ("delete", no_class, enable_delete_command, _("\
8256 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8257 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8260 add_cmd ("delete", no_class, enable_delete_command, _("\
8261 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8262 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8265 add_cmd ("once", no_class, enable_once_command, _("\
8266 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8267 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8270 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8271 Disable some breakpoints.\n\
8272 Arguments are breakpoint numbers with spaces in between.\n\
8273 To disable all breakpoints, give no argument.\n\
8274 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8275 &disablelist, "disable ", 1, &cmdlist);
8276 add_com_alias ("dis", "disable", class_breakpoint, 1);
8277 add_com_alias ("disa", "disable", class_breakpoint, 1);
8279 add_com ("sb", class_breakpoint, disable_command, _("\
8280 Disable some breakpoints.\n\
8281 Arguments are breakpoint numbers with spaces in between.\n\
8282 To disable all breakpoints, give no argument.\n\
8283 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8285 add_cmd ("breakpoints", class_alias, disable_command, _("\
8286 Disable some breakpoints.\n\
8287 Arguments are breakpoint numbers with spaces in between.\n\
8288 To disable all breakpoints, give no argument.\n\
8289 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8290 This command may be abbreviated \"disable\"."),
8293 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8294 Delete some breakpoints or auto-display expressions.\n\
8295 Arguments are breakpoint numbers with spaces in between.\n\
8296 To delete all breakpoints, give no argument.\n\
8298 Also a prefix command for deletion of other GDB objects.\n\
8299 The \"unset\" command is also an alias for \"delete\"."),
8300 &deletelist, "delete ", 1, &cmdlist);
8301 add_com_alias ("d", "delete", class_breakpoint, 1);
8302 add_com_alias ("del", "delete", class_breakpoint, 1);
8304 add_com ("db", class_breakpoint, delete_command, _("\
8305 Delete some breakpoints.\n\
8306 Arguments are breakpoint numbers with spaces in between.\n\
8307 To delete all breakpoints, give no argument.\n"));
8309 add_cmd ("breakpoints", class_alias, delete_command, _("\
8310 Delete some breakpoints or auto-display expressions.\n\
8311 Arguments are breakpoint numbers with spaces in between.\n\
8312 To delete all breakpoints, give no argument.\n\
8313 This command may be abbreviated \"delete\"."),
8316 add_com ("clear", class_breakpoint, clear_command, _("\
8317 Clear breakpoint at specified line or function.\n\
8318 Argument may be line number, function name, or \"*\" and an address.\n\
8319 If line number is specified, all breakpoints in that line are cleared.\n\
8320 If function is specified, breakpoints at beginning of function are cleared.\n\
8321 If an address is specified, breakpoints at that address are cleared.\n\
8323 With no argument, clears all breakpoints in the line that the selected frame\n\
8326 See also the \"delete\" command which clears breakpoints by number."));
8328 c = add_com ("break", class_breakpoint, break_command, _("\
8329 Set breakpoint at specified line or function.\n"
8330 BREAK_ARGS_HELP ("break")));
8331 set_cmd_completer (c, location_completer);
8333 add_com_alias ("b", "break", class_run, 1);
8334 add_com_alias ("br", "break", class_run, 1);
8335 add_com_alias ("bre", "break", class_run, 1);
8336 add_com_alias ("brea", "break", class_run, 1);
8340 add_com_alias ("ba", "break", class_breakpoint, 1);
8341 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8346 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8347 Break in function/address or break at a line in the current file."),
8348 &stoplist, "stop ", 1, &cmdlist);
8349 add_cmd ("in", class_breakpoint, stopin_command,
8350 _("Break in function or address."), &stoplist);
8351 add_cmd ("at", class_breakpoint, stopat_command,
8352 _("Break at a line in the current file."), &stoplist);
8353 add_com ("status", class_info, breakpoints_info, _("\
8354 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8355 The \"Type\" column indicates one of:\n\
8356 \tbreakpoint - normal breakpoint\n\
8357 \twatchpoint - watchpoint\n\
8358 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8359 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8360 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8361 address and file/line number respectively.\n\
8363 Convenience variable \"$_\" and default examine address for \"x\"\n\
8364 are set to the address of the last breakpoint listed unless the command\n\
8365 is prefixed with \"server \".\n\n\
8366 Convenience variable \"$bpnum\" contains the number of the last\n\
8370 add_info ("breakpoints", breakpoints_info, _("\
8371 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8372 The \"Type\" column indicates one of:\n\
8373 \tbreakpoint - normal breakpoint\n\
8374 \twatchpoint - watchpoint\n\
8375 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8376 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8377 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8378 address and file/line number respectively.\n\
8380 Convenience variable \"$_\" and default examine address for \"x\"\n\
8381 are set to the address of the last breakpoint listed unless the command\n\
8382 is prefixed with \"server \".\n\n\
8383 Convenience variable \"$bpnum\" contains the number of the last\n\
8387 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8388 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8389 The \"Type\" column indicates one of:\n\
8390 \tbreakpoint - normal breakpoint\n\
8391 \twatchpoint - watchpoint\n\
8392 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8393 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8394 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8395 address and file/line number respectively.\n\
8397 Convenience variable \"$_\" and default examine address for \"x\"\n\
8398 are set to the address of the last breakpoint listed unless the command\n\
8399 is prefixed with \"server \".\n\n\
8400 Convenience variable \"$bpnum\" contains the number of the last\n\
8403 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8404 Status of all breakpoints, or breakpoint number NUMBER.\n\
8405 The \"Type\" column indicates one of:\n\
8406 \tbreakpoint - normal breakpoint\n\
8407 \twatchpoint - watchpoint\n\
8408 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8409 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8410 \tuntil - internal breakpoint used by the \"until\" command\n\
8411 \tfinish - internal breakpoint used by the \"finish\" command\n\
8412 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8413 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8414 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8415 address and file/line number respectively.\n\
8417 Convenience variable \"$_\" and default examine address for \"x\"\n\
8418 are set to the address of the last breakpoint listed unless the command\n\
8419 is prefixed with \"server \".\n\n\
8420 Convenience variable \"$bpnum\" contains the number of the last\n\
8422 &maintenanceinfolist);
8424 add_com ("catch", class_breakpoint, catch_command, _("\
8425 Set catchpoints to catch events.\n\
8426 Raised signals may be caught:\n\
8427 \tcatch signal - all signals\n\
8428 \tcatch signal <signame> - a particular signal\n\
8429 Raised exceptions may be caught:\n\
8430 \tcatch throw - all exceptions, when thrown\n\
8431 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8432 \tcatch catch - all exceptions, when caught\n\
8433 \tcatch catch <exceptname> - a particular exception, when caught\n\
8434 Thread or process events may be caught:\n\
8435 \tcatch thread_start - any threads, just after creation\n\
8436 \tcatch thread_exit - any threads, just before expiration\n\
8437 \tcatch thread_join - any threads, just after joins\n\
8438 Process events may be caught:\n\
8439 \tcatch start - any processes, just after creation\n\
8440 \tcatch exit - any processes, just before expiration\n\
8441 \tcatch fork - calls to fork()\n\
8442 \tcatch vfork - calls to vfork()\n\
8443 \tcatch exec - calls to exec()\n\
8444 Dynamically-linked library events may be caught:\n\
8445 \tcatch load - loads of any library\n\
8446 \tcatch load <libname> - loads of a particular library\n\
8447 \tcatch unload - unloads of any library\n\
8448 \tcatch unload <libname> - unloads of a particular library\n\
8449 The act of your program's execution stopping may also be caught:\n\
8451 C++ exceptions may be caught:\n\
8452 \tcatch throw - all exceptions, when thrown\n\
8453 \tcatch catch - all exceptions, when caught\n\
8454 Ada exceptions may be caught:\n\
8455 \tcatch exception - all exceptions, when raised\n\
8456 \tcatch exception <name> - a particular exception, when raised\n\
8457 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8458 \tcatch assert - all failed assertions, when raised\n\
8460 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8461 after a fork or vfork is caught.\n\n\
8462 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8464 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8465 Set temporary catchpoints to catch events.\n\
8466 Args like \"catch\" command.\n\
8467 Like \"catch\" except the catchpoint is only temporary,\n\
8468 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8469 by using \"enable delete\" on the catchpoint number."));
8471 c = add_com ("watch", class_breakpoint, watch_command, _("\
8472 Set a watchpoint for an expression.\n\
8473 A watchpoint stops execution of your program whenever the value of\n\
8474 an expression changes."));
8475 set_cmd_completer (c, location_completer);
8477 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8478 Set a read watchpoint for an expression.\n\
8479 A watchpoint stops execution of your program whenever the value of\n\
8480 an expression is read."));
8481 set_cmd_completer (c, location_completer);
8483 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8484 Set a watchpoint for an expression.\n\
8485 A watchpoint stops execution of your program whenever the value of\n\
8486 an expression is either read or written."));
8487 set_cmd_completer (c, location_completer);
8489 add_info ("watchpoints", breakpoints_info,
8490 _("Synonym for ``info breakpoints''."));
8493 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8494 respond to changes - contrary to the description. */
8495 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8496 &can_use_hw_watchpoints, _("\
8497 Set debugger's willingness to use watchpoint hardware."), _("\
8498 Show debugger's willingness to use watchpoint hardware."), _("\
8499 If zero, gdb will not use hardware for new watchpoints, even if\n\
8500 such is available. (However, any hardware watchpoints that were\n\
8501 created before setting this to nonzero, will continue to use watchpoint\n\
8504 show_can_use_hw_watchpoints,
8505 &setlist, &showlist);
8507 can_use_hw_watchpoints = 1;
8509 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8510 Breakpoint specific settings\n\
8511 Configure various breakpoint-specific variables such as\n\
8512 pending breakpoint behavior"),
8513 &breakpoint_set_cmdlist, "set breakpoint ",
8514 0/*allow-unknown*/, &setlist);
8515 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8516 Breakpoint specific settings\n\
8517 Configure various breakpoint-specific variables such as\n\
8518 pending breakpoint behavior"),
8519 &breakpoint_show_cmdlist, "show breakpoint ",
8520 0/*allow-unknown*/, &showlist);
8522 add_setshow_auto_boolean_cmd ("pending", no_class,
8523 &pending_break_support, _("\
8524 Set debugger's behavior regarding pending breakpoints."), _("\
8525 Show debugger's behavior regarding pending breakpoints."), _("\
8526 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8527 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8528 an error. If auto, an unrecognized breakpoint location results in a\n\
8529 user-query to see if a pending breakpoint should be created."),
8531 show_pending_break_support,
8532 &breakpoint_set_cmdlist,
8533 &breakpoint_show_cmdlist);
8535 pending_break_support = AUTO_BOOLEAN_AUTO;
8537 add_setshow_boolean_cmd ("auto-hw", no_class,
8538 &automatic_hardware_breakpoints, _("\
8539 Set automatic usage of hardware breakpoints."), _("\
8540 Show automatic usage of hardware breakpoints."), _("\
8541 If set, the debugger will automatically use hardware breakpoints for\n\
8542 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8543 a warning will be emitted for such breakpoints."),
8545 show_automatic_hardware_breakpoints,
8546 &breakpoint_set_cmdlist,
8547 &breakpoint_show_cmdlist);
8549 add_setshow_boolean_cmd ("always-inserted", class_support,
8550 &always_inserted_mode, _("\
8551 Set mode for inserting breakpoints."), _("\
8552 Show mode for inserting breakpoints."), _("\
8553 When this mode is off (which is the default), breakpoints are inserted in\n\
8554 inferior when it is resumed, and removed when execution stops. When this\n\
8555 mode is on, breakpoints are inserted immediately and removed only when\n\
8556 the user deletes the breakpoint."),
8558 &show_always_inserted_mode,
8559 &breakpoint_set_cmdlist,
8560 &breakpoint_show_cmdlist);
8562 automatic_hardware_breakpoints = 1;