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 void watch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value *);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint *);
109 /* This function is used in gdbtk sources and thus can not be made static. */
110 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
111 struct symtab_and_line,
114 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
116 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
120 static void describe_other_breakpoints (struct gdbarch *,
121 struct program_space *, CORE_ADDR,
122 struct obj_section *, int);
124 static int breakpoint_address_match (struct address_space *aspace1,
126 struct address_space *aspace2,
129 static int watchpoint_locations_match (struct bp_location *loc1,
130 struct bp_location *loc2);
132 static void breakpoints_info (char *, int);
134 static void watchpoints_info (char *, int);
136 static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
138 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
140 static int breakpoint_cond_eval (void *);
142 static void cleanup_executing_breakpoints (void *);
144 static void commands_command (char *, int);
146 static void condition_command (char *, int);
148 static int get_number_trailer (char **, int);
157 static int remove_breakpoint (struct bp_location *, insertion_state_t);
158 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
160 static enum print_stop_action print_it_typical (bpstat);
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
164 static int watchpoint_check (void *);
166 static void maintenance_info_breakpoints (char *, int);
168 static int hw_breakpoint_used_count (void);
170 static int hw_watchpoint_used_count (enum bptype, int *);
172 static void hbreak_command (char *, int);
174 static void thbreak_command (char *, int);
176 static void watch_command_1 (char *, int, int);
178 static void rwatch_command (char *, int);
180 static void awatch_command (char *, int);
182 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_parse_optional_if_clause (char **arg);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event,
193 char *arg, int tempflag, int from_tty);
195 static void tcatch_command (char *arg, int from_tty);
197 static void ep_skip_leading_whitespace (char **s);
199 static int single_step_breakpoint_inserted_here_p (struct address_space *,
202 static void free_bp_location (struct bp_location *loc);
204 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
206 static void update_global_location_list (int);
208 static void update_global_location_list_nothrow (int);
210 static int bpstat_remove_bp_location_callback (struct thread_info *th,
213 static int is_hardware_watchpoint (const struct breakpoint *bpt);
215 static int is_watchpoint (const struct breakpoint *bpt);
217 static void insert_breakpoint_locations (void);
219 static int syscall_catchpoint_p (struct breakpoint *b);
221 static void tracepoints_info (char *, int);
223 static void delete_trace_command (char *, int);
225 static void enable_trace_command (char *, int);
227 static void disable_trace_command (char *, int);
229 static void trace_pass_command (char *, int);
231 /* A reference-counted struct command_line. This lets multiple
232 breakpoints share a single command list. */
233 struct counted_command_line
235 /* The reference count. */
238 /* The command list. */
239 struct command_line *commands;
242 struct command_line *
243 breakpoint_commands (struct breakpoint *b)
245 return b->commands ? b->commands->commands : NULL;
248 /* Flag indicating that a command has proceeded the inferior past the
249 current breakpoint. */
251 static int breakpoint_proceeded;
254 bpdisp_text (enum bpdisp disp)
256 /* NOTE: the following values are a part of MI protocol and represent
257 values of 'disp' field returned when inferior stops at a breakpoint. */
258 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
260 return bpdisps[(int) disp];
263 /* Prototypes for exported functions. */
264 /* If FALSE, gdb will not use hardware support for watchpoints, even
265 if such is available. */
266 static int can_use_hw_watchpoints;
269 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
270 struct cmd_list_element *c,
273 fprintf_filtered (file, _("\
274 Debugger's willingness to use watchpoint hardware is %s.\n"),
278 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
279 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
280 for unrecognized breakpoint locations.
281 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
282 static enum auto_boolean pending_break_support;
284 show_pending_break_support (struct ui_file *file, int from_tty,
285 struct cmd_list_element *c,
288 fprintf_filtered (file, _("\
289 Debugger's behavior regarding pending breakpoints is %s.\n"),
293 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
294 set with "break" but falling in read-only memory.
295 If 0, gdb will warn about such breakpoints, but won't automatically
296 use hardware breakpoints. */
297 static int automatic_hardware_breakpoints;
299 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
300 struct cmd_list_element *c,
303 fprintf_filtered (file, _("\
304 Automatic usage of hardware breakpoints is %s.\n"),
308 /* If on, gdb will keep breakpoints inserted even as inferior is
309 stopped, and immediately insert any new breakpoints. If off, gdb
310 will insert breakpoints into inferior only when resuming it, and
311 will remove breakpoints upon stop. If auto, GDB will behave as ON
312 if in non-stop mode, and as OFF if all-stop mode.*/
314 static const char always_inserted_auto[] = "auto";
315 static const char always_inserted_on[] = "on";
316 static const char always_inserted_off[] = "off";
317 static const char *always_inserted_enums[] = {
318 always_inserted_auto,
323 static const char *always_inserted_mode = always_inserted_auto;
325 show_always_inserted_mode (struct ui_file *file, int from_tty,
326 struct cmd_list_element *c, const char *value)
328 if (always_inserted_mode == always_inserted_auto)
329 fprintf_filtered (file, _("\
330 Always inserted breakpoint mode is %s (currently %s).\n"),
332 breakpoints_always_inserted_mode () ? "on" : "off");
334 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
338 breakpoints_always_inserted_mode (void)
340 return (always_inserted_mode == always_inserted_on
341 || (always_inserted_mode == always_inserted_auto && non_stop));
344 void _initialize_breakpoint (void);
346 /* Are we executing breakpoint commands? */
347 static int executing_breakpoint_commands;
349 /* Are overlay event breakpoints enabled? */
350 static int overlay_events_enabled;
352 /* Walk the following statement or block through all breakpoints.
353 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
356 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
358 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
359 for (B = breakpoint_chain; \
360 B ? (TMP=B->next, 1): 0; \
363 /* Similar iterator for the low-level breakpoints. SAFE variant is not
364 provided so update_global_location_list must not be called while executing
365 the block of ALL_BP_LOCATIONS. */
367 #define ALL_BP_LOCATIONS(B,BP_TMP) \
368 for (BP_TMP = bp_location; \
369 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
372 /* Iterator for tracepoints only. */
374 #define ALL_TRACEPOINTS(B) \
375 for (B = breakpoint_chain; B; B = B->next) \
376 if (is_tracepoint (B))
378 /* Chains of all breakpoints defined. */
380 struct breakpoint *breakpoint_chain;
382 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
384 static struct bp_location **bp_location;
386 /* Number of elements of BP_LOCATION. */
388 static unsigned bp_location_count;
390 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
391 for the current elements of BP_LOCATION which get a valid result from
392 bp_location_has_shadow. You can use it for roughly limiting the subrange of
393 BP_LOCATION to scan for shadow bytes for an address you need to read. */
395 static CORE_ADDR bp_location_placed_address_before_address_max;
397 /* Maximum offset plus alignment between
398 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
399 the current elements of BP_LOCATION which get a valid result from
400 bp_location_has_shadow. You can use it for roughly limiting the subrange of
401 BP_LOCATION to scan for shadow bytes for an address you need to read. */
403 static CORE_ADDR bp_location_shadow_len_after_address_max;
405 /* The locations that no longer correspond to any breakpoint,
406 unlinked from bp_location array, but for which a hit
407 may still be reported by a target. */
408 VEC(bp_location_p) *moribund_locations = NULL;
410 /* Number of last breakpoint made. */
412 static int breakpoint_count;
414 /* The value of `breakpoint_count' before the last command that
415 created breakpoints. If the last (break-like) command created more
416 than one breakpoint, then the difference between BREAKPOINT_COUNT
417 and PREV_BREAKPOINT_COUNT is more than one. */
418 static int prev_breakpoint_count;
420 /* Number of last tracepoint made. */
422 static int tracepoint_count;
424 static struct cmd_list_element *breakpoint_set_cmdlist;
425 static struct cmd_list_element *breakpoint_show_cmdlist;
426 static struct cmd_list_element *save_cmdlist;
428 /* Return whether a breakpoint is an active enabled breakpoint. */
430 breakpoint_enabled (struct breakpoint *b)
432 return (b->enable_state == bp_enabled);
435 /* Set breakpoint count to NUM. */
438 set_breakpoint_count (int num)
440 prev_breakpoint_count = breakpoint_count;
441 breakpoint_count = num;
442 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
445 /* Used by `start_rbreak_breakpoints' below, to record the current
446 breakpoint count before "rbreak" creates any breakpoint. */
447 static int rbreak_start_breakpoint_count;
449 /* Called at the start an "rbreak" command to record the first
453 start_rbreak_breakpoints (void)
455 rbreak_start_breakpoint_count = breakpoint_count;
458 /* Called at the end of an "rbreak" command to record the last
462 end_rbreak_breakpoints (void)
464 prev_breakpoint_count = rbreak_start_breakpoint_count;
467 /* Used in run_command to zero the hit count when a new run starts. */
470 clear_breakpoint_hit_counts (void)
472 struct breakpoint *b;
478 /* Allocate a new counted_command_line with reference count of 1.
479 The new structure owns COMMANDS. */
481 static struct counted_command_line *
482 alloc_counted_command_line (struct command_line *commands)
484 struct counted_command_line *result
485 = xmalloc (sizeof (struct counted_command_line));
488 result->commands = commands;
492 /* Increment reference count. This does nothing if CMD is NULL. */
495 incref_counted_command_line (struct counted_command_line *cmd)
501 /* Decrement reference count. If the reference count reaches 0,
502 destroy the counted_command_line. Sets *CMDP to NULL. This does
503 nothing if *CMDP is NULL. */
506 decref_counted_command_line (struct counted_command_line **cmdp)
510 if (--(*cmdp)->refc == 0)
512 free_command_lines (&(*cmdp)->commands);
519 /* A cleanup function that calls decref_counted_command_line. */
522 do_cleanup_counted_command_line (void *arg)
524 decref_counted_command_line (arg);
527 /* Create a cleanup that calls decref_counted_command_line on the
530 static struct cleanup *
531 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
533 return make_cleanup (do_cleanup_counted_command_line, cmdp);
536 /* Default address, symtab and line to put a breakpoint at
537 for "break" command with no arg.
538 if default_breakpoint_valid is zero, the other three are
539 not valid, and "break" with no arg is an error.
541 This set by print_stack_frame, which calls set_default_breakpoint. */
543 int default_breakpoint_valid;
544 CORE_ADDR default_breakpoint_address;
545 struct symtab *default_breakpoint_symtab;
546 int default_breakpoint_line;
547 struct program_space *default_breakpoint_pspace;
550 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
551 Advance *PP after the string and any trailing whitespace.
553 Currently the string can either be a number or "$" followed by the name
554 of a convenience variable. Making it an expression wouldn't work well
555 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
557 If the string is a NULL pointer, that denotes the last breakpoint.
559 TRAILER is a character which can be found after the number; most
560 commonly this is `-'. If you don't want a trailer, use \0. */
562 get_number_trailer (char **pp, int trailer)
564 int retval = 0; /* default */
568 /* Empty line means refer to the last breakpoint. */
569 return breakpoint_count;
572 /* Make a copy of the name, so we can null-terminate it
573 to pass to lookup_internalvar(). */
578 while (isalnum (*p) || *p == '_')
580 varname = (char *) alloca (p - start + 1);
581 strncpy (varname, start, p - start);
582 varname[p - start] = '\0';
583 if (get_internalvar_integer (lookup_internalvar (varname), &val))
587 printf_filtered (_("Convenience variable must have integer value.\n"));
595 while (*p >= '0' && *p <= '9')
598 /* There is no number here. (e.g. "cond a == b"). */
600 /* Skip non-numeric token */
601 while (*p && !isspace((int) *p))
603 /* Return zero, which caller must interpret as error. */
609 if (!(isspace (*p) || *p == '\0' || *p == trailer))
611 /* Trailing junk: return 0 and let caller print error msg. */
612 while (!(isspace (*p) || *p == '\0' || *p == trailer))
623 /* Like get_number_trailer, but don't allow a trailer. */
625 get_number (char **pp)
627 return get_number_trailer (pp, '\0');
630 /* Parse a number or a range.
631 * A number will be of the form handled by get_number.
632 * A range will be of the form <number1> - <number2>, and
633 * will represent all the integers between number1 and number2,
636 * While processing a range, this fuction is called iteratively;
637 * At each call it will return the next value in the range.
639 * At the beginning of parsing a range, the char pointer PP will
640 * be advanced past <number1> and left pointing at the '-' token.
641 * Subsequent calls will not advance the pointer until the range
642 * is completed. The call that completes the range will advance
643 * pointer PP past <number2>.
647 get_number_or_range (char **pp)
649 static int last_retval, end_value;
650 static char *end_ptr;
651 static int in_range = 0;
655 /* Default case: pp is pointing either to a solo number,
656 or to the first number of a range. */
657 last_retval = get_number_trailer (pp, '-');
662 /* This is the start of a range (<number1> - <number2>).
663 Skip the '-', parse and remember the second number,
664 and also remember the end of the final token. */
668 while (isspace ((int) *end_ptr))
669 end_ptr++; /* skip white space */
670 end_value = get_number (temp);
671 if (end_value < last_retval)
673 error (_("inverted range"));
675 else if (end_value == last_retval)
677 /* degenerate range (number1 == number2). Advance the
678 token pointer so that the range will be treated as a
687 error (_("negative value"));
690 /* pp points to the '-' that betokens a range. All
691 number-parsing has already been done. Return the next
692 integer value (one greater than the saved previous value).
693 Do not advance the token pointer 'pp' until the end of range
696 if (++last_retval == end_value)
698 /* End of range reached; advance token pointer. */
706 /* Return the breakpoint with the specified number, or NULL
707 if the number does not refer to an existing breakpoint. */
710 get_breakpoint (int num)
712 struct breakpoint *b;
715 if (b->number == num)
724 set_breakpoint_condition (struct breakpoint *b, char *exp,
727 struct bp_location *loc = b->loc;
729 for (; loc; loc = loc->next)
734 xfree (b->cond_string);
735 b->cond_string = NULL;
742 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
748 /* I don't know if it matters whether this is the string the user
749 typed in or the decompiled expression. */
750 b->cond_string = xstrdup (arg);
751 b->condition_not_parsed = 0;
753 if (is_watchpoint (b))
755 innermost_block = NULL;
757 b->cond_exp = parse_exp_1 (&arg, 0, 0);
759 error (_("Junk at end of expression"));
760 b->cond_exp_valid_block = innermost_block;
764 for (loc = b->loc; loc; loc = loc->next)
768 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
770 error (_("Junk at end of expression"));
774 breakpoints_changed ();
775 observer_notify_breakpoint_modified (b->number);
778 /* condition N EXP -- set break condition of breakpoint N to EXP. */
781 condition_command (char *arg, int from_tty)
783 struct breakpoint *b;
788 error_no_arg (_("breakpoint number"));
791 bnum = get_number (&p);
793 error (_("Bad breakpoint argument: '%s'"), arg);
796 if (b->number == bnum)
798 set_breakpoint_condition (b, p, from_tty);
802 error (_("No breakpoint number %d."), bnum);
805 /* Check that COMMAND do not contain commands that are suitable
806 only for tracepoints and not suitable for ordinary breakpoints.
807 Throw if any such commands is found.
810 check_no_tracepoint_commands (struct command_line *commands)
812 struct command_line *c;
814 for (c = commands; c; c = c->next)
818 if (c->control_type == while_stepping_control)
819 error (_("The 'while-stepping' command can only be used for tracepoints"));
821 for (i = 0; i < c->body_count; ++i)
822 check_no_tracepoint_commands ((c->body_list)[i]);
824 /* Not that command parsing removes leading whitespace and comment
825 lines and also empty lines. So, we only need to check for
827 if (strstr (c->line, "collect ") == c->line)
828 error (_("The 'collect' command can only be used for tracepoints"));
830 if (strstr (c->line, "teval ") == c->line)
831 error (_("The 'teval' command can only be used for tracepoints"));
835 /* Encapsulate tests for different types of tracepoints. */
838 is_tracepoint (const struct breakpoint *b)
840 return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint);
843 /* A helper function that validsates that COMMANDS are valid for a
844 breakpoint. This function will throw an exception if a problem is
848 validate_commands_for_breakpoint (struct breakpoint *b,
849 struct command_line *commands)
851 if (is_tracepoint (b))
853 /* We need to verify that each top-level element of commands
854 is valid for tracepoints, that there's at most one while-stepping
855 element, and that while-stepping's body has valid tracing commands
856 excluding nested while-stepping. */
857 struct command_line *c;
858 struct command_line *while_stepping = 0;
859 for (c = commands; c; c = c->next)
861 if (c->control_type == while_stepping_control)
863 if (b->type == bp_fast_tracepoint)
864 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
867 error (_("The 'while-stepping' command can be used only once"));
874 struct command_line *c2;
876 gdb_assert (while_stepping->body_count == 1);
877 c2 = while_stepping->body_list[0];
878 for (; c2; c2 = c2->next)
880 if (c2->control_type == while_stepping_control)
881 error (_("The 'while-stepping' command cannot be nested"));
887 check_no_tracepoint_commands (commands);
891 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
892 validate that only allowed commands are included.
896 breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
898 validate_commands_for_breakpoint (b, commands);
900 decref_counted_command_line (&b->commands);
901 b->commands = alloc_counted_command_line (commands);
902 breakpoints_changed ();
903 observer_notify_breakpoint_modified (b->number);
907 check_tracepoint_command (char *line, void *closure)
909 struct breakpoint *b = closure;
911 validate_actionline (&line, b);
914 /* A structure used to pass information through
915 map_breakpoint_numbers. */
919 /* True if the command was typed at a tty. */
922 /* The breakpoint range spec. */
925 /* Non-NULL if the body of the commands are being read from this
926 already-parsed command. */
927 struct command_line *control;
929 /* The command lines read from the user, or NULL if they have not
931 struct counted_command_line *cmd;
934 /* A callback for map_breakpoint_numbers that sets the commands for
938 do_map_commands_command (struct breakpoint *b, void *data)
940 struct commands_info *info = data;
942 if (info->cmd == NULL)
944 struct command_line *l;
946 if (info->control != NULL)
947 l = copy_command_lines (info->control->body_list[0]);
950 struct cleanup *old_chain;
953 str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
956 old_chain = make_cleanup (xfree, str);
958 l = read_command_lines (str,
961 ? check_tracepoint_command : 0),
964 do_cleanups (old_chain);
967 info->cmd = alloc_counted_command_line (l);
970 /* If a breakpoint was on the list more than once, we don't need to
972 if (b->commands != info->cmd)
974 validate_commands_for_breakpoint (b, info->cmd->commands);
975 incref_counted_command_line (info->cmd);
976 decref_counted_command_line (&b->commands);
977 b->commands = info->cmd;
978 breakpoints_changed ();
979 observer_notify_breakpoint_modified (b->number);
984 commands_command_1 (char *arg, int from_tty, struct command_line *control)
986 struct cleanup *cleanups;
987 struct commands_info info;
989 info.from_tty = from_tty;
990 info.control = control;
992 /* If we read command lines from the user, then `info' will hold an
993 extra reference to the commands that we must clean up. */
994 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
996 if (arg == NULL || !*arg)
998 if (breakpoint_count - prev_breakpoint_count > 1)
999 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count);
1000 else if (breakpoint_count > 0)
1001 arg = xstrprintf ("%d", breakpoint_count);
1004 /* So that we don't try to free the incoming non-NULL
1005 argument in the cleanup below. Mapping breakpoint
1006 numbers will fail in this case. */
1011 /* The command loop has some static state, so we need to preserve
1013 arg = xstrdup (arg);
1016 make_cleanup (xfree, arg);
1020 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1022 if (info.cmd == NULL)
1023 error (_("No breakpoints specified."));
1025 do_cleanups (cleanups);
1029 commands_command (char *arg, int from_tty)
1031 commands_command_1 (arg, from_tty, NULL);
1034 /* Like commands_command, but instead of reading the commands from
1035 input stream, takes them from an already parsed command structure.
1037 This is used by cli-script.c to DTRT with breakpoint commands
1038 that are part of if and while bodies. */
1039 enum command_control_type
1040 commands_from_control_command (char *arg, struct command_line *cmd)
1042 commands_command_1 (arg, 0, cmd);
1043 return simple_control;
1046 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1049 bp_location_has_shadow (struct bp_location *bl)
1051 if (bl->loc_type != bp_loc_software_breakpoint)
1055 if (bl->target_info.shadow_len == 0)
1056 /* bp isn't valid, or doesn't shadow memory. */
1061 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1062 by replacing any memory breakpoints with their shadowed contents.
1064 The range of shadowed area by each bp_location is:
1065 b->address - bp_location_placed_address_before_address_max
1066 up to b->address + bp_location_shadow_len_after_address_max
1067 The range we were requested to resolve shadows for is:
1068 memaddr ... memaddr + len
1069 Thus the safe cutoff boundaries for performance optimization are
1070 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1072 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1075 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1077 /* Left boundary, right boundary and median element of our binary search. */
1078 unsigned bc_l, bc_r, bc;
1080 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1081 safe to report lower value but a failure to report higher one. */
1084 bc_r = bp_location_count;
1085 while (bc_l + 1 < bc_r)
1087 struct bp_location *b;
1089 bc = (bc_l + bc_r) / 2;
1090 b = bp_location[bc];
1092 /* Check first B->ADDRESS will not overflow due to the added constant.
1093 Then advance the left boundary only if we are sure the BC element can
1094 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1096 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1097 we cannot miss a breakpoint with its shadow range tail still reaching
1100 if (b->address + bp_location_shadow_len_after_address_max >= b->address
1101 && b->address + bp_location_shadow_len_after_address_max <= memaddr)
1107 /* Now do full processing of the found relevant range of elements. */
1109 for (bc = bc_l; bc < bp_location_count; bc++)
1111 struct bp_location *b = bp_location[bc];
1112 CORE_ADDR bp_addr = 0;
1116 /* bp_location array has B->OWNER always non-NULL. */
1117 if (b->owner->type == bp_none)
1118 warning (_("reading through apparently deleted breakpoint #%d?"),
1121 /* Performance optimization: any futher element can no longer affect BUF
1124 if (b->address >= bp_location_placed_address_before_address_max
1125 && memaddr + len <= b->address
1126 - bp_location_placed_address_before_address_max)
1129 if (!bp_location_has_shadow (b))
1131 if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
1132 current_program_space->aspace, 0))
1135 /* Addresses and length of the part of the breakpoint that
1137 bp_addr = b->target_info.placed_address;
1138 bp_size = b->target_info.shadow_len;
1140 if (bp_addr + bp_size <= memaddr)
1141 /* The breakpoint is entirely before the chunk of memory we
1145 if (bp_addr >= memaddr + len)
1146 /* The breakpoint is entirely after the chunk of memory we are
1150 /* Offset within shadow_contents. */
1151 if (bp_addr < memaddr)
1153 /* Only copy the second part of the breakpoint. */
1154 bp_size -= memaddr - bp_addr;
1155 bptoffset = memaddr - bp_addr;
1159 if (bp_addr + bp_size > memaddr + len)
1161 /* Only copy the first part of the breakpoint. */
1162 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1165 memcpy (buf + bp_addr - memaddr,
1166 b->target_info.shadow_contents + bptoffset, bp_size);
1171 /* A wrapper function for inserting catchpoints. */
1173 insert_catchpoint (struct ui_out *uo, void *args)
1175 struct breakpoint *b = (struct breakpoint *) args;
1177 gdb_assert (b->type == bp_catchpoint);
1178 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
1183 /* Return true if BPT is of any hardware watchpoint kind. */
1186 is_hardware_watchpoint (const struct breakpoint *bpt)
1188 return (bpt->type == bp_hardware_watchpoint
1189 || bpt->type == bp_read_watchpoint
1190 || bpt->type == bp_access_watchpoint);
1193 /* Return true if BPT is of any watchpoint kind, hardware or
1197 is_watchpoint (const struct breakpoint *bpt)
1199 return (is_hardware_watchpoint (bpt)
1200 || bpt->type == bp_watchpoint);
1203 /* Find the current value of a watchpoint on EXP. Return the value in
1204 *VALP and *RESULTP and the chain of intermediate and final values
1205 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1208 If a memory error occurs while evaluating the expression, *RESULTP will
1209 be set to NULL. *RESULTP may be a lazy value, if the result could
1210 not be read from memory. It is used to determine whether a value
1211 is user-specified (we should watch the whole value) or intermediate
1212 (we should watch only the bit used to locate the final value).
1214 If the final value, or any intermediate value, could not be read
1215 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1216 set to any referenced values. *VALP will never be a lazy value.
1217 This is the value which we store in struct breakpoint.
1219 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1220 value chain. The caller must free the values individually. If
1221 VAL_CHAIN is NULL, all generated values will be left on the value
1225 fetch_watchpoint_value (struct expression *exp, struct value **valp,
1226 struct value **resultp, struct value **val_chain)
1228 struct value *mark, *new_mark, *result;
1229 volatile struct gdb_exception ex;
1237 /* Evaluate the expression. */
1238 mark = value_mark ();
1241 TRY_CATCH (ex, RETURN_MASK_ALL)
1243 result = evaluate_expression (exp);
1247 /* Ignore memory errors, we want watchpoints pointing at
1248 inaccessible memory to still be created; otherwise, throw the
1249 error to some higher catcher. */
1255 throw_exception (ex);
1260 new_mark = value_mark ();
1261 if (mark == new_mark)
1266 /* Make sure it's not lazy, so that after the target stops again we
1267 have a non-lazy previous value to compare with. */
1269 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
1274 /* Return the chain of intermediate values. We use this to
1275 decide which addresses to watch. */
1276 *val_chain = new_mark;
1277 value_release_to_mark (mark);
1281 /* Assuming that B is a watchpoint: returns true if the current thread
1282 and its running state are safe to evaluate or update watchpoint B.
1283 Watchpoints on local expressions need to be evaluated in the
1284 context of the thread that was current when the watchpoint was
1285 created, and, that thread needs to be stopped to be able to select
1286 the correct frame context. Watchpoints on global expressions can
1287 be evaluated on any thread, and in any state. It is presently left
1288 to the target allowing memory accesses when threads are
1292 watchpoint_in_thread_scope (struct breakpoint *b)
1294 return (ptid_equal (b->watchpoint_thread, null_ptid)
1295 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1296 && !is_executing (inferior_ptid)));
1299 /* Assuming that B is a watchpoint:
1300 - Reparse watchpoint expression, if REPARSE is non-zero
1301 - Evaluate expression and store the result in B->val
1302 - Evaluate the condition if there is one, and store the result
1304 - Update the list of values that must be watched in B->loc.
1306 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1307 If this is local watchpoint that is out of scope, delete it.
1309 Even with `set breakpoint always-inserted on' the watchpoints are removed
1310 + inserted on each stop here. Normal breakpoints must never be removed
1311 because they might be missed by a running thread when debugging in non-stop
1312 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1313 processed here) are specific to each LWP since they are stored in each LWP's
1314 hardware debug registers. Therefore, such LWP must be stopped first in
1315 order to be able to modify its hardware watchpoints.
1317 Hardware watchpoints must be reset exactly once after being presented to the
1318 user. It cannot be done sooner, because it would reset the data used to
1319 present the watchpoint hit to the user. And it must not be done later
1320 because it could display the same single watchpoint hit during multiple GDB
1321 stops. Note that the latter is relevant only to the hardware watchpoint
1322 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1323 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1324 memory content has not changed.
1326 The following constraints influence the location where we can reset hardware
1329 * target_stopped_by_watchpoint and target_stopped_data_address are called
1330 several times when GDB stops.
1333 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1334 stop. GDB only presents one hardware watchpoint hit at a time as the
1335 reason for stopping, and all the other hits are presented later, one after
1336 the other, each time the user requests the execution to be resumed.
1337 Execution is not resumed for the threads still having pending hit event
1338 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1339 the inferior on the first stop the thread hit event is kept being reported
1340 from its cached value by linux_nat_stopped_data_address until the real
1341 thread resume happens after the watchpoint gets presented and thus its
1342 LWP_INFO->STATUS gets reset.
1344 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1345 removal from inferior. */
1348 update_watchpoint (struct breakpoint *b, int reparse)
1350 int within_current_scope;
1351 struct frame_id saved_frame_id;
1354 /* If this is a local watchpoint, we only want to check if the
1355 watchpoint frame is in scope if the current thread is the thread
1356 that was used to create the watchpoint. */
1357 if (!watchpoint_in_thread_scope (b))
1360 /* We don't free locations. They are stored in bp_location array and
1361 update_global_locations will eventually delete them and remove
1362 breakpoints if needed. */
1365 if (b->disposition == disp_del_at_next_stop)
1370 /* Determine if the watchpoint is within scope. */
1371 if (b->exp_valid_block == NULL)
1372 within_current_scope = 1;
1375 struct frame_info *fi;
1377 /* Save the current frame's ID so we can restore it after
1378 evaluating the watchpoint expression on its own frame. */
1379 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1380 took a frame parameter, so that we didn't have to change the
1383 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1385 fi = frame_find_by_id (b->watchpoint_frame);
1386 within_current_scope = (fi != NULL);
1387 if (within_current_scope)
1391 if (within_current_scope && reparse)
1400 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1401 /* If the meaning of expression itself changed, the old value is
1402 no longer relevant. We don't want to report a watchpoint hit
1403 to the user when the old value and the new value may actually
1404 be completely different objects. */
1405 value_free (b->val);
1409 /* Note that unlike with breakpoints, the watchpoint's condition
1410 expression is stored in the breakpoint object, not in the
1411 locations (re)created below. */
1412 if (b->cond_string != NULL)
1414 if (b->cond_exp != NULL)
1416 xfree (b->cond_exp);
1421 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1425 /* If we failed to parse the expression, for example because
1426 it refers to a global variable in a not-yet-loaded shared library,
1427 don't try to insert watchpoint. We don't automatically delete
1428 such watchpoint, though, since failure to parse expression
1429 is different from out-of-scope watchpoint. */
1430 if ( !target_has_execution)
1432 /* Without execution, memory can't change. No use to try and
1433 set watchpoint locations. The watchpoint will be reset when
1434 the target gains execution, through breakpoint_re_set. */
1436 else if (within_current_scope && b->exp)
1438 struct value *val_chain, *v, *result, *next;
1439 struct program_space *frame_pspace;
1441 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
1443 /* Avoid setting b->val if it's already set. The meaning of
1444 b->val is 'the last value' user saw, and we should update
1445 it only if we reported that last value to user. As it
1446 happens, the code that reports it updates b->val directly. */
1453 /* Change the type of breakpoint between hardware assisted or an
1454 ordinary watchpoint depending on the hardware support and free
1455 hardware slots. REPARSE is set when the inferior is started. */
1456 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1459 int i, mem_cnt, other_type_used;
1461 /* We need to determine how many resources are already used
1462 for all other hardware watchpoints to see if we still have
1463 enough resources to also fit this watchpoint in as well.
1464 To avoid the hw_watchpoint_used_count call below from counting
1465 this watchpoint, make sure that it is marked as a software
1467 b->type = bp_watchpoint;
1468 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1470 mem_cnt = can_use_hardware_watchpoint (val_chain);
1473 b->type = bp_watchpoint;
1476 int target_resources_ok = target_can_use_hardware_watchpoint
1477 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1478 if (target_resources_ok <= 0)
1479 b->type = bp_watchpoint;
1481 b->type = bp_hardware_watchpoint;
1485 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1487 /* Look at each value on the value chain. */
1488 for (v = val_chain; v; v = next)
1490 /* If it's a memory location, and GDB actually needed
1491 its contents to evaluate the expression, then we
1492 must watch it. If the first value returned is
1493 still lazy, that means an error occurred reading it;
1494 watch it anyway in case it becomes readable. */
1495 if (VALUE_LVAL (v) == lval_memory
1496 && (v == val_chain || ! value_lazy (v)))
1498 struct type *vtype = check_typedef (value_type (v));
1500 /* We only watch structs and arrays if user asked
1501 for it explicitly, never if they just happen to
1502 appear in the middle of some value chain. */
1504 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1505 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1509 struct bp_location *loc, **tmp;
1511 addr = value_address (v);
1512 len = TYPE_LENGTH (value_type (v));
1514 if (b->type == bp_read_watchpoint)
1516 else if (b->type == bp_access_watchpoint)
1519 loc = allocate_bp_location (b);
1520 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1523 loc->gdbarch = get_type_arch (value_type (v));
1525 loc->pspace = frame_pspace;
1526 loc->address = addr;
1528 loc->watchpoint_type = type;
1532 next = value_next (v);
1537 /* If a software watchpoint is not watching any memory, then the
1538 above left it without any location set up. But,
1539 bpstat_stop_status requires a location to be able to report
1540 stops, so make sure there's at least a dummy one. */
1541 if (b->type == bp_watchpoint && b->loc == NULL)
1543 b->loc = allocate_bp_location (b);
1544 b->loc->pspace = frame_pspace;
1545 b->loc->address = -1;
1546 b->loc->length = -1;
1547 b->loc->watchpoint_type = -1;
1550 else if (!within_current_scope)
1552 printf_filtered (_("\
1553 Watchpoint %d deleted because the program has left the block \n\
1554 in which its expression is valid.\n"),
1556 if (b->related_breakpoint)
1558 b->related_breakpoint->disposition = disp_del_at_next_stop;
1559 b->related_breakpoint->related_breakpoint = NULL;
1560 b->related_breakpoint= NULL;
1562 b->disposition = disp_del_at_next_stop;
1565 /* Restore the selected frame. */
1567 select_frame (frame_find_by_id (saved_frame_id));
1571 /* Returns 1 iff breakpoint location should be
1572 inserted in the inferior. */
1574 should_be_inserted (struct bp_location *bpt)
1576 if (bpt->owner == NULL || !breakpoint_enabled (bpt->owner))
1579 if (bpt->owner->disposition == disp_del_at_next_stop)
1582 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1585 /* This is set for example, when we're attached to the parent of a
1586 vfork, and have detached from the child. The child is running
1587 free, and we expect it to do an exec or exit, at which point the
1588 OS makes the parent schedulable again (and the target reports
1589 that the vfork is done). Until the child is done with the shared
1590 memory region, do not insert breakpoints in the parent, otherwise
1591 the child could still trip on the parent's breakpoints. Since
1592 the parent is blocked anyway, it won't miss any breakpoint. */
1593 if (bpt->pspace->breakpoints_not_allowed)
1596 /* Tracepoints are inserted by the target at a time of its choosing,
1598 if (is_tracepoint (bpt->owner))
1604 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1605 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1606 and HW_BREAKPOINT_ERROR are used to report problems.
1608 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1609 method for each breakpoint or catchpoint type. */
1611 insert_bp_location (struct bp_location *bpt,
1612 struct ui_file *tmp_error_stream,
1613 int *disabled_breaks,
1614 int *hw_breakpoint_error)
1618 if (!should_be_inserted (bpt) || bpt->inserted)
1621 /* Initialize the target-specific information. */
1622 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1623 bpt->target_info.placed_address = bpt->address;
1624 bpt->target_info.placed_address_space = bpt->pspace->aspace;
1626 if (bpt->loc_type == bp_loc_software_breakpoint
1627 || bpt->loc_type == bp_loc_hardware_breakpoint)
1629 if (bpt->owner->type != bp_hardware_breakpoint)
1631 /* If the explicitly specified breakpoint type
1632 is not hardware breakpoint, check the memory map to see
1633 if the breakpoint address is in read only memory or not.
1634 Two important cases are:
1635 - location type is not hardware breakpoint, memory
1636 is readonly. We change the type of the location to
1637 hardware breakpoint.
1638 - location type is hardware breakpoint, memory is read-write.
1639 This means we've previously made the location hardware one, but
1640 then the memory map changed, so we undo.
1642 When breakpoints are removed, remove_breakpoints will
1643 use location types we've just set here, the only possible
1644 problem is that memory map has changed during running program,
1645 but it's not going to work anyway with current gdb. */
1646 struct mem_region *mr
1647 = lookup_mem_region (bpt->target_info.placed_address);
1651 if (automatic_hardware_breakpoints)
1653 enum bp_loc_type new_type;
1655 if (mr->attrib.mode != MEM_RW)
1656 new_type = bp_loc_hardware_breakpoint;
1658 new_type = bp_loc_software_breakpoint;
1660 if (new_type != bpt->loc_type)
1662 static int said = 0;
1664 bpt->loc_type = new_type;
1667 fprintf_filtered (gdb_stdout, _("\
1668 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1673 else if (bpt->loc_type == bp_loc_software_breakpoint
1674 && mr->attrib.mode != MEM_RW)
1675 warning (_("cannot set software breakpoint at readonly address %s"),
1676 paddress (bpt->gdbarch, bpt->address));
1680 /* First check to see if we have to handle an overlay. */
1681 if (overlay_debugging == ovly_off
1682 || bpt->section == NULL
1683 || !(section_is_overlay (bpt->section)))
1685 /* No overlay handling: just set the breakpoint. */
1687 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1688 val = target_insert_hw_breakpoint (bpt->gdbarch,
1691 val = target_insert_breakpoint (bpt->gdbarch,
1696 /* This breakpoint is in an overlay section.
1697 Shall we set a breakpoint at the LMA? */
1698 if (!overlay_events_enabled)
1700 /* Yes -- overlay event support is not active,
1701 so we must try to set a breakpoint at the LMA.
1702 This will not work for a hardware breakpoint. */
1703 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1704 warning (_("hardware breakpoint %d not supported in overlay!"),
1705 bpt->owner->number);
1708 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1710 /* Set a software (trap) breakpoint at the LMA. */
1711 bpt->overlay_target_info = bpt->target_info;
1712 bpt->overlay_target_info.placed_address = addr;
1713 val = target_insert_breakpoint (bpt->gdbarch,
1714 &bpt->overlay_target_info);
1716 fprintf_unfiltered (tmp_error_stream,
1717 "Overlay breakpoint %d failed: in ROM?\n",
1718 bpt->owner->number);
1721 /* Shall we set a breakpoint at the VMA? */
1722 if (section_is_mapped (bpt->section))
1724 /* Yes. This overlay section is mapped into memory. */
1725 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1726 val = target_insert_hw_breakpoint (bpt->gdbarch,
1729 val = target_insert_breakpoint (bpt->gdbarch,
1734 /* No. This breakpoint will not be inserted.
1735 No error, but do not mark the bp as 'inserted'. */
1742 /* Can't set the breakpoint. */
1743 if (solib_name_from_address (bpt->pspace, bpt->address))
1745 /* See also: disable_breakpoints_in_shlibs. */
1747 bpt->shlib_disabled = 1;
1748 if (!*disabled_breaks)
1750 fprintf_unfiltered (tmp_error_stream,
1751 "Cannot insert breakpoint %d.\n",
1752 bpt->owner->number);
1753 fprintf_unfiltered (tmp_error_stream,
1754 "Temporarily disabling shared library breakpoints:\n");
1756 *disabled_breaks = 1;
1757 fprintf_unfiltered (tmp_error_stream,
1758 "breakpoint #%d\n", bpt->owner->number);
1762 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1764 *hw_breakpoint_error = 1;
1765 fprintf_unfiltered (tmp_error_stream,
1766 "Cannot insert hardware breakpoint %d.\n",
1767 bpt->owner->number);
1771 fprintf_unfiltered (tmp_error_stream,
1772 "Cannot insert breakpoint %d.\n",
1773 bpt->owner->number);
1774 fprintf_filtered (tmp_error_stream,
1775 "Error accessing memory address ");
1776 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1778 fprintf_filtered (tmp_error_stream, ": %s.\n",
1779 safe_strerror (val));
1790 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1791 /* NOTE drow/2003-09-08: This state only exists for removing
1792 watchpoints. It's not clear that it's necessary... */
1793 && bpt->owner->disposition != disp_del_at_next_stop)
1795 val = target_insert_watchpoint (bpt->address,
1797 bpt->watchpoint_type);
1799 /* If trying to set a read-watchpoint, and it turns out it's not
1800 supported, try emulating one with an access watchpoint. */
1801 if (val == 1 && bpt->watchpoint_type == hw_read)
1803 struct bp_location *loc, **loc_temp;
1805 /* But don't try to insert it, if there's already another
1806 hw_access location that would be considered a duplicate
1808 ALL_BP_LOCATIONS (loc, loc_temp)
1810 && loc->watchpoint_type == hw_access
1811 && watchpoint_locations_match (bpt, loc))
1815 bpt->target_info = loc->target_info;
1816 bpt->watchpoint_type = hw_access;
1823 val = target_insert_watchpoint (bpt->address,
1827 bpt->watchpoint_type = hw_access;
1831 bpt->inserted = (val == 0);
1834 else if (bpt->owner->type == bp_catchpoint)
1836 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1837 bpt->owner, RETURN_MASK_ERROR);
1838 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1839 bpt->owner->number);
1841 bpt->owner->enable_state = bp_disabled;
1845 /* We've already printed an error message if there was a problem
1846 inserting this catchpoint, and we've disabled the catchpoint,
1847 so just return success. */
1854 /* This function is called when program space PSPACE is about to be
1855 deleted. It takes care of updating breakpoints to not reference
1859 breakpoint_program_space_exit (struct program_space *pspace)
1861 struct breakpoint *b, *b_temp;
1862 struct bp_location *loc, **loc_temp;
1864 /* Remove any breakpoint that was set through this program space. */
1865 ALL_BREAKPOINTS_SAFE (b, b_temp)
1867 if (b->pspace == pspace)
1868 delete_breakpoint (b);
1871 /* Breakpoints set through other program spaces could have locations
1872 bound to PSPACE as well. Remove those. */
1873 ALL_BP_LOCATIONS (loc, loc_temp)
1875 struct bp_location *tmp;
1877 if (loc->pspace == pspace)
1879 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1880 if (loc->owner->loc == loc)
1881 loc->owner->loc = loc->next;
1883 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1884 if (tmp->next == loc)
1886 tmp->next = loc->next;
1892 /* Now update the global location list to permanently delete the
1893 removed locations above. */
1894 update_global_location_list (0);
1897 /* Make sure all breakpoints are inserted in inferior.
1898 Throws exception on any error.
1899 A breakpoint that is already inserted won't be inserted
1900 again, so calling this function twice is safe. */
1902 insert_breakpoints (void)
1904 struct breakpoint *bpt;
1906 ALL_BREAKPOINTS (bpt)
1907 if (is_hardware_watchpoint (bpt))
1908 update_watchpoint (bpt, 0 /* don't reparse. */);
1910 update_global_location_list (1);
1912 /* update_global_location_list does not insert breakpoints when
1913 always_inserted_mode is not enabled. Explicitly insert them
1915 if (!breakpoints_always_inserted_mode ())
1916 insert_breakpoint_locations ();
1919 /* insert_breakpoints is used when starting or continuing the program.
1920 remove_breakpoints is used when the program stops.
1921 Both return zero if successful,
1922 or an `errno' value if could not write the inferior. */
1925 insert_breakpoint_locations (void)
1927 struct breakpoint *bpt;
1928 struct bp_location *b, **bp_tmp;
1931 int disabled_breaks = 0;
1932 int hw_breakpoint_error = 0;
1934 struct ui_file *tmp_error_stream = mem_fileopen ();
1935 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1937 /* Explicitly mark the warning -- this will only be printed if
1938 there was an error. */
1939 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1941 save_current_space_and_thread ();
1943 ALL_BP_LOCATIONS (b, bp_tmp)
1945 if (!should_be_inserted (b) || b->inserted)
1948 /* There is no point inserting thread-specific breakpoints if the
1949 thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER
1951 if (b->owner->thread != -1
1952 && !valid_thread_id (b->owner->thread))
1955 switch_to_program_space_and_thread (b->pspace);
1957 /* For targets that support global breakpoints, there's no need
1958 to select an inferior to insert breakpoint to. In fact, even
1959 if we aren't attached to any process yet, we should still
1960 insert breakpoints. */
1961 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1962 && ptid_equal (inferior_ptid, null_ptid))
1965 val = insert_bp_location (b, tmp_error_stream,
1967 &hw_breakpoint_error);
1972 /* If we failed to insert all locations of a watchpoint,
1973 remove them, as half-inserted watchpoint is of limited use. */
1974 ALL_BREAKPOINTS (bpt)
1976 int some_failed = 0;
1977 struct bp_location *loc;
1979 if (!is_hardware_watchpoint (bpt))
1982 if (!breakpoint_enabled (bpt))
1985 if (bpt->disposition == disp_del_at_next_stop)
1988 for (loc = bpt->loc; loc; loc = loc->next)
1989 if (!loc->inserted && should_be_inserted (loc))
1996 for (loc = bpt->loc; loc; loc = loc->next)
1998 remove_breakpoint (loc, mark_uninserted);
2000 hw_breakpoint_error = 1;
2001 fprintf_unfiltered (tmp_error_stream,
2002 "Could not insert hardware watchpoint %d.\n",
2010 /* If a hardware breakpoint or watchpoint was inserted, add a
2011 message about possibly exhausted resources. */
2012 if (hw_breakpoint_error)
2014 fprintf_unfiltered (tmp_error_stream,
2015 "Could not insert hardware breakpoints:\n\
2016 You may have requested too many hardware breakpoints/watchpoints.\n");
2018 target_terminal_ours_for_output ();
2019 error_stream (tmp_error_stream);
2022 do_cleanups (cleanups);
2026 remove_breakpoints (void)
2028 struct bp_location *b, **bp_tmp;
2031 ALL_BP_LOCATIONS (b, bp_tmp)
2034 val |= remove_breakpoint (b, mark_uninserted);
2039 /* Remove breakpoints of process PID. */
2042 remove_breakpoints_pid (int pid)
2044 struct bp_location *b, **b_tmp;
2046 struct inferior *inf = find_inferior_pid (pid);
2048 ALL_BP_LOCATIONS (b, b_tmp)
2050 if (b->pspace != inf->pspace)
2055 val = remove_breakpoint (b, mark_uninserted);
2064 remove_hw_watchpoints (void)
2066 struct bp_location *b, **bp_tmp;
2069 ALL_BP_LOCATIONS (b, bp_tmp)
2071 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
2072 val |= remove_breakpoint (b, mark_uninserted);
2078 reattach_breakpoints (int pid)
2080 struct cleanup *old_chain;
2081 struct bp_location *b, **bp_tmp;
2083 struct ui_file *tmp_error_stream = mem_fileopen ();
2084 int dummy1 = 0, dummy2 = 0;
2085 struct inferior *inf;
2086 struct thread_info *tp;
2088 tp = any_live_thread_of_process (pid);
2092 inf = find_inferior_pid (pid);
2093 old_chain = save_inferior_ptid ();
2095 inferior_ptid = tp->ptid;
2097 make_cleanup_ui_file_delete (tmp_error_stream);
2099 ALL_BP_LOCATIONS (b, bp_tmp)
2101 if (b->pspace != inf->pspace)
2107 val = insert_bp_location (b, tmp_error_stream,
2111 do_cleanups (old_chain);
2116 do_cleanups (old_chain);
2120 static int internal_breakpoint_number = -1;
2122 static struct breakpoint *
2123 create_internal_breakpoint (struct gdbarch *gdbarch,
2124 CORE_ADDR address, enum bptype type)
2126 struct symtab_and_line sal;
2127 struct breakpoint *b;
2129 init_sal (&sal); /* initialize to zeroes */
2132 sal.section = find_pc_overlay (sal.pc);
2133 sal.pspace = current_program_space;
2135 b = set_raw_breakpoint (gdbarch, sal, type);
2136 b->number = internal_breakpoint_number--;
2137 b->disposition = disp_donttouch;
2143 create_overlay_event_breakpoint (char *func_name)
2145 struct objfile *objfile;
2147 ALL_OBJFILES (objfile)
2149 struct breakpoint *b;
2150 struct minimal_symbol *m;
2152 m = lookup_minimal_symbol_text (func_name, objfile);
2156 b = create_internal_breakpoint (get_objfile_arch (objfile),
2157 SYMBOL_VALUE_ADDRESS (m),
2159 b->addr_string = xstrdup (func_name);
2161 if (overlay_debugging == ovly_auto)
2163 b->enable_state = bp_enabled;
2164 overlay_events_enabled = 1;
2168 b->enable_state = bp_disabled;
2169 overlay_events_enabled = 0;
2172 update_global_location_list (1);
2176 create_longjmp_master_breakpoint (char *func_name)
2178 struct program_space *pspace;
2179 struct objfile *objfile;
2180 struct cleanup *old_chain;
2182 old_chain = save_current_program_space ();
2184 ALL_PSPACES (pspace)
2185 ALL_OBJFILES (objfile)
2187 struct breakpoint *b;
2188 struct minimal_symbol *m;
2190 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2193 set_current_program_space (pspace);
2195 m = lookup_minimal_symbol_text (func_name, objfile);
2199 b = create_internal_breakpoint (get_objfile_arch (objfile),
2200 SYMBOL_VALUE_ADDRESS (m),
2202 b->addr_string = xstrdup (func_name);
2203 b->enable_state = bp_disabled;
2205 update_global_location_list (1);
2207 do_cleanups (old_chain);
2210 /* Create a master std::terminate breakpoint. The actual function
2211 looked for is named FUNC_NAME. */
2213 create_std_terminate_master_breakpoint (const char *func_name)
2215 struct program_space *pspace;
2216 struct objfile *objfile;
2217 struct cleanup *old_chain;
2219 old_chain = save_current_program_space ();
2221 ALL_PSPACES (pspace)
2222 ALL_OBJFILES (objfile)
2224 struct breakpoint *b;
2225 struct minimal_symbol *m;
2227 set_current_program_space (pspace);
2229 m = lookup_minimal_symbol (func_name, NULL, objfile);
2230 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2231 && MSYMBOL_TYPE (m) != mst_file_text))
2234 b = create_internal_breakpoint (get_objfile_arch (objfile),
2235 SYMBOL_VALUE_ADDRESS (m),
2236 bp_std_terminate_master);
2237 b->addr_string = xstrdup (func_name);
2238 b->enable_state = bp_disabled;
2240 update_global_location_list (1);
2242 do_cleanups (old_chain);
2246 update_breakpoints_after_exec (void)
2248 struct breakpoint *b;
2249 struct breakpoint *temp;
2250 struct bp_location *bploc, **bplocp_tmp;
2252 /* We're about to delete breakpoints from GDB's lists. If the
2253 INSERTED flag is true, GDB will try to lift the breakpoints by
2254 writing the breakpoints' "shadow contents" back into memory. The
2255 "shadow contents" are NOT valid after an exec, so GDB should not
2256 do that. Instead, the target is responsible from marking
2257 breakpoints out as soon as it detects an exec. We don't do that
2258 here instead, because there may be other attempts to delete
2259 breakpoints after detecting an exec and before reaching here. */
2260 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2261 if (bploc->pspace == current_program_space)
2262 gdb_assert (!bploc->inserted);
2264 ALL_BREAKPOINTS_SAFE (b, temp)
2266 if (b->pspace != current_program_space)
2269 /* Solib breakpoints must be explicitly reset after an exec(). */
2270 if (b->type == bp_shlib_event)
2272 delete_breakpoint (b);
2276 /* JIT breakpoints must be explicitly reset after an exec(). */
2277 if (b->type == bp_jit_event)
2279 delete_breakpoint (b);
2283 /* Thread event breakpoints must be set anew after an exec(),
2284 as must overlay event and longjmp master breakpoints. */
2285 if (b->type == bp_thread_event || b->type == bp_overlay_event
2286 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
2288 delete_breakpoint (b);
2292 /* Step-resume breakpoints are meaningless after an exec(). */
2293 if (b->type == bp_step_resume)
2295 delete_breakpoint (b);
2299 /* Longjmp and longjmp-resume breakpoints are also meaningless
2301 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
2303 delete_breakpoint (b);
2307 if (b->type == bp_catchpoint)
2309 /* For now, none of the bp_catchpoint breakpoints need to
2310 do anything at this point. In the future, if some of
2311 the catchpoints need to something, we will need to add
2312 a new method, and call this method from here. */
2316 /* bp_finish is a special case. The only way we ought to be able
2317 to see one of these when an exec() has happened, is if the user
2318 caught a vfork, and then said "finish". Ordinarily a finish just
2319 carries them to the call-site of the current callee, by setting
2320 a temporary bp there and resuming. But in this case, the finish
2321 will carry them entirely through the vfork & exec.
2323 We don't want to allow a bp_finish to remain inserted now. But
2324 we can't safely delete it, 'cause finish_command has a handle to
2325 the bp on a bpstat, and will later want to delete it. There's a
2326 chance (and I've seen it happen) that if we delete the bp_finish
2327 here, that its storage will get reused by the time finish_command
2328 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2329 We really must allow finish_command to delete a bp_finish.
2331 In the absense of a general solution for the "how do we know
2332 it's safe to delete something others may have handles to?"
2333 problem, what we'll do here is just uninsert the bp_finish, and
2334 let finish_command delete it.
2336 (We know the bp_finish is "doomed" in the sense that it's
2337 momentary, and will be deleted as soon as finish_command sees
2338 the inferior stopped. So it doesn't matter that the bp's
2339 address is probably bogus in the new a.out, unlike e.g., the
2340 solib breakpoints.) */
2342 if (b->type == bp_finish)
2347 /* Without a symbolic address, we have little hope of the
2348 pre-exec() address meaning the same thing in the post-exec()
2350 if (b->addr_string == NULL)
2352 delete_breakpoint (b);
2356 /* FIXME what about longjmp breakpoints? Re-create them here? */
2357 create_overlay_event_breakpoint ("_ovly_debug_event");
2358 create_longjmp_master_breakpoint ("longjmp");
2359 create_longjmp_master_breakpoint ("_longjmp");
2360 create_longjmp_master_breakpoint ("siglongjmp");
2361 create_longjmp_master_breakpoint ("_siglongjmp");
2362 create_std_terminate_master_breakpoint ("std::terminate()");
2366 detach_breakpoints (int pid)
2368 struct bp_location *b, **bp_tmp;
2370 struct cleanup *old_chain = save_inferior_ptid ();
2371 struct inferior *inf = current_inferior ();
2373 if (pid == PIDGET (inferior_ptid))
2374 error (_("Cannot detach breakpoints of inferior_ptid"));
2376 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2377 inferior_ptid = pid_to_ptid (pid);
2378 ALL_BP_LOCATIONS (b, bp_tmp)
2380 if (b->pspace != inf->pspace)
2384 val |= remove_breakpoint_1 (b, mark_inserted);
2386 do_cleanups (old_chain);
2390 /* Remove the breakpoint location B from the current address space.
2391 Note that this is used to detach breakpoints from a child fork.
2392 When we get here, the child isn't in the inferior list, and neither
2393 do we have objects to represent its address space --- we should
2394 *not* look at b->pspace->aspace here. */
2397 remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
2401 /* B is never in moribund_locations by our callers. */
2402 gdb_assert (b->owner != NULL);
2404 if (b->owner->enable_state == bp_permanent)
2405 /* Permanent breakpoints cannot be inserted or removed. */
2408 /* The type of none suggests that owner is actually deleted.
2409 This should not ever happen. */
2410 gdb_assert (b->owner->type != bp_none);
2412 if (b->loc_type == bp_loc_software_breakpoint
2413 || b->loc_type == bp_loc_hardware_breakpoint)
2415 /* "Normal" instruction breakpoint: either the standard
2416 trap-instruction bp (bp_breakpoint), or a
2417 bp_hardware_breakpoint. */
2419 /* First check to see if we have to handle an overlay. */
2420 if (overlay_debugging == ovly_off
2421 || b->section == NULL
2422 || !(section_is_overlay (b->section)))
2424 /* No overlay handling: just remove the breakpoint. */
2426 if (b->loc_type == bp_loc_hardware_breakpoint)
2427 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
2429 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
2433 /* This breakpoint is in an overlay section.
2434 Did we set a breakpoint at the LMA? */
2435 if (!overlay_events_enabled)
2437 /* Yes -- overlay event support is not active, so we
2438 should have set a breakpoint at the LMA. Remove it.
2440 /* Ignore any failures: if the LMA is in ROM, we will
2441 have already warned when we failed to insert it. */
2442 if (b->loc_type == bp_loc_hardware_breakpoint)
2443 target_remove_hw_breakpoint (b->gdbarch,
2444 &b->overlay_target_info);
2446 target_remove_breakpoint (b->gdbarch,
2447 &b->overlay_target_info);
2449 /* Did we set a breakpoint at the VMA?
2450 If so, we will have marked the breakpoint 'inserted'. */
2453 /* Yes -- remove it. Previously we did not bother to
2454 remove the breakpoint if the section had been
2455 unmapped, but let's not rely on that being safe. We
2456 don't know what the overlay manager might do. */
2457 if (b->loc_type == bp_loc_hardware_breakpoint)
2458 val = target_remove_hw_breakpoint (b->gdbarch,
2461 /* However, we should remove *software* breakpoints only
2462 if the section is still mapped, or else we overwrite
2463 wrong code with the saved shadow contents. */
2464 else if (section_is_mapped (b->section))
2465 val = target_remove_breakpoint (b->gdbarch,
2472 /* No -- not inserted, so no need to remove. No error. */
2477 /* In some cases, we might not be able to remove a breakpoint
2478 in a shared library that has already been removed, but we
2479 have not yet processed the shlib unload event. */
2480 if (val && solib_name_from_address (b->pspace, b->address))
2485 b->inserted = (is == mark_inserted);
2487 else if (b->loc_type == bp_loc_hardware_watchpoint)
2489 b->inserted = (is == mark_inserted);
2490 val = target_remove_watchpoint (b->address, b->length,
2491 b->watchpoint_type);
2493 /* Failure to remove any of the hardware watchpoints comes here. */
2494 if ((is == mark_uninserted) && (b->inserted))
2495 warning (_("Could not remove hardware watchpoint %d."),
2498 else if (b->owner->type == bp_catchpoint
2499 && breakpoint_enabled (b->owner)
2502 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
2504 val = b->owner->ops->remove (b->owner);
2507 b->inserted = (is == mark_inserted);
2514 remove_breakpoint (struct bp_location *b, insertion_state_t is)
2517 struct cleanup *old_chain;
2519 /* B is never in moribund_locations by our callers. */
2520 gdb_assert (b->owner != NULL);
2522 if (b->owner->enable_state == bp_permanent)
2523 /* Permanent breakpoints cannot be inserted or removed. */
2526 /* The type of none suggests that owner is actually deleted.
2527 This should not ever happen. */
2528 gdb_assert (b->owner->type != bp_none);
2530 old_chain = save_current_space_and_thread ();
2532 switch_to_program_space_and_thread (b->pspace);
2534 ret = remove_breakpoint_1 (b, is);
2536 do_cleanups (old_chain);
2540 /* Clear the "inserted" flag in all breakpoints. */
2543 mark_breakpoints_out (void)
2545 struct bp_location *bpt, **bptp_tmp;
2547 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2548 if (bpt->pspace == current_program_space)
2552 /* Clear the "inserted" flag in all breakpoints and delete any
2553 breakpoints which should go away between runs of the program.
2555 Plus other such housekeeping that has to be done for breakpoints
2558 Note: this function gets called at the end of a run (by
2559 generic_mourn_inferior) and when a run begins (by
2560 init_wait_for_inferior). */
2565 breakpoint_init_inferior (enum inf_context context)
2567 struct breakpoint *b, *temp;
2568 struct bp_location *bpt, **bptp_tmp;
2570 struct program_space *pspace = current_program_space;
2572 /* If breakpoint locations are shared across processes, then there's
2574 if (gdbarch_has_global_breakpoints (target_gdbarch))
2577 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2579 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2580 if (bpt->pspace == pspace
2581 && bpt->owner->enable_state != bp_permanent)
2585 ALL_BREAKPOINTS_SAFE (b, temp)
2587 if (b->loc && b->loc->pspace != pspace)
2594 /* If the call dummy breakpoint is at the entry point it will
2595 cause problems when the inferior is rerun, so we better get
2598 case bp_watchpoint_scope:
2600 /* Also get rid of scope breakpoints. */
2602 case bp_shlib_event:
2604 /* Also remove solib event breakpoints. Their addresses may
2605 have changed since the last time we ran the program.
2606 Actually we may now be debugging against different target;
2607 and so the solib backend that installed this breakpoint may
2608 not be used in by the target. E.g.,
2610 (gdb) file prog-linux
2611 (gdb) run # native linux target
2614 (gdb) file prog-win.exe
2615 (gdb) tar rem :9999 # remote Windows gdbserver.
2618 delete_breakpoint (b);
2622 case bp_hardware_watchpoint:
2623 case bp_read_watchpoint:
2624 case bp_access_watchpoint:
2626 /* Likewise for watchpoints on local expressions. */
2627 if (b->exp_valid_block != NULL)
2628 delete_breakpoint (b);
2629 else if (context == inf_starting)
2631 /* Reset val field to force reread of starting value
2632 in insert_breakpoints. */
2634 value_free (b->val);
2644 /* Get rid of the moribund locations. */
2645 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
2646 free_bp_location (bpt);
2647 VEC_free (bp_location_p, moribund_locations);
2650 /* These functions concern about actual breakpoints inserted in the
2651 target --- to e.g. check if we need to do decr_pc adjustment or if
2652 we need to hop over the bkpt --- so we check for address space
2653 match, not program space. */
2655 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2656 exists at PC. It returns ordinary_breakpoint_here if it's an
2657 ordinary breakpoint, or permanent_breakpoint_here if it's a
2658 permanent breakpoint.
2659 - When continuing from a location with an ordinary breakpoint, we
2660 actually single step once before calling insert_breakpoints.
2661 - When continuing from a localion with a permanent breakpoint, we
2662 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2663 the target, to advance the PC past the breakpoint. */
2665 enum breakpoint_here
2666 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2668 struct bp_location *bpt, **bptp_tmp;
2669 int any_breakpoint_here = 0;
2671 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2673 if (bpt->loc_type != bp_loc_software_breakpoint
2674 && bpt->loc_type != bp_loc_hardware_breakpoint)
2677 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2678 if ((breakpoint_enabled (bpt->owner)
2679 || bpt->owner->enable_state == bp_permanent)
2680 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2683 if (overlay_debugging
2684 && section_is_overlay (bpt->section)
2685 && !section_is_mapped (bpt->section))
2686 continue; /* unmapped overlay -- can't be a match */
2687 else if (bpt->owner->enable_state == bp_permanent)
2688 return permanent_breakpoint_here;
2690 any_breakpoint_here = 1;
2694 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2697 /* Return true if there's a moribund breakpoint at PC. */
2700 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2702 struct bp_location *loc;
2705 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2706 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2713 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2714 inserted using regular breakpoint_chain / bp_location array mechanism.
2715 This does not check for single-step breakpoints, which are
2716 inserted and removed using direct target manipulation. */
2719 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2721 struct bp_location *bpt, **bptp_tmp;
2723 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2725 if (bpt->loc_type != bp_loc_software_breakpoint
2726 && bpt->loc_type != bp_loc_hardware_breakpoint)
2730 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2733 if (overlay_debugging
2734 && section_is_overlay (bpt->section)
2735 && !section_is_mapped (bpt->section))
2736 continue; /* unmapped overlay -- can't be a match */
2744 /* Returns non-zero iff there's either regular breakpoint
2745 or a single step breakpoint inserted at PC. */
2748 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2750 if (regular_breakpoint_inserted_here_p (aspace, pc))
2753 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2759 /* This function returns non-zero iff there is a software breakpoint
2763 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2765 struct bp_location *bpt, **bptp_tmp;
2767 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2769 if (bpt->loc_type != bp_loc_software_breakpoint)
2773 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2776 if (overlay_debugging
2777 && section_is_overlay (bpt->section)
2778 && !section_is_mapped (bpt->section))
2779 continue; /* unmapped overlay -- can't be a match */
2785 /* Also check for software single-step breakpoints. */
2786 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2793 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2794 CORE_ADDR addr, ULONGEST len)
2796 struct breakpoint *bpt;
2798 ALL_BREAKPOINTS (bpt)
2800 struct bp_location *loc;
2802 if (bpt->type != bp_hardware_watchpoint
2803 && bpt->type != bp_access_watchpoint)
2806 if (!breakpoint_enabled (bpt))
2809 for (loc = bpt->loc; loc; loc = loc->next)
2810 if (loc->pspace->aspace == aspace && loc->inserted)
2814 /* Check for intersection. */
2815 l = max (loc->address, addr);
2816 h = min (loc->address + loc->length, addr + len);
2824 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2825 PC is valid for process/thread PTID. */
2828 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2831 struct bp_location *bpt, **bptp_tmp;
2832 /* The thread and task IDs associated to PTID, computed lazily. */
2836 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2838 if (bpt->loc_type != bp_loc_software_breakpoint
2839 && bpt->loc_type != bp_loc_hardware_breakpoint)
2842 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2843 if (!breakpoint_enabled (bpt->owner)
2844 && bpt->owner->enable_state != bp_permanent)
2847 if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2851 if (bpt->owner->thread != -1)
2853 /* This is a thread-specific breakpoint. Check that ptid
2854 matches that thread. If thread hasn't been computed yet,
2855 it is now time to do so. */
2857 thread = pid_to_thread_id (ptid);
2858 if (bpt->owner->thread != thread)
2862 if (bpt->owner->task != 0)
2864 /* This is a task-specific breakpoint. Check that ptid
2865 matches that task. If task hasn't been computed yet,
2866 it is now time to do so. */
2868 task = ada_get_task_number (ptid);
2869 if (bpt->owner->task != task)
2873 if (overlay_debugging
2874 && section_is_overlay (bpt->section)
2875 && !section_is_mapped (bpt->section))
2876 continue; /* unmapped overlay -- can't be a match */
2885 /* bpstat stuff. External routines' interfaces are documented
2889 ep_is_catchpoint (struct breakpoint *ep)
2891 return (ep->type == bp_catchpoint);
2895 bpstat_free (bpstat bs)
2897 if (bs->old_val != NULL)
2898 value_free (bs->old_val);
2899 decref_counted_command_line (&bs->commands);
2903 /* Clear a bpstat so that it says we are not at any breakpoint.
2904 Also free any storage that is part of a bpstat. */
2907 bpstat_clear (bpstat *bsp)
2924 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2925 is part of the bpstat is copied as well. */
2928 bpstat_copy (bpstat bs)
2932 bpstat retval = NULL;
2937 for (; bs != NULL; bs = bs->next)
2939 tmp = (bpstat) xmalloc (sizeof (*tmp));
2940 memcpy (tmp, bs, sizeof (*tmp));
2941 incref_counted_command_line (tmp->commands);
2942 if (bs->old_val != NULL)
2944 tmp->old_val = value_copy (bs->old_val);
2945 release_value (tmp->old_val);
2949 /* This is the first thing in the chain. */
2959 /* Find the bpstat associated with this breakpoint */
2962 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2967 for (; bsp != NULL; bsp = bsp->next)
2969 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2975 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2976 at. *BSP upon return is a bpstat which points to the remaining
2977 breakpoints stopped at (but which is not guaranteed to be good for
2978 anything but further calls to bpstat_num).
2979 Return 0 if passed a bpstat which does not indicate any breakpoints.
2980 Return -1 if stopped at a breakpoint that has been deleted since
2982 Return 1 otherwise. */
2985 bpstat_num (bpstat *bsp, int *num)
2987 struct breakpoint *b;
2990 return 0; /* No more breakpoint values */
2992 /* We assume we'll never have several bpstats that
2993 correspond to a single breakpoint -- otherwise,
2994 this function might return the same number more
2995 than once and this will look ugly. */
2996 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2997 *bsp = (*bsp)->next;
2999 return -1; /* breakpoint that's been deleted since */
3001 *num = b->number; /* We have its number */
3005 /* Modify BS so that the actions will not be performed. */
3008 bpstat_clear_actions (bpstat bs)
3010 for (; bs != NULL; bs = bs->next)
3012 decref_counted_command_line (&bs->commands);
3013 bs->commands_left = NULL;
3014 if (bs->old_val != NULL)
3016 value_free (bs->old_val);
3022 /* Called when a command is about to proceed the inferior. */
3025 breakpoint_about_to_proceed (void)
3027 if (!ptid_equal (inferior_ptid, null_ptid))
3029 struct thread_info *tp = inferior_thread ();
3031 /* Allow inferior function calls in breakpoint commands to not
3032 interrupt the command list. When the call finishes
3033 successfully, the inferior will be standing at the same
3034 breakpoint as if nothing happened. */
3039 breakpoint_proceeded = 1;
3042 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3044 cleanup_executing_breakpoints (void *ignore)
3046 executing_breakpoint_commands = 0;
3049 /* Execute all the commands associated with all the breakpoints at this
3050 location. Any of these commands could cause the process to proceed
3051 beyond this point, etc. We look out for such changes by checking
3052 the global "breakpoint_proceeded" after each command.
3054 Returns true if a breakpoint command resumed the inferior. In that
3055 case, it is the caller's responsibility to recall it again with the
3056 bpstat of the current thread. */
3059 bpstat_do_actions_1 (bpstat *bsp)
3062 struct cleanup *old_chain;
3065 /* Avoid endless recursion if a `source' command is contained
3067 if (executing_breakpoint_commands)
3070 executing_breakpoint_commands = 1;
3071 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3073 /* This pointer will iterate over the list of bpstat's. */
3076 breakpoint_proceeded = 0;
3077 for (; bs != NULL; bs = bs->next)
3079 struct counted_command_line *ccmd;
3080 struct command_line *cmd;
3081 struct cleanup *this_cmd_tree_chain;
3083 /* Take ownership of the BSP's command tree, if it has one.
3085 The command tree could legitimately contain commands like
3086 'step' and 'next', which call clear_proceed_status, which
3087 frees stop_bpstat's command tree. To make sure this doesn't
3088 free the tree we're executing out from under us, we need to
3089 take ownership of the tree ourselves. Since a given bpstat's
3090 commands are only executed once, we don't need to copy it; we
3091 can clear the pointer in the bpstat, and make sure we free
3092 the tree when we're done. */
3093 ccmd = bs->commands;
3094 bs->commands = NULL;
3096 = make_cleanup_decref_counted_command_line (&ccmd);
3097 cmd = bs->commands_left;
3098 bs->commands_left = NULL;
3102 execute_control_command (cmd);
3104 if (breakpoint_proceeded)
3110 /* We can free this command tree now. */
3111 do_cleanups (this_cmd_tree_chain);
3113 if (breakpoint_proceeded)
3115 if (target_can_async_p ())
3116 /* If we are in async mode, then the target might be still
3117 running, not stopped at any breakpoint, so nothing for
3118 us to do here -- just return to the event loop. */
3121 /* In sync mode, when execute_control_command returns
3122 we're already standing on the next breakpoint.
3123 Breakpoint commands for that stop were not run, since
3124 execute_command does not run breakpoint commands --
3125 only command_line_handler does, but that one is not
3126 involved in execution of breakpoint commands. So, we
3127 can now execute breakpoint commands. It should be
3128 noted that making execute_command do bpstat actions is
3129 not an option -- in this case we'll have recursive
3130 invocation of bpstat for each breakpoint with a
3131 command, and can easily blow up GDB stack. Instead, we
3132 return true, which will trigger the caller to recall us
3133 with the new stop_bpstat. */
3138 do_cleanups (old_chain);
3143 bpstat_do_actions (void)
3145 /* Do any commands attached to breakpoint we are stopped at. */
3146 while (!ptid_equal (inferior_ptid, null_ptid)
3147 && target_has_execution
3148 && !is_exited (inferior_ptid)
3149 && !is_executing (inferior_ptid))
3150 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3151 and only return when it is stopped at the next breakpoint, we
3152 keep doing breakpoint actions until it returns false to
3153 indicate the inferior was not resumed. */
3154 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
3158 /* Print out the (old or new) value associated with a watchpoint. */
3161 watchpoint_value_print (struct value *val, struct ui_file *stream)
3164 fprintf_unfiltered (stream, _("<unreadable>"));
3167 struct value_print_options opts;
3168 get_user_print_options (&opts);
3169 value_print (val, stream, &opts);
3173 /* This is the normal print function for a bpstat. In the future,
3174 much of this logic could (should?) be moved to bpstat_stop_status,
3175 by having it set different print_it values.
3177 Current scheme: When we stop, bpstat_print() is called. It loops
3178 through the bpstat list of things causing this stop, calling the
3179 print_bp_stop_message function on each one. The behavior of the
3180 print_bp_stop_message function depends on the print_it field of
3181 bpstat. If such field so indicates, call this function here.
3183 Return values from this routine (ultimately used by bpstat_print()
3184 and normal_stop() to decide what to do):
3185 PRINT_NOTHING: Means we already printed all we needed to print,
3186 don't print anything else.
3187 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3188 that something to be followed by a location.
3189 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3190 that something to be followed by a location.
3191 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3194 static enum print_stop_action
3195 print_it_typical (bpstat bs)
3197 struct cleanup *old_chain;
3198 struct breakpoint *b;
3199 const struct bp_location *bl;
3200 struct ui_stream *stb;
3202 enum print_stop_action result;
3204 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3205 which has since been deleted. */
3206 if (bs->breakpoint_at == NULL)
3207 return PRINT_UNKNOWN;
3208 bl = bs->breakpoint_at;
3210 /* bl->owner can be NULL if it was a momentary breakpoint
3211 which has since been placed into moribund_locations. */
3212 if (bl->owner == NULL)
3213 return PRINT_UNKNOWN;
3216 stb = ui_out_stream_new (uiout);
3217 old_chain = make_cleanup_ui_out_stream_delete (stb);
3222 case bp_hardware_breakpoint:
3223 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
3224 if (bl->address != bl->requested_address)
3225 breakpoint_adjustment_warning (bl->requested_address,
3228 annotate_breakpoint (b->number);
3230 ui_out_text (uiout, "\nTemporary breakpoint ");
3232 ui_out_text (uiout, "\nBreakpoint ");
3233 if (ui_out_is_mi_like_p (uiout))
3235 ui_out_field_string (uiout, "reason",
3236 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3237 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3239 ui_out_field_int (uiout, "bkptno", b->number);
3240 ui_out_text (uiout, ", ");
3241 result = PRINT_SRC_AND_LOC;
3244 case bp_shlib_event:
3245 /* Did we stop because the user set the stop_on_solib_events
3246 variable? (If so, we report this as a generic, "Stopped due
3247 to shlib event" message.) */
3248 printf_filtered (_("Stopped due to shared library event\n"));
3249 result = PRINT_NOTHING;
3252 case bp_thread_event:
3253 /* Not sure how we will get here.
3254 GDB should not stop for these breakpoints. */
3255 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3256 result = PRINT_NOTHING;
3259 case bp_overlay_event:
3260 /* By analogy with the thread event, GDB should not stop for these. */
3261 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3262 result = PRINT_NOTHING;
3265 case bp_longjmp_master:
3266 /* These should never be enabled. */
3267 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3268 result = PRINT_NOTHING;
3271 case bp_std_terminate_master:
3272 /* These should never be enabled. */
3273 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3274 result = PRINT_NOTHING;
3278 case bp_hardware_watchpoint:
3279 annotate_watchpoint (b->number);
3280 if (ui_out_is_mi_like_p (uiout))
3283 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3285 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3286 ui_out_text (uiout, "\nOld value = ");
3287 watchpoint_value_print (bs->old_val, stb->stream);
3288 ui_out_field_stream (uiout, "old", stb);
3289 ui_out_text (uiout, "\nNew value = ");
3290 watchpoint_value_print (b->val, stb->stream);
3291 ui_out_field_stream (uiout, "new", stb);
3292 ui_out_text (uiout, "\n");
3293 /* More than one watchpoint may have been triggered. */
3294 result = PRINT_UNKNOWN;
3297 case bp_read_watchpoint:
3298 if (ui_out_is_mi_like_p (uiout))
3301 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3303 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3304 ui_out_text (uiout, "\nValue = ");
3305 watchpoint_value_print (b->val, stb->stream);
3306 ui_out_field_stream (uiout, "value", stb);
3307 ui_out_text (uiout, "\n");
3308 result = PRINT_UNKNOWN;
3311 case bp_access_watchpoint:
3312 if (bs->old_val != NULL)
3314 annotate_watchpoint (b->number);
3315 if (ui_out_is_mi_like_p (uiout))
3318 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3320 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3321 ui_out_text (uiout, "\nOld value = ");
3322 watchpoint_value_print (bs->old_val, stb->stream);
3323 ui_out_field_stream (uiout, "old", stb);
3324 ui_out_text (uiout, "\nNew value = ");
3329 if (ui_out_is_mi_like_p (uiout))
3332 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3333 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3334 ui_out_text (uiout, "\nValue = ");
3336 watchpoint_value_print (b->val, stb->stream);
3337 ui_out_field_stream (uiout, "new", stb);
3338 ui_out_text (uiout, "\n");
3339 result = PRINT_UNKNOWN;
3342 /* Fall through, we don't deal with these types of breakpoints
3346 if (ui_out_is_mi_like_p (uiout))
3349 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3350 result = PRINT_UNKNOWN;
3354 if (ui_out_is_mi_like_p (uiout))
3357 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3358 result = PRINT_UNKNOWN;
3363 case bp_longjmp_resume:
3364 case bp_step_resume:
3365 case bp_watchpoint_scope:
3367 case bp_std_terminate:
3369 case bp_fast_tracepoint:
3372 result = PRINT_UNKNOWN;
3376 do_cleanups (old_chain);
3380 /* Generic routine for printing messages indicating why we
3381 stopped. The behavior of this function depends on the value
3382 'print_it' in the bpstat structure. Under some circumstances we
3383 may decide not to print anything here and delegate the task to
3386 static enum print_stop_action
3387 print_bp_stop_message (bpstat bs)
3389 switch (bs->print_it)
3392 /* Nothing should be printed for this bpstat entry. */
3393 return PRINT_UNKNOWN;
3397 /* We still want to print the frame, but we already printed the
3398 relevant messages. */
3399 return PRINT_SRC_AND_LOC;
3402 case print_it_normal:
3404 const struct bp_location *bl = bs->breakpoint_at;
3405 struct breakpoint *b = bl ? bl->owner : NULL;
3407 /* Normal case. Call the breakpoint's print_it method, or
3408 print_it_typical. */
3409 /* FIXME: how breakpoint can ever be NULL here? */
3410 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3411 return b->ops->print_it (b);
3413 return print_it_typical (bs);
3418 internal_error (__FILE__, __LINE__,
3419 _("print_bp_stop_message: unrecognized enum value"));
3424 /* Print a message indicating what happened. This is called from
3425 normal_stop(). The input to this routine is the head of the bpstat
3426 list - a list of the eventpoints that caused this stop. This
3427 routine calls the generic print routine for printing a message
3428 about reasons for stopping. This will print (for example) the
3429 "Breakpoint n," part of the output. The return value of this
3432 PRINT_UNKNOWN: Means we printed nothing
3433 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3434 code to print the location. An example is
3435 "Breakpoint 1, " which should be followed by
3437 PRINT_SRC_ONLY: Means we printed something, but there is no need
3438 to also print the location part of the message.
3439 An example is the catch/throw messages, which
3440 don't require a location appended to the end.
3441 PRINT_NOTHING: We have done some printing and we don't need any
3442 further info to be printed.*/
3444 enum print_stop_action
3445 bpstat_print (bpstat bs)
3449 /* Maybe another breakpoint in the chain caused us to stop.
3450 (Currently all watchpoints go on the bpstat whether hit or not.
3451 That probably could (should) be changed, provided care is taken
3452 with respect to bpstat_explains_signal). */
3453 for (; bs; bs = bs->next)
3455 val = print_bp_stop_message (bs);
3456 if (val == PRINT_SRC_ONLY
3457 || val == PRINT_SRC_AND_LOC
3458 || val == PRINT_NOTHING)
3462 /* We reached the end of the chain, or we got a null BS to start
3463 with and nothing was printed. */
3464 return PRINT_UNKNOWN;
3467 /* Evaluate the expression EXP and return 1 if value is zero.
3468 This is used inside a catch_errors to evaluate the breakpoint condition.
3469 The argument is a "struct expression *" that has been cast to char * to
3470 make it pass through catch_errors. */
3473 breakpoint_cond_eval (void *exp)
3475 struct value *mark = value_mark ();
3476 int i = !value_true (evaluate_expression ((struct expression *) exp));
3478 value_free_to_mark (mark);
3482 /* Allocate a new bpstat and chain it to the current one. */
3485 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
3489 bs = (bpstat) xmalloc (sizeof (*bs));
3491 bs->breakpoint_at = bl;
3492 /* If the condition is false, etc., don't do the commands. */
3493 bs->commands = NULL;
3494 bs->commands_left = NULL;
3496 bs->print_it = print_it_normal;
3500 /* The target has stopped with waitstatus WS. Check if any hardware
3501 watchpoints have triggered, according to the target. */
3504 watchpoints_triggered (struct target_waitstatus *ws)
3506 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3508 struct breakpoint *b;
3510 if (!stopped_by_watchpoint)
3512 /* We were not stopped by a watchpoint. Mark all watchpoints
3513 as not triggered. */
3515 if (is_hardware_watchpoint (b))
3516 b->watchpoint_triggered = watch_triggered_no;
3521 if (!target_stopped_data_address (¤t_target, &addr))
3523 /* We were stopped by a watchpoint, but we don't know where.
3524 Mark all watchpoints as unknown. */
3526 if (is_hardware_watchpoint (b))
3527 b->watchpoint_triggered = watch_triggered_unknown;
3529 return stopped_by_watchpoint;
3532 /* The target could report the data address. Mark watchpoints
3533 affected by this data address as triggered, and all others as not
3537 if (is_hardware_watchpoint (b))
3539 struct bp_location *loc;
3541 b->watchpoint_triggered = watch_triggered_no;
3542 for (loc = b->loc; loc; loc = loc->next)
3543 /* Exact match not required. Within range is
3545 if (target_watchpoint_addr_within_range (¤t_target,
3549 b->watchpoint_triggered = watch_triggered_yes;
3557 /* Possible return values for watchpoint_check (this can't be an enum
3558 because of check_errors). */
3559 /* The watchpoint has been deleted. */
3560 #define WP_DELETED 1
3561 /* The value has changed. */
3562 #define WP_VALUE_CHANGED 2
3563 /* The value has not changed. */
3564 #define WP_VALUE_NOT_CHANGED 3
3565 /* Ignore this watchpoint, no matter if the value changed or not. */
3568 #define BP_TEMPFLAG 1
3569 #define BP_HARDWAREFLAG 2
3571 /* Evaluate watchpoint condition expression and check if its value changed.
3573 P should be a pointer to struct bpstat, but is defined as a void *
3574 in order for this function to be usable with catch_errors. */
3577 watchpoint_check (void *p)
3579 bpstat bs = (bpstat) p;
3580 struct breakpoint *b;
3581 struct frame_info *fr;
3582 int within_current_scope;
3584 /* BS is built for existing struct breakpoint. */
3585 gdb_assert (bs->breakpoint_at != NULL);
3586 gdb_assert (bs->breakpoint_at->owner != NULL);
3587 b = bs->breakpoint_at->owner;
3589 /* If this is a local watchpoint, we only want to check if the
3590 watchpoint frame is in scope if the current thread is the thread
3591 that was used to create the watchpoint. */
3592 if (!watchpoint_in_thread_scope (b))
3595 if (b->exp_valid_block == NULL)
3596 within_current_scope = 1;
3599 struct frame_info *frame = get_current_frame ();
3600 struct gdbarch *frame_arch = get_frame_arch (frame);
3601 CORE_ADDR frame_pc = get_frame_pc (frame);
3603 /* in_function_epilogue_p() returns a non-zero value if we're still
3604 in the function but the stack frame has already been invalidated.
3605 Since we can't rely on the values of local variables after the
3606 stack has been destroyed, we are treating the watchpoint in that
3607 state as `not changed' without further checking. Don't mark
3608 watchpoints as changed if the current frame is in an epilogue -
3609 even if they are in some other frame, our view of the stack
3610 is likely to be wrong and frame_find_by_id could error out. */
3611 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3614 fr = frame_find_by_id (b->watchpoint_frame);
3615 within_current_scope = (fr != NULL);
3617 /* If we've gotten confused in the unwinder, we might have
3618 returned a frame that can't describe this variable. */
3619 if (within_current_scope)
3621 struct symbol *function;
3623 function = get_frame_function (fr);
3624 if (function == NULL
3625 || !contained_in (b->exp_valid_block,
3626 SYMBOL_BLOCK_VALUE (function)))
3627 within_current_scope = 0;
3630 if (within_current_scope)
3631 /* If we end up stopping, the current frame will get selected
3632 in normal_stop. So this call to select_frame won't affect
3637 if (within_current_scope)
3639 /* We use value_{,free_to_}mark because it could be a
3640 *long* time before we return to the command level and
3641 call free_all_values. We can't call free_all_values because
3642 we might be in the middle of evaluating a function call. */
3644 struct value *mark = value_mark ();
3645 struct value *new_val;
3647 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
3649 /* We use value_equal_contents instead of value_equal because the latter
3650 coerces an array to a pointer, thus comparing just the address of the
3651 array instead of its contents. This is not what we want. */
3652 if ((b->val != NULL) != (new_val != NULL)
3653 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3655 if (new_val != NULL)
3657 release_value (new_val);
3658 value_free_to_mark (mark);
3660 bs->old_val = b->val;
3663 return WP_VALUE_CHANGED;
3667 /* Nothing changed. */
3668 value_free_to_mark (mark);
3669 return WP_VALUE_NOT_CHANGED;
3674 /* This seems like the only logical thing to do because
3675 if we temporarily ignored the watchpoint, then when
3676 we reenter the block in which it is valid it contains
3677 garbage (in the case of a function, it may have two
3678 garbage values, one before and one after the prologue).
3679 So we can't even detect the first assignment to it and
3680 watch after that (since the garbage may or may not equal
3681 the first value assigned). */
3682 /* We print all the stop information in print_it_typical(), but
3683 in this case, by the time we call print_it_typical() this bp
3684 will be deleted already. So we have no choice but print the
3685 information here. */
3686 if (ui_out_is_mi_like_p (uiout))
3688 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3689 ui_out_text (uiout, "\nWatchpoint ");
3690 ui_out_field_int (uiout, "wpnum", b->number);
3691 ui_out_text (uiout, " deleted because the program has left the block in\n\
3692 which its expression is valid.\n");
3694 if (b->related_breakpoint)
3696 b->related_breakpoint->disposition = disp_del_at_next_stop;
3697 b->related_breakpoint->related_breakpoint = NULL;
3698 b->related_breakpoint = NULL;
3700 b->disposition = disp_del_at_next_stop;
3706 /* Return true if it looks like target has stopped due to hitting
3707 breakpoint location BL. This function does not check if we
3708 should stop, only if BL explains the stop. */
3710 bpstat_check_location (const struct bp_location *bl,
3711 struct address_space *aspace, CORE_ADDR bp_addr)
3713 struct breakpoint *b = bl->owner;
3715 /* BL is from existing struct breakpoint. */
3716 gdb_assert (b != NULL);
3718 /* By definition, the inferior does not report stops at
3720 if (is_tracepoint (b))
3723 if (!is_watchpoint (b)
3724 && b->type != bp_hardware_breakpoint
3725 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3727 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3730 if (overlay_debugging /* unmapped overlay section */
3731 && section_is_overlay (bl->section)
3732 && !section_is_mapped (bl->section))
3736 /* Continuable hardware watchpoints are treated as non-existent if the
3737 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3738 some data address). Otherwise gdb won't stop on a break instruction
3739 in the code (not from a breakpoint) when a hardware watchpoint has
3740 been defined. Also skip watchpoints which we know did not trigger
3741 (did not match the data address). */
3743 if (is_hardware_watchpoint (b)
3744 && b->watchpoint_triggered == watch_triggered_no)
3747 if (b->type == bp_hardware_breakpoint)
3749 if (bl->address != bp_addr)
3751 if (overlay_debugging /* unmapped overlay section */
3752 && section_is_overlay (bl->section)
3753 && !section_is_mapped (bl->section))
3757 if (b->type == bp_catchpoint)
3759 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3760 if (!b->ops->breakpoint_hit (b))
3767 /* If BS refers to a watchpoint, determine if the watched values
3768 has actually changed, and we should stop. If not, set BS->stop
3771 bpstat_check_watchpoint (bpstat bs)
3773 const struct bp_location *bl;
3774 struct breakpoint *b;
3776 /* BS is built for existing struct breakpoint. */
3777 bl = bs->breakpoint_at;
3778 gdb_assert (bl != NULL);
3780 gdb_assert (b != NULL);
3782 if (is_watchpoint (b))
3784 int must_check_value = 0;
3786 if (b->type == bp_watchpoint)
3787 /* For a software watchpoint, we must always check the
3789 must_check_value = 1;
3790 else if (b->watchpoint_triggered == watch_triggered_yes)
3791 /* We have a hardware watchpoint (read, write, or access)
3792 and the target earlier reported an address watched by
3794 must_check_value = 1;
3795 else if (b->watchpoint_triggered == watch_triggered_unknown
3796 && b->type == bp_hardware_watchpoint)
3797 /* We were stopped by a hardware watchpoint, but the target could
3798 not report the data address. We must check the watchpoint's
3799 value. Access and read watchpoints are out of luck; without
3800 a data address, we can't figure it out. */
3801 must_check_value = 1;
3803 if (must_check_value)
3805 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3807 struct cleanup *cleanups = make_cleanup (xfree, message);
3808 int e = catch_errors (watchpoint_check, bs, message,
3810 do_cleanups (cleanups);
3814 /* We've already printed what needs to be printed. */
3815 bs->print_it = print_it_done;
3819 bs->print_it = print_it_noop;
3822 case WP_VALUE_CHANGED:
3823 if (b->type == bp_read_watchpoint)
3825 /* There are two cases to consider here:
3827 1. we're watching the triggered memory for reads.
3828 In that case, trust the target, and always report
3829 the watchpoint hit to the user. Even though
3830 reads don't cause value changes, the value may
3831 have changed since the last time it was read, and
3832 since we're not trapping writes, we will not see
3833 those, and as such we should ignore our notion of
3836 2. we're watching the triggered memory for both
3837 reads and writes. There are two ways this may
3840 2.1. this is a target that can't break on data
3841 reads only, but can break on accesses (reads or
3842 writes), such as e.g., x86. We detect this case
3843 at the time we try to insert read watchpoints.
3845 2.2. otherwise, the target supports read
3846 watchpoints, but, the user set an access or write
3847 watchpoint watching the same memory as this read
3850 If we're watching memory writes as well as reads,
3851 ignore watchpoint hits when we find that the
3852 value hasn't changed, as reads don't cause
3853 changes. This still gives false positives when
3854 the program writes the same value to memory as
3855 what there was already in memory (we will confuse
3856 it for a read), but it's much better than
3859 int other_write_watchpoint = 0;
3861 if (bl->watchpoint_type == hw_read)
3863 struct breakpoint *other_b;
3865 ALL_BREAKPOINTS (other_b)
3866 if ((other_b->type == bp_hardware_watchpoint
3867 || other_b->type == bp_access_watchpoint)
3868 && (other_b->watchpoint_triggered
3869 == watch_triggered_yes))
3871 other_write_watchpoint = 1;
3876 if (other_write_watchpoint
3877 || bl->watchpoint_type == hw_access)
3879 /* We're watching the same memory for writes,
3880 and the value changed since the last time we
3881 updated it, so this trap must be for a write.
3883 bs->print_it = print_it_noop;
3888 case WP_VALUE_NOT_CHANGED:
3889 if (b->type == bp_hardware_watchpoint
3890 || b->type == bp_watchpoint)
3892 /* Don't stop: write watchpoints shouldn't fire if
3893 the value hasn't changed. */
3894 bs->print_it = print_it_noop;
3902 /* Error from catch_errors. */
3903 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3904 if (b->related_breakpoint)
3905 b->related_breakpoint->disposition = disp_del_at_next_stop;
3906 b->disposition = disp_del_at_next_stop;
3907 /* We've already printed what needs to be printed. */
3908 bs->print_it = print_it_done;
3912 else /* must_check_value == 0 */
3914 /* This is a case where some watchpoint(s) triggered, but
3915 not at the address of this watchpoint, or else no
3916 watchpoint triggered after all. So don't print
3917 anything for this watchpoint. */
3918 bs->print_it = print_it_noop;
3925 /* Check conditions (condition proper, frame, thread and ignore count)
3926 of breakpoint referred to by BS. If we should not stop for this
3927 breakpoint, set BS->stop to 0. */
3929 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3931 int thread_id = pid_to_thread_id (ptid);
3932 const struct bp_location *bl;
3933 struct breakpoint *b;
3935 /* BS is built for existing struct breakpoint. */
3936 bl = bs->breakpoint_at;
3937 gdb_assert (bl != NULL);
3939 gdb_assert (b != NULL);
3941 if (frame_id_p (b->frame_id)
3942 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3946 int value_is_zero = 0;
3947 struct expression *cond;
3949 /* If this is a scope breakpoint, mark the associated
3950 watchpoint as triggered so that we will handle the
3951 out-of-scope event. We'll get to the watchpoint next
3953 if (b->type == bp_watchpoint_scope)
3954 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3956 if (is_watchpoint (b))
3961 if (cond && bl->owner->disposition != disp_del_at_next_stop)
3963 int within_current_scope = 1;
3965 /* We use value_mark and value_free_to_mark because it could
3966 be a long time before we return to the command level and
3967 call free_all_values. We can't call free_all_values
3968 because we might be in the middle of evaluating a
3970 struct value *mark = value_mark ();
3972 /* Need to select the frame, with all that implies so that
3973 the conditions will have the right context. Because we
3974 use the frame, we will not see an inlined function's
3975 variables when we arrive at a breakpoint at the start
3976 of the inlined function; the current frame will be the
3978 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
3979 select_frame (get_current_frame ());
3982 struct frame_info *frame;
3984 /* For local watchpoint expressions, which particular
3985 instance of a local is being watched matters, so we
3986 keep track of the frame to evaluate the expression
3987 in. To evaluate the condition however, it doesn't
3988 really matter which instantiation of the function
3989 where the condition makes sense triggers the
3990 watchpoint. This allows an expression like "watch
3991 global if q > 10" set in `func', catch writes to
3992 global on all threads that call `func', or catch
3993 writes on all recursive calls of `func' by a single
3994 thread. We simply always evaluate the condition in
3995 the innermost frame that's executing where it makes
3996 sense to evaluate the condition. It seems
3998 frame = block_innermost_frame (b->cond_exp_valid_block);
4000 select_frame (frame);
4002 within_current_scope = 0;
4004 if (within_current_scope)
4006 = catch_errors (breakpoint_cond_eval, cond,
4007 "Error in testing breakpoint condition:\n",
4011 warning (_("Watchpoint condition cannot be tested "
4012 "in the current scope"));
4013 /* If we failed to set the right context for this
4014 watchpoint, unconditionally report it. */
4017 /* FIXME-someday, should give breakpoint # */
4018 value_free_to_mark (mark);
4021 if (cond && value_is_zero)
4025 else if (b->thread != -1 && b->thread != thread_id)
4029 else if (b->ignore_count > 0)
4032 annotate_ignore_count_change ();
4034 /* Increase the hit count even though we don't
4042 /* Get a bpstat associated with having just stopped at address
4043 BP_ADDR in thread PTID.
4045 Determine whether we stopped at a breakpoint, etc, or whether we
4046 don't understand this stop. Result is a chain of bpstat's such that:
4048 if we don't understand the stop, the result is a null pointer.
4050 if we understand why we stopped, the result is not null.
4052 Each element of the chain refers to a particular breakpoint or
4053 watchpoint at which we have stopped. (We may have stopped for
4054 several reasons concurrently.)
4056 Each element of the chain has valid next, breakpoint_at,
4057 commands, FIXME??? fields. */
4060 bpstat_stop_status (struct address_space *aspace,
4061 CORE_ADDR bp_addr, ptid_t ptid)
4063 struct breakpoint *b = NULL;
4064 struct bp_location *bl;
4065 struct bp_location *loc;
4066 /* Root of the chain of bpstat's */
4067 struct bpstats root_bs[1];
4068 /* Pointer to the last thing in the chain currently. */
4069 bpstat bs = root_bs;
4071 int need_remove_insert;
4073 /* ALL_BP_LOCATIONS iteration would break across
4074 update_global_location_list possibly executed by
4075 bpstat_check_breakpoint_conditions's inferior call. */
4079 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4082 for (bl = b->loc; bl != NULL; bl = bl->next)
4084 /* For hardware watchpoints, we look only at the first location.
4085 The watchpoint_check function will work on the entire expression,
4086 not the individual locations. For read watchpoints, the
4087 watchpoints_triggered function has checked all locations
4089 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4092 if (bl->shlib_disabled)
4095 if (!bpstat_check_location (bl, aspace, bp_addr))
4098 /* Come here if it's a watchpoint, or if the break address matches */
4100 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
4102 /* Assume we stop. Should we find watchpoint that is not actually
4103 triggered, or if condition of breakpoint is false, we'll reset
4108 bpstat_check_watchpoint (bs);
4112 if (b->type == bp_thread_event || b->type == bp_overlay_event
4113 || b->type == bp_longjmp_master
4114 || b->type == bp_std_terminate_master)
4115 /* We do not stop for these. */
4118 bpstat_check_breakpoint_conditions (bs, ptid);
4124 /* We will stop here */
4125 if (b->disposition == disp_disable)
4127 if (b->enable_state != bp_permanent)
4128 b->enable_state = bp_disabled;
4129 update_global_location_list (0);
4133 bs->commands = b->commands;
4134 incref_counted_command_line (bs->commands);
4135 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4136 if (bs->commands_left
4137 && (strcmp ("silent", bs->commands_left->line) == 0
4140 bs->commands_left->line) == 0)))
4142 bs->commands_left = bs->commands_left->next;
4147 /* Print nothing for this entry if we dont stop or dont print. */
4148 if (bs->stop == 0 || bs->print == 0)
4149 bs->print_it = print_it_noop;
4153 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4155 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4158 bs = bpstat_alloc (loc, bs);
4159 /* For hits of moribund locations, we should just proceed. */
4162 bs->print_it = print_it_noop;
4166 bs->next = NULL; /* Terminate the chain */
4168 /* If we aren't stopping, the value of some hardware watchpoint may
4169 not have changed, but the intermediate memory locations we are
4170 watching may have. Don't bother if we're stopping; this will get
4172 need_remove_insert = 0;
4173 if (! bpstat_causes_stop (root_bs->next))
4174 for (bs = root_bs->next; bs != NULL; bs = bs->next)
4176 && bs->breakpoint_at->owner
4177 && is_hardware_watchpoint (bs->breakpoint_at->owner))
4179 update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */);
4180 /* Updating watchpoints invalidates bs->breakpoint_at.
4181 Prevent further code from trying to use it. */
4182 bs->breakpoint_at = NULL;
4183 need_remove_insert = 1;
4186 if (need_remove_insert)
4187 update_global_location_list (1);
4189 return root_bs->next;
4192 /* Tell what to do about this bpstat. */
4194 bpstat_what (bpstat bs)
4196 /* Classify each bpstat as one of the following. */
4199 /* This bpstat element has no effect on the main_action. */
4202 /* There was a watchpoint, stop but don't print. */
4205 /* There was a watchpoint, stop and print. */
4208 /* There was a breakpoint but we're not stopping. */
4211 /* There was a breakpoint, stop but don't print. */
4214 /* There was a breakpoint, stop and print. */
4217 /* We hit the longjmp breakpoint. */
4220 /* We hit the longjmp_resume breakpoint. */
4223 /* We hit the step_resume breakpoint. */
4226 /* We hit the shared library event breakpoint. */
4229 /* We hit the jit event breakpoint. */
4232 /* This is just used to count how many enums there are. */
4236 /* Here is the table which drives this routine. So that we can
4237 format it pretty, we define some abbreviations for the
4238 enum bpstat_what codes. */
4239 #define kc BPSTAT_WHAT_KEEP_CHECKING
4240 #define ss BPSTAT_WHAT_STOP_SILENT
4241 #define sn BPSTAT_WHAT_STOP_NOISY
4242 #define sgl BPSTAT_WHAT_SINGLE
4243 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4244 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4245 #define sr BPSTAT_WHAT_STEP_RESUME
4246 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4247 #define jit BPSTAT_WHAT_CHECK_JIT
4249 /* "Can't happen." Might want to print an error message.
4250 abort() is not out of the question, but chances are GDB is just
4251 a bit confused, not unusable. */
4252 #define err BPSTAT_WHAT_STOP_NOISY
4254 /* Given an old action and a class, come up with a new action. */
4255 /* One interesting property of this table is that wp_silent is the same
4256 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4257 after stopping, the check for whether to step over a breakpoint
4258 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4259 reference to how we stopped. We retain separate wp_silent and
4260 bp_silent codes in case we want to change that someday.
4262 Another possibly interesting property of this table is that
4263 there's a partial ordering, priority-like, of the actions. Once
4264 you've decided that some action is appropriate, you'll never go
4265 back and decide something of a lower priority is better. The
4268 kc < jit clr sgl shl slr sn sr ss
4269 sgl < jit shl slr sn sr ss
4270 slr < jit err shl sn sr ss
4271 clr < jit err shl sn sr ss
4278 What I think this means is that we don't need a damned table
4279 here. If you just put the rows and columns in the right order,
4280 it'd look awfully regular. We could simply walk the bpstat list
4281 and choose the highest priority action we find, with a little
4282 logic to handle the 'err' cases. */
4284 /* step_resume entries: a step resume breakpoint overrides another
4285 breakpoint of signal handling (see comment in wait_for_inferior
4286 at where we set the step_resume breakpoint). */
4288 static const enum bpstat_what_main_action
4289 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
4292 /* kc ss sn sgl slr clr sr shl jit */
4293 /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit},
4294 /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
4295 /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
4296 /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit},
4297 /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit},
4298 /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit},
4299 /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit},
4300 /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit},
4301 /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr },
4302 /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl},
4303 /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit}
4317 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
4318 struct bpstat_what retval;
4320 retval.call_dummy = STOP_NONE;
4321 for (; bs != NULL; bs = bs->next)
4323 enum class bs_class = no_effect;
4324 if (bs->breakpoint_at == NULL)
4325 /* I suspect this can happen if it was a momentary breakpoint
4326 which has since been deleted. */
4328 if (bs->breakpoint_at->owner == NULL)
4329 bs_class = bp_nostop;
4331 switch (bs->breakpoint_at->owner->type)
4337 case bp_hardware_breakpoint:
4343 bs_class = bp_noisy;
4345 bs_class = bp_silent;
4348 bs_class = bp_nostop;
4351 case bp_hardware_watchpoint:
4352 case bp_read_watchpoint:
4353 case bp_access_watchpoint:
4357 bs_class = wp_noisy;
4359 bs_class = wp_silent;
4362 /* There was a watchpoint, but we're not stopping.
4363 This requires no further action. */
4364 bs_class = no_effect;
4367 bs_class = long_jump;
4369 case bp_longjmp_resume:
4370 bs_class = long_resume;
4372 case bp_step_resume:
4375 bs_class = step_resume;
4378 /* It is for the wrong frame. */
4379 bs_class = bp_nostop;
4381 case bp_watchpoint_scope:
4382 bs_class = bp_nostop;
4384 case bp_shlib_event:
4385 bs_class = shlib_event;
4388 bs_class = jit_event;
4390 case bp_thread_event:
4391 case bp_overlay_event:
4392 case bp_longjmp_master:
4393 case bp_std_terminate_master:
4394 bs_class = bp_nostop;
4400 bs_class = bp_noisy;
4402 bs_class = bp_silent;
4405 /* There was a catchpoint, but we're not stopping.
4406 This requires no further action. */
4407 bs_class = no_effect;
4410 /* Make sure the action is stop (silent or noisy),
4411 so infrun.c pops the dummy frame. */
4412 bs_class = bp_silent;
4413 retval.call_dummy = STOP_STACK_DUMMY;
4415 case bp_std_terminate:
4416 /* Make sure the action is stop (silent or noisy),
4417 so infrun.c pops the dummy frame. */
4418 bs_class = bp_silent;
4419 retval.call_dummy = STOP_STD_TERMINATE;
4422 case bp_fast_tracepoint:
4423 /* Tracepoint hits should not be reported back to GDB, and
4424 if one got through somehow, it should have been filtered
4426 internal_error (__FILE__, __LINE__,
4427 _("bpstat_what: tracepoint encountered"));
4430 current_action = table[(int) bs_class][(int) current_action];
4432 retval.main_action = current_action;
4436 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4437 without hardware support). This isn't related to a specific bpstat,
4438 just to things like whether watchpoints are set. */
4441 bpstat_should_step (void)
4443 struct breakpoint *b;
4446 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4452 bpstat_causes_stop (bpstat bs)
4454 for (; bs != NULL; bs = bs->next)
4463 /* Print the LOC location out of the list of B->LOC locations. */
4465 static void print_breakpoint_location (struct breakpoint *b,
4466 struct bp_location *loc,
4468 struct ui_stream *stb)
4470 struct cleanup *old_chain = save_current_program_space ();
4472 if (loc != NULL && loc->shlib_disabled)
4476 set_current_program_space (loc->pspace);
4478 if (b->source_file && loc)
4481 = find_pc_sect_function (loc->address, loc->section);
4484 ui_out_text (uiout, "in ");
4485 ui_out_field_string (uiout, "func",
4486 SYMBOL_PRINT_NAME (sym));
4487 ui_out_wrap_hint (uiout, wrap_indent);
4488 ui_out_text (uiout, " at ");
4490 ui_out_field_string (uiout, "file", b->source_file);
4491 ui_out_text (uiout, ":");
4493 if (ui_out_is_mi_like_p (uiout))
4495 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4496 char *fullname = symtab_to_fullname (sal.symtab);
4499 ui_out_field_string (uiout, "fullname", fullname);
4502 ui_out_field_int (uiout, "line", b->line_number);
4506 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4508 ui_out_field_stream (uiout, "at", stb);
4511 ui_out_field_string (uiout, "pending", b->addr_string);
4513 do_cleanups (old_chain);
4516 /* Print B to gdb_stdout. */
4518 print_one_breakpoint_location (struct breakpoint *b,
4519 struct bp_location *loc,
4521 struct bp_location **last_loc,
4522 int print_address_bits,
4525 struct command_line *l;
4526 struct ep_type_description
4531 static struct ep_type_description bptypes[] =
4533 {bp_none, "?deleted?"},
4534 {bp_breakpoint, "breakpoint"},
4535 {bp_hardware_breakpoint, "hw breakpoint"},
4536 {bp_until, "until"},
4537 {bp_finish, "finish"},
4538 {bp_watchpoint, "watchpoint"},
4539 {bp_hardware_watchpoint, "hw watchpoint"},
4540 {bp_read_watchpoint, "read watchpoint"},
4541 {bp_access_watchpoint, "acc watchpoint"},
4542 {bp_longjmp, "longjmp"},
4543 {bp_longjmp_resume, "longjmp resume"},
4544 {bp_step_resume, "step resume"},
4545 {bp_watchpoint_scope, "watchpoint scope"},
4546 {bp_call_dummy, "call dummy"},
4547 {bp_std_terminate, "std::terminate"},
4548 {bp_shlib_event, "shlib events"},
4549 {bp_thread_event, "thread events"},
4550 {bp_overlay_event, "overlay events"},
4551 {bp_longjmp_master, "longjmp master"},
4552 {bp_std_terminate_master, "std::terminate master"},
4553 {bp_catchpoint, "catchpoint"},
4554 {bp_tracepoint, "tracepoint"},
4555 {bp_fast_tracepoint, "fast tracepoint"},
4556 {bp_jit_event, "jit events"},
4559 static char bpenables[] = "nynny";
4560 char wrap_indent[80];
4561 struct ui_stream *stb = ui_out_stream_new (uiout);
4562 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4563 struct cleanup *bkpt_chain;
4565 int header_of_multiple = 0;
4566 int part_of_multiple = (loc != NULL);
4567 struct value_print_options opts;
4569 get_user_print_options (&opts);
4571 gdb_assert (!loc || loc_number != 0);
4572 /* See comment in print_one_breakpoint concerning
4573 treatment of breakpoints with single disabled
4577 && (b->loc->next != NULL || !b->loc->enabled)))
4578 header_of_multiple = 1;
4583 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4587 if (part_of_multiple)
4590 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4591 ui_out_field_string (uiout, "number", formatted);
4596 ui_out_field_int (uiout, "number", b->number);
4601 if (part_of_multiple)
4602 ui_out_field_skip (uiout, "type");
4605 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4606 || ((int) b->type != bptypes[(int) b->type].type))
4607 internal_error (__FILE__, __LINE__,
4608 _("bptypes table does not describe type #%d."),
4610 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
4615 if (part_of_multiple)
4616 ui_out_field_skip (uiout, "disp");
4618 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4623 if (part_of_multiple)
4624 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4626 ui_out_field_fmt (uiout, "enabled", "%c",
4627 bpenables[(int) b->enable_state]);
4628 ui_out_spaces (uiout, 2);
4632 strcpy (wrap_indent, " ");
4633 if (opts.addressprint)
4635 if (print_address_bits <= 32)
4636 strcat (wrap_indent, " ");
4638 strcat (wrap_indent, " ");
4641 if (b->ops != NULL && b->ops->print_one != NULL)
4643 /* Although the print_one can possibly print
4644 all locations, calling it here is not likely
4645 to get any nice result. So, make sure there's
4646 just one location. */
4647 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4648 b->ops->print_one (b, last_loc);
4654 internal_error (__FILE__, __LINE__,
4655 _("print_one_breakpoint: bp_none encountered\n"));
4659 case bp_hardware_watchpoint:
4660 case bp_read_watchpoint:
4661 case bp_access_watchpoint:
4662 /* Field 4, the address, is omitted (which makes the columns
4663 not line up too nicely with the headers, but the effect
4664 is relatively readable). */
4665 if (opts.addressprint)
4666 ui_out_field_skip (uiout, "addr");
4668 ui_out_field_string (uiout, "what", b->exp_string);
4672 case bp_hardware_breakpoint:
4676 case bp_longjmp_resume:
4677 case bp_step_resume:
4678 case bp_watchpoint_scope:
4680 case bp_std_terminate:
4681 case bp_shlib_event:
4682 case bp_thread_event:
4683 case bp_overlay_event:
4684 case bp_longjmp_master:
4685 case bp_std_terminate_master:
4687 case bp_fast_tracepoint:
4689 if (opts.addressprint)
4692 if (header_of_multiple)
4693 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4694 else if (b->loc == NULL || loc->shlib_disabled)
4695 ui_out_field_string (uiout, "addr", "<PENDING>");
4697 ui_out_field_core_addr (uiout, "addr",
4698 loc->gdbarch, loc->address);
4701 if (!header_of_multiple)
4702 print_breakpoint_location (b, loc, wrap_indent, stb);
4709 /* For backward compatibility, don't display inferiors unless there
4712 && !header_of_multiple
4714 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4715 && (number_of_program_spaces () > 1
4716 || number_of_inferiors () > 1)
4717 /* LOC is for existing B, it cannot be in moribund_locations and
4718 thus having NULL OWNER. */
4719 && loc->owner->type != bp_catchpoint)))
4721 struct inferior *inf;
4724 for (inf = inferior_list; inf != NULL; inf = inf->next)
4726 if (inf->pspace == loc->pspace)
4731 ui_out_text (uiout, " inf ");
4734 ui_out_text (uiout, ", ");
4735 ui_out_text (uiout, plongest (inf->num));
4740 if (!part_of_multiple)
4742 if (b->thread != -1)
4744 /* FIXME: This seems to be redundant and lost here; see the
4745 "stop only in" line a little further down. */
4746 ui_out_text (uiout, " thread ");
4747 ui_out_field_int (uiout, "thread", b->thread);
4749 else if (b->task != 0)
4751 ui_out_text (uiout, " task ");
4752 ui_out_field_int (uiout, "task", b->task);
4756 ui_out_text (uiout, "\n");
4758 if (part_of_multiple && frame_id_p (b->frame_id))
4761 ui_out_text (uiout, "\tstop only in stack frame at ");
4762 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4764 ui_out_field_core_addr (uiout, "frame",
4765 b->gdbarch, b->frame_id.stack_addr);
4766 ui_out_text (uiout, "\n");
4769 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4771 /* We do not print the condition for Ada exception catchpoints
4772 because the condition is an internal implementation detail
4773 that we do not want to expose to the user. */
4775 if (is_tracepoint (b))
4776 ui_out_text (uiout, "\ttrace only if ");
4778 ui_out_text (uiout, "\tstop only if ");
4779 ui_out_field_string (uiout, "cond", b->cond_string);
4780 ui_out_text (uiout, "\n");
4783 if (!part_of_multiple && b->thread != -1)
4785 /* FIXME should make an annotation for this */
4786 ui_out_text (uiout, "\tstop only in thread ");
4787 ui_out_field_int (uiout, "thread", b->thread);
4788 ui_out_text (uiout, "\n");
4791 if (!part_of_multiple && b->hit_count)
4793 /* FIXME should make an annotation for this */
4794 if (ep_is_catchpoint (b))
4795 ui_out_text (uiout, "\tcatchpoint");
4797 ui_out_text (uiout, "\tbreakpoint");
4798 ui_out_text (uiout, " already hit ");
4799 ui_out_field_int (uiout, "times", b->hit_count);
4800 if (b->hit_count == 1)
4801 ui_out_text (uiout, " time\n");
4803 ui_out_text (uiout, " times\n");
4806 /* Output the count also if it is zero, but only if this is
4807 mi. FIXME: Should have a better test for this. */
4808 if (ui_out_is_mi_like_p (uiout))
4809 if (!part_of_multiple && b->hit_count == 0)
4810 ui_out_field_int (uiout, "times", b->hit_count);
4812 if (!part_of_multiple && b->ignore_count)
4815 ui_out_text (uiout, "\tignore next ");
4816 ui_out_field_int (uiout, "ignore", b->ignore_count);
4817 ui_out_text (uiout, " hits\n");
4820 l = b->commands ? b->commands->commands : NULL;
4821 if (!part_of_multiple && l)
4823 struct cleanup *script_chain;
4826 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4827 print_command_lines (uiout, l, 4);
4828 do_cleanups (script_chain);
4831 if (!part_of_multiple && b->pass_count)
4833 annotate_field (10);
4834 ui_out_text (uiout, "\tpass count ");
4835 ui_out_field_int (uiout, "pass", b->pass_count);
4836 ui_out_text (uiout, " \n");
4839 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4842 ui_out_field_string (uiout, "original-location", b->addr_string);
4843 else if (b->exp_string)
4844 ui_out_field_string (uiout, "original-location", b->exp_string);
4847 do_cleanups (bkpt_chain);
4848 do_cleanups (old_chain);
4852 print_one_breakpoint (struct breakpoint *b,
4853 struct bp_location **last_loc, int print_address_bits,
4856 print_one_breakpoint_location (b, NULL, 0, last_loc,
4857 print_address_bits, allflag);
4859 /* If this breakpoint has custom print function,
4860 it's already printed. Otherwise, print individual
4861 locations, if any. */
4862 if (b->ops == NULL || b->ops->print_one == NULL)
4864 /* If breakpoint has a single location that is
4865 disabled, we print it as if it had
4866 several locations, since otherwise it's hard to
4867 represent "breakpoint enabled, location disabled"
4869 Note that while hardware watchpoints have
4870 several locations internally, that's no a property
4873 && !is_hardware_watchpoint (b)
4874 && (b->loc->next || !b->loc->enabled)
4875 && !ui_out_is_mi_like_p (uiout))
4877 struct bp_location *loc;
4879 for (loc = b->loc; loc; loc = loc->next, ++n)
4880 print_one_breakpoint_location (b, loc, n, last_loc,
4881 print_address_bits, allflag);
4887 breakpoint_address_bits (struct breakpoint *b)
4889 int print_address_bits = 0;
4890 struct bp_location *loc;
4892 for (loc = b->loc; loc; loc = loc->next)
4896 /* Software watchpoints that aren't watching memory don't have
4897 an address to print. */
4898 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4901 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4902 if (addr_bit > print_address_bits)
4903 print_address_bits = addr_bit;
4906 return print_address_bits;
4909 struct captured_breakpoint_query_args
4915 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4917 struct captured_breakpoint_query_args *args = data;
4918 struct breakpoint *b;
4919 struct bp_location *dummy_loc = NULL;
4923 if (args->bnum == b->number)
4925 int print_address_bits = breakpoint_address_bits (b);
4927 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4935 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4937 struct captured_breakpoint_query_args args;
4940 /* For the moment we don't trust print_one_breakpoint() to not throw
4942 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4943 error_message, RETURN_MASK_ALL) < 0)
4949 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4950 catchpoints, et.al.). */
4953 user_settable_breakpoint (const struct breakpoint *b)
4955 return (b->type == bp_breakpoint
4956 || b->type == bp_catchpoint
4957 || b->type == bp_hardware_breakpoint
4958 || is_tracepoint (b)
4959 || is_watchpoint (b));
4962 /* Print information on user settable breakpoint (watchpoint, etc)
4963 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4964 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4965 FILTER is non-NULL, call it on each breakpoint and only include the
4966 ones for which it returns non-zero. Return the total number of
4967 breakpoints listed. */
4970 breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
4972 struct breakpoint *b;
4973 struct bp_location *last_loc = NULL;
4974 int nr_printable_breakpoints;
4975 struct cleanup *bkpttbl_chain;
4976 struct value_print_options opts;
4977 int print_address_bits = 0;
4979 get_user_print_options (&opts);
4981 /* Compute the number of rows in the table, as well as the
4982 size required for address fields. */
4983 nr_printable_breakpoints = 0;
4986 || bnum == b->number)
4988 /* If we have a filter, only list the breakpoints it accepts. */
4989 if (filter && !filter (b))
4992 if (allflag || user_settable_breakpoint (b))
4994 int addr_bit = breakpoint_address_bits (b);
4995 if (addr_bit > print_address_bits)
4996 print_address_bits = addr_bit;
4998 nr_printable_breakpoints++;
5002 if (opts.addressprint)
5004 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
5008 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
5011 if (nr_printable_breakpoints > 0)
5012 annotate_breakpoints_headers ();
5013 if (nr_printable_breakpoints > 0)
5015 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5016 if (nr_printable_breakpoints > 0)
5018 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
5019 if (nr_printable_breakpoints > 0)
5021 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5022 if (nr_printable_breakpoints > 0)
5024 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5025 if (opts.addressprint)
5027 if (nr_printable_breakpoints > 0)
5029 if (print_address_bits <= 32)
5030 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
5032 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
5034 if (nr_printable_breakpoints > 0)
5036 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5037 ui_out_table_body (uiout);
5038 if (nr_printable_breakpoints > 0)
5039 annotate_breakpoints_table ();
5045 || bnum == b->number)
5047 /* If we have a filter, only list the breakpoints it accepts. */
5048 if (filter && !filter (b))
5051 /* We only print out user settable breakpoints unless the
5053 if (allflag || user_settable_breakpoint (b))
5054 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5058 do_cleanups (bkpttbl_chain);
5060 if (nr_printable_breakpoints == 0)
5062 /* If there's a filter, let the caller decide how to report empty list. */
5066 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5068 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
5074 if (last_loc && !server_command)
5075 set_next_address (last_loc->gdbarch, last_loc->address);
5078 /* FIXME? Should this be moved up so that it is only called when
5079 there have been breakpoints? */
5080 annotate_breakpoints_table_end ();
5082 return nr_printable_breakpoints;
5085 /* Display the value of default-collect in a way that is generally
5086 compatible with the breakpoint list. */
5089 default_collect_info (void)
5091 /* If it has no value (which is frequently the case), say nothing; a
5092 message like "No default-collect." gets in user's face when it's
5094 if (!*default_collect)
5097 /* The following phrase lines up nicely with per-tracepoint collect
5099 ui_out_text (uiout, "default collect ");
5100 ui_out_field_string (uiout, "default-collect", default_collect);
5101 ui_out_text (uiout, " \n");
5105 breakpoints_info (char *bnum_exp, int from_tty)
5110 bnum = parse_and_eval_long (bnum_exp);
5112 breakpoint_1 (bnum, 0, NULL);
5114 default_collect_info ();
5118 watchpoints_info (char *wpnum_exp, int from_tty)
5120 int wpnum = -1, num_printed;
5123 wpnum = parse_and_eval_long (wpnum_exp);
5125 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5127 if (num_printed == 0)
5130 ui_out_message (uiout, 0, "No watchpoints.\n");
5132 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5137 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5142 bnum = parse_and_eval_long (bnum_exp);
5144 breakpoint_1 (bnum, 1, NULL);
5146 default_collect_info ();
5150 breakpoint_has_pc (struct breakpoint *b,
5151 struct program_space *pspace,
5152 CORE_ADDR pc, struct obj_section *section)
5154 struct bp_location *bl = b->loc;
5156 for (; bl; bl = bl->next)
5158 if (bl->pspace == pspace
5159 && bl->address == pc
5160 && (!overlay_debugging || bl->section == section))
5166 /* Print a message describing any breakpoints set at PC. This
5167 concerns with logical breakpoints, so we match program spaces, not
5171 describe_other_breakpoints (struct gdbarch *gdbarch,
5172 struct program_space *pspace, CORE_ADDR pc,
5173 struct obj_section *section, int thread)
5176 struct breakpoint *b;
5179 others += breakpoint_has_pc (b, pspace, pc, section);
5183 printf_filtered (_("Note: breakpoint "));
5184 else /* if (others == ???) */
5185 printf_filtered (_("Note: breakpoints "));
5187 if (breakpoint_has_pc (b, pspace, pc, section))
5190 printf_filtered ("%d", b->number);
5191 if (b->thread == -1 && thread != -1)
5192 printf_filtered (" (all threads)");
5193 else if (b->thread != -1)
5194 printf_filtered (" (thread %d)", b->thread);
5195 printf_filtered ("%s%s ",
5196 ((b->enable_state == bp_disabled
5197 || b->enable_state == bp_call_disabled
5198 || b->enable_state == bp_startup_disabled)
5200 : b->enable_state == bp_permanent
5204 : ((others == 1) ? " and" : ""));
5206 printf_filtered (_("also set at pc "));
5207 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5208 printf_filtered (".\n");
5212 /* Set the default place to put a breakpoint
5213 for the `break' command with no arguments. */
5216 set_default_breakpoint (int valid, struct program_space *pspace,
5217 CORE_ADDR addr, struct symtab *symtab,
5220 default_breakpoint_valid = valid;
5221 default_breakpoint_pspace = pspace;
5222 default_breakpoint_address = addr;
5223 default_breakpoint_symtab = symtab;
5224 default_breakpoint_line = line;
5227 /* Return true iff it is meaningful to use the address member of
5228 BPT. For some breakpoint types, the address member is irrelevant
5229 and it makes no sense to attempt to compare it to other addresses
5230 (or use it for any other purpose either).
5232 More specifically, each of the following breakpoint types will always
5233 have a zero valued address and we don't want to mark breakpoints of any of
5234 these types to be a duplicate of an actual breakpoint at address zero:
5242 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5244 enum bptype type = bpt->type;
5246 return (type != bp_watchpoint && type != bp_catchpoint);
5249 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5250 true if LOC1 and LOC2 represent the same watchpoint location. */
5253 watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5255 /* Both of them must not be in moribund_locations. */
5256 gdb_assert (loc1->owner != NULL);
5257 gdb_assert (loc2->owner != NULL);
5259 /* Note that this checks the owner's type, not the location's. In
5260 case the target does not support read watchpoints, but does
5261 support access watchpoints, we'll have bp_read_watchpoint
5262 watchpoints with hw_access locations. Those should be considered
5263 duplicates of hw_read locations. The hw_read locations will
5264 become hw_access locations later. */
5265 return (loc1->owner->type == loc2->owner->type
5266 && loc1->pspace->aspace == loc2->pspace->aspace
5267 && loc1->address == loc2->address
5268 && loc1->length == loc2->length);
5271 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5272 same breakpoint location. In most targets, this can only be true
5273 if ASPACE1 matches ASPACE2. On targets that have global
5274 breakpoints, the address space doesn't really matter. */
5277 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5278 struct address_space *aspace2, CORE_ADDR addr2)
5280 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5281 || aspace1 == aspace2)
5285 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5286 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5287 represent the same location. */
5290 breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5292 int hw_point1, hw_point2;
5294 /* Both of them must not be in moribund_locations. */
5295 gdb_assert (loc1->owner != NULL);
5296 gdb_assert (loc2->owner != NULL);
5298 hw_point1 = is_hardware_watchpoint (loc1->owner);
5299 hw_point2 = is_hardware_watchpoint (loc2->owner);
5301 if (hw_point1 != hw_point2)
5304 return watchpoint_locations_match (loc1, loc2);
5306 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5307 loc2->pspace->aspace, loc2->address);
5311 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5312 int bnum, int have_bnum)
5317 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5318 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5320 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5321 bnum, astr1, astr2);
5323 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5326 /* Adjust a breakpoint's address to account for architectural constraints
5327 on breakpoint placement. Return the adjusted address. Note: Very
5328 few targets require this kind of adjustment. For most targets,
5329 this function is simply the identity function. */
5332 adjust_breakpoint_address (struct gdbarch *gdbarch,
5333 CORE_ADDR bpaddr, enum bptype bptype)
5335 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5337 /* Very few targets need any kind of breakpoint adjustment. */
5340 else if (bptype == bp_watchpoint
5341 || bptype == bp_hardware_watchpoint
5342 || bptype == bp_read_watchpoint
5343 || bptype == bp_access_watchpoint
5344 || bptype == bp_catchpoint)
5346 /* Watchpoints and the various bp_catch_* eventpoints should not
5347 have their addresses modified. */
5352 CORE_ADDR adjusted_bpaddr;
5354 /* Some targets have architectural constraints on the placement
5355 of breakpoint instructions. Obtain the adjusted address. */
5356 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5358 /* An adjusted breakpoint address can significantly alter
5359 a user's expectations. Print a warning if an adjustment
5361 if (adjusted_bpaddr != bpaddr)
5362 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5364 return adjusted_bpaddr;
5368 /* Allocate a struct bp_location. */
5370 static struct bp_location *
5371 allocate_bp_location (struct breakpoint *bpt)
5373 struct bp_location *loc;
5375 loc = xmalloc (sizeof (struct bp_location));
5376 memset (loc, 0, sizeof (*loc));
5380 loc->shlib_disabled = 0;
5389 case bp_longjmp_resume:
5390 case bp_step_resume:
5391 case bp_watchpoint_scope:
5393 case bp_std_terminate:
5394 case bp_shlib_event:
5395 case bp_thread_event:
5396 case bp_overlay_event:
5398 case bp_longjmp_master:
5399 case bp_std_terminate_master:
5400 loc->loc_type = bp_loc_software_breakpoint;
5402 case bp_hardware_breakpoint:
5403 loc->loc_type = bp_loc_hardware_breakpoint;
5405 case bp_hardware_watchpoint:
5406 case bp_read_watchpoint:
5407 case bp_access_watchpoint:
5408 loc->loc_type = bp_loc_hardware_watchpoint;
5413 case bp_fast_tracepoint:
5414 loc->loc_type = bp_loc_other;
5417 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5423 static void free_bp_location (struct bp_location *loc)
5425 /* Be sure no bpstat's are pointing at it after it's been freed. */
5426 /* FIXME, how can we find all bpstat's?
5427 We just check stop_bpstat for now. Note that we cannot just
5428 remove bpstats pointing at bpt from the stop_bpstat list
5429 entirely, as breakpoint commands are associated with the bpstat;
5430 if we remove it here, then the later call to
5431 bpstat_do_actions (&stop_bpstat);
5432 in event-top.c won't do anything, and temporary breakpoints
5433 with commands won't work. */
5435 iterate_over_threads (bpstat_remove_bp_location_callback, loc);
5440 if (loc->function_name)
5441 xfree (loc->function_name);
5446 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5447 that has type BPTYPE and has no locations as yet. */
5448 /* This function is used in gdbtk sources and thus can not be made static. */
5450 static struct breakpoint *
5451 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5454 struct breakpoint *b, *b1;
5456 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5457 memset (b, 0, sizeof (*b));
5460 b->gdbarch = gdbarch;
5461 b->language = current_language->la_language;
5462 b->input_radix = input_radix;
5464 b->enable_state = bp_enabled;
5467 b->ignore_count = 0;
5469 b->frame_id = null_frame_id;
5470 b->forked_inferior_pid = null_ptid;
5471 b->exec_pathname = NULL;
5472 b->syscalls_to_be_caught = NULL;
5474 b->condition_not_parsed = 0;
5476 /* Add this breakpoint to the end of the chain
5477 so that a list of breakpoints will come out in order
5478 of increasing numbers. */
5480 b1 = breakpoint_chain;
5482 breakpoint_chain = b;
5492 /* Initialize loc->function_name. */
5494 set_breakpoint_location_function (struct bp_location *loc)
5496 gdb_assert (loc->owner != NULL);
5498 if (loc->owner->type == bp_breakpoint
5499 || loc->owner->type == bp_hardware_breakpoint
5500 || is_tracepoint (loc->owner))
5502 find_pc_partial_function (loc->address, &(loc->function_name),
5504 if (loc->function_name)
5505 loc->function_name = xstrdup (loc->function_name);
5509 /* Attempt to determine architecture of location identified by SAL. */
5510 static struct gdbarch *
5511 get_sal_arch (struct symtab_and_line sal)
5514 return get_objfile_arch (sal.section->objfile);
5516 return get_objfile_arch (sal.symtab->objfile);
5521 /* set_raw_breakpoint is a low level routine for allocating and
5522 partially initializing a breakpoint of type BPTYPE. The newly
5523 created breakpoint's address, section, source file name, and line
5524 number are provided by SAL. The newly created and partially
5525 initialized breakpoint is added to the breakpoint chain and
5526 is also returned as the value of this function.
5528 It is expected that the caller will complete the initialization of
5529 the newly created breakpoint struct as well as output any status
5530 information regarding the creation of a new breakpoint. In
5531 particular, set_raw_breakpoint does NOT set the breakpoint
5532 number! Care should be taken to not allow an error to occur
5533 prior to completing the initialization of the breakpoint. If this
5534 should happen, a bogus breakpoint will be left on the chain. */
5537 set_raw_breakpoint (struct gdbarch *gdbarch,
5538 struct symtab_and_line sal, enum bptype bptype)
5540 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
5541 CORE_ADDR adjusted_address;
5542 struct gdbarch *loc_gdbarch;
5544 loc_gdbarch = get_sal_arch (sal);
5546 loc_gdbarch = b->gdbarch;
5548 if (bptype != bp_catchpoint)
5549 gdb_assert (sal.pspace != NULL);
5551 /* Adjust the breakpoint's address prior to allocating a location.
5552 Once we call allocate_bp_location(), that mostly uninitialized
5553 location will be placed on the location chain. Adjustment of the
5554 breakpoint may cause target_read_memory() to be called and we do
5555 not want its scan of the location chain to find a breakpoint and
5556 location that's only been partially initialized. */
5557 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
5559 b->loc = allocate_bp_location (b);
5560 b->loc->gdbarch = loc_gdbarch;
5561 b->loc->requested_address = sal.pc;
5562 b->loc->address = adjusted_address;
5563 b->loc->pspace = sal.pspace;
5565 /* Store the program space that was used to set the breakpoint, for
5566 breakpoint resetting. */
5567 b->pspace = sal.pspace;
5569 if (sal.symtab == NULL)
5570 b->source_file = NULL;
5572 b->source_file = xstrdup (sal.symtab->filename);
5573 b->loc->section = sal.section;
5574 b->line_number = sal.line;
5576 set_breakpoint_location_function (b->loc);
5578 breakpoints_changed ();
5584 /* Note that the breakpoint object B describes a permanent breakpoint
5585 instruction, hard-wired into the inferior's code. */
5587 make_breakpoint_permanent (struct breakpoint *b)
5589 struct bp_location *bl;
5591 b->enable_state = bp_permanent;
5593 /* By definition, permanent breakpoints are already present in the code.
5594 Mark all locations as inserted. For now, make_breakpoint_permanent
5595 is called in just one place, so it's hard to say if it's reasonable
5596 to have permanent breakpoint with multiple locations or not,
5597 but it's easy to implmement. */
5598 for (bl = b->loc; bl; bl = bl->next)
5602 /* Call this routine when stepping and nexting to enable a breakpoint
5603 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5604 set_longjmp_resume_breakpoint() to figure out where we are going. */
5607 set_longjmp_breakpoint (int thread)
5609 struct breakpoint *b, *temp;
5611 /* To avoid having to rescan all objfile symbols at every step,
5612 we maintain a list of continually-inserted but always disabled
5613 longjmp "master" breakpoints. Here, we simply create momentary
5614 clones of those and enable them for the requested thread. */
5615 ALL_BREAKPOINTS_SAFE (b, temp)
5616 if (b->pspace == current_program_space
5617 && b->type == bp_longjmp_master)
5619 struct breakpoint *clone = clone_momentary_breakpoint (b);
5621 clone->type = bp_longjmp;
5622 clone->thread = thread;
5626 /* Delete all longjmp breakpoints from THREAD. */
5628 delete_longjmp_breakpoint (int thread)
5630 struct breakpoint *b, *temp;
5632 ALL_BREAKPOINTS_SAFE (b, temp)
5633 if (b->type == bp_longjmp)
5635 if (b->thread == thread)
5636 delete_breakpoint (b);
5641 enable_overlay_breakpoints (void)
5643 struct breakpoint *b;
5646 if (b->type == bp_overlay_event)
5648 b->enable_state = bp_enabled;
5649 update_global_location_list (1);
5650 overlay_events_enabled = 1;
5655 disable_overlay_breakpoints (void)
5657 struct breakpoint *b;
5660 if (b->type == bp_overlay_event)
5662 b->enable_state = bp_disabled;
5663 update_global_location_list (0);
5664 overlay_events_enabled = 0;
5668 /* Set an active std::terminate breakpoint for each std::terminate
5669 master breakpoint. */
5671 set_std_terminate_breakpoint (void)
5673 struct breakpoint *b, *temp;
5675 ALL_BREAKPOINTS_SAFE (b, temp)
5676 if (b->pspace == current_program_space
5677 && b->type == bp_std_terminate_master)
5679 struct breakpoint *clone = clone_momentary_breakpoint (b);
5680 clone->type = bp_std_terminate;
5684 /* Delete all the std::terminate breakpoints. */
5686 delete_std_terminate_breakpoint (void)
5688 struct breakpoint *b, *temp;
5690 ALL_BREAKPOINTS_SAFE (b, temp)
5691 if (b->type == bp_std_terminate)
5692 delete_breakpoint (b);
5696 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5698 struct breakpoint *b;
5700 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5702 b->enable_state = bp_enabled;
5703 /* addr_string has to be used or breakpoint_re_set will delete me. */
5705 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5707 update_global_location_list_nothrow (1);
5713 remove_thread_event_breakpoints (void)
5715 struct breakpoint *b, *temp;
5717 ALL_BREAKPOINTS_SAFE (b, temp)
5718 if (b->type == bp_thread_event
5719 && b->loc->pspace == current_program_space)
5720 delete_breakpoint (b);
5723 struct captured_parse_breakpoint_args
5726 struct symtabs_and_lines *sals_p;
5727 char ***addr_string_p;
5731 struct lang_and_radix
5737 /* Create a breakpoint for JIT code registration and unregistration. */
5740 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5742 struct breakpoint *b;
5744 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5745 update_global_location_list_nothrow (1);
5750 remove_solib_event_breakpoints (void)
5752 struct breakpoint *b, *temp;
5754 ALL_BREAKPOINTS_SAFE (b, temp)
5755 if (b->type == bp_shlib_event
5756 && b->loc->pspace == current_program_space)
5757 delete_breakpoint (b);
5761 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5763 struct breakpoint *b;
5765 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5766 update_global_location_list_nothrow (1);
5770 /* Disable any breakpoints that are on code in shared libraries. Only
5771 apply to enabled breakpoints, disabled ones can just stay disabled. */
5774 disable_breakpoints_in_shlibs (void)
5776 struct bp_location *loc, **locp_tmp;
5778 ALL_BP_LOCATIONS (loc, locp_tmp)
5780 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5781 struct breakpoint *b = loc->owner;
5783 /* We apply the check to all breakpoints, including disabled
5784 for those with loc->duplicate set. This is so that when breakpoint
5785 becomes enabled, or the duplicate is removed, gdb will try to insert
5786 all breakpoints. If we don't set shlib_disabled here, we'll try
5787 to insert those breakpoints and fail. */
5788 if (((b->type == bp_breakpoint)
5789 || (b->type == bp_jit_event)
5790 || (b->type == bp_hardware_breakpoint)
5791 || (is_tracepoint (b)))
5792 && loc->pspace == current_program_space
5793 && !loc->shlib_disabled
5795 && PC_SOLIB (loc->address)
5797 && solib_name_from_address (loc->pspace, loc->address)
5801 loc->shlib_disabled = 1;
5806 /* Disable any breakpoints that are in in an unloaded shared library. Only
5807 apply to enabled breakpoints, disabled ones can just stay disabled. */
5810 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5812 struct bp_location *loc, **locp_tmp;
5813 int disabled_shlib_breaks = 0;
5815 /* SunOS a.out shared libraries are always mapped, so do not
5816 disable breakpoints; they will only be reported as unloaded
5817 through clear_solib when GDB discards its shared library
5818 list. See clear_solib for more information. */
5819 if (exec_bfd != NULL
5820 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5823 ALL_BP_LOCATIONS (loc, locp_tmp)
5825 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5826 struct breakpoint *b = loc->owner;
5828 if ((loc->loc_type == bp_loc_hardware_breakpoint
5829 || loc->loc_type == bp_loc_software_breakpoint)
5830 && solib->pspace == loc->pspace
5831 && !loc->shlib_disabled
5832 && (b->type == bp_breakpoint
5833 || b->type == bp_jit_event
5834 || b->type == bp_hardware_breakpoint)
5835 && solib_contains_address_p (solib, loc->address))
5837 loc->shlib_disabled = 1;
5838 /* At this point, we cannot rely on remove_breakpoint
5839 succeeding so we must mark the breakpoint as not inserted
5840 to prevent future errors occurring in remove_breakpoints. */
5842 if (!disabled_shlib_breaks)
5844 target_terminal_ours_for_output ();
5845 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5848 disabled_shlib_breaks = 1;
5853 /* FORK & VFORK catchpoints. */
5855 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5858 insert_catch_fork (struct breakpoint *b)
5860 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5863 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5866 remove_catch_fork (struct breakpoint *b)
5868 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5871 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5875 breakpoint_hit_catch_fork (struct breakpoint *b)
5877 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5880 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5882 static enum print_stop_action
5883 print_it_catch_fork (struct breakpoint *b)
5885 annotate_catchpoint (b->number);
5886 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5887 b->number, ptid_get_pid (b->forked_inferior_pid));
5888 return PRINT_SRC_AND_LOC;
5891 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5894 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5896 struct value_print_options opts;
5898 get_user_print_options (&opts);
5900 /* Field 4, the address, is omitted (which makes the columns
5901 not line up too nicely with the headers, but the effect
5902 is relatively readable). */
5903 if (opts.addressprint)
5904 ui_out_field_skip (uiout, "addr");
5906 ui_out_text (uiout, "fork");
5907 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5909 ui_out_text (uiout, ", process ");
5910 ui_out_field_int (uiout, "what",
5911 ptid_get_pid (b->forked_inferior_pid));
5912 ui_out_spaces (uiout, 1);
5916 /* Implement the "print_mention" breakpoint_ops method for fork
5920 print_mention_catch_fork (struct breakpoint *b)
5922 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5925 /* Implement the "print_recreate" breakpoint_ops method for fork
5929 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
5931 fprintf_unfiltered (fp, "catch fork");
5934 /* The breakpoint_ops structure to be used in fork catchpoints. */
5936 static struct breakpoint_ops catch_fork_breakpoint_ops =
5940 breakpoint_hit_catch_fork,
5941 print_it_catch_fork,
5942 print_one_catch_fork,
5943 print_mention_catch_fork,
5944 print_recreate_catch_fork
5947 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5950 insert_catch_vfork (struct breakpoint *b)
5952 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
5955 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5958 remove_catch_vfork (struct breakpoint *b)
5960 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
5963 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5967 breakpoint_hit_catch_vfork (struct breakpoint *b)
5969 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
5972 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5974 static enum print_stop_action
5975 print_it_catch_vfork (struct breakpoint *b)
5977 annotate_catchpoint (b->number);
5978 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5979 b->number, ptid_get_pid (b->forked_inferior_pid));
5980 return PRINT_SRC_AND_LOC;
5983 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5986 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
5988 struct value_print_options opts;
5990 get_user_print_options (&opts);
5991 /* Field 4, the address, is omitted (which makes the columns
5992 not line up too nicely with the headers, but the effect
5993 is relatively readable). */
5994 if (opts.addressprint)
5995 ui_out_field_skip (uiout, "addr");
5997 ui_out_text (uiout, "vfork");
5998 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
6000 ui_out_text (uiout, ", process ");
6001 ui_out_field_int (uiout, "what",
6002 ptid_get_pid (b->forked_inferior_pid));
6003 ui_out_spaces (uiout, 1);
6007 /* Implement the "print_mention" breakpoint_ops method for vfork
6011 print_mention_catch_vfork (struct breakpoint *b)
6013 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6016 /* Implement the "print_recreate" breakpoint_ops method for vfork
6020 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6022 fprintf_unfiltered (fp, "catch vfork");
6025 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6027 static struct breakpoint_ops catch_vfork_breakpoint_ops =
6031 breakpoint_hit_catch_vfork,
6032 print_it_catch_vfork,
6033 print_one_catch_vfork,
6034 print_mention_catch_vfork,
6035 print_recreate_catch_vfork
6038 /* Implement the "insert" breakpoint_ops method for syscall
6042 insert_catch_syscall (struct breakpoint *b)
6044 struct inferior *inf = current_inferior ();
6046 ++inf->total_syscalls_count;
6047 if (!b->syscalls_to_be_caught)
6048 ++inf->any_syscall_count;
6054 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6059 if (iter >= VEC_length (int, inf->syscalls_counts))
6061 int old_size = VEC_length (int, inf->syscalls_counts);
6062 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
6064 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6065 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6067 memset ((void *) vec_addr, 0,
6068 (iter + 1 - old_size) * sizeof (int));
6070 elem = VEC_index (int, inf->syscalls_counts, iter);
6071 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6075 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6076 inf->total_syscalls_count != 0,
6077 inf->any_syscall_count,
6078 VEC_length (int, inf->syscalls_counts),
6079 VEC_address (int, inf->syscalls_counts));
6082 /* Implement the "remove" breakpoint_ops method for syscall
6086 remove_catch_syscall (struct breakpoint *b)
6088 struct inferior *inf = current_inferior ();
6090 --inf->total_syscalls_count;
6091 if (!b->syscalls_to_be_caught)
6092 --inf->any_syscall_count;
6098 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6102 if (iter >= VEC_length (int, inf->syscalls_counts))
6103 /* Shouldn't happen. */
6105 elem = VEC_index (int, inf->syscalls_counts, iter);
6106 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6110 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6111 inf->total_syscalls_count != 0,
6112 inf->any_syscall_count,
6113 VEC_length (int, inf->syscalls_counts),
6114 VEC_address (int, inf->syscalls_counts));
6117 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6121 breakpoint_hit_catch_syscall (struct breakpoint *b)
6123 /* We must check if we are catching specific syscalls in this breakpoint.
6124 If we are, then we must guarantee that the called syscall is the same
6125 syscall we are catching. */
6126 int syscall_number = 0;
6128 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6131 /* Now, checking if the syscall is the same. */
6132 if (b->syscalls_to_be_caught)
6137 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6139 if (syscall_number == iter)
6149 /* Implement the "print_it" breakpoint_ops method for syscall
6152 static enum print_stop_action
6153 print_it_catch_syscall (struct breakpoint *b)
6155 /* These are needed because we want to know in which state a
6156 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6157 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6158 must print "called syscall" or "returned from syscall". */
6160 struct target_waitstatus last;
6162 struct cleanup *old_chain;
6165 get_last_target_status (&ptid, &last);
6167 get_syscall_by_number (last.value.syscall_number, &s);
6169 annotate_catchpoint (b->number);
6172 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6174 syscall_id = xstrprintf ("'%s'", s.name);
6176 old_chain = make_cleanup (xfree, syscall_id);
6178 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6179 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6180 b->number, syscall_id);
6181 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6182 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6183 b->number, syscall_id);
6185 do_cleanups (old_chain);
6187 return PRINT_SRC_AND_LOC;
6190 /* Implement the "print_one" breakpoint_ops method for syscall
6194 print_one_catch_syscall (struct breakpoint *b,
6195 struct bp_location **last_loc)
6197 struct value_print_options opts;
6199 get_user_print_options (&opts);
6200 /* Field 4, the address, is omitted (which makes the columns
6201 not line up too nicely with the headers, but the effect
6202 is relatively readable). */
6203 if (opts.addressprint)
6204 ui_out_field_skip (uiout, "addr");
6207 if (b->syscalls_to_be_caught
6208 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6209 ui_out_text (uiout, "syscalls \"");
6211 ui_out_text (uiout, "syscall \"");
6213 if (b->syscalls_to_be_caught)
6216 char *text = xstrprintf ("%s", "");
6219 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6224 get_syscall_by_number (iter, &s);
6227 text = xstrprintf ("%s%s, ", text, s.name);
6229 text = xstrprintf ("%s%d, ", text, iter);
6231 /* We have to xfree the last 'text' (now stored at 'x')
6232 because xstrprintf dinamically allocates new space for it
6236 /* Remove the last comma. */
6237 text[strlen (text) - 2] = '\0';
6238 ui_out_field_string (uiout, "what", text);
6241 ui_out_field_string (uiout, "what", "<any syscall>");
6242 ui_out_text (uiout, "\" ");
6245 /* Implement the "print_mention" breakpoint_ops method for syscall
6249 print_mention_catch_syscall (struct breakpoint *b)
6251 if (b->syscalls_to_be_caught)
6255 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6256 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6258 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6261 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6265 get_syscall_by_number (iter, &s);
6268 printf_filtered (" '%s' [%d]", s.name, s.number);
6270 printf_filtered (" %d", s.number);
6272 printf_filtered (")");
6275 printf_filtered (_("Catchpoint %d (any syscall)"),
6279 /* Implement the "print_recreate" breakpoint_ops method for syscall
6283 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6285 fprintf_unfiltered (fp, "catch syscall");
6287 if (b->syscalls_to_be_caught)
6292 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6297 get_syscall_by_number (iter, &s);
6299 fprintf_unfiltered (fp, " %s", s.name);
6301 fprintf_unfiltered (fp, " %d", s.number);
6306 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6308 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6310 insert_catch_syscall,
6311 remove_catch_syscall,
6312 breakpoint_hit_catch_syscall,
6313 print_it_catch_syscall,
6314 print_one_catch_syscall,
6315 print_mention_catch_syscall,
6316 print_recreate_catch_syscall
6319 /* Returns non-zero if 'b' is a syscall catchpoint. */
6322 syscall_catchpoint_p (struct breakpoint *b)
6324 return (b->ops == &catch_syscall_breakpoint_ops);
6327 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6328 but does NOT mention it nor update the global location list.
6329 This is useful if you need to fill more fields in the
6330 struct breakpoint before calling mention.
6332 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6333 If COND_STRING is not NULL, then store it in the breakpoint.
6334 OPS, if not NULL, is the breakpoint_ops structure associated
6335 to the catchpoint. */
6337 static struct breakpoint *
6338 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6340 struct breakpoint_ops *ops)
6342 struct symtab_and_line sal;
6343 struct breakpoint *b;
6346 sal.pspace = current_program_space;
6348 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6349 set_breakpoint_count (breakpoint_count + 1);
6350 b->number = breakpoint_count;
6352 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6354 b->addr_string = NULL;
6355 b->enable_state = bp_enabled;
6356 b->disposition = tempflag ? disp_del : disp_donttouch;
6362 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6364 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6365 If COND_STRING is not NULL, then store it in the breakpoint.
6366 OPS, if not NULL, is the breakpoint_ops structure associated
6367 to the catchpoint. */
6369 static struct breakpoint *
6370 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6371 char *cond_string, struct breakpoint_ops *ops)
6373 struct breakpoint *b =
6374 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6377 update_global_location_list (1);
6383 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6384 int tempflag, char *cond_string,
6385 struct breakpoint_ops *ops)
6387 struct breakpoint *b
6388 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6390 /* FIXME: We should put this information in a breakpoint private data
6392 b->forked_inferior_pid = null_ptid;
6395 /* Exec catchpoints. */
6398 insert_catch_exec (struct breakpoint *b)
6400 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6404 remove_catch_exec (struct breakpoint *b)
6406 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6410 breakpoint_hit_catch_exec (struct breakpoint *b)
6412 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6415 static enum print_stop_action
6416 print_it_catch_exec (struct breakpoint *b)
6418 annotate_catchpoint (b->number);
6419 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6421 return PRINT_SRC_AND_LOC;
6425 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6427 struct value_print_options opts;
6429 get_user_print_options (&opts);
6431 /* Field 4, the address, is omitted (which makes the columns
6432 not line up too nicely with the headers, but the effect
6433 is relatively readable). */
6434 if (opts.addressprint)
6435 ui_out_field_skip (uiout, "addr");
6437 ui_out_text (uiout, "exec");
6438 if (b->exec_pathname != NULL)
6440 ui_out_text (uiout, ", program \"");
6441 ui_out_field_string (uiout, "what", b->exec_pathname);
6442 ui_out_text (uiout, "\" ");
6447 print_mention_catch_exec (struct breakpoint *b)
6449 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6452 /* Implement the "print_recreate" breakpoint_ops method for exec
6456 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6458 fprintf_unfiltered (fp, "catch exec");
6461 static struct breakpoint_ops catch_exec_breakpoint_ops =
6465 breakpoint_hit_catch_exec,
6466 print_it_catch_exec,
6467 print_one_catch_exec,
6468 print_mention_catch_exec,
6469 print_recreate_catch_exec
6473 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6474 struct breakpoint_ops *ops)
6476 struct gdbarch *gdbarch = get_current_arch ();
6477 struct breakpoint *b =
6478 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6480 b->syscalls_to_be_caught = filter;
6482 /* Now, we have to mention the breakpoint and update the global
6485 update_global_location_list (1);
6489 hw_breakpoint_used_count (void)
6491 struct breakpoint *b;
6496 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6504 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6506 struct breakpoint *b;
6509 *other_type_used = 0;
6512 if (breakpoint_enabled (b))
6514 if (b->type == type)
6516 else if (is_hardware_watchpoint (b))
6517 *other_type_used = 1;
6524 disable_watchpoints_before_interactive_call_start (void)
6526 struct breakpoint *b;
6530 if (is_watchpoint (b) && breakpoint_enabled (b))
6532 b->enable_state = bp_call_disabled;
6533 update_global_location_list (0);
6539 enable_watchpoints_after_interactive_call_stop (void)
6541 struct breakpoint *b;
6545 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6547 b->enable_state = bp_enabled;
6548 update_global_location_list (1);
6554 disable_breakpoints_before_startup (void)
6556 struct breakpoint *b;
6561 if (b->pspace != current_program_space)
6564 if ((b->type == bp_breakpoint
6565 || b->type == bp_hardware_breakpoint)
6566 && breakpoint_enabled (b))
6568 b->enable_state = bp_startup_disabled;
6574 update_global_location_list (0);
6576 current_program_space->executing_startup = 1;
6580 enable_breakpoints_after_startup (void)
6582 struct breakpoint *b;
6585 current_program_space->executing_startup = 0;
6589 if (b->pspace != current_program_space)
6592 if ((b->type == bp_breakpoint
6593 || b->type == bp_hardware_breakpoint)
6594 && b->enable_state == bp_startup_disabled)
6596 b->enable_state = bp_enabled;
6602 breakpoint_re_set ();
6606 /* Set a breakpoint that will evaporate an end of command
6607 at address specified by SAL.
6608 Restrict it to frame FRAME if FRAME is nonzero. */
6611 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6612 struct frame_id frame_id, enum bptype type)
6614 struct breakpoint *b;
6616 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6618 gdb_assert (!frame_id_inlined_p (frame_id));
6620 b = set_raw_breakpoint (gdbarch, sal, type);
6621 b->enable_state = bp_enabled;
6622 b->disposition = disp_donttouch;
6623 b->frame_id = frame_id;
6625 /* If we're debugging a multi-threaded program, then we
6626 want momentary breakpoints to be active in only a
6627 single thread of control. */
6628 if (in_thread_list (inferior_ptid))
6629 b->thread = pid_to_thread_id (inferior_ptid);
6631 update_global_location_list_nothrow (1);
6636 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6640 clone_momentary_breakpoint (struct breakpoint *orig)
6642 struct breakpoint *copy;
6644 /* If there's nothing to clone, then return nothing. */
6648 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6649 copy->loc = allocate_bp_location (copy);
6650 set_breakpoint_location_function (copy->loc);
6652 copy->loc->gdbarch = orig->loc->gdbarch;
6653 copy->loc->requested_address = orig->loc->requested_address;
6654 copy->loc->address = orig->loc->address;
6655 copy->loc->section = orig->loc->section;
6656 copy->loc->pspace = orig->loc->pspace;
6658 if (orig->source_file == NULL)
6659 copy->source_file = NULL;
6661 copy->source_file = xstrdup (orig->source_file);
6663 copy->line_number = orig->line_number;
6664 copy->frame_id = orig->frame_id;
6665 copy->thread = orig->thread;
6666 copy->pspace = orig->pspace;
6668 copy->enable_state = bp_enabled;
6669 copy->disposition = disp_donttouch;
6670 copy->number = internal_breakpoint_number--;
6672 update_global_location_list_nothrow (0);
6677 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6680 struct symtab_and_line sal;
6682 sal = find_pc_line (pc, 0);
6684 sal.section = find_pc_overlay (pc);
6685 sal.explicit_pc = 1;
6687 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6691 /* Tell the user we have just set a breakpoint B. */
6694 mention (struct breakpoint *b)
6697 struct cleanup *ui_out_chain;
6698 struct value_print_options opts;
6700 get_user_print_options (&opts);
6702 /* FIXME: This is misplaced; mention() is called by things (like
6703 hitting a watchpoint) other than breakpoint creation. It should
6704 be possible to clean this up and at the same time replace the
6705 random calls to breakpoint_changed with this hook. */
6706 observer_notify_breakpoint_created (b->number);
6708 if (b->ops != NULL && b->ops->print_mention != NULL)
6709 b->ops->print_mention (b);
6714 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
6717 ui_out_text (uiout, "Watchpoint ");
6718 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6719 ui_out_field_int (uiout, "number", b->number);
6720 ui_out_text (uiout, ": ");
6721 ui_out_field_string (uiout, "exp", b->exp_string);
6722 do_cleanups (ui_out_chain);
6724 case bp_hardware_watchpoint:
6725 ui_out_text (uiout, "Hardware watchpoint ");
6726 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6727 ui_out_field_int (uiout, "number", b->number);
6728 ui_out_text (uiout, ": ");
6729 ui_out_field_string (uiout, "exp", b->exp_string);
6730 do_cleanups (ui_out_chain);
6732 case bp_read_watchpoint:
6733 ui_out_text (uiout, "Hardware read watchpoint ");
6734 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6735 ui_out_field_int (uiout, "number", b->number);
6736 ui_out_text (uiout, ": ");
6737 ui_out_field_string (uiout, "exp", b->exp_string);
6738 do_cleanups (ui_out_chain);
6740 case bp_access_watchpoint:
6741 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6742 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6743 ui_out_field_int (uiout, "number", b->number);
6744 ui_out_text (uiout, ": ");
6745 ui_out_field_string (uiout, "exp", b->exp_string);
6746 do_cleanups (ui_out_chain);
6749 if (ui_out_is_mi_like_p (uiout))
6754 if (b->disposition == disp_del)
6755 printf_filtered (_("Temporary breakpoint"));
6757 printf_filtered (_("Breakpoint"));
6758 printf_filtered (_(" %d"), b->number);
6761 case bp_hardware_breakpoint:
6762 if (ui_out_is_mi_like_p (uiout))
6767 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6771 if (ui_out_is_mi_like_p (uiout))
6776 printf_filtered (_("Tracepoint"));
6777 printf_filtered (_(" %d"), b->number);
6780 case bp_fast_tracepoint:
6781 if (ui_out_is_mi_like_p (uiout))
6786 printf_filtered (_("Fast tracepoint"));
6787 printf_filtered (_(" %d"), b->number);
6794 case bp_longjmp_resume:
6795 case bp_step_resume:
6797 case bp_std_terminate:
6798 case bp_watchpoint_scope:
6799 case bp_shlib_event:
6800 case bp_thread_event:
6801 case bp_overlay_event:
6803 case bp_longjmp_master:
6804 case bp_std_terminate_master:
6810 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6814 printf_filtered (_(" (%s) pending."), b->addr_string);
6818 if (opts.addressprint || b->source_file == NULL)
6820 printf_filtered (" at ");
6821 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
6825 printf_filtered (": file %s, line %d.",
6826 b->source_file, b->line_number);
6830 struct bp_location *loc = b->loc;
6832 for (; loc; loc = loc->next)
6834 printf_filtered (" (%d locations)", n);
6839 if (ui_out_is_mi_like_p (uiout))
6841 printf_filtered ("\n");
6845 static struct bp_location *
6846 add_location_to_breakpoint (struct breakpoint *b,
6847 const struct symtab_and_line *sal)
6849 struct bp_location *loc, **tmp;
6851 loc = allocate_bp_location (b);
6852 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
6855 loc->gdbarch = get_sal_arch (*sal);
6857 loc->gdbarch = b->gdbarch;
6858 loc->requested_address = sal->pc;
6859 loc->address = adjust_breakpoint_address (loc->gdbarch,
6860 loc->requested_address, b->type);
6861 loc->pspace = sal->pspace;
6862 gdb_assert (loc->pspace != NULL);
6863 loc->section = sal->section;
6865 set_breakpoint_location_function (loc);
6870 /* Return 1 if LOC is pointing to a permanent breakpoint,
6871 return 0 otherwise. */
6874 bp_loc_is_permanent (struct bp_location *loc)
6878 const gdb_byte *brk;
6879 gdb_byte *target_mem;
6880 struct cleanup *cleanup;
6883 gdb_assert (loc != NULL);
6885 addr = loc->address;
6886 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6888 /* Software breakpoints unsupported? */
6892 target_mem = alloca (len);
6894 /* Enable the automatic memory restoration from breakpoints while
6895 we read the memory. Otherwise we could say about our temporary
6896 breakpoints they are permanent. */
6897 cleanup = save_current_space_and_thread ();
6899 switch_to_program_space_and_thread (loc->pspace);
6900 make_show_memory_breakpoints_cleanup (0);
6902 if (target_read_memory (loc->address, target_mem, len) == 0
6903 && memcmp (target_mem, brk, len) == 0)
6906 do_cleanups (cleanup);
6913 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6914 as textual description of the location, and COND_STRING
6915 as condition expression. */
6918 create_breakpoint_sal (struct gdbarch *gdbarch,
6919 struct symtabs_and_lines sals, char *addr_string,
6921 enum bptype type, enum bpdisp disposition,
6922 int thread, int task, int ignore_count,
6923 struct breakpoint_ops *ops, int from_tty, int enabled)
6925 struct breakpoint *b = NULL;
6928 if (type == bp_hardware_breakpoint)
6930 int i = hw_breakpoint_used_count ();
6931 int target_resources_ok =
6932 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
6934 if (target_resources_ok == 0)
6935 error (_("No hardware breakpoint support in the target."));
6936 else if (target_resources_ok < 0)
6937 error (_("Hardware breakpoints used exceeds limit."));
6940 gdb_assert (sals.nelts > 0);
6942 for (i = 0; i < sals.nelts; ++i)
6944 struct symtab_and_line sal = sals.sals[i];
6945 struct bp_location *loc;
6949 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
6951 loc_gdbarch = gdbarch;
6953 describe_other_breakpoints (loc_gdbarch,
6954 sal.pspace, sal.pc, sal.section, thread);
6959 b = set_raw_breakpoint (gdbarch, sal, type);
6960 set_breakpoint_count (breakpoint_count + 1);
6961 b->number = breakpoint_count;
6965 b->cond_string = cond_string;
6966 b->ignore_count = ignore_count;
6967 b->enable_state = enabled ? bp_enabled : bp_disabled;
6968 b->disposition = disposition;
6970 b->pspace = sals.sals[0].pspace;
6972 if (enabled && b->pspace->executing_startup
6973 && (b->type == bp_breakpoint
6974 || b->type == bp_hardware_breakpoint))
6975 b->enable_state = bp_startup_disabled;
6981 loc = add_location_to_breakpoint (b, &sal);
6984 if (bp_loc_is_permanent (loc))
6985 make_breakpoint_permanent (b);
6989 char *arg = b->cond_string;
6990 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
6992 error (_("Garbage %s follows condition"), arg);
6997 b->addr_string = addr_string;
6999 /* addr_string has to be used or breakpoint_re_set will delete
7002 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7008 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7009 elements to fill the void space. */
7011 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7013 int i = index_to_remove+1;
7014 int last_index = sal->nelts-1;
7016 for (;i <= last_index; ++i)
7017 sal->sals[i-1] = sal->sals[i];
7022 /* If appropriate, obtains all sals that correspond to the same file
7023 and line as SAL, in all program spaces. Users debugging with IDEs,
7024 will want to set a breakpoint at foo.c:line, and not really care
7025 about program spaces. This is done only if SAL does not have
7026 explicit PC and has line and file information. If we got just a
7027 single expanded sal, return the original.
7029 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7030 which the name of enclosing function is different from SAL. This
7031 makes sure that if we have breakpoint originally set in template
7032 instantiation, say foo<int>(), we won't expand SAL to locations at
7033 the same line in all existing instantiations of 'foo'. */
7035 static struct symtabs_and_lines
7036 expand_line_sal_maybe (struct symtab_and_line sal)
7038 struct symtabs_and_lines expanded;
7039 CORE_ADDR original_pc = sal.pc;
7040 char *original_function = NULL;
7043 struct cleanup *old_chain;
7045 /* If we have explicit pc, don't expand.
7046 If we have no line number, we can't expand. */
7047 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7050 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7051 expanded.sals[0] = sal;
7057 old_chain = save_current_space_and_thread ();
7059 switch_to_program_space_and_thread (sal.pspace);
7061 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7063 /* Note that expand_line_sal visits *all* program spaces. */
7064 expanded = expand_line_sal (sal);
7066 if (expanded.nelts == 1)
7068 /* We had one sal, we got one sal. Return that sal, adjusting it
7069 past the function prologue if necessary. */
7070 xfree (expanded.sals);
7072 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7073 sal.pc = original_pc;
7074 expanded.sals[0] = sal;
7075 skip_prologue_sal (&expanded.sals[0]);
7076 do_cleanups (old_chain);
7080 if (!sal.explicit_line)
7082 CORE_ADDR func_addr, func_end;
7083 for (i = 0; i < expanded.nelts; ++i)
7085 CORE_ADDR pc = expanded.sals[i].pc;
7086 char *this_function;
7088 /* We need to switch threads as well since we're about to
7090 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7092 if (find_pc_partial_function (pc, &this_function,
7093 &func_addr, &func_end))
7096 && strcmp (this_function, original_function) != 0)
7098 remove_sal (&expanded, i);
7105 /* Skip the function prologue if necessary. */
7106 for (i = 0; i < expanded.nelts; ++i)
7107 skip_prologue_sal (&expanded.sals[i]);
7109 do_cleanups (old_chain);
7111 if (expanded.nelts <= 1)
7113 /* This is un ugly workaround. If we get zero
7114 expanded sals then something is really wrong.
7115 Fix that by returnign the original sal. */
7116 xfree (expanded.sals);
7118 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7119 sal.pc = original_pc;
7120 expanded.sals[0] = sal;
7127 for (i = 0; i < expanded.nelts; ++i)
7128 if (expanded.sals[i].pc == original_pc)
7139 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7140 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7141 value. COND_STRING, if not NULL, specified the condition to be
7142 used for all breakpoints. Essentially the only case where
7143 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7144 function. In that case, it's still not possible to specify
7145 separate conditions for different overloaded functions, so
7146 we take just a single condition string.
7148 NOTE: If the function succeeds, the caller is expected to cleanup
7149 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7150 array contents). If the function fails (error() is called), the
7151 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7152 COND and SALS arrays and each of those arrays contents. */
7155 create_breakpoints_sal (struct gdbarch *gdbarch,
7156 struct symtabs_and_lines sals, char **addr_string,
7158 enum bptype type, enum bpdisp disposition,
7159 int thread, int task, int ignore_count,
7160 struct breakpoint_ops *ops, int from_tty,
7165 for (i = 0; i < sals.nelts; ++i)
7167 struct symtabs_and_lines expanded =
7168 expand_line_sal_maybe (sals.sals[i]);
7170 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7171 cond_string, type, disposition,
7172 thread, task, ignore_count, ops, from_tty, enabled);
7176 /* Parse ARG which is assumed to be a SAL specification possibly
7177 followed by conditionals. On return, SALS contains an array of SAL
7178 addresses found. ADDR_STRING contains a vector of (canonical)
7179 address strings. ARG points to the end of the SAL. */
7182 parse_breakpoint_sals (char **address,
7183 struct symtabs_and_lines *sals,
7184 char ***addr_string,
7187 char *addr_start = *address;
7189 *addr_string = NULL;
7190 /* If no arg given, or if first arg is 'if ', use the default
7192 if ((*address) == NULL
7193 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7195 if (default_breakpoint_valid)
7197 struct symtab_and_line sal;
7199 init_sal (&sal); /* initialize to zeroes */
7200 sals->sals = (struct symtab_and_line *)
7201 xmalloc (sizeof (struct symtab_and_line));
7202 sal.pc = default_breakpoint_address;
7203 sal.line = default_breakpoint_line;
7204 sal.symtab = default_breakpoint_symtab;
7205 sal.pspace = default_breakpoint_pspace;
7206 sal.section = find_pc_overlay (sal.pc);
7208 /* "break" without arguments is equivalent to "break *PC" where PC is
7209 the default_breakpoint_address. So make sure to set
7210 sal.explicit_pc to prevent GDB from trying to expand the list of
7211 sals to include all other instances with the same symtab and line.
7213 sal.explicit_pc = 1;
7215 sals->sals[0] = sal;
7219 error (_("No default breakpoint address now."));
7223 /* Force almost all breakpoints to be in terms of the
7224 current_source_symtab (which is decode_line_1's default). This
7225 should produce the results we want almost all of the time while
7226 leaving default_breakpoint_* alone.
7227 ObjC: However, don't match an Objective-C method name which
7228 may have a '+' or '-' succeeded by a '[' */
7230 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7232 if (default_breakpoint_valid
7234 || ((strchr ("+-", (*address)[0]) != NULL)
7235 && ((*address)[1] != '['))))
7236 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7237 default_breakpoint_line, addr_string,
7240 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7241 addr_string, not_found_ptr);
7243 /* For any SAL that didn't have a canonical string, fill one in. */
7244 if (sals->nelts > 0 && *addr_string == NULL)
7245 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7246 if (addr_start != (*address))
7250 for (i = 0; i < sals->nelts; i++)
7252 /* Add the string if not present. */
7253 if ((*addr_string)[i] == NULL)
7254 (*addr_string)[i] = savestring (addr_start,
7255 (*address) - addr_start);
7261 /* Convert each SAL into a real PC. Verify that the PC can be
7262 inserted as a breakpoint. If it can't throw an error. */
7265 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
7270 for (i = 0; i < sals->nelts; i++)
7271 resolve_sal_pc (&sals->sals[i]);
7274 /* Fast tracepoints may have restrictions on valid locations. For
7275 instance, a fast tracepoint using a jump instead of a trap will
7276 likely have to overwrite more bytes than a trap would, and so can
7277 only be placed where the instruction is longer than the jump, or a
7278 multi-instruction sequence does not have a jump into the middle of
7282 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7283 struct symtabs_and_lines *sals)
7286 struct symtab_and_line *sal;
7288 struct cleanup *old_chain;
7290 for (i = 0; i < sals->nelts; i++)
7292 sal = &sals->sals[i];
7294 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7296 old_chain = make_cleanup (xfree, msg);
7299 error (_("May not have a fast tracepoint at 0x%s%s"),
7300 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7302 do_cleanups (old_chain);
7307 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7309 struct captured_parse_breakpoint_args *args = data;
7311 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7312 args->not_found_ptr);
7315 /* Given TOK, a string specification of condition and thread, as
7316 accepted by the 'break' command, extract the condition
7317 string and thread number and set *COND_STRING and *THREAD.
7318 PC identifies the context at which the condition should be parsed.
7319 If no condition is found, *COND_STRING is set to NULL.
7320 If no thread is found, *THREAD is set to -1. */
7322 find_condition_and_thread (char *tok, CORE_ADDR pc,
7323 char **cond_string, int *thread, int *task)
7325 *cond_string = NULL;
7331 char *cond_start = NULL;
7332 char *cond_end = NULL;
7334 while (*tok == ' ' || *tok == '\t')
7339 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7342 toklen = end_tok - tok;
7344 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7346 struct expression *expr;
7348 tok = cond_start = end_tok + 1;
7349 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7352 *cond_string = savestring (cond_start,
7353 cond_end - cond_start);
7355 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7361 *thread = strtol (tok, &tok, 0);
7363 error (_("Junk after thread keyword."));
7364 if (!valid_thread_id (*thread))
7365 error (_("Unknown thread %d."), *thread);
7367 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7373 *task = strtol (tok, &tok, 0);
7375 error (_("Junk after task keyword."));
7376 if (!valid_task_id (*task))
7377 error (_("Unknown task %d."), *task);
7380 error (_("Junk at end of arguments."));
7384 /* Set a breakpoint. This function is shared between CLI and MI
7385 functions for setting a breakpoint. This function has two major
7386 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7387 parameter. If non-zero, the function will parse arg, extracting
7388 breakpoint location, address and thread. Otherwise, ARG is just the
7389 location of breakpoint, with condition and thread specified by the
7390 COND_STRING and THREAD parameters. Returns true if any breakpoint
7391 was created; false otherwise. */
7394 create_breakpoint (struct gdbarch *gdbarch,
7395 char *arg, char *cond_string, int thread,
7396 int parse_condition_and_thread,
7397 int tempflag, int hardwareflag, int traceflag,
7399 enum auto_boolean pending_break_support,
7400 struct breakpoint_ops *ops,
7404 struct gdb_exception e;
7405 struct symtabs_and_lines sals;
7406 struct symtab_and_line pending_sal;
7408 char *addr_start = arg;
7410 struct cleanup *old_chain;
7411 struct cleanup *bkpt_chain = NULL;
7412 struct captured_parse_breakpoint_args parse_args;
7416 enum bptype type_wanted;
7418 int prev_bkpt_count = breakpoint_count;
7424 parse_args.arg_p = &arg;
7425 parse_args.sals_p = &sals;
7426 parse_args.addr_string_p = &addr_string;
7427 parse_args.not_found_ptr = ¬_found;
7429 e = catch_exception (uiout, do_captured_parse_breakpoint,
7430 &parse_args, RETURN_MASK_ALL);
7432 /* If caller is interested in rc value from parse, set value. */
7436 throw_exception (e);
7440 case NOT_FOUND_ERROR:
7442 /* If pending breakpoint support is turned off, throw
7445 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7446 throw_exception (e);
7448 exception_print (gdb_stderr, e);
7450 /* If pending breakpoint support is auto query and the user
7451 selects no, then simply return the error code. */
7452 if (pending_break_support == AUTO_BOOLEAN_AUTO
7453 && !nquery ("Make breakpoint pending on future shared library load? "))
7456 /* At this point, either the user was queried about setting
7457 a pending breakpoint and selected yes, or pending
7458 breakpoint behavior is on and thus a pending breakpoint
7459 is defaulted on behalf of the user. */
7460 copy_arg = xstrdup (addr_start);
7461 addr_string = ©_arg;
7463 sals.sals = &pending_sal;
7468 throw_exception (e);
7475 /* Create a chain of things that always need to be cleaned up. */
7476 old_chain = make_cleanup (null_cleanup, 0);
7480 /* Make sure that all storage allocated to SALS gets freed. */
7481 make_cleanup (xfree, sals.sals);
7483 /* Cleanup the addr_string array but not its contents. */
7484 make_cleanup (xfree, addr_string);
7487 /* ----------------------------- SNIP -----------------------------
7488 Anything added to the cleanup chain beyond this point is assumed
7489 to be part of a breakpoint. If the breakpoint create succeeds
7490 then the memory is not reclaimed. */
7491 bkpt_chain = make_cleanup (null_cleanup, 0);
7493 /* Mark the contents of the addr_string for cleanup. These go on
7494 the bkpt_chain and only occur if the breakpoint create fails. */
7495 for (i = 0; i < sals.nelts; i++)
7497 if (addr_string[i] != NULL)
7498 make_cleanup (xfree, addr_string[i]);
7501 /* Resolve all line numbers to PC's and verify that the addresses
7502 are ok for the target. */
7504 breakpoint_sals_to_pc (&sals, addr_start);
7506 type_wanted = (traceflag
7507 ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint)
7508 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
7510 /* Fast tracepoints may have additional restrictions on location. */
7511 if (type_wanted == bp_fast_tracepoint)
7512 check_fast_tracepoint_sals (gdbarch, &sals);
7514 /* Verify that condition can be parsed, before setting any
7515 breakpoints. Allocate a separate condition expression for each
7519 if (parse_condition_and_thread)
7521 /* Here we only parse 'arg' to separate condition
7522 from thread number, so parsing in context of first
7523 sal is OK. When setting the breakpoint we'll
7524 re-parse it in context of each sal. */
7527 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7530 make_cleanup (xfree, cond_string);
7534 /* Create a private copy of condition string. */
7537 cond_string = xstrdup (cond_string);
7538 make_cleanup (xfree, cond_string);
7541 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7542 type_wanted, tempflag ? disp_del : disp_donttouch,
7543 thread, task, ignore_count, ops, from_tty,
7548 struct breakpoint *b;
7550 make_cleanup (xfree, copy_arg);
7552 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7553 set_breakpoint_count (breakpoint_count + 1);
7554 b->number = breakpoint_count;
7556 b->addr_string = addr_string[0];
7557 b->cond_string = NULL;
7558 b->ignore_count = ignore_count;
7559 b->disposition = tempflag ? disp_del : disp_donttouch;
7560 b->condition_not_parsed = 1;
7562 b->enable_state = enabled ? bp_enabled : bp_disabled;
7563 b->pspace = current_program_space;
7565 if (enabled && b->pspace->executing_startup
7566 && (b->type == bp_breakpoint
7567 || b->type == bp_hardware_breakpoint))
7568 b->enable_state = bp_startup_disabled;
7575 warning (_("Multiple breakpoints were set.\n"
7576 "Use the \"delete\" command to delete unwanted breakpoints."));
7577 prev_breakpoint_count = prev_bkpt_count;
7580 /* That's it. Discard the cleanups for data inserted into the
7582 discard_cleanups (bkpt_chain);
7583 /* But cleanup everything else. */
7584 do_cleanups (old_chain);
7586 /* error call may happen here - have BKPT_CHAIN already discarded. */
7587 update_global_location_list (1);
7592 /* Set a breakpoint.
7593 ARG is a string describing breakpoint address,
7594 condition, and thread.
7595 FLAG specifies if a breakpoint is hardware on,
7596 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7600 break_command_1 (char *arg, int flag, int from_tty)
7602 int hardwareflag = flag & BP_HARDWAREFLAG;
7603 int tempflag = flag & BP_TEMPFLAG;
7605 create_breakpoint (get_current_arch (),
7607 NULL, 0, 1 /* parse arg */,
7608 tempflag, hardwareflag, 0 /* traceflag */,
7609 0 /* Ignore count */,
7610 pending_break_support,
7611 NULL /* breakpoint_ops */,
7617 /* Helper function for break_command_1 and disassemble_command. */
7620 resolve_sal_pc (struct symtab_and_line *sal)
7624 if (sal->pc == 0 && sal->symtab != NULL)
7626 if (!find_line_pc (sal->symtab, sal->line, &pc))
7627 error (_("No line %d in file \"%s\"."),
7628 sal->line, sal->symtab->filename);
7631 /* If this SAL corresponds to a breakpoint inserted using
7632 a line number, then skip the function prologue if necessary. */
7633 if (sal->explicit_line)
7634 skip_prologue_sal (sal);
7637 if (sal->section == 0 && sal->symtab != NULL)
7639 struct blockvector *bv;
7643 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7646 sym = block_linkage_function (b);
7649 fixup_symbol_section (sym, sal->symtab->objfile);
7650 sal->section = SYMBOL_OBJ_SECTION (sym);
7654 /* It really is worthwhile to have the section, so we'll just
7655 have to look harder. This case can be executed if we have
7656 line numbers but no functions (as can happen in assembly
7659 struct minimal_symbol *msym;
7660 struct cleanup *old_chain = save_current_space_and_thread ();
7662 switch_to_program_space_and_thread (sal->pspace);
7664 msym = lookup_minimal_symbol_by_pc (sal->pc);
7666 sal->section = SYMBOL_OBJ_SECTION (msym);
7668 do_cleanups (old_chain);
7675 break_command (char *arg, int from_tty)
7677 break_command_1 (arg, 0, from_tty);
7681 tbreak_command (char *arg, int from_tty)
7683 break_command_1 (arg, BP_TEMPFLAG, from_tty);
7687 hbreak_command (char *arg, int from_tty)
7689 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
7693 thbreak_command (char *arg, int from_tty)
7695 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
7699 stop_command (char *arg, int from_tty)
7701 printf_filtered (_("Specify the type of breakpoint to set.\n\
7702 Usage: stop in <function | address>\n\
7703 stop at <line>\n"));
7707 stopin_command (char *arg, int from_tty)
7711 if (arg == (char *) NULL)
7713 else if (*arg != '*')
7718 /* look for a ':'. If this is a line number specification, then
7719 say it is bad, otherwise, it should be an address or
7720 function/method name */
7721 while (*argptr && !hasColon)
7723 hasColon = (*argptr == ':');
7728 badInput = (*argptr != ':'); /* Not a class::method */
7730 badInput = isdigit (*arg); /* a simple line number */
7734 printf_filtered (_("Usage: stop in <function | address>\n"));
7736 break_command_1 (arg, 0, from_tty);
7740 stopat_command (char *arg, int from_tty)
7744 if (arg == (char *) NULL || *arg == '*') /* no line number */
7751 /* look for a ':'. If there is a '::' then get out, otherwise
7752 it is probably a line number. */
7753 while (*argptr && !hasColon)
7755 hasColon = (*argptr == ':');
7760 badInput = (*argptr == ':'); /* we have class::method */
7762 badInput = !isdigit (*arg); /* not a line number */
7766 printf_filtered (_("Usage: stop at <line>\n"));
7768 break_command_1 (arg, 0, from_tty);
7771 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
7772 variable. Also the constant detection may fail for some constant
7773 expressions and in such case still falsely return zero. */
7775 watchpoint_exp_is_const (const struct expression *exp)
7783 /* We are only interested in the descriptor of each element. */
7784 operator_length (exp, i, &oplenp, &argsp);
7787 switch (exp->elts[i].opcode)
7797 case BINOP_LOGICAL_AND:
7798 case BINOP_LOGICAL_OR:
7799 case BINOP_BITWISE_AND:
7800 case BINOP_BITWISE_IOR:
7801 case BINOP_BITWISE_XOR:
7803 case BINOP_NOTEQUAL:
7819 case TERNOP_SLICE_COUNT:
7831 case OP_OBJC_NSSTRING:
7834 case UNOP_LOGICAL_NOT:
7835 case UNOP_COMPLEMENT:
7838 /* Unary, binary and ternary operators: We have to check their
7839 operands. If they are constant, then so is the result of
7840 that operation. For instance, if A and B are determined to be
7841 constants, then so is "A + B".
7843 UNOP_IND is one exception to the rule above, because the value
7844 of *ADDR is not necessarily a constant, even when ADDR is. */
7848 /* Check whether the associated symbol is a constant.
7849 We use SYMBOL_CLASS rather than TYPE_CONST because it's
7850 possible that a buggy compiler could mark a variable as constant
7851 even when it is not, and TYPE_CONST would return true in this
7852 case, while SYMBOL_CLASS wouldn't.
7853 We also have to check for function symbols because they are
7856 struct symbol *s = exp->elts[i + 2].symbol;
7858 if (SYMBOL_CLASS (s) != LOC_BLOCK
7859 && SYMBOL_CLASS (s) != LOC_CONST
7860 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
7865 /* The default action is to return 0 because we are using
7866 the optimistic approach here: If we don't know something,
7867 then it is not a constant. */
7876 /* accessflag: hw_write: watch write,
7877 hw_read: watch read,
7878 hw_access: watch access (read or write) */
7880 watch_command_1 (char *arg, int accessflag, int from_tty)
7882 struct breakpoint *b, *scope_breakpoint = NULL;
7883 struct expression *exp;
7884 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
7885 struct value *val, *mark;
7886 struct frame_info *frame;
7887 char *exp_start = NULL;
7888 char *exp_end = NULL;
7889 char *tok, *id_tok_start, *end_tok;
7891 char *cond_start = NULL;
7892 char *cond_end = NULL;
7893 int i, other_type_used, target_resources_ok = 0;
7894 enum bptype bp_type;
7898 /* Make sure that we actually have parameters to parse. */
7899 if (arg != NULL && arg[0] != '\0')
7901 toklen = strlen (arg); /* Size of argument list. */
7903 /* Points tok to the end of the argument list. */
7904 tok = arg + toklen - 1;
7906 /* Go backwards in the parameters list. Skip the last parameter.
7907 If we're expecting a 'thread <thread_num>' parameter, this should
7908 be the thread identifier. */
7909 while (tok > arg && (*tok == ' ' || *tok == '\t'))
7911 while (tok > arg && (*tok != ' ' && *tok != '\t'))
7914 /* Points end_tok to the beginning of the last token. */
7915 id_tok_start = tok + 1;
7917 /* Go backwards in the parameters list. Skip one more parameter.
7918 If we're expecting a 'thread <thread_num>' parameter, we should
7919 reach a "thread" token. */
7920 while (tok > arg && (*tok == ' ' || *tok == '\t'))
7925 while (tok > arg && (*tok != ' ' && *tok != '\t'))
7928 /* Move the pointer forward to skip the whitespace and
7929 calculate the length of the token. */
7931 toklen = end_tok - tok;
7933 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7935 /* At this point we've found a "thread" token, which means
7936 the user is trying to set a watchpoint that triggers
7937 only in a specific thread. */
7940 /* Extract the thread ID from the next token. */
7941 thread = strtol (id_tok_start, &endp, 0);
7943 /* Check if the user provided a valid numeric value for the
7945 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
7946 error (_("Invalid thread ID specification %s."), id_tok_start);
7948 /* Check if the thread actually exists. */
7949 if (!valid_thread_id (thread))
7950 error (_("Unknown thread %d."), thread);
7952 /* Truncate the string and get rid of the thread <thread_num>
7953 parameter before the parameter list is parsed by the
7954 evaluate_expression() function. */
7959 /* Parse the rest of the arguments. */
7960 innermost_block = NULL;
7962 exp = parse_exp_1 (&arg, 0, 0);
7964 /* Remove trailing whitespace from the expression before saving it.
7965 This makes the eventual display of the expression string a bit
7967 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
7970 /* Checking if the expression is not constant. */
7971 if (watchpoint_exp_is_const (exp))
7975 len = exp_end - exp_start;
7976 while (len > 0 && isspace (exp_start[len - 1]))
7978 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
7981 exp_valid_block = innermost_block;
7982 mark = value_mark ();
7983 fetch_watchpoint_value (exp, &val, NULL, NULL);
7985 release_value (val);
7988 while (*tok == ' ' || *tok == '\t')
7992 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7995 toklen = end_tok - tok;
7996 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7998 struct expression *cond;
8000 innermost_block = NULL;
8001 tok = cond_start = end_tok + 1;
8002 cond = parse_exp_1 (&tok, 0, 0);
8004 /* The watchpoint expression may not be local, but the condition
8005 may still be. E.g.: `watch global if local > 0'. */
8006 cond_exp_valid_block = innermost_block;
8012 error (_("Junk at end of command."));
8014 if (accessflag == hw_read)
8015 bp_type = bp_read_watchpoint;
8016 else if (accessflag == hw_access)
8017 bp_type = bp_access_watchpoint;
8019 bp_type = bp_hardware_watchpoint;
8021 mem_cnt = can_use_hardware_watchpoint (val);
8022 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
8023 error (_("Expression cannot be implemented with read/access watchpoint."));
8026 i = hw_watchpoint_used_count (bp_type, &other_type_used);
8027 target_resources_ok =
8028 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
8030 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8031 error (_("Target does not support this type of hardware watchpoint."));
8033 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8034 error (_("Target can only support one kind of HW watchpoint at a time."));
8037 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8038 watchpoint could not be set. */
8039 if (!mem_cnt || target_resources_ok <= 0)
8040 bp_type = bp_watchpoint;
8042 frame = block_innermost_frame (exp_valid_block);
8044 /* If the expression is "local", then set up a "watchpoint scope"
8045 breakpoint at the point where we've left the scope of the watchpoint
8046 expression. Create the scope breakpoint before the watchpoint, so
8047 that we will encounter it first in bpstat_stop_status. */
8048 if (exp_valid_block && frame)
8050 if (frame_id_p (frame_unwind_caller_id (frame)))
8053 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
8054 frame_unwind_caller_pc (frame),
8055 bp_watchpoint_scope);
8057 scope_breakpoint->enable_state = bp_enabled;
8059 /* Automatically delete the breakpoint when it hits. */
8060 scope_breakpoint->disposition = disp_del;
8062 /* Only break in the proper frame (help with recursion). */
8063 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
8065 /* Set the address at which we will stop. */
8066 scope_breakpoint->loc->gdbarch
8067 = frame_unwind_caller_arch (frame);
8068 scope_breakpoint->loc->requested_address
8069 = frame_unwind_caller_pc (frame);
8070 scope_breakpoint->loc->address
8071 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
8072 scope_breakpoint->loc->requested_address,
8073 scope_breakpoint->type);
8077 /* Now set up the breakpoint. */
8078 b = set_raw_breakpoint_without_location (NULL, bp_type);
8079 set_breakpoint_count (breakpoint_count + 1);
8080 b->number = breakpoint_count;
8082 b->disposition = disp_donttouch;
8084 b->exp_valid_block = exp_valid_block;
8085 b->cond_exp_valid_block = cond_exp_valid_block;
8086 b->exp_string = savestring (exp_start, exp_end - exp_start);
8090 b->cond_string = savestring (cond_start, cond_end - cond_start);
8096 b->watchpoint_frame = get_frame_id (frame);
8097 b->watchpoint_thread = inferior_ptid;
8101 b->watchpoint_frame = null_frame_id;
8102 b->watchpoint_thread = null_ptid;
8105 if (scope_breakpoint != NULL)
8107 /* The scope breakpoint is related to the watchpoint. We will
8108 need to act on them together. */
8109 b->related_breakpoint = scope_breakpoint;
8110 scope_breakpoint->related_breakpoint = b;
8113 value_free_to_mark (mark);
8115 /* Finally update the new watchpoint. This creates the locations
8116 that should be inserted. */
8117 update_watchpoint (b, 1);
8120 update_global_location_list (1);
8123 /* Return count of locations need to be watched and can be handled
8124 in hardware. If the watchpoint can not be handled
8125 in hardware return zero. */
8128 can_use_hardware_watchpoint (struct value *v)
8130 int found_memory_cnt = 0;
8131 struct value *head = v;
8133 /* Did the user specifically forbid us to use hardware watchpoints? */
8134 if (!can_use_hw_watchpoints)
8137 /* Make sure that the value of the expression depends only upon
8138 memory contents, and values computed from them within GDB. If we
8139 find any register references or function calls, we can't use a
8140 hardware watchpoint.
8142 The idea here is that evaluating an expression generates a series
8143 of values, one holding the value of every subexpression. (The
8144 expression a*b+c has five subexpressions: a, b, a*b, c, and
8145 a*b+c.) GDB's values hold almost enough information to establish
8146 the criteria given above --- they identify memory lvalues,
8147 register lvalues, computed values, etcetera. So we can evaluate
8148 the expression, and then scan the chain of values that leaves
8149 behind to decide whether we can detect any possible change to the
8150 expression's final value using only hardware watchpoints.
8152 However, I don't think that the values returned by inferior
8153 function calls are special in any way. So this function may not
8154 notice that an expression involving an inferior function call
8155 can't be watched with hardware watchpoints. FIXME. */
8156 for (; v; v = value_next (v))
8158 if (VALUE_LVAL (v) == lval_memory)
8161 /* A lazy memory lvalue is one that GDB never needed to fetch;
8162 we either just used its address (e.g., `a' in `a.b') or
8163 we never needed it at all (e.g., `a' in `a,b'). */
8167 /* Ahh, memory we actually used! Check if we can cover
8168 it with hardware watchpoints. */
8169 struct type *vtype = check_typedef (value_type (v));
8171 /* We only watch structs and arrays if user asked for it
8172 explicitly, never if they just happen to appear in a
8173 middle of some value chain. */
8175 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
8176 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
8178 CORE_ADDR vaddr = value_address (v);
8179 int len = TYPE_LENGTH (value_type (v));
8181 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
8188 else if (VALUE_LVAL (v) != not_lval
8189 && deprecated_value_modifiable (v) == 0)
8190 return 0; /* ??? What does this represent? */
8191 else if (VALUE_LVAL (v) == lval_register)
8192 return 0; /* cannot watch a register with a HW watchpoint */
8195 /* The expression itself looks suitable for using a hardware
8196 watchpoint, but give the target machine a chance to reject it. */
8197 return found_memory_cnt;
8201 watch_command_wrapper (char *arg, int from_tty)
8203 watch_command (arg, from_tty);
8207 watch_command (char *arg, int from_tty)
8209 watch_command_1 (arg, hw_write, from_tty);
8213 rwatch_command_wrapper (char *arg, int from_tty)
8215 rwatch_command (arg, from_tty);
8219 rwatch_command (char *arg, int from_tty)
8221 watch_command_1 (arg, hw_read, from_tty);
8225 awatch_command_wrapper (char *arg, int from_tty)
8227 awatch_command (arg, from_tty);
8231 awatch_command (char *arg, int from_tty)
8233 watch_command_1 (arg, hw_access, from_tty);
8237 /* Helper routines for the until_command routine in infcmd.c. Here
8238 because it uses the mechanisms of breakpoints. */
8240 struct until_break_command_continuation_args
8242 struct breakpoint *breakpoint;
8243 struct breakpoint *breakpoint2;
8246 /* This function is called by fetch_inferior_event via the
8247 cmd_continuation pointer, to complete the until command. It takes
8248 care of cleaning up the temporary breakpoints set up by the until
8251 until_break_command_continuation (void *arg)
8253 struct until_break_command_continuation_args *a = arg;
8255 delete_breakpoint (a->breakpoint);
8257 delete_breakpoint (a->breakpoint2);
8261 until_break_command (char *arg, int from_tty, int anywhere)
8263 struct symtabs_and_lines sals;
8264 struct symtab_and_line sal;
8265 struct frame_info *frame = get_selected_frame (NULL);
8266 struct breakpoint *breakpoint;
8267 struct breakpoint *breakpoint2 = NULL;
8268 struct cleanup *old_chain;
8270 clear_proceed_status ();
8272 /* Set a breakpoint where the user wants it and at return from
8275 if (default_breakpoint_valid)
8276 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8277 default_breakpoint_line, (char ***) NULL, NULL);
8279 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8280 0, (char ***) NULL, NULL);
8282 if (sals.nelts != 1)
8283 error (_("Couldn't get information on specified line."));
8286 xfree (sals.sals); /* malloc'd, so freed */
8289 error (_("Junk at end of arguments."));
8291 resolve_sal_pc (&sal);
8294 /* If the user told us to continue until a specified location,
8295 we don't specify a frame at which we need to stop. */
8296 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8297 null_frame_id, bp_until);
8299 /* Otherwise, specify the selected frame, because we want to stop only
8300 at the very same frame. */
8301 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8302 get_stack_frame_id (frame),
8305 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8307 /* Keep within the current frame, or in frames called by the current
8310 if (frame_id_p (frame_unwind_caller_id (frame)))
8312 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8313 sal.pc = frame_unwind_caller_pc (frame);
8314 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8316 frame_unwind_caller_id (frame),
8318 make_cleanup_delete_breakpoint (breakpoint2);
8321 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8323 /* If we are running asynchronously, and proceed call above has actually
8324 managed to start the target, arrange for breakpoints to be
8325 deleted when the target stops. Otherwise, we're already stopped and
8326 delete breakpoints via cleanup chain. */
8328 if (target_can_async_p () && is_running (inferior_ptid))
8330 struct until_break_command_continuation_args *args;
8331 args = xmalloc (sizeof (*args));
8333 args->breakpoint = breakpoint;
8334 args->breakpoint2 = breakpoint2;
8336 discard_cleanups (old_chain);
8337 add_continuation (inferior_thread (),
8338 until_break_command_continuation, args,
8342 do_cleanups (old_chain);
8346 ep_skip_leading_whitespace (char **s)
8348 if ((s == NULL) || (*s == NULL))
8350 while (isspace (**s))
8354 /* This function attempts to parse an optional "if <cond>" clause
8355 from the arg string. If one is not found, it returns NULL.
8357 Else, it returns a pointer to the condition string. (It does not
8358 attempt to evaluate the string against a particular block.) And,
8359 it updates arg to point to the first character following the parsed
8360 if clause in the arg string. */
8363 ep_parse_optional_if_clause (char **arg)
8367 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8370 /* Skip the "if" keyword. */
8373 /* Skip any extra leading whitespace, and record the start of the
8374 condition string. */
8375 ep_skip_leading_whitespace (arg);
8378 /* Assume that the condition occupies the remainder of the arg string. */
8379 (*arg) += strlen (cond_string);
8384 /* Commands to deal with catching events, such as signals, exceptions,
8385 process start/exit, etc. */
8389 catch_fork_temporary, catch_vfork_temporary,
8390 catch_fork_permanent, catch_vfork_permanent
8395 catch_fork_command_1 (char *arg, int from_tty,
8396 struct cmd_list_element *command)
8398 struct gdbarch *gdbarch = get_current_arch ();
8399 char *cond_string = NULL;
8400 catch_fork_kind fork_kind;
8403 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8404 tempflag = (fork_kind == catch_fork_temporary
8405 || fork_kind == catch_vfork_temporary);
8409 ep_skip_leading_whitespace (&arg);
8411 /* The allowed syntax is:
8413 catch [v]fork if <cond>
8415 First, check if there's an if clause. */
8416 cond_string = ep_parse_optional_if_clause (&arg);
8418 if ((*arg != '\0') && !isspace (*arg))
8419 error (_("Junk at end of arguments."));
8421 /* If this target supports it, create a fork or vfork catchpoint
8422 and enable reporting of such events. */
8425 case catch_fork_temporary:
8426 case catch_fork_permanent:
8427 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8428 &catch_fork_breakpoint_ops);
8430 case catch_vfork_temporary:
8431 case catch_vfork_permanent:
8432 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8433 &catch_vfork_breakpoint_ops);
8436 error (_("unsupported or unknown fork kind; cannot catch it"));
8442 catch_exec_command_1 (char *arg, int from_tty,
8443 struct cmd_list_element *command)
8445 struct gdbarch *gdbarch = get_current_arch ();
8447 char *cond_string = NULL;
8449 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8453 ep_skip_leading_whitespace (&arg);
8455 /* The allowed syntax is:
8457 catch exec if <cond>
8459 First, check if there's an if clause. */
8460 cond_string = ep_parse_optional_if_clause (&arg);
8462 if ((*arg != '\0') && !isspace (*arg))
8463 error (_("Junk at end of arguments."));
8465 /* If this target supports it, create an exec catchpoint
8466 and enable reporting of such events. */
8467 create_catchpoint (gdbarch, tempflag, cond_string,
8468 &catch_exec_breakpoint_ops);
8471 static enum print_stop_action
8472 print_exception_catchpoint (struct breakpoint *b)
8474 int bp_temp, bp_throw;
8476 annotate_catchpoint (b->number);
8478 bp_throw = strstr (b->addr_string, "throw") != NULL;
8479 if (b->loc->address != b->loc->requested_address)
8480 breakpoint_adjustment_warning (b->loc->requested_address,
8483 bp_temp = b->disposition == disp_del;
8485 bp_temp ? "Temporary catchpoint "
8487 if (!ui_out_is_mi_like_p (uiout))
8488 ui_out_field_int (uiout, "bkptno", b->number);
8490 bp_throw ? " (exception thrown), "
8491 : " (exception caught), ");
8492 if (ui_out_is_mi_like_p (uiout))
8494 ui_out_field_string (uiout, "reason",
8495 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8496 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8497 ui_out_field_int (uiout, "bkptno", b->number);
8499 return PRINT_SRC_AND_LOC;
8503 print_one_exception_catchpoint (struct breakpoint *b,
8504 struct bp_location **last_loc)
8506 struct value_print_options opts;
8508 get_user_print_options (&opts);
8509 if (opts.addressprint)
8512 if (b->loc == NULL || b->loc->shlib_disabled)
8513 ui_out_field_string (uiout, "addr", "<PENDING>");
8515 ui_out_field_core_addr (uiout, "addr",
8516 b->loc->gdbarch, b->loc->address);
8521 if (strstr (b->addr_string, "throw") != NULL)
8522 ui_out_field_string (uiout, "what", "exception throw");
8524 ui_out_field_string (uiout, "what", "exception catch");
8528 print_mention_exception_catchpoint (struct breakpoint *b)
8533 bp_temp = b->disposition == disp_del;
8534 bp_throw = strstr (b->addr_string, "throw") != NULL;
8535 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
8536 : _("Catchpoint "));
8537 ui_out_field_int (uiout, "bkptno", b->number);
8538 ui_out_text (uiout, bp_throw ? _(" (throw)")
8542 /* Implement the "print_recreate" breakpoint_ops method for throw and
8543 catch catchpoints. */
8546 print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
8551 bp_temp = b->disposition == disp_del;
8552 bp_throw = strstr (b->addr_string, "throw") != NULL;
8553 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
8554 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
8557 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
8560 NULL, /* breakpoint_hit */
8561 print_exception_catchpoint,
8562 print_one_exception_catchpoint,
8563 print_mention_exception_catchpoint,
8564 print_recreate_exception_catchpoint
8568 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
8569 enum exception_event_kind ex_event, int from_tty)
8571 char *trigger_func_name;
8573 if (ex_event == EX_EVENT_CATCH)
8574 trigger_func_name = "__cxa_begin_catch";
8576 trigger_func_name = "__cxa_throw";
8578 create_breakpoint (get_current_arch (),
8579 trigger_func_name, cond_string, -1,
8580 0 /* condition and thread are valid. */,
8583 AUTO_BOOLEAN_TRUE /* pending */,
8584 &gnu_v3_exception_catchpoint_ops, from_tty,
8590 /* Deal with "catch catch" and "catch throw" commands */
8593 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
8594 int tempflag, int from_tty)
8596 char *cond_string = NULL;
8600 ep_skip_leading_whitespace (&arg);
8602 cond_string = ep_parse_optional_if_clause (&arg);
8604 if ((*arg != '\0') && !isspace (*arg))
8605 error (_("Junk at end of arguments."));
8607 if (ex_event != EX_EVENT_THROW
8608 && ex_event != EX_EVENT_CATCH)
8609 error (_("Unsupported or unknown exception event; cannot catch it"));
8611 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
8614 warning (_("Unsupported with this platform/compiler combination."));
8617 /* Implementation of "catch catch" command. */
8620 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
8622 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8624 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
8627 /* Implementation of "catch throw" command. */
8630 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
8632 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8634 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
8637 /* Create a breakpoint struct for Ada exception catchpoints. */
8640 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
8641 struct symtab_and_line sal,
8645 struct expression *cond,
8646 struct breakpoint_ops *ops,
8650 struct breakpoint *b;
8654 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8656 loc_gdbarch = gdbarch;
8658 describe_other_breakpoints (loc_gdbarch,
8659 sal.pspace, sal.pc, sal.section, -1);
8660 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8661 version for exception catchpoints, because two catchpoints
8662 used for different exception names will use the same address.
8663 In this case, a "breakpoint ... also set at..." warning is
8664 unproductive. Besides. the warning phrasing is also a bit
8665 inapropriate, we should use the word catchpoint, and tell
8666 the user what type of catchpoint it is. The above is good
8667 enough for now, though. */
8670 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
8671 set_breakpoint_count (breakpoint_count + 1);
8673 b->enable_state = bp_enabled;
8674 b->disposition = tempflag ? disp_del : disp_donttouch;
8675 b->number = breakpoint_count;
8676 b->ignore_count = 0;
8677 b->loc->cond = cond;
8678 b->addr_string = addr_string;
8679 b->language = language_ada;
8680 b->cond_string = cond_string;
8681 b->exp_string = exp_string;
8686 update_global_location_list (1);
8689 /* Implement the "catch exception" command. */
8692 catch_ada_exception_command (char *arg, int from_tty,
8693 struct cmd_list_element *command)
8695 struct gdbarch *gdbarch = get_current_arch ();
8697 struct symtab_and_line sal;
8698 char *addr_string = NULL;
8699 char *exp_string = NULL;
8700 char *cond_string = NULL;
8701 struct expression *cond = NULL;
8702 struct breakpoint_ops *ops = NULL;
8704 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8708 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
8709 &cond_string, &cond, &ops);
8710 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
8711 cond_string, cond, ops, tempflag,
8715 /* Cleanup function for a syscall filter list. */
8717 clean_up_filters (void *arg)
8719 VEC(int) *iter = *(VEC(int) **) arg;
8720 VEC_free (int, iter);
8723 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8724 filter list, or NULL if no filtering is required. */
8726 catch_syscall_split_args (char *arg)
8728 VEC(int) *result = NULL;
8729 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
8731 while (*arg != '\0')
8733 int i, syscall_number;
8738 /* Skip whitespace. */
8739 while (isspace (*arg))
8742 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
8743 cur_name[i] = arg[i];
8747 /* Check if the user provided a syscall name or a number. */
8748 syscall_number = (int) strtol (cur_name, &endptr, 0);
8749 if (*endptr == '\0')
8750 get_syscall_by_number (syscall_number, &s);
8753 /* We have a name. Let's check if it's valid and convert it
8755 get_syscall_by_name (cur_name, &s);
8757 if (s.number == UNKNOWN_SYSCALL)
8758 /* Here we have to issue an error instead of a warning, because
8759 GDB cannot do anything useful if there's no syscall number to
8761 error (_("Unknown syscall name '%s'."), cur_name);
8764 /* Ok, it's valid. */
8765 VEC_safe_push (int, result, s.number);
8768 discard_cleanups (cleanup);
8772 /* Implement the "catch syscall" command. */
8775 catch_syscall_command_1 (char *arg, int from_tty,
8776 struct cmd_list_element *command)
8781 struct gdbarch *gdbarch = get_current_arch ();
8783 /* Checking if the feature if supported. */
8784 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
8785 error (_("The feature 'catch syscall' is not supported on \
8786 this architeture yet."));
8788 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8790 ep_skip_leading_whitespace (&arg);
8792 /* We need to do this first "dummy" translation in order
8793 to get the syscall XML file loaded or, most important,
8794 to display a warning to the user if there's no XML file
8795 for his/her architecture. */
8796 get_syscall_by_number (0, &s);
8798 /* The allowed syntax is:
8800 catch syscall <name | number> [<name | number> ... <name | number>]
8802 Let's check if there's a syscall name. */
8805 filter = catch_syscall_split_args (arg);
8809 create_syscall_event_catchpoint (tempflag, filter,
8810 &catch_syscall_breakpoint_ops);
8813 /* Implement the "catch assert" command. */
8816 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
8818 struct gdbarch *gdbarch = get_current_arch ();
8820 struct symtab_and_line sal;
8821 char *addr_string = NULL;
8822 struct breakpoint_ops *ops = NULL;
8824 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8828 sal = ada_decode_assert_location (arg, &addr_string, &ops);
8829 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
8830 ops, tempflag, from_tty);
8834 catch_command (char *arg, int from_tty)
8836 error (_("Catch requires an event name."));
8841 tcatch_command (char *arg, int from_tty)
8843 error (_("Catch requires an event name."));
8846 /* Delete breakpoints by address or line. */
8849 clear_command (char *arg, int from_tty)
8851 struct breakpoint *b;
8852 VEC(breakpoint_p) *found = 0;
8855 struct symtabs_and_lines sals;
8856 struct symtab_and_line sal;
8861 sals = decode_line_spec (arg, 1);
8866 sals.sals = (struct symtab_and_line *)
8867 xmalloc (sizeof (struct symtab_and_line));
8868 make_cleanup (xfree, sals.sals);
8869 init_sal (&sal); /* initialize to zeroes */
8870 sal.line = default_breakpoint_line;
8871 sal.symtab = default_breakpoint_symtab;
8872 sal.pc = default_breakpoint_address;
8873 sal.pspace = default_breakpoint_pspace;
8874 if (sal.symtab == 0)
8875 error (_("No source file specified."));
8883 /* We don't call resolve_sal_pc here. That's not
8884 as bad as it seems, because all existing breakpoints
8885 typically have both file/line and pc set. So, if
8886 clear is given file/line, we can match this to existing
8887 breakpoint without obtaining pc at all.
8889 We only support clearing given the address explicitly
8890 present in breakpoint table. Say, we've set breakpoint
8891 at file:line. There were several PC values for that file:line,
8892 due to optimization, all in one block.
8893 We've picked one PC value. If "clear" is issued with another
8894 PC corresponding to the same file:line, the breakpoint won't
8895 be cleared. We probably can still clear the breakpoint, but
8896 since the other PC value is never presented to user, user
8897 can only find it by guessing, and it does not seem important
8900 /* For each line spec given, delete bps which correspond
8901 to it. Do it in two passes, solely to preserve the current
8902 behavior that from_tty is forced true if we delete more than
8906 for (i = 0; i < sals.nelts; i++)
8908 /* If exact pc given, clear bpts at that pc.
8909 If line given (pc == 0), clear all bpts on specified line.
8910 If defaulting, clear all bpts on default line
8913 defaulting sal.pc != 0 tests to do
8918 1 0 <can't happen> */
8922 /* Find all matching breakpoints and add them to
8927 /* Are we going to delete b? */
8928 if (b->type != bp_none && !is_watchpoint (b))
8930 struct bp_location *loc = b->loc;
8931 for (; loc; loc = loc->next)
8933 int pc_match = sal.pc
8934 && (loc->pspace == sal.pspace)
8935 && (loc->address == sal.pc)
8936 && (!section_is_overlay (loc->section)
8937 || loc->section == sal.section);
8938 int line_match = ((default_match || (0 == sal.pc))
8939 && b->source_file != NULL
8940 && sal.symtab != NULL
8941 && sal.pspace == loc->pspace
8942 && strcmp (b->source_file, sal.symtab->filename) == 0
8943 && b->line_number == sal.line);
8944 if (pc_match || line_match)
8953 VEC_safe_push(breakpoint_p, found, b);
8956 /* Now go thru the 'found' chain and delete them. */
8957 if (VEC_empty(breakpoint_p, found))
8960 error (_("No breakpoint at %s."), arg);
8962 error (_("No breakpoint at this line."));
8965 if (VEC_length(breakpoint_p, found) > 1)
8966 from_tty = 1; /* Always report if deleted more than one */
8969 if (VEC_length(breakpoint_p, found) == 1)
8970 printf_unfiltered (_("Deleted breakpoint "));
8972 printf_unfiltered (_("Deleted breakpoints "));
8974 breakpoints_changed ();
8976 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
8979 printf_unfiltered ("%d ", b->number);
8980 delete_breakpoint (b);
8983 putchar_unfiltered ('\n');
8986 /* Delete breakpoint in BS if they are `delete' breakpoints and
8987 all breakpoints that are marked for deletion, whether hit or not.
8988 This is called after any breakpoint is hit, or after errors. */
8991 breakpoint_auto_delete (bpstat bs)
8993 struct breakpoint *b, *temp;
8995 for (; bs; bs = bs->next)
8996 if (bs->breakpoint_at
8997 && bs->breakpoint_at->owner
8998 && bs->breakpoint_at->owner->disposition == disp_del
9000 delete_breakpoint (bs->breakpoint_at->owner);
9002 ALL_BREAKPOINTS_SAFE (b, temp)
9004 if (b->disposition == disp_del_at_next_stop)
9005 delete_breakpoint (b);
9009 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9010 Sort elements primarily by their ADDRESS (no matter what does
9011 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9012 first bp_permanent OWNERed elements and terciarily just ensuring the array
9013 is sorted stable way despite qsort being an instable algorithm. */
9016 bp_location_compare (const void *ap, const void *bp)
9018 struct bp_location *a = *(void **) ap;
9019 struct bp_location *b = *(void **) bp;
9020 /* A and B come from existing breakpoints having non-NULL OWNER. */
9021 int a_perm = a->owner->enable_state == bp_permanent;
9022 int b_perm = b->owner->enable_state == bp_permanent;
9024 if (a->address != b->address)
9025 return (a->address > b->address) - (a->address < b->address);
9027 /* Sort permanent breakpoints first. */
9028 if (a_perm != b_perm)
9029 return (a_perm < b_perm) - (a_perm > b_perm);
9031 /* Make the user-visible order stable across GDB runs. Locations of the same
9032 breakpoint can be sorted in arbitrary order. */
9034 if (a->owner->number != b->owner->number)
9035 return (a->owner->number > b->owner->number)
9036 - (a->owner->number < b->owner->number);
9038 return (a > b) - (a < b);
9041 /* Set bp_location_placed_address_before_address_max and
9042 bp_location_shadow_len_after_address_max according to the current content of
9043 the bp_location array. */
9046 bp_location_target_extensions_update (void)
9048 struct bp_location *bl, **blp_tmp;
9050 bp_location_placed_address_before_address_max = 0;
9051 bp_location_shadow_len_after_address_max = 0;
9053 ALL_BP_LOCATIONS (bl, blp_tmp)
9055 CORE_ADDR start, end, addr;
9057 if (!bp_location_has_shadow (bl))
9060 start = bl->target_info.placed_address;
9061 end = start + bl->target_info.shadow_len;
9063 gdb_assert (bl->address >= start);
9064 addr = bl->address - start;
9065 if (addr > bp_location_placed_address_before_address_max)
9066 bp_location_placed_address_before_address_max = addr;
9068 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9070 gdb_assert (bl->address < end);
9071 addr = end - bl->address;
9072 if (addr > bp_location_shadow_len_after_address_max)
9073 bp_location_shadow_len_after_address_max = addr;
9077 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9078 into the inferior, only remove already-inserted locations that no
9079 longer should be inserted. Functions that delete a breakpoint or
9080 breakpoints should pass false, so that deleting a breakpoint
9081 doesn't have the side effect of inserting the locations of other
9082 breakpoints that are marked not-inserted, but should_be_inserted
9083 returns true on them.
9085 This behaviour is useful is situations close to tear-down -- e.g.,
9086 after an exec, while the target still has execution, but breakpoint
9087 shadows of the previous executable image should *NOT* be restored
9088 to the new image; or before detaching, where the target still has
9089 execution and wants to delete breakpoints from GDB's lists, and all
9090 breakpoints had already been removed from the inferior. */
9093 update_global_location_list (int should_insert)
9095 struct breakpoint *b;
9096 struct bp_location **locp, *loc;
9097 struct cleanup *cleanups;
9099 /* Used in the duplicates detection below. When iterating over all
9100 bp_locations, points to the first bp_location of a given address.
9101 Breakpoints and watchpoints of different types are never
9102 duplicates of each other. Keep one pointer for each type of
9103 breakpoint/watchpoint, so we only need to loop over all locations
9105 struct bp_location *bp_loc_first; /* breakpoint */
9106 struct bp_location *wp_loc_first; /* hardware watchpoint */
9107 struct bp_location *awp_loc_first; /* access watchpoint */
9108 struct bp_location *rwp_loc_first; /* read watchpoint */
9110 /* Saved former bp_location array which we compare against the newly built
9111 bp_location from the current state of ALL_BREAKPOINTS. */
9112 struct bp_location **old_location, **old_locp;
9113 unsigned old_location_count;
9115 old_location = bp_location;
9116 old_location_count = bp_location_count;
9118 bp_location_count = 0;
9119 cleanups = make_cleanup (xfree, old_location);
9122 for (loc = b->loc; loc; loc = loc->next)
9123 bp_location_count++;
9125 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
9128 for (loc = b->loc; loc; loc = loc->next)
9130 qsort (bp_location, bp_location_count, sizeof (*bp_location),
9131 bp_location_compare);
9133 bp_location_target_extensions_update ();
9135 /* Identify bp_location instances that are no longer present in the new
9136 list, and therefore should be freed. Note that it's not necessary that
9137 those locations should be removed from inferior -- if there's another
9138 location at the same address (previously marked as duplicate),
9139 we don't need to remove/insert the location.
9141 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9142 former bp_location array state respectively. */
9145 for (old_locp = old_location; old_locp < old_location + old_location_count;
9148 struct bp_location *old_loc = *old_locp;
9149 struct bp_location **loc2p;
9151 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9153 int found_object = 0;
9154 /* Tells if the location should remain inserted in the target. */
9155 int keep_in_target = 0;
9158 /* Skip LOCP entries which will definitely never be needed. Stop either
9159 at or being the one matching OLD_LOC. */
9160 while (locp < bp_location + bp_location_count
9161 && (*locp)->address < old_loc->address)
9165 (loc2p < bp_location + bp_location_count
9166 && (*loc2p)->address == old_loc->address);
9169 if (*loc2p == old_loc)
9176 /* If this location is no longer present, and inserted, look if there's
9177 maybe a new location at the same address. If so, mark that one
9178 inserted, and don't remove this one. This is needed so that we
9179 don't have a time window where a breakpoint at certain location is not
9182 if (old_loc->inserted)
9184 /* If the location is inserted now, we might have to remove it. */
9186 if (found_object && should_be_inserted (old_loc))
9188 /* The location is still present in the location list, and still
9189 should be inserted. Don't do anything. */
9194 /* The location is either no longer present, or got disabled.
9195 See if there's another location at the same address, in which
9196 case we don't need to remove this one from the target. */
9198 /* OLD_LOC comes from existing struct breakpoint. */
9199 if (breakpoint_address_is_meaningful (old_loc->owner))
9202 (loc2p < bp_location + bp_location_count
9203 && (*loc2p)->address == old_loc->address);
9206 struct bp_location *loc2 = *loc2p;
9208 if (breakpoint_locations_match (loc2, old_loc))
9210 /* For the sake of should_be_inserted.
9211 Duplicates check below will fix up this later. */
9212 loc2->duplicate = 0;
9214 /* Read watchpoint locations are switched to
9215 access watchpoints, if the former are not
9216 supported, but the latter are. */
9217 if (is_hardware_watchpoint (old_loc->owner))
9219 gdb_assert (is_hardware_watchpoint (loc2->owner));
9220 loc2->watchpoint_type = old_loc->watchpoint_type;
9223 if (loc2 != old_loc && should_be_inserted (loc2))
9226 loc2->target_info = old_loc->target_info;
9235 if (!keep_in_target)
9237 if (remove_breakpoint (old_loc, mark_uninserted))
9239 /* This is just about all we can do. We could keep this
9240 location on the global list, and try to remove it next
9241 time, but there's no particular reason why we will
9244 Note that at this point, old_loc->owner is still valid,
9245 as delete_breakpoint frees the breakpoint only
9246 after calling us. */
9247 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9248 old_loc->owner->number);
9256 if (removed && non_stop
9257 && breakpoint_address_is_meaningful (old_loc->owner)
9258 && !is_hardware_watchpoint (old_loc->owner))
9260 /* This location was removed from the target. In
9261 non-stop mode, a race condition is possible where
9262 we've removed a breakpoint, but stop events for that
9263 breakpoint are already queued and will arrive later.
9264 We apply an heuristic to be able to distinguish such
9265 SIGTRAPs from other random SIGTRAPs: we keep this
9266 breakpoint location for a bit, and will retire it
9267 after we see some number of events. The theory here
9268 is that reporting of events should, "on the average",
9269 be fair, so after a while we'll see events from all
9270 threads that have anything of interest, and no longer
9271 need to keep this breakpoint location around. We
9272 don't hold locations forever so to reduce chances of
9273 mistaking a non-breakpoint SIGTRAP for a breakpoint
9276 The heuristic failing can be disastrous on
9277 decr_pc_after_break targets.
9279 On decr_pc_after_break targets, like e.g., x86-linux,
9280 if we fail to recognize a late breakpoint SIGTRAP,
9281 because events_till_retirement has reached 0 too
9282 soon, we'll fail to do the PC adjustment, and report
9283 a random SIGTRAP to the user. When the user resumes
9284 the inferior, it will most likely immediately crash
9285 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9286 corrupted, because of being resumed e.g., in the
9287 middle of a multi-byte instruction, or skipped a
9288 one-byte instruction. This was actually seen happen
9289 on native x86-linux, and should be less rare on
9290 targets that do not support new thread events, like
9291 remote, due to the heuristic depending on
9294 Mistaking a random SIGTRAP for a breakpoint trap
9295 causes similar symptoms (PC adjustment applied when
9296 it shouldn't), but then again, playing with SIGTRAPs
9297 behind the debugger's back is asking for trouble.
9299 Since hardware watchpoint traps are always
9300 distinguishable from other traps, so we don't need to
9301 apply keep hardware watchpoint moribund locations
9302 around. We simply always ignore hardware watchpoint
9303 traps we can no longer explain. */
9305 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9306 old_loc->owner = NULL;
9308 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9311 free_bp_location (old_loc);
9315 /* Rescan breakpoints at the same address and section, marking the
9316 first one as "first" and any others as "duplicates". This is so
9317 that the bpt instruction is only inserted once. If we have a
9318 permanent breakpoint at the same place as BPT, make that one the
9319 official one, and the rest as duplicates. Permanent breakpoints
9320 are sorted first for the same address.
9322 Do the same for hardware watchpoints, but also considering the
9323 watchpoint's type (regular/access/read) and length. */
9325 bp_loc_first = NULL;
9326 wp_loc_first = NULL;
9327 awp_loc_first = NULL;
9328 rwp_loc_first = NULL;
9329 ALL_BP_LOCATIONS (loc, locp)
9331 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9332 struct breakpoint *b = loc->owner;
9333 struct bp_location **loc_first_p;
9335 if (b->enable_state == bp_disabled
9336 || b->enable_state == bp_call_disabled
9337 || b->enable_state == bp_startup_disabled
9339 || loc->shlib_disabled
9340 || !breakpoint_address_is_meaningful (b)
9341 || is_tracepoint (b))
9344 /* Permanent breakpoint should always be inserted. */
9345 if (b->enable_state == bp_permanent && ! loc->inserted)
9346 internal_error (__FILE__, __LINE__,
9347 _("allegedly permanent breakpoint is not "
9348 "actually inserted"));
9350 if (b->type == bp_hardware_watchpoint)
9351 loc_first_p = &wp_loc_first;
9352 else if (b->type == bp_read_watchpoint)
9353 loc_first_p = &rwp_loc_first;
9354 else if (b->type == bp_access_watchpoint)
9355 loc_first_p = &awp_loc_first;
9357 loc_first_p = &bp_loc_first;
9359 if (*loc_first_p == NULL
9360 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9361 || !breakpoint_locations_match (loc, *loc_first_p))
9370 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9371 && b->enable_state != bp_permanent)
9372 internal_error (__FILE__, __LINE__,
9373 _("another breakpoint was inserted on top of "
9374 "a permanent breakpoint"));
9377 if (breakpoints_always_inserted_mode () && should_insert
9378 && (have_live_inferiors ()
9379 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9380 insert_breakpoint_locations ();
9382 do_cleanups (cleanups);
9386 breakpoint_retire_moribund (void)
9388 struct bp_location *loc;
9391 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9392 if (--(loc->events_till_retirement) == 0)
9394 free_bp_location (loc);
9395 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9401 update_global_location_list_nothrow (int inserting)
9403 struct gdb_exception e;
9405 TRY_CATCH (e, RETURN_MASK_ERROR)
9406 update_global_location_list (inserting);
9409 /* Clear LOC from a BPS. */
9411 bpstat_remove_bp_location (bpstat bps, struct bp_location *loc)
9415 for (bs = bps; bs; bs = bs->next)
9416 if (bs->breakpoint_at == loc)
9418 bs->breakpoint_at = NULL;
9420 /* bs->commands will be freed later. */
9424 /* Callback for iterate_over_threads. */
9426 bpstat_remove_bp_location_callback (struct thread_info *th, void *data)
9428 struct bp_location *loc = data;
9430 bpstat_remove_bp_location (th->stop_bpstat, loc);
9434 /* Delete a breakpoint and clean up all traces of it in the data
9438 delete_breakpoint (struct breakpoint *bpt)
9440 struct breakpoint *b;
9442 gdb_assert (bpt != NULL);
9444 /* Has this bp already been deleted? This can happen because multiple
9445 lists can hold pointers to bp's. bpstat lists are especial culprits.
9447 One example of this happening is a watchpoint's scope bp. When the
9448 scope bp triggers, we notice that the watchpoint is out of scope, and
9449 delete it. We also delete its scope bp. But the scope bp is marked
9450 "auto-deleting", and is already on a bpstat. That bpstat is then
9451 checked for auto-deleting bp's, which are deleted.
9453 A real solution to this problem might involve reference counts in bp's,
9454 and/or giving them pointers back to their referencing bpstat's, and
9455 teaching delete_breakpoint to only free a bp's storage when no more
9456 references were extent. A cheaper bandaid was chosen. */
9457 if (bpt->type == bp_none)
9460 /* At least avoid this stale reference until the reference counting of
9461 breakpoints gets resolved. */
9462 if (bpt->related_breakpoint != NULL)
9464 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
9465 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
9466 bpt->related_breakpoint->related_breakpoint = NULL;
9467 bpt->related_breakpoint = NULL;
9470 observer_notify_breakpoint_deleted (bpt->number);
9472 if (breakpoint_chain == bpt)
9473 breakpoint_chain = bpt->next;
9478 b->next = bpt->next;
9482 decref_counted_command_line (&bpt->commands);
9483 xfree (bpt->cond_string);
9484 xfree (bpt->cond_exp);
9485 xfree (bpt->addr_string);
9487 xfree (bpt->exp_string);
9488 value_free (bpt->val);
9489 xfree (bpt->source_file);
9490 xfree (bpt->exec_pathname);
9491 clean_up_filters (&bpt->syscalls_to_be_caught);
9493 /* Now that breakpoint is removed from breakpoint
9494 list, update the global location list. This
9495 will remove locations that used to belong to
9496 this breakpoint. Do this before freeing
9497 the breakpoint itself, since remove_breakpoint
9498 looks at location's owner. It might be better
9499 design to have location completely self-contained,
9500 but it's not the case now. */
9501 update_global_location_list (0);
9504 /* On the chance that someone will soon try again to delete this same
9505 bp, we mark it as deleted before freeing its storage. */
9506 bpt->type = bp_none;
9512 do_delete_breakpoint_cleanup (void *b)
9514 delete_breakpoint (b);
9518 make_cleanup_delete_breakpoint (struct breakpoint *b)
9520 return make_cleanup (do_delete_breakpoint_cleanup, b);
9523 /* A callback for map_breakpoint_numbers that calls
9524 delete_breakpoint. */
9527 do_delete_breakpoint (struct breakpoint *b, void *ignore)
9529 delete_breakpoint (b);
9533 delete_command (char *arg, int from_tty)
9535 struct breakpoint *b, *temp;
9541 int breaks_to_delete = 0;
9543 /* Delete all breakpoints if no argument.
9544 Do not delete internal or call-dummy breakpoints, these
9545 have to be deleted with an explicit breakpoint number argument. */
9548 if (b->type != bp_call_dummy
9549 && b->type != bp_std_terminate
9550 && b->type != bp_shlib_event
9551 && b->type != bp_jit_event
9552 && b->type != bp_thread_event
9553 && b->type != bp_overlay_event
9554 && b->type != bp_longjmp_master
9555 && b->type != bp_std_terminate_master
9558 breaks_to_delete = 1;
9563 /* Ask user only if there are some breakpoints to delete. */
9565 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
9567 ALL_BREAKPOINTS_SAFE (b, temp)
9569 if (b->type != bp_call_dummy
9570 && b->type != bp_std_terminate
9571 && b->type != bp_shlib_event
9572 && b->type != bp_thread_event
9573 && b->type != bp_jit_event
9574 && b->type != bp_overlay_event
9575 && b->type != bp_longjmp_master
9576 && b->type != bp_std_terminate_master
9578 delete_breakpoint (b);
9583 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
9587 all_locations_are_pending (struct bp_location *loc)
9589 for (; loc; loc = loc->next)
9590 if (!loc->shlib_disabled)
9595 /* Subroutine of update_breakpoint_locations to simplify it.
9596 Return non-zero if multiple fns in list LOC have the same name.
9597 Null names are ignored. */
9600 ambiguous_names_p (struct bp_location *loc)
9602 struct bp_location *l;
9603 htab_t htab = htab_create_alloc (13, htab_hash_string,
9604 (int (*) (const void *,
9605 const void *)) streq,
9606 NULL, xcalloc, xfree);
9608 for (l = loc; l != NULL; l = l->next)
9611 const char *name = l->function_name;
9613 /* Allow for some names to be NULL, ignore them. */
9617 slot = (const char **) htab_find_slot (htab, (const void *) name,
9619 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9634 update_breakpoint_locations (struct breakpoint *b,
9635 struct symtabs_and_lines sals)
9639 struct bp_location *existing_locations = b->loc;
9641 /* If there's no new locations, and all existing locations
9642 are pending, don't do anything. This optimizes
9643 the common case where all locations are in the same
9644 shared library, that was unloaded. We'd like to
9645 retain the location, so that when the library
9646 is loaded again, we don't loose the enabled/disabled
9647 status of the individual locations. */
9648 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
9653 for (i = 0; i < sals.nelts; ++i)
9655 struct bp_location *new_loc =
9656 add_location_to_breakpoint (b, &(sals.sals[i]));
9658 /* Reparse conditions, they might contain references to the
9660 if (b->cond_string != NULL)
9662 struct gdb_exception e;
9665 TRY_CATCH (e, RETURN_MASK_ERROR)
9667 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
9672 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9673 b->number, e.message);
9674 new_loc->enabled = 0;
9678 if (b->source_file != NULL)
9679 xfree (b->source_file);
9680 if (sals.sals[i].symtab == NULL)
9681 b->source_file = NULL;
9683 b->source_file = xstrdup (sals.sals[i].symtab->filename);
9685 if (b->line_number == 0)
9686 b->line_number = sals.sals[i].line;
9689 /* Update locations of permanent breakpoints. */
9690 if (b->enable_state == bp_permanent)
9691 make_breakpoint_permanent (b);
9693 /* If possible, carry over 'disable' status from existing breakpoints. */
9695 struct bp_location *e = existing_locations;
9696 /* If there are multiple breakpoints with the same function name,
9697 e.g. for inline functions, comparing function names won't work.
9698 Instead compare pc addresses; this is just a heuristic as things
9699 may have moved, but in practice it gives the correct answer
9700 often enough until a better solution is found. */
9701 int have_ambiguous_names = ambiguous_names_p (b->loc);
9703 for (; e; e = e->next)
9705 if (!e->enabled && e->function_name)
9707 struct bp_location *l = b->loc;
9708 if (have_ambiguous_names)
9710 for (; l; l = l->next)
9711 if (breakpoint_address_match (e->pspace->aspace, e->address,
9712 l->pspace->aspace, l->address))
9720 for (; l; l = l->next)
9721 if (l->function_name
9722 && strcmp (e->function_name, l->function_name) == 0)
9732 update_global_location_list (1);
9736 /* Reset a breakpoint given it's struct breakpoint * BINT.
9737 The value we return ends up being the return value from catch_errors.
9738 Unused in this case. */
9741 breakpoint_re_set_one (void *bint)
9743 /* get past catch_errs */
9744 struct breakpoint *b = (struct breakpoint *) bint;
9746 int *not_found_ptr = ¬_found;
9747 struct symtabs_and_lines sals = {0};
9748 struct symtabs_and_lines expanded = {0};
9750 struct gdb_exception e;
9751 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
9756 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9760 case bp_hardware_breakpoint:
9762 case bp_fast_tracepoint:
9763 /* Do not attempt to re-set breakpoints disabled during startup. */
9764 if (b->enable_state == bp_startup_disabled)
9767 if (b->addr_string == NULL)
9769 /* Anything without a string can't be re-set. */
9770 delete_breakpoint (b);
9774 set_language (b->language);
9775 input_radix = b->input_radix;
9778 save_current_space_and_thread ();
9779 switch_to_program_space_and_thread (b->pspace);
9781 TRY_CATCH (e, RETURN_MASK_ERROR)
9783 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
9788 int not_found_and_ok = 0;
9789 /* For pending breakpoints, it's expected that parsing
9790 will fail until the right shared library is loaded.
9791 User has already told to create pending breakpoints and
9792 don't need extra messages. If breakpoint is in bp_shlib_disabled
9793 state, then user already saw the message about that breakpoint
9794 being disabled, and don't want to see more errors. */
9796 && (b->condition_not_parsed
9797 || (b->loc && b->loc->shlib_disabled)
9798 || b->enable_state == bp_disabled))
9799 not_found_and_ok = 1;
9801 if (!not_found_and_ok)
9803 /* We surely don't want to warn about the same breakpoint
9804 10 times. One solution, implemented here, is disable
9805 the breakpoint on error. Another solution would be to
9806 have separate 'warning emitted' flag. Since this
9807 happens only when a binary has changed, I don't know
9808 which approach is better. */
9809 b->enable_state = bp_disabled;
9810 throw_exception (e);
9816 gdb_assert (sals.nelts == 1);
9818 resolve_sal_pc (&sals.sals[0]);
9819 if (b->condition_not_parsed && s && s[0])
9821 char *cond_string = 0;
9825 find_condition_and_thread (s, sals.sals[0].pc,
9826 &cond_string, &thread, &task);
9828 b->cond_string = cond_string;
9831 b->condition_not_parsed = 0;
9834 expanded = expand_line_sal_maybe (sals.sals[0]);
9837 make_cleanup (xfree, sals.sals);
9838 update_breakpoint_locations (b, expanded);
9842 case bp_hardware_watchpoint:
9843 case bp_read_watchpoint:
9844 case bp_access_watchpoint:
9845 /* Watchpoint can be either on expression using entirely global variables,
9846 or it can be on local variables.
9848 Watchpoints of the first kind are never auto-deleted, and even persist
9849 across program restarts. Since they can use variables from shared
9850 libraries, we need to reparse expression as libraries are loaded
9853 Watchpoints on local variables can also change meaning as result
9854 of solib event. For example, if a watchpoint uses both a local and
9855 a global variables in expression, it's a local watchpoint, but
9856 unloading of a shared library will make the expression invalid.
9857 This is not a very common use case, but we still re-evaluate
9858 expression, to avoid surprises to the user.
9860 Note that for local watchpoints, we re-evaluate it only if
9861 watchpoints frame id is still valid. If it's not, it means
9862 the watchpoint is out of scope and will be deleted soon. In fact,
9863 I'm not sure we'll ever be called in this case.
9865 If a local watchpoint's frame id is still valid, then
9866 b->exp_valid_block is likewise valid, and we can safely use it.
9868 Don't do anything about disabled watchpoints, since they will
9869 be reevaluated again when enabled. */
9870 update_watchpoint (b, 1 /* reparse */);
9872 /* We needn't really do anything to reset these, since the mask
9873 that requests them is unaffected by e.g., new libraries being
9879 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
9881 /* Delete overlay event and longjmp master breakpoints; they will be
9882 reset later by breakpoint_re_set. */
9883 case bp_overlay_event:
9884 case bp_longjmp_master:
9885 case bp_std_terminate_master:
9886 delete_breakpoint (b);
9889 /* This breakpoint is special, it's set up when the inferior
9890 starts and we really don't want to touch it. */
9891 case bp_shlib_event:
9893 /* Like bp_shlib_event, this breakpoint type is special.
9894 Once it is set up, we do not want to touch it. */
9895 case bp_thread_event:
9897 /* Keep temporary breakpoints, which can be encountered when we step
9898 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9899 Otherwise these should have been blown away via the cleanup chain
9900 or by breakpoint_init_inferior when we rerun the executable. */
9903 case bp_watchpoint_scope:
9905 case bp_std_terminate:
9906 case bp_step_resume:
9908 case bp_longjmp_resume:
9913 do_cleanups (cleanups);
9917 /* Re-set all breakpoints after symbols have been re-loaded. */
9919 breakpoint_re_set (void)
9921 struct breakpoint *b, *temp;
9922 enum language save_language;
9923 int save_input_radix;
9924 struct cleanup *old_chain;
9926 save_language = current_language->la_language;
9927 save_input_radix = input_radix;
9928 old_chain = save_current_program_space ();
9930 ALL_BREAKPOINTS_SAFE (b, temp)
9932 /* Format possible error msg */
9933 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
9935 struct cleanup *cleanups = make_cleanup (xfree, message);
9936 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
9937 do_cleanups (cleanups);
9939 set_language (save_language);
9940 input_radix = save_input_radix;
9942 jit_breakpoint_re_set ();
9944 do_cleanups (old_chain);
9946 create_overlay_event_breakpoint ("_ovly_debug_event");
9947 create_longjmp_master_breakpoint ("longjmp");
9948 create_longjmp_master_breakpoint ("_longjmp");
9949 create_longjmp_master_breakpoint ("siglongjmp");
9950 create_longjmp_master_breakpoint ("_siglongjmp");
9951 create_std_terminate_master_breakpoint ("std::terminate()");
9954 /* Reset the thread number of this breakpoint:
9956 - If the breakpoint is for all threads, leave it as-is.
9957 - Else, reset it to the current thread for inferior_ptid. */
9959 breakpoint_re_set_thread (struct breakpoint *b)
9961 if (b->thread != -1)
9963 if (in_thread_list (inferior_ptid))
9964 b->thread = pid_to_thread_id (inferior_ptid);
9966 /* We're being called after following a fork. The new fork is
9967 selected as current, and unless this was a vfork will have a
9968 different program space from the original thread. Reset that
9970 b->loc->pspace = current_program_space;
9974 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9975 If from_tty is nonzero, it prints a message to that effect,
9976 which ends with a period (no newline). */
9979 set_ignore_count (int bptnum, int count, int from_tty)
9981 struct breakpoint *b;
9987 if (b->number == bptnum)
9989 if (is_tracepoint (b))
9991 if (from_tty && count != 0)
9992 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9997 b->ignore_count = count;
10001 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10003 else if (count == 1)
10004 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10007 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10010 breakpoints_changed ();
10011 observer_notify_breakpoint_modified (b->number);
10015 error (_("No breakpoint number %d."), bptnum);
10019 make_breakpoint_silent (struct breakpoint *b)
10021 /* Silence the breakpoint. */
10025 /* Command to set ignore-count of breakpoint N to COUNT. */
10028 ignore_command (char *args, int from_tty)
10034 error_no_arg (_("a breakpoint number"));
10036 num = get_number (&p);
10038 error (_("bad breakpoint number: '%s'"), args);
10040 error (_("Second argument (specified ignore-count) is missing."));
10042 set_ignore_count (num,
10043 longest_to_int (value_as_long (parse_and_eval (p))),
10046 printf_filtered ("\n");
10049 /* Call FUNCTION on each of the breakpoints
10050 whose numbers are given in ARGS. */
10053 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
10060 struct breakpoint *b, *tmp;
10064 error_no_arg (_("one or more breakpoint numbers"));
10071 num = get_number_or_range (&p1);
10074 warning (_("bad breakpoint number at or near '%s'"), p);
10078 ALL_BREAKPOINTS_SAFE (b, tmp)
10079 if (b->number == num)
10081 struct breakpoint *related_breakpoint = b->related_breakpoint;
10083 function (b, data);
10084 if (related_breakpoint)
10085 function (related_breakpoint, data);
10089 printf_unfiltered (_("No breakpoint number %d.\n"), num);
10095 static struct bp_location *
10096 find_location_by_number (char *number)
10098 char *dot = strchr (number, '.');
10102 struct breakpoint *b;
10103 struct bp_location *loc;
10108 bp_num = get_number_or_range (&p1);
10110 error (_("Bad breakpoint number '%s'"), number);
10112 ALL_BREAKPOINTS (b)
10113 if (b->number == bp_num)
10118 if (!b || b->number != bp_num)
10119 error (_("Bad breakpoint number '%s'"), number);
10122 loc_num = get_number_or_range (&p1);
10124 error (_("Bad breakpoint location number '%s'"), number);
10128 for (;loc_num && loc; --loc_num, loc = loc->next)
10131 error (_("Bad breakpoint location number '%s'"), dot+1);
10137 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10138 If from_tty is nonzero, it prints a message to that effect,
10139 which ends with a period (no newline). */
10142 disable_breakpoint (struct breakpoint *bpt)
10144 /* Never disable a watchpoint scope breakpoint; we want to
10145 hit them when we leave scope so we can delete both the
10146 watchpoint and its scope breakpoint at that time. */
10147 if (bpt->type == bp_watchpoint_scope)
10150 /* You can't disable permanent breakpoints. */
10151 if (bpt->enable_state == bp_permanent)
10154 bpt->enable_state = bp_disabled;
10156 update_global_location_list (0);
10158 observer_notify_breakpoint_modified (bpt->number);
10161 /* A callback for map_breakpoint_numbers that calls
10162 disable_breakpoint. */
10165 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
10167 disable_breakpoint (b);
10171 disable_command (char *args, int from_tty)
10173 struct breakpoint *bpt;
10176 ALL_BREAKPOINTS (bpt)
10180 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10183 case bp_breakpoint:
10184 case bp_tracepoint:
10185 case bp_fast_tracepoint:
10186 case bp_catchpoint:
10187 case bp_hardware_breakpoint:
10188 case bp_watchpoint:
10189 case bp_hardware_watchpoint:
10190 case bp_read_watchpoint:
10191 case bp_access_watchpoint:
10192 disable_breakpoint (bpt);
10196 else if (strchr (args, '.'))
10198 struct bp_location *loc = find_location_by_number (args);
10201 update_global_location_list (0);
10204 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
10208 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
10210 int target_resources_ok;
10212 if (bpt->type == bp_hardware_breakpoint)
10215 i = hw_breakpoint_used_count ();
10216 target_resources_ok =
10217 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10219 if (target_resources_ok == 0)
10220 error (_("No hardware breakpoint support in the target."));
10221 else if (target_resources_ok < 0)
10222 error (_("Hardware breakpoints used exceeds limit."));
10225 if (is_watchpoint (bpt))
10227 struct gdb_exception e;
10229 TRY_CATCH (e, RETURN_MASK_ALL)
10231 update_watchpoint (bpt, 1 /* reparse */);
10235 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10241 if (bpt->enable_state != bp_permanent)
10242 bpt->enable_state = bp_enabled;
10243 bpt->disposition = disposition;
10244 update_global_location_list (1);
10245 breakpoints_changed ();
10247 observer_notify_breakpoint_modified (bpt->number);
10252 enable_breakpoint (struct breakpoint *bpt)
10254 do_enable_breakpoint (bpt, bpt->disposition);
10257 /* A callback for map_breakpoint_numbers that calls
10258 enable_breakpoint. */
10261 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10263 enable_breakpoint (b);
10266 /* The enable command enables the specified breakpoints (or all defined
10267 breakpoints) so they once again become (or continue to be) effective
10268 in stopping the inferior. */
10271 enable_command (char *args, int from_tty)
10273 struct breakpoint *bpt;
10276 ALL_BREAKPOINTS (bpt)
10280 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10283 case bp_breakpoint:
10284 case bp_tracepoint:
10285 case bp_fast_tracepoint:
10286 case bp_catchpoint:
10287 case bp_hardware_breakpoint:
10288 case bp_watchpoint:
10289 case bp_hardware_watchpoint:
10290 case bp_read_watchpoint:
10291 case bp_access_watchpoint:
10292 enable_breakpoint (bpt);
10296 else if (strchr (args, '.'))
10298 struct bp_location *loc = find_location_by_number (args);
10301 update_global_location_list (1);
10304 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
10308 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
10310 do_enable_breakpoint (bpt, disp_disable);
10314 enable_once_command (char *args, int from_tty)
10316 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
10320 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
10322 do_enable_breakpoint (bpt, disp_del);
10326 enable_delete_command (char *args, int from_tty)
10328 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
10332 set_breakpoint_cmd (char *args, int from_tty)
10337 show_breakpoint_cmd (char *args, int from_tty)
10341 /* Invalidate last known value of any hardware watchpoint if
10342 the memory which that value represents has been written to by
10346 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
10347 const bfd_byte *data)
10349 struct breakpoint *bp;
10351 ALL_BREAKPOINTS (bp)
10352 if (bp->enable_state == bp_enabled
10353 && bp->type == bp_hardware_watchpoint
10354 && bp->val_valid && bp->val)
10356 struct bp_location *loc;
10358 for (loc = bp->loc; loc != NULL; loc = loc->next)
10359 if (loc->loc_type == bp_loc_hardware_watchpoint
10360 && loc->address + loc->length > addr
10361 && addr + len > loc->address)
10363 value_free (bp->val);
10370 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10372 struct symtabs_and_lines
10373 decode_line_spec_1 (char *string, int funfirstline)
10375 struct symtabs_and_lines sals;
10378 error (_("Empty line specification."));
10379 if (default_breakpoint_valid)
10380 sals = decode_line_1 (&string, funfirstline,
10381 default_breakpoint_symtab,
10382 default_breakpoint_line,
10383 (char ***) NULL, NULL);
10385 sals = decode_line_1 (&string, funfirstline,
10386 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
10388 error (_("Junk at end of line specification: %s"), string);
10392 /* Create and insert a raw software breakpoint at PC. Return an
10393 identifier, which should be used to remove the breakpoint later.
10394 In general, places which call this should be using something on the
10395 breakpoint chain instead; this function should be eliminated
10399 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
10400 struct address_space *aspace, CORE_ADDR pc)
10402 struct bp_target_info *bp_tgt;
10404 bp_tgt = XZALLOC (struct bp_target_info);
10406 bp_tgt->placed_address_space = aspace;
10407 bp_tgt->placed_address = pc;
10409 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
10411 /* Could not insert the breakpoint. */
10419 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10422 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
10424 struct bp_target_info *bp_tgt = bp;
10427 ret = target_remove_breakpoint (gdbarch, bp_tgt);
10433 /* One (or perhaps two) breakpoints used for software single stepping. */
10435 static void *single_step_breakpoints[2];
10436 static struct gdbarch *single_step_gdbarch[2];
10438 /* Create and insert a breakpoint for software single step. */
10441 insert_single_step_breakpoint (struct gdbarch *gdbarch,
10442 struct address_space *aspace, CORE_ADDR next_pc)
10446 if (single_step_breakpoints[0] == NULL)
10448 bpt_p = &single_step_breakpoints[0];
10449 single_step_gdbarch[0] = gdbarch;
10453 gdb_assert (single_step_breakpoints[1] == NULL);
10454 bpt_p = &single_step_breakpoints[1];
10455 single_step_gdbarch[1] = gdbarch;
10458 /* NOTE drow/2006-04-11: A future improvement to this function would be
10459 to only create the breakpoints once, and actually put them on the
10460 breakpoint chain. That would let us use set_raw_breakpoint. We could
10461 adjust the addresses each time they were needed. Doing this requires
10462 corresponding changes elsewhere where single step breakpoints are
10463 handled, however. So, for now, we use this. */
10465 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
10466 if (*bpt_p == NULL)
10467 error (_("Could not insert single-step breakpoint at %s"),
10468 paddress (gdbarch, next_pc));
10471 /* Remove and delete any breakpoints used for software single step. */
10474 remove_single_step_breakpoints (void)
10476 gdb_assert (single_step_breakpoints[0] != NULL);
10478 /* See insert_single_step_breakpoint for more about this deprecated
10480 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
10481 single_step_breakpoints[0]);
10482 single_step_gdbarch[0] = NULL;
10483 single_step_breakpoints[0] = NULL;
10485 if (single_step_breakpoints[1] != NULL)
10487 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
10488 single_step_breakpoints[1]);
10489 single_step_gdbarch[1] = NULL;
10490 single_step_breakpoints[1] = NULL;
10494 /* Check whether a software single-step breakpoint is inserted at PC. */
10497 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
10502 for (i = 0; i < 2; i++)
10504 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
10506 && breakpoint_address_match (bp_tgt->placed_address_space,
10507 bp_tgt->placed_address,
10515 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10516 non-zero otherwise. */
10518 is_syscall_catchpoint_enabled (struct breakpoint *bp)
10520 if (syscall_catchpoint_p (bp)
10521 && bp->enable_state != bp_disabled
10522 && bp->enable_state != bp_call_disabled)
10529 catch_syscall_enabled (void)
10531 struct inferior *inf = current_inferior ();
10533 return inf->total_syscalls_count != 0;
10537 catching_syscall_number (int syscall_number)
10539 struct breakpoint *bp;
10541 ALL_BREAKPOINTS (bp)
10542 if (is_syscall_catchpoint_enabled (bp))
10544 if (bp->syscalls_to_be_caught)
10548 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
10550 if (syscall_number == iter)
10560 /* Complete syscall names. Used by "catch syscall". */
10562 catch_syscall_completer (struct cmd_list_element *cmd,
10563 char *text, char *word)
10565 const char **list = get_syscall_names ();
10567 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
10570 /* Tracepoint-specific operations. */
10572 /* Set tracepoint count to NUM. */
10574 set_tracepoint_count (int num)
10576 tracepoint_count = num;
10577 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
10581 trace_command (char *arg, int from_tty)
10583 if (create_breakpoint (get_current_arch (),
10585 NULL, 0, 1 /* parse arg */,
10586 0 /* tempflag */, 0 /* hardwareflag */,
10588 0 /* Ignore count */,
10589 pending_break_support,
10593 set_tracepoint_count (breakpoint_count);
10597 ftrace_command (char *arg, int from_tty)
10599 if (create_breakpoint (get_current_arch (),
10601 NULL, 0, 1 /* parse arg */,
10602 0 /* tempflag */, 1 /* hardwareflag */,
10604 0 /* Ignore count */,
10605 pending_break_support,
10609 set_tracepoint_count (breakpoint_count);
10612 /* Set up a fake reader function that gets command lines from a linked
10613 list that was acquired during tracepoint uploading. */
10615 static struct uploaded_tp *this_utp;
10616 static int next_cmd;
10619 read_uploaded_action (void)
10623 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
10630 /* Given information about a tracepoint as recorded on a target (which
10631 can be either a live system or a trace file), attempt to create an
10632 equivalent GDB tracepoint. This is not a reliable process, since
10633 the target does not necessarily have all the information used when
10634 the tracepoint was originally defined. */
10636 struct breakpoint *
10637 create_tracepoint_from_upload (struct uploaded_tp *utp)
10639 char *addr_str, small_buf[100];
10640 struct breakpoint *tp;
10642 if (utp->at_string)
10643 addr_str = utp->at_string;
10646 /* In the absence of a source location, fall back to raw
10647 address. Since there is no way to confirm that the address
10648 means the same thing as when the trace was started, warn the
10650 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10652 sprintf (small_buf, "*%s", hex_string (utp->addr));
10653 addr_str = small_buf;
10656 /* There's not much we can do with a sequence of bytecodes. */
10657 if (utp->cond && !utp->cond_string)
10658 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10661 if (!create_breakpoint (get_current_arch (),
10663 utp->cond_string, -1, 0 /* parse cond/thread */,
10665 (utp->type == bp_fast_tracepoint) /* hardwareflag */,
10667 0 /* Ignore count */,
10668 pending_break_support,
10671 utp->enabled /* enabled */))
10674 set_tracepoint_count (breakpoint_count);
10676 /* Get the tracepoint we just created. */
10677 tp = get_tracepoint (tracepoint_count);
10678 gdb_assert (tp != NULL);
10682 sprintf (small_buf, "%d %d", utp->pass, tp->number);
10684 trace_pass_command (small_buf, 0);
10687 /* If we have uploaded versions of the original commands, set up a
10688 special-purpose "reader" function and call the usual command line
10689 reader, then pass the result to the breakpoint command-setting
10691 if (!VEC_empty (char_ptr, utp->cmd_strings))
10693 struct command_line *cmd_list;
10698 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
10700 breakpoint_set_commands (tp, cmd_list);
10702 else if (!VEC_empty (char_ptr, utp->actions)
10703 || !VEC_empty (char_ptr, utp->step_actions))
10704 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10710 /* Print information on tracepoint number TPNUM_EXP, or all if
10714 tracepoints_info (char *tpnum_exp, int from_tty)
10716 int tpnum = -1, num_printed;
10719 tpnum = parse_and_eval_long (tpnum_exp);
10721 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
10723 if (num_printed == 0)
10726 ui_out_message (uiout, 0, "No tracepoints.\n");
10728 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
10731 default_collect_info ();
10734 /* The 'enable trace' command enables tracepoints.
10735 Not supported by all targets. */
10737 enable_trace_command (char *args, int from_tty)
10739 enable_command (args, from_tty);
10742 /* The 'disable trace' command disables tracepoints.
10743 Not supported by all targets. */
10745 disable_trace_command (char *args, int from_tty)
10747 disable_command (args, from_tty);
10750 /* Remove a tracepoint (or all if no argument) */
10752 delete_trace_command (char *arg, int from_tty)
10754 struct breakpoint *b, *temp;
10760 int breaks_to_delete = 0;
10762 /* Delete all breakpoints if no argument.
10763 Do not delete internal or call-dummy breakpoints, these
10764 have to be deleted with an explicit breakpoint number argument. */
10765 ALL_TRACEPOINTS (b)
10767 if (b->number >= 0)
10769 breaks_to_delete = 1;
10774 /* Ask user only if there are some breakpoints to delete. */
10776 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
10778 ALL_BREAKPOINTS_SAFE (b, temp)
10780 if (is_tracepoint (b)
10782 delete_breakpoint (b);
10787 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
10790 /* Set passcount for tracepoint.
10792 First command argument is passcount, second is tracepoint number.
10793 If tracepoint number omitted, apply to most recently defined.
10794 Also accepts special argument "all". */
10797 trace_pass_command (char *args, int from_tty)
10799 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
10800 unsigned int count;
10803 if (args == 0 || *args == 0)
10804 error (_("passcount command requires an argument (count + optional TP num)"));
10806 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
10808 while (*args && isspace ((int) *args))
10811 if (*args && strncasecmp (args, "all", 3) == 0)
10813 args += 3; /* Skip special argument "all". */
10816 error (_("Junk at end of arguments."));
10819 t1 = get_tracepoint_by_number (&args, 1, 1);
10825 ALL_TRACEPOINTS (t2)
10826 if (t1 == (struct breakpoint *) -1 || t1 == t2)
10828 t2->pass_count = count;
10829 observer_notify_tracepoint_modified (t2->number);
10831 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10832 t2->number, count);
10834 if (! all && *args)
10835 t1 = get_tracepoint_by_number (&args, 1, 0);
10841 struct breakpoint *
10842 get_tracepoint (int num)
10844 struct breakpoint *t;
10846 ALL_TRACEPOINTS (t)
10847 if (t->number == num)
10853 /* Find the tracepoint with the given target-side number (which may be
10854 different from the tracepoint number after disconnecting and
10857 struct breakpoint *
10858 get_tracepoint_by_number_on_target (int num)
10860 struct breakpoint *t;
10862 ALL_TRACEPOINTS (t)
10863 if (t->number_on_target == num)
10869 /* Utility: parse a tracepoint number and look it up in the list.
10870 If MULTI_P is true, there might be a range of tracepoints in ARG.
10871 if OPTIONAL_P is true, then if the argument is missing, the most
10872 recent tracepoint (tracepoint_count) is returned. */
10873 struct breakpoint *
10874 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
10876 extern int tracepoint_count;
10877 struct breakpoint *t;
10879 char *instring = arg == NULL ? NULL : *arg;
10881 if (arg == NULL || *arg == NULL || ! **arg)
10884 tpnum = tracepoint_count;
10886 error_no_arg (_("tracepoint number"));
10889 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
10893 if (instring && *instring)
10894 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10897 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10901 ALL_TRACEPOINTS (t)
10902 if (t->number == tpnum)
10907 /* FIXME: if we are in the middle of a range we don't want to give
10908 a message. The current interface to get_number_or_range doesn't
10909 allow us to discover this. */
10910 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
10914 /* Save information on user settable breakpoints (watchpoints, etc) to
10915 a new script file named FILENAME. If FILTER is non-NULL, call it
10916 on each breakpoint and only include the ones for which it returns
10920 save_breakpoints (char *filename, int from_tty,
10921 int (*filter) (const struct breakpoint *))
10923 struct breakpoint *tp;
10926 struct cleanup *cleanup;
10927 struct ui_file *fp;
10928 int extra_trace_bits = 0;
10930 if (filename == 0 || *filename == 0)
10931 error (_("Argument required (file name in which to save)"));
10933 /* See if we have anything to save. */
10934 ALL_BREAKPOINTS (tp)
10936 /* Skip internal and momentary breakpoints. */
10937 if (!user_settable_breakpoint (tp))
10940 /* If we have a filter, only save the breakpoints it accepts. */
10941 if (filter && !filter (tp))
10946 if (is_tracepoint (tp))
10948 extra_trace_bits = 1;
10950 /* We can stop searching. */
10957 warning (_("Nothing to save."));
10961 pathname = tilde_expand (filename);
10962 cleanup = make_cleanup (xfree, pathname);
10963 fp = gdb_fopen (pathname, "w");
10965 error (_("Unable to open file '%s' for saving (%s)"),
10966 filename, safe_strerror (errno));
10967 make_cleanup_ui_file_delete (fp);
10969 if (extra_trace_bits)
10970 save_trace_state_variables (fp);
10972 ALL_BREAKPOINTS (tp)
10974 /* Skip internal and momentary breakpoints. */
10975 if (!user_settable_breakpoint (tp))
10978 /* If we have a filter, only save the breakpoints it accepts. */
10979 if (filter && !filter (tp))
10982 if (tp->ops != NULL)
10983 (tp->ops->print_recreate) (tp, fp);
10986 if (tp->type == bp_fast_tracepoint)
10987 fprintf_unfiltered (fp, "ftrace");
10988 else if (tp->type == bp_tracepoint)
10989 fprintf_unfiltered (fp, "trace");
10990 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
10991 fprintf_unfiltered (fp, "tbreak");
10992 else if (tp->type == bp_breakpoint)
10993 fprintf_unfiltered (fp, "break");
10994 else if (tp->type == bp_hardware_breakpoint
10995 && tp->disposition == disp_del)
10996 fprintf_unfiltered (fp, "thbreak");
10997 else if (tp->type == bp_hardware_breakpoint)
10998 fprintf_unfiltered (fp, "hbreak");
10999 else if (tp->type == bp_watchpoint)
11000 fprintf_unfiltered (fp, "watch");
11001 else if (tp->type == bp_hardware_watchpoint)
11002 fprintf_unfiltered (fp, "watch");
11003 else if (tp->type == bp_read_watchpoint)
11004 fprintf_unfiltered (fp, "rwatch");
11005 else if (tp->type == bp_access_watchpoint)
11006 fprintf_unfiltered (fp, "awatch");
11008 internal_error (__FILE__, __LINE__,
11009 _("unhandled breakpoint type %d"), (int) tp->type);
11011 if (tp->exp_string)
11012 fprintf_unfiltered (fp, " %s", tp->exp_string);
11013 else if (tp->addr_string)
11014 fprintf_unfiltered (fp, " %s", tp->addr_string);
11019 sprintf_vma (tmp, tp->loc->address);
11020 fprintf_unfiltered (fp, " *0x%s", tmp);
11024 if (tp->thread != -1)
11025 fprintf_unfiltered (fp, " thread %d", tp->thread);
11028 fprintf_unfiltered (fp, " task %d", tp->task);
11030 fprintf_unfiltered (fp, "\n");
11032 /* Note, we can't rely on tp->number for anything, as we can't
11033 assume the recreated breakpoint numbers will match. Use $bpnum
11036 if (tp->cond_string)
11037 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
11039 if (tp->ignore_count)
11040 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
11042 if (tp->pass_count)
11043 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11047 volatile struct gdb_exception ex;
11049 fprintf_unfiltered (fp, " commands\n");
11051 ui_out_redirect (uiout, fp);
11052 TRY_CATCH (ex, RETURN_MASK_ERROR)
11054 print_command_lines (uiout, tp->commands->commands, 2);
11056 ui_out_redirect (uiout, NULL);
11059 throw_exception (ex);
11061 fprintf_unfiltered (fp, " end\n");
11064 if (tp->enable_state == bp_disabled)
11065 fprintf_unfiltered (fp, "disable\n");
11067 /* If this is a multi-location breakpoint, check if the locations
11068 should be individually disabled. Watchpoint locations are
11069 special, and not user visible. */
11070 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
11072 struct bp_location *loc;
11075 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
11077 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
11081 if (extra_trace_bits && *default_collect)
11082 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
11084 do_cleanups (cleanup);
11086 printf_filtered (_("Saved to file '%s'.\n"), filename);
11089 /* The `save breakpoints' command. */
11092 save_breakpoints_command (char *args, int from_tty)
11094 save_breakpoints (args, from_tty, NULL);
11097 /* The `save tracepoints' command. */
11100 save_tracepoints_command (char *args, int from_tty)
11102 save_breakpoints (args, from_tty, is_tracepoint);
11105 /* Create a vector of all tracepoints. */
11107 VEC(breakpoint_p) *
11110 VEC(breakpoint_p) *tp_vec = 0;
11111 struct breakpoint *tp;
11113 ALL_TRACEPOINTS (tp)
11115 VEC_safe_push (breakpoint_p, tp_vec, tp);
11122 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11123 It is defined as a macro to prevent duplication.
11124 COMMAND should be a string constant containing the name of the command. */
11125 #define BREAK_ARGS_HELP(command) \
11126 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11127 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11128 If a line number is specified, break at start of code for that line.\n\
11129 If a function is specified, break at start of code for that function.\n\
11130 If an address is specified, break at that exact address.\n\
11131 With no LOCATION, uses current execution address of selected stack frame.\n\
11132 This is useful for breaking on return to a stack frame.\n\
11134 THREADNUM is the number from \"info threads\".\n\
11135 CONDITION is a boolean expression.\n\
11137 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
11139 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11141 /* List of subcommands for "catch". */
11142 static struct cmd_list_element *catch_cmdlist;
11144 /* List of subcommands for "tcatch". */
11145 static struct cmd_list_element *tcatch_cmdlist;
11147 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11148 lists, and pass some additional user data to the command function. */
11150 add_catch_command (char *name, char *docstring,
11151 void (*sfunc) (char *args, int from_tty,
11152 struct cmd_list_element *command),
11153 char **(*completer) (struct cmd_list_element *cmd,
11154 char *text, char *word),
11155 void *user_data_catch,
11156 void *user_data_tcatch)
11158 struct cmd_list_element *command;
11160 command = add_cmd (name, class_breakpoint, NULL, docstring,
11162 set_cmd_sfunc (command, sfunc);
11163 set_cmd_context (command, user_data_catch);
11164 set_cmd_completer (command, completer);
11166 command = add_cmd (name, class_breakpoint, NULL, docstring,
11168 set_cmd_sfunc (command, sfunc);
11169 set_cmd_context (command, user_data_tcatch);
11170 set_cmd_completer (command, completer);
11174 clear_syscall_counts (struct inferior *inf)
11176 inf->total_syscalls_count = 0;
11177 inf->any_syscall_count = 0;
11178 VEC_free (int, inf->syscalls_counts);
11182 save_command (char *arg, int from_tty)
11184 printf_unfiltered (_("\
11185 \"save\" must be followed by the name of a save subcommand.\n"));
11186 help_list (save_cmdlist, "save ", -1, gdb_stdout);
11190 _initialize_breakpoint (void)
11192 struct cmd_list_element *c;
11194 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
11195 observer_attach_inferior_exit (clear_syscall_counts);
11196 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
11198 breakpoint_chain = 0;
11199 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11200 before a breakpoint is set. */
11201 breakpoint_count = 0;
11203 tracepoint_count = 0;
11205 add_com ("ignore", class_breakpoint, ignore_command, _("\
11206 Set ignore-count of breakpoint number N to COUNT.\n\
11207 Usage is `ignore N COUNT'."));
11209 add_com_alias ("bc", "ignore", class_breakpoint, 1);
11211 add_com ("commands", class_breakpoint, commands_command, _("\
11212 Set commands to be executed when a breakpoint is hit.\n\
11213 Give breakpoint number as argument after \"commands\".\n\
11214 With no argument, the targeted breakpoint is the last one set.\n\
11215 The commands themselves follow starting on the next line.\n\
11216 Type a line containing \"end\" to indicate the end of them.\n\
11217 Give \"silent\" as the first line to make the breakpoint silent;\n\
11218 then no output is printed when it is hit, except what the commands print."));
11220 add_com ("condition", class_breakpoint, condition_command, _("\
11221 Specify breakpoint number N to break only if COND is true.\n\
11222 Usage is `condition N COND', where N is an integer and COND is an\n\
11223 expression to be evaluated whenever breakpoint N is reached."));
11225 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
11226 Set a temporary breakpoint.\n\
11227 Like \"break\" except the breakpoint is only temporary,\n\
11228 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11229 by using \"enable delete\" on the breakpoint number.\n\
11231 BREAK_ARGS_HELP ("tbreak")));
11232 set_cmd_completer (c, location_completer);
11234 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
11235 Set a hardware assisted breakpoint.\n\
11236 Like \"break\" except the breakpoint requires hardware support,\n\
11237 some target hardware may not have this support.\n\
11239 BREAK_ARGS_HELP ("hbreak")));
11240 set_cmd_completer (c, location_completer);
11242 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
11243 Set a temporary hardware assisted breakpoint.\n\
11244 Like \"hbreak\" except the breakpoint is only temporary,\n\
11245 so it will be deleted when hit.\n\
11247 BREAK_ARGS_HELP ("thbreak")));
11248 set_cmd_completer (c, location_completer);
11250 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
11251 Enable some breakpoints.\n\
11252 Give breakpoint numbers (separated by spaces) as arguments.\n\
11253 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11254 This is used to cancel the effect of the \"disable\" command.\n\
11255 With a subcommand you can enable temporarily."),
11256 &enablelist, "enable ", 1, &cmdlist);
11258 add_com ("ab", class_breakpoint, enable_command, _("\
11259 Enable some breakpoints.\n\
11260 Give breakpoint numbers (separated by spaces) as arguments.\n\
11261 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11262 This is used to cancel the effect of the \"disable\" command.\n\
11263 With a subcommand you can enable temporarily."));
11265 add_com_alias ("en", "enable", class_breakpoint, 1);
11267 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
11268 Enable some breakpoints.\n\
11269 Give breakpoint numbers (separated by spaces) as arguments.\n\
11270 This is used to cancel the effect of the \"disable\" command.\n\
11271 May be abbreviated to simply \"enable\".\n"),
11272 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
11274 add_cmd ("once", no_class, enable_once_command, _("\
11275 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11276 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11279 add_cmd ("delete", no_class, enable_delete_command, _("\
11280 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11281 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11284 add_cmd ("delete", no_class, enable_delete_command, _("\
11285 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11286 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11289 add_cmd ("once", no_class, enable_once_command, _("\
11290 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11291 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11294 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
11295 Disable some breakpoints.\n\
11296 Arguments are breakpoint numbers with spaces in between.\n\
11297 To disable all breakpoints, give no argument.\n\
11298 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11299 &disablelist, "disable ", 1, &cmdlist);
11300 add_com_alias ("dis", "disable", class_breakpoint, 1);
11301 add_com_alias ("disa", "disable", class_breakpoint, 1);
11303 add_com ("sb", class_breakpoint, disable_command, _("\
11304 Disable some breakpoints.\n\
11305 Arguments are breakpoint numbers with spaces in between.\n\
11306 To disable all breakpoints, give no argument.\n\
11307 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11309 add_cmd ("breakpoints", class_alias, disable_command, _("\
11310 Disable some breakpoints.\n\
11311 Arguments are breakpoint numbers with spaces in between.\n\
11312 To disable all breakpoints, give no argument.\n\
11313 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11314 This command may be abbreviated \"disable\"."),
11317 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
11318 Delete some breakpoints or auto-display expressions.\n\
11319 Arguments are breakpoint numbers with spaces in between.\n\
11320 To delete all breakpoints, give no argument.\n\
11322 Also a prefix command for deletion of other GDB objects.\n\
11323 The \"unset\" command is also an alias for \"delete\"."),
11324 &deletelist, "delete ", 1, &cmdlist);
11325 add_com_alias ("d", "delete", class_breakpoint, 1);
11326 add_com_alias ("del", "delete", class_breakpoint, 1);
11328 add_com ("db", class_breakpoint, delete_command, _("\
11329 Delete some breakpoints.\n\
11330 Arguments are breakpoint numbers with spaces in between.\n\
11331 To delete all breakpoints, give no argument.\n"));
11333 add_cmd ("breakpoints", class_alias, delete_command, _("\
11334 Delete some breakpoints or auto-display expressions.\n\
11335 Arguments are breakpoint numbers with spaces in between.\n\
11336 To delete all breakpoints, give no argument.\n\
11337 This command may be abbreviated \"delete\"."),
11340 add_com ("clear", class_breakpoint, clear_command, _("\
11341 Clear breakpoint at specified line or function.\n\
11342 Argument may be line number, function name, or \"*\" and an address.\n\
11343 If line number is specified, all breakpoints in that line are cleared.\n\
11344 If function is specified, breakpoints at beginning of function are cleared.\n\
11345 If an address is specified, breakpoints at that address are cleared.\n\
11347 With no argument, clears all breakpoints in the line that the selected frame\n\
11348 is executing in.\n\
11350 See also the \"delete\" command which clears breakpoints by number."));
11352 c = add_com ("break", class_breakpoint, break_command, _("\
11353 Set breakpoint at specified line or function.\n"
11354 BREAK_ARGS_HELP ("break")));
11355 set_cmd_completer (c, location_completer);
11357 add_com_alias ("b", "break", class_run, 1);
11358 add_com_alias ("br", "break", class_run, 1);
11359 add_com_alias ("bre", "break", class_run, 1);
11360 add_com_alias ("brea", "break", class_run, 1);
11363 add_com_alias ("ba", "break", class_breakpoint, 1);
11367 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
11368 Break in function/address or break at a line in the current file."),
11369 &stoplist, "stop ", 1, &cmdlist);
11370 add_cmd ("in", class_breakpoint, stopin_command,
11371 _("Break in function or address."), &stoplist);
11372 add_cmd ("at", class_breakpoint, stopat_command,
11373 _("Break at a line in the current file."), &stoplist);
11374 add_com ("status", class_info, breakpoints_info, _("\
11375 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11376 The \"Type\" column indicates one of:\n\
11377 \tbreakpoint - normal breakpoint\n\
11378 \twatchpoint - watchpoint\n\
11379 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11380 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11381 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11382 address and file/line number respectively.\n\
11384 Convenience variable \"$_\" and default examine address for \"x\"\n\
11385 are set to the address of the last breakpoint listed unless the command\n\
11386 is prefixed with \"server \".\n\n\
11387 Convenience variable \"$bpnum\" contains the number of the last\n\
11388 breakpoint set."));
11391 add_info ("breakpoints", breakpoints_info, _("\
11392 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11393 The \"Type\" column indicates one of:\n\
11394 \tbreakpoint - normal breakpoint\n\
11395 \twatchpoint - watchpoint\n\
11396 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11397 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11398 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11399 address and file/line number respectively.\n\
11401 Convenience variable \"$_\" and default examine address for \"x\"\n\
11402 are set to the address of the last breakpoint listed unless the command\n\
11403 is prefixed with \"server \".\n\n\
11404 Convenience variable \"$bpnum\" contains the number of the last\n\
11405 breakpoint set."));
11407 add_info_alias ("b", "breakpoints", 1);
11410 add_com ("lb", class_breakpoint, breakpoints_info, _("\
11411 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11412 The \"Type\" column indicates one of:\n\
11413 \tbreakpoint - normal breakpoint\n\
11414 \twatchpoint - watchpoint\n\
11415 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11416 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11417 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11418 address and file/line number respectively.\n\
11420 Convenience variable \"$_\" and default examine address for \"x\"\n\
11421 are set to the address of the last breakpoint listed unless the command\n\
11422 is prefixed with \"server \".\n\n\
11423 Convenience variable \"$bpnum\" contains the number of the last\n\
11424 breakpoint set."));
11426 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
11427 Status of all breakpoints, or breakpoint number NUMBER.\n\
11428 The \"Type\" column indicates one of:\n\
11429 \tbreakpoint - normal breakpoint\n\
11430 \twatchpoint - watchpoint\n\
11431 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11432 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11433 \tuntil - internal breakpoint used by the \"until\" command\n\
11434 \tfinish - internal breakpoint used by the \"finish\" command\n\
11435 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11436 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11437 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11438 address and file/line number respectively.\n\
11440 Convenience variable \"$_\" and default examine address for \"x\"\n\
11441 are set to the address of the last breakpoint listed unless the command\n\
11442 is prefixed with \"server \".\n\n\
11443 Convenience variable \"$bpnum\" contains the number of the last\n\
11445 &maintenanceinfolist);
11447 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
11448 Set catchpoints to catch events."),
11449 &catch_cmdlist, "catch ",
11450 0/*allow-unknown*/, &cmdlist);
11452 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
11453 Set temporary catchpoints to catch events."),
11454 &tcatch_cmdlist, "tcatch ",
11455 0/*allow-unknown*/, &cmdlist);
11457 /* Add catch and tcatch sub-commands. */
11458 add_catch_command ("catch", _("\
11459 Catch an exception, when caught.\n\
11460 With an argument, catch only exceptions with the given name."),
11461 catch_catch_command,
11465 add_catch_command ("throw", _("\
11466 Catch an exception, when thrown.\n\
11467 With an argument, catch only exceptions with the given name."),
11468 catch_throw_command,
11472 add_catch_command ("fork", _("Catch calls to fork."),
11473 catch_fork_command_1,
11475 (void *) (uintptr_t) catch_fork_permanent,
11476 (void *) (uintptr_t) catch_fork_temporary);
11477 add_catch_command ("vfork", _("Catch calls to vfork."),
11478 catch_fork_command_1,
11480 (void *) (uintptr_t) catch_vfork_permanent,
11481 (void *) (uintptr_t) catch_vfork_temporary);
11482 add_catch_command ("exec", _("Catch calls to exec."),
11483 catch_exec_command_1,
11487 add_catch_command ("syscall", _("\
11488 Catch system calls by their names and/or numbers.\n\
11489 Arguments say which system calls to catch. If no arguments\n\
11490 are given, every system call will be caught.\n\
11491 Arguments, if given, should be one or more system call names\n\
11492 (if your system supports that), or system call numbers."),
11493 catch_syscall_command_1,
11494 catch_syscall_completer,
11497 add_catch_command ("exception", _("\
11498 Catch Ada exceptions, when raised.\n\
11499 With an argument, catch only exceptions with the given name."),
11500 catch_ada_exception_command,
11504 add_catch_command ("assert", _("\
11505 Catch failed Ada assertions, when raised.\n\
11506 With an argument, catch only exceptions with the given name."),
11507 catch_assert_command,
11512 c = add_com ("watch", class_breakpoint, watch_command, _("\
11513 Set a watchpoint for an expression.\n\
11514 A watchpoint stops execution of your program whenever the value of\n\
11515 an expression changes."));
11516 set_cmd_completer (c, expression_completer);
11518 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
11519 Set a read watchpoint for an expression.\n\
11520 A watchpoint stops execution of your program whenever the value of\n\
11521 an expression is read."));
11522 set_cmd_completer (c, expression_completer);
11524 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
11525 Set a watchpoint for an expression.\n\
11526 A watchpoint stops execution of your program whenever the value of\n\
11527 an expression is either read or written."));
11528 set_cmd_completer (c, expression_completer);
11530 add_info ("watchpoints", watchpoints_info, _("\
11531 Status of watchpoints, or watchpoint number NUMBER."));
11535 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11536 respond to changes - contrary to the description. */
11537 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
11538 &can_use_hw_watchpoints, _("\
11539 Set debugger's willingness to use watchpoint hardware."), _("\
11540 Show debugger's willingness to use watchpoint hardware."), _("\
11541 If zero, gdb will not use hardware for new watchpoints, even if\n\
11542 such is available. (However, any hardware watchpoints that were\n\
11543 created before setting this to nonzero, will continue to use watchpoint\n\
11546 show_can_use_hw_watchpoints,
11547 &setlist, &showlist);
11549 can_use_hw_watchpoints = 1;
11551 /* Tracepoint manipulation commands. */
11553 c = add_com ("trace", class_breakpoint, trace_command, _("\
11554 Set a tracepoint at specified line or function.\n\
11556 BREAK_ARGS_HELP ("trace") "\n\
11557 Do \"help tracepoints\" for info on other tracepoint commands."));
11558 set_cmd_completer (c, location_completer);
11560 add_com_alias ("tp", "trace", class_alias, 0);
11561 add_com_alias ("tr", "trace", class_alias, 1);
11562 add_com_alias ("tra", "trace", class_alias, 1);
11563 add_com_alias ("trac", "trace", class_alias, 1);
11565 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
11566 Set a fast tracepoint at specified line or function.\n\
11568 BREAK_ARGS_HELP ("ftrace") "\n\
11569 Do \"help tracepoints\" for info on other tracepoint commands."));
11570 set_cmd_completer (c, location_completer);
11572 add_info ("tracepoints", tracepoints_info, _("\
11573 Status of tracepoints, or tracepoint number NUMBER.\n\
11574 Convenience variable \"$tpnum\" contains the number of the\n\
11575 last tracepoint set."));
11577 add_info_alias ("tp", "tracepoints", 1);
11579 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
11580 Delete specified tracepoints.\n\
11581 Arguments are tracepoint numbers, separated by spaces.\n\
11582 No argument means delete all tracepoints."),
11585 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
11586 Disable specified tracepoints.\n\
11587 Arguments are tracepoint numbers, separated by spaces.\n\
11588 No argument means disable all tracepoints."),
11590 deprecate_cmd (c, "disable");
11592 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
11593 Enable specified tracepoints.\n\
11594 Arguments are tracepoint numbers, separated by spaces.\n\
11595 No argument means enable all tracepoints."),
11597 deprecate_cmd (c, "enable");
11599 add_com ("passcount", class_trace, trace_pass_command, _("\
11600 Set the passcount for a tracepoint.\n\
11601 The trace will end when the tracepoint has been passed 'count' times.\n\
11602 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11603 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11605 add_prefix_cmd ("save", class_breakpoint, save_command,
11606 _("Save breakpoint definitions as a script."),
11607 &save_cmdlist, "save ",
11608 0/*allow-unknown*/, &cmdlist);
11610 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
11611 Save current breakpoint definitions as a script.\n\
11612 This includes all types of breakpoints (breakpoints, watchpoints, \n\
11613 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11614 session to restore them."),
11616 set_cmd_completer (c, filename_completer);
11618 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
11619 Save current tracepoint definitions as a script.\n\
11620 Use the 'source' command in another debug session to restore them."),
11622 set_cmd_completer (c, filename_completer);
11624 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
11625 deprecate_cmd (c, "save tracepoints");
11627 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
11628 Breakpoint specific settings\n\
11629 Configure various breakpoint-specific variables such as\n\
11630 pending breakpoint behavior"),
11631 &breakpoint_set_cmdlist, "set breakpoint ",
11632 0/*allow-unknown*/, &setlist);
11633 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
11634 Breakpoint specific settings\n\
11635 Configure various breakpoint-specific variables such as\n\
11636 pending breakpoint behavior"),
11637 &breakpoint_show_cmdlist, "show breakpoint ",
11638 0/*allow-unknown*/, &showlist);
11640 add_setshow_auto_boolean_cmd ("pending", no_class,
11641 &pending_break_support, _("\
11642 Set debugger's behavior regarding pending breakpoints."), _("\
11643 Show debugger's behavior regarding pending breakpoints."), _("\
11644 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11645 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11646 an error. If auto, an unrecognized breakpoint location results in a\n\
11647 user-query to see if a pending breakpoint should be created."),
11649 show_pending_break_support,
11650 &breakpoint_set_cmdlist,
11651 &breakpoint_show_cmdlist);
11653 pending_break_support = AUTO_BOOLEAN_AUTO;
11655 add_setshow_boolean_cmd ("auto-hw", no_class,
11656 &automatic_hardware_breakpoints, _("\
11657 Set automatic usage of hardware breakpoints."), _("\
11658 Show automatic usage of hardware breakpoints."), _("\
11659 If set, the debugger will automatically use hardware breakpoints for\n\
11660 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11661 a warning will be emitted for such breakpoints."),
11663 show_automatic_hardware_breakpoints,
11664 &breakpoint_set_cmdlist,
11665 &breakpoint_show_cmdlist);
11667 add_setshow_enum_cmd ("always-inserted", class_support,
11668 always_inserted_enums, &always_inserted_mode, _("\
11669 Set mode for inserting breakpoints."), _("\
11670 Show mode for inserting breakpoints."), _("\
11671 When this mode is off, breakpoints are inserted in inferior when it is\n\
11672 resumed, and removed when execution stops. When this mode is on,\n\
11673 breakpoints are inserted immediately and removed only when the user\n\
11674 deletes the breakpoint. When this mode is auto (which is the default),\n\
11675 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11676 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11677 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11678 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11680 &show_always_inserted_mode,
11681 &breakpoint_set_cmdlist,
11682 &breakpoint_show_cmdlist);
11684 automatic_hardware_breakpoints = 1;
11686 observer_attach_about_to_proceed (breakpoint_about_to_proceed);