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"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value *);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint *);
107 /* This function is used in gdbtk sources and thus can not be made static. */
108 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
109 struct symtab_and_line,
112 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
114 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
118 static void describe_other_breakpoints (struct gdbarch *,
119 struct program_space *, CORE_ADDR,
120 struct obj_section *, int);
122 static int breakpoint_address_match (struct address_space *aspace1,
124 struct address_space *aspace2,
127 static int watchpoint_locations_match (struct bp_location *loc1,
128 struct bp_location *loc2);
130 static void breakpoints_info (char *, int);
132 static void watchpoints_info (char *, int);
134 static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
136 static int breakpoint_cond_eval (void *);
138 static void cleanup_executing_breakpoints (void *);
140 static void commands_command (char *, int);
142 static void condition_command (char *, int);
144 static int get_number_trailer (char **, int);
153 static int remove_breakpoint (struct bp_location *, insertion_state_t);
154 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
156 static enum print_stop_action print_it_typical (bpstat);
158 static enum print_stop_action print_bp_stop_message (bpstat bs);
160 static int watchpoint_check (void *);
162 static void maintenance_info_breakpoints (char *, int);
164 static int hw_breakpoint_used_count (void);
166 static int hw_watchpoint_used_count (enum bptype, int *);
168 static void hbreak_command (char *, int);
170 static void thbreak_command (char *, int);
172 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
174 static void stop_command (char *arg, int from_tty);
176 static void stopin_command (char *arg, int from_tty);
178 static void stopat_command (char *arg, int from_tty);
180 static char *ep_parse_optional_if_clause (char **arg);
182 static void catch_exception_command_1 (enum exception_event_kind ex_event,
183 char *arg, int tempflag, int from_tty);
185 static void tcatch_command (char *arg, int from_tty);
187 static void ep_skip_leading_whitespace (char **s);
189 static void detach_single_step_breakpoints (void);
191 static int single_step_breakpoint_inserted_here_p (struct address_space *,
194 static void free_bp_location (struct bp_location *loc);
195 static void incref_bp_location (struct bp_location *loc);
196 static void decref_bp_location (struct bp_location **loc);
198 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
200 static void update_global_location_list (int);
202 static void update_global_location_list_nothrow (int);
204 static int is_hardware_watchpoint (const struct breakpoint *bpt);
206 static int is_watchpoint (const struct breakpoint *bpt);
208 static void insert_breakpoint_locations (void);
210 static int syscall_catchpoint_p (struct breakpoint *b);
212 static void tracepoints_info (char *, int);
214 static void delete_trace_command (char *, int);
216 static void enable_trace_command (char *, int);
218 static void disable_trace_command (char *, int);
220 static void trace_pass_command (char *, int);
222 /* Assuming we're creating a static tracepoint, does S look like a
223 static tracepoint marker spec ("-m MARKER_ID")? */
224 #define is_marker_spec(s) \
225 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
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 const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
256 return bpdisps[(int) disp];
259 /* Prototypes for exported functions. */
260 /* If FALSE, gdb will not use hardware support for watchpoints, even
261 if such is available. */
262 static int can_use_hw_watchpoints;
265 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
266 struct cmd_list_element *c,
269 fprintf_filtered (file, _("\
270 Debugger's willingness to use watchpoint hardware is %s.\n"),
274 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
275 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
276 for unrecognized breakpoint locations.
277 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
278 static enum auto_boolean pending_break_support;
280 show_pending_break_support (struct ui_file *file, int from_tty,
281 struct cmd_list_element *c,
284 fprintf_filtered (file, _("\
285 Debugger's behavior regarding pending breakpoints is %s.\n"),
289 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
290 set with "break" but falling in read-only memory.
291 If 0, gdb will warn about such breakpoints, but won't automatically
292 use hardware breakpoints. */
293 static int automatic_hardware_breakpoints;
295 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
296 struct cmd_list_element *c,
299 fprintf_filtered (file, _("\
300 Automatic usage of hardware breakpoints is %s.\n"),
304 /* If on, gdb will keep breakpoints inserted even as inferior is
305 stopped, and immediately insert any new breakpoints. If off, gdb
306 will insert breakpoints into inferior only when resuming it, and
307 will remove breakpoints upon stop. If auto, GDB will behave as ON
308 if in non-stop mode, and as OFF if all-stop mode.*/
310 static const char always_inserted_auto[] = "auto";
311 static const char always_inserted_on[] = "on";
312 static const char always_inserted_off[] = "off";
313 static const char *always_inserted_enums[] = {
314 always_inserted_auto,
319 static const char *always_inserted_mode = always_inserted_auto;
321 show_always_inserted_mode (struct ui_file *file, int from_tty,
322 struct cmd_list_element *c, const char *value)
324 if (always_inserted_mode == always_inserted_auto)
325 fprintf_filtered (file, _("\
326 Always inserted breakpoint mode is %s (currently %s).\n"),
328 breakpoints_always_inserted_mode () ? "on" : "off");
330 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
334 breakpoints_always_inserted_mode (void)
336 return (always_inserted_mode == always_inserted_on
337 || (always_inserted_mode == always_inserted_auto && non_stop));
340 void _initialize_breakpoint (void);
342 /* Are we executing breakpoint commands? */
343 static int executing_breakpoint_commands;
345 /* Are overlay event breakpoints enabled? */
346 static int overlay_events_enabled;
348 /* Walk the following statement or block through all breakpoints.
349 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
352 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
354 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
355 for (B = breakpoint_chain; \
356 B ? (TMP=B->next, 1): 0; \
359 /* Similar iterator for the low-level breakpoints. SAFE variant is not
360 provided so update_global_location_list must not be called while executing
361 the block of ALL_BP_LOCATIONS. */
363 #define ALL_BP_LOCATIONS(B,BP_TMP) \
364 for (BP_TMP = bp_location; \
365 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
368 /* Iterator for tracepoints only. */
370 #define ALL_TRACEPOINTS(B) \
371 for (B = breakpoint_chain; B; B = B->next) \
372 if (is_tracepoint (B))
374 /* Chains of all breakpoints defined. */
376 struct breakpoint *breakpoint_chain;
378 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
380 static struct bp_location **bp_location;
382 /* Number of elements of BP_LOCATION. */
384 static unsigned bp_location_count;
386 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
387 for the current elements of BP_LOCATION which get a valid result from
388 bp_location_has_shadow. You can use it for roughly limiting the subrange of
389 BP_LOCATION to scan for shadow bytes for an address you need to read. */
391 static CORE_ADDR bp_location_placed_address_before_address_max;
393 /* Maximum offset plus alignment between
394 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
395 the current elements of BP_LOCATION which get a valid result from
396 bp_location_has_shadow. You can use it for roughly limiting the subrange of
397 BP_LOCATION to scan for shadow bytes for an address you need to read. */
399 static CORE_ADDR bp_location_shadow_len_after_address_max;
401 /* The locations that no longer correspond to any breakpoint,
402 unlinked from bp_location array, but for which a hit
403 may still be reported by a target. */
404 VEC(bp_location_p) *moribund_locations = NULL;
406 /* Number of last breakpoint made. */
408 static int breakpoint_count;
410 /* The value of `breakpoint_count' before the last command that
411 created breakpoints. If the last (break-like) command created more
412 than one breakpoint, then the difference between BREAKPOINT_COUNT
413 and PREV_BREAKPOINT_COUNT is more than one. */
414 static int prev_breakpoint_count;
416 /* Number of last tracepoint made. */
418 static int tracepoint_count;
420 static struct cmd_list_element *breakpoint_set_cmdlist;
421 static struct cmd_list_element *breakpoint_show_cmdlist;
422 struct cmd_list_element *save_cmdlist;
424 /* Return whether a breakpoint is an active enabled breakpoint. */
426 breakpoint_enabled (struct breakpoint *b)
428 return (b->enable_state == bp_enabled);
431 /* Set breakpoint count to NUM. */
434 set_breakpoint_count (int num)
436 prev_breakpoint_count = breakpoint_count;
437 breakpoint_count = num;
438 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
441 /* Used by `start_rbreak_breakpoints' below, to record the current
442 breakpoint count before "rbreak" creates any breakpoint. */
443 static int rbreak_start_breakpoint_count;
445 /* Called at the start an "rbreak" command to record the first
449 start_rbreak_breakpoints (void)
451 rbreak_start_breakpoint_count = breakpoint_count;
454 /* Called at the end of an "rbreak" command to record the last
458 end_rbreak_breakpoints (void)
460 prev_breakpoint_count = rbreak_start_breakpoint_count;
463 /* Used in run_command to zero the hit count when a new run starts. */
466 clear_breakpoint_hit_counts (void)
468 struct breakpoint *b;
474 /* Allocate a new counted_command_line with reference count of 1.
475 The new structure owns COMMANDS. */
477 static struct counted_command_line *
478 alloc_counted_command_line (struct command_line *commands)
480 struct counted_command_line *result
481 = xmalloc (sizeof (struct counted_command_line));
484 result->commands = commands;
488 /* Increment reference count. This does nothing if CMD is NULL. */
491 incref_counted_command_line (struct counted_command_line *cmd)
497 /* Decrement reference count. If the reference count reaches 0,
498 destroy the counted_command_line. Sets *CMDP to NULL. This does
499 nothing if *CMDP is NULL. */
502 decref_counted_command_line (struct counted_command_line **cmdp)
506 if (--(*cmdp)->refc == 0)
508 free_command_lines (&(*cmdp)->commands);
515 /* A cleanup function that calls decref_counted_command_line. */
518 do_cleanup_counted_command_line (void *arg)
520 decref_counted_command_line (arg);
523 /* Create a cleanup that calls decref_counted_command_line on the
526 static struct cleanup *
527 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
529 return make_cleanup (do_cleanup_counted_command_line, cmdp);
532 /* Default address, symtab and line to put a breakpoint at
533 for "break" command with no arg.
534 if default_breakpoint_valid is zero, the other three are
535 not valid, and "break" with no arg is an error.
537 This set by print_stack_frame, which calls set_default_breakpoint. */
539 int default_breakpoint_valid;
540 CORE_ADDR default_breakpoint_address;
541 struct symtab *default_breakpoint_symtab;
542 int default_breakpoint_line;
543 struct program_space *default_breakpoint_pspace;
546 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
547 Advance *PP after the string and any trailing whitespace.
549 Currently the string can either be a number or "$" followed by the name
550 of a convenience variable. Making it an expression wouldn't work well
551 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
553 If the string is a NULL pointer, that denotes the last breakpoint.
555 TRAILER is a character which can be found after the number; most
556 commonly this is `-'. If you don't want a trailer, use \0. */
558 get_number_trailer (char **pp, int trailer)
560 int retval = 0; /* default */
564 /* Empty line means refer to the last breakpoint. */
565 return breakpoint_count;
568 /* Make a copy of the name, so we can null-terminate it
569 to pass to lookup_internalvar(). */
574 while (isalnum (*p) || *p == '_')
576 varname = (char *) alloca (p - start + 1);
577 strncpy (varname, start, p - start);
578 varname[p - start] = '\0';
579 if (get_internalvar_integer (lookup_internalvar (varname), &val))
583 printf_filtered (_("Convenience variable must have integer value.\n"));
591 while (*p >= '0' && *p <= '9')
594 /* There is no number here. (e.g. "cond a == b"). */
596 /* Skip non-numeric token */
597 while (*p && !isspace((int) *p))
599 /* Return zero, which caller must interpret as error. */
605 if (!(isspace (*p) || *p == '\0' || *p == trailer))
607 /* Trailing junk: return 0 and let caller print error msg. */
608 while (!(isspace (*p) || *p == '\0' || *p == trailer))
619 /* Like get_number_trailer, but don't allow a trailer. */
621 get_number (char **pp)
623 return get_number_trailer (pp, '\0');
626 /* Parse a number or a range.
627 * A number will be of the form handled by get_number.
628 * A range will be of the form <number1> - <number2>, and
629 * will represent all the integers between number1 and number2,
632 * While processing a range, this fuction is called iteratively;
633 * At each call it will return the next value in the range.
635 * At the beginning of parsing a range, the char pointer PP will
636 * be advanced past <number1> and left pointing at the '-' token.
637 * Subsequent calls will not advance the pointer until the range
638 * is completed. The call that completes the range will advance
639 * pointer PP past <number2>.
643 get_number_or_range (char **pp)
645 static int last_retval, end_value;
646 static char *end_ptr;
647 static int in_range = 0;
651 /* Default case: pp is pointing either to a solo number,
652 or to the first number of a range. */
653 last_retval = get_number_trailer (pp, '-');
658 /* This is the start of a range (<number1> - <number2>).
659 Skip the '-', parse and remember the second number,
660 and also remember the end of the final token. */
664 while (isspace ((int) *end_ptr))
665 end_ptr++; /* skip white space */
666 end_value = get_number (temp);
667 if (end_value < last_retval)
669 error (_("inverted range"));
671 else if (end_value == last_retval)
673 /* degenerate range (number1 == number2). Advance the
674 token pointer so that the range will be treated as a
683 error (_("negative value"));
686 /* pp points to the '-' that betokens a range. All
687 number-parsing has already been done. Return the next
688 integer value (one greater than the saved previous value).
689 Do not advance the token pointer 'pp' until the end of range
692 if (++last_retval == end_value)
694 /* End of range reached; advance token pointer. */
702 /* Return the breakpoint with the specified number, or NULL
703 if the number does not refer to an existing breakpoint. */
706 get_breakpoint (int num)
708 struct breakpoint *b;
711 if (b->number == num)
720 set_breakpoint_condition (struct breakpoint *b, char *exp,
723 struct bp_location *loc = b->loc;
725 for (; loc; loc = loc->next)
730 xfree (b->cond_string);
731 b->cond_string = NULL;
738 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
744 /* I don't know if it matters whether this is the string the user
745 typed in or the decompiled expression. */
746 b->cond_string = xstrdup (arg);
747 b->condition_not_parsed = 0;
749 if (is_watchpoint (b))
751 innermost_block = NULL;
753 b->cond_exp = parse_exp_1 (&arg, 0, 0);
755 error (_("Junk at end of expression"));
756 b->cond_exp_valid_block = innermost_block;
760 for (loc = b->loc; loc; loc = loc->next)
764 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
766 error (_("Junk at end of expression"));
770 breakpoints_changed ();
771 observer_notify_breakpoint_modified (b->number);
774 /* condition N EXP -- set break condition of breakpoint N to EXP. */
777 condition_command (char *arg, int from_tty)
779 struct breakpoint *b;
784 error_no_arg (_("breakpoint number"));
787 bnum = get_number (&p);
789 error (_("Bad breakpoint argument: '%s'"), arg);
792 if (b->number == bnum)
794 set_breakpoint_condition (b, p, from_tty);
798 error (_("No breakpoint number %d."), bnum);
801 /* Check that COMMAND do not contain commands that are suitable
802 only for tracepoints and not suitable for ordinary breakpoints.
803 Throw if any such commands is found.
806 check_no_tracepoint_commands (struct command_line *commands)
808 struct command_line *c;
810 for (c = commands; c; c = c->next)
814 if (c->control_type == while_stepping_control)
815 error (_("The 'while-stepping' command can only be used for tracepoints"));
817 for (i = 0; i < c->body_count; ++i)
818 check_no_tracepoint_commands ((c->body_list)[i]);
820 /* Not that command parsing removes leading whitespace and comment
821 lines and also empty lines. So, we only need to check for
823 if (strstr (c->line, "collect ") == c->line)
824 error (_("The 'collect' command can only be used for tracepoints"));
826 if (strstr (c->line, "teval ") == c->line)
827 error (_("The 'teval' command can only be used for tracepoints"));
831 /* Encapsulate tests for different types of tracepoints. */
834 is_tracepoint (const struct breakpoint *b)
836 return (b->type == bp_tracepoint
837 || b->type == bp_fast_tracepoint
838 || b->type == bp_static_tracepoint);
841 /* A helper function that validsates that COMMANDS are valid for a
842 breakpoint. This function will throw an exception if a problem is
846 validate_commands_for_breakpoint (struct breakpoint *b,
847 struct command_line *commands)
849 if (is_tracepoint (b))
851 /* We need to verify that each top-level element of commands
852 is valid for tracepoints, that there's at most one while-stepping
853 element, and that while-stepping's body has valid tracing commands
854 excluding nested while-stepping. */
855 struct command_line *c;
856 struct command_line *while_stepping = 0;
857 for (c = commands; c; c = c->next)
859 if (c->control_type == while_stepping_control)
861 if (b->type == bp_fast_tracepoint)
863 The 'while-stepping' command cannot be used for fast tracepoint"));
864 else if (b->type == bp_static_tracepoint)
866 The 'while-stepping' command cannot be used for static tracepoint"));
869 error (_("The 'while-stepping' command can be used only once"));
876 struct command_line *c2;
878 gdb_assert (while_stepping->body_count == 1);
879 c2 = while_stepping->body_list[0];
880 for (; c2; c2 = c2->next)
882 if (c2->control_type == while_stepping_control)
883 error (_("The 'while-stepping' command cannot be nested"));
889 check_no_tracepoint_commands (commands);
893 /* Return a vector of all the static tracepoints set at ADDR. The
894 caller is responsible for releasing the vector. */
897 static_tracepoints_here (CORE_ADDR addr)
899 struct breakpoint *b;
900 VEC(breakpoint_p) *found = 0;
901 struct bp_location *loc;
904 if (b->type == bp_static_tracepoint)
906 for (loc = b->loc; loc; loc = loc->next)
907 if (loc->address == addr)
908 VEC_safe_push(breakpoint_p, found, b);
914 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
915 validate that only allowed commands are included.
919 breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
921 validate_commands_for_breakpoint (b, commands);
923 decref_counted_command_line (&b->commands);
924 b->commands = alloc_counted_command_line (commands);
925 breakpoints_changed ();
926 observer_notify_breakpoint_modified (b->number);
930 check_tracepoint_command (char *line, void *closure)
932 struct breakpoint *b = closure;
934 validate_actionline (&line, b);
937 /* A structure used to pass information through
938 map_breakpoint_numbers. */
942 /* True if the command was typed at a tty. */
945 /* The breakpoint range spec. */
948 /* Non-NULL if the body of the commands are being read from this
949 already-parsed command. */
950 struct command_line *control;
952 /* The command lines read from the user, or NULL if they have not
954 struct counted_command_line *cmd;
957 /* A callback for map_breakpoint_numbers that sets the commands for
961 do_map_commands_command (struct breakpoint *b, void *data)
963 struct commands_info *info = data;
965 if (info->cmd == NULL)
967 struct command_line *l;
969 if (info->control != NULL)
970 l = copy_command_lines (info->control->body_list[0]);
973 struct cleanup *old_chain;
976 str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
979 old_chain = make_cleanup (xfree, str);
981 l = read_command_lines (str,
984 ? check_tracepoint_command : 0),
987 do_cleanups (old_chain);
990 info->cmd = alloc_counted_command_line (l);
993 /* If a breakpoint was on the list more than once, we don't need to
995 if (b->commands != info->cmd)
997 validate_commands_for_breakpoint (b, info->cmd->commands);
998 incref_counted_command_line (info->cmd);
999 decref_counted_command_line (&b->commands);
1000 b->commands = info->cmd;
1001 breakpoints_changed ();
1002 observer_notify_breakpoint_modified (b->number);
1007 commands_command_1 (char *arg, int from_tty, struct command_line *control)
1009 struct cleanup *cleanups;
1010 struct commands_info info;
1012 info.from_tty = from_tty;
1013 info.control = control;
1015 /* If we read command lines from the user, then `info' will hold an
1016 extra reference to the commands that we must clean up. */
1017 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1019 if (arg == NULL || !*arg)
1021 if (breakpoint_count - prev_breakpoint_count > 1)
1022 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count);
1023 else if (breakpoint_count > 0)
1024 arg = xstrprintf ("%d", breakpoint_count);
1027 /* So that we don't try to free the incoming non-NULL
1028 argument in the cleanup below. Mapping breakpoint
1029 numbers will fail in this case. */
1034 /* The command loop has some static state, so we need to preserve
1036 arg = xstrdup (arg);
1039 make_cleanup (xfree, arg);
1043 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1045 if (info.cmd == NULL)
1046 error (_("No breakpoints specified."));
1048 do_cleanups (cleanups);
1052 commands_command (char *arg, int from_tty)
1054 commands_command_1 (arg, from_tty, NULL);
1057 /* Like commands_command, but instead of reading the commands from
1058 input stream, takes them from an already parsed command structure.
1060 This is used by cli-script.c to DTRT with breakpoint commands
1061 that are part of if and while bodies. */
1062 enum command_control_type
1063 commands_from_control_command (char *arg, struct command_line *cmd)
1065 commands_command_1 (arg, 0, cmd);
1066 return simple_control;
1069 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1072 bp_location_has_shadow (struct bp_location *bl)
1074 if (bl->loc_type != bp_loc_software_breakpoint)
1078 if (bl->target_info.shadow_len == 0)
1079 /* bp isn't valid, or doesn't shadow memory. */
1084 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1085 by replacing any memory breakpoints with their shadowed contents.
1087 The range of shadowed area by each bp_location is:
1088 bl->address - bp_location_placed_address_before_address_max
1089 up to bl->address + bp_location_shadow_len_after_address_max
1090 The range we were requested to resolve shadows for is:
1091 memaddr ... memaddr + len
1092 Thus the safe cutoff boundaries for performance optimization are
1093 memaddr + len <= (bl->address
1094 - bp_location_placed_address_before_address_max)
1096 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1099 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1101 /* Left boundary, right boundary and median element of our binary search. */
1102 unsigned bc_l, bc_r, bc;
1104 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1105 safe to report lower value but a failure to report higher one. */
1108 bc_r = bp_location_count;
1109 while (bc_l + 1 < bc_r)
1111 struct bp_location *bl;
1113 bc = (bc_l + bc_r) / 2;
1114 bl = bp_location[bc];
1116 /* Check first BL->ADDRESS will not overflow due to the added constant.
1117 Then advance the left boundary only if we are sure the BC element can
1118 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1120 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1121 we cannot miss a breakpoint with its shadow range tail still reaching
1124 if ((bl->address + bp_location_shadow_len_after_address_max
1126 && (bl->address + bp_location_shadow_len_after_address_max
1133 /* Now do full processing of the found relevant range of elements. */
1135 for (bc = bc_l; bc < bp_location_count; bc++)
1137 struct bp_location *bl = bp_location[bc];
1138 CORE_ADDR bp_addr = 0;
1142 /* bp_location array has BL->OWNER always non-NULL. */
1143 if (bl->owner->type == bp_none)
1144 warning (_("reading through apparently deleted breakpoint #%d?"),
1147 /* Performance optimization: any futher element can no longer affect BUF
1150 if (bl->address >= bp_location_placed_address_before_address_max
1151 && memaddr + len <= (bl->address
1152 - bp_location_placed_address_before_address_max))
1155 if (!bp_location_has_shadow (bl))
1157 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1158 current_program_space->aspace, 0))
1161 /* Addresses and length of the part of the breakpoint that
1163 bp_addr = bl->target_info.placed_address;
1164 bp_size = bl->target_info.shadow_len;
1166 if (bp_addr + bp_size <= memaddr)
1167 /* The breakpoint is entirely before the chunk of memory we
1171 if (bp_addr >= memaddr + len)
1172 /* The breakpoint is entirely after the chunk of memory we are
1176 /* Offset within shadow_contents. */
1177 if (bp_addr < memaddr)
1179 /* Only copy the second part of the breakpoint. */
1180 bp_size -= memaddr - bp_addr;
1181 bptoffset = memaddr - bp_addr;
1185 if (bp_addr + bp_size > memaddr + len)
1187 /* Only copy the first part of the breakpoint. */
1188 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1191 memcpy (buf + bp_addr - memaddr,
1192 bl->target_info.shadow_contents + bptoffset, bp_size);
1197 /* A wrapper function for inserting catchpoints. */
1199 insert_catchpoint (struct ui_out *uo, void *args)
1201 struct breakpoint *b = (struct breakpoint *) args;
1203 gdb_assert (b->type == bp_catchpoint);
1204 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
1209 /* Return true if BPT is of any hardware watchpoint kind. */
1212 is_hardware_watchpoint (const struct breakpoint *bpt)
1214 return (bpt->type == bp_hardware_watchpoint
1215 || bpt->type == bp_read_watchpoint
1216 || bpt->type == bp_access_watchpoint);
1219 /* Return true if BPT is of any watchpoint kind, hardware or
1223 is_watchpoint (const struct breakpoint *bpt)
1225 return (is_hardware_watchpoint (bpt)
1226 || bpt->type == bp_watchpoint);
1229 /* Assuming that B is a watchpoint: returns true if the current thread
1230 and its running state are safe to evaluate or update watchpoint B.
1231 Watchpoints on local expressions need to be evaluated in the
1232 context of the thread that was current when the watchpoint was
1233 created, and, that thread needs to be stopped to be able to select
1234 the correct frame context. Watchpoints on global expressions can
1235 be evaluated on any thread, and in any state. It is presently left
1236 to the target allowing memory accesses when threads are
1240 watchpoint_in_thread_scope (struct breakpoint *b)
1242 return (ptid_equal (b->watchpoint_thread, null_ptid)
1243 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1244 && !is_executing (inferior_ptid)));
1247 /* Assuming that B is a watchpoint:
1248 - Reparse watchpoint expression, if REPARSE is non-zero
1249 - Evaluate expression and store the result in B->val
1250 - Evaluate the condition if there is one, and store the result
1252 - Update the list of values that must be watched in B->loc.
1254 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1255 If this is local watchpoint that is out of scope, delete it.
1257 Even with `set breakpoint always-inserted on' the watchpoints are removed
1258 + inserted on each stop here. Normal breakpoints must never be removed
1259 because they might be missed by a running thread when debugging in non-stop
1260 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1261 processed here) are specific to each LWP since they are stored in each LWP's
1262 hardware debug registers. Therefore, such LWP must be stopped first in
1263 order to be able to modify its hardware watchpoints.
1265 Hardware watchpoints must be reset exactly once after being presented to the
1266 user. It cannot be done sooner, because it would reset the data used to
1267 present the watchpoint hit to the user. And it must not be done later
1268 because it could display the same single watchpoint hit during multiple GDB
1269 stops. Note that the latter is relevant only to the hardware watchpoint
1270 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1271 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1272 memory content has not changed.
1274 The following constraints influence the location where we can reset hardware
1277 * target_stopped_by_watchpoint and target_stopped_data_address are called
1278 several times when GDB stops.
1281 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1282 stop. GDB only presents one hardware watchpoint hit at a time as the
1283 reason for stopping, and all the other hits are presented later, one after
1284 the other, each time the user requests the execution to be resumed.
1285 Execution is not resumed for the threads still having pending hit event
1286 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1287 the inferior on the first stop the thread hit event is kept being reported
1288 from its cached value by linux_nat_stopped_data_address until the real
1289 thread resume happens after the watchpoint gets presented and thus its
1290 LWP_INFO->STATUS gets reset.
1292 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1293 removal from inferior. */
1296 update_watchpoint (struct breakpoint *b, int reparse)
1298 int within_current_scope;
1299 struct frame_id saved_frame_id;
1302 /* If this is a local watchpoint, we only want to check if the
1303 watchpoint frame is in scope if the current thread is the thread
1304 that was used to create the watchpoint. */
1305 if (!watchpoint_in_thread_scope (b))
1308 /* We don't free locations. They are stored in bp_location array and
1309 update_global_locations will eventually delete them and remove
1310 breakpoints if needed. */
1313 if (b->disposition == disp_del_at_next_stop)
1318 /* Determine if the watchpoint is within scope. */
1319 if (b->exp_valid_block == NULL)
1320 within_current_scope = 1;
1323 struct frame_info *fi;
1325 /* Save the current frame's ID so we can restore it after
1326 evaluating the watchpoint expression on its own frame. */
1327 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1328 took a frame parameter, so that we didn't have to change the
1331 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1333 fi = frame_find_by_id (b->watchpoint_frame);
1334 within_current_scope = (fi != NULL);
1335 if (within_current_scope)
1339 if (within_current_scope && reparse)
1348 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1349 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1350 /* If the meaning of expression itself changed, the old value is
1351 no longer relevant. We don't want to report a watchpoint hit
1352 to the user when the old value and the new value may actually
1353 be completely different objects. */
1354 value_free (b->val);
1358 /* Note that unlike with breakpoints, the watchpoint's condition
1359 expression is stored in the breakpoint object, not in the
1360 locations (re)created below. */
1361 if (b->cond_string != NULL)
1363 if (b->cond_exp != NULL)
1365 xfree (b->cond_exp);
1370 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1374 /* If we failed to parse the expression, for example because
1375 it refers to a global variable in a not-yet-loaded shared library,
1376 don't try to insert watchpoint. We don't automatically delete
1377 such watchpoint, though, since failure to parse expression
1378 is different from out-of-scope watchpoint. */
1379 if ( !target_has_execution)
1381 /* Without execution, memory can't change. No use to try and
1382 set watchpoint locations. The watchpoint will be reset when
1383 the target gains execution, through breakpoint_re_set. */
1385 else if (within_current_scope && b->exp)
1388 struct value *val_chain, *v, *result, *next;
1389 struct program_space *frame_pspace;
1391 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1393 /* Avoid setting b->val if it's already set. The meaning of
1394 b->val is 'the last value' user saw, and we should update
1395 it only if we reported that last value to user. As it
1396 happens, the code that reports it updates b->val directly. */
1403 /* Change the type of breakpoint between hardware assisted or an
1404 ordinary watchpoint depending on the hardware support and free
1405 hardware slots. REPARSE is set when the inferior is started. */
1406 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1409 int i, mem_cnt, other_type_used;
1411 /* We need to determine how many resources are already used
1412 for all other hardware watchpoints to see if we still have
1413 enough resources to also fit this watchpoint in as well.
1414 To avoid the hw_watchpoint_used_count call below from counting
1415 this watchpoint, make sure that it is marked as a software
1417 b->type = bp_watchpoint;
1418 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1420 mem_cnt = can_use_hardware_watchpoint (val_chain);
1423 b->type = bp_watchpoint;
1426 int target_resources_ok = target_can_use_hardware_watchpoint
1427 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1428 if (target_resources_ok <= 0)
1429 b->type = bp_watchpoint;
1431 b->type = bp_hardware_watchpoint;
1435 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1437 /* Look at each value on the value chain. */
1438 for (v = val_chain; v; v = next)
1440 /* If it's a memory location, and GDB actually needed
1441 its contents to evaluate the expression, then we
1442 must watch it. If the first value returned is
1443 still lazy, that means an error occurred reading it;
1444 watch it anyway in case it becomes readable. */
1445 if (VALUE_LVAL (v) == lval_memory
1446 && (v == val_chain || ! value_lazy (v)))
1448 struct type *vtype = check_typedef (value_type (v));
1450 /* We only watch structs and arrays if user asked
1451 for it explicitly, never if they just happen to
1452 appear in the middle of some value chain. */
1454 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1455 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1459 struct bp_location *loc, **tmp;
1461 addr = value_address (v);
1462 len = TYPE_LENGTH (value_type (v));
1464 if (b->type == bp_read_watchpoint)
1466 else if (b->type == bp_access_watchpoint)
1469 loc = allocate_bp_location (b);
1470 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1473 loc->gdbarch = get_type_arch (value_type (v));
1475 loc->pspace = frame_pspace;
1476 loc->address = addr;
1478 loc->watchpoint_type = type;
1482 next = value_next (v);
1487 /* If a software watchpoint is not watching any memory, then the
1488 above left it without any location set up. But,
1489 bpstat_stop_status requires a location to be able to report
1490 stops, so make sure there's at least a dummy one. */
1491 if (b->type == bp_watchpoint && b->loc == NULL)
1493 b->loc = allocate_bp_location (b);
1494 b->loc->pspace = frame_pspace;
1495 b->loc->address = -1;
1496 b->loc->length = -1;
1497 b->loc->watchpoint_type = -1;
1500 else if (!within_current_scope)
1502 printf_filtered (_("\
1503 Watchpoint %d deleted because the program has left the block\n\
1504 in which its expression is valid.\n"),
1506 if (b->related_breakpoint)
1508 b->related_breakpoint->disposition = disp_del_at_next_stop;
1509 b->related_breakpoint->related_breakpoint = NULL;
1510 b->related_breakpoint= NULL;
1512 b->disposition = disp_del_at_next_stop;
1515 /* Restore the selected frame. */
1517 select_frame (frame_find_by_id (saved_frame_id));
1521 /* Returns 1 iff breakpoint location should be
1522 inserted in the inferior. */
1524 should_be_inserted (struct bp_location *bl)
1526 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1529 if (bl->owner->disposition == disp_del_at_next_stop)
1532 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1535 /* This is set for example, when we're attached to the parent of a
1536 vfork, and have detached from the child. The child is running
1537 free, and we expect it to do an exec or exit, at which point the
1538 OS makes the parent schedulable again (and the target reports
1539 that the vfork is done). Until the child is done with the shared
1540 memory region, do not insert breakpoints in the parent, otherwise
1541 the child could still trip on the parent's breakpoints. Since
1542 the parent is blocked anyway, it won't miss any breakpoint. */
1543 if (bl->pspace->breakpoints_not_allowed)
1546 /* Tracepoints are inserted by the target at a time of its choosing,
1548 if (is_tracepoint (bl->owner))
1554 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1555 location. Any error messages are printed to TMP_ERROR_STREAM; and
1556 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1558 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1559 method for each breakpoint or catchpoint type. */
1561 insert_bp_location (struct bp_location *bl,
1562 struct ui_file *tmp_error_stream,
1563 int *disabled_breaks,
1564 int *hw_breakpoint_error)
1568 if (!should_be_inserted (bl) || bl->inserted)
1571 /* Initialize the target-specific information. */
1572 memset (&bl->target_info, 0, sizeof (bl->target_info));
1573 bl->target_info.placed_address = bl->address;
1574 bl->target_info.placed_address_space = bl->pspace->aspace;
1576 if (bl->loc_type == bp_loc_software_breakpoint
1577 || bl->loc_type == bp_loc_hardware_breakpoint)
1579 if (bl->owner->type != bp_hardware_breakpoint)
1581 /* If the explicitly specified breakpoint type
1582 is not hardware breakpoint, check the memory map to see
1583 if the breakpoint address is in read only memory or not.
1584 Two important cases are:
1585 - location type is not hardware breakpoint, memory
1586 is readonly. We change the type of the location to
1587 hardware breakpoint.
1588 - location type is hardware breakpoint, memory is read-write.
1589 This means we've previously made the location hardware one, but
1590 then the memory map changed, so we undo.
1592 When breakpoints are removed, remove_breakpoints will
1593 use location types we've just set here, the only possible
1594 problem is that memory map has changed during running program,
1595 but it's not going to work anyway with current gdb. */
1596 struct mem_region *mr
1597 = lookup_mem_region (bl->target_info.placed_address);
1601 if (automatic_hardware_breakpoints)
1603 enum bp_loc_type new_type;
1605 if (mr->attrib.mode != MEM_RW)
1606 new_type = bp_loc_hardware_breakpoint;
1608 new_type = bp_loc_software_breakpoint;
1610 if (new_type != bl->loc_type)
1612 static int said = 0;
1614 bl->loc_type = new_type;
1617 fprintf_filtered (gdb_stdout, _("\
1618 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1623 else if (bl->loc_type == bp_loc_software_breakpoint
1624 && mr->attrib.mode != MEM_RW)
1625 warning (_("cannot set software breakpoint at readonly address %s"),
1626 paddress (bl->gdbarch, bl->address));
1630 /* First check to see if we have to handle an overlay. */
1631 if (overlay_debugging == ovly_off
1632 || bl->section == NULL
1633 || !(section_is_overlay (bl->section)))
1635 /* No overlay handling: just set the breakpoint. */
1637 if (bl->loc_type == bp_loc_hardware_breakpoint)
1638 val = target_insert_hw_breakpoint (bl->gdbarch,
1641 val = target_insert_breakpoint (bl->gdbarch,
1646 /* This breakpoint is in an overlay section.
1647 Shall we set a breakpoint at the LMA? */
1648 if (!overlay_events_enabled)
1650 /* Yes -- overlay event support is not active,
1651 so we must try to set a breakpoint at the LMA.
1652 This will not work for a hardware breakpoint. */
1653 if (bl->loc_type == bp_loc_hardware_breakpoint)
1654 warning (_("hardware breakpoint %d not supported in overlay!"),
1658 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1660 /* Set a software (trap) breakpoint at the LMA. */
1661 bl->overlay_target_info = bl->target_info;
1662 bl->overlay_target_info.placed_address = addr;
1663 val = target_insert_breakpoint (bl->gdbarch,
1664 &bl->overlay_target_info);
1666 fprintf_unfiltered (tmp_error_stream,
1667 "Overlay breakpoint %d failed: in ROM?\n",
1671 /* Shall we set a breakpoint at the VMA? */
1672 if (section_is_mapped (bl->section))
1674 /* Yes. This overlay section is mapped into memory. */
1675 if (bl->loc_type == bp_loc_hardware_breakpoint)
1676 val = target_insert_hw_breakpoint (bl->gdbarch,
1679 val = target_insert_breakpoint (bl->gdbarch,
1684 /* No. This breakpoint will not be inserted.
1685 No error, but do not mark the bp as 'inserted'. */
1692 /* Can't set the breakpoint. */
1693 if (solib_name_from_address (bl->pspace, bl->address))
1695 /* See also: disable_breakpoints_in_shlibs. */
1697 bl->shlib_disabled = 1;
1698 if (!*disabled_breaks)
1700 fprintf_unfiltered (tmp_error_stream,
1701 "Cannot insert breakpoint %d.\n",
1703 fprintf_unfiltered (tmp_error_stream,
1704 "Temporarily disabling shared library breakpoints:\n");
1706 *disabled_breaks = 1;
1707 fprintf_unfiltered (tmp_error_stream,
1708 "breakpoint #%d\n", bl->owner->number);
1712 if (bl->loc_type == bp_loc_hardware_breakpoint)
1714 *hw_breakpoint_error = 1;
1715 fprintf_unfiltered (tmp_error_stream,
1716 "Cannot insert hardware breakpoint %d.\n",
1721 fprintf_unfiltered (tmp_error_stream,
1722 "Cannot insert breakpoint %d.\n",
1724 fprintf_filtered (tmp_error_stream,
1725 "Error accessing memory address ");
1726 fputs_filtered (paddress (bl->gdbarch, bl->address),
1728 fprintf_filtered (tmp_error_stream, ": %s.\n",
1729 safe_strerror (val));
1740 else if (bl->loc_type == bp_loc_hardware_watchpoint
1741 /* NOTE drow/2003-09-08: This state only exists for removing
1742 watchpoints. It's not clear that it's necessary... */
1743 && bl->owner->disposition != disp_del_at_next_stop)
1745 val = target_insert_watchpoint (bl->address,
1747 bl->watchpoint_type,
1748 bl->owner->cond_exp);
1750 /* If trying to set a read-watchpoint, and it turns out it's not
1751 supported, try emulating one with an access watchpoint. */
1752 if (val == 1 && bl->watchpoint_type == hw_read)
1754 struct bp_location *loc, **loc_temp;
1756 /* But don't try to insert it, if there's already another
1757 hw_access location that would be considered a duplicate
1759 ALL_BP_LOCATIONS (loc, loc_temp)
1761 && loc->watchpoint_type == hw_access
1762 && watchpoint_locations_match (bl, loc))
1766 bl->target_info = loc->target_info;
1767 bl->watchpoint_type = hw_access;
1774 val = target_insert_watchpoint (bl->address,
1777 bl->owner->cond_exp);
1779 bl->watchpoint_type = hw_access;
1783 bl->inserted = (val == 0);
1786 else if (bl->owner->type == bp_catchpoint)
1788 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1789 bl->owner, RETURN_MASK_ERROR);
1790 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1793 bl->owner->enable_state = bp_disabled;
1797 /* We've already printed an error message if there was a problem
1798 inserting this catchpoint, and we've disabled the catchpoint,
1799 so just return success. */
1806 /* This function is called when program space PSPACE is about to be
1807 deleted. It takes care of updating breakpoints to not reference
1811 breakpoint_program_space_exit (struct program_space *pspace)
1813 struct breakpoint *b, *b_temp;
1814 struct bp_location *loc, **loc_temp;
1816 /* Remove any breakpoint that was set through this program space. */
1817 ALL_BREAKPOINTS_SAFE (b, b_temp)
1819 if (b->pspace == pspace)
1820 delete_breakpoint (b);
1823 /* Breakpoints set through other program spaces could have locations
1824 bound to PSPACE as well. Remove those. */
1825 ALL_BP_LOCATIONS (loc, loc_temp)
1827 struct bp_location *tmp;
1829 if (loc->pspace == pspace)
1831 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1832 if (loc->owner->loc == loc)
1833 loc->owner->loc = loc->next;
1835 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1836 if (tmp->next == loc)
1838 tmp->next = loc->next;
1844 /* Now update the global location list to permanently delete the
1845 removed locations above. */
1846 update_global_location_list (0);
1849 /* Make sure all breakpoints are inserted in inferior.
1850 Throws exception on any error.
1851 A breakpoint that is already inserted won't be inserted
1852 again, so calling this function twice is safe. */
1854 insert_breakpoints (void)
1856 struct breakpoint *bpt;
1858 ALL_BREAKPOINTS (bpt)
1859 if (is_hardware_watchpoint (bpt))
1860 update_watchpoint (bpt, 0 /* don't reparse. */);
1862 update_global_location_list (1);
1864 /* update_global_location_list does not insert breakpoints when
1865 always_inserted_mode is not enabled. Explicitly insert them
1867 if (!breakpoints_always_inserted_mode ())
1868 insert_breakpoint_locations ();
1871 /* insert_breakpoints is used when starting or continuing the program.
1872 remove_breakpoints is used when the program stops.
1873 Both return zero if successful,
1874 or an `errno' value if could not write the inferior. */
1877 insert_breakpoint_locations (void)
1879 struct breakpoint *bpt;
1880 struct bp_location *bl, **blp_tmp;
1883 int disabled_breaks = 0;
1884 int hw_breakpoint_error = 0;
1886 struct ui_file *tmp_error_stream = mem_fileopen ();
1887 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1889 /* Explicitly mark the warning -- this will only be printed if
1890 there was an error. */
1891 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1893 save_current_space_and_thread ();
1895 ALL_BP_LOCATIONS (bl, blp_tmp)
1897 if (!should_be_inserted (bl) || bl->inserted)
1900 /* There is no point inserting thread-specific breakpoints if the
1901 thread no longer exists. ALL_BP_LOCATIONS bp_location has BL->OWNER
1903 if (bl->owner->thread != -1
1904 && !valid_thread_id (bl->owner->thread))
1907 switch_to_program_space_and_thread (bl->pspace);
1909 /* For targets that support global breakpoints, there's no need
1910 to select an inferior to insert breakpoint to. In fact, even
1911 if we aren't attached to any process yet, we should still
1912 insert breakpoints. */
1913 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1914 && ptid_equal (inferior_ptid, null_ptid))
1917 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1918 &hw_breakpoint_error);
1923 /* If we failed to insert all locations of a watchpoint,
1924 remove them, as half-inserted watchpoint is of limited use. */
1925 ALL_BREAKPOINTS (bpt)
1927 int some_failed = 0;
1928 struct bp_location *loc;
1930 if (!is_hardware_watchpoint (bpt))
1933 if (!breakpoint_enabled (bpt))
1936 if (bpt->disposition == disp_del_at_next_stop)
1939 for (loc = bpt->loc; loc; loc = loc->next)
1940 if (!loc->inserted && should_be_inserted (loc))
1947 for (loc = bpt->loc; loc; loc = loc->next)
1949 remove_breakpoint (loc, mark_uninserted);
1951 hw_breakpoint_error = 1;
1952 fprintf_unfiltered (tmp_error_stream,
1953 "Could not insert hardware watchpoint %d.\n",
1961 /* If a hardware breakpoint or watchpoint was inserted, add a
1962 message about possibly exhausted resources. */
1963 if (hw_breakpoint_error)
1965 fprintf_unfiltered (tmp_error_stream,
1966 "Could not insert hardware breakpoints:\n\
1967 You may have requested too many hardware breakpoints/watchpoints.\n");
1969 target_terminal_ours_for_output ();
1970 error_stream (tmp_error_stream);
1973 do_cleanups (cleanups);
1977 remove_breakpoints (void)
1979 struct bp_location *bl, **blp_tmp;
1982 ALL_BP_LOCATIONS (bl, blp_tmp)
1985 val |= remove_breakpoint (bl, mark_uninserted);
1990 /* Remove breakpoints of process PID. */
1993 remove_breakpoints_pid (int pid)
1995 struct bp_location *bl, **blp_tmp;
1997 struct inferior *inf = find_inferior_pid (pid);
1999 ALL_BP_LOCATIONS (bl, blp_tmp)
2001 if (bl->pspace != inf->pspace)
2006 val = remove_breakpoint (bl, mark_uninserted);
2015 remove_hw_watchpoints (void)
2017 struct bp_location *bl, **blp_tmp;
2020 ALL_BP_LOCATIONS (bl, blp_tmp)
2022 if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint)
2023 val |= remove_breakpoint (bl, mark_uninserted);
2029 reattach_breakpoints (int pid)
2031 struct cleanup *old_chain;
2032 struct bp_location *bl, **blp_tmp;
2034 struct ui_file *tmp_error_stream = mem_fileopen ();
2035 int dummy1 = 0, dummy2 = 0;
2036 struct inferior *inf;
2037 struct thread_info *tp;
2039 tp = any_live_thread_of_process (pid);
2043 inf = find_inferior_pid (pid);
2044 old_chain = save_inferior_ptid ();
2046 inferior_ptid = tp->ptid;
2048 make_cleanup_ui_file_delete (tmp_error_stream);
2050 ALL_BP_LOCATIONS (bl, blp_tmp)
2052 if (bl->pspace != inf->pspace)
2058 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2061 do_cleanups (old_chain);
2066 do_cleanups (old_chain);
2070 static int internal_breakpoint_number = -1;
2072 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2073 If INTERNAL is non-zero, the breakpoint number will be populated
2074 from internal_breakpoint_number and that variable decremented.
2075 Otherwis the breakpoint number will be populated from
2076 breakpoint_count and that value incremented. Internal breakpoints
2077 do not set the internal var bpnum. */
2079 set_breakpoint_number (int internal, struct breakpoint *b)
2082 b->number = internal_breakpoint_number--;
2085 set_breakpoint_count (breakpoint_count + 1);
2086 b->number = breakpoint_count;
2090 static struct breakpoint *
2091 create_internal_breakpoint (struct gdbarch *gdbarch,
2092 CORE_ADDR address, enum bptype type)
2094 struct symtab_and_line sal;
2095 struct breakpoint *b;
2097 init_sal (&sal); /* initialize to zeroes */
2100 sal.section = find_pc_overlay (sal.pc);
2101 sal.pspace = current_program_space;
2103 b = set_raw_breakpoint (gdbarch, sal, type);
2104 b->number = internal_breakpoint_number--;
2105 b->disposition = disp_donttouch;
2111 create_overlay_event_breakpoint (char *func_name)
2113 struct objfile *objfile;
2115 ALL_OBJFILES (objfile)
2117 struct breakpoint *b;
2118 struct minimal_symbol *m;
2120 m = lookup_minimal_symbol_text (func_name, objfile);
2124 b = create_internal_breakpoint (get_objfile_arch (objfile),
2125 SYMBOL_VALUE_ADDRESS (m),
2127 b->addr_string = xstrdup (func_name);
2129 if (overlay_debugging == ovly_auto)
2131 b->enable_state = bp_enabled;
2132 overlay_events_enabled = 1;
2136 b->enable_state = bp_disabled;
2137 overlay_events_enabled = 0;
2140 update_global_location_list (1);
2144 create_longjmp_master_breakpoint (char *func_name)
2146 struct program_space *pspace;
2147 struct objfile *objfile;
2148 struct cleanup *old_chain;
2150 old_chain = save_current_program_space ();
2152 ALL_PSPACES (pspace)
2153 ALL_OBJFILES (objfile)
2155 struct breakpoint *b;
2156 struct minimal_symbol *m;
2158 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2161 set_current_program_space (pspace);
2163 m = lookup_minimal_symbol_text (func_name, objfile);
2167 b = create_internal_breakpoint (get_objfile_arch (objfile),
2168 SYMBOL_VALUE_ADDRESS (m),
2170 b->addr_string = xstrdup (func_name);
2171 b->enable_state = bp_disabled;
2173 update_global_location_list (1);
2175 do_cleanups (old_chain);
2178 /* Create a master std::terminate breakpoint. The actual function
2179 looked for is named FUNC_NAME. */
2181 create_std_terminate_master_breakpoint (const char *func_name)
2183 struct program_space *pspace;
2184 struct objfile *objfile;
2185 struct cleanup *old_chain;
2187 old_chain = save_current_program_space ();
2189 ALL_PSPACES (pspace)
2190 ALL_OBJFILES (objfile)
2192 struct breakpoint *b;
2193 struct minimal_symbol *m;
2195 set_current_program_space (pspace);
2197 m = lookup_minimal_symbol (func_name, NULL, objfile);
2198 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2199 && MSYMBOL_TYPE (m) != mst_file_text))
2202 b = create_internal_breakpoint (get_objfile_arch (objfile),
2203 SYMBOL_VALUE_ADDRESS (m),
2204 bp_std_terminate_master);
2205 b->addr_string = xstrdup (func_name);
2206 b->enable_state = bp_disabled;
2208 update_global_location_list (1);
2210 do_cleanups (old_chain);
2213 /* Install a master breakpoint on the unwinder's debug hook. */
2216 create_exception_master_breakpoint (void)
2218 struct objfile *objfile;
2220 ALL_OBJFILES (objfile)
2222 struct minimal_symbol *debug_hook;
2224 debug_hook = lookup_minimal_symbol ("_Unwind_DebugHook", NULL, objfile);
2225 if (debug_hook != NULL)
2227 struct breakpoint *b;
2228 CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (debug_hook);
2229 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2231 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2233 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master);
2234 b->addr_string = xstrdup ("_Unwind_DebugHook");
2235 b->enable_state = bp_disabled;
2239 update_global_location_list (1);
2243 update_breakpoints_after_exec (void)
2245 struct breakpoint *b, *b_tmp;
2246 struct bp_location *bploc, **bplocp_tmp;
2248 /* We're about to delete breakpoints from GDB's lists. If the
2249 INSERTED flag is true, GDB will try to lift the breakpoints by
2250 writing the breakpoints' "shadow contents" back into memory. The
2251 "shadow contents" are NOT valid after an exec, so GDB should not
2252 do that. Instead, the target is responsible from marking
2253 breakpoints out as soon as it detects an exec. We don't do that
2254 here instead, because there may be other attempts to delete
2255 breakpoints after detecting an exec and before reaching here. */
2256 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2257 if (bploc->pspace == current_program_space)
2258 gdb_assert (!bploc->inserted);
2260 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2262 if (b->pspace != current_program_space)
2265 /* Solib breakpoints must be explicitly reset after an exec(). */
2266 if (b->type == bp_shlib_event)
2268 delete_breakpoint (b);
2272 /* JIT breakpoints must be explicitly reset after an exec(). */
2273 if (b->type == bp_jit_event)
2275 delete_breakpoint (b);
2279 /* Thread event breakpoints must be set anew after an exec(),
2280 as must overlay event and longjmp master breakpoints. */
2281 if (b->type == bp_thread_event || b->type == bp_overlay_event
2282 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2283 || b->type == bp_exception_master)
2285 delete_breakpoint (b);
2289 /* Step-resume breakpoints are meaningless after an exec(). */
2290 if (b->type == bp_step_resume)
2292 delete_breakpoint (b);
2296 /* Longjmp and longjmp-resume breakpoints are also meaningless
2298 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2299 || b->type == bp_exception || b->type == bp_exception_resume)
2301 delete_breakpoint (b);
2305 if (b->type == bp_catchpoint)
2307 /* For now, none of the bp_catchpoint breakpoints need to
2308 do anything at this point. In the future, if some of
2309 the catchpoints need to something, we will need to add
2310 a new method, and call this method from here. */
2314 /* bp_finish is a special case. The only way we ought to be able
2315 to see one of these when an exec() has happened, is if the user
2316 caught a vfork, and then said "finish". Ordinarily a finish just
2317 carries them to the call-site of the current callee, by setting
2318 a temporary bp there and resuming. But in this case, the finish
2319 will carry them entirely through the vfork & exec.
2321 We don't want to allow a bp_finish to remain inserted now. But
2322 we can't safely delete it, 'cause finish_command has a handle to
2323 the bp on a bpstat, and will later want to delete it. There's a
2324 chance (and I've seen it happen) that if we delete the bp_finish
2325 here, that its storage will get reused by the time finish_command
2326 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2327 We really must allow finish_command to delete a bp_finish.
2329 In the absense of a general solution for the "how do we know
2330 it's safe to delete something others may have handles to?"
2331 problem, what we'll do here is just uninsert the bp_finish, and
2332 let finish_command delete it.
2334 (We know the bp_finish is "doomed" in the sense that it's
2335 momentary, and will be deleted as soon as finish_command sees
2336 the inferior stopped. So it doesn't matter that the bp's
2337 address is probably bogus in the new a.out, unlike e.g., the
2338 solib breakpoints.) */
2340 if (b->type == bp_finish)
2345 /* Without a symbolic address, we have little hope of the
2346 pre-exec() address meaning the same thing in the post-exec()
2348 if (b->addr_string == NULL)
2350 delete_breakpoint (b);
2354 /* FIXME what about longjmp breakpoints? Re-create them here? */
2355 create_overlay_event_breakpoint ("_ovly_debug_event");
2356 create_longjmp_master_breakpoint ("longjmp");
2357 create_longjmp_master_breakpoint ("_longjmp");
2358 create_longjmp_master_breakpoint ("siglongjmp");
2359 create_longjmp_master_breakpoint ("_siglongjmp");
2360 create_std_terminate_master_breakpoint ("std::terminate()");
2361 create_exception_master_breakpoint ();
2365 detach_breakpoints (int pid)
2367 struct bp_location *bl, **blp_tmp;
2369 struct cleanup *old_chain = save_inferior_ptid ();
2370 struct inferior *inf = current_inferior ();
2372 if (pid == PIDGET (inferior_ptid))
2373 error (_("Cannot detach breakpoints of inferior_ptid"));
2375 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2376 inferior_ptid = pid_to_ptid (pid);
2377 ALL_BP_LOCATIONS (bl, blp_tmp)
2379 if (bl->pspace != inf->pspace)
2383 val |= remove_breakpoint_1 (bl, mark_inserted);
2386 /* Detach single-step breakpoints as well. */
2387 detach_single_step_breakpoints ();
2389 do_cleanups (old_chain);
2393 /* Remove the breakpoint location BL from the current address space.
2394 Note that this is used to detach breakpoints from a child fork.
2395 When we get here, the child isn't in the inferior list, and neither
2396 do we have objects to represent its address space --- we should
2397 *not* look at bl->pspace->aspace here. */
2400 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2404 /* BL is never in moribund_locations by our callers. */
2405 gdb_assert (bl->owner != NULL);
2407 if (bl->owner->enable_state == bp_permanent)
2408 /* Permanent breakpoints cannot be inserted or removed. */
2411 /* The type of none suggests that owner is actually deleted.
2412 This should not ever happen. */
2413 gdb_assert (bl->owner->type != bp_none);
2415 if (bl->loc_type == bp_loc_software_breakpoint
2416 || bl->loc_type == bp_loc_hardware_breakpoint)
2418 /* "Normal" instruction breakpoint: either the standard
2419 trap-instruction bp (bp_breakpoint), or a
2420 bp_hardware_breakpoint. */
2422 /* First check to see if we have to handle an overlay. */
2423 if (overlay_debugging == ovly_off
2424 || bl->section == NULL
2425 || !(section_is_overlay (bl->section)))
2427 /* No overlay handling: just remove the breakpoint. */
2429 if (bl->loc_type == bp_loc_hardware_breakpoint)
2430 val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
2432 val = target_remove_breakpoint (bl->gdbarch, &bl->target_info);
2436 /* This breakpoint is in an overlay section.
2437 Did we set a breakpoint at the LMA? */
2438 if (!overlay_events_enabled)
2440 /* Yes -- overlay event support is not active, so we
2441 should have set a breakpoint at the LMA. Remove it.
2443 /* Ignore any failures: if the LMA is in ROM, we will
2444 have already warned when we failed to insert it. */
2445 if (bl->loc_type == bp_loc_hardware_breakpoint)
2446 target_remove_hw_breakpoint (bl->gdbarch,
2447 &bl->overlay_target_info);
2449 target_remove_breakpoint (bl->gdbarch,
2450 &bl->overlay_target_info);
2452 /* Did we set a breakpoint at the VMA?
2453 If so, we will have marked the breakpoint 'inserted'. */
2456 /* Yes -- remove it. Previously we did not bother to
2457 remove the breakpoint if the section had been
2458 unmapped, but let's not rely on that being safe. We
2459 don't know what the overlay manager might do. */
2460 if (bl->loc_type == bp_loc_hardware_breakpoint)
2461 val = target_remove_hw_breakpoint (bl->gdbarch,
2464 /* However, we should remove *software* breakpoints only
2465 if the section is still mapped, or else we overwrite
2466 wrong code with the saved shadow contents. */
2467 else if (section_is_mapped (bl->section))
2468 val = target_remove_breakpoint (bl->gdbarch,
2475 /* No -- not inserted, so no need to remove. No error. */
2480 /* In some cases, we might not be able to remove a breakpoint
2481 in a shared library that has already been removed, but we
2482 have not yet processed the shlib unload event. */
2483 if (val && solib_name_from_address (bl->pspace, bl->address))
2488 bl->inserted = (is == mark_inserted);
2490 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2492 bl->inserted = (is == mark_inserted);
2493 val = target_remove_watchpoint (bl->address, bl->length,
2494 bl->watchpoint_type, bl->owner->cond_exp);
2496 /* Failure to remove any of the hardware watchpoints comes here. */
2497 if ((is == mark_uninserted) && (bl->inserted))
2498 warning (_("Could not remove hardware watchpoint %d."),
2501 else if (bl->owner->type == bp_catchpoint
2502 && breakpoint_enabled (bl->owner)
2505 gdb_assert (bl->owner->ops != NULL && bl->owner->ops->remove != NULL);
2507 val = bl->owner->ops->remove (bl->owner);
2510 bl->inserted = (is == mark_inserted);
2517 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2520 struct cleanup *old_chain;
2522 /* BL is never in moribund_locations by our callers. */
2523 gdb_assert (bl->owner != NULL);
2525 if (bl->owner->enable_state == bp_permanent)
2526 /* Permanent breakpoints cannot be inserted or removed. */
2529 /* The type of none suggests that owner is actually deleted.
2530 This should not ever happen. */
2531 gdb_assert (bl->owner->type != bp_none);
2533 old_chain = save_current_space_and_thread ();
2535 switch_to_program_space_and_thread (bl->pspace);
2537 ret = remove_breakpoint_1 (bl, is);
2539 do_cleanups (old_chain);
2543 /* Clear the "inserted" flag in all breakpoints. */
2546 mark_breakpoints_out (void)
2548 struct bp_location *bl, **blp_tmp;
2550 ALL_BP_LOCATIONS (bl, blp_tmp)
2551 if (bl->pspace == current_program_space)
2555 /* Clear the "inserted" flag in all breakpoints and delete any
2556 breakpoints which should go away between runs of the program.
2558 Plus other such housekeeping that has to be done for breakpoints
2561 Note: this function gets called at the end of a run (by
2562 generic_mourn_inferior) and when a run begins (by
2563 init_wait_for_inferior). */
2568 breakpoint_init_inferior (enum inf_context context)
2570 struct breakpoint *b, *b_tmp;
2571 struct bp_location *bl, **blp_tmp;
2573 struct program_space *pspace = current_program_space;
2575 /* If breakpoint locations are shared across processes, then there's
2577 if (gdbarch_has_global_breakpoints (target_gdbarch))
2580 ALL_BP_LOCATIONS (bl, blp_tmp)
2582 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2583 if (bl->pspace == pspace
2584 && bl->owner->enable_state != bp_permanent)
2588 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2590 if (b->loc && b->loc->pspace != pspace)
2597 /* If the call dummy breakpoint is at the entry point it will
2598 cause problems when the inferior is rerun, so we better get
2601 case bp_watchpoint_scope:
2603 /* Also get rid of scope breakpoints. */
2605 case bp_shlib_event:
2607 /* Also remove solib event breakpoints. Their addresses may
2608 have changed since the last time we ran the program.
2609 Actually we may now be debugging against different target;
2610 and so the solib backend that installed this breakpoint may
2611 not be used in by the target. E.g.,
2613 (gdb) file prog-linux
2614 (gdb) run # native linux target
2617 (gdb) file prog-win.exe
2618 (gdb) tar rem :9999 # remote Windows gdbserver.
2621 delete_breakpoint (b);
2625 case bp_hardware_watchpoint:
2626 case bp_read_watchpoint:
2627 case bp_access_watchpoint:
2629 /* Likewise for watchpoints on local expressions. */
2630 if (b->exp_valid_block != NULL)
2631 delete_breakpoint (b);
2632 else if (context == inf_starting)
2634 /* Reset val field to force reread of starting value
2635 in insert_breakpoints. */
2637 value_free (b->val);
2647 /* Get rid of the moribund locations. */
2648 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2649 decref_bp_location (&bl);
2650 VEC_free (bp_location_p, moribund_locations);
2653 /* These functions concern about actual breakpoints inserted in the
2654 target --- to e.g. check if we need to do decr_pc adjustment or if
2655 we need to hop over the bkpt --- so we check for address space
2656 match, not program space. */
2658 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2659 exists at PC. It returns ordinary_breakpoint_here if it's an
2660 ordinary breakpoint, or permanent_breakpoint_here if it's a
2661 permanent breakpoint.
2662 - When continuing from a location with an ordinary breakpoint, we
2663 actually single step once before calling insert_breakpoints.
2664 - When continuing from a localion with a permanent breakpoint, we
2665 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2666 the target, to advance the PC past the breakpoint. */
2668 enum breakpoint_here
2669 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2671 struct bp_location *bl, **blp_tmp;
2672 int any_breakpoint_here = 0;
2674 ALL_BP_LOCATIONS (bl, blp_tmp)
2676 if (bl->loc_type != bp_loc_software_breakpoint
2677 && bl->loc_type != bp_loc_hardware_breakpoint)
2680 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2681 if ((breakpoint_enabled (bl->owner)
2682 || bl->owner->enable_state == bp_permanent)
2683 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2686 if (overlay_debugging
2687 && section_is_overlay (bl->section)
2688 && !section_is_mapped (bl->section))
2689 continue; /* unmapped overlay -- can't be a match */
2690 else if (bl->owner->enable_state == bp_permanent)
2691 return permanent_breakpoint_here;
2693 any_breakpoint_here = 1;
2697 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2700 /* Return true if there's a moribund breakpoint at PC. */
2703 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2705 struct bp_location *loc;
2708 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2709 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2716 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2717 inserted using regular breakpoint_chain / bp_location array mechanism.
2718 This does not check for single-step breakpoints, which are
2719 inserted and removed using direct target manipulation. */
2722 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2724 struct bp_location *bl, **blp_tmp;
2726 ALL_BP_LOCATIONS (bl, blp_tmp)
2728 if (bl->loc_type != bp_loc_software_breakpoint
2729 && bl->loc_type != bp_loc_hardware_breakpoint)
2733 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2736 if (overlay_debugging
2737 && section_is_overlay (bl->section)
2738 && !section_is_mapped (bl->section))
2739 continue; /* unmapped overlay -- can't be a match */
2747 /* Returns non-zero iff there's either regular breakpoint
2748 or a single step breakpoint inserted at PC. */
2751 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2753 if (regular_breakpoint_inserted_here_p (aspace, pc))
2756 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2762 /* This function returns non-zero iff there is a software breakpoint
2766 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2768 struct bp_location *bl, **blp_tmp;
2770 ALL_BP_LOCATIONS (bl, blp_tmp)
2772 if (bl->loc_type != bp_loc_software_breakpoint)
2776 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2779 if (overlay_debugging
2780 && section_is_overlay (bl->section)
2781 && !section_is_mapped (bl->section))
2782 continue; /* unmapped overlay -- can't be a match */
2788 /* Also check for software single-step breakpoints. */
2789 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2796 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2797 CORE_ADDR addr, ULONGEST len)
2799 struct breakpoint *bpt;
2801 ALL_BREAKPOINTS (bpt)
2803 struct bp_location *loc;
2805 if (bpt->type != bp_hardware_watchpoint
2806 && bpt->type != bp_access_watchpoint)
2809 if (!breakpoint_enabled (bpt))
2812 for (loc = bpt->loc; loc; loc = loc->next)
2813 if (loc->pspace->aspace == aspace && loc->inserted)
2817 /* Check for intersection. */
2818 l = max (loc->address, addr);
2819 h = min (loc->address + loc->length, addr + len);
2827 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2828 PC is valid for process/thread PTID. */
2831 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2834 struct bp_location *bl, **blp_tmp;
2835 /* The thread and task IDs associated to PTID, computed lazily. */
2839 ALL_BP_LOCATIONS (bl, blp_tmp)
2841 if (bl->loc_type != bp_loc_software_breakpoint
2842 && bl->loc_type != bp_loc_hardware_breakpoint)
2845 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2846 if (!breakpoint_enabled (bl->owner)
2847 && bl->owner->enable_state != bp_permanent)
2850 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
2854 if (bl->owner->thread != -1)
2856 /* This is a thread-specific breakpoint. Check that ptid
2857 matches that thread. If thread hasn't been computed yet,
2858 it is now time to do so. */
2860 thread = pid_to_thread_id (ptid);
2861 if (bl->owner->thread != thread)
2865 if (bl->owner->task != 0)
2867 /* This is a task-specific breakpoint. Check that ptid
2868 matches that task. If task hasn't been computed yet,
2869 it is now time to do so. */
2871 task = ada_get_task_number (ptid);
2872 if (bl->owner->task != task)
2876 if (overlay_debugging
2877 && section_is_overlay (bl->section)
2878 && !section_is_mapped (bl->section))
2879 continue; /* unmapped overlay -- can't be a match */
2888 /* bpstat stuff. External routines' interfaces are documented
2892 ep_is_catchpoint (struct breakpoint *ep)
2894 return (ep->type == bp_catchpoint);
2897 /* Frees any storage that is part of a bpstat. Does not walk the
2901 bpstat_free (bpstat bs)
2903 if (bs->old_val != NULL)
2904 value_free (bs->old_val);
2905 decref_counted_command_line (&bs->commands);
2906 decref_bp_location (&bs->bp_location_at);
2910 /* Clear a bpstat so that it says we are not at any breakpoint.
2911 Also free any storage that is part of a bpstat. */
2914 bpstat_clear (bpstat *bsp)
2931 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2932 is part of the bpstat is copied as well. */
2935 bpstat_copy (bpstat bs)
2939 bpstat retval = NULL;
2944 for (; bs != NULL; bs = bs->next)
2946 tmp = (bpstat) xmalloc (sizeof (*tmp));
2947 memcpy (tmp, bs, sizeof (*tmp));
2948 incref_counted_command_line (tmp->commands);
2949 incref_bp_location (tmp->bp_location_at);
2950 if (bs->old_val != NULL)
2952 tmp->old_val = value_copy (bs->old_val);
2953 release_value (tmp->old_val);
2957 /* This is the first thing in the chain. */
2967 /* Find the bpstat associated with this breakpoint */
2970 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2975 for (; bsp != NULL; bsp = bsp->next)
2977 if (bsp->breakpoint_at == breakpoint)
2983 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2984 at. *BSP upon return is a bpstat which points to the remaining
2985 breakpoints stopped at (but which is not guaranteed to be good for
2986 anything but further calls to bpstat_num).
2987 Return 0 if passed a bpstat which does not indicate any breakpoints.
2988 Return -1 if stopped at a breakpoint that has been deleted since
2990 Return 1 otherwise. */
2993 bpstat_num (bpstat *bsp, int *num)
2995 struct breakpoint *b;
2998 return 0; /* No more breakpoint values */
3000 /* We assume we'll never have several bpstats that
3001 correspond to a single breakpoint -- otherwise,
3002 this function might return the same number more
3003 than once and this will look ugly. */
3004 b = (*bsp)->breakpoint_at;
3005 *bsp = (*bsp)->next;
3007 return -1; /* breakpoint that's been deleted since */
3009 *num = b->number; /* We have its number */
3013 /* Modify BS so that the actions will not be performed. */
3016 bpstat_clear_actions (bpstat bs)
3018 for (; bs != NULL; bs = bs->next)
3020 decref_counted_command_line (&bs->commands);
3021 bs->commands_left = NULL;
3022 if (bs->old_val != NULL)
3024 value_free (bs->old_val);
3030 /* Called when a command is about to proceed the inferior. */
3033 breakpoint_about_to_proceed (void)
3035 if (!ptid_equal (inferior_ptid, null_ptid))
3037 struct thread_info *tp = inferior_thread ();
3039 /* Allow inferior function calls in breakpoint commands to not
3040 interrupt the command list. When the call finishes
3041 successfully, the inferior will be standing at the same
3042 breakpoint as if nothing happened. */
3043 if (tp->control.in_infcall)
3047 breakpoint_proceeded = 1;
3050 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3052 cleanup_executing_breakpoints (void *ignore)
3054 executing_breakpoint_commands = 0;
3057 /* Execute all the commands associated with all the breakpoints at this
3058 location. Any of these commands could cause the process to proceed
3059 beyond this point, etc. We look out for such changes by checking
3060 the global "breakpoint_proceeded" after each command.
3062 Returns true if a breakpoint command resumed the inferior. In that
3063 case, it is the caller's responsibility to recall it again with the
3064 bpstat of the current thread. */
3067 bpstat_do_actions_1 (bpstat *bsp)
3070 struct cleanup *old_chain;
3073 /* Avoid endless recursion if a `source' command is contained
3075 if (executing_breakpoint_commands)
3078 executing_breakpoint_commands = 1;
3079 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3081 /* This pointer will iterate over the list of bpstat's. */
3084 breakpoint_proceeded = 0;
3085 for (; bs != NULL; bs = bs->next)
3087 struct counted_command_line *ccmd;
3088 struct command_line *cmd;
3089 struct cleanup *this_cmd_tree_chain;
3091 /* Take ownership of the BSP's command tree, if it has one.
3093 The command tree could legitimately contain commands like
3094 'step' and 'next', which call clear_proceed_status, which
3095 frees stop_bpstat's command tree. To make sure this doesn't
3096 free the tree we're executing out from under us, we need to
3097 take ownership of the tree ourselves. Since a given bpstat's
3098 commands are only executed once, we don't need to copy it; we
3099 can clear the pointer in the bpstat, and make sure we free
3100 the tree when we're done. */
3101 ccmd = bs->commands;
3102 bs->commands = NULL;
3104 = make_cleanup_decref_counted_command_line (&ccmd);
3105 cmd = bs->commands_left;
3106 bs->commands_left = NULL;
3110 execute_control_command (cmd);
3112 if (breakpoint_proceeded)
3118 /* We can free this command tree now. */
3119 do_cleanups (this_cmd_tree_chain);
3121 if (breakpoint_proceeded)
3123 if (target_can_async_p ())
3124 /* If we are in async mode, then the target might be still
3125 running, not stopped at any breakpoint, so nothing for
3126 us to do here -- just return to the event loop. */
3129 /* In sync mode, when execute_control_command returns
3130 we're already standing on the next breakpoint.
3131 Breakpoint commands for that stop were not run, since
3132 execute_command does not run breakpoint commands --
3133 only command_line_handler does, but that one is not
3134 involved in execution of breakpoint commands. So, we
3135 can now execute breakpoint commands. It should be
3136 noted that making execute_command do bpstat actions is
3137 not an option -- in this case we'll have recursive
3138 invocation of bpstat for each breakpoint with a
3139 command, and can easily blow up GDB stack. Instead, we
3140 return true, which will trigger the caller to recall us
3141 with the new stop_bpstat. */
3146 do_cleanups (old_chain);
3151 bpstat_do_actions (void)
3153 /* Do any commands attached to breakpoint we are stopped at. */
3154 while (!ptid_equal (inferior_ptid, null_ptid)
3155 && target_has_execution
3156 && !is_exited (inferior_ptid)
3157 && !is_executing (inferior_ptid))
3158 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3159 and only return when it is stopped at the next breakpoint, we
3160 keep doing breakpoint actions until it returns false to
3161 indicate the inferior was not resumed. */
3162 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3166 /* Print out the (old or new) value associated with a watchpoint. */
3169 watchpoint_value_print (struct value *val, struct ui_file *stream)
3172 fprintf_unfiltered (stream, _("<unreadable>"));
3175 struct value_print_options opts;
3176 get_user_print_options (&opts);
3177 value_print (val, stream, &opts);
3181 /* This is the normal print function for a bpstat. In the future,
3182 much of this logic could (should?) be moved to bpstat_stop_status,
3183 by having it set different print_it values.
3185 Current scheme: When we stop, bpstat_print() is called. It loops
3186 through the bpstat list of things causing this stop, calling the
3187 print_bp_stop_message function on each one. The behavior of the
3188 print_bp_stop_message function depends on the print_it field of
3189 bpstat. If such field so indicates, call this function here.
3191 Return values from this routine (ultimately used by bpstat_print()
3192 and normal_stop() to decide what to do):
3193 PRINT_NOTHING: Means we already printed all we needed to print,
3194 don't print anything else.
3195 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3196 that something to be followed by a location.
3197 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3198 that something to be followed by a location.
3199 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3202 static enum print_stop_action
3203 print_it_typical (bpstat bs)
3205 struct cleanup *old_chain;
3206 struct breakpoint *b;
3207 const struct bp_location *bl;
3208 struct ui_stream *stb;
3210 enum print_stop_action result;
3212 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3213 which has since been deleted. */
3214 if (bs->breakpoint_at == NULL)
3215 return PRINT_UNKNOWN;
3217 gdb_assert (bs->bp_location_at != NULL);
3219 bl = bs->bp_location_at;
3220 b = bs->breakpoint_at;
3222 stb = ui_out_stream_new (uiout);
3223 old_chain = make_cleanup_ui_out_stream_delete (stb);
3228 case bp_hardware_breakpoint:
3229 bp_temp = b->disposition == disp_del;
3230 if (bl->address != bl->requested_address)
3231 breakpoint_adjustment_warning (bl->requested_address,
3234 annotate_breakpoint (b->number);
3236 ui_out_text (uiout, "\nTemporary breakpoint ");
3238 ui_out_text (uiout, "\nBreakpoint ");
3239 if (ui_out_is_mi_like_p (uiout))
3241 ui_out_field_string (uiout, "reason",
3242 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3243 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3245 ui_out_field_int (uiout, "bkptno", b->number);
3246 ui_out_text (uiout, ", ");
3247 result = PRINT_SRC_AND_LOC;
3250 case bp_shlib_event:
3251 /* Did we stop because the user set the stop_on_solib_events
3252 variable? (If so, we report this as a generic, "Stopped due
3253 to shlib event" message.) */
3254 printf_filtered (_("Stopped due to shared library event\n"));
3255 result = PRINT_NOTHING;
3258 case bp_thread_event:
3259 /* Not sure how we will get here.
3260 GDB should not stop for these breakpoints. */
3261 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3262 result = PRINT_NOTHING;
3265 case bp_overlay_event:
3266 /* By analogy with the thread event, GDB should not stop for these. */
3267 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3268 result = PRINT_NOTHING;
3271 case bp_longjmp_master:
3272 /* These should never be enabled. */
3273 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3274 result = PRINT_NOTHING;
3277 case bp_std_terminate_master:
3278 /* These should never be enabled. */
3279 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3280 result = PRINT_NOTHING;
3283 case bp_exception_master:
3284 /* These should never be enabled. */
3285 printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
3286 result = PRINT_NOTHING;
3290 case bp_hardware_watchpoint:
3291 annotate_watchpoint (b->number);
3292 if (ui_out_is_mi_like_p (uiout))
3295 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3297 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3298 ui_out_text (uiout, "\nOld value = ");
3299 watchpoint_value_print (bs->old_val, stb->stream);
3300 ui_out_field_stream (uiout, "old", stb);
3301 ui_out_text (uiout, "\nNew value = ");
3302 watchpoint_value_print (b->val, stb->stream);
3303 ui_out_field_stream (uiout, "new", stb);
3304 ui_out_text (uiout, "\n");
3305 /* More than one watchpoint may have been triggered. */
3306 result = PRINT_UNKNOWN;
3309 case bp_read_watchpoint:
3310 if (ui_out_is_mi_like_p (uiout))
3313 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3315 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3316 ui_out_text (uiout, "\nValue = ");
3317 watchpoint_value_print (b->val, stb->stream);
3318 ui_out_field_stream (uiout, "value", stb);
3319 ui_out_text (uiout, "\n");
3320 result = PRINT_UNKNOWN;
3323 case bp_access_watchpoint:
3324 if (bs->old_val != NULL)
3326 annotate_watchpoint (b->number);
3327 if (ui_out_is_mi_like_p (uiout))
3330 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3332 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3333 ui_out_text (uiout, "\nOld value = ");
3334 watchpoint_value_print (bs->old_val, stb->stream);
3335 ui_out_field_stream (uiout, "old", stb);
3336 ui_out_text (uiout, "\nNew value = ");
3341 if (ui_out_is_mi_like_p (uiout))
3344 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3345 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3346 ui_out_text (uiout, "\nValue = ");
3348 watchpoint_value_print (b->val, stb->stream);
3349 ui_out_field_stream (uiout, "new", stb);
3350 ui_out_text (uiout, "\n");
3351 result = PRINT_UNKNOWN;
3354 /* Fall through, we don't deal with these types of breakpoints
3358 if (ui_out_is_mi_like_p (uiout))
3361 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3362 result = PRINT_UNKNOWN;
3366 if (ui_out_is_mi_like_p (uiout))
3369 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3370 result = PRINT_UNKNOWN;
3375 case bp_longjmp_resume:
3377 case bp_exception_resume:
3378 case bp_step_resume:
3379 case bp_watchpoint_scope:
3381 case bp_std_terminate:
3383 case bp_fast_tracepoint:
3386 result = PRINT_UNKNOWN;
3390 do_cleanups (old_chain);
3394 /* Generic routine for printing messages indicating why we
3395 stopped. The behavior of this function depends on the value
3396 'print_it' in the bpstat structure. Under some circumstances we
3397 may decide not to print anything here and delegate the task to
3400 static enum print_stop_action
3401 print_bp_stop_message (bpstat bs)
3403 switch (bs->print_it)
3406 /* Nothing should be printed for this bpstat entry. */
3407 return PRINT_UNKNOWN;
3411 /* We still want to print the frame, but we already printed the
3412 relevant messages. */
3413 return PRINT_SRC_AND_LOC;
3416 case print_it_normal:
3418 struct breakpoint *b = bs->breakpoint_at;
3420 /* Normal case. Call the breakpoint's print_it method, or
3421 print_it_typical. */
3422 /* FIXME: how breakpoint can ever be NULL here? */
3423 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3424 return b->ops->print_it (b);
3426 return print_it_typical (bs);
3431 internal_error (__FILE__, __LINE__,
3432 _("print_bp_stop_message: unrecognized enum value"));
3437 /* Print a message indicating what happened. This is called from
3438 normal_stop(). The input to this routine is the head of the bpstat
3439 list - a list of the eventpoints that caused this stop. This
3440 routine calls the generic print routine for printing a message
3441 about reasons for stopping. This will print (for example) the
3442 "Breakpoint n," part of the output. The return value of this
3445 PRINT_UNKNOWN: Means we printed nothing
3446 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3447 code to print the location. An example is
3448 "Breakpoint 1, " which should be followed by
3450 PRINT_SRC_ONLY: Means we printed something, but there is no need
3451 to also print the location part of the message.
3452 An example is the catch/throw messages, which
3453 don't require a location appended to the end.
3454 PRINT_NOTHING: We have done some printing and we don't need any
3455 further info to be printed.*/
3457 enum print_stop_action
3458 bpstat_print (bpstat bs)
3462 /* Maybe another breakpoint in the chain caused us to stop.
3463 (Currently all watchpoints go on the bpstat whether hit or not.
3464 That probably could (should) be changed, provided care is taken
3465 with respect to bpstat_explains_signal). */
3466 for (; bs; bs = bs->next)
3468 val = print_bp_stop_message (bs);
3469 if (val == PRINT_SRC_ONLY
3470 || val == PRINT_SRC_AND_LOC
3471 || val == PRINT_NOTHING)
3475 /* We reached the end of the chain, or we got a null BS to start
3476 with and nothing was printed. */
3477 return PRINT_UNKNOWN;
3480 /* Evaluate the expression EXP and return 1 if value is zero.
3481 This is used inside a catch_errors to evaluate the breakpoint condition.
3482 The argument is a "struct expression *" that has been cast to char * to
3483 make it pass through catch_errors. */
3486 breakpoint_cond_eval (void *exp)
3488 struct value *mark = value_mark ();
3489 int i = !value_true (evaluate_expression ((struct expression *) exp));
3491 value_free_to_mark (mark);
3495 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3498 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3502 bs = (bpstat) xmalloc (sizeof (*bs));
3504 **bs_link_pointer = bs;
3505 *bs_link_pointer = &bs->next;
3506 bs->breakpoint_at = bl->owner;
3507 bs->bp_location_at = bl;
3508 incref_bp_location (bl);
3509 /* If the condition is false, etc., don't do the commands. */
3510 bs->commands = NULL;
3511 bs->commands_left = NULL;
3513 bs->print_it = print_it_normal;
3517 /* The target has stopped with waitstatus WS. Check if any hardware
3518 watchpoints have triggered, according to the target. */
3521 watchpoints_triggered (struct target_waitstatus *ws)
3523 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3525 struct breakpoint *b;
3527 if (!stopped_by_watchpoint)
3529 /* We were not stopped by a watchpoint. Mark all watchpoints
3530 as not triggered. */
3532 if (is_hardware_watchpoint (b))
3533 b->watchpoint_triggered = watch_triggered_no;
3538 if (!target_stopped_data_address (¤t_target, &addr))
3540 /* We were stopped by a watchpoint, but we don't know where.
3541 Mark all watchpoints as unknown. */
3543 if (is_hardware_watchpoint (b))
3544 b->watchpoint_triggered = watch_triggered_unknown;
3546 return stopped_by_watchpoint;
3549 /* The target could report the data address. Mark watchpoints
3550 affected by this data address as triggered, and all others as not
3554 if (is_hardware_watchpoint (b))
3556 struct bp_location *loc;
3558 b->watchpoint_triggered = watch_triggered_no;
3559 for (loc = b->loc; loc; loc = loc->next)
3560 /* Exact match not required. Within range is
3562 if (target_watchpoint_addr_within_range (¤t_target,
3566 b->watchpoint_triggered = watch_triggered_yes;
3574 /* Possible return values for watchpoint_check (this can't be an enum
3575 because of check_errors). */
3576 /* The watchpoint has been deleted. */
3577 #define WP_DELETED 1
3578 /* The value has changed. */
3579 #define WP_VALUE_CHANGED 2
3580 /* The value has not changed. */
3581 #define WP_VALUE_NOT_CHANGED 3
3582 /* Ignore this watchpoint, no matter if the value changed or not. */
3585 #define BP_TEMPFLAG 1
3586 #define BP_HARDWAREFLAG 2
3588 /* Evaluate watchpoint condition expression and check if its value changed.
3590 P should be a pointer to struct bpstat, but is defined as a void *
3591 in order for this function to be usable with catch_errors. */
3594 watchpoint_check (void *p)
3596 bpstat bs = (bpstat) p;
3597 struct breakpoint *b;
3598 struct frame_info *fr;
3599 int within_current_scope;
3601 /* BS is built from an existing struct breakpoint. */
3602 gdb_assert (bs->breakpoint_at != NULL);
3603 b = bs->breakpoint_at;
3605 /* If this is a local watchpoint, we only want to check if the
3606 watchpoint frame is in scope if the current thread is the thread
3607 that was used to create the watchpoint. */
3608 if (!watchpoint_in_thread_scope (b))
3611 if (b->exp_valid_block == NULL)
3612 within_current_scope = 1;
3615 struct frame_info *frame = get_current_frame ();
3616 struct gdbarch *frame_arch = get_frame_arch (frame);
3617 CORE_ADDR frame_pc = get_frame_pc (frame);
3619 /* in_function_epilogue_p() returns a non-zero value if we're still
3620 in the function but the stack frame has already been invalidated.
3621 Since we can't rely on the values of local variables after the
3622 stack has been destroyed, we are treating the watchpoint in that
3623 state as `not changed' without further checking. Don't mark
3624 watchpoints as changed if the current frame is in an epilogue -
3625 even if they are in some other frame, our view of the stack
3626 is likely to be wrong and frame_find_by_id could error out. */
3627 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3630 fr = frame_find_by_id (b->watchpoint_frame);
3631 within_current_scope = (fr != NULL);
3633 /* If we've gotten confused in the unwinder, we might have
3634 returned a frame that can't describe this variable. */
3635 if (within_current_scope)
3637 struct symbol *function;
3639 function = get_frame_function (fr);
3640 if (function == NULL
3641 || !contained_in (b->exp_valid_block,
3642 SYMBOL_BLOCK_VALUE (function)))
3643 within_current_scope = 0;
3646 if (within_current_scope)
3647 /* If we end up stopping, the current frame will get selected
3648 in normal_stop. So this call to select_frame won't affect
3653 if (within_current_scope)
3655 /* We use value_{,free_to_}mark because it could be a
3656 *long* time before we return to the command level and
3657 call free_all_values. We can't call free_all_values because
3658 we might be in the middle of evaluating a function call. */
3661 struct value *mark = value_mark ();
3662 struct value *new_val;
3664 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3666 /* We use value_equal_contents instead of value_equal because the latter
3667 coerces an array to a pointer, thus comparing just the address of the
3668 array instead of its contents. This is not what we want. */
3669 if ((b->val != NULL) != (new_val != NULL)
3670 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3672 if (new_val != NULL)
3674 release_value (new_val);
3675 value_free_to_mark (mark);
3677 bs->old_val = b->val;
3680 return WP_VALUE_CHANGED;
3684 /* Nothing changed. */
3685 value_free_to_mark (mark);
3686 return WP_VALUE_NOT_CHANGED;
3691 /* This seems like the only logical thing to do because
3692 if we temporarily ignored the watchpoint, then when
3693 we reenter the block in which it is valid it contains
3694 garbage (in the case of a function, it may have two
3695 garbage values, one before and one after the prologue).
3696 So we can't even detect the first assignment to it and
3697 watch after that (since the garbage may or may not equal
3698 the first value assigned). */
3699 /* We print all the stop information in print_it_typical(), but
3700 in this case, by the time we call print_it_typical() this bp
3701 will be deleted already. So we have no choice but print the
3702 information here. */
3703 if (ui_out_is_mi_like_p (uiout))
3705 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3706 ui_out_text (uiout, "\nWatchpoint ");
3707 ui_out_field_int (uiout, "wpnum", b->number);
3708 ui_out_text (uiout, " deleted because the program has left the block in\n\
3709 which its expression is valid.\n");
3711 if (b->related_breakpoint)
3713 b->related_breakpoint->disposition = disp_del_at_next_stop;
3714 b->related_breakpoint->related_breakpoint = NULL;
3715 b->related_breakpoint = NULL;
3717 b->disposition = disp_del_at_next_stop;
3723 /* Return true if it looks like target has stopped due to hitting
3724 breakpoint location BL. This function does not check if we
3725 should stop, only if BL explains the stop. */
3727 bpstat_check_location (const struct bp_location *bl,
3728 struct address_space *aspace, CORE_ADDR bp_addr)
3730 struct breakpoint *b = bl->owner;
3732 /* BL is from existing struct breakpoint. */
3733 gdb_assert (b != NULL);
3735 /* By definition, the inferior does not report stops at
3737 if (is_tracepoint (b))
3740 if (!is_watchpoint (b)
3741 && b->type != bp_hardware_breakpoint
3742 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3744 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3747 if (overlay_debugging /* unmapped overlay section */
3748 && section_is_overlay (bl->section)
3749 && !section_is_mapped (bl->section))
3753 /* Continuable hardware watchpoints are treated as non-existent if the
3754 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3755 some data address). Otherwise gdb won't stop on a break instruction
3756 in the code (not from a breakpoint) when a hardware watchpoint has
3757 been defined. Also skip watchpoints which we know did not trigger
3758 (did not match the data address). */
3760 if (is_hardware_watchpoint (b)
3761 && b->watchpoint_triggered == watch_triggered_no)
3764 if (b->type == bp_hardware_breakpoint)
3766 if (bl->address != bp_addr)
3768 if (overlay_debugging /* unmapped overlay section */
3769 && section_is_overlay (bl->section)
3770 && !section_is_mapped (bl->section))
3774 if (b->type == bp_catchpoint)
3776 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3777 if (!b->ops->breakpoint_hit (b))
3784 /* If BS refers to a watchpoint, determine if the watched values
3785 has actually changed, and we should stop. If not, set BS->stop
3788 bpstat_check_watchpoint (bpstat bs)
3790 const struct bp_location *bl;
3791 struct breakpoint *b;
3793 /* BS is built for existing struct breakpoint. */
3794 bl = bs->bp_location_at;
3795 gdb_assert (bl != NULL);
3796 b = bs->breakpoint_at;
3797 gdb_assert (b != NULL);
3799 if (is_watchpoint (b))
3801 int must_check_value = 0;
3803 if (b->type == bp_watchpoint)
3804 /* For a software watchpoint, we must always check the
3806 must_check_value = 1;
3807 else if (b->watchpoint_triggered == watch_triggered_yes)
3808 /* We have a hardware watchpoint (read, write, or access)
3809 and the target earlier reported an address watched by
3811 must_check_value = 1;
3812 else if (b->watchpoint_triggered == watch_triggered_unknown
3813 && b->type == bp_hardware_watchpoint)
3814 /* We were stopped by a hardware watchpoint, but the target could
3815 not report the data address. We must check the watchpoint's
3816 value. Access and read watchpoints are out of luck; without
3817 a data address, we can't figure it out. */
3818 must_check_value = 1;
3820 if (must_check_value)
3822 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3824 struct cleanup *cleanups = make_cleanup (xfree, message);
3825 int e = catch_errors (watchpoint_check, bs, message,
3827 do_cleanups (cleanups);
3831 /* We've already printed what needs to be printed. */
3832 bs->print_it = print_it_done;
3836 bs->print_it = print_it_noop;
3839 case WP_VALUE_CHANGED:
3840 if (b->type == bp_read_watchpoint)
3842 /* There are two cases to consider here:
3844 1. we're watching the triggered memory for reads.
3845 In that case, trust the target, and always report
3846 the watchpoint hit to the user. Even though
3847 reads don't cause value changes, the value may
3848 have changed since the last time it was read, and
3849 since we're not trapping writes, we will not see
3850 those, and as such we should ignore our notion of
3853 2. we're watching the triggered memory for both
3854 reads and writes. There are two ways this may
3857 2.1. this is a target that can't break on data
3858 reads only, but can break on accesses (reads or
3859 writes), such as e.g., x86. We detect this case
3860 at the time we try to insert read watchpoints.
3862 2.2. otherwise, the target supports read
3863 watchpoints, but, the user set an access or write
3864 watchpoint watching the same memory as this read
3867 If we're watching memory writes as well as reads,
3868 ignore watchpoint hits when we find that the
3869 value hasn't changed, as reads don't cause
3870 changes. This still gives false positives when
3871 the program writes the same value to memory as
3872 what there was already in memory (we will confuse
3873 it for a read), but it's much better than
3876 int other_write_watchpoint = 0;
3878 if (bl->watchpoint_type == hw_read)
3880 struct breakpoint *other_b;
3882 ALL_BREAKPOINTS (other_b)
3883 if ((other_b->type == bp_hardware_watchpoint
3884 || other_b->type == bp_access_watchpoint)
3885 && (other_b->watchpoint_triggered
3886 == watch_triggered_yes))
3888 other_write_watchpoint = 1;
3893 if (other_write_watchpoint
3894 || bl->watchpoint_type == hw_access)
3896 /* We're watching the same memory for writes,
3897 and the value changed since the last time we
3898 updated it, so this trap must be for a write.
3900 bs->print_it = print_it_noop;
3905 case WP_VALUE_NOT_CHANGED:
3906 if (b->type == bp_hardware_watchpoint
3907 || b->type == bp_watchpoint)
3909 /* Don't stop: write watchpoints shouldn't fire if
3910 the value hasn't changed. */
3911 bs->print_it = print_it_noop;
3919 /* Error from catch_errors. */
3920 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3921 if (b->related_breakpoint)
3922 b->related_breakpoint->disposition = disp_del_at_next_stop;
3923 b->disposition = disp_del_at_next_stop;
3924 /* We've already printed what needs to be printed. */
3925 bs->print_it = print_it_done;
3929 else /* must_check_value == 0 */
3931 /* This is a case where some watchpoint(s) triggered, but
3932 not at the address of this watchpoint, or else no
3933 watchpoint triggered after all. So don't print
3934 anything for this watchpoint. */
3935 bs->print_it = print_it_noop;
3942 /* Check conditions (condition proper, frame, thread and ignore count)
3943 of breakpoint referred to by BS. If we should not stop for this
3944 breakpoint, set BS->stop to 0. */
3947 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3949 int thread_id = pid_to_thread_id (ptid);
3950 const struct bp_location *bl;
3951 struct breakpoint *b;
3953 /* BS is built for existing struct breakpoint. */
3954 bl = bs->bp_location_at;
3955 gdb_assert (bl != NULL);
3956 b = bs->breakpoint_at;
3957 gdb_assert (b != NULL);
3959 if (frame_id_p (b->frame_id)
3960 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3964 int value_is_zero = 0;
3965 struct expression *cond;
3967 if (is_watchpoint (b))
3972 if (cond && b->disposition != disp_del_at_next_stop)
3974 int within_current_scope = 1;
3976 /* We use value_mark and value_free_to_mark because it could
3977 be a long time before we return to the command level and
3978 call free_all_values. We can't call free_all_values
3979 because we might be in the middle of evaluating a
3981 struct value *mark = value_mark ();
3983 /* Need to select the frame, with all that implies so that
3984 the conditions will have the right context. Because we
3985 use the frame, we will not see an inlined function's
3986 variables when we arrive at a breakpoint at the start
3987 of the inlined function; the current frame will be the
3989 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
3990 select_frame (get_current_frame ());
3993 struct frame_info *frame;
3995 /* For local watchpoint expressions, which particular
3996 instance of a local is being watched matters, so we
3997 keep track of the frame to evaluate the expression
3998 in. To evaluate the condition however, it doesn't
3999 really matter which instantiation of the function
4000 where the condition makes sense triggers the
4001 watchpoint. This allows an expression like "watch
4002 global if q > 10" set in `func', catch writes to
4003 global on all threads that call `func', or catch
4004 writes on all recursive calls of `func' by a single
4005 thread. We simply always evaluate the condition in
4006 the innermost frame that's executing where it makes
4007 sense to evaluate the condition. It seems
4009 frame = block_innermost_frame (b->cond_exp_valid_block);
4011 select_frame (frame);
4013 within_current_scope = 0;
4015 if (within_current_scope)
4017 = catch_errors (breakpoint_cond_eval, cond,
4018 "Error in testing breakpoint condition:\n",
4022 warning (_("Watchpoint condition cannot be tested "
4023 "in the current scope"));
4024 /* If we failed to set the right context for this
4025 watchpoint, unconditionally report it. */
4028 /* FIXME-someday, should give breakpoint # */
4029 value_free_to_mark (mark);
4032 if (cond && value_is_zero)
4036 else if (b->thread != -1 && b->thread != thread_id)
4040 else if (b->ignore_count > 0)
4043 annotate_ignore_count_change ();
4045 /* Increase the hit count even though we don't
4053 /* Get a bpstat associated with having just stopped at address
4054 BP_ADDR in thread PTID.
4056 Determine whether we stopped at a breakpoint, etc, or whether we
4057 don't understand this stop. Result is a chain of bpstat's such that:
4059 if we don't understand the stop, the result is a null pointer.
4061 if we understand why we stopped, the result is not null.
4063 Each element of the chain refers to a particular breakpoint or
4064 watchpoint at which we have stopped. (We may have stopped for
4065 several reasons concurrently.)
4067 Each element of the chain has valid next, breakpoint_at,
4068 commands, FIXME??? fields. */
4071 bpstat_stop_status (struct address_space *aspace,
4072 CORE_ADDR bp_addr, ptid_t ptid)
4074 struct breakpoint *b = NULL;
4075 struct bp_location *bl;
4076 struct bp_location *loc;
4077 /* First item of allocated bpstat's. */
4078 bpstat bs_head = NULL, *bs_link = &bs_head;
4079 /* Pointer to the last thing in the chain currently. */
4082 int need_remove_insert;
4085 /* First, build the bpstat chain with locations that explain a
4086 target stop, while being careful to not set the target running,
4087 as that may invalidate locations (in particular watchpoint
4088 locations are recreated). Resuming will happen here with
4089 breakpoint conditions or watchpoint expressions that include
4090 inferior function calls. */
4094 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4097 for (bl = b->loc; bl != NULL; bl = bl->next)
4099 /* For hardware watchpoints, we look only at the first location.
4100 The watchpoint_check function will work on the entire expression,
4101 not the individual locations. For read watchpoints, the
4102 watchpoints_triggered function has checked all locations
4104 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4107 if (bl->shlib_disabled)
4110 if (!bpstat_check_location (bl, aspace, bp_addr))
4113 /* Come here if it's a watchpoint, or if the break address matches */
4115 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to explain stop */
4117 /* Assume we stop. Should we find a watchpoint that is not
4118 actually triggered, or if the condition of the breakpoint
4119 evaluates as false, we'll reset 'stop' to 0. */
4123 /* If this is a scope breakpoint, mark the associated
4124 watchpoint as triggered so that we will handle the
4125 out-of-scope event. We'll get to the watchpoint next
4127 if (b->type == bp_watchpoint_scope)
4128 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
4132 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4134 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4137 bs = bpstat_alloc (loc, &bs_link);
4138 /* For hits of moribund locations, we should just proceed. */
4141 bs->print_it = print_it_noop;
4145 /* Now go through the locations that caused the target to stop, and
4146 check whether we're interested in reporting this stop to higher
4147 layers, or whether we should resume the target transparently. */
4151 for (bs = bs_head; bs != NULL; bs = bs->next)
4156 bpstat_check_watchpoint (bs);
4160 b = bs->breakpoint_at;
4162 if (b->type == bp_thread_event || b->type == bp_overlay_event
4163 || b->type == bp_longjmp_master
4164 || b->type == bp_std_terminate_master
4165 || b->type == bp_exception_master)
4166 /* We do not stop for these. */
4169 bpstat_check_breakpoint_conditions (bs, ptid);
4175 /* We will stop here */
4176 if (b->disposition == disp_disable)
4178 if (b->enable_state != bp_permanent)
4179 b->enable_state = bp_disabled;
4184 bs->commands = b->commands;
4185 incref_counted_command_line (bs->commands);
4186 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4187 if (bs->commands_left
4188 && (strcmp ("silent", bs->commands_left->line) == 0
4191 bs->commands_left->line) == 0)))
4193 bs->commands_left = bs->commands_left->next;
4198 /* Print nothing for this entry if we dont stop or dont print. */
4199 if (bs->stop == 0 || bs->print == 0)
4200 bs->print_it = print_it_noop;
4203 /* If we aren't stopping, the value of some hardware watchpoint may
4204 not have changed, but the intermediate memory locations we are
4205 watching may have. Don't bother if we're stopping; this will get
4207 need_remove_insert = 0;
4208 if (! bpstat_causes_stop (bs_head))
4209 for (bs = bs_head; bs != NULL; bs = bs->next)
4211 && bs->breakpoint_at
4212 && is_hardware_watchpoint (bs->breakpoint_at))
4214 update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */);
4215 need_remove_insert = 1;
4218 if (need_remove_insert)
4219 update_global_location_list (1);
4220 else if (removed_any)
4221 update_global_location_list (0);
4227 handle_jit_event (void)
4229 struct frame_info *frame;
4230 struct gdbarch *gdbarch;
4232 /* Switch terminal for any messages produced by
4233 breakpoint_re_set. */
4234 target_terminal_ours_for_output ();
4236 frame = get_current_frame ();
4237 gdbarch = get_frame_arch (frame);
4239 jit_event_handler (gdbarch);
4241 target_terminal_inferior ();
4244 /* Prepare WHAT final decision for infrun. */
4246 /* Decide what infrun needs to do with this bpstat. */
4249 bpstat_what (bpstat bs)
4251 struct bpstat_what retval;
4252 /* We need to defer calling `solib_add', as adding new symbols
4253 resets breakpoints, which in turn deletes breakpoint locations,
4254 and hence may clear unprocessed entries in the BS chain. */
4255 int shlib_event = 0;
4258 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4259 retval.call_dummy = STOP_NONE;
4260 retval.is_longjmp = 0;
4262 for (; bs != NULL; bs = bs->next)
4264 /* Extract this BS's action. After processing each BS, we check
4265 if its action overrides all we've seem so far. */
4266 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4269 if (bs->breakpoint_at == NULL)
4271 /* I suspect this can happen if it was a momentary
4272 breakpoint which has since been deleted. */
4275 else if (bs->breakpoint_at == NULL)
4278 bptype = bs->breakpoint_at->type;
4285 case bp_hardware_breakpoint:
4291 this_action = BPSTAT_WHAT_STOP_NOISY;
4293 this_action = BPSTAT_WHAT_STOP_SILENT;
4296 this_action = BPSTAT_WHAT_SINGLE;
4299 case bp_hardware_watchpoint:
4300 case bp_read_watchpoint:
4301 case bp_access_watchpoint:
4305 this_action = BPSTAT_WHAT_STOP_NOISY;
4307 this_action = BPSTAT_WHAT_STOP_SILENT;
4311 /* There was a watchpoint, but we're not stopping.
4312 This requires no further action. */
4317 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4318 retval.is_longjmp = bptype == bp_longjmp;
4320 case bp_longjmp_resume:
4321 case bp_exception_resume:
4322 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4323 retval.is_longjmp = bptype == bp_longjmp_resume;
4325 case bp_step_resume:
4327 this_action = BPSTAT_WHAT_STEP_RESUME;
4330 /* It is for the wrong frame. */
4331 this_action = BPSTAT_WHAT_SINGLE;
4334 case bp_watchpoint_scope:
4335 case bp_thread_event:
4336 case bp_overlay_event:
4337 case bp_longjmp_master:
4338 case bp_std_terminate_master:
4339 case bp_exception_master:
4340 this_action = BPSTAT_WHAT_SINGLE;
4346 this_action = BPSTAT_WHAT_STOP_NOISY;
4348 this_action = BPSTAT_WHAT_STOP_SILENT;
4352 /* There was a catchpoint, but we're not stopping.
4353 This requires no further action. */
4356 case bp_shlib_event:
4359 /* If requested, stop when the dynamic linker notifies GDB
4360 of events. This allows the user to get control and place
4361 breakpoints in initializer routines for dynamically
4362 loaded objects (among other things). */
4363 if (stop_on_solib_events)
4364 this_action = BPSTAT_WHAT_STOP_NOISY;
4366 this_action = BPSTAT_WHAT_SINGLE;
4370 this_action = BPSTAT_WHAT_SINGLE;
4373 /* Make sure the action is stop (silent or noisy),
4374 so infrun.c pops the dummy frame. */
4375 retval.call_dummy = STOP_STACK_DUMMY;
4376 this_action = BPSTAT_WHAT_STOP_SILENT;
4378 case bp_std_terminate:
4379 /* Make sure the action is stop (silent or noisy),
4380 so infrun.c pops the dummy frame. */
4381 retval.call_dummy = STOP_STD_TERMINATE;
4382 this_action = BPSTAT_WHAT_STOP_SILENT;
4385 case bp_fast_tracepoint:
4386 case bp_static_tracepoint:
4387 /* Tracepoint hits should not be reported back to GDB, and
4388 if one got through somehow, it should have been filtered
4390 internal_error (__FILE__, __LINE__,
4391 _("bpstat_what: tracepoint encountered"));
4393 internal_error (__FILE__, __LINE__,
4394 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4397 retval.main_action = max (retval.main_action, this_action);
4403 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4405 /* Check for any newly added shared libraries if we're supposed
4406 to be adding them automatically. */
4408 /* Switch terminal for any messages produced by
4409 breakpoint_re_set. */
4410 target_terminal_ours_for_output ();
4413 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4415 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4418 target_terminal_inferior ();
4424 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4426 handle_jit_event ();
4432 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4433 without hardware support). This isn't related to a specific bpstat,
4434 just to things like whether watchpoints are set. */
4437 bpstat_should_step (void)
4439 struct breakpoint *b;
4442 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4448 bpstat_causes_stop (bpstat bs)
4450 for (; bs != NULL; bs = bs->next)
4459 /* Print the LOC location out of the list of B->LOC locations. */
4461 static void print_breakpoint_location (struct breakpoint *b,
4462 struct bp_location *loc,
4464 struct ui_stream *stb)
4466 struct cleanup *old_chain = save_current_program_space ();
4468 if (loc != NULL && loc->shlib_disabled)
4472 set_current_program_space (loc->pspace);
4474 if (b->source_file && loc)
4477 = find_pc_sect_function (loc->address, loc->section);
4480 ui_out_text (uiout, "in ");
4481 ui_out_field_string (uiout, "func",
4482 SYMBOL_PRINT_NAME (sym));
4483 ui_out_wrap_hint (uiout, wrap_indent);
4484 ui_out_text (uiout, " at ");
4486 ui_out_field_string (uiout, "file", b->source_file);
4487 ui_out_text (uiout, ":");
4489 if (ui_out_is_mi_like_p (uiout))
4491 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4492 char *fullname = symtab_to_fullname (sal.symtab);
4495 ui_out_field_string (uiout, "fullname", fullname);
4498 ui_out_field_int (uiout, "line", b->line_number);
4502 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4504 ui_out_field_stream (uiout, "at", stb);
4507 ui_out_field_string (uiout, "pending", b->addr_string);
4509 do_cleanups (old_chain);
4513 bptype_string (enum bptype type)
4515 struct ep_type_description
4520 static struct ep_type_description bptypes[] =
4522 {bp_none, "?deleted?"},
4523 {bp_breakpoint, "breakpoint"},
4524 {bp_hardware_breakpoint, "hw breakpoint"},
4525 {bp_until, "until"},
4526 {bp_finish, "finish"},
4527 {bp_watchpoint, "watchpoint"},
4528 {bp_hardware_watchpoint, "hw watchpoint"},
4529 {bp_read_watchpoint, "read watchpoint"},
4530 {bp_access_watchpoint, "acc watchpoint"},
4531 {bp_longjmp, "longjmp"},
4532 {bp_longjmp_resume, "longjmp resume"},
4533 {bp_exception, "exception"},
4534 {bp_exception_resume, "exception resume"},
4535 {bp_step_resume, "step resume"},
4536 {bp_watchpoint_scope, "watchpoint scope"},
4537 {bp_call_dummy, "call dummy"},
4538 {bp_std_terminate, "std::terminate"},
4539 {bp_shlib_event, "shlib events"},
4540 {bp_thread_event, "thread events"},
4541 {bp_overlay_event, "overlay events"},
4542 {bp_longjmp_master, "longjmp master"},
4543 {bp_std_terminate_master, "std::terminate master"},
4544 {bp_exception_master, "exception master"},
4545 {bp_catchpoint, "catchpoint"},
4546 {bp_tracepoint, "tracepoint"},
4547 {bp_fast_tracepoint, "fast tracepoint"},
4548 {bp_static_tracepoint, "static tracepoint"},
4549 {bp_jit_event, "jit events"},
4552 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4553 || ((int) type != bptypes[(int) type].type))
4554 internal_error (__FILE__, __LINE__,
4555 _("bptypes table does not describe type #%d."),
4558 return bptypes[(int) type].description;
4561 /* Print B to gdb_stdout. */
4564 print_one_breakpoint_location (struct breakpoint *b,
4565 struct bp_location *loc,
4567 struct bp_location **last_loc,
4568 int print_address_bits,
4571 struct command_line *l;
4572 static char bpenables[] = "nynny";
4573 char wrap_indent[80];
4574 struct ui_stream *stb = ui_out_stream_new (uiout);
4575 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4576 struct cleanup *bkpt_chain;
4578 int header_of_multiple = 0;
4579 int part_of_multiple = (loc != NULL);
4580 struct value_print_options opts;
4582 get_user_print_options (&opts);
4584 gdb_assert (!loc || loc_number != 0);
4585 /* See comment in print_one_breakpoint concerning
4586 treatment of breakpoints with single disabled
4590 && (b->loc->next != NULL || !b->loc->enabled)))
4591 header_of_multiple = 1;
4596 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4600 if (part_of_multiple)
4603 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4604 ui_out_field_string (uiout, "number", formatted);
4609 ui_out_field_int (uiout, "number", b->number);
4614 if (part_of_multiple)
4615 ui_out_field_skip (uiout, "type");
4617 ui_out_field_string (uiout, "type", bptype_string (b->type));
4621 if (part_of_multiple)
4622 ui_out_field_skip (uiout, "disp");
4624 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4629 if (part_of_multiple)
4630 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4632 ui_out_field_fmt (uiout, "enabled", "%c",
4633 bpenables[(int) b->enable_state]);
4634 ui_out_spaces (uiout, 2);
4638 strcpy (wrap_indent, " ");
4639 if (opts.addressprint)
4641 if (print_address_bits <= 32)
4642 strcat (wrap_indent, " ");
4644 strcat (wrap_indent, " ");
4647 if (b->ops != NULL && b->ops->print_one != NULL)
4649 /* Although the print_one can possibly print
4650 all locations, calling it here is not likely
4651 to get any nice result. So, make sure there's
4652 just one location. */
4653 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4654 b->ops->print_one (b, last_loc);
4660 internal_error (__FILE__, __LINE__,
4661 _("print_one_breakpoint: bp_none encountered\n"));
4665 case bp_hardware_watchpoint:
4666 case bp_read_watchpoint:
4667 case bp_access_watchpoint:
4668 /* Field 4, the address, is omitted (which makes the columns
4669 not line up too nicely with the headers, but the effect
4670 is relatively readable). */
4671 if (opts.addressprint)
4672 ui_out_field_skip (uiout, "addr");
4674 ui_out_field_string (uiout, "what", b->exp_string);
4678 case bp_hardware_breakpoint:
4682 case bp_longjmp_resume:
4684 case bp_exception_resume:
4685 case bp_step_resume:
4686 case bp_watchpoint_scope:
4688 case bp_std_terminate:
4689 case bp_shlib_event:
4690 case bp_thread_event:
4691 case bp_overlay_event:
4692 case bp_longjmp_master:
4693 case bp_std_terminate_master:
4694 case bp_exception_master:
4696 case bp_fast_tracepoint:
4697 case bp_static_tracepoint:
4699 if (opts.addressprint)
4702 if (header_of_multiple)
4703 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4704 else if (b->loc == NULL || loc->shlib_disabled)
4705 ui_out_field_string (uiout, "addr", "<PENDING>");
4707 ui_out_field_core_addr (uiout, "addr",
4708 loc->gdbarch, loc->address);
4711 if (!header_of_multiple)
4712 print_breakpoint_location (b, loc, wrap_indent, stb);
4719 /* For backward compatibility, don't display inferiors unless there
4722 && !header_of_multiple
4724 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4725 && (number_of_program_spaces () > 1
4726 || number_of_inferiors () > 1)
4727 /* LOC is for existing B, it cannot be in moribund_locations and
4728 thus having NULL OWNER. */
4729 && loc->owner->type != bp_catchpoint)))
4731 struct inferior *inf;
4734 for (inf = inferior_list; inf != NULL; inf = inf->next)
4736 if (inf->pspace == loc->pspace)
4741 ui_out_text (uiout, " inf ");
4744 ui_out_text (uiout, ", ");
4745 ui_out_text (uiout, plongest (inf->num));
4750 if (!part_of_multiple)
4752 if (b->thread != -1)
4754 /* FIXME: This seems to be redundant and lost here; see the
4755 "stop only in" line a little further down. */
4756 ui_out_text (uiout, " thread ");
4757 ui_out_field_int (uiout, "thread", b->thread);
4759 else if (b->task != 0)
4761 ui_out_text (uiout, " task ");
4762 ui_out_field_int (uiout, "task", b->task);
4766 ui_out_text (uiout, "\n");
4768 if (!part_of_multiple && b->static_trace_marker_id)
4770 gdb_assert (b->type == bp_static_tracepoint);
4772 ui_out_text (uiout, "\tmarker id is ");
4773 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
4774 b->static_trace_marker_id);
4775 ui_out_text (uiout, "\n");
4778 if (part_of_multiple && frame_id_p (b->frame_id))
4781 ui_out_text (uiout, "\tstop only in stack frame at ");
4782 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4784 ui_out_field_core_addr (uiout, "frame",
4785 b->gdbarch, b->frame_id.stack_addr);
4786 ui_out_text (uiout, "\n");
4789 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4791 /* We do not print the condition for Ada exception catchpoints
4792 because the condition is an internal implementation detail
4793 that we do not want to expose to the user. */
4795 if (is_tracepoint (b))
4796 ui_out_text (uiout, "\ttrace only if ");
4798 ui_out_text (uiout, "\tstop only if ");
4799 ui_out_field_string (uiout, "cond", b->cond_string);
4800 ui_out_text (uiout, "\n");
4803 if (!part_of_multiple && b->thread != -1)
4805 /* FIXME should make an annotation for this */
4806 ui_out_text (uiout, "\tstop only in thread ");
4807 ui_out_field_int (uiout, "thread", b->thread);
4808 ui_out_text (uiout, "\n");
4811 if (!part_of_multiple && b->hit_count)
4813 /* FIXME should make an annotation for this */
4814 if (ep_is_catchpoint (b))
4815 ui_out_text (uiout, "\tcatchpoint");
4817 ui_out_text (uiout, "\tbreakpoint");
4818 ui_out_text (uiout, " already hit ");
4819 ui_out_field_int (uiout, "times", b->hit_count);
4820 if (b->hit_count == 1)
4821 ui_out_text (uiout, " time\n");
4823 ui_out_text (uiout, " times\n");
4826 /* Output the count also if it is zero, but only if this is
4827 mi. FIXME: Should have a better test for this. */
4828 if (ui_out_is_mi_like_p (uiout))
4829 if (!part_of_multiple && b->hit_count == 0)
4830 ui_out_field_int (uiout, "times", b->hit_count);
4832 if (!part_of_multiple && b->ignore_count)
4835 ui_out_text (uiout, "\tignore next ");
4836 ui_out_field_int (uiout, "ignore", b->ignore_count);
4837 ui_out_text (uiout, " hits\n");
4840 l = b->commands ? b->commands->commands : NULL;
4841 if (!part_of_multiple && l)
4843 struct cleanup *script_chain;
4846 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4847 print_command_lines (uiout, l, 4);
4848 do_cleanups (script_chain);
4851 if (!part_of_multiple && b->pass_count)
4853 annotate_field (10);
4854 ui_out_text (uiout, "\tpass count ");
4855 ui_out_field_int (uiout, "pass", b->pass_count);
4856 ui_out_text (uiout, " \n");
4859 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4862 ui_out_field_string (uiout, "original-location", b->addr_string);
4863 else if (b->exp_string)
4864 ui_out_field_string (uiout, "original-location", b->exp_string);
4867 do_cleanups (bkpt_chain);
4868 do_cleanups (old_chain);
4872 print_one_breakpoint (struct breakpoint *b,
4873 struct bp_location **last_loc, int print_address_bits,
4876 print_one_breakpoint_location (b, NULL, 0, last_loc,
4877 print_address_bits, allflag);
4879 /* If this breakpoint has custom print function,
4880 it's already printed. Otherwise, print individual
4881 locations, if any. */
4882 if (b->ops == NULL || b->ops->print_one == NULL)
4884 /* If breakpoint has a single location that is
4885 disabled, we print it as if it had
4886 several locations, since otherwise it's hard to
4887 represent "breakpoint enabled, location disabled"
4889 Note that while hardware watchpoints have
4890 several locations internally, that's no a property
4893 && !is_hardware_watchpoint (b)
4894 && (b->loc->next || !b->loc->enabled)
4895 && !ui_out_is_mi_like_p (uiout))
4897 struct bp_location *loc;
4899 for (loc = b->loc; loc; loc = loc->next, ++n)
4900 print_one_breakpoint_location (b, loc, n, last_loc,
4901 print_address_bits, allflag);
4907 breakpoint_address_bits (struct breakpoint *b)
4909 int print_address_bits = 0;
4910 struct bp_location *loc;
4912 for (loc = b->loc; loc; loc = loc->next)
4916 /* Software watchpoints that aren't watching memory don't have
4917 an address to print. */
4918 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4921 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4922 if (addr_bit > print_address_bits)
4923 print_address_bits = addr_bit;
4926 return print_address_bits;
4929 struct captured_breakpoint_query_args
4935 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4937 struct captured_breakpoint_query_args *args = data;
4938 struct breakpoint *b;
4939 struct bp_location *dummy_loc = NULL;
4943 if (args->bnum == b->number)
4945 int print_address_bits = breakpoint_address_bits (b);
4947 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4955 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4957 struct captured_breakpoint_query_args args;
4960 /* For the moment we don't trust print_one_breakpoint() to not throw
4962 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4963 error_message, RETURN_MASK_ALL) < 0)
4969 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4970 catchpoints, et.al.). */
4973 user_settable_breakpoint (const struct breakpoint *b)
4975 return (b->type == bp_breakpoint
4976 || b->type == bp_catchpoint
4977 || b->type == bp_hardware_breakpoint
4978 || is_tracepoint (b)
4979 || is_watchpoint (b));
4982 /* Print information on user settable breakpoint (watchpoint, etc)
4983 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4984 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4985 FILTER is non-NULL, call it on each breakpoint and only include the
4986 ones for which it returns non-zero. Return the total number of
4987 breakpoints listed. */
4990 breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
4992 struct breakpoint *b;
4993 struct bp_location *last_loc = NULL;
4994 int nr_printable_breakpoints;
4995 struct cleanup *bkpttbl_chain;
4996 struct value_print_options opts;
4997 int print_address_bits = 0;
4998 int print_type_col_width = 14;
5000 get_user_print_options (&opts);
5002 /* Compute the number of rows in the table, as well as the
5003 size required for address fields. */
5004 nr_printable_breakpoints = 0;
5007 || bnum == b->number)
5009 /* If we have a filter, only list the breakpoints it accepts. */
5010 if (filter && !filter (b))
5013 if (allflag || (user_settable_breakpoint (b)
5016 int addr_bit, type_len;
5018 addr_bit = breakpoint_address_bits (b);
5019 if (addr_bit > print_address_bits)
5020 print_address_bits = addr_bit;
5022 type_len = strlen (bptype_string (b->type));
5023 if (type_len > print_type_col_width)
5024 print_type_col_width = type_len;
5026 nr_printable_breakpoints++;
5030 if (opts.addressprint)
5032 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
5036 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
5039 if (nr_printable_breakpoints > 0)
5040 annotate_breakpoints_headers ();
5041 if (nr_printable_breakpoints > 0)
5043 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5044 if (nr_printable_breakpoints > 0)
5046 ui_out_table_header (uiout, print_type_col_width, ui_left,
5047 "type", "Type"); /* 2 */
5048 if (nr_printable_breakpoints > 0)
5050 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5051 if (nr_printable_breakpoints > 0)
5053 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5054 if (opts.addressprint)
5056 if (nr_printable_breakpoints > 0)
5058 if (print_address_bits <= 32)
5059 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
5061 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
5063 if (nr_printable_breakpoints > 0)
5065 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5066 ui_out_table_body (uiout);
5067 if (nr_printable_breakpoints > 0)
5068 annotate_breakpoints_table ();
5074 || bnum == b->number)
5076 /* If we have a filter, only list the breakpoints it accepts. */
5077 if (filter && !filter (b))
5080 /* We only print out user settable breakpoints unless the
5082 if (allflag || (user_settable_breakpoint (b)
5084 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5088 do_cleanups (bkpttbl_chain);
5090 if (nr_printable_breakpoints == 0)
5092 /* If there's a filter, let the caller decide how to report empty list. */
5096 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5098 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
5104 if (last_loc && !server_command)
5105 set_next_address (last_loc->gdbarch, last_loc->address);
5108 /* FIXME? Should this be moved up so that it is only called when
5109 there have been breakpoints? */
5110 annotate_breakpoints_table_end ();
5112 return nr_printable_breakpoints;
5115 /* Display the value of default-collect in a way that is generally
5116 compatible with the breakpoint list. */
5119 default_collect_info (void)
5121 /* If it has no value (which is frequently the case), say nothing; a
5122 message like "No default-collect." gets in user's face when it's
5124 if (!*default_collect)
5127 /* The following phrase lines up nicely with per-tracepoint collect
5129 ui_out_text (uiout, "default collect ");
5130 ui_out_field_string (uiout, "default-collect", default_collect);
5131 ui_out_text (uiout, " \n");
5135 breakpoints_info (char *bnum_exp, int from_tty)
5140 bnum = parse_and_eval_long (bnum_exp);
5142 breakpoint_1 (bnum, 0, NULL);
5144 default_collect_info ();
5148 watchpoints_info (char *wpnum_exp, int from_tty)
5150 int wpnum = -1, num_printed;
5153 wpnum = parse_and_eval_long (wpnum_exp);
5155 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5157 if (num_printed == 0)
5160 ui_out_message (uiout, 0, "No watchpoints.\n");
5162 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5167 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5172 bnum = parse_and_eval_long (bnum_exp);
5174 breakpoint_1 (bnum, 1, NULL);
5176 default_collect_info ();
5180 breakpoint_has_pc (struct breakpoint *b,
5181 struct program_space *pspace,
5182 CORE_ADDR pc, struct obj_section *section)
5184 struct bp_location *bl = b->loc;
5186 for (; bl; bl = bl->next)
5188 if (bl->pspace == pspace
5189 && bl->address == pc
5190 && (!overlay_debugging || bl->section == section))
5196 /* Print a message describing any breakpoints set at PC. This
5197 concerns with logical breakpoints, so we match program spaces, not
5201 describe_other_breakpoints (struct gdbarch *gdbarch,
5202 struct program_space *pspace, CORE_ADDR pc,
5203 struct obj_section *section, int thread)
5206 struct breakpoint *b;
5209 others += breakpoint_has_pc (b, pspace, pc, section);
5213 printf_filtered (_("Note: breakpoint "));
5214 else /* if (others == ???) */
5215 printf_filtered (_("Note: breakpoints "));
5217 if (breakpoint_has_pc (b, pspace, pc, section))
5220 printf_filtered ("%d", b->number);
5221 if (b->thread == -1 && thread != -1)
5222 printf_filtered (" (all threads)");
5223 else if (b->thread != -1)
5224 printf_filtered (" (thread %d)", b->thread);
5225 printf_filtered ("%s%s ",
5226 ((b->enable_state == bp_disabled
5227 || b->enable_state == bp_call_disabled
5228 || b->enable_state == bp_startup_disabled)
5230 : b->enable_state == bp_permanent
5234 : ((others == 1) ? " and" : ""));
5236 printf_filtered (_("also set at pc "));
5237 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5238 printf_filtered (".\n");
5242 /* Set the default place to put a breakpoint
5243 for the `break' command with no arguments. */
5246 set_default_breakpoint (int valid, struct program_space *pspace,
5247 CORE_ADDR addr, struct symtab *symtab,
5250 default_breakpoint_valid = valid;
5251 default_breakpoint_pspace = pspace;
5252 default_breakpoint_address = addr;
5253 default_breakpoint_symtab = symtab;
5254 default_breakpoint_line = line;
5257 /* Return true iff it is meaningful to use the address member of
5258 BPT. For some breakpoint types, the address member is irrelevant
5259 and it makes no sense to attempt to compare it to other addresses
5260 (or use it for any other purpose either).
5262 More specifically, each of the following breakpoint types will always
5263 have a zero valued address and we don't want to mark breakpoints of any of
5264 these types to be a duplicate of an actual breakpoint at address zero:
5272 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5274 enum bptype type = bpt->type;
5276 return (type != bp_watchpoint && type != bp_catchpoint);
5279 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5280 true if LOC1 and LOC2 represent the same watchpoint location. */
5283 watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5285 /* Both of them must not be in moribund_locations. */
5286 gdb_assert (loc1->owner != NULL);
5287 gdb_assert (loc2->owner != NULL);
5289 /* If the target can evaluate the condition expression in hardware, then we
5290 we need to insert both watchpoints even if they are at the same place.
5291 Otherwise the watchpoint will only trigger when the condition of whichever
5292 watchpoint was inserted evaluates to true, not giving a chance for GDB to
5293 check the condition of the other watchpoint. */
5294 if ((loc1->owner->cond_exp
5295 && target_can_accel_watchpoint_condition (loc1->address, loc1->length,
5296 loc1->watchpoint_type,
5297 loc1->owner->cond_exp))
5298 || (loc2->owner->cond_exp
5299 && target_can_accel_watchpoint_condition (loc2->address, loc2->length,
5300 loc2->watchpoint_type,
5301 loc2->owner->cond_exp)))
5304 /* Note that this checks the owner's type, not the location's. In
5305 case the target does not support read watchpoints, but does
5306 support access watchpoints, we'll have bp_read_watchpoint
5307 watchpoints with hw_access locations. Those should be considered
5308 duplicates of hw_read locations. The hw_read locations will
5309 become hw_access locations later. */
5310 return (loc1->owner->type == loc2->owner->type
5311 && loc1->pspace->aspace == loc2->pspace->aspace
5312 && loc1->address == loc2->address
5313 && loc1->length == loc2->length);
5316 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5317 same breakpoint location. In most targets, this can only be true
5318 if ASPACE1 matches ASPACE2. On targets that have global
5319 breakpoints, the address space doesn't really matter. */
5322 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5323 struct address_space *aspace2, CORE_ADDR addr2)
5325 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5326 || aspace1 == aspace2)
5330 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5331 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5332 represent the same location. */
5335 breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5337 int hw_point1, hw_point2;
5339 /* Both of them must not be in moribund_locations. */
5340 gdb_assert (loc1->owner != NULL);
5341 gdb_assert (loc2->owner != NULL);
5343 hw_point1 = is_hardware_watchpoint (loc1->owner);
5344 hw_point2 = is_hardware_watchpoint (loc2->owner);
5346 if (hw_point1 != hw_point2)
5349 return watchpoint_locations_match (loc1, loc2);
5351 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5352 loc2->pspace->aspace, loc2->address);
5356 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5357 int bnum, int have_bnum)
5362 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5363 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5365 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5366 bnum, astr1, astr2);
5368 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5371 /* Adjust a breakpoint's address to account for architectural constraints
5372 on breakpoint placement. Return the adjusted address. Note: Very
5373 few targets require this kind of adjustment. For most targets,
5374 this function is simply the identity function. */
5377 adjust_breakpoint_address (struct gdbarch *gdbarch,
5378 CORE_ADDR bpaddr, enum bptype bptype)
5380 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5382 /* Very few targets need any kind of breakpoint adjustment. */
5385 else if (bptype == bp_watchpoint
5386 || bptype == bp_hardware_watchpoint
5387 || bptype == bp_read_watchpoint
5388 || bptype == bp_access_watchpoint
5389 || bptype == bp_catchpoint)
5391 /* Watchpoints and the various bp_catch_* eventpoints should not
5392 have their addresses modified. */
5397 CORE_ADDR adjusted_bpaddr;
5399 /* Some targets have architectural constraints on the placement
5400 of breakpoint instructions. Obtain the adjusted address. */
5401 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5403 /* An adjusted breakpoint address can significantly alter
5404 a user's expectations. Print a warning if an adjustment
5406 if (adjusted_bpaddr != bpaddr)
5407 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5409 return adjusted_bpaddr;
5413 /* Allocate a struct bp_location. */
5415 static struct bp_location *
5416 allocate_bp_location (struct breakpoint *bpt)
5418 struct bp_location *loc;
5420 loc = xmalloc (sizeof (struct bp_location));
5421 memset (loc, 0, sizeof (*loc));
5425 loc->shlib_disabled = 0;
5434 case bp_longjmp_resume:
5436 case bp_exception_resume:
5437 case bp_step_resume:
5438 case bp_watchpoint_scope:
5440 case bp_std_terminate:
5441 case bp_shlib_event:
5442 case bp_thread_event:
5443 case bp_overlay_event:
5445 case bp_longjmp_master:
5446 case bp_std_terminate_master:
5447 case bp_exception_master:
5448 loc->loc_type = bp_loc_software_breakpoint;
5450 case bp_hardware_breakpoint:
5451 loc->loc_type = bp_loc_hardware_breakpoint;
5453 case bp_hardware_watchpoint:
5454 case bp_read_watchpoint:
5455 case bp_access_watchpoint:
5456 loc->loc_type = bp_loc_hardware_watchpoint;
5461 case bp_fast_tracepoint:
5462 case bp_static_tracepoint:
5463 loc->loc_type = bp_loc_other;
5466 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5474 free_bp_location (struct bp_location *loc)
5479 if (loc->function_name)
5480 xfree (loc->function_name);
5485 /* Increment reference count. */
5488 incref_bp_location (struct bp_location *bl)
5493 /* Decrement reference count. If the reference count reaches 0,
5494 destroy the bp_location. Sets *BLP to NULL. */
5497 decref_bp_location (struct bp_location **blp)
5499 gdb_assert ((*blp)->refc > 0);
5501 if (--(*blp)->refc == 0)
5502 free_bp_location (*blp);
5506 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5507 that has type BPTYPE and has no locations as yet. */
5508 /* This function is used in gdbtk sources and thus can not be made static. */
5510 static struct breakpoint *
5511 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5514 struct breakpoint *b, *b1;
5516 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5517 memset (b, 0, sizeof (*b));
5520 b->gdbarch = gdbarch;
5521 b->language = current_language->la_language;
5522 b->input_radix = input_radix;
5524 b->enable_state = bp_enabled;
5527 b->ignore_count = 0;
5529 b->frame_id = null_frame_id;
5530 b->forked_inferior_pid = null_ptid;
5531 b->exec_pathname = NULL;
5532 b->syscalls_to_be_caught = NULL;
5534 b->condition_not_parsed = 0;
5535 b->py_bp_object = NULL;
5537 /* Add this breakpoint to the end of the chain
5538 so that a list of breakpoints will come out in order
5539 of increasing numbers. */
5541 b1 = breakpoint_chain;
5543 breakpoint_chain = b;
5553 /* Initialize loc->function_name. */
5555 set_breakpoint_location_function (struct bp_location *loc)
5557 gdb_assert (loc->owner != NULL);
5559 if (loc->owner->type == bp_breakpoint
5560 || loc->owner->type == bp_hardware_breakpoint
5561 || is_tracepoint (loc->owner))
5563 find_pc_partial_function (loc->address, &(loc->function_name),
5565 if (loc->function_name)
5566 loc->function_name = xstrdup (loc->function_name);
5570 /* Attempt to determine architecture of location identified by SAL. */
5571 static struct gdbarch *
5572 get_sal_arch (struct symtab_and_line sal)
5575 return get_objfile_arch (sal.section->objfile);
5577 return get_objfile_arch (sal.symtab->objfile);
5582 /* set_raw_breakpoint is a low level routine for allocating and
5583 partially initializing a breakpoint of type BPTYPE. The newly
5584 created breakpoint's address, section, source file name, and line
5585 number are provided by SAL. The newly created and partially
5586 initialized breakpoint is added to the breakpoint chain and
5587 is also returned as the value of this function.
5589 It is expected that the caller will complete the initialization of
5590 the newly created breakpoint struct as well as output any status
5591 information regarding the creation of a new breakpoint. In
5592 particular, set_raw_breakpoint does NOT set the breakpoint
5593 number! Care should be taken to not allow an error to occur
5594 prior to completing the initialization of the breakpoint. If this
5595 should happen, a bogus breakpoint will be left on the chain. */
5598 set_raw_breakpoint (struct gdbarch *gdbarch,
5599 struct symtab_and_line sal, enum bptype bptype)
5601 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
5602 CORE_ADDR adjusted_address;
5603 struct gdbarch *loc_gdbarch;
5605 loc_gdbarch = get_sal_arch (sal);
5607 loc_gdbarch = b->gdbarch;
5609 if (bptype != bp_catchpoint)
5610 gdb_assert (sal.pspace != NULL);
5612 /* Adjust the breakpoint's address prior to allocating a location.
5613 Once we call allocate_bp_location(), that mostly uninitialized
5614 location will be placed on the location chain. Adjustment of the
5615 breakpoint may cause target_read_memory() to be called and we do
5616 not want its scan of the location chain to find a breakpoint and
5617 location that's only been partially initialized. */
5618 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
5620 b->loc = allocate_bp_location (b);
5621 b->loc->gdbarch = loc_gdbarch;
5622 b->loc->requested_address = sal.pc;
5623 b->loc->address = adjusted_address;
5624 b->loc->pspace = sal.pspace;
5626 /* Store the program space that was used to set the breakpoint, for
5627 breakpoint resetting. */
5628 b->pspace = sal.pspace;
5630 if (sal.symtab == NULL)
5631 b->source_file = NULL;
5633 b->source_file = xstrdup (sal.symtab->filename);
5634 b->loc->section = sal.section;
5635 b->line_number = sal.line;
5637 set_breakpoint_location_function (b->loc);
5639 breakpoints_changed ();
5645 /* Note that the breakpoint object B describes a permanent breakpoint
5646 instruction, hard-wired into the inferior's code. */
5648 make_breakpoint_permanent (struct breakpoint *b)
5650 struct bp_location *bl;
5652 b->enable_state = bp_permanent;
5654 /* By definition, permanent breakpoints are already present in the code.
5655 Mark all locations as inserted. For now, make_breakpoint_permanent
5656 is called in just one place, so it's hard to say if it's reasonable
5657 to have permanent breakpoint with multiple locations or not,
5658 but it's easy to implmement. */
5659 for (bl = b->loc; bl; bl = bl->next)
5663 /* Call this routine when stepping and nexting to enable a breakpoint
5664 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5665 initiated the operation. */
5668 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
5670 struct breakpoint *b, *b_tmp;
5671 int thread = tp->num;
5673 /* To avoid having to rescan all objfile symbols at every step,
5674 we maintain a list of continually-inserted but always disabled
5675 longjmp "master" breakpoints. Here, we simply create momentary
5676 clones of those and enable them for the requested thread. */
5677 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5678 if (b->pspace == current_program_space
5679 && (b->type == bp_longjmp_master
5680 || b->type == bp_exception_master))
5682 struct breakpoint *clone = clone_momentary_breakpoint (b);
5684 clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
5685 clone->thread = thread;
5688 tp->initiating_frame = frame;
5691 /* Delete all longjmp breakpoints from THREAD. */
5693 delete_longjmp_breakpoint (int thread)
5695 struct breakpoint *b, *b_tmp;
5697 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5698 if (b->type == bp_longjmp || b->type == bp_exception)
5700 if (b->thread == thread)
5701 delete_breakpoint (b);
5706 enable_overlay_breakpoints (void)
5708 struct breakpoint *b;
5711 if (b->type == bp_overlay_event)
5713 b->enable_state = bp_enabled;
5714 update_global_location_list (1);
5715 overlay_events_enabled = 1;
5720 disable_overlay_breakpoints (void)
5722 struct breakpoint *b;
5725 if (b->type == bp_overlay_event)
5727 b->enable_state = bp_disabled;
5728 update_global_location_list (0);
5729 overlay_events_enabled = 0;
5733 /* Set an active std::terminate breakpoint for each std::terminate
5734 master breakpoint. */
5736 set_std_terminate_breakpoint (void)
5738 struct breakpoint *b, *b_tmp;
5740 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5741 if (b->pspace == current_program_space
5742 && b->type == bp_std_terminate_master)
5744 struct breakpoint *clone = clone_momentary_breakpoint (b);
5745 clone->type = bp_std_terminate;
5749 /* Delete all the std::terminate breakpoints. */
5751 delete_std_terminate_breakpoint (void)
5753 struct breakpoint *b, *b_tmp;
5755 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5756 if (b->type == bp_std_terminate)
5757 delete_breakpoint (b);
5761 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5763 struct breakpoint *b;
5765 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5767 b->enable_state = bp_enabled;
5768 /* addr_string has to be used or breakpoint_re_set will delete me. */
5770 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5772 update_global_location_list_nothrow (1);
5778 remove_thread_event_breakpoints (void)
5780 struct breakpoint *b, *b_tmp;
5782 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5783 if (b->type == bp_thread_event
5784 && b->loc->pspace == current_program_space)
5785 delete_breakpoint (b);
5788 struct captured_parse_breakpoint_args
5791 struct symtabs_and_lines *sals_p;
5792 char ***addr_string_p;
5796 struct lang_and_radix
5802 /* Create a breakpoint for JIT code registration and unregistration. */
5805 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5807 struct breakpoint *b;
5809 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5810 update_global_location_list_nothrow (1);
5815 remove_solib_event_breakpoints (void)
5817 struct breakpoint *b, *b_tmp;
5819 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5820 if (b->type == bp_shlib_event
5821 && b->loc->pspace == current_program_space)
5822 delete_breakpoint (b);
5826 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5828 struct breakpoint *b;
5830 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5831 update_global_location_list_nothrow (1);
5835 /* Disable any breakpoints that are on code in shared libraries. Only
5836 apply to enabled breakpoints, disabled ones can just stay disabled. */
5839 disable_breakpoints_in_shlibs (void)
5841 struct bp_location *loc, **locp_tmp;
5843 ALL_BP_LOCATIONS (loc, locp_tmp)
5845 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5846 struct breakpoint *b = loc->owner;
5848 /* We apply the check to all breakpoints, including disabled
5849 for those with loc->duplicate set. This is so that when breakpoint
5850 becomes enabled, or the duplicate is removed, gdb will try to insert
5851 all breakpoints. If we don't set shlib_disabled here, we'll try
5852 to insert those breakpoints and fail. */
5853 if (((b->type == bp_breakpoint)
5854 || (b->type == bp_jit_event)
5855 || (b->type == bp_hardware_breakpoint)
5856 || (is_tracepoint (b)))
5857 && loc->pspace == current_program_space
5858 && !loc->shlib_disabled
5860 && PC_SOLIB (loc->address)
5862 && solib_name_from_address (loc->pspace, loc->address)
5866 loc->shlib_disabled = 1;
5871 /* Disable any breakpoints that are in in an unloaded shared library. Only
5872 apply to enabled breakpoints, disabled ones can just stay disabled. */
5875 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5877 struct bp_location *loc, **locp_tmp;
5878 int disabled_shlib_breaks = 0;
5880 /* SunOS a.out shared libraries are always mapped, so do not
5881 disable breakpoints; they will only be reported as unloaded
5882 through clear_solib when GDB discards its shared library
5883 list. See clear_solib for more information. */
5884 if (exec_bfd != NULL
5885 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5888 ALL_BP_LOCATIONS (loc, locp_tmp)
5890 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5891 struct breakpoint *b = loc->owner;
5893 if ((loc->loc_type == bp_loc_hardware_breakpoint
5894 || loc->loc_type == bp_loc_software_breakpoint)
5895 && solib->pspace == loc->pspace
5896 && !loc->shlib_disabled
5897 && (b->type == bp_breakpoint
5898 || b->type == bp_jit_event
5899 || b->type == bp_hardware_breakpoint)
5900 && solib_contains_address_p (solib, loc->address))
5902 loc->shlib_disabled = 1;
5903 /* At this point, we cannot rely on remove_breakpoint
5904 succeeding so we must mark the breakpoint as not inserted
5905 to prevent future errors occurring in remove_breakpoints. */
5907 if (!disabled_shlib_breaks)
5909 target_terminal_ours_for_output ();
5910 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5913 disabled_shlib_breaks = 1;
5918 /* FORK & VFORK catchpoints. */
5920 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5923 insert_catch_fork (struct breakpoint *b)
5925 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5928 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5931 remove_catch_fork (struct breakpoint *b)
5933 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5936 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5940 breakpoint_hit_catch_fork (struct breakpoint *b)
5942 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5945 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5947 static enum print_stop_action
5948 print_it_catch_fork (struct breakpoint *b)
5950 annotate_catchpoint (b->number);
5951 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5952 b->number, ptid_get_pid (b->forked_inferior_pid));
5953 return PRINT_SRC_AND_LOC;
5956 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5959 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5961 struct value_print_options opts;
5963 get_user_print_options (&opts);
5965 /* Field 4, the address, is omitted (which makes the columns
5966 not line up too nicely with the headers, but the effect
5967 is relatively readable). */
5968 if (opts.addressprint)
5969 ui_out_field_skip (uiout, "addr");
5971 ui_out_text (uiout, "fork");
5972 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5974 ui_out_text (uiout, ", process ");
5975 ui_out_field_int (uiout, "what",
5976 ptid_get_pid (b->forked_inferior_pid));
5977 ui_out_spaces (uiout, 1);
5981 /* Implement the "print_mention" breakpoint_ops method for fork
5985 print_mention_catch_fork (struct breakpoint *b)
5987 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5990 /* Implement the "print_recreate" breakpoint_ops method for fork
5994 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
5996 fprintf_unfiltered (fp, "catch fork");
5999 /* The breakpoint_ops structure to be used in fork catchpoints. */
6001 static struct breakpoint_ops catch_fork_breakpoint_ops =
6005 breakpoint_hit_catch_fork,
6006 print_it_catch_fork,
6007 print_one_catch_fork,
6008 print_mention_catch_fork,
6009 print_recreate_catch_fork
6012 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
6015 insert_catch_vfork (struct breakpoint *b)
6017 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6020 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
6023 remove_catch_vfork (struct breakpoint *b)
6025 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6028 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6032 breakpoint_hit_catch_vfork (struct breakpoint *b)
6034 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
6037 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
6039 static enum print_stop_action
6040 print_it_catch_vfork (struct breakpoint *b)
6042 annotate_catchpoint (b->number);
6043 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6044 b->number, ptid_get_pid (b->forked_inferior_pid));
6045 return PRINT_SRC_AND_LOC;
6048 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
6051 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6053 struct value_print_options opts;
6055 get_user_print_options (&opts);
6056 /* Field 4, the address, is omitted (which makes the columns
6057 not line up too nicely with the headers, but the effect
6058 is relatively readable). */
6059 if (opts.addressprint)
6060 ui_out_field_skip (uiout, "addr");
6062 ui_out_text (uiout, "vfork");
6063 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
6065 ui_out_text (uiout, ", process ");
6066 ui_out_field_int (uiout, "what",
6067 ptid_get_pid (b->forked_inferior_pid));
6068 ui_out_spaces (uiout, 1);
6072 /* Implement the "print_mention" breakpoint_ops method for vfork
6076 print_mention_catch_vfork (struct breakpoint *b)
6078 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6081 /* Implement the "print_recreate" breakpoint_ops method for vfork
6085 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6087 fprintf_unfiltered (fp, "catch vfork");
6090 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6092 static struct breakpoint_ops catch_vfork_breakpoint_ops =
6096 breakpoint_hit_catch_vfork,
6097 print_it_catch_vfork,
6098 print_one_catch_vfork,
6099 print_mention_catch_vfork,
6100 print_recreate_catch_vfork
6103 /* Implement the "insert" breakpoint_ops method for syscall
6107 insert_catch_syscall (struct breakpoint *b)
6109 struct inferior *inf = current_inferior ();
6111 ++inf->total_syscalls_count;
6112 if (!b->syscalls_to_be_caught)
6113 ++inf->any_syscall_count;
6119 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6124 if (iter >= VEC_length (int, inf->syscalls_counts))
6126 int old_size = VEC_length (int, inf->syscalls_counts);
6127 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
6129 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6130 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6132 memset ((void *) vec_addr, 0,
6133 (iter + 1 - old_size) * sizeof (int));
6135 elem = VEC_index (int, inf->syscalls_counts, iter);
6136 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6140 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6141 inf->total_syscalls_count != 0,
6142 inf->any_syscall_count,
6143 VEC_length (int, inf->syscalls_counts),
6144 VEC_address (int, inf->syscalls_counts));
6147 /* Implement the "remove" breakpoint_ops method for syscall
6151 remove_catch_syscall (struct breakpoint *b)
6153 struct inferior *inf = current_inferior ();
6155 --inf->total_syscalls_count;
6156 if (!b->syscalls_to_be_caught)
6157 --inf->any_syscall_count;
6163 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6167 if (iter >= VEC_length (int, inf->syscalls_counts))
6168 /* Shouldn't happen. */
6170 elem = VEC_index (int, inf->syscalls_counts, iter);
6171 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6175 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6176 inf->total_syscalls_count != 0,
6177 inf->any_syscall_count,
6178 VEC_length (int, inf->syscalls_counts),
6179 VEC_address (int, inf->syscalls_counts));
6182 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6186 breakpoint_hit_catch_syscall (struct breakpoint *b)
6188 /* We must check if we are catching specific syscalls in this breakpoint.
6189 If we are, then we must guarantee that the called syscall is the same
6190 syscall we are catching. */
6191 int syscall_number = 0;
6193 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6196 /* Now, checking if the syscall is the same. */
6197 if (b->syscalls_to_be_caught)
6202 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6204 if (syscall_number == iter)
6214 /* Implement the "print_it" breakpoint_ops method for syscall
6217 static enum print_stop_action
6218 print_it_catch_syscall (struct breakpoint *b)
6220 /* These are needed because we want to know in which state a
6221 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6222 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6223 must print "called syscall" or "returned from syscall". */
6225 struct target_waitstatus last;
6227 struct cleanup *old_chain;
6230 get_last_target_status (&ptid, &last);
6232 get_syscall_by_number (last.value.syscall_number, &s);
6234 annotate_catchpoint (b->number);
6237 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6239 syscall_id = xstrprintf ("'%s'", s.name);
6241 old_chain = make_cleanup (xfree, syscall_id);
6243 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6244 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6245 b->number, syscall_id);
6246 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6247 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6248 b->number, syscall_id);
6250 do_cleanups (old_chain);
6252 return PRINT_SRC_AND_LOC;
6255 /* Implement the "print_one" breakpoint_ops method for syscall
6259 print_one_catch_syscall (struct breakpoint *b,
6260 struct bp_location **last_loc)
6262 struct value_print_options opts;
6264 get_user_print_options (&opts);
6265 /* Field 4, the address, is omitted (which makes the columns
6266 not line up too nicely with the headers, but the effect
6267 is relatively readable). */
6268 if (opts.addressprint)
6269 ui_out_field_skip (uiout, "addr");
6272 if (b->syscalls_to_be_caught
6273 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6274 ui_out_text (uiout, "syscalls \"");
6276 ui_out_text (uiout, "syscall \"");
6278 if (b->syscalls_to_be_caught)
6281 char *text = xstrprintf ("%s", "");
6284 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6289 get_syscall_by_number (iter, &s);
6292 text = xstrprintf ("%s%s, ", text, s.name);
6294 text = xstrprintf ("%s%d, ", text, iter);
6296 /* We have to xfree the last 'text' (now stored at 'x')
6297 because xstrprintf dinamically allocates new space for it
6301 /* Remove the last comma. */
6302 text[strlen (text) - 2] = '\0';
6303 ui_out_field_string (uiout, "what", text);
6306 ui_out_field_string (uiout, "what", "<any syscall>");
6307 ui_out_text (uiout, "\" ");
6310 /* Implement the "print_mention" breakpoint_ops method for syscall
6314 print_mention_catch_syscall (struct breakpoint *b)
6316 if (b->syscalls_to_be_caught)
6320 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6321 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6323 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6326 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6330 get_syscall_by_number (iter, &s);
6333 printf_filtered (" '%s' [%d]", s.name, s.number);
6335 printf_filtered (" %d", s.number);
6337 printf_filtered (")");
6340 printf_filtered (_("Catchpoint %d (any syscall)"),
6344 /* Implement the "print_recreate" breakpoint_ops method for syscall
6348 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6350 fprintf_unfiltered (fp, "catch syscall");
6352 if (b->syscalls_to_be_caught)
6357 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6362 get_syscall_by_number (iter, &s);
6364 fprintf_unfiltered (fp, " %s", s.name);
6366 fprintf_unfiltered (fp, " %d", s.number);
6371 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6373 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6375 insert_catch_syscall,
6376 remove_catch_syscall,
6377 breakpoint_hit_catch_syscall,
6378 print_it_catch_syscall,
6379 print_one_catch_syscall,
6380 print_mention_catch_syscall,
6381 print_recreate_catch_syscall
6384 /* Returns non-zero if 'b' is a syscall catchpoint. */
6387 syscall_catchpoint_p (struct breakpoint *b)
6389 return (b->ops == &catch_syscall_breakpoint_ops);
6392 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6393 but does NOT mention it nor update the global location list.
6394 This is useful if you need to fill more fields in the
6395 struct breakpoint before calling mention.
6397 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6398 If COND_STRING is not NULL, then store it in the breakpoint.
6399 OPS, if not NULL, is the breakpoint_ops structure associated
6400 to the catchpoint. */
6402 static struct breakpoint *
6403 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6405 struct breakpoint_ops *ops)
6407 struct symtab_and_line sal;
6408 struct breakpoint *b;
6411 sal.pspace = current_program_space;
6413 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6414 set_breakpoint_count (breakpoint_count + 1);
6415 b->number = breakpoint_count;
6417 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6419 b->addr_string = NULL;
6420 b->enable_state = bp_enabled;
6421 b->disposition = tempflag ? disp_del : disp_donttouch;
6427 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6429 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6430 If COND_STRING is not NULL, then store it in the breakpoint.
6431 OPS, if not NULL, is the breakpoint_ops structure associated
6432 to the catchpoint. */
6434 static struct breakpoint *
6435 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6436 char *cond_string, struct breakpoint_ops *ops)
6438 struct breakpoint *b =
6439 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6442 update_global_location_list (1);
6448 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6449 int tempflag, char *cond_string,
6450 struct breakpoint_ops *ops)
6452 struct breakpoint *b
6453 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6455 /* FIXME: We should put this information in a breakpoint private data
6457 b->forked_inferior_pid = null_ptid;
6460 /* Exec catchpoints. */
6463 insert_catch_exec (struct breakpoint *b)
6465 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6469 remove_catch_exec (struct breakpoint *b)
6471 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6475 breakpoint_hit_catch_exec (struct breakpoint *b)
6477 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6480 static enum print_stop_action
6481 print_it_catch_exec (struct breakpoint *b)
6483 annotate_catchpoint (b->number);
6484 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6486 return PRINT_SRC_AND_LOC;
6490 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6492 struct value_print_options opts;
6494 get_user_print_options (&opts);
6496 /* Field 4, the address, is omitted (which makes the columns
6497 not line up too nicely with the headers, but the effect
6498 is relatively readable). */
6499 if (opts.addressprint)
6500 ui_out_field_skip (uiout, "addr");
6502 ui_out_text (uiout, "exec");
6503 if (b->exec_pathname != NULL)
6505 ui_out_text (uiout, ", program \"");
6506 ui_out_field_string (uiout, "what", b->exec_pathname);
6507 ui_out_text (uiout, "\" ");
6512 print_mention_catch_exec (struct breakpoint *b)
6514 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6517 /* Implement the "print_recreate" breakpoint_ops method for exec
6521 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6523 fprintf_unfiltered (fp, "catch exec");
6526 static struct breakpoint_ops catch_exec_breakpoint_ops =
6530 breakpoint_hit_catch_exec,
6531 print_it_catch_exec,
6532 print_one_catch_exec,
6533 print_mention_catch_exec,
6534 print_recreate_catch_exec
6538 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6539 struct breakpoint_ops *ops)
6541 struct gdbarch *gdbarch = get_current_arch ();
6542 struct breakpoint *b =
6543 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6545 b->syscalls_to_be_caught = filter;
6547 /* Now, we have to mention the breakpoint and update the global
6550 update_global_location_list (1);
6554 hw_breakpoint_used_count (void)
6556 struct breakpoint *b;
6561 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6569 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6571 struct breakpoint *b;
6574 *other_type_used = 0;
6577 if (breakpoint_enabled (b))
6579 if (b->type == type)
6581 else if (is_hardware_watchpoint (b))
6582 *other_type_used = 1;
6589 disable_watchpoints_before_interactive_call_start (void)
6591 struct breakpoint *b;
6595 if (is_watchpoint (b) && breakpoint_enabled (b))
6597 b->enable_state = bp_call_disabled;
6598 update_global_location_list (0);
6604 enable_watchpoints_after_interactive_call_stop (void)
6606 struct breakpoint *b;
6610 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6612 b->enable_state = bp_enabled;
6613 update_global_location_list (1);
6619 disable_breakpoints_before_startup (void)
6621 struct breakpoint *b;
6626 if (b->pspace != current_program_space)
6629 if ((b->type == bp_breakpoint
6630 || b->type == bp_hardware_breakpoint)
6631 && breakpoint_enabled (b))
6633 b->enable_state = bp_startup_disabled;
6639 update_global_location_list (0);
6641 current_program_space->executing_startup = 1;
6645 enable_breakpoints_after_startup (void)
6647 struct breakpoint *b;
6650 current_program_space->executing_startup = 0;
6654 if (b->pspace != current_program_space)
6657 if ((b->type == bp_breakpoint
6658 || b->type == bp_hardware_breakpoint)
6659 && b->enable_state == bp_startup_disabled)
6661 b->enable_state = bp_enabled;
6667 breakpoint_re_set ();
6671 /* Set a breakpoint that will evaporate an end of command
6672 at address specified by SAL.
6673 Restrict it to frame FRAME if FRAME is nonzero. */
6676 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6677 struct frame_id frame_id, enum bptype type)
6679 struct breakpoint *b;
6681 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6683 gdb_assert (!frame_id_inlined_p (frame_id));
6685 b = set_raw_breakpoint (gdbarch, sal, type);
6686 b->enable_state = bp_enabled;
6687 b->disposition = disp_donttouch;
6688 b->frame_id = frame_id;
6690 /* If we're debugging a multi-threaded program, then we
6691 want momentary breakpoints to be active in only a
6692 single thread of control. */
6693 if (in_thread_list (inferior_ptid))
6694 b->thread = pid_to_thread_id (inferior_ptid);
6696 update_global_location_list_nothrow (1);
6701 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6705 clone_momentary_breakpoint (struct breakpoint *orig)
6707 struct breakpoint *copy;
6709 /* If there's nothing to clone, then return nothing. */
6713 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6714 copy->loc = allocate_bp_location (copy);
6715 set_breakpoint_location_function (copy->loc);
6717 copy->loc->gdbarch = orig->loc->gdbarch;
6718 copy->loc->requested_address = orig->loc->requested_address;
6719 copy->loc->address = orig->loc->address;
6720 copy->loc->section = orig->loc->section;
6721 copy->loc->pspace = orig->loc->pspace;
6723 if (orig->source_file == NULL)
6724 copy->source_file = NULL;
6726 copy->source_file = xstrdup (orig->source_file);
6728 copy->line_number = orig->line_number;
6729 copy->frame_id = orig->frame_id;
6730 copy->thread = orig->thread;
6731 copy->pspace = orig->pspace;
6733 copy->enable_state = bp_enabled;
6734 copy->disposition = disp_donttouch;
6735 copy->number = internal_breakpoint_number--;
6737 update_global_location_list_nothrow (0);
6742 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6745 struct symtab_and_line sal;
6747 sal = find_pc_line (pc, 0);
6749 sal.section = find_pc_overlay (pc);
6750 sal.explicit_pc = 1;
6752 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6756 /* Tell the user we have just set a breakpoint B. */
6759 mention (struct breakpoint *b)
6762 struct cleanup *ui_out_chain;
6763 struct value_print_options opts;
6765 get_user_print_options (&opts);
6767 /* FIXME: This is misplaced; mention() is called by things (like
6768 hitting a watchpoint) other than breakpoint creation. It should
6769 be possible to clean this up and at the same time replace the
6770 random calls to breakpoint_changed with this hook. */
6771 observer_notify_breakpoint_created (b->number);
6773 if (b->ops != NULL && b->ops->print_mention != NULL)
6774 b->ops->print_mention (b);
6779 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
6782 ui_out_text (uiout, "Watchpoint ");
6783 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6784 ui_out_field_int (uiout, "number", b->number);
6785 ui_out_text (uiout, ": ");
6786 ui_out_field_string (uiout, "exp", b->exp_string);
6787 do_cleanups (ui_out_chain);
6789 case bp_hardware_watchpoint:
6790 ui_out_text (uiout, "Hardware watchpoint ");
6791 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6792 ui_out_field_int (uiout, "number", b->number);
6793 ui_out_text (uiout, ": ");
6794 ui_out_field_string (uiout, "exp", b->exp_string);
6795 do_cleanups (ui_out_chain);
6797 case bp_read_watchpoint:
6798 ui_out_text (uiout, "Hardware read watchpoint ");
6799 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6800 ui_out_field_int (uiout, "number", b->number);
6801 ui_out_text (uiout, ": ");
6802 ui_out_field_string (uiout, "exp", b->exp_string);
6803 do_cleanups (ui_out_chain);
6805 case bp_access_watchpoint:
6806 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6807 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6808 ui_out_field_int (uiout, "number", b->number);
6809 ui_out_text (uiout, ": ");
6810 ui_out_field_string (uiout, "exp", b->exp_string);
6811 do_cleanups (ui_out_chain);
6814 if (ui_out_is_mi_like_p (uiout))
6819 if (b->disposition == disp_del)
6820 printf_filtered (_("Temporary breakpoint"));
6822 printf_filtered (_("Breakpoint"));
6823 printf_filtered (_(" %d"), b->number);
6826 case bp_hardware_breakpoint:
6827 if (ui_out_is_mi_like_p (uiout))
6832 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6836 if (ui_out_is_mi_like_p (uiout))
6841 printf_filtered (_("Tracepoint"));
6842 printf_filtered (_(" %d"), b->number);
6845 case bp_fast_tracepoint:
6846 if (ui_out_is_mi_like_p (uiout))
6851 printf_filtered (_("Fast tracepoint"));
6852 printf_filtered (_(" %d"), b->number);
6855 case bp_static_tracepoint:
6856 if (ui_out_is_mi_like_p (uiout))
6861 printf_filtered (_("Static tracepoint"));
6862 printf_filtered (_(" %d"), b->number);
6869 case bp_longjmp_resume:
6871 case bp_exception_resume:
6872 case bp_step_resume:
6874 case bp_std_terminate:
6875 case bp_watchpoint_scope:
6876 case bp_shlib_event:
6877 case bp_thread_event:
6878 case bp_overlay_event:
6880 case bp_longjmp_master:
6881 case bp_std_terminate_master:
6882 case bp_exception_master:
6888 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6892 printf_filtered (_(" (%s) pending."), b->addr_string);
6896 if (opts.addressprint || b->source_file == NULL)
6898 printf_filtered (" at ");
6899 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
6903 printf_filtered (": file %s, line %d.",
6904 b->source_file, b->line_number);
6908 struct bp_location *loc = b->loc;
6910 for (; loc; loc = loc->next)
6912 printf_filtered (" (%d locations)", n);
6917 if (ui_out_is_mi_like_p (uiout))
6919 printf_filtered ("\n");
6923 static struct bp_location *
6924 add_location_to_breakpoint (struct breakpoint *b,
6925 const struct symtab_and_line *sal)
6927 struct bp_location *loc, **tmp;
6929 loc = allocate_bp_location (b);
6930 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
6933 loc->gdbarch = get_sal_arch (*sal);
6935 loc->gdbarch = b->gdbarch;
6936 loc->requested_address = sal->pc;
6937 loc->address = adjust_breakpoint_address (loc->gdbarch,
6938 loc->requested_address, b->type);
6939 loc->pspace = sal->pspace;
6940 gdb_assert (loc->pspace != NULL);
6941 loc->section = sal->section;
6943 set_breakpoint_location_function (loc);
6948 /* Return 1 if LOC is pointing to a permanent breakpoint,
6949 return 0 otherwise. */
6952 bp_loc_is_permanent (struct bp_location *loc)
6956 const gdb_byte *brk;
6957 gdb_byte *target_mem;
6958 struct cleanup *cleanup;
6961 gdb_assert (loc != NULL);
6963 addr = loc->address;
6964 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6966 /* Software breakpoints unsupported? */
6970 target_mem = alloca (len);
6972 /* Enable the automatic memory restoration from breakpoints while
6973 we read the memory. Otherwise we could say about our temporary
6974 breakpoints they are permanent. */
6975 cleanup = save_current_space_and_thread ();
6977 switch_to_program_space_and_thread (loc->pspace);
6978 make_show_memory_breakpoints_cleanup (0);
6980 if (target_read_memory (loc->address, target_mem, len) == 0
6981 && memcmp (target_mem, brk, len) == 0)
6984 do_cleanups (cleanup);
6991 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6992 as textual description of the location, and COND_STRING
6993 as condition expression. */
6996 create_breakpoint_sal (struct gdbarch *gdbarch,
6997 struct symtabs_and_lines sals, char *addr_string,
6999 enum bptype type, enum bpdisp disposition,
7000 int thread, int task, int ignore_count,
7001 struct breakpoint_ops *ops, int from_tty,
7002 int enabled, int internal)
7004 struct breakpoint *b = NULL;
7007 if (type == bp_hardware_breakpoint)
7009 int i = hw_breakpoint_used_count ();
7010 int target_resources_ok =
7011 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7013 if (target_resources_ok == 0)
7014 error (_("No hardware breakpoint support in the target."));
7015 else if (target_resources_ok < 0)
7016 error (_("Hardware breakpoints used exceeds limit."));
7019 gdb_assert (sals.nelts > 0);
7021 for (i = 0; i < sals.nelts; ++i)
7023 struct symtab_and_line sal = sals.sals[i];
7024 struct bp_location *loc;
7028 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7030 loc_gdbarch = gdbarch;
7032 describe_other_breakpoints (loc_gdbarch,
7033 sal.pspace, sal.pc, sal.section, thread);
7038 b = set_raw_breakpoint (gdbarch, sal, type);
7039 set_breakpoint_number (internal, b);
7043 b->cond_string = cond_string;
7044 b->ignore_count = ignore_count;
7045 b->enable_state = enabled ? bp_enabled : bp_disabled;
7046 b->disposition = disposition;
7047 b->pspace = sals.sals[0].pspace;
7049 if (type == bp_static_tracepoint)
7051 struct static_tracepoint_marker marker;
7053 if (is_marker_spec (addr_string))
7055 /* We already know the marker exists, otherwise, we
7056 wouldn't see a sal for it. */
7057 char *p = &addr_string[3];
7062 while (*p == ' ' || *p == '\t')
7066 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7069 marker_str = savestring (p, endp - p);
7070 b->static_trace_marker_id = marker_str;
7072 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7073 b->static_trace_marker_id);
7075 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7077 b->static_trace_marker_id = xstrdup (marker.str_id);
7078 release_static_tracepoint_marker (&marker);
7080 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7081 b->static_trace_marker_id);
7085 Couldn't determine the static tracepoint marker to probe"));
7088 if (enabled && b->pspace->executing_startup
7089 && (b->type == bp_breakpoint
7090 || b->type == bp_hardware_breakpoint))
7091 b->enable_state = bp_startup_disabled;
7097 loc = add_location_to_breakpoint (b, &sal);
7100 if (bp_loc_is_permanent (loc))
7101 make_breakpoint_permanent (b);
7105 char *arg = b->cond_string;
7106 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7108 error (_("Garbage %s follows condition"), arg);
7113 b->addr_string = addr_string;
7115 /* addr_string has to be used or breakpoint_re_set will delete
7118 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7122 /* Do not mention breakpoints with a negative number, but do
7123 notify observers. */
7124 observer_notify_breakpoint_created (b->number);
7129 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7130 elements to fill the void space. */
7132 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7134 int i = index_to_remove+1;
7135 int last_index = sal->nelts-1;
7137 for (;i <= last_index; ++i)
7138 sal->sals[i-1] = sal->sals[i];
7143 /* If appropriate, obtains all sals that correspond to the same file
7144 and line as SAL, in all program spaces. Users debugging with IDEs,
7145 will want to set a breakpoint at foo.c:line, and not really care
7146 about program spaces. This is done only if SAL does not have
7147 explicit PC and has line and file information. If we got just a
7148 single expanded sal, return the original.
7150 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7151 which the name of enclosing function is different from SAL. This
7152 makes sure that if we have breakpoint originally set in template
7153 instantiation, say foo<int>(), we won't expand SAL to locations at
7154 the same line in all existing instantiations of 'foo'. */
7156 static struct symtabs_and_lines
7157 expand_line_sal_maybe (struct symtab_and_line sal)
7159 struct symtabs_and_lines expanded;
7160 CORE_ADDR original_pc = sal.pc;
7161 char *original_function = NULL;
7164 struct cleanup *old_chain;
7166 /* If we have explicit pc, don't expand.
7167 If we have no line number, we can't expand. */
7168 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7171 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7172 expanded.sals[0] = sal;
7178 old_chain = save_current_space_and_thread ();
7180 switch_to_program_space_and_thread (sal.pspace);
7182 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7184 /* Note that expand_line_sal visits *all* program spaces. */
7185 expanded = expand_line_sal (sal);
7187 if (expanded.nelts == 1)
7189 /* We had one sal, we got one sal. Return that sal, adjusting it
7190 past the function prologue if necessary. */
7191 xfree (expanded.sals);
7193 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7194 sal.pc = original_pc;
7195 expanded.sals[0] = sal;
7196 skip_prologue_sal (&expanded.sals[0]);
7197 do_cleanups (old_chain);
7201 if (!sal.explicit_line)
7203 CORE_ADDR func_addr, func_end;
7204 for (i = 0; i < expanded.nelts; ++i)
7206 CORE_ADDR pc = expanded.sals[i].pc;
7207 char *this_function;
7209 /* We need to switch threads as well since we're about to
7211 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7213 if (find_pc_partial_function (pc, &this_function,
7214 &func_addr, &func_end))
7217 && strcmp (this_function, original_function) != 0)
7219 remove_sal (&expanded, i);
7226 /* Skip the function prologue if necessary. */
7227 for (i = 0; i < expanded.nelts; ++i)
7228 skip_prologue_sal (&expanded.sals[i]);
7230 do_cleanups (old_chain);
7232 if (expanded.nelts <= 1)
7234 /* This is un ugly workaround. If we get zero
7235 expanded sals then something is really wrong.
7236 Fix that by returnign the original sal. */
7237 xfree (expanded.sals);
7239 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7240 sal.pc = original_pc;
7241 expanded.sals[0] = sal;
7248 for (i = 0; i < expanded.nelts; ++i)
7249 if (expanded.sals[i].pc == original_pc)
7260 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7261 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7262 value. COND_STRING, if not NULL, specified the condition to be
7263 used for all breakpoints. Essentially the only case where
7264 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7265 function. In that case, it's still not possible to specify
7266 separate conditions for different overloaded functions, so
7267 we take just a single condition string.
7269 NOTE: If the function succeeds, the caller is expected to cleanup
7270 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7271 array contents). If the function fails (error() is called), the
7272 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7273 COND and SALS arrays and each of those arrays contents. */
7276 create_breakpoints_sal (struct gdbarch *gdbarch,
7277 struct symtabs_and_lines sals, char **addr_string,
7279 enum bptype type, enum bpdisp disposition,
7280 int thread, int task, int ignore_count,
7281 struct breakpoint_ops *ops, int from_tty,
7282 int enabled, int internal)
7286 for (i = 0; i < sals.nelts; ++i)
7288 struct symtabs_and_lines expanded =
7289 expand_line_sal_maybe (sals.sals[i]);
7291 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7292 cond_string, type, disposition,
7293 thread, task, ignore_count, ops,
7294 from_tty, enabled, internal);
7298 /* Parse ARG which is assumed to be a SAL specification possibly
7299 followed by conditionals. On return, SALS contains an array of SAL
7300 addresses found. ADDR_STRING contains a vector of (canonical)
7301 address strings. ARG points to the end of the SAL. */
7304 parse_breakpoint_sals (char **address,
7305 struct symtabs_and_lines *sals,
7306 char ***addr_string,
7309 char *addr_start = *address;
7311 *addr_string = NULL;
7312 /* If no arg given, or if first arg is 'if ', use the default
7314 if ((*address) == NULL
7315 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7317 if (default_breakpoint_valid)
7319 struct symtab_and_line sal;
7321 init_sal (&sal); /* initialize to zeroes */
7322 sals->sals = (struct symtab_and_line *)
7323 xmalloc (sizeof (struct symtab_and_line));
7324 sal.pc = default_breakpoint_address;
7325 sal.line = default_breakpoint_line;
7326 sal.symtab = default_breakpoint_symtab;
7327 sal.pspace = default_breakpoint_pspace;
7328 sal.section = find_pc_overlay (sal.pc);
7330 /* "break" without arguments is equivalent to "break *PC" where PC is
7331 the default_breakpoint_address. So make sure to set
7332 sal.explicit_pc to prevent GDB from trying to expand the list of
7333 sals to include all other instances with the same symtab and line.
7335 sal.explicit_pc = 1;
7337 sals->sals[0] = sal;
7341 error (_("No default breakpoint address now."));
7345 /* Force almost all breakpoints to be in terms of the
7346 current_source_symtab (which is decode_line_1's default). This
7347 should produce the results we want almost all of the time while
7348 leaving default_breakpoint_* alone.
7349 ObjC: However, don't match an Objective-C method name which
7350 may have a '+' or '-' succeeded by a '[' */
7352 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7354 if (default_breakpoint_valid
7356 || ((strchr ("+-", (*address)[0]) != NULL)
7357 && ((*address)[1] != '['))))
7358 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7359 default_breakpoint_line, addr_string,
7362 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7363 addr_string, not_found_ptr);
7365 /* For any SAL that didn't have a canonical string, fill one in. */
7366 if (sals->nelts > 0 && *addr_string == NULL)
7367 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7368 if (addr_start != (*address))
7372 for (i = 0; i < sals->nelts; i++)
7374 /* Add the string if not present. */
7375 if ((*addr_string)[i] == NULL)
7376 (*addr_string)[i] = savestring (addr_start,
7377 (*address) - addr_start);
7383 /* Convert each SAL into a real PC. Verify that the PC can be
7384 inserted as a breakpoint. If it can't throw an error. */
7387 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7391 for (i = 0; i < sals->nelts; i++)
7392 resolve_sal_pc (&sals->sals[i]);
7395 /* Fast tracepoints may have restrictions on valid locations. For
7396 instance, a fast tracepoint using a jump instead of a trap will
7397 likely have to overwrite more bytes than a trap would, and so can
7398 only be placed where the instruction is longer than the jump, or a
7399 multi-instruction sequence does not have a jump into the middle of
7403 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7404 struct symtabs_and_lines *sals)
7407 struct symtab_and_line *sal;
7409 struct cleanup *old_chain;
7411 for (i = 0; i < sals->nelts; i++)
7413 sal = &sals->sals[i];
7415 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7417 old_chain = make_cleanup (xfree, msg);
7420 error (_("May not have a fast tracepoint at 0x%s%s"),
7421 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7423 do_cleanups (old_chain);
7428 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7430 struct captured_parse_breakpoint_args *args = data;
7432 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7433 args->not_found_ptr);
7436 /* Given TOK, a string specification of condition and thread, as
7437 accepted by the 'break' command, extract the condition
7438 string and thread number and set *COND_STRING and *THREAD.
7439 PC identifies the context at which the condition should be parsed.
7440 If no condition is found, *COND_STRING is set to NULL.
7441 If no thread is found, *THREAD is set to -1. */
7443 find_condition_and_thread (char *tok, CORE_ADDR pc,
7444 char **cond_string, int *thread, int *task)
7446 *cond_string = NULL;
7452 char *cond_start = NULL;
7453 char *cond_end = NULL;
7455 while (*tok == ' ' || *tok == '\t')
7460 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7463 toklen = end_tok - tok;
7465 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7467 struct expression *expr;
7469 tok = cond_start = end_tok + 1;
7470 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7473 *cond_string = savestring (cond_start,
7474 cond_end - cond_start);
7476 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7482 *thread = strtol (tok, &tok, 0);
7484 error (_("Junk after thread keyword."));
7485 if (!valid_thread_id (*thread))
7486 error (_("Unknown thread %d."), *thread);
7488 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7494 *task = strtol (tok, &tok, 0);
7496 error (_("Junk after task keyword."));
7497 if (!valid_task_id (*task))
7498 error (_("Unknown task %d."), *task);
7501 error (_("Junk at end of arguments."));
7505 /* Decode a static tracepoint marker spec. */
7507 static struct symtabs_and_lines
7508 decode_static_tracepoint_spec (char **arg_p)
7510 VEC(static_tracepoint_marker_p) *markers = NULL;
7511 struct symtabs_and_lines sals;
7512 struct symtab_and_line sal;
7514 struct cleanup *old_chain;
7515 char *p = &(*arg_p)[3];
7520 while (*p == ' ' || *p == '\t')
7524 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7527 marker_str = savestring (p, endp - p);
7528 old_chain = make_cleanup (xfree, marker_str);
7530 markers = target_static_tracepoint_markers_by_strid (marker_str);
7531 if (VEC_empty(static_tracepoint_marker_p, markers))
7532 error (_("No known static tracepoint marker named %s"), marker_str);
7534 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7535 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7537 for (i = 0; i < sals.nelts; i++)
7539 struct static_tracepoint_marker *marker;
7541 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7543 init_sal (&sals.sals[i]);
7545 sals.sals[i] = find_pc_line (marker->address, 0);
7546 sals.sals[i].pc = marker->address;
7548 release_static_tracepoint_marker (marker);
7551 do_cleanups (old_chain);
7557 /* Set a breakpoint. This function is shared between CLI and MI
7558 functions for setting a breakpoint. This function has two major
7559 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7560 parameter. If non-zero, the function will parse arg, extracting
7561 breakpoint location, address and thread. Otherwise, ARG is just the
7562 location of breakpoint, with condition and thread specified by the
7563 COND_STRING and THREAD parameters. If INTERNAL is non-zero, the
7564 breakpoint number will be allocated from the internal breakpoint
7565 count. Returns true if any breakpoint was created; false
7569 create_breakpoint (struct gdbarch *gdbarch,
7570 char *arg, char *cond_string, int thread,
7571 int parse_condition_and_thread,
7572 int tempflag, enum bptype type_wanted,
7574 enum auto_boolean pending_break_support,
7575 struct breakpoint_ops *ops,
7576 int from_tty, int enabled, int internal)
7578 struct gdb_exception e;
7579 struct symtabs_and_lines sals;
7580 struct symtab_and_line pending_sal;
7582 char *addr_start = arg;
7584 struct cleanup *old_chain;
7585 struct cleanup *bkpt_chain = NULL;
7586 struct captured_parse_breakpoint_args parse_args;
7591 int prev_bkpt_count = breakpoint_count;
7597 parse_args.arg_p = &arg;
7598 parse_args.sals_p = &sals;
7599 parse_args.addr_string_p = &addr_string;
7600 parse_args.not_found_ptr = ¬_found;
7602 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7606 sals = decode_static_tracepoint_spec (&arg);
7608 copy_arg = savestring (addr_start, arg - addr_start);
7609 addr_string = xcalloc (sals.nelts, sizeof (char **));
7610 for (i = 0; i < sals.nelts; i++)
7611 addr_string[i] = xstrdup (copy_arg);
7615 e = catch_exception (uiout, do_captured_parse_breakpoint,
7616 &parse_args, RETURN_MASK_ALL);
7618 /* If caller is interested in rc value from parse, set value. */
7622 throw_exception (e);
7626 case NOT_FOUND_ERROR:
7628 /* If pending breakpoint support is turned off, throw
7631 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7632 throw_exception (e);
7634 exception_print (gdb_stderr, e);
7636 /* If pending breakpoint support is auto query and the user
7637 selects no, then simply return the error code. */
7638 if (pending_break_support == AUTO_BOOLEAN_AUTO
7639 && !nquery (_("Make breakpoint pending on future shared library load? ")))
7642 /* At this point, either the user was queried about setting
7643 a pending breakpoint and selected yes, or pending
7644 breakpoint behavior is on and thus a pending breakpoint
7645 is defaulted on behalf of the user. */
7646 copy_arg = xstrdup (addr_start);
7647 addr_string = ©_arg;
7649 sals.sals = &pending_sal;
7654 throw_exception (e);
7663 /* Create a chain of things that always need to be cleaned up. */
7664 old_chain = make_cleanup (null_cleanup, 0);
7668 /* Make sure that all storage allocated to SALS gets freed. */
7669 make_cleanup (xfree, sals.sals);
7671 /* Cleanup the addr_string array but not its contents. */
7672 make_cleanup (xfree, addr_string);
7675 /* ----------------------------- SNIP -----------------------------
7676 Anything added to the cleanup chain beyond this point is assumed
7677 to be part of a breakpoint. If the breakpoint create succeeds
7678 then the memory is not reclaimed. */
7679 bkpt_chain = make_cleanup (null_cleanup, 0);
7681 /* Mark the contents of the addr_string for cleanup. These go on
7682 the bkpt_chain and only occur if the breakpoint create fails. */
7683 for (i = 0; i < sals.nelts; i++)
7685 if (addr_string[i] != NULL)
7686 make_cleanup (xfree, addr_string[i]);
7689 /* Resolve all line numbers to PC's and verify that the addresses
7690 are ok for the target. */
7692 breakpoint_sals_to_pc (&sals);
7694 /* Fast tracepoints may have additional restrictions on location. */
7695 if (type_wanted == bp_fast_tracepoint)
7696 check_fast_tracepoint_sals (gdbarch, &sals);
7698 /* Verify that condition can be parsed, before setting any
7699 breakpoints. Allocate a separate condition expression for each
7703 if (parse_condition_and_thread)
7705 /* Here we only parse 'arg' to separate condition
7706 from thread number, so parsing in context of first
7707 sal is OK. When setting the breakpoint we'll
7708 re-parse it in context of each sal. */
7711 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7714 make_cleanup (xfree, cond_string);
7718 /* Create a private copy of condition string. */
7721 cond_string = xstrdup (cond_string);
7722 make_cleanup (xfree, cond_string);
7726 /* If the user is creating a static tracepoint by marker id
7727 (strace -m MARKER_ID), then store the sals index, so that
7728 breakpoint_re_set can try to match up which of the newly
7729 found markers corresponds to this one, and, don't try to
7730 expand multiple locations for each sal, given than SALS
7731 already should contain all sals for MARKER_ID. */
7732 if (type_wanted == bp_static_tracepoint
7733 && is_marker_spec (addr_string[0]))
7737 for (i = 0; i < sals.nelts; ++i)
7739 struct symtabs_and_lines expanded;
7740 struct breakpoint *tp;
7741 struct cleanup *old_chain;
7744 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7745 expanded.sals[0] = sals.sals[i];
7746 old_chain = make_cleanup (xfree, expanded.sals);
7748 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7749 cond_string, type_wanted,
7750 tempflag ? disp_del : disp_donttouch,
7751 thread, task, ignore_count, ops,
7752 from_tty, enabled, internal);
7754 do_cleanups (old_chain);
7756 /* Get the tracepoint we just created. */
7758 tp = get_breakpoint (internal_breakpoint_number);
7760 tp = get_breakpoint (breakpoint_count);
7761 gdb_assert (tp != NULL);
7763 /* Given that its possible to have multiple markers with
7764 the same string id, if the user is creating a static
7765 tracepoint by marker id ("strace -m MARKER_ID"), then
7766 store the sals index, so that breakpoint_re_set can
7767 try to match up which of the newly found markers
7768 corresponds to this one */
7769 tp->static_trace_marker_id_idx = i;
7773 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7774 type_wanted, tempflag ? disp_del : disp_donttouch,
7775 thread, task, ignore_count, ops, from_tty,
7780 struct breakpoint *b;
7782 make_cleanup (xfree, copy_arg);
7784 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7785 set_breakpoint_number (internal, b);
7787 b->addr_string = addr_string[0];
7788 b->cond_string = NULL;
7789 b->ignore_count = ignore_count;
7790 b->disposition = tempflag ? disp_del : disp_donttouch;
7791 b->condition_not_parsed = 1;
7793 b->enable_state = enabled ? bp_enabled : bp_disabled;
7794 b->pspace = current_program_space;
7795 b->py_bp_object = NULL;
7797 if (enabled && b->pspace->executing_startup
7798 && (b->type == bp_breakpoint
7799 || b->type == bp_hardware_breakpoint))
7800 b->enable_state = bp_startup_disabled;
7803 /* Do not mention breakpoints with a negative number,
7804 but do notify observers. */
7805 observer_notify_breakpoint_created (b->number);
7812 warning (_("Multiple breakpoints were set.\n"
7813 "Use the \"delete\" command to delete unwanted breakpoints."));
7814 prev_breakpoint_count = prev_bkpt_count;
7817 /* That's it. Discard the cleanups for data inserted into the
7819 discard_cleanups (bkpt_chain);
7820 /* But cleanup everything else. */
7821 do_cleanups (old_chain);
7823 /* error call may happen here - have BKPT_CHAIN already discarded. */
7824 update_global_location_list (1);
7829 /* Set a breakpoint.
7830 ARG is a string describing breakpoint address,
7831 condition, and thread.
7832 FLAG specifies if a breakpoint is hardware on,
7833 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7837 break_command_1 (char *arg, int flag, int from_tty)
7839 int tempflag = flag & BP_TEMPFLAG;
7840 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
7841 ? bp_hardware_breakpoint
7844 create_breakpoint (get_current_arch (),
7846 NULL, 0, 1 /* parse arg */,
7847 tempflag, type_wanted,
7848 0 /* Ignore count */,
7849 pending_break_support,
7850 NULL /* breakpoint_ops */,
7857 /* Helper function for break_command_1 and disassemble_command. */
7860 resolve_sal_pc (struct symtab_and_line *sal)
7864 if (sal->pc == 0 && sal->symtab != NULL)
7866 if (!find_line_pc (sal->symtab, sal->line, &pc))
7867 error (_("No line %d in file \"%s\"."),
7868 sal->line, sal->symtab->filename);
7871 /* If this SAL corresponds to a breakpoint inserted using
7872 a line number, then skip the function prologue if necessary. */
7873 if (sal->explicit_line)
7874 skip_prologue_sal (sal);
7877 if (sal->section == 0 && sal->symtab != NULL)
7879 struct blockvector *bv;
7883 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7886 sym = block_linkage_function (b);
7889 fixup_symbol_section (sym, sal->symtab->objfile);
7890 sal->section = SYMBOL_OBJ_SECTION (sym);
7894 /* It really is worthwhile to have the section, so we'll just
7895 have to look harder. This case can be executed if we have
7896 line numbers but no functions (as can happen in assembly
7899 struct minimal_symbol *msym;
7900 struct cleanup *old_chain = save_current_space_and_thread ();
7902 switch_to_program_space_and_thread (sal->pspace);
7904 msym = lookup_minimal_symbol_by_pc (sal->pc);
7906 sal->section = SYMBOL_OBJ_SECTION (msym);
7908 do_cleanups (old_chain);
7915 break_command (char *arg, int from_tty)
7917 break_command_1 (arg, 0, from_tty);
7921 tbreak_command (char *arg, int from_tty)
7923 break_command_1 (arg, BP_TEMPFLAG, from_tty);
7927 hbreak_command (char *arg, int from_tty)
7929 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
7933 thbreak_command (char *arg, int from_tty)
7935 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
7939 stop_command (char *arg, int from_tty)
7941 printf_filtered (_("Specify the type of breakpoint to set.\n\
7942 Usage: stop in <function | address>\n\
7943 stop at <line>\n"));
7947 stopin_command (char *arg, int from_tty)
7951 if (arg == (char *) NULL)
7953 else if (*arg != '*')
7958 /* look for a ':'. If this is a line number specification, then
7959 say it is bad, otherwise, it should be an address or
7960 function/method name */
7961 while (*argptr && !hasColon)
7963 hasColon = (*argptr == ':');
7968 badInput = (*argptr != ':'); /* Not a class::method */
7970 badInput = isdigit (*arg); /* a simple line number */
7974 printf_filtered (_("Usage: stop in <function | address>\n"));
7976 break_command_1 (arg, 0, from_tty);
7980 stopat_command (char *arg, int from_tty)
7984 if (arg == (char *) NULL || *arg == '*') /* no line number */
7991 /* look for a ':'. If there is a '::' then get out, otherwise
7992 it is probably a line number. */
7993 while (*argptr && !hasColon)
7995 hasColon = (*argptr == ':');
8000 badInput = (*argptr == ':'); /* we have class::method */
8002 badInput = !isdigit (*arg); /* not a line number */
8006 printf_filtered (_("Usage: stop at <line>\n"));
8008 break_command_1 (arg, 0, from_tty);
8011 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
8012 variable. Also the constant detection may fail for some constant
8013 expressions and in such case still falsely return zero. */
8015 watchpoint_exp_is_const (const struct expression *exp)
8023 /* We are only interested in the descriptor of each element. */
8024 operator_length (exp, i, &oplenp, &argsp);
8027 switch (exp->elts[i].opcode)
8037 case BINOP_LOGICAL_AND:
8038 case BINOP_LOGICAL_OR:
8039 case BINOP_BITWISE_AND:
8040 case BINOP_BITWISE_IOR:
8041 case BINOP_BITWISE_XOR:
8043 case BINOP_NOTEQUAL:
8059 case TERNOP_SLICE_COUNT:
8071 case OP_OBJC_NSSTRING:
8074 case UNOP_LOGICAL_NOT:
8075 case UNOP_COMPLEMENT:
8078 /* Unary, binary and ternary operators: We have to check their
8079 operands. If they are constant, then so is the result of
8080 that operation. For instance, if A and B are determined to be
8081 constants, then so is "A + B".
8083 UNOP_IND is one exception to the rule above, because the value
8084 of *ADDR is not necessarily a constant, even when ADDR is. */
8088 /* Check whether the associated symbol is a constant.
8089 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8090 possible that a buggy compiler could mark a variable as constant
8091 even when it is not, and TYPE_CONST would return true in this
8092 case, while SYMBOL_CLASS wouldn't.
8093 We also have to check for function symbols because they are
8096 struct symbol *s = exp->elts[i + 2].symbol;
8098 if (SYMBOL_CLASS (s) != LOC_BLOCK
8099 && SYMBOL_CLASS (s) != LOC_CONST
8100 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8105 /* The default action is to return 0 because we are using
8106 the optimistic approach here: If we don't know something,
8107 then it is not a constant. */
8116 /* accessflag: hw_write: watch write,
8117 hw_read: watch read,
8118 hw_access: watch access (read or write) */
8120 watch_command_1 (char *arg, int accessflag, int from_tty,
8121 int just_location, int internal)
8123 struct breakpoint *b, *scope_breakpoint = NULL;
8124 struct expression *exp;
8125 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
8126 struct value *val, *mark, *result;
8127 struct frame_info *frame;
8128 char *exp_start = NULL;
8129 char *exp_end = NULL;
8130 char *tok, *id_tok_start, *end_tok;
8132 char *cond_start = NULL;
8133 char *cond_end = NULL;
8134 int i, other_type_used, target_resources_ok = 0;
8135 enum bptype bp_type;
8140 /* Make sure that we actually have parameters to parse. */
8141 if (arg != NULL && arg[0] != '\0')
8143 toklen = strlen (arg); /* Size of argument list. */
8145 /* Points tok to the end of the argument list. */
8146 tok = arg + toklen - 1;
8148 /* Go backwards in the parameters list. Skip the last parameter.
8149 If we're expecting a 'thread <thread_num>' parameter, this should
8150 be the thread identifier. */
8151 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8153 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8156 /* Points end_tok to the beginning of the last token. */
8157 id_tok_start = tok + 1;
8159 /* Go backwards in the parameters list. Skip one more parameter.
8160 If we're expecting a 'thread <thread_num>' parameter, we should
8161 reach a "thread" token. */
8162 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8167 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8170 /* Move the pointer forward to skip the whitespace and
8171 calculate the length of the token. */
8173 toklen = end_tok - tok;
8175 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8177 /* At this point we've found a "thread" token, which means
8178 the user is trying to set a watchpoint that triggers
8179 only in a specific thread. */
8182 /* Extract the thread ID from the next token. */
8183 thread = strtol (id_tok_start, &endp, 0);
8185 /* Check if the user provided a valid numeric value for the
8187 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
8188 error (_("Invalid thread ID specification %s."), id_tok_start);
8190 /* Check if the thread actually exists. */
8191 if (!valid_thread_id (thread))
8192 error (_("Unknown thread %d."), thread);
8194 /* Truncate the string and get rid of the thread <thread_num>
8195 parameter before the parameter list is parsed by the
8196 evaluate_expression() function. */
8201 /* Parse the rest of the arguments. */
8202 innermost_block = NULL;
8204 exp = parse_exp_1 (&arg, 0, 0);
8206 /* Remove trailing whitespace from the expression before saving it.
8207 This makes the eventual display of the expression string a bit
8209 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
8212 /* Checking if the expression is not constant. */
8213 if (watchpoint_exp_is_const (exp))
8217 len = exp_end - exp_start;
8218 while (len > 0 && isspace (exp_start[len - 1]))
8220 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
8223 exp_valid_block = innermost_block;
8224 mark = value_mark ();
8225 fetch_subexp_value (exp, &pc, &val, &result, NULL);
8229 exp_valid_block = NULL;
8230 val = value_addr (result);
8231 release_value (val);
8232 value_free_to_mark (mark);
8234 else if (val != NULL)
8235 release_value (val);
8238 while (*tok == ' ' || *tok == '\t')
8242 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
8245 toklen = end_tok - tok;
8246 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8248 struct expression *cond;
8250 innermost_block = NULL;
8251 tok = cond_start = end_tok + 1;
8252 cond = parse_exp_1 (&tok, 0, 0);
8254 /* The watchpoint expression may not be local, but the condition
8255 may still be. E.g.: `watch global if local > 0'. */
8256 cond_exp_valid_block = innermost_block;
8262 error (_("Junk at end of command."));
8264 if (accessflag == hw_read)
8265 bp_type = bp_read_watchpoint;
8266 else if (accessflag == hw_access)
8267 bp_type = bp_access_watchpoint;
8269 bp_type = bp_hardware_watchpoint;
8271 mem_cnt = can_use_hardware_watchpoint (val);
8272 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
8273 error (_("Expression cannot be implemented with read/access watchpoint."));
8276 i = hw_watchpoint_used_count (bp_type, &other_type_used);
8277 target_resources_ok =
8278 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
8280 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8281 error (_("Target does not support this type of hardware watchpoint."));
8283 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8284 error (_("Target can only support one kind of HW watchpoint at a time."));
8287 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8288 watchpoint could not be set. */
8289 if (!mem_cnt || target_resources_ok <= 0)
8290 bp_type = bp_watchpoint;
8292 frame = block_innermost_frame (exp_valid_block);
8294 /* If the expression is "local", then set up a "watchpoint scope"
8295 breakpoint at the point where we've left the scope of the watchpoint
8296 expression. Create the scope breakpoint before the watchpoint, so
8297 that we will encounter it first in bpstat_stop_status. */
8298 if (exp_valid_block && frame)
8300 if (frame_id_p (frame_unwind_caller_id (frame)))
8303 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
8304 frame_unwind_caller_pc (frame),
8305 bp_watchpoint_scope);
8307 scope_breakpoint->enable_state = bp_enabled;
8309 /* Automatically delete the breakpoint when it hits. */
8310 scope_breakpoint->disposition = disp_del;
8312 /* Only break in the proper frame (help with recursion). */
8313 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
8315 /* Set the address at which we will stop. */
8316 scope_breakpoint->loc->gdbarch
8317 = frame_unwind_caller_arch (frame);
8318 scope_breakpoint->loc->requested_address
8319 = frame_unwind_caller_pc (frame);
8320 scope_breakpoint->loc->address
8321 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
8322 scope_breakpoint->loc->requested_address,
8323 scope_breakpoint->type);
8327 /* Now set up the breakpoint. */
8328 b = set_raw_breakpoint_without_location (NULL, bp_type);
8329 set_breakpoint_number (internal, b);
8331 b->disposition = disp_donttouch;
8333 b->exp_valid_block = exp_valid_block;
8334 b->cond_exp_valid_block = cond_exp_valid_block;
8337 struct type *t = value_type (val);
8338 CORE_ADDR addr = value_as_address (val);
8341 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
8342 name = type_to_string (t);
8344 b->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
8345 core_addr_to_string (addr));
8348 b->exp_string = xstrprintf ("-location: %.*s",
8349 (int) (exp_end - exp_start), exp_start);
8351 /* The above expression is in C. */
8352 b->language = language_c;
8355 b->exp_string = savestring (exp_start, exp_end - exp_start);
8359 b->cond_string = savestring (cond_start, cond_end - cond_start);
8365 b->watchpoint_frame = get_frame_id (frame);
8366 b->watchpoint_thread = inferior_ptid;
8370 b->watchpoint_frame = null_frame_id;
8371 b->watchpoint_thread = null_ptid;
8374 if (scope_breakpoint != NULL)
8376 /* The scope breakpoint is related to the watchpoint. We will
8377 need to act on them together. */
8378 b->related_breakpoint = scope_breakpoint;
8379 scope_breakpoint->related_breakpoint = b;
8383 value_free_to_mark (mark);
8385 /* Finally update the new watchpoint. This creates the locations
8386 that should be inserted. */
8387 update_watchpoint (b, 1);
8389 /* Do not mention breakpoints with a negative number, but do
8390 notify observers. */
8391 observer_notify_breakpoint_created (b->number);
8394 update_global_location_list (1);
8397 /* Return count of locations need to be watched and can be handled
8398 in hardware. If the watchpoint can not be handled
8399 in hardware return zero. */
8402 can_use_hardware_watchpoint (struct value *v)
8404 int found_memory_cnt = 0;
8405 struct value *head = v;
8407 /* Did the user specifically forbid us to use hardware watchpoints? */
8408 if (!can_use_hw_watchpoints)
8411 /* Make sure that the value of the expression depends only upon
8412 memory contents, and values computed from them within GDB. If we
8413 find any register references or function calls, we can't use a
8414 hardware watchpoint.
8416 The idea here is that evaluating an expression generates a series
8417 of values, one holding the value of every subexpression. (The
8418 expression a*b+c has five subexpressions: a, b, a*b, c, and
8419 a*b+c.) GDB's values hold almost enough information to establish
8420 the criteria given above --- they identify memory lvalues,
8421 register lvalues, computed values, etcetera. So we can evaluate
8422 the expression, and then scan the chain of values that leaves
8423 behind to decide whether we can detect any possible change to the
8424 expression's final value using only hardware watchpoints.
8426 However, I don't think that the values returned by inferior
8427 function calls are special in any way. So this function may not
8428 notice that an expression involving an inferior function call
8429 can't be watched with hardware watchpoints. FIXME. */
8430 for (; v; v = value_next (v))
8432 if (VALUE_LVAL (v) == lval_memory)
8434 if (v != head && value_lazy (v))
8435 /* A lazy memory lvalue in the chain is one that GDB never
8436 needed to fetch; we either just used its address (e.g.,
8437 `a' in `a.b') or we never needed it at all (e.g., `a'
8438 in `a,b'). This doesn't apply to HEAD; if that is
8439 lazy then it was not readable, but watch it anyway. */
8443 /* Ahh, memory we actually used! Check if we can cover
8444 it with hardware watchpoints. */
8445 struct type *vtype = check_typedef (value_type (v));
8447 /* We only watch structs and arrays if user asked for it
8448 explicitly, never if they just happen to appear in a
8449 middle of some value chain. */
8451 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
8452 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
8454 CORE_ADDR vaddr = value_address (v);
8455 int len = TYPE_LENGTH (value_type (v));
8457 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
8464 else if (VALUE_LVAL (v) != not_lval
8465 && deprecated_value_modifiable (v) == 0)
8466 return 0; /* These are values from the history (e.g., $1). */
8467 else if (VALUE_LVAL (v) == lval_register)
8468 return 0; /* Cannot watch a register with a HW watchpoint. */
8471 /* The expression itself looks suitable for using a hardware
8472 watchpoint, but give the target machine a chance to reject it. */
8473 return found_memory_cnt;
8477 watch_command_wrapper (char *arg, int from_tty, int internal)
8479 watch_command_1 (arg, hw_write, from_tty, 0, internal);
8482 /* A helper function that looks for an argument at the start of a
8483 string. The argument must also either be at the end of the string,
8484 or be followed by whitespace. Returns 1 if it finds the argument,
8485 0 otherwise. If the argument is found, it updates *STR. */
8488 check_for_argument (char **str, char *arg, int arg_len)
8490 if (strncmp (*str, arg, arg_len) == 0
8491 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
8499 /* A helper function that looks for the "-location" argument and then
8500 calls watch_command_1. */
8503 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
8505 int just_location = 0;
8508 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
8509 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
8511 ep_skip_leading_whitespace (&arg);
8515 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
8519 watch_command (char *arg, int from_tty)
8521 watch_maybe_just_location (arg, hw_write, from_tty);
8525 rwatch_command_wrapper (char *arg, int from_tty, int internal)
8527 watch_command_1 (arg, hw_read, from_tty, 0, internal);
8531 rwatch_command (char *arg, int from_tty)
8533 watch_maybe_just_location (arg, hw_read, from_tty);
8537 awatch_command_wrapper (char *arg, int from_tty, int internal)
8539 watch_command_1 (arg, hw_access, from_tty, 0, internal);
8543 awatch_command (char *arg, int from_tty)
8545 watch_maybe_just_location (arg, hw_access, from_tty);
8549 /* Helper routines for the until_command routine in infcmd.c. Here
8550 because it uses the mechanisms of breakpoints. */
8552 struct until_break_command_continuation_args
8554 struct breakpoint *breakpoint;
8555 struct breakpoint *breakpoint2;
8559 /* This function is called by fetch_inferior_event via the
8560 cmd_continuation pointer, to complete the until command. It takes
8561 care of cleaning up the temporary breakpoints set up by the until
8564 until_break_command_continuation (void *arg)
8566 struct until_break_command_continuation_args *a = arg;
8568 delete_breakpoint (a->breakpoint);
8570 delete_breakpoint (a->breakpoint2);
8571 delete_longjmp_breakpoint (a->thread_num);
8575 until_break_command (char *arg, int from_tty, int anywhere)
8577 struct symtabs_and_lines sals;
8578 struct symtab_and_line sal;
8579 struct frame_info *frame = get_selected_frame (NULL);
8580 struct breakpoint *breakpoint;
8581 struct breakpoint *breakpoint2 = NULL;
8582 struct cleanup *old_chain;
8584 struct thread_info *tp;
8586 clear_proceed_status ();
8588 /* Set a breakpoint where the user wants it and at return from
8591 if (default_breakpoint_valid)
8592 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8593 default_breakpoint_line, (char ***) NULL, NULL);
8595 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8596 0, (char ***) NULL, NULL);
8598 if (sals.nelts != 1)
8599 error (_("Couldn't get information on specified line."));
8602 xfree (sals.sals); /* malloc'd, so freed */
8605 error (_("Junk at end of arguments."));
8607 resolve_sal_pc (&sal);
8610 /* If the user told us to continue until a specified location,
8611 we don't specify a frame at which we need to stop. */
8612 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8613 null_frame_id, bp_until);
8615 /* Otherwise, specify the selected frame, because we want to stop only
8616 at the very same frame. */
8617 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8618 get_stack_frame_id (frame),
8621 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8623 tp = inferior_thread ();
8626 /* Keep within the current frame, or in frames called by the current
8629 if (frame_id_p (frame_unwind_caller_id (frame)))
8631 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8632 sal.pc = frame_unwind_caller_pc (frame);
8633 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8635 frame_unwind_caller_id (frame),
8637 make_cleanup_delete_breakpoint (breakpoint2);
8639 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
8640 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
8643 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8645 /* If we are running asynchronously, and proceed call above has actually
8646 managed to start the target, arrange for breakpoints to be
8647 deleted when the target stops. Otherwise, we're already stopped and
8648 delete breakpoints via cleanup chain. */
8650 if (target_can_async_p () && is_running (inferior_ptid))
8652 struct until_break_command_continuation_args *args;
8653 args = xmalloc (sizeof (*args));
8655 args->breakpoint = breakpoint;
8656 args->breakpoint2 = breakpoint2;
8657 args->thread_num = thread;
8659 discard_cleanups (old_chain);
8660 add_continuation (inferior_thread (),
8661 until_break_command_continuation, args,
8665 do_cleanups (old_chain);
8669 ep_skip_leading_whitespace (char **s)
8671 if ((s == NULL) || (*s == NULL))
8673 while (isspace (**s))
8677 /* This function attempts to parse an optional "if <cond>" clause
8678 from the arg string. If one is not found, it returns NULL.
8680 Else, it returns a pointer to the condition string. (It does not
8681 attempt to evaluate the string against a particular block.) And,
8682 it updates arg to point to the first character following the parsed
8683 if clause in the arg string. */
8686 ep_parse_optional_if_clause (char **arg)
8690 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8693 /* Skip the "if" keyword. */
8696 /* Skip any extra leading whitespace, and record the start of the
8697 condition string. */
8698 ep_skip_leading_whitespace (arg);
8701 /* Assume that the condition occupies the remainder of the arg string. */
8702 (*arg) += strlen (cond_string);
8707 /* Commands to deal with catching events, such as signals, exceptions,
8708 process start/exit, etc. */
8712 catch_fork_temporary, catch_vfork_temporary,
8713 catch_fork_permanent, catch_vfork_permanent
8718 catch_fork_command_1 (char *arg, int from_tty,
8719 struct cmd_list_element *command)
8721 struct gdbarch *gdbarch = get_current_arch ();
8722 char *cond_string = NULL;
8723 catch_fork_kind fork_kind;
8726 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8727 tempflag = (fork_kind == catch_fork_temporary
8728 || fork_kind == catch_vfork_temporary);
8732 ep_skip_leading_whitespace (&arg);
8734 /* The allowed syntax is:
8736 catch [v]fork if <cond>
8738 First, check if there's an if clause. */
8739 cond_string = ep_parse_optional_if_clause (&arg);
8741 if ((*arg != '\0') && !isspace (*arg))
8742 error (_("Junk at end of arguments."));
8744 /* If this target supports it, create a fork or vfork catchpoint
8745 and enable reporting of such events. */
8748 case catch_fork_temporary:
8749 case catch_fork_permanent:
8750 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8751 &catch_fork_breakpoint_ops);
8753 case catch_vfork_temporary:
8754 case catch_vfork_permanent:
8755 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8756 &catch_vfork_breakpoint_ops);
8759 error (_("unsupported or unknown fork kind; cannot catch it"));
8765 catch_exec_command_1 (char *arg, int from_tty,
8766 struct cmd_list_element *command)
8768 struct gdbarch *gdbarch = get_current_arch ();
8770 char *cond_string = NULL;
8772 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8776 ep_skip_leading_whitespace (&arg);
8778 /* The allowed syntax is:
8780 catch exec if <cond>
8782 First, check if there's an if clause. */
8783 cond_string = ep_parse_optional_if_clause (&arg);
8785 if ((*arg != '\0') && !isspace (*arg))
8786 error (_("Junk at end of arguments."));
8788 /* If this target supports it, create an exec catchpoint
8789 and enable reporting of such events. */
8790 create_catchpoint (gdbarch, tempflag, cond_string,
8791 &catch_exec_breakpoint_ops);
8794 static enum print_stop_action
8795 print_exception_catchpoint (struct breakpoint *b)
8797 int bp_temp, bp_throw;
8799 annotate_catchpoint (b->number);
8801 bp_throw = strstr (b->addr_string, "throw") != NULL;
8802 if (b->loc->address != b->loc->requested_address)
8803 breakpoint_adjustment_warning (b->loc->requested_address,
8806 bp_temp = b->disposition == disp_del;
8808 bp_temp ? "Temporary catchpoint "
8810 if (!ui_out_is_mi_like_p (uiout))
8811 ui_out_field_int (uiout, "bkptno", b->number);
8813 bp_throw ? " (exception thrown), "
8814 : " (exception caught), ");
8815 if (ui_out_is_mi_like_p (uiout))
8817 ui_out_field_string (uiout, "reason",
8818 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8819 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8820 ui_out_field_int (uiout, "bkptno", b->number);
8822 return PRINT_SRC_AND_LOC;
8826 print_one_exception_catchpoint (struct breakpoint *b,
8827 struct bp_location **last_loc)
8829 struct value_print_options opts;
8831 get_user_print_options (&opts);
8832 if (opts.addressprint)
8835 if (b->loc == NULL || b->loc->shlib_disabled)
8836 ui_out_field_string (uiout, "addr", "<PENDING>");
8838 ui_out_field_core_addr (uiout, "addr",
8839 b->loc->gdbarch, b->loc->address);
8844 if (strstr (b->addr_string, "throw") != NULL)
8845 ui_out_field_string (uiout, "what", "exception throw");
8847 ui_out_field_string (uiout, "what", "exception catch");
8851 print_mention_exception_catchpoint (struct breakpoint *b)
8856 bp_temp = b->disposition == disp_del;
8857 bp_throw = strstr (b->addr_string, "throw") != NULL;
8858 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
8859 : _("Catchpoint "));
8860 ui_out_field_int (uiout, "bkptno", b->number);
8861 ui_out_text (uiout, bp_throw ? _(" (throw)")
8865 /* Implement the "print_recreate" breakpoint_ops method for throw and
8866 catch catchpoints. */
8869 print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
8874 bp_temp = b->disposition == disp_del;
8875 bp_throw = strstr (b->addr_string, "throw") != NULL;
8876 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
8877 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
8880 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
8883 NULL, /* breakpoint_hit */
8884 print_exception_catchpoint,
8885 print_one_exception_catchpoint,
8886 print_mention_exception_catchpoint,
8887 print_recreate_exception_catchpoint
8891 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
8892 enum exception_event_kind ex_event, int from_tty)
8894 char *trigger_func_name;
8896 if (ex_event == EX_EVENT_CATCH)
8897 trigger_func_name = "__cxa_begin_catch";
8899 trigger_func_name = "__cxa_throw";
8901 create_breakpoint (get_current_arch (),
8902 trigger_func_name, cond_string, -1,
8903 0 /* condition and thread are valid. */,
8904 tempflag, bp_breakpoint,
8906 AUTO_BOOLEAN_TRUE /* pending */,
8907 &gnu_v3_exception_catchpoint_ops, from_tty,
8914 /* Deal with "catch catch" and "catch throw" commands */
8917 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
8918 int tempflag, int from_tty)
8920 char *cond_string = NULL;
8924 ep_skip_leading_whitespace (&arg);
8926 cond_string = ep_parse_optional_if_clause (&arg);
8928 if ((*arg != '\0') && !isspace (*arg))
8929 error (_("Junk at end of arguments."));
8931 if (ex_event != EX_EVENT_THROW
8932 && ex_event != EX_EVENT_CATCH)
8933 error (_("Unsupported or unknown exception event; cannot catch it"));
8935 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
8938 warning (_("Unsupported with this platform/compiler combination."));
8941 /* Implementation of "catch catch" command. */
8944 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
8946 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8948 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
8951 /* Implementation of "catch throw" command. */
8954 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
8956 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8958 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
8961 /* Create a breakpoint struct for Ada exception catchpoints. */
8964 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
8965 struct symtab_and_line sal,
8969 struct expression *cond,
8970 struct breakpoint_ops *ops,
8974 struct breakpoint *b;
8978 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8980 loc_gdbarch = gdbarch;
8982 describe_other_breakpoints (loc_gdbarch,
8983 sal.pspace, sal.pc, sal.section, -1);
8984 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8985 version for exception catchpoints, because two catchpoints
8986 used for different exception names will use the same address.
8987 In this case, a "breakpoint ... also set at..." warning is
8988 unproductive. Besides. the warning phrasing is also a bit
8989 inapropriate, we should use the word catchpoint, and tell
8990 the user what type of catchpoint it is. The above is good
8991 enough for now, though. */
8994 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
8995 set_breakpoint_count (breakpoint_count + 1);
8997 b->enable_state = bp_enabled;
8998 b->disposition = tempflag ? disp_del : disp_donttouch;
8999 b->number = breakpoint_count;
9000 b->ignore_count = 0;
9001 b->loc->cond = cond;
9002 b->addr_string = addr_string;
9003 b->language = language_ada;
9004 b->cond_string = cond_string;
9005 b->exp_string = exp_string;
9010 update_global_location_list (1);
9013 /* Implement the "catch exception" command. */
9016 catch_ada_exception_command (char *arg, int from_tty,
9017 struct cmd_list_element *command)
9019 struct gdbarch *gdbarch = get_current_arch ();
9021 struct symtab_and_line sal;
9022 char *addr_string = NULL;
9023 char *exp_string = NULL;
9024 char *cond_string = NULL;
9025 struct expression *cond = NULL;
9026 struct breakpoint_ops *ops = NULL;
9028 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9032 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
9033 &cond_string, &cond, &ops);
9034 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
9035 cond_string, cond, ops, tempflag,
9039 /* Cleanup function for a syscall filter list. */
9041 clean_up_filters (void *arg)
9043 VEC(int) *iter = *(VEC(int) **) arg;
9044 VEC_free (int, iter);
9047 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9048 filter list, or NULL if no filtering is required. */
9050 catch_syscall_split_args (char *arg)
9052 VEC(int) *result = NULL;
9053 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
9055 while (*arg != '\0')
9057 int i, syscall_number;
9062 /* Skip whitespace. */
9063 while (isspace (*arg))
9066 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
9067 cur_name[i] = arg[i];
9071 /* Check if the user provided a syscall name or a number. */
9072 syscall_number = (int) strtol (cur_name, &endptr, 0);
9073 if (*endptr == '\0')
9074 get_syscall_by_number (syscall_number, &s);
9077 /* We have a name. Let's check if it's valid and convert it
9079 get_syscall_by_name (cur_name, &s);
9081 if (s.number == UNKNOWN_SYSCALL)
9082 /* Here we have to issue an error instead of a warning, because
9083 GDB cannot do anything useful if there's no syscall number to
9085 error (_("Unknown syscall name '%s'."), cur_name);
9088 /* Ok, it's valid. */
9089 VEC_safe_push (int, result, s.number);
9092 discard_cleanups (cleanup);
9096 /* Implement the "catch syscall" command. */
9099 catch_syscall_command_1 (char *arg, int from_tty,
9100 struct cmd_list_element *command)
9105 struct gdbarch *gdbarch = get_current_arch ();
9107 /* Checking if the feature if supported. */
9108 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
9109 error (_("The feature 'catch syscall' is not supported on \
9110 this architeture yet."));
9112 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9114 ep_skip_leading_whitespace (&arg);
9116 /* We need to do this first "dummy" translation in order
9117 to get the syscall XML file loaded or, most important,
9118 to display a warning to the user if there's no XML file
9119 for his/her architecture. */
9120 get_syscall_by_number (0, &s);
9122 /* The allowed syntax is:
9124 catch syscall <name | number> [<name | number> ... <name | number>]
9126 Let's check if there's a syscall name. */
9129 filter = catch_syscall_split_args (arg);
9133 create_syscall_event_catchpoint (tempflag, filter,
9134 &catch_syscall_breakpoint_ops);
9137 /* Implement the "catch assert" command. */
9140 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
9142 struct gdbarch *gdbarch = get_current_arch ();
9144 struct symtab_and_line sal;
9145 char *addr_string = NULL;
9146 struct breakpoint_ops *ops = NULL;
9148 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9152 sal = ada_decode_assert_location (arg, &addr_string, &ops);
9153 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
9154 ops, tempflag, from_tty);
9158 catch_command (char *arg, int from_tty)
9160 error (_("Catch requires an event name."));
9165 tcatch_command (char *arg, int from_tty)
9167 error (_("Catch requires an event name."));
9170 /* Delete breakpoints by address or line. */
9173 clear_command (char *arg, int from_tty)
9175 struct breakpoint *b;
9176 VEC(breakpoint_p) *found = 0;
9179 struct symtabs_and_lines sals;
9180 struct symtab_and_line sal;
9185 sals = decode_line_spec (arg, 1);
9190 sals.sals = (struct symtab_and_line *)
9191 xmalloc (sizeof (struct symtab_and_line));
9192 make_cleanup (xfree, sals.sals);
9193 init_sal (&sal); /* initialize to zeroes */
9194 sal.line = default_breakpoint_line;
9195 sal.symtab = default_breakpoint_symtab;
9196 sal.pc = default_breakpoint_address;
9197 sal.pspace = default_breakpoint_pspace;
9198 if (sal.symtab == 0)
9199 error (_("No source file specified."));
9207 /* We don't call resolve_sal_pc here. That's not
9208 as bad as it seems, because all existing breakpoints
9209 typically have both file/line and pc set. So, if
9210 clear is given file/line, we can match this to existing
9211 breakpoint without obtaining pc at all.
9213 We only support clearing given the address explicitly
9214 present in breakpoint table. Say, we've set breakpoint
9215 at file:line. There were several PC values for that file:line,
9216 due to optimization, all in one block.
9217 We've picked one PC value. If "clear" is issued with another
9218 PC corresponding to the same file:line, the breakpoint won't
9219 be cleared. We probably can still clear the breakpoint, but
9220 since the other PC value is never presented to user, user
9221 can only find it by guessing, and it does not seem important
9224 /* For each line spec given, delete bps which correspond
9225 to it. Do it in two passes, solely to preserve the current
9226 behavior that from_tty is forced true if we delete more than
9230 for (i = 0; i < sals.nelts; i++)
9232 /* If exact pc given, clear bpts at that pc.
9233 If line given (pc == 0), clear all bpts on specified line.
9234 If defaulting, clear all bpts on default line
9237 defaulting sal.pc != 0 tests to do
9242 1 0 <can't happen> */
9246 /* Find all matching breakpoints and add them to
9251 /* Are we going to delete b? */
9252 if (b->type != bp_none && !is_watchpoint (b))
9254 struct bp_location *loc = b->loc;
9255 for (; loc; loc = loc->next)
9257 int pc_match = sal.pc
9258 && (loc->pspace == sal.pspace)
9259 && (loc->address == sal.pc)
9260 && (!section_is_overlay (loc->section)
9261 || loc->section == sal.section);
9262 int line_match = ((default_match || (0 == sal.pc))
9263 && b->source_file != NULL
9264 && sal.symtab != NULL
9265 && sal.pspace == loc->pspace
9266 && strcmp (b->source_file, sal.symtab->filename) == 0
9267 && b->line_number == sal.line);
9268 if (pc_match || line_match)
9277 VEC_safe_push(breakpoint_p, found, b);
9280 /* Now go thru the 'found' chain and delete them. */
9281 if (VEC_empty(breakpoint_p, found))
9284 error (_("No breakpoint at %s."), arg);
9286 error (_("No breakpoint at this line."));
9289 if (VEC_length(breakpoint_p, found) > 1)
9290 from_tty = 1; /* Always report if deleted more than one */
9293 if (VEC_length(breakpoint_p, found) == 1)
9294 printf_unfiltered (_("Deleted breakpoint "));
9296 printf_unfiltered (_("Deleted breakpoints "));
9298 breakpoints_changed ();
9300 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
9303 printf_unfiltered ("%d ", b->number);
9304 delete_breakpoint (b);
9307 putchar_unfiltered ('\n');
9310 /* Delete breakpoint in BS if they are `delete' breakpoints and
9311 all breakpoints that are marked for deletion, whether hit or not.
9312 This is called after any breakpoint is hit, or after errors. */
9315 breakpoint_auto_delete (bpstat bs)
9317 struct breakpoint *b, *b_tmp;
9319 for (; bs; bs = bs->next)
9320 if (bs->breakpoint_at
9321 && bs->breakpoint_at->disposition == disp_del
9323 delete_breakpoint (bs->breakpoint_at);
9325 ALL_BREAKPOINTS_SAFE (b, b_tmp)
9327 if (b->disposition == disp_del_at_next_stop)
9328 delete_breakpoint (b);
9332 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9333 Sort elements primarily by their ADDRESS (no matter what does
9334 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9335 first bp_permanent OWNERed elements and terciarily just ensuring the array
9336 is sorted stable way despite qsort being an instable algorithm. */
9339 bp_location_compare (const void *ap, const void *bp)
9341 struct bp_location *a = *(void **) ap;
9342 struct bp_location *b = *(void **) bp;
9343 /* A and B come from existing breakpoints having non-NULL OWNER. */
9344 int a_perm = a->owner->enable_state == bp_permanent;
9345 int b_perm = b->owner->enable_state == bp_permanent;
9347 if (a->address != b->address)
9348 return (a->address > b->address) - (a->address < b->address);
9350 /* Sort permanent breakpoints first. */
9351 if (a_perm != b_perm)
9352 return (a_perm < b_perm) - (a_perm > b_perm);
9354 /* Make the user-visible order stable across GDB runs. Locations of the same
9355 breakpoint can be sorted in arbitrary order. */
9357 if (a->owner->number != b->owner->number)
9358 return (a->owner->number > b->owner->number)
9359 - (a->owner->number < b->owner->number);
9361 return (a > b) - (a < b);
9364 /* Set bp_location_placed_address_before_address_max and
9365 bp_location_shadow_len_after_address_max according to the current content of
9366 the bp_location array. */
9369 bp_location_target_extensions_update (void)
9371 struct bp_location *bl, **blp_tmp;
9373 bp_location_placed_address_before_address_max = 0;
9374 bp_location_shadow_len_after_address_max = 0;
9376 ALL_BP_LOCATIONS (bl, blp_tmp)
9378 CORE_ADDR start, end, addr;
9380 if (!bp_location_has_shadow (bl))
9383 start = bl->target_info.placed_address;
9384 end = start + bl->target_info.shadow_len;
9386 gdb_assert (bl->address >= start);
9387 addr = bl->address - start;
9388 if (addr > bp_location_placed_address_before_address_max)
9389 bp_location_placed_address_before_address_max = addr;
9391 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9393 gdb_assert (bl->address < end);
9394 addr = end - bl->address;
9395 if (addr > bp_location_shadow_len_after_address_max)
9396 bp_location_shadow_len_after_address_max = addr;
9400 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9401 into the inferior, only remove already-inserted locations that no
9402 longer should be inserted. Functions that delete a breakpoint or
9403 breakpoints should pass false, so that deleting a breakpoint
9404 doesn't have the side effect of inserting the locations of other
9405 breakpoints that are marked not-inserted, but should_be_inserted
9406 returns true on them.
9408 This behaviour is useful is situations close to tear-down -- e.g.,
9409 after an exec, while the target still has execution, but breakpoint
9410 shadows of the previous executable image should *NOT* be restored
9411 to the new image; or before detaching, where the target still has
9412 execution and wants to delete breakpoints from GDB's lists, and all
9413 breakpoints had already been removed from the inferior. */
9416 update_global_location_list (int should_insert)
9418 struct breakpoint *b;
9419 struct bp_location **locp, *loc;
9420 struct cleanup *cleanups;
9422 /* Used in the duplicates detection below. When iterating over all
9423 bp_locations, points to the first bp_location of a given address.
9424 Breakpoints and watchpoints of different types are never
9425 duplicates of each other. Keep one pointer for each type of
9426 breakpoint/watchpoint, so we only need to loop over all locations
9428 struct bp_location *bp_loc_first; /* breakpoint */
9429 struct bp_location *wp_loc_first; /* hardware watchpoint */
9430 struct bp_location *awp_loc_first; /* access watchpoint */
9431 struct bp_location *rwp_loc_first; /* read watchpoint */
9433 /* Saved former bp_location array which we compare against the newly built
9434 bp_location from the current state of ALL_BREAKPOINTS. */
9435 struct bp_location **old_location, **old_locp;
9436 unsigned old_location_count;
9438 old_location = bp_location;
9439 old_location_count = bp_location_count;
9441 bp_location_count = 0;
9442 cleanups = make_cleanup (xfree, old_location);
9445 for (loc = b->loc; loc; loc = loc->next)
9446 bp_location_count++;
9448 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
9451 for (loc = b->loc; loc; loc = loc->next)
9453 qsort (bp_location, bp_location_count, sizeof (*bp_location),
9454 bp_location_compare);
9456 bp_location_target_extensions_update ();
9458 /* Identify bp_location instances that are no longer present in the new
9459 list, and therefore should be freed. Note that it's not necessary that
9460 those locations should be removed from inferior -- if there's another
9461 location at the same address (previously marked as duplicate),
9462 we don't need to remove/insert the location.
9464 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9465 former bp_location array state respectively. */
9468 for (old_locp = old_location; old_locp < old_location + old_location_count;
9471 struct bp_location *old_loc = *old_locp;
9472 struct bp_location **loc2p;
9474 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9476 int found_object = 0;
9477 /* Tells if the location should remain inserted in the target. */
9478 int keep_in_target = 0;
9481 /* Skip LOCP entries which will definitely never be needed. Stop either
9482 at or being the one matching OLD_LOC. */
9483 while (locp < bp_location + bp_location_count
9484 && (*locp)->address < old_loc->address)
9488 (loc2p < bp_location + bp_location_count
9489 && (*loc2p)->address == old_loc->address);
9492 if (*loc2p == old_loc)
9499 /* If this location is no longer present, and inserted, look if there's
9500 maybe a new location at the same address. If so, mark that one
9501 inserted, and don't remove this one. This is needed so that we
9502 don't have a time window where a breakpoint at certain location is not
9505 if (old_loc->inserted)
9507 /* If the location is inserted now, we might have to remove it. */
9509 if (found_object && should_be_inserted (old_loc))
9511 /* The location is still present in the location list, and still
9512 should be inserted. Don't do anything. */
9517 /* The location is either no longer present, or got disabled.
9518 See if there's another location at the same address, in which
9519 case we don't need to remove this one from the target. */
9521 /* OLD_LOC comes from existing struct breakpoint. */
9522 if (breakpoint_address_is_meaningful (old_loc->owner))
9525 (loc2p < bp_location + bp_location_count
9526 && (*loc2p)->address == old_loc->address);
9529 struct bp_location *loc2 = *loc2p;
9531 if (breakpoint_locations_match (loc2, old_loc))
9533 /* For the sake of should_be_inserted.
9534 Duplicates check below will fix up this later. */
9535 loc2->duplicate = 0;
9537 /* Read watchpoint locations are switched to
9538 access watchpoints, if the former are not
9539 supported, but the latter are. */
9540 if (is_hardware_watchpoint (old_loc->owner))
9542 gdb_assert (is_hardware_watchpoint (loc2->owner));
9543 loc2->watchpoint_type = old_loc->watchpoint_type;
9546 if (loc2 != old_loc && should_be_inserted (loc2))
9549 loc2->target_info = old_loc->target_info;
9558 if (!keep_in_target)
9560 if (remove_breakpoint (old_loc, mark_uninserted))
9562 /* This is just about all we can do. We could keep this
9563 location on the global list, and try to remove it next
9564 time, but there's no particular reason why we will
9567 Note that at this point, old_loc->owner is still valid,
9568 as delete_breakpoint frees the breakpoint only
9569 after calling us. */
9570 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9571 old_loc->owner->number);
9579 if (removed && non_stop
9580 && breakpoint_address_is_meaningful (old_loc->owner)
9581 && !is_hardware_watchpoint (old_loc->owner))
9583 /* This location was removed from the target. In
9584 non-stop mode, a race condition is possible where
9585 we've removed a breakpoint, but stop events for that
9586 breakpoint are already queued and will arrive later.
9587 We apply an heuristic to be able to distinguish such
9588 SIGTRAPs from other random SIGTRAPs: we keep this
9589 breakpoint location for a bit, and will retire it
9590 after we see some number of events. The theory here
9591 is that reporting of events should, "on the average",
9592 be fair, so after a while we'll see events from all
9593 threads that have anything of interest, and no longer
9594 need to keep this breakpoint location around. We
9595 don't hold locations forever so to reduce chances of
9596 mistaking a non-breakpoint SIGTRAP for a breakpoint
9599 The heuristic failing can be disastrous on
9600 decr_pc_after_break targets.
9602 On decr_pc_after_break targets, like e.g., x86-linux,
9603 if we fail to recognize a late breakpoint SIGTRAP,
9604 because events_till_retirement has reached 0 too
9605 soon, we'll fail to do the PC adjustment, and report
9606 a random SIGTRAP to the user. When the user resumes
9607 the inferior, it will most likely immediately crash
9608 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9609 corrupted, because of being resumed e.g., in the
9610 middle of a multi-byte instruction, or skipped a
9611 one-byte instruction. This was actually seen happen
9612 on native x86-linux, and should be less rare on
9613 targets that do not support new thread events, like
9614 remote, due to the heuristic depending on
9617 Mistaking a random SIGTRAP for a breakpoint trap
9618 causes similar symptoms (PC adjustment applied when
9619 it shouldn't), but then again, playing with SIGTRAPs
9620 behind the debugger's back is asking for trouble.
9622 Since hardware watchpoint traps are always
9623 distinguishable from other traps, so we don't need to
9624 apply keep hardware watchpoint moribund locations
9625 around. We simply always ignore hardware watchpoint
9626 traps we can no longer explain. */
9628 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9629 old_loc->owner = NULL;
9631 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9635 old_loc->owner = NULL;
9636 decref_bp_location (&old_loc);
9641 /* Rescan breakpoints at the same address and section, marking the
9642 first one as "first" and any others as "duplicates". This is so
9643 that the bpt instruction is only inserted once. If we have a
9644 permanent breakpoint at the same place as BPT, make that one the
9645 official one, and the rest as duplicates. Permanent breakpoints
9646 are sorted first for the same address.
9648 Do the same for hardware watchpoints, but also considering the
9649 watchpoint's type (regular/access/read) and length. */
9651 bp_loc_first = NULL;
9652 wp_loc_first = NULL;
9653 awp_loc_first = NULL;
9654 rwp_loc_first = NULL;
9655 ALL_BP_LOCATIONS (loc, locp)
9657 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9658 struct breakpoint *b = loc->owner;
9659 struct bp_location **loc_first_p;
9661 if (b->enable_state == bp_disabled
9662 || b->enable_state == bp_call_disabled
9663 || b->enable_state == bp_startup_disabled
9665 || loc->shlib_disabled
9666 || !breakpoint_address_is_meaningful (b)
9667 || is_tracepoint (b))
9670 /* Permanent breakpoint should always be inserted. */
9671 if (b->enable_state == bp_permanent && ! loc->inserted)
9672 internal_error (__FILE__, __LINE__,
9673 _("allegedly permanent breakpoint is not "
9674 "actually inserted"));
9676 if (b->type == bp_hardware_watchpoint)
9677 loc_first_p = &wp_loc_first;
9678 else if (b->type == bp_read_watchpoint)
9679 loc_first_p = &rwp_loc_first;
9680 else if (b->type == bp_access_watchpoint)
9681 loc_first_p = &awp_loc_first;
9683 loc_first_p = &bp_loc_first;
9685 if (*loc_first_p == NULL
9686 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9687 || !breakpoint_locations_match (loc, *loc_first_p))
9696 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9697 && b->enable_state != bp_permanent)
9698 internal_error (__FILE__, __LINE__,
9699 _("another breakpoint was inserted on top of "
9700 "a permanent breakpoint"));
9703 if (breakpoints_always_inserted_mode () && should_insert
9704 && (have_live_inferiors ()
9705 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9706 insert_breakpoint_locations ();
9708 do_cleanups (cleanups);
9712 breakpoint_retire_moribund (void)
9714 struct bp_location *loc;
9717 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9718 if (--(loc->events_till_retirement) == 0)
9720 decref_bp_location (&loc);
9721 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9727 update_global_location_list_nothrow (int inserting)
9729 struct gdb_exception e;
9731 TRY_CATCH (e, RETURN_MASK_ERROR)
9732 update_global_location_list (inserting);
9735 /* Clear BKP from a BPS. */
9738 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
9742 for (bs = bps; bs; bs = bs->next)
9743 if (bs->breakpoint_at == bpt)
9745 bs->breakpoint_at = NULL;
9747 /* bs->commands will be freed later. */
9751 /* Callback for iterate_over_threads. */
9753 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
9755 struct breakpoint *bpt = data;
9757 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
9761 /* Delete a breakpoint and clean up all traces of it in the data
9765 delete_breakpoint (struct breakpoint *bpt)
9767 struct breakpoint *b;
9769 gdb_assert (bpt != NULL);
9771 /* Has this bp already been deleted? This can happen because multiple
9772 lists can hold pointers to bp's. bpstat lists are especial culprits.
9774 One example of this happening is a watchpoint's scope bp. When the
9775 scope bp triggers, we notice that the watchpoint is out of scope, and
9776 delete it. We also delete its scope bp. But the scope bp is marked
9777 "auto-deleting", and is already on a bpstat. That bpstat is then
9778 checked for auto-deleting bp's, which are deleted.
9780 A real solution to this problem might involve reference counts in bp's,
9781 and/or giving them pointers back to their referencing bpstat's, and
9782 teaching delete_breakpoint to only free a bp's storage when no more
9783 references were extent. A cheaper bandaid was chosen. */
9784 if (bpt->type == bp_none)
9787 /* At least avoid this stale reference until the reference counting of
9788 breakpoints gets resolved. */
9789 if (bpt->related_breakpoint != NULL)
9791 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
9792 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
9793 bpt->related_breakpoint->related_breakpoint = NULL;
9794 bpt->related_breakpoint = NULL;
9797 observer_notify_breakpoint_deleted (bpt->number);
9799 if (breakpoint_chain == bpt)
9800 breakpoint_chain = bpt->next;
9805 b->next = bpt->next;
9809 decref_counted_command_line (&bpt->commands);
9810 xfree (bpt->cond_string);
9811 xfree (bpt->cond_exp);
9812 xfree (bpt->addr_string);
9814 xfree (bpt->exp_string);
9815 xfree (bpt->exp_string_reparse);
9816 value_free (bpt->val);
9817 xfree (bpt->source_file);
9818 xfree (bpt->exec_pathname);
9819 clean_up_filters (&bpt->syscalls_to_be_caught);
9822 /* Be sure no bpstat's are pointing at the breakpoint after it's
9824 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
9825 in all threeds for now. Note that we cannot just remove bpstats
9826 pointing at bpt from the stop_bpstat list entirely, as breakpoint
9827 commands are associated with the bpstat; if we remove it here,
9828 then the later call to bpstat_do_actions (&stop_bpstat); in
9829 event-top.c won't do anything, and temporary breakpoints with
9830 commands won't work. */
9832 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
9834 /* Now that breakpoint is removed from breakpoint
9835 list, update the global location list. This
9836 will remove locations that used to belong to
9837 this breakpoint. Do this before freeing
9838 the breakpoint itself, since remove_breakpoint
9839 looks at location's owner. It might be better
9840 design to have location completely self-contained,
9841 but it's not the case now. */
9842 update_global_location_list (0);
9845 /* On the chance that someone will soon try again to delete this same
9846 bp, we mark it as deleted before freeing its storage. */
9847 bpt->type = bp_none;
9853 do_delete_breakpoint_cleanup (void *b)
9855 delete_breakpoint (b);
9859 make_cleanup_delete_breakpoint (struct breakpoint *b)
9861 return make_cleanup (do_delete_breakpoint_cleanup, b);
9864 /* A callback for map_breakpoint_numbers that calls
9865 delete_breakpoint. */
9868 do_delete_breakpoint (struct breakpoint *b, void *ignore)
9870 delete_breakpoint (b);
9874 delete_command (char *arg, int from_tty)
9876 struct breakpoint *b, *b_tmp;
9882 int breaks_to_delete = 0;
9884 /* Delete all breakpoints if no argument.
9885 Do not delete internal or call-dummy breakpoints, these
9886 have to be deleted with an explicit breakpoint number argument. */
9889 if (b->type != bp_call_dummy
9890 && b->type != bp_std_terminate
9891 && b->type != bp_shlib_event
9892 && b->type != bp_jit_event
9893 && b->type != bp_thread_event
9894 && b->type != bp_overlay_event
9895 && b->type != bp_longjmp_master
9896 && b->type != bp_std_terminate_master
9897 && b->type != bp_exception_master
9900 breaks_to_delete = 1;
9905 /* Ask user only if there are some breakpoints to delete. */
9907 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
9909 ALL_BREAKPOINTS_SAFE (b, b_tmp)
9911 if (b->type != bp_call_dummy
9912 && b->type != bp_std_terminate
9913 && b->type != bp_shlib_event
9914 && b->type != bp_thread_event
9915 && b->type != bp_jit_event
9916 && b->type != bp_overlay_event
9917 && b->type != bp_longjmp_master
9918 && b->type != bp_std_terminate_master
9919 && b->type != bp_exception_master
9921 delete_breakpoint (b);
9926 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
9930 all_locations_are_pending (struct bp_location *loc)
9932 for (; loc; loc = loc->next)
9933 if (!loc->shlib_disabled)
9938 /* Subroutine of update_breakpoint_locations to simplify it.
9939 Return non-zero if multiple fns in list LOC have the same name.
9940 Null names are ignored. */
9943 ambiguous_names_p (struct bp_location *loc)
9945 struct bp_location *l;
9946 htab_t htab = htab_create_alloc (13, htab_hash_string,
9947 (int (*) (const void *,
9948 const void *)) streq,
9949 NULL, xcalloc, xfree);
9951 for (l = loc; l != NULL; l = l->next)
9954 const char *name = l->function_name;
9956 /* Allow for some names to be NULL, ignore them. */
9960 slot = (const char **) htab_find_slot (htab, (const void *) name,
9962 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9976 /* When symbols change, it probably means the sources changed as well,
9977 and it might mean the static tracepoint markers are no longer at
9978 the same address or line numbers they used to be at last we
9979 checked. Losing your static tracepoints whenever you rebuild is
9980 undesirable. This function tries to resync/rematch gdb static
9981 tracepoints with the markers on the target, for static tracepoints
9982 that have not been set by marker id. Static tracepoint that have
9983 been set by marker id are reset by marker id in breakpoint_re_set.
9986 1) For a tracepoint set at a specific address, look for a marker at
9987 the old PC. If one is found there, assume to be the same marker.
9988 If the name / string id of the marker found is different from the
9989 previous known name, assume that means the user renamed the marker
9990 in the sources, and output a warning.
9992 2) For a tracepoint set at a given line number, look for a marker
9993 at the new address of the old line number. If one is found there,
9994 assume to be the same marker. If the name / string id of the
9995 marker found is different from the previous known name, assume that
9996 means the user renamed the marker in the sources, and output a
9999 3) If a marker is no longer found at the same address or line, it
10000 may mean the marker no longer exists. But it may also just mean
10001 the code changed a bit. Maybe the user added a few lines of code
10002 that made the marker move up or down (in line number terms). Ask
10003 the target for info about the marker with the string id as we knew
10004 it. If found, update line number and address in the matching
10005 static tracepoint. This will get confused if there's more than one
10006 marker with the same ID (possible in UST, although unadvised
10007 precisely because it confuses tools). */
10009 static struct symtab_and_line
10010 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
10012 struct static_tracepoint_marker marker;
10018 find_line_pc (sal.symtab, sal.line, &pc);
10020 if (target_static_tracepoint_marker_at (pc, &marker))
10022 if (strcmp (b->static_trace_marker_id, marker.str_id) != 0)
10023 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10025 b->static_trace_marker_id, marker.str_id);
10027 xfree (b->static_trace_marker_id);
10028 b->static_trace_marker_id = xstrdup (marker.str_id);
10029 release_static_tracepoint_marker (&marker);
10034 /* Old marker wasn't found on target at lineno. Try looking it up
10036 if (!sal.explicit_pc
10038 && sal.symtab != NULL
10039 && b->static_trace_marker_id != NULL)
10041 VEC(static_tracepoint_marker_p) *markers;
10044 = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id);
10046 if (!VEC_empty(static_tracepoint_marker_p, markers))
10048 struct symtab_and_line sal;
10049 struct symbol *sym;
10050 struct static_tracepoint_marker *marker;
10052 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
10054 xfree (b->static_trace_marker_id);
10055 b->static_trace_marker_id = xstrdup (marker->str_id);
10057 warning (_("marker for static tracepoint %d (%s) not "
10058 "found at previous line number"),
10059 b->number, b->static_trace_marker_id);
10063 sal.pc = marker->address;
10065 sal = find_pc_line (marker->address, 0);
10066 sym = find_pc_sect_function (marker->address, NULL);
10067 ui_out_text (uiout, "Now in ");
10070 ui_out_field_string (uiout, "func",
10071 SYMBOL_PRINT_NAME (sym));
10072 ui_out_text (uiout, " at ");
10074 ui_out_field_string (uiout, "file", sal.symtab->filename);
10075 ui_out_text (uiout, ":");
10077 if (ui_out_is_mi_like_p (uiout))
10079 char *fullname = symtab_to_fullname (sal.symtab);
10082 ui_out_field_string (uiout, "fullname", fullname);
10085 ui_out_field_int (uiout, "line", sal.line);
10086 ui_out_text (uiout, "\n");
10088 b->line_number = sal.line;
10090 xfree (b->source_file);
10092 b->source_file = xstrdup (sal.symtab->filename);
10094 b->source_file = NULL;
10096 xfree (b->addr_string);
10097 b->addr_string = xstrprintf ("%s:%d",
10098 sal.symtab->filename, b->line_number);
10100 /* Might be nice to check if function changed, and warn if
10103 release_static_tracepoint_marker (marker);
10110 update_breakpoint_locations (struct breakpoint *b,
10111 struct symtabs_and_lines sals)
10115 struct bp_location *existing_locations = b->loc;
10117 /* If there's no new locations, and all existing locations
10118 are pending, don't do anything. This optimizes
10119 the common case where all locations are in the same
10120 shared library, that was unloaded. We'd like to
10121 retain the location, so that when the library
10122 is loaded again, we don't loose the enabled/disabled
10123 status of the individual locations. */
10124 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
10129 for (i = 0; i < sals.nelts; ++i)
10131 struct bp_location *new_loc =
10132 add_location_to_breakpoint (b, &(sals.sals[i]));
10134 /* Reparse conditions, they might contain references to the
10136 if (b->cond_string != NULL)
10138 struct gdb_exception e;
10140 s = b->cond_string;
10141 TRY_CATCH (e, RETURN_MASK_ERROR)
10143 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
10148 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
10149 b->number, e.message);
10150 new_loc->enabled = 0;
10154 if (b->source_file != NULL)
10155 xfree (b->source_file);
10156 if (sals.sals[i].symtab == NULL)
10157 b->source_file = NULL;
10159 b->source_file = xstrdup (sals.sals[i].symtab->filename);
10161 if (b->line_number == 0)
10162 b->line_number = sals.sals[i].line;
10165 /* Update locations of permanent breakpoints. */
10166 if (b->enable_state == bp_permanent)
10167 make_breakpoint_permanent (b);
10169 /* If possible, carry over 'disable' status from existing breakpoints. */
10171 struct bp_location *e = existing_locations;
10172 /* If there are multiple breakpoints with the same function name,
10173 e.g. for inline functions, comparing function names won't work.
10174 Instead compare pc addresses; this is just a heuristic as things
10175 may have moved, but in practice it gives the correct answer
10176 often enough until a better solution is found. */
10177 int have_ambiguous_names = ambiguous_names_p (b->loc);
10179 for (; e; e = e->next)
10181 if (!e->enabled && e->function_name)
10183 struct bp_location *l = b->loc;
10184 if (have_ambiguous_names)
10186 for (; l; l = l->next)
10187 if (breakpoint_address_match (e->pspace->aspace, e->address,
10188 l->pspace->aspace, l->address))
10196 for (; l; l = l->next)
10197 if (l->function_name
10198 && strcmp (e->function_name, l->function_name) == 0)
10208 update_global_location_list (1);
10211 /* Reset a breakpoint given it's struct breakpoint * BINT.
10212 The value we return ends up being the return value from catch_errors.
10213 Unused in this case. */
10216 breakpoint_re_set_one (void *bint)
10218 /* get past catch_errs */
10219 struct breakpoint *b = (struct breakpoint *) bint;
10221 int *not_found_ptr = ¬_found;
10222 struct symtabs_and_lines sals = {0};
10223 struct symtabs_and_lines expanded = {0};
10225 struct gdb_exception e;
10226 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10227 int marker_spec = 0;
10232 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10235 case bp_breakpoint:
10236 case bp_hardware_breakpoint:
10237 case bp_tracepoint:
10238 case bp_fast_tracepoint:
10239 case bp_static_tracepoint:
10240 /* Do not attempt to re-set breakpoints disabled during startup. */
10241 if (b->enable_state == bp_startup_disabled)
10244 if (b->addr_string == NULL)
10246 /* Anything without a string can't be re-set. */
10247 delete_breakpoint (b);
10251 input_radix = b->input_radix;
10252 s = b->addr_string;
10254 save_current_space_and_thread ();
10255 switch_to_program_space_and_thread (b->pspace);
10257 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
10259 set_language (b->language);
10260 TRY_CATCH (e, RETURN_MASK_ERROR)
10264 sals = decode_static_tracepoint_spec (&s);
10265 if (sals.nelts > b->static_trace_marker_id_idx)
10267 sals.sals[0] = sals.sals[b->static_trace_marker_id_idx];
10271 error (_("marker %s not found"), b->static_trace_marker_id);
10274 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
10279 int not_found_and_ok = 0;
10280 /* For pending breakpoints, it's expected that parsing
10281 will fail until the right shared library is loaded.
10282 User has already told to create pending breakpoints and
10283 don't need extra messages. If breakpoint is in bp_shlib_disabled
10284 state, then user already saw the message about that breakpoint
10285 being disabled, and don't want to see more errors. */
10287 && (b->condition_not_parsed
10288 || (b->loc && b->loc->shlib_disabled)
10289 || b->enable_state == bp_disabled))
10290 not_found_and_ok = 1;
10292 if (!not_found_and_ok)
10294 /* We surely don't want to warn about the same breakpoint
10295 10 times. One solution, implemented here, is disable
10296 the breakpoint on error. Another solution would be to
10297 have separate 'warning emitted' flag. Since this
10298 happens only when a binary has changed, I don't know
10299 which approach is better. */
10300 b->enable_state = bp_disabled;
10301 throw_exception (e);
10307 gdb_assert (sals.nelts == 1);
10309 resolve_sal_pc (&sals.sals[0]);
10310 if (b->condition_not_parsed && s && s[0])
10312 char *cond_string = 0;
10316 find_condition_and_thread (s, sals.sals[0].pc,
10317 &cond_string, &thread, &task);
10319 b->cond_string = cond_string;
10320 b->thread = thread;
10322 b->condition_not_parsed = 0;
10325 if (b->type == bp_static_tracepoint && !marker_spec)
10326 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
10328 expanded = expand_line_sal_maybe (sals.sals[0]);
10331 make_cleanup (xfree, sals.sals);
10332 update_breakpoint_locations (b, expanded);
10335 case bp_watchpoint:
10336 case bp_hardware_watchpoint:
10337 case bp_read_watchpoint:
10338 case bp_access_watchpoint:
10339 /* Watchpoint can be either on expression using entirely global variables,
10340 or it can be on local variables.
10342 Watchpoints of the first kind are never auto-deleted, and even persist
10343 across program restarts. Since they can use variables from shared
10344 libraries, we need to reparse expression as libraries are loaded
10347 Watchpoints on local variables can also change meaning as result
10348 of solib event. For example, if a watchpoint uses both a local and
10349 a global variables in expression, it's a local watchpoint, but
10350 unloading of a shared library will make the expression invalid.
10351 This is not a very common use case, but we still re-evaluate
10352 expression, to avoid surprises to the user.
10354 Note that for local watchpoints, we re-evaluate it only if
10355 watchpoints frame id is still valid. If it's not, it means
10356 the watchpoint is out of scope and will be deleted soon. In fact,
10357 I'm not sure we'll ever be called in this case.
10359 If a local watchpoint's frame id is still valid, then
10360 b->exp_valid_block is likewise valid, and we can safely use it.
10362 Don't do anything about disabled watchpoints, since they will
10363 be reevaluated again when enabled. */
10364 update_watchpoint (b, 1 /* reparse */);
10366 /* We needn't really do anything to reset these, since the mask
10367 that requests them is unaffected by e.g., new libraries being
10369 case bp_catchpoint:
10373 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
10375 /* Delete overlay event and longjmp master breakpoints; they will be
10376 reset later by breakpoint_re_set. */
10377 case bp_overlay_event:
10378 case bp_longjmp_master:
10379 case bp_std_terminate_master:
10380 case bp_exception_master:
10381 delete_breakpoint (b);
10384 /* This breakpoint is special, it's set up when the inferior
10385 starts and we really don't want to touch it. */
10386 case bp_shlib_event:
10388 /* Like bp_shlib_event, this breakpoint type is special.
10389 Once it is set up, we do not want to touch it. */
10390 case bp_thread_event:
10392 /* Keep temporary breakpoints, which can be encountered when we step
10393 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10394 Otherwise these should have been blown away via the cleanup chain
10395 or by breakpoint_init_inferior when we rerun the executable. */
10398 case bp_watchpoint_scope:
10399 case bp_call_dummy:
10400 case bp_std_terminate:
10401 case bp_step_resume:
10403 case bp_longjmp_resume:
10405 case bp_exception_resume:
10410 do_cleanups (cleanups);
10414 /* Re-set all breakpoints after symbols have been re-loaded. */
10416 breakpoint_re_set (void)
10418 struct breakpoint *b, *b_tmp;
10419 enum language save_language;
10420 int save_input_radix;
10421 struct cleanup *old_chain;
10423 save_language = current_language->la_language;
10424 save_input_radix = input_radix;
10425 old_chain = save_current_program_space ();
10427 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10429 /* Format possible error msg */
10430 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
10432 struct cleanup *cleanups = make_cleanup (xfree, message);
10433 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
10434 do_cleanups (cleanups);
10436 set_language (save_language);
10437 input_radix = save_input_radix;
10439 jit_breakpoint_re_set ();
10441 do_cleanups (old_chain);
10443 create_overlay_event_breakpoint ("_ovly_debug_event");
10444 create_longjmp_master_breakpoint ("longjmp");
10445 create_longjmp_master_breakpoint ("_longjmp");
10446 create_longjmp_master_breakpoint ("siglongjmp");
10447 create_longjmp_master_breakpoint ("_siglongjmp");
10448 create_std_terminate_master_breakpoint ("std::terminate()");
10449 create_exception_master_breakpoint ();
10452 /* Reset the thread number of this breakpoint:
10454 - If the breakpoint is for all threads, leave it as-is.
10455 - Else, reset it to the current thread for inferior_ptid. */
10457 breakpoint_re_set_thread (struct breakpoint *b)
10459 if (b->thread != -1)
10461 if (in_thread_list (inferior_ptid))
10462 b->thread = pid_to_thread_id (inferior_ptid);
10464 /* We're being called after following a fork. The new fork is
10465 selected as current, and unless this was a vfork will have a
10466 different program space from the original thread. Reset that
10468 b->loc->pspace = current_program_space;
10472 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10473 If from_tty is nonzero, it prints a message to that effect,
10474 which ends with a period (no newline). */
10477 set_ignore_count (int bptnum, int count, int from_tty)
10479 struct breakpoint *b;
10484 ALL_BREAKPOINTS (b)
10485 if (b->number == bptnum)
10487 if (is_tracepoint (b))
10489 if (from_tty && count != 0)
10490 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10495 b->ignore_count = count;
10499 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10501 else if (count == 1)
10502 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10505 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10508 breakpoints_changed ();
10509 observer_notify_breakpoint_modified (b->number);
10513 error (_("No breakpoint number %d."), bptnum);
10517 make_breakpoint_silent (struct breakpoint *b)
10519 /* Silence the breakpoint. */
10523 /* Command to set ignore-count of breakpoint N to COUNT. */
10526 ignore_command (char *args, int from_tty)
10532 error_no_arg (_("a breakpoint number"));
10534 num = get_number (&p);
10536 error (_("bad breakpoint number: '%s'"), args);
10538 error (_("Second argument (specified ignore-count) is missing."));
10540 set_ignore_count (num,
10541 longest_to_int (value_as_long (parse_and_eval (p))),
10544 printf_filtered ("\n");
10547 /* Call FUNCTION on each of the breakpoints
10548 whose numbers are given in ARGS. */
10551 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
10558 struct breakpoint *b, *tmp;
10562 error_no_arg (_("one or more breakpoint numbers"));
10569 num = get_number_or_range (&p1);
10572 warning (_("bad breakpoint number at or near '%s'"), p);
10576 ALL_BREAKPOINTS_SAFE (b, tmp)
10577 if (b->number == num)
10579 struct breakpoint *related_breakpoint = b->related_breakpoint;
10581 function (b, data);
10582 if (related_breakpoint)
10583 function (related_breakpoint, data);
10587 printf_unfiltered (_("No breakpoint number %d.\n"), num);
10593 static struct bp_location *
10594 find_location_by_number (char *number)
10596 char *dot = strchr (number, '.');
10600 struct breakpoint *b;
10601 struct bp_location *loc;
10606 bp_num = get_number_or_range (&p1);
10608 error (_("Bad breakpoint number '%s'"), number);
10610 ALL_BREAKPOINTS (b)
10611 if (b->number == bp_num)
10616 if (!b || b->number != bp_num)
10617 error (_("Bad breakpoint number '%s'"), number);
10620 loc_num = get_number_or_range (&p1);
10622 error (_("Bad breakpoint location number '%s'"), number);
10626 for (;loc_num && loc; --loc_num, loc = loc->next)
10629 error (_("Bad breakpoint location number '%s'"), dot+1);
10635 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10636 If from_tty is nonzero, it prints a message to that effect,
10637 which ends with a period (no newline). */
10640 disable_breakpoint (struct breakpoint *bpt)
10642 /* Never disable a watchpoint scope breakpoint; we want to
10643 hit them when we leave scope so we can delete both the
10644 watchpoint and its scope breakpoint at that time. */
10645 if (bpt->type == bp_watchpoint_scope)
10648 /* You can't disable permanent breakpoints. */
10649 if (bpt->enable_state == bp_permanent)
10652 bpt->enable_state = bp_disabled;
10654 update_global_location_list (0);
10656 observer_notify_breakpoint_modified (bpt->number);
10659 /* A callback for map_breakpoint_numbers that calls
10660 disable_breakpoint. */
10663 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
10665 disable_breakpoint (b);
10669 disable_command (char *args, int from_tty)
10671 struct breakpoint *bpt;
10674 ALL_BREAKPOINTS (bpt)
10678 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10681 case bp_breakpoint:
10682 case bp_tracepoint:
10683 case bp_fast_tracepoint:
10684 case bp_static_tracepoint:
10685 case bp_catchpoint:
10686 case bp_hardware_breakpoint:
10687 case bp_watchpoint:
10688 case bp_hardware_watchpoint:
10689 case bp_read_watchpoint:
10690 case bp_access_watchpoint:
10691 disable_breakpoint (bpt);
10695 else if (strchr (args, '.'))
10697 struct bp_location *loc = find_location_by_number (args);
10700 update_global_location_list (0);
10703 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
10707 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
10709 int target_resources_ok;
10711 if (bpt->type == bp_hardware_breakpoint)
10714 i = hw_breakpoint_used_count ();
10715 target_resources_ok =
10716 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10718 if (target_resources_ok == 0)
10719 error (_("No hardware breakpoint support in the target."));
10720 else if (target_resources_ok < 0)
10721 error (_("Hardware breakpoints used exceeds limit."));
10724 if (is_watchpoint (bpt))
10726 struct gdb_exception e;
10728 TRY_CATCH (e, RETURN_MASK_ALL)
10730 update_watchpoint (bpt, 1 /* reparse */);
10734 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10740 if (bpt->enable_state != bp_permanent)
10741 bpt->enable_state = bp_enabled;
10742 bpt->disposition = disposition;
10743 update_global_location_list (1);
10744 breakpoints_changed ();
10746 observer_notify_breakpoint_modified (bpt->number);
10751 enable_breakpoint (struct breakpoint *bpt)
10753 do_enable_breakpoint (bpt, bpt->disposition);
10756 /* A callback for map_breakpoint_numbers that calls
10757 enable_breakpoint. */
10760 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10762 enable_breakpoint (b);
10765 /* The enable command enables the specified breakpoints (or all defined
10766 breakpoints) so they once again become (or continue to be) effective
10767 in stopping the inferior. */
10770 enable_command (char *args, int from_tty)
10772 struct breakpoint *bpt;
10775 ALL_BREAKPOINTS (bpt)
10779 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10782 case bp_breakpoint:
10783 case bp_tracepoint:
10784 case bp_fast_tracepoint:
10785 case bp_static_tracepoint:
10786 case bp_catchpoint:
10787 case bp_hardware_breakpoint:
10788 case bp_watchpoint:
10789 case bp_hardware_watchpoint:
10790 case bp_read_watchpoint:
10791 case bp_access_watchpoint:
10792 enable_breakpoint (bpt);
10796 else if (strchr (args, '.'))
10798 struct bp_location *loc = find_location_by_number (args);
10801 update_global_location_list (1);
10804 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
10808 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
10810 do_enable_breakpoint (bpt, disp_disable);
10814 enable_once_command (char *args, int from_tty)
10816 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
10820 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
10822 do_enable_breakpoint (bpt, disp_del);
10826 enable_delete_command (char *args, int from_tty)
10828 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
10832 set_breakpoint_cmd (char *args, int from_tty)
10837 show_breakpoint_cmd (char *args, int from_tty)
10841 /* Invalidate last known value of any hardware watchpoint if
10842 the memory which that value represents has been written to by
10846 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
10847 const bfd_byte *data)
10849 struct breakpoint *bp;
10851 ALL_BREAKPOINTS (bp)
10852 if (bp->enable_state == bp_enabled
10853 && bp->type == bp_hardware_watchpoint
10854 && bp->val_valid && bp->val)
10856 struct bp_location *loc;
10858 for (loc = bp->loc; loc != NULL; loc = loc->next)
10859 if (loc->loc_type == bp_loc_hardware_watchpoint
10860 && loc->address + loc->length > addr
10861 && addr + len > loc->address)
10863 value_free (bp->val);
10870 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10872 struct symtabs_and_lines
10873 decode_line_spec_1 (char *string, int funfirstline)
10875 struct symtabs_and_lines sals;
10878 error (_("Empty line specification."));
10879 if (default_breakpoint_valid)
10880 sals = decode_line_1 (&string, funfirstline,
10881 default_breakpoint_symtab,
10882 default_breakpoint_line,
10883 (char ***) NULL, NULL);
10885 sals = decode_line_1 (&string, funfirstline,
10886 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
10888 error (_("Junk at end of line specification: %s"), string);
10892 /* Create and insert a raw software breakpoint at PC. Return an
10893 identifier, which should be used to remove the breakpoint later.
10894 In general, places which call this should be using something on the
10895 breakpoint chain instead; this function should be eliminated
10899 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
10900 struct address_space *aspace, CORE_ADDR pc)
10902 struct bp_target_info *bp_tgt;
10904 bp_tgt = XZALLOC (struct bp_target_info);
10906 bp_tgt->placed_address_space = aspace;
10907 bp_tgt->placed_address = pc;
10909 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
10911 /* Could not insert the breakpoint. */
10919 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10922 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
10924 struct bp_target_info *bp_tgt = bp;
10927 ret = target_remove_breakpoint (gdbarch, bp_tgt);
10933 /* One (or perhaps two) breakpoints used for software single stepping. */
10935 static void *single_step_breakpoints[2];
10936 static struct gdbarch *single_step_gdbarch[2];
10938 /* Create and insert a breakpoint for software single step. */
10941 insert_single_step_breakpoint (struct gdbarch *gdbarch,
10942 struct address_space *aspace, CORE_ADDR next_pc)
10946 if (single_step_breakpoints[0] == NULL)
10948 bpt_p = &single_step_breakpoints[0];
10949 single_step_gdbarch[0] = gdbarch;
10953 gdb_assert (single_step_breakpoints[1] == NULL);
10954 bpt_p = &single_step_breakpoints[1];
10955 single_step_gdbarch[1] = gdbarch;
10958 /* NOTE drow/2006-04-11: A future improvement to this function would be
10959 to only create the breakpoints once, and actually put them on the
10960 breakpoint chain. That would let us use set_raw_breakpoint. We could
10961 adjust the addresses each time they were needed. Doing this requires
10962 corresponding changes elsewhere where single step breakpoints are
10963 handled, however. So, for now, we use this. */
10965 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
10966 if (*bpt_p == NULL)
10967 error (_("Could not insert single-step breakpoint at %s"),
10968 paddress (gdbarch, next_pc));
10971 /* Check if the breakpoints used for software single stepping
10972 were inserted or not. */
10975 single_step_breakpoints_inserted (void)
10977 return (single_step_breakpoints[0] != NULL
10978 || single_step_breakpoints[1] != NULL);
10981 /* Remove and delete any breakpoints used for software single step. */
10984 remove_single_step_breakpoints (void)
10986 gdb_assert (single_step_breakpoints[0] != NULL);
10988 /* See insert_single_step_breakpoint for more about this deprecated
10990 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
10991 single_step_breakpoints[0]);
10992 single_step_gdbarch[0] = NULL;
10993 single_step_breakpoints[0] = NULL;
10995 if (single_step_breakpoints[1] != NULL)
10997 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
10998 single_step_breakpoints[1]);
10999 single_step_gdbarch[1] = NULL;
11000 single_step_breakpoints[1] = NULL;
11004 /* Delete software single step breakpoints without removing them from
11005 the inferior. This is intended to be used if the inferior's address
11006 space where they were inserted is already gone, e.g. after exit or
11010 cancel_single_step_breakpoints (void)
11014 for (i = 0; i < 2; i++)
11015 if (single_step_breakpoints[i])
11017 xfree (single_step_breakpoints[i]);
11018 single_step_breakpoints[i] = NULL;
11019 single_step_gdbarch[i] = NULL;
11023 /* Detach software single-step breakpoints from INFERIOR_PTID without
11027 detach_single_step_breakpoints (void)
11031 for (i = 0; i < 2; i++)
11032 if (single_step_breakpoints[i])
11033 target_remove_breakpoint (single_step_gdbarch[i],
11034 single_step_breakpoints[i]);
11037 /* Check whether a software single-step breakpoint is inserted at PC. */
11040 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
11045 for (i = 0; i < 2; i++)
11047 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
11049 && breakpoint_address_match (bp_tgt->placed_address_space,
11050 bp_tgt->placed_address,
11058 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11059 non-zero otherwise. */
11061 is_syscall_catchpoint_enabled (struct breakpoint *bp)
11063 if (syscall_catchpoint_p (bp)
11064 && bp->enable_state != bp_disabled
11065 && bp->enable_state != bp_call_disabled)
11072 catch_syscall_enabled (void)
11074 struct inferior *inf = current_inferior ();
11076 return inf->total_syscalls_count != 0;
11080 catching_syscall_number (int syscall_number)
11082 struct breakpoint *bp;
11084 ALL_BREAKPOINTS (bp)
11085 if (is_syscall_catchpoint_enabled (bp))
11087 if (bp->syscalls_to_be_caught)
11091 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
11093 if (syscall_number == iter)
11103 /* Complete syscall names. Used by "catch syscall". */
11105 catch_syscall_completer (struct cmd_list_element *cmd,
11106 char *text, char *word)
11108 const char **list = get_syscall_names ();
11110 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
11113 /* Tracepoint-specific operations. */
11115 /* Set tracepoint count to NUM. */
11117 set_tracepoint_count (int num)
11119 tracepoint_count = num;
11120 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
11124 trace_command (char *arg, int from_tty)
11126 if (create_breakpoint (get_current_arch (),
11128 NULL, 0, 1 /* parse arg */,
11130 bp_tracepoint /* type_wanted */,
11131 0 /* Ignore count */,
11132 pending_break_support,
11137 set_tracepoint_count (breakpoint_count);
11141 ftrace_command (char *arg, int from_tty)
11143 if (create_breakpoint (get_current_arch (),
11145 NULL, 0, 1 /* parse arg */,
11147 bp_fast_tracepoint /* type_wanted */,
11148 0 /* Ignore count */,
11149 pending_break_support,
11154 set_tracepoint_count (breakpoint_count);
11157 /* strace command implementation. Creates a static tracepoint. */
11160 strace_command (char *arg, int from_tty)
11162 if (create_breakpoint (get_current_arch (),
11164 NULL, 0, 1 /* parse arg */,
11166 bp_static_tracepoint /* type_wanted */,
11167 0 /* Ignore count */,
11168 pending_break_support,
11173 set_tracepoint_count (breakpoint_count);
11176 /* Set up a fake reader function that gets command lines from a linked
11177 list that was acquired during tracepoint uploading. */
11179 static struct uploaded_tp *this_utp;
11180 static int next_cmd;
11183 read_uploaded_action (void)
11187 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
11194 /* Given information about a tracepoint as recorded on a target (which
11195 can be either a live system or a trace file), attempt to create an
11196 equivalent GDB tracepoint. This is not a reliable process, since
11197 the target does not necessarily have all the information used when
11198 the tracepoint was originally defined. */
11200 struct breakpoint *
11201 create_tracepoint_from_upload (struct uploaded_tp *utp)
11203 char *addr_str, small_buf[100];
11204 struct breakpoint *tp;
11206 if (utp->at_string)
11207 addr_str = utp->at_string;
11210 /* In the absence of a source location, fall back to raw
11211 address. Since there is no way to confirm that the address
11212 means the same thing as when the trace was started, warn the
11214 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
11216 sprintf (small_buf, "*%s", hex_string (utp->addr));
11217 addr_str = small_buf;
11220 /* There's not much we can do with a sequence of bytecodes. */
11221 if (utp->cond && !utp->cond_string)
11222 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
11225 if (!create_breakpoint (get_current_arch (),
11227 utp->cond_string, -1, 0 /* parse cond/thread */,
11229 utp->type /* type_wanted */,
11230 0 /* Ignore count */,
11231 pending_break_support,
11234 utp->enabled /* enabled */,
11238 set_tracepoint_count (breakpoint_count);
11240 /* Get the tracepoint we just created. */
11241 tp = get_tracepoint (tracepoint_count);
11242 gdb_assert (tp != NULL);
11246 sprintf (small_buf, "%d %d", utp->pass, tp->number);
11248 trace_pass_command (small_buf, 0);
11251 /* If we have uploaded versions of the original commands, set up a
11252 special-purpose "reader" function and call the usual command line
11253 reader, then pass the result to the breakpoint command-setting
11255 if (!VEC_empty (char_ptr, utp->cmd_strings))
11257 struct command_line *cmd_list;
11262 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
11264 breakpoint_set_commands (tp, cmd_list);
11266 else if (!VEC_empty (char_ptr, utp->actions)
11267 || !VEC_empty (char_ptr, utp->step_actions))
11268 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
11274 /* Print information on tracepoint number TPNUM_EXP, or all if
11278 tracepoints_info (char *tpnum_exp, int from_tty)
11280 int tpnum = -1, num_printed;
11283 tpnum = parse_and_eval_long (tpnum_exp);
11285 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
11287 if (num_printed == 0)
11290 ui_out_message (uiout, 0, "No tracepoints.\n");
11292 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
11295 default_collect_info ();
11298 /* The 'enable trace' command enables tracepoints.
11299 Not supported by all targets. */
11301 enable_trace_command (char *args, int from_tty)
11303 enable_command (args, from_tty);
11306 /* The 'disable trace' command disables tracepoints.
11307 Not supported by all targets. */
11309 disable_trace_command (char *args, int from_tty)
11311 disable_command (args, from_tty);
11314 /* Remove a tracepoint (or all if no argument) */
11316 delete_trace_command (char *arg, int from_tty)
11318 struct breakpoint *b, *b_tmp;
11324 int breaks_to_delete = 0;
11326 /* Delete all breakpoints if no argument.
11327 Do not delete internal or call-dummy breakpoints, these
11328 have to be deleted with an explicit breakpoint number argument. */
11329 ALL_TRACEPOINTS (b)
11331 if (b->number >= 0)
11333 breaks_to_delete = 1;
11338 /* Ask user only if there are some breakpoints to delete. */
11340 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
11342 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11344 if (is_tracepoint (b)
11346 delete_breakpoint (b);
11351 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
11354 /* Set passcount for tracepoint.
11356 First command argument is passcount, second is tracepoint number.
11357 If tracepoint number omitted, apply to most recently defined.
11358 Also accepts special argument "all". */
11361 trace_pass_command (char *args, int from_tty)
11363 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
11364 unsigned int count;
11367 if (args == 0 || *args == 0)
11368 error (_("passcount command requires an argument (count + optional TP num)"));
11370 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
11372 while (*args && isspace ((int) *args))
11375 if (*args && strncasecmp (args, "all", 3) == 0)
11377 args += 3; /* Skip special argument "all". */
11380 error (_("Junk at end of arguments."));
11383 t1 = get_tracepoint_by_number (&args, 1, 1);
11389 ALL_TRACEPOINTS (t2)
11390 if (t1 == (struct breakpoint *) -1 || t1 == t2)
11392 t2->pass_count = count;
11393 observer_notify_tracepoint_modified (t2->number);
11395 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
11396 t2->number, count);
11398 if (! all && *args)
11399 t1 = get_tracepoint_by_number (&args, 1, 0);
11405 struct breakpoint *
11406 get_tracepoint (int num)
11408 struct breakpoint *t;
11410 ALL_TRACEPOINTS (t)
11411 if (t->number == num)
11417 /* Find the tracepoint with the given target-side number (which may be
11418 different from the tracepoint number after disconnecting and
11421 struct breakpoint *
11422 get_tracepoint_by_number_on_target (int num)
11424 struct breakpoint *t;
11426 ALL_TRACEPOINTS (t)
11427 if (t->number_on_target == num)
11433 /* Utility: parse a tracepoint number and look it up in the list.
11434 If MULTI_P is true, there might be a range of tracepoints in ARG.
11435 if OPTIONAL_P is true, then if the argument is missing, the most
11436 recent tracepoint (tracepoint_count) is returned. */
11437 struct breakpoint *
11438 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
11440 extern int tracepoint_count;
11441 struct breakpoint *t;
11443 char *instring = arg == NULL ? NULL : *arg;
11445 if (arg == NULL || *arg == NULL || ! **arg)
11448 tpnum = tracepoint_count;
11450 error_no_arg (_("tracepoint number"));
11453 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
11457 if (instring && *instring)
11458 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11461 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
11465 ALL_TRACEPOINTS (t)
11466 if (t->number == tpnum)
11471 /* FIXME: if we are in the middle of a range we don't want to give
11472 a message. The current interface to get_number_or_range doesn't
11473 allow us to discover this. */
11474 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
11478 /* Save information on user settable breakpoints (watchpoints, etc) to
11479 a new script file named FILENAME. If FILTER is non-NULL, call it
11480 on each breakpoint and only include the ones for which it returns
11484 save_breakpoints (char *filename, int from_tty,
11485 int (*filter) (const struct breakpoint *))
11487 struct breakpoint *tp;
11490 struct cleanup *cleanup;
11491 struct ui_file *fp;
11492 int extra_trace_bits = 0;
11494 if (filename == 0 || *filename == 0)
11495 error (_("Argument required (file name in which to save)"));
11497 /* See if we have anything to save. */
11498 ALL_BREAKPOINTS (tp)
11500 /* Skip internal and momentary breakpoints. */
11501 if (!user_settable_breakpoint (tp) || tp->number < 0)
11504 /* If we have a filter, only save the breakpoints it accepts. */
11505 if (filter && !filter (tp))
11510 if (is_tracepoint (tp))
11512 extra_trace_bits = 1;
11514 /* We can stop searching. */
11521 warning (_("Nothing to save."));
11525 pathname = tilde_expand (filename);
11526 cleanup = make_cleanup (xfree, pathname);
11527 fp = gdb_fopen (pathname, "w");
11529 error (_("Unable to open file '%s' for saving (%s)"),
11530 filename, safe_strerror (errno));
11531 make_cleanup_ui_file_delete (fp);
11533 if (extra_trace_bits)
11534 save_trace_state_variables (fp);
11536 ALL_BREAKPOINTS (tp)
11538 /* Skip internal and momentary breakpoints. */
11539 if (!user_settable_breakpoint (tp) || tp->number < 0)
11542 /* If we have a filter, only save the breakpoints it accepts. */
11543 if (filter && !filter (tp))
11546 if (tp->ops != NULL)
11547 (tp->ops->print_recreate) (tp, fp);
11550 if (tp->type == bp_fast_tracepoint)
11551 fprintf_unfiltered (fp, "ftrace");
11552 if (tp->type == bp_static_tracepoint)
11553 fprintf_unfiltered (fp, "strace");
11554 else if (tp->type == bp_tracepoint)
11555 fprintf_unfiltered (fp, "trace");
11556 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11557 fprintf_unfiltered (fp, "tbreak");
11558 else if (tp->type == bp_breakpoint)
11559 fprintf_unfiltered (fp, "break");
11560 else if (tp->type == bp_hardware_breakpoint
11561 && tp->disposition == disp_del)
11562 fprintf_unfiltered (fp, "thbreak");
11563 else if (tp->type == bp_hardware_breakpoint)
11564 fprintf_unfiltered (fp, "hbreak");
11565 else if (tp->type == bp_watchpoint)
11566 fprintf_unfiltered (fp, "watch");
11567 else if (tp->type == bp_hardware_watchpoint)
11568 fprintf_unfiltered (fp, "watch");
11569 else if (tp->type == bp_read_watchpoint)
11570 fprintf_unfiltered (fp, "rwatch");
11571 else if (tp->type == bp_access_watchpoint)
11572 fprintf_unfiltered (fp, "awatch");
11574 internal_error (__FILE__, __LINE__,
11575 _("unhandled breakpoint type %d"), (int) tp->type);
11577 if (tp->exp_string)
11578 fprintf_unfiltered (fp, " %s", tp->exp_string);
11579 else if (tp->addr_string)
11580 fprintf_unfiltered (fp, " %s", tp->addr_string);
11585 sprintf_vma (tmp, tp->loc->address);
11586 fprintf_unfiltered (fp, " *0x%s", tmp);
11590 if (tp->thread != -1)
11591 fprintf_unfiltered (fp, " thread %d", tp->thread);
11594 fprintf_unfiltered (fp, " task %d", tp->task);
11596 fprintf_unfiltered (fp, "\n");
11598 /* Note, we can't rely on tp->number for anything, as we can't
11599 assume the recreated breakpoint numbers will match. Use $bpnum
11602 if (tp->cond_string)
11603 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
11605 if (tp->ignore_count)
11606 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
11608 if (tp->pass_count)
11609 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11613 volatile struct gdb_exception ex;
11615 fprintf_unfiltered (fp, " commands\n");
11617 ui_out_redirect (uiout, fp);
11618 TRY_CATCH (ex, RETURN_MASK_ALL)
11620 print_command_lines (uiout, tp->commands->commands, 2);
11622 ui_out_redirect (uiout, NULL);
11625 throw_exception (ex);
11627 fprintf_unfiltered (fp, " end\n");
11630 if (tp->enable_state == bp_disabled)
11631 fprintf_unfiltered (fp, "disable\n");
11633 /* If this is a multi-location breakpoint, check if the locations
11634 should be individually disabled. Watchpoint locations are
11635 special, and not user visible. */
11636 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
11638 struct bp_location *loc;
11641 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
11643 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
11647 if (extra_trace_bits && *default_collect)
11648 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
11650 do_cleanups (cleanup);
11652 printf_filtered (_("Saved to file '%s'.\n"), filename);
11655 /* The `save breakpoints' command. */
11658 save_breakpoints_command (char *args, int from_tty)
11660 save_breakpoints (args, from_tty, NULL);
11663 /* The `save tracepoints' command. */
11666 save_tracepoints_command (char *args, int from_tty)
11668 save_breakpoints (args, from_tty, is_tracepoint);
11671 /* Create a vector of all tracepoints. */
11673 VEC(breakpoint_p) *
11676 VEC(breakpoint_p) *tp_vec = 0;
11677 struct breakpoint *tp;
11679 ALL_TRACEPOINTS (tp)
11681 VEC_safe_push (breakpoint_p, tp_vec, tp);
11688 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11689 It is defined as a macro to prevent duplication.
11690 COMMAND should be a string constant containing the name of the command. */
11691 #define BREAK_ARGS_HELP(command) \
11692 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11693 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11694 If a line number is specified, break at start of code for that line.\n\
11695 If a function is specified, break at start of code for that function.\n\
11696 If an address is specified, break at that exact address.\n\
11697 With no LOCATION, uses current execution address of the selected\n\
11698 stack frame. This is useful for breaking on return to a stack frame.\n\
11700 THREADNUM is the number from \"info threads\".\n\
11701 CONDITION is a boolean expression.\n\
11703 Multiple breakpoints at one place are permitted, and useful if their\n\
11704 conditions are different.\n\
11706 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11708 /* List of subcommands for "catch". */
11709 static struct cmd_list_element *catch_cmdlist;
11711 /* List of subcommands for "tcatch". */
11712 static struct cmd_list_element *tcatch_cmdlist;
11714 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11715 lists, and pass some additional user data to the command function. */
11717 add_catch_command (char *name, char *docstring,
11718 void (*sfunc) (char *args, int from_tty,
11719 struct cmd_list_element *command),
11720 char **(*completer) (struct cmd_list_element *cmd,
11721 char *text, char *word),
11722 void *user_data_catch,
11723 void *user_data_tcatch)
11725 struct cmd_list_element *command;
11727 command = add_cmd (name, class_breakpoint, NULL, docstring,
11729 set_cmd_sfunc (command, sfunc);
11730 set_cmd_context (command, user_data_catch);
11731 set_cmd_completer (command, completer);
11733 command = add_cmd (name, class_breakpoint, NULL, docstring,
11735 set_cmd_sfunc (command, sfunc);
11736 set_cmd_context (command, user_data_tcatch);
11737 set_cmd_completer (command, completer);
11741 clear_syscall_counts (struct inferior *inf)
11743 inf->total_syscalls_count = 0;
11744 inf->any_syscall_count = 0;
11745 VEC_free (int, inf->syscalls_counts);
11749 save_command (char *arg, int from_tty)
11751 printf_unfiltered (_("\
11752 \"save\" must be followed by the name of a save subcommand.\n"));
11753 help_list (save_cmdlist, "save ", -1, gdb_stdout);
11756 struct breakpoint *
11757 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
11760 struct breakpoint *b, *b_tmp;
11762 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11764 if ((*callback) (b, data))
11772 _initialize_breakpoint (void)
11774 struct cmd_list_element *c;
11776 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
11777 observer_attach_inferior_exit (clear_syscall_counts);
11778 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
11780 breakpoint_chain = 0;
11781 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11782 before a breakpoint is set. */
11783 breakpoint_count = 0;
11785 tracepoint_count = 0;
11787 add_com ("ignore", class_breakpoint, ignore_command, _("\
11788 Set ignore-count of breakpoint number N to COUNT.\n\
11789 Usage is `ignore N COUNT'."));
11791 add_com_alias ("bc", "ignore", class_breakpoint, 1);
11793 add_com ("commands", class_breakpoint, commands_command, _("\
11794 Set commands to be executed when a breakpoint is hit.\n\
11795 Give breakpoint number as argument after \"commands\".\n\
11796 With no argument, the targeted breakpoint is the last one set.\n\
11797 The commands themselves follow starting on the next line.\n\
11798 Type a line containing \"end\" to indicate the end of them.\n\
11799 Give \"silent\" as the first line to make the breakpoint silent;\n\
11800 then no output is printed when it is hit, except what the commands print."));
11802 add_com ("condition", class_breakpoint, condition_command, _("\
11803 Specify breakpoint number N to break only if COND is true.\n\
11804 Usage is `condition N COND', where N is an integer and COND is an\n\
11805 expression to be evaluated whenever breakpoint N is reached."));
11807 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
11808 Set a temporary breakpoint.\n\
11809 Like \"break\" except the breakpoint is only temporary,\n\
11810 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11811 by using \"enable delete\" on the breakpoint number.\n\
11813 BREAK_ARGS_HELP ("tbreak")));
11814 set_cmd_completer (c, location_completer);
11816 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
11817 Set a hardware assisted breakpoint.\n\
11818 Like \"break\" except the breakpoint requires hardware support,\n\
11819 some target hardware may not have this support.\n\
11821 BREAK_ARGS_HELP ("hbreak")));
11822 set_cmd_completer (c, location_completer);
11824 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
11825 Set a temporary hardware assisted breakpoint.\n\
11826 Like \"hbreak\" except the breakpoint is only temporary,\n\
11827 so it will be deleted when hit.\n\
11829 BREAK_ARGS_HELP ("thbreak")));
11830 set_cmd_completer (c, location_completer);
11832 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
11833 Enable some breakpoints.\n\
11834 Give breakpoint numbers (separated by spaces) as arguments.\n\
11835 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11836 This is used to cancel the effect of the \"disable\" command.\n\
11837 With a subcommand you can enable temporarily."),
11838 &enablelist, "enable ", 1, &cmdlist);
11840 add_com ("ab", class_breakpoint, enable_command, _("\
11841 Enable some breakpoints.\n\
11842 Give breakpoint numbers (separated by spaces) as arguments.\n\
11843 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11844 This is used to cancel the effect of the \"disable\" command.\n\
11845 With a subcommand you can enable temporarily."));
11847 add_com_alias ("en", "enable", class_breakpoint, 1);
11849 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
11850 Enable some breakpoints.\n\
11851 Give breakpoint numbers (separated by spaces) as arguments.\n\
11852 This is used to cancel the effect of the \"disable\" command.\n\
11853 May be abbreviated to simply \"enable\".\n"),
11854 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
11856 add_cmd ("once", no_class, enable_once_command, _("\
11857 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11858 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11861 add_cmd ("delete", no_class, enable_delete_command, _("\
11862 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11863 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11866 add_cmd ("delete", no_class, enable_delete_command, _("\
11867 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11868 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11871 add_cmd ("once", no_class, enable_once_command, _("\
11872 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11873 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11876 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
11877 Disable some breakpoints.\n\
11878 Arguments are breakpoint numbers with spaces in between.\n\
11879 To disable all breakpoints, give no argument.\n\
11880 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11881 &disablelist, "disable ", 1, &cmdlist);
11882 add_com_alias ("dis", "disable", class_breakpoint, 1);
11883 add_com_alias ("disa", "disable", class_breakpoint, 1);
11885 add_com ("sb", class_breakpoint, disable_command, _("\
11886 Disable some breakpoints.\n\
11887 Arguments are breakpoint numbers with spaces in between.\n\
11888 To disable all breakpoints, give no argument.\n\
11889 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11891 add_cmd ("breakpoints", class_alias, disable_command, _("\
11892 Disable some breakpoints.\n\
11893 Arguments are breakpoint numbers with spaces in between.\n\
11894 To disable all breakpoints, give no argument.\n\
11895 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11896 This command may be abbreviated \"disable\"."),
11899 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
11900 Delete some breakpoints or auto-display expressions.\n\
11901 Arguments are breakpoint numbers with spaces in between.\n\
11902 To delete all breakpoints, give no argument.\n\
11904 Also a prefix command for deletion of other GDB objects.\n\
11905 The \"unset\" command is also an alias for \"delete\"."),
11906 &deletelist, "delete ", 1, &cmdlist);
11907 add_com_alias ("d", "delete", class_breakpoint, 1);
11908 add_com_alias ("del", "delete", class_breakpoint, 1);
11910 add_com ("db", class_breakpoint, delete_command, _("\
11911 Delete some breakpoints.\n\
11912 Arguments are breakpoint numbers with spaces in between.\n\
11913 To delete all breakpoints, give no argument.\n"));
11915 add_cmd ("breakpoints", class_alias, delete_command, _("\
11916 Delete some breakpoints or auto-display expressions.\n\
11917 Arguments are breakpoint numbers with spaces in between.\n\
11918 To delete all breakpoints, give no argument.\n\
11919 This command may be abbreviated \"delete\"."),
11922 add_com ("clear", class_breakpoint, clear_command, _("\
11923 Clear breakpoint at specified line or function.\n\
11924 Argument may be line number, function name, or \"*\" and an address.\n\
11925 If line number is specified, all breakpoints in that line are cleared.\n\
11926 If function is specified, breakpoints at beginning of function are cleared.\n\
11927 If an address is specified, breakpoints at that address are cleared.\n\
11929 With no argument, clears all breakpoints in the line that the selected frame\n\
11930 is executing in.\n\
11932 See also the \"delete\" command which clears breakpoints by number."));
11933 add_com_alias ("cl", "clear", class_breakpoint, 1);
11935 c = add_com ("break", class_breakpoint, break_command, _("\
11936 Set breakpoint at specified line or function.\n"
11937 BREAK_ARGS_HELP ("break")));
11938 set_cmd_completer (c, location_completer);
11940 add_com_alias ("b", "break", class_run, 1);
11941 add_com_alias ("br", "break", class_run, 1);
11942 add_com_alias ("bre", "break", class_run, 1);
11943 add_com_alias ("brea", "break", class_run, 1);
11946 add_com_alias ("ba", "break", class_breakpoint, 1);
11950 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
11951 Break in function/address or break at a line in the current file."),
11952 &stoplist, "stop ", 1, &cmdlist);
11953 add_cmd ("in", class_breakpoint, stopin_command,
11954 _("Break in function or address."), &stoplist);
11955 add_cmd ("at", class_breakpoint, stopat_command,
11956 _("Break at a line in the current file."), &stoplist);
11957 add_com ("status", class_info, breakpoints_info, _("\
11958 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11959 The \"Type\" column indicates one of:\n\
11960 \tbreakpoint - normal breakpoint\n\
11961 \twatchpoint - watchpoint\n\
11962 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11963 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11964 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11965 address and file/line number respectively.\n\
11967 Convenience variable \"$_\" and default examine address for \"x\"\n\
11968 are set to the address of the last breakpoint listed unless the command\n\
11969 is prefixed with \"server \".\n\n\
11970 Convenience variable \"$bpnum\" contains the number of the last\n\
11971 breakpoint set."));
11974 add_info ("breakpoints", breakpoints_info, _("\
11975 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11976 The \"Type\" column indicates one of:\n\
11977 \tbreakpoint - normal breakpoint\n\
11978 \twatchpoint - watchpoint\n\
11979 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11980 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11981 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11982 address and file/line number respectively.\n\
11984 Convenience variable \"$_\" and default examine address for \"x\"\n\
11985 are set to the address of the last breakpoint listed unless the command\n\
11986 is prefixed with \"server \".\n\n\
11987 Convenience variable \"$bpnum\" contains the number of the last\n\
11988 breakpoint set."));
11990 add_info_alias ("b", "breakpoints", 1);
11993 add_com ("lb", class_breakpoint, breakpoints_info, _("\
11994 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11995 The \"Type\" column indicates one of:\n\
11996 \tbreakpoint - normal breakpoint\n\
11997 \twatchpoint - watchpoint\n\
11998 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11999 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12000 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12001 address and file/line number respectively.\n\
12003 Convenience variable \"$_\" and default examine address for \"x\"\n\
12004 are set to the address of the last breakpoint listed unless the command\n\
12005 is prefixed with \"server \".\n\n\
12006 Convenience variable \"$bpnum\" contains the number of the last\n\
12007 breakpoint set."));
12009 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
12010 Status of all breakpoints, or breakpoint number NUMBER.\n\
12011 The \"Type\" column indicates one of:\n\
12012 \tbreakpoint - normal breakpoint\n\
12013 \twatchpoint - watchpoint\n\
12014 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12015 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12016 \tuntil - internal breakpoint used by the \"until\" command\n\
12017 \tfinish - internal breakpoint used by the \"finish\" command\n\
12018 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12019 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12020 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12021 address and file/line number respectively.\n\
12023 Convenience variable \"$_\" and default examine address for \"x\"\n\
12024 are set to the address of the last breakpoint listed unless the command\n\
12025 is prefixed with \"server \".\n\n\
12026 Convenience variable \"$bpnum\" contains the number of the last\n\
12028 &maintenanceinfolist);
12030 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
12031 Set catchpoints to catch events."),
12032 &catch_cmdlist, "catch ",
12033 0/*allow-unknown*/, &cmdlist);
12035 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
12036 Set temporary catchpoints to catch events."),
12037 &tcatch_cmdlist, "tcatch ",
12038 0/*allow-unknown*/, &cmdlist);
12040 /* Add catch and tcatch sub-commands. */
12041 add_catch_command ("catch", _("\
12042 Catch an exception, when caught.\n\
12043 With an argument, catch only exceptions with the given name."),
12044 catch_catch_command,
12048 add_catch_command ("throw", _("\
12049 Catch an exception, when thrown.\n\
12050 With an argument, catch only exceptions with the given name."),
12051 catch_throw_command,
12055 add_catch_command ("fork", _("Catch calls to fork."),
12056 catch_fork_command_1,
12058 (void *) (uintptr_t) catch_fork_permanent,
12059 (void *) (uintptr_t) catch_fork_temporary);
12060 add_catch_command ("vfork", _("Catch calls to vfork."),
12061 catch_fork_command_1,
12063 (void *) (uintptr_t) catch_vfork_permanent,
12064 (void *) (uintptr_t) catch_vfork_temporary);
12065 add_catch_command ("exec", _("Catch calls to exec."),
12066 catch_exec_command_1,
12070 add_catch_command ("syscall", _("\
12071 Catch system calls by their names and/or numbers.\n\
12072 Arguments say which system calls to catch. If no arguments\n\
12073 are given, every system call will be caught.\n\
12074 Arguments, if given, should be one or more system call names\n\
12075 (if your system supports that), or system call numbers."),
12076 catch_syscall_command_1,
12077 catch_syscall_completer,
12080 add_catch_command ("exception", _("\
12081 Catch Ada exceptions, when raised.\n\
12082 With an argument, catch only exceptions with the given name."),
12083 catch_ada_exception_command,
12087 add_catch_command ("assert", _("\
12088 Catch failed Ada assertions, when raised.\n\
12089 With an argument, catch only exceptions with the given name."),
12090 catch_assert_command,
12095 c = add_com ("watch", class_breakpoint, watch_command, _("\
12096 Set a watchpoint for an expression.\n\
12097 Usage: watch [-l|-location] EXPRESSION\n\
12098 A watchpoint stops execution of your program whenever the value of\n\
12099 an expression changes.\n\
12100 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12101 the memory to which it refers."));
12102 set_cmd_completer (c, expression_completer);
12104 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
12105 Set a read watchpoint for an expression.\n\
12106 Usage: rwatch [-l|-location] EXPRESSION\n\
12107 A watchpoint stops execution of your program whenever the value of\n\
12108 an expression is read.\n\
12109 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12110 the memory to which it refers."));
12111 set_cmd_completer (c, expression_completer);
12113 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
12114 Set a watchpoint for an expression.\n\
12115 Usage: awatch [-l|-location] EXPRESSION\n\
12116 A watchpoint stops execution of your program whenever the value of\n\
12117 an expression is either read or written.\n\
12118 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12119 the memory to which it refers."));
12120 set_cmd_completer (c, expression_completer);
12122 add_info ("watchpoints", watchpoints_info, _("\
12123 Status of watchpoints, or watchpoint number NUMBER."));
12127 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12128 respond to changes - contrary to the description. */
12129 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
12130 &can_use_hw_watchpoints, _("\
12131 Set debugger's willingness to use watchpoint hardware."), _("\
12132 Show debugger's willingness to use watchpoint hardware."), _("\
12133 If zero, gdb will not use hardware for new watchpoints, even if\n\
12134 such is available. (However, any hardware watchpoints that were\n\
12135 created before setting this to nonzero, will continue to use watchpoint\n\
12138 show_can_use_hw_watchpoints,
12139 &setlist, &showlist);
12141 can_use_hw_watchpoints = 1;
12143 /* Tracepoint manipulation commands. */
12145 c = add_com ("trace", class_breakpoint, trace_command, _("\
12146 Set a tracepoint at specified line or function.\n\
12148 BREAK_ARGS_HELP ("trace") "\n\
12149 Do \"help tracepoints\" for info on other tracepoint commands."));
12150 set_cmd_completer (c, location_completer);
12152 add_com_alias ("tp", "trace", class_alias, 0);
12153 add_com_alias ("tr", "trace", class_alias, 1);
12154 add_com_alias ("tra", "trace", class_alias, 1);
12155 add_com_alias ("trac", "trace", class_alias, 1);
12157 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
12158 Set a fast tracepoint at specified line or function.\n\
12160 BREAK_ARGS_HELP ("ftrace") "\n\
12161 Do \"help tracepoints\" for info on other tracepoint commands."));
12162 set_cmd_completer (c, location_completer);
12164 c = add_com ("strace", class_breakpoint, strace_command, _("\
12165 Set a static tracepoint at specified line, function or marker.\n\
12167 strace [LOCATION] [if CONDITION]\n\
12168 LOCATION may be a line number, function name, \"*\" and an address,\n\
12169 or -m MARKER_ID.\n\
12170 If a line number is specified, probe the marker at start of code\n\
12171 for that line. If a function is specified, probe the marker at start\n\
12172 of code for that function. If an address is specified, probe the marker\n\
12173 at that exact address. If a marker id is specified, probe the marker\n\
12174 with that name. With no LOCATION, uses current execution address of\n\
12175 the selected stack frame.\n\
12176 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12177 This collects arbitrary user data passed in the probe point call to the\n\
12178 tracing library. You can inspect it when analyzing the trace buffer,\n\
12179 by printing the $_sdata variable like any other convenience variable.\n\
12181 CONDITION is a boolean expression.\n\
12183 Multiple tracepoints at one place are permitted, and useful if their\n\
12184 conditions are different.\n\
12186 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12187 Do \"help tracepoints\" for info on other tracepoint commands."));
12188 set_cmd_completer (c, location_completer);
12190 add_info ("tracepoints", tracepoints_info, _("\
12191 Status of tracepoints, or tracepoint number NUMBER.\n\
12192 Convenience variable \"$tpnum\" contains the number of the\n\
12193 last tracepoint set."));
12195 add_info_alias ("tp", "tracepoints", 1);
12197 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
12198 Delete specified tracepoints.\n\
12199 Arguments are tracepoint numbers, separated by spaces.\n\
12200 No argument means delete all tracepoints."),
12203 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
12204 Disable specified tracepoints.\n\
12205 Arguments are tracepoint numbers, separated by spaces.\n\
12206 No argument means disable all tracepoints."),
12208 deprecate_cmd (c, "disable");
12210 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
12211 Enable specified tracepoints.\n\
12212 Arguments are tracepoint numbers, separated by spaces.\n\
12213 No argument means enable all tracepoints."),
12215 deprecate_cmd (c, "enable");
12217 add_com ("passcount", class_trace, trace_pass_command, _("\
12218 Set the passcount for a tracepoint.\n\
12219 The trace will end when the tracepoint has been passed 'count' times.\n\
12220 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12221 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12223 add_prefix_cmd ("save", class_breakpoint, save_command,
12224 _("Save breakpoint definitions as a script."),
12225 &save_cmdlist, "save ",
12226 0/*allow-unknown*/, &cmdlist);
12228 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
12229 Save current breakpoint definitions as a script.\n\
12230 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12231 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12232 session to restore them."),
12234 set_cmd_completer (c, filename_completer);
12236 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
12237 Save current tracepoint definitions as a script.\n\
12238 Use the 'source' command in another debug session to restore them."),
12240 set_cmd_completer (c, filename_completer);
12242 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
12243 deprecate_cmd (c, "save tracepoints");
12245 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
12246 Breakpoint specific settings\n\
12247 Configure various breakpoint-specific variables such as\n\
12248 pending breakpoint behavior"),
12249 &breakpoint_set_cmdlist, "set breakpoint ",
12250 0/*allow-unknown*/, &setlist);
12251 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
12252 Breakpoint specific settings\n\
12253 Configure various breakpoint-specific variables such as\n\
12254 pending breakpoint behavior"),
12255 &breakpoint_show_cmdlist, "show breakpoint ",
12256 0/*allow-unknown*/, &showlist);
12258 add_setshow_auto_boolean_cmd ("pending", no_class,
12259 &pending_break_support, _("\
12260 Set debugger's behavior regarding pending breakpoints."), _("\
12261 Show debugger's behavior regarding pending breakpoints."), _("\
12262 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12263 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12264 an error. If auto, an unrecognized breakpoint location results in a\n\
12265 user-query to see if a pending breakpoint should be created."),
12267 show_pending_break_support,
12268 &breakpoint_set_cmdlist,
12269 &breakpoint_show_cmdlist);
12271 pending_break_support = AUTO_BOOLEAN_AUTO;
12273 add_setshow_boolean_cmd ("auto-hw", no_class,
12274 &automatic_hardware_breakpoints, _("\
12275 Set automatic usage of hardware breakpoints."), _("\
12276 Show automatic usage of hardware breakpoints."), _("\
12277 If set, the debugger will automatically use hardware breakpoints for\n\
12278 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12279 a warning will be emitted for such breakpoints."),
12281 show_automatic_hardware_breakpoints,
12282 &breakpoint_set_cmdlist,
12283 &breakpoint_show_cmdlist);
12285 add_setshow_enum_cmd ("always-inserted", class_support,
12286 always_inserted_enums, &always_inserted_mode, _("\
12287 Set mode for inserting breakpoints."), _("\
12288 Show mode for inserting breakpoints."), _("\
12289 When this mode is off, breakpoints are inserted in inferior when it is\n\
12290 resumed, and removed when execution stops. When this mode is on,\n\
12291 breakpoints are inserted immediately and removed only when the user\n\
12292 deletes the breakpoint. When this mode is auto (which is the default),\n\
12293 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12294 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12295 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12296 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12298 &show_always_inserted_mode,
12299 &breakpoint_set_cmdlist,
12300 &breakpoint_show_cmdlist);
12302 automatic_hardware_breakpoints = 1;
12304 observer_attach_about_to_proceed (breakpoint_about_to_proceed);