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, 2010 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 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_once_command (char *, int);
84 static void disable_command (char *, int);
86 static void enable_command (char *, int);
88 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 breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
115 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
119 static void describe_other_breakpoints (struct gdbarch *,
120 struct program_space *, CORE_ADDR,
121 struct obj_section *, int);
123 static int breakpoint_address_match (struct address_space *aspace1,
125 struct address_space *aspace2,
128 static int watchpoint_locations_match (struct bp_location *loc1,
129 struct bp_location *loc2);
131 static void breakpoints_info (char *, int);
133 static void watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
137 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
147 static int get_number_trailer (char **, int);
156 static int remove_breakpoint (struct bp_location *, insertion_state_t);
157 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
159 static enum print_stop_action print_it_typical (bpstat);
161 static enum print_stop_action print_bp_stop_message (bpstat bs);
163 static int watchpoint_check (void *);
165 static void maintenance_info_breakpoints (char *, int);
167 static int hw_breakpoint_used_count (void);
169 static int hw_watchpoint_used_count (enum bptype, int *);
171 static void hbreak_command (char *, int);
173 static void thbreak_command (char *, int);
175 static void watch_command_1 (char *, int, int);
177 static void rwatch_command (char *, int);
179 static void awatch_command (char *, int);
181 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
183 static void stop_command (char *arg, int from_tty);
185 static void stopin_command (char *arg, int from_tty);
187 static void stopat_command (char *arg, int from_tty);
189 static char *ep_parse_optional_if_clause (char **arg);
191 static void catch_exception_command_1 (enum exception_event_kind ex_event,
192 char *arg, int tempflag, int from_tty);
194 static void tcatch_command (char *arg, int from_tty);
196 static void ep_skip_leading_whitespace (char **s);
198 static int single_step_breakpoint_inserted_here_p (struct address_space *,
201 static void free_bp_location (struct bp_location *loc);
203 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
205 static void update_global_location_list (int);
207 static void update_global_location_list_nothrow (int);
209 static int is_hardware_watchpoint (const struct breakpoint *bpt);
211 static int is_watchpoint (const struct breakpoint *bpt);
213 static void insert_breakpoint_locations (void);
215 static int syscall_catchpoint_p (struct breakpoint *b);
217 static void tracepoints_info (char *, int);
219 static void delete_trace_command (char *, int);
221 static void enable_trace_command (char *, int);
223 static void disable_trace_command (char *, int);
225 static void trace_pass_command (char *, int);
227 /* A reference-counted struct command_line. This lets multiple
228 breakpoints share a single command list. */
229 struct counted_command_line
231 /* The reference count. */
234 /* The command list. */
235 struct command_line *commands;
238 struct command_line *
239 breakpoint_commands (struct breakpoint *b)
241 return b->commands ? b->commands->commands : NULL;
244 /* Flag indicating that a command has proceeded the inferior past the
245 current breakpoint. */
247 static int breakpoint_proceeded;
250 bpdisp_text (enum bpdisp disp)
252 /* NOTE: the following values are a part of MI protocol and represent
253 values of 'disp' field returned when inferior stops at a breakpoint. */
254 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
255 return bpdisps[(int) disp];
258 /* Prototypes for exported functions. */
259 /* If FALSE, gdb will not use hardware support for watchpoints, even
260 if such is available. */
261 static int can_use_hw_watchpoints;
264 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
265 struct cmd_list_element *c,
268 fprintf_filtered (file, _("\
269 Debugger's willingness to use watchpoint hardware is %s.\n"),
273 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
274 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
275 for unrecognized breakpoint locations.
276 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
277 static enum auto_boolean pending_break_support;
279 show_pending_break_support (struct ui_file *file, int from_tty,
280 struct cmd_list_element *c,
283 fprintf_filtered (file, _("\
284 Debugger's behavior regarding pending breakpoints is %s.\n"),
288 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
289 set with "break" but falling in read-only memory.
290 If 0, gdb will warn about such breakpoints, but won't automatically
291 use hardware breakpoints. */
292 static int automatic_hardware_breakpoints;
294 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
295 struct cmd_list_element *c,
298 fprintf_filtered (file, _("\
299 Automatic usage of hardware breakpoints is %s.\n"),
303 /* If on, gdb will keep breakpoints inserted even as inferior is
304 stopped, and immediately insert any new breakpoints. If off, gdb
305 will insert breakpoints into inferior only when resuming it, and
306 will remove breakpoints upon stop. If auto, GDB will behave as ON
307 if in non-stop mode, and as OFF if all-stop mode.*/
309 static const char always_inserted_auto[] = "auto";
310 static const char always_inserted_on[] = "on";
311 static const char always_inserted_off[] = "off";
312 static const char *always_inserted_enums[] = {
313 always_inserted_auto,
318 static const char *always_inserted_mode = always_inserted_auto;
320 show_always_inserted_mode (struct ui_file *file, int from_tty,
321 struct cmd_list_element *c, const char *value)
323 if (always_inserted_mode == always_inserted_auto)
324 fprintf_filtered (file, _("\
325 Always inserted breakpoint mode is %s (currently %s).\n"),
327 breakpoints_always_inserted_mode () ? "on" : "off");
329 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
333 breakpoints_always_inserted_mode (void)
335 return (always_inserted_mode == always_inserted_on
336 || (always_inserted_mode == always_inserted_auto && non_stop));
339 void _initialize_breakpoint (void);
341 /* Are we executing breakpoint commands? */
342 static int executing_breakpoint_commands;
344 /* Are overlay event breakpoints enabled? */
345 static int overlay_events_enabled;
347 /* Walk the following statement or block through all breakpoints.
348 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
351 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
353 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
354 for (B = breakpoint_chain; \
355 B ? (TMP=B->next, 1): 0; \
358 /* Similar iterator for the low-level breakpoints. SAFE variant is not
359 provided so update_global_location_list must not be called while executing
360 the block of ALL_BP_LOCATIONS. */
362 #define ALL_BP_LOCATIONS(B,BP_TMP) \
363 for (BP_TMP = bp_location; \
364 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
367 /* Iterator for tracepoints only. */
369 #define ALL_TRACEPOINTS(B) \
370 for (B = breakpoint_chain; B; B = B->next) \
371 if (is_tracepoint (B))
373 /* Chains of all breakpoints defined. */
375 struct breakpoint *breakpoint_chain;
377 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
379 static struct bp_location **bp_location;
381 /* Number of elements of BP_LOCATION. */
383 static unsigned bp_location_count;
385 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
386 for the current elements of BP_LOCATION which get a valid result from
387 bp_location_has_shadow. You can use it for roughly limiting the subrange of
388 BP_LOCATION to scan for shadow bytes for an address you need to read. */
390 static CORE_ADDR bp_location_placed_address_before_address_max;
392 /* Maximum offset plus alignment between
393 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
394 the current elements of BP_LOCATION which get a valid result from
395 bp_location_has_shadow. You can use it for roughly limiting the subrange of
396 BP_LOCATION to scan for shadow bytes for an address you need to read. */
398 static CORE_ADDR bp_location_shadow_len_after_address_max;
400 /* The locations that no longer correspond to any breakpoint,
401 unlinked from bp_location array, but for which a hit
402 may still be reported by a target. */
403 VEC(bp_location_p) *moribund_locations = NULL;
405 /* Number of last breakpoint made. */
407 static int breakpoint_count;
409 /* The value of `breakpoint_count' before the last command that
410 created breakpoints. If the last (break-like) command created more
411 than one breakpoint, then the difference between BREAKPOINT_COUNT
412 and PREV_BREAKPOINT_COUNT is more than one. */
413 static int prev_breakpoint_count;
415 /* Number of last tracepoint made. */
417 static int tracepoint_count;
419 static struct cmd_list_element *breakpoint_set_cmdlist;
420 static struct cmd_list_element *breakpoint_show_cmdlist;
421 static struct cmd_list_element *save_cmdlist;
423 /* Return whether a breakpoint is an active enabled breakpoint. */
425 breakpoint_enabled (struct breakpoint *b)
427 return (b->enable_state == bp_enabled);
430 /* Set breakpoint count to NUM. */
433 set_breakpoint_count (int num)
435 prev_breakpoint_count = breakpoint_count;
436 breakpoint_count = num;
437 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
440 /* Used by `start_rbreak_breakpoints' below, to record the current
441 breakpoint count before "rbreak" creates any breakpoint. */
442 static int rbreak_start_breakpoint_count;
444 /* Called at the start an "rbreak" command to record the first
448 start_rbreak_breakpoints (void)
450 rbreak_start_breakpoint_count = breakpoint_count;
453 /* Called at the end of an "rbreak" command to record the last
457 end_rbreak_breakpoints (void)
459 prev_breakpoint_count = rbreak_start_breakpoint_count;
462 /* Used in run_command to zero the hit count when a new run starts. */
465 clear_breakpoint_hit_counts (void)
467 struct breakpoint *b;
473 /* Allocate a new counted_command_line with reference count of 1.
474 The new structure owns COMMANDS. */
476 static struct counted_command_line *
477 alloc_counted_command_line (struct command_line *commands)
479 struct counted_command_line *result
480 = xmalloc (sizeof (struct counted_command_line));
482 result->commands = commands;
486 /* Increment reference count. This does nothing if CMD is NULL. */
489 incref_counted_command_line (struct counted_command_line *cmd)
495 /* Decrement reference count. If the reference count reaches 0,
496 destroy the counted_command_line. Sets *CMDP to NULL. This does
497 nothing if *CMDP is NULL. */
500 decref_counted_command_line (struct counted_command_line **cmdp)
504 if (--(*cmdp)->refc == 0)
506 free_command_lines (&(*cmdp)->commands);
513 /* A cleanup function that calls decref_counted_command_line. */
516 do_cleanup_counted_command_line (void *arg)
518 decref_counted_command_line (arg);
521 /* Create a cleanup that calls decref_counted_command_line on the
524 static struct cleanup *
525 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
527 return make_cleanup (do_cleanup_counted_command_line, cmdp);
530 /* Default address, symtab and line to put a breakpoint at
531 for "break" command with no arg.
532 if default_breakpoint_valid is zero, the other three are
533 not valid, and "break" with no arg is an error.
535 This set by print_stack_frame, which calls set_default_breakpoint. */
537 int default_breakpoint_valid;
538 CORE_ADDR default_breakpoint_address;
539 struct symtab *default_breakpoint_symtab;
540 int default_breakpoint_line;
541 struct program_space *default_breakpoint_pspace;
544 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
545 Advance *PP after the string and any trailing whitespace.
547 Currently the string can either be a number or "$" followed by the name
548 of a convenience variable. Making it an expression wouldn't work well
549 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
551 If the string is a NULL pointer, that denotes the last breakpoint.
553 TRAILER is a character which can be found after the number; most
554 commonly this is `-'. If you don't want a trailer, use \0. */
556 get_number_trailer (char **pp, int trailer)
558 int retval = 0; /* default */
562 /* Empty line means refer to the last breakpoint. */
563 return breakpoint_count;
566 /* Make a copy of the name, so we can null-terminate it
567 to pass to lookup_internalvar(). */
572 while (isalnum (*p) || *p == '_')
574 varname = (char *) alloca (p - start + 1);
575 strncpy (varname, start, p - start);
576 varname[p - start] = '\0';
577 if (get_internalvar_integer (lookup_internalvar (varname), &val))
581 printf_filtered (_("Convenience variable must have integer value.\n"));
589 while (*p >= '0' && *p <= '9')
592 /* There is no number here. (e.g. "cond a == b"). */
594 /* Skip non-numeric token */
595 while (*p && !isspace((int) *p))
597 /* Return zero, which caller must interpret as error. */
603 if (!(isspace (*p) || *p == '\0' || *p == trailer))
605 /* Trailing junk: return 0 and let caller print error msg. */
606 while (!(isspace (*p) || *p == '\0' || *p == trailer))
617 /* Like get_number_trailer, but don't allow a trailer. */
619 get_number (char **pp)
621 return get_number_trailer (pp, '\0');
624 /* Parse a number or a range.
625 * A number will be of the form handled by get_number.
626 * A range will be of the form <number1> - <number2>, and
627 * will represent all the integers between number1 and number2,
630 * While processing a range, this fuction is called iteratively;
631 * At each call it will return the next value in the range.
633 * At the beginning of parsing a range, the char pointer PP will
634 * be advanced past <number1> and left pointing at the '-' token.
635 * Subsequent calls will not advance the pointer until the range
636 * is completed. The call that completes the range will advance
637 * pointer PP past <number2>.
641 get_number_or_range (char **pp)
643 static int last_retval, end_value;
644 static char *end_ptr;
645 static int in_range = 0;
649 /* Default case: pp is pointing either to a solo number,
650 or to the first number of a range. */
651 last_retval = get_number_trailer (pp, '-');
656 /* This is the start of a range (<number1> - <number2>).
657 Skip the '-', parse and remember the second number,
658 and also remember the end of the final token. */
662 while (isspace ((int) *end_ptr))
663 end_ptr++; /* skip white space */
664 end_value = get_number (temp);
665 if (end_value < last_retval)
667 error (_("inverted range"));
669 else if (end_value == last_retval)
671 /* degenerate range (number1 == number2). Advance the
672 token pointer so that the range will be treated as a
681 error (_("negative value"));
684 /* pp points to the '-' that betokens a range. All
685 number-parsing has already been done. Return the next
686 integer value (one greater than the saved previous value).
687 Do not advance the token pointer 'pp' until the end of range
690 if (++last_retval == end_value)
692 /* End of range reached; advance token pointer. */
700 /* Return the breakpoint with the specified number, or NULL
701 if the number does not refer to an existing breakpoint. */
704 get_breakpoint (int num)
706 struct breakpoint *b;
709 if (b->number == num)
718 set_breakpoint_condition (struct breakpoint *b, char *exp,
721 struct bp_location *loc = b->loc;
723 for (; loc; loc = loc->next)
728 xfree (b->cond_string);
729 b->cond_string = NULL;
736 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
741 /* I don't know if it matters whether this is the string the user
742 typed in or the decompiled expression. */
743 b->cond_string = xstrdup (arg);
744 b->condition_not_parsed = 0;
746 if (is_watchpoint (b))
748 innermost_block = NULL;
750 b->cond_exp = parse_exp_1 (&arg, 0, 0);
752 error (_("Junk at end of expression"));
753 b->cond_exp_valid_block = innermost_block;
757 for (loc = b->loc; loc; loc = loc->next)
761 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
763 error (_("Junk at end of expression"));
767 breakpoints_changed ();
768 observer_notify_breakpoint_modified (b->number);
771 /* condition N EXP -- set break condition of breakpoint N to EXP. */
774 condition_command (char *arg, int from_tty)
776 struct breakpoint *b;
781 error_no_arg (_("breakpoint number"));
784 bnum = get_number (&p);
786 error (_("Bad breakpoint argument: '%s'"), arg);
789 if (b->number == bnum)
791 set_breakpoint_condition (b, p, from_tty);
795 error (_("No breakpoint number %d."), bnum);
798 /* Check that COMMAND do not contain commands that are suitable
799 only for tracepoints and not suitable for ordinary breakpoints.
800 Throw if any such commands is found.
803 check_no_tracepoint_commands (struct command_line *commands)
805 struct command_line *c;
806 for (c = commands; c; c = c->next)
810 if (c->control_type == while_stepping_control)
811 error (_("The 'while-stepping' command can only be used for tracepoints"));
813 for (i = 0; i < c->body_count; ++i)
814 check_no_tracepoint_commands ((c->body_list)[i]);
816 /* Not that command parsing removes leading whitespace and comment
817 lines and also empty lines. So, we only need to check for
819 if (strstr (c->line, "collect ") == c->line)
820 error (_("The 'collect' command can only be used for tracepoints"));
822 if (strstr (c->line, "teval ") == c->line)
823 error (_("The 'teval' command can only be used for tracepoints"));
827 /* Encapsulate tests for different types of tracepoints. */
830 is_tracepoint (const struct breakpoint *b)
832 return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint);
835 /* A helper function that validsates that COMMANDS are valid for a
836 breakpoint. This function will throw an exception if a problem is
840 validate_commands_for_breakpoint (struct breakpoint *b,
841 struct command_line *commands)
843 if (is_tracepoint (b))
845 /* We need to verify that each top-level element of commands
846 is valid for tracepoints, that there's at most one while-stepping
847 element, and that while-stepping's body has valid tracing commands
848 excluding nested while-stepping. */
849 struct command_line *c;
850 struct command_line *while_stepping = 0;
851 for (c = commands; c; c = c->next)
853 if (c->control_type == while_stepping_control)
855 if (b->type == bp_fast_tracepoint)
856 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
859 error (_("The 'while-stepping' command can be used only once"));
866 struct command_line *c2;
868 gdb_assert (while_stepping->body_count == 1);
869 c2 = while_stepping->body_list[0];
870 for (; c2; c2 = c2->next)
872 if (c2->control_type == while_stepping_control)
873 error (_("The 'while-stepping' command cannot be nested"));
879 check_no_tracepoint_commands (commands);
883 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
884 validate that only allowed commands are included.
888 breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
890 validate_commands_for_breakpoint (b, commands);
892 decref_counted_command_line (&b->commands);
893 b->commands = alloc_counted_command_line (commands);
894 breakpoints_changed ();
895 observer_notify_breakpoint_modified (b->number);
899 check_tracepoint_command (char *line, void *closure)
901 struct breakpoint *b = closure;
902 validate_actionline (&line, b);
905 /* A structure used to pass information through
906 map_breakpoint_numbers. */
910 /* True if the command was typed at a tty. */
913 /* The breakpoint range spec. */
916 /* Non-NULL if the body of the commands are being read from this
917 already-parsed command. */
918 struct command_line *control;
920 /* The command lines read from the user, or NULL if they have not
922 struct counted_command_line *cmd;
925 /* A callback for map_breakpoint_numbers that sets the commands for
929 do_map_commands_command (struct breakpoint *b, void *data)
931 struct commands_info *info = data;
933 if (info->cmd == NULL)
935 struct command_line *l;
937 if (info->control != NULL)
938 l = copy_command_lines (info->control->body_list[0]);
941 struct cleanup *old_chain;
944 str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
947 old_chain = make_cleanup (xfree, str);
949 l = read_command_lines (str,
952 ? check_tracepoint_command : 0),
955 do_cleanups (old_chain);
958 info->cmd = alloc_counted_command_line (l);
961 /* If a breakpoint was on the list more than once, we don't need to
963 if (b->commands != info->cmd)
965 validate_commands_for_breakpoint (b, info->cmd->commands);
966 incref_counted_command_line (info->cmd);
967 decref_counted_command_line (&b->commands);
968 b->commands = info->cmd;
969 breakpoints_changed ();
970 observer_notify_breakpoint_modified (b->number);
975 commands_command_1 (char *arg, int from_tty, struct command_line *control)
977 struct cleanup *cleanups;
978 struct commands_info info;
980 info.from_tty = from_tty;
981 info.control = control;
983 /* If we read command lines from the user, then `info' will hold an
984 extra reference to the commands that we must clean up. */
985 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
987 if (arg == NULL || !*arg)
989 if (breakpoint_count - prev_breakpoint_count > 1)
990 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count);
991 else if (breakpoint_count > 0)
992 arg = xstrprintf ("%d", breakpoint_count);
995 /* So that we don't try to free the incoming non-NULL
996 argument in the cleanup below. Mapping breakpoint
997 numbers will fail in this case. */
1002 /* The command loop has some static state, so we need to preserve
1004 arg = xstrdup (arg);
1007 make_cleanup (xfree, arg);
1011 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1013 if (info.cmd == NULL)
1014 error (_("No breakpoints specified."));
1016 do_cleanups (cleanups);
1020 commands_command (char *arg, int from_tty)
1022 commands_command_1 (arg, from_tty, NULL);
1025 /* Like commands_command, but instead of reading the commands from
1026 input stream, takes them from an already parsed command structure.
1028 This is used by cli-script.c to DTRT with breakpoint commands
1029 that are part of if and while bodies. */
1030 enum command_control_type
1031 commands_from_control_command (char *arg, struct command_line *cmd)
1033 commands_command_1 (arg, 0, cmd);
1034 return simple_control;
1037 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1040 bp_location_has_shadow (struct bp_location *bl)
1042 if (bl->loc_type != bp_loc_software_breakpoint)
1046 if (bl->target_info.shadow_len == 0)
1047 /* bp isn't valid, or doesn't shadow memory. */
1052 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1053 by replacing any memory breakpoints with their shadowed contents.
1055 The range of shadowed area by each bp_location is:
1056 b->address - bp_location_placed_address_before_address_max
1057 up to b->address + bp_location_shadow_len_after_address_max
1058 The range we were requested to resolve shadows for is:
1059 memaddr ... memaddr + len
1060 Thus the safe cutoff boundaries for performance optimization are
1061 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1063 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1066 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1068 /* Left boundary, right boundary and median element of our binary search. */
1069 unsigned bc_l, bc_r, bc;
1071 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1072 safe to report lower value but a failure to report higher one. */
1075 bc_r = bp_location_count;
1076 while (bc_l + 1 < bc_r)
1078 struct bp_location *b;
1080 bc = (bc_l + bc_r) / 2;
1081 b = bp_location[bc];
1083 /* Check first B->ADDRESS will not overflow due to the added constant.
1084 Then advance the left boundary only if we are sure the BC element can
1085 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1087 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1088 we cannot miss a breakpoint with its shadow range tail still reaching
1091 if (b->address + bp_location_shadow_len_after_address_max >= b->address
1092 && b->address + bp_location_shadow_len_after_address_max <= memaddr)
1098 /* Now do full processing of the found relevant range of elements. */
1100 for (bc = bc_l; bc < bp_location_count; bc++)
1102 struct bp_location *b = bp_location[bc];
1103 CORE_ADDR bp_addr = 0;
1107 if (b->owner->type == bp_none)
1108 warning (_("reading through apparently deleted breakpoint #%d?"),
1111 /* Performance optimization: any futher element can no longer affect BUF
1114 if (b->address >= bp_location_placed_address_before_address_max
1115 && memaddr + len <= b->address
1116 - bp_location_placed_address_before_address_max)
1119 if (!bp_location_has_shadow (b))
1121 if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
1122 current_program_space->aspace, 0))
1125 /* Addresses and length of the part of the breakpoint that
1127 bp_addr = b->target_info.placed_address;
1128 bp_size = b->target_info.shadow_len;
1130 if (bp_addr + bp_size <= memaddr)
1131 /* The breakpoint is entirely before the chunk of memory we
1135 if (bp_addr >= memaddr + len)
1136 /* The breakpoint is entirely after the chunk of memory we are
1140 /* Offset within shadow_contents. */
1141 if (bp_addr < memaddr)
1143 /* Only copy the second part of the breakpoint. */
1144 bp_size -= memaddr - bp_addr;
1145 bptoffset = memaddr - bp_addr;
1149 if (bp_addr + bp_size > memaddr + len)
1151 /* Only copy the first part of the breakpoint. */
1152 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1155 memcpy (buf + bp_addr - memaddr,
1156 b->target_info.shadow_contents + bptoffset, bp_size);
1161 /* A wrapper function for inserting catchpoints. */
1163 insert_catchpoint (struct ui_out *uo, void *args)
1165 struct breakpoint *b = (struct breakpoint *) args;
1167 gdb_assert (b->type == bp_catchpoint);
1168 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
1173 /* Return true if BPT is of any hardware watchpoint kind. */
1176 is_hardware_watchpoint (const struct breakpoint *bpt)
1178 return (bpt->type == bp_hardware_watchpoint
1179 || bpt->type == bp_read_watchpoint
1180 || bpt->type == bp_access_watchpoint);
1183 /* Return true if BPT is of any watchpoint kind, hardware or
1187 is_watchpoint (const struct breakpoint *bpt)
1189 return (is_hardware_watchpoint (bpt)
1190 || bpt->type == bp_watchpoint);
1193 /* Find the current value of a watchpoint on EXP. Return the value in
1194 *VALP and *RESULTP and the chain of intermediate and final values
1195 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1198 If a memory error occurs while evaluating the expression, *RESULTP will
1199 be set to NULL. *RESULTP may be a lazy value, if the result could
1200 not be read from memory. It is used to determine whether a value
1201 is user-specified (we should watch the whole value) or intermediate
1202 (we should watch only the bit used to locate the final value).
1204 If the final value, or any intermediate value, could not be read
1205 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1206 set to any referenced values. *VALP will never be a lazy value.
1207 This is the value which we store in struct breakpoint.
1209 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1210 value chain. The caller must free the values individually. If
1211 VAL_CHAIN is NULL, all generated values will be left on the value
1215 fetch_watchpoint_value (struct expression *exp, struct value **valp,
1216 struct value **resultp, struct value **val_chain)
1218 struct value *mark, *new_mark, *result;
1219 volatile struct gdb_exception ex;
1227 /* Evaluate the expression. */
1228 mark = value_mark ();
1231 TRY_CATCH (ex, RETURN_MASK_ALL)
1233 result = evaluate_expression (exp);
1237 /* Ignore memory errors, we want watchpoints pointing at
1238 inaccessible memory to still be created; otherwise, throw the
1239 error to some higher catcher. */
1245 throw_exception (ex);
1250 new_mark = value_mark ();
1251 if (mark == new_mark)
1256 /* Make sure it's not lazy, so that after the target stops again we
1257 have a non-lazy previous value to compare with. */
1259 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
1264 /* Return the chain of intermediate values. We use this to
1265 decide which addresses to watch. */
1266 *val_chain = new_mark;
1267 value_release_to_mark (mark);
1271 /* Assuming that B is a watchpoint: returns true if the current thread
1272 and its running state are safe to evaluate or update watchpoint B.
1273 Watchpoints on local expressions need to be evaluated in the
1274 context of the thread that was current when the watchpoint was
1275 created, and, that thread needs to be stopped to be able to select
1276 the correct frame context. Watchpoints on global expressions can
1277 be evaluated on any thread, and in any state. It is presently left
1278 to the target allowing memory accesses when threads are
1282 watchpoint_in_thread_scope (struct breakpoint *b)
1284 return (ptid_equal (b->watchpoint_thread, null_ptid)
1285 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1286 && !is_executing (inferior_ptid)));
1289 /* Assuming that B is a watchpoint:
1290 - Reparse watchpoint expression, if REPARSE is non-zero
1291 - Evaluate expression and store the result in B->val
1292 - Evaluate the condition if there is one, and store the result
1294 - Update the list of values that must be watched in B->loc.
1296 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1297 If this is local watchpoint that is out of scope, delete it.
1299 Even with `set breakpoint always-inserted on' the watchpoints are removed
1300 + inserted on each stop here. Normal breakpoints must never be removed
1301 because they might be missed by a running thread when debugging in non-stop
1302 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1303 processed here) are specific to each LWP since they are stored in each LWP's
1304 hardware debug registers. Therefore, such LWP must be stopped first in
1305 order to be able to modify its hardware watchpoints.
1307 Hardware watchpoints must be reset exactly once after being presented to the
1308 user. It cannot be done sooner, because it would reset the data used to
1309 present the watchpoint hit to the user. And it must not be done later
1310 because it could display the same single watchpoint hit during multiple GDB
1311 stops. Note that the latter is relevant only to the hardware watchpoint
1312 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1313 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1314 memory content has not changed.
1316 The following constraints influence the location where we can reset hardware
1319 * target_stopped_by_watchpoint and target_stopped_data_address are called
1320 several times when GDB stops.
1323 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1324 stop. GDB only presents one hardware watchpoint hit at a time as the
1325 reason for stopping, and all the other hits are presented later, one after
1326 the other, each time the user requests the execution to be resumed.
1327 Execution is not resumed for the threads still having pending hit event
1328 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1329 the inferior on the first stop the thread hit event is kept being reported
1330 from its cached value by linux_nat_stopped_data_address until the real
1331 thread resume happens after the watchpoint gets presented and thus its
1332 LWP_INFO->STATUS gets reset.
1334 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1335 removal from inferior. */
1338 update_watchpoint (struct breakpoint *b, int reparse)
1340 int within_current_scope;
1341 struct frame_id saved_frame_id;
1344 /* If this is a local watchpoint, we only want to check if the
1345 watchpoint frame is in scope if the current thread is the thread
1346 that was used to create the watchpoint. */
1347 if (!watchpoint_in_thread_scope (b))
1350 /* We don't free locations. They are stored in bp_location array and
1351 update_global_locations will eventually delete them and remove
1352 breakpoints if needed. */
1355 if (b->disposition == disp_del_at_next_stop)
1360 /* Determine if the watchpoint is within scope. */
1361 if (b->exp_valid_block == NULL)
1362 within_current_scope = 1;
1365 struct frame_info *fi;
1367 /* Save the current frame's ID so we can restore it after
1368 evaluating the watchpoint expression on its own frame. */
1369 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1370 took a frame parameter, so that we didn't have to change the
1373 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1375 fi = frame_find_by_id (b->watchpoint_frame);
1376 within_current_scope = (fi != NULL);
1377 if (within_current_scope)
1381 if (within_current_scope && reparse)
1390 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1391 /* If the meaning of expression itself changed, the old value is
1392 no longer relevant. We don't want to report a watchpoint hit
1393 to the user when the old value and the new value may actually
1394 be completely different objects. */
1395 value_free (b->val);
1399 /* Note that unlike with breakpoints, the watchpoint's condition
1400 expression is stored in the breakpoint object, not in the
1401 locations (re)created below. */
1402 if (b->cond_string != NULL)
1404 if (b->cond_exp != NULL)
1406 xfree (b->cond_exp);
1411 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1415 /* If we failed to parse the expression, for example because
1416 it refers to a global variable in a not-yet-loaded shared library,
1417 don't try to insert watchpoint. We don't automatically delete
1418 such watchpoint, though, since failure to parse expression
1419 is different from out-of-scope watchpoint. */
1420 if ( !target_has_execution)
1422 /* Without execution, memory can't change. No use to try and
1423 set watchpoint locations. The watchpoint will be reset when
1424 the target gains execution, through breakpoint_re_set. */
1426 else if (within_current_scope && b->exp)
1428 struct value *val_chain, *v, *result, *next;
1429 struct program_space *frame_pspace;
1431 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
1433 /* Avoid setting b->val if it's already set. The meaning of
1434 b->val is 'the last value' user saw, and we should update
1435 it only if we reported that last value to user. As it
1436 happens, the code that reports it updates b->val directly. */
1443 /* Change the type of breakpoint between hardware assisted or an
1444 ordinary watchpoint depending on the hardware support and free
1445 hardware slots. REPARSE is set when the inferior is started. */
1446 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1449 int i, mem_cnt, other_type_used;
1451 /* We need to determine how many resources are already used
1452 for all other hardware watchpoints to see if we still have
1453 enough resources to also fit this watchpoint in as well.
1454 To avoid the hw_watchpoint_used_count call below from counting
1455 this watchpoint, make sure that it is marked as a software
1457 b->type = bp_watchpoint;
1458 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1460 mem_cnt = can_use_hardware_watchpoint (val_chain);
1463 b->type = bp_watchpoint;
1466 int target_resources_ok = target_can_use_hardware_watchpoint
1467 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1468 if (target_resources_ok <= 0)
1469 b->type = bp_watchpoint;
1471 b->type = bp_hardware_watchpoint;
1475 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1477 /* Look at each value on the value chain. */
1478 for (v = val_chain; v; v = next)
1480 /* If it's a memory location, and GDB actually needed
1481 its contents to evaluate the expression, then we
1482 must watch it. If the first value returned is
1483 still lazy, that means an error occurred reading it;
1484 watch it anyway in case it becomes readable. */
1485 if (VALUE_LVAL (v) == lval_memory
1486 && (v == val_chain || ! value_lazy (v)))
1488 struct type *vtype = check_typedef (value_type (v));
1490 /* We only watch structs and arrays if user asked
1491 for it explicitly, never if they just happen to
1492 appear in the middle of some value chain. */
1494 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1495 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1499 struct bp_location *loc, **tmp;
1501 addr = value_address (v);
1502 len = TYPE_LENGTH (value_type (v));
1504 if (b->type == bp_read_watchpoint)
1506 else if (b->type == bp_access_watchpoint)
1509 loc = allocate_bp_location (b);
1510 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1513 loc->gdbarch = get_type_arch (value_type (v));
1515 loc->pspace = frame_pspace;
1516 loc->address = addr;
1518 loc->watchpoint_type = type;
1522 next = value_next (v);
1527 /* If a software watchpoint is not watching any memory, then the
1528 above left it without any location set up. But,
1529 bpstat_stop_status requires a location to be able to report
1530 stops, so make sure there's at least a dummy one. */
1531 if (b->type == bp_watchpoint && b->loc == NULL)
1533 b->loc = allocate_bp_location (b);
1534 b->loc->pspace = frame_pspace;
1535 b->loc->address = -1;
1536 b->loc->length = -1;
1537 b->loc->watchpoint_type = -1;
1540 else if (!within_current_scope)
1542 printf_filtered (_("\
1543 Watchpoint %d deleted because the program has left the block \n\
1544 in which its expression is valid.\n"),
1546 if (b->related_breakpoint)
1548 b->related_breakpoint->disposition = disp_del_at_next_stop;
1549 b->related_breakpoint->related_breakpoint = NULL;
1550 b->related_breakpoint= NULL;
1552 b->disposition = disp_del_at_next_stop;
1555 /* Restore the selected frame. */
1557 select_frame (frame_find_by_id (saved_frame_id));
1561 /* Returns 1 iff breakpoint location should be
1562 inserted in the inferior. */
1564 should_be_inserted (struct bp_location *bpt)
1566 if (!breakpoint_enabled (bpt->owner))
1569 if (bpt->owner->disposition == disp_del_at_next_stop)
1572 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1575 /* This is set for example, when we're attached to the parent of a
1576 vfork, and have detached from the child. The child is running
1577 free, and we expect it to do an exec or exit, at which point the
1578 OS makes the parent schedulable again (and the target reports
1579 that the vfork is done). Until the child is done with the shared
1580 memory region, do not insert breakpoints in the parent, otherwise
1581 the child could still trip on the parent's breakpoints. Since
1582 the parent is blocked anyway, it won't miss any breakpoint. */
1583 if (bpt->pspace->breakpoints_not_allowed)
1586 /* Tracepoints are inserted by the target at a time of its choosing,
1588 if (is_tracepoint (bpt->owner))
1594 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1595 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1596 and HW_BREAKPOINT_ERROR are used to report problems.
1598 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1599 method for each breakpoint or catchpoint type. */
1601 insert_bp_location (struct bp_location *bpt,
1602 struct ui_file *tmp_error_stream,
1603 int *disabled_breaks,
1604 int *hw_breakpoint_error)
1608 if (!should_be_inserted (bpt) || bpt->inserted)
1611 /* Initialize the target-specific information. */
1612 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1613 bpt->target_info.placed_address = bpt->address;
1614 bpt->target_info.placed_address_space = bpt->pspace->aspace;
1616 if (bpt->loc_type == bp_loc_software_breakpoint
1617 || bpt->loc_type == bp_loc_hardware_breakpoint)
1619 if (bpt->owner->type != bp_hardware_breakpoint)
1621 /* If the explicitly specified breakpoint type
1622 is not hardware breakpoint, check the memory map to see
1623 if the breakpoint address is in read only memory or not.
1624 Two important cases are:
1625 - location type is not hardware breakpoint, memory
1626 is readonly. We change the type of the location to
1627 hardware breakpoint.
1628 - location type is hardware breakpoint, memory is read-write.
1629 This means we've previously made the location hardware one, but
1630 then the memory map changed, so we undo.
1632 When breakpoints are removed, remove_breakpoints will
1633 use location types we've just set here, the only possible
1634 problem is that memory map has changed during running program,
1635 but it's not going to work anyway with current gdb. */
1636 struct mem_region *mr
1637 = lookup_mem_region (bpt->target_info.placed_address);
1641 if (automatic_hardware_breakpoints)
1643 enum bp_loc_type new_type;
1645 if (mr->attrib.mode != MEM_RW)
1646 new_type = bp_loc_hardware_breakpoint;
1648 new_type = bp_loc_software_breakpoint;
1650 if (new_type != bpt->loc_type)
1652 static int said = 0;
1653 bpt->loc_type = new_type;
1656 fprintf_filtered (gdb_stdout, _("\
1657 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1662 else if (bpt->loc_type == bp_loc_software_breakpoint
1663 && mr->attrib.mode != MEM_RW)
1664 warning (_("cannot set software breakpoint at readonly address %s"),
1665 paddress (bpt->gdbarch, bpt->address));
1669 /* First check to see if we have to handle an overlay. */
1670 if (overlay_debugging == ovly_off
1671 || bpt->section == NULL
1672 || !(section_is_overlay (bpt->section)))
1674 /* No overlay handling: just set the breakpoint. */
1676 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1677 val = target_insert_hw_breakpoint (bpt->gdbarch,
1680 val = target_insert_breakpoint (bpt->gdbarch,
1685 /* This breakpoint is in an overlay section.
1686 Shall we set a breakpoint at the LMA? */
1687 if (!overlay_events_enabled)
1689 /* Yes -- overlay event support is not active,
1690 so we must try to set a breakpoint at the LMA.
1691 This will not work for a hardware breakpoint. */
1692 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1693 warning (_("hardware breakpoint %d not supported in overlay!"),
1694 bpt->owner->number);
1697 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1699 /* Set a software (trap) breakpoint at the LMA. */
1700 bpt->overlay_target_info = bpt->target_info;
1701 bpt->overlay_target_info.placed_address = addr;
1702 val = target_insert_breakpoint (bpt->gdbarch,
1703 &bpt->overlay_target_info);
1705 fprintf_unfiltered (tmp_error_stream,
1706 "Overlay breakpoint %d failed: in ROM?\n",
1707 bpt->owner->number);
1710 /* Shall we set a breakpoint at the VMA? */
1711 if (section_is_mapped (bpt->section))
1713 /* Yes. This overlay section is mapped into memory. */
1714 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1715 val = target_insert_hw_breakpoint (bpt->gdbarch,
1718 val = target_insert_breakpoint (bpt->gdbarch,
1723 /* No. This breakpoint will not be inserted.
1724 No error, but do not mark the bp as 'inserted'. */
1731 /* Can't set the breakpoint. */
1732 if (solib_name_from_address (bpt->pspace, bpt->address))
1734 /* See also: disable_breakpoints_in_shlibs. */
1736 bpt->shlib_disabled = 1;
1737 if (!*disabled_breaks)
1739 fprintf_unfiltered (tmp_error_stream,
1740 "Cannot insert breakpoint %d.\n",
1741 bpt->owner->number);
1742 fprintf_unfiltered (tmp_error_stream,
1743 "Temporarily disabling shared library breakpoints:\n");
1745 *disabled_breaks = 1;
1746 fprintf_unfiltered (tmp_error_stream,
1747 "breakpoint #%d\n", bpt->owner->number);
1751 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1753 *hw_breakpoint_error = 1;
1754 fprintf_unfiltered (tmp_error_stream,
1755 "Cannot insert hardware breakpoint %d.\n",
1756 bpt->owner->number);
1760 fprintf_unfiltered (tmp_error_stream,
1761 "Cannot insert breakpoint %d.\n",
1762 bpt->owner->number);
1763 fprintf_filtered (tmp_error_stream,
1764 "Error accessing memory address ");
1765 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1767 fprintf_filtered (tmp_error_stream, ": %s.\n",
1768 safe_strerror (val));
1779 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1780 /* NOTE drow/2003-09-08: This state only exists for removing
1781 watchpoints. It's not clear that it's necessary... */
1782 && bpt->owner->disposition != disp_del_at_next_stop)
1784 val = target_insert_watchpoint (bpt->address,
1786 bpt->watchpoint_type);
1788 /* If trying to set a read-watchpoint, and it turns out it's not
1789 supported, try emulating one with an access watchpoint. */
1790 if (val == 1 && bpt->watchpoint_type == hw_read)
1792 struct bp_location *loc, **loc_temp;
1794 /* But don't try to insert it, if there's already another
1795 hw_access location that would be considered a duplicate
1797 ALL_BP_LOCATIONS (loc, loc_temp)
1799 && loc->watchpoint_type == hw_access
1800 && watchpoint_locations_match (bpt, loc))
1804 bpt->target_info = loc->target_info;
1805 bpt->watchpoint_type = hw_access;
1812 val = target_insert_watchpoint (bpt->address,
1816 bpt->watchpoint_type = hw_access;
1820 bpt->inserted = (val == 0);
1823 else if (bpt->owner->type == bp_catchpoint)
1825 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1826 bpt->owner, RETURN_MASK_ERROR);
1827 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1828 bpt->owner->number);
1830 bpt->owner->enable_state = bp_disabled;
1834 /* We've already printed an error message if there was a problem
1835 inserting this catchpoint, and we've disabled the catchpoint,
1836 so just return success. */
1843 /* This function is called when program space PSPACE is about to be
1844 deleted. It takes care of updating breakpoints to not reference
1848 breakpoint_program_space_exit (struct program_space *pspace)
1850 struct breakpoint *b, *b_temp;
1851 struct bp_location *loc, **loc_temp;
1853 /* Remove any breakpoint that was set through this program space. */
1854 ALL_BREAKPOINTS_SAFE (b, b_temp)
1856 if (b->pspace == pspace)
1857 delete_breakpoint (b);
1860 /* Breakpoints set through other program spaces could have locations
1861 bound to PSPACE as well. Remove those. */
1862 ALL_BP_LOCATIONS (loc, loc_temp)
1864 struct bp_location *tmp;
1866 if (loc->pspace == pspace)
1868 if (loc->owner->loc == loc)
1869 loc->owner->loc = loc->next;
1871 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1872 if (tmp->next == loc)
1874 tmp->next = loc->next;
1880 /* Now update the global location list to permanently delete the
1881 removed locations above. */
1882 update_global_location_list (0);
1885 /* Make sure all breakpoints are inserted in inferior.
1886 Throws exception on any error.
1887 A breakpoint that is already inserted won't be inserted
1888 again, so calling this function twice is safe. */
1890 insert_breakpoints (void)
1892 struct breakpoint *bpt;
1894 ALL_BREAKPOINTS (bpt)
1895 if (is_hardware_watchpoint (bpt))
1896 update_watchpoint (bpt, 0 /* don't reparse. */);
1898 update_global_location_list (1);
1900 /* update_global_location_list does not insert breakpoints when
1901 always_inserted_mode is not enabled. Explicitly insert them
1903 if (!breakpoints_always_inserted_mode ())
1904 insert_breakpoint_locations ();
1907 /* insert_breakpoints is used when starting or continuing the program.
1908 remove_breakpoints is used when the program stops.
1909 Both return zero if successful,
1910 or an `errno' value if could not write the inferior. */
1913 insert_breakpoint_locations (void)
1915 struct breakpoint *bpt;
1916 struct bp_location *b, **bp_tmp;
1919 int disabled_breaks = 0;
1920 int hw_breakpoint_error = 0;
1922 struct ui_file *tmp_error_stream = mem_fileopen ();
1923 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1925 /* Explicitly mark the warning -- this will only be printed if
1926 there was an error. */
1927 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1929 save_current_space_and_thread ();
1931 ALL_BP_LOCATIONS (b, bp_tmp)
1933 if (!should_be_inserted (b) || b->inserted)
1936 /* There is no point inserting thread-specific breakpoints if the
1937 thread no longer exists. */
1938 if (b->owner->thread != -1
1939 && !valid_thread_id (b->owner->thread))
1942 switch_to_program_space_and_thread (b->pspace);
1944 /* For targets that support global breakpoints, there's no need
1945 to select an inferior to insert breakpoint to. In fact, even
1946 if we aren't attached to any process yet, we should still
1947 insert breakpoints. */
1948 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1949 && ptid_equal (inferior_ptid, null_ptid))
1952 val = insert_bp_location (b, tmp_error_stream,
1954 &hw_breakpoint_error);
1959 /* If we failed to insert all locations of a watchpoint,
1960 remove them, as half-inserted watchpoint is of limited use. */
1961 ALL_BREAKPOINTS (bpt)
1963 int some_failed = 0;
1964 struct bp_location *loc;
1966 if (!is_hardware_watchpoint (bpt))
1969 if (!breakpoint_enabled (bpt))
1972 if (bpt->disposition == disp_del_at_next_stop)
1975 for (loc = bpt->loc; loc; loc = loc->next)
1976 if (!loc->inserted && should_be_inserted (loc))
1983 for (loc = bpt->loc; loc; loc = loc->next)
1985 remove_breakpoint (loc, mark_uninserted);
1987 hw_breakpoint_error = 1;
1988 fprintf_unfiltered (tmp_error_stream,
1989 "Could not insert hardware watchpoint %d.\n",
1997 /* If a hardware breakpoint or watchpoint was inserted, add a
1998 message about possibly exhausted resources. */
1999 if (hw_breakpoint_error)
2001 fprintf_unfiltered (tmp_error_stream,
2002 "Could not insert hardware breakpoints:\n\
2003 You may have requested too many hardware breakpoints/watchpoints.\n");
2005 target_terminal_ours_for_output ();
2006 error_stream (tmp_error_stream);
2009 do_cleanups (cleanups);
2013 remove_breakpoints (void)
2015 struct bp_location *b, **bp_tmp;
2018 ALL_BP_LOCATIONS (b, bp_tmp)
2021 val |= remove_breakpoint (b, mark_uninserted);
2026 /* Remove breakpoints of process PID. */
2029 remove_breakpoints_pid (int pid)
2031 struct bp_location *b, **b_tmp;
2033 struct inferior *inf = find_inferior_pid (pid);
2035 ALL_BP_LOCATIONS (b, b_tmp)
2037 if (b->pspace != inf->pspace)
2042 val = remove_breakpoint (b, mark_uninserted);
2051 remove_hw_watchpoints (void)
2053 struct bp_location *b, **bp_tmp;
2056 ALL_BP_LOCATIONS (b, bp_tmp)
2058 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
2059 val |= remove_breakpoint (b, mark_uninserted);
2065 reattach_breakpoints (int pid)
2067 struct cleanup *old_chain;
2068 struct bp_location *b, **bp_tmp;
2070 struct ui_file *tmp_error_stream = mem_fileopen ();
2071 int dummy1 = 0, dummy2 = 0;
2072 struct inferior *inf;
2073 struct thread_info *tp;
2075 tp = any_live_thread_of_process (pid);
2079 inf = find_inferior_pid (pid);
2080 old_chain = save_inferior_ptid ();
2082 inferior_ptid = tp->ptid;
2084 make_cleanup_ui_file_delete (tmp_error_stream);
2086 ALL_BP_LOCATIONS (b, bp_tmp)
2088 if (b->pspace != inf->pspace)
2094 val = insert_bp_location (b, tmp_error_stream,
2098 do_cleanups (old_chain);
2103 do_cleanups (old_chain);
2107 static int internal_breakpoint_number = -1;
2109 static struct breakpoint *
2110 create_internal_breakpoint (struct gdbarch *gdbarch,
2111 CORE_ADDR address, enum bptype type)
2113 struct symtab_and_line sal;
2114 struct breakpoint *b;
2116 init_sal (&sal); /* initialize to zeroes */
2119 sal.section = find_pc_overlay (sal.pc);
2120 sal.pspace = current_program_space;
2122 b = set_raw_breakpoint (gdbarch, sal, type);
2123 b->number = internal_breakpoint_number--;
2124 b->disposition = disp_donttouch;
2130 create_overlay_event_breakpoint (char *func_name)
2132 struct objfile *objfile;
2134 ALL_OBJFILES (objfile)
2136 struct breakpoint *b;
2137 struct minimal_symbol *m;
2139 m = lookup_minimal_symbol_text (func_name, objfile);
2143 b = create_internal_breakpoint (get_objfile_arch (objfile),
2144 SYMBOL_VALUE_ADDRESS (m),
2146 b->addr_string = xstrdup (func_name);
2148 if (overlay_debugging == ovly_auto)
2150 b->enable_state = bp_enabled;
2151 overlay_events_enabled = 1;
2155 b->enable_state = bp_disabled;
2156 overlay_events_enabled = 0;
2159 update_global_location_list (1);
2163 create_longjmp_master_breakpoint (char *func_name)
2165 struct program_space *pspace;
2166 struct objfile *objfile;
2167 struct cleanup *old_chain;
2169 old_chain = save_current_program_space ();
2171 ALL_PSPACES (pspace)
2172 ALL_OBJFILES (objfile)
2174 struct breakpoint *b;
2175 struct minimal_symbol *m;
2177 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2180 set_current_program_space (pspace);
2182 m = lookup_minimal_symbol_text (func_name, objfile);
2186 b = create_internal_breakpoint (get_objfile_arch (objfile),
2187 SYMBOL_VALUE_ADDRESS (m),
2189 b->addr_string = xstrdup (func_name);
2190 b->enable_state = bp_disabled;
2192 update_global_location_list (1);
2194 do_cleanups (old_chain);
2197 /* Create a master std::terminate breakpoint. The actual function
2198 looked for is named FUNC_NAME. */
2200 create_std_terminate_master_breakpoint (const char *func_name)
2202 struct program_space *pspace;
2203 struct objfile *objfile;
2204 struct cleanup *old_chain;
2206 old_chain = save_current_program_space ();
2208 ALL_PSPACES (pspace)
2209 ALL_OBJFILES (objfile)
2211 struct breakpoint *b;
2212 struct minimal_symbol *m;
2214 set_current_program_space (pspace);
2216 m = lookup_minimal_symbol (func_name, NULL, objfile);
2217 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2218 && MSYMBOL_TYPE (m) != mst_file_text))
2221 b = create_internal_breakpoint (get_objfile_arch (objfile),
2222 SYMBOL_VALUE_ADDRESS (m),
2223 bp_std_terminate_master);
2224 b->addr_string = xstrdup (func_name);
2225 b->enable_state = bp_disabled;
2227 update_global_location_list (1);
2229 do_cleanups (old_chain);
2233 update_breakpoints_after_exec (void)
2235 struct breakpoint *b;
2236 struct breakpoint *temp;
2237 struct bp_location *bploc, **bplocp_tmp;
2239 /* We're about to delete breakpoints from GDB's lists. If the
2240 INSERTED flag is true, GDB will try to lift the breakpoints by
2241 writing the breakpoints' "shadow contents" back into memory. The
2242 "shadow contents" are NOT valid after an exec, so GDB should not
2243 do that. Instead, the target is responsible from marking
2244 breakpoints out as soon as it detects an exec. We don't do that
2245 here instead, because there may be other attempts to delete
2246 breakpoints after detecting an exec and before reaching here. */
2247 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2248 if (bploc->pspace == current_program_space)
2249 gdb_assert (!bploc->inserted);
2251 ALL_BREAKPOINTS_SAFE (b, temp)
2253 if (b->pspace != current_program_space)
2256 /* Solib breakpoints must be explicitly reset after an exec(). */
2257 if (b->type == bp_shlib_event)
2259 delete_breakpoint (b);
2263 /* JIT breakpoints must be explicitly reset after an exec(). */
2264 if (b->type == bp_jit_event)
2266 delete_breakpoint (b);
2270 /* Thread event breakpoints must be set anew after an exec(),
2271 as must overlay event and longjmp master breakpoints. */
2272 if (b->type == bp_thread_event || b->type == bp_overlay_event
2273 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
2275 delete_breakpoint (b);
2279 /* Step-resume breakpoints are meaningless after an exec(). */
2280 if (b->type == bp_step_resume)
2282 delete_breakpoint (b);
2286 /* Longjmp and longjmp-resume breakpoints are also meaningless
2288 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
2290 delete_breakpoint (b);
2294 if (b->type == bp_catchpoint)
2296 /* For now, none of the bp_catchpoint breakpoints need to
2297 do anything at this point. In the future, if some of
2298 the catchpoints need to something, we will need to add
2299 a new method, and call this method from here. */
2303 /* bp_finish is a special case. The only way we ought to be able
2304 to see one of these when an exec() has happened, is if the user
2305 caught a vfork, and then said "finish". Ordinarily a finish just
2306 carries them to the call-site of the current callee, by setting
2307 a temporary bp there and resuming. But in this case, the finish
2308 will carry them entirely through the vfork & exec.
2310 We don't want to allow a bp_finish to remain inserted now. But
2311 we can't safely delete it, 'cause finish_command has a handle to
2312 the bp on a bpstat, and will later want to delete it. There's a
2313 chance (and I've seen it happen) that if we delete the bp_finish
2314 here, that its storage will get reused by the time finish_command
2315 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2316 We really must allow finish_command to delete a bp_finish.
2318 In the absense of a general solution for the "how do we know
2319 it's safe to delete something others may have handles to?"
2320 problem, what we'll do here is just uninsert the bp_finish, and
2321 let finish_command delete it.
2323 (We know the bp_finish is "doomed" in the sense that it's
2324 momentary, and will be deleted as soon as finish_command sees
2325 the inferior stopped. So it doesn't matter that the bp's
2326 address is probably bogus in the new a.out, unlike e.g., the
2327 solib breakpoints.) */
2329 if (b->type == bp_finish)
2334 /* Without a symbolic address, we have little hope of the
2335 pre-exec() address meaning the same thing in the post-exec()
2337 if (b->addr_string == NULL)
2339 delete_breakpoint (b);
2343 /* FIXME what about longjmp breakpoints? Re-create them here? */
2344 create_overlay_event_breakpoint ("_ovly_debug_event");
2345 create_longjmp_master_breakpoint ("longjmp");
2346 create_longjmp_master_breakpoint ("_longjmp");
2347 create_longjmp_master_breakpoint ("siglongjmp");
2348 create_longjmp_master_breakpoint ("_siglongjmp");
2349 create_std_terminate_master_breakpoint ("std::terminate()");
2353 detach_breakpoints (int pid)
2355 struct bp_location *b, **bp_tmp;
2357 struct cleanup *old_chain = save_inferior_ptid ();
2358 struct inferior *inf = current_inferior ();
2360 if (pid == PIDGET (inferior_ptid))
2361 error (_("Cannot detach breakpoints of inferior_ptid"));
2363 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2364 inferior_ptid = pid_to_ptid (pid);
2365 ALL_BP_LOCATIONS (b, bp_tmp)
2367 if (b->pspace != inf->pspace)
2371 val |= remove_breakpoint_1 (b, mark_inserted);
2373 do_cleanups (old_chain);
2377 /* Remove the breakpoint location B from the current address space.
2378 Note that this is used to detach breakpoints from a child fork.
2379 When we get here, the child isn't in the inferior list, and neither
2380 do we have objects to represent its address space --- we should
2381 *not* look at b->pspace->aspace here. */
2384 remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
2388 if (b->owner->enable_state == bp_permanent)
2389 /* Permanent breakpoints cannot be inserted or removed. */
2392 /* The type of none suggests that owner is actually deleted.
2393 This should not ever happen. */
2394 gdb_assert (b->owner->type != bp_none);
2396 if (b->loc_type == bp_loc_software_breakpoint
2397 || b->loc_type == bp_loc_hardware_breakpoint)
2399 /* "Normal" instruction breakpoint: either the standard
2400 trap-instruction bp (bp_breakpoint), or a
2401 bp_hardware_breakpoint. */
2403 /* First check to see if we have to handle an overlay. */
2404 if (overlay_debugging == ovly_off
2405 || b->section == NULL
2406 || !(section_is_overlay (b->section)))
2408 /* No overlay handling: just remove the breakpoint. */
2410 if (b->loc_type == bp_loc_hardware_breakpoint)
2411 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
2413 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
2417 /* This breakpoint is in an overlay section.
2418 Did we set a breakpoint at the LMA? */
2419 if (!overlay_events_enabled)
2421 /* Yes -- overlay event support is not active, so we
2422 should have set a breakpoint at the LMA. Remove it.
2424 /* Ignore any failures: if the LMA is in ROM, we will
2425 have already warned when we failed to insert it. */
2426 if (b->loc_type == bp_loc_hardware_breakpoint)
2427 target_remove_hw_breakpoint (b->gdbarch,
2428 &b->overlay_target_info);
2430 target_remove_breakpoint (b->gdbarch,
2431 &b->overlay_target_info);
2433 /* Did we set a breakpoint at the VMA?
2434 If so, we will have marked the breakpoint 'inserted'. */
2437 /* Yes -- remove it. Previously we did not bother to
2438 remove the breakpoint if the section had been
2439 unmapped, but let's not rely on that being safe. We
2440 don't know what the overlay manager might do. */
2441 if (b->loc_type == bp_loc_hardware_breakpoint)
2442 val = target_remove_hw_breakpoint (b->gdbarch,
2445 /* However, we should remove *software* breakpoints only
2446 if the section is still mapped, or else we overwrite
2447 wrong code with the saved shadow contents. */
2448 else if (section_is_mapped (b->section))
2449 val = target_remove_breakpoint (b->gdbarch,
2456 /* No -- not inserted, so no need to remove. No error. */
2461 /* In some cases, we might not be able to remove a breakpoint
2462 in a shared library that has already been removed, but we
2463 have not yet processed the shlib unload event. */
2464 if (val && solib_name_from_address (b->pspace, b->address))
2469 b->inserted = (is == mark_inserted);
2471 else if (b->loc_type == bp_loc_hardware_watchpoint)
2473 b->inserted = (is == mark_inserted);
2474 val = target_remove_watchpoint (b->address, b->length,
2475 b->watchpoint_type);
2477 /* Failure to remove any of the hardware watchpoints comes here. */
2478 if ((is == mark_uninserted) && (b->inserted))
2479 warning (_("Could not remove hardware watchpoint %d."),
2482 else if (b->owner->type == bp_catchpoint
2483 && breakpoint_enabled (b->owner)
2486 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
2488 val = b->owner->ops->remove (b->owner);
2491 b->inserted = (is == mark_inserted);
2498 remove_breakpoint (struct bp_location *b, insertion_state_t is)
2501 struct cleanup *old_chain;
2503 if (b->owner->enable_state == bp_permanent)
2504 /* Permanent breakpoints cannot be inserted or removed. */
2507 /* The type of none suggests that owner is actually deleted.
2508 This should not ever happen. */
2509 gdb_assert (b->owner->type != bp_none);
2511 old_chain = save_current_space_and_thread ();
2513 switch_to_program_space_and_thread (b->pspace);
2515 ret = remove_breakpoint_1 (b, is);
2517 do_cleanups (old_chain);
2521 /* Clear the "inserted" flag in all breakpoints. */
2524 mark_breakpoints_out (void)
2526 struct bp_location *bpt, **bptp_tmp;
2528 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2529 if (bpt->pspace == current_program_space)
2533 /* Clear the "inserted" flag in all breakpoints and delete any
2534 breakpoints which should go away between runs of the program.
2536 Plus other such housekeeping that has to be done for breakpoints
2539 Note: this function gets called at the end of a run (by
2540 generic_mourn_inferior) and when a run begins (by
2541 init_wait_for_inferior). */
2546 breakpoint_init_inferior (enum inf_context context)
2548 struct breakpoint *b, *temp;
2549 struct bp_location *bpt, **bptp_tmp;
2551 struct program_space *pspace = current_program_space;
2553 /* If breakpoint locations are shared across processes, then there's
2555 if (gdbarch_has_global_breakpoints (target_gdbarch))
2558 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2560 if (bpt->pspace == pspace
2561 && bpt->owner->enable_state != bp_permanent)
2565 ALL_BREAKPOINTS_SAFE (b, temp)
2567 if (b->loc && b->loc->pspace != pspace)
2574 /* If the call dummy breakpoint is at the entry point it will
2575 cause problems when the inferior is rerun, so we better get
2578 case bp_watchpoint_scope:
2580 /* Also get rid of scope breakpoints. */
2582 case bp_shlib_event:
2584 /* Also remove solib event breakpoints. Their addresses may
2585 have changed since the last time we ran the program.
2586 Actually we may now be debugging against different target;
2587 and so the solib backend that installed this breakpoint may
2588 not be used in by the target. E.g.,
2590 (gdb) file prog-linux
2591 (gdb) run # native linux target
2594 (gdb) file prog-win.exe
2595 (gdb) tar rem :9999 # remote Windows gdbserver.
2598 delete_breakpoint (b);
2602 case bp_hardware_watchpoint:
2603 case bp_read_watchpoint:
2604 case bp_access_watchpoint:
2606 /* Likewise for watchpoints on local expressions. */
2607 if (b->exp_valid_block != NULL)
2608 delete_breakpoint (b);
2609 else if (context == inf_starting)
2611 /* Reset val field to force reread of starting value
2612 in insert_breakpoints. */
2614 value_free (b->val);
2624 /* Get rid of the moribund locations. */
2625 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
2626 free_bp_location (bpt);
2627 VEC_free (bp_location_p, moribund_locations);
2630 /* These functions concern about actual breakpoints inserted in the
2631 target --- to e.g. check if we need to do decr_pc adjustment or if
2632 we need to hop over the bkpt --- so we check for address space
2633 match, not program space. */
2635 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2636 exists at PC. It returns ordinary_breakpoint_here if it's an
2637 ordinary breakpoint, or permanent_breakpoint_here if it's a
2638 permanent breakpoint.
2639 - When continuing from a location with an ordinary breakpoint, we
2640 actually single step once before calling insert_breakpoints.
2641 - When continuing from a localion with a permanent breakpoint, we
2642 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2643 the target, to advance the PC past the breakpoint. */
2645 enum breakpoint_here
2646 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2648 struct bp_location *bpt, **bptp_tmp;
2649 int any_breakpoint_here = 0;
2651 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2653 if (bpt->loc_type != bp_loc_software_breakpoint
2654 && bpt->loc_type != bp_loc_hardware_breakpoint)
2657 if ((breakpoint_enabled (bpt->owner)
2658 || bpt->owner->enable_state == bp_permanent)
2659 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2662 if (overlay_debugging
2663 && section_is_overlay (bpt->section)
2664 && !section_is_mapped (bpt->section))
2665 continue; /* unmapped overlay -- can't be a match */
2666 else if (bpt->owner->enable_state == bp_permanent)
2667 return permanent_breakpoint_here;
2669 any_breakpoint_here = 1;
2673 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2676 /* Return true if there's a moribund breakpoint at PC. */
2679 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2681 struct bp_location *loc;
2684 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2685 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2692 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2693 inserted using regular breakpoint_chain / bp_location array mechanism.
2694 This does not check for single-step breakpoints, which are
2695 inserted and removed using direct target manipulation. */
2698 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2700 struct bp_location *bpt, **bptp_tmp;
2702 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2704 if (bpt->loc_type != bp_loc_software_breakpoint
2705 && bpt->loc_type != bp_loc_hardware_breakpoint)
2709 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2712 if (overlay_debugging
2713 && section_is_overlay (bpt->section)
2714 && !section_is_mapped (bpt->section))
2715 continue; /* unmapped overlay -- can't be a match */
2723 /* Returns non-zero iff there's either regular breakpoint
2724 or a single step breakpoint inserted at PC. */
2727 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2729 if (regular_breakpoint_inserted_here_p (aspace, pc))
2732 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2738 /* This function returns non-zero iff there is a software breakpoint
2742 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2744 struct bp_location *bpt, **bptp_tmp;
2746 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2748 if (bpt->loc_type != bp_loc_software_breakpoint)
2752 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2755 if (overlay_debugging
2756 && section_is_overlay (bpt->section)
2757 && !section_is_mapped (bpt->section))
2758 continue; /* unmapped overlay -- can't be a match */
2764 /* Also check for software single-step breakpoints. */
2765 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2772 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2773 CORE_ADDR addr, ULONGEST len)
2775 struct breakpoint *bpt;
2777 ALL_BREAKPOINTS (bpt)
2779 struct bp_location *loc;
2781 if (bpt->type != bp_hardware_watchpoint
2782 && bpt->type != bp_access_watchpoint)
2785 if (!breakpoint_enabled (bpt))
2788 for (loc = bpt->loc; loc; loc = loc->next)
2789 if (loc->pspace->aspace == aspace && loc->inserted)
2793 /* Check for intersection. */
2794 l = max (loc->address, addr);
2795 h = min (loc->address + loc->length, addr + len);
2803 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2804 PC is valid for process/thread PTID. */
2807 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2810 struct bp_location *bpt, **bptp_tmp;
2811 /* The thread and task IDs associated to PTID, computed lazily. */
2815 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2817 if (bpt->loc_type != bp_loc_software_breakpoint
2818 && bpt->loc_type != bp_loc_hardware_breakpoint)
2821 if (!breakpoint_enabled (bpt->owner)
2822 && bpt->owner->enable_state != bp_permanent)
2825 if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2829 if (bpt->owner->thread != -1)
2831 /* This is a thread-specific breakpoint. Check that ptid
2832 matches that thread. If thread hasn't been computed yet,
2833 it is now time to do so. */
2835 thread = pid_to_thread_id (ptid);
2836 if (bpt->owner->thread != thread)
2840 if (bpt->owner->task != 0)
2842 /* This is a task-specific breakpoint. Check that ptid
2843 matches that task. If task hasn't been computed yet,
2844 it is now time to do so. */
2846 task = ada_get_task_number (ptid);
2847 if (bpt->owner->task != task)
2851 if (overlay_debugging
2852 && section_is_overlay (bpt->section)
2853 && !section_is_mapped (bpt->section))
2854 continue; /* unmapped overlay -- can't be a match */
2863 /* bpstat stuff. External routines' interfaces are documented
2867 ep_is_catchpoint (struct breakpoint *ep)
2869 return (ep->type == bp_catchpoint);
2873 bpstat_free (bpstat bs)
2875 if (bs->old_val != NULL)
2876 value_free (bs->old_val);
2877 decref_counted_command_line (&bs->commands);
2881 /* Clear a bpstat so that it says we are not at any breakpoint.
2882 Also free any storage that is part of a bpstat. */
2885 bpstat_clear (bpstat *bsp)
2902 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2903 is part of the bpstat is copied as well. */
2906 bpstat_copy (bpstat bs)
2910 bpstat retval = NULL;
2915 for (; bs != NULL; bs = bs->next)
2917 tmp = (bpstat) xmalloc (sizeof (*tmp));
2918 memcpy (tmp, bs, sizeof (*tmp));
2919 incref_counted_command_line (tmp->commands);
2920 if (bs->old_val != NULL)
2922 tmp->old_val = value_copy (bs->old_val);
2923 release_value (tmp->old_val);
2927 /* This is the first thing in the chain. */
2937 /* Find the bpstat associated with this breakpoint */
2940 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2945 for (; bsp != NULL; bsp = bsp->next)
2947 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2953 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2954 at. *BSP upon return is a bpstat which points to the remaining
2955 breakpoints stopped at (but which is not guaranteed to be good for
2956 anything but further calls to bpstat_num).
2957 Return 0 if passed a bpstat which does not indicate any breakpoints.
2958 Return -1 if stopped at a breakpoint that has been deleted since
2960 Return 1 otherwise. */
2963 bpstat_num (bpstat *bsp, int *num)
2965 struct breakpoint *b;
2968 return 0; /* No more breakpoint values */
2970 /* We assume we'll never have several bpstats that
2971 correspond to a single breakpoint -- otherwise,
2972 this function might return the same number more
2973 than once and this will look ugly. */
2974 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2975 *bsp = (*bsp)->next;
2977 return -1; /* breakpoint that's been deleted since */
2979 *num = b->number; /* We have its number */
2983 /* Modify BS so that the actions will not be performed. */
2986 bpstat_clear_actions (bpstat bs)
2988 for (; bs != NULL; bs = bs->next)
2990 decref_counted_command_line (&bs->commands);
2991 bs->commands_left = NULL;
2992 if (bs->old_val != NULL)
2994 value_free (bs->old_val);
3000 /* Called when a command is about to proceed the inferior. */
3003 breakpoint_about_to_proceed (void)
3005 if (!ptid_equal (inferior_ptid, null_ptid))
3007 struct thread_info *tp = inferior_thread ();
3009 /* Allow inferior function calls in breakpoint commands to not
3010 interrupt the command list. When the call finishes
3011 successfully, the inferior will be standing at the same
3012 breakpoint as if nothing happened. */
3017 breakpoint_proceeded = 1;
3020 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3022 cleanup_executing_breakpoints (void *ignore)
3024 executing_breakpoint_commands = 0;
3027 /* Execute all the commands associated with all the breakpoints at this
3028 location. Any of these commands could cause the process to proceed
3029 beyond this point, etc. We look out for such changes by checking
3030 the global "breakpoint_proceeded" after each command.
3032 Returns true if a breakpoint command resumed the inferior. In that
3033 case, it is the caller's responsibility to recall it again with the
3034 bpstat of the current thread. */
3037 bpstat_do_actions_1 (bpstat *bsp)
3040 struct cleanup *old_chain;
3043 /* Avoid endless recursion if a `source' command is contained
3045 if (executing_breakpoint_commands)
3048 executing_breakpoint_commands = 1;
3049 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3051 /* This pointer will iterate over the list of bpstat's. */
3054 breakpoint_proceeded = 0;
3055 for (; bs != NULL; bs = bs->next)
3057 struct counted_command_line *ccmd;
3058 struct command_line *cmd;
3059 struct cleanup *this_cmd_tree_chain;
3061 /* Take ownership of the BSP's command tree, if it has one.
3063 The command tree could legitimately contain commands like
3064 'step' and 'next', which call clear_proceed_status, which
3065 frees stop_bpstat's command tree. To make sure this doesn't
3066 free the tree we're executing out from under us, we need to
3067 take ownership of the tree ourselves. Since a given bpstat's
3068 commands are only executed once, we don't need to copy it; we
3069 can clear the pointer in the bpstat, and make sure we free
3070 the tree when we're done. */
3071 ccmd = bs->commands;
3072 bs->commands = NULL;
3074 = make_cleanup_decref_counted_command_line (&ccmd);
3075 cmd = bs->commands_left;
3076 bs->commands_left = NULL;
3080 execute_control_command (cmd);
3082 if (breakpoint_proceeded)
3088 /* We can free this command tree now. */
3089 do_cleanups (this_cmd_tree_chain);
3091 if (breakpoint_proceeded)
3093 if (target_can_async_p ())
3094 /* If we are in async mode, then the target might be still
3095 running, not stopped at any breakpoint, so nothing for
3096 us to do here -- just return to the event loop. */
3099 /* In sync mode, when execute_control_command returns
3100 we're already standing on the next breakpoint.
3101 Breakpoint commands for that stop were not run, since
3102 execute_command does not run breakpoint commands --
3103 only command_line_handler does, but that one is not
3104 involved in execution of breakpoint commands. So, we
3105 can now execute breakpoint commands. It should be
3106 noted that making execute_command do bpstat actions is
3107 not an option -- in this case we'll have recursive
3108 invocation of bpstat for each breakpoint with a
3109 command, and can easily blow up GDB stack. Instead, we
3110 return true, which will trigger the caller to recall us
3111 with the new stop_bpstat. */
3116 do_cleanups (old_chain);
3121 bpstat_do_actions (void)
3123 /* Do any commands attached to breakpoint we are stopped at. */
3124 while (!ptid_equal (inferior_ptid, null_ptid)
3125 && target_has_execution
3126 && !is_exited (inferior_ptid)
3127 && !is_executing (inferior_ptid))
3128 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3129 and only return when it is stopped at the next breakpoint, we
3130 keep doing breakpoint actions until it returns false to
3131 indicate the inferior was not resumed. */
3132 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
3136 /* Print out the (old or new) value associated with a watchpoint. */
3139 watchpoint_value_print (struct value *val, struct ui_file *stream)
3142 fprintf_unfiltered (stream, _("<unreadable>"));
3145 struct value_print_options opts;
3146 get_user_print_options (&opts);
3147 value_print (val, stream, &opts);
3151 /* This is the normal print function for a bpstat. In the future,
3152 much of this logic could (should?) be moved to bpstat_stop_status,
3153 by having it set different print_it values.
3155 Current scheme: When we stop, bpstat_print() is called. It loops
3156 through the bpstat list of things causing this stop, calling the
3157 print_bp_stop_message function on each one. The behavior of the
3158 print_bp_stop_message function depends on the print_it field of
3159 bpstat. If such field so indicates, call this function here.
3161 Return values from this routine (ultimately used by bpstat_print()
3162 and normal_stop() to decide what to do):
3163 PRINT_NOTHING: Means we already printed all we needed to print,
3164 don't print anything else.
3165 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3166 that something to be followed by a location.
3167 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3168 that something to be followed by a location.
3169 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3172 static enum print_stop_action
3173 print_it_typical (bpstat bs)
3175 struct cleanup *old_chain;
3176 struct breakpoint *b;
3177 const struct bp_location *bl;
3178 struct ui_stream *stb;
3180 enum print_stop_action result;
3182 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3183 which has since been deleted. */
3184 if (bs->breakpoint_at == NULL)
3185 return PRINT_UNKNOWN;
3186 bl = bs->breakpoint_at;
3189 stb = ui_out_stream_new (uiout);
3190 old_chain = make_cleanup_ui_out_stream_delete (stb);
3195 case bp_hardware_breakpoint:
3196 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
3197 if (bl->address != bl->requested_address)
3198 breakpoint_adjustment_warning (bl->requested_address,
3201 annotate_breakpoint (b->number);
3203 ui_out_text (uiout, "\nTemporary breakpoint ");
3205 ui_out_text (uiout, "\nBreakpoint ");
3206 if (ui_out_is_mi_like_p (uiout))
3208 ui_out_field_string (uiout, "reason",
3209 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3210 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3212 ui_out_field_int (uiout, "bkptno", b->number);
3213 ui_out_text (uiout, ", ");
3214 result = PRINT_SRC_AND_LOC;
3217 case bp_shlib_event:
3218 /* Did we stop because the user set the stop_on_solib_events
3219 variable? (If so, we report this as a generic, "Stopped due
3220 to shlib event" message.) */
3221 printf_filtered (_("Stopped due to shared library event\n"));
3222 result = PRINT_NOTHING;
3225 case bp_thread_event:
3226 /* Not sure how we will get here.
3227 GDB should not stop for these breakpoints. */
3228 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3229 result = PRINT_NOTHING;
3232 case bp_overlay_event:
3233 /* By analogy with the thread event, GDB should not stop for these. */
3234 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3235 result = PRINT_NOTHING;
3238 case bp_longjmp_master:
3239 /* These should never be enabled. */
3240 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3241 result = PRINT_NOTHING;
3244 case bp_std_terminate_master:
3245 /* These should never be enabled. */
3246 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3247 result = PRINT_NOTHING;
3251 case bp_hardware_watchpoint:
3252 annotate_watchpoint (b->number);
3253 if (ui_out_is_mi_like_p (uiout))
3256 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3258 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3259 ui_out_text (uiout, "\nOld value = ");
3260 watchpoint_value_print (bs->old_val, stb->stream);
3261 ui_out_field_stream (uiout, "old", stb);
3262 ui_out_text (uiout, "\nNew value = ");
3263 watchpoint_value_print (b->val, stb->stream);
3264 ui_out_field_stream (uiout, "new", stb);
3265 ui_out_text (uiout, "\n");
3266 /* More than one watchpoint may have been triggered. */
3267 result = PRINT_UNKNOWN;
3270 case bp_read_watchpoint:
3271 if (ui_out_is_mi_like_p (uiout))
3274 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3276 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3277 ui_out_text (uiout, "\nValue = ");
3278 watchpoint_value_print (b->val, stb->stream);
3279 ui_out_field_stream (uiout, "value", stb);
3280 ui_out_text (uiout, "\n");
3281 result = PRINT_UNKNOWN;
3284 case bp_access_watchpoint:
3285 if (bs->old_val != NULL)
3287 annotate_watchpoint (b->number);
3288 if (ui_out_is_mi_like_p (uiout))
3291 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3293 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3294 ui_out_text (uiout, "\nOld value = ");
3295 watchpoint_value_print (bs->old_val, stb->stream);
3296 ui_out_field_stream (uiout, "old", stb);
3297 ui_out_text (uiout, "\nNew value = ");
3302 if (ui_out_is_mi_like_p (uiout))
3305 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3306 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3307 ui_out_text (uiout, "\nValue = ");
3309 watchpoint_value_print (b->val, stb->stream);
3310 ui_out_field_stream (uiout, "new", stb);
3311 ui_out_text (uiout, "\n");
3312 result = PRINT_UNKNOWN;
3315 /* Fall through, we don't deal with these types of breakpoints
3319 if (ui_out_is_mi_like_p (uiout))
3322 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3323 result = PRINT_UNKNOWN;
3327 if (ui_out_is_mi_like_p (uiout))
3330 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3331 result = PRINT_UNKNOWN;
3336 case bp_longjmp_resume:
3337 case bp_step_resume:
3338 case bp_watchpoint_scope:
3340 case bp_std_terminate:
3342 case bp_fast_tracepoint:
3345 result = PRINT_UNKNOWN;
3349 do_cleanups (old_chain);
3353 /* Generic routine for printing messages indicating why we
3354 stopped. The behavior of this function depends on the value
3355 'print_it' in the bpstat structure. Under some circumstances we
3356 may decide not to print anything here and delegate the task to
3359 static enum print_stop_action
3360 print_bp_stop_message (bpstat bs)
3362 switch (bs->print_it)
3365 /* Nothing should be printed for this bpstat entry. */
3366 return PRINT_UNKNOWN;
3370 /* We still want to print the frame, but we already printed the
3371 relevant messages. */
3372 return PRINT_SRC_AND_LOC;
3375 case print_it_normal:
3377 const struct bp_location *bl = bs->breakpoint_at;
3378 struct breakpoint *b = bl ? bl->owner : NULL;
3380 /* Normal case. Call the breakpoint's print_it method, or
3381 print_it_typical. */
3382 /* FIXME: how breakpoint can ever be NULL here? */
3383 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3384 return b->ops->print_it (b);
3386 return print_it_typical (bs);
3391 internal_error (__FILE__, __LINE__,
3392 _("print_bp_stop_message: unrecognized enum value"));
3397 /* Print a message indicating what happened. This is called from
3398 normal_stop(). The input to this routine is the head of the bpstat
3399 list - a list of the eventpoints that caused this stop. This
3400 routine calls the generic print routine for printing a message
3401 about reasons for stopping. This will print (for example) the
3402 "Breakpoint n," part of the output. The return value of this
3405 PRINT_UNKNOWN: Means we printed nothing
3406 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3407 code to print the location. An example is
3408 "Breakpoint 1, " which should be followed by
3410 PRINT_SRC_ONLY: Means we printed something, but there is no need
3411 to also print the location part of the message.
3412 An example is the catch/throw messages, which
3413 don't require a location appended to the end.
3414 PRINT_NOTHING: We have done some printing and we don't need any
3415 further info to be printed.*/
3417 enum print_stop_action
3418 bpstat_print (bpstat bs)
3422 /* Maybe another breakpoint in the chain caused us to stop.
3423 (Currently all watchpoints go on the bpstat whether hit or not.
3424 That probably could (should) be changed, provided care is taken
3425 with respect to bpstat_explains_signal). */
3426 for (; bs; bs = bs->next)
3428 val = print_bp_stop_message (bs);
3429 if (val == PRINT_SRC_ONLY
3430 || val == PRINT_SRC_AND_LOC
3431 || val == PRINT_NOTHING)
3435 /* We reached the end of the chain, or we got a null BS to start
3436 with and nothing was printed. */
3437 return PRINT_UNKNOWN;
3440 /* Evaluate the expression EXP and return 1 if value is zero.
3441 This is used inside a catch_errors to evaluate the breakpoint condition.
3442 The argument is a "struct expression *" that has been cast to char * to
3443 make it pass through catch_errors. */
3446 breakpoint_cond_eval (void *exp)
3448 struct value *mark = value_mark ();
3449 int i = !value_true (evaluate_expression ((struct expression *) exp));
3450 value_free_to_mark (mark);
3454 /* Allocate a new bpstat and chain it to the current one. */
3457 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
3461 bs = (bpstat) xmalloc (sizeof (*bs));
3463 bs->breakpoint_at = bl;
3464 /* If the condition is false, etc., don't do the commands. */
3465 bs->commands = NULL;
3466 bs->commands_left = NULL;
3468 bs->print_it = print_it_normal;
3472 /* The target has stopped with waitstatus WS. Check if any hardware
3473 watchpoints have triggered, according to the target. */
3476 watchpoints_triggered (struct target_waitstatus *ws)
3478 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3480 struct breakpoint *b;
3482 if (!stopped_by_watchpoint)
3484 /* We were not stopped by a watchpoint. Mark all watchpoints
3485 as not triggered. */
3487 if (is_hardware_watchpoint (b))
3488 b->watchpoint_triggered = watch_triggered_no;
3493 if (!target_stopped_data_address (¤t_target, &addr))
3495 /* We were stopped by a watchpoint, but we don't know where.
3496 Mark all watchpoints as unknown. */
3498 if (is_hardware_watchpoint (b))
3499 b->watchpoint_triggered = watch_triggered_unknown;
3501 return stopped_by_watchpoint;
3504 /* The target could report the data address. Mark watchpoints
3505 affected by this data address as triggered, and all others as not
3509 if (is_hardware_watchpoint (b))
3511 struct bp_location *loc;
3513 b->watchpoint_triggered = watch_triggered_no;
3514 for (loc = b->loc; loc; loc = loc->next)
3515 /* Exact match not required. Within range is
3517 if (target_watchpoint_addr_within_range (¤t_target,
3521 b->watchpoint_triggered = watch_triggered_yes;
3529 /* Possible return values for watchpoint_check (this can't be an enum
3530 because of check_errors). */
3531 /* The watchpoint has been deleted. */
3532 #define WP_DELETED 1
3533 /* The value has changed. */
3534 #define WP_VALUE_CHANGED 2
3535 /* The value has not changed. */
3536 #define WP_VALUE_NOT_CHANGED 3
3537 /* Ignore this watchpoint, no matter if the value changed or not. */
3540 #define BP_TEMPFLAG 1
3541 #define BP_HARDWAREFLAG 2
3543 /* Evaluate watchpoint condition expression and check if its value changed.
3545 P should be a pointer to struct bpstat, but is defined as a void *
3546 in order for this function to be usable with catch_errors. */
3549 watchpoint_check (void *p)
3551 bpstat bs = (bpstat) p;
3552 struct breakpoint *b;
3553 struct frame_info *fr;
3554 int within_current_scope;
3556 b = bs->breakpoint_at->owner;
3558 /* If this is a local watchpoint, we only want to check if the
3559 watchpoint frame is in scope if the current thread is the thread
3560 that was used to create the watchpoint. */
3561 if (!watchpoint_in_thread_scope (b))
3564 if (b->exp_valid_block == NULL)
3565 within_current_scope = 1;
3568 struct frame_info *frame = get_current_frame ();
3569 struct gdbarch *frame_arch = get_frame_arch (frame);
3570 CORE_ADDR frame_pc = get_frame_pc (frame);
3572 /* in_function_epilogue_p() returns a non-zero value if we're still
3573 in the function but the stack frame has already been invalidated.
3574 Since we can't rely on the values of local variables after the
3575 stack has been destroyed, we are treating the watchpoint in that
3576 state as `not changed' without further checking. Don't mark
3577 watchpoints as changed if the current frame is in an epilogue -
3578 even if they are in some other frame, our view of the stack
3579 is likely to be wrong and frame_find_by_id could error out. */
3580 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3583 fr = frame_find_by_id (b->watchpoint_frame);
3584 within_current_scope = (fr != NULL);
3586 /* If we've gotten confused in the unwinder, we might have
3587 returned a frame that can't describe this variable. */
3588 if (within_current_scope)
3590 struct symbol *function;
3592 function = get_frame_function (fr);
3593 if (function == NULL
3594 || !contained_in (b->exp_valid_block,
3595 SYMBOL_BLOCK_VALUE (function)))
3596 within_current_scope = 0;
3599 if (within_current_scope)
3600 /* If we end up stopping, the current frame will get selected
3601 in normal_stop. So this call to select_frame won't affect
3606 if (within_current_scope)
3608 /* We use value_{,free_to_}mark because it could be a
3609 *long* time before we return to the command level and
3610 call free_all_values. We can't call free_all_values because
3611 we might be in the middle of evaluating a function call. */
3613 struct value *mark = value_mark ();
3614 struct value *new_val;
3616 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
3618 /* We use value_equal_contents instead of value_equal because the latter
3619 coerces an array to a pointer, thus comparing just the address of the
3620 array instead of its contents. This is not what we want. */
3621 if ((b->val != NULL) != (new_val != NULL)
3622 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3624 if (new_val != NULL)
3626 release_value (new_val);
3627 value_free_to_mark (mark);
3629 bs->old_val = b->val;
3632 return WP_VALUE_CHANGED;
3636 /* Nothing changed. */
3637 value_free_to_mark (mark);
3638 return WP_VALUE_NOT_CHANGED;
3643 /* This seems like the only logical thing to do because
3644 if we temporarily ignored the watchpoint, then when
3645 we reenter the block in which it is valid it contains
3646 garbage (in the case of a function, it may have two
3647 garbage values, one before and one after the prologue).
3648 So we can't even detect the first assignment to it and
3649 watch after that (since the garbage may or may not equal
3650 the first value assigned). */
3651 /* We print all the stop information in print_it_typical(), but
3652 in this case, by the time we call print_it_typical() this bp
3653 will be deleted already. So we have no choice but print the
3654 information here. */
3655 if (ui_out_is_mi_like_p (uiout))
3657 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3658 ui_out_text (uiout, "\nWatchpoint ");
3659 ui_out_field_int (uiout, "wpnum", b->number);
3660 ui_out_text (uiout, " deleted because the program has left the block in\n\
3661 which its expression is valid.\n");
3663 if (b->related_breakpoint)
3665 b->related_breakpoint->disposition = disp_del_at_next_stop;
3666 b->related_breakpoint->related_breakpoint = NULL;
3667 b->related_breakpoint = NULL;
3669 b->disposition = disp_del_at_next_stop;
3675 /* Return true if it looks like target has stopped due to hitting
3676 breakpoint location BL. This function does not check if we
3677 should stop, only if BL explains the stop. */
3679 bpstat_check_location (const struct bp_location *bl,
3680 struct address_space *aspace, CORE_ADDR bp_addr)
3682 struct breakpoint *b = bl->owner;
3684 /* By definition, the inferior does not report stops at
3686 if (is_tracepoint (b))
3689 if (!is_watchpoint (b)
3690 && b->type != bp_hardware_breakpoint
3691 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3693 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3696 if (overlay_debugging /* unmapped overlay section */
3697 && section_is_overlay (bl->section)
3698 && !section_is_mapped (bl->section))
3702 /* Continuable hardware watchpoints are treated as non-existent if the
3703 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3704 some data address). Otherwise gdb won't stop on a break instruction
3705 in the code (not from a breakpoint) when a hardware watchpoint has
3706 been defined. Also skip watchpoints which we know did not trigger
3707 (did not match the data address). */
3709 if (is_hardware_watchpoint (b)
3710 && b->watchpoint_triggered == watch_triggered_no)
3713 if (b->type == bp_hardware_breakpoint)
3715 if (bl->address != bp_addr)
3717 if (overlay_debugging /* unmapped overlay section */
3718 && section_is_overlay (bl->section)
3719 && !section_is_mapped (bl->section))
3723 if (b->type == bp_catchpoint)
3725 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3726 if (!b->ops->breakpoint_hit (b))
3733 /* If BS refers to a watchpoint, determine if the watched values
3734 has actually changed, and we should stop. If not, set BS->stop
3737 bpstat_check_watchpoint (bpstat bs)
3739 const struct bp_location *bl = bs->breakpoint_at;
3740 struct breakpoint *b = bl->owner;
3742 if (is_watchpoint (b))
3744 int must_check_value = 0;
3746 if (b->type == bp_watchpoint)
3747 /* For a software watchpoint, we must always check the
3749 must_check_value = 1;
3750 else if (b->watchpoint_triggered == watch_triggered_yes)
3751 /* We have a hardware watchpoint (read, write, or access)
3752 and the target earlier reported an address watched by
3754 must_check_value = 1;
3755 else if (b->watchpoint_triggered == watch_triggered_unknown
3756 && b->type == bp_hardware_watchpoint)
3757 /* We were stopped by a hardware watchpoint, but the target could
3758 not report the data address. We must check the watchpoint's
3759 value. Access and read watchpoints are out of luck; without
3760 a data address, we can't figure it out. */
3761 must_check_value = 1;
3763 if (must_check_value)
3765 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3767 struct cleanup *cleanups = make_cleanup (xfree, message);
3768 int e = catch_errors (watchpoint_check, bs, message,
3770 do_cleanups (cleanups);
3774 /* We've already printed what needs to be printed. */
3775 bs->print_it = print_it_done;
3779 bs->print_it = print_it_noop;
3782 case WP_VALUE_CHANGED:
3783 if (b->type == bp_read_watchpoint)
3785 /* There are two cases to consider here:
3787 1. we're watching the triggered memory for reads.
3788 In that case, trust the target, and always report
3789 the watchpoint hit to the user. Even though
3790 reads don't cause value changes, the value may
3791 have changed since the last time it was read, and
3792 since we're not trapping writes, we will not see
3793 those, and as such we should ignore our notion of
3796 2. we're watching the triggered memory for both
3797 reads and writes. There are two ways this may
3800 2.1. this is a target that can't break on data
3801 reads only, but can break on accesses (reads or
3802 writes), such as e.g., x86. We detect this case
3803 at the time we try to insert read watchpoints.
3805 2.2. otherwise, the target supports read
3806 watchpoints, but, the user set an access or write
3807 watchpoint watching the same memory as this read
3810 If we're watching memory writes as well as reads,
3811 ignore watchpoint hits when we find that the
3812 value hasn't changed, as reads don't cause
3813 changes. This still gives false positives when
3814 the program writes the same value to memory as
3815 what there was already in memory (we will confuse
3816 it for a read), but it's much better than
3819 int other_write_watchpoint = 0;
3821 if (bl->watchpoint_type == hw_read)
3823 struct breakpoint *other_b;
3825 ALL_BREAKPOINTS (other_b)
3826 if ((other_b->type == bp_hardware_watchpoint
3827 || other_b->type == bp_access_watchpoint)
3828 && (other_b->watchpoint_triggered
3829 == watch_triggered_yes))
3831 other_write_watchpoint = 1;
3836 if (other_write_watchpoint
3837 || bl->watchpoint_type == hw_access)
3839 /* We're watching the same memory for writes,
3840 and the value changed since the last time we
3841 updated it, so this trap must be for a write.
3843 bs->print_it = print_it_noop;
3848 case WP_VALUE_NOT_CHANGED:
3849 if (b->type == bp_hardware_watchpoint
3850 || b->type == bp_watchpoint)
3852 /* Don't stop: write watchpoints shouldn't fire if
3853 the value hasn't changed. */
3854 bs->print_it = print_it_noop;
3862 /* Error from catch_errors. */
3863 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3864 if (b->related_breakpoint)
3865 b->related_breakpoint->disposition = disp_del_at_next_stop;
3866 b->disposition = disp_del_at_next_stop;
3867 /* We've already printed what needs to be printed. */
3868 bs->print_it = print_it_done;
3872 else /* must_check_value == 0 */
3874 /* This is a case where some watchpoint(s) triggered, but
3875 not at the address of this watchpoint, or else no
3876 watchpoint triggered after all. So don't print
3877 anything for this watchpoint. */
3878 bs->print_it = print_it_noop;
3885 /* Check conditions (condition proper, frame, thread and ignore count)
3886 of breakpoint referred to by BS. If we should not stop for this
3887 breakpoint, set BS->stop to 0. */
3889 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3891 int thread_id = pid_to_thread_id (ptid);
3892 const struct bp_location *bl = bs->breakpoint_at;
3893 struct breakpoint *b = bl->owner;
3895 if (frame_id_p (b->frame_id)
3896 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3900 int value_is_zero = 0;
3901 struct expression *cond;
3903 /* If this is a scope breakpoint, mark the associated
3904 watchpoint as triggered so that we will handle the
3905 out-of-scope event. We'll get to the watchpoint next
3907 if (b->type == bp_watchpoint_scope)
3908 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3910 if (is_watchpoint (b))
3915 if (cond && bl->owner->disposition != disp_del_at_next_stop)
3917 int within_current_scope = 1;
3919 /* We use value_mark and value_free_to_mark because it could
3920 be a long time before we return to the command level and
3921 call free_all_values. We can't call free_all_values
3922 because we might be in the middle of evaluating a
3924 struct value *mark = value_mark ();
3926 /* Need to select the frame, with all that implies so that
3927 the conditions will have the right context. Because we
3928 use the frame, we will not see an inlined function's
3929 variables when we arrive at a breakpoint at the start
3930 of the inlined function; the current frame will be the
3932 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
3933 select_frame (get_current_frame ());
3936 struct frame_info *frame;
3938 /* For local watchpoint expressions, which particular
3939 instance of a local is being watched matters, so we
3940 keep track of the frame to evaluate the expression
3941 in. To evaluate the condition however, it doesn't
3942 really matter which instantiation of the function
3943 where the condition makes sense triggers the
3944 watchpoint. This allows an expression like "watch
3945 global if q > 10" set in `func', catch writes to
3946 global on all threads that call `func', or catch
3947 writes on all recursive calls of `func' by a single
3948 thread. We simply always evaluate the condition in
3949 the innermost frame that's executing where it makes
3950 sense to evaluate the condition. It seems
3952 frame = block_innermost_frame (b->cond_exp_valid_block);
3954 select_frame (frame);
3956 within_current_scope = 0;
3958 if (within_current_scope)
3960 = catch_errors (breakpoint_cond_eval, cond,
3961 "Error in testing breakpoint condition:\n",
3965 warning (_("Watchpoint condition cannot be tested "
3966 "in the current scope"));
3967 /* If we failed to set the right context for this
3968 watchpoint, unconditionally report it. */
3971 /* FIXME-someday, should give breakpoint # */
3972 value_free_to_mark (mark);
3975 if (cond && value_is_zero)
3979 else if (b->thread != -1 && b->thread != thread_id)
3983 else if (b->ignore_count > 0)
3986 annotate_ignore_count_change ();
3988 /* Increase the hit count even though we don't
3996 /* Get a bpstat associated with having just stopped at address
3997 BP_ADDR in thread PTID.
3999 Determine whether we stopped at a breakpoint, etc, or whether we
4000 don't understand this stop. Result is a chain of bpstat's such that:
4002 if we don't understand the stop, the result is a null pointer.
4004 if we understand why we stopped, the result is not null.
4006 Each element of the chain refers to a particular breakpoint or
4007 watchpoint at which we have stopped. (We may have stopped for
4008 several reasons concurrently.)
4010 Each element of the chain has valid next, breakpoint_at,
4011 commands, FIXME??? fields. */
4014 bpstat_stop_status (struct address_space *aspace,
4015 CORE_ADDR bp_addr, ptid_t ptid)
4017 struct breakpoint *b = NULL;
4018 struct bp_location *bl;
4019 struct bp_location *loc;
4020 /* Root of the chain of bpstat's */
4021 struct bpstats root_bs[1];
4022 /* Pointer to the last thing in the chain currently. */
4023 bpstat bs = root_bs;
4025 int need_remove_insert;
4027 /* ALL_BP_LOCATIONS iteration would break across
4028 update_global_location_list possibly executed by
4029 bpstat_check_breakpoint_conditions's inferior call. */
4033 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4036 for (bl = b->loc; bl != NULL; bl = bl->next)
4038 /* For hardware watchpoints, we look only at the first location.
4039 The watchpoint_check function will work on the entire expression,
4040 not the individual locations. For read watchpoints, the
4041 watchpoints_triggered function has checked all locations
4043 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4046 if (bl->shlib_disabled)
4049 if (!bpstat_check_location (bl, aspace, bp_addr))
4052 /* Come here if it's a watchpoint, or if the break address matches */
4054 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
4056 /* Assume we stop. Should we find watchpoint that is not actually
4057 triggered, or if condition of breakpoint is false, we'll reset
4062 bpstat_check_watchpoint (bs);
4066 if (b->type == bp_thread_event || b->type == bp_overlay_event
4067 || b->type == bp_longjmp_master
4068 || b->type == bp_std_terminate_master)
4069 /* We do not stop for these. */
4072 bpstat_check_breakpoint_conditions (bs, ptid);
4078 /* We will stop here */
4079 if (b->disposition == disp_disable)
4081 if (b->enable_state != bp_permanent)
4082 b->enable_state = bp_disabled;
4083 update_global_location_list (0);
4087 bs->commands = b->commands;
4088 incref_counted_command_line (bs->commands);
4089 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4090 if (bs->commands_left
4091 && (strcmp ("silent", bs->commands_left->line) == 0
4094 bs->commands_left->line) == 0)))
4096 bs->commands_left = bs->commands_left->next;
4101 /* Print nothing for this entry if we dont stop or dont print. */
4102 if (bs->stop == 0 || bs->print == 0)
4103 bs->print_it = print_it_noop;
4107 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4109 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4112 bs = bpstat_alloc (loc, bs);
4113 /* For hits of moribund locations, we should just proceed. */
4116 bs->print_it = print_it_noop;
4120 bs->next = NULL; /* Terminate the chain */
4122 /* If we aren't stopping, the value of some hardware watchpoint may
4123 not have changed, but the intermediate memory locations we are
4124 watching may have. Don't bother if we're stopping; this will get
4126 need_remove_insert = 0;
4127 if (! bpstat_causes_stop (root_bs->next))
4128 for (bs = root_bs->next; bs != NULL; bs = bs->next)
4130 && bs->breakpoint_at->owner
4131 && is_hardware_watchpoint (bs->breakpoint_at->owner))
4133 update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */);
4134 /* Updating watchpoints invalidates bs->breakpoint_at.
4135 Prevent further code from trying to use it. */
4136 bs->breakpoint_at = NULL;
4137 need_remove_insert = 1;
4140 if (need_remove_insert)
4141 update_global_location_list (1);
4143 return root_bs->next;
4146 /* Tell what to do about this bpstat. */
4148 bpstat_what (bpstat bs)
4150 /* Classify each bpstat as one of the following. */
4153 /* This bpstat element has no effect on the main_action. */
4156 /* There was a watchpoint, stop but don't print. */
4159 /* There was a watchpoint, stop and print. */
4162 /* There was a breakpoint but we're not stopping. */
4165 /* There was a breakpoint, stop but don't print. */
4168 /* There was a breakpoint, stop and print. */
4171 /* We hit the longjmp breakpoint. */
4174 /* We hit the longjmp_resume breakpoint. */
4177 /* We hit the step_resume breakpoint. */
4180 /* We hit the shared library event breakpoint. */
4183 /* We hit the jit event breakpoint. */
4186 /* This is just used to count how many enums there are. */
4190 /* Here is the table which drives this routine. So that we can
4191 format it pretty, we define some abbreviations for the
4192 enum bpstat_what codes. */
4193 #define kc BPSTAT_WHAT_KEEP_CHECKING
4194 #define ss BPSTAT_WHAT_STOP_SILENT
4195 #define sn BPSTAT_WHAT_STOP_NOISY
4196 #define sgl BPSTAT_WHAT_SINGLE
4197 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4198 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4199 #define sr BPSTAT_WHAT_STEP_RESUME
4200 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4201 #define jit BPSTAT_WHAT_CHECK_JIT
4203 /* "Can't happen." Might want to print an error message.
4204 abort() is not out of the question, but chances are GDB is just
4205 a bit confused, not unusable. */
4206 #define err BPSTAT_WHAT_STOP_NOISY
4208 /* Given an old action and a class, come up with a new action. */
4209 /* One interesting property of this table is that wp_silent is the same
4210 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4211 after stopping, the check for whether to step over a breakpoint
4212 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4213 reference to how we stopped. We retain separate wp_silent and
4214 bp_silent codes in case we want to change that someday.
4216 Another possibly interesting property of this table is that
4217 there's a partial ordering, priority-like, of the actions. Once
4218 you've decided that some action is appropriate, you'll never go
4219 back and decide something of a lower priority is better. The
4222 kc < jit clr sgl shl slr sn sr ss
4223 sgl < jit shl slr sn sr ss
4224 slr < jit err shl sn sr ss
4225 clr < jit err shl sn sr ss
4232 What I think this means is that we don't need a damned table
4233 here. If you just put the rows and columns in the right order,
4234 it'd look awfully regular. We could simply walk the bpstat list
4235 and choose the highest priority action we find, with a little
4236 logic to handle the 'err' cases. */
4238 /* step_resume entries: a step resume breakpoint overrides another
4239 breakpoint of signal handling (see comment in wait_for_inferior
4240 at where we set the step_resume breakpoint). */
4242 static const enum bpstat_what_main_action
4243 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
4246 /* kc ss sn sgl slr clr sr shl jit */
4247 /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit},
4248 /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
4249 /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
4250 /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit},
4251 /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
4252 /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
4253 /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit},
4254 /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit},
4255 /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr },
4256 /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl},
4257 /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit}
4271 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
4272 struct bpstat_what retval;
4274 retval.call_dummy = STOP_NONE;
4275 for (; bs != NULL; bs = bs->next)
4277 enum class bs_class = no_effect;
4278 if (bs->breakpoint_at == NULL)
4279 /* I suspect this can happen if it was a momentary breakpoint
4280 which has since been deleted. */
4282 if (bs->breakpoint_at->owner == NULL)
4283 bs_class = bp_nostop;
4285 switch (bs->breakpoint_at->owner->type)
4291 case bp_hardware_breakpoint:
4297 bs_class = bp_noisy;
4299 bs_class = bp_silent;
4302 bs_class = bp_nostop;
4305 case bp_hardware_watchpoint:
4306 case bp_read_watchpoint:
4307 case bp_access_watchpoint:
4311 bs_class = wp_noisy;
4313 bs_class = wp_silent;
4316 /* There was a watchpoint, but we're not stopping.
4317 This requires no further action. */
4318 bs_class = no_effect;
4321 bs_class = long_jump;
4323 case bp_longjmp_resume:
4324 bs_class = long_resume;
4326 case bp_step_resume:
4329 bs_class = step_resume;
4332 /* It is for the wrong frame. */
4333 bs_class = bp_nostop;
4335 case bp_watchpoint_scope:
4336 bs_class = bp_nostop;
4338 case bp_shlib_event:
4339 bs_class = shlib_event;
4342 bs_class = jit_event;
4344 case bp_thread_event:
4345 case bp_overlay_event:
4346 case bp_longjmp_master:
4347 case bp_std_terminate_master:
4348 bs_class = bp_nostop;
4354 bs_class = bp_noisy;
4356 bs_class = bp_silent;
4359 /* There was a catchpoint, but we're not stopping.
4360 This requires no further action. */
4361 bs_class = no_effect;
4364 /* Make sure the action is stop (silent or noisy),
4365 so infrun.c pops the dummy frame. */
4366 bs_class = bp_silent;
4367 retval.call_dummy = STOP_STACK_DUMMY;
4369 case bp_std_terminate:
4370 /* Make sure the action is stop (silent or noisy),
4371 so infrun.c pops the dummy frame. */
4372 bs_class = bp_silent;
4373 retval.call_dummy = STOP_STD_TERMINATE;
4376 case bp_fast_tracepoint:
4377 /* Tracepoint hits should not be reported back to GDB, and
4378 if one got through somehow, it should have been filtered
4380 internal_error (__FILE__, __LINE__,
4381 _("bpstat_what: tracepoint encountered"));
4384 current_action = table[(int) bs_class][(int) current_action];
4386 retval.main_action = current_action;
4390 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4391 without hardware support). This isn't related to a specific bpstat,
4392 just to things like whether watchpoints are set. */
4395 bpstat_should_step (void)
4397 struct breakpoint *b;
4399 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4405 bpstat_causes_stop (bpstat bs)
4407 for (; bs != NULL; bs = bs->next)
4416 /* Print the LOC location out of the list of B->LOC locations. */
4418 static void print_breakpoint_location (struct breakpoint *b,
4419 struct bp_location *loc,
4421 struct ui_stream *stb)
4423 struct cleanup *old_chain = save_current_program_space ();
4425 if (loc != NULL && loc->shlib_disabled)
4429 set_current_program_space (loc->pspace);
4431 if (b->source_file && loc)
4434 = find_pc_sect_function (loc->address, loc->section);
4437 ui_out_text (uiout, "in ");
4438 ui_out_field_string (uiout, "func",
4439 SYMBOL_PRINT_NAME (sym));
4440 ui_out_wrap_hint (uiout, wrap_indent);
4441 ui_out_text (uiout, " at ");
4443 ui_out_field_string (uiout, "file", b->source_file);
4444 ui_out_text (uiout, ":");
4446 if (ui_out_is_mi_like_p (uiout))
4448 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4449 char *fullname = symtab_to_fullname (sal.symtab);
4452 ui_out_field_string (uiout, "fullname", fullname);
4455 ui_out_field_int (uiout, "line", b->line_number);
4459 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4461 ui_out_field_stream (uiout, "at", stb);
4464 ui_out_field_string (uiout, "pending", b->addr_string);
4466 do_cleanups (old_chain);
4469 /* Print B to gdb_stdout. */
4471 print_one_breakpoint_location (struct breakpoint *b,
4472 struct bp_location *loc,
4474 struct bp_location **last_loc,
4475 int print_address_bits,
4478 struct command_line *l;
4479 struct ep_type_description
4484 static struct ep_type_description bptypes[] =
4486 {bp_none, "?deleted?"},
4487 {bp_breakpoint, "breakpoint"},
4488 {bp_hardware_breakpoint, "hw breakpoint"},
4489 {bp_until, "until"},
4490 {bp_finish, "finish"},
4491 {bp_watchpoint, "watchpoint"},
4492 {bp_hardware_watchpoint, "hw watchpoint"},
4493 {bp_read_watchpoint, "read watchpoint"},
4494 {bp_access_watchpoint, "acc watchpoint"},
4495 {bp_longjmp, "longjmp"},
4496 {bp_longjmp_resume, "longjmp resume"},
4497 {bp_step_resume, "step resume"},
4498 {bp_watchpoint_scope, "watchpoint scope"},
4499 {bp_call_dummy, "call dummy"},
4500 {bp_std_terminate, "std::terminate"},
4501 {bp_shlib_event, "shlib events"},
4502 {bp_thread_event, "thread events"},
4503 {bp_overlay_event, "overlay events"},
4504 {bp_longjmp_master, "longjmp master"},
4505 {bp_std_terminate_master, "std::terminate master"},
4506 {bp_catchpoint, "catchpoint"},
4507 {bp_tracepoint, "tracepoint"},
4508 {bp_fast_tracepoint, "fast tracepoint"},
4509 {bp_jit_event, "jit events"},
4512 static char bpenables[] = "nynny";
4513 char wrap_indent[80];
4514 struct ui_stream *stb = ui_out_stream_new (uiout);
4515 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4516 struct cleanup *bkpt_chain;
4518 int header_of_multiple = 0;
4519 int part_of_multiple = (loc != NULL);
4520 struct value_print_options opts;
4522 get_user_print_options (&opts);
4524 gdb_assert (!loc || loc_number != 0);
4525 /* See comment in print_one_breakpoint concerning
4526 treatment of breakpoints with single disabled
4530 && (b->loc->next != NULL || !b->loc->enabled)))
4531 header_of_multiple = 1;
4536 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4540 if (part_of_multiple)
4543 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4544 ui_out_field_string (uiout, "number", formatted);
4549 ui_out_field_int (uiout, "number", b->number);
4554 if (part_of_multiple)
4555 ui_out_field_skip (uiout, "type");
4558 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4559 || ((int) b->type != bptypes[(int) b->type].type))
4560 internal_error (__FILE__, __LINE__,
4561 _("bptypes table does not describe type #%d."),
4563 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
4568 if (part_of_multiple)
4569 ui_out_field_skip (uiout, "disp");
4571 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4576 if (part_of_multiple)
4577 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4579 ui_out_field_fmt (uiout, "enabled", "%c",
4580 bpenables[(int) b->enable_state]);
4581 ui_out_spaces (uiout, 2);
4585 strcpy (wrap_indent, " ");
4586 if (opts.addressprint)
4588 if (print_address_bits <= 32)
4589 strcat (wrap_indent, " ");
4591 strcat (wrap_indent, " ");
4594 if (b->ops != NULL && b->ops->print_one != NULL)
4596 /* Although the print_one can possibly print
4597 all locations, calling it here is not likely
4598 to get any nice result. So, make sure there's
4599 just one location. */
4600 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4601 b->ops->print_one (b, last_loc);
4607 internal_error (__FILE__, __LINE__,
4608 _("print_one_breakpoint: bp_none encountered\n"));
4612 case bp_hardware_watchpoint:
4613 case bp_read_watchpoint:
4614 case bp_access_watchpoint:
4615 /* Field 4, the address, is omitted (which makes the columns
4616 not line up too nicely with the headers, but the effect
4617 is relatively readable). */
4618 if (opts.addressprint)
4619 ui_out_field_skip (uiout, "addr");
4621 ui_out_field_string (uiout, "what", b->exp_string);
4625 case bp_hardware_breakpoint:
4629 case bp_longjmp_resume:
4630 case bp_step_resume:
4631 case bp_watchpoint_scope:
4633 case bp_std_terminate:
4634 case bp_shlib_event:
4635 case bp_thread_event:
4636 case bp_overlay_event:
4637 case bp_longjmp_master:
4638 case bp_std_terminate_master:
4640 case bp_fast_tracepoint:
4642 if (opts.addressprint)
4645 if (header_of_multiple)
4646 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4647 else if (b->loc == NULL || loc->shlib_disabled)
4648 ui_out_field_string (uiout, "addr", "<PENDING>");
4650 ui_out_field_core_addr (uiout, "addr",
4651 loc->gdbarch, loc->address);
4654 if (!header_of_multiple)
4655 print_breakpoint_location (b, loc, wrap_indent, stb);
4662 /* For backward compatibility, don't display inferiors unless there
4665 && !header_of_multiple
4667 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4668 && (number_of_program_spaces () > 1
4669 || number_of_inferiors () > 1)
4670 && loc->owner->type != bp_catchpoint)))
4672 struct inferior *inf;
4675 for (inf = inferior_list; inf != NULL; inf = inf->next)
4677 if (inf->pspace == loc->pspace)
4682 ui_out_text (uiout, " inf ");
4685 ui_out_text (uiout, ", ");
4686 ui_out_text (uiout, plongest (inf->num));
4691 if (!part_of_multiple)
4693 if (b->thread != -1)
4695 /* FIXME: This seems to be redundant and lost here; see the
4696 "stop only in" line a little further down. */
4697 ui_out_text (uiout, " thread ");
4698 ui_out_field_int (uiout, "thread", b->thread);
4700 else if (b->task != 0)
4702 ui_out_text (uiout, " task ");
4703 ui_out_field_int (uiout, "task", b->task);
4707 ui_out_text (uiout, "\n");
4709 if (part_of_multiple && frame_id_p (b->frame_id))
4712 ui_out_text (uiout, "\tstop only in stack frame at ");
4713 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4715 ui_out_field_core_addr (uiout, "frame",
4716 b->gdbarch, b->frame_id.stack_addr);
4717 ui_out_text (uiout, "\n");
4720 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4722 /* We do not print the condition for Ada exception catchpoints
4723 because the condition is an internal implementation detail
4724 that we do not want to expose to the user. */
4726 if (is_tracepoint (b))
4727 ui_out_text (uiout, "\ttrace only if ");
4729 ui_out_text (uiout, "\tstop only if ");
4730 ui_out_field_string (uiout, "cond", b->cond_string);
4731 ui_out_text (uiout, "\n");
4734 if (!part_of_multiple && b->thread != -1)
4736 /* FIXME should make an annotation for this */
4737 ui_out_text (uiout, "\tstop only in thread ");
4738 ui_out_field_int (uiout, "thread", b->thread);
4739 ui_out_text (uiout, "\n");
4742 if (!part_of_multiple && b->hit_count)
4744 /* FIXME should make an annotation for this */
4745 if (ep_is_catchpoint (b))
4746 ui_out_text (uiout, "\tcatchpoint");
4748 ui_out_text (uiout, "\tbreakpoint");
4749 ui_out_text (uiout, " already hit ");
4750 ui_out_field_int (uiout, "times", b->hit_count);
4751 if (b->hit_count == 1)
4752 ui_out_text (uiout, " time\n");
4754 ui_out_text (uiout, " times\n");
4757 /* Output the count also if it is zero, but only if this is
4758 mi. FIXME: Should have a better test for this. */
4759 if (ui_out_is_mi_like_p (uiout))
4760 if (!part_of_multiple && b->hit_count == 0)
4761 ui_out_field_int (uiout, "times", b->hit_count);
4763 if (!part_of_multiple && b->ignore_count)
4766 ui_out_text (uiout, "\tignore next ");
4767 ui_out_field_int (uiout, "ignore", b->ignore_count);
4768 ui_out_text (uiout, " hits\n");
4771 l = b->commands ? b->commands->commands : NULL;
4772 if (!part_of_multiple && l)
4774 struct cleanup *script_chain;
4777 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4778 print_command_lines (uiout, l, 4);
4779 do_cleanups (script_chain);
4782 if (!part_of_multiple && b->pass_count)
4784 annotate_field (10);
4785 ui_out_text (uiout, "\tpass count ");
4786 ui_out_field_int (uiout, "pass", b->pass_count);
4787 ui_out_text (uiout, " \n");
4790 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4793 ui_out_field_string (uiout, "original-location", b->addr_string);
4794 else if (b->exp_string)
4795 ui_out_field_string (uiout, "original-location", b->exp_string);
4798 do_cleanups (bkpt_chain);
4799 do_cleanups (old_chain);
4803 print_one_breakpoint (struct breakpoint *b,
4804 struct bp_location **last_loc, int print_address_bits,
4807 print_one_breakpoint_location (b, NULL, 0, last_loc,
4808 print_address_bits, allflag);
4810 /* If this breakpoint has custom print function,
4811 it's already printed. Otherwise, print individual
4812 locations, if any. */
4813 if (b->ops == NULL || b->ops->print_one == NULL)
4815 /* If breakpoint has a single location that is
4816 disabled, we print it as if it had
4817 several locations, since otherwise it's hard to
4818 represent "breakpoint enabled, location disabled"
4820 Note that while hardware watchpoints have
4821 several locations internally, that's no a property
4824 && !is_hardware_watchpoint (b)
4825 && (b->loc->next || !b->loc->enabled)
4826 && !ui_out_is_mi_like_p (uiout))
4828 struct bp_location *loc;
4830 for (loc = b->loc; loc; loc = loc->next, ++n)
4831 print_one_breakpoint_location (b, loc, n, last_loc,
4832 print_address_bits, allflag);
4838 breakpoint_address_bits (struct breakpoint *b)
4840 int print_address_bits = 0;
4841 struct bp_location *loc;
4843 for (loc = b->loc; loc; loc = loc->next)
4847 /* Software watchpoints that aren't watching memory don't have
4848 an address to print. */
4849 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4852 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4853 if (addr_bit > print_address_bits)
4854 print_address_bits = addr_bit;
4857 return print_address_bits;
4860 struct captured_breakpoint_query_args
4866 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4868 struct captured_breakpoint_query_args *args = data;
4869 struct breakpoint *b;
4870 struct bp_location *dummy_loc = NULL;
4873 if (args->bnum == b->number)
4875 int print_address_bits = breakpoint_address_bits (b);
4876 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4884 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4886 struct captured_breakpoint_query_args args;
4888 /* For the moment we don't trust print_one_breakpoint() to not throw
4890 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4891 error_message, RETURN_MASK_ALL) < 0)
4897 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4898 catchpoints, et.al.). */
4901 user_settable_breakpoint (const struct breakpoint *b)
4903 return (b->type == bp_breakpoint
4904 || b->type == bp_catchpoint
4905 || b->type == bp_hardware_breakpoint
4906 || is_tracepoint (b)
4907 || is_watchpoint (b));
4910 /* Print information on user settable breakpoint (watchpoint, etc)
4911 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4912 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4913 FILTER is non-NULL, call it on each breakpoint and only include the
4914 ones for which it returns non-zero. Return the total number of
4915 breakpoints listed. */
4918 breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
4920 struct breakpoint *b;
4921 struct bp_location *last_loc = NULL;
4922 int nr_printable_breakpoints;
4923 struct cleanup *bkpttbl_chain;
4924 struct value_print_options opts;
4925 int print_address_bits = 0;
4927 get_user_print_options (&opts);
4929 /* Compute the number of rows in the table, as well as the
4930 size required for address fields. */
4931 nr_printable_breakpoints = 0;
4934 || bnum == b->number)
4936 /* If we have a filter, only list the breakpoints it accepts. */
4937 if (filter && !filter (b))
4940 if (allflag || user_settable_breakpoint (b))
4942 int addr_bit = breakpoint_address_bits (b);
4943 if (addr_bit > print_address_bits)
4944 print_address_bits = addr_bit;
4946 nr_printable_breakpoints++;
4950 if (opts.addressprint)
4952 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
4956 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
4959 if (nr_printable_breakpoints > 0)
4960 annotate_breakpoints_headers ();
4961 if (nr_printable_breakpoints > 0)
4963 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
4964 if (nr_printable_breakpoints > 0)
4966 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
4967 if (nr_printable_breakpoints > 0)
4969 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
4970 if (nr_printable_breakpoints > 0)
4972 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
4973 if (opts.addressprint)
4975 if (nr_printable_breakpoints > 0)
4977 if (print_address_bits <= 32)
4978 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
4980 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
4982 if (nr_printable_breakpoints > 0)
4984 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
4985 ui_out_table_body (uiout);
4986 if (nr_printable_breakpoints > 0)
4987 annotate_breakpoints_table ();
4993 || bnum == b->number)
4995 /* If we have a filter, only list the breakpoints it accepts. */
4996 if (filter && !filter (b))
4999 /* We only print out user settable breakpoints unless the
5001 if (allflag || user_settable_breakpoint (b))
5002 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5006 do_cleanups (bkpttbl_chain);
5008 if (nr_printable_breakpoints == 0)
5010 /* If there's a filter, let the caller decide how to report empty list. */
5014 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5016 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
5022 if (last_loc && !server_command)
5023 set_next_address (last_loc->gdbarch, last_loc->address);
5026 /* FIXME? Should this be moved up so that it is only called when
5027 there have been breakpoints? */
5028 annotate_breakpoints_table_end ();
5030 return nr_printable_breakpoints;
5033 /* Display the value of default-collect in a way that is generally
5034 compatible with the breakpoint list. */
5037 default_collect_info (void)
5039 /* If it has no value (which is frequently the case), say nothing; a
5040 message like "No default-collect." gets in user's face when it's
5042 if (!*default_collect)
5045 /* The following phrase lines up nicely with per-tracepoint collect
5047 ui_out_text (uiout, "default collect ");
5048 ui_out_field_string (uiout, "default-collect", default_collect);
5049 ui_out_text (uiout, " \n");
5053 breakpoints_info (char *bnum_exp, int from_tty)
5058 bnum = parse_and_eval_long (bnum_exp);
5060 breakpoint_1 (bnum, 0, NULL);
5062 default_collect_info ();
5066 watchpoints_info (char *wpnum_exp, int from_tty)
5068 int wpnum = -1, num_printed;
5071 wpnum = parse_and_eval_long (wpnum_exp);
5073 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5075 if (num_printed == 0)
5078 ui_out_message (uiout, 0, "No watchpoints.\n");
5080 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5085 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5090 bnum = parse_and_eval_long (bnum_exp);
5092 breakpoint_1 (bnum, 1, NULL);
5094 default_collect_info ();
5098 breakpoint_has_pc (struct breakpoint *b,
5099 struct program_space *pspace,
5100 CORE_ADDR pc, struct obj_section *section)
5102 struct bp_location *bl = b->loc;
5103 for (; bl; bl = bl->next)
5105 if (bl->pspace == pspace
5106 && bl->address == pc
5107 && (!overlay_debugging || bl->section == section))
5113 /* Print a message describing any breakpoints set at PC. This
5114 concerns with logical breakpoints, so we match program spaces, not
5118 describe_other_breakpoints (struct gdbarch *gdbarch,
5119 struct program_space *pspace, CORE_ADDR pc,
5120 struct obj_section *section, int thread)
5123 struct breakpoint *b;
5126 others += breakpoint_has_pc (b, pspace, pc, section);
5130 printf_filtered (_("Note: breakpoint "));
5131 else /* if (others == ???) */
5132 printf_filtered (_("Note: breakpoints "));
5134 if (breakpoint_has_pc (b, pspace, pc, section))
5137 printf_filtered ("%d", b->number);
5138 if (b->thread == -1 && thread != -1)
5139 printf_filtered (" (all threads)");
5140 else if (b->thread != -1)
5141 printf_filtered (" (thread %d)", b->thread);
5142 printf_filtered ("%s%s ",
5143 ((b->enable_state == bp_disabled
5144 || b->enable_state == bp_call_disabled
5145 || b->enable_state == bp_startup_disabled)
5147 : b->enable_state == bp_permanent
5151 : ((others == 1) ? " and" : ""));
5153 printf_filtered (_("also set at pc "));
5154 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5155 printf_filtered (".\n");
5159 /* Set the default place to put a breakpoint
5160 for the `break' command with no arguments. */
5163 set_default_breakpoint (int valid, struct program_space *pspace,
5164 CORE_ADDR addr, struct symtab *symtab,
5167 default_breakpoint_valid = valid;
5168 default_breakpoint_pspace = pspace;
5169 default_breakpoint_address = addr;
5170 default_breakpoint_symtab = symtab;
5171 default_breakpoint_line = line;
5174 /* Return true iff it is meaningful to use the address member of
5175 BPT. For some breakpoint types, the address member is irrelevant
5176 and it makes no sense to attempt to compare it to other addresses
5177 (or use it for any other purpose either).
5179 More specifically, each of the following breakpoint types will always
5180 have a zero valued address and we don't want to mark breakpoints of any of
5181 these types to be a duplicate of an actual breakpoint at address zero:
5189 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5191 enum bptype type = bpt->type;
5193 return (type != bp_watchpoint && type != bp_catchpoint);
5196 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5197 true if LOC1 and LOC2 represent the same watchpoint location. */
5200 watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5202 /* Note that this checks the owner's type, not the location's. In
5203 case the target does not support read watchpoints, but does
5204 support access watchpoints, we'll have bp_read_watchpoint
5205 watchpoints with hw_access locations. Those should be considered
5206 duplicates of hw_read locations. The hw_read locations will
5207 become hw_access locations later. */
5208 return (loc1->owner->type == loc2->owner->type
5209 && loc1->pspace->aspace == loc2->pspace->aspace
5210 && loc1->address == loc2->address
5211 && loc1->length == loc2->length);
5214 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5215 same breakpoint location. In most targets, this can only be true
5216 if ASPACE1 matches ASPACE2. On targets that have global
5217 breakpoints, the address space doesn't really matter. */
5220 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5221 struct address_space *aspace2, CORE_ADDR addr2)
5223 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5224 || aspace1 == aspace2)
5228 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5229 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5230 represent the same location. */
5233 breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5235 int hw_point1 = is_hardware_watchpoint (loc1->owner);
5236 int hw_point2 = is_hardware_watchpoint (loc2->owner);
5238 if (hw_point1 != hw_point2)
5241 return watchpoint_locations_match (loc1, loc2);
5243 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5244 loc2->pspace->aspace, loc2->address);
5248 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5249 int bnum, int have_bnum)
5254 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5255 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5257 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5258 bnum, astr1, astr2);
5260 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5263 /* Adjust a breakpoint's address to account for architectural constraints
5264 on breakpoint placement. Return the adjusted address. Note: Very
5265 few targets require this kind of adjustment. For most targets,
5266 this function is simply the identity function. */
5269 adjust_breakpoint_address (struct gdbarch *gdbarch,
5270 CORE_ADDR bpaddr, enum bptype bptype)
5272 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5274 /* Very few targets need any kind of breakpoint adjustment. */
5277 else if (bptype == bp_watchpoint
5278 || bptype == bp_hardware_watchpoint
5279 || bptype == bp_read_watchpoint
5280 || bptype == bp_access_watchpoint
5281 || bptype == bp_catchpoint)
5283 /* Watchpoints and the various bp_catch_* eventpoints should not
5284 have their addresses modified. */
5289 CORE_ADDR adjusted_bpaddr;
5291 /* Some targets have architectural constraints on the placement
5292 of breakpoint instructions. Obtain the adjusted address. */
5293 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5295 /* An adjusted breakpoint address can significantly alter
5296 a user's expectations. Print a warning if an adjustment
5298 if (adjusted_bpaddr != bpaddr)
5299 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5301 return adjusted_bpaddr;
5305 /* Allocate a struct bp_location. */
5307 static struct bp_location *
5308 allocate_bp_location (struct breakpoint *bpt)
5310 struct bp_location *loc;
5312 loc = xmalloc (sizeof (struct bp_location));
5313 memset (loc, 0, sizeof (*loc));
5317 loc->shlib_disabled = 0;
5326 case bp_longjmp_resume:
5327 case bp_step_resume:
5328 case bp_watchpoint_scope:
5330 case bp_std_terminate:
5331 case bp_shlib_event:
5332 case bp_thread_event:
5333 case bp_overlay_event:
5335 case bp_longjmp_master:
5336 case bp_std_terminate_master:
5337 loc->loc_type = bp_loc_software_breakpoint;
5339 case bp_hardware_breakpoint:
5340 loc->loc_type = bp_loc_hardware_breakpoint;
5342 case bp_hardware_watchpoint:
5343 case bp_read_watchpoint:
5344 case bp_access_watchpoint:
5345 loc->loc_type = bp_loc_hardware_watchpoint;
5350 case bp_fast_tracepoint:
5351 loc->loc_type = bp_loc_other;
5354 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5360 static void free_bp_location (struct bp_location *loc)
5365 if (loc->function_name)
5366 xfree (loc->function_name);
5371 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5372 that has type BPTYPE and has no locations as yet. */
5373 /* This function is used in gdbtk sources and thus can not be made static. */
5375 static struct breakpoint *
5376 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5379 struct breakpoint *b, *b1;
5381 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5382 memset (b, 0, sizeof (*b));
5385 b->gdbarch = gdbarch;
5386 b->language = current_language->la_language;
5387 b->input_radix = input_radix;
5389 b->enable_state = bp_enabled;
5392 b->ignore_count = 0;
5394 b->frame_id = null_frame_id;
5395 b->forked_inferior_pid = null_ptid;
5396 b->exec_pathname = NULL;
5397 b->syscalls_to_be_caught = NULL;
5399 b->condition_not_parsed = 0;
5401 /* Add this breakpoint to the end of the chain
5402 so that a list of breakpoints will come out in order
5403 of increasing numbers. */
5405 b1 = breakpoint_chain;
5407 breakpoint_chain = b;
5417 /* Initialize loc->function_name. */
5419 set_breakpoint_location_function (struct bp_location *loc)
5421 if (loc->owner->type == bp_breakpoint
5422 || loc->owner->type == bp_hardware_breakpoint
5423 || is_tracepoint (loc->owner))
5425 find_pc_partial_function (loc->address, &(loc->function_name),
5427 if (loc->function_name)
5428 loc->function_name = xstrdup (loc->function_name);
5432 /* Attempt to determine architecture of location identified by SAL. */
5433 static struct gdbarch *
5434 get_sal_arch (struct symtab_and_line sal)
5437 return get_objfile_arch (sal.section->objfile);
5439 return get_objfile_arch (sal.symtab->objfile);
5444 /* set_raw_breakpoint is a low level routine for allocating and
5445 partially initializing a breakpoint of type BPTYPE. The newly
5446 created breakpoint's address, section, source file name, and line
5447 number are provided by SAL. The newly created and partially
5448 initialized breakpoint is added to the breakpoint chain and
5449 is also returned as the value of this function.
5451 It is expected that the caller will complete the initialization of
5452 the newly created breakpoint struct as well as output any status
5453 information regarding the creation of a new breakpoint. In
5454 particular, set_raw_breakpoint does NOT set the breakpoint
5455 number! Care should be taken to not allow an error to occur
5456 prior to completing the initialization of the breakpoint. If this
5457 should happen, a bogus breakpoint will be left on the chain. */
5460 set_raw_breakpoint (struct gdbarch *gdbarch,
5461 struct symtab_and_line sal, enum bptype bptype)
5463 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
5464 CORE_ADDR adjusted_address;
5465 struct gdbarch *loc_gdbarch;
5467 loc_gdbarch = get_sal_arch (sal);
5469 loc_gdbarch = b->gdbarch;
5471 if (bptype != bp_catchpoint)
5472 gdb_assert (sal.pspace != NULL);
5474 /* Adjust the breakpoint's address prior to allocating a location.
5475 Once we call allocate_bp_location(), that mostly uninitialized
5476 location will be placed on the location chain. Adjustment of the
5477 breakpoint may cause target_read_memory() to be called and we do
5478 not want its scan of the location chain to find a breakpoint and
5479 location that's only been partially initialized. */
5480 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
5482 b->loc = allocate_bp_location (b);
5483 b->loc->gdbarch = loc_gdbarch;
5484 b->loc->requested_address = sal.pc;
5485 b->loc->address = adjusted_address;
5486 b->loc->pspace = sal.pspace;
5488 /* Store the program space that was used to set the breakpoint, for
5489 breakpoint resetting. */
5490 b->pspace = sal.pspace;
5492 if (sal.symtab == NULL)
5493 b->source_file = NULL;
5495 b->source_file = xstrdup (sal.symtab->filename);
5496 b->loc->section = sal.section;
5497 b->line_number = sal.line;
5499 set_breakpoint_location_function (b->loc);
5501 breakpoints_changed ();
5507 /* Note that the breakpoint object B describes a permanent breakpoint
5508 instruction, hard-wired into the inferior's code. */
5510 make_breakpoint_permanent (struct breakpoint *b)
5512 struct bp_location *bl;
5513 b->enable_state = bp_permanent;
5515 /* By definition, permanent breakpoints are already present in the code.
5516 Mark all locations as inserted. For now, make_breakpoint_permanent
5517 is called in just one place, so it's hard to say if it's reasonable
5518 to have permanent breakpoint with multiple locations or not,
5519 but it's easy to implmement. */
5520 for (bl = b->loc; bl; bl = bl->next)
5524 /* Call this routine when stepping and nexting to enable a breakpoint
5525 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5526 set_longjmp_resume_breakpoint() to figure out where we are going. */
5529 set_longjmp_breakpoint (int thread)
5531 struct breakpoint *b, *temp;
5533 /* To avoid having to rescan all objfile symbols at every step,
5534 we maintain a list of continually-inserted but always disabled
5535 longjmp "master" breakpoints. Here, we simply create momentary
5536 clones of those and enable them for the requested thread. */
5537 ALL_BREAKPOINTS_SAFE (b, temp)
5538 if (b->pspace == current_program_space
5539 && b->type == bp_longjmp_master)
5541 struct breakpoint *clone = clone_momentary_breakpoint (b);
5542 clone->type = bp_longjmp;
5543 clone->thread = thread;
5547 /* Delete all longjmp breakpoints from THREAD. */
5549 delete_longjmp_breakpoint (int thread)
5551 struct breakpoint *b, *temp;
5553 ALL_BREAKPOINTS_SAFE (b, temp)
5554 if (b->type == bp_longjmp)
5556 if (b->thread == thread)
5557 delete_breakpoint (b);
5562 enable_overlay_breakpoints (void)
5564 struct breakpoint *b;
5567 if (b->type == bp_overlay_event)
5569 b->enable_state = bp_enabled;
5570 update_global_location_list (1);
5571 overlay_events_enabled = 1;
5576 disable_overlay_breakpoints (void)
5578 struct breakpoint *b;
5581 if (b->type == bp_overlay_event)
5583 b->enable_state = bp_disabled;
5584 update_global_location_list (0);
5585 overlay_events_enabled = 0;
5589 /* Set an active std::terminate breakpoint for each std::terminate
5590 master breakpoint. */
5592 set_std_terminate_breakpoint (void)
5594 struct breakpoint *b, *temp;
5596 ALL_BREAKPOINTS_SAFE (b, temp)
5597 if (b->pspace == current_program_space
5598 && b->type == bp_std_terminate_master)
5600 struct breakpoint *clone = clone_momentary_breakpoint (b);
5601 clone->type = bp_std_terminate;
5605 /* Delete all the std::terminate breakpoints. */
5607 delete_std_terminate_breakpoint (void)
5609 struct breakpoint *b, *temp;
5611 ALL_BREAKPOINTS_SAFE (b, temp)
5612 if (b->type == bp_std_terminate)
5613 delete_breakpoint (b);
5617 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5619 struct breakpoint *b;
5621 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5623 b->enable_state = bp_enabled;
5624 /* addr_string has to be used or breakpoint_re_set will delete me. */
5626 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5628 update_global_location_list_nothrow (1);
5634 remove_thread_event_breakpoints (void)
5636 struct breakpoint *b, *temp;
5638 ALL_BREAKPOINTS_SAFE (b, temp)
5639 if (b->type == bp_thread_event
5640 && b->loc->pspace == current_program_space)
5641 delete_breakpoint (b);
5644 struct captured_parse_breakpoint_args
5647 struct symtabs_and_lines *sals_p;
5648 char ***addr_string_p;
5652 struct lang_and_radix
5658 /* Create a breakpoint for JIT code registration and unregistration. */
5661 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5663 struct breakpoint *b;
5665 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5666 update_global_location_list_nothrow (1);
5671 remove_solib_event_breakpoints (void)
5673 struct breakpoint *b, *temp;
5675 ALL_BREAKPOINTS_SAFE (b, temp)
5676 if (b->type == bp_shlib_event
5677 && b->loc->pspace == current_program_space)
5678 delete_breakpoint (b);
5682 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5684 struct breakpoint *b;
5686 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5687 update_global_location_list_nothrow (1);
5691 /* Disable any breakpoints that are on code in shared libraries. Only
5692 apply to enabled breakpoints, disabled ones can just stay disabled. */
5695 disable_breakpoints_in_shlibs (void)
5697 struct bp_location *loc, **locp_tmp;
5699 ALL_BP_LOCATIONS (loc, locp_tmp)
5701 struct breakpoint *b = loc->owner;
5702 /* We apply the check to all breakpoints, including disabled
5703 for those with loc->duplicate set. This is so that when breakpoint
5704 becomes enabled, or the duplicate is removed, gdb will try to insert
5705 all breakpoints. If we don't set shlib_disabled here, we'll try
5706 to insert those breakpoints and fail. */
5707 if (((b->type == bp_breakpoint)
5708 || (b->type == bp_jit_event)
5709 || (b->type == bp_hardware_breakpoint)
5710 || (is_tracepoint (b)))
5711 && loc->pspace == current_program_space
5712 && !loc->shlib_disabled
5714 && PC_SOLIB (loc->address)
5716 && solib_name_from_address (loc->pspace, loc->address)
5720 loc->shlib_disabled = 1;
5725 /* Disable any breakpoints that are in in an unloaded shared library. Only
5726 apply to enabled breakpoints, disabled ones can just stay disabled. */
5729 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5731 struct bp_location *loc, **locp_tmp;
5732 int disabled_shlib_breaks = 0;
5734 /* SunOS a.out shared libraries are always mapped, so do not
5735 disable breakpoints; they will only be reported as unloaded
5736 through clear_solib when GDB discards its shared library
5737 list. See clear_solib for more information. */
5738 if (exec_bfd != NULL
5739 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5742 ALL_BP_LOCATIONS (loc, locp_tmp)
5744 struct breakpoint *b = loc->owner;
5745 if ((loc->loc_type == bp_loc_hardware_breakpoint
5746 || loc->loc_type == bp_loc_software_breakpoint)
5747 && solib->pspace == loc->pspace
5748 && !loc->shlib_disabled
5749 && (b->type == bp_breakpoint
5750 || b->type == bp_jit_event
5751 || b->type == bp_hardware_breakpoint)
5752 && solib_contains_address_p (solib, loc->address))
5754 loc->shlib_disabled = 1;
5755 /* At this point, we cannot rely on remove_breakpoint
5756 succeeding so we must mark the breakpoint as not inserted
5757 to prevent future errors occurring in remove_breakpoints. */
5759 if (!disabled_shlib_breaks)
5761 target_terminal_ours_for_output ();
5762 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5765 disabled_shlib_breaks = 1;
5770 /* FORK & VFORK catchpoints. */
5772 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5775 insert_catch_fork (struct breakpoint *b)
5777 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5780 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5783 remove_catch_fork (struct breakpoint *b)
5785 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5788 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5792 breakpoint_hit_catch_fork (struct breakpoint *b)
5794 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5797 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5799 static enum print_stop_action
5800 print_it_catch_fork (struct breakpoint *b)
5802 annotate_catchpoint (b->number);
5803 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5804 b->number, ptid_get_pid (b->forked_inferior_pid));
5805 return PRINT_SRC_AND_LOC;
5808 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5811 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5813 struct value_print_options opts;
5815 get_user_print_options (&opts);
5817 /* Field 4, the address, is omitted (which makes the columns
5818 not line up too nicely with the headers, but the effect
5819 is relatively readable). */
5820 if (opts.addressprint)
5821 ui_out_field_skip (uiout, "addr");
5823 ui_out_text (uiout, "fork");
5824 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5826 ui_out_text (uiout, ", process ");
5827 ui_out_field_int (uiout, "what",
5828 ptid_get_pid (b->forked_inferior_pid));
5829 ui_out_spaces (uiout, 1);
5833 /* Implement the "print_mention" breakpoint_ops method for fork
5837 print_mention_catch_fork (struct breakpoint *b)
5839 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5842 /* Implement the "print_recreate" breakpoint_ops method for fork
5846 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
5848 fprintf_unfiltered (fp, "catch fork");
5851 /* The breakpoint_ops structure to be used in fork catchpoints. */
5853 static struct breakpoint_ops catch_fork_breakpoint_ops =
5857 breakpoint_hit_catch_fork,
5858 print_it_catch_fork,
5859 print_one_catch_fork,
5860 print_mention_catch_fork,
5861 print_recreate_catch_fork
5864 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5867 insert_catch_vfork (struct breakpoint *b)
5869 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
5872 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5875 remove_catch_vfork (struct breakpoint *b)
5877 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
5880 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5884 breakpoint_hit_catch_vfork (struct breakpoint *b)
5886 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
5889 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5891 static enum print_stop_action
5892 print_it_catch_vfork (struct breakpoint *b)
5894 annotate_catchpoint (b->number);
5895 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5896 b->number, ptid_get_pid (b->forked_inferior_pid));
5897 return PRINT_SRC_AND_LOC;
5900 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5903 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
5905 struct value_print_options opts;
5907 get_user_print_options (&opts);
5908 /* Field 4, the address, is omitted (which makes the columns
5909 not line up too nicely with the headers, but the effect
5910 is relatively readable). */
5911 if (opts.addressprint)
5912 ui_out_field_skip (uiout, "addr");
5914 ui_out_text (uiout, "vfork");
5915 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5917 ui_out_text (uiout, ", process ");
5918 ui_out_field_int (uiout, "what",
5919 ptid_get_pid (b->forked_inferior_pid));
5920 ui_out_spaces (uiout, 1);
5924 /* Implement the "print_mention" breakpoint_ops method for vfork
5928 print_mention_catch_vfork (struct breakpoint *b)
5930 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
5933 /* Implement the "print_recreate" breakpoint_ops method for vfork
5937 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
5939 fprintf_unfiltered (fp, "catch vfork");
5942 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5944 static struct breakpoint_ops catch_vfork_breakpoint_ops =
5948 breakpoint_hit_catch_vfork,
5949 print_it_catch_vfork,
5950 print_one_catch_vfork,
5951 print_mention_catch_vfork,
5952 print_recreate_catch_vfork
5955 /* Implement the "insert" breakpoint_ops method for syscall
5959 insert_catch_syscall (struct breakpoint *b)
5961 struct inferior *inf = current_inferior ();
5963 ++inf->total_syscalls_count;
5964 if (!b->syscalls_to_be_caught)
5965 ++inf->any_syscall_count;
5970 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
5974 if (iter >= VEC_length (int, inf->syscalls_counts))
5976 int old_size = VEC_length (int, inf->syscalls_counts);
5977 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
5979 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
5980 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
5982 memset ((void *) vec_addr, 0,
5983 (iter + 1 - old_size) * sizeof (int));
5985 elem = VEC_index (int, inf->syscalls_counts, iter);
5986 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
5990 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
5991 inf->total_syscalls_count != 0,
5992 inf->any_syscall_count,
5993 VEC_length (int, inf->syscalls_counts),
5994 VEC_address (int, inf->syscalls_counts));
5997 /* Implement the "remove" breakpoint_ops method for syscall
6001 remove_catch_syscall (struct breakpoint *b)
6003 struct inferior *inf = current_inferior ();
6005 --inf->total_syscalls_count;
6006 if (!b->syscalls_to_be_caught)
6007 --inf->any_syscall_count;
6012 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6016 if (iter >= VEC_length (int, inf->syscalls_counts))
6017 /* Shouldn't happen. */
6019 elem = VEC_index (int, inf->syscalls_counts, iter);
6020 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6024 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6025 inf->total_syscalls_count != 0,
6026 inf->any_syscall_count,
6027 VEC_length (int, inf->syscalls_counts),
6028 VEC_address (int, inf->syscalls_counts));
6031 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6035 breakpoint_hit_catch_syscall (struct breakpoint *b)
6037 /* We must check if we are catching specific syscalls in this breakpoint.
6038 If we are, then we must guarantee that the called syscall is the same
6039 syscall we are catching. */
6040 int syscall_number = 0;
6042 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6045 /* Now, checking if the syscall is the same. */
6046 if (b->syscalls_to_be_caught)
6050 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6052 if (syscall_number == iter)
6062 /* Implement the "print_it" breakpoint_ops method for syscall
6065 static enum print_stop_action
6066 print_it_catch_syscall (struct breakpoint *b)
6068 /* These are needed because we want to know in which state a
6069 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6070 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6071 must print "called syscall" or "returned from syscall". */
6073 struct target_waitstatus last;
6075 struct cleanup *old_chain;
6078 get_last_target_status (&ptid, &last);
6080 get_syscall_by_number (last.value.syscall_number, &s);
6082 annotate_catchpoint (b->number);
6085 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6087 syscall_id = xstrprintf ("'%s'", s.name);
6089 old_chain = make_cleanup (xfree, syscall_id);
6091 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6092 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6093 b->number, syscall_id);
6094 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6095 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6096 b->number, syscall_id);
6098 do_cleanups (old_chain);
6100 return PRINT_SRC_AND_LOC;
6103 /* Implement the "print_one" breakpoint_ops method for syscall
6107 print_one_catch_syscall (struct breakpoint *b,
6108 struct bp_location **last_loc)
6110 struct value_print_options opts;
6112 get_user_print_options (&opts);
6113 /* Field 4, the address, is omitted (which makes the columns
6114 not line up too nicely with the headers, but the effect
6115 is relatively readable). */
6116 if (opts.addressprint)
6117 ui_out_field_skip (uiout, "addr");
6120 if (b->syscalls_to_be_caught
6121 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6122 ui_out_text (uiout, "syscalls \"");
6124 ui_out_text (uiout, "syscall \"");
6126 if (b->syscalls_to_be_caught)
6129 char *text = xstrprintf ("%s", "");
6131 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6136 get_syscall_by_number (iter, &s);
6139 text = xstrprintf ("%s%s, ", text, s.name);
6141 text = xstrprintf ("%s%d, ", text, iter);
6143 /* We have to xfree the last 'text' (now stored at 'x')
6144 because xstrprintf dinamically allocates new space for it
6148 /* Remove the last comma. */
6149 text[strlen (text) - 2] = '\0';
6150 ui_out_field_string (uiout, "what", text);
6153 ui_out_field_string (uiout, "what", "<any syscall>");
6154 ui_out_text (uiout, "\" ");
6157 /* Implement the "print_mention" breakpoint_ops method for syscall
6161 print_mention_catch_syscall (struct breakpoint *b)
6163 if (b->syscalls_to_be_caught)
6167 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6168 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6170 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6173 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6177 get_syscall_by_number (iter, &s);
6180 printf_filtered (" '%s' [%d]", s.name, s.number);
6182 printf_filtered (" %d", s.number);
6184 printf_filtered (")");
6187 printf_filtered (_("Catchpoint %d (any syscall)"),
6191 /* Implement the "print_recreate" breakpoint_ops method for syscall
6195 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6197 fprintf_unfiltered (fp, "catch syscall");
6199 if (b->syscalls_to_be_caught)
6204 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6209 get_syscall_by_number (iter, &s);
6211 fprintf_unfiltered (fp, " %s", s.name);
6213 fprintf_unfiltered (fp, " %d", s.number);
6218 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6220 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6222 insert_catch_syscall,
6223 remove_catch_syscall,
6224 breakpoint_hit_catch_syscall,
6225 print_it_catch_syscall,
6226 print_one_catch_syscall,
6227 print_mention_catch_syscall,
6228 print_recreate_catch_syscall
6231 /* Returns non-zero if 'b' is a syscall catchpoint. */
6234 syscall_catchpoint_p (struct breakpoint *b)
6236 return (b->ops == &catch_syscall_breakpoint_ops);
6239 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6240 but does NOT mention it nor update the global location list.
6241 This is useful if you need to fill more fields in the
6242 struct breakpoint before calling mention.
6244 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6245 If COND_STRING is not NULL, then store it in the breakpoint.
6246 OPS, if not NULL, is the breakpoint_ops structure associated
6247 to the catchpoint. */
6249 static struct breakpoint *
6250 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6252 struct breakpoint_ops *ops)
6254 struct symtab_and_line sal;
6255 struct breakpoint *b;
6258 sal.pspace = current_program_space;
6260 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6261 set_breakpoint_count (breakpoint_count + 1);
6262 b->number = breakpoint_count;
6264 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6266 b->addr_string = NULL;
6267 b->enable_state = bp_enabled;
6268 b->disposition = tempflag ? disp_del : disp_donttouch;
6274 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6276 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6277 If COND_STRING is not NULL, then store it in the breakpoint.
6278 OPS, if not NULL, is the breakpoint_ops structure associated
6279 to the catchpoint. */
6281 static struct breakpoint *
6282 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6283 char *cond_string, struct breakpoint_ops *ops)
6285 struct breakpoint *b =
6286 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6289 update_global_location_list (1);
6295 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6296 int tempflag, char *cond_string,
6297 struct breakpoint_ops *ops)
6299 struct breakpoint *b
6300 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6302 /* FIXME: We should put this information in a breakpoint private data
6304 b->forked_inferior_pid = null_ptid;
6307 /* Exec catchpoints. */
6310 insert_catch_exec (struct breakpoint *b)
6312 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6316 remove_catch_exec (struct breakpoint *b)
6318 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6322 breakpoint_hit_catch_exec (struct breakpoint *b)
6324 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6327 static enum print_stop_action
6328 print_it_catch_exec (struct breakpoint *b)
6330 annotate_catchpoint (b->number);
6331 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6333 return PRINT_SRC_AND_LOC;
6337 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6339 struct value_print_options opts;
6341 get_user_print_options (&opts);
6343 /* Field 4, the address, is omitted (which makes the columns
6344 not line up too nicely with the headers, but the effect
6345 is relatively readable). */
6346 if (opts.addressprint)
6347 ui_out_field_skip (uiout, "addr");
6349 ui_out_text (uiout, "exec");
6350 if (b->exec_pathname != NULL)
6352 ui_out_text (uiout, ", program \"");
6353 ui_out_field_string (uiout, "what", b->exec_pathname);
6354 ui_out_text (uiout, "\" ");
6359 print_mention_catch_exec (struct breakpoint *b)
6361 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6364 /* Implement the "print_recreate" breakpoint_ops method for exec
6368 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6370 fprintf_unfiltered (fp, "catch exec");
6373 static struct breakpoint_ops catch_exec_breakpoint_ops =
6377 breakpoint_hit_catch_exec,
6378 print_it_catch_exec,
6379 print_one_catch_exec,
6380 print_mention_catch_exec,
6381 print_recreate_catch_exec
6385 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6386 struct breakpoint_ops *ops)
6388 struct gdbarch *gdbarch = get_current_arch ();
6389 struct breakpoint *b =
6390 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6392 b->syscalls_to_be_caught = filter;
6394 /* Now, we have to mention the breakpoint and update the global
6397 update_global_location_list (1);
6401 hw_breakpoint_used_count (void)
6403 struct breakpoint *b;
6408 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6416 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6418 struct breakpoint *b;
6421 *other_type_used = 0;
6424 if (breakpoint_enabled (b))
6426 if (b->type == type)
6428 else if (is_hardware_watchpoint (b))
6429 *other_type_used = 1;
6436 disable_watchpoints_before_interactive_call_start (void)
6438 struct breakpoint *b;
6442 if (is_watchpoint (b) && breakpoint_enabled (b))
6444 b->enable_state = bp_call_disabled;
6445 update_global_location_list (0);
6451 enable_watchpoints_after_interactive_call_stop (void)
6453 struct breakpoint *b;
6457 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6459 b->enable_state = bp_enabled;
6460 update_global_location_list (1);
6466 disable_breakpoints_before_startup (void)
6468 struct breakpoint *b;
6473 if (b->pspace != current_program_space)
6476 if ((b->type == bp_breakpoint
6477 || b->type == bp_hardware_breakpoint)
6478 && breakpoint_enabled (b))
6480 b->enable_state = bp_startup_disabled;
6486 update_global_location_list (0);
6488 current_program_space->executing_startup = 1;
6492 enable_breakpoints_after_startup (void)
6494 struct breakpoint *b;
6497 current_program_space->executing_startup = 0;
6501 if (b->pspace != current_program_space)
6504 if ((b->type == bp_breakpoint
6505 || b->type == bp_hardware_breakpoint)
6506 && b->enable_state == bp_startup_disabled)
6508 b->enable_state = bp_enabled;
6514 breakpoint_re_set ();
6518 /* Set a breakpoint that will evaporate an end of command
6519 at address specified by SAL.
6520 Restrict it to frame FRAME if FRAME is nonzero. */
6523 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6524 struct frame_id frame_id, enum bptype type)
6526 struct breakpoint *b;
6528 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6530 gdb_assert (!frame_id_inlined_p (frame_id));
6532 b = set_raw_breakpoint (gdbarch, sal, type);
6533 b->enable_state = bp_enabled;
6534 b->disposition = disp_donttouch;
6535 b->frame_id = frame_id;
6537 /* If we're debugging a multi-threaded program, then we
6538 want momentary breakpoints to be active in only a
6539 single thread of control. */
6540 if (in_thread_list (inferior_ptid))
6541 b->thread = pid_to_thread_id (inferior_ptid);
6543 update_global_location_list_nothrow (1);
6548 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6552 clone_momentary_breakpoint (struct breakpoint *orig)
6554 struct breakpoint *copy;
6556 /* If there's nothing to clone, then return nothing. */
6560 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6561 copy->loc = allocate_bp_location (copy);
6562 set_breakpoint_location_function (copy->loc);
6564 copy->loc->gdbarch = orig->loc->gdbarch;
6565 copy->loc->requested_address = orig->loc->requested_address;
6566 copy->loc->address = orig->loc->address;
6567 copy->loc->section = orig->loc->section;
6568 copy->loc->pspace = orig->loc->pspace;
6570 if (orig->source_file == NULL)
6571 copy->source_file = NULL;
6573 copy->source_file = xstrdup (orig->source_file);
6575 copy->line_number = orig->line_number;
6576 copy->frame_id = orig->frame_id;
6577 copy->thread = orig->thread;
6578 copy->pspace = orig->pspace;
6580 copy->enable_state = bp_enabled;
6581 copy->disposition = disp_donttouch;
6582 copy->number = internal_breakpoint_number--;
6584 update_global_location_list_nothrow (0);
6589 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6592 struct symtab_and_line sal;
6594 sal = find_pc_line (pc, 0);
6596 sal.section = find_pc_overlay (pc);
6597 sal.explicit_pc = 1;
6599 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6603 /* Tell the user we have just set a breakpoint B. */
6606 mention (struct breakpoint *b)
6609 struct cleanup *ui_out_chain;
6610 struct value_print_options opts;
6612 get_user_print_options (&opts);
6614 /* FIXME: This is misplaced; mention() is called by things (like
6615 hitting a watchpoint) other than breakpoint creation. It should
6616 be possible to clean this up and at the same time replace the
6617 random calls to breakpoint_changed with this hook. */
6618 observer_notify_breakpoint_created (b->number);
6620 if (b->ops != NULL && b->ops->print_mention != NULL)
6621 b->ops->print_mention (b);
6626 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
6629 ui_out_text (uiout, "Watchpoint ");
6630 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6631 ui_out_field_int (uiout, "number", b->number);
6632 ui_out_text (uiout, ": ");
6633 ui_out_field_string (uiout, "exp", b->exp_string);
6634 do_cleanups (ui_out_chain);
6636 case bp_hardware_watchpoint:
6637 ui_out_text (uiout, "Hardware watchpoint ");
6638 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6639 ui_out_field_int (uiout, "number", b->number);
6640 ui_out_text (uiout, ": ");
6641 ui_out_field_string (uiout, "exp", b->exp_string);
6642 do_cleanups (ui_out_chain);
6644 case bp_read_watchpoint:
6645 ui_out_text (uiout, "Hardware read watchpoint ");
6646 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6647 ui_out_field_int (uiout, "number", b->number);
6648 ui_out_text (uiout, ": ");
6649 ui_out_field_string (uiout, "exp", b->exp_string);
6650 do_cleanups (ui_out_chain);
6652 case bp_access_watchpoint:
6653 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6654 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6655 ui_out_field_int (uiout, "number", b->number);
6656 ui_out_text (uiout, ": ");
6657 ui_out_field_string (uiout, "exp", b->exp_string);
6658 do_cleanups (ui_out_chain);
6661 if (ui_out_is_mi_like_p (uiout))
6666 if (b->disposition == disp_del)
6667 printf_filtered (_("Temporary breakpoint"));
6669 printf_filtered (_("Breakpoint"));
6670 printf_filtered (_(" %d"), b->number);
6673 case bp_hardware_breakpoint:
6674 if (ui_out_is_mi_like_p (uiout))
6679 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6683 if (ui_out_is_mi_like_p (uiout))
6688 printf_filtered (_("Tracepoint"));
6689 printf_filtered (_(" %d"), b->number);
6692 case bp_fast_tracepoint:
6693 if (ui_out_is_mi_like_p (uiout))
6698 printf_filtered (_("Fast tracepoint"));
6699 printf_filtered (_(" %d"), b->number);
6706 case bp_longjmp_resume:
6707 case bp_step_resume:
6709 case bp_std_terminate:
6710 case bp_watchpoint_scope:
6711 case bp_shlib_event:
6712 case bp_thread_event:
6713 case bp_overlay_event:
6715 case bp_longjmp_master:
6716 case bp_std_terminate_master:
6722 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6726 printf_filtered (_(" (%s) pending."), b->addr_string);
6730 if (opts.addressprint || b->source_file == NULL)
6732 printf_filtered (" at ");
6733 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
6737 printf_filtered (": file %s, line %d.",
6738 b->source_file, b->line_number);
6742 struct bp_location *loc = b->loc;
6744 for (; loc; loc = loc->next)
6746 printf_filtered (" (%d locations)", n);
6751 if (ui_out_is_mi_like_p (uiout))
6753 printf_filtered ("\n");
6757 static struct bp_location *
6758 add_location_to_breakpoint (struct breakpoint *b,
6759 const struct symtab_and_line *sal)
6761 struct bp_location *loc, **tmp;
6763 loc = allocate_bp_location (b);
6764 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
6767 loc->gdbarch = get_sal_arch (*sal);
6769 loc->gdbarch = b->gdbarch;
6770 loc->requested_address = sal->pc;
6771 loc->address = adjust_breakpoint_address (loc->gdbarch,
6772 loc->requested_address, b->type);
6773 loc->pspace = sal->pspace;
6774 gdb_assert (loc->pspace != NULL);
6775 loc->section = sal->section;
6777 set_breakpoint_location_function (loc);
6782 /* Return 1 if LOC is pointing to a permanent breakpoint,
6783 return 0 otherwise. */
6786 bp_loc_is_permanent (struct bp_location *loc)
6790 const gdb_byte *brk;
6791 gdb_byte *target_mem;
6792 struct cleanup *cleanup;
6795 gdb_assert (loc != NULL);
6797 addr = loc->address;
6798 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6800 /* Software breakpoints unsupported? */
6804 target_mem = alloca (len);
6806 /* Enable the automatic memory restoration from breakpoints while
6807 we read the memory. Otherwise we could say about our temporary
6808 breakpoints they are permanent. */
6809 cleanup = save_current_space_and_thread ();
6811 switch_to_program_space_and_thread (loc->pspace);
6812 make_show_memory_breakpoints_cleanup (0);
6814 if (target_read_memory (loc->address, target_mem, len) == 0
6815 && memcmp (target_mem, brk, len) == 0)
6818 do_cleanups (cleanup);
6825 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6826 as textual description of the location, and COND_STRING
6827 as condition expression. */
6830 create_breakpoint_sal (struct gdbarch *gdbarch,
6831 struct symtabs_and_lines sals, char *addr_string,
6833 enum bptype type, enum bpdisp disposition,
6834 int thread, int task, int ignore_count,
6835 struct breakpoint_ops *ops, int from_tty, int enabled)
6837 struct breakpoint *b = NULL;
6840 if (type == bp_hardware_breakpoint)
6842 int i = hw_breakpoint_used_count ();
6843 int target_resources_ok =
6844 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
6846 if (target_resources_ok == 0)
6847 error (_("No hardware breakpoint support in the target."));
6848 else if (target_resources_ok < 0)
6849 error (_("Hardware breakpoints used exceeds limit."));
6852 gdb_assert (sals.nelts > 0);
6854 for (i = 0; i < sals.nelts; ++i)
6856 struct symtab_and_line sal = sals.sals[i];
6857 struct bp_location *loc;
6861 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
6863 loc_gdbarch = gdbarch;
6865 describe_other_breakpoints (loc_gdbarch,
6866 sal.pspace, sal.pc, sal.section, thread);
6871 b = set_raw_breakpoint (gdbarch, sal, type);
6872 set_breakpoint_count (breakpoint_count + 1);
6873 b->number = breakpoint_count;
6877 b->cond_string = cond_string;
6878 b->ignore_count = ignore_count;
6879 b->enable_state = enabled ? bp_enabled : bp_disabled;
6880 b->disposition = disposition;
6882 b->pspace = sals.sals[0].pspace;
6884 if (enabled && b->pspace->executing_startup
6885 && (b->type == bp_breakpoint
6886 || b->type == bp_hardware_breakpoint))
6887 b->enable_state = bp_startup_disabled;
6893 loc = add_location_to_breakpoint (b, &sal);
6896 if (bp_loc_is_permanent (loc))
6897 make_breakpoint_permanent (b);
6901 char *arg = b->cond_string;
6902 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
6904 error (_("Garbage %s follows condition"), arg);
6909 b->addr_string = addr_string;
6911 /* addr_string has to be used or breakpoint_re_set will delete
6914 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6920 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6921 elements to fill the void space. */
6923 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
6925 int i = index_to_remove+1;
6926 int last_index = sal->nelts-1;
6928 for (;i <= last_index; ++i)
6929 sal->sals[i-1] = sal->sals[i];
6934 /* If appropriate, obtains all sals that correspond to the same file
6935 and line as SAL, in all program spaces. Users debugging with IDEs,
6936 will want to set a breakpoint at foo.c:line, and not really care
6937 about program spaces. This is done only if SAL does not have
6938 explicit PC and has line and file information. If we got just a
6939 single expanded sal, return the original.
6941 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6942 which the name of enclosing function is different from SAL. This
6943 makes sure that if we have breakpoint originally set in template
6944 instantiation, say foo<int>(), we won't expand SAL to locations at
6945 the same line in all existing instantiations of 'foo'. */
6947 static struct symtabs_and_lines
6948 expand_line_sal_maybe (struct symtab_and_line sal)
6950 struct symtabs_and_lines expanded;
6951 CORE_ADDR original_pc = sal.pc;
6952 char *original_function = NULL;
6955 struct cleanup *old_chain;
6957 /* If we have explicit pc, don't expand.
6958 If we have no line number, we can't expand. */
6959 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
6962 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
6963 expanded.sals[0] = sal;
6969 old_chain = save_current_space_and_thread ();
6971 switch_to_program_space_and_thread (sal.pspace);
6973 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
6975 /* Note that expand_line_sal visits *all* program spaces. */
6976 expanded = expand_line_sal (sal);
6978 if (expanded.nelts == 1)
6980 /* We had one sal, we got one sal. Return that sal, adjusting it
6981 past the function prologue if necessary. */
6982 xfree (expanded.sals);
6984 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
6985 sal.pc = original_pc;
6986 expanded.sals[0] = sal;
6987 skip_prologue_sal (&expanded.sals[0]);
6988 do_cleanups (old_chain);
6992 if (!sal.explicit_line)
6994 CORE_ADDR func_addr, func_end;
6995 for (i = 0; i < expanded.nelts; ++i)
6997 CORE_ADDR pc = expanded.sals[i].pc;
6998 char *this_function;
7000 /* We need to switch threads as well since we're about to
7002 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7004 if (find_pc_partial_function (pc, &this_function,
7005 &func_addr, &func_end))
7008 && strcmp (this_function, original_function) != 0)
7010 remove_sal (&expanded, i);
7017 /* Skip the function prologue if necessary. */
7018 for (i = 0; i < expanded.nelts; ++i)
7019 skip_prologue_sal (&expanded.sals[i]);
7021 do_cleanups (old_chain);
7023 if (expanded.nelts <= 1)
7025 /* This is un ugly workaround. If we get zero
7026 expanded sals then something is really wrong.
7027 Fix that by returnign the original sal. */
7028 xfree (expanded.sals);
7030 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7031 sal.pc = original_pc;
7032 expanded.sals[0] = sal;
7039 for (i = 0; i < expanded.nelts; ++i)
7040 if (expanded.sals[i].pc == original_pc)
7051 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7052 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7053 value. COND_STRING, if not NULL, specified the condition to be
7054 used for all breakpoints. Essentially the only case where
7055 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7056 function. In that case, it's still not possible to specify
7057 separate conditions for different overloaded functions, so
7058 we take just a single condition string.
7060 NOTE: If the function succeeds, the caller is expected to cleanup
7061 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7062 array contents). If the function fails (error() is called), the
7063 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7064 COND and SALS arrays and each of those arrays contents. */
7067 create_breakpoints_sal (struct gdbarch *gdbarch,
7068 struct symtabs_and_lines sals, char **addr_string,
7070 enum bptype type, enum bpdisp disposition,
7071 int thread, int task, int ignore_count,
7072 struct breakpoint_ops *ops, int from_tty,
7076 for (i = 0; i < sals.nelts; ++i)
7078 struct symtabs_and_lines expanded =
7079 expand_line_sal_maybe (sals.sals[i]);
7081 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7082 cond_string, type, disposition,
7083 thread, task, ignore_count, ops, from_tty, enabled);
7087 /* Parse ARG which is assumed to be a SAL specification possibly
7088 followed by conditionals. On return, SALS contains an array of SAL
7089 addresses found. ADDR_STRING contains a vector of (canonical)
7090 address strings. ARG points to the end of the SAL. */
7093 parse_breakpoint_sals (char **address,
7094 struct symtabs_and_lines *sals,
7095 char ***addr_string,
7098 char *addr_start = *address;
7099 *addr_string = NULL;
7100 /* If no arg given, or if first arg is 'if ', use the default
7102 if ((*address) == NULL
7103 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7105 if (default_breakpoint_valid)
7107 struct symtab_and_line sal;
7108 init_sal (&sal); /* initialize to zeroes */
7109 sals->sals = (struct symtab_and_line *)
7110 xmalloc (sizeof (struct symtab_and_line));
7111 sal.pc = default_breakpoint_address;
7112 sal.line = default_breakpoint_line;
7113 sal.symtab = default_breakpoint_symtab;
7114 sal.pspace = default_breakpoint_pspace;
7115 sal.section = find_pc_overlay (sal.pc);
7117 /* "break" without arguments is equivalent to "break *PC" where PC is
7118 the default_breakpoint_address. So make sure to set
7119 sal.explicit_pc to prevent GDB from trying to expand the list of
7120 sals to include all other instances with the same symtab and line.
7122 sal.explicit_pc = 1;
7124 sals->sals[0] = sal;
7128 error (_("No default breakpoint address now."));
7132 /* Force almost all breakpoints to be in terms of the
7133 current_source_symtab (which is decode_line_1's default). This
7134 should produce the results we want almost all of the time while
7135 leaving default_breakpoint_* alone.
7136 ObjC: However, don't match an Objective-C method name which
7137 may have a '+' or '-' succeeded by a '[' */
7139 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7141 if (default_breakpoint_valid
7143 || ((strchr ("+-", (*address)[0]) != NULL)
7144 && ((*address)[1] != '['))))
7145 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7146 default_breakpoint_line, addr_string,
7149 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7150 addr_string, not_found_ptr);
7152 /* For any SAL that didn't have a canonical string, fill one in. */
7153 if (sals->nelts > 0 && *addr_string == NULL)
7154 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7155 if (addr_start != (*address))
7158 for (i = 0; i < sals->nelts; i++)
7160 /* Add the string if not present. */
7161 if ((*addr_string)[i] == NULL)
7162 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
7168 /* Convert each SAL into a real PC. Verify that the PC can be
7169 inserted as a breakpoint. If it can't throw an error. */
7172 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
7176 for (i = 0; i < sals->nelts; i++)
7177 resolve_sal_pc (&sals->sals[i]);
7180 /* Fast tracepoints may have restrictions on valid locations. For
7181 instance, a fast tracepoint using a jump instead of a trap will
7182 likely have to overwrite more bytes than a trap would, and so can
7183 only be placed where the instruction is longer than the jump, or a
7184 multi-instruction sequence does not have a jump into the middle of
7188 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7189 struct symtabs_and_lines *sals)
7192 struct symtab_and_line *sal;
7194 struct cleanup *old_chain;
7196 for (i = 0; i < sals->nelts; i++)
7198 sal = &sals->sals[i];
7200 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7202 old_chain = make_cleanup (xfree, msg);
7205 error (_("May not have a fast tracepoint at 0x%s%s"),
7206 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7208 do_cleanups (old_chain);
7213 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7215 struct captured_parse_breakpoint_args *args = data;
7217 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7218 args->not_found_ptr);
7221 /* Given TOK, a string specification of condition and thread, as
7222 accepted by the 'break' command, extract the condition
7223 string and thread number and set *COND_STRING and *THREAD.
7224 PC identifies the context at which the condition should be parsed.
7225 If no condition is found, *COND_STRING is set to NULL.
7226 If no thread is found, *THREAD is set to -1. */
7228 find_condition_and_thread (char *tok, CORE_ADDR pc,
7229 char **cond_string, int *thread, int *task)
7231 *cond_string = NULL;
7237 char *cond_start = NULL;
7238 char *cond_end = NULL;
7239 while (*tok == ' ' || *tok == '\t')
7244 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7247 toklen = end_tok - tok;
7249 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7251 struct expression *expr;
7253 tok = cond_start = end_tok + 1;
7254 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7257 *cond_string = savestring (cond_start,
7258 cond_end - cond_start);
7260 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7266 *thread = strtol (tok, &tok, 0);
7268 error (_("Junk after thread keyword."));
7269 if (!valid_thread_id (*thread))
7270 error (_("Unknown thread %d."), *thread);
7272 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7278 *task = strtol (tok, &tok, 0);
7280 error (_("Junk after task keyword."));
7281 if (!valid_task_id (*task))
7282 error (_("Unknown task %d."), *task);
7285 error (_("Junk at end of arguments."));
7289 /* Set a breakpoint. This function is shared between CLI and MI
7290 functions for setting a breakpoint. This function has two major
7291 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7292 parameter. If non-zero, the function will parse arg, extracting
7293 breakpoint location, address and thread. Otherwise, ARG is just the
7294 location of breakpoint, with condition and thread specified by the
7295 COND_STRING and THREAD parameters. Returns true if any breakpoint
7296 was created; false otherwise. */
7299 create_breakpoint (struct gdbarch *gdbarch,
7300 char *arg, char *cond_string, int thread,
7301 int parse_condition_and_thread,
7302 int tempflag, int hardwareflag, int traceflag,
7304 enum auto_boolean pending_break_support,
7305 struct breakpoint_ops *ops,
7309 struct gdb_exception e;
7310 struct symtabs_and_lines sals;
7311 struct symtab_and_line pending_sal;
7313 char *addr_start = arg;
7315 struct cleanup *old_chain;
7316 struct cleanup *bkpt_chain = NULL;
7317 struct captured_parse_breakpoint_args parse_args;
7321 enum bptype type_wanted;
7323 int prev_bkpt_count = breakpoint_count;
7329 parse_args.arg_p = &arg;
7330 parse_args.sals_p = &sals;
7331 parse_args.addr_string_p = &addr_string;
7332 parse_args.not_found_ptr = ¬_found;
7334 e = catch_exception (uiout, do_captured_parse_breakpoint,
7335 &parse_args, RETURN_MASK_ALL);
7337 /* If caller is interested in rc value from parse, set value. */
7341 throw_exception (e);
7345 case NOT_FOUND_ERROR:
7347 /* If pending breakpoint support is turned off, throw
7350 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7351 throw_exception (e);
7353 exception_print (gdb_stderr, e);
7355 /* If pending breakpoint support is auto query and the user
7356 selects no, then simply return the error code. */
7357 if (pending_break_support == AUTO_BOOLEAN_AUTO
7358 && !nquery ("Make breakpoint pending on future shared library load? "))
7361 /* At this point, either the user was queried about setting
7362 a pending breakpoint and selected yes, or pending
7363 breakpoint behavior is on and thus a pending breakpoint
7364 is defaulted on behalf of the user. */
7365 copy_arg = xstrdup (addr_start);
7366 addr_string = ©_arg;
7368 sals.sals = &pending_sal;
7373 throw_exception (e);
7380 /* Create a chain of things that always need to be cleaned up. */
7381 old_chain = make_cleanup (null_cleanup, 0);
7385 /* Make sure that all storage allocated to SALS gets freed. */
7386 make_cleanup (xfree, sals.sals);
7388 /* Cleanup the addr_string array but not its contents. */
7389 make_cleanup (xfree, addr_string);
7392 /* ----------------------------- SNIP -----------------------------
7393 Anything added to the cleanup chain beyond this point is assumed
7394 to be part of a breakpoint. If the breakpoint create succeeds
7395 then the memory is not reclaimed. */
7396 bkpt_chain = make_cleanup (null_cleanup, 0);
7398 /* Mark the contents of the addr_string for cleanup. These go on
7399 the bkpt_chain and only occur if the breakpoint create fails. */
7400 for (i = 0; i < sals.nelts; i++)
7402 if (addr_string[i] != NULL)
7403 make_cleanup (xfree, addr_string[i]);
7406 /* Resolve all line numbers to PC's and verify that the addresses
7407 are ok for the target. */
7409 breakpoint_sals_to_pc (&sals, addr_start);
7411 type_wanted = (traceflag
7412 ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint)
7413 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
7415 /* Fast tracepoints may have additional restrictions on location. */
7416 if (type_wanted == bp_fast_tracepoint)
7417 check_fast_tracepoint_sals (gdbarch, &sals);
7419 /* Verify that condition can be parsed, before setting any
7420 breakpoints. Allocate a separate condition expression for each
7424 if (parse_condition_and_thread)
7426 /* Here we only parse 'arg' to separate condition
7427 from thread number, so parsing in context of first
7428 sal is OK. When setting the breakpoint we'll
7429 re-parse it in context of each sal. */
7432 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7435 make_cleanup (xfree, cond_string);
7439 /* Create a private copy of condition string. */
7442 cond_string = xstrdup (cond_string);
7443 make_cleanup (xfree, cond_string);
7446 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7447 type_wanted, tempflag ? disp_del : disp_donttouch,
7448 thread, task, ignore_count, ops, from_tty,
7453 struct breakpoint *b;
7455 make_cleanup (xfree, copy_arg);
7457 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7458 set_breakpoint_count (breakpoint_count + 1);
7459 b->number = breakpoint_count;
7461 b->addr_string = addr_string[0];
7462 b->cond_string = NULL;
7463 b->ignore_count = ignore_count;
7464 b->disposition = tempflag ? disp_del : disp_donttouch;
7465 b->condition_not_parsed = 1;
7467 b->enable_state = enabled ? bp_enabled : bp_disabled;
7468 b->pspace = current_program_space;
7470 if (enabled && b->pspace->executing_startup
7471 && (b->type == bp_breakpoint
7472 || b->type == bp_hardware_breakpoint))
7473 b->enable_state = bp_startup_disabled;
7480 warning (_("Multiple breakpoints were set.\n"
7481 "Use the \"delete\" command to delete unwanted breakpoints."));
7482 prev_breakpoint_count = prev_bkpt_count;
7485 /* That's it. Discard the cleanups for data inserted into the
7487 discard_cleanups (bkpt_chain);
7488 /* But cleanup everything else. */
7489 do_cleanups (old_chain);
7491 /* error call may happen here - have BKPT_CHAIN already discarded. */
7492 update_global_location_list (1);
7497 /* Set a breakpoint.
7498 ARG is a string describing breakpoint address,
7499 condition, and thread.
7500 FLAG specifies if a breakpoint is hardware on,
7501 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7505 break_command_1 (char *arg, int flag, int from_tty)
7507 int hardwareflag = flag & BP_HARDWAREFLAG;
7508 int tempflag = flag & BP_TEMPFLAG;
7510 create_breakpoint (get_current_arch (),
7512 NULL, 0, 1 /* parse arg */,
7513 tempflag, hardwareflag, 0 /* traceflag */,
7514 0 /* Ignore count */,
7515 pending_break_support,
7516 NULL /* breakpoint_ops */,
7523 /* Helper function for break_command_1 and disassemble_command. */
7526 resolve_sal_pc (struct symtab_and_line *sal)
7530 if (sal->pc == 0 && sal->symtab != NULL)
7532 if (!find_line_pc (sal->symtab, sal->line, &pc))
7533 error (_("No line %d in file \"%s\"."),
7534 sal->line, sal->symtab->filename);
7537 /* If this SAL corresponds to a breakpoint inserted using
7538 a line number, then skip the function prologue if necessary. */
7539 if (sal->explicit_line)
7540 skip_prologue_sal (sal);
7543 if (sal->section == 0 && sal->symtab != NULL)
7545 struct blockvector *bv;
7549 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7552 sym = block_linkage_function (b);
7555 fixup_symbol_section (sym, sal->symtab->objfile);
7556 sal->section = SYMBOL_OBJ_SECTION (sym);
7560 /* It really is worthwhile to have the section, so we'll just
7561 have to look harder. This case can be executed if we have
7562 line numbers but no functions (as can happen in assembly
7565 struct minimal_symbol *msym;
7566 struct cleanup *old_chain = save_current_space_and_thread ();
7568 switch_to_program_space_and_thread (sal->pspace);
7570 msym = lookup_minimal_symbol_by_pc (sal->pc);
7572 sal->section = SYMBOL_OBJ_SECTION (msym);
7574 do_cleanups (old_chain);
7581 break_command (char *arg, int from_tty)
7583 break_command_1 (arg, 0, from_tty);
7587 tbreak_command (char *arg, int from_tty)
7589 break_command_1 (arg, BP_TEMPFLAG, from_tty);
7593 hbreak_command (char *arg, int from_tty)
7595 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
7599 thbreak_command (char *arg, int from_tty)
7601 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
7605 stop_command (char *arg, int from_tty)
7607 printf_filtered (_("Specify the type of breakpoint to set.\n\
7608 Usage: stop in <function | address>\n\
7609 stop at <line>\n"));
7613 stopin_command (char *arg, int from_tty)
7617 if (arg == (char *) NULL)
7619 else if (*arg != '*')
7624 /* look for a ':'. If this is a line number specification, then
7625 say it is bad, otherwise, it should be an address or
7626 function/method name */
7627 while (*argptr && !hasColon)
7629 hasColon = (*argptr == ':');
7634 badInput = (*argptr != ':'); /* Not a class::method */
7636 badInput = isdigit (*arg); /* a simple line number */
7640 printf_filtered (_("Usage: stop in <function | address>\n"));
7642 break_command_1 (arg, 0, from_tty);
7646 stopat_command (char *arg, int from_tty)
7650 if (arg == (char *) NULL || *arg == '*') /* no line number */
7657 /* look for a ':'. If there is a '::' then get out, otherwise
7658 it is probably a line number. */
7659 while (*argptr && !hasColon)
7661 hasColon = (*argptr == ':');
7666 badInput = (*argptr == ':'); /* we have class::method */
7668 badInput = !isdigit (*arg); /* not a line number */
7672 printf_filtered (_("Usage: stop at <line>\n"));
7674 break_command_1 (arg, 0, from_tty);
7677 /* accessflag: hw_write: watch write,
7678 hw_read: watch read,
7679 hw_access: watch access (read or write) */
7681 watch_command_1 (char *arg, int accessflag, int from_tty)
7683 struct breakpoint *b, *scope_breakpoint = NULL;
7684 struct expression *exp;
7685 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
7686 struct value *val, *mark;
7687 struct frame_info *frame;
7688 char *exp_start = NULL;
7689 char *exp_end = NULL;
7690 char *tok, *id_tok_start, *end_tok;
7692 char *cond_start = NULL;
7693 char *cond_end = NULL;
7694 int i, other_type_used, target_resources_ok = 0;
7695 enum bptype bp_type;
7699 /* Make sure that we actually have parameters to parse. */
7700 if (arg != NULL && arg[0] != '\0')
7702 toklen = strlen (arg); /* Size of argument list. */
7704 /* Points tok to the end of the argument list. */
7705 tok = arg + toklen - 1;
7707 /* Go backwards in the parameters list. Skip the last parameter.
7708 If we're expecting a 'thread <thread_num>' parameter, this should
7709 be the thread identifier. */
7710 while (tok > arg && (*tok == ' ' || *tok == '\t'))
7712 while (tok > arg && (*tok != ' ' && *tok != '\t'))
7715 /* Points end_tok to the beginning of the last token. */
7716 id_tok_start = tok + 1;
7718 /* Go backwards in the parameters list. Skip one more parameter.
7719 If we're expecting a 'thread <thread_num>' parameter, we should
7720 reach a "thread" token. */
7721 while (tok > arg && (*tok == ' ' || *tok == '\t'))
7726 while (tok > arg && (*tok != ' ' && *tok != '\t'))
7729 /* Move the pointer forward to skip the whitespace and
7730 calculate the length of the token. */
7732 toklen = end_tok - tok;
7734 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7736 /* At this point we've found a "thread" token, which means
7737 the user is trying to set a watchpoint that triggers
7738 only in a specific thread. */
7741 /* Extract the thread ID from the next token. */
7742 thread = strtol (id_tok_start, &endp, 0);
7744 /* Check if the user provided a valid numeric value for the
7746 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
7747 error (_("Invalid thread ID specification %s."), id_tok_start);
7749 /* Check if the thread actually exists. */
7750 if (!valid_thread_id (thread))
7751 error (_("Unknown thread %d."), thread);
7753 /* Truncate the string and get rid of the thread <thread_num>
7754 parameter before the parameter list is parsed by the
7755 evaluate_expression() function. */
7760 /* Parse the rest of the arguments. */
7761 innermost_block = NULL;
7763 exp = parse_exp_1 (&arg, 0, 0);
7765 /* Remove trailing whitespace from the expression before saving it.
7766 This makes the eventual display of the expression string a bit
7768 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
7771 exp_valid_block = innermost_block;
7772 mark = value_mark ();
7773 fetch_watchpoint_value (exp, &val, NULL, NULL);
7775 release_value (val);
7778 while (*tok == ' ' || *tok == '\t')
7782 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7785 toklen = end_tok - tok;
7786 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7788 struct expression *cond;
7790 innermost_block = NULL;
7791 tok = cond_start = end_tok + 1;
7792 cond = parse_exp_1 (&tok, 0, 0);
7794 /* The watchpoint expression may not be local, but the condition
7795 may still be. E.g.: `watch global if local > 0'. */
7796 cond_exp_valid_block = innermost_block;
7802 error (_("Junk at end of command."));
7804 if (accessflag == hw_read)
7805 bp_type = bp_read_watchpoint;
7806 else if (accessflag == hw_access)
7807 bp_type = bp_access_watchpoint;
7809 bp_type = bp_hardware_watchpoint;
7811 mem_cnt = can_use_hardware_watchpoint (val);
7812 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
7813 error (_("Expression cannot be implemented with read/access watchpoint."));
7816 i = hw_watchpoint_used_count (bp_type, &other_type_used);
7817 target_resources_ok =
7818 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
7820 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
7821 error (_("Target does not support this type of hardware watchpoint."));
7823 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
7824 error (_("Target can only support one kind of HW watchpoint at a time."));
7827 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7828 watchpoint could not be set. */
7829 if (!mem_cnt || target_resources_ok <= 0)
7830 bp_type = bp_watchpoint;
7832 frame = block_innermost_frame (exp_valid_block);
7834 /* If the expression is "local", then set up a "watchpoint scope"
7835 breakpoint at the point where we've left the scope of the watchpoint
7836 expression. Create the scope breakpoint before the watchpoint, so
7837 that we will encounter it first in bpstat_stop_status. */
7838 if (exp_valid_block && frame)
7840 if (frame_id_p (frame_unwind_caller_id (frame)))
7843 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
7844 frame_unwind_caller_pc (frame),
7845 bp_watchpoint_scope);
7847 scope_breakpoint->enable_state = bp_enabled;
7849 /* Automatically delete the breakpoint when it hits. */
7850 scope_breakpoint->disposition = disp_del;
7852 /* Only break in the proper frame (help with recursion). */
7853 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
7855 /* Set the address at which we will stop. */
7856 scope_breakpoint->loc->gdbarch
7857 = frame_unwind_caller_arch (frame);
7858 scope_breakpoint->loc->requested_address
7859 = frame_unwind_caller_pc (frame);
7860 scope_breakpoint->loc->address
7861 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
7862 scope_breakpoint->loc->requested_address,
7863 scope_breakpoint->type);
7867 /* Now set up the breakpoint. */
7868 b = set_raw_breakpoint_without_location (NULL, bp_type);
7869 set_breakpoint_count (breakpoint_count + 1);
7870 b->number = breakpoint_count;
7872 b->disposition = disp_donttouch;
7874 b->exp_valid_block = exp_valid_block;
7875 b->cond_exp_valid_block = cond_exp_valid_block;
7876 b->exp_string = savestring (exp_start, exp_end - exp_start);
7880 b->cond_string = savestring (cond_start, cond_end - cond_start);
7886 b->watchpoint_frame = get_frame_id (frame);
7887 b->watchpoint_thread = inferior_ptid;
7891 b->watchpoint_frame = null_frame_id;
7892 b->watchpoint_thread = null_ptid;
7895 if (scope_breakpoint != NULL)
7897 /* The scope breakpoint is related to the watchpoint. We will
7898 need to act on them together. */
7899 b->related_breakpoint = scope_breakpoint;
7900 scope_breakpoint->related_breakpoint = b;
7903 value_free_to_mark (mark);
7905 /* Finally update the new watchpoint. This creates the locations
7906 that should be inserted. */
7907 update_watchpoint (b, 1);
7910 update_global_location_list (1);
7913 /* Return count of locations need to be watched and can be handled
7914 in hardware. If the watchpoint can not be handled
7915 in hardware return zero. */
7918 can_use_hardware_watchpoint (struct value *v)
7920 int found_memory_cnt = 0;
7921 struct value *head = v;
7923 /* Did the user specifically forbid us to use hardware watchpoints? */
7924 if (!can_use_hw_watchpoints)
7927 /* Make sure that the value of the expression depends only upon
7928 memory contents, and values computed from them within GDB. If we
7929 find any register references or function calls, we can't use a
7930 hardware watchpoint.
7932 The idea here is that evaluating an expression generates a series
7933 of values, one holding the value of every subexpression. (The
7934 expression a*b+c has five subexpressions: a, b, a*b, c, and
7935 a*b+c.) GDB's values hold almost enough information to establish
7936 the criteria given above --- they identify memory lvalues,
7937 register lvalues, computed values, etcetera. So we can evaluate
7938 the expression, and then scan the chain of values that leaves
7939 behind to decide whether we can detect any possible change to the
7940 expression's final value using only hardware watchpoints.
7942 However, I don't think that the values returned by inferior
7943 function calls are special in any way. So this function may not
7944 notice that an expression involving an inferior function call
7945 can't be watched with hardware watchpoints. FIXME. */
7946 for (; v; v = value_next (v))
7948 if (VALUE_LVAL (v) == lval_memory)
7951 /* A lazy memory lvalue is one that GDB never needed to fetch;
7952 we either just used its address (e.g., `a' in `a.b') or
7953 we never needed it at all (e.g., `a' in `a,b'). */
7957 /* Ahh, memory we actually used! Check if we can cover
7958 it with hardware watchpoints. */
7959 struct type *vtype = check_typedef (value_type (v));
7961 /* We only watch structs and arrays if user asked for it
7962 explicitly, never if they just happen to appear in a
7963 middle of some value chain. */
7965 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
7966 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
7968 CORE_ADDR vaddr = value_address (v);
7969 int len = TYPE_LENGTH (value_type (v));
7971 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
7978 else if (VALUE_LVAL (v) != not_lval
7979 && deprecated_value_modifiable (v) == 0)
7980 return 0; /* ??? What does this represent? */
7981 else if (VALUE_LVAL (v) == lval_register)
7982 return 0; /* cannot watch a register with a HW watchpoint */
7985 /* The expression itself looks suitable for using a hardware
7986 watchpoint, but give the target machine a chance to reject it. */
7987 return found_memory_cnt;
7991 watch_command_wrapper (char *arg, int from_tty)
7993 watch_command (arg, from_tty);
7997 watch_command (char *arg, int from_tty)
7999 watch_command_1 (arg, hw_write, from_tty);
8003 rwatch_command_wrapper (char *arg, int from_tty)
8005 rwatch_command (arg, from_tty);
8009 rwatch_command (char *arg, int from_tty)
8011 watch_command_1 (arg, hw_read, from_tty);
8015 awatch_command_wrapper (char *arg, int from_tty)
8017 awatch_command (arg, from_tty);
8021 awatch_command (char *arg, int from_tty)
8023 watch_command_1 (arg, hw_access, from_tty);
8027 /* Helper routines for the until_command routine in infcmd.c. Here
8028 because it uses the mechanisms of breakpoints. */
8030 struct until_break_command_continuation_args
8032 struct breakpoint *breakpoint;
8033 struct breakpoint *breakpoint2;
8036 /* This function is called by fetch_inferior_event via the
8037 cmd_continuation pointer, to complete the until command. It takes
8038 care of cleaning up the temporary breakpoints set up by the until
8041 until_break_command_continuation (void *arg)
8043 struct until_break_command_continuation_args *a = arg;
8045 delete_breakpoint (a->breakpoint);
8047 delete_breakpoint (a->breakpoint2);
8051 until_break_command (char *arg, int from_tty, int anywhere)
8053 struct symtabs_and_lines sals;
8054 struct symtab_and_line sal;
8055 struct frame_info *frame = get_selected_frame (NULL);
8056 struct breakpoint *breakpoint;
8057 struct breakpoint *breakpoint2 = NULL;
8058 struct cleanup *old_chain;
8060 clear_proceed_status ();
8062 /* Set a breakpoint where the user wants it and at return from
8065 if (default_breakpoint_valid)
8066 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8067 default_breakpoint_line, (char ***) NULL, NULL);
8069 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8070 0, (char ***) NULL, NULL);
8072 if (sals.nelts != 1)
8073 error (_("Couldn't get information on specified line."));
8076 xfree (sals.sals); /* malloc'd, so freed */
8079 error (_("Junk at end of arguments."));
8081 resolve_sal_pc (&sal);
8084 /* If the user told us to continue until a specified location,
8085 we don't specify a frame at which we need to stop. */
8086 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8087 null_frame_id, bp_until);
8089 /* Otherwise, specify the selected frame, because we want to stop only
8090 at the very same frame. */
8091 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8092 get_stack_frame_id (frame),
8095 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8097 /* Keep within the current frame, or in frames called by the current
8100 if (frame_id_p (frame_unwind_caller_id (frame)))
8102 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8103 sal.pc = frame_unwind_caller_pc (frame);
8104 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8106 frame_unwind_caller_id (frame),
8108 make_cleanup_delete_breakpoint (breakpoint2);
8111 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8113 /* If we are running asynchronously, and proceed call above has actually
8114 managed to start the target, arrange for breakpoints to be
8115 deleted when the target stops. Otherwise, we're already stopped and
8116 delete breakpoints via cleanup chain. */
8118 if (target_can_async_p () && is_running (inferior_ptid))
8120 struct until_break_command_continuation_args *args;
8121 args = xmalloc (sizeof (*args));
8123 args->breakpoint = breakpoint;
8124 args->breakpoint2 = breakpoint2;
8126 discard_cleanups (old_chain);
8127 add_continuation (inferior_thread (),
8128 until_break_command_continuation, args,
8132 do_cleanups (old_chain);
8136 ep_skip_leading_whitespace (char **s)
8138 if ((s == NULL) || (*s == NULL))
8140 while (isspace (**s))
8144 /* This function attempts to parse an optional "if <cond>" clause
8145 from the arg string. If one is not found, it returns NULL.
8147 Else, it returns a pointer to the condition string. (It does not
8148 attempt to evaluate the string against a particular block.) And,
8149 it updates arg to point to the first character following the parsed
8150 if clause in the arg string. */
8153 ep_parse_optional_if_clause (char **arg)
8157 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8160 /* Skip the "if" keyword. */
8163 /* Skip any extra leading whitespace, and record the start of the
8164 condition string. */
8165 ep_skip_leading_whitespace (arg);
8168 /* Assume that the condition occupies the remainder of the arg string. */
8169 (*arg) += strlen (cond_string);
8174 /* Commands to deal with catching events, such as signals, exceptions,
8175 process start/exit, etc. */
8179 catch_fork_temporary, catch_vfork_temporary,
8180 catch_fork_permanent, catch_vfork_permanent
8185 catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
8187 struct gdbarch *gdbarch = get_current_arch ();
8188 char *cond_string = NULL;
8189 catch_fork_kind fork_kind;
8192 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8193 tempflag = (fork_kind == catch_fork_temporary
8194 || fork_kind == catch_vfork_temporary);
8198 ep_skip_leading_whitespace (&arg);
8200 /* The allowed syntax is:
8202 catch [v]fork if <cond>
8204 First, check if there's an if clause. */
8205 cond_string = ep_parse_optional_if_clause (&arg);
8207 if ((*arg != '\0') && !isspace (*arg))
8208 error (_("Junk at end of arguments."));
8210 /* If this target supports it, create a fork or vfork catchpoint
8211 and enable reporting of such events. */
8214 case catch_fork_temporary:
8215 case catch_fork_permanent:
8216 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8217 &catch_fork_breakpoint_ops);
8219 case catch_vfork_temporary:
8220 case catch_vfork_permanent:
8221 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8222 &catch_vfork_breakpoint_ops);
8225 error (_("unsupported or unknown fork kind; cannot catch it"));
8231 catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
8233 struct gdbarch *gdbarch = get_current_arch ();
8235 char *cond_string = NULL;
8237 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8241 ep_skip_leading_whitespace (&arg);
8243 /* The allowed syntax is:
8245 catch exec if <cond>
8247 First, check if there's an if clause. */
8248 cond_string = ep_parse_optional_if_clause (&arg);
8250 if ((*arg != '\0') && !isspace (*arg))
8251 error (_("Junk at end of arguments."));
8253 /* If this target supports it, create an exec catchpoint
8254 and enable reporting of such events. */
8255 create_catchpoint (gdbarch, tempflag, cond_string,
8256 &catch_exec_breakpoint_ops);
8259 static enum print_stop_action
8260 print_exception_catchpoint (struct breakpoint *b)
8262 int bp_temp, bp_throw;
8264 annotate_catchpoint (b->number);
8266 bp_throw = strstr (b->addr_string, "throw") != NULL;
8267 if (b->loc->address != b->loc->requested_address)
8268 breakpoint_adjustment_warning (b->loc->requested_address,
8271 bp_temp = b->disposition == disp_del;
8273 bp_temp ? "Temporary catchpoint "
8275 if (!ui_out_is_mi_like_p (uiout))
8276 ui_out_field_int (uiout, "bkptno", b->number);
8278 bp_throw ? " (exception thrown), "
8279 : " (exception caught), ");
8280 if (ui_out_is_mi_like_p (uiout))
8282 ui_out_field_string (uiout, "reason",
8283 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8284 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8285 ui_out_field_int (uiout, "bkptno", b->number);
8287 return PRINT_SRC_AND_LOC;
8291 print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc)
8293 struct value_print_options opts;
8294 get_user_print_options (&opts);
8295 if (opts.addressprint)
8298 if (b->loc == NULL || b->loc->shlib_disabled)
8299 ui_out_field_string (uiout, "addr", "<PENDING>");
8301 ui_out_field_core_addr (uiout, "addr",
8302 b->loc->gdbarch, b->loc->address);
8307 if (strstr (b->addr_string, "throw") != NULL)
8308 ui_out_field_string (uiout, "what", "exception throw");
8310 ui_out_field_string (uiout, "what", "exception catch");
8314 print_mention_exception_catchpoint (struct breakpoint *b)
8319 bp_temp = b->disposition == disp_del;
8320 bp_throw = strstr (b->addr_string, "throw") != NULL;
8321 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
8322 : _("Catchpoint "));
8323 ui_out_field_int (uiout, "bkptno", b->number);
8324 ui_out_text (uiout, bp_throw ? _(" (throw)")
8328 /* Implement the "print_recreate" breakpoint_ops method for throw and
8329 catch catchpoints. */
8332 print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
8337 bp_temp = b->disposition == disp_del;
8338 bp_throw = strstr (b->addr_string, "throw") != NULL;
8339 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
8340 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
8343 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
8346 NULL, /* breakpoint_hit */
8347 print_exception_catchpoint,
8348 print_one_exception_catchpoint,
8349 print_mention_exception_catchpoint,
8350 print_recreate_exception_catchpoint
8354 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
8355 enum exception_event_kind ex_event, int from_tty)
8357 char *trigger_func_name;
8359 if (ex_event == EX_EVENT_CATCH)
8360 trigger_func_name = "__cxa_begin_catch";
8362 trigger_func_name = "__cxa_throw";
8364 create_breakpoint (get_current_arch (),
8365 trigger_func_name, cond_string, -1,
8366 0 /* condition and thread are valid. */,
8369 AUTO_BOOLEAN_TRUE /* pending */,
8370 &gnu_v3_exception_catchpoint_ops, from_tty,
8376 /* Deal with "catch catch" and "catch throw" commands */
8379 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
8380 int tempflag, int from_tty)
8382 char *cond_string = NULL;
8386 ep_skip_leading_whitespace (&arg);
8388 cond_string = ep_parse_optional_if_clause (&arg);
8390 if ((*arg != '\0') && !isspace (*arg))
8391 error (_("Junk at end of arguments."));
8393 if (ex_event != EX_EVENT_THROW
8394 && ex_event != EX_EVENT_CATCH)
8395 error (_("Unsupported or unknown exception event; cannot catch it"));
8397 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
8400 warning (_("Unsupported with this platform/compiler combination."));
8403 /* Implementation of "catch catch" command. */
8406 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
8408 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8409 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
8412 /* Implementation of "catch throw" command. */
8415 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
8417 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8418 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
8421 /* Create a breakpoint struct for Ada exception catchpoints. */
8424 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
8425 struct symtab_and_line sal,
8429 struct expression *cond,
8430 struct breakpoint_ops *ops,
8434 struct breakpoint *b;
8438 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8440 loc_gdbarch = gdbarch;
8442 describe_other_breakpoints (loc_gdbarch,
8443 sal.pspace, sal.pc, sal.section, -1);
8444 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8445 version for exception catchpoints, because two catchpoints
8446 used for different exception names will use the same address.
8447 In this case, a "breakpoint ... also set at..." warning is
8448 unproductive. Besides. the warning phrasing is also a bit
8449 inapropriate, we should use the word catchpoint, and tell
8450 the user what type of catchpoint it is. The above is good
8451 enough for now, though. */
8454 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
8455 set_breakpoint_count (breakpoint_count + 1);
8457 b->enable_state = bp_enabled;
8458 b->disposition = tempflag ? disp_del : disp_donttouch;
8459 b->number = breakpoint_count;
8460 b->ignore_count = 0;
8461 b->loc->cond = cond;
8462 b->addr_string = addr_string;
8463 b->language = language_ada;
8464 b->cond_string = cond_string;
8465 b->exp_string = exp_string;
8470 update_global_location_list (1);
8473 /* Implement the "catch exception" command. */
8476 catch_ada_exception_command (char *arg, int from_tty,
8477 struct cmd_list_element *command)
8479 struct gdbarch *gdbarch = get_current_arch ();
8481 struct symtab_and_line sal;
8482 char *addr_string = NULL;
8483 char *exp_string = NULL;
8484 char *cond_string = NULL;
8485 struct expression *cond = NULL;
8486 struct breakpoint_ops *ops = NULL;
8488 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8492 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
8493 &cond_string, &cond, &ops);
8494 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
8495 cond_string, cond, ops, tempflag,
8499 /* Cleanup function for a syscall filter list. */
8501 clean_up_filters (void *arg)
8503 VEC(int) *iter = *(VEC(int) **) arg;
8504 VEC_free (int, iter);
8507 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8508 filter list, or NULL if no filtering is required. */
8510 catch_syscall_split_args (char *arg)
8512 VEC(int) *result = NULL;
8513 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
8515 while (*arg != '\0')
8517 int i, syscall_number;
8522 /* Skip whitespace. */
8523 while (isspace (*arg))
8526 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
8527 cur_name[i] = arg[i];
8531 /* Check if the user provided a syscall name or a number. */
8532 syscall_number = (int) strtol (cur_name, &endptr, 0);
8533 if (*endptr == '\0')
8534 get_syscall_by_number (syscall_number, &s);
8537 /* We have a name. Let's check if it's valid and convert it
8539 get_syscall_by_name (cur_name, &s);
8541 if (s.number == UNKNOWN_SYSCALL)
8542 /* Here we have to issue an error instead of a warning, because
8543 GDB cannot do anything useful if there's no syscall number to
8545 error (_("Unknown syscall name '%s'."), cur_name);
8548 /* Ok, it's valid. */
8549 VEC_safe_push (int, result, s.number);
8552 discard_cleanups (cleanup);
8556 /* Implement the "catch syscall" command. */
8559 catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
8564 struct gdbarch *gdbarch = get_current_arch ();
8566 /* Checking if the feature if supported. */
8567 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
8568 error (_("The feature 'catch syscall' is not supported on \
8569 this architeture yet."));
8571 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8573 ep_skip_leading_whitespace (&arg);
8575 /* We need to do this first "dummy" translation in order
8576 to get the syscall XML file loaded or, most important,
8577 to display a warning to the user if there's no XML file
8578 for his/her architecture. */
8579 get_syscall_by_number (0, &s);
8581 /* The allowed syntax is:
8583 catch syscall <name | number> [<name | number> ... <name | number>]
8585 Let's check if there's a syscall name. */
8588 filter = catch_syscall_split_args (arg);
8592 create_syscall_event_catchpoint (tempflag, filter,
8593 &catch_syscall_breakpoint_ops);
8596 /* Implement the "catch assert" command. */
8599 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
8601 struct gdbarch *gdbarch = get_current_arch ();
8603 struct symtab_and_line sal;
8604 char *addr_string = NULL;
8605 struct breakpoint_ops *ops = NULL;
8607 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8611 sal = ada_decode_assert_location (arg, &addr_string, &ops);
8612 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
8613 ops, tempflag, from_tty);
8617 catch_command (char *arg, int from_tty)
8619 error (_("Catch requires an event name."));
8624 tcatch_command (char *arg, int from_tty)
8626 error (_("Catch requires an event name."));
8629 /* Delete breakpoints by address or line. */
8632 clear_command (char *arg, int from_tty)
8634 struct breakpoint *b;
8635 VEC(breakpoint_p) *found = 0;
8638 struct symtabs_and_lines sals;
8639 struct symtab_and_line sal;
8644 sals = decode_line_spec (arg, 1);
8649 sals.sals = (struct symtab_and_line *)
8650 xmalloc (sizeof (struct symtab_and_line));
8651 make_cleanup (xfree, sals.sals);
8652 init_sal (&sal); /* initialize to zeroes */
8653 sal.line = default_breakpoint_line;
8654 sal.symtab = default_breakpoint_symtab;
8655 sal.pc = default_breakpoint_address;
8656 sal.pspace = default_breakpoint_pspace;
8657 if (sal.symtab == 0)
8658 error (_("No source file specified."));
8666 /* We don't call resolve_sal_pc here. That's not
8667 as bad as it seems, because all existing breakpoints
8668 typically have both file/line and pc set. So, if
8669 clear is given file/line, we can match this to existing
8670 breakpoint without obtaining pc at all.
8672 We only support clearing given the address explicitly
8673 present in breakpoint table. Say, we've set breakpoint
8674 at file:line. There were several PC values for that file:line,
8675 due to optimization, all in one block.
8676 We've picked one PC value. If "clear" is issued with another
8677 PC corresponding to the same file:line, the breakpoint won't
8678 be cleared. We probably can still clear the breakpoint, but
8679 since the other PC value is never presented to user, user
8680 can only find it by guessing, and it does not seem important
8683 /* For each line spec given, delete bps which correspond
8684 to it. Do it in two passes, solely to preserve the current
8685 behavior that from_tty is forced true if we delete more than
8689 for (i = 0; i < sals.nelts; i++)
8691 /* If exact pc given, clear bpts at that pc.
8692 If line given (pc == 0), clear all bpts on specified line.
8693 If defaulting, clear all bpts on default line
8696 defaulting sal.pc != 0 tests to do
8701 1 0 <can't happen> */
8705 /* Find all matching breakpoints and add them to
8710 /* Are we going to delete b? */
8711 if (b->type != bp_none && !is_watchpoint (b))
8713 struct bp_location *loc = b->loc;
8714 for (; loc; loc = loc->next)
8716 int pc_match = sal.pc
8717 && (loc->pspace == sal.pspace)
8718 && (loc->address == sal.pc)
8719 && (!section_is_overlay (loc->section)
8720 || loc->section == sal.section);
8721 int line_match = ((default_match || (0 == sal.pc))
8722 && b->source_file != NULL
8723 && sal.symtab != NULL
8724 && sal.pspace == loc->pspace
8725 && strcmp (b->source_file, sal.symtab->filename) == 0
8726 && b->line_number == sal.line);
8727 if (pc_match || line_match)
8736 VEC_safe_push(breakpoint_p, found, b);
8739 /* Now go thru the 'found' chain and delete them. */
8740 if (VEC_empty(breakpoint_p, found))
8743 error (_("No breakpoint at %s."), arg);
8745 error (_("No breakpoint at this line."));
8748 if (VEC_length(breakpoint_p, found) > 1)
8749 from_tty = 1; /* Always report if deleted more than one */
8752 if (VEC_length(breakpoint_p, found) == 1)
8753 printf_unfiltered (_("Deleted breakpoint "));
8755 printf_unfiltered (_("Deleted breakpoints "));
8757 breakpoints_changed ();
8759 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
8762 printf_unfiltered ("%d ", b->number);
8763 delete_breakpoint (b);
8766 putchar_unfiltered ('\n');
8769 /* Delete breakpoint in BS if they are `delete' breakpoints and
8770 all breakpoints that are marked for deletion, whether hit or not.
8771 This is called after any breakpoint is hit, or after errors. */
8774 breakpoint_auto_delete (bpstat bs)
8776 struct breakpoint *b, *temp;
8778 for (; bs; bs = bs->next)
8779 if (bs->breakpoint_at
8780 && bs->breakpoint_at->owner
8781 && bs->breakpoint_at->owner->disposition == disp_del
8783 delete_breakpoint (bs->breakpoint_at->owner);
8785 ALL_BREAKPOINTS_SAFE (b, temp)
8787 if (b->disposition == disp_del_at_next_stop)
8788 delete_breakpoint (b);
8792 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8793 Sort elements primarily by their ADDRESS (no matter what does
8794 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8795 first bp_permanent OWNERed elements and terciarily just ensuring the array
8796 is sorted stable way despite qsort being an instable algorithm. */
8799 bp_location_compare (const void *ap, const void *bp)
8801 struct bp_location *a = *(void **) ap;
8802 struct bp_location *b = *(void **) bp;
8803 int a_perm = a->owner->enable_state == bp_permanent;
8804 int b_perm = b->owner->enable_state == bp_permanent;
8806 if (a->address != b->address)
8807 return (a->address > b->address) - (a->address < b->address);
8809 /* Sort permanent breakpoints first. */
8810 if (a_perm != b_perm)
8811 return (a_perm < b_perm) - (a_perm > b_perm);
8813 /* Make the user-visible order stable across GDB runs. Locations of the same
8814 breakpoint can be sorted in arbitrary order. */
8816 if (a->owner->number != b->owner->number)
8817 return (a->owner->number > b->owner->number)
8818 - (a->owner->number < b->owner->number);
8820 return (a > b) - (a < b);
8823 /* Set bp_location_placed_address_before_address_max and
8824 bp_location_shadow_len_after_address_max according to the current content of
8825 the bp_location array. */
8828 bp_location_target_extensions_update (void)
8830 struct bp_location *bl, **blp_tmp;
8832 bp_location_placed_address_before_address_max = 0;
8833 bp_location_shadow_len_after_address_max = 0;
8835 ALL_BP_LOCATIONS (bl, blp_tmp)
8837 CORE_ADDR start, end, addr;
8839 if (!bp_location_has_shadow (bl))
8842 start = bl->target_info.placed_address;
8843 end = start + bl->target_info.shadow_len;
8845 gdb_assert (bl->address >= start);
8846 addr = bl->address - start;
8847 if (addr > bp_location_placed_address_before_address_max)
8848 bp_location_placed_address_before_address_max = addr;
8850 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8852 gdb_assert (bl->address < end);
8853 addr = end - bl->address;
8854 if (addr > bp_location_shadow_len_after_address_max)
8855 bp_location_shadow_len_after_address_max = addr;
8859 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8860 into the inferior, only remove already-inserted locations that no
8861 longer should be inserted. Functions that delete a breakpoint or
8862 breakpoints should pass false, so that deleting a breakpoint
8863 doesn't have the side effect of inserting the locations of other
8864 breakpoints that are marked not-inserted, but should_be_inserted
8865 returns true on them.
8867 This behaviour is useful is situations close to tear-down -- e.g.,
8868 after an exec, while the target still has execution, but breakpoint
8869 shadows of the previous executable image should *NOT* be restored
8870 to the new image; or before detaching, where the target still has
8871 execution and wants to delete breakpoints from GDB's lists, and all
8872 breakpoints had already been removed from the inferior. */
8875 update_global_location_list (int should_insert)
8877 struct breakpoint *b;
8878 struct bp_location **locp, *loc;
8879 struct cleanup *cleanups;
8881 /* Used in the duplicates detection below. When iterating over all
8882 bp_locations, points to the first bp_location of a given address.
8883 Breakpoints and watchpoints of different types are never
8884 duplicates of each other. Keep one pointer for each type of
8885 breakpoint/watchpoint, so we only need to loop over all locations
8887 struct bp_location *bp_loc_first; /* breakpoint */
8888 struct bp_location *wp_loc_first; /* hardware watchpoint */
8889 struct bp_location *awp_loc_first; /* access watchpoint */
8890 struct bp_location *rwp_loc_first; /* read watchpoint */
8892 /* Saved former bp_location array which we compare against the newly built
8893 bp_location from the current state of ALL_BREAKPOINTS. */
8894 struct bp_location **old_location, **old_locp;
8895 unsigned old_location_count;
8897 old_location = bp_location;
8898 old_location_count = bp_location_count;
8900 bp_location_count = 0;
8901 cleanups = make_cleanup (xfree, old_location);
8904 for (loc = b->loc; loc; loc = loc->next)
8905 bp_location_count++;
8907 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
8910 for (loc = b->loc; loc; loc = loc->next)
8912 qsort (bp_location, bp_location_count, sizeof (*bp_location),
8913 bp_location_compare);
8915 bp_location_target_extensions_update ();
8917 /* Identify bp_location instances that are no longer present in the new
8918 list, and therefore should be freed. Note that it's not necessary that
8919 those locations should be removed from inferior -- if there's another
8920 location at the same address (previously marked as duplicate),
8921 we don't need to remove/insert the location.
8923 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8924 former bp_location array state respectively. */
8927 for (old_locp = old_location; old_locp < old_location + old_location_count;
8930 struct bp_location *old_loc = *old_locp;
8931 struct bp_location **loc2p;
8933 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8935 int found_object = 0;
8936 /* Tells if the location should remain inserted in the target. */
8937 int keep_in_target = 0;
8940 /* Skip LOCP entries which will definitely never be needed. Stop either
8941 at or being the one matching OLD_LOC. */
8942 while (locp < bp_location + bp_location_count
8943 && (*locp)->address < old_loc->address)
8947 (loc2p < bp_location + bp_location_count
8948 && (*loc2p)->address == old_loc->address);
8951 if (*loc2p == old_loc)
8958 /* If this location is no longer present, and inserted, look if there's
8959 maybe a new location at the same address. If so, mark that one
8960 inserted, and don't remove this one. This is needed so that we
8961 don't have a time window where a breakpoint at certain location is not
8964 if (old_loc->inserted)
8966 /* If the location is inserted now, we might have to remove it. */
8968 if (found_object && should_be_inserted (old_loc))
8970 /* The location is still present in the location list, and still
8971 should be inserted. Don't do anything. */
8976 /* The location is either no longer present, or got disabled.
8977 See if there's another location at the same address, in which
8978 case we don't need to remove this one from the target. */
8980 if (breakpoint_address_is_meaningful (old_loc->owner))
8983 (loc2p < bp_location + bp_location_count
8984 && (*loc2p)->address == old_loc->address);
8987 struct bp_location *loc2 = *loc2p;
8989 if (breakpoint_locations_match (loc2, old_loc))
8991 /* For the sake of should_be_inserted.
8992 Duplicates check below will fix up this later. */
8993 loc2->duplicate = 0;
8995 /* Read watchpoint locations are switched to
8996 access watchpoints, if the former are not
8997 supported, but the latter are. */
8998 if (is_hardware_watchpoint (old_loc->owner))
9000 gdb_assert (is_hardware_watchpoint (loc2->owner));
9001 loc2->watchpoint_type = old_loc->watchpoint_type;
9004 if (loc2 != old_loc && should_be_inserted (loc2))
9007 loc2->target_info = old_loc->target_info;
9016 if (!keep_in_target)
9018 if (remove_breakpoint (old_loc, mark_uninserted))
9020 /* This is just about all we can do. We could keep this
9021 location on the global list, and try to remove it next
9022 time, but there's no particular reason why we will
9025 Note that at this point, old_loc->owner is still valid,
9026 as delete_breakpoint frees the breakpoint only
9027 after calling us. */
9028 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9029 old_loc->owner->number);
9037 if (removed && non_stop
9038 && breakpoint_address_is_meaningful (old_loc->owner)
9039 && !is_hardware_watchpoint (old_loc->owner))
9041 /* This location was removed from the target. In
9042 non-stop mode, a race condition is possible where
9043 we've removed a breakpoint, but stop events for that
9044 breakpoint are already queued and will arrive later.
9045 We apply an heuristic to be able to distinguish such
9046 SIGTRAPs from other random SIGTRAPs: we keep this
9047 breakpoint location for a bit, and will retire it
9048 after we see some number of events. The theory here
9049 is that reporting of events should, "on the average",
9050 be fair, so after a while we'll see events from all
9051 threads that have anything of interest, and no longer
9052 need to keep this breakpoint location around. We
9053 don't hold locations forever so to reduce chances of
9054 mistaking a non-breakpoint SIGTRAP for a breakpoint
9057 The heuristic failing can be disastrous on
9058 decr_pc_after_break targets.
9060 On decr_pc_after_break targets, like e.g., x86-linux,
9061 if we fail to recognize a late breakpoint SIGTRAP,
9062 because events_till_retirement has reached 0 too
9063 soon, we'll fail to do the PC adjustment, and report
9064 a random SIGTRAP to the user. When the user resumes
9065 the inferior, it will most likely immediately crash
9066 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9067 corrupted, because of being resumed e.g., in the
9068 middle of a multi-byte instruction, or skipped a
9069 one-byte instruction. This was actually seen happen
9070 on native x86-linux, and should be less rare on
9071 targets that do not support new thread events, like
9072 remote, due to the heuristic depending on
9075 Mistaking a random SIGTRAP for a breakpoint trap
9076 causes similar symptoms (PC adjustment applied when
9077 it shouldn't), but then again, playing with SIGTRAPs
9078 behind the debugger's back is asking for trouble.
9080 Since hardware watchpoint traps are always
9081 distinguishable from other traps, so we don't need to
9082 apply keep hardware watchpoint moribund locations
9083 around. We simply always ignore hardware watchpoint
9084 traps we can no longer explain. */
9086 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9087 old_loc->owner = NULL;
9089 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9092 free_bp_location (old_loc);
9096 /* Rescan breakpoints at the same address and section, marking the
9097 first one as "first" and any others as "duplicates". This is so
9098 that the bpt instruction is only inserted once. If we have a
9099 permanent breakpoint at the same place as BPT, make that one the
9100 official one, and the rest as duplicates. Permanent breakpoints
9101 are sorted first for the same address.
9103 Do the same for hardware watchpoints, but also considering the
9104 watchpoint's type (regular/access/read) and length. */
9106 bp_loc_first = NULL;
9107 wp_loc_first = NULL;
9108 awp_loc_first = NULL;
9109 rwp_loc_first = NULL;
9110 ALL_BP_LOCATIONS (loc, locp)
9112 struct breakpoint *b = loc->owner;
9113 struct bp_location **loc_first_p;
9115 if (b->enable_state == bp_disabled
9116 || b->enable_state == bp_call_disabled
9117 || b->enable_state == bp_startup_disabled
9119 || loc->shlib_disabled
9120 || !breakpoint_address_is_meaningful (b)
9121 || is_tracepoint (b))
9124 /* Permanent breakpoint should always be inserted. */
9125 if (b->enable_state == bp_permanent && ! loc->inserted)
9126 internal_error (__FILE__, __LINE__,
9127 _("allegedly permanent breakpoint is not "
9128 "actually inserted"));
9130 if (b->type == bp_hardware_watchpoint)
9131 loc_first_p = &wp_loc_first;
9132 else if (b->type == bp_read_watchpoint)
9133 loc_first_p = &rwp_loc_first;
9134 else if (b->type == bp_access_watchpoint)
9135 loc_first_p = &awp_loc_first;
9137 loc_first_p = &bp_loc_first;
9139 if (*loc_first_p == NULL
9140 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9141 || !breakpoint_locations_match (loc, *loc_first_p))
9150 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9151 && b->enable_state != bp_permanent)
9152 internal_error (__FILE__, __LINE__,
9153 _("another breakpoint was inserted on top of "
9154 "a permanent breakpoint"));
9157 if (breakpoints_always_inserted_mode () && should_insert
9158 && (have_live_inferiors ()
9159 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9160 insert_breakpoint_locations ();
9162 do_cleanups (cleanups);
9166 breakpoint_retire_moribund (void)
9168 struct bp_location *loc;
9171 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9172 if (--(loc->events_till_retirement) == 0)
9174 free_bp_location (loc);
9175 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9181 update_global_location_list_nothrow (int inserting)
9183 struct gdb_exception e;
9184 TRY_CATCH (e, RETURN_MASK_ERROR)
9185 update_global_location_list (inserting);
9188 /* Clear BPT from a BPS. */
9190 bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
9193 for (bs = bps; bs; bs = bs->next)
9194 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
9196 bs->breakpoint_at = NULL;
9198 /* bs->commands will be freed later. */
9202 /* Callback for iterate_over_threads. */
9204 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
9206 struct breakpoint *bpt = data;
9207 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
9211 /* Delete a breakpoint and clean up all traces of it in the data
9215 delete_breakpoint (struct breakpoint *bpt)
9217 struct breakpoint *b;
9219 gdb_assert (bpt != NULL);
9221 /* Has this bp already been deleted? This can happen because multiple
9222 lists can hold pointers to bp's. bpstat lists are especial culprits.
9224 One example of this happening is a watchpoint's scope bp. When the
9225 scope bp triggers, we notice that the watchpoint is out of scope, and
9226 delete it. We also delete its scope bp. But the scope bp is marked
9227 "auto-deleting", and is already on a bpstat. That bpstat is then
9228 checked for auto-deleting bp's, which are deleted.
9230 A real solution to this problem might involve reference counts in bp's,
9231 and/or giving them pointers back to their referencing bpstat's, and
9232 teaching delete_breakpoint to only free a bp's storage when no more
9233 references were extent. A cheaper bandaid was chosen. */
9234 if (bpt->type == bp_none)
9237 /* At least avoid this stale reference until the reference counting of
9238 breakpoints gets resolved. */
9239 if (bpt->related_breakpoint != NULL)
9241 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
9242 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
9243 bpt->related_breakpoint->related_breakpoint = NULL;
9244 bpt->related_breakpoint = NULL;
9247 observer_notify_breakpoint_deleted (bpt->number);
9249 if (breakpoint_chain == bpt)
9250 breakpoint_chain = bpt->next;
9255 b->next = bpt->next;
9259 decref_counted_command_line (&bpt->commands);
9260 xfree (bpt->cond_string);
9261 xfree (bpt->cond_exp);
9262 xfree (bpt->addr_string);
9264 xfree (bpt->exp_string);
9265 value_free (bpt->val);
9266 xfree (bpt->source_file);
9267 xfree (bpt->exec_pathname);
9268 clean_up_filters (&bpt->syscalls_to_be_caught);
9270 /* Be sure no bpstat's are pointing at it after it's been freed. */
9271 /* FIXME, how can we find all bpstat's?
9272 We just check stop_bpstat for now. Note that we cannot just
9273 remove bpstats pointing at bpt from the stop_bpstat list
9274 entirely, as breakpoint commands are associated with the bpstat;
9275 if we remove it here, then the later call to
9276 bpstat_do_actions (&stop_bpstat);
9277 in event-top.c won't do anything, and temporary breakpoints
9278 with commands won't work. */
9280 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
9282 /* Now that breakpoint is removed from breakpoint
9283 list, update the global location list. This
9284 will remove locations that used to belong to
9285 this breakpoint. Do this before freeing
9286 the breakpoint itself, since remove_breakpoint
9287 looks at location's owner. It might be better
9288 design to have location completely self-contained,
9289 but it's not the case now. */
9290 update_global_location_list (0);
9293 /* On the chance that someone will soon try again to delete this same
9294 bp, we mark it as deleted before freeing its storage. */
9295 bpt->type = bp_none;
9301 do_delete_breakpoint_cleanup (void *b)
9303 delete_breakpoint (b);
9307 make_cleanup_delete_breakpoint (struct breakpoint *b)
9309 return make_cleanup (do_delete_breakpoint_cleanup, b);
9312 /* A callback for map_breakpoint_numbers that calls
9313 delete_breakpoint. */
9316 do_delete_breakpoint (struct breakpoint *b, void *ignore)
9318 delete_breakpoint (b);
9322 delete_command (char *arg, int from_tty)
9324 struct breakpoint *b, *temp;
9330 int breaks_to_delete = 0;
9332 /* Delete all breakpoints if no argument.
9333 Do not delete internal or call-dummy breakpoints, these
9334 have to be deleted with an explicit breakpoint number argument. */
9337 if (b->type != bp_call_dummy
9338 && b->type != bp_std_terminate
9339 && b->type != bp_shlib_event
9340 && b->type != bp_jit_event
9341 && b->type != bp_thread_event
9342 && b->type != bp_overlay_event
9343 && b->type != bp_longjmp_master
9344 && b->type != bp_std_terminate_master
9347 breaks_to_delete = 1;
9352 /* Ask user only if there are some breakpoints to delete. */
9354 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
9356 ALL_BREAKPOINTS_SAFE (b, temp)
9358 if (b->type != bp_call_dummy
9359 && b->type != bp_std_terminate
9360 && b->type != bp_shlib_event
9361 && b->type != bp_thread_event
9362 && b->type != bp_jit_event
9363 && b->type != bp_overlay_event
9364 && b->type != bp_longjmp_master
9365 && b->type != bp_std_terminate_master
9367 delete_breakpoint (b);
9372 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
9376 all_locations_are_pending (struct bp_location *loc)
9378 for (; loc; loc = loc->next)
9379 if (!loc->shlib_disabled)
9384 /* Subroutine of update_breakpoint_locations to simplify it.
9385 Return non-zero if multiple fns in list LOC have the same name.
9386 Null names are ignored. */
9389 ambiguous_names_p (struct bp_location *loc)
9391 struct bp_location *l;
9392 htab_t htab = htab_create_alloc (13, htab_hash_string,
9393 (int (*) (const void *, const void *)) streq,
9394 NULL, xcalloc, xfree);
9396 for (l = loc; l != NULL; l = l->next)
9399 const char *name = l->function_name;
9401 /* Allow for some names to be NULL, ignore them. */
9405 slot = (const char **) htab_find_slot (htab, (const void *) name,
9407 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9422 update_breakpoint_locations (struct breakpoint *b,
9423 struct symtabs_and_lines sals)
9427 struct bp_location *existing_locations = b->loc;
9429 /* If there's no new locations, and all existing locations
9430 are pending, don't do anything. This optimizes
9431 the common case where all locations are in the same
9432 shared library, that was unloaded. We'd like to
9433 retain the location, so that when the library
9434 is loaded again, we don't loose the enabled/disabled
9435 status of the individual locations. */
9436 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
9441 for (i = 0; i < sals.nelts; ++i)
9443 struct bp_location *new_loc =
9444 add_location_to_breakpoint (b, &(sals.sals[i]));
9446 /* Reparse conditions, they might contain references to the
9448 if (b->cond_string != NULL)
9450 struct gdb_exception e;
9453 TRY_CATCH (e, RETURN_MASK_ERROR)
9455 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
9460 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9461 b->number, e.message);
9462 new_loc->enabled = 0;
9466 if (b->source_file != NULL)
9467 xfree (b->source_file);
9468 if (sals.sals[i].symtab == NULL)
9469 b->source_file = NULL;
9471 b->source_file = xstrdup (sals.sals[i].symtab->filename);
9473 if (b->line_number == 0)
9474 b->line_number = sals.sals[i].line;
9477 /* Update locations of permanent breakpoints. */
9478 if (b->enable_state == bp_permanent)
9479 make_breakpoint_permanent (b);
9481 /* If possible, carry over 'disable' status from existing breakpoints. */
9483 struct bp_location *e = existing_locations;
9484 /* If there are multiple breakpoints with the same function name,
9485 e.g. for inline functions, comparing function names won't work.
9486 Instead compare pc addresses; this is just a heuristic as things
9487 may have moved, but in practice it gives the correct answer
9488 often enough until a better solution is found. */
9489 int have_ambiguous_names = ambiguous_names_p (b->loc);
9491 for (; e; e = e->next)
9493 if (!e->enabled && e->function_name)
9495 struct bp_location *l = b->loc;
9496 if (have_ambiguous_names)
9498 for (; l; l = l->next)
9499 if (breakpoint_address_match (e->pspace->aspace, e->address,
9500 l->pspace->aspace, l->address))
9508 for (; l; l = l->next)
9509 if (l->function_name
9510 && strcmp (e->function_name, l->function_name) == 0)
9520 update_global_location_list (1);
9524 /* Reset a breakpoint given it's struct breakpoint * BINT.
9525 The value we return ends up being the return value from catch_errors.
9526 Unused in this case. */
9529 breakpoint_re_set_one (void *bint)
9531 /* get past catch_errs */
9532 struct breakpoint *b = (struct breakpoint *) bint;
9534 int *not_found_ptr = ¬_found;
9535 struct symtabs_and_lines sals = {0};
9536 struct symtabs_and_lines expanded = {0};
9538 struct gdb_exception e;
9539 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
9544 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9548 case bp_hardware_breakpoint:
9550 case bp_fast_tracepoint:
9551 /* Do not attempt to re-set breakpoints disabled during startup. */
9552 if (b->enable_state == bp_startup_disabled)
9555 if (b->addr_string == NULL)
9557 /* Anything without a string can't be re-set. */
9558 delete_breakpoint (b);
9562 set_language (b->language);
9563 input_radix = b->input_radix;
9566 save_current_space_and_thread ();
9567 switch_to_program_space_and_thread (b->pspace);
9569 TRY_CATCH (e, RETURN_MASK_ERROR)
9571 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
9576 int not_found_and_ok = 0;
9577 /* For pending breakpoints, it's expected that parsing
9578 will fail until the right shared library is loaded.
9579 User has already told to create pending breakpoints and
9580 don't need extra messages. If breakpoint is in bp_shlib_disabled
9581 state, then user already saw the message about that breakpoint
9582 being disabled, and don't want to see more errors. */
9584 && (b->condition_not_parsed
9585 || (b->loc && b->loc->shlib_disabled)
9586 || b->enable_state == bp_disabled))
9587 not_found_and_ok = 1;
9589 if (!not_found_and_ok)
9591 /* We surely don't want to warn about the same breakpoint
9592 10 times. One solution, implemented here, is disable
9593 the breakpoint on error. Another solution would be to
9594 have separate 'warning emitted' flag. Since this
9595 happens only when a binary has changed, I don't know
9596 which approach is better. */
9597 b->enable_state = bp_disabled;
9598 throw_exception (e);
9604 gdb_assert (sals.nelts == 1);
9606 resolve_sal_pc (&sals.sals[0]);
9607 if (b->condition_not_parsed && s && s[0])
9609 char *cond_string = 0;
9613 find_condition_and_thread (s, sals.sals[0].pc,
9614 &cond_string, &thread, &task);
9616 b->cond_string = cond_string;
9619 b->condition_not_parsed = 0;
9622 expanded = expand_line_sal_maybe (sals.sals[0]);
9625 make_cleanup (xfree, sals.sals);
9626 update_breakpoint_locations (b, expanded);
9630 case bp_hardware_watchpoint:
9631 case bp_read_watchpoint:
9632 case bp_access_watchpoint:
9633 /* Watchpoint can be either on expression using entirely global variables,
9634 or it can be on local variables.
9636 Watchpoints of the first kind are never auto-deleted, and even persist
9637 across program restarts. Since they can use variables from shared
9638 libraries, we need to reparse expression as libraries are loaded
9641 Watchpoints on local variables can also change meaning as result
9642 of solib event. For example, if a watchpoint uses both a local and
9643 a global variables in expression, it's a local watchpoint, but
9644 unloading of a shared library will make the expression invalid.
9645 This is not a very common use case, but we still re-evaluate
9646 expression, to avoid surprises to the user.
9648 Note that for local watchpoints, we re-evaluate it only if
9649 watchpoints frame id is still valid. If it's not, it means
9650 the watchpoint is out of scope and will be deleted soon. In fact,
9651 I'm not sure we'll ever be called in this case.
9653 If a local watchpoint's frame id is still valid, then
9654 b->exp_valid_block is likewise valid, and we can safely use it.
9656 Don't do anything about disabled watchpoints, since they will
9657 be reevaluated again when enabled. */
9658 update_watchpoint (b, 1 /* reparse */);
9660 /* We needn't really do anything to reset these, since the mask
9661 that requests them is unaffected by e.g., new libraries being
9667 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
9669 /* Delete overlay event and longjmp master breakpoints; they will be
9670 reset later by breakpoint_re_set. */
9671 case bp_overlay_event:
9672 case bp_longjmp_master:
9673 case bp_std_terminate_master:
9674 delete_breakpoint (b);
9677 /* This breakpoint is special, it's set up when the inferior
9678 starts and we really don't want to touch it. */
9679 case bp_shlib_event:
9681 /* Like bp_shlib_event, this breakpoint type is special.
9682 Once it is set up, we do not want to touch it. */
9683 case bp_thread_event:
9685 /* Keep temporary breakpoints, which can be encountered when we step
9686 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9687 Otherwise these should have been blown away via the cleanup chain
9688 or by breakpoint_init_inferior when we rerun the executable. */
9691 case bp_watchpoint_scope:
9693 case bp_std_terminate:
9694 case bp_step_resume:
9696 case bp_longjmp_resume:
9701 do_cleanups (cleanups);
9705 /* Re-set all breakpoints after symbols have been re-loaded. */
9707 breakpoint_re_set (void)
9709 struct breakpoint *b, *temp;
9710 enum language save_language;
9711 int save_input_radix;
9712 struct cleanup *old_chain;
9714 save_language = current_language->la_language;
9715 save_input_radix = input_radix;
9716 old_chain = save_current_program_space ();
9718 ALL_BREAKPOINTS_SAFE (b, temp)
9720 /* Format possible error msg */
9721 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
9723 struct cleanup *cleanups = make_cleanup (xfree, message);
9724 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
9725 do_cleanups (cleanups);
9727 set_language (save_language);
9728 input_radix = save_input_radix;
9730 jit_breakpoint_re_set ();
9732 do_cleanups (old_chain);
9734 create_overlay_event_breakpoint ("_ovly_debug_event");
9735 create_longjmp_master_breakpoint ("longjmp");
9736 create_longjmp_master_breakpoint ("_longjmp");
9737 create_longjmp_master_breakpoint ("siglongjmp");
9738 create_longjmp_master_breakpoint ("_siglongjmp");
9739 create_std_terminate_master_breakpoint ("std::terminate()");
9742 /* Reset the thread number of this breakpoint:
9744 - If the breakpoint is for all threads, leave it as-is.
9745 - Else, reset it to the current thread for inferior_ptid. */
9747 breakpoint_re_set_thread (struct breakpoint *b)
9749 if (b->thread != -1)
9751 if (in_thread_list (inferior_ptid))
9752 b->thread = pid_to_thread_id (inferior_ptid);
9754 /* We're being called after following a fork. The new fork is
9755 selected as current, and unless this was a vfork will have a
9756 different program space from the original thread. Reset that
9758 b->loc->pspace = current_program_space;
9762 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9763 If from_tty is nonzero, it prints a message to that effect,
9764 which ends with a period (no newline). */
9767 set_ignore_count (int bptnum, int count, int from_tty)
9769 struct breakpoint *b;
9775 if (b->number == bptnum)
9777 if (is_tracepoint (b))
9779 if (from_tty && count != 0)
9780 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9785 b->ignore_count = count;
9789 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9791 else if (count == 1)
9792 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9795 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9798 breakpoints_changed ();
9799 observer_notify_breakpoint_modified (b->number);
9803 error (_("No breakpoint number %d."), bptnum);
9807 make_breakpoint_silent (struct breakpoint *b)
9809 /* Silence the breakpoint. */
9813 /* Command to set ignore-count of breakpoint N to COUNT. */
9816 ignore_command (char *args, int from_tty)
9822 error_no_arg (_("a breakpoint number"));
9824 num = get_number (&p);
9826 error (_("bad breakpoint number: '%s'"), args);
9828 error (_("Second argument (specified ignore-count) is missing."));
9830 set_ignore_count (num,
9831 longest_to_int (value_as_long (parse_and_eval (p))),
9834 printf_filtered ("\n");
9837 /* Call FUNCTION on each of the breakpoints
9838 whose numbers are given in ARGS. */
9841 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
9848 struct breakpoint *b, *tmp;
9852 error_no_arg (_("one or more breakpoint numbers"));
9859 num = get_number_or_range (&p1);
9862 warning (_("bad breakpoint number at or near '%s'"), p);
9866 ALL_BREAKPOINTS_SAFE (b, tmp)
9867 if (b->number == num)
9869 struct breakpoint *related_breakpoint = b->related_breakpoint;
9872 if (related_breakpoint)
9873 function (related_breakpoint, data);
9877 printf_unfiltered (_("No breakpoint number %d.\n"), num);
9883 static struct bp_location *
9884 find_location_by_number (char *number)
9886 char *dot = strchr (number, '.');
9890 struct breakpoint *b;
9891 struct bp_location *loc;
9896 bp_num = get_number_or_range (&p1);
9898 error (_("Bad breakpoint number '%s'"), number);
9901 if (b->number == bp_num)
9906 if (!b || b->number != bp_num)
9907 error (_("Bad breakpoint number '%s'"), number);
9910 loc_num = get_number_or_range (&p1);
9912 error (_("Bad breakpoint location number '%s'"), number);
9916 for (;loc_num && loc; --loc_num, loc = loc->next)
9919 error (_("Bad breakpoint location number '%s'"), dot+1);
9925 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9926 If from_tty is nonzero, it prints a message to that effect,
9927 which ends with a period (no newline). */
9930 disable_breakpoint (struct breakpoint *bpt)
9932 /* Never disable a watchpoint scope breakpoint; we want to
9933 hit them when we leave scope so we can delete both the
9934 watchpoint and its scope breakpoint at that time. */
9935 if (bpt->type == bp_watchpoint_scope)
9938 /* You can't disable permanent breakpoints. */
9939 if (bpt->enable_state == bp_permanent)
9942 bpt->enable_state = bp_disabled;
9944 update_global_location_list (0);
9946 observer_notify_breakpoint_modified (bpt->number);
9949 /* A callback for map_breakpoint_numbers that calls
9950 disable_breakpoint. */
9953 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
9955 disable_breakpoint (b);
9959 disable_command (char *args, int from_tty)
9961 struct breakpoint *bpt;
9963 ALL_BREAKPOINTS (bpt)
9967 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9972 case bp_fast_tracepoint:
9974 case bp_hardware_breakpoint:
9976 case bp_hardware_watchpoint:
9977 case bp_read_watchpoint:
9978 case bp_access_watchpoint:
9979 disable_breakpoint (bpt);
9983 else if (strchr (args, '.'))
9985 struct bp_location *loc = find_location_by_number (args);
9988 update_global_location_list (0);
9991 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
9995 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
9997 int target_resources_ok;
9999 if (bpt->type == bp_hardware_breakpoint)
10002 i = hw_breakpoint_used_count ();
10003 target_resources_ok =
10004 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10006 if (target_resources_ok == 0)
10007 error (_("No hardware breakpoint support in the target."));
10008 else if (target_resources_ok < 0)
10009 error (_("Hardware breakpoints used exceeds limit."));
10012 if (is_watchpoint (bpt))
10014 struct gdb_exception e;
10016 TRY_CATCH (e, RETURN_MASK_ALL)
10018 update_watchpoint (bpt, 1 /* reparse */);
10022 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10028 if (bpt->enable_state != bp_permanent)
10029 bpt->enable_state = bp_enabled;
10030 bpt->disposition = disposition;
10031 update_global_location_list (1);
10032 breakpoints_changed ();
10034 observer_notify_breakpoint_modified (bpt->number);
10039 enable_breakpoint (struct breakpoint *bpt)
10041 do_enable_breakpoint (bpt, bpt->disposition);
10044 /* A callback for map_breakpoint_numbers that calls
10045 enable_breakpoint. */
10048 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10050 enable_breakpoint (b);
10053 /* The enable command enables the specified breakpoints (or all defined
10054 breakpoints) so they once again become (or continue to be) effective
10055 in stopping the inferior. */
10058 enable_command (char *args, int from_tty)
10060 struct breakpoint *bpt;
10062 ALL_BREAKPOINTS (bpt)
10066 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10069 case bp_breakpoint:
10070 case bp_tracepoint:
10071 case bp_fast_tracepoint:
10072 case bp_catchpoint:
10073 case bp_hardware_breakpoint:
10074 case bp_watchpoint:
10075 case bp_hardware_watchpoint:
10076 case bp_read_watchpoint:
10077 case bp_access_watchpoint:
10078 enable_breakpoint (bpt);
10082 else if (strchr (args, '.'))
10084 struct bp_location *loc = find_location_by_number (args);
10087 update_global_location_list (1);
10090 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
10094 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
10096 do_enable_breakpoint (bpt, disp_disable);
10100 enable_once_command (char *args, int from_tty)
10102 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
10106 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
10108 do_enable_breakpoint (bpt, disp_del);
10112 enable_delete_command (char *args, int from_tty)
10114 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
10118 set_breakpoint_cmd (char *args, int from_tty)
10123 show_breakpoint_cmd (char *args, int from_tty)
10127 /* Invalidate last known value of any hardware watchpoint if
10128 the memory which that value represents has been written to by
10132 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
10133 const bfd_byte *data)
10135 struct breakpoint *bp;
10137 ALL_BREAKPOINTS (bp)
10138 if (bp->enable_state == bp_enabled
10139 && bp->type == bp_hardware_watchpoint
10140 && bp->val_valid && bp->val)
10142 struct bp_location *loc;
10144 for (loc = bp->loc; loc != NULL; loc = loc->next)
10145 if (loc->loc_type == bp_loc_hardware_watchpoint
10146 && loc->address + loc->length > addr
10147 && addr + len > loc->address)
10149 value_free (bp->val);
10156 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10158 struct symtabs_and_lines
10159 decode_line_spec_1 (char *string, int funfirstline)
10161 struct symtabs_and_lines sals;
10163 error (_("Empty line specification."));
10164 if (default_breakpoint_valid)
10165 sals = decode_line_1 (&string, funfirstline,
10166 default_breakpoint_symtab,
10167 default_breakpoint_line,
10168 (char ***) NULL, NULL);
10170 sals = decode_line_1 (&string, funfirstline,
10171 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
10173 error (_("Junk at end of line specification: %s"), string);
10177 /* Create and insert a raw software breakpoint at PC. Return an
10178 identifier, which should be used to remove the breakpoint later.
10179 In general, places which call this should be using something on the
10180 breakpoint chain instead; this function should be eliminated
10184 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
10185 struct address_space *aspace, CORE_ADDR pc)
10187 struct bp_target_info *bp_tgt;
10189 bp_tgt = XZALLOC (struct bp_target_info);
10191 bp_tgt->placed_address_space = aspace;
10192 bp_tgt->placed_address = pc;
10194 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
10196 /* Could not insert the breakpoint. */
10204 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10207 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
10209 struct bp_target_info *bp_tgt = bp;
10212 ret = target_remove_breakpoint (gdbarch, bp_tgt);
10218 /* One (or perhaps two) breakpoints used for software single stepping. */
10220 static void *single_step_breakpoints[2];
10221 static struct gdbarch *single_step_gdbarch[2];
10223 /* Create and insert a breakpoint for software single step. */
10226 insert_single_step_breakpoint (struct gdbarch *gdbarch,
10227 struct address_space *aspace, CORE_ADDR next_pc)
10231 if (single_step_breakpoints[0] == NULL)
10233 bpt_p = &single_step_breakpoints[0];
10234 single_step_gdbarch[0] = gdbarch;
10238 gdb_assert (single_step_breakpoints[1] == NULL);
10239 bpt_p = &single_step_breakpoints[1];
10240 single_step_gdbarch[1] = gdbarch;
10243 /* NOTE drow/2006-04-11: A future improvement to this function would be
10244 to only create the breakpoints once, and actually put them on the
10245 breakpoint chain. That would let us use set_raw_breakpoint. We could
10246 adjust the addresses each time they were needed. Doing this requires
10247 corresponding changes elsewhere where single step breakpoints are
10248 handled, however. So, for now, we use this. */
10250 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
10251 if (*bpt_p == NULL)
10252 error (_("Could not insert single-step breakpoint at %s"),
10253 paddress (gdbarch, next_pc));
10256 /* Remove and delete any breakpoints used for software single step. */
10259 remove_single_step_breakpoints (void)
10261 gdb_assert (single_step_breakpoints[0] != NULL);
10263 /* See insert_single_step_breakpoint for more about this deprecated
10265 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
10266 single_step_breakpoints[0]);
10267 single_step_gdbarch[0] = NULL;
10268 single_step_breakpoints[0] = NULL;
10270 if (single_step_breakpoints[1] != NULL)
10272 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
10273 single_step_breakpoints[1]);
10274 single_step_gdbarch[1] = NULL;
10275 single_step_breakpoints[1] = NULL;
10279 /* Check whether a software single-step breakpoint is inserted at PC. */
10282 single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
10286 for (i = 0; i < 2; i++)
10288 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
10290 && breakpoint_address_match (bp_tgt->placed_address_space,
10291 bp_tgt->placed_address,
10299 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10300 non-zero otherwise. */
10302 is_syscall_catchpoint_enabled (struct breakpoint *bp)
10304 if (syscall_catchpoint_p (bp)
10305 && bp->enable_state != bp_disabled
10306 && bp->enable_state != bp_call_disabled)
10313 catch_syscall_enabled (void)
10315 struct inferior *inf = current_inferior ();
10317 return inf->total_syscalls_count != 0;
10321 catching_syscall_number (int syscall_number)
10323 struct breakpoint *bp;
10325 ALL_BREAKPOINTS (bp)
10326 if (is_syscall_catchpoint_enabled (bp))
10328 if (bp->syscalls_to_be_caught)
10332 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
10334 if (syscall_number == iter)
10344 /* Complete syscall names. Used by "catch syscall". */
10346 catch_syscall_completer (struct cmd_list_element *cmd,
10347 char *text, char *word)
10349 const char **list = get_syscall_names ();
10350 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
10353 /* Tracepoint-specific operations. */
10355 /* Set tracepoint count to NUM. */
10357 set_tracepoint_count (int num)
10359 tracepoint_count = num;
10360 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
10364 trace_command (char *arg, int from_tty)
10366 if (create_breakpoint (get_current_arch (),
10368 NULL, 0, 1 /* parse arg */,
10369 0 /* tempflag */, 0 /* hardwareflag */,
10371 0 /* Ignore count */,
10372 pending_break_support,
10376 set_tracepoint_count (breakpoint_count);
10380 ftrace_command (char *arg, int from_tty)
10382 if (create_breakpoint (get_current_arch (),
10384 NULL, 0, 1 /* parse arg */,
10385 0 /* tempflag */, 1 /* hardwareflag */,
10387 0 /* Ignore count */,
10388 pending_break_support,
10392 set_tracepoint_count (breakpoint_count);
10395 /* Set up a fake reader function that gets command lines from a linked
10396 list that was acquired during tracepoint uploading. */
10398 static struct uploaded_tp *this_utp;
10399 static int next_cmd;
10402 read_uploaded_action (void)
10406 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
10413 /* Given information about a tracepoint as recorded on a target (which
10414 can be either a live system or a trace file), attempt to create an
10415 equivalent GDB tracepoint. This is not a reliable process, since
10416 the target does not necessarily have all the information used when
10417 the tracepoint was originally defined. */
10419 struct breakpoint *
10420 create_tracepoint_from_upload (struct uploaded_tp *utp)
10422 char *addr_str, small_buf[100];
10423 struct breakpoint *tp;
10425 if (utp->at_string)
10426 addr_str = utp->at_string;
10429 /* In the absence of a source location, fall back to raw
10430 address. Since there is no way to confirm that the address
10431 means the same thing as when the trace was started, warn the
10433 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10435 sprintf (small_buf, "*%s", hex_string (utp->addr));
10436 addr_str = small_buf;
10439 /* There's not much we can do with a sequence of bytecodes. */
10440 if (utp->cond && !utp->cond_string)
10441 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10444 if (!create_breakpoint (get_current_arch (),
10446 utp->cond_string, -1, 0 /* parse cond/thread */,
10448 (utp->type == bp_fast_tracepoint) /* hardwareflag */,
10450 0 /* Ignore count */,
10451 pending_break_support,
10454 utp->enabled /* enabled */))
10457 set_tracepoint_count (breakpoint_count);
10459 /* Get the tracepoint we just created. */
10460 tp = get_tracepoint (tracepoint_count);
10461 gdb_assert (tp != NULL);
10465 sprintf (small_buf, "%d %d", utp->pass, tp->number);
10467 trace_pass_command (small_buf, 0);
10470 /* If we have uploaded versions of the original commands, set up a
10471 special-purpose "reader" function and call the usual command line
10472 reader, then pass the result to the breakpoint command-setting
10474 if (!VEC_empty (char_ptr, utp->cmd_strings))
10476 struct command_line *cmd_list;
10481 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
10483 breakpoint_set_commands (tp, cmd_list);
10485 else if (!VEC_empty (char_ptr, utp->actions)
10486 || !VEC_empty (char_ptr, utp->step_actions))
10487 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10493 /* Print information on tracepoint number TPNUM_EXP, or all if
10497 tracepoints_info (char *tpnum_exp, int from_tty)
10499 int tpnum = -1, num_printed;
10502 tpnum = parse_and_eval_long (tpnum_exp);
10504 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
10506 if (num_printed == 0)
10509 ui_out_message (uiout, 0, "No tracepoints.\n");
10511 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
10514 default_collect_info ();
10517 /* The 'enable trace' command enables tracepoints.
10518 Not supported by all targets. */
10520 enable_trace_command (char *args, int from_tty)
10522 enable_command (args, from_tty);
10525 /* The 'disable trace' command disables tracepoints.
10526 Not supported by all targets. */
10528 disable_trace_command (char *args, int from_tty)
10530 disable_command (args, from_tty);
10533 /* Remove a tracepoint (or all if no argument) */
10535 delete_trace_command (char *arg, int from_tty)
10537 struct breakpoint *b, *temp;
10543 int breaks_to_delete = 0;
10545 /* Delete all breakpoints if no argument.
10546 Do not delete internal or call-dummy breakpoints, these
10547 have to be deleted with an explicit breakpoint number argument. */
10548 ALL_TRACEPOINTS (b)
10550 if (b->number >= 0)
10552 breaks_to_delete = 1;
10557 /* Ask user only if there are some breakpoints to delete. */
10559 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
10561 ALL_BREAKPOINTS_SAFE (b, temp)
10563 if (is_tracepoint (b)
10565 delete_breakpoint (b);
10570 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
10573 /* Set passcount for tracepoint.
10575 First command argument is passcount, second is tracepoint number.
10576 If tracepoint number omitted, apply to most recently defined.
10577 Also accepts special argument "all". */
10580 trace_pass_command (char *args, int from_tty)
10582 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
10583 unsigned int count;
10586 if (args == 0 || *args == 0)
10587 error (_("passcount command requires an argument (count + optional TP num)"));
10589 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
10591 while (*args && isspace ((int) *args))
10594 if (*args && strncasecmp (args, "all", 3) == 0)
10596 args += 3; /* Skip special argument "all". */
10599 error (_("Junk at end of arguments."));
10602 t1 = get_tracepoint_by_number (&args, 1, 1);
10608 ALL_TRACEPOINTS (t2)
10609 if (t1 == (struct breakpoint *) -1 || t1 == t2)
10611 t2->pass_count = count;
10612 observer_notify_tracepoint_modified (t2->number);
10614 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10615 t2->number, count);
10617 if (! all && *args)
10618 t1 = get_tracepoint_by_number (&args, 1, 0);
10624 struct breakpoint *
10625 get_tracepoint (int num)
10627 struct breakpoint *t;
10629 ALL_TRACEPOINTS (t)
10630 if (t->number == num)
10636 /* Find the tracepoint with the given target-side number (which may be
10637 different from the tracepoint number after disconnecting and
10640 struct breakpoint *
10641 get_tracepoint_by_number_on_target (int num)
10643 struct breakpoint *t;
10645 ALL_TRACEPOINTS (t)
10646 if (t->number_on_target == num)
10652 /* Utility: parse a tracepoint number and look it up in the list.
10653 If MULTI_P is true, there might be a range of tracepoints in ARG.
10654 if OPTIONAL_P is true, then if the argument is missing, the most
10655 recent tracepoint (tracepoint_count) is returned. */
10656 struct breakpoint *
10657 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
10659 extern int tracepoint_count;
10660 struct breakpoint *t;
10662 char *instring = arg == NULL ? NULL : *arg;
10664 if (arg == NULL || *arg == NULL || ! **arg)
10667 tpnum = tracepoint_count;
10669 error_no_arg (_("tracepoint number"));
10672 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
10676 if (instring && *instring)
10677 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10680 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10684 ALL_TRACEPOINTS (t)
10685 if (t->number == tpnum)
10690 /* FIXME: if we are in the middle of a range we don't want to give
10691 a message. The current interface to get_number_or_range doesn't
10692 allow us to discover this. */
10693 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
10697 /* Save information on user settable breakpoints (watchpoints, etc) to
10698 a new script file named FILENAME. If FILTER is non-NULL, call it
10699 on each breakpoint and only include the ones for which it returns
10703 save_breakpoints (char *filename, int from_tty,
10704 int (*filter) (const struct breakpoint *))
10706 struct breakpoint *tp;
10709 struct cleanup *cleanup;
10710 struct ui_file *fp;
10711 int extra_trace_bits = 0;
10713 if (filename == 0 || *filename == 0)
10714 error (_("Argument required (file name in which to save)"));
10716 /* See if we have anything to save. */
10717 ALL_BREAKPOINTS (tp)
10719 /* Skip internal and momentary breakpoints. */
10720 if (!user_settable_breakpoint (tp))
10723 /* If we have a filter, only save the breakpoints it accepts. */
10724 if (filter && !filter (tp))
10729 if (is_tracepoint (tp))
10731 extra_trace_bits = 1;
10733 /* We can stop searching. */
10740 warning (_("Nothing to save."));
10744 pathname = tilde_expand (filename);
10745 cleanup = make_cleanup (xfree, pathname);
10746 fp = gdb_fopen (pathname, "w");
10748 error (_("Unable to open file '%s' for saving (%s)"),
10749 filename, safe_strerror (errno));
10750 make_cleanup_ui_file_delete (fp);
10752 if (extra_trace_bits)
10753 save_trace_state_variables (fp);
10755 ALL_BREAKPOINTS (tp)
10757 /* Skip internal and momentary breakpoints. */
10758 if (!user_settable_breakpoint (tp))
10761 /* If we have a filter, only save the breakpoints it accepts. */
10762 if (filter && !filter (tp))
10765 if (tp->ops != NULL)
10766 (tp->ops->print_recreate) (tp, fp);
10769 if (tp->type == bp_fast_tracepoint)
10770 fprintf_unfiltered (fp, "ftrace");
10771 else if (tp->type == bp_tracepoint)
10772 fprintf_unfiltered (fp, "trace");
10773 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
10774 fprintf_unfiltered (fp, "tbreak");
10775 else if (tp->type == bp_breakpoint)
10776 fprintf_unfiltered (fp, "break");
10777 else if (tp->type == bp_hardware_breakpoint
10778 && tp->disposition == disp_del)
10779 fprintf_unfiltered (fp, "thbreak");
10780 else if (tp->type == bp_hardware_breakpoint)
10781 fprintf_unfiltered (fp, "hbreak");
10782 else if (tp->type == bp_watchpoint)
10783 fprintf_unfiltered (fp, "watch");
10784 else if (tp->type == bp_hardware_watchpoint)
10785 fprintf_unfiltered (fp, "watch");
10786 else if (tp->type == bp_read_watchpoint)
10787 fprintf_unfiltered (fp, "rwatch");
10788 else if (tp->type == bp_access_watchpoint)
10789 fprintf_unfiltered (fp, "awatch");
10791 internal_error (__FILE__, __LINE__,
10792 _("unhandled breakpoint type %d"), (int) tp->type);
10794 if (tp->exp_string)
10795 fprintf_unfiltered (fp, " %s", tp->exp_string);
10796 else if (tp->addr_string)
10797 fprintf_unfiltered (fp, " %s", tp->addr_string);
10802 sprintf_vma (tmp, tp->loc->address);
10803 fprintf_unfiltered (fp, " *0x%s", tmp);
10807 if (tp->thread != -1)
10808 fprintf_unfiltered (fp, " thread %d", tp->thread);
10811 fprintf_unfiltered (fp, " task %d", tp->task);
10813 fprintf_unfiltered (fp, "\n");
10815 /* Note, we can't rely on tp->number for anything, as we can't
10816 assume the recreated breakpoint numbers will match. Use $bpnum
10819 if (tp->cond_string)
10820 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
10822 if (tp->ignore_count)
10823 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
10825 if (tp->pass_count)
10826 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
10830 volatile struct gdb_exception ex;
10832 fprintf_unfiltered (fp, " commands\n");
10834 ui_out_redirect (uiout, fp);
10835 TRY_CATCH (ex, RETURN_MASK_ERROR)
10837 print_command_lines (uiout, tp->commands->commands, 2);
10839 ui_out_redirect (uiout, NULL);
10842 throw_exception (ex);
10844 fprintf_unfiltered (fp, " end\n");
10847 if (tp->enable_state == bp_disabled)
10848 fprintf_unfiltered (fp, "disable\n");
10850 /* If this is a multi-location breakpoint, check if the locations
10851 should be individually disabled. Watchpoint locations are
10852 special, and not user visible. */
10853 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
10855 struct bp_location *loc;
10858 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
10860 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
10864 if (extra_trace_bits && *default_collect)
10865 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
10867 do_cleanups (cleanup);
10869 printf_filtered (_("Saved to file '%s'.\n"), filename);
10872 /* The `save breakpoints' command. */
10875 save_breakpoints_command (char *args, int from_tty)
10877 save_breakpoints (args, from_tty, NULL);
10880 /* The `save tracepoints' command. */
10883 save_tracepoints_command (char *args, int from_tty)
10885 save_breakpoints (args, from_tty, is_tracepoint);
10888 /* Create a vector of all tracepoints. */
10890 VEC(breakpoint_p) *
10893 VEC(breakpoint_p) *tp_vec = 0;
10894 struct breakpoint *tp;
10896 ALL_TRACEPOINTS (tp)
10898 VEC_safe_push (breakpoint_p, tp_vec, tp);
10905 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10906 It is defined as a macro to prevent duplication.
10907 COMMAND should be a string constant containing the name of the command. */
10908 #define BREAK_ARGS_HELP(command) \
10909 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10910 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10911 If a line number is specified, break at start of code for that line.\n\
10912 If a function is specified, break at start of code for that function.\n\
10913 If an address is specified, break at that exact address.\n\
10914 With no LOCATION, uses current execution address of selected stack frame.\n\
10915 This is useful for breaking on return to a stack frame.\n\
10917 THREADNUM is the number from \"info threads\".\n\
10918 CONDITION is a boolean expression.\n\
10920 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10922 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10924 /* List of subcommands for "catch". */
10925 static struct cmd_list_element *catch_cmdlist;
10927 /* List of subcommands for "tcatch". */
10928 static struct cmd_list_element *tcatch_cmdlist;
10930 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10931 lists, and pass some additional user data to the command function. */
10933 add_catch_command (char *name, char *docstring,
10934 void (*sfunc) (char *args, int from_tty,
10935 struct cmd_list_element *command),
10936 char **(*completer) (struct cmd_list_element *cmd,
10937 char *text, char *word),
10938 void *user_data_catch,
10939 void *user_data_tcatch)
10941 struct cmd_list_element *command;
10943 command = add_cmd (name, class_breakpoint, NULL, docstring,
10945 set_cmd_sfunc (command, sfunc);
10946 set_cmd_context (command, user_data_catch);
10947 set_cmd_completer (command, completer);
10949 command = add_cmd (name, class_breakpoint, NULL, docstring,
10951 set_cmd_sfunc (command, sfunc);
10952 set_cmd_context (command, user_data_tcatch);
10953 set_cmd_completer (command, completer);
10957 clear_syscall_counts (struct inferior *inf)
10959 inf->total_syscalls_count = 0;
10960 inf->any_syscall_count = 0;
10961 VEC_free (int, inf->syscalls_counts);
10965 save_command (char *arg, int from_tty)
10967 printf_unfiltered (_("\
10968 \"save\" must be followed by the name of a save subcommand.\n"));
10969 help_list (save_cmdlist, "save ", -1, gdb_stdout);
10973 _initialize_breakpoint (void)
10975 struct cmd_list_element *c;
10977 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
10978 observer_attach_inferior_exit (clear_syscall_counts);
10979 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
10981 breakpoint_chain = 0;
10982 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10983 before a breakpoint is set. */
10984 breakpoint_count = 0;
10986 tracepoint_count = 0;
10988 add_com ("ignore", class_breakpoint, ignore_command, _("\
10989 Set ignore-count of breakpoint number N to COUNT.\n\
10990 Usage is `ignore N COUNT'."));
10992 add_com_alias ("bc", "ignore", class_breakpoint, 1);
10994 add_com ("commands", class_breakpoint, commands_command, _("\
10995 Set commands to be executed when a breakpoint is hit.\n\
10996 Give breakpoint number as argument after \"commands\".\n\
10997 With no argument, the targeted breakpoint is the last one set.\n\
10998 The commands themselves follow starting on the next line.\n\
10999 Type a line containing \"end\" to indicate the end of them.\n\
11000 Give \"silent\" as the first line to make the breakpoint silent;\n\
11001 then no output is printed when it is hit, except what the commands print."));
11003 add_com ("condition", class_breakpoint, condition_command, _("\
11004 Specify breakpoint number N to break only if COND is true.\n\
11005 Usage is `condition N COND', where N is an integer and COND is an\n\
11006 expression to be evaluated whenever breakpoint N is reached."));
11008 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
11009 Set a temporary breakpoint.\n\
11010 Like \"break\" except the breakpoint is only temporary,\n\
11011 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11012 by using \"enable delete\" on the breakpoint number.\n\
11014 BREAK_ARGS_HELP ("tbreak")));
11015 set_cmd_completer (c, location_completer);
11017 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
11018 Set a hardware assisted breakpoint.\n\
11019 Like \"break\" except the breakpoint requires hardware support,\n\
11020 some target hardware may not have this support.\n\
11022 BREAK_ARGS_HELP ("hbreak")));
11023 set_cmd_completer (c, location_completer);
11025 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
11026 Set a temporary hardware assisted breakpoint.\n\
11027 Like \"hbreak\" except the breakpoint is only temporary,\n\
11028 so it will be deleted when hit.\n\
11030 BREAK_ARGS_HELP ("thbreak")));
11031 set_cmd_completer (c, location_completer);
11033 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
11034 Enable some breakpoints.\n\
11035 Give breakpoint numbers (separated by spaces) as arguments.\n\
11036 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11037 This is used to cancel the effect of the \"disable\" command.\n\
11038 With a subcommand you can enable temporarily."),
11039 &enablelist, "enable ", 1, &cmdlist);
11041 add_com ("ab", class_breakpoint, enable_command, _("\
11042 Enable some breakpoints.\n\
11043 Give breakpoint numbers (separated by spaces) as arguments.\n\
11044 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11045 This is used to cancel the effect of the \"disable\" command.\n\
11046 With a subcommand you can enable temporarily."));
11048 add_com_alias ("en", "enable", class_breakpoint, 1);
11050 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
11051 Enable some breakpoints.\n\
11052 Give breakpoint numbers (separated by spaces) as arguments.\n\
11053 This is used to cancel the effect of the \"disable\" command.\n\
11054 May be abbreviated to simply \"enable\".\n"),
11055 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
11057 add_cmd ("once", no_class, enable_once_command, _("\
11058 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11059 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11062 add_cmd ("delete", no_class, enable_delete_command, _("\
11063 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11064 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11067 add_cmd ("delete", no_class, enable_delete_command, _("\
11068 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11069 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11072 add_cmd ("once", no_class, enable_once_command, _("\
11073 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11074 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11077 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
11078 Disable some breakpoints.\n\
11079 Arguments are breakpoint numbers with spaces in between.\n\
11080 To disable all breakpoints, give no argument.\n\
11081 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11082 &disablelist, "disable ", 1, &cmdlist);
11083 add_com_alias ("dis", "disable", class_breakpoint, 1);
11084 add_com_alias ("disa", "disable", class_breakpoint, 1);
11086 add_com ("sb", class_breakpoint, disable_command, _("\
11087 Disable some breakpoints.\n\
11088 Arguments are breakpoint numbers with spaces in between.\n\
11089 To disable all breakpoints, give no argument.\n\
11090 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11092 add_cmd ("breakpoints", class_alias, disable_command, _("\
11093 Disable some breakpoints.\n\
11094 Arguments are breakpoint numbers with spaces in between.\n\
11095 To disable all breakpoints, give no argument.\n\
11096 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11097 This command may be abbreviated \"disable\"."),
11100 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
11101 Delete some breakpoints or auto-display expressions.\n\
11102 Arguments are breakpoint numbers with spaces in between.\n\
11103 To delete all breakpoints, give no argument.\n\
11105 Also a prefix command for deletion of other GDB objects.\n\
11106 The \"unset\" command is also an alias for \"delete\"."),
11107 &deletelist, "delete ", 1, &cmdlist);
11108 add_com_alias ("d", "delete", class_breakpoint, 1);
11109 add_com_alias ("del", "delete", class_breakpoint, 1);
11111 add_com ("db", class_breakpoint, delete_command, _("\
11112 Delete some breakpoints.\n\
11113 Arguments are breakpoint numbers with spaces in between.\n\
11114 To delete all breakpoints, give no argument.\n"));
11116 add_cmd ("breakpoints", class_alias, delete_command, _("\
11117 Delete some breakpoints or auto-display expressions.\n\
11118 Arguments are breakpoint numbers with spaces in between.\n\
11119 To delete all breakpoints, give no argument.\n\
11120 This command may be abbreviated \"delete\"."),
11123 add_com ("clear", class_breakpoint, clear_command, _("\
11124 Clear breakpoint at specified line or function.\n\
11125 Argument may be line number, function name, or \"*\" and an address.\n\
11126 If line number is specified, all breakpoints in that line are cleared.\n\
11127 If function is specified, breakpoints at beginning of function are cleared.\n\
11128 If an address is specified, breakpoints at that address are cleared.\n\
11130 With no argument, clears all breakpoints in the line that the selected frame\n\
11131 is executing in.\n\
11133 See also the \"delete\" command which clears breakpoints by number."));
11135 c = add_com ("break", class_breakpoint, break_command, _("\
11136 Set breakpoint at specified line or function.\n"
11137 BREAK_ARGS_HELP ("break")));
11138 set_cmd_completer (c, location_completer);
11140 add_com_alias ("b", "break", class_run, 1);
11141 add_com_alias ("br", "break", class_run, 1);
11142 add_com_alias ("bre", "break", class_run, 1);
11143 add_com_alias ("brea", "break", class_run, 1);
11146 add_com_alias ("ba", "break", class_breakpoint, 1);
11150 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
11151 Break in function/address or break at a line in the current file."),
11152 &stoplist, "stop ", 1, &cmdlist);
11153 add_cmd ("in", class_breakpoint, stopin_command,
11154 _("Break in function or address."), &stoplist);
11155 add_cmd ("at", class_breakpoint, stopat_command,
11156 _("Break at a line in the current file."), &stoplist);
11157 add_com ("status", class_info, breakpoints_info, _("\
11158 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11159 The \"Type\" column indicates one of:\n\
11160 \tbreakpoint - normal breakpoint\n\
11161 \twatchpoint - watchpoint\n\
11162 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11163 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11164 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11165 address and file/line number respectively.\n\
11167 Convenience variable \"$_\" and default examine address for \"x\"\n\
11168 are set to the address of the last breakpoint listed unless the command\n\
11169 is prefixed with \"server \".\n\n\
11170 Convenience variable \"$bpnum\" contains the number of the last\n\
11171 breakpoint set."));
11174 add_info ("breakpoints", breakpoints_info, _("\
11175 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11176 The \"Type\" column indicates one of:\n\
11177 \tbreakpoint - normal breakpoint\n\
11178 \twatchpoint - watchpoint\n\
11179 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11180 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11181 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11182 address and file/line number respectively.\n\
11184 Convenience variable \"$_\" and default examine address for \"x\"\n\
11185 are set to the address of the last breakpoint listed unless the command\n\
11186 is prefixed with \"server \".\n\n\
11187 Convenience variable \"$bpnum\" contains the number of the last\n\
11188 breakpoint set."));
11190 add_info_alias ("b", "breakpoints", 1);
11193 add_com ("lb", class_breakpoint, breakpoints_info, _("\
11194 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11195 The \"Type\" column indicates one of:\n\
11196 \tbreakpoint - normal breakpoint\n\
11197 \twatchpoint - watchpoint\n\
11198 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11199 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11200 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11201 address and file/line number respectively.\n\
11203 Convenience variable \"$_\" and default examine address for \"x\"\n\
11204 are set to the address of the last breakpoint listed unless the command\n\
11205 is prefixed with \"server \".\n\n\
11206 Convenience variable \"$bpnum\" contains the number of the last\n\
11207 breakpoint set."));
11209 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
11210 Status of all breakpoints, or breakpoint number NUMBER.\n\
11211 The \"Type\" column indicates one of:\n\
11212 \tbreakpoint - normal breakpoint\n\
11213 \twatchpoint - watchpoint\n\
11214 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11215 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11216 \tuntil - internal breakpoint used by the \"until\" command\n\
11217 \tfinish - internal breakpoint used by the \"finish\" command\n\
11218 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11219 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11220 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11221 address and file/line number respectively.\n\
11223 Convenience variable \"$_\" and default examine address for \"x\"\n\
11224 are set to the address of the last breakpoint listed unless the command\n\
11225 is prefixed with \"server \".\n\n\
11226 Convenience variable \"$bpnum\" contains the number of the last\n\
11228 &maintenanceinfolist);
11230 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
11231 Set catchpoints to catch events."),
11232 &catch_cmdlist, "catch ",
11233 0/*allow-unknown*/, &cmdlist);
11235 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
11236 Set temporary catchpoints to catch events."),
11237 &tcatch_cmdlist, "tcatch ",
11238 0/*allow-unknown*/, &cmdlist);
11240 /* Add catch and tcatch sub-commands. */
11241 add_catch_command ("catch", _("\
11242 Catch an exception, when caught.\n\
11243 With an argument, catch only exceptions with the given name."),
11244 catch_catch_command,
11248 add_catch_command ("throw", _("\
11249 Catch an exception, when thrown.\n\
11250 With an argument, catch only exceptions with the given name."),
11251 catch_throw_command,
11255 add_catch_command ("fork", _("Catch calls to fork."),
11256 catch_fork_command_1,
11258 (void *) (uintptr_t) catch_fork_permanent,
11259 (void *) (uintptr_t) catch_fork_temporary);
11260 add_catch_command ("vfork", _("Catch calls to vfork."),
11261 catch_fork_command_1,
11263 (void *) (uintptr_t) catch_vfork_permanent,
11264 (void *) (uintptr_t) catch_vfork_temporary);
11265 add_catch_command ("exec", _("Catch calls to exec."),
11266 catch_exec_command_1,
11270 add_catch_command ("syscall", _("\
11271 Catch system calls by their names and/or numbers.\n\
11272 Arguments say which system calls to catch. If no arguments\n\
11273 are given, every system call will be caught.\n\
11274 Arguments, if given, should be one or more system call names\n\
11275 (if your system supports that), or system call numbers."),
11276 catch_syscall_command_1,
11277 catch_syscall_completer,
11280 add_catch_command ("exception", _("\
11281 Catch Ada exceptions, when raised.\n\
11282 With an argument, catch only exceptions with the given name."),
11283 catch_ada_exception_command,
11287 add_catch_command ("assert", _("\
11288 Catch failed Ada assertions, when raised.\n\
11289 With an argument, catch only exceptions with the given name."),
11290 catch_assert_command,
11295 c = add_com ("watch", class_breakpoint, watch_command, _("\
11296 Set a watchpoint for an expression.\n\
11297 A watchpoint stops execution of your program whenever the value of\n\
11298 an expression changes."));
11299 set_cmd_completer (c, expression_completer);
11301 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
11302 Set a read watchpoint for an expression.\n\
11303 A watchpoint stops execution of your program whenever the value of\n\
11304 an expression is read."));
11305 set_cmd_completer (c, expression_completer);
11307 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
11308 Set a watchpoint for an expression.\n\
11309 A watchpoint stops execution of your program whenever the value of\n\
11310 an expression is either read or written."));
11311 set_cmd_completer (c, expression_completer);
11313 add_info ("watchpoints", watchpoints_info, _("\
11314 Status of watchpoints, or watchpoint number NUMBER."));
11318 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11319 respond to changes - contrary to the description. */
11320 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
11321 &can_use_hw_watchpoints, _("\
11322 Set debugger's willingness to use watchpoint hardware."), _("\
11323 Show debugger's willingness to use watchpoint hardware."), _("\
11324 If zero, gdb will not use hardware for new watchpoints, even if\n\
11325 such is available. (However, any hardware watchpoints that were\n\
11326 created before setting this to nonzero, will continue to use watchpoint\n\
11329 show_can_use_hw_watchpoints,
11330 &setlist, &showlist);
11332 can_use_hw_watchpoints = 1;
11334 /* Tracepoint manipulation commands. */
11336 c = add_com ("trace", class_breakpoint, trace_command, _("\
11337 Set a tracepoint at specified line or function.\n\
11339 BREAK_ARGS_HELP ("trace") "\n\
11340 Do \"help tracepoints\" for info on other tracepoint commands."));
11341 set_cmd_completer (c, location_completer);
11343 add_com_alias ("tp", "trace", class_alias, 0);
11344 add_com_alias ("tr", "trace", class_alias, 1);
11345 add_com_alias ("tra", "trace", class_alias, 1);
11346 add_com_alias ("trac", "trace", class_alias, 1);
11348 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
11349 Set a fast tracepoint at specified line or function.\n\
11351 BREAK_ARGS_HELP ("ftrace") "\n\
11352 Do \"help tracepoints\" for info on other tracepoint commands."));
11353 set_cmd_completer (c, location_completer);
11355 add_info ("tracepoints", tracepoints_info, _("\
11356 Status of tracepoints, or tracepoint number NUMBER.\n\
11357 Convenience variable \"$tpnum\" contains the number of the\n\
11358 last tracepoint set."));
11360 add_info_alias ("tp", "tracepoints", 1);
11362 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
11363 Delete specified tracepoints.\n\
11364 Arguments are tracepoint numbers, separated by spaces.\n\
11365 No argument means delete all tracepoints."),
11368 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
11369 Disable specified tracepoints.\n\
11370 Arguments are tracepoint numbers, separated by spaces.\n\
11371 No argument means disable all tracepoints."),
11373 deprecate_cmd (c, "disable");
11375 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
11376 Enable specified tracepoints.\n\
11377 Arguments are tracepoint numbers, separated by spaces.\n\
11378 No argument means enable all tracepoints."),
11380 deprecate_cmd (c, "enable");
11382 add_com ("passcount", class_trace, trace_pass_command, _("\
11383 Set the passcount for a tracepoint.\n\
11384 The trace will end when the tracepoint has been passed 'count' times.\n\
11385 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11386 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11388 add_prefix_cmd ("save", class_breakpoint, save_command,
11389 _("Save breakpoint definitions as a script."),
11390 &save_cmdlist, "save ",
11391 0/*allow-unknown*/, &cmdlist);
11393 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
11394 Save current breakpoint definitions as a script.\n\
11395 This includes all types of breakpoints (breakpoints, watchpoints, \n\
11396 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11397 session to restore them."),
11399 set_cmd_completer (c, filename_completer);
11401 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
11402 Save current tracepoint definitions as a script.\n\
11403 Use the 'source' command in another debug session to restore them."),
11405 set_cmd_completer (c, filename_completer);
11407 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
11408 deprecate_cmd (c, "save tracepoints");
11410 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
11411 Breakpoint specific settings\n\
11412 Configure various breakpoint-specific variables such as\n\
11413 pending breakpoint behavior"),
11414 &breakpoint_set_cmdlist, "set breakpoint ",
11415 0/*allow-unknown*/, &setlist);
11416 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
11417 Breakpoint specific settings\n\
11418 Configure various breakpoint-specific variables such as\n\
11419 pending breakpoint behavior"),
11420 &breakpoint_show_cmdlist, "show breakpoint ",
11421 0/*allow-unknown*/, &showlist);
11423 add_setshow_auto_boolean_cmd ("pending", no_class,
11424 &pending_break_support, _("\
11425 Set debugger's behavior regarding pending breakpoints."), _("\
11426 Show debugger's behavior regarding pending breakpoints."), _("\
11427 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11428 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11429 an error. If auto, an unrecognized breakpoint location results in a\n\
11430 user-query to see if a pending breakpoint should be created."),
11432 show_pending_break_support,
11433 &breakpoint_set_cmdlist,
11434 &breakpoint_show_cmdlist);
11436 pending_break_support = AUTO_BOOLEAN_AUTO;
11438 add_setshow_boolean_cmd ("auto-hw", no_class,
11439 &automatic_hardware_breakpoints, _("\
11440 Set automatic usage of hardware breakpoints."), _("\
11441 Show automatic usage of hardware breakpoints."), _("\
11442 If set, the debugger will automatically use hardware breakpoints for\n\
11443 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11444 a warning will be emitted for such breakpoints."),
11446 show_automatic_hardware_breakpoints,
11447 &breakpoint_set_cmdlist,
11448 &breakpoint_show_cmdlist);
11450 add_setshow_enum_cmd ("always-inserted", class_support,
11451 always_inserted_enums, &always_inserted_mode, _("\
11452 Set mode for inserting breakpoints."), _("\
11453 Show mode for inserting breakpoints."), _("\
11454 When this mode is off, breakpoints are inserted in inferior when it is\n\
11455 resumed, and removed when execution stops. When this mode is on,\n\
11456 breakpoints are inserted immediately and removed only when the user\n\
11457 deletes the breakpoint. When this mode is auto (which is the default),\n\
11458 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11459 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11460 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11461 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11463 &show_always_inserted_mode,
11464 &breakpoint_set_cmdlist,
11465 &breakpoint_show_cmdlist);
11467 automatic_hardware_breakpoints = 1;
11469 observer_attach_about_to_proceed (breakpoint_about_to_proceed);