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, 2009 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/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 /* readline include files */
64 #include "readline/readline.h"
65 #include "readline/history.h"
67 /* readline defines this. */
70 #include "mi/mi-common.h"
72 /* Arguments to pass as context to some catch command handlers. */
73 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
74 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
76 /* Prototypes for local functions. */
78 static void enable_delete_command (char *, int);
80 static void enable_delete_breakpoint (struct breakpoint *);
82 static void enable_once_command (char *, int);
84 static void enable_once_breakpoint (struct breakpoint *);
86 static void disable_command (char *, int);
88 static void enable_command (char *, int);
90 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value *);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint *);
108 /* This function is used in gdbtk sources and thus can not be made static. */
109 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
110 struct symtab_and_line,
113 static void check_duplicates (struct breakpoint *);
115 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
117 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
121 static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR,
122 struct obj_section *, int);
124 static void breakpoints_info (char *, int);
126 static void breakpoint_1 (int, int);
128 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
130 static int breakpoint_cond_eval (void *);
132 static void cleanup_executing_breakpoints (void *);
134 static void commands_command (char *, int);
136 static void condition_command (char *, int);
138 static int get_number_trailer (char **, int);
140 void set_breakpoint_count (int);
149 static int remove_breakpoint (struct bp_location *, insertion_state_t);
151 static enum print_stop_action print_it_typical (bpstat);
153 static enum print_stop_action print_bp_stop_message (bpstat bs);
155 static int watchpoint_check (void *);
157 static void maintenance_info_breakpoints (char *, int);
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 stop_command (char *arg, int from_tty);
177 static void stopin_command (char *arg, int from_tty);
179 static void stopat_command (char *arg, int from_tty);
181 static char *ep_parse_optional_if_clause (char **arg);
183 static char *ep_parse_optional_filename (char **arg);
185 static void catch_exception_command_1 (enum exception_event_kind ex_event,
186 char *arg, int tempflag, int from_tty);
188 static void tcatch_command (char *arg, int from_tty);
190 static void ep_skip_leading_whitespace (char **s);
192 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
194 static void free_bp_location (struct bp_location *loc);
196 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
198 static void update_global_location_list (int);
200 static void update_global_location_list_nothrow (int);
202 static int is_hardware_watchpoint (struct breakpoint *bpt);
204 static void insert_breakpoint_locations (void);
206 static void tracepoints_info (char *, int);
208 static void delete_trace_command (char *, int);
210 static void enable_trace_command (char *, int);
212 static void disable_trace_command (char *, int);
214 static void trace_pass_command (char *, int);
216 static void skip_prologue_sal (struct symtab_and_line *sal);
219 /* Flag indicating that a command has proceeded the inferior past the
220 current breakpoint. */
222 static int breakpoint_proceeded;
225 bpdisp_text (enum bpdisp disp)
227 /* NOTE: the following values are a part of MI protocol and represent
228 values of 'disp' field returned when inferior stops at a breakpoint. */
229 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
230 return bpdisps[(int) disp];
233 /* Prototypes for exported functions. */
234 /* If FALSE, gdb will not use hardware support for watchpoints, even
235 if such is available. */
236 static int can_use_hw_watchpoints;
239 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
240 struct cmd_list_element *c,
243 fprintf_filtered (file, _("\
244 Debugger's willingness to use watchpoint hardware is %s.\n"),
248 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
249 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
250 for unrecognized breakpoint locations.
251 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
252 static enum auto_boolean pending_break_support;
254 show_pending_break_support (struct ui_file *file, int from_tty,
255 struct cmd_list_element *c,
258 fprintf_filtered (file, _("\
259 Debugger's behavior regarding pending breakpoints is %s.\n"),
263 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
264 set with "break" but falling in read-only memory.
265 If 0, gdb will warn about such breakpoints, but won't automatically
266 use hardware breakpoints. */
267 static int automatic_hardware_breakpoints;
269 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
270 struct cmd_list_element *c,
273 fprintf_filtered (file, _("\
274 Automatic usage of hardware breakpoints is %s.\n"),
278 /* If on, gdb will keep breakpoints inserted even as inferior is
279 stopped, and immediately insert any new breakpoints. If off, gdb
280 will insert breakpoints into inferior only when resuming it, and
281 will remove breakpoints upon stop. If auto, GDB will behave as ON
282 if in non-stop mode, and as OFF if all-stop mode.*/
284 static const char always_inserted_auto[] = "auto";
285 static const char always_inserted_on[] = "on";
286 static const char always_inserted_off[] = "off";
287 static const char *always_inserted_enums[] = {
288 always_inserted_auto,
293 static const char *always_inserted_mode = always_inserted_auto;
295 show_always_inserted_mode (struct ui_file *file, int from_tty,
296 struct cmd_list_element *c, const char *value)
298 if (always_inserted_mode == always_inserted_auto)
299 fprintf_filtered (file, _("\
300 Always inserted breakpoint mode is %s (currently %s).\n"),
302 breakpoints_always_inserted_mode () ? "on" : "off");
304 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
308 breakpoints_always_inserted_mode (void)
310 return (always_inserted_mode == always_inserted_on
311 || (always_inserted_mode == always_inserted_auto && non_stop));
314 void _initialize_breakpoint (void);
316 /* Are we executing breakpoint commands? */
317 static int executing_breakpoint_commands;
319 /* Are overlay event breakpoints enabled? */
320 static int overlay_events_enabled;
322 /* Walk the following statement or block through all breakpoints.
323 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
326 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
328 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
329 for (B = breakpoint_chain; \
330 B ? (TMP=B->next, 1): 0; \
333 /* Similar iterators for the low-level breakpoints. */
335 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
337 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
338 for (B = bp_location_chain; \
339 B ? (TMP=B->global_next, 1): 0; \
342 /* Iterator for tracepoints only. */
344 #define ALL_TRACEPOINTS(B) \
345 for (B = breakpoint_chain; B; B = B->next) \
346 if ((B)->type == bp_tracepoint)
348 /* Chains of all breakpoints defined. */
350 struct breakpoint *breakpoint_chain;
352 struct bp_location *bp_location_chain;
354 /* The locations that no longer correspond to any breakpoint,
355 unlinked from bp_location_chain, but for which a hit
356 may still be reported by a target. */
357 VEC(bp_location_p) *moribund_locations = NULL;
359 /* Number of last breakpoint made. */
361 int breakpoint_count;
363 /* Number of last tracepoint made. */
365 int tracepoint_count;
367 /* Return whether a breakpoint is an active enabled breakpoint. */
369 breakpoint_enabled (struct breakpoint *b)
371 return (b->enable_state == bp_enabled);
374 /* Set breakpoint count to NUM. */
377 set_breakpoint_count (int num)
379 breakpoint_count = num;
380 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
383 /* Used in run_command to zero the hit count when a new run starts. */
386 clear_breakpoint_hit_counts (void)
388 struct breakpoint *b;
394 /* Default address, symtab and line to put a breakpoint at
395 for "break" command with no arg.
396 if default_breakpoint_valid is zero, the other three are
397 not valid, and "break" with no arg is an error.
399 This set by print_stack_frame, which calls set_default_breakpoint. */
401 int default_breakpoint_valid;
402 CORE_ADDR default_breakpoint_address;
403 struct symtab *default_breakpoint_symtab;
404 int default_breakpoint_line;
406 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
407 Advance *PP after the string and any trailing whitespace.
409 Currently the string can either be a number or "$" followed by the name
410 of a convenience variable. Making it an expression wouldn't work well
411 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
413 If the string is a NULL pointer, that denotes the last breakpoint.
415 TRAILER is a character which can be found after the number; most
416 commonly this is `-'. If you don't want a trailer, use \0. */
418 get_number_trailer (char **pp, int trailer)
420 int retval = 0; /* default */
424 /* Empty line means refer to the last breakpoint. */
425 return breakpoint_count;
428 /* Make a copy of the name, so we can null-terminate it
429 to pass to lookup_internalvar(). */
434 while (isalnum (*p) || *p == '_')
436 varname = (char *) alloca (p - start + 1);
437 strncpy (varname, start, p - start);
438 varname[p - start] = '\0';
439 if (get_internalvar_integer (lookup_internalvar (varname), &val))
443 printf_filtered (_("Convenience variable must have integer value.\n"));
451 while (*p >= '0' && *p <= '9')
454 /* There is no number here. (e.g. "cond a == b"). */
456 /* Skip non-numeric token */
457 while (*p && !isspace((int) *p))
459 /* Return zero, which caller must interpret as error. */
465 if (!(isspace (*p) || *p == '\0' || *p == trailer))
467 /* Trailing junk: return 0 and let caller print error msg. */
468 while (!(isspace (*p) || *p == '\0' || *p == trailer))
479 /* Like get_number_trailer, but don't allow a trailer. */
481 get_number (char **pp)
483 return get_number_trailer (pp, '\0');
486 /* Parse a number or a range.
487 * A number will be of the form handled by get_number.
488 * A range will be of the form <number1> - <number2>, and
489 * will represent all the integers between number1 and number2,
492 * While processing a range, this fuction is called iteratively;
493 * At each call it will return the next value in the range.
495 * At the beginning of parsing a range, the char pointer PP will
496 * be advanced past <number1> and left pointing at the '-' token.
497 * Subsequent calls will not advance the pointer until the range
498 * is completed. The call that completes the range will advance
499 * pointer PP past <number2>.
503 get_number_or_range (char **pp)
505 static int last_retval, end_value;
506 static char *end_ptr;
507 static int in_range = 0;
511 /* Default case: pp is pointing either to a solo number,
512 or to the first number of a range. */
513 last_retval = get_number_trailer (pp, '-');
518 /* This is the start of a range (<number1> - <number2>).
519 Skip the '-', parse and remember the second number,
520 and also remember the end of the final token. */
524 while (isspace ((int) *end_ptr))
525 end_ptr++; /* skip white space */
526 end_value = get_number (temp);
527 if (end_value < last_retval)
529 error (_("inverted range"));
531 else if (end_value == last_retval)
533 /* degenerate range (number1 == number2). Advance the
534 token pointer so that the range will be treated as a
543 error (_("negative value"));
546 /* pp points to the '-' that betokens a range. All
547 number-parsing has already been done. Return the next
548 integer value (one greater than the saved previous value).
549 Do not advance the token pointer 'pp' until the end of range
552 if (++last_retval == end_value)
554 /* End of range reached; advance token pointer. */
564 /* condition N EXP -- set break condition of breakpoint N to EXP. */
567 condition_command (char *arg, int from_tty)
569 struct breakpoint *b;
574 error_no_arg (_("breakpoint number"));
577 bnum = get_number (&p);
579 error (_("Bad breakpoint argument: '%s'"), arg);
582 if (b->number == bnum)
584 struct bp_location *loc = b->loc;
585 for (; loc; loc = loc->next)
593 if (b->cond_string != NULL)
594 xfree (b->cond_string);
598 b->cond_string = NULL;
600 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
605 /* I don't know if it matters whether this is the string the user
606 typed in or the decompiled expression. */
607 b->cond_string = xstrdup (arg);
608 b->condition_not_parsed = 0;
609 for (loc = b->loc; loc; loc = loc->next)
613 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
615 error (_("Junk at end of expression"));
618 breakpoints_changed ();
619 observer_notify_breakpoint_modified (b->number);
623 error (_("No breakpoint number %d."), bnum);
627 commands_command (char *arg, int from_tty)
629 struct breakpoint *b;
632 struct command_line *l;
634 /* If we allowed this, we would have problems with when to
635 free the storage, if we change the commands currently
638 if (executing_breakpoint_commands)
639 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
642 bnum = get_number (&p);
645 error (_("Unexpected extra arguments following breakpoint number."));
648 if (b->number == bnum)
650 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
652 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
653 l = read_command_lines (tmpbuf, from_tty, 1);
654 do_cleanups (cleanups);
655 free_command_lines (&b->commands);
657 breakpoints_changed ();
658 observer_notify_breakpoint_modified (b->number);
661 error (_("No breakpoint number %d."), bnum);
664 /* Like commands_command, but instead of reading the commands from
665 input stream, takes them from an already parsed command structure.
667 This is used by cli-script.c to DTRT with breakpoint commands
668 that are part of if and while bodies. */
669 enum command_control_type
670 commands_from_control_command (char *arg, struct command_line *cmd)
672 struct breakpoint *b;
676 /* If we allowed this, we would have problems with when to
677 free the storage, if we change the commands currently
680 if (executing_breakpoint_commands)
681 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
683 /* An empty string for the breakpoint number means the last
684 breakpoint, but get_number expects a NULL pointer. */
689 bnum = get_number (&p);
692 error (_("Unexpected extra arguments following breakpoint number."));
695 if (b->number == bnum)
697 free_command_lines (&b->commands);
698 if (cmd->body_count != 1)
699 error (_("Invalid \"commands\" block structure."));
700 /* We need to copy the commands because if/while will free the
701 list after it finishes execution. */
702 b->commands = copy_command_lines (cmd->body_list[0]);
703 breakpoints_changed ();
704 observer_notify_breakpoint_modified (b->number);
705 return simple_control;
707 error (_("No breakpoint number %d."), bnum);
710 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
711 by replacing any memory breakpoints with their shadowed contents. */
714 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
716 struct bp_location *b;
717 CORE_ADDR bp_addr = 0;
723 if (b->owner->type == bp_none)
724 warning (_("reading through apparently deleted breakpoint #%d?"),
727 if (b->loc_type != bp_loc_software_breakpoint)
731 /* Addresses and length of the part of the breakpoint that
733 bp_addr = b->target_info.placed_address;
734 bp_size = b->target_info.shadow_len;
736 /* bp isn't valid, or doesn't shadow memory. */
739 if (bp_addr + bp_size <= memaddr)
740 /* The breakpoint is entirely before the chunk of memory we
744 if (bp_addr >= memaddr + len)
745 /* The breakpoint is entirely after the chunk of memory we are
749 /* Offset within shadow_contents. */
750 if (bp_addr < memaddr)
752 /* Only copy the second part of the breakpoint. */
753 bp_size -= memaddr - bp_addr;
754 bptoffset = memaddr - bp_addr;
758 if (bp_addr + bp_size > memaddr + len)
760 /* Only copy the first part of the breakpoint. */
761 bp_size -= (bp_addr + bp_size) - (memaddr + len);
764 memcpy (buf + bp_addr - memaddr,
765 b->target_info.shadow_contents + bptoffset, bp_size);
770 /* A wrapper function for inserting catchpoints. */
772 insert_catchpoint (struct ui_out *uo, void *args)
774 struct breakpoint *b = (struct breakpoint *) args;
777 gdb_assert (b->type == bp_catchpoint);
778 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
784 is_hardware_watchpoint (struct breakpoint *bpt)
786 return (bpt->type == bp_hardware_watchpoint
787 || bpt->type == bp_read_watchpoint
788 || bpt->type == bp_access_watchpoint);
791 /* Find the current value of a watchpoint on EXP. Return the value in
792 *VALP and *RESULTP and the chain of intermediate and final values
793 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
796 If a memory error occurs while evaluating the expression, *RESULTP will
797 be set to NULL. *RESULTP may be a lazy value, if the result could
798 not be read from memory. It is used to determine whether a value
799 is user-specified (we should watch the whole value) or intermediate
800 (we should watch only the bit used to locate the final value).
802 If the final value, or any intermediate value, could not be read
803 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
804 set to any referenced values. *VALP will never be a lazy value.
805 This is the value which we store in struct breakpoint.
807 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
808 value chain. The caller must free the values individually. If
809 VAL_CHAIN is NULL, all generated values will be left on the value
813 fetch_watchpoint_value (struct expression *exp, struct value **valp,
814 struct value **resultp, struct value **val_chain)
816 struct value *mark, *new_mark, *result;
817 volatile struct gdb_exception ex;
825 /* Evaluate the expression. */
826 mark = value_mark ();
829 TRY_CATCH (ex, RETURN_MASK_ALL)
831 result = evaluate_expression (exp);
835 /* Ignore memory errors, we want watchpoints pointing at
836 inaccessible memory to still be created; otherwise, throw the
837 error to some higher catcher. */
843 throw_exception (ex);
848 new_mark = value_mark ();
849 if (mark == new_mark)
854 /* Make sure it's not lazy, so that after the target stops again we
855 have a non-lazy previous value to compare with. */
857 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
862 /* Return the chain of intermediate values. We use this to
863 decide which addresses to watch. */
864 *val_chain = new_mark;
865 value_release_to_mark (mark);
869 /* Assuming that B is a watchpoint:
870 - Reparse watchpoint expression, if REPARSE is non-zero
871 - Evaluate expression and store the result in B->val
872 - Evaluate the condition if there is one, and store the result
874 - Update the list of values that must be watched in B->loc.
876 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
877 If this is local watchpoint that is out of scope, delete it. */
879 update_watchpoint (struct breakpoint *b, int reparse)
881 int within_current_scope;
882 struct frame_id saved_frame_id;
883 struct bp_location *loc;
886 /* We don't free locations. They are stored in bp_location_chain and
887 update_global_locations will eventually delete them and remove
888 breakpoints if needed. */
891 if (b->disposition == disp_del_at_next_stop)
894 /* Save the current frame's ID so we can restore it after
895 evaluating the watchpoint expression on its own frame. */
896 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
897 took a frame parameter, so that we didn't have to change the
899 saved_frame_id = get_frame_id (get_selected_frame (NULL));
901 /* Determine if the watchpoint is within scope. */
902 if (b->exp_valid_block == NULL)
903 within_current_scope = 1;
906 struct frame_info *fi;
907 fi = frame_find_by_id (b->watchpoint_frame);
908 within_current_scope = (fi != NULL);
909 if (within_current_scope)
913 if (within_current_scope && reparse)
922 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
923 /* If the meaning of expression itself changed, the old value is
924 no longer relevant. We don't want to report a watchpoint hit
925 to the user when the old value and the new value may actually
926 be completely different objects. */
932 /* If we failed to parse the expression, for example because
933 it refers to a global variable in a not-yet-loaded shared library,
934 don't try to insert watchpoint. We don't automatically delete
935 such watchpoint, though, since failure to parse expression
936 is different from out-of-scope watchpoint. */
937 if (within_current_scope && b->exp)
939 struct value *val_chain, *v, *result, *next;
941 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
943 /* Avoid setting b->val if it's already set. The meaning of
944 b->val is 'the last value' user saw, and we should update
945 it only if we reported that last value to user. As it
946 happens, the code that reports it updates b->val directly. */
953 /* Change the type of breakpoint between hardware assisted or an
954 ordinary watchpoint depending on the hardware support and free
955 hardware slots. REPARSE is set when the inferior is started. */
956 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
959 int i, mem_cnt, other_type_used;
961 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
963 mem_cnt = can_use_hardware_watchpoint (val_chain);
966 b->type = bp_watchpoint;
969 int target_resources_ok = target_can_use_hardware_watchpoint
970 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
971 if (target_resources_ok <= 0)
972 b->type = bp_watchpoint;
974 b->type = bp_hardware_watchpoint;
978 /* Look at each value on the value chain. */
979 for (v = val_chain; v; v = next)
981 /* If it's a memory location, and GDB actually needed
982 its contents to evaluate the expression, then we
983 must watch it. If the first value returned is
984 still lazy, that means an error occurred reading it;
985 watch it anyway in case it becomes readable. */
986 if (VALUE_LVAL (v) == lval_memory
987 && (v == val_chain || ! value_lazy (v)))
989 struct type *vtype = check_typedef (value_type (v));
991 /* We only watch structs and arrays if user asked
992 for it explicitly, never if they just happen to
993 appear in the middle of some value chain. */
995 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
996 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1000 struct bp_location *loc, **tmp;
1002 addr = value_address (v);
1003 len = TYPE_LENGTH (value_type (v));
1005 if (b->type == bp_read_watchpoint)
1007 else if (b->type == bp_access_watchpoint)
1010 loc = allocate_bp_location (b);
1011 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1014 loc->gdbarch = get_type_arch (value_type (v));
1015 loc->address = addr;
1017 loc->watchpoint_type = type;
1021 next = value_next (v);
1026 /* We just regenerated the list of breakpoint locations.
1027 The new location does not have its condition field set to anything
1028 and therefore, we must always reparse the cond_string, independently
1029 of the value of the reparse flag. */
1030 if (b->cond_string != NULL)
1032 char *s = b->cond_string;
1033 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1036 else if (!within_current_scope)
1038 printf_filtered (_("\
1039 Watchpoint %d deleted because the program has left the block \n\
1040 in which its expression is valid.\n"),
1042 if (b->related_breakpoint)
1043 b->related_breakpoint->disposition = disp_del_at_next_stop;
1044 b->disposition = disp_del_at_next_stop;
1047 /* Restore the selected frame. */
1048 select_frame (frame_find_by_id (saved_frame_id));
1052 /* Returns 1 iff breakpoint location should be
1053 inserted in the inferior. */
1055 should_be_inserted (struct bp_location *bpt)
1057 if (!breakpoint_enabled (bpt->owner))
1060 if (bpt->owner->disposition == disp_del_at_next_stop)
1063 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1066 /* Tracepoints are inserted by the target at a time of its choosing,
1068 if (bpt->owner->type == bp_tracepoint)
1074 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1075 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1076 and HW_BREAKPOINT_ERROR are used to report problems.
1078 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1079 method for each breakpoint or catchpoint type. */
1081 insert_bp_location (struct bp_location *bpt,
1082 struct ui_file *tmp_error_stream,
1083 int *disabled_breaks,
1084 int *hw_breakpoint_error)
1088 if (!should_be_inserted (bpt) || bpt->inserted)
1091 /* Initialize the target-specific information. */
1092 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1093 bpt->target_info.placed_address = bpt->address;
1095 if (bpt->loc_type == bp_loc_software_breakpoint
1096 || bpt->loc_type == bp_loc_hardware_breakpoint)
1098 if (bpt->owner->type != bp_hardware_breakpoint)
1100 /* If the explicitly specified breakpoint type
1101 is not hardware breakpoint, check the memory map to see
1102 if the breakpoint address is in read only memory or not.
1103 Two important cases are:
1104 - location type is not hardware breakpoint, memory
1105 is readonly. We change the type of the location to
1106 hardware breakpoint.
1107 - location type is hardware breakpoint, memory is read-write.
1108 This means we've previously made the location hardware one, but
1109 then the memory map changed, so we undo.
1111 When breakpoints are removed, remove_breakpoints will
1112 use location types we've just set here, the only possible
1113 problem is that memory map has changed during running program,
1114 but it's not going to work anyway with current gdb. */
1115 struct mem_region *mr
1116 = lookup_mem_region (bpt->target_info.placed_address);
1120 if (automatic_hardware_breakpoints)
1123 enum bp_loc_type new_type;
1125 if (mr->attrib.mode != MEM_RW)
1126 new_type = bp_loc_hardware_breakpoint;
1128 new_type = bp_loc_software_breakpoint;
1130 if (new_type != bpt->loc_type)
1132 static int said = 0;
1133 bpt->loc_type = new_type;
1136 fprintf_filtered (gdb_stdout, _("\
1137 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1142 else if (bpt->loc_type == bp_loc_software_breakpoint
1143 && mr->attrib.mode != MEM_RW)
1144 warning (_("cannot set software breakpoint at readonly address %s"),
1145 paddress (bpt->gdbarch, bpt->address));
1149 /* First check to see if we have to handle an overlay. */
1150 if (overlay_debugging == ovly_off
1151 || bpt->section == NULL
1152 || !(section_is_overlay (bpt->section)))
1154 /* No overlay handling: just set the breakpoint. */
1156 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1157 val = target_insert_hw_breakpoint (bpt->gdbarch,
1160 val = target_insert_breakpoint (bpt->gdbarch,
1165 /* This breakpoint is in an overlay section.
1166 Shall we set a breakpoint at the LMA? */
1167 if (!overlay_events_enabled)
1169 /* Yes -- overlay event support is not active,
1170 so we must try to set a breakpoint at the LMA.
1171 This will not work for a hardware breakpoint. */
1172 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1173 warning (_("hardware breakpoint %d not supported in overlay!"),
1174 bpt->owner->number);
1177 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1179 /* Set a software (trap) breakpoint at the LMA. */
1180 bpt->overlay_target_info = bpt->target_info;
1181 bpt->overlay_target_info.placed_address = addr;
1182 val = target_insert_breakpoint (bpt->gdbarch,
1183 &bpt->overlay_target_info);
1185 fprintf_unfiltered (tmp_error_stream,
1186 "Overlay breakpoint %d failed: in ROM?\n",
1187 bpt->owner->number);
1190 /* Shall we set a breakpoint at the VMA? */
1191 if (section_is_mapped (bpt->section))
1193 /* Yes. This overlay section is mapped into memory. */
1194 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1195 val = target_insert_hw_breakpoint (bpt->gdbarch,
1198 val = target_insert_breakpoint (bpt->gdbarch,
1203 /* No. This breakpoint will not be inserted.
1204 No error, but do not mark the bp as 'inserted'. */
1211 /* Can't set the breakpoint. */
1212 if (solib_name_from_address (bpt->address))
1214 /* See also: disable_breakpoints_in_shlibs. */
1216 bpt->shlib_disabled = 1;
1217 if (!*disabled_breaks)
1219 fprintf_unfiltered (tmp_error_stream,
1220 "Cannot insert breakpoint %d.\n",
1221 bpt->owner->number);
1222 fprintf_unfiltered (tmp_error_stream,
1223 "Temporarily disabling shared library breakpoints:\n");
1225 *disabled_breaks = 1;
1226 fprintf_unfiltered (tmp_error_stream,
1227 "breakpoint #%d\n", bpt->owner->number);
1231 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1233 *hw_breakpoint_error = 1;
1234 fprintf_unfiltered (tmp_error_stream,
1235 "Cannot insert hardware breakpoint %d.\n",
1236 bpt->owner->number);
1240 fprintf_unfiltered (tmp_error_stream,
1241 "Cannot insert breakpoint %d.\n",
1242 bpt->owner->number);
1243 fprintf_filtered (tmp_error_stream,
1244 "Error accessing memory address ");
1245 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1247 fprintf_filtered (tmp_error_stream, ": %s.\n",
1248 safe_strerror (val));
1259 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1260 /* NOTE drow/2003-09-08: This state only exists for removing
1261 watchpoints. It's not clear that it's necessary... */
1262 && bpt->owner->disposition != disp_del_at_next_stop)
1264 val = target_insert_watchpoint (bpt->address,
1266 bpt->watchpoint_type);
1267 bpt->inserted = (val != -1);
1270 else if (bpt->owner->type == bp_catchpoint)
1272 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1273 bpt->owner, RETURN_MASK_ERROR);
1274 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1275 bpt->owner->number);
1277 bpt->owner->enable_state = bp_disabled;
1281 /* We've already printed an error message if there was a problem
1282 inserting this catchpoint, and we've disabled the catchpoint,
1283 so just return success. */
1290 /* Make sure all breakpoints are inserted in inferior.
1291 Throws exception on any error.
1292 A breakpoint that is already inserted won't be inserted
1293 again, so calling this function twice is safe. */
1295 insert_breakpoints (void)
1297 struct breakpoint *bpt;
1299 ALL_BREAKPOINTS (bpt)
1300 if (is_hardware_watchpoint (bpt))
1301 update_watchpoint (bpt, 0 /* don't reparse. */);
1303 update_global_location_list (1);
1305 /* update_global_location_list does not insert breakpoints when
1306 always_inserted_mode is not enabled. Explicitly insert them
1308 if (!breakpoints_always_inserted_mode ())
1309 insert_breakpoint_locations ();
1312 /* insert_breakpoints is used when starting or continuing the program.
1313 remove_breakpoints is used when the program stops.
1314 Both return zero if successful,
1315 or an `errno' value if could not write the inferior. */
1318 insert_breakpoint_locations (void)
1320 struct breakpoint *bpt;
1321 struct bp_location *b, *temp;
1324 int disabled_breaks = 0;
1325 int hw_breakpoint_error = 0;
1327 struct ui_file *tmp_error_stream = mem_fileopen ();
1328 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1330 /* Explicitly mark the warning -- this will only be printed if
1331 there was an error. */
1332 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1334 ALL_BP_LOCATIONS_SAFE (b, temp)
1336 if (!should_be_inserted (b) || b->inserted)
1339 /* There is no point inserting thread-specific breakpoints if the
1340 thread no longer exists. */
1341 if (b->owner->thread != -1
1342 && !valid_thread_id (b->owner->thread))
1345 val = insert_bp_location (b, tmp_error_stream,
1347 &hw_breakpoint_error);
1352 /* If we failed to insert all locations of a watchpoint,
1353 remove them, as half-inserted watchpoint is of limited use. */
1354 ALL_BREAKPOINTS (bpt)
1356 int some_failed = 0;
1357 struct bp_location *loc;
1359 if (!is_hardware_watchpoint (bpt))
1362 if (!breakpoint_enabled (bpt))
1365 if (bpt->disposition == disp_del_at_next_stop)
1368 for (loc = bpt->loc; loc; loc = loc->next)
1376 for (loc = bpt->loc; loc; loc = loc->next)
1378 remove_breakpoint (loc, mark_uninserted);
1380 hw_breakpoint_error = 1;
1381 fprintf_unfiltered (tmp_error_stream,
1382 "Could not insert hardware watchpoint %d.\n",
1390 /* If a hardware breakpoint or watchpoint was inserted, add a
1391 message about possibly exhausted resources. */
1392 if (hw_breakpoint_error)
1394 fprintf_unfiltered (tmp_error_stream,
1395 "Could not insert hardware breakpoints:\n\
1396 You may have requested too many hardware breakpoints/watchpoints.\n");
1398 target_terminal_ours_for_output ();
1399 error_stream (tmp_error_stream);
1402 do_cleanups (cleanups);
1406 remove_breakpoints (void)
1408 struct bp_location *b;
1411 ALL_BP_LOCATIONS (b)
1415 val = remove_breakpoint (b, mark_uninserted);
1424 remove_hw_watchpoints (void)
1426 struct bp_location *b;
1429 ALL_BP_LOCATIONS (b)
1431 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1433 val = remove_breakpoint (b, mark_uninserted);
1442 reattach_breakpoints (int pid)
1444 struct bp_location *b;
1446 struct cleanup *old_chain = save_inferior_ptid ();
1447 struct ui_file *tmp_error_stream = mem_fileopen ();
1448 int dummy1 = 0, dummy2 = 0;
1450 make_cleanup_ui_file_delete (tmp_error_stream);
1452 inferior_ptid = pid_to_ptid (pid);
1453 ALL_BP_LOCATIONS (b)
1458 val = insert_bp_location (b, tmp_error_stream,
1462 do_cleanups (old_chain);
1467 do_cleanups (old_chain);
1471 static int internal_breakpoint_number = -1;
1473 static struct breakpoint *
1474 create_internal_breakpoint (struct gdbarch *gdbarch,
1475 CORE_ADDR address, enum bptype type)
1477 struct symtab_and_line sal;
1478 struct breakpoint *b;
1480 init_sal (&sal); /* initialize to zeroes */
1483 sal.section = find_pc_overlay (sal.pc);
1485 b = set_raw_breakpoint (gdbarch, sal, type);
1486 b->number = internal_breakpoint_number--;
1487 b->disposition = disp_donttouch;
1493 create_overlay_event_breakpoint (char *func_name)
1495 struct objfile *objfile;
1497 ALL_OBJFILES (objfile)
1499 struct breakpoint *b;
1500 struct minimal_symbol *m;
1502 m = lookup_minimal_symbol_text (func_name, objfile);
1506 b = create_internal_breakpoint (get_objfile_arch (objfile),
1507 SYMBOL_VALUE_ADDRESS (m),
1509 b->addr_string = xstrdup (func_name);
1511 if (overlay_debugging == ovly_auto)
1513 b->enable_state = bp_enabled;
1514 overlay_events_enabled = 1;
1518 b->enable_state = bp_disabled;
1519 overlay_events_enabled = 0;
1522 update_global_location_list (1);
1526 create_longjmp_master_breakpoint (char *func_name)
1528 struct objfile *objfile;
1530 ALL_OBJFILES (objfile)
1532 struct breakpoint *b;
1533 struct minimal_symbol *m;
1535 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
1538 m = lookup_minimal_symbol_text (func_name, objfile);
1542 b = create_internal_breakpoint (get_objfile_arch (objfile),
1543 SYMBOL_VALUE_ADDRESS (m),
1545 b->addr_string = xstrdup (func_name);
1546 b->enable_state = bp_disabled;
1548 update_global_location_list (1);
1552 update_breakpoints_after_exec (void)
1554 struct breakpoint *b;
1555 struct breakpoint *temp;
1556 struct bp_location *bploc;
1558 /* We're about to delete breakpoints from GDB's lists. If the
1559 INSERTED flag is true, GDB will try to lift the breakpoints by
1560 writing the breakpoints' "shadow contents" back into memory. The
1561 "shadow contents" are NOT valid after an exec, so GDB should not
1562 do that. Instead, the target is responsible from marking
1563 breakpoints out as soon as it detects an exec. We don't do that
1564 here instead, because there may be other attempts to delete
1565 breakpoints after detecting an exec and before reaching here. */
1566 ALL_BP_LOCATIONS (bploc)
1567 gdb_assert (!bploc->inserted);
1569 ALL_BREAKPOINTS_SAFE (b, temp)
1571 /* Solib breakpoints must be explicitly reset after an exec(). */
1572 if (b->type == bp_shlib_event)
1574 delete_breakpoint (b);
1578 /* Thread event breakpoints must be set anew after an exec(),
1579 as must overlay event and longjmp master breakpoints. */
1580 if (b->type == bp_thread_event || b->type == bp_overlay_event
1581 || b->type == bp_longjmp_master)
1583 delete_breakpoint (b);
1587 /* Step-resume breakpoints are meaningless after an exec(). */
1588 if (b->type == bp_step_resume)
1590 delete_breakpoint (b);
1594 /* Longjmp and longjmp-resume breakpoints are also meaningless
1596 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1598 delete_breakpoint (b);
1602 if (b->type == bp_catchpoint)
1604 /* For now, none of the bp_catchpoint breakpoints need to
1605 do anything at this point. In the future, if some of
1606 the catchpoints need to something, we will need to add
1607 a new method, and call this method from here. */
1611 /* bp_finish is a special case. The only way we ought to be able
1612 to see one of these when an exec() has happened, is if the user
1613 caught a vfork, and then said "finish". Ordinarily a finish just
1614 carries them to the call-site of the current callee, by setting
1615 a temporary bp there and resuming. But in this case, the finish
1616 will carry them entirely through the vfork & exec.
1618 We don't want to allow a bp_finish to remain inserted now. But
1619 we can't safely delete it, 'cause finish_command has a handle to
1620 the bp on a bpstat, and will later want to delete it. There's a
1621 chance (and I've seen it happen) that if we delete the bp_finish
1622 here, that its storage will get reused by the time finish_command
1623 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1624 We really must allow finish_command to delete a bp_finish.
1626 In the absense of a general solution for the "how do we know
1627 it's safe to delete something others may have handles to?"
1628 problem, what we'll do here is just uninsert the bp_finish, and
1629 let finish_command delete it.
1631 (We know the bp_finish is "doomed" in the sense that it's
1632 momentary, and will be deleted as soon as finish_command sees
1633 the inferior stopped. So it doesn't matter that the bp's
1634 address is probably bogus in the new a.out, unlike e.g., the
1635 solib breakpoints.) */
1637 if (b->type == bp_finish)
1642 /* Without a symbolic address, we have little hope of the
1643 pre-exec() address meaning the same thing in the post-exec()
1645 if (b->addr_string == NULL)
1647 delete_breakpoint (b);
1651 /* FIXME what about longjmp breakpoints? Re-create them here? */
1652 create_overlay_event_breakpoint ("_ovly_debug_event");
1653 create_longjmp_master_breakpoint ("longjmp");
1654 create_longjmp_master_breakpoint ("_longjmp");
1655 create_longjmp_master_breakpoint ("siglongjmp");
1656 create_longjmp_master_breakpoint ("_siglongjmp");
1660 detach_breakpoints (int pid)
1662 struct bp_location *b;
1664 struct cleanup *old_chain = save_inferior_ptid ();
1666 if (pid == PIDGET (inferior_ptid))
1667 error (_("Cannot detach breakpoints of inferior_ptid"));
1669 /* Set inferior_ptid; remove_breakpoint uses this global. */
1670 inferior_ptid = pid_to_ptid (pid);
1671 ALL_BP_LOCATIONS (b)
1675 val = remove_breakpoint (b, mark_inserted);
1678 do_cleanups (old_chain);
1683 do_cleanups (old_chain);
1688 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1692 if (b->owner->enable_state == bp_permanent)
1693 /* Permanent breakpoints cannot be inserted or removed. */
1696 /* The type of none suggests that owner is actually deleted.
1697 This should not ever happen. */
1698 gdb_assert (b->owner->type != bp_none);
1700 if (b->loc_type == bp_loc_software_breakpoint
1701 || b->loc_type == bp_loc_hardware_breakpoint)
1703 /* "Normal" instruction breakpoint: either the standard
1704 trap-instruction bp (bp_breakpoint), or a
1705 bp_hardware_breakpoint. */
1707 /* First check to see if we have to handle an overlay. */
1708 if (overlay_debugging == ovly_off
1709 || b->section == NULL
1710 || !(section_is_overlay (b->section)))
1712 /* No overlay handling: just remove the breakpoint. */
1714 if (b->loc_type == bp_loc_hardware_breakpoint)
1715 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
1717 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
1721 /* This breakpoint is in an overlay section.
1722 Did we set a breakpoint at the LMA? */
1723 if (!overlay_events_enabled)
1725 /* Yes -- overlay event support is not active, so we
1726 should have set a breakpoint at the LMA. Remove it.
1728 /* Ignore any failures: if the LMA is in ROM, we will
1729 have already warned when we failed to insert it. */
1730 if (b->loc_type == bp_loc_hardware_breakpoint)
1731 target_remove_hw_breakpoint (b->gdbarch,
1732 &b->overlay_target_info);
1734 target_remove_breakpoint (b->gdbarch,
1735 &b->overlay_target_info);
1737 /* Did we set a breakpoint at the VMA?
1738 If so, we will have marked the breakpoint 'inserted'. */
1741 /* Yes -- remove it. Previously we did not bother to
1742 remove the breakpoint if the section had been
1743 unmapped, but let's not rely on that being safe. We
1744 don't know what the overlay manager might do. */
1745 if (b->loc_type == bp_loc_hardware_breakpoint)
1746 val = target_remove_hw_breakpoint (b->gdbarch,
1749 /* However, we should remove *software* breakpoints only
1750 if the section is still mapped, or else we overwrite
1751 wrong code with the saved shadow contents. */
1752 else if (section_is_mapped (b->section))
1753 val = target_remove_breakpoint (b->gdbarch,
1760 /* No -- not inserted, so no need to remove. No error. */
1765 /* In some cases, we might not be able to remove a breakpoint
1766 in a shared library that has already been removed, but we
1767 have not yet processed the shlib unload event. */
1768 if (val && solib_name_from_address (b->address))
1773 b->inserted = (is == mark_inserted);
1775 else if (b->loc_type == bp_loc_hardware_watchpoint)
1780 b->inserted = (is == mark_inserted);
1781 val = target_remove_watchpoint (b->address, b->length,
1782 b->watchpoint_type);
1784 /* Failure to remove any of the hardware watchpoints comes here. */
1785 if ((is == mark_uninserted) && (b->inserted))
1786 warning (_("Could not remove hardware watchpoint %d."),
1789 else if (b->owner->type == bp_catchpoint
1790 && breakpoint_enabled (b->owner)
1793 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
1795 val = b->owner->ops->remove (b->owner);
1798 b->inserted = (is == mark_inserted);
1804 /* Clear the "inserted" flag in all breakpoints. */
1807 mark_breakpoints_out (void)
1809 struct bp_location *bpt;
1811 ALL_BP_LOCATIONS (bpt)
1815 /* Clear the "inserted" flag in all breakpoints and delete any
1816 breakpoints which should go away between runs of the program.
1818 Plus other such housekeeping that has to be done for breakpoints
1821 Note: this function gets called at the end of a run (by
1822 generic_mourn_inferior) and when a run begins (by
1823 init_wait_for_inferior). */
1828 breakpoint_init_inferior (enum inf_context context)
1830 struct breakpoint *b, *temp;
1831 struct bp_location *bpt;
1834 /* If breakpoint locations are shared across processes, then there's
1836 if (gdbarch_has_global_breakpoints (target_gdbarch))
1839 ALL_BP_LOCATIONS (bpt)
1840 if (bpt->owner->enable_state != bp_permanent)
1843 ALL_BREAKPOINTS_SAFE (b, temp)
1848 case bp_watchpoint_scope:
1850 /* If the call dummy breakpoint is at the entry point it will
1851 cause problems when the inferior is rerun, so we better
1854 Also get rid of scope breakpoints. */
1855 delete_breakpoint (b);
1859 case bp_hardware_watchpoint:
1860 case bp_read_watchpoint:
1861 case bp_access_watchpoint:
1863 /* Likewise for watchpoints on local expressions. */
1864 if (b->exp_valid_block != NULL)
1865 delete_breakpoint (b);
1866 else if (context == inf_starting)
1868 /* Reset val field to force reread of starting value
1869 in insert_breakpoints. */
1871 value_free (b->val);
1881 /* Get rid of the moribund locations. */
1882 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
1883 free_bp_location (bpt);
1884 VEC_free (bp_location_p, moribund_locations);
1887 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1888 exists at PC. It returns ordinary_breakpoint_here if it's an
1889 ordinary breakpoint, or permanent_breakpoint_here if it's a
1890 permanent breakpoint.
1891 - When continuing from a location with an ordinary breakpoint, we
1892 actually single step once before calling insert_breakpoints.
1893 - When continuing from a localion with a permanent breakpoint, we
1894 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1895 the target, to advance the PC past the breakpoint. */
1897 enum breakpoint_here
1898 breakpoint_here_p (CORE_ADDR pc)
1900 const struct bp_location *bpt;
1901 int any_breakpoint_here = 0;
1903 ALL_BP_LOCATIONS (bpt)
1905 if (bpt->loc_type != bp_loc_software_breakpoint
1906 && bpt->loc_type != bp_loc_hardware_breakpoint)
1909 if ((breakpoint_enabled (bpt->owner)
1910 || bpt->owner->enable_state == bp_permanent)
1911 && bpt->address == pc) /* bp is enabled and matches pc */
1913 if (overlay_debugging
1914 && section_is_overlay (bpt->section)
1915 && !section_is_mapped (bpt->section))
1916 continue; /* unmapped overlay -- can't be a match */
1917 else if (bpt->owner->enable_state == bp_permanent)
1918 return permanent_breakpoint_here;
1920 any_breakpoint_here = 1;
1924 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1927 /* Return true if there's a moribund breakpoint at PC. */
1930 moribund_breakpoint_here_p (CORE_ADDR pc)
1932 struct bp_location *loc;
1935 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1936 if (loc->address == pc)
1942 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1943 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1944 This does not check for single-step breakpoints, which are
1945 inserted and removed using direct target manipulation. */
1948 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1950 const struct bp_location *bpt;
1952 ALL_BP_LOCATIONS (bpt)
1954 if (bpt->loc_type != bp_loc_software_breakpoint
1955 && bpt->loc_type != bp_loc_hardware_breakpoint)
1959 && bpt->address == pc) /* bp is inserted and matches pc */
1961 if (overlay_debugging
1962 && section_is_overlay (bpt->section)
1963 && !section_is_mapped (bpt->section))
1964 continue; /* unmapped overlay -- can't be a match */
1972 /* Returns non-zero iff there's either regular breakpoint
1973 or a single step breakpoint inserted at PC. */
1976 breakpoint_inserted_here_p (CORE_ADDR pc)
1978 if (regular_breakpoint_inserted_here_p (pc))
1981 if (single_step_breakpoint_inserted_here_p (pc))
1987 /* This function returns non-zero iff there is a software breakpoint
1991 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1993 const struct bp_location *bpt;
1994 int any_breakpoint_here = 0;
1996 ALL_BP_LOCATIONS (bpt)
1998 if (bpt->loc_type != bp_loc_software_breakpoint)
2002 && bpt->address == pc) /* bp is enabled and matches pc */
2004 if (overlay_debugging
2005 && section_is_overlay (bpt->section)
2006 && !section_is_mapped (bpt->section))
2007 continue; /* unmapped overlay -- can't be a match */
2013 /* Also check for software single-step breakpoints. */
2014 if (single_step_breakpoint_inserted_here_p (pc))
2020 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2021 PC is valid for process/thread PTID. */
2024 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
2026 const struct bp_location *bpt;
2027 /* The thread and task IDs associated to PTID, computed lazily. */
2031 ALL_BP_LOCATIONS (bpt)
2033 if (bpt->loc_type != bp_loc_software_breakpoint
2034 && bpt->loc_type != bp_loc_hardware_breakpoint)
2037 if (!breakpoint_enabled (bpt->owner)
2038 && bpt->owner->enable_state != bp_permanent)
2041 if (bpt->address != pc)
2044 if (bpt->owner->thread != -1)
2046 /* This is a thread-specific breakpoint. Check that ptid
2047 matches that thread. If thread hasn't been computed yet,
2048 it is now time to do so. */
2050 thread = pid_to_thread_id (ptid);
2051 if (bpt->owner->thread != thread)
2055 if (bpt->owner->task != 0)
2057 /* This is a task-specific breakpoint. Check that ptid
2058 matches that task. If task hasn't been computed yet,
2059 it is now time to do so. */
2061 task = ada_get_task_number (ptid);
2062 if (bpt->owner->task != task)
2066 if (overlay_debugging
2067 && section_is_overlay (bpt->section)
2068 && !section_is_mapped (bpt->section))
2069 continue; /* unmapped overlay -- can't be a match */
2078 /* bpstat stuff. External routines' interfaces are documented
2082 ep_is_catchpoint (struct breakpoint *ep)
2084 return (ep->type == bp_catchpoint);
2088 bpstat_free (bpstat bs)
2090 if (bs->old_val != NULL)
2091 value_free (bs->old_val);
2092 free_command_lines (&bs->commands);
2096 /* Clear a bpstat so that it says we are not at any breakpoint.
2097 Also free any storage that is part of a bpstat. */
2100 bpstat_clear (bpstat *bsp)
2117 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2118 is part of the bpstat is copied as well. */
2121 bpstat_copy (bpstat bs)
2125 bpstat retval = NULL;
2130 for (; bs != NULL; bs = bs->next)
2132 tmp = (bpstat) xmalloc (sizeof (*tmp));
2133 memcpy (tmp, bs, sizeof (*tmp));
2134 if (bs->commands != NULL)
2135 tmp->commands = copy_command_lines (bs->commands);
2136 if (bs->old_val != NULL)
2138 tmp->old_val = value_copy (bs->old_val);
2139 release_value (tmp->old_val);
2143 /* This is the first thing in the chain. */
2153 /* Find the bpstat associated with this breakpoint */
2156 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2161 for (; bsp != NULL; bsp = bsp->next)
2163 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2169 /* Find a step_resume breakpoint associated with this bpstat.
2170 (If there are multiple step_resume bp's on the list, this function
2171 will arbitrarily pick one.)
2173 It is an error to use this function if BPSTAT doesn't contain a
2174 step_resume breakpoint.
2176 See wait_for_inferior's use of this function. */
2178 bpstat_find_step_resume_breakpoint (bpstat bsp)
2182 gdb_assert (bsp != NULL);
2184 current_thread = pid_to_thread_id (inferior_ptid);
2186 for (; bsp != NULL; bsp = bsp->next)
2188 if ((bsp->breakpoint_at != NULL)
2189 && (bsp->breakpoint_at->owner->type == bp_step_resume)
2190 && (bsp->breakpoint_at->owner->thread == current_thread
2191 || bsp->breakpoint_at->owner->thread == -1))
2192 return bsp->breakpoint_at->owner;
2195 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2199 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2200 at. *BSP upon return is a bpstat which points to the remaining
2201 breakpoints stopped at (but which is not guaranteed to be good for
2202 anything but further calls to bpstat_num).
2203 Return 0 if passed a bpstat which does not indicate any breakpoints.
2204 Return -1 if stopped at a breakpoint that has been deleted since
2206 Return 1 otherwise. */
2209 bpstat_num (bpstat *bsp, int *num)
2211 struct breakpoint *b;
2214 return 0; /* No more breakpoint values */
2216 /* We assume we'll never have several bpstats that
2217 correspond to a single breakpoint -- otherwise,
2218 this function might return the same number more
2219 than once and this will look ugly. */
2220 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2221 *bsp = (*bsp)->next;
2223 return -1; /* breakpoint that's been deleted since */
2225 *num = b->number; /* We have its number */
2229 /* Modify BS so that the actions will not be performed. */
2232 bpstat_clear_actions (bpstat bs)
2234 for (; bs != NULL; bs = bs->next)
2236 free_command_lines (&bs->commands);
2237 if (bs->old_val != NULL)
2239 value_free (bs->old_val);
2245 /* Called when a command is about to proceed the inferior. */
2248 breakpoint_about_to_proceed (void)
2250 if (!ptid_equal (inferior_ptid, null_ptid))
2252 struct thread_info *tp = inferior_thread ();
2254 /* Allow inferior function calls in breakpoint commands to not
2255 interrupt the command list. When the call finishes
2256 successfully, the inferior will be standing at the same
2257 breakpoint as if nothing happened. */
2262 breakpoint_proceeded = 1;
2265 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2267 cleanup_executing_breakpoints (void *ignore)
2269 executing_breakpoint_commands = 0;
2272 /* Execute all the commands associated with all the breakpoints at this
2273 location. Any of these commands could cause the process to proceed
2274 beyond this point, etc. We look out for such changes by checking
2275 the global "breakpoint_proceeded" after each command.
2277 Returns true if a breakpoint command resumed the inferior. In that
2278 case, it is the caller's responsibility to recall it again with the
2279 bpstat of the current thread. */
2282 bpstat_do_actions_1 (bpstat *bsp)
2285 struct cleanup *old_chain;
2288 /* Avoid endless recursion if a `source' command is contained
2290 if (executing_breakpoint_commands)
2293 executing_breakpoint_commands = 1;
2294 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2296 /* This pointer will iterate over the list of bpstat's. */
2299 breakpoint_proceeded = 0;
2300 for (; bs != NULL; bs = bs->next)
2302 struct command_line *cmd;
2303 struct cleanup *this_cmd_tree_chain;
2305 /* Take ownership of the BSP's command tree, if it has one.
2307 The command tree could legitimately contain commands like
2308 'step' and 'next', which call clear_proceed_status, which
2309 frees stop_bpstat's command tree. To make sure this doesn't
2310 free the tree we're executing out from under us, we need to
2311 take ownership of the tree ourselves. Since a given bpstat's
2312 commands are only executed once, we don't need to copy it; we
2313 can clear the pointer in the bpstat, and make sure we free
2314 the tree when we're done. */
2317 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2321 execute_control_command (cmd);
2323 if (breakpoint_proceeded)
2329 /* We can free this command tree now. */
2330 do_cleanups (this_cmd_tree_chain);
2332 if (breakpoint_proceeded)
2334 if (target_can_async_p ())
2335 /* If we are in async mode, then the target might be still
2336 running, not stopped at any breakpoint, so nothing for
2337 us to do here -- just return to the event loop. */
2340 /* In sync mode, when execute_control_command returns
2341 we're already standing on the next breakpoint.
2342 Breakpoint commands for that stop were not run, since
2343 execute_command does not run breakpoint commands --
2344 only command_line_handler does, but that one is not
2345 involved in execution of breakpoint commands. So, we
2346 can now execute breakpoint commands. It should be
2347 noted that making execute_command do bpstat actions is
2348 not an option -- in this case we'll have recursive
2349 invocation of bpstat for each breakpoint with a
2350 command, and can easily blow up GDB stack. Instead, we
2351 return true, which will trigger the caller to recall us
2352 with the new stop_bpstat. */
2357 do_cleanups (old_chain);
2362 bpstat_do_actions (void)
2364 /* Do any commands attached to breakpoint we are stopped at. */
2365 while (!ptid_equal (inferior_ptid, null_ptid)
2366 && target_has_execution
2367 && !is_exited (inferior_ptid)
2368 && !is_executing (inferior_ptid))
2369 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2370 and only return when it is stopped at the next breakpoint, we
2371 keep doing breakpoint actions until it returns false to
2372 indicate the inferior was not resumed. */
2373 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
2377 /* Print out the (old or new) value associated with a watchpoint. */
2380 watchpoint_value_print (struct value *val, struct ui_file *stream)
2383 fprintf_unfiltered (stream, _("<unreadable>"));
2386 struct value_print_options opts;
2387 get_user_print_options (&opts);
2388 value_print (val, stream, &opts);
2392 /* This is the normal print function for a bpstat. In the future,
2393 much of this logic could (should?) be moved to bpstat_stop_status,
2394 by having it set different print_it values.
2396 Current scheme: When we stop, bpstat_print() is called. It loops
2397 through the bpstat list of things causing this stop, calling the
2398 print_bp_stop_message function on each one. The behavior of the
2399 print_bp_stop_message function depends on the print_it field of
2400 bpstat. If such field so indicates, call this function here.
2402 Return values from this routine (ultimately used by bpstat_print()
2403 and normal_stop() to decide what to do):
2404 PRINT_NOTHING: Means we already printed all we needed to print,
2405 don't print anything else.
2406 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2407 that something to be followed by a location.
2408 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2409 that something to be followed by a location.
2410 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2413 static enum print_stop_action
2414 print_it_typical (bpstat bs)
2416 struct cleanup *old_chain;
2417 struct breakpoint *b;
2418 const struct bp_location *bl;
2419 struct ui_stream *stb;
2421 enum print_stop_action result;
2423 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2424 which has since been deleted. */
2425 if (bs->breakpoint_at == NULL)
2426 return PRINT_UNKNOWN;
2427 bl = bs->breakpoint_at;
2430 stb = ui_out_stream_new (uiout);
2431 old_chain = make_cleanup_ui_out_stream_delete (stb);
2436 case bp_hardware_breakpoint:
2437 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2438 if (bl->address != bl->requested_address)
2439 breakpoint_adjustment_warning (bl->requested_address,
2442 annotate_breakpoint (b->number);
2444 ui_out_text (uiout, "\nTemporary breakpoint ");
2446 ui_out_text (uiout, "\nBreakpoint ");
2447 if (ui_out_is_mi_like_p (uiout))
2449 ui_out_field_string (uiout, "reason",
2450 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2451 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2453 ui_out_field_int (uiout, "bkptno", b->number);
2454 ui_out_text (uiout, ", ");
2455 result = PRINT_SRC_AND_LOC;
2458 case bp_shlib_event:
2459 /* Did we stop because the user set the stop_on_solib_events
2460 variable? (If so, we report this as a generic, "Stopped due
2461 to shlib event" message.) */
2462 printf_filtered (_("Stopped due to shared library event\n"));
2463 result = PRINT_NOTHING;
2466 case bp_thread_event:
2467 /* Not sure how we will get here.
2468 GDB should not stop for these breakpoints. */
2469 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2470 result = PRINT_NOTHING;
2473 case bp_overlay_event:
2474 /* By analogy with the thread event, GDB should not stop for these. */
2475 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2476 result = PRINT_NOTHING;
2479 case bp_longjmp_master:
2480 /* These should never be enabled. */
2481 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2482 result = PRINT_NOTHING;
2486 case bp_hardware_watchpoint:
2487 annotate_watchpoint (b->number);
2488 if (ui_out_is_mi_like_p (uiout))
2491 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2493 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2494 ui_out_text (uiout, "\nOld value = ");
2495 watchpoint_value_print (bs->old_val, stb->stream);
2496 ui_out_field_stream (uiout, "old", stb);
2497 ui_out_text (uiout, "\nNew value = ");
2498 watchpoint_value_print (b->val, stb->stream);
2499 ui_out_field_stream (uiout, "new", stb);
2500 ui_out_text (uiout, "\n");
2501 /* More than one watchpoint may have been triggered. */
2502 result = PRINT_UNKNOWN;
2505 case bp_read_watchpoint:
2506 if (ui_out_is_mi_like_p (uiout))
2509 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2511 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2512 ui_out_text (uiout, "\nValue = ");
2513 watchpoint_value_print (b->val, stb->stream);
2514 ui_out_field_stream (uiout, "value", stb);
2515 ui_out_text (uiout, "\n");
2516 result = PRINT_UNKNOWN;
2519 case bp_access_watchpoint:
2520 if (bs->old_val != NULL)
2522 annotate_watchpoint (b->number);
2523 if (ui_out_is_mi_like_p (uiout))
2526 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2528 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2529 ui_out_text (uiout, "\nOld value = ");
2530 watchpoint_value_print (bs->old_val, stb->stream);
2531 ui_out_field_stream (uiout, "old", stb);
2532 ui_out_text (uiout, "\nNew value = ");
2537 if (ui_out_is_mi_like_p (uiout))
2540 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2541 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2542 ui_out_text (uiout, "\nValue = ");
2544 watchpoint_value_print (b->val, stb->stream);
2545 ui_out_field_stream (uiout, "new", stb);
2546 ui_out_text (uiout, "\n");
2547 result = PRINT_UNKNOWN;
2550 /* Fall through, we don't deal with these types of breakpoints
2554 if (ui_out_is_mi_like_p (uiout))
2557 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2558 result = PRINT_UNKNOWN;
2562 if (ui_out_is_mi_like_p (uiout))
2565 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2566 result = PRINT_UNKNOWN;
2571 case bp_longjmp_resume:
2572 case bp_step_resume:
2573 case bp_watchpoint_scope:
2577 result = PRINT_UNKNOWN;
2581 do_cleanups (old_chain);
2585 /* Generic routine for printing messages indicating why we
2586 stopped. The behavior of this function depends on the value
2587 'print_it' in the bpstat structure. Under some circumstances we
2588 may decide not to print anything here and delegate the task to
2591 static enum print_stop_action
2592 print_bp_stop_message (bpstat bs)
2594 switch (bs->print_it)
2597 /* Nothing should be printed for this bpstat entry. */
2598 return PRINT_UNKNOWN;
2602 /* We still want to print the frame, but we already printed the
2603 relevant messages. */
2604 return PRINT_SRC_AND_LOC;
2607 case print_it_normal:
2609 const struct bp_location *bl = bs->breakpoint_at;
2610 struct breakpoint *b = bl ? bl->owner : NULL;
2612 /* Normal case. Call the breakpoint's print_it method, or
2613 print_it_typical. */
2614 /* FIXME: how breakpoint can ever be NULL here? */
2615 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2616 return b->ops->print_it (b);
2618 return print_it_typical (bs);
2623 internal_error (__FILE__, __LINE__,
2624 _("print_bp_stop_message: unrecognized enum value"));
2629 /* Print a message indicating what happened. This is called from
2630 normal_stop(). The input to this routine is the head of the bpstat
2631 list - a list of the eventpoints that caused this stop. This
2632 routine calls the generic print routine for printing a message
2633 about reasons for stopping. This will print (for example) the
2634 "Breakpoint n," part of the output. The return value of this
2637 PRINT_UNKNOWN: Means we printed nothing
2638 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2639 code to print the location. An example is
2640 "Breakpoint 1, " which should be followed by
2642 PRINT_SRC_ONLY: Means we printed something, but there is no need
2643 to also print the location part of the message.
2644 An example is the catch/throw messages, which
2645 don't require a location appended to the end.
2646 PRINT_NOTHING: We have done some printing and we don't need any
2647 further info to be printed.*/
2649 enum print_stop_action
2650 bpstat_print (bpstat bs)
2654 /* Maybe another breakpoint in the chain caused us to stop.
2655 (Currently all watchpoints go on the bpstat whether hit or not.
2656 That probably could (should) be changed, provided care is taken
2657 with respect to bpstat_explains_signal). */
2658 for (; bs; bs = bs->next)
2660 val = print_bp_stop_message (bs);
2661 if (val == PRINT_SRC_ONLY
2662 || val == PRINT_SRC_AND_LOC
2663 || val == PRINT_NOTHING)
2667 /* We reached the end of the chain, or we got a null BS to start
2668 with and nothing was printed. */
2669 return PRINT_UNKNOWN;
2672 /* Evaluate the expression EXP and return 1 if value is zero.
2673 This is used inside a catch_errors to evaluate the breakpoint condition.
2674 The argument is a "struct expression *" that has been cast to char * to
2675 make it pass through catch_errors. */
2678 breakpoint_cond_eval (void *exp)
2680 struct value *mark = value_mark ();
2681 int i = !value_true (evaluate_expression ((struct expression *) exp));
2682 value_free_to_mark (mark);
2686 /* Allocate a new bpstat and chain it to the current one. */
2689 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2693 bs = (bpstat) xmalloc (sizeof (*bs));
2695 bs->breakpoint_at = bl;
2696 /* If the condition is false, etc., don't do the commands. */
2697 bs->commands = NULL;
2699 bs->print_it = print_it_normal;
2703 /* The target has stopped with waitstatus WS. Check if any hardware
2704 watchpoints have triggered, according to the target. */
2707 watchpoints_triggered (struct target_waitstatus *ws)
2709 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
2711 struct breakpoint *b;
2713 if (!stopped_by_watchpoint)
2715 /* We were not stopped by a watchpoint. Mark all watchpoints
2716 as not triggered. */
2718 if (b->type == bp_hardware_watchpoint
2719 || b->type == bp_read_watchpoint
2720 || b->type == bp_access_watchpoint)
2721 b->watchpoint_triggered = watch_triggered_no;
2726 if (!target_stopped_data_address (¤t_target, &addr))
2728 /* We were stopped by a watchpoint, but we don't know where.
2729 Mark all watchpoints as unknown. */
2731 if (b->type == bp_hardware_watchpoint
2732 || b->type == bp_read_watchpoint
2733 || b->type == bp_access_watchpoint)
2734 b->watchpoint_triggered = watch_triggered_unknown;
2736 return stopped_by_watchpoint;
2739 /* The target could report the data address. Mark watchpoints
2740 affected by this data address as triggered, and all others as not
2744 if (b->type == bp_hardware_watchpoint
2745 || b->type == bp_read_watchpoint
2746 || b->type == bp_access_watchpoint)
2748 struct bp_location *loc;
2751 b->watchpoint_triggered = watch_triggered_no;
2752 for (loc = b->loc; loc; loc = loc->next)
2753 /* Exact match not required. Within range is
2755 if (target_watchpoint_addr_within_range (¤t_target,
2759 b->watchpoint_triggered = watch_triggered_yes;
2767 /* Possible return values for watchpoint_check (this can't be an enum
2768 because of check_errors). */
2769 /* The watchpoint has been deleted. */
2770 #define WP_DELETED 1
2771 /* The value has changed. */
2772 #define WP_VALUE_CHANGED 2
2773 /* The value has not changed. */
2774 #define WP_VALUE_NOT_CHANGED 3
2776 #define BP_TEMPFLAG 1
2777 #define BP_HARDWAREFLAG 2
2779 /* Check watchpoint condition. */
2782 watchpoint_check (void *p)
2784 bpstat bs = (bpstat) p;
2785 struct breakpoint *b;
2786 struct frame_info *fr;
2787 int within_current_scope;
2789 b = bs->breakpoint_at->owner;
2791 if (b->exp_valid_block == NULL)
2792 within_current_scope = 1;
2795 struct frame_info *frame = get_current_frame ();
2796 struct gdbarch *frame_arch = get_frame_arch (frame);
2797 CORE_ADDR frame_pc = get_frame_pc (frame);
2799 fr = frame_find_by_id (b->watchpoint_frame);
2800 within_current_scope = (fr != NULL);
2802 /* If we've gotten confused in the unwinder, we might have
2803 returned a frame that can't describe this variable. */
2804 if (within_current_scope)
2806 struct symbol *function;
2808 function = get_frame_function (fr);
2809 if (function == NULL
2810 || !contained_in (b->exp_valid_block,
2811 SYMBOL_BLOCK_VALUE (function)))
2812 within_current_scope = 0;
2815 /* in_function_epilogue_p() returns a non-zero value if we're still
2816 in the function but the stack frame has already been invalidated.
2817 Since we can't rely on the values of local variables after the
2818 stack has been destroyed, we are treating the watchpoint in that
2819 state as `not changed' without further checking. Don't mark
2820 watchpoints as changed if the current frame is in an epilogue -
2821 even if they are in some other frame, our view of the stack
2822 is likely to be wrong. */
2823 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
2824 return WP_VALUE_NOT_CHANGED;
2826 if (within_current_scope)
2827 /* If we end up stopping, the current frame will get selected
2828 in normal_stop. So this call to select_frame won't affect
2833 if (within_current_scope)
2835 /* We use value_{,free_to_}mark because it could be a
2836 *long* time before we return to the command level and
2837 call free_all_values. We can't call free_all_values because
2838 we might be in the middle of evaluating a function call. */
2840 struct value *mark = value_mark ();
2841 struct value *new_val;
2843 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2844 if ((b->val != NULL) != (new_val != NULL)
2845 || (b->val != NULL && !value_equal (b->val, new_val)))
2847 if (new_val != NULL)
2849 release_value (new_val);
2850 value_free_to_mark (mark);
2852 bs->old_val = b->val;
2855 /* We will stop here */
2856 return WP_VALUE_CHANGED;
2860 /* Nothing changed, don't do anything. */
2861 value_free_to_mark (mark);
2862 /* We won't stop here */
2863 return WP_VALUE_NOT_CHANGED;
2868 /* This seems like the only logical thing to do because
2869 if we temporarily ignored the watchpoint, then when
2870 we reenter the block in which it is valid it contains
2871 garbage (in the case of a function, it may have two
2872 garbage values, one before and one after the prologue).
2873 So we can't even detect the first assignment to it and
2874 watch after that (since the garbage may or may not equal
2875 the first value assigned). */
2876 /* We print all the stop information in print_it_typical(), but
2877 in this case, by the time we call print_it_typical() this bp
2878 will be deleted already. So we have no choice but print the
2879 information here. */
2880 if (ui_out_is_mi_like_p (uiout))
2882 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2883 ui_out_text (uiout, "\nWatchpoint ");
2884 ui_out_field_int (uiout, "wpnum", b->number);
2885 ui_out_text (uiout, " deleted because the program has left the block in\n\
2886 which its expression is valid.\n");
2888 if (b->related_breakpoint)
2889 b->related_breakpoint->disposition = disp_del_at_next_stop;
2890 b->disposition = disp_del_at_next_stop;
2896 /* Return true if it looks like target has stopped due to hitting
2897 breakpoint location BL. This function does not check if we
2898 should stop, only if BL explains the stop. */
2900 bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2902 struct breakpoint *b = bl->owner;
2904 if (b->type != bp_watchpoint
2905 && b->type != bp_hardware_watchpoint
2906 && b->type != bp_read_watchpoint
2907 && b->type != bp_access_watchpoint
2908 && b->type != bp_hardware_breakpoint
2909 && b->type != bp_catchpoint) /* a non-watchpoint bp */
2911 if (bl->address != bp_addr) /* address doesn't match */
2913 if (overlay_debugging /* unmapped overlay section */
2914 && section_is_overlay (bl->section)
2915 && !section_is_mapped (bl->section))
2919 /* Continuable hardware watchpoints are treated as non-existent if the
2920 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2921 some data address). Otherwise gdb won't stop on a break instruction
2922 in the code (not from a breakpoint) when a hardware watchpoint has
2923 been defined. Also skip watchpoints which we know did not trigger
2924 (did not match the data address). */
2926 if ((b->type == bp_hardware_watchpoint
2927 || b->type == bp_read_watchpoint
2928 || b->type == bp_access_watchpoint)
2929 && b->watchpoint_triggered == watch_triggered_no)
2932 if (b->type == bp_hardware_breakpoint)
2934 if (bl->address != bp_addr)
2936 if (overlay_debugging /* unmapped overlay section */
2937 && section_is_overlay (bl->section)
2938 && !section_is_mapped (bl->section))
2942 if (b->type == bp_catchpoint)
2944 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
2945 if (!b->ops->breakpoint_hit (b))
2952 /* If BS refers to a watchpoint, determine if the watched values
2953 has actually changed, and we should stop. If not, set BS->stop
2956 bpstat_check_watchpoint (bpstat bs)
2958 const struct bp_location *bl = bs->breakpoint_at;
2959 struct breakpoint *b = bl->owner;
2961 if (b->type == bp_watchpoint
2962 || b->type == bp_read_watchpoint
2963 || b->type == bp_access_watchpoint
2964 || b->type == bp_hardware_watchpoint)
2968 int must_check_value = 0;
2970 if (b->type == bp_watchpoint)
2971 /* For a software watchpoint, we must always check the
2973 must_check_value = 1;
2974 else if (b->watchpoint_triggered == watch_triggered_yes)
2975 /* We have a hardware watchpoint (read, write, or access)
2976 and the target earlier reported an address watched by
2978 must_check_value = 1;
2979 else if (b->watchpoint_triggered == watch_triggered_unknown
2980 && b->type == bp_hardware_watchpoint)
2981 /* We were stopped by a hardware watchpoint, but the target could
2982 not report the data address. We must check the watchpoint's
2983 value. Access and read watchpoints are out of luck; without
2984 a data address, we can't figure it out. */
2985 must_check_value = 1;
2987 if (must_check_value)
2989 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2991 struct cleanup *cleanups = make_cleanup (xfree, message);
2992 int e = catch_errors (watchpoint_check, bs, message,
2994 do_cleanups (cleanups);
2998 /* We've already printed what needs to be printed. */
2999 bs->print_it = print_it_done;
3002 case WP_VALUE_CHANGED:
3003 if (b->type == bp_read_watchpoint)
3005 /* Don't stop: read watchpoints shouldn't fire if
3006 the value has changed. This is for targets
3007 which cannot set read-only watchpoints. */
3008 bs->print_it = print_it_noop;
3012 case WP_VALUE_NOT_CHANGED:
3013 if (b->type == bp_hardware_watchpoint
3014 || b->type == bp_watchpoint)
3016 /* Don't stop: write watchpoints shouldn't fire if
3017 the value hasn't changed. */
3018 bs->print_it = print_it_noop;
3026 /* Error from catch_errors. */
3027 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3028 if (b->related_breakpoint)
3029 b->related_breakpoint->disposition = disp_del_at_next_stop;
3030 b->disposition = disp_del_at_next_stop;
3031 /* We've already printed what needs to be printed. */
3032 bs->print_it = print_it_done;
3036 else /* must_check_value == 0 */
3038 /* This is a case where some watchpoint(s) triggered, but
3039 not at the address of this watchpoint, or else no
3040 watchpoint triggered after all. So don't print
3041 anything for this watchpoint. */
3042 bs->print_it = print_it_noop;
3049 /* Check conditions (condition proper, frame, thread and ignore count)
3050 of breakpoint referred to by BS. If we should not stop for this
3051 breakpoint, set BS->stop to 0. */
3053 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3055 int thread_id = pid_to_thread_id (ptid);
3056 const struct bp_location *bl = bs->breakpoint_at;
3057 struct breakpoint *b = bl->owner;
3059 if (frame_id_p (b->frame_id)
3060 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3064 int value_is_zero = 0;
3066 /* If this is a scope breakpoint, mark the associated
3067 watchpoint as triggered so that we will handle the
3068 out-of-scope event. We'll get to the watchpoint next
3070 if (b->type == bp_watchpoint_scope)
3071 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3073 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
3075 /* We use value_mark and value_free_to_mark because it could
3076 be a long time before we return to the command level and
3077 call free_all_values. We can't call free_all_values
3078 because we might be in the middle of evaluating a
3080 struct value *mark = value_mark ();
3082 /* Need to select the frame, with all that implies so that
3083 the conditions will have the right context. Because we
3084 use the frame, we will not see an inlined function's
3085 variables when we arrive at a breakpoint at the start
3086 of the inlined function; the current frame will be the
3088 select_frame (get_current_frame ());
3090 = catch_errors (breakpoint_cond_eval, (bl->cond),
3091 "Error in testing breakpoint condition:\n",
3093 /* FIXME-someday, should give breakpoint # */
3094 value_free_to_mark (mark);
3096 if (bl->cond && value_is_zero)
3100 else if (b->thread != -1 && b->thread != thread_id)
3104 else if (b->ignore_count > 0)
3107 annotate_ignore_count_change ();
3109 /* Increase the hit count even though we don't
3117 /* Get a bpstat associated with having just stopped at address
3118 BP_ADDR in thread PTID.
3120 Determine whether we stopped at a breakpoint, etc, or whether we
3121 don't understand this stop. Result is a chain of bpstat's such that:
3123 if we don't understand the stop, the result is a null pointer.
3125 if we understand why we stopped, the result is not null.
3127 Each element of the chain refers to a particular breakpoint or
3128 watchpoint at which we have stopped. (We may have stopped for
3129 several reasons concurrently.)
3131 Each element of the chain has valid next, breakpoint_at,
3132 commands, FIXME??? fields. */
3135 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3137 struct breakpoint *b = NULL;
3138 const struct bp_location *bl;
3139 struct bp_location *loc;
3140 /* Root of the chain of bpstat's */
3141 struct bpstats root_bs[1];
3142 /* Pointer to the last thing in the chain currently. */
3143 bpstat bs = root_bs;
3145 int need_remove_insert;
3147 ALL_BP_LOCATIONS (bl)
3151 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3154 /* For hardware watchpoints, we look only at the first location.
3155 The watchpoint_check function will work on entire expression,
3156 not the individual locations. For read watchopints, the
3157 watchpoints_triggered function have checked all locations
3160 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3163 if (!bpstat_check_location (bl, bp_addr))
3166 /* Come here if it's a watchpoint, or if the break address matches */
3168 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3170 /* Assume we stop. Should we find watchpoint that is not actually
3171 triggered, or if condition of breakpoint is false, we'll reset
3176 bpstat_check_watchpoint (bs);
3180 if (b->type == bp_thread_event || b->type == bp_overlay_event
3181 || b->type == bp_longjmp_master)
3182 /* We do not stop for these. */
3185 bpstat_check_breakpoint_conditions (bs, ptid);
3191 /* We will stop here */
3192 if (b->disposition == disp_disable)
3194 if (b->enable_state != bp_permanent)
3195 b->enable_state = bp_disabled;
3196 update_global_location_list (0);
3200 bs->commands = b->commands;
3202 && (strcmp ("silent", bs->commands->line) == 0
3203 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3205 bs->commands = bs->commands->next;
3208 bs->commands = copy_command_lines (bs->commands);
3211 /* Print nothing for this entry if we dont stop or if we dont print. */
3212 if (bs->stop == 0 || bs->print == 0)
3213 bs->print_it = print_it_noop;
3216 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3218 if (loc->address == bp_addr)
3220 bs = bpstat_alloc (loc, bs);
3221 /* For hits of moribund locations, we should just proceed. */
3224 bs->print_it = print_it_noop;
3228 bs->next = NULL; /* Terminate the chain */
3229 bs = root_bs->next; /* Re-grab the head of the chain */
3231 /* If we aren't stopping, the value of some hardware watchpoint may
3232 not have changed, but the intermediate memory locations we are
3233 watching may have. Don't bother if we're stopping; this will get
3235 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3239 need_remove_insert = 0;
3241 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3243 && bs->breakpoint_at->owner
3244 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3245 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3246 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3248 /* remove/insert can invalidate bs->breakpoint_at, if this
3249 location is no longer used by the watchpoint. Prevent
3250 further code from trying to use it. */
3251 bs->breakpoint_at = NULL;
3252 need_remove_insert = 1;
3255 if (need_remove_insert)
3257 remove_breakpoints ();
3258 insert_breakpoints ();
3261 return root_bs->next;
3264 /* Tell what to do about this bpstat. */
3266 bpstat_what (bpstat bs)
3268 /* Classify each bpstat as one of the following. */
3271 /* This bpstat element has no effect on the main_action. */
3274 /* There was a watchpoint, stop but don't print. */
3277 /* There was a watchpoint, stop and print. */
3280 /* There was a breakpoint but we're not stopping. */
3283 /* There was a breakpoint, stop but don't print. */
3286 /* There was a breakpoint, stop and print. */
3289 /* We hit the longjmp breakpoint. */
3292 /* We hit the longjmp_resume breakpoint. */
3295 /* We hit the step_resume breakpoint. */
3298 /* We hit the shared library event breakpoint. */
3301 /* This is just used to count how many enums there are. */
3305 /* Here is the table which drives this routine. So that we can
3306 format it pretty, we define some abbreviations for the
3307 enum bpstat_what codes. */
3308 #define kc BPSTAT_WHAT_KEEP_CHECKING
3309 #define ss BPSTAT_WHAT_STOP_SILENT
3310 #define sn BPSTAT_WHAT_STOP_NOISY
3311 #define sgl BPSTAT_WHAT_SINGLE
3312 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3313 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3314 #define sr BPSTAT_WHAT_STEP_RESUME
3315 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3317 /* "Can't happen." Might want to print an error message.
3318 abort() is not out of the question, but chances are GDB is just
3319 a bit confused, not unusable. */
3320 #define err BPSTAT_WHAT_STOP_NOISY
3322 /* Given an old action and a class, come up with a new action. */
3323 /* One interesting property of this table is that wp_silent is the same
3324 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3325 after stopping, the check for whether to step over a breakpoint
3326 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3327 reference to how we stopped. We retain separate wp_silent and
3328 bp_silent codes in case we want to change that someday.
3330 Another possibly interesting property of this table is that
3331 there's a partial ordering, priority-like, of the actions. Once
3332 you've decided that some action is appropriate, you'll never go
3333 back and decide something of a lower priority is better. The
3336 kc < clr sgl shl slr sn sr ss
3337 sgl < shl slr sn sr ss
3338 slr < err shl sn sr ss
3339 clr < err shl sn sr ss
3345 What I think this means is that we don't need a damned table
3346 here. If you just put the rows and columns in the right order,
3347 it'd look awfully regular. We could simply walk the bpstat list
3348 and choose the highest priority action we find, with a little
3349 logic to handle the 'err' cases. */
3351 /* step_resume entries: a step resume breakpoint overrides another
3352 breakpoint of signal handling (see comment in wait_for_inferior
3353 at where we set the step_resume breakpoint). */
3355 static const enum bpstat_what_main_action
3356 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3359 /* kc ss sn sgl slr clr sr shl
3362 {kc, ss, sn, sgl, slr, clr, sr, shl},
3364 {ss, ss, sn, ss, ss, ss, sr, shl},
3366 {sn, sn, sn, sn, sn, sn, sr, shl},
3368 {sgl, ss, sn, sgl, slr, slr, sr, shl},
3370 {ss, ss, sn, ss, ss, ss, sr, shl},
3372 {sn, sn, sn, sn, sn, sn, sr, shl},
3374 {slr, ss, sn, slr, slr, err, sr, shl},
3376 {clr, ss, sn, err, err, err, sr, shl},
3378 {sr, sr, sr, sr, sr, sr, sr, sr},
3380 {shl, shl, shl, shl, shl, shl, sr, shl}
3393 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3394 struct bpstat_what retval;
3396 retval.call_dummy = 0;
3397 for (; bs != NULL; bs = bs->next)
3399 enum class bs_class = no_effect;
3400 if (bs->breakpoint_at == NULL)
3401 /* I suspect this can happen if it was a momentary breakpoint
3402 which has since been deleted. */
3404 if (bs->breakpoint_at->owner == NULL)
3405 bs_class = bp_nostop;
3407 switch (bs->breakpoint_at->owner->type)
3413 case bp_hardware_breakpoint:
3419 bs_class = bp_noisy;
3421 bs_class = bp_silent;
3424 bs_class = bp_nostop;
3427 case bp_hardware_watchpoint:
3428 case bp_read_watchpoint:
3429 case bp_access_watchpoint:
3433 bs_class = wp_noisy;
3435 bs_class = wp_silent;
3438 /* There was a watchpoint, but we're not stopping.
3439 This requires no further action. */
3440 bs_class = no_effect;
3443 bs_class = long_jump;
3445 case bp_longjmp_resume:
3446 bs_class = long_resume;
3448 case bp_step_resume:
3451 bs_class = step_resume;
3454 /* It is for the wrong frame. */
3455 bs_class = bp_nostop;
3457 case bp_watchpoint_scope:
3458 bs_class = bp_nostop;
3460 case bp_shlib_event:
3461 bs_class = shlib_event;
3463 case bp_thread_event:
3464 case bp_overlay_event:
3465 case bp_longjmp_master:
3466 bs_class = bp_nostop;
3472 bs_class = bp_noisy;
3474 bs_class = bp_silent;
3477 /* There was a catchpoint, but we're not stopping.
3478 This requires no further action. */
3479 bs_class = no_effect;
3482 /* Make sure the action is stop (silent or noisy),
3483 so infrun.c pops the dummy frame. */
3484 bs_class = bp_silent;
3485 retval.call_dummy = 1;
3488 /* Tracepoint hits should not be reported back to GDB, and
3489 if one got through somehow, it should have been filtered
3491 internal_error (__FILE__, __LINE__,
3492 _("bpstat_what: bp_tracepoint encountered"));
3495 current_action = table[(int) bs_class][(int) current_action];
3497 retval.main_action = current_action;
3501 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3502 without hardware support). This isn't related to a specific bpstat,
3503 just to things like whether watchpoints are set. */
3506 bpstat_should_step (void)
3508 struct breakpoint *b;
3510 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
3517 static void print_breakpoint_location (struct breakpoint *b,
3518 struct bp_location *loc,
3520 struct ui_stream *stb)
3525 = find_pc_sect_function (loc->address, loc->section);
3528 ui_out_text (uiout, "in ");
3529 ui_out_field_string (uiout, "func",
3530 SYMBOL_PRINT_NAME (sym));
3531 ui_out_wrap_hint (uiout, wrap_indent);
3532 ui_out_text (uiout, " at ");
3534 ui_out_field_string (uiout, "file", b->source_file);
3535 ui_out_text (uiout, ":");
3537 if (ui_out_is_mi_like_p (uiout))
3539 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3540 char *fullname = symtab_to_fullname (sal.symtab);
3543 ui_out_field_string (uiout, "fullname", fullname);
3546 ui_out_field_int (uiout, "line", b->line_number);
3550 ui_out_field_string (uiout, "pending", b->addr_string);
3554 print_address_symbolic (loc->address, stb->stream, demangle, "");
3555 ui_out_field_stream (uiout, "at", stb);
3559 /* Print B to gdb_stdout. */
3561 print_one_breakpoint_location (struct breakpoint *b,
3562 struct bp_location *loc,
3564 struct bp_location **last_loc,
3565 int print_address_bits)
3567 struct command_line *l;
3569 struct ep_type_description
3574 static struct ep_type_description bptypes[] =
3576 {bp_none, "?deleted?"},
3577 {bp_breakpoint, "breakpoint"},
3578 {bp_hardware_breakpoint, "hw breakpoint"},
3579 {bp_until, "until"},
3580 {bp_finish, "finish"},
3581 {bp_watchpoint, "watchpoint"},
3582 {bp_hardware_watchpoint, "hw watchpoint"},
3583 {bp_read_watchpoint, "read watchpoint"},
3584 {bp_access_watchpoint, "acc watchpoint"},
3585 {bp_longjmp, "longjmp"},
3586 {bp_longjmp_resume, "longjmp resume"},
3587 {bp_step_resume, "step resume"},
3588 {bp_watchpoint_scope, "watchpoint scope"},
3589 {bp_call_dummy, "call dummy"},
3590 {bp_shlib_event, "shlib events"},
3591 {bp_thread_event, "thread events"},
3592 {bp_overlay_event, "overlay events"},
3593 {bp_longjmp_master, "longjmp master"},
3594 {bp_catchpoint, "catchpoint"},
3595 {bp_tracepoint, "tracepoint"},
3598 static char bpenables[] = "nynny";
3599 char wrap_indent[80];
3600 struct ui_stream *stb = ui_out_stream_new (uiout);
3601 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3602 struct cleanup *bkpt_chain;
3604 int header_of_multiple = 0;
3605 int part_of_multiple = (loc != NULL);
3606 struct value_print_options opts;
3608 get_user_print_options (&opts);
3610 gdb_assert (!loc || loc_number != 0);
3611 /* See comment in print_one_breakpoint concerning
3612 treatment of breakpoints with single disabled
3616 && (b->loc->next != NULL || !b->loc->enabled)))
3617 header_of_multiple = 1;
3622 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3626 if (part_of_multiple)
3629 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3630 ui_out_field_string (uiout, "number", formatted);
3635 ui_out_field_int (uiout, "number", b->number);
3640 if (part_of_multiple)
3641 ui_out_field_skip (uiout, "type");
3644 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3645 || ((int) b->type != bptypes[(int) b->type].type))
3646 internal_error (__FILE__, __LINE__,
3647 _("bptypes table does not describe type #%d."),
3649 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3654 if (part_of_multiple)
3655 ui_out_field_skip (uiout, "disp");
3657 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3662 if (part_of_multiple)
3663 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3665 ui_out_field_fmt (uiout, "enabled", "%c",
3666 bpenables[(int) b->enable_state]);
3667 ui_out_spaces (uiout, 2);
3671 strcpy (wrap_indent, " ");
3672 if (opts.addressprint)
3674 if (print_address_bits <= 32)
3675 strcat (wrap_indent, " ");
3677 strcat (wrap_indent, " ");
3680 if (b->ops != NULL && b->ops->print_one != NULL)
3682 /* Although the print_one can possibly print
3683 all locations, calling it here is not likely
3684 to get any nice result. So, make sure there's
3685 just one location. */
3686 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3687 b->ops->print_one (b, last_loc);
3693 internal_error (__FILE__, __LINE__,
3694 _("print_one_breakpoint: bp_none encountered\n"));
3698 case bp_hardware_watchpoint:
3699 case bp_read_watchpoint:
3700 case bp_access_watchpoint:
3701 /* Field 4, the address, is omitted (which makes the columns
3702 not line up too nicely with the headers, but the effect
3703 is relatively readable). */
3704 if (opts.addressprint)
3705 ui_out_field_skip (uiout, "addr");
3707 ui_out_field_string (uiout, "what", b->exp_string);
3711 case bp_hardware_breakpoint:
3715 case bp_longjmp_resume:
3716 case bp_step_resume:
3717 case bp_watchpoint_scope:
3719 case bp_shlib_event:
3720 case bp_thread_event:
3721 case bp_overlay_event:
3722 case bp_longjmp_master:
3724 if (opts.addressprint)
3727 if (header_of_multiple)
3728 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3729 else if (b->loc == NULL || loc->shlib_disabled)
3730 ui_out_field_string (uiout, "addr", "<PENDING>");
3732 ui_out_field_core_addr (uiout, "addr",
3733 loc->gdbarch, loc->address);
3736 if (!header_of_multiple)
3737 print_breakpoint_location (b, loc, wrap_indent, stb);
3743 if (!part_of_multiple)
3745 if (b->thread != -1)
3747 /* FIXME: This seems to be redundant and lost here; see the
3748 "stop only in" line a little further down. */
3749 ui_out_text (uiout, " thread ");
3750 ui_out_field_int (uiout, "thread", b->thread);
3752 else if (b->task != 0)
3754 ui_out_text (uiout, " task ");
3755 ui_out_field_int (uiout, "task", b->task);
3759 ui_out_text (uiout, "\n");
3761 if (part_of_multiple && frame_id_p (b->frame_id))
3764 ui_out_text (uiout, "\tstop only in stack frame at ");
3765 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3767 ui_out_field_core_addr (uiout, "frame",
3768 b->gdbarch, b->frame_id.stack_addr);
3769 ui_out_text (uiout, "\n");
3772 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3774 /* We do not print the condition for Ada exception catchpoints
3775 because the condition is an internal implementation detail
3776 that we do not want to expose to the user. */
3778 if (b->type == bp_tracepoint)
3779 ui_out_text (uiout, "\ttrace only if ");
3781 ui_out_text (uiout, "\tstop only if ");
3782 ui_out_field_string (uiout, "cond", b->cond_string);
3783 ui_out_text (uiout, "\n");
3786 if (!part_of_multiple && b->thread != -1)
3788 /* FIXME should make an annotation for this */
3789 ui_out_text (uiout, "\tstop only in thread ");
3790 ui_out_field_int (uiout, "thread", b->thread);
3791 ui_out_text (uiout, "\n");
3794 if (!part_of_multiple && b->hit_count)
3796 /* FIXME should make an annotation for this */
3797 if (ep_is_catchpoint (b))
3798 ui_out_text (uiout, "\tcatchpoint");
3800 ui_out_text (uiout, "\tbreakpoint");
3801 ui_out_text (uiout, " already hit ");
3802 ui_out_field_int (uiout, "times", b->hit_count);
3803 if (b->hit_count == 1)
3804 ui_out_text (uiout, " time\n");
3806 ui_out_text (uiout, " times\n");
3809 /* Output the count also if it is zero, but only if this is
3810 mi. FIXME: Should have a better test for this. */
3811 if (ui_out_is_mi_like_p (uiout))
3812 if (!part_of_multiple && b->hit_count == 0)
3813 ui_out_field_int (uiout, "times", b->hit_count);
3815 if (!part_of_multiple && b->ignore_count)
3818 ui_out_text (uiout, "\tignore next ");
3819 ui_out_field_int (uiout, "ignore", b->ignore_count);
3820 ui_out_text (uiout, " hits\n");
3824 if (!part_of_multiple && l)
3826 struct cleanup *script_chain;
3829 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3830 print_command_lines (uiout, l, 4);
3831 do_cleanups (script_chain);
3834 if (!part_of_multiple && b->pass_count)
3836 annotate_field (10);
3837 ui_out_text (uiout, "\tpass count ");
3838 ui_out_field_int (uiout, "pass", b->pass_count);
3839 ui_out_text (uiout, " \n");
3842 if (!part_of_multiple && b->step_count)
3844 annotate_field (11);
3845 ui_out_text (uiout, "\tstep count ");
3846 ui_out_field_int (uiout, "step", b->step_count);
3847 ui_out_text (uiout, " \n");
3850 if (!part_of_multiple && b->actions)
3852 struct action_line *action;
3853 annotate_field (12);
3854 for (action = b->actions; action; action = action->next)
3856 ui_out_text (uiout, " A\t");
3857 ui_out_text (uiout, action->action);
3858 ui_out_text (uiout, "\n");
3862 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3865 ui_out_field_string (uiout, "original-location", b->addr_string);
3866 else if (b->exp_string)
3867 ui_out_field_string (uiout, "original-location", b->exp_string);
3870 do_cleanups (bkpt_chain);
3871 do_cleanups (old_chain);
3875 print_one_breakpoint (struct breakpoint *b,
3876 struct bp_location **last_loc, int print_address_bits)
3878 print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits);
3880 /* If this breakpoint has custom print function,
3881 it's already printed. Otherwise, print individual
3882 locations, if any. */
3883 if (b->ops == NULL || b->ops->print_one == NULL)
3885 /* If breakpoint has a single location that is
3886 disabled, we print it as if it had
3887 several locations, since otherwise it's hard to
3888 represent "breakpoint enabled, location disabled"
3890 Note that while hardware watchpoints have
3891 several locations internally, that's no a property
3894 && !is_hardware_watchpoint (b)
3895 && (b->loc->next || !b->loc->enabled)
3896 && !ui_out_is_mi_like_p (uiout))
3898 struct bp_location *loc;
3900 for (loc = b->loc; loc; loc = loc->next, ++n)
3901 print_one_breakpoint_location (b, loc, n, last_loc,
3902 print_address_bits);
3908 breakpoint_address_bits (struct breakpoint *b)
3910 int print_address_bits = 0;
3911 struct bp_location *loc;
3913 for (loc = b->loc; loc; loc = loc->next)
3915 int addr_bit = gdbarch_addr_bit (b->gdbarch);
3916 if (addr_bit > print_address_bits)
3917 print_address_bits = addr_bit;
3920 return print_address_bits;
3923 struct captured_breakpoint_query_args
3929 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3931 struct captured_breakpoint_query_args *args = data;
3932 struct breakpoint *b;
3933 struct bp_location *dummy_loc = NULL;
3936 if (args->bnum == b->number)
3938 int print_address_bits = breakpoint_address_bits (b);
3939 print_one_breakpoint (b, &dummy_loc, print_address_bits);
3947 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3949 struct captured_breakpoint_query_args args;
3951 /* For the moment we don't trust print_one_breakpoint() to not throw
3953 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3954 error_message, RETURN_MASK_ALL) < 0)
3960 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3961 catchpoints, et.al.). */
3964 user_settable_breakpoint (const struct breakpoint *b)
3966 return (b->type == bp_breakpoint
3967 || b->type == bp_catchpoint
3968 || b->type == bp_hardware_breakpoint
3969 || b->type == bp_tracepoint
3970 || b->type == bp_watchpoint
3971 || b->type == bp_read_watchpoint
3972 || b->type == bp_access_watchpoint
3973 || b->type == bp_hardware_watchpoint);
3976 /* Print information on user settable breakpoint (watchpoint, etc)
3977 number BNUM. If BNUM is -1 print all user settable breakpoints.
3978 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3981 breakpoint_1 (int bnum, int allflag)
3983 struct breakpoint *b;
3984 struct bp_location *last_loc = NULL;
3985 int nr_printable_breakpoints;
3986 struct cleanup *bkpttbl_chain;
3987 struct value_print_options opts;
3988 int print_address_bits = 0;
3990 get_user_print_options (&opts);
3992 /* Compute the number of rows in the table, as well as the
3993 size required for address fields. */
3994 nr_printable_breakpoints = 0;
3997 || bnum == b->number)
3999 if (allflag || user_settable_breakpoint (b))
4001 int addr_bit = breakpoint_address_bits (b);
4002 if (addr_bit > print_address_bits)
4003 print_address_bits = addr_bit;
4005 nr_printable_breakpoints++;
4009 if (opts.addressprint)
4011 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
4015 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
4018 if (nr_printable_breakpoints > 0)
4019 annotate_breakpoints_headers ();
4020 if (nr_printable_breakpoints > 0)
4022 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
4023 if (nr_printable_breakpoints > 0)
4025 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
4026 if (nr_printable_breakpoints > 0)
4028 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
4029 if (nr_printable_breakpoints > 0)
4031 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
4032 if (opts.addressprint)
4034 if (nr_printable_breakpoints > 0)
4036 if (print_address_bits <= 32)
4037 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
4039 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
4041 if (nr_printable_breakpoints > 0)
4043 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
4044 ui_out_table_body (uiout);
4045 if (nr_printable_breakpoints > 0)
4046 annotate_breakpoints_table ();
4050 || bnum == b->number)
4052 /* We only print out user settable breakpoints unless the
4054 if (allflag || user_settable_breakpoint (b))
4055 print_one_breakpoint (b, &last_loc, print_address_bits);
4058 do_cleanups (bkpttbl_chain);
4060 if (nr_printable_breakpoints == 0)
4063 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
4065 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
4070 if (last_loc && !server_command)
4071 set_next_address (last_loc->gdbarch, last_loc->address);
4074 /* FIXME? Should this be moved up so that it is only called when
4075 there have been breakpoints? */
4076 annotate_breakpoints_table_end ();
4080 breakpoints_info (char *bnum_exp, int from_tty)
4085 bnum = parse_and_eval_long (bnum_exp);
4087 breakpoint_1 (bnum, 0);
4091 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4096 bnum = parse_and_eval_long (bnum_exp);
4098 breakpoint_1 (bnum, 1);
4102 breakpoint_has_pc (struct breakpoint *b,
4103 CORE_ADDR pc, struct obj_section *section)
4105 struct bp_location *bl = b->loc;
4106 for (; bl; bl = bl->next)
4108 if (bl->address == pc
4109 && (!overlay_debugging || bl->section == section))
4115 /* Print a message describing any breakpoints set at PC. */
4118 describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc,
4119 struct obj_section *section, int thread)
4122 struct breakpoint *b;
4125 others += breakpoint_has_pc (b, pc, section);
4129 printf_filtered (_("Note: breakpoint "));
4130 else /* if (others == ???) */
4131 printf_filtered (_("Note: breakpoints "));
4133 if (breakpoint_has_pc (b, pc, section))
4136 printf_filtered ("%d", b->number);
4137 if (b->thread == -1 && thread != -1)
4138 printf_filtered (" (all threads)");
4139 else if (b->thread != -1)
4140 printf_filtered (" (thread %d)", b->thread);
4141 printf_filtered ("%s%s ",
4142 ((b->enable_state == bp_disabled
4143 || b->enable_state == bp_call_disabled)
4145 : b->enable_state == bp_permanent
4149 : ((others == 1) ? " and" : ""));
4151 printf_filtered (_("also set at pc "));
4152 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
4153 printf_filtered (".\n");
4157 /* Set the default place to put a breakpoint
4158 for the `break' command with no arguments. */
4161 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4164 default_breakpoint_valid = valid;
4165 default_breakpoint_address = addr;
4166 default_breakpoint_symtab = symtab;
4167 default_breakpoint_line = line;
4170 /* Return true iff it is meaningful to use the address member of
4171 BPT. For some breakpoint types, the address member is irrelevant
4172 and it makes no sense to attempt to compare it to other addresses
4173 (or use it for any other purpose either).
4175 More specifically, each of the following breakpoint types will always
4176 have a zero valued address and we don't want check_duplicates() to mark
4177 breakpoints of any of these types to be a duplicate of an actual
4178 breakpoint at address zero:
4181 bp_hardware_watchpoint
4183 bp_access_watchpoint
4187 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4189 enum bptype type = bpt->type;
4191 return (type != bp_watchpoint
4192 && type != bp_hardware_watchpoint
4193 && type != bp_read_watchpoint
4194 && type != bp_access_watchpoint
4195 && type != bp_catchpoint);
4198 /* Rescan breakpoints at the same address and section as BPT,
4199 marking the first one as "first" and any others as "duplicates".
4200 This is so that the bpt instruction is only inserted once.
4201 If we have a permanent breakpoint at the same place as BPT, make
4202 that one the official one, and the rest as duplicates. */
4205 check_duplicates_for (CORE_ADDR address, struct obj_section *section)
4207 struct bp_location *b;
4209 struct bp_location *perm_bp = 0;
4211 ALL_BP_LOCATIONS (b)
4212 if (b->owner->enable_state != bp_disabled
4213 && b->owner->enable_state != bp_call_disabled
4215 && !b->shlib_disabled
4216 && b->address == address /* address / overlay match */
4217 && (!overlay_debugging || b->section == section)
4218 && breakpoint_address_is_meaningful (b->owner))
4220 /* Have we found a permanent breakpoint? */
4221 if (b->owner->enable_state == bp_permanent)
4228 b->duplicate = count > 1;
4231 /* If we found a permanent breakpoint at this address, go over the
4232 list again and declare all the other breakpoints there (except
4233 other permanent breakpoints) to be the duplicates. */
4236 perm_bp->duplicate = 0;
4238 /* Permanent breakpoint should always be inserted. */
4239 if (! perm_bp->inserted)
4240 internal_error (__FILE__, __LINE__,
4241 _("allegedly permanent breakpoint is not "
4242 "actually inserted"));
4244 ALL_BP_LOCATIONS (b)
4247 if (b->owner->enable_state != bp_permanent
4248 && b->owner->enable_state != bp_disabled
4249 && b->owner->enable_state != bp_call_disabled
4250 && b->enabled && !b->shlib_disabled
4251 && b->address == address /* address / overlay match */
4252 && (!overlay_debugging || b->section == section)
4253 && breakpoint_address_is_meaningful (b->owner))
4256 internal_error (__FILE__, __LINE__,
4257 _("another breakpoint was inserted on top of "
4258 "a permanent breakpoint"));
4267 check_duplicates (struct breakpoint *bpt)
4269 struct bp_location *bl = bpt->loc;
4271 if (! breakpoint_address_is_meaningful (bpt))
4274 for (; bl; bl = bl->next)
4275 check_duplicates_for (bl->address, bl->section);
4279 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4280 int bnum, int have_bnum)
4285 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4286 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4288 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4289 bnum, astr1, astr2);
4291 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4294 /* Adjust a breakpoint's address to account for architectural constraints
4295 on breakpoint placement. Return the adjusted address. Note: Very
4296 few targets require this kind of adjustment. For most targets,
4297 this function is simply the identity function. */
4300 adjust_breakpoint_address (struct gdbarch *gdbarch,
4301 CORE_ADDR bpaddr, enum bptype bptype)
4303 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
4305 /* Very few targets need any kind of breakpoint adjustment. */
4308 else if (bptype == bp_watchpoint
4309 || bptype == bp_hardware_watchpoint
4310 || bptype == bp_read_watchpoint
4311 || bptype == bp_access_watchpoint
4312 || bptype == bp_catchpoint)
4314 /* Watchpoints and the various bp_catch_* eventpoints should not
4315 have their addresses modified. */
4320 CORE_ADDR adjusted_bpaddr;
4322 /* Some targets have architectural constraints on the placement
4323 of breakpoint instructions. Obtain the adjusted address. */
4324 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
4326 /* An adjusted breakpoint address can significantly alter
4327 a user's expectations. Print a warning if an adjustment
4329 if (adjusted_bpaddr != bpaddr)
4330 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4332 return adjusted_bpaddr;
4336 /* Allocate a struct bp_location. */
4338 static struct bp_location *
4339 allocate_bp_location (struct breakpoint *bpt)
4341 struct bp_location *loc, *loc_p;
4343 loc = xmalloc (sizeof (struct bp_location));
4344 memset (loc, 0, sizeof (*loc));
4348 loc->shlib_disabled = 0;
4358 case bp_longjmp_resume:
4359 case bp_step_resume:
4360 case bp_watchpoint_scope:
4362 case bp_shlib_event:
4363 case bp_thread_event:
4364 case bp_overlay_event:
4365 case bp_longjmp_master:
4366 loc->loc_type = bp_loc_software_breakpoint;
4368 case bp_hardware_breakpoint:
4369 loc->loc_type = bp_loc_hardware_breakpoint;
4371 case bp_hardware_watchpoint:
4372 case bp_read_watchpoint:
4373 case bp_access_watchpoint:
4374 loc->loc_type = bp_loc_hardware_watchpoint;
4378 loc->loc_type = bp_loc_other;
4381 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4387 static void free_bp_location (struct bp_location *loc)
4392 if (loc->function_name)
4393 xfree (loc->function_name);
4398 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4399 that has type BPTYPE and has no locations as yet. */
4400 /* This function is used in gdbtk sources and thus can not be made static. */
4402 static struct breakpoint *
4403 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
4406 struct breakpoint *b, *b1;
4408 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4409 memset (b, 0, sizeof (*b));
4412 b->gdbarch = gdbarch;
4413 b->language = current_language->la_language;
4414 b->input_radix = input_radix;
4416 b->enable_state = bp_enabled;
4419 b->ignore_count = 0;
4421 b->frame_id = null_frame_id;
4422 b->forked_inferior_pid = null_ptid;
4423 b->exec_pathname = NULL;
4425 b->condition_not_parsed = 0;
4427 /* Add this breakpoint to the end of the chain
4428 so that a list of breakpoints will come out in order
4429 of increasing numbers. */
4431 b1 = breakpoint_chain;
4433 breakpoint_chain = b;
4443 /* Initialize loc->function_name. */
4445 set_breakpoint_location_function (struct bp_location *loc)
4447 if (loc->owner->type == bp_breakpoint
4448 || loc->owner->type == bp_hardware_breakpoint
4449 || loc->owner->type == bp_tracepoint)
4451 find_pc_partial_function (loc->address, &(loc->function_name),
4453 if (loc->function_name)
4454 loc->function_name = xstrdup (loc->function_name);
4458 /* Attempt to determine architecture of location identified by SAL. */
4459 static struct gdbarch *
4460 get_sal_arch (struct symtab_and_line sal)
4463 return get_objfile_arch (sal.section->objfile);
4465 return get_objfile_arch (sal.symtab->objfile);
4470 /* set_raw_breakpoint is a low level routine for allocating and
4471 partially initializing a breakpoint of type BPTYPE. The newly
4472 created breakpoint's address, section, source file name, and line
4473 number are provided by SAL. The newly created and partially
4474 initialized breakpoint is added to the breakpoint chain and
4475 is also returned as the value of this function.
4477 It is expected that the caller will complete the initialization of
4478 the newly created breakpoint struct as well as output any status
4479 information regarding the creation of a new breakpoint. In
4480 particular, set_raw_breakpoint does NOT set the breakpoint
4481 number! Care should be taken to not allow an error to occur
4482 prior to completing the initialization of the breakpoint. If this
4483 should happen, a bogus breakpoint will be left on the chain. */
4486 set_raw_breakpoint (struct gdbarch *gdbarch,
4487 struct symtab_and_line sal, enum bptype bptype)
4489 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
4490 CORE_ADDR adjusted_address;
4491 struct gdbarch *loc_gdbarch;
4493 loc_gdbarch = get_sal_arch (sal);
4495 loc_gdbarch = b->gdbarch;
4497 /* Adjust the breakpoint's address prior to allocating a location.
4498 Once we call allocate_bp_location(), that mostly uninitialized
4499 location will be placed on the location chain. Adjustment of the
4500 breakpoint may cause target_read_memory() to be called and we do
4501 not want its scan of the location chain to find a breakpoint and
4502 location that's only been partially initialized. */
4503 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
4505 b->loc = allocate_bp_location (b);
4506 b->loc->gdbarch = loc_gdbarch;
4507 b->loc->requested_address = sal.pc;
4508 b->loc->address = adjusted_address;
4510 if (sal.symtab == NULL)
4511 b->source_file = NULL;
4513 b->source_file = xstrdup (sal.symtab->filename);
4514 b->loc->section = sal.section;
4515 b->line_number = sal.line;
4517 set_breakpoint_location_function (b->loc);
4519 breakpoints_changed ();
4525 /* Note that the breakpoint object B describes a permanent breakpoint
4526 instruction, hard-wired into the inferior's code. */
4528 make_breakpoint_permanent (struct breakpoint *b)
4530 struct bp_location *bl;
4531 b->enable_state = bp_permanent;
4533 /* By definition, permanent breakpoints are already present in the code.
4534 Mark all locations as inserted. For now, make_breakpoint_permanent
4535 is called in just one place, so it's hard to say if it's reasonable
4536 to have permanent breakpoint with multiple locations or not,
4537 but it's easy to implmement. */
4538 for (bl = b->loc; bl; bl = bl->next)
4542 /* Call this routine when stepping and nexting to enable a breakpoint
4543 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4544 set_longjmp_resume_breakpoint() to figure out where we are going. */
4547 set_longjmp_breakpoint (int thread)
4549 struct breakpoint *b, *temp;
4551 /* To avoid having to rescan all objfile symbols at every step,
4552 we maintain a list of continually-inserted but always disabled
4553 longjmp "master" breakpoints. Here, we simply create momentary
4554 clones of those and enable them for the requested thread. */
4555 ALL_BREAKPOINTS_SAFE (b, temp)
4556 if (b->type == bp_longjmp_master)
4558 struct breakpoint *clone = clone_momentary_breakpoint (b);
4559 clone->type = bp_longjmp;
4560 clone->thread = thread;
4564 /* Delete all longjmp breakpoints from THREAD. */
4566 delete_longjmp_breakpoint (int thread)
4568 struct breakpoint *b, *temp;
4570 ALL_BREAKPOINTS_SAFE (b, temp)
4571 if (b->type == bp_longjmp)
4573 if (b->thread == thread)
4574 delete_breakpoint (b);
4579 enable_overlay_breakpoints (void)
4581 struct breakpoint *b;
4584 if (b->type == bp_overlay_event)
4586 b->enable_state = bp_enabled;
4587 update_global_location_list (1);
4588 overlay_events_enabled = 1;
4593 disable_overlay_breakpoints (void)
4595 struct breakpoint *b;
4598 if (b->type == bp_overlay_event)
4600 b->enable_state = bp_disabled;
4601 update_global_location_list (0);
4602 overlay_events_enabled = 0;
4607 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
4609 struct breakpoint *b;
4611 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
4613 b->enable_state = bp_enabled;
4614 /* addr_string has to be used or breakpoint_re_set will delete me. */
4616 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
4618 update_global_location_list_nothrow (1);
4624 remove_thread_event_breakpoints (void)
4626 struct breakpoint *b, *temp;
4628 ALL_BREAKPOINTS_SAFE (b, temp)
4629 if (b->type == bp_thread_event)
4630 delete_breakpoint (b);
4633 struct captured_parse_breakpoint_args
4636 struct symtabs_and_lines *sals_p;
4637 char ***addr_string_p;
4641 struct lang_and_radix
4649 remove_solib_event_breakpoints (void)
4651 struct breakpoint *b, *temp;
4653 ALL_BREAKPOINTS_SAFE (b, temp)
4654 if (b->type == bp_shlib_event)
4655 delete_breakpoint (b);
4659 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
4661 struct breakpoint *b;
4663 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
4664 update_global_location_list_nothrow (1);
4668 /* Disable any breakpoints that are on code in shared libraries. Only
4669 apply to enabled breakpoints, disabled ones can just stay disabled. */
4672 disable_breakpoints_in_shlibs (void)
4674 struct bp_location *loc;
4676 ALL_BP_LOCATIONS (loc)
4678 struct breakpoint *b = loc->owner;
4679 /* We apply the check to all breakpoints, including disabled
4680 for those with loc->duplicate set. This is so that when breakpoint
4681 becomes enabled, or the duplicate is removed, gdb will try to insert
4682 all breakpoints. If we don't set shlib_disabled here, we'll try
4683 to insert those breakpoints and fail. */
4684 if (((b->type == bp_breakpoint)
4685 || (b->type == bp_hardware_breakpoint)
4686 || (b->type == bp_tracepoint))
4687 && !loc->shlib_disabled
4689 && PC_SOLIB (loc->address)
4691 && solib_name_from_address (loc->address)
4695 loc->shlib_disabled = 1;
4700 /* Disable any breakpoints that are in in an unloaded shared library. Only
4701 apply to enabled breakpoints, disabled ones can just stay disabled. */
4704 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4706 struct bp_location *loc;
4707 int disabled_shlib_breaks = 0;
4709 /* SunOS a.out shared libraries are always mapped, so do not
4710 disable breakpoints; they will only be reported as unloaded
4711 through clear_solib when GDB discards its shared library
4712 list. See clear_solib for more information. */
4713 if (exec_bfd != NULL
4714 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
4717 ALL_BP_LOCATIONS (loc)
4719 struct breakpoint *b = loc->owner;
4720 if ((loc->loc_type == bp_loc_hardware_breakpoint
4721 || loc->loc_type == bp_loc_software_breakpoint)
4722 && !loc->shlib_disabled
4723 && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
4724 && solib_contains_address_p (solib, loc->address))
4726 loc->shlib_disabled = 1;
4727 /* At this point, we cannot rely on remove_breakpoint
4728 succeeding so we must mark the breakpoint as not inserted
4729 to prevent future errors occurring in remove_breakpoints. */
4731 if (!disabled_shlib_breaks)
4733 target_terminal_ours_for_output ();
4734 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4737 disabled_shlib_breaks = 1;
4742 /* FORK & VFORK catchpoints. */
4744 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4747 insert_catch_fork (struct breakpoint *b)
4749 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
4752 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4755 remove_catch_fork (struct breakpoint *b)
4757 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
4760 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4764 breakpoint_hit_catch_fork (struct breakpoint *b)
4766 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
4769 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4771 static enum print_stop_action
4772 print_it_catch_fork (struct breakpoint *b)
4774 annotate_catchpoint (b->number);
4775 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4776 b->number, ptid_get_pid (b->forked_inferior_pid));
4777 return PRINT_SRC_AND_LOC;
4780 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4783 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
4785 struct value_print_options opts;
4787 get_user_print_options (&opts);
4789 /* Field 4, the address, is omitted (which makes the columns
4790 not line up too nicely with the headers, but the effect
4791 is relatively readable). */
4792 if (opts.addressprint)
4793 ui_out_field_skip (uiout, "addr");
4795 ui_out_text (uiout, "fork");
4796 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4798 ui_out_text (uiout, ", process ");
4799 ui_out_field_int (uiout, "what",
4800 ptid_get_pid (b->forked_inferior_pid));
4801 ui_out_spaces (uiout, 1);
4805 /* Implement the "print_mention" breakpoint_ops method for fork
4809 print_mention_catch_fork (struct breakpoint *b)
4811 printf_filtered (_("Catchpoint %d (fork)"), b->number);
4814 /* The breakpoint_ops structure to be used in fork catchpoints. */
4816 static struct breakpoint_ops catch_fork_breakpoint_ops =
4820 breakpoint_hit_catch_fork,
4821 print_it_catch_fork,
4822 print_one_catch_fork,
4823 print_mention_catch_fork
4826 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4829 insert_catch_vfork (struct breakpoint *b)
4831 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
4834 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4837 remove_catch_vfork (struct breakpoint *b)
4839 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
4842 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4846 breakpoint_hit_catch_vfork (struct breakpoint *b)
4848 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
4851 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4853 static enum print_stop_action
4854 print_it_catch_vfork (struct breakpoint *b)
4856 annotate_catchpoint (b->number);
4857 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4858 b->number, ptid_get_pid (b->forked_inferior_pid));
4859 return PRINT_SRC_AND_LOC;
4862 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4865 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
4867 struct value_print_options opts;
4869 get_user_print_options (&opts);
4870 /* Field 4, the address, is omitted (which makes the columns
4871 not line up too nicely with the headers, but the effect
4872 is relatively readable). */
4873 if (opts.addressprint)
4874 ui_out_field_skip (uiout, "addr");
4876 ui_out_text (uiout, "vfork");
4877 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4879 ui_out_text (uiout, ", process ");
4880 ui_out_field_int (uiout, "what",
4881 ptid_get_pid (b->forked_inferior_pid));
4882 ui_out_spaces (uiout, 1);
4886 /* Implement the "print_mention" breakpoint_ops method for vfork
4890 print_mention_catch_vfork (struct breakpoint *b)
4892 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
4895 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4897 static struct breakpoint_ops catch_vfork_breakpoint_ops =
4901 breakpoint_hit_catch_vfork,
4902 print_it_catch_vfork,
4903 print_one_catch_vfork,
4904 print_mention_catch_vfork
4907 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4909 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4910 If COND_STRING is not NULL, then store it in the breakpoint.
4911 OPS, if not NULL, is the breakpoint_ops structure associated
4912 to the catchpoint. */
4914 static struct breakpoint *
4915 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
4916 char *cond_string, struct breakpoint_ops *ops)
4918 struct symtab_and_line sal;
4919 struct breakpoint *b;
4926 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
4927 set_breakpoint_count (breakpoint_count + 1);
4928 b->number = breakpoint_count;
4930 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
4932 b->addr_string = NULL;
4933 b->enable_state = bp_enabled;
4934 b->disposition = tempflag ? disp_del : disp_donttouch;
4938 update_global_location_list (1);
4944 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
4945 int tempflag, char *cond_string,
4946 struct breakpoint_ops *ops)
4948 struct breakpoint *b
4949 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
4951 /* FIXME: We should put this information in a breakpoint private data
4953 b->forked_inferior_pid = null_ptid;
4956 /* Exec catchpoints. */
4959 insert_catch_exec (struct breakpoint *b)
4961 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
4965 remove_catch_exec (struct breakpoint *b)
4967 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
4971 breakpoint_hit_catch_exec (struct breakpoint *b)
4973 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
4976 static enum print_stop_action
4977 print_it_catch_exec (struct breakpoint *b)
4979 annotate_catchpoint (b->number);
4980 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
4982 return PRINT_SRC_AND_LOC;
4986 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
4988 struct value_print_options opts;
4990 get_user_print_options (&opts);
4992 /* Field 4, the address, is omitted (which makes the columns
4993 not line up too nicely with the headers, but the effect
4994 is relatively readable). */
4995 if (opts.addressprint)
4996 ui_out_field_skip (uiout, "addr");
4998 ui_out_text (uiout, "exec");
4999 if (b->exec_pathname != NULL)
5001 ui_out_text (uiout, ", program \"");
5002 ui_out_field_string (uiout, "what", b->exec_pathname);
5003 ui_out_text (uiout, "\" ");
5008 print_mention_catch_exec (struct breakpoint *b)
5010 printf_filtered (_("Catchpoint %d (exec)"), b->number);
5013 static struct breakpoint_ops catch_exec_breakpoint_ops =
5017 breakpoint_hit_catch_exec,
5018 print_it_catch_exec,
5019 print_one_catch_exec,
5020 print_mention_catch_exec
5024 hw_breakpoint_used_count (void)
5026 struct breakpoint *b;
5031 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
5039 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
5041 struct breakpoint *b;
5044 *other_type_used = 0;
5047 if (breakpoint_enabled (b))
5049 if (b->type == type)
5051 else if ((b->type == bp_hardware_watchpoint
5052 || b->type == bp_read_watchpoint
5053 || b->type == bp_access_watchpoint))
5054 *other_type_used = 1;
5061 disable_watchpoints_before_interactive_call_start (void)
5063 struct breakpoint *b;
5067 if (((b->type == bp_watchpoint)
5068 || (b->type == bp_hardware_watchpoint)
5069 || (b->type == bp_read_watchpoint)
5070 || (b->type == bp_access_watchpoint))
5071 && breakpoint_enabled (b))
5073 b->enable_state = bp_call_disabled;
5074 update_global_location_list (0);
5080 enable_watchpoints_after_interactive_call_stop (void)
5082 struct breakpoint *b;
5086 if (((b->type == bp_watchpoint)
5087 || (b->type == bp_hardware_watchpoint)
5088 || (b->type == bp_read_watchpoint)
5089 || (b->type == bp_access_watchpoint))
5090 && (b->enable_state == bp_call_disabled))
5092 b->enable_state = bp_enabled;
5093 update_global_location_list (1);
5099 /* Set a breakpoint that will evaporate an end of command
5100 at address specified by SAL.
5101 Restrict it to frame FRAME if FRAME is nonzero. */
5104 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
5105 struct frame_id frame_id, enum bptype type)
5107 struct breakpoint *b;
5109 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5111 gdb_assert (!frame_id_inlined_p (frame_id));
5113 b = set_raw_breakpoint (gdbarch, sal, type);
5114 b->enable_state = bp_enabled;
5115 b->disposition = disp_donttouch;
5116 b->frame_id = frame_id;
5118 /* If we're debugging a multi-threaded program, then we
5119 want momentary breakpoints to be active in only a
5120 single thread of control. */
5121 if (in_thread_list (inferior_ptid))
5122 b->thread = pid_to_thread_id (inferior_ptid);
5124 update_global_location_list_nothrow (1);
5129 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5133 clone_momentary_breakpoint (struct breakpoint *orig)
5135 struct breakpoint *copy;
5137 /* If there's nothing to clone, then return nothing. */
5141 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
5142 copy->loc = allocate_bp_location (copy);
5143 set_breakpoint_location_function (copy->loc);
5145 copy->loc->gdbarch = orig->loc->gdbarch;
5146 copy->loc->requested_address = orig->loc->requested_address;
5147 copy->loc->address = orig->loc->address;
5148 copy->loc->section = orig->loc->section;
5150 if (orig->source_file == NULL)
5151 copy->source_file = NULL;
5153 copy->source_file = xstrdup (orig->source_file);
5155 copy->line_number = orig->line_number;
5156 copy->frame_id = orig->frame_id;
5157 copy->thread = orig->thread;
5159 copy->enable_state = bp_enabled;
5160 copy->disposition = disp_donttouch;
5161 copy->number = internal_breakpoint_number--;
5163 update_global_location_list_nothrow (0);
5168 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
5171 struct symtab_and_line sal;
5173 sal = find_pc_line (pc, 0);
5175 sal.section = find_pc_overlay (pc);
5176 sal.explicit_pc = 1;
5178 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
5182 /* Tell the user we have just set a breakpoint B. */
5185 mention (struct breakpoint *b)
5188 struct cleanup *ui_out_chain;
5189 struct value_print_options opts;
5191 get_user_print_options (&opts);
5193 /* FIXME: This is misplaced; mention() is called by things (like
5194 hitting a watchpoint) other than breakpoint creation. It should
5195 be possible to clean this up and at the same time replace the
5196 random calls to breakpoint_changed with this hook. */
5197 observer_notify_breakpoint_created (b->number);
5199 if (b->ops != NULL && b->ops->print_mention != NULL)
5200 b->ops->print_mention (b);
5205 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
5208 ui_out_text (uiout, "Watchpoint ");
5209 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5210 ui_out_field_int (uiout, "number", b->number);
5211 ui_out_text (uiout, ": ");
5212 ui_out_field_string (uiout, "exp", b->exp_string);
5213 do_cleanups (ui_out_chain);
5215 case bp_hardware_watchpoint:
5216 ui_out_text (uiout, "Hardware watchpoint ");
5217 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5218 ui_out_field_int (uiout, "number", b->number);
5219 ui_out_text (uiout, ": ");
5220 ui_out_field_string (uiout, "exp", b->exp_string);
5221 do_cleanups (ui_out_chain);
5223 case bp_read_watchpoint:
5224 ui_out_text (uiout, "Hardware read watchpoint ");
5225 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
5226 ui_out_field_int (uiout, "number", b->number);
5227 ui_out_text (uiout, ": ");
5228 ui_out_field_string (uiout, "exp", b->exp_string);
5229 do_cleanups (ui_out_chain);
5231 case bp_access_watchpoint:
5232 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
5233 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
5234 ui_out_field_int (uiout, "number", b->number);
5235 ui_out_text (uiout, ": ");
5236 ui_out_field_string (uiout, "exp", b->exp_string);
5237 do_cleanups (ui_out_chain);
5240 if (ui_out_is_mi_like_p (uiout))
5245 if (b->disposition == disp_del)
5246 printf_filtered (_("Temporary breakpoint"));
5248 printf_filtered (_("Breakpoint"));
5249 printf_filtered (_(" %d"), b->number);
5252 case bp_hardware_breakpoint:
5253 if (ui_out_is_mi_like_p (uiout))
5258 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
5262 if (ui_out_is_mi_like_p (uiout))
5267 printf_filtered (_("Tracepoint"));
5268 printf_filtered (_(" %d"), b->number);
5275 case bp_longjmp_resume:
5276 case bp_step_resume:
5278 case bp_watchpoint_scope:
5279 case bp_shlib_event:
5280 case bp_thread_event:
5281 case bp_overlay_event:
5282 case bp_longjmp_master:
5288 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5292 printf_filtered (_(" (%s) pending."), b->addr_string);
5296 if (opts.addressprint || b->source_file == NULL)
5298 printf_filtered (" at ");
5299 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
5303 printf_filtered (": file %s, line %d.",
5304 b->source_file, b->line_number);
5308 struct bp_location *loc = b->loc;
5310 for (; loc; loc = loc->next)
5312 printf_filtered (" (%d locations)", n);
5317 if (ui_out_is_mi_like_p (uiout))
5319 printf_filtered ("\n");
5323 static struct bp_location *
5324 add_location_to_breakpoint (struct breakpoint *b,
5325 const struct symtab_and_line *sal)
5327 struct bp_location *loc, **tmp;
5329 loc = allocate_bp_location (b);
5330 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5333 loc->gdbarch = get_sal_arch (*sal);
5335 loc->gdbarch = b->gdbarch;
5336 loc->requested_address = sal->pc;
5337 loc->address = adjust_breakpoint_address (loc->gdbarch,
5338 loc->requested_address, b->type);
5339 loc->section = sal->section;
5341 set_breakpoint_location_function (loc);
5346 /* Return 1 if LOC is pointing to a permanent breakpoint,
5347 return 0 otherwise. */
5350 bp_loc_is_permanent (struct bp_location *loc)
5354 const gdb_byte *brk;
5355 gdb_byte *target_mem;
5356 struct cleanup *cleanup;
5359 gdb_assert (loc != NULL);
5361 addr = loc->address;
5362 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
5364 /* Software breakpoints unsupported? */
5368 target_mem = alloca (len);
5370 /* Enable the automatic memory restoration from breakpoints while
5371 we read the memory. Otherwise we could say about our temporary
5372 breakpoints they are permanent. */
5373 cleanup = make_show_memory_breakpoints_cleanup (0);
5375 if (target_read_memory (loc->address, target_mem, len) == 0
5376 && memcmp (target_mem, brk, len) == 0)
5379 do_cleanups (cleanup);
5386 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5387 as textual description of the location, and COND_STRING
5388 as condition expression. */
5391 create_breakpoint (struct gdbarch *gdbarch,
5392 struct symtabs_and_lines sals, char *addr_string,
5394 enum bptype type, enum bpdisp disposition,
5395 int thread, int task, int ignore_count,
5396 struct breakpoint_ops *ops, int from_tty, int enabled)
5398 struct breakpoint *b = NULL;
5401 if (type == bp_hardware_breakpoint)
5403 int i = hw_breakpoint_used_count ();
5404 int target_resources_ok =
5405 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
5407 if (target_resources_ok == 0)
5408 error (_("No hardware breakpoint support in the target."));
5409 else if (target_resources_ok < 0)
5410 error (_("Hardware breakpoints used exceeds limit."));
5413 for (i = 0; i < sals.nelts; ++i)
5415 struct symtab_and_line sal = sals.sals[i];
5416 struct bp_location *loc;
5420 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
5422 loc_gdbarch = gdbarch;
5424 describe_other_breakpoints (loc_gdbarch,
5425 sal.pc, sal.section, thread);
5430 b = set_raw_breakpoint (gdbarch, sal, type);
5431 set_breakpoint_count (breakpoint_count + 1);
5432 b->number = breakpoint_count;
5436 b->cond_string = cond_string;
5437 b->ignore_count = ignore_count;
5438 b->enable_state = enabled ? bp_enabled : bp_disabled;
5439 b->disposition = disposition;
5445 loc = add_location_to_breakpoint (b, &sal);
5448 if (bp_loc_is_permanent (loc))
5449 make_breakpoint_permanent (b);
5453 char *arg = b->cond_string;
5454 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5456 error (_("Garbage %s follows condition"), arg);
5461 b->addr_string = addr_string;
5463 /* addr_string has to be used or breakpoint_re_set will delete
5466 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5472 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5473 elements to fill the void space. */
5475 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5477 int i = index_to_remove+1;
5478 int last_index = sal->nelts-1;
5480 for (;i <= last_index; ++i)
5481 sal->sals[i-1] = sal->sals[i];
5486 /* If appropriate, obtains all sals that correspond
5487 to the same file and line as SAL. This is done
5488 only if SAL does not have explicit PC and has
5489 line and file information. If we got just a single
5490 expanded sal, return the original.
5492 Otherwise, if SAL.explicit_line is not set, filter out
5493 all sals for which the name of enclosing function
5494 is different from SAL. This makes sure that if we have
5495 breakpoint originally set in template instantiation, say
5496 foo<int>(), we won't expand SAL to locations at the same
5497 line in all existing instantiations of 'foo'.
5500 static struct symtabs_and_lines
5501 expand_line_sal_maybe (struct symtab_and_line sal)
5503 struct symtabs_and_lines expanded;
5504 CORE_ADDR original_pc = sal.pc;
5505 char *original_function = NULL;
5509 /* If we have explicit pc, don't expand.
5510 If we have no line number, we can't expand. */
5511 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5514 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5515 expanded.sals[0] = sal;
5520 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5522 expanded = expand_line_sal (sal);
5523 if (expanded.nelts == 1)
5525 /* We had one sal, we got one sal. Without futher
5526 processing, just return the original sal. */
5527 xfree (expanded.sals);
5529 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5530 sal.pc = original_pc;
5531 expanded.sals[0] = sal;
5535 if (!sal.explicit_line)
5537 CORE_ADDR func_addr, func_end;
5538 for (i = 0; i < expanded.nelts; ++i)
5540 CORE_ADDR pc = expanded.sals[i].pc;
5541 char *this_function;
5542 if (find_pc_partial_function (pc, &this_function,
5543 &func_addr, &func_end))
5546 && strcmp (this_function, original_function) != 0)
5548 remove_sal (&expanded, i);
5551 else if (func_addr == pc)
5553 /* We're at beginning of a function, and should
5555 struct symbol *sym = find_pc_function (pc);
5557 expanded.sals[i] = find_function_start_sal (sym, 1);
5560 /* Since find_pc_partial_function returned true,
5561 we should really always find the section here. */
5562 struct obj_section *section = find_pc_section (pc);
5565 struct gdbarch *gdbarch
5566 = get_objfile_arch (section->objfile);
5568 = gdbarch_skip_prologue (gdbarch, pc);
5577 for (i = 0; i < expanded.nelts; ++i)
5579 /* If this SAL corresponds to a breakpoint inserted using a
5580 line number, then skip the function prologue if necessary. */
5581 skip_prologue_sal (&expanded.sals[i]);
5586 if (expanded.nelts <= 1)
5588 /* This is un ugly workaround. If we get zero
5589 expanded sals then something is really wrong.
5590 Fix that by returnign the original sal. */
5591 xfree (expanded.sals);
5593 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5594 sal.pc = original_pc;
5595 expanded.sals[0] = sal;
5602 for (i = 0; i < expanded.nelts; ++i)
5603 if (expanded.sals[i].pc == original_pc)
5614 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5615 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5616 value. COND_STRING, if not NULL, specified the condition to be
5617 used for all breakpoints. Essentially the only case where
5618 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5619 function. In that case, it's still not possible to specify
5620 separate conditions for different overloaded functions, so
5621 we take just a single condition string.
5623 NOTE: If the function succeeds, the caller is expected to cleanup
5624 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5625 array contents). If the function fails (error() is called), the
5626 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5627 COND and SALS arrays and each of those arrays contents. */
5630 create_breakpoints (struct gdbarch *gdbarch,
5631 struct symtabs_and_lines sals, char **addr_string,
5633 enum bptype type, enum bpdisp disposition,
5634 int thread, int task, int ignore_count,
5635 struct breakpoint_ops *ops, int from_tty,
5639 for (i = 0; i < sals.nelts; ++i)
5641 struct symtabs_and_lines expanded =
5642 expand_line_sal_maybe (sals.sals[i]);
5644 create_breakpoint (gdbarch, expanded, addr_string[i],
5645 cond_string, type, disposition,
5646 thread, task, ignore_count, ops, from_tty, enabled);
5650 /* Parse ARG which is assumed to be a SAL specification possibly
5651 followed by conditionals. On return, SALS contains an array of SAL
5652 addresses found. ADDR_STRING contains a vector of (canonical)
5653 address strings. ARG points to the end of the SAL. */
5656 parse_breakpoint_sals (char **address,
5657 struct symtabs_and_lines *sals,
5658 char ***addr_string,
5661 char *addr_start = *address;
5662 *addr_string = NULL;
5663 /* If no arg given, or if first arg is 'if ', use the default
5665 if ((*address) == NULL
5666 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5668 if (default_breakpoint_valid)
5670 struct symtab_and_line sal;
5671 init_sal (&sal); /* initialize to zeroes */
5672 sals->sals = (struct symtab_and_line *)
5673 xmalloc (sizeof (struct symtab_and_line));
5674 sal.pc = default_breakpoint_address;
5675 sal.line = default_breakpoint_line;
5676 sal.symtab = default_breakpoint_symtab;
5677 sal.section = find_pc_overlay (sal.pc);
5679 /* "break" without arguments is equivalent to "break *PC" where PC is
5680 the default_breakpoint_address. So make sure to set
5681 sal.explicit_pc to prevent GDB from trying to expand the list of
5682 sals to include all other instances with the same symtab and line.
5684 sal.explicit_pc = 1;
5686 sals->sals[0] = sal;
5690 error (_("No default breakpoint address now."));
5694 /* Force almost all breakpoints to be in terms of the
5695 current_source_symtab (which is decode_line_1's default). This
5696 should produce the results we want almost all of the time while
5697 leaving default_breakpoint_* alone.
5698 ObjC: However, don't match an Objective-C method name which
5699 may have a '+' or '-' succeeded by a '[' */
5701 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5703 if (default_breakpoint_valid
5705 || ((strchr ("+-", (*address)[0]) != NULL)
5706 && ((*address)[1] != '['))))
5707 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5708 default_breakpoint_line, addr_string,
5711 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5712 addr_string, not_found_ptr);
5714 /* For any SAL that didn't have a canonical string, fill one in. */
5715 if (sals->nelts > 0 && *addr_string == NULL)
5716 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5717 if (addr_start != (*address))
5720 for (i = 0; i < sals->nelts; i++)
5722 /* Add the string if not present. */
5723 if ((*addr_string)[i] == NULL)
5724 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5730 /* Convert each SAL into a real PC. Verify that the PC can be
5731 inserted as a breakpoint. If it can't throw an error. */
5734 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5738 for (i = 0; i < sals->nelts; i++)
5739 resolve_sal_pc (&sals->sals[i]);
5743 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5745 struct captured_parse_breakpoint_args *args = data;
5747 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5748 args->not_found_ptr);
5751 /* Given TOK, a string specification of condition and thread, as
5752 accepted by the 'break' command, extract the condition
5753 string and thread number and set *COND_STRING and *THREAD.
5754 PC identifies the context at which the condition should be parsed.
5755 If no condition is found, *COND_STRING is set to NULL.
5756 If no thread is found, *THREAD is set to -1. */
5758 find_condition_and_thread (char *tok, CORE_ADDR pc,
5759 char **cond_string, int *thread, int *task)
5761 *cond_string = NULL;
5767 char *cond_start = NULL;
5768 char *cond_end = NULL;
5769 while (*tok == ' ' || *tok == '\t')
5774 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5777 toklen = end_tok - tok;
5779 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5781 struct expression *expr;
5783 tok = cond_start = end_tok + 1;
5784 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
5787 *cond_string = savestring (cond_start,
5788 cond_end - cond_start);
5790 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5796 *thread = strtol (tok, &tok, 0);
5798 error (_("Junk after thread keyword."));
5799 if (!valid_thread_id (*thread))
5800 error (_("Unknown thread %d."), *thread);
5802 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
5808 *task = strtol (tok, &tok, 0);
5810 error (_("Junk after task keyword."));
5811 if (!valid_task_id (*task))
5812 error (_("Unknown task %d\n"), *task);
5815 error (_("Junk at end of arguments."));
5819 /* Set a breakpoint. This function is shared between
5820 CLI and MI functions for setting a breakpoint.
5821 This function has two major modes of operations,
5822 selected by the PARSE_CONDITION_AND_THREAD parameter.
5823 If non-zero, the function will parse arg, extracting
5824 breakpoint location, address and thread. Otherwise,
5825 ARG is just the location of breakpoint, with condition
5826 and thread specified by the COND_STRING and THREAD
5830 break_command_really (struct gdbarch *gdbarch,
5831 char *arg, char *cond_string, int thread,
5832 int parse_condition_and_thread,
5833 int tempflag, int hardwareflag, int traceflag,
5835 enum auto_boolean pending_break_support,
5836 struct breakpoint_ops *ops,
5840 struct gdb_exception e;
5841 struct symtabs_and_lines sals;
5842 struct symtab_and_line pending_sal;
5845 char *addr_start = arg;
5847 struct cleanup *old_chain;
5848 struct cleanup *bkpt_chain = NULL;
5849 struct captured_parse_breakpoint_args parse_args;
5853 enum bptype type_wanted;
5860 parse_args.arg_p = &arg;
5861 parse_args.sals_p = &sals;
5862 parse_args.addr_string_p = &addr_string;
5863 parse_args.not_found_ptr = ¬_found;
5865 e = catch_exception (uiout, do_captured_parse_breakpoint,
5866 &parse_args, RETURN_MASK_ALL);
5868 /* If caller is interested in rc value from parse, set value. */
5872 throw_exception (e);
5876 case NOT_FOUND_ERROR:
5878 /* If pending breakpoint support is turned off, throw
5881 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5882 throw_exception (e);
5884 exception_print (gdb_stderr, e);
5886 /* If pending breakpoint support is auto query and the user
5887 selects no, then simply return the error code. */
5888 if (pending_break_support == AUTO_BOOLEAN_AUTO
5889 && !nquery ("Make breakpoint pending on future shared library load? "))
5892 /* At this point, either the user was queried about setting
5893 a pending breakpoint and selected yes, or pending
5894 breakpoint behavior is on and thus a pending breakpoint
5895 is defaulted on behalf of the user. */
5896 copy_arg = xstrdup (addr_start);
5897 addr_string = ©_arg;
5899 sals.sals = &pending_sal;
5904 throw_exception (e);
5911 /* Create a chain of things that always need to be cleaned up. */
5912 old_chain = make_cleanup (null_cleanup, 0);
5916 /* Make sure that all storage allocated to SALS gets freed. */
5917 make_cleanup (xfree, sals.sals);
5919 /* Cleanup the addr_string array but not its contents. */
5920 make_cleanup (xfree, addr_string);
5923 /* ----------------------------- SNIP -----------------------------
5924 Anything added to the cleanup chain beyond this point is assumed
5925 to be part of a breakpoint. If the breakpoint create succeeds
5926 then the memory is not reclaimed. */
5927 bkpt_chain = make_cleanup (null_cleanup, 0);
5929 /* Mark the contents of the addr_string for cleanup. These go on
5930 the bkpt_chain and only occur if the breakpoint create fails. */
5931 for (i = 0; i < sals.nelts; i++)
5933 if (addr_string[i] != NULL)
5934 make_cleanup (xfree, addr_string[i]);
5937 /* Resolve all line numbers to PC's and verify that the addresses
5938 are ok for the target. */
5940 breakpoint_sals_to_pc (&sals, addr_start);
5942 type_wanted = (traceflag
5944 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
5946 /* Verify that condition can be parsed, before setting any
5947 breakpoints. Allocate a separate condition expression for each
5951 if (parse_condition_and_thread)
5953 /* Here we only parse 'arg' to separate condition
5954 from thread number, so parsing in context of first
5955 sal is OK. When setting the breakpoint we'll
5956 re-parse it in context of each sal. */
5959 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
5962 make_cleanup (xfree, cond_string);
5966 /* Create a private copy of condition string. */
5969 cond_string = xstrdup (cond_string);
5970 make_cleanup (xfree, cond_string);
5973 create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted,
5974 tempflag ? disp_del : disp_donttouch,
5975 thread, task, ignore_count, ops, from_tty, enabled);
5979 struct symtab_and_line sal = {0};
5980 struct breakpoint *b;
5982 make_cleanup (xfree, copy_arg);
5984 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
5985 set_breakpoint_count (breakpoint_count + 1);
5986 b->number = breakpoint_count;
5988 b->addr_string = addr_string[0];
5989 b->cond_string = NULL;
5990 b->ignore_count = ignore_count;
5991 b->disposition = tempflag ? disp_del : disp_donttouch;
5992 b->condition_not_parsed = 1;
5994 b->enable_state = enabled ? bp_enabled : bp_disabled;
6000 warning (_("Multiple breakpoints were set.\n"
6001 "Use the \"delete\" command to delete unwanted breakpoints."));
6002 /* That's it. Discard the cleanups for data inserted into the
6004 discard_cleanups (bkpt_chain);
6005 /* But cleanup everything else. */
6006 do_cleanups (old_chain);
6008 /* error call may happen here - have BKPT_CHAIN already discarded. */
6009 update_global_location_list (1);
6012 /* Set a breakpoint.
6013 ARG is a string describing breakpoint address,
6014 condition, and thread.
6015 FLAG specifies if a breakpoint is hardware on,
6016 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6020 break_command_1 (char *arg, int flag, int from_tty)
6022 int hardwareflag = flag & BP_HARDWAREFLAG;
6023 int tempflag = flag & BP_TEMPFLAG;
6025 break_command_really (get_current_arch (),
6027 NULL, 0, 1 /* parse arg */,
6028 tempflag, hardwareflag, 0 /* traceflag */,
6029 0 /* Ignore count */,
6030 pending_break_support,
6031 NULL /* breakpoint_ops */,
6038 set_breakpoint (struct gdbarch *gdbarch,
6039 char *address, char *condition,
6040 int hardwareflag, int tempflag,
6041 int thread, int ignore_count,
6042 int pending, int enabled)
6044 break_command_really (gdbarch,
6045 address, condition, thread,
6046 0 /* condition and thread are valid. */,
6047 tempflag, hardwareflag, 0 /* traceflag */,
6050 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
6054 /* Adjust SAL to the first instruction past the function prologue.
6055 The end of the prologue is determined using the line table from
6056 the debugging information. explicit_pc and explicit_line are
6059 If SAL is already past the prologue, then do nothing. */
6062 skip_prologue_sal (struct symtab_and_line *sal)
6064 struct symbol *sym = find_pc_function (sal->pc);
6065 struct symtab_and_line start_sal;
6070 start_sal = find_function_start_sal (sym, 1);
6071 if (sal->pc < start_sal.pc)
6073 start_sal.explicit_line = sal->explicit_line;
6074 start_sal.explicit_pc = sal->explicit_pc;
6079 /* Helper function for break_command_1 and disassemble_command. */
6082 resolve_sal_pc (struct symtab_and_line *sal)
6086 if (sal->pc == 0 && sal->symtab != NULL)
6088 if (!find_line_pc (sal->symtab, sal->line, &pc))
6089 error (_("No line %d in file \"%s\"."),
6090 sal->line, sal->symtab->filename);
6093 /* If this SAL corresponds to a breakpoint inserted using
6094 a line number, then skip the function prologue if necessary. */
6095 if (sal->explicit_line)
6097 /* Preserve the original line number. */
6098 int saved_line = sal->line;
6099 skip_prologue_sal (sal);
6100 sal->line = saved_line;
6104 if (sal->section == 0 && sal->symtab != NULL)
6106 struct blockvector *bv;
6110 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
6113 sym = block_linkage_function (b);
6116 fixup_symbol_section (sym, sal->symtab->objfile);
6117 sal->section = SYMBOL_OBJ_SECTION (sym);
6121 /* It really is worthwhile to have the section, so we'll just
6122 have to look harder. This case can be executed if we have
6123 line numbers but no functions (as can happen in assembly
6126 struct minimal_symbol *msym;
6128 msym = lookup_minimal_symbol_by_pc (sal->pc);
6130 sal->section = SYMBOL_OBJ_SECTION (msym);
6137 break_command (char *arg, int from_tty)
6139 break_command_1 (arg, 0, from_tty);
6143 tbreak_command (char *arg, int from_tty)
6145 break_command_1 (arg, BP_TEMPFLAG, from_tty);
6149 hbreak_command (char *arg, int from_tty)
6151 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
6155 thbreak_command (char *arg, int from_tty)
6157 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
6161 stop_command (char *arg, int from_tty)
6163 printf_filtered (_("Specify the type of breakpoint to set.\n\
6164 Usage: stop in <function | address>\n\
6165 stop at <line>\n"));
6169 stopin_command (char *arg, int from_tty)
6173 if (arg == (char *) NULL)
6175 else if (*arg != '*')
6180 /* look for a ':'. If this is a line number specification, then
6181 say it is bad, otherwise, it should be an address or
6182 function/method name */
6183 while (*argptr && !hasColon)
6185 hasColon = (*argptr == ':');
6190 badInput = (*argptr != ':'); /* Not a class::method */
6192 badInput = isdigit (*arg); /* a simple line number */
6196 printf_filtered (_("Usage: stop in <function | address>\n"));
6198 break_command_1 (arg, 0, from_tty);
6202 stopat_command (char *arg, int from_tty)
6206 if (arg == (char *) NULL || *arg == '*') /* no line number */
6213 /* look for a ':'. If there is a '::' then get out, otherwise
6214 it is probably a line number. */
6215 while (*argptr && !hasColon)
6217 hasColon = (*argptr == ':');
6222 badInput = (*argptr == ':'); /* we have class::method */
6224 badInput = !isdigit (*arg); /* not a line number */
6228 printf_filtered (_("Usage: stop at <line>\n"));
6230 break_command_1 (arg, 0, from_tty);
6233 /* accessflag: hw_write: watch write,
6234 hw_read: watch read,
6235 hw_access: watch access (read or write) */
6237 watch_command_1 (char *arg, int accessflag, int from_tty)
6239 struct gdbarch *gdbarch = get_current_arch ();
6240 struct breakpoint *b, *scope_breakpoint = NULL;
6241 struct symtab_and_line sal;
6242 struct expression *exp;
6243 struct block *exp_valid_block;
6244 struct value *val, *mark;
6245 struct frame_info *frame;
6246 char *exp_start = NULL;
6247 char *exp_end = NULL;
6248 char *tok, *id_tok_start, *end_tok;
6250 char *cond_start = NULL;
6251 char *cond_end = NULL;
6252 struct expression *cond = NULL;
6253 int i, other_type_used, target_resources_ok = 0;
6254 enum bptype bp_type;
6258 init_sal (&sal); /* initialize to zeroes */
6260 /* Make sure that we actually have parameters to parse. */
6261 if (arg != NULL && arg[0] != '\0')
6263 toklen = strlen (arg); /* Size of argument list. */
6265 /* Points tok to the end of the argument list. */
6266 tok = arg + toklen - 1;
6268 /* Go backwards in the parameters list. Skip the last parameter.
6269 If we're expecting a 'thread <thread_num>' parameter, this should
6270 be the thread identifier. */
6271 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6273 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6276 /* Points end_tok to the beginning of the last token. */
6277 id_tok_start = tok + 1;
6279 /* Go backwards in the parameters list. Skip one more parameter.
6280 If we're expecting a 'thread <thread_num>' parameter, we should
6281 reach a "thread" token. */
6282 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6287 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6290 /* Move the pointer forward to skip the whitespace and
6291 calculate the length of the token. */
6293 toklen = end_tok - tok;
6295 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
6297 /* At this point we've found a "thread" token, which means
6298 the user is trying to set a watchpoint that triggers
6299 only in a specific thread. */
6302 /* Extract the thread ID from the next token. */
6303 thread = strtol (id_tok_start, &endp, 0);
6305 /* Check if the user provided a valid numeric value for the
6307 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
6308 error (_("Invalid thread ID specification %s."), id_tok_start);
6310 /* Check if the thread actually exists. */
6311 if (!valid_thread_id (thread))
6312 error (_("Unknown thread %d."), thread);
6314 /* Truncate the string and get rid of the thread <thread_num>
6315 parameter before the parameter list is parsed by the
6316 evaluate_expression() function. */
6321 /* Parse the rest of the arguments. */
6322 innermost_block = NULL;
6324 exp = parse_exp_1 (&arg, 0, 0);
6326 /* Remove trailing whitespace from the expression before saving it.
6327 This makes the eventual display of the expression string a bit
6329 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
6332 exp_valid_block = innermost_block;
6333 mark = value_mark ();
6334 fetch_watchpoint_value (exp, &val, NULL, NULL);
6336 release_value (val);
6339 while (*tok == ' ' || *tok == '\t')
6343 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6346 toklen = end_tok - tok;
6347 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6349 tok = cond_start = end_tok + 1;
6350 cond = parse_exp_1 (&tok, 0, 0);
6354 error (_("Junk at end of command."));
6356 if (accessflag == hw_read)
6357 bp_type = bp_read_watchpoint;
6358 else if (accessflag == hw_access)
6359 bp_type = bp_access_watchpoint;
6361 bp_type = bp_hardware_watchpoint;
6363 mem_cnt = can_use_hardware_watchpoint (val);
6364 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
6365 error (_("Expression cannot be implemented with read/access watchpoint."));
6368 i = hw_watchpoint_used_count (bp_type, &other_type_used);
6369 target_resources_ok =
6370 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
6372 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
6373 error (_("Target does not support this type of hardware watchpoint."));
6375 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
6376 error (_("Target can only support one kind of HW watchpoint at a time."));
6379 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6380 watchpoint could not be set. */
6381 if (!mem_cnt || target_resources_ok <= 0)
6382 bp_type = bp_watchpoint;
6384 frame = block_innermost_frame (exp_valid_block);
6386 /* If the expression is "local", then set up a "watchpoint scope"
6387 breakpoint at the point where we've left the scope of the watchpoint
6388 expression. Create the scope breakpoint before the watchpoint, so
6389 that we will encounter it first in bpstat_stop_status. */
6390 if (innermost_block && frame)
6392 if (frame_id_p (frame_unwind_caller_id (frame)))
6395 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
6396 frame_unwind_caller_pc (frame),
6397 bp_watchpoint_scope);
6399 scope_breakpoint->enable_state = bp_enabled;
6401 /* Automatically delete the breakpoint when it hits. */
6402 scope_breakpoint->disposition = disp_del;
6404 /* Only break in the proper frame (help with recursion). */
6405 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
6407 /* Set the address at which we will stop. */
6408 scope_breakpoint->loc->gdbarch
6409 = frame_unwind_caller_arch (frame);
6410 scope_breakpoint->loc->requested_address
6411 = frame_unwind_caller_pc (frame);
6412 scope_breakpoint->loc->address
6413 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
6414 scope_breakpoint->loc->requested_address,
6415 scope_breakpoint->type);
6419 /* Now set up the breakpoint. */
6420 b = set_raw_breakpoint (gdbarch, sal, bp_type);
6421 set_breakpoint_count (breakpoint_count + 1);
6422 b->number = breakpoint_count;
6424 b->disposition = disp_donttouch;
6426 b->exp_valid_block = exp_valid_block;
6427 b->exp_string = savestring (exp_start, exp_end - exp_start);
6430 b->loc->cond = cond;
6432 b->cond_string = savestring (cond_start, cond_end - cond_start);
6437 b->watchpoint_frame = get_frame_id (frame);
6439 b->watchpoint_frame = null_frame_id;
6441 if (scope_breakpoint != NULL)
6443 /* The scope breakpoint is related to the watchpoint. We will
6444 need to act on them together. */
6445 b->related_breakpoint = scope_breakpoint;
6446 scope_breakpoint->related_breakpoint = b;
6449 value_free_to_mark (mark);
6451 update_global_location_list (1);
6454 /* Return count of locations need to be watched and can be handled
6455 in hardware. If the watchpoint can not be handled
6456 in hardware return zero. */
6459 can_use_hardware_watchpoint (struct value *v)
6461 int found_memory_cnt = 0;
6462 struct value *head = v;
6464 /* Did the user specifically forbid us to use hardware watchpoints? */
6465 if (!can_use_hw_watchpoints)
6468 /* Make sure that the value of the expression depends only upon
6469 memory contents, and values computed from them within GDB. If we
6470 find any register references or function calls, we can't use a
6471 hardware watchpoint.
6473 The idea here is that evaluating an expression generates a series
6474 of values, one holding the value of every subexpression. (The
6475 expression a*b+c has five subexpressions: a, b, a*b, c, and
6476 a*b+c.) GDB's values hold almost enough information to establish
6477 the criteria given above --- they identify memory lvalues,
6478 register lvalues, computed values, etcetera. So we can evaluate
6479 the expression, and then scan the chain of values that leaves
6480 behind to decide whether we can detect any possible change to the
6481 expression's final value using only hardware watchpoints.
6483 However, I don't think that the values returned by inferior
6484 function calls are special in any way. So this function may not
6485 notice that an expression involving an inferior function call
6486 can't be watched with hardware watchpoints. FIXME. */
6487 for (; v; v = value_next (v))
6489 if (VALUE_LVAL (v) == lval_memory)
6492 /* A lazy memory lvalue is one that GDB never needed to fetch;
6493 we either just used its address (e.g., `a' in `a.b') or
6494 we never needed it at all (e.g., `a' in `a,b'). */
6498 /* Ahh, memory we actually used! Check if we can cover
6499 it with hardware watchpoints. */
6500 struct type *vtype = check_typedef (value_type (v));
6502 /* We only watch structs and arrays if user asked for it
6503 explicitly, never if they just happen to appear in a
6504 middle of some value chain. */
6506 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6507 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6509 CORE_ADDR vaddr = value_address (v);
6510 int len = TYPE_LENGTH (value_type (v));
6512 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
6519 else if (VALUE_LVAL (v) != not_lval
6520 && deprecated_value_modifiable (v) == 0)
6521 return 0; /* ??? What does this represent? */
6522 else if (VALUE_LVAL (v) == lval_register)
6523 return 0; /* cannot watch a register with a HW watchpoint */
6526 /* The expression itself looks suitable for using a hardware
6527 watchpoint, but give the target machine a chance to reject it. */
6528 return found_memory_cnt;
6532 watch_command_wrapper (char *arg, int from_tty)
6534 watch_command (arg, from_tty);
6538 watch_command (char *arg, int from_tty)
6540 watch_command_1 (arg, hw_write, from_tty);
6544 rwatch_command_wrapper (char *arg, int from_tty)
6546 rwatch_command (arg, from_tty);
6550 rwatch_command (char *arg, int from_tty)
6552 watch_command_1 (arg, hw_read, from_tty);
6556 awatch_command_wrapper (char *arg, int from_tty)
6558 awatch_command (arg, from_tty);
6562 awatch_command (char *arg, int from_tty)
6564 watch_command_1 (arg, hw_access, from_tty);
6568 /* Helper routines for the until_command routine in infcmd.c. Here
6569 because it uses the mechanisms of breakpoints. */
6571 struct until_break_command_continuation_args
6573 struct breakpoint *breakpoint;
6574 struct breakpoint *breakpoint2;
6577 /* This function is called by fetch_inferior_event via the
6578 cmd_continuation pointer, to complete the until command. It takes
6579 care of cleaning up the temporary breakpoints set up by the until
6582 until_break_command_continuation (void *arg)
6584 struct until_break_command_continuation_args *a = arg;
6586 delete_breakpoint (a->breakpoint);
6588 delete_breakpoint (a->breakpoint2);
6592 until_break_command (char *arg, int from_tty, int anywhere)
6594 struct symtabs_and_lines sals;
6595 struct symtab_and_line sal;
6596 struct frame_info *frame = get_selected_frame (NULL);
6597 struct breakpoint *breakpoint;
6598 struct breakpoint *breakpoint2 = NULL;
6599 struct cleanup *old_chain;
6601 clear_proceed_status ();
6603 /* Set a breakpoint where the user wants it and at return from
6606 if (default_breakpoint_valid)
6607 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6608 default_breakpoint_line, (char ***) NULL, NULL);
6610 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6611 0, (char ***) NULL, NULL);
6613 if (sals.nelts != 1)
6614 error (_("Couldn't get information on specified line."));
6617 xfree (sals.sals); /* malloc'd, so freed */
6620 error (_("Junk at end of arguments."));
6622 resolve_sal_pc (&sal);
6625 /* If the user told us to continue until a specified location,
6626 we don't specify a frame at which we need to stop. */
6627 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
6628 null_frame_id, bp_until);
6630 /* Otherwise, specify the selected frame, because we want to stop only
6631 at the very same frame. */
6632 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
6633 get_stack_frame_id (frame),
6636 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6638 /* Keep within the current frame, or in frames called by the current
6641 if (frame_id_p (frame_unwind_caller_id (frame)))
6643 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
6644 sal.pc = frame_unwind_caller_pc (frame);
6645 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
6647 frame_unwind_caller_id (frame),
6649 make_cleanup_delete_breakpoint (breakpoint2);
6652 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6654 /* If we are running asynchronously, and proceed call above has actually
6655 managed to start the target, arrange for breakpoints to be
6656 deleted when the target stops. Otherwise, we're already stopped and
6657 delete breakpoints via cleanup chain. */
6659 if (target_can_async_p () && is_running (inferior_ptid))
6661 struct until_break_command_continuation_args *args;
6662 args = xmalloc (sizeof (*args));
6664 args->breakpoint = breakpoint;
6665 args->breakpoint2 = breakpoint2;
6667 discard_cleanups (old_chain);
6668 add_continuation (inferior_thread (),
6669 until_break_command_continuation, args,
6673 do_cleanups (old_chain);
6677 ep_skip_leading_whitespace (char **s)
6679 if ((s == NULL) || (*s == NULL))
6681 while (isspace (**s))
6685 /* This function attempts to parse an optional "if <cond>" clause
6686 from the arg string. If one is not found, it returns NULL.
6688 Else, it returns a pointer to the condition string. (It does not
6689 attempt to evaluate the string against a particular block.) And,
6690 it updates arg to point to the first character following the parsed
6691 if clause in the arg string. */
6694 ep_parse_optional_if_clause (char **arg)
6698 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6701 /* Skip the "if" keyword. */
6704 /* Skip any extra leading whitespace, and record the start of the
6705 condition string. */
6706 ep_skip_leading_whitespace (arg);
6709 /* Assume that the condition occupies the remainder of the arg string. */
6710 (*arg) += strlen (cond_string);
6715 /* This function attempts to parse an optional filename from the arg
6716 string. If one is not found, it returns NULL.
6718 Else, it returns a pointer to the parsed filename. (This function
6719 makes no attempt to verify that a file of that name exists, or is
6720 accessible.) And, it updates arg to point to the first character
6721 following the parsed filename in the arg string.
6723 Note that clients needing to preserve the returned filename for
6724 future access should copy it to their own buffers. */
6726 ep_parse_optional_filename (char **arg)
6728 static char filename[1024];
6733 if ((*arg_p == '\0') || isspace (*arg_p))
6751 /* Commands to deal with catching events, such as signals, exceptions,
6752 process start/exit, etc. */
6756 catch_fork_temporary, catch_vfork_temporary,
6757 catch_fork_permanent, catch_vfork_permanent
6762 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6764 struct gdbarch *gdbarch = get_current_arch ();
6765 char *cond_string = NULL;
6766 catch_fork_kind fork_kind;
6769 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
6770 tempflag = (fork_kind == catch_fork_temporary
6771 || fork_kind == catch_vfork_temporary);
6775 ep_skip_leading_whitespace (&arg);
6777 /* The allowed syntax is:
6779 catch [v]fork if <cond>
6781 First, check if there's an if clause. */
6782 cond_string = ep_parse_optional_if_clause (&arg);
6784 if ((*arg != '\0') && !isspace (*arg))
6785 error (_("Junk at end of arguments."));
6787 /* If this target supports it, create a fork or vfork catchpoint
6788 and enable reporting of such events. */
6791 case catch_fork_temporary:
6792 case catch_fork_permanent:
6793 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
6794 &catch_fork_breakpoint_ops);
6796 case catch_vfork_temporary:
6797 case catch_vfork_permanent:
6798 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
6799 &catch_vfork_breakpoint_ops);
6802 error (_("unsupported or unknown fork kind; cannot catch it"));
6808 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
6810 struct gdbarch *gdbarch = get_current_arch ();
6812 char *cond_string = NULL;
6814 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6818 ep_skip_leading_whitespace (&arg);
6820 /* The allowed syntax is:
6822 catch exec if <cond>
6824 First, check if there's an if clause. */
6825 cond_string = ep_parse_optional_if_clause (&arg);
6827 if ((*arg != '\0') && !isspace (*arg))
6828 error (_("Junk at end of arguments."));
6830 /* If this target supports it, create an exec catchpoint
6831 and enable reporting of such events. */
6832 create_catchpoint (gdbarch, tempflag, cond_string,
6833 &catch_exec_breakpoint_ops);
6836 static enum print_stop_action
6837 print_exception_catchpoint (struct breakpoint *b)
6839 int bp_temp, bp_throw;
6841 annotate_catchpoint (b->number);
6843 bp_throw = strstr (b->addr_string, "throw") != NULL;
6844 if (b->loc->address != b->loc->requested_address)
6845 breakpoint_adjustment_warning (b->loc->requested_address,
6848 bp_temp = b->disposition == disp_del;
6850 bp_temp ? "Temporary catchpoint "
6852 if (!ui_out_is_mi_like_p (uiout))
6853 ui_out_field_int (uiout, "bkptno", b->number);
6855 bp_throw ? " (exception thrown), "
6856 : " (exception caught), ");
6857 if (ui_out_is_mi_like_p (uiout))
6859 ui_out_field_string (uiout, "reason",
6860 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6861 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6862 ui_out_field_int (uiout, "bkptno", b->number);
6864 return PRINT_SRC_AND_LOC;
6868 print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc)
6870 struct value_print_options opts;
6871 get_user_print_options (&opts);
6872 if (opts.addressprint)
6875 if (b->loc == NULL || b->loc->shlib_disabled)
6876 ui_out_field_string (uiout, "addr", "<PENDING>");
6878 ui_out_field_core_addr (uiout, "addr",
6879 b->loc->gdbarch, b->loc->address);
6884 if (strstr (b->addr_string, "throw") != NULL)
6885 ui_out_field_string (uiout, "what", "exception throw");
6887 ui_out_field_string (uiout, "what", "exception catch");
6891 print_mention_exception_catchpoint (struct breakpoint *b)
6896 bp_temp = b->disposition == disp_del;
6897 bp_throw = strstr (b->addr_string, "throw") != NULL;
6898 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6899 : _("Catchpoint "));
6900 ui_out_field_int (uiout, "bkptno", b->number);
6901 ui_out_text (uiout, bp_throw ? _(" (throw)")
6905 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6908 NULL, /* breakpoint_hit */
6909 print_exception_catchpoint,
6910 print_one_exception_catchpoint,
6911 print_mention_exception_catchpoint
6915 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6916 enum exception_event_kind ex_event, int from_tty)
6918 char *trigger_func_name;
6920 if (ex_event == EX_EVENT_CATCH)
6921 trigger_func_name = "__cxa_begin_catch";
6923 trigger_func_name = "__cxa_throw";
6925 break_command_really (get_current_arch (),
6926 trigger_func_name, cond_string, -1,
6927 0 /* condition and thread are valid. */,
6930 AUTO_BOOLEAN_TRUE /* pending */,
6931 &gnu_v3_exception_catchpoint_ops, from_tty,
6937 /* Deal with "catch catch" and "catch throw" commands */
6940 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6941 int tempflag, int from_tty)
6943 char *cond_string = NULL;
6944 struct symtab_and_line *sal = NULL;
6948 ep_skip_leading_whitespace (&arg);
6950 cond_string = ep_parse_optional_if_clause (&arg);
6952 if ((*arg != '\0') && !isspace (*arg))
6953 error (_("Junk at end of arguments."));
6955 if (ex_event != EX_EVENT_THROW
6956 && ex_event != EX_EVENT_CATCH)
6957 error (_("Unsupported or unknown exception event; cannot catch it"));
6959 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6962 warning (_("Unsupported with this platform/compiler combination."));
6965 /* Implementation of "catch catch" command. */
6968 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
6970 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6971 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
6974 /* Implementation of "catch throw" command. */
6977 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
6979 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6980 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
6983 /* Create a breakpoint struct for Ada exception catchpoints. */
6986 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
6987 struct symtab_and_line sal,
6991 struct expression *cond,
6992 struct breakpoint_ops *ops,
6996 struct breakpoint *b;
7000 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7002 loc_gdbarch = gdbarch;
7004 describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1);
7005 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7006 version for exception catchpoints, because two catchpoints
7007 used for different exception names will use the same address.
7008 In this case, a "breakpoint ... also set at..." warning is
7009 unproductive. Besides. the warning phrasing is also a bit
7010 inapropriate, we should use the word catchpoint, and tell
7011 the user what type of catchpoint it is. The above is good
7012 enough for now, though. */
7015 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
7016 set_breakpoint_count (breakpoint_count + 1);
7018 b->enable_state = bp_enabled;
7019 b->disposition = tempflag ? disp_del : disp_donttouch;
7020 b->number = breakpoint_count;
7021 b->ignore_count = 0;
7022 b->loc->cond = cond;
7023 b->addr_string = addr_string;
7024 b->language = language_ada;
7025 b->cond_string = cond_string;
7026 b->exp_string = exp_string;
7031 update_global_location_list (1);
7034 /* Implement the "catch exception" command. */
7037 catch_ada_exception_command (char *arg, int from_tty,
7038 struct cmd_list_element *command)
7040 struct gdbarch *gdbarch = get_current_arch ();
7042 struct symtab_and_line sal;
7044 char *addr_string = NULL;
7045 char *exp_string = NULL;
7046 char *cond_string = NULL;
7047 struct expression *cond = NULL;
7048 struct breakpoint_ops *ops = NULL;
7050 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7054 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
7055 &cond_string, &cond, &ops);
7056 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
7057 cond_string, cond, ops, tempflag,
7061 /* Implement the "catch assert" command. */
7064 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
7066 struct gdbarch *gdbarch = get_current_arch ();
7068 struct symtab_and_line sal;
7069 char *addr_string = NULL;
7070 struct breakpoint_ops *ops = NULL;
7072 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7076 sal = ada_decode_assert_location (arg, &addr_string, &ops);
7077 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
7078 ops, tempflag, from_tty);
7082 catch_command (char *arg, int from_tty)
7084 error (_("Catch requires an event name."));
7089 tcatch_command (char *arg, int from_tty)
7091 error (_("Catch requires an event name."));
7094 /* Delete breakpoints by address or line. */
7097 clear_command (char *arg, int from_tty)
7099 struct breakpoint *b;
7100 VEC(breakpoint_p) *found = 0;
7103 struct symtabs_and_lines sals;
7104 struct symtab_and_line sal;
7109 sals = decode_line_spec (arg, 1);
7114 sals.sals = (struct symtab_and_line *)
7115 xmalloc (sizeof (struct symtab_and_line));
7116 make_cleanup (xfree, sals.sals);
7117 init_sal (&sal); /* initialize to zeroes */
7118 sal.line = default_breakpoint_line;
7119 sal.symtab = default_breakpoint_symtab;
7120 sal.pc = default_breakpoint_address;
7121 if (sal.symtab == 0)
7122 error (_("No source file specified."));
7130 /* We don't call resolve_sal_pc here. That's not
7131 as bad as it seems, because all existing breakpoints
7132 typically have both file/line and pc set. So, if
7133 clear is given file/line, we can match this to existing
7134 breakpoint without obtaining pc at all.
7136 We only support clearing given the address explicitly
7137 present in breakpoint table. Say, we've set breakpoint
7138 at file:line. There were several PC values for that file:line,
7139 due to optimization, all in one block.
7140 We've picked one PC value. If "clear" is issued with another
7141 PC corresponding to the same file:line, the breakpoint won't
7142 be cleared. We probably can still clear the breakpoint, but
7143 since the other PC value is never presented to user, user
7144 can only find it by guessing, and it does not seem important
7147 /* For each line spec given, delete bps which correspond
7148 to it. Do it in two passes, solely to preserve the current
7149 behavior that from_tty is forced true if we delete more than
7153 for (i = 0; i < sals.nelts; i++)
7155 /* If exact pc given, clear bpts at that pc.
7156 If line given (pc == 0), clear all bpts on specified line.
7157 If defaulting, clear all bpts on default line
7160 defaulting sal.pc != 0 tests to do
7165 1 0 <can't happen> */
7169 /* Find all matching breakpoints and add them to
7174 /* Are we going to delete b? */
7175 if (b->type != bp_none
7176 && b->type != bp_watchpoint
7177 && b->type != bp_hardware_watchpoint
7178 && b->type != bp_read_watchpoint
7179 && b->type != bp_access_watchpoint)
7181 struct bp_location *loc = b->loc;
7182 for (; loc; loc = loc->next)
7184 int pc_match = sal.pc
7185 && (loc->address == sal.pc)
7186 && (!section_is_overlay (loc->section)
7187 || loc->section == sal.section);
7188 int line_match = ((default_match || (0 == sal.pc))
7189 && b->source_file != NULL
7190 && sal.symtab != NULL
7191 && strcmp (b->source_file, sal.symtab->filename) == 0
7192 && b->line_number == sal.line);
7193 if (pc_match || line_match)
7202 VEC_safe_push(breakpoint_p, found, b);
7205 /* Now go thru the 'found' chain and delete them. */
7206 if (VEC_empty(breakpoint_p, found))
7209 error (_("No breakpoint at %s."), arg);
7211 error (_("No breakpoint at this line."));
7214 if (VEC_length(breakpoint_p, found) > 1)
7215 from_tty = 1; /* Always report if deleted more than one */
7218 if (VEC_length(breakpoint_p, found) == 1)
7219 printf_unfiltered (_("Deleted breakpoint "));
7221 printf_unfiltered (_("Deleted breakpoints "));
7223 breakpoints_changed ();
7225 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
7228 printf_unfiltered ("%d ", b->number);
7229 delete_breakpoint (b);
7232 putchar_unfiltered ('\n');
7235 /* Delete breakpoint in BS if they are `delete' breakpoints and
7236 all breakpoints that are marked for deletion, whether hit or not.
7237 This is called after any breakpoint is hit, or after errors. */
7240 breakpoint_auto_delete (bpstat bs)
7242 struct breakpoint *b, *temp;
7244 for (; bs; bs = bs->next)
7245 if (bs->breakpoint_at
7246 && bs->breakpoint_at->owner
7247 && bs->breakpoint_at->owner->disposition == disp_del
7249 delete_breakpoint (bs->breakpoint_at->owner);
7251 ALL_BREAKPOINTS_SAFE (b, temp)
7253 if (b->disposition == disp_del_at_next_stop)
7254 delete_breakpoint (b);
7258 /* A cleanup function which destroys a vector. */
7261 do_vec_free (void *p)
7263 VEC(bp_location_p) **vec = p;
7265 VEC_free (bp_location_p, *vec);
7268 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7269 into the inferior, only remove already-inserted locations that no
7270 longer should be inserted. Functions that delete a breakpoint or
7271 breakpoints should pass false, so that deleting a breakpoint
7272 doesn't have the side effect of inserting the locations of other
7273 breakpoints that are marked not-inserted, but should_be_inserted
7274 returns true on them.
7276 This behaviour is useful is situations close to tear-down -- e.g.,
7277 after an exec, while the target still has execution, but breakpoint
7278 shadows of the previous executable image should *NOT* be restored
7279 to the new image; or before detaching, where the target still has
7280 execution and wants to delete breakpoints from GDB's lists, and all
7281 breakpoints had already been removed from the inferior. */
7284 update_global_location_list (int should_insert)
7286 struct breakpoint *b;
7287 struct bp_location **next = &bp_location_chain;
7288 struct bp_location *loc;
7289 struct bp_location *loc2;
7290 VEC(bp_location_p) *old_locations = NULL;
7293 struct cleanup *cleanups;
7295 cleanups = make_cleanup (do_vec_free, &old_locations);
7296 /* Store old locations for future reference. */
7297 for (loc = bp_location_chain; loc; loc = loc->global_next)
7298 VEC_safe_push (bp_location_p, old_locations, loc);
7300 bp_location_chain = NULL;
7303 for (loc = b->loc; loc; loc = loc->next)
7306 next = &(loc->global_next);
7311 /* Identify bp_location instances that are no longer present in the new
7312 list, and therefore should be freed. Note that it's not necessary that
7313 those locations should be removed from inferior -- if there's another
7314 location at the same address (previously marked as duplicate),
7315 we don't need to remove/insert the location. */
7316 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7318 /* Tells if 'loc' is found amoung the new locations. If not, we
7320 int found_object = 0;
7321 /* Tells if the location should remain inserted in the target. */
7322 int keep_in_target = 0;
7324 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7331 /* If this location is no longer present, and inserted, look if there's
7332 maybe a new location at the same address. If so, mark that one
7333 inserted, and don't remove this one. This is needed so that we
7334 don't have a time window where a breakpoint at certain location is not
7339 /* If the location is inserted now, we might have to remove it. */
7341 if (found_object && should_be_inserted (loc))
7343 /* The location is still present in the location list, and still
7344 should be inserted. Don't do anything. */
7349 /* The location is either no longer present, or got disabled.
7350 See if there's another location at the same address, in which
7351 case we don't need to remove this one from the target. */
7352 if (breakpoint_address_is_meaningful (loc->owner))
7353 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7355 /* For the sake of should_insert_location. The
7356 call to check_duplicates will fix up this later. */
7357 loc2->duplicate = 0;
7358 if (should_be_inserted (loc2)
7359 && loc2 != loc && loc2->address == loc->address)
7362 loc2->target_info = loc->target_info;
7369 if (!keep_in_target)
7371 if (remove_breakpoint (loc, mark_uninserted))
7373 /* This is just about all we can do. We could keep this
7374 location on the global list, and try to remove it next
7375 time, but there's no particular reason why we will
7378 Note that at this point, loc->owner is still valid,
7379 as delete_breakpoint frees the breakpoint only
7380 after calling us. */
7381 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7382 loc->owner->number);
7390 if (removed && non_stop)
7392 /* This location was removed from the targets. In non-stop mode,
7393 a race condition is possible where we've removed a breakpoint,
7394 but stop events for that breakpoint are already queued and will
7395 arrive later. To suppress spurious SIGTRAPs reported to user,
7396 we keep this breakpoint location for a bit, and will retire it
7397 after we see 3 * thread_count events.
7398 The theory here is that reporting of events should,
7399 "on the average", be fair, so after that many event we'll see
7400 events from all threads that have anything of interest, and no
7401 longer need to keep this breakpoint. This is just a
7402 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7403 which is usability issue, but not a correctness problem. */
7404 loc->events_till_retirement = 3 * (thread_count () + 1);
7407 VEC_safe_push (bp_location_p, moribund_locations, loc);
7410 free_bp_location (loc);
7416 check_duplicates (b);
7419 if (breakpoints_always_inserted_mode () && should_insert
7420 && (have_live_inferiors ()
7421 || (gdbarch_has_global_breakpoints (target_gdbarch))))
7422 insert_breakpoint_locations ();
7424 do_cleanups (cleanups);
7428 breakpoint_retire_moribund (void)
7430 struct bp_location *loc;
7433 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
7434 if (--(loc->events_till_retirement) == 0)
7436 free_bp_location (loc);
7437 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
7443 update_global_location_list_nothrow (int inserting)
7445 struct gdb_exception e;
7446 TRY_CATCH (e, RETURN_MASK_ERROR)
7447 update_global_location_list (inserting);
7450 /* Clear BPT from a BPS. */
7452 bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
7455 for (bs = bps; bs; bs = bs->next)
7456 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7458 bs->breakpoint_at = NULL;
7460 /* bs->commands will be freed later. */
7464 /* Callback for iterate_over_threads. */
7466 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
7468 struct breakpoint *bpt = data;
7469 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
7473 /* Delete a breakpoint and clean up all traces of it in the data
7477 delete_breakpoint (struct breakpoint *bpt)
7479 struct breakpoint *b;
7480 struct bp_location *loc, *next;
7482 gdb_assert (bpt != NULL);
7484 /* Has this bp already been deleted? This can happen because multiple
7485 lists can hold pointers to bp's. bpstat lists are especial culprits.
7487 One example of this happening is a watchpoint's scope bp. When the
7488 scope bp triggers, we notice that the watchpoint is out of scope, and
7489 delete it. We also delete its scope bp. But the scope bp is marked
7490 "auto-deleting", and is already on a bpstat. That bpstat is then
7491 checked for auto-deleting bp's, which are deleted.
7493 A real solution to this problem might involve reference counts in bp's,
7494 and/or giving them pointers back to their referencing bpstat's, and
7495 teaching delete_breakpoint to only free a bp's storage when no more
7496 references were extent. A cheaper bandaid was chosen. */
7497 if (bpt->type == bp_none)
7500 observer_notify_breakpoint_deleted (bpt->number);
7502 if (breakpoint_chain == bpt)
7503 breakpoint_chain = bpt->next;
7508 b->next = bpt->next;
7512 free_command_lines (&bpt->commands);
7513 if (bpt->cond_string != NULL)
7514 xfree (bpt->cond_string);
7515 if (bpt->addr_string != NULL)
7516 xfree (bpt->addr_string);
7517 if (bpt->exp != NULL)
7519 if (bpt->exp_string != NULL)
7520 xfree (bpt->exp_string);
7521 if (bpt->val != NULL)
7522 value_free (bpt->val);
7523 if (bpt->source_file != NULL)
7524 xfree (bpt->source_file);
7525 if (bpt->exec_pathname != NULL)
7526 xfree (bpt->exec_pathname);
7528 /* Be sure no bpstat's are pointing at it after it's been freed. */
7529 /* FIXME, how can we find all bpstat's?
7530 We just check stop_bpstat for now. Note that we cannot just
7531 remove bpstats pointing at bpt from the stop_bpstat list
7532 entirely, as breakpoint commands are associated with the bpstat;
7533 if we remove it here, then the later call to
7534 bpstat_do_actions (&stop_bpstat);
7535 in event-top.c won't do anything, and temporary breakpoints
7536 with commands won't work. */
7538 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
7540 /* Now that breakpoint is removed from breakpoint
7541 list, update the global location list. This
7542 will remove locations that used to belong to
7543 this breakpoint. Do this before freeing
7544 the breakpoint itself, since remove_breakpoint
7545 looks at location's owner. It might be better
7546 design to have location completely self-contained,
7547 but it's not the case now. */
7548 update_global_location_list (0);
7551 /* On the chance that someone will soon try again to delete this same
7552 bp, we mark it as deleted before freeing its storage. */
7553 bpt->type = bp_none;
7559 do_delete_breakpoint_cleanup (void *b)
7561 delete_breakpoint (b);
7565 make_cleanup_delete_breakpoint (struct breakpoint *b)
7567 return make_cleanup (do_delete_breakpoint_cleanup, b);
7571 delete_command (char *arg, int from_tty)
7573 struct breakpoint *b, *temp;
7579 int breaks_to_delete = 0;
7581 /* Delete all breakpoints if no argument.
7582 Do not delete internal or call-dummy breakpoints, these
7583 have to be deleted with an explicit breakpoint number argument. */
7586 if (b->type != bp_call_dummy
7587 && b->type != bp_shlib_event
7588 && b->type != bp_thread_event
7589 && b->type != bp_overlay_event
7590 && b->type != bp_longjmp_master
7593 breaks_to_delete = 1;
7598 /* Ask user only if there are some breakpoints to delete. */
7600 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7602 ALL_BREAKPOINTS_SAFE (b, temp)
7604 if (b->type != bp_call_dummy
7605 && b->type != bp_shlib_event
7606 && b->type != bp_thread_event
7607 && b->type != bp_overlay_event
7608 && b->type != bp_longjmp_master
7610 delete_breakpoint (b);
7615 map_breakpoint_numbers (arg, delete_breakpoint);
7619 all_locations_are_pending (struct bp_location *loc)
7621 for (; loc; loc = loc->next)
7622 if (!loc->shlib_disabled)
7627 /* Subroutine of update_breakpoint_locations to simplify it.
7628 Return non-zero if multiple fns in list LOC have the same name.
7629 Null names are ignored. */
7632 ambiguous_names_p (struct bp_location *loc)
7634 struct bp_location *l;
7635 htab_t htab = htab_create_alloc (13, htab_hash_string,
7636 (int (*) (const void *, const void *)) streq,
7637 NULL, xcalloc, xfree);
7639 for (l = loc; l != NULL; l = l->next)
7642 const char *name = l->function_name;
7644 /* Allow for some names to be NULL, ignore them. */
7648 slot = (const char **) htab_find_slot (htab, (const void *) name,
7650 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7665 update_breakpoint_locations (struct breakpoint *b,
7666 struct symtabs_and_lines sals)
7670 struct bp_location *existing_locations = b->loc;
7672 /* If there's no new locations, and all existing locations
7673 are pending, don't do anything. This optimizes
7674 the common case where all locations are in the same
7675 shared library, that was unloaded. We'd like to
7676 retain the location, so that when the library
7677 is loaded again, we don't loose the enabled/disabled
7678 status of the individual locations. */
7679 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7684 for (i = 0; i < sals.nelts; ++i)
7686 struct bp_location *new_loc =
7687 add_location_to_breakpoint (b, &(sals.sals[i]));
7689 /* Reparse conditions, they might contain references to the
7691 if (b->cond_string != NULL)
7693 struct gdb_exception e;
7696 TRY_CATCH (e, RETURN_MASK_ERROR)
7698 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7703 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7704 b->number, e.message);
7705 new_loc->enabled = 0;
7709 if (b->source_file != NULL)
7710 xfree (b->source_file);
7711 if (sals.sals[i].symtab == NULL)
7712 b->source_file = NULL;
7714 b->source_file = xstrdup (sals.sals[i].symtab->filename);
7716 if (b->line_number == 0)
7717 b->line_number = sals.sals[i].line;
7720 /* Update locations of permanent breakpoints. */
7721 if (b->enable_state == bp_permanent)
7722 make_breakpoint_permanent (b);
7724 /* If possible, carry over 'disable' status from existing breakpoints. */
7726 struct bp_location *e = existing_locations;
7727 /* If there are multiple breakpoints with the same function name,
7728 e.g. for inline functions, comparing function names won't work.
7729 Instead compare pc addresses; this is just a heuristic as things
7730 may have moved, but in practice it gives the correct answer
7731 often enough until a better solution is found. */
7732 int have_ambiguous_names = ambiguous_names_p (b->loc);
7734 for (; e; e = e->next)
7736 if (!e->enabled && e->function_name)
7738 struct bp_location *l = b->loc;
7739 if (have_ambiguous_names)
7741 for (; l; l = l->next)
7742 if (e->address == l->address)
7750 for (; l; l = l->next)
7751 if (l->function_name
7752 && strcmp (e->function_name, l->function_name) == 0)
7762 update_global_location_list (1);
7766 /* Reset a breakpoint given it's struct breakpoint * BINT.
7767 The value we return ends up being the return value from catch_errors.
7768 Unused in this case. */
7771 breakpoint_re_set_one (void *bint)
7773 /* get past catch_errs */
7774 struct breakpoint *b = (struct breakpoint *) bint;
7778 int *not_found_ptr = ¬_found;
7779 struct symtabs_and_lines sals = {};
7780 struct symtabs_and_lines expanded;
7782 enum enable_state save_enable;
7783 struct gdb_exception e;
7784 struct cleanup *cleanups;
7789 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7793 case bp_hardware_breakpoint:
7795 if (b->addr_string == NULL)
7797 /* Anything without a string can't be re-set. */
7798 delete_breakpoint (b);
7802 set_language (b->language);
7803 input_radix = b->input_radix;
7805 TRY_CATCH (e, RETURN_MASK_ERROR)
7807 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7812 int not_found_and_ok = 0;
7813 /* For pending breakpoints, it's expected that parsing
7814 will fail until the right shared library is loaded.
7815 User has already told to create pending breakpoints and
7816 don't need extra messages. If breakpoint is in bp_shlib_disabled
7817 state, then user already saw the message about that breakpoint
7818 being disabled, and don't want to see more errors. */
7820 && (b->condition_not_parsed
7821 || (b->loc && b->loc->shlib_disabled)
7822 || b->enable_state == bp_disabled))
7823 not_found_and_ok = 1;
7825 if (!not_found_and_ok)
7827 /* We surely don't want to warn about the same breakpoint
7828 10 times. One solution, implemented here, is disable
7829 the breakpoint on error. Another solution would be to
7830 have separate 'warning emitted' flag. Since this
7831 happens only when a binary has changed, I don't know
7832 which approach is better. */
7833 b->enable_state = bp_disabled;
7834 throw_exception (e);
7841 gdb_assert (sals.nelts == 1);
7842 resolve_sal_pc (&sals.sals[0]);
7843 if (b->condition_not_parsed && s && s[0])
7845 char *cond_string = 0;
7849 find_condition_and_thread (s, sals.sals[0].pc,
7850 &cond_string, &thread, &task);
7852 b->cond_string = cond_string;
7855 b->condition_not_parsed = 0;
7857 expanded = expand_line_sal_maybe (sals.sals[0]);
7858 cleanups = make_cleanup (xfree, sals.sals);
7859 update_breakpoint_locations (b, expanded);
7860 do_cleanups (cleanups);
7864 case bp_hardware_watchpoint:
7865 case bp_read_watchpoint:
7866 case bp_access_watchpoint:
7867 /* Watchpoint can be either on expression using entirely global variables,
7868 or it can be on local variables.
7870 Watchpoints of the first kind are never auto-deleted, and even persist
7871 across program restarts. Since they can use variables from shared
7872 libraries, we need to reparse expression as libraries are loaded
7875 Watchpoints on local variables can also change meaning as result
7876 of solib event. For example, if a watchpoint uses both a local and
7877 a global variables in expression, it's a local watchpoint, but
7878 unloading of a shared library will make the expression invalid.
7879 This is not a very common use case, but we still re-evaluate
7880 expression, to avoid surprises to the user.
7882 Note that for local watchpoints, we re-evaluate it only if
7883 watchpoints frame id is still valid. If it's not, it means
7884 the watchpoint is out of scope and will be deleted soon. In fact,
7885 I'm not sure we'll ever be called in this case.
7887 If a local watchpoint's frame id is still valid, then
7888 b->exp_valid_block is likewise valid, and we can safely use it.
7890 Don't do anything about disabled watchpoints, since they will
7891 be reevaluated again when enabled. */
7892 update_watchpoint (b, 1 /* reparse */);
7894 /* We needn't really do anything to reset these, since the mask
7895 that requests them is unaffected by e.g., new libraries being
7901 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7903 /* Delete overlay event and longjmp master breakpoints; they will be
7904 reset later by breakpoint_re_set. */
7905 case bp_overlay_event:
7906 case bp_longjmp_master:
7907 delete_breakpoint (b);
7910 /* This breakpoint is special, it's set up when the inferior
7911 starts and we really don't want to touch it. */
7912 case bp_shlib_event:
7914 /* Like bp_shlib_event, this breakpoint type is special.
7915 Once it is set up, we do not want to touch it. */
7916 case bp_thread_event:
7918 /* Keep temporary breakpoints, which can be encountered when we step
7919 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7920 Otherwise these should have been blown away via the cleanup chain
7921 or by breakpoint_init_inferior when we rerun the executable. */
7924 case bp_watchpoint_scope:
7926 case bp_step_resume:
7928 case bp_longjmp_resume:
7935 /* Re-set all breakpoints after symbols have been re-loaded. */
7937 breakpoint_re_set (void)
7939 struct breakpoint *b, *temp;
7940 enum language save_language;
7941 int save_input_radix;
7943 save_language = current_language->la_language;
7944 save_input_radix = input_radix;
7945 ALL_BREAKPOINTS_SAFE (b, temp)
7947 /* Format possible error msg */
7948 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7950 struct cleanup *cleanups = make_cleanup (xfree, message);
7951 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7952 do_cleanups (cleanups);
7954 set_language (save_language);
7955 input_radix = save_input_radix;
7957 create_overlay_event_breakpoint ("_ovly_debug_event");
7958 create_longjmp_master_breakpoint ("longjmp");
7959 create_longjmp_master_breakpoint ("_longjmp");
7960 create_longjmp_master_breakpoint ("siglongjmp");
7961 create_longjmp_master_breakpoint ("_siglongjmp");
7964 /* Reset the thread number of this breakpoint:
7966 - If the breakpoint is for all threads, leave it as-is.
7967 - Else, reset it to the current thread for inferior_ptid. */
7969 breakpoint_re_set_thread (struct breakpoint *b)
7971 if (b->thread != -1)
7973 if (in_thread_list (inferior_ptid))
7974 b->thread = pid_to_thread_id (inferior_ptid);
7978 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7979 If from_tty is nonzero, it prints a message to that effect,
7980 which ends with a period (no newline). */
7983 set_ignore_count (int bptnum, int count, int from_tty)
7985 struct breakpoint *b;
7991 if (b->number == bptnum)
7993 b->ignore_count = count;
7997 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7999 else if (count == 1)
8000 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8003 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8006 breakpoints_changed ();
8007 observer_notify_breakpoint_modified (b->number);
8011 error (_("No breakpoint number %d."), bptnum);
8015 make_breakpoint_silent (struct breakpoint *b)
8017 /* Silence the breakpoint. */
8021 /* Command to set ignore-count of breakpoint N to COUNT. */
8024 ignore_command (char *args, int from_tty)
8030 error_no_arg (_("a breakpoint number"));
8032 num = get_number (&p);
8034 error (_("bad breakpoint number: '%s'"), args);
8036 error (_("Second argument (specified ignore-count) is missing."));
8038 set_ignore_count (num,
8039 longest_to_int (value_as_long (parse_and_eval (p))),
8042 printf_filtered ("\n");
8045 /* Call FUNCTION on each of the breakpoints
8046 whose numbers are given in ARGS. */
8049 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
8054 struct breakpoint *b, *tmp;
8058 error_no_arg (_("one or more breakpoint numbers"));
8065 num = get_number_or_range (&p1);
8068 warning (_("bad breakpoint number at or near '%s'"), p);
8072 ALL_BREAKPOINTS_SAFE (b, tmp)
8073 if (b->number == num)
8075 struct breakpoint *related_breakpoint = b->related_breakpoint;
8078 if (related_breakpoint)
8079 function (related_breakpoint);
8083 printf_unfiltered (_("No breakpoint number %d.\n"), num);
8089 static struct bp_location *
8090 find_location_by_number (char *number)
8092 char *dot = strchr (number, '.');
8096 struct breakpoint *b;
8097 struct bp_location *loc;
8102 bp_num = get_number_or_range (&p1);
8104 error (_("Bad breakpoint number '%s'"), number);
8107 if (b->number == bp_num)
8112 if (!b || b->number != bp_num)
8113 error (_("Bad breakpoint number '%s'"), number);
8116 loc_num = get_number_or_range (&p1);
8118 error (_("Bad breakpoint location number '%s'"), number);
8122 for (;loc_num && loc; --loc_num, loc = loc->next)
8125 error (_("Bad breakpoint location number '%s'"), dot+1);
8131 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8132 If from_tty is nonzero, it prints a message to that effect,
8133 which ends with a period (no newline). */
8136 disable_breakpoint (struct breakpoint *bpt)
8138 /* Never disable a watchpoint scope breakpoint; we want to
8139 hit them when we leave scope so we can delete both the
8140 watchpoint and its scope breakpoint at that time. */
8141 if (bpt->type == bp_watchpoint_scope)
8144 /* You can't disable permanent breakpoints. */
8145 if (bpt->enable_state == bp_permanent)
8148 bpt->enable_state = bp_disabled;
8150 update_global_location_list (0);
8152 observer_notify_breakpoint_modified (bpt->number);
8156 disable_command (char *args, int from_tty)
8158 struct breakpoint *bpt;
8160 ALL_BREAKPOINTS (bpt)
8164 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8170 case bp_hardware_breakpoint:
8172 case bp_hardware_watchpoint:
8173 case bp_read_watchpoint:
8174 case bp_access_watchpoint:
8175 disable_breakpoint (bpt);
8179 else if (strchr (args, '.'))
8181 struct bp_location *loc = find_location_by_number (args);
8184 update_global_location_list (0);
8187 map_breakpoint_numbers (args, disable_breakpoint);
8191 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
8193 int target_resources_ok, other_type_used;
8196 if (bpt->type == bp_hardware_breakpoint)
8199 i = hw_breakpoint_used_count ();
8200 target_resources_ok =
8201 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8203 if (target_resources_ok == 0)
8204 error (_("No hardware breakpoint support in the target."));
8205 else if (target_resources_ok < 0)
8206 error (_("Hardware breakpoints used exceeds limit."));
8209 if (bpt->type == bp_watchpoint
8210 || bpt->type == bp_hardware_watchpoint
8211 || bpt->type == bp_read_watchpoint
8212 || bpt->type == bp_access_watchpoint)
8214 struct gdb_exception e;
8216 TRY_CATCH (e, RETURN_MASK_ALL)
8218 update_watchpoint (bpt, 1 /* reparse */);
8222 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
8228 if (bpt->enable_state != bp_permanent)
8229 bpt->enable_state = bp_enabled;
8230 bpt->disposition = disposition;
8231 update_global_location_list (1);
8232 breakpoints_changed ();
8234 observer_notify_breakpoint_modified (bpt->number);
8239 enable_breakpoint (struct breakpoint *bpt)
8241 do_enable_breakpoint (bpt, bpt->disposition);
8244 /* The enable command enables the specified breakpoints (or all defined
8245 breakpoints) so they once again become (or continue to be) effective
8246 in stopping the inferior. */
8249 enable_command (char *args, int from_tty)
8251 struct breakpoint *bpt;
8253 ALL_BREAKPOINTS (bpt)
8257 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8263 case bp_hardware_breakpoint:
8265 case bp_hardware_watchpoint:
8266 case bp_read_watchpoint:
8267 case bp_access_watchpoint:
8268 enable_breakpoint (bpt);
8272 else if (strchr (args, '.'))
8274 struct bp_location *loc = find_location_by_number (args);
8277 update_global_location_list (1);
8280 map_breakpoint_numbers (args, enable_breakpoint);
8284 enable_once_breakpoint (struct breakpoint *bpt)
8286 do_enable_breakpoint (bpt, disp_disable);
8290 enable_once_command (char *args, int from_tty)
8292 map_breakpoint_numbers (args, enable_once_breakpoint);
8296 enable_delete_breakpoint (struct breakpoint *bpt)
8298 do_enable_breakpoint (bpt, disp_del);
8302 enable_delete_command (char *args, int from_tty)
8304 map_breakpoint_numbers (args, enable_delete_breakpoint);
8308 set_breakpoint_cmd (char *args, int from_tty)
8313 show_breakpoint_cmd (char *args, int from_tty)
8317 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8319 struct symtabs_and_lines
8320 decode_line_spec_1 (char *string, int funfirstline)
8322 struct symtabs_and_lines sals;
8324 error (_("Empty line specification."));
8325 if (default_breakpoint_valid)
8326 sals = decode_line_1 (&string, funfirstline,
8327 default_breakpoint_symtab,
8328 default_breakpoint_line,
8329 (char ***) NULL, NULL);
8331 sals = decode_line_1 (&string, funfirstline,
8332 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8334 error (_("Junk at end of line specification: %s"), string);
8338 /* Create and insert a raw software breakpoint at PC. Return an
8339 identifier, which should be used to remove the breakpoint later.
8340 In general, places which call this should be using something on the
8341 breakpoint chain instead; this function should be eliminated
8345 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
8347 struct bp_target_info *bp_tgt;
8349 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8350 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8352 bp_tgt->placed_address = pc;
8353 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
8355 /* Could not insert the breakpoint. */
8363 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8366 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
8368 struct bp_target_info *bp_tgt = bp;
8371 ret = target_remove_breakpoint (gdbarch, bp_tgt);
8377 /* One (or perhaps two) breakpoints used for software single stepping. */
8379 static void *single_step_breakpoints[2];
8380 static struct gdbarch *single_step_gdbarch[2];
8382 /* Create and insert a breakpoint for software single step. */
8385 insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc)
8389 if (single_step_breakpoints[0] == NULL)
8391 bpt_p = &single_step_breakpoints[0];
8392 single_step_gdbarch[0] = gdbarch;
8396 gdb_assert (single_step_breakpoints[1] == NULL);
8397 bpt_p = &single_step_breakpoints[1];
8398 single_step_gdbarch[1] = gdbarch;
8401 /* NOTE drow/2006-04-11: A future improvement to this function would be
8402 to only create the breakpoints once, and actually put them on the
8403 breakpoint chain. That would let us use set_raw_breakpoint. We could
8404 adjust the addresses each time they were needed. Doing this requires
8405 corresponding changes elsewhere where single step breakpoints are
8406 handled, however. So, for now, we use this. */
8408 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc);
8410 error (_("Could not insert single-step breakpoint at %s"),
8411 paddress (gdbarch, next_pc));
8414 /* Remove and delete any breakpoints used for software single step. */
8417 remove_single_step_breakpoints (void)
8419 gdb_assert (single_step_breakpoints[0] != NULL);
8421 /* See insert_single_step_breakpoint for more about this deprecated
8423 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
8424 single_step_breakpoints[0]);
8425 single_step_gdbarch[0] = NULL;
8426 single_step_breakpoints[0] = NULL;
8428 if (single_step_breakpoints[1] != NULL)
8430 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
8431 single_step_breakpoints[1]);
8432 single_step_gdbarch[1] = NULL;
8433 single_step_breakpoints[1] = NULL;
8437 /* Check whether a software single-step breakpoint is inserted at PC. */
8440 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8444 for (i = 0; i < 2; i++)
8446 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8447 if (bp_tgt && bp_tgt->placed_address == pc)
8454 /* Tracepoint-specific operations. */
8456 /* Set tracepoint count to NUM. */
8458 set_tracepoint_count (int num)
8460 tracepoint_count = num;
8461 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
8465 trace_command (char *arg, int from_tty)
8467 break_command_really (get_current_arch (),
8469 NULL, 0, 1 /* parse arg */,
8470 0 /* tempflag */, 0 /* hardwareflag */,
8472 0 /* Ignore count */,
8473 pending_break_support,
8477 set_tracepoint_count (breakpoint_count);
8480 /* Print information on tracepoint number TPNUM_EXP, or all if
8484 tracepoints_info (char *tpnum_exp, int from_tty)
8486 struct breakpoint *b;
8487 int tps_to_list = 0;
8489 /* In the no-arguments case, say "No tracepoints" if none found. */
8502 ui_out_message (uiout, 0, "No tracepoints.\n");
8507 /* Otherwise be the same as "info break". */
8508 breakpoints_info (tpnum_exp, from_tty);
8511 /* The 'enable trace' command enables tracepoints.
8512 Not supported by all targets. */
8514 enable_trace_command (char *args, int from_tty)
8516 enable_command (args, from_tty);
8519 /* The 'disable trace' command disables tracepoints.
8520 Not supported by all targets. */
8522 disable_trace_command (char *args, int from_tty)
8524 disable_command (args, from_tty);
8527 /* Remove a tracepoint (or all if no argument) */
8529 delete_trace_command (char *arg, int from_tty)
8531 struct breakpoint *b, *temp;
8537 int breaks_to_delete = 0;
8539 /* Delete all breakpoints if no argument.
8540 Do not delete internal or call-dummy breakpoints, these
8541 have to be deleted with an explicit breakpoint number argument. */
8546 breaks_to_delete = 1;
8551 /* Ask user only if there are some breakpoints to delete. */
8553 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
8555 ALL_BREAKPOINTS_SAFE (b, temp)
8557 if (b->type == bp_tracepoint
8559 delete_breakpoint (b);
8564 map_breakpoint_numbers (arg, delete_breakpoint);
8567 /* Set passcount for tracepoint.
8569 First command argument is passcount, second is tracepoint number.
8570 If tracepoint number omitted, apply to most recently defined.
8571 Also accepts special argument "all". */
8574 trace_pass_command (char *args, int from_tty)
8576 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
8580 if (args == 0 || *args == 0)
8581 error (_("passcount command requires an argument (count + optional TP num)"));
8583 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
8585 while (*args && isspace ((int) *args))
8588 if (*args && strncasecmp (args, "all", 3) == 0)
8590 args += 3; /* Skip special argument "all". */
8593 error (_("Junk at end of arguments."));
8596 t1 = get_tracepoint_by_number (&args, 1, 1);
8602 ALL_TRACEPOINTS (t2)
8603 if (t1 == (struct breakpoint *) -1 || t1 == t2)
8605 t2->pass_count = count;
8606 observer_notify_tracepoint_modified (t2->number);
8608 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8612 t1 = get_tracepoint_by_number (&args, 1, 0);
8619 get_tracepoint (int num)
8621 struct breakpoint *t;
8624 if (t->number == num)
8630 /* Utility: parse a tracepoint number and look it up in the list.
8631 If MULTI_P is true, there might be a range of tracepoints in ARG.
8632 if OPTIONAL_P is true, then if the argument is missing, the most
8633 recent tracepoint (tracepoint_count) is returned. */
8635 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
8637 extern int tracepoint_count;
8638 struct breakpoint *t;
8640 char *instring = arg == NULL ? NULL : *arg;
8642 if (arg == NULL || *arg == NULL || ! **arg)
8645 tpnum = tracepoint_count;
8647 error_no_arg (_("tracepoint number"));
8650 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
8654 if (instring && *instring)
8655 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8658 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8663 if (t->number == tpnum)
8668 /* FIXME: if we are in the middle of a range we don't want to give
8669 a message. The current interface to get_number_or_range doesn't
8670 allow us to discover this. */
8671 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
8675 /* save-tracepoints command */
8677 tracepoint_save_command (char *args, int from_tty)
8679 struct breakpoint *tp;
8681 struct action_line *line;
8683 char *i1 = " ", *i2 = " ";
8684 char *indent, *actionline, *pathname;
8686 struct cleanup *cleanup;
8688 if (args == 0 || *args == 0)
8689 error (_("Argument required (file name in which to save tracepoints)"));
8691 /* See if we have anything to save. */
8692 ALL_TRACEPOINTS (tp)
8699 warning (_("save-tracepoints: no tracepoints to save."));
8703 pathname = tilde_expand (args);
8704 cleanup = make_cleanup (xfree, pathname);
8705 fp = fopen (pathname, "w");
8707 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8708 args, safe_strerror (errno));
8709 make_cleanup_fclose (fp);
8711 ALL_TRACEPOINTS (tp)
8713 if (tp->addr_string)
8714 fprintf (fp, "trace %s\n", tp->addr_string);
8717 sprintf_vma (tmp, tp->loc->address);
8718 fprintf (fp, "trace *0x%s\n", tmp);
8722 fprintf (fp, " passcount %d\n", tp->pass_count);
8726 fprintf (fp, " actions\n");
8728 for (line = tp->actions; line; line = line->next)
8730 struct cmd_list_element *cmd;
8732 QUIT; /* allow user to bail out with ^C */
8733 actionline = line->action;
8734 while (isspace ((int) *actionline))
8737 fprintf (fp, "%s%s\n", indent, actionline);
8738 if (*actionline != '#') /* skip for comment lines */
8740 cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1);
8742 error (_("Bad action list item: %s"), actionline);
8743 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
8745 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
8751 do_cleanups (cleanup);
8753 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
8757 /* Create a vector of all tracepoints. */
8762 VEC(breakpoint_p) *tp_vec = 0;
8763 struct breakpoint *tp;
8765 ALL_TRACEPOINTS (tp)
8767 VEC_safe_push (breakpoint_p, tp_vec, tp);
8774 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8775 It is defined as a macro to prevent duplication.
8776 COMMAND should be a string constant containing the name of the command. */
8777 #define BREAK_ARGS_HELP(command) \
8778 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8779 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8780 If a line number is specified, break at start of code for that line.\n\
8781 If a function is specified, break at start of code for that function.\n\
8782 If an address is specified, break at that exact address.\n\
8783 With no LOCATION, uses current execution address of selected stack frame.\n\
8784 This is useful for breaking on return to a stack frame.\n\
8786 THREADNUM is the number from \"info threads\".\n\
8787 CONDITION is a boolean expression.\n\
8789 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8791 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8793 /* List of subcommands for "catch". */
8794 static struct cmd_list_element *catch_cmdlist;
8796 /* List of subcommands for "tcatch". */
8797 static struct cmd_list_element *tcatch_cmdlist;
8799 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8800 lists, and pass some additional user data to the command function. */
8802 add_catch_command (char *name, char *docstring,
8803 void (*sfunc) (char *args, int from_tty,
8804 struct cmd_list_element *command),
8805 void *user_data_catch,
8806 void *user_data_tcatch)
8808 struct cmd_list_element *command;
8810 command = add_cmd (name, class_breakpoint, NULL, docstring,
8812 set_cmd_sfunc (command, sfunc);
8813 set_cmd_context (command, user_data_catch);
8815 command = add_cmd (name, class_breakpoint, NULL, docstring,
8817 set_cmd_sfunc (command, sfunc);
8818 set_cmd_context (command, user_data_tcatch);
8822 _initialize_breakpoint (void)
8824 static struct cmd_list_element *breakpoint_set_cmdlist;
8825 static struct cmd_list_element *breakpoint_show_cmdlist;
8826 struct cmd_list_element *c;
8828 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8830 breakpoint_chain = 0;
8831 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8832 before a breakpoint is set. */
8833 breakpoint_count = 0;
8835 tracepoint_count = 0;
8837 add_com ("ignore", class_breakpoint, ignore_command, _("\
8838 Set ignore-count of breakpoint number N to COUNT.\n\
8839 Usage is `ignore N COUNT'."));
8841 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8843 add_com ("commands", class_breakpoint, commands_command, _("\
8844 Set commands to be executed when a breakpoint is hit.\n\
8845 Give breakpoint number as argument after \"commands\".\n\
8846 With no argument, the targeted breakpoint is the last one set.\n\
8847 The commands themselves follow starting on the next line.\n\
8848 Type a line containing \"end\" to indicate the end of them.\n\
8849 Give \"silent\" as the first line to make the breakpoint silent;\n\
8850 then no output is printed when it is hit, except what the commands print."));
8852 add_com ("condition", class_breakpoint, condition_command, _("\
8853 Specify breakpoint number N to break only if COND is true.\n\
8854 Usage is `condition N COND', where N is an integer and COND is an\n\
8855 expression to be evaluated whenever breakpoint N is reached."));
8857 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8858 Set a temporary breakpoint.\n\
8859 Like \"break\" except the breakpoint is only temporary,\n\
8860 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8861 by using \"enable delete\" on the breakpoint number.\n\
8863 BREAK_ARGS_HELP ("tbreak")));
8864 set_cmd_completer (c, location_completer);
8866 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8867 Set a hardware assisted breakpoint.\n\
8868 Like \"break\" except the breakpoint requires hardware support,\n\
8869 some target hardware may not have this support.\n\
8871 BREAK_ARGS_HELP ("hbreak")));
8872 set_cmd_completer (c, location_completer);
8874 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8875 Set a temporary hardware assisted breakpoint.\n\
8876 Like \"hbreak\" except the breakpoint is only temporary,\n\
8877 so it will be deleted when hit.\n\
8879 BREAK_ARGS_HELP ("thbreak")));
8880 set_cmd_completer (c, location_completer);
8882 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8883 Enable some breakpoints.\n\
8884 Give breakpoint numbers (separated by spaces) as arguments.\n\
8885 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8886 This is used to cancel the effect of the \"disable\" command.\n\
8887 With a subcommand you can enable temporarily."),
8888 &enablelist, "enable ", 1, &cmdlist);
8890 add_com ("ab", class_breakpoint, enable_command, _("\
8891 Enable some breakpoints.\n\
8892 Give breakpoint numbers (separated by spaces) as arguments.\n\
8893 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8894 This is used to cancel the effect of the \"disable\" command.\n\
8895 With a subcommand you can enable temporarily."));
8897 add_com_alias ("en", "enable", class_breakpoint, 1);
8899 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8900 Enable some breakpoints.\n\
8901 Give breakpoint numbers (separated by spaces) as arguments.\n\
8902 This is used to cancel the effect of the \"disable\" command.\n\
8903 May be abbreviated to simply \"enable\".\n"),
8904 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8906 add_cmd ("once", no_class, enable_once_command, _("\
8907 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8908 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8911 add_cmd ("delete", no_class, enable_delete_command, _("\
8912 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8913 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8916 add_cmd ("delete", no_class, enable_delete_command, _("\
8917 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8918 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8921 add_cmd ("once", no_class, enable_once_command, _("\
8922 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8923 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8926 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8927 Disable some breakpoints.\n\
8928 Arguments are breakpoint numbers with spaces in between.\n\
8929 To disable all breakpoints, give no argument.\n\
8930 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8931 &disablelist, "disable ", 1, &cmdlist);
8932 add_com_alias ("dis", "disable", class_breakpoint, 1);
8933 add_com_alias ("disa", "disable", class_breakpoint, 1);
8935 add_com ("sb", class_breakpoint, disable_command, _("\
8936 Disable some breakpoints.\n\
8937 Arguments are breakpoint numbers with spaces in between.\n\
8938 To disable all breakpoints, give no argument.\n\
8939 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8941 add_cmd ("breakpoints", class_alias, disable_command, _("\
8942 Disable some breakpoints.\n\
8943 Arguments are breakpoint numbers with spaces in between.\n\
8944 To disable all breakpoints, give no argument.\n\
8945 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8946 This command may be abbreviated \"disable\"."),
8949 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8950 Delete some breakpoints or auto-display expressions.\n\
8951 Arguments are breakpoint numbers with spaces in between.\n\
8952 To delete all breakpoints, give no argument.\n\
8954 Also a prefix command for deletion of other GDB objects.\n\
8955 The \"unset\" command is also an alias for \"delete\"."),
8956 &deletelist, "delete ", 1, &cmdlist);
8957 add_com_alias ("d", "delete", class_breakpoint, 1);
8958 add_com_alias ("del", "delete", class_breakpoint, 1);
8960 add_com ("db", class_breakpoint, delete_command, _("\
8961 Delete some breakpoints.\n\
8962 Arguments are breakpoint numbers with spaces in between.\n\
8963 To delete all breakpoints, give no argument.\n"));
8965 add_cmd ("breakpoints", class_alias, delete_command, _("\
8966 Delete some breakpoints or auto-display expressions.\n\
8967 Arguments are breakpoint numbers with spaces in between.\n\
8968 To delete all breakpoints, give no argument.\n\
8969 This command may be abbreviated \"delete\"."),
8972 add_com ("clear", class_breakpoint, clear_command, _("\
8973 Clear breakpoint at specified line or function.\n\
8974 Argument may be line number, function name, or \"*\" and an address.\n\
8975 If line number is specified, all breakpoints in that line are cleared.\n\
8976 If function is specified, breakpoints at beginning of function are cleared.\n\
8977 If an address is specified, breakpoints at that address are cleared.\n\
8979 With no argument, clears all breakpoints in the line that the selected frame\n\
8982 See also the \"delete\" command which clears breakpoints by number."));
8984 c = add_com ("break", class_breakpoint, break_command, _("\
8985 Set breakpoint at specified line or function.\n"
8986 BREAK_ARGS_HELP ("break")));
8987 set_cmd_completer (c, location_completer);
8989 add_com_alias ("b", "break", class_run, 1);
8990 add_com_alias ("br", "break", class_run, 1);
8991 add_com_alias ("bre", "break", class_run, 1);
8992 add_com_alias ("brea", "break", class_run, 1);
8995 add_com_alias ("ba", "break", class_breakpoint, 1);
8999 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
9000 Break in function/address or break at a line in the current file."),
9001 &stoplist, "stop ", 1, &cmdlist);
9002 add_cmd ("in", class_breakpoint, stopin_command,
9003 _("Break in function or address."), &stoplist);
9004 add_cmd ("at", class_breakpoint, stopat_command,
9005 _("Break at a line in the current file."), &stoplist);
9006 add_com ("status", class_info, breakpoints_info, _("\
9007 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9008 The \"Type\" column indicates one of:\n\
9009 \tbreakpoint - normal breakpoint\n\
9010 \twatchpoint - watchpoint\n\
9011 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9012 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9013 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9014 address and file/line number respectively.\n\
9016 Convenience variable \"$_\" and default examine address for \"x\"\n\
9017 are set to the address of the last breakpoint listed unless the command\n\
9018 is prefixed with \"server \".\n\n\
9019 Convenience variable \"$bpnum\" contains the number of the last\n\
9023 add_info ("breakpoints", breakpoints_info, _("\
9024 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9025 The \"Type\" column indicates one of:\n\
9026 \tbreakpoint - normal breakpoint\n\
9027 \twatchpoint - watchpoint\n\
9028 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9029 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9030 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9031 address and file/line number respectively.\n\
9033 Convenience variable \"$_\" and default examine address for \"x\"\n\
9034 are set to the address of the last breakpoint listed unless the command\n\
9035 is prefixed with \"server \".\n\n\
9036 Convenience variable \"$bpnum\" contains the number of the last\n\
9040 add_com ("lb", class_breakpoint, breakpoints_info, _("\
9041 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9042 The \"Type\" column indicates one of:\n\
9043 \tbreakpoint - normal breakpoint\n\
9044 \twatchpoint - watchpoint\n\
9045 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9046 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9047 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9048 address and file/line number respectively.\n\
9050 Convenience variable \"$_\" and default examine address for \"x\"\n\
9051 are set to the address of the last breakpoint listed unless the command\n\
9052 is prefixed with \"server \".\n\n\
9053 Convenience variable \"$bpnum\" contains the number of the last\n\
9056 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
9057 Status of all breakpoints, or breakpoint number NUMBER.\n\
9058 The \"Type\" column indicates one of:\n\
9059 \tbreakpoint - normal breakpoint\n\
9060 \twatchpoint - watchpoint\n\
9061 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9062 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9063 \tuntil - internal breakpoint used by the \"until\" command\n\
9064 \tfinish - internal breakpoint used by the \"finish\" command\n\
9065 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9066 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9067 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9068 address and file/line number respectively.\n\
9070 Convenience variable \"$_\" and default examine address for \"x\"\n\
9071 are set to the address of the last breakpoint listed unless the command\n\
9072 is prefixed with \"server \".\n\n\
9073 Convenience variable \"$bpnum\" contains the number of the last\n\
9075 &maintenanceinfolist);
9077 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
9078 Set catchpoints to catch events."),
9079 &catch_cmdlist, "catch ",
9080 0/*allow-unknown*/, &cmdlist);
9082 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
9083 Set temporary catchpoints to catch events."),
9084 &tcatch_cmdlist, "tcatch ",
9085 0/*allow-unknown*/, &cmdlist);
9087 /* Add catch and tcatch sub-commands. */
9088 add_catch_command ("catch", _("\
9089 Catch an exception, when caught.\n\
9090 With an argument, catch only exceptions with the given name."),
9091 catch_catch_command,
9094 add_catch_command ("throw", _("\
9095 Catch an exception, when thrown.\n\
9096 With an argument, catch only exceptions with the given name."),
9097 catch_throw_command,
9100 add_catch_command ("fork", _("Catch calls to fork."),
9101 catch_fork_command_1,
9102 (void *) (uintptr_t) catch_fork_permanent,
9103 (void *) (uintptr_t) catch_fork_temporary);
9104 add_catch_command ("vfork", _("Catch calls to vfork."),
9105 catch_fork_command_1,
9106 (void *) (uintptr_t) catch_vfork_permanent,
9107 (void *) (uintptr_t) catch_vfork_temporary);
9108 add_catch_command ("exec", _("Catch calls to exec."),
9109 catch_exec_command_1,
9112 add_catch_command ("exception", _("\
9113 Catch Ada exceptions, when raised.\n\
9114 With an argument, catch only exceptions with the given name."),
9115 catch_ada_exception_command,
9118 add_catch_command ("assert", _("\
9119 Catch failed Ada assertions, when raised.\n\
9120 With an argument, catch only exceptions with the given name."),
9121 catch_assert_command,
9125 c = add_com ("watch", class_breakpoint, watch_command, _("\
9126 Set a watchpoint for an expression.\n\
9127 A watchpoint stops execution of your program whenever the value of\n\
9128 an expression changes."));
9129 set_cmd_completer (c, expression_completer);
9131 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
9132 Set a read watchpoint for an expression.\n\
9133 A watchpoint stops execution of your program whenever the value of\n\
9134 an expression is read."));
9135 set_cmd_completer (c, expression_completer);
9137 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
9138 Set a watchpoint for an expression.\n\
9139 A watchpoint stops execution of your program whenever the value of\n\
9140 an expression is either read or written."));
9141 set_cmd_completer (c, expression_completer);
9143 add_info ("watchpoints", breakpoints_info,
9144 _("Synonym for ``info breakpoints''."));
9147 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9148 respond to changes - contrary to the description. */
9149 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
9150 &can_use_hw_watchpoints, _("\
9151 Set debugger's willingness to use watchpoint hardware."), _("\
9152 Show debugger's willingness to use watchpoint hardware."), _("\
9153 If zero, gdb will not use hardware for new watchpoints, even if\n\
9154 such is available. (However, any hardware watchpoints that were\n\
9155 created before setting this to nonzero, will continue to use watchpoint\n\
9158 show_can_use_hw_watchpoints,
9159 &setlist, &showlist);
9161 can_use_hw_watchpoints = 1;
9163 /* Tracepoint manipulation commands. */
9165 c = add_com ("trace", class_breakpoint, trace_command, _("\
9166 Set a tracepoint at specified line or function.\n\
9168 BREAK_ARGS_HELP ("trace") "\n\
9169 Do \"help tracepoints\" for info on other tracepoint commands."));
9170 set_cmd_completer (c, location_completer);
9172 add_com_alias ("tp", "trace", class_alias, 0);
9173 add_com_alias ("tr", "trace", class_alias, 1);
9174 add_com_alias ("tra", "trace", class_alias, 1);
9175 add_com_alias ("trac", "trace", class_alias, 1);
9177 add_info ("tracepoints", tracepoints_info, _("\
9178 Status of tracepoints, or tracepoint number NUMBER.\n\
9179 Convenience variable \"$tpnum\" contains the number of the\n\
9180 last tracepoint set."));
9182 add_info_alias ("tp", "tracepoints", 1);
9184 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
9185 Delete specified tracepoints.\n\
9186 Arguments are tracepoint numbers, separated by spaces.\n\
9187 No argument means delete all tracepoints."),
9190 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
9191 Disable specified tracepoints.\n\
9192 Arguments are tracepoint numbers, separated by spaces.\n\
9193 No argument means disable all tracepoints."),
9195 deprecate_cmd (c, "disable");
9197 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
9198 Enable specified tracepoints.\n\
9199 Arguments are tracepoint numbers, separated by spaces.\n\
9200 No argument means enable all tracepoints."),
9202 deprecate_cmd (c, "enable");
9204 add_com ("passcount", class_trace, trace_pass_command, _("\
9205 Set the passcount for a tracepoint.\n\
9206 The trace will end when the tracepoint has been passed 'count' times.\n\
9207 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9208 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9210 c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\
9211 Save current tracepoint definitions as a script.\n\
9212 Use the 'source' command in another debug session to restore them."));
9213 set_cmd_completer (c, filename_completer);
9215 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
9216 Breakpoint specific settings\n\
9217 Configure various breakpoint-specific variables such as\n\
9218 pending breakpoint behavior"),
9219 &breakpoint_set_cmdlist, "set breakpoint ",
9220 0/*allow-unknown*/, &setlist);
9221 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
9222 Breakpoint specific settings\n\
9223 Configure various breakpoint-specific variables such as\n\
9224 pending breakpoint behavior"),
9225 &breakpoint_show_cmdlist, "show breakpoint ",
9226 0/*allow-unknown*/, &showlist);
9228 add_setshow_auto_boolean_cmd ("pending", no_class,
9229 &pending_break_support, _("\
9230 Set debugger's behavior regarding pending breakpoints."), _("\
9231 Show debugger's behavior regarding pending breakpoints."), _("\
9232 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9233 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9234 an error. If auto, an unrecognized breakpoint location results in a\n\
9235 user-query to see if a pending breakpoint should be created."),
9237 show_pending_break_support,
9238 &breakpoint_set_cmdlist,
9239 &breakpoint_show_cmdlist);
9241 pending_break_support = AUTO_BOOLEAN_AUTO;
9243 add_setshow_boolean_cmd ("auto-hw", no_class,
9244 &automatic_hardware_breakpoints, _("\
9245 Set automatic usage of hardware breakpoints."), _("\
9246 Show automatic usage of hardware breakpoints."), _("\
9247 If set, the debugger will automatically use hardware breakpoints for\n\
9248 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9249 a warning will be emitted for such breakpoints."),
9251 show_automatic_hardware_breakpoints,
9252 &breakpoint_set_cmdlist,
9253 &breakpoint_show_cmdlist);
9255 add_setshow_enum_cmd ("always-inserted", class_support,
9256 always_inserted_enums, &always_inserted_mode, _("\
9257 Set mode for inserting breakpoints."), _("\
9258 Show mode for inserting breakpoints."), _("\
9259 When this mode is off, breakpoints are inserted in inferior when it is\n\
9260 resumed, and removed when execution stops. When this mode is on,\n\
9261 breakpoints are inserted immediately and removed only when the user\n\
9262 deletes the breakpoint. When this mode is auto (which is the default),\n\
9263 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9264 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9265 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9266 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9268 &show_always_inserted_mode,
9269 &breakpoint_set_cmdlist,
9270 &breakpoint_show_cmdlist);
9272 automatic_hardware_breakpoints = 1;
9274 observer_attach_about_to_proceed (breakpoint_about_to_proceed);