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, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value *, int);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint *);
107 /* This function is used in gdbtk sources and thus can not be made
109 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
110 struct symtab_and_line,
113 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
115 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
119 static void describe_other_breakpoints (struct gdbarch *,
120 struct program_space *, CORE_ADDR,
121 struct obj_section *, int);
123 static int breakpoint_address_match (struct address_space *aspace1,
125 struct address_space *aspace2,
128 static int watchpoint_locations_match (struct bp_location *loc1,
129 struct bp_location *loc2);
131 static void breakpoints_info (char *, int);
133 static void watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
137 static int breakpoint_cond_eval (void *);
139 static void cleanup_executing_breakpoints (void *);
141 static void commands_command (char *, int);
143 static void condition_command (char *, int);
145 static int get_number_trailer (char **, int);
154 static int remove_breakpoint (struct bp_location *, insertion_state_t);
155 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
157 static enum print_stop_action print_it_typical (bpstat);
159 static enum print_stop_action print_bp_stop_message (bpstat bs);
161 static int watchpoint_check (void *);
163 static void maintenance_info_breakpoints (char *, int);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_used_count (enum bptype, int *);
169 static void hbreak_command (char *, int);
171 static void thbreak_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
175 static void stop_command (char *arg, int from_tty);
177 static void stopin_command (char *arg, int from_tty);
179 static void stopat_command (char *arg, int from_tty);
181 static char *ep_parse_optional_if_clause (char **arg);
183 static void catch_exception_command_1 (enum exception_event_kind ex_event,
184 char *arg, int tempflag, int from_tty);
186 static void tcatch_command (char *arg, int from_tty);
188 static void ep_skip_leading_whitespace (char **s);
190 static void detach_single_step_breakpoints (void);
192 static int single_step_breakpoint_inserted_here_p (struct address_space *,
195 static void free_bp_location (struct bp_location *loc);
196 static void incref_bp_location (struct bp_location *loc);
197 static void decref_bp_location (struct bp_location **loc);
199 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
201 static void update_global_location_list (int);
203 static void update_global_location_list_nothrow (int);
205 static int is_hardware_watchpoint (const struct breakpoint *bpt);
207 static int is_watchpoint (const struct breakpoint *bpt);
209 static void insert_breakpoint_locations (void);
211 static int syscall_catchpoint_p (struct breakpoint *b);
213 static void tracepoints_info (char *, int);
215 static void delete_trace_command (char *, int);
217 static void enable_trace_command (char *, int);
219 static void disable_trace_command (char *, int);
221 static void trace_pass_command (char *, int);
223 /* Assuming we're creating a static tracepoint, does S look like a
224 static tracepoint marker spec ("-m MARKER_ID")? */
225 #define is_marker_spec(s) \
226 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
228 /* A reference-counted struct command_line. This lets multiple
229 breakpoints share a single command list. */
230 struct counted_command_line
232 /* The reference count. */
235 /* The command list. */
236 struct command_line *commands;
239 struct command_line *
240 breakpoint_commands (struct breakpoint *b)
242 return b->commands ? b->commands->commands : NULL;
245 /* Flag indicating that a command has proceeded the inferior past the
246 current breakpoint. */
248 static int breakpoint_proceeded;
251 bpdisp_text (enum bpdisp disp)
253 /* NOTE: the following values are a part of MI protocol and
254 represent values of 'disp' field returned when inferior stops at
256 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
258 return bpdisps[(int) disp];
261 /* Prototypes for exported functions. */
262 /* If FALSE, gdb will not use hardware support for watchpoints, even
263 if such is available. */
264 static int can_use_hw_watchpoints;
267 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
268 struct cmd_list_element *c,
271 fprintf_filtered (file,
272 _("Debugger's willingness to use "
273 "watchpoint hardware is %s.\n"),
277 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
278 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
279 for unrecognized breakpoint locations.
280 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
281 static enum auto_boolean pending_break_support;
283 show_pending_break_support (struct ui_file *file, int from_tty,
284 struct cmd_list_element *c,
287 fprintf_filtered (file,
288 _("Debugger's behavior regarding "
289 "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 "
331 "mode is %s (currently %s).\n"),
333 breakpoints_always_inserted_mode () ? "on" : "off");
335 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
340 breakpoints_always_inserted_mode (void)
342 return (always_inserted_mode == always_inserted_on
343 || (always_inserted_mode == always_inserted_auto && non_stop));
346 void _initialize_breakpoint (void);
348 /* Are we executing breakpoint commands? */
349 static int executing_breakpoint_commands;
351 /* Are overlay event breakpoints enabled? */
352 static int overlay_events_enabled;
354 /* See description in breakpoint.h. */
355 int target_exact_watchpoints = 0;
357 /* Walk the following statement or block through all breakpoints.
358 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
359 current breakpoint. */
361 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
363 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
364 for (B = breakpoint_chain; \
365 B ? (TMP=B->next, 1): 0; \
368 /* Similar iterator for the low-level breakpoints. SAFE variant is
369 not provided so update_global_location_list must not be called
370 while executing the block of ALL_BP_LOCATIONS. */
372 #define ALL_BP_LOCATIONS(B,BP_TMP) \
373 for (BP_TMP = bp_location; \
374 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
377 /* Iterator for tracepoints only. */
379 #define ALL_TRACEPOINTS(B) \
380 for (B = breakpoint_chain; B; B = B->next) \
381 if (is_tracepoint (B))
383 /* Chains of all breakpoints defined. */
385 struct breakpoint *breakpoint_chain;
387 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
389 static struct bp_location **bp_location;
391 /* Number of elements of BP_LOCATION. */
393 static unsigned bp_location_count;
395 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
396 ADDRESS for the current elements of BP_LOCATION which get a valid
397 result from bp_location_has_shadow. You can use it for roughly
398 limiting the subrange of BP_LOCATION to scan for shadow bytes for
399 an address you need to read. */
401 static CORE_ADDR bp_location_placed_address_before_address_max;
403 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
404 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
405 BP_LOCATION which get a valid result from bp_location_has_shadow.
406 You can use it for roughly limiting the subrange of BP_LOCATION to
407 scan for shadow bytes for an address you need to read. */
409 static CORE_ADDR bp_location_shadow_len_after_address_max;
411 /* The locations that no longer correspond to any breakpoint, unlinked
412 from bp_location array, but for which a hit may still be reported
414 VEC(bp_location_p) *moribund_locations = NULL;
416 /* Number of last breakpoint made. */
418 static int breakpoint_count;
420 /* The value of `breakpoint_count' before the last command that
421 created breakpoints. If the last (break-like) command created more
422 than one breakpoint, then the difference between BREAKPOINT_COUNT
423 and PREV_BREAKPOINT_COUNT is more than one. */
424 static int prev_breakpoint_count;
426 /* Number of last tracepoint made. */
428 static int tracepoint_count;
430 static struct cmd_list_element *breakpoint_set_cmdlist;
431 static struct cmd_list_element *breakpoint_show_cmdlist;
432 struct cmd_list_element *save_cmdlist;
434 /* Return whether a breakpoint is an active enabled breakpoint. */
436 breakpoint_enabled (struct breakpoint *b)
438 return (b->enable_state == bp_enabled);
441 /* Set breakpoint count to NUM. */
444 set_breakpoint_count (int num)
446 prev_breakpoint_count = breakpoint_count;
447 breakpoint_count = num;
448 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
451 /* Used by `start_rbreak_breakpoints' below, to record the current
452 breakpoint count before "rbreak" creates any breakpoint. */
453 static int rbreak_start_breakpoint_count;
455 /* Called at the start an "rbreak" command to record the first
459 start_rbreak_breakpoints (void)
461 rbreak_start_breakpoint_count = breakpoint_count;
464 /* Called at the end of an "rbreak" command to record the last
468 end_rbreak_breakpoints (void)
470 prev_breakpoint_count = rbreak_start_breakpoint_count;
473 /* Used in run_command to zero the hit count when a new run starts. */
476 clear_breakpoint_hit_counts (void)
478 struct breakpoint *b;
484 /* Allocate a new counted_command_line with reference count of 1.
485 The new structure owns COMMANDS. */
487 static struct counted_command_line *
488 alloc_counted_command_line (struct command_line *commands)
490 struct counted_command_line *result
491 = xmalloc (sizeof (struct counted_command_line));
494 result->commands = commands;
498 /* Increment reference count. This does nothing if CMD is NULL. */
501 incref_counted_command_line (struct counted_command_line *cmd)
507 /* Decrement reference count. If the reference count reaches 0,
508 destroy the counted_command_line. Sets *CMDP to NULL. This does
509 nothing if *CMDP is NULL. */
512 decref_counted_command_line (struct counted_command_line **cmdp)
516 if (--(*cmdp)->refc == 0)
518 free_command_lines (&(*cmdp)->commands);
525 /* A cleanup function that calls decref_counted_command_line. */
528 do_cleanup_counted_command_line (void *arg)
530 decref_counted_command_line (arg);
533 /* Create a cleanup that calls decref_counted_command_line on the
536 static struct cleanup *
537 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
539 return make_cleanup (do_cleanup_counted_command_line, cmdp);
542 /* Default address, symtab and line to put a breakpoint at
543 for "break" command with no arg.
544 If default_breakpoint_valid is zero, the other three are
545 not valid, and "break" with no arg is an error.
547 This set by print_stack_frame, which calls set_default_breakpoint. */
549 int default_breakpoint_valid;
550 CORE_ADDR default_breakpoint_address;
551 struct symtab *default_breakpoint_symtab;
552 int default_breakpoint_line;
553 struct program_space *default_breakpoint_pspace;
556 /* *PP is a string denoting a breakpoint. Get the number of the
557 breakpoint. Advance *PP after the string and any trailing
560 Currently the string can either be a number or "$" followed by the
561 name of a convenience variable. Making it an expression wouldn't
562 work well for map_breakpoint_numbers (e.g. "4 + 5 + 6").
564 If the string is a NULL pointer, that denotes the last breakpoint.
566 TRAILER is a character which can be found after the number; most
567 commonly this is `-'. If you don't want a trailer, use \0. */
570 get_number_trailer (char **pp, int trailer)
572 int retval = 0; /* default */
576 /* Empty line means refer to the last breakpoint. */
577 return breakpoint_count;
580 /* Make a copy of the name, so we can null-terminate it
581 to pass to lookup_internalvar(). */
586 while (isalnum (*p) || *p == '_')
588 varname = (char *) alloca (p - start + 1);
589 strncpy (varname, start, p - start);
590 varname[p - start] = '\0';
591 if (get_internalvar_integer (lookup_internalvar (varname), &val))
595 printf_filtered (_("Convenience variable must "
596 "have integer value.\n"));
604 while (*p >= '0' && *p <= '9')
607 /* There is no number here. (e.g. "cond a == b"). */
609 /* Skip non-numeric token. */
610 while (*p && !isspace((int) *p))
612 /* Return zero, which caller must interpret as error. */
618 if (!(isspace (*p) || *p == '\0' || *p == trailer))
620 /* Trailing junk: return 0 and let caller print error msg. */
621 while (!(isspace (*p) || *p == '\0' || *p == trailer))
632 /* Like get_number_trailer, but don't allow a trailer. */
634 get_number (char **pp)
636 return get_number_trailer (pp, '\0');
639 /* Parse a number or a range.
640 A number will be of the form handled by get_number.
641 A range will be of the form <number1> - <number2>, and
642 will represent all the integers between number1 and number2,
645 While processing a range, this fuction is called iteratively;
646 At each call it will return the next value in the range.
648 At the beginning of parsing a range, the char pointer PP will
649 be advanced past <number1> and left pointing at the '-' token.
650 Subsequent calls will not advance the pointer until the range
651 is completed. The call that completes the range will advance
652 pointer PP past <number2>. */
655 get_number_or_range (char **pp)
657 static int last_retval, end_value;
658 static char *end_ptr;
659 static int in_range = 0;
663 /* Default case: pp is pointing either to a solo number,
664 or to the first number of a range. */
665 last_retval = get_number_trailer (pp, '-');
670 /* This is the start of a range (<number1> - <number2>).
671 Skip the '-', parse and remember the second number,
672 and also remember the end of the final token. */
676 while (isspace ((int) *end_ptr))
677 end_ptr++; /* skip white space */
678 end_value = get_number (temp);
679 if (end_value < last_retval)
681 error (_("inverted range"));
683 else if (end_value == last_retval)
685 /* Degenerate range (number1 == number2). Advance the
686 token pointer so that the range will be treated as a
695 error (_("negative value"));
698 /* pp points to the '-' that betokens a range. All
699 number-parsing has already been done. Return the next
700 integer value (one greater than the saved previous value).
701 Do not advance the token pointer 'pp' until the end of range
704 if (++last_retval == end_value)
706 /* End of range reached; advance token pointer. */
714 /* Return the breakpoint with the specified number, or NULL
715 if the number does not refer to an existing breakpoint. */
718 get_breakpoint (int num)
720 struct breakpoint *b;
723 if (b->number == num)
732 set_breakpoint_condition (struct breakpoint *b, char *exp,
735 struct bp_location *loc = b->loc;
737 for (; loc; loc = loc->next)
742 xfree (b->cond_string);
743 b->cond_string = NULL;
750 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
756 /* I don't know if it matters whether this is the string the user
757 typed in or the decompiled expression. */
758 b->cond_string = xstrdup (arg);
759 b->condition_not_parsed = 0;
761 if (is_watchpoint (b))
763 innermost_block = NULL;
765 b->cond_exp = parse_exp_1 (&arg, 0, 0);
767 error (_("Junk at end of expression"));
768 b->cond_exp_valid_block = innermost_block;
772 for (loc = b->loc; loc; loc = loc->next)
776 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
778 error (_("Junk at end of expression"));
782 breakpoints_changed ();
783 observer_notify_breakpoint_modified (b->number);
786 /* condition N EXP -- set break condition of breakpoint N to EXP. */
789 condition_command (char *arg, int from_tty)
791 struct breakpoint *b;
796 error_no_arg (_("breakpoint number"));
799 bnum = get_number (&p);
801 error (_("Bad breakpoint argument: '%s'"), arg);
804 if (b->number == bnum)
806 set_breakpoint_condition (b, p, from_tty);
810 error (_("No breakpoint number %d."), bnum);
813 /* Check that COMMAND do not contain commands that are suitable
814 only for tracepoints and not suitable for ordinary breakpoints.
815 Throw if any such commands is found. */
818 check_no_tracepoint_commands (struct command_line *commands)
820 struct command_line *c;
822 for (c = commands; c; c = c->next)
826 if (c->control_type == while_stepping_control)
827 error (_("The 'while-stepping' command can "
828 "only be used for tracepoints"));
830 for (i = 0; i < c->body_count; ++i)
831 check_no_tracepoint_commands ((c->body_list)[i]);
833 /* Not that command parsing removes leading whitespace and comment
834 lines and also empty lines. So, we only need to check for
836 if (strstr (c->line, "collect ") == c->line)
837 error (_("The 'collect' command can only be used for tracepoints"));
839 if (strstr (c->line, "teval ") == c->line)
840 error (_("The 'teval' command can only be used for tracepoints"));
844 /* Encapsulate tests for different types of tracepoints. */
847 is_tracepoint (const struct breakpoint *b)
849 return (b->type == bp_tracepoint
850 || b->type == bp_fast_tracepoint
851 || b->type == bp_static_tracepoint);
854 /* A helper function that validsates that COMMANDS are valid for a
855 breakpoint. This function will throw an exception if a problem is
859 validate_commands_for_breakpoint (struct breakpoint *b,
860 struct command_line *commands)
862 if (is_tracepoint (b))
864 /* We need to verify that each top-level element of commands is
865 valid for tracepoints, that there's at most one
866 while-stepping element, and that while-stepping's body has
867 valid tracing commands excluding nested while-stepping. */
868 struct command_line *c;
869 struct command_line *while_stepping = 0;
870 for (c = commands; c; c = c->next)
872 if (c->control_type == while_stepping_control)
874 if (b->type == bp_fast_tracepoint)
875 error (_("The 'while-stepping' command "
876 "cannot be used for fast tracepoint"));
877 else if (b->type == bp_static_tracepoint)
878 error (_("The 'while-stepping' command "
879 "cannot be used for static tracepoint"));
882 error (_("The 'while-stepping' command "
883 "can be used only once"));
890 struct command_line *c2;
892 gdb_assert (while_stepping->body_count == 1);
893 c2 = while_stepping->body_list[0];
894 for (; c2; c2 = c2->next)
896 if (c2->control_type == while_stepping_control)
897 error (_("The 'while-stepping' command cannot be nested"));
903 check_no_tracepoint_commands (commands);
907 /* Return a vector of all the static tracepoints set at ADDR. The
908 caller is responsible for releasing the vector. */
911 static_tracepoints_here (CORE_ADDR addr)
913 struct breakpoint *b;
914 VEC(breakpoint_p) *found = 0;
915 struct bp_location *loc;
918 if (b->type == bp_static_tracepoint)
920 for (loc = b->loc; loc; loc = loc->next)
921 if (loc->address == addr)
922 VEC_safe_push(breakpoint_p, found, b);
928 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
929 validate that only allowed commands are included. */
932 breakpoint_set_commands (struct breakpoint *b,
933 struct command_line *commands)
935 validate_commands_for_breakpoint (b, commands);
937 decref_counted_command_line (&b->commands);
938 b->commands = alloc_counted_command_line (commands);
939 breakpoints_changed ();
940 observer_notify_breakpoint_modified (b->number);
944 check_tracepoint_command (char *line, void *closure)
946 struct breakpoint *b = closure;
948 validate_actionline (&line, b);
951 /* A structure used to pass information through
952 map_breakpoint_numbers. */
956 /* True if the command was typed at a tty. */
959 /* The breakpoint range spec. */
962 /* Non-NULL if the body of the commands are being read from this
963 already-parsed command. */
964 struct command_line *control;
966 /* The command lines read from the user, or NULL if they have not
968 struct counted_command_line *cmd;
971 /* A callback for map_breakpoint_numbers that sets the commands for
975 do_map_commands_command (struct breakpoint *b, void *data)
977 struct commands_info *info = data;
979 if (info->cmd == NULL)
981 struct command_line *l;
983 if (info->control != NULL)
984 l = copy_command_lines (info->control->body_list[0]);
987 struct cleanup *old_chain;
990 str = xstrprintf (_("Type commands for breakpoint(s) "
991 "%s, one per line."),
994 old_chain = make_cleanup (xfree, str);
996 l = read_command_lines (str,
999 ? check_tracepoint_command : 0),
1002 do_cleanups (old_chain);
1005 info->cmd = alloc_counted_command_line (l);
1008 /* If a breakpoint was on the list more than once, we don't need to
1010 if (b->commands != info->cmd)
1012 validate_commands_for_breakpoint (b, info->cmd->commands);
1013 incref_counted_command_line (info->cmd);
1014 decref_counted_command_line (&b->commands);
1015 b->commands = info->cmd;
1016 breakpoints_changed ();
1017 observer_notify_breakpoint_modified (b->number);
1022 commands_command_1 (char *arg, int from_tty,
1023 struct command_line *control)
1025 struct cleanup *cleanups;
1026 struct commands_info info;
1028 info.from_tty = from_tty;
1029 info.control = control;
1031 /* If we read command lines from the user, then `info' will hold an
1032 extra reference to the commands that we must clean up. */
1033 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1035 if (arg == NULL || !*arg)
1037 if (breakpoint_count - prev_breakpoint_count > 1)
1038 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1040 else if (breakpoint_count > 0)
1041 arg = xstrprintf ("%d", breakpoint_count);
1044 /* So that we don't try to free the incoming non-NULL
1045 argument in the cleanup below. Mapping breakpoint
1046 numbers will fail in this case. */
1051 /* The command loop has some static state, so we need to preserve
1053 arg = xstrdup (arg);
1056 make_cleanup (xfree, arg);
1060 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1062 if (info.cmd == NULL)
1063 error (_("No breakpoints specified."));
1065 do_cleanups (cleanups);
1069 commands_command (char *arg, int from_tty)
1071 commands_command_1 (arg, from_tty, NULL);
1074 /* Like commands_command, but instead of reading the commands from
1075 input stream, takes them from an already parsed command structure.
1077 This is used by cli-script.c to DTRT with breakpoint commands
1078 that are part of if and while bodies. */
1079 enum command_control_type
1080 commands_from_control_command (char *arg, struct command_line *cmd)
1082 commands_command_1 (arg, 0, cmd);
1083 return simple_control;
1086 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1089 bp_location_has_shadow (struct bp_location *bl)
1091 if (bl->loc_type != bp_loc_software_breakpoint)
1095 if (bl->target_info.shadow_len == 0)
1096 /* bp isn't valid, or doesn't shadow memory. */
1101 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1102 by replacing any memory breakpoints with their shadowed contents.
1104 The range of shadowed area by each bp_location is:
1105 bl->address - bp_location_placed_address_before_address_max
1106 up to bl->address + bp_location_shadow_len_after_address_max
1107 The range we were requested to resolve shadows for is:
1108 memaddr ... memaddr + len
1109 Thus the safe cutoff boundaries for performance optimization are
1110 memaddr + len <= (bl->address
1111 - bp_location_placed_address_before_address_max)
1113 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1116 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1118 /* Left boundary, right boundary and median element of our binary
1120 unsigned bc_l, bc_r, bc;
1122 /* Find BC_L which is a leftmost element which may affect BUF
1123 content. It is safe to report lower value but a failure to
1124 report higher one. */
1127 bc_r = bp_location_count;
1128 while (bc_l + 1 < bc_r)
1130 struct bp_location *bl;
1132 bc = (bc_l + bc_r) / 2;
1133 bl = bp_location[bc];
1135 /* Check first BL->ADDRESS will not overflow due to the added
1136 constant. Then advance the left boundary only if we are sure
1137 the BC element can in no way affect the BUF content (MEMADDR
1138 to MEMADDR + LEN range).
1140 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1141 offset so that we cannot miss a breakpoint with its shadow
1142 range tail still reaching MEMADDR. */
1144 if ((bl->address + bp_location_shadow_len_after_address_max
1146 && (bl->address + bp_location_shadow_len_after_address_max
1153 /* Due to the binary search above, we need to make sure we pick the
1154 first location that's at BC_L's address. E.g., if there are
1155 multiple locations at the same address, BC_L may end up pointing
1156 at a duplicate location, and miss the "master"/"inserted"
1157 location. Say, given locations L1, L2 and L3 at addresses A and
1160 L1@A, L2@A, L3@B, ...
1162 BC_L could end up pointing at location L2, while the "master"
1163 location could be L1. Since the `loc->inserted' flag is only set
1164 on "master" locations, we'd forget to restore the shadow of L1
1167 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1170 /* Now do full processing of the found relevant range of elements. */
1172 for (bc = bc_l; bc < bp_location_count; bc++)
1174 struct bp_location *bl = bp_location[bc];
1175 CORE_ADDR bp_addr = 0;
1179 /* bp_location array has BL->OWNER always non-NULL. */
1180 if (bl->owner->type == bp_none)
1181 warning (_("reading through apparently deleted breakpoint #%d?"),
1184 /* Performance optimization: any futher element can no longer affect BUF
1187 if (bl->address >= bp_location_placed_address_before_address_max
1188 && memaddr + len <= (bl->address
1189 - bp_location_placed_address_before_address_max))
1192 if (!bp_location_has_shadow (bl))
1194 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1195 current_program_space->aspace, 0))
1198 /* Addresses and length of the part of the breakpoint that
1200 bp_addr = bl->target_info.placed_address;
1201 bp_size = bl->target_info.shadow_len;
1203 if (bp_addr + bp_size <= memaddr)
1204 /* The breakpoint is entirely before the chunk of memory we
1208 if (bp_addr >= memaddr + len)
1209 /* The breakpoint is entirely after the chunk of memory we are
1213 /* Offset within shadow_contents. */
1214 if (bp_addr < memaddr)
1216 /* Only copy the second part of the breakpoint. */
1217 bp_size -= memaddr - bp_addr;
1218 bptoffset = memaddr - bp_addr;
1222 if (bp_addr + bp_size > memaddr + len)
1224 /* Only copy the first part of the breakpoint. */
1225 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1228 memcpy (buf + bp_addr - memaddr,
1229 bl->target_info.shadow_contents + bptoffset, bp_size);
1234 /* Return true if BPT is of any hardware watchpoint kind. */
1237 is_hardware_watchpoint (const struct breakpoint *bpt)
1239 return (bpt->type == bp_hardware_watchpoint
1240 || bpt->type == bp_read_watchpoint
1241 || bpt->type == bp_access_watchpoint);
1244 /* Return true if BPT is of any watchpoint kind, hardware or
1248 is_watchpoint (const struct breakpoint *bpt)
1250 return (is_hardware_watchpoint (bpt)
1251 || bpt->type == bp_watchpoint);
1254 /* Assuming that B is a watchpoint: returns true if the current thread
1255 and its running state are safe to evaluate or update watchpoint B.
1256 Watchpoints on local expressions need to be evaluated in the
1257 context of the thread that was current when the watchpoint was
1258 created, and, that thread needs to be stopped to be able to select
1259 the correct frame context. Watchpoints on global expressions can
1260 be evaluated on any thread, and in any state. It is presently left
1261 to the target allowing memory accesses when threads are
1265 watchpoint_in_thread_scope (struct breakpoint *b)
1267 return (ptid_equal (b->watchpoint_thread, null_ptid)
1268 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1269 && !is_executing (inferior_ptid)));
1272 /* Assuming that B is a watchpoint:
1273 - Reparse watchpoint expression, if REPARSE is non-zero
1274 - Evaluate expression and store the result in B->val
1275 - Evaluate the condition if there is one, and store the result
1277 - Update the list of values that must be watched in B->loc.
1279 If the watchpoint disposition is disp_del_at_next_stop, then do
1280 nothing. If this is local watchpoint that is out of scope, delete
1283 Even with `set breakpoint always-inserted on' the watchpoints are
1284 removed + inserted on each stop here. Normal breakpoints must
1285 never be removed because they might be missed by a running thread
1286 when debugging in non-stop mode. On the other hand, hardware
1287 watchpoints (is_hardware_watchpoint; processed here) are specific
1288 to each LWP since they are stored in each LWP's hardware debug
1289 registers. Therefore, such LWP must be stopped first in order to
1290 be able to modify its hardware watchpoints.
1292 Hardware watchpoints must be reset exactly once after being
1293 presented to the user. It cannot be done sooner, because it would
1294 reset the data used to present the watchpoint hit to the user. And
1295 it must not be done later because it could display the same single
1296 watchpoint hit during multiple GDB stops. Note that the latter is
1297 relevant only to the hardware watchpoint types bp_read_watchpoint
1298 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1299 not user-visible - its hit is suppressed if the memory content has
1302 The following constraints influence the location where we can reset
1303 hardware watchpoints:
1305 * target_stopped_by_watchpoint and target_stopped_data_address are
1306 called several times when GDB stops.
1309 * Multiple hardware watchpoints can be hit at the same time,
1310 causing GDB to stop. GDB only presents one hardware watchpoint
1311 hit at a time as the reason for stopping, and all the other hits
1312 are presented later, one after the other, each time the user
1313 requests the execution to be resumed. Execution is not resumed
1314 for the threads still having pending hit event stored in
1315 LWP_INFO->STATUS. While the watchpoint is already removed from
1316 the inferior on the first stop the thread hit event is kept being
1317 reported from its cached value by linux_nat_stopped_data_address
1318 until the real thread resume happens after the watchpoint gets
1319 presented and thus its LWP_INFO->STATUS gets reset.
1321 Therefore the hardware watchpoint hit can get safely reset on the
1322 watchpoint removal from inferior. */
1325 update_watchpoint (struct breakpoint *b, int reparse)
1327 int within_current_scope;
1328 struct frame_id saved_frame_id;
1331 /* If this is a local watchpoint, we only want to check if the
1332 watchpoint frame is in scope if the current thread is the thread
1333 that was used to create the watchpoint. */
1334 if (!watchpoint_in_thread_scope (b))
1337 /* We don't free locations. They are stored in bp_location array
1338 and update_global_locations will eventually delete them and
1339 remove breakpoints if needed. */
1342 if (b->disposition == disp_del_at_next_stop)
1347 /* Determine if the watchpoint is within scope. */
1348 if (b->exp_valid_block == NULL)
1349 within_current_scope = 1;
1352 struct frame_info *fi;
1354 /* Save the current frame's ID so we can restore it after
1355 evaluating the watchpoint expression on its own frame. */
1356 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1357 took a frame parameter, so that we didn't have to change the
1360 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1362 fi = frame_find_by_id (b->watchpoint_frame);
1363 within_current_scope = (fi != NULL);
1364 if (within_current_scope)
1368 if (within_current_scope && reparse)
1377 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1378 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1379 /* If the meaning of expression itself changed, the old value is
1380 no longer relevant. We don't want to report a watchpoint hit
1381 to the user when the old value and the new value may actually
1382 be completely different objects. */
1383 value_free (b->val);
1387 /* Note that unlike with breakpoints, the watchpoint's condition
1388 expression is stored in the breakpoint object, not in the
1389 locations (re)created below. */
1390 if (b->cond_string != NULL)
1392 if (b->cond_exp != NULL)
1394 xfree (b->cond_exp);
1399 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1403 /* If we failed to parse the expression, for example because
1404 it refers to a global variable in a not-yet-loaded shared library,
1405 don't try to insert watchpoint. We don't automatically delete
1406 such watchpoint, though, since failure to parse expression
1407 is different from out-of-scope watchpoint. */
1408 if ( !target_has_execution)
1410 /* Without execution, memory can't change. No use to try and
1411 set watchpoint locations. The watchpoint will be reset when
1412 the target gains execution, through breakpoint_re_set. */
1414 else if (within_current_scope && b->exp)
1417 struct value *val_chain, *v, *result, *next;
1418 struct program_space *frame_pspace;
1420 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1422 /* Avoid setting b->val if it's already set. The meaning of
1423 b->val is 'the last value' user saw, and we should update
1424 it only if we reported that last value to user. As it
1425 happens, the code that reports it updates b->val directly. */
1432 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1434 /* Look at each value on the value chain. */
1435 for (v = val_chain; v; v = value_next (v))
1437 /* If it's a memory location, and GDB actually needed
1438 its contents to evaluate the expression, then we
1439 must watch it. If the first value returned is
1440 still lazy, that means an error occurred reading it;
1441 watch it anyway in case it becomes readable. */
1442 if (VALUE_LVAL (v) == lval_memory
1443 && (v == val_chain || ! value_lazy (v)))
1445 struct type *vtype = check_typedef (value_type (v));
1447 /* We only watch structs and arrays if user asked
1448 for it explicitly, never if they just happen to
1449 appear in the middle of some value chain. */
1451 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1452 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1456 struct bp_location *loc, **tmp;
1458 addr = value_address (v);
1459 len = TYPE_LENGTH (value_type (v));
1461 if (b->type == bp_read_watchpoint)
1463 else if (b->type == bp_access_watchpoint)
1466 loc = allocate_bp_location (b);
1467 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1470 loc->gdbarch = get_type_arch (value_type (v));
1472 loc->pspace = frame_pspace;
1473 loc->address = addr;
1475 loc->watchpoint_type = type;
1480 /* Change the type of breakpoint between hardware assisted or
1481 an ordinary watchpoint depending on the hardware support
1482 and free hardware slots. REPARSE is set when the inferior
1484 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1488 enum bp_loc_type loc_type;
1489 struct bp_location *bl;
1491 reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact);
1495 int i, target_resources_ok, other_type_used;
1496 enum enable_state orig_enable_state;
1498 /* We need to determine how many resources are already
1499 used for all other hardware watchpoints plus this one
1500 to see if we still have enough resources to also fit
1501 this watchpoint in as well. To guarantee the
1502 hw_watchpoint_used_count call below counts this
1503 watchpoint, make sure that it is marked as a hardware
1505 b->type = bp_hardware_watchpoint;
1507 /* hw_watchpoint_used_count ignores disabled watchpoints,
1508 and b might be disabled if we're being called from
1509 do_enable_breakpoint. */
1510 orig_enable_state = b->enable_state;
1511 b->enable_state = bp_enabled;
1513 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1516 b->enable_state = orig_enable_state;
1518 target_resources_ok = target_can_use_hardware_watchpoint
1519 (bp_hardware_watchpoint, i, other_type_used);
1520 if (target_resources_ok <= 0)
1521 b->type = bp_watchpoint;
1524 b->type = bp_watchpoint;
1526 loc_type = (b->type == bp_watchpoint? bp_loc_other
1527 : bp_loc_hardware_watchpoint);
1528 for (bl = b->loc; bl; bl = bl->next)
1529 bl->loc_type = loc_type;
1532 for (v = val_chain; v; v = next)
1534 next = value_next (v);
1539 /* If a software watchpoint is not watching any memory, then the
1540 above left it without any location set up. But,
1541 bpstat_stop_status requires a location to be able to report
1542 stops, so make sure there's at least a dummy one. */
1543 if (b->type == bp_watchpoint && b->loc == NULL)
1545 b->loc = allocate_bp_location (b);
1546 b->loc->pspace = frame_pspace;
1547 b->loc->address = -1;
1548 b->loc->length = -1;
1549 b->loc->watchpoint_type = -1;
1552 else if (!within_current_scope)
1554 printf_filtered (_("\
1555 Watchpoint %d deleted because the program has left the block\n\
1556 in which its expression is valid.\n"),
1558 if (b->related_breakpoint)
1560 b->related_breakpoint->disposition = disp_del_at_next_stop;
1561 b->related_breakpoint->related_breakpoint = NULL;
1562 b->related_breakpoint= NULL;
1564 b->disposition = disp_del_at_next_stop;
1567 /* Restore the selected frame. */
1569 select_frame (frame_find_by_id (saved_frame_id));
1573 /* Returns 1 iff breakpoint location should be
1574 inserted in the inferior. */
1576 should_be_inserted (struct bp_location *bl)
1578 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1581 if (bl->owner->disposition == disp_del_at_next_stop)
1584 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1587 /* This is set for example, when we're attached to the parent of a
1588 vfork, and have detached from the child. The child is running
1589 free, and we expect it to do an exec or exit, at which point the
1590 OS makes the parent schedulable again (and the target reports
1591 that the vfork is done). Until the child is done with the shared
1592 memory region, do not insert breakpoints in the parent, otherwise
1593 the child could still trip on the parent's breakpoints. Since
1594 the parent is blocked anyway, it won't miss any breakpoint. */
1595 if (bl->pspace->breakpoints_not_allowed)
1598 /* Tracepoints are inserted by the target at a time of its choosing,
1600 if (is_tracepoint (bl->owner))
1606 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1607 location. Any error messages are printed to TMP_ERROR_STREAM; and
1608 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1610 NOTE drow/2003-09-09: This routine could be broken down to an
1611 object-style method for each breakpoint or catchpoint type. */
1613 insert_bp_location (struct bp_location *bl,
1614 struct ui_file *tmp_error_stream,
1615 int *disabled_breaks,
1616 int *hw_breakpoint_error)
1620 if (!should_be_inserted (bl) || bl->inserted)
1623 /* Initialize the target-specific information. */
1624 memset (&bl->target_info, 0, sizeof (bl->target_info));
1625 bl->target_info.placed_address = bl->address;
1626 bl->target_info.placed_address_space = bl->pspace->aspace;
1628 if (bl->loc_type == bp_loc_software_breakpoint
1629 || bl->loc_type == bp_loc_hardware_breakpoint)
1631 if (bl->owner->type != bp_hardware_breakpoint)
1633 /* If the explicitly specified breakpoint type
1634 is not hardware breakpoint, check the memory map to see
1635 if the breakpoint address is in read only memory or not.
1637 Two important cases are:
1638 - location type is not hardware breakpoint, memory
1639 is readonly. We change the type of the location to
1640 hardware breakpoint.
1641 - location type is hardware breakpoint, memory is
1642 read-write. This means we've previously made the
1643 location hardware one, but then the memory map changed,
1646 When breakpoints are removed, remove_breakpoints will use
1647 location types we've just set here, the only possible
1648 problem is that memory map has changed during running
1649 program, but it's not going to work anyway with current
1651 struct mem_region *mr
1652 = lookup_mem_region (bl->target_info.placed_address);
1656 if (automatic_hardware_breakpoints)
1658 enum bp_loc_type new_type;
1660 if (mr->attrib.mode != MEM_RW)
1661 new_type = bp_loc_hardware_breakpoint;
1663 new_type = bp_loc_software_breakpoint;
1665 if (new_type != bl->loc_type)
1667 static int said = 0;
1669 bl->loc_type = new_type;
1672 fprintf_filtered (gdb_stdout,
1673 _("Note: automatically using "
1674 "hardware breakpoints for "
1675 "read-only addresses.\n"));
1680 else if (bl->loc_type == bp_loc_software_breakpoint
1681 && mr->attrib.mode != MEM_RW)
1682 warning (_("cannot set software breakpoint "
1683 "at readonly address %s"),
1684 paddress (bl->gdbarch, bl->address));
1688 /* First check to see if we have to handle an overlay. */
1689 if (overlay_debugging == ovly_off
1690 || bl->section == NULL
1691 || !(section_is_overlay (bl->section)))
1693 /* No overlay handling: just set the breakpoint. */
1695 if (bl->loc_type == bp_loc_hardware_breakpoint)
1696 val = target_insert_hw_breakpoint (bl->gdbarch,
1699 val = target_insert_breakpoint (bl->gdbarch,
1704 /* This breakpoint is in an overlay section.
1705 Shall we set a breakpoint at the LMA? */
1706 if (!overlay_events_enabled)
1708 /* Yes -- overlay event support is not active,
1709 so we must try to set a breakpoint at the LMA.
1710 This will not work for a hardware breakpoint. */
1711 if (bl->loc_type == bp_loc_hardware_breakpoint)
1712 warning (_("hardware breakpoint %d not supported in overlay!"),
1716 CORE_ADDR addr = overlay_unmapped_address (bl->address,
1718 /* Set a software (trap) breakpoint at the LMA. */
1719 bl->overlay_target_info = bl->target_info;
1720 bl->overlay_target_info.placed_address = addr;
1721 val = target_insert_breakpoint (bl->gdbarch,
1722 &bl->overlay_target_info);
1724 fprintf_unfiltered (tmp_error_stream,
1725 "Overlay breakpoint %d "
1726 "failed: in ROM?\n",
1730 /* Shall we set a breakpoint at the VMA? */
1731 if (section_is_mapped (bl->section))
1733 /* Yes. This overlay section is mapped into memory. */
1734 if (bl->loc_type == bp_loc_hardware_breakpoint)
1735 val = target_insert_hw_breakpoint (bl->gdbarch,
1738 val = target_insert_breakpoint (bl->gdbarch,
1743 /* No. This breakpoint will not be inserted.
1744 No error, but do not mark the bp as 'inserted'. */
1751 /* Can't set the breakpoint. */
1752 if (solib_name_from_address (bl->pspace, bl->address))
1754 /* See also: disable_breakpoints_in_shlibs. */
1756 bl->shlib_disabled = 1;
1757 if (!*disabled_breaks)
1759 fprintf_unfiltered (tmp_error_stream,
1760 "Cannot insert breakpoint %d.\n",
1762 fprintf_unfiltered (tmp_error_stream,
1763 "Temporarily disabling shared "
1764 "library breakpoints:\n");
1766 *disabled_breaks = 1;
1767 fprintf_unfiltered (tmp_error_stream,
1768 "breakpoint #%d\n", bl->owner->number);
1772 if (bl->loc_type == bp_loc_hardware_breakpoint)
1774 *hw_breakpoint_error = 1;
1775 fprintf_unfiltered (tmp_error_stream,
1776 "Cannot insert hardware "
1782 fprintf_unfiltered (tmp_error_stream,
1783 "Cannot insert breakpoint %d.\n",
1785 fprintf_filtered (tmp_error_stream,
1786 "Error accessing memory address ");
1787 fputs_filtered (paddress (bl->gdbarch, bl->address),
1789 fprintf_filtered (tmp_error_stream, ": %s.\n",
1790 safe_strerror (val));
1801 else if (bl->loc_type == bp_loc_hardware_watchpoint
1802 /* NOTE drow/2003-09-08: This state only exists for removing
1803 watchpoints. It's not clear that it's necessary... */
1804 && bl->owner->disposition != disp_del_at_next_stop)
1806 gdb_assert (bl->owner->ops != NULL
1807 && bl->owner->ops->insert_location != NULL);
1809 val = bl->owner->ops->insert_location (bl);
1811 /* If trying to set a read-watchpoint, and it turns out it's not
1812 supported, try emulating one with an access watchpoint. */
1813 if (val == 1 && bl->watchpoint_type == hw_read)
1815 struct bp_location *loc, **loc_temp;
1817 /* But don't try to insert it, if there's already another
1818 hw_access location that would be considered a duplicate
1820 ALL_BP_LOCATIONS (loc, loc_temp)
1822 && loc->watchpoint_type == hw_access
1823 && watchpoint_locations_match (bl, loc))
1827 bl->target_info = loc->target_info;
1828 bl->watchpoint_type = hw_access;
1835 bl->watchpoint_type = hw_access;
1836 val = bl->owner->ops->insert_location (bl);
1839 /* Back to the original value. */
1840 bl->watchpoint_type = hw_read;
1844 bl->inserted = (val == 0);
1847 else if (bl->owner->type == bp_catchpoint)
1849 gdb_assert (bl->owner->ops != NULL
1850 && bl->owner->ops->insert_location != NULL);
1852 val = bl->owner->ops->insert_location (bl);
1855 bl->owner->enable_state = bp_disabled;
1859 Error inserting catchpoint %d: Your system does not support this type\n\
1860 of catchpoint."), bl->owner->number);
1862 warning (_("Error inserting catchpoint %d."), bl->owner->number);
1865 bl->inserted = (val == 0);
1867 /* We've already printed an error message if there was a problem
1868 inserting this catchpoint, and we've disabled the catchpoint,
1869 so just return success. */
1876 /* This function is called when program space PSPACE is about to be
1877 deleted. It takes care of updating breakpoints to not reference
1881 breakpoint_program_space_exit (struct program_space *pspace)
1883 struct breakpoint *b, *b_temp;
1884 struct bp_location *loc, **loc_temp;
1886 /* Remove any breakpoint that was set through this program space. */
1887 ALL_BREAKPOINTS_SAFE (b, b_temp)
1889 if (b->pspace == pspace)
1890 delete_breakpoint (b);
1893 /* Breakpoints set through other program spaces could have locations
1894 bound to PSPACE as well. Remove those. */
1895 ALL_BP_LOCATIONS (loc, loc_temp)
1897 struct bp_location *tmp;
1899 if (loc->pspace == pspace)
1901 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1902 if (loc->owner->loc == loc)
1903 loc->owner->loc = loc->next;
1905 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1906 if (tmp->next == loc)
1908 tmp->next = loc->next;
1914 /* Now update the global location list to permanently delete the
1915 removed locations above. */
1916 update_global_location_list (0);
1919 /* Make sure all breakpoints are inserted in inferior.
1920 Throws exception on any error.
1921 A breakpoint that is already inserted won't be inserted
1922 again, so calling this function twice is safe. */
1924 insert_breakpoints (void)
1926 struct breakpoint *bpt;
1928 ALL_BREAKPOINTS (bpt)
1929 if (is_hardware_watchpoint (bpt))
1930 update_watchpoint (bpt, 0 /* don't reparse. */);
1932 update_global_location_list (1);
1934 /* update_global_location_list does not insert breakpoints when
1935 always_inserted_mode is not enabled. Explicitly insert them
1937 if (!breakpoints_always_inserted_mode ())
1938 insert_breakpoint_locations ();
1941 /* insert_breakpoints is used when starting or continuing the program.
1942 remove_breakpoints is used when the program stops.
1943 Both return zero if successful,
1944 or an `errno' value if could not write the inferior. */
1947 insert_breakpoint_locations (void)
1949 struct breakpoint *bpt;
1950 struct bp_location *bl, **blp_tmp;
1953 int disabled_breaks = 0;
1954 int hw_breakpoint_error = 0;
1956 struct ui_file *tmp_error_stream = mem_fileopen ();
1957 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1959 /* Explicitly mark the warning -- this will only be printed if
1960 there was an error. */
1961 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1963 save_current_space_and_thread ();
1965 ALL_BP_LOCATIONS (bl, blp_tmp)
1967 if (!should_be_inserted (bl) || bl->inserted)
1970 /* There is no point inserting thread-specific breakpoints if
1971 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1972 has BL->OWNER always non-NULL. */
1973 if (bl->owner->thread != -1
1974 && !valid_thread_id (bl->owner->thread))
1977 switch_to_program_space_and_thread (bl->pspace);
1979 /* For targets that support global breakpoints, there's no need
1980 to select an inferior to insert breakpoint to. In fact, even
1981 if we aren't attached to any process yet, we should still
1982 insert breakpoints. */
1983 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1984 && ptid_equal (inferior_ptid, null_ptid))
1987 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
1988 &hw_breakpoint_error);
1993 /* If we failed to insert all locations of a watchpoint, remove
1994 them, as half-inserted watchpoint is of limited use. */
1995 ALL_BREAKPOINTS (bpt)
1997 int some_failed = 0;
1998 struct bp_location *loc;
2000 if (!is_hardware_watchpoint (bpt))
2003 if (!breakpoint_enabled (bpt))
2006 if (bpt->disposition == disp_del_at_next_stop)
2009 for (loc = bpt->loc; loc; loc = loc->next)
2010 if (!loc->inserted && should_be_inserted (loc))
2017 for (loc = bpt->loc; loc; loc = loc->next)
2019 remove_breakpoint (loc, mark_uninserted);
2021 hw_breakpoint_error = 1;
2022 fprintf_unfiltered (tmp_error_stream,
2023 "Could not insert hardware watchpoint %d.\n",
2031 /* If a hardware breakpoint or watchpoint was inserted, add a
2032 message about possibly exhausted resources. */
2033 if (hw_breakpoint_error)
2035 fprintf_unfiltered (tmp_error_stream,
2036 "Could not insert hardware breakpoints:\n\
2037 You may have requested too many hardware breakpoints/watchpoints.\n");
2039 target_terminal_ours_for_output ();
2040 error_stream (tmp_error_stream);
2043 do_cleanups (cleanups);
2047 remove_breakpoints (void)
2049 struct bp_location *bl, **blp_tmp;
2052 ALL_BP_LOCATIONS (bl, blp_tmp)
2055 val |= remove_breakpoint (bl, mark_uninserted);
2060 /* Remove breakpoints of process PID. */
2063 remove_breakpoints_pid (int pid)
2065 struct bp_location *bl, **blp_tmp;
2067 struct inferior *inf = find_inferior_pid (pid);
2069 ALL_BP_LOCATIONS (bl, blp_tmp)
2071 if (bl->pspace != inf->pspace)
2076 val = remove_breakpoint (bl, mark_uninserted);
2085 remove_hw_watchpoints (void)
2087 struct bp_location *bl, **blp_tmp;
2090 ALL_BP_LOCATIONS (bl, blp_tmp)
2092 if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint)
2093 val |= remove_breakpoint (bl, mark_uninserted);
2099 reattach_breakpoints (int pid)
2101 struct cleanup *old_chain;
2102 struct bp_location *bl, **blp_tmp;
2104 struct ui_file *tmp_error_stream = mem_fileopen ();
2105 int dummy1 = 0, dummy2 = 0;
2106 struct inferior *inf;
2107 struct thread_info *tp;
2109 tp = any_live_thread_of_process (pid);
2113 inf = find_inferior_pid (pid);
2114 old_chain = save_inferior_ptid ();
2116 inferior_ptid = tp->ptid;
2118 make_cleanup_ui_file_delete (tmp_error_stream);
2120 ALL_BP_LOCATIONS (bl, blp_tmp)
2122 if (bl->pspace != inf->pspace)
2128 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2131 do_cleanups (old_chain);
2136 do_cleanups (old_chain);
2140 static int internal_breakpoint_number = -1;
2142 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2143 If INTERNAL is non-zero, the breakpoint number will be populated
2144 from internal_breakpoint_number and that variable decremented.
2145 Otherwis the breakpoint number will be populated from
2146 breakpoint_count and that value incremented. Internal breakpoints
2147 do not set the internal var bpnum. */
2149 set_breakpoint_number (int internal, struct breakpoint *b)
2152 b->number = internal_breakpoint_number--;
2155 set_breakpoint_count (breakpoint_count + 1);
2156 b->number = breakpoint_count;
2160 static struct breakpoint *
2161 create_internal_breakpoint (struct gdbarch *gdbarch,
2162 CORE_ADDR address, enum bptype type)
2164 struct symtab_and_line sal;
2165 struct breakpoint *b;
2167 init_sal (&sal); /* Initialize to zeroes. */
2170 sal.section = find_pc_overlay (sal.pc);
2171 sal.pspace = current_program_space;
2173 b = set_raw_breakpoint (gdbarch, sal, type);
2174 b->number = internal_breakpoint_number--;
2175 b->disposition = disp_donttouch;
2181 create_overlay_event_breakpoint (char *func_name)
2183 struct objfile *objfile;
2185 ALL_OBJFILES (objfile)
2187 struct breakpoint *b;
2188 struct minimal_symbol *m;
2190 m = lookup_minimal_symbol_text (func_name, objfile);
2194 b = create_internal_breakpoint (get_objfile_arch (objfile),
2195 SYMBOL_VALUE_ADDRESS (m),
2197 b->addr_string = xstrdup (func_name);
2199 if (overlay_debugging == ovly_auto)
2201 b->enable_state = bp_enabled;
2202 overlay_events_enabled = 1;
2206 b->enable_state = bp_disabled;
2207 overlay_events_enabled = 0;
2210 update_global_location_list (1);
2214 create_longjmp_master_breakpoint (char *func_name)
2216 struct program_space *pspace;
2217 struct objfile *objfile;
2218 struct cleanup *old_chain;
2220 old_chain = save_current_program_space ();
2222 ALL_PSPACES (pspace)
2223 ALL_OBJFILES (objfile)
2225 struct breakpoint *b;
2226 struct minimal_symbol *m;
2228 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2231 set_current_program_space (pspace);
2233 m = lookup_minimal_symbol_text (func_name, objfile);
2237 b = create_internal_breakpoint (get_objfile_arch (objfile),
2238 SYMBOL_VALUE_ADDRESS (m),
2240 b->addr_string = xstrdup (func_name);
2241 b->enable_state = bp_disabled;
2243 update_global_location_list (1);
2245 do_cleanups (old_chain);
2248 /* Create a master std::terminate breakpoint. The actual function
2249 looked for is named FUNC_NAME. */
2251 create_std_terminate_master_breakpoint (const char *func_name)
2253 struct program_space *pspace;
2254 struct objfile *objfile;
2255 struct cleanup *old_chain;
2257 old_chain = save_current_program_space ();
2259 ALL_PSPACES (pspace)
2260 ALL_OBJFILES (objfile)
2262 struct breakpoint *b;
2263 struct minimal_symbol *m;
2265 set_current_program_space (pspace);
2267 m = lookup_minimal_symbol (func_name, NULL, objfile);
2268 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2269 && MSYMBOL_TYPE (m) != mst_file_text))
2272 b = create_internal_breakpoint (get_objfile_arch (objfile),
2273 SYMBOL_VALUE_ADDRESS (m),
2274 bp_std_terminate_master);
2275 b->addr_string = xstrdup (func_name);
2276 b->enable_state = bp_disabled;
2278 update_global_location_list (1);
2280 do_cleanups (old_chain);
2283 /* Install a master breakpoint on the unwinder's debug hook. */
2286 create_exception_master_breakpoint (void)
2288 struct objfile *objfile;
2290 ALL_OBJFILES (objfile)
2292 struct minimal_symbol *debug_hook;
2294 debug_hook = lookup_minimal_symbol ("_Unwind_DebugHook", NULL, objfile);
2295 if (debug_hook != NULL)
2297 struct breakpoint *b;
2298 CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (debug_hook);
2299 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2301 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
2303 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master);
2304 b->addr_string = xstrdup ("_Unwind_DebugHook");
2305 b->enable_state = bp_disabled;
2309 update_global_location_list (1);
2313 update_breakpoints_after_exec (void)
2315 struct breakpoint *b, *b_tmp;
2316 struct bp_location *bploc, **bplocp_tmp;
2318 /* We're about to delete breakpoints from GDB's lists. If the
2319 INSERTED flag is true, GDB will try to lift the breakpoints by
2320 writing the breakpoints' "shadow contents" back into memory. The
2321 "shadow contents" are NOT valid after an exec, so GDB should not
2322 do that. Instead, the target is responsible from marking
2323 breakpoints out as soon as it detects an exec. We don't do that
2324 here instead, because there may be other attempts to delete
2325 breakpoints after detecting an exec and before reaching here. */
2326 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2327 if (bploc->pspace == current_program_space)
2328 gdb_assert (!bploc->inserted);
2330 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2332 if (b->pspace != current_program_space)
2335 /* Solib breakpoints must be explicitly reset after an exec(). */
2336 if (b->type == bp_shlib_event)
2338 delete_breakpoint (b);
2342 /* JIT breakpoints must be explicitly reset after an exec(). */
2343 if (b->type == bp_jit_event)
2345 delete_breakpoint (b);
2349 /* Thread event breakpoints must be set anew after an exec(),
2350 as must overlay event and longjmp master breakpoints. */
2351 if (b->type == bp_thread_event || b->type == bp_overlay_event
2352 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
2353 || b->type == bp_exception_master)
2355 delete_breakpoint (b);
2359 /* Step-resume breakpoints are meaningless after an exec(). */
2360 if (b->type == bp_step_resume)
2362 delete_breakpoint (b);
2366 /* Longjmp and longjmp-resume breakpoints are also meaningless
2368 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
2369 || b->type == bp_exception || b->type == bp_exception_resume)
2371 delete_breakpoint (b);
2375 if (b->type == bp_catchpoint)
2377 /* For now, none of the bp_catchpoint breakpoints need to
2378 do anything at this point. In the future, if some of
2379 the catchpoints need to something, we will need to add
2380 a new method, and call this method from here. */
2384 /* bp_finish is a special case. The only way we ought to be able
2385 to see one of these when an exec() has happened, is if the user
2386 caught a vfork, and then said "finish". Ordinarily a finish just
2387 carries them to the call-site of the current callee, by setting
2388 a temporary bp there and resuming. But in this case, the finish
2389 will carry them entirely through the vfork & exec.
2391 We don't want to allow a bp_finish to remain inserted now. But
2392 we can't safely delete it, 'cause finish_command has a handle to
2393 the bp on a bpstat, and will later want to delete it. There's a
2394 chance (and I've seen it happen) that if we delete the bp_finish
2395 here, that its storage will get reused by the time finish_command
2396 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2397 We really must allow finish_command to delete a bp_finish.
2399 In the absense of a general solution for the "how do we know
2400 it's safe to delete something others may have handles to?"
2401 problem, what we'll do here is just uninsert the bp_finish, and
2402 let finish_command delete it.
2404 (We know the bp_finish is "doomed" in the sense that it's
2405 momentary, and will be deleted as soon as finish_command sees
2406 the inferior stopped. So it doesn't matter that the bp's
2407 address is probably bogus in the new a.out, unlike e.g., the
2408 solib breakpoints.) */
2410 if (b->type == bp_finish)
2415 /* Without a symbolic address, we have little hope of the
2416 pre-exec() address meaning the same thing in the post-exec()
2418 if (b->addr_string == NULL)
2420 delete_breakpoint (b);
2424 /* FIXME what about longjmp breakpoints? Re-create them here? */
2425 create_overlay_event_breakpoint ("_ovly_debug_event");
2426 create_longjmp_master_breakpoint ("longjmp");
2427 create_longjmp_master_breakpoint ("_longjmp");
2428 create_longjmp_master_breakpoint ("siglongjmp");
2429 create_longjmp_master_breakpoint ("_siglongjmp");
2430 create_std_terminate_master_breakpoint ("std::terminate()");
2431 create_exception_master_breakpoint ();
2435 detach_breakpoints (int pid)
2437 struct bp_location *bl, **blp_tmp;
2439 struct cleanup *old_chain = save_inferior_ptid ();
2440 struct inferior *inf = current_inferior ();
2442 if (pid == PIDGET (inferior_ptid))
2443 error (_("Cannot detach breakpoints of inferior_ptid"));
2445 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2446 inferior_ptid = pid_to_ptid (pid);
2447 ALL_BP_LOCATIONS (bl, blp_tmp)
2449 if (bl->pspace != inf->pspace)
2453 val |= remove_breakpoint_1 (bl, mark_inserted);
2456 /* Detach single-step breakpoints as well. */
2457 detach_single_step_breakpoints ();
2459 do_cleanups (old_chain);
2463 /* Remove the breakpoint location BL from the current address space.
2464 Note that this is used to detach breakpoints from a child fork.
2465 When we get here, the child isn't in the inferior list, and neither
2466 do we have objects to represent its address space --- we should
2467 *not* look at bl->pspace->aspace here. */
2470 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
2474 /* BL is never in moribund_locations by our callers. */
2475 gdb_assert (bl->owner != NULL);
2477 if (bl->owner->enable_state == bp_permanent)
2478 /* Permanent breakpoints cannot be inserted or removed. */
2481 /* The type of none suggests that owner is actually deleted.
2482 This should not ever happen. */
2483 gdb_assert (bl->owner->type != bp_none);
2485 if (bl->loc_type == bp_loc_software_breakpoint
2486 || bl->loc_type == bp_loc_hardware_breakpoint)
2488 /* "Normal" instruction breakpoint: either the standard
2489 trap-instruction bp (bp_breakpoint), or a
2490 bp_hardware_breakpoint. */
2492 /* First check to see if we have to handle an overlay. */
2493 if (overlay_debugging == ovly_off
2494 || bl->section == NULL
2495 || !(section_is_overlay (bl->section)))
2497 /* No overlay handling: just remove the breakpoint. */
2499 if (bl->loc_type == bp_loc_hardware_breakpoint)
2500 val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
2502 val = target_remove_breakpoint (bl->gdbarch, &bl->target_info);
2506 /* This breakpoint is in an overlay section.
2507 Did we set a breakpoint at the LMA? */
2508 if (!overlay_events_enabled)
2510 /* Yes -- overlay event support is not active, so we
2511 should have set a breakpoint at the LMA. Remove it.
2513 /* Ignore any failures: if the LMA is in ROM, we will
2514 have already warned when we failed to insert it. */
2515 if (bl->loc_type == bp_loc_hardware_breakpoint)
2516 target_remove_hw_breakpoint (bl->gdbarch,
2517 &bl->overlay_target_info);
2519 target_remove_breakpoint (bl->gdbarch,
2520 &bl->overlay_target_info);
2522 /* Did we set a breakpoint at the VMA?
2523 If so, we will have marked the breakpoint 'inserted'. */
2526 /* Yes -- remove it. Previously we did not bother to
2527 remove the breakpoint if the section had been
2528 unmapped, but let's not rely on that being safe. We
2529 don't know what the overlay manager might do. */
2530 if (bl->loc_type == bp_loc_hardware_breakpoint)
2531 val = target_remove_hw_breakpoint (bl->gdbarch,
2534 /* However, we should remove *software* breakpoints only
2535 if the section is still mapped, or else we overwrite
2536 wrong code with the saved shadow contents. */
2537 else if (section_is_mapped (bl->section))
2538 val = target_remove_breakpoint (bl->gdbarch,
2545 /* No -- not inserted, so no need to remove. No error. */
2550 /* In some cases, we might not be able to remove a breakpoint
2551 in a shared library that has already been removed, but we
2552 have not yet processed the shlib unload event. */
2553 if (val && solib_name_from_address (bl->pspace, bl->address))
2558 bl->inserted = (is == mark_inserted);
2560 else if (bl->loc_type == bp_loc_hardware_watchpoint)
2562 gdb_assert (bl->owner->ops != NULL
2563 && bl->owner->ops->remove_location != NULL);
2565 bl->inserted = (is == mark_inserted);
2566 bl->owner->ops->remove_location (bl);
2568 /* Failure to remove any of the hardware watchpoints comes here. */
2569 if ((is == mark_uninserted) && (bl->inserted))
2570 warning (_("Could not remove hardware watchpoint %d."),
2573 else if (bl->owner->type == bp_catchpoint
2574 && breakpoint_enabled (bl->owner)
2577 gdb_assert (bl->owner->ops != NULL
2578 && bl->owner->ops->remove_location != NULL);
2580 val = bl->owner->ops->remove_location (bl);
2584 bl->inserted = (is == mark_inserted);
2591 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
2594 struct cleanup *old_chain;
2596 /* BL is never in moribund_locations by our callers. */
2597 gdb_assert (bl->owner != NULL);
2599 if (bl->owner->enable_state == bp_permanent)
2600 /* Permanent breakpoints cannot be inserted or removed. */
2603 /* The type of none suggests that owner is actually deleted.
2604 This should not ever happen. */
2605 gdb_assert (bl->owner->type != bp_none);
2607 old_chain = save_current_space_and_thread ();
2609 switch_to_program_space_and_thread (bl->pspace);
2611 ret = remove_breakpoint_1 (bl, is);
2613 do_cleanups (old_chain);
2617 /* Clear the "inserted" flag in all breakpoints. */
2620 mark_breakpoints_out (void)
2622 struct bp_location *bl, **blp_tmp;
2624 ALL_BP_LOCATIONS (bl, blp_tmp)
2625 if (bl->pspace == current_program_space)
2629 /* Clear the "inserted" flag in all breakpoints and delete any
2630 breakpoints which should go away between runs of the program.
2632 Plus other such housekeeping that has to be done for breakpoints
2635 Note: this function gets called at the end of a run (by
2636 generic_mourn_inferior) and when a run begins (by
2637 init_wait_for_inferior). */
2642 breakpoint_init_inferior (enum inf_context context)
2644 struct breakpoint *b, *b_tmp;
2645 struct bp_location *bl, **blp_tmp;
2647 struct program_space *pspace = current_program_space;
2649 /* If breakpoint locations are shared across processes, then there's
2651 if (gdbarch_has_global_breakpoints (target_gdbarch))
2654 ALL_BP_LOCATIONS (bl, blp_tmp)
2656 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2657 if (bl->pspace == pspace
2658 && bl->owner->enable_state != bp_permanent)
2662 ALL_BREAKPOINTS_SAFE (b, b_tmp)
2664 if (b->loc && b->loc->pspace != pspace)
2671 /* If the call dummy breakpoint is at the entry point it will
2672 cause problems when the inferior is rerun, so we better get
2675 case bp_watchpoint_scope:
2677 /* Also get rid of scope breakpoints. */
2679 case bp_shlib_event:
2681 /* Also remove solib event breakpoints. Their addresses may
2682 have changed since the last time we ran the program.
2683 Actually we may now be debugging against different target;
2684 and so the solib backend that installed this breakpoint may
2685 not be used in by the target. E.g.,
2687 (gdb) file prog-linux
2688 (gdb) run # native linux target
2691 (gdb) file prog-win.exe
2692 (gdb) tar rem :9999 # remote Windows gdbserver.
2695 delete_breakpoint (b);
2699 case bp_hardware_watchpoint:
2700 case bp_read_watchpoint:
2701 case bp_access_watchpoint:
2703 /* Likewise for watchpoints on local expressions. */
2704 if (b->exp_valid_block != NULL)
2705 delete_breakpoint (b);
2706 else if (context == inf_starting)
2708 /* Reset val field to force reread of starting value in
2709 insert_breakpoints. */
2711 value_free (b->val);
2721 /* Get rid of the moribund locations. */
2722 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
2723 decref_bp_location (&bl);
2724 VEC_free (bp_location_p, moribund_locations);
2727 /* These functions concern about actual breakpoints inserted in the
2728 target --- to e.g. check if we need to do decr_pc adjustment or if
2729 we need to hop over the bkpt --- so we check for address space
2730 match, not program space. */
2732 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2733 exists at PC. It returns ordinary_breakpoint_here if it's an
2734 ordinary breakpoint, or permanent_breakpoint_here if it's a
2735 permanent breakpoint.
2736 - When continuing from a location with an ordinary breakpoint, we
2737 actually single step once before calling insert_breakpoints.
2738 - When continuing from a localion with a permanent breakpoint, we
2739 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2740 the target, to advance the PC past the breakpoint. */
2742 enum breakpoint_here
2743 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2745 struct bp_location *bl, **blp_tmp;
2746 int any_breakpoint_here = 0;
2748 ALL_BP_LOCATIONS (bl, blp_tmp)
2750 if (bl->loc_type != bp_loc_software_breakpoint
2751 && bl->loc_type != bp_loc_hardware_breakpoint)
2754 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2755 if ((breakpoint_enabled (bl->owner)
2756 || bl->owner->enable_state == bp_permanent)
2757 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2760 if (overlay_debugging
2761 && section_is_overlay (bl->section)
2762 && !section_is_mapped (bl->section))
2763 continue; /* unmapped overlay -- can't be a match */
2764 else if (bl->owner->enable_state == bp_permanent)
2765 return permanent_breakpoint_here;
2767 any_breakpoint_here = 1;
2771 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2774 /* Return true if there's a moribund breakpoint at PC. */
2777 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2779 struct bp_location *loc;
2782 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2783 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2790 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2791 inserted using regular breakpoint_chain / bp_location array
2792 mechanism. This does not check for single-step breakpoints, which
2793 are inserted and removed using direct target manipulation. */
2796 regular_breakpoint_inserted_here_p (struct address_space *aspace,
2799 struct bp_location *bl, **blp_tmp;
2801 ALL_BP_LOCATIONS (bl, blp_tmp)
2803 if (bl->loc_type != bp_loc_software_breakpoint
2804 && bl->loc_type != bp_loc_hardware_breakpoint)
2808 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2811 if (overlay_debugging
2812 && section_is_overlay (bl->section)
2813 && !section_is_mapped (bl->section))
2814 continue; /* unmapped overlay -- can't be a match */
2822 /* Returns non-zero iff there's either regular breakpoint
2823 or a single step breakpoint inserted at PC. */
2826 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2828 if (regular_breakpoint_inserted_here_p (aspace, pc))
2831 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2837 /* This function returns non-zero iff there is a software breakpoint
2841 software_breakpoint_inserted_here_p (struct address_space *aspace,
2844 struct bp_location *bl, **blp_tmp;
2846 ALL_BP_LOCATIONS (bl, blp_tmp)
2848 if (bl->loc_type != bp_loc_software_breakpoint)
2852 && breakpoint_address_match (bl->pspace->aspace, bl->address,
2855 if (overlay_debugging
2856 && section_is_overlay (bl->section)
2857 && !section_is_mapped (bl->section))
2858 continue; /* unmapped overlay -- can't be a match */
2864 /* Also check for software single-step breakpoints. */
2865 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2872 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2873 CORE_ADDR addr, ULONGEST len)
2875 struct breakpoint *bpt;
2877 ALL_BREAKPOINTS (bpt)
2879 struct bp_location *loc;
2881 if (bpt->type != bp_hardware_watchpoint
2882 && bpt->type != bp_access_watchpoint)
2885 if (!breakpoint_enabled (bpt))
2888 for (loc = bpt->loc; loc; loc = loc->next)
2889 if (loc->pspace->aspace == aspace && loc->inserted)
2893 /* Check for intersection. */
2894 l = max (loc->address, addr);
2895 h = min (loc->address + loc->length, addr + len);
2903 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2904 PC is valid for process/thread PTID. */
2907 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2910 struct bp_location *bl, **blp_tmp;
2911 /* The thread and task IDs associated to PTID, computed lazily. */
2915 ALL_BP_LOCATIONS (bl, blp_tmp)
2917 if (bl->loc_type != bp_loc_software_breakpoint
2918 && bl->loc_type != bp_loc_hardware_breakpoint)
2921 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2922 if (!breakpoint_enabled (bl->owner)
2923 && bl->owner->enable_state != bp_permanent)
2926 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
2930 if (bl->owner->thread != -1)
2932 /* This is a thread-specific breakpoint. Check that ptid
2933 matches that thread. If thread hasn't been computed yet,
2934 it is now time to do so. */
2936 thread = pid_to_thread_id (ptid);
2937 if (bl->owner->thread != thread)
2941 if (bl->owner->task != 0)
2943 /* This is a task-specific breakpoint. Check that ptid
2944 matches that task. If task hasn't been computed yet,
2945 it is now time to do so. */
2947 task = ada_get_task_number (ptid);
2948 if (bl->owner->task != task)
2952 if (overlay_debugging
2953 && section_is_overlay (bl->section)
2954 && !section_is_mapped (bl->section))
2955 continue; /* unmapped overlay -- can't be a match */
2964 /* bpstat stuff. External routines' interfaces are documented
2968 ep_is_catchpoint (struct breakpoint *ep)
2970 return (ep->type == bp_catchpoint);
2973 /* Frees any storage that is part of a bpstat. Does not walk the
2977 bpstat_free (bpstat bs)
2979 if (bs->old_val != NULL)
2980 value_free (bs->old_val);
2981 decref_counted_command_line (&bs->commands);
2982 decref_bp_location (&bs->bp_location_at);
2986 /* Clear a bpstat so that it says we are not at any breakpoint.
2987 Also free any storage that is part of a bpstat. */
2990 bpstat_clear (bpstat *bsp)
3007 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3008 is part of the bpstat is copied as well. */
3011 bpstat_copy (bpstat bs)
3015 bpstat retval = NULL;
3020 for (; bs != NULL; bs = bs->next)
3022 tmp = (bpstat) xmalloc (sizeof (*tmp));
3023 memcpy (tmp, bs, sizeof (*tmp));
3024 incref_counted_command_line (tmp->commands);
3025 incref_bp_location (tmp->bp_location_at);
3026 if (bs->old_val != NULL)
3028 tmp->old_val = value_copy (bs->old_val);
3029 release_value (tmp->old_val);
3033 /* This is the first thing in the chain. */
3043 /* Find the bpstat associated with this breakpoint. */
3046 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3051 for (; bsp != NULL; bsp = bsp->next)
3053 if (bsp->breakpoint_at == breakpoint)
3059 /* Put in *NUM the breakpoint number of the first breakpoint we are
3060 stopped at. *BSP upon return is a bpstat which points to the
3061 remaining breakpoints stopped at (but which is not guaranteed to be
3062 good for anything but further calls to bpstat_num).
3064 Return 0 if passed a bpstat which does not indicate any breakpoints.
3065 Return -1 if stopped at a breakpoint that has been deleted since
3067 Return 1 otherwise. */
3070 bpstat_num (bpstat *bsp, int *num)
3072 struct breakpoint *b;
3075 return 0; /* No more breakpoint values */
3077 /* We assume we'll never have several bpstats that correspond to a
3078 single breakpoint -- otherwise, this function might return the
3079 same number more than once and this will look ugly. */
3080 b = (*bsp)->breakpoint_at;
3081 *bsp = (*bsp)->next;
3083 return -1; /* breakpoint that's been deleted since */
3085 *num = b->number; /* We have its number */
3089 /* Modify BS so that the actions will not be performed. */
3092 bpstat_clear_actions (bpstat bs)
3094 for (; bs != NULL; bs = bs->next)
3096 decref_counted_command_line (&bs->commands);
3097 bs->commands_left = NULL;
3098 if (bs->old_val != NULL)
3100 value_free (bs->old_val);
3106 /* Called when a command is about to proceed the inferior. */
3109 breakpoint_about_to_proceed (void)
3111 if (!ptid_equal (inferior_ptid, null_ptid))
3113 struct thread_info *tp = inferior_thread ();
3115 /* Allow inferior function calls in breakpoint commands to not
3116 interrupt the command list. When the call finishes
3117 successfully, the inferior will be standing at the same
3118 breakpoint as if nothing happened. */
3119 if (tp->control.in_infcall)
3123 breakpoint_proceeded = 1;
3126 /* Stub for cleaning up our state if we error-out of a breakpoint
3129 cleanup_executing_breakpoints (void *ignore)
3131 executing_breakpoint_commands = 0;
3134 /* Execute all the commands associated with all the breakpoints at
3135 this location. Any of these commands could cause the process to
3136 proceed beyond this point, etc. We look out for such changes by
3137 checking the global "breakpoint_proceeded" after each command.
3139 Returns true if a breakpoint command resumed the inferior. In that
3140 case, it is the caller's responsibility to recall it again with the
3141 bpstat of the current thread. */
3144 bpstat_do_actions_1 (bpstat *bsp)
3147 struct cleanup *old_chain;
3150 /* Avoid endless recursion if a `source' command is contained
3152 if (executing_breakpoint_commands)
3155 executing_breakpoint_commands = 1;
3156 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3158 /* This pointer will iterate over the list of bpstat's. */
3161 breakpoint_proceeded = 0;
3162 for (; bs != NULL; bs = bs->next)
3164 struct counted_command_line *ccmd;
3165 struct command_line *cmd;
3166 struct cleanup *this_cmd_tree_chain;
3168 /* Take ownership of the BSP's command tree, if it has one.
3170 The command tree could legitimately contain commands like
3171 'step' and 'next', which call clear_proceed_status, which
3172 frees stop_bpstat's command tree. To make sure this doesn't
3173 free the tree we're executing out from under us, we need to
3174 take ownership of the tree ourselves. Since a given bpstat's
3175 commands are only executed once, we don't need to copy it; we
3176 can clear the pointer in the bpstat, and make sure we free
3177 the tree when we're done. */
3178 ccmd = bs->commands;
3179 bs->commands = NULL;
3181 = make_cleanup_decref_counted_command_line (&ccmd);
3182 cmd = bs->commands_left;
3183 bs->commands_left = NULL;
3187 execute_control_command (cmd);
3189 if (breakpoint_proceeded)
3195 /* We can free this command tree now. */
3196 do_cleanups (this_cmd_tree_chain);
3198 if (breakpoint_proceeded)
3200 if (target_can_async_p ())
3201 /* If we are in async mode, then the target might be still
3202 running, not stopped at any breakpoint, so nothing for
3203 us to do here -- just return to the event loop. */
3206 /* In sync mode, when execute_control_command returns
3207 we're already standing on the next breakpoint.
3208 Breakpoint commands for that stop were not run, since
3209 execute_command does not run breakpoint commands --
3210 only command_line_handler does, but that one is not
3211 involved in execution of breakpoint commands. So, we
3212 can now execute breakpoint commands. It should be
3213 noted that making execute_command do bpstat actions is
3214 not an option -- in this case we'll have recursive
3215 invocation of bpstat for each breakpoint with a
3216 command, and can easily blow up GDB stack. Instead, we
3217 return true, which will trigger the caller to recall us
3218 with the new stop_bpstat. */
3223 do_cleanups (old_chain);
3228 bpstat_do_actions (void)
3230 /* Do any commands attached to breakpoint we are stopped at. */
3231 while (!ptid_equal (inferior_ptid, null_ptid)
3232 && target_has_execution
3233 && !is_exited (inferior_ptid)
3234 && !is_executing (inferior_ptid))
3235 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3236 and only return when it is stopped at the next breakpoint, we
3237 keep doing breakpoint actions until it returns false to
3238 indicate the inferior was not resumed. */
3239 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
3243 /* Print out the (old or new) value associated with a watchpoint. */
3246 watchpoint_value_print (struct value *val, struct ui_file *stream)
3249 fprintf_unfiltered (stream, _("<unreadable>"));
3252 struct value_print_options opts;
3253 get_user_print_options (&opts);
3254 value_print (val, stream, &opts);
3258 /* This is the normal print function for a bpstat. In the future,
3259 much of this logic could (should?) be moved to bpstat_stop_status,
3260 by having it set different print_it values.
3262 Current scheme: When we stop, bpstat_print() is called. It loops
3263 through the bpstat list of things causing this stop, calling the
3264 print_bp_stop_message function on each one. The behavior of the
3265 print_bp_stop_message function depends on the print_it field of
3266 bpstat. If such field so indicates, call this function here.
3268 Return values from this routine (ultimately used by bpstat_print()
3269 and normal_stop() to decide what to do):
3270 PRINT_NOTHING: Means we already printed all we needed to print,
3271 don't print anything else.
3272 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3273 that something to be followed by a location.
3274 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3275 that something to be followed by a location.
3276 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3279 static enum print_stop_action
3280 print_it_typical (bpstat bs)
3282 struct cleanup *old_chain;
3283 struct breakpoint *b;
3284 const struct bp_location *bl;
3285 struct ui_stream *stb;
3287 enum print_stop_action result;
3289 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3290 which has since been deleted. */
3291 if (bs->breakpoint_at == NULL)
3292 return PRINT_UNKNOWN;
3294 gdb_assert (bs->bp_location_at != NULL);
3296 bl = bs->bp_location_at;
3297 b = bs->breakpoint_at;
3299 stb = ui_out_stream_new (uiout);
3300 old_chain = make_cleanup_ui_out_stream_delete (stb);
3305 case bp_hardware_breakpoint:
3306 bp_temp = b->disposition == disp_del;
3307 if (bl->address != bl->requested_address)
3308 breakpoint_adjustment_warning (bl->requested_address,
3311 annotate_breakpoint (b->number);
3313 ui_out_text (uiout, "\nTemporary breakpoint ");
3315 ui_out_text (uiout, "\nBreakpoint ");
3316 if (ui_out_is_mi_like_p (uiout))
3318 ui_out_field_string (uiout, "reason",
3319 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3320 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3322 ui_out_field_int (uiout, "bkptno", b->number);
3323 ui_out_text (uiout, ", ");
3324 result = PRINT_SRC_AND_LOC;
3327 case bp_shlib_event:
3328 /* Did we stop because the user set the stop_on_solib_events
3329 variable? (If so, we report this as a generic, "Stopped due
3330 to shlib event" message.) */
3331 printf_filtered (_("Stopped due to shared library event\n"));
3332 result = PRINT_NOTHING;
3335 case bp_thread_event:
3336 /* Not sure how we will get here.
3337 GDB should not stop for these breakpoints. */
3338 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3339 result = PRINT_NOTHING;
3342 case bp_overlay_event:
3343 /* By analogy with the thread event, GDB should not stop for these. */
3344 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3345 result = PRINT_NOTHING;
3348 case bp_longjmp_master:
3349 /* These should never be enabled. */
3350 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3351 result = PRINT_NOTHING;
3354 case bp_std_terminate_master:
3355 /* These should never be enabled. */
3356 printf_filtered (_("std::terminate Master Breakpoint: "
3357 "gdb should not stop!\n"));
3358 result = PRINT_NOTHING;
3361 case bp_exception_master:
3362 /* These should never be enabled. */
3363 printf_filtered (_("Exception Master Breakpoint: "
3364 "gdb should not stop!\n"));
3365 result = PRINT_NOTHING;
3369 case bp_hardware_watchpoint:
3370 annotate_watchpoint (b->number);
3371 if (ui_out_is_mi_like_p (uiout))
3374 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3376 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3377 ui_out_text (uiout, "\nOld value = ");
3378 watchpoint_value_print (bs->old_val, stb->stream);
3379 ui_out_field_stream (uiout, "old", stb);
3380 ui_out_text (uiout, "\nNew value = ");
3381 watchpoint_value_print (b->val, stb->stream);
3382 ui_out_field_stream (uiout, "new", stb);
3383 ui_out_text (uiout, "\n");
3384 /* More than one watchpoint may have been triggered. */
3385 result = PRINT_UNKNOWN;
3388 case bp_read_watchpoint:
3389 if (ui_out_is_mi_like_p (uiout))
3392 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3394 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3395 ui_out_text (uiout, "\nValue = ");
3396 watchpoint_value_print (b->val, stb->stream);
3397 ui_out_field_stream (uiout, "value", stb);
3398 ui_out_text (uiout, "\n");
3399 result = PRINT_UNKNOWN;
3402 case bp_access_watchpoint:
3403 if (bs->old_val != NULL)
3405 annotate_watchpoint (b->number);
3406 if (ui_out_is_mi_like_p (uiout))
3409 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3411 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3412 ui_out_text (uiout, "\nOld value = ");
3413 watchpoint_value_print (bs->old_val, stb->stream);
3414 ui_out_field_stream (uiout, "old", stb);
3415 ui_out_text (uiout, "\nNew value = ");
3420 if (ui_out_is_mi_like_p (uiout))
3423 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3424 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3425 ui_out_text (uiout, "\nValue = ");
3427 watchpoint_value_print (b->val, stb->stream);
3428 ui_out_field_stream (uiout, "new", stb);
3429 ui_out_text (uiout, "\n");
3430 result = PRINT_UNKNOWN;
3433 /* Fall through, we don't deal with these types of breakpoints
3437 if (ui_out_is_mi_like_p (uiout))
3440 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3441 result = PRINT_UNKNOWN;
3445 if (ui_out_is_mi_like_p (uiout))
3448 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3449 result = PRINT_UNKNOWN;
3454 case bp_longjmp_resume:
3456 case bp_exception_resume:
3457 case bp_step_resume:
3458 case bp_watchpoint_scope:
3460 case bp_std_terminate:
3462 case bp_fast_tracepoint:
3465 result = PRINT_UNKNOWN;
3469 do_cleanups (old_chain);
3473 /* Generic routine for printing messages indicating why we
3474 stopped. The behavior of this function depends on the value
3475 'print_it' in the bpstat structure. Under some circumstances we
3476 may decide not to print anything here and delegate the task to
3479 static enum print_stop_action
3480 print_bp_stop_message (bpstat bs)
3482 switch (bs->print_it)
3485 /* Nothing should be printed for this bpstat entry. */
3486 return PRINT_UNKNOWN;
3490 /* We still want to print the frame, but we already printed the
3491 relevant messages. */
3492 return PRINT_SRC_AND_LOC;
3495 case print_it_normal:
3497 struct breakpoint *b = bs->breakpoint_at;
3499 /* Normal case. Call the breakpoint's print_it method, or
3500 print_it_typical. */
3501 /* FIXME: how breakpoint can ever be NULL here? */
3502 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3503 return b->ops->print_it (b);
3505 return print_it_typical (bs);
3510 internal_error (__FILE__, __LINE__,
3511 _("print_bp_stop_message: unrecognized enum value"));
3516 /* Print a message indicating what happened. This is called from
3517 normal_stop(). The input to this routine is the head of the bpstat
3518 list - a list of the eventpoints that caused this stop. This
3519 routine calls the generic print routine for printing a message
3520 about reasons for stopping. This will print (for example) the
3521 "Breakpoint n," part of the output. The return value of this
3524 PRINT_UNKNOWN: Means we printed nothing.
3525 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3526 code to print the location. An example is
3527 "Breakpoint 1, " which should be followed by
3529 PRINT_SRC_ONLY: Means we printed something, but there is no need
3530 to also print the location part of the message.
3531 An example is the catch/throw messages, which
3532 don't require a location appended to the end.
3533 PRINT_NOTHING: We have done some printing and we don't need any
3534 further info to be printed. */
3536 enum print_stop_action
3537 bpstat_print (bpstat bs)
3541 /* Maybe another breakpoint in the chain caused us to stop.
3542 (Currently all watchpoints go on the bpstat whether hit or not.
3543 That probably could (should) be changed, provided care is taken
3544 with respect to bpstat_explains_signal). */
3545 for (; bs; bs = bs->next)
3547 val = print_bp_stop_message (bs);
3548 if (val == PRINT_SRC_ONLY
3549 || val == PRINT_SRC_AND_LOC
3550 || val == PRINT_NOTHING)
3554 /* We reached the end of the chain, or we got a null BS to start
3555 with and nothing was printed. */
3556 return PRINT_UNKNOWN;
3559 /* Evaluate the expression EXP and return 1 if value is zero. This is
3560 used inside a catch_errors to evaluate the breakpoint condition.
3561 The argument is a "struct expression *" that has been cast to a
3562 "char *" to make it pass through catch_errors. */
3565 breakpoint_cond_eval (void *exp)
3567 struct value *mark = value_mark ();
3568 int i = !value_true (evaluate_expression ((struct expression *) exp));
3570 value_free_to_mark (mark);
3574 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3577 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
3581 bs = (bpstat) xmalloc (sizeof (*bs));
3583 **bs_link_pointer = bs;
3584 *bs_link_pointer = &bs->next;
3585 bs->breakpoint_at = bl->owner;
3586 bs->bp_location_at = bl;
3587 incref_bp_location (bl);
3588 /* If the condition is false, etc., don't do the commands. */
3589 bs->commands = NULL;
3590 bs->commands_left = NULL;
3592 bs->print_it = print_it_normal;
3596 /* The target has stopped with waitstatus WS. Check if any hardware
3597 watchpoints have triggered, according to the target. */
3600 watchpoints_triggered (struct target_waitstatus *ws)
3602 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3604 struct breakpoint *b;
3606 if (!stopped_by_watchpoint)
3608 /* We were not stopped by a watchpoint. Mark all watchpoints
3609 as not triggered. */
3611 if (is_hardware_watchpoint (b))
3612 b->watchpoint_triggered = watch_triggered_no;
3617 if (!target_stopped_data_address (¤t_target, &addr))
3619 /* We were stopped by a watchpoint, but we don't know where.
3620 Mark all watchpoints as unknown. */
3622 if (is_hardware_watchpoint (b))
3623 b->watchpoint_triggered = watch_triggered_unknown;
3625 return stopped_by_watchpoint;
3628 /* The target could report the data address. Mark watchpoints
3629 affected by this data address as triggered, and all others as not
3633 if (is_hardware_watchpoint (b))
3635 struct bp_location *loc;
3637 b->watchpoint_triggered = watch_triggered_no;
3638 for (loc = b->loc; loc; loc = loc->next)
3639 /* Exact match not required. Within range is
3641 if (target_watchpoint_addr_within_range (¤t_target,
3645 b->watchpoint_triggered = watch_triggered_yes;
3653 /* Possible return values for watchpoint_check (this can't be an enum
3654 because of check_errors). */
3655 /* The watchpoint has been deleted. */
3656 #define WP_DELETED 1
3657 /* The value has changed. */
3658 #define WP_VALUE_CHANGED 2
3659 /* The value has not changed. */
3660 #define WP_VALUE_NOT_CHANGED 3
3661 /* Ignore this watchpoint, no matter if the value changed or not. */
3664 #define BP_TEMPFLAG 1
3665 #define BP_HARDWAREFLAG 2
3667 /* Evaluate watchpoint condition expression and check if its value
3670 P should be a pointer to struct bpstat, but is defined as a void *
3671 in order for this function to be usable with catch_errors. */
3674 watchpoint_check (void *p)
3676 bpstat bs = (bpstat) p;
3677 struct breakpoint *b;
3678 struct frame_info *fr;
3679 int within_current_scope;
3681 /* BS is built from an existing struct breakpoint. */
3682 gdb_assert (bs->breakpoint_at != NULL);
3683 b = bs->breakpoint_at;
3685 /* If this is a local watchpoint, we only want to check if the
3686 watchpoint frame is in scope if the current thread is the thread
3687 that was used to create the watchpoint. */
3688 if (!watchpoint_in_thread_scope (b))
3691 if (b->exp_valid_block == NULL)
3692 within_current_scope = 1;
3695 struct frame_info *frame = get_current_frame ();
3696 struct gdbarch *frame_arch = get_frame_arch (frame);
3697 CORE_ADDR frame_pc = get_frame_pc (frame);
3699 /* in_function_epilogue_p() returns a non-zero value if we're
3700 still in the function but the stack frame has already been
3701 invalidated. Since we can't rely on the values of local
3702 variables after the stack has been destroyed, we are treating
3703 the watchpoint in that state as `not changed' without further
3704 checking. Don't mark watchpoints as changed if the current
3705 frame is in an epilogue - even if they are in some other
3706 frame, our view of the stack is likely to be wrong and
3707 frame_find_by_id could error out. */
3708 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3711 fr = frame_find_by_id (b->watchpoint_frame);
3712 within_current_scope = (fr != NULL);
3714 /* If we've gotten confused in the unwinder, we might have
3715 returned a frame that can't describe this variable. */
3716 if (within_current_scope)
3718 struct symbol *function;
3720 function = get_frame_function (fr);
3721 if (function == NULL
3722 || !contained_in (b->exp_valid_block,
3723 SYMBOL_BLOCK_VALUE (function)))
3724 within_current_scope = 0;
3727 if (within_current_scope)
3728 /* If we end up stopping, the current frame will get selected
3729 in normal_stop. So this call to select_frame won't affect
3734 if (within_current_scope)
3736 /* We use value_{,free_to_}mark because it could be a *long*
3737 time before we return to the command level and call
3738 free_all_values. We can't call free_all_values because we
3739 might be in the middle of evaluating a function call. */
3742 struct value *mark = value_mark ();
3743 struct value *new_val;
3745 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3747 /* We use value_equal_contents instead of value_equal because
3748 the latter coerces an array to a pointer, thus comparing just
3749 the address of the array instead of its contents. This is
3750 not what we want. */
3751 if ((b->val != NULL) != (new_val != NULL)
3752 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3754 if (new_val != NULL)
3756 release_value (new_val);
3757 value_free_to_mark (mark);
3759 bs->old_val = b->val;
3762 return WP_VALUE_CHANGED;
3766 /* Nothing changed. */
3767 value_free_to_mark (mark);
3768 return WP_VALUE_NOT_CHANGED;
3773 /* This seems like the only logical thing to do because
3774 if we temporarily ignored the watchpoint, then when
3775 we reenter the block in which it is valid it contains
3776 garbage (in the case of a function, it may have two
3777 garbage values, one before and one after the prologue).
3778 So we can't even detect the first assignment to it and
3779 watch after that (since the garbage may or may not equal
3780 the first value assigned). */
3781 /* We print all the stop information in print_it_typical(), but
3782 in this case, by the time we call print_it_typical() this bp
3783 will be deleted already. So we have no choice but print the
3784 information here. */
3785 if (ui_out_is_mi_like_p (uiout))
3787 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3788 ui_out_text (uiout, "\nWatchpoint ");
3789 ui_out_field_int (uiout, "wpnum", b->number);
3791 " deleted because the program has left the block in\n\
3792 which its expression is valid.\n");
3794 if (b->related_breakpoint)
3796 b->related_breakpoint->disposition = disp_del_at_next_stop;
3797 b->related_breakpoint->related_breakpoint = NULL;
3798 b->related_breakpoint = NULL;
3800 b->disposition = disp_del_at_next_stop;
3806 /* Return true if it looks like target has stopped due to hitting
3807 breakpoint location BL. This function does not check if we
3808 should stop, only if BL explains the stop. */
3810 bpstat_check_location (const struct bp_location *bl,
3811 struct address_space *aspace, CORE_ADDR bp_addr)
3813 struct breakpoint *b = bl->owner;
3815 /* BL is from existing struct breakpoint. */
3816 gdb_assert (b != NULL);
3818 /* By definition, the inferior does not report stops at
3820 if (is_tracepoint (b))
3823 if (!is_watchpoint (b)
3824 && b->type != bp_hardware_breakpoint
3825 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3827 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3830 if (overlay_debugging /* unmapped overlay section */
3831 && section_is_overlay (bl->section)
3832 && !section_is_mapped (bl->section))
3836 /* Continuable hardware watchpoints are treated as non-existent if the
3837 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3838 some data address). Otherwise gdb won't stop on a break instruction
3839 in the code (not from a breakpoint) when a hardware watchpoint has
3840 been defined. Also skip watchpoints which we know did not trigger
3841 (did not match the data address). */
3843 if (is_hardware_watchpoint (b)
3844 && b->watchpoint_triggered == watch_triggered_no)
3847 if (b->type == bp_hardware_breakpoint)
3849 if (bl->address != bp_addr)
3851 if (overlay_debugging /* unmapped overlay section */
3852 && section_is_overlay (bl->section)
3853 && !section_is_mapped (bl->section))
3857 if (b->type == bp_catchpoint)
3859 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3860 if (!b->ops->breakpoint_hit (b))
3867 /* If BS refers to a watchpoint, determine if the watched values
3868 has actually changed, and we should stop. If not, set BS->stop
3871 bpstat_check_watchpoint (bpstat bs)
3873 const struct bp_location *bl;
3874 struct breakpoint *b;
3876 /* BS is built for existing struct breakpoint. */
3877 bl = bs->bp_location_at;
3878 gdb_assert (bl != NULL);
3879 b = bs->breakpoint_at;
3880 gdb_assert (b != NULL);
3882 if (is_watchpoint (b))
3884 int must_check_value = 0;
3886 if (b->type == bp_watchpoint)
3887 /* For a software watchpoint, we must always check the
3889 must_check_value = 1;
3890 else if (b->watchpoint_triggered == watch_triggered_yes)
3891 /* We have a hardware watchpoint (read, write, or access)
3892 and the target earlier reported an address watched by
3894 must_check_value = 1;
3895 else if (b->watchpoint_triggered == watch_triggered_unknown
3896 && b->type == bp_hardware_watchpoint)
3897 /* We were stopped by a hardware watchpoint, but the target could
3898 not report the data address. We must check the watchpoint's
3899 value. Access and read watchpoints are out of luck; without
3900 a data address, we can't figure it out. */
3901 must_check_value = 1;
3903 if (must_check_value)
3906 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3908 struct cleanup *cleanups = make_cleanup (xfree, message);
3909 int e = catch_errors (watchpoint_check, bs, message,
3911 do_cleanups (cleanups);
3915 /* We've already printed what needs to be printed. */
3916 bs->print_it = print_it_done;
3920 bs->print_it = print_it_noop;
3923 case WP_VALUE_CHANGED:
3924 if (b->type == bp_read_watchpoint)
3926 /* There are two cases to consider here:
3928 1. We're watching the triggered memory for reads.
3929 In that case, trust the target, and always report
3930 the watchpoint hit to the user. Even though
3931 reads don't cause value changes, the value may
3932 have changed since the last time it was read, and
3933 since we're not trapping writes, we will not see
3934 those, and as such we should ignore our notion of
3937 2. We're watching the triggered memory for both
3938 reads and writes. There are two ways this may
3941 2.1. This is a target that can't break on data
3942 reads only, but can break on accesses (reads or
3943 writes), such as e.g., x86. We detect this case
3944 at the time we try to insert read watchpoints.
3946 2.2. Otherwise, the target supports read
3947 watchpoints, but, the user set an access or write
3948 watchpoint watching the same memory as this read
3951 If we're watching memory writes as well as reads,
3952 ignore watchpoint hits when we find that the
3953 value hasn't changed, as reads don't cause
3954 changes. This still gives false positives when
3955 the program writes the same value to memory as
3956 what there was already in memory (we will confuse
3957 it for a read), but it's much better than
3960 int other_write_watchpoint = 0;
3962 if (bl->watchpoint_type == hw_read)
3964 struct breakpoint *other_b;
3966 ALL_BREAKPOINTS (other_b)
3967 if ((other_b->type == bp_hardware_watchpoint
3968 || other_b->type == bp_access_watchpoint)
3969 && (other_b->watchpoint_triggered
3970 == watch_triggered_yes))
3972 other_write_watchpoint = 1;
3977 if (other_write_watchpoint
3978 || bl->watchpoint_type == hw_access)
3980 /* We're watching the same memory for writes,
3981 and the value changed since the last time we
3982 updated it, so this trap must be for a write.
3984 bs->print_it = print_it_noop;
3989 case WP_VALUE_NOT_CHANGED:
3990 if (b->type == bp_hardware_watchpoint
3991 || b->type == bp_watchpoint)
3993 /* Don't stop: write watchpoints shouldn't fire if
3994 the value hasn't changed. */
3995 bs->print_it = print_it_noop;
4003 /* Error from catch_errors. */
4004 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
4005 if (b->related_breakpoint)
4006 b->related_breakpoint->disposition = disp_del_at_next_stop;
4007 b->disposition = disp_del_at_next_stop;
4008 /* We've already printed what needs to be printed. */
4009 bs->print_it = print_it_done;
4013 else /* must_check_value == 0 */
4015 /* This is a case where some watchpoint(s) triggered, but
4016 not at the address of this watchpoint, or else no
4017 watchpoint triggered after all. So don't print
4018 anything for this watchpoint. */
4019 bs->print_it = print_it_noop;
4026 /* Check conditions (condition proper, frame, thread and ignore count)
4027 of breakpoint referred to by BS. If we should not stop for this
4028 breakpoint, set BS->stop to 0. */
4031 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4033 int thread_id = pid_to_thread_id (ptid);
4034 const struct bp_location *bl;
4035 struct breakpoint *b;
4037 /* BS is built for existing struct breakpoint. */
4038 bl = bs->bp_location_at;
4039 gdb_assert (bl != NULL);
4040 b = bs->breakpoint_at;
4041 gdb_assert (b != NULL);
4043 if (frame_id_p (b->frame_id)
4044 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4048 int value_is_zero = 0;
4049 struct expression *cond;
4051 if (is_watchpoint (b))
4056 if (cond && b->disposition != disp_del_at_next_stop)
4058 int within_current_scope = 1;
4060 /* We use value_mark and value_free_to_mark because it could
4061 be a long time before we return to the command level and
4062 call free_all_values. We can't call free_all_values
4063 because we might be in the middle of evaluating a
4065 struct value *mark = value_mark ();
4067 /* Need to select the frame, with all that implies so that
4068 the conditions will have the right context. Because we
4069 use the frame, we will not see an inlined function's
4070 variables when we arrive at a breakpoint at the start
4071 of the inlined function; the current frame will be the
4073 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
4074 select_frame (get_current_frame ());
4077 struct frame_info *frame;
4079 /* For local watchpoint expressions, which particular
4080 instance of a local is being watched matters, so we
4081 keep track of the frame to evaluate the expression
4082 in. To evaluate the condition however, it doesn't
4083 really matter which instantiation of the function
4084 where the condition makes sense triggers the
4085 watchpoint. This allows an expression like "watch
4086 global if q > 10" set in `func', catch writes to
4087 global on all threads that call `func', or catch
4088 writes on all recursive calls of `func' by a single
4089 thread. We simply always evaluate the condition in
4090 the innermost frame that's executing where it makes
4091 sense to evaluate the condition. It seems
4093 frame = block_innermost_frame (b->cond_exp_valid_block);
4095 select_frame (frame);
4097 within_current_scope = 0;
4099 if (within_current_scope)
4101 = catch_errors (breakpoint_cond_eval, cond,
4102 "Error in testing breakpoint condition:\n",
4106 warning (_("Watchpoint condition cannot be tested "
4107 "in the current scope"));
4108 /* If we failed to set the right context for this
4109 watchpoint, unconditionally report it. */
4112 /* FIXME-someday, should give breakpoint #. */
4113 value_free_to_mark (mark);
4116 if (cond && value_is_zero)
4120 else if (b->thread != -1 && b->thread != thread_id)
4124 else if (b->ignore_count > 0)
4127 annotate_ignore_count_change ();
4129 /* Increase the hit count even though we don't stop. */
4136 /* Get a bpstat associated with having just stopped at address
4137 BP_ADDR in thread PTID.
4139 Determine whether we stopped at a breakpoint, etc, or whether we
4140 don't understand this stop. Result is a chain of bpstat's such
4143 if we don't understand the stop, the result is a null pointer.
4145 if we understand why we stopped, the result is not null.
4147 Each element of the chain refers to a particular breakpoint or
4148 watchpoint at which we have stopped. (We may have stopped for
4149 several reasons concurrently.)
4151 Each element of the chain has valid next, breakpoint_at,
4152 commands, FIXME??? fields. */
4155 bpstat_stop_status (struct address_space *aspace,
4156 CORE_ADDR bp_addr, ptid_t ptid)
4158 struct breakpoint *b = NULL;
4159 struct bp_location *bl;
4160 struct bp_location *loc;
4161 /* First item of allocated bpstat's. */
4162 bpstat bs_head = NULL, *bs_link = &bs_head;
4163 /* Pointer to the last thing in the chain currently. */
4166 int need_remove_insert;
4169 /* First, build the bpstat chain with locations that explain a
4170 target stop, while being careful to not set the target running,
4171 as that may invalidate locations (in particular watchpoint
4172 locations are recreated). Resuming will happen here with
4173 breakpoint conditions or watchpoint expressions that include
4174 inferior function calls. */
4178 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4181 for (bl = b->loc; bl != NULL; bl = bl->next)
4183 /* For hardware watchpoints, we look only at the first
4184 location. The watchpoint_check function will work on the
4185 entire expression, not the individual locations. For
4186 read watchpoints, the watchpoints_triggered function has
4187 checked all locations already. */
4188 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4191 if (bl->shlib_disabled)
4194 if (!bpstat_check_location (bl, aspace, bp_addr))
4197 /* Come here if it's a watchpoint, or if the break address
4200 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4203 /* Assume we stop. Should we find a watchpoint that is not
4204 actually triggered, or if the condition of the breakpoint
4205 evaluates as false, we'll reset 'stop' to 0. */
4209 /* If this is a scope breakpoint, mark the associated
4210 watchpoint as triggered so that we will handle the
4211 out-of-scope event. We'll get to the watchpoint next
4213 if (b->type == bp_watchpoint_scope)
4214 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
4218 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4220 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4223 bs = bpstat_alloc (loc, &bs_link);
4224 /* For hits of moribund locations, we should just proceed. */
4227 bs->print_it = print_it_noop;
4231 /* Now go through the locations that caused the target to stop, and
4232 check whether we're interested in reporting this stop to higher
4233 layers, or whether we should resume the target transparently. */
4237 for (bs = bs_head; bs != NULL; bs = bs->next)
4242 bpstat_check_watchpoint (bs);
4246 b = bs->breakpoint_at;
4248 if (b->type == bp_thread_event || b->type == bp_overlay_event
4249 || b->type == bp_longjmp_master
4250 || b->type == bp_std_terminate_master
4251 || b->type == bp_exception_master)
4252 /* We do not stop for these. */
4255 bpstat_check_breakpoint_conditions (bs, ptid);
4261 /* We will stop here. */
4262 if (b->disposition == disp_disable)
4264 if (b->enable_state != bp_permanent)
4265 b->enable_state = bp_disabled;
4270 bs->commands = b->commands;
4271 incref_counted_command_line (bs->commands);
4272 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4273 if (bs->commands_left
4274 && (strcmp ("silent", bs->commands_left->line) == 0
4277 bs->commands_left->line) == 0)))
4279 bs->commands_left = bs->commands_left->next;
4284 /* Print nothing for this entry if we dont stop or dont print. */
4285 if (bs->stop == 0 || bs->print == 0)
4286 bs->print_it = print_it_noop;
4289 /* If we aren't stopping, the value of some hardware watchpoint may
4290 not have changed, but the intermediate memory locations we are
4291 watching may have. Don't bother if we're stopping; this will get
4293 need_remove_insert = 0;
4294 if (! bpstat_causes_stop (bs_head))
4295 for (bs = bs_head; bs != NULL; bs = bs->next)
4297 && bs->breakpoint_at
4298 && is_hardware_watchpoint (bs->breakpoint_at))
4300 update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */);
4301 need_remove_insert = 1;
4304 if (need_remove_insert)
4305 update_global_location_list (1);
4306 else if (removed_any)
4307 update_global_location_list (0);
4313 handle_jit_event (void)
4315 struct frame_info *frame;
4316 struct gdbarch *gdbarch;
4318 /* Switch terminal for any messages produced by
4319 breakpoint_re_set. */
4320 target_terminal_ours_for_output ();
4322 frame = get_current_frame ();
4323 gdbarch = get_frame_arch (frame);
4325 jit_event_handler (gdbarch);
4327 target_terminal_inferior ();
4330 /* Prepare WHAT final decision for infrun. */
4332 /* Decide what infrun needs to do with this bpstat. */
4335 bpstat_what (bpstat bs)
4337 struct bpstat_what retval;
4338 /* We need to defer calling `solib_add', as adding new symbols
4339 resets breakpoints, which in turn deletes breakpoint locations,
4340 and hence may clear unprocessed entries in the BS chain. */
4341 int shlib_event = 0;
4344 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4345 retval.call_dummy = STOP_NONE;
4346 retval.is_longjmp = 0;
4348 for (; bs != NULL; bs = bs->next)
4350 /* Extract this BS's action. After processing each BS, we check
4351 if its action overrides all we've seem so far. */
4352 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4355 if (bs->breakpoint_at == NULL)
4357 /* I suspect this can happen if it was a momentary
4358 breakpoint which has since been deleted. */
4361 else if (bs->breakpoint_at == NULL)
4364 bptype = bs->breakpoint_at->type;
4371 case bp_hardware_breakpoint:
4377 this_action = BPSTAT_WHAT_STOP_NOISY;
4379 this_action = BPSTAT_WHAT_STOP_SILENT;
4382 this_action = BPSTAT_WHAT_SINGLE;
4385 case bp_hardware_watchpoint:
4386 case bp_read_watchpoint:
4387 case bp_access_watchpoint:
4391 this_action = BPSTAT_WHAT_STOP_NOISY;
4393 this_action = BPSTAT_WHAT_STOP_SILENT;
4397 /* There was a watchpoint, but we're not stopping.
4398 This requires no further action. */
4403 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4404 retval.is_longjmp = bptype == bp_longjmp;
4406 case bp_longjmp_resume:
4407 case bp_exception_resume:
4408 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4409 retval.is_longjmp = bptype == bp_longjmp_resume;
4411 case bp_step_resume:
4413 this_action = BPSTAT_WHAT_STEP_RESUME;
4416 /* It is for the wrong frame. */
4417 this_action = BPSTAT_WHAT_SINGLE;
4420 case bp_watchpoint_scope:
4421 case bp_thread_event:
4422 case bp_overlay_event:
4423 case bp_longjmp_master:
4424 case bp_std_terminate_master:
4425 case bp_exception_master:
4426 this_action = BPSTAT_WHAT_SINGLE;
4432 this_action = BPSTAT_WHAT_STOP_NOISY;
4434 this_action = BPSTAT_WHAT_STOP_SILENT;
4438 /* There was a catchpoint, but we're not stopping.
4439 This requires no further action. */
4442 case bp_shlib_event:
4445 /* If requested, stop when the dynamic linker notifies GDB
4446 of events. This allows the user to get control and place
4447 breakpoints in initializer routines for dynamically
4448 loaded objects (among other things). */
4449 if (stop_on_solib_events)
4450 this_action = BPSTAT_WHAT_STOP_NOISY;
4452 this_action = BPSTAT_WHAT_SINGLE;
4456 this_action = BPSTAT_WHAT_SINGLE;
4459 /* Make sure the action is stop (silent or noisy),
4460 so infrun.c pops the dummy frame. */
4461 retval.call_dummy = STOP_STACK_DUMMY;
4462 this_action = BPSTAT_WHAT_STOP_SILENT;
4464 case bp_std_terminate:
4465 /* Make sure the action is stop (silent or noisy),
4466 so infrun.c pops the dummy frame. */
4467 retval.call_dummy = STOP_STD_TERMINATE;
4468 this_action = BPSTAT_WHAT_STOP_SILENT;
4471 case bp_fast_tracepoint:
4472 case bp_static_tracepoint:
4473 /* Tracepoint hits should not be reported back to GDB, and
4474 if one got through somehow, it should have been filtered
4476 internal_error (__FILE__, __LINE__,
4477 _("bpstat_what: tracepoint encountered"));
4479 internal_error (__FILE__, __LINE__,
4480 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4483 retval.main_action = max (retval.main_action, this_action);
4489 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4491 /* Check for any newly added shared libraries if we're supposed
4492 to be adding them automatically. */
4494 /* Switch terminal for any messages produced by
4495 breakpoint_re_set. */
4496 target_terminal_ours_for_output ();
4499 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4501 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4504 target_terminal_inferior ();
4510 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4512 handle_jit_event ();
4518 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4519 without hardware support). This isn't related to a specific bpstat,
4520 just to things like whether watchpoints are set. */
4523 bpstat_should_step (void)
4525 struct breakpoint *b;
4528 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4534 bpstat_causes_stop (bpstat bs)
4536 for (; bs != NULL; bs = bs->next)
4545 /* Print the LOC location out of the list of B->LOC locations. */
4547 static void print_breakpoint_location (struct breakpoint *b,
4548 struct bp_location *loc,
4550 struct ui_stream *stb)
4552 struct cleanup *old_chain = save_current_program_space ();
4554 if (loc != NULL && loc->shlib_disabled)
4558 set_current_program_space (loc->pspace);
4560 if (b->source_file && loc)
4563 = find_pc_sect_function (loc->address, loc->section);
4566 ui_out_text (uiout, "in ");
4567 ui_out_field_string (uiout, "func",
4568 SYMBOL_PRINT_NAME (sym));
4569 ui_out_wrap_hint (uiout, wrap_indent);
4570 ui_out_text (uiout, " at ");
4572 ui_out_field_string (uiout, "file", b->source_file);
4573 ui_out_text (uiout, ":");
4575 if (ui_out_is_mi_like_p (uiout))
4577 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4578 char *fullname = symtab_to_fullname (sal.symtab);
4581 ui_out_field_string (uiout, "fullname", fullname);
4584 ui_out_field_int (uiout, "line", b->line_number);
4588 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4590 ui_out_field_stream (uiout, "at", stb);
4593 ui_out_field_string (uiout, "pending", b->addr_string);
4595 do_cleanups (old_chain);
4599 bptype_string (enum bptype type)
4601 struct ep_type_description
4606 static struct ep_type_description bptypes[] =
4608 {bp_none, "?deleted?"},
4609 {bp_breakpoint, "breakpoint"},
4610 {bp_hardware_breakpoint, "hw breakpoint"},
4611 {bp_until, "until"},
4612 {bp_finish, "finish"},
4613 {bp_watchpoint, "watchpoint"},
4614 {bp_hardware_watchpoint, "hw watchpoint"},
4615 {bp_read_watchpoint, "read watchpoint"},
4616 {bp_access_watchpoint, "acc watchpoint"},
4617 {bp_longjmp, "longjmp"},
4618 {bp_longjmp_resume, "longjmp resume"},
4619 {bp_exception, "exception"},
4620 {bp_exception_resume, "exception resume"},
4621 {bp_step_resume, "step resume"},
4622 {bp_watchpoint_scope, "watchpoint scope"},
4623 {bp_call_dummy, "call dummy"},
4624 {bp_std_terminate, "std::terminate"},
4625 {bp_shlib_event, "shlib events"},
4626 {bp_thread_event, "thread events"},
4627 {bp_overlay_event, "overlay events"},
4628 {bp_longjmp_master, "longjmp master"},
4629 {bp_std_terminate_master, "std::terminate master"},
4630 {bp_exception_master, "exception master"},
4631 {bp_catchpoint, "catchpoint"},
4632 {bp_tracepoint, "tracepoint"},
4633 {bp_fast_tracepoint, "fast tracepoint"},
4634 {bp_static_tracepoint, "static tracepoint"},
4635 {bp_jit_event, "jit events"},
4638 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4639 || ((int) type != bptypes[(int) type].type))
4640 internal_error (__FILE__, __LINE__,
4641 _("bptypes table does not describe type #%d."),
4644 return bptypes[(int) type].description;
4647 /* Print B to gdb_stdout. */
4650 print_one_breakpoint_location (struct breakpoint *b,
4651 struct bp_location *loc,
4653 struct bp_location **last_loc,
4654 int print_address_bits,
4657 struct command_line *l;
4658 static char bpenables[] = "nynny";
4659 char wrap_indent[80];
4660 struct ui_stream *stb = ui_out_stream_new (uiout);
4661 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4662 struct cleanup *bkpt_chain;
4664 int header_of_multiple = 0;
4665 int part_of_multiple = (loc != NULL);
4666 struct value_print_options opts;
4668 get_user_print_options (&opts);
4670 gdb_assert (!loc || loc_number != 0);
4671 /* See comment in print_one_breakpoint concerning treatment of
4672 breakpoints with single disabled location. */
4675 && (b->loc->next != NULL || !b->loc->enabled)))
4676 header_of_multiple = 1;
4681 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4685 if (part_of_multiple)
4688 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4689 ui_out_field_string (uiout, "number", formatted);
4694 ui_out_field_int (uiout, "number", b->number);
4699 if (part_of_multiple)
4700 ui_out_field_skip (uiout, "type");
4702 ui_out_field_string (uiout, "type", bptype_string (b->type));
4706 if (part_of_multiple)
4707 ui_out_field_skip (uiout, "disp");
4709 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4714 if (part_of_multiple)
4715 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4717 ui_out_field_fmt (uiout, "enabled", "%c",
4718 bpenables[(int) b->enable_state]);
4719 ui_out_spaces (uiout, 2);
4723 strcpy (wrap_indent, " ");
4724 if (opts.addressprint)
4726 if (print_address_bits <= 32)
4727 strcat (wrap_indent, " ");
4729 strcat (wrap_indent, " ");
4732 if (b->ops != NULL && b->ops->print_one != NULL)
4734 /* Although the print_one can possibly print all locations,
4735 calling it here is not likely to get any nice result. So,
4736 make sure there's just one location. */
4737 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4738 b->ops->print_one (b, last_loc);
4744 internal_error (__FILE__, __LINE__,
4745 _("print_one_breakpoint: bp_none encountered\n"));
4749 case bp_hardware_watchpoint:
4750 case bp_read_watchpoint:
4751 case bp_access_watchpoint:
4752 /* Field 4, the address, is omitted (which makes the columns
4753 not line up too nicely with the headers, but the effect
4754 is relatively readable). */
4755 if (opts.addressprint)
4756 ui_out_field_skip (uiout, "addr");
4758 ui_out_field_string (uiout, "what", b->exp_string);
4762 case bp_hardware_breakpoint:
4766 case bp_longjmp_resume:
4768 case bp_exception_resume:
4769 case bp_step_resume:
4770 case bp_watchpoint_scope:
4772 case bp_std_terminate:
4773 case bp_shlib_event:
4774 case bp_thread_event:
4775 case bp_overlay_event:
4776 case bp_longjmp_master:
4777 case bp_std_terminate_master:
4778 case bp_exception_master:
4780 case bp_fast_tracepoint:
4781 case bp_static_tracepoint:
4783 if (opts.addressprint)
4786 if (header_of_multiple)
4787 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4788 else if (b->loc == NULL || loc->shlib_disabled)
4789 ui_out_field_string (uiout, "addr", "<PENDING>");
4791 ui_out_field_core_addr (uiout, "addr",
4792 loc->gdbarch, loc->address);
4795 if (!header_of_multiple)
4796 print_breakpoint_location (b, loc, wrap_indent, stb);
4803 /* For backward compatibility, don't display inferiors unless there
4806 && !header_of_multiple
4808 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4809 && (number_of_program_spaces () > 1
4810 || number_of_inferiors () > 1)
4811 /* LOC is for existing B, it cannot be in
4812 moribund_locations and thus having NULL OWNER. */
4813 && loc->owner->type != bp_catchpoint)))
4815 struct inferior *inf;
4818 for (inf = inferior_list; inf != NULL; inf = inf->next)
4820 if (inf->pspace == loc->pspace)
4825 ui_out_text (uiout, " inf ");
4828 ui_out_text (uiout, ", ");
4829 ui_out_text (uiout, plongest (inf->num));
4834 if (!part_of_multiple)
4836 if (b->thread != -1)
4838 /* FIXME: This seems to be redundant and lost here; see the
4839 "stop only in" line a little further down. */
4840 ui_out_text (uiout, " thread ");
4841 ui_out_field_int (uiout, "thread", b->thread);
4843 else if (b->task != 0)
4845 ui_out_text (uiout, " task ");
4846 ui_out_field_int (uiout, "task", b->task);
4850 ui_out_text (uiout, "\n");
4852 if (!part_of_multiple && b->static_trace_marker_id)
4854 gdb_assert (b->type == bp_static_tracepoint);
4856 ui_out_text (uiout, "\tmarker id is ");
4857 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
4858 b->static_trace_marker_id);
4859 ui_out_text (uiout, "\n");
4862 if (part_of_multiple && frame_id_p (b->frame_id))
4865 ui_out_text (uiout, "\tstop only in stack frame at ");
4866 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4868 ui_out_field_core_addr (uiout, "frame",
4869 b->gdbarch, b->frame_id.stack_addr);
4870 ui_out_text (uiout, "\n");
4873 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4875 /* We do not print the condition for Ada exception catchpoints
4876 because the condition is an internal implementation detail
4877 that we do not want to expose to the user. */
4879 if (is_tracepoint (b))
4880 ui_out_text (uiout, "\ttrace only if ");
4882 ui_out_text (uiout, "\tstop only if ");
4883 ui_out_field_string (uiout, "cond", b->cond_string);
4884 ui_out_text (uiout, "\n");
4887 if (!part_of_multiple && b->thread != -1)
4889 /* FIXME should make an annotation for this. */
4890 ui_out_text (uiout, "\tstop only in thread ");
4891 ui_out_field_int (uiout, "thread", b->thread);
4892 ui_out_text (uiout, "\n");
4895 if (!part_of_multiple && b->hit_count)
4897 /* FIXME should make an annotation for this. */
4898 if (ep_is_catchpoint (b))
4899 ui_out_text (uiout, "\tcatchpoint");
4901 ui_out_text (uiout, "\tbreakpoint");
4902 ui_out_text (uiout, " already hit ");
4903 ui_out_field_int (uiout, "times", b->hit_count);
4904 if (b->hit_count == 1)
4905 ui_out_text (uiout, " time\n");
4907 ui_out_text (uiout, " times\n");
4910 /* Output the count also if it is zero, but only if this is mi.
4911 FIXME: Should have a better test for this. */
4912 if (ui_out_is_mi_like_p (uiout))
4913 if (!part_of_multiple && b->hit_count == 0)
4914 ui_out_field_int (uiout, "times", b->hit_count);
4916 if (!part_of_multiple && b->ignore_count)
4919 ui_out_text (uiout, "\tignore next ");
4920 ui_out_field_int (uiout, "ignore", b->ignore_count);
4921 ui_out_text (uiout, " hits\n");
4924 l = b->commands ? b->commands->commands : NULL;
4925 if (!part_of_multiple && l)
4927 struct cleanup *script_chain;
4930 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4931 print_command_lines (uiout, l, 4);
4932 do_cleanups (script_chain);
4935 if (!part_of_multiple && b->pass_count)
4937 annotate_field (10);
4938 ui_out_text (uiout, "\tpass count ");
4939 ui_out_field_int (uiout, "pass", b->pass_count);
4940 ui_out_text (uiout, " \n");
4943 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4946 ui_out_field_string (uiout, "original-location", b->addr_string);
4947 else if (b->exp_string)
4948 ui_out_field_string (uiout, "original-location", b->exp_string);
4951 do_cleanups (bkpt_chain);
4952 do_cleanups (old_chain);
4956 print_one_breakpoint (struct breakpoint *b,
4957 struct bp_location **last_loc,
4958 int print_address_bits,
4961 print_one_breakpoint_location (b, NULL, 0, last_loc,
4962 print_address_bits, allflag);
4964 /* If this breakpoint has custom print function,
4965 it's already printed. Otherwise, print individual
4966 locations, if any. */
4967 if (b->ops == NULL || b->ops->print_one == NULL)
4969 /* If breakpoint has a single location that is disabled, we
4970 print it as if it had several locations, since otherwise it's
4971 hard to represent "breakpoint enabled, location disabled"
4974 Note that while hardware watchpoints have several locations
4975 internally, that's no a property exposed to user. */
4977 && !is_hardware_watchpoint (b)
4978 && (b->loc->next || !b->loc->enabled)
4979 && !ui_out_is_mi_like_p (uiout))
4981 struct bp_location *loc;
4983 for (loc = b->loc; loc; loc = loc->next, ++n)
4984 print_one_breakpoint_location (b, loc, n, last_loc,
4985 print_address_bits, allflag);
4991 breakpoint_address_bits (struct breakpoint *b)
4993 int print_address_bits = 0;
4994 struct bp_location *loc;
4996 for (loc = b->loc; loc; loc = loc->next)
5000 /* Software watchpoints that aren't watching memory don't have
5001 an address to print. */
5002 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5005 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5006 if (addr_bit > print_address_bits)
5007 print_address_bits = addr_bit;
5010 return print_address_bits;
5013 struct captured_breakpoint_query_args
5019 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5021 struct captured_breakpoint_query_args *args = data;
5022 struct breakpoint *b;
5023 struct bp_location *dummy_loc = NULL;
5027 if (args->bnum == b->number)
5029 int print_address_bits = breakpoint_address_bits (b);
5031 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
5039 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5040 char **error_message)
5042 struct captured_breakpoint_query_args args;
5045 /* For the moment we don't trust print_one_breakpoint() to not throw
5047 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5048 error_message, RETURN_MASK_ALL) < 0)
5054 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5055 catchpoints, et.al.). */
5058 user_settable_breakpoint (const struct breakpoint *b)
5060 return (b->type == bp_breakpoint
5061 || b->type == bp_catchpoint
5062 || b->type == bp_hardware_breakpoint
5063 || is_tracepoint (b)
5064 || is_watchpoint (b));
5067 /* Print information on user settable breakpoint (watchpoint, etc)
5068 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5069 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5070 FILTER is non-NULL, call it on each breakpoint and only include the
5071 ones for which it returns non-zero. Return the total number of
5072 breakpoints listed. */
5075 breakpoint_1 (int bnum, int allflag,
5076 int (*filter) (const struct breakpoint *))
5078 struct breakpoint *b;
5079 struct bp_location *last_loc = NULL;
5080 int nr_printable_breakpoints;
5081 struct cleanup *bkpttbl_chain;
5082 struct value_print_options opts;
5083 int print_address_bits = 0;
5084 int print_type_col_width = 14;
5086 get_user_print_options (&opts);
5088 /* Compute the number of rows in the table, as well as the size
5089 required for address fields. */
5090 nr_printable_breakpoints = 0;
5093 || bnum == b->number)
5095 /* If we have a filter, only list the breakpoints it accepts. */
5096 if (filter && !filter (b))
5099 if (allflag || (user_settable_breakpoint (b)
5102 int addr_bit, type_len;
5104 addr_bit = breakpoint_address_bits (b);
5105 if (addr_bit > print_address_bits)
5106 print_address_bits = addr_bit;
5108 type_len = strlen (bptype_string (b->type));
5109 if (type_len > print_type_col_width)
5110 print_type_col_width = type_len;
5112 nr_printable_breakpoints++;
5116 if (opts.addressprint)
5118 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5119 nr_printable_breakpoints,
5123 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5124 nr_printable_breakpoints,
5127 if (nr_printable_breakpoints > 0)
5128 annotate_breakpoints_headers ();
5129 if (nr_printable_breakpoints > 0)
5131 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5132 if (nr_printable_breakpoints > 0)
5134 ui_out_table_header (uiout, print_type_col_width, ui_left,
5135 "type", "Type"); /* 2 */
5136 if (nr_printable_breakpoints > 0)
5138 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5139 if (nr_printable_breakpoints > 0)
5141 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5142 if (opts.addressprint)
5144 if (nr_printable_breakpoints > 0)
5146 if (print_address_bits <= 32)
5147 ui_out_table_header (uiout, 10, ui_left,
5148 "addr", "Address"); /* 5 */
5150 ui_out_table_header (uiout, 18, ui_left,
5151 "addr", "Address"); /* 5 */
5153 if (nr_printable_breakpoints > 0)
5155 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5156 ui_out_table_body (uiout);
5157 if (nr_printable_breakpoints > 0)
5158 annotate_breakpoints_table ();
5164 || bnum == b->number)
5166 /* If we have a filter, only list the breakpoints it accepts. */
5167 if (filter && !filter (b))
5170 /* We only print out user settable breakpoints unless the
5172 if (allflag || (user_settable_breakpoint (b)
5174 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5178 do_cleanups (bkpttbl_chain);
5180 if (nr_printable_breakpoints == 0)
5182 /* If there's a filter, let the caller decide how to report
5187 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5189 ui_out_message (uiout, 0,
5190 "No breakpoint or watchpoint number %d.\n",
5196 if (last_loc && !server_command)
5197 set_next_address (last_loc->gdbarch, last_loc->address);
5200 /* FIXME? Should this be moved up so that it is only called when
5201 there have been breakpoints? */
5202 annotate_breakpoints_table_end ();
5204 return nr_printable_breakpoints;
5207 /* Display the value of default-collect in a way that is generally
5208 compatible with the breakpoint list. */
5211 default_collect_info (void)
5213 /* If it has no value (which is frequently the case), say nothing; a
5214 message like "No default-collect." gets in user's face when it's
5216 if (!*default_collect)
5219 /* The following phrase lines up nicely with per-tracepoint collect
5221 ui_out_text (uiout, "default collect ");
5222 ui_out_field_string (uiout, "default-collect", default_collect);
5223 ui_out_text (uiout, " \n");
5227 breakpoints_info (char *bnum_exp, int from_tty)
5232 bnum = parse_and_eval_long (bnum_exp);
5234 breakpoint_1 (bnum, 0, NULL);
5236 default_collect_info ();
5240 watchpoints_info (char *wpnum_exp, int from_tty)
5242 int wpnum = -1, num_printed;
5245 wpnum = parse_and_eval_long (wpnum_exp);
5247 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5249 if (num_printed == 0)
5252 ui_out_message (uiout, 0, "No watchpoints.\n");
5254 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5259 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5264 bnum = parse_and_eval_long (bnum_exp);
5266 breakpoint_1 (bnum, 1, NULL);
5268 default_collect_info ();
5272 breakpoint_has_pc (struct breakpoint *b,
5273 struct program_space *pspace,
5274 CORE_ADDR pc, struct obj_section *section)
5276 struct bp_location *bl = b->loc;
5278 for (; bl; bl = bl->next)
5280 if (bl->pspace == pspace
5281 && bl->address == pc
5282 && (!overlay_debugging || bl->section == section))
5288 /* Print a message describing any breakpoints set at PC. This
5289 concerns with logical breakpoints, so we match program spaces, not
5293 describe_other_breakpoints (struct gdbarch *gdbarch,
5294 struct program_space *pspace, CORE_ADDR pc,
5295 struct obj_section *section, int thread)
5298 struct breakpoint *b;
5301 others += breakpoint_has_pc (b, pspace, pc, section);
5305 printf_filtered (_("Note: breakpoint "));
5306 else /* if (others == ???) */
5307 printf_filtered (_("Note: breakpoints "));
5309 if (breakpoint_has_pc (b, pspace, pc, section))
5312 printf_filtered ("%d", b->number);
5313 if (b->thread == -1 && thread != -1)
5314 printf_filtered (" (all threads)");
5315 else if (b->thread != -1)
5316 printf_filtered (" (thread %d)", b->thread);
5317 printf_filtered ("%s%s ",
5318 ((b->enable_state == bp_disabled
5319 || b->enable_state == bp_call_disabled
5320 || b->enable_state == bp_startup_disabled)
5322 : b->enable_state == bp_permanent
5326 : ((others == 1) ? " and" : ""));
5328 printf_filtered (_("also set at pc "));
5329 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5330 printf_filtered (".\n");
5334 /* Set the default place to put a breakpoint
5335 for the `break' command with no arguments. */
5338 set_default_breakpoint (int valid, struct program_space *pspace,
5339 CORE_ADDR addr, struct symtab *symtab,
5342 default_breakpoint_valid = valid;
5343 default_breakpoint_pspace = pspace;
5344 default_breakpoint_address = addr;
5345 default_breakpoint_symtab = symtab;
5346 default_breakpoint_line = line;
5349 /* Return true iff it is meaningful to use the address member of
5350 BPT. For some breakpoint types, the address member is irrelevant
5351 and it makes no sense to attempt to compare it to other addresses
5352 (or use it for any other purpose either).
5354 More specifically, each of the following breakpoint types will
5355 always have a zero valued address and we don't want to mark
5356 breakpoints of any of these types to be a duplicate of an actual
5357 breakpoint at address zero:
5365 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5367 enum bptype type = bpt->type;
5369 return (type != bp_watchpoint && type != bp_catchpoint);
5372 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5373 true if LOC1 and LOC2 represent the same watchpoint location. */
5376 watchpoint_locations_match (struct bp_location *loc1,
5377 struct bp_location *loc2)
5379 /* Both of them must not be in moribund_locations. */
5380 gdb_assert (loc1->owner != NULL);
5381 gdb_assert (loc2->owner != NULL);
5383 /* If the target can evaluate the condition expression in hardware,
5384 then we we need to insert both watchpoints even if they are at
5385 the same place. Otherwise the watchpoint will only trigger when
5386 the condition of whichever watchpoint was inserted evaluates to
5387 true, not giving a chance for GDB to check the condition of the
5388 other watchpoint. */
5389 if ((loc1->owner->cond_exp
5390 && target_can_accel_watchpoint_condition (loc1->address,
5392 loc1->watchpoint_type,
5393 loc1->owner->cond_exp))
5394 || (loc2->owner->cond_exp
5395 && target_can_accel_watchpoint_condition (loc2->address,
5397 loc2->watchpoint_type,
5398 loc2->owner->cond_exp)))
5401 /* Note that this checks the owner's type, not the location's. In
5402 case the target does not support read watchpoints, but does
5403 support access watchpoints, we'll have bp_read_watchpoint
5404 watchpoints with hw_access locations. Those should be considered
5405 duplicates of hw_read locations. The hw_read locations will
5406 become hw_access locations later. */
5407 return (loc1->owner->type == loc2->owner->type
5408 && loc1->pspace->aspace == loc2->pspace->aspace
5409 && loc1->address == loc2->address
5410 && loc1->length == loc2->length);
5413 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5414 same breakpoint location. In most targets, this can only be true
5415 if ASPACE1 matches ASPACE2. On targets that have global
5416 breakpoints, the address space doesn't really matter. */
5419 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5420 struct address_space *aspace2, CORE_ADDR addr2)
5422 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5423 || aspace1 == aspace2)
5427 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5428 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5429 represent the same location. */
5432 breakpoint_locations_match (struct bp_location *loc1,
5433 struct bp_location *loc2)
5435 int hw_point1, hw_point2;
5437 /* Both of them must not be in moribund_locations. */
5438 gdb_assert (loc1->owner != NULL);
5439 gdb_assert (loc2->owner != NULL);
5441 hw_point1 = is_hardware_watchpoint (loc1->owner);
5442 hw_point2 = is_hardware_watchpoint (loc2->owner);
5444 if (hw_point1 != hw_point2)
5447 return watchpoint_locations_match (loc1, loc2);
5449 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5450 loc2->pspace->aspace, loc2->address);
5454 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5455 int bnum, int have_bnum)
5460 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5461 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5463 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5464 bnum, astr1, astr2);
5466 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5469 /* Adjust a breakpoint's address to account for architectural
5470 constraints on breakpoint placement. Return the adjusted address.
5471 Note: Very few targets require this kind of adjustment. For most
5472 targets, this function is simply the identity function. */
5475 adjust_breakpoint_address (struct gdbarch *gdbarch,
5476 CORE_ADDR bpaddr, enum bptype bptype)
5478 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5480 /* Very few targets need any kind of breakpoint adjustment. */
5483 else if (bptype == bp_watchpoint
5484 || bptype == bp_hardware_watchpoint
5485 || bptype == bp_read_watchpoint
5486 || bptype == bp_access_watchpoint
5487 || bptype == bp_catchpoint)
5489 /* Watchpoints and the various bp_catch_* eventpoints should not
5490 have their addresses modified. */
5495 CORE_ADDR adjusted_bpaddr;
5497 /* Some targets have architectural constraints on the placement
5498 of breakpoint instructions. Obtain the adjusted address. */
5499 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5501 /* An adjusted breakpoint address can significantly alter
5502 a user's expectations. Print a warning if an adjustment
5504 if (adjusted_bpaddr != bpaddr)
5505 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5507 return adjusted_bpaddr;
5511 /* Allocate a struct bp_location. */
5513 static struct bp_location *
5514 allocate_bp_location (struct breakpoint *bpt)
5516 struct bp_location *loc;
5518 loc = xmalloc (sizeof (struct bp_location));
5519 memset (loc, 0, sizeof (*loc));
5523 loc->shlib_disabled = 0;
5532 case bp_longjmp_resume:
5534 case bp_exception_resume:
5535 case bp_step_resume:
5536 case bp_watchpoint_scope:
5538 case bp_std_terminate:
5539 case bp_shlib_event:
5540 case bp_thread_event:
5541 case bp_overlay_event:
5543 case bp_longjmp_master:
5544 case bp_std_terminate_master:
5545 case bp_exception_master:
5546 loc->loc_type = bp_loc_software_breakpoint;
5548 case bp_hardware_breakpoint:
5549 loc->loc_type = bp_loc_hardware_breakpoint;
5551 case bp_hardware_watchpoint:
5552 case bp_read_watchpoint:
5553 case bp_access_watchpoint:
5554 loc->loc_type = bp_loc_hardware_watchpoint;
5559 case bp_fast_tracepoint:
5560 case bp_static_tracepoint:
5561 loc->loc_type = bp_loc_other;
5564 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5572 free_bp_location (struct bp_location *loc)
5577 if (loc->function_name)
5578 xfree (loc->function_name);
5583 /* Increment reference count. */
5586 incref_bp_location (struct bp_location *bl)
5591 /* Decrement reference count. If the reference count reaches 0,
5592 destroy the bp_location. Sets *BLP to NULL. */
5595 decref_bp_location (struct bp_location **blp)
5597 gdb_assert ((*blp)->refc > 0);
5599 if (--(*blp)->refc == 0)
5600 free_bp_location (*blp);
5604 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5605 type BPTYPE and has no locations as yet. */
5606 /* This function is used in gdbtk sources and thus can not be made
5609 static struct breakpoint *
5610 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5613 struct breakpoint *b, *b1;
5615 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5616 memset (b, 0, sizeof (*b));
5619 b->gdbarch = gdbarch;
5620 b->language = current_language->la_language;
5621 b->input_radix = input_radix;
5623 b->enable_state = bp_enabled;
5626 b->ignore_count = 0;
5628 b->frame_id = null_frame_id;
5629 b->forked_inferior_pid = null_ptid;
5630 b->exec_pathname = NULL;
5631 b->syscalls_to_be_caught = NULL;
5633 b->condition_not_parsed = 0;
5634 b->py_bp_object = NULL;
5636 /* Add this breakpoint to the end of the chain so that a list of
5637 breakpoints will come out in order of increasing numbers. */
5639 b1 = breakpoint_chain;
5641 breakpoint_chain = b;
5651 /* Initialize loc->function_name. */
5653 set_breakpoint_location_function (struct bp_location *loc)
5655 gdb_assert (loc->owner != NULL);
5657 if (loc->owner->type == bp_breakpoint
5658 || loc->owner->type == bp_hardware_breakpoint
5659 || is_tracepoint (loc->owner))
5661 find_pc_partial_function (loc->address, &(loc->function_name),
5663 if (loc->function_name)
5664 loc->function_name = xstrdup (loc->function_name);
5668 /* Attempt to determine architecture of location identified by SAL. */
5669 static struct gdbarch *
5670 get_sal_arch (struct symtab_and_line sal)
5673 return get_objfile_arch (sal.section->objfile);
5675 return get_objfile_arch (sal.symtab->objfile);
5680 /* set_raw_breakpoint is a low level routine for allocating and
5681 partially initializing a breakpoint of type BPTYPE. The newly
5682 created breakpoint's address, section, source file name, and line
5683 number are provided by SAL. The newly created and partially
5684 initialized breakpoint is added to the breakpoint chain and
5685 is also returned as the value of this function.
5687 It is expected that the caller will complete the initialization of
5688 the newly created breakpoint struct as well as output any status
5689 information regarding the creation of a new breakpoint. In
5690 particular, set_raw_breakpoint does NOT set the breakpoint
5691 number! Care should be taken to not allow an error to occur
5692 prior to completing the initialization of the breakpoint. If this
5693 should happen, a bogus breakpoint will be left on the chain. */
5696 set_raw_breakpoint (struct gdbarch *gdbarch,
5697 struct symtab_and_line sal, enum bptype bptype)
5699 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch,
5701 CORE_ADDR adjusted_address;
5702 struct gdbarch *loc_gdbarch;
5704 loc_gdbarch = get_sal_arch (sal);
5706 loc_gdbarch = b->gdbarch;
5708 if (bptype != bp_catchpoint)
5709 gdb_assert (sal.pspace != NULL);
5711 /* Adjust the breakpoint's address prior to allocating a location.
5712 Once we call allocate_bp_location(), that mostly uninitialized
5713 location will be placed on the location chain. Adjustment of the
5714 breakpoint may cause target_read_memory() to be called and we do
5715 not want its scan of the location chain to find a breakpoint and
5716 location that's only been partially initialized. */
5717 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
5720 b->loc = allocate_bp_location (b);
5721 b->loc->gdbarch = loc_gdbarch;
5722 b->loc->requested_address = sal.pc;
5723 b->loc->address = adjusted_address;
5724 b->loc->pspace = sal.pspace;
5726 /* Store the program space that was used to set the breakpoint, for
5727 breakpoint resetting. */
5728 b->pspace = sal.pspace;
5730 if (sal.symtab == NULL)
5731 b->source_file = NULL;
5733 b->source_file = xstrdup (sal.symtab->filename);
5734 b->loc->section = sal.section;
5735 b->line_number = sal.line;
5737 set_breakpoint_location_function (b->loc);
5739 breakpoints_changed ();
5745 /* Note that the breakpoint object B describes a permanent breakpoint
5746 instruction, hard-wired into the inferior's code. */
5748 make_breakpoint_permanent (struct breakpoint *b)
5750 struct bp_location *bl;
5752 b->enable_state = bp_permanent;
5754 /* By definition, permanent breakpoints are already present in the
5755 code. Mark all locations as inserted. For now,
5756 make_breakpoint_permanent is called in just one place, so it's
5757 hard to say if it's reasonable to have permanent breakpoint with
5758 multiple locations or not, but it's easy to implmement. */
5759 for (bl = b->loc; bl; bl = bl->next)
5763 /* Call this routine when stepping and nexting to enable a breakpoint
5764 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5765 initiated the operation. */
5768 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
5770 struct breakpoint *b, *b_tmp;
5771 int thread = tp->num;
5773 /* To avoid having to rescan all objfile symbols at every step,
5774 we maintain a list of continually-inserted but always disabled
5775 longjmp "master" breakpoints. Here, we simply create momentary
5776 clones of those and enable them for the requested thread. */
5777 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5778 if (b->pspace == current_program_space
5779 && (b->type == bp_longjmp_master
5780 || b->type == bp_exception_master))
5782 struct breakpoint *clone = clone_momentary_breakpoint (b);
5784 clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
5785 clone->thread = thread;
5788 tp->initiating_frame = frame;
5791 /* Delete all longjmp breakpoints from THREAD. */
5793 delete_longjmp_breakpoint (int thread)
5795 struct breakpoint *b, *b_tmp;
5797 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5798 if (b->type == bp_longjmp || b->type == bp_exception)
5800 if (b->thread == thread)
5801 delete_breakpoint (b);
5806 enable_overlay_breakpoints (void)
5808 struct breakpoint *b;
5811 if (b->type == bp_overlay_event)
5813 b->enable_state = bp_enabled;
5814 update_global_location_list (1);
5815 overlay_events_enabled = 1;
5820 disable_overlay_breakpoints (void)
5822 struct breakpoint *b;
5825 if (b->type == bp_overlay_event)
5827 b->enable_state = bp_disabled;
5828 update_global_location_list (0);
5829 overlay_events_enabled = 0;
5833 /* Set an active std::terminate breakpoint for each std::terminate
5834 master breakpoint. */
5836 set_std_terminate_breakpoint (void)
5838 struct breakpoint *b, *b_tmp;
5840 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5841 if (b->pspace == current_program_space
5842 && b->type == bp_std_terminate_master)
5844 struct breakpoint *clone = clone_momentary_breakpoint (b);
5845 clone->type = bp_std_terminate;
5849 /* Delete all the std::terminate breakpoints. */
5851 delete_std_terminate_breakpoint (void)
5853 struct breakpoint *b, *b_tmp;
5855 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5856 if (b->type == bp_std_terminate)
5857 delete_breakpoint (b);
5861 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5863 struct breakpoint *b;
5865 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5867 b->enable_state = bp_enabled;
5868 /* addr_string has to be used or breakpoint_re_set will delete me. */
5870 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5872 update_global_location_list_nothrow (1);
5878 remove_thread_event_breakpoints (void)
5880 struct breakpoint *b, *b_tmp;
5882 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5883 if (b->type == bp_thread_event
5884 && b->loc->pspace == current_program_space)
5885 delete_breakpoint (b);
5888 struct captured_parse_breakpoint_args
5891 struct symtabs_and_lines *sals_p;
5892 char ***addr_string_p;
5896 struct lang_and_radix
5902 /* Create a breakpoint for JIT code registration and unregistration. */
5905 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5907 struct breakpoint *b;
5909 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5910 update_global_location_list_nothrow (1);
5915 remove_solib_event_breakpoints (void)
5917 struct breakpoint *b, *b_tmp;
5919 ALL_BREAKPOINTS_SAFE (b, b_tmp)
5920 if (b->type == bp_shlib_event
5921 && b->loc->pspace == current_program_space)
5922 delete_breakpoint (b);
5926 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5928 struct breakpoint *b;
5930 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5931 update_global_location_list_nothrow (1);
5935 /* Disable any breakpoints that are on code in shared libraries. Only
5936 apply to enabled breakpoints, disabled ones can just stay disabled. */
5939 disable_breakpoints_in_shlibs (void)
5941 struct bp_location *loc, **locp_tmp;
5943 ALL_BP_LOCATIONS (loc, locp_tmp)
5945 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5946 struct breakpoint *b = loc->owner;
5948 /* We apply the check to all breakpoints, including disabled for
5949 those with loc->duplicate set. This is so that when breakpoint
5950 becomes enabled, or the duplicate is removed, gdb will try to
5951 insert all breakpoints. If we don't set shlib_disabled here,
5952 we'll try to insert those breakpoints and fail. */
5953 if (((b->type == bp_breakpoint)
5954 || (b->type == bp_jit_event)
5955 || (b->type == bp_hardware_breakpoint)
5956 || (is_tracepoint (b)))
5957 && loc->pspace == current_program_space
5958 && !loc->shlib_disabled
5960 && PC_SOLIB (loc->address)
5962 && solib_name_from_address (loc->pspace, loc->address)
5966 loc->shlib_disabled = 1;
5971 /* Disable any breakpoints that are in in an unloaded shared library.
5972 Only apply to enabled breakpoints, disabled ones can just stay
5976 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5978 struct bp_location *loc, **locp_tmp;
5979 int disabled_shlib_breaks = 0;
5981 /* SunOS a.out shared libraries are always mapped, so do not
5982 disable breakpoints; they will only be reported as unloaded
5983 through clear_solib when GDB discards its shared library
5984 list. See clear_solib for more information. */
5985 if (exec_bfd != NULL
5986 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5989 ALL_BP_LOCATIONS (loc, locp_tmp)
5991 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5992 struct breakpoint *b = loc->owner;
5994 if ((loc->loc_type == bp_loc_hardware_breakpoint
5995 || loc->loc_type == bp_loc_software_breakpoint)
5996 && solib->pspace == loc->pspace
5997 && !loc->shlib_disabled
5998 && (b->type == bp_breakpoint
5999 || b->type == bp_jit_event
6000 || b->type == bp_hardware_breakpoint)
6001 && solib_contains_address_p (solib, loc->address))
6003 loc->shlib_disabled = 1;
6004 /* At this point, we cannot rely on remove_breakpoint
6005 succeeding so we must mark the breakpoint as not inserted
6006 to prevent future errors occurring in remove_breakpoints. */
6008 if (!disabled_shlib_breaks)
6010 target_terminal_ours_for_output ();
6011 warning (_("Temporarily disabling breakpoints "
6012 "for unloaded shared library \"%s\""),
6015 disabled_shlib_breaks = 1;
6020 /* FORK & VFORK catchpoints. */
6022 /* Implement the "insert" breakpoint_ops method for fork
6026 insert_catch_fork (struct bp_location *bl)
6028 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
6031 /* Implement the "remove" breakpoint_ops method for fork
6035 remove_catch_fork (struct bp_location *bl)
6037 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
6040 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6044 breakpoint_hit_catch_fork (struct breakpoint *b)
6046 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
6049 /* Implement the "print_it" breakpoint_ops method for fork
6052 static enum print_stop_action
6053 print_it_catch_fork (struct breakpoint *b)
6055 annotate_catchpoint (b->number);
6056 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6057 b->number, ptid_get_pid (b->forked_inferior_pid));
6058 return PRINT_SRC_AND_LOC;
6061 /* Implement the "print_one" breakpoint_ops method for fork
6065 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
6067 struct value_print_options opts;
6069 get_user_print_options (&opts);
6071 /* Field 4, the address, is omitted (which makes the columns not
6072 line up too nicely with the headers, but the effect is relatively
6074 if (opts.addressprint)
6075 ui_out_field_skip (uiout, "addr");
6077 ui_out_text (uiout, "fork");
6078 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
6080 ui_out_text (uiout, ", process ");
6081 ui_out_field_int (uiout, "what",
6082 ptid_get_pid (b->forked_inferior_pid));
6083 ui_out_spaces (uiout, 1);
6087 /* Implement the "print_mention" breakpoint_ops method for fork
6091 print_mention_catch_fork (struct breakpoint *b)
6093 printf_filtered (_("Catchpoint %d (fork)"), b->number);
6096 /* Implement the "print_recreate" breakpoint_ops method for fork
6100 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
6102 fprintf_unfiltered (fp, "catch fork");
6105 /* The breakpoint_ops structure to be used in fork catchpoints. */
6107 static struct breakpoint_ops catch_fork_breakpoint_ops =
6111 breakpoint_hit_catch_fork,
6112 NULL, /* resources_needed */
6113 print_it_catch_fork,
6114 print_one_catch_fork,
6115 print_mention_catch_fork,
6116 print_recreate_catch_fork
6119 /* Implement the "insert" breakpoint_ops method for vfork
6123 insert_catch_vfork (struct bp_location *bl)
6125 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
6128 /* Implement the "remove" breakpoint_ops method for vfork
6132 remove_catch_vfork (struct bp_location *bl)
6134 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
6137 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6141 breakpoint_hit_catch_vfork (struct breakpoint *b)
6143 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
6146 /* Implement the "print_it" breakpoint_ops method for vfork
6149 static enum print_stop_action
6150 print_it_catch_vfork (struct breakpoint *b)
6152 annotate_catchpoint (b->number);
6153 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6154 b->number, ptid_get_pid (b->forked_inferior_pid));
6155 return PRINT_SRC_AND_LOC;
6158 /* Implement the "print_one" breakpoint_ops method for vfork
6162 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
6164 struct value_print_options opts;
6166 get_user_print_options (&opts);
6167 /* Field 4, the address, is omitted (which makes the columns not
6168 line up too nicely with the headers, but the effect is relatively
6170 if (opts.addressprint)
6171 ui_out_field_skip (uiout, "addr");
6173 ui_out_text (uiout, "vfork");
6174 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
6176 ui_out_text (uiout, ", process ");
6177 ui_out_field_int (uiout, "what",
6178 ptid_get_pid (b->forked_inferior_pid));
6179 ui_out_spaces (uiout, 1);
6183 /* Implement the "print_mention" breakpoint_ops method for vfork
6187 print_mention_catch_vfork (struct breakpoint *b)
6189 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6192 /* Implement the "print_recreate" breakpoint_ops method for vfork
6196 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6198 fprintf_unfiltered (fp, "catch vfork");
6201 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6203 static struct breakpoint_ops catch_vfork_breakpoint_ops =
6207 breakpoint_hit_catch_vfork,
6208 NULL, /* resources_needed */
6209 print_it_catch_vfork,
6210 print_one_catch_vfork,
6211 print_mention_catch_vfork,
6212 print_recreate_catch_vfork
6215 /* Implement the "insert" breakpoint_ops method for syscall
6219 insert_catch_syscall (struct bp_location *bl)
6221 struct inferior *inf = current_inferior ();
6223 ++inf->total_syscalls_count;
6224 if (!bl->owner->syscalls_to_be_caught)
6225 ++inf->any_syscall_count;
6231 VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter);
6236 if (iter >= VEC_length (int, inf->syscalls_counts))
6238 int old_size = VEC_length (int, inf->syscalls_counts);
6239 uintptr_t vec_addr_offset
6240 = old_size * ((uintptr_t) sizeof (int));
6242 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6243 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6245 memset ((void *) vec_addr, 0,
6246 (iter + 1 - old_size) * sizeof (int));
6248 elem = VEC_index (int, inf->syscalls_counts, iter);
6249 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6253 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6254 inf->total_syscalls_count != 0,
6255 inf->any_syscall_count,
6256 VEC_length (int, inf->syscalls_counts),
6257 VEC_address (int, inf->syscalls_counts));
6260 /* Implement the "remove" breakpoint_ops method for syscall
6264 remove_catch_syscall (struct bp_location *bl)
6266 struct inferior *inf = current_inferior ();
6268 --inf->total_syscalls_count;
6269 if (!bl->owner->syscalls_to_be_caught)
6270 --inf->any_syscall_count;
6276 VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter);
6280 if (iter >= VEC_length (int, inf->syscalls_counts))
6281 /* Shouldn't happen. */
6283 elem = VEC_index (int, inf->syscalls_counts, iter);
6284 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6288 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6289 inf->total_syscalls_count != 0,
6290 inf->any_syscall_count,
6291 VEC_length (int, inf->syscalls_counts),
6293 inf->syscalls_counts));
6296 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6300 breakpoint_hit_catch_syscall (struct breakpoint *b)
6302 /* We must check if we are catching specific syscalls in this
6303 breakpoint. If we are, then we must guarantee that the called
6304 syscall is the same syscall we are catching. */
6305 int syscall_number = 0;
6307 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6310 /* Now, checking if the syscall is the same. */
6311 if (b->syscalls_to_be_caught)
6316 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6318 if (syscall_number == iter)
6328 /* Implement the "print_it" breakpoint_ops method for syscall
6331 static enum print_stop_action
6332 print_it_catch_syscall (struct breakpoint *b)
6334 /* These are needed because we want to know in which state a
6335 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6336 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6337 must print "called syscall" or "returned from syscall". */
6339 struct target_waitstatus last;
6341 struct cleanup *old_chain;
6344 get_last_target_status (&ptid, &last);
6346 get_syscall_by_number (last.value.syscall_number, &s);
6348 annotate_catchpoint (b->number);
6351 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6353 syscall_id = xstrprintf ("'%s'", s.name);
6355 old_chain = make_cleanup (xfree, syscall_id);
6357 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6358 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6359 b->number, syscall_id);
6360 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6361 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6362 b->number, syscall_id);
6364 do_cleanups (old_chain);
6366 return PRINT_SRC_AND_LOC;
6369 /* Implement the "print_one" breakpoint_ops method for syscall
6373 print_one_catch_syscall (struct breakpoint *b,
6374 struct bp_location **last_loc)
6376 struct value_print_options opts;
6378 get_user_print_options (&opts);
6379 /* Field 4, the address, is omitted (which makes the columns not
6380 line up too nicely with the headers, but the effect is relatively
6382 if (opts.addressprint)
6383 ui_out_field_skip (uiout, "addr");
6386 if (b->syscalls_to_be_caught
6387 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6388 ui_out_text (uiout, "syscalls \"");
6390 ui_out_text (uiout, "syscall \"");
6392 if (b->syscalls_to_be_caught)
6395 char *text = xstrprintf ("%s", "");
6398 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6403 get_syscall_by_number (iter, &s);
6406 text = xstrprintf ("%s%s, ", text, s.name);
6408 text = xstrprintf ("%s%d, ", text, iter);
6410 /* We have to xfree the last 'text' (now stored at 'x')
6411 because xstrprintf dinamically allocates new space for it
6415 /* Remove the last comma. */
6416 text[strlen (text) - 2] = '\0';
6417 ui_out_field_string (uiout, "what", text);
6420 ui_out_field_string (uiout, "what", "<any syscall>");
6421 ui_out_text (uiout, "\" ");
6424 /* Implement the "print_mention" breakpoint_ops method for syscall
6428 print_mention_catch_syscall (struct breakpoint *b)
6430 if (b->syscalls_to_be_caught)
6434 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6435 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6437 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6440 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6444 get_syscall_by_number (iter, &s);
6447 printf_filtered (" '%s' [%d]", s.name, s.number);
6449 printf_filtered (" %d", s.number);
6451 printf_filtered (")");
6454 printf_filtered (_("Catchpoint %d (any syscall)"),
6458 /* Implement the "print_recreate" breakpoint_ops method for syscall
6462 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6464 fprintf_unfiltered (fp, "catch syscall");
6466 if (b->syscalls_to_be_caught)
6471 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6476 get_syscall_by_number (iter, &s);
6478 fprintf_unfiltered (fp, " %s", s.name);
6480 fprintf_unfiltered (fp, " %d", s.number);
6485 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6487 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6489 insert_catch_syscall,
6490 remove_catch_syscall,
6491 breakpoint_hit_catch_syscall,
6492 NULL, /* resources_needed */
6493 print_it_catch_syscall,
6494 print_one_catch_syscall,
6495 print_mention_catch_syscall,
6496 print_recreate_catch_syscall
6499 /* Returns non-zero if 'b' is a syscall catchpoint. */
6502 syscall_catchpoint_p (struct breakpoint *b)
6504 return (b->ops == &catch_syscall_breakpoint_ops);
6507 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6508 but does NOT mention it nor update the global location list.
6509 This is useful if you need to fill more fields in the
6510 struct breakpoint before calling mention.
6512 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6513 If COND_STRING is not NULL, then store it in the breakpoint.
6514 OPS, if not NULL, is the breakpoint_ops structure associated
6515 to the catchpoint. */
6517 static struct breakpoint *
6518 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6520 struct breakpoint_ops *ops)
6522 struct symtab_and_line sal;
6523 struct breakpoint *b;
6526 sal.pspace = current_program_space;
6528 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6529 set_breakpoint_count (breakpoint_count + 1);
6530 b->number = breakpoint_count;
6532 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6534 b->addr_string = NULL;
6535 b->enable_state = bp_enabled;
6536 b->disposition = tempflag ? disp_del : disp_donttouch;
6542 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6544 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6545 If COND_STRING is not NULL, then store it in the breakpoint.
6546 OPS, if not NULL, is the breakpoint_ops structure associated
6547 to the catchpoint. */
6549 static struct breakpoint *
6550 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6551 char *cond_string, struct breakpoint_ops *ops)
6553 struct breakpoint *b =
6554 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6557 update_global_location_list (1);
6563 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6564 int tempflag, char *cond_string,
6565 struct breakpoint_ops *ops)
6567 struct breakpoint *b
6568 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6570 /* FIXME: We should put this information in a breakpoint private data
6572 b->forked_inferior_pid = null_ptid;
6575 /* Exec catchpoints. */
6578 insert_catch_exec (struct bp_location *bl)
6580 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6584 remove_catch_exec (struct bp_location *bl)
6586 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6590 breakpoint_hit_catch_exec (struct breakpoint *b)
6592 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6595 static enum print_stop_action
6596 print_it_catch_exec (struct breakpoint *b)
6598 annotate_catchpoint (b->number);
6599 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6601 return PRINT_SRC_AND_LOC;
6605 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6607 struct value_print_options opts;
6609 get_user_print_options (&opts);
6611 /* Field 4, the address, is omitted (which makes the columns
6612 not line up too nicely with the headers, but the effect
6613 is relatively readable). */
6614 if (opts.addressprint)
6615 ui_out_field_skip (uiout, "addr");
6617 ui_out_text (uiout, "exec");
6618 if (b->exec_pathname != NULL)
6620 ui_out_text (uiout, ", program \"");
6621 ui_out_field_string (uiout, "what", b->exec_pathname);
6622 ui_out_text (uiout, "\" ");
6627 print_mention_catch_exec (struct breakpoint *b)
6629 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6632 /* Implement the "print_recreate" breakpoint_ops method for exec
6636 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6638 fprintf_unfiltered (fp, "catch exec");
6641 static struct breakpoint_ops catch_exec_breakpoint_ops =
6645 breakpoint_hit_catch_exec,
6646 NULL, /* resources_needed */
6647 print_it_catch_exec,
6648 print_one_catch_exec,
6649 print_mention_catch_exec,
6650 print_recreate_catch_exec
6654 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6655 struct breakpoint_ops *ops)
6657 struct gdbarch *gdbarch = get_current_arch ();
6658 struct breakpoint *b =
6659 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6661 b->syscalls_to_be_caught = filter;
6663 /* Now, we have to mention the breakpoint and update the global
6666 update_global_location_list (1);
6670 hw_breakpoint_used_count (void)
6672 struct breakpoint *b;
6677 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6685 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6688 struct breakpoint *b;
6689 struct bp_location *bl;
6691 *other_type_used = 0;
6694 if (!breakpoint_enabled (b))
6697 if (b->type == type)
6698 for (bl = b->loc; bl; bl = bl->next)
6700 /* Special types of hardware watchpoints may use more than
6702 if (b->ops && b->ops->resources_needed)
6703 i += b->ops->resources_needed (bl);
6707 else if (is_hardware_watchpoint (b))
6708 *other_type_used = 1;
6715 disable_watchpoints_before_interactive_call_start (void)
6717 struct breakpoint *b;
6721 if (is_watchpoint (b) && breakpoint_enabled (b))
6723 b->enable_state = bp_call_disabled;
6724 update_global_location_list (0);
6730 enable_watchpoints_after_interactive_call_stop (void)
6732 struct breakpoint *b;
6736 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6738 b->enable_state = bp_enabled;
6739 update_global_location_list (1);
6745 disable_breakpoints_before_startup (void)
6747 struct breakpoint *b;
6752 if (b->pspace != current_program_space)
6755 if ((b->type == bp_breakpoint
6756 || b->type == bp_hardware_breakpoint)
6757 && breakpoint_enabled (b))
6759 b->enable_state = bp_startup_disabled;
6765 update_global_location_list (0);
6767 current_program_space->executing_startup = 1;
6771 enable_breakpoints_after_startup (void)
6773 struct breakpoint *b;
6776 current_program_space->executing_startup = 0;
6780 if (b->pspace != current_program_space)
6783 if ((b->type == bp_breakpoint
6784 || b->type == bp_hardware_breakpoint)
6785 && b->enable_state == bp_startup_disabled)
6787 b->enable_state = bp_enabled;
6793 breakpoint_re_set ();
6797 /* Set a breakpoint that will evaporate an end of command
6798 at address specified by SAL.
6799 Restrict it to frame FRAME if FRAME is nonzero. */
6802 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6803 struct frame_id frame_id, enum bptype type)
6805 struct breakpoint *b;
6807 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6809 gdb_assert (!frame_id_inlined_p (frame_id));
6811 b = set_raw_breakpoint (gdbarch, sal, type);
6812 b->enable_state = bp_enabled;
6813 b->disposition = disp_donttouch;
6814 b->frame_id = frame_id;
6816 /* If we're debugging a multi-threaded program, then we want
6817 momentary breakpoints to be active in only a single thread of
6819 if (in_thread_list (inferior_ptid))
6820 b->thread = pid_to_thread_id (inferior_ptid);
6822 update_global_location_list_nothrow (1);
6827 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6831 clone_momentary_breakpoint (struct breakpoint *orig)
6833 struct breakpoint *copy;
6835 /* If there's nothing to clone, then return nothing. */
6839 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6840 copy->loc = allocate_bp_location (copy);
6841 set_breakpoint_location_function (copy->loc);
6843 copy->loc->gdbarch = orig->loc->gdbarch;
6844 copy->loc->requested_address = orig->loc->requested_address;
6845 copy->loc->address = orig->loc->address;
6846 copy->loc->section = orig->loc->section;
6847 copy->loc->pspace = orig->loc->pspace;
6849 if (orig->source_file == NULL)
6850 copy->source_file = NULL;
6852 copy->source_file = xstrdup (orig->source_file);
6854 copy->line_number = orig->line_number;
6855 copy->frame_id = orig->frame_id;
6856 copy->thread = orig->thread;
6857 copy->pspace = orig->pspace;
6859 copy->enable_state = bp_enabled;
6860 copy->disposition = disp_donttouch;
6861 copy->number = internal_breakpoint_number--;
6863 update_global_location_list_nothrow (0);
6868 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6871 struct symtab_and_line sal;
6873 sal = find_pc_line (pc, 0);
6875 sal.section = find_pc_overlay (pc);
6876 sal.explicit_pc = 1;
6878 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6882 /* Tell the user we have just set a breakpoint B. */
6885 mention (struct breakpoint *b)
6888 struct cleanup *ui_out_chain;
6889 struct value_print_options opts;
6891 get_user_print_options (&opts);
6893 /* FIXME: This is misplaced; mention() is called by things (like
6894 hitting a watchpoint) other than breakpoint creation. It should
6895 be possible to clean this up and at the same time replace the
6896 random calls to breakpoint_changed with this hook. */
6897 observer_notify_breakpoint_created (b->number);
6899 if (b->ops != NULL && b->ops->print_mention != NULL)
6900 b->ops->print_mention (b);
6905 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6909 ui_out_text (uiout, "Watchpoint ");
6910 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6911 ui_out_field_int (uiout, "number", b->number);
6912 ui_out_text (uiout, ": ");
6913 ui_out_field_string (uiout, "exp", b->exp_string);
6914 do_cleanups (ui_out_chain);
6916 case bp_hardware_watchpoint:
6917 ui_out_text (uiout, "Hardware watchpoint ");
6918 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6919 ui_out_field_int (uiout, "number", b->number);
6920 ui_out_text (uiout, ": ");
6921 ui_out_field_string (uiout, "exp", b->exp_string);
6922 do_cleanups (ui_out_chain);
6924 case bp_read_watchpoint:
6925 ui_out_text (uiout, "Hardware read watchpoint ");
6926 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6927 ui_out_field_int (uiout, "number", b->number);
6928 ui_out_text (uiout, ": ");
6929 ui_out_field_string (uiout, "exp", b->exp_string);
6930 do_cleanups (ui_out_chain);
6932 case bp_access_watchpoint:
6933 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6934 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6935 ui_out_field_int (uiout, "number", b->number);
6936 ui_out_text (uiout, ": ");
6937 ui_out_field_string (uiout, "exp", b->exp_string);
6938 do_cleanups (ui_out_chain);
6941 if (ui_out_is_mi_like_p (uiout))
6946 if (b->disposition == disp_del)
6947 printf_filtered (_("Temporary breakpoint"));
6949 printf_filtered (_("Breakpoint"));
6950 printf_filtered (_(" %d"), b->number);
6953 case bp_hardware_breakpoint:
6954 if (ui_out_is_mi_like_p (uiout))
6959 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6963 if (ui_out_is_mi_like_p (uiout))
6968 printf_filtered (_("Tracepoint"));
6969 printf_filtered (_(" %d"), b->number);
6972 case bp_fast_tracepoint:
6973 if (ui_out_is_mi_like_p (uiout))
6978 printf_filtered (_("Fast tracepoint"));
6979 printf_filtered (_(" %d"), b->number);
6982 case bp_static_tracepoint:
6983 if (ui_out_is_mi_like_p (uiout))
6988 printf_filtered (_("Static tracepoint"));
6989 printf_filtered (_(" %d"), b->number);
6996 case bp_longjmp_resume:
6998 case bp_exception_resume:
6999 case bp_step_resume:
7001 case bp_std_terminate:
7002 case bp_watchpoint_scope:
7003 case bp_shlib_event:
7004 case bp_thread_event:
7005 case bp_overlay_event:
7007 case bp_longjmp_master:
7008 case bp_std_terminate_master:
7009 case bp_exception_master:
7015 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7019 printf_filtered (_(" (%s) pending."), b->addr_string);
7023 if (opts.addressprint || b->source_file == NULL)
7025 printf_filtered (" at ");
7026 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
7030 printf_filtered (": file %s, line %d.",
7031 b->source_file, b->line_number);
7035 struct bp_location *loc = b->loc;
7037 for (; loc; loc = loc->next)
7039 printf_filtered (" (%d locations)", n);
7044 if (ui_out_is_mi_like_p (uiout))
7046 printf_filtered ("\n");
7050 static struct bp_location *
7051 add_location_to_breakpoint (struct breakpoint *b,
7052 const struct symtab_and_line *sal)
7054 struct bp_location *loc, **tmp;
7056 loc = allocate_bp_location (b);
7057 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
7060 loc->gdbarch = get_sal_arch (*sal);
7062 loc->gdbarch = b->gdbarch;
7063 loc->requested_address = sal->pc;
7064 loc->address = adjust_breakpoint_address (loc->gdbarch,
7065 loc->requested_address, b->type);
7066 loc->pspace = sal->pspace;
7067 gdb_assert (loc->pspace != NULL);
7068 loc->section = sal->section;
7070 set_breakpoint_location_function (loc);
7075 /* Return 1 if LOC is pointing to a permanent breakpoint,
7076 return 0 otherwise. */
7079 bp_loc_is_permanent (struct bp_location *loc)
7083 const gdb_byte *brk;
7084 gdb_byte *target_mem;
7085 struct cleanup *cleanup;
7088 gdb_assert (loc != NULL);
7090 addr = loc->address;
7091 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
7093 /* Software breakpoints unsupported? */
7097 target_mem = alloca (len);
7099 /* Enable the automatic memory restoration from breakpoints while
7100 we read the memory. Otherwise we could say about our temporary
7101 breakpoints they are permanent. */
7102 cleanup = save_current_space_and_thread ();
7104 switch_to_program_space_and_thread (loc->pspace);
7105 make_show_memory_breakpoints_cleanup (0);
7107 if (target_read_memory (loc->address, target_mem, len) == 0
7108 && memcmp (target_mem, brk, len) == 0)
7111 do_cleanups (cleanup);
7118 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7119 as textual description of the location, and COND_STRING
7120 as condition expression. */
7123 create_breakpoint_sal (struct gdbarch *gdbarch,
7124 struct symtabs_and_lines sals, char *addr_string,
7126 enum bptype type, enum bpdisp disposition,
7127 int thread, int task, int ignore_count,
7128 struct breakpoint_ops *ops, int from_tty,
7129 int enabled, int internal)
7131 struct breakpoint *b = NULL;
7134 if (type == bp_hardware_breakpoint)
7136 int i = hw_breakpoint_used_count ();
7137 int target_resources_ok =
7138 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
7140 if (target_resources_ok == 0)
7141 error (_("No hardware breakpoint support in the target."));
7142 else if (target_resources_ok < 0)
7143 error (_("Hardware breakpoints used exceeds limit."));
7146 gdb_assert (sals.nelts > 0);
7148 for (i = 0; i < sals.nelts; ++i)
7150 struct symtab_and_line sal = sals.sals[i];
7151 struct bp_location *loc;
7155 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
7157 loc_gdbarch = gdbarch;
7159 describe_other_breakpoints (loc_gdbarch,
7160 sal.pspace, sal.pc, sal.section, thread);
7165 b = set_raw_breakpoint (gdbarch, sal, type);
7166 set_breakpoint_number (internal, b);
7170 b->cond_string = cond_string;
7171 b->ignore_count = ignore_count;
7172 b->enable_state = enabled ? bp_enabled : bp_disabled;
7173 b->disposition = disposition;
7174 b->pspace = sals.sals[0].pspace;
7176 if (type == bp_static_tracepoint)
7178 struct static_tracepoint_marker marker;
7180 if (is_marker_spec (addr_string))
7182 /* We already know the marker exists, otherwise, we
7183 wouldn't see a sal for it. */
7184 char *p = &addr_string[3];
7189 while (*p == ' ' || *p == '\t')
7193 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7196 marker_str = savestring (p, endp - p);
7197 b->static_trace_marker_id = marker_str;
7199 printf_filtered (_("Probed static tracepoint "
7201 b->static_trace_marker_id);
7203 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7205 b->static_trace_marker_id = xstrdup (marker.str_id);
7206 release_static_tracepoint_marker (&marker);
7208 printf_filtered (_("Probed static tracepoint "
7210 b->static_trace_marker_id);
7213 warning (_("Couldn't determine the static "
7214 "tracepoint marker to probe"));
7217 if (enabled && b->pspace->executing_startup
7218 && (b->type == bp_breakpoint
7219 || b->type == bp_hardware_breakpoint))
7220 b->enable_state = bp_startup_disabled;
7226 loc = add_location_to_breakpoint (b, &sal);
7229 if (bp_loc_is_permanent (loc))
7230 make_breakpoint_permanent (b);
7234 char *arg = b->cond_string;
7235 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7237 error (_("Garbage %s follows condition"), arg);
7242 b->addr_string = addr_string;
7244 /* addr_string has to be used or breakpoint_re_set will delete
7247 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7251 /* Do not mention breakpoints with a negative number, but do
7252 notify observers. */
7253 observer_notify_breakpoint_created (b->number);
7258 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7259 elements to fill the void space. */
7261 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7263 int i = index_to_remove+1;
7264 int last_index = sal->nelts-1;
7266 for (;i <= last_index; ++i)
7267 sal->sals[i-1] = sal->sals[i];
7272 /* If appropriate, obtains all sals that correspond to the same file
7273 and line as SAL, in all program spaces. Users debugging with IDEs,
7274 will want to set a breakpoint at foo.c:line, and not really care
7275 about program spaces. This is done only if SAL does not have
7276 explicit PC and has line and file information. If we got just a
7277 single expanded sal, return the original.
7279 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7280 which the name of enclosing function is different from SAL. This
7281 makes sure that if we have breakpoint originally set in template
7282 instantiation, say foo<int>(), we won't expand SAL to locations at
7283 the same line in all existing instantiations of 'foo'. */
7285 static struct symtabs_and_lines
7286 expand_line_sal_maybe (struct symtab_and_line sal)
7288 struct symtabs_and_lines expanded;
7289 CORE_ADDR original_pc = sal.pc;
7290 char *original_function = NULL;
7293 struct cleanup *old_chain;
7295 /* If we have explicit pc, don't expand.
7296 If we have no line number, we can't expand. */
7297 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7300 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7301 expanded.sals[0] = sal;
7307 old_chain = save_current_space_and_thread ();
7309 switch_to_program_space_and_thread (sal.pspace);
7311 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7313 /* Note that expand_line_sal visits *all* program spaces. */
7314 expanded = expand_line_sal (sal);
7316 if (expanded.nelts == 1)
7318 /* We had one sal, we got one sal. Return that sal, adjusting it
7319 past the function prologue if necessary. */
7320 xfree (expanded.sals);
7322 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7323 sal.pc = original_pc;
7324 expanded.sals[0] = sal;
7325 skip_prologue_sal (&expanded.sals[0]);
7326 do_cleanups (old_chain);
7330 if (!sal.explicit_line)
7332 CORE_ADDR func_addr, func_end;
7333 for (i = 0; i < expanded.nelts; ++i)
7335 CORE_ADDR pc = expanded.sals[i].pc;
7336 char *this_function;
7338 /* We need to switch threads as well since we're about to
7340 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7342 if (find_pc_partial_function (pc, &this_function,
7343 &func_addr, &func_end))
7346 && strcmp (this_function, original_function) != 0)
7348 remove_sal (&expanded, i);
7355 /* Skip the function prologue if necessary. */
7356 for (i = 0; i < expanded.nelts; ++i)
7357 skip_prologue_sal (&expanded.sals[i]);
7359 do_cleanups (old_chain);
7361 if (expanded.nelts <= 1)
7363 /* This is un ugly workaround. If we get zero expanded sals
7364 then something is really wrong. Fix that by returning the
7367 xfree (expanded.sals);
7369 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7370 sal.pc = original_pc;
7371 expanded.sals[0] = sal;
7378 for (i = 0; i < expanded.nelts; ++i)
7379 if (expanded.sals[i].pc == original_pc)
7390 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7391 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7392 value. COND_STRING, if not NULL, specified the condition to be
7393 used for all breakpoints. Essentially the only case where
7394 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7395 function. In that case, it's still not possible to specify
7396 separate conditions for different overloaded functions, so
7397 we take just a single condition string.
7399 NOTE: If the function succeeds, the caller is expected to cleanup
7400 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7401 array contents). If the function fails (error() is called), the
7402 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7403 COND and SALS arrays and each of those arrays contents. */
7406 create_breakpoints_sal (struct gdbarch *gdbarch,
7407 struct symtabs_and_lines sals, char **addr_string,
7409 enum bptype type, enum bpdisp disposition,
7410 int thread, int task, int ignore_count,
7411 struct breakpoint_ops *ops, int from_tty,
7412 int enabled, int internal)
7416 for (i = 0; i < sals.nelts; ++i)
7418 struct symtabs_and_lines expanded =
7419 expand_line_sal_maybe (sals.sals[i]);
7421 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7422 cond_string, type, disposition,
7423 thread, task, ignore_count, ops,
7424 from_tty, enabled, internal);
7428 /* Parse ARG which is assumed to be a SAL specification possibly
7429 followed by conditionals. On return, SALS contains an array of SAL
7430 addresses found. ADDR_STRING contains a vector of (canonical)
7431 address strings. ARG points to the end of the SAL. */
7434 parse_breakpoint_sals (char **address,
7435 struct symtabs_and_lines *sals,
7436 char ***addr_string,
7439 char *addr_start = *address;
7441 *addr_string = NULL;
7442 /* If no arg given, or if first arg is 'if ', use the default
7444 if ((*address) == NULL
7445 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7447 if (default_breakpoint_valid)
7449 struct symtab_and_line sal;
7451 init_sal (&sal); /* Initialize to zeroes. */
7452 sals->sals = (struct symtab_and_line *)
7453 xmalloc (sizeof (struct symtab_and_line));
7454 sal.pc = default_breakpoint_address;
7455 sal.line = default_breakpoint_line;
7456 sal.symtab = default_breakpoint_symtab;
7457 sal.pspace = default_breakpoint_pspace;
7458 sal.section = find_pc_overlay (sal.pc);
7460 /* "break" without arguments is equivalent to "break *PC"
7461 where PC is the default_breakpoint_address. So make sure
7462 to set sal.explicit_pc to prevent GDB from trying to
7463 expand the list of sals to include all other instances
7464 with the same symtab and line. */
7465 sal.explicit_pc = 1;
7467 sals->sals[0] = sal;
7471 error (_("No default breakpoint address now."));
7475 /* Force almost all breakpoints to be in terms of the
7476 current_source_symtab (which is decode_line_1's default).
7477 This should produce the results we want almost all of the
7478 time while leaving default_breakpoint_* alone.
7480 ObjC: However, don't match an Objective-C method name which
7481 may have a '+' or '-' succeeded by a '[' */
7483 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7485 if (default_breakpoint_valid
7487 || ((strchr ("+-", (*address)[0]) != NULL)
7488 && ((*address)[1] != '['))))
7489 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7490 default_breakpoint_line, addr_string,
7493 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7494 addr_string, not_found_ptr);
7496 /* For any SAL that didn't have a canonical string, fill one in. */
7497 if (sals->nelts > 0 && *addr_string == NULL)
7498 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7499 if (addr_start != (*address))
7503 for (i = 0; i < sals->nelts; i++)
7505 /* Add the string if not present. */
7506 if ((*addr_string)[i] == NULL)
7507 (*addr_string)[i] = savestring (addr_start,
7508 (*address) - addr_start);
7514 /* Convert each SAL into a real PC. Verify that the PC can be
7515 inserted as a breakpoint. If it can't throw an error. */
7518 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7522 for (i = 0; i < sals->nelts; i++)
7523 resolve_sal_pc (&sals->sals[i]);
7526 /* Fast tracepoints may have restrictions on valid locations. For
7527 instance, a fast tracepoint using a jump instead of a trap will
7528 likely have to overwrite more bytes than a trap would, and so can
7529 only be placed where the instruction is longer than the jump, or a
7530 multi-instruction sequence does not have a jump into the middle of
7534 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7535 struct symtabs_and_lines *sals)
7538 struct symtab_and_line *sal;
7540 struct cleanup *old_chain;
7542 for (i = 0; i < sals->nelts; i++)
7544 sal = &sals->sals[i];
7546 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7548 old_chain = make_cleanup (xfree, msg);
7551 error (_("May not have a fast tracepoint at 0x%s%s"),
7552 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7554 do_cleanups (old_chain);
7559 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7561 struct captured_parse_breakpoint_args *args = data;
7563 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7564 args->not_found_ptr);
7567 /* Given TOK, a string specification of condition and thread, as
7568 accepted by the 'break' command, extract the condition
7569 string and thread number and set *COND_STRING and *THREAD.
7570 PC identifies the context at which the condition should be parsed.
7571 If no condition is found, *COND_STRING is set to NULL.
7572 If no thread is found, *THREAD is set to -1. */
7574 find_condition_and_thread (char *tok, CORE_ADDR pc,
7575 char **cond_string, int *thread, int *task)
7577 *cond_string = NULL;
7583 char *cond_start = NULL;
7584 char *cond_end = NULL;
7586 while (*tok == ' ' || *tok == '\t')
7591 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7594 toklen = end_tok - tok;
7596 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7598 struct expression *expr;
7600 tok = cond_start = end_tok + 1;
7601 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7604 *cond_string = savestring (cond_start,
7605 cond_end - cond_start);
7607 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7613 *thread = strtol (tok, &tok, 0);
7615 error (_("Junk after thread keyword."));
7616 if (!valid_thread_id (*thread))
7617 error (_("Unknown thread %d."), *thread);
7619 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7625 *task = strtol (tok, &tok, 0);
7627 error (_("Junk after task keyword."));
7628 if (!valid_task_id (*task))
7629 error (_("Unknown task %d."), *task);
7632 error (_("Junk at end of arguments."));
7636 /* Decode a static tracepoint marker spec. */
7638 static struct symtabs_and_lines
7639 decode_static_tracepoint_spec (char **arg_p)
7641 VEC(static_tracepoint_marker_p) *markers = NULL;
7642 struct symtabs_and_lines sals;
7643 struct symtab_and_line sal;
7645 struct cleanup *old_chain;
7646 char *p = &(*arg_p)[3];
7651 while (*p == ' ' || *p == '\t')
7655 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7658 marker_str = savestring (p, endp - p);
7659 old_chain = make_cleanup (xfree, marker_str);
7661 markers = target_static_tracepoint_markers_by_strid (marker_str);
7662 if (VEC_empty(static_tracepoint_marker_p, markers))
7663 error (_("No known static tracepoint marker named %s"), marker_str);
7665 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7666 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7668 for (i = 0; i < sals.nelts; i++)
7670 struct static_tracepoint_marker *marker;
7672 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7674 init_sal (&sals.sals[i]);
7676 sals.sals[i] = find_pc_line (marker->address, 0);
7677 sals.sals[i].pc = marker->address;
7679 release_static_tracepoint_marker (marker);
7682 do_cleanups (old_chain);
7688 /* Set a breakpoint. This function is shared between CLI and MI
7689 functions for setting a breakpoint. This function has two major
7690 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7691 parameter. If non-zero, the function will parse arg, extracting
7692 breakpoint location, address and thread. Otherwise, ARG is just
7693 the location of breakpoint, with condition and thread specified by
7694 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7695 the breakpoint number will be allocated from the internal
7696 breakpoint count. Returns true if any breakpoint was created;
7700 create_breakpoint (struct gdbarch *gdbarch,
7701 char *arg, char *cond_string, int thread,
7702 int parse_condition_and_thread,
7703 int tempflag, enum bptype type_wanted,
7705 enum auto_boolean pending_break_support,
7706 struct breakpoint_ops *ops,
7707 int from_tty, int enabled, int internal)
7709 struct gdb_exception e;
7710 struct symtabs_and_lines sals;
7711 struct symtab_and_line pending_sal;
7713 char *addr_start = arg;
7715 struct cleanup *old_chain;
7716 struct cleanup *bkpt_chain = NULL;
7717 struct captured_parse_breakpoint_args parse_args;
7722 int prev_bkpt_count = breakpoint_count;
7728 parse_args.arg_p = &arg;
7729 parse_args.sals_p = &sals;
7730 parse_args.addr_string_p = &addr_string;
7731 parse_args.not_found_ptr = ¬_found;
7733 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7737 sals = decode_static_tracepoint_spec (&arg);
7739 copy_arg = savestring (addr_start, arg - addr_start);
7740 addr_string = xcalloc (sals.nelts, sizeof (char **));
7741 for (i = 0; i < sals.nelts; i++)
7742 addr_string[i] = xstrdup (copy_arg);
7746 e = catch_exception (uiout, do_captured_parse_breakpoint,
7747 &parse_args, RETURN_MASK_ALL);
7749 /* If caller is interested in rc value from parse, set value. */
7753 throw_exception (e);
7757 case NOT_FOUND_ERROR:
7759 /* If pending breakpoint support is turned off, throw
7762 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7763 throw_exception (e);
7765 exception_print (gdb_stderr, e);
7767 /* If pending breakpoint support is auto query and the user
7768 selects no, then simply return the error code. */
7769 if (pending_break_support == AUTO_BOOLEAN_AUTO
7770 && !nquery (_("Make breakpoint pending on "
7771 "future shared library load? ")))
7774 /* At this point, either the user was queried about setting
7775 a pending breakpoint and selected yes, or pending
7776 breakpoint behavior is on and thus a pending breakpoint
7777 is defaulted on behalf of the user. */
7778 copy_arg = xstrdup (addr_start);
7779 addr_string = ©_arg;
7781 sals.sals = &pending_sal;
7786 throw_exception (e);
7795 /* Create a chain of things that always need to be cleaned up. */
7796 old_chain = make_cleanup (null_cleanup, 0);
7800 /* Make sure that all storage allocated to SALS gets freed. */
7801 make_cleanup (xfree, sals.sals);
7803 /* Cleanup the addr_string array but not its contents. */
7804 make_cleanup (xfree, addr_string);
7807 /* ----------------------------- SNIP -----------------------------
7808 Anything added to the cleanup chain beyond this point is assumed
7809 to be part of a breakpoint. If the breakpoint create succeeds
7810 then the memory is not reclaimed. */
7811 bkpt_chain = make_cleanup (null_cleanup, 0);
7813 /* Mark the contents of the addr_string for cleanup. These go on
7814 the bkpt_chain and only occur if the breakpoint create fails. */
7815 for (i = 0; i < sals.nelts; i++)
7817 if (addr_string[i] != NULL)
7818 make_cleanup (xfree, addr_string[i]);
7821 /* Resolve all line numbers to PC's and verify that the addresses
7822 are ok for the target. */
7824 breakpoint_sals_to_pc (&sals);
7826 /* Fast tracepoints may have additional restrictions on location. */
7827 if (type_wanted == bp_fast_tracepoint)
7828 check_fast_tracepoint_sals (gdbarch, &sals);
7830 /* Verify that condition can be parsed, before setting any
7831 breakpoints. Allocate a separate condition expression for each
7835 if (parse_condition_and_thread)
7837 /* Here we only parse 'arg' to separate condition
7838 from thread number, so parsing in context of first
7839 sal is OK. When setting the breakpoint we'll
7840 re-parse it in context of each sal. */
7843 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7846 make_cleanup (xfree, cond_string);
7850 /* Create a private copy of condition string. */
7853 cond_string = xstrdup (cond_string);
7854 make_cleanup (xfree, cond_string);
7858 /* If the user is creating a static tracepoint by marker id
7859 (strace -m MARKER_ID), then store the sals index, so that
7860 breakpoint_re_set can try to match up which of the newly
7861 found markers corresponds to this one, and, don't try to
7862 expand multiple locations for each sal, given than SALS
7863 already should contain all sals for MARKER_ID. */
7864 if (type_wanted == bp_static_tracepoint
7865 && is_marker_spec (addr_string[0]))
7869 for (i = 0; i < sals.nelts; ++i)
7871 struct symtabs_and_lines expanded;
7872 struct breakpoint *tp;
7873 struct cleanup *old_chain;
7876 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7877 expanded.sals[0] = sals.sals[i];
7878 old_chain = make_cleanup (xfree, expanded.sals);
7880 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7881 cond_string, type_wanted,
7882 tempflag ? disp_del : disp_donttouch,
7883 thread, task, ignore_count, ops,
7884 from_tty, enabled, internal);
7886 do_cleanups (old_chain);
7888 /* Get the tracepoint we just created. */
7890 tp = get_breakpoint (internal_breakpoint_number);
7892 tp = get_breakpoint (breakpoint_count);
7893 gdb_assert (tp != NULL);
7895 /* Given that its possible to have multiple markers with
7896 the same string id, if the user is creating a static
7897 tracepoint by marker id ("strace -m MARKER_ID"), then
7898 store the sals index, so that breakpoint_re_set can
7899 try to match up which of the newly found markers
7900 corresponds to this one */
7901 tp->static_trace_marker_id_idx = i;
7905 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7907 tempflag ? disp_del : disp_donttouch,
7908 thread, task, ignore_count, ops, from_tty,
7913 struct breakpoint *b;
7915 make_cleanup (xfree, copy_arg);
7917 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7918 set_breakpoint_number (internal, b);
7920 b->addr_string = addr_string[0];
7921 b->cond_string = NULL;
7922 b->ignore_count = ignore_count;
7923 b->disposition = tempflag ? disp_del : disp_donttouch;
7924 b->condition_not_parsed = 1;
7926 b->enable_state = enabled ? bp_enabled : bp_disabled;
7927 b->pspace = current_program_space;
7928 b->py_bp_object = NULL;
7930 if (enabled && b->pspace->executing_startup
7931 && (b->type == bp_breakpoint
7932 || b->type == bp_hardware_breakpoint))
7933 b->enable_state = bp_startup_disabled;
7936 /* Do not mention breakpoints with a negative number,
7937 but do notify observers. */
7938 observer_notify_breakpoint_created (b->number);
7945 warning (_("Multiple breakpoints were set.\nUse the "
7946 "\"delete\" command to delete unwanted breakpoints."));
7947 prev_breakpoint_count = prev_bkpt_count;
7950 /* That's it. Discard the cleanups for data inserted into the
7952 discard_cleanups (bkpt_chain);
7953 /* But cleanup everything else. */
7954 do_cleanups (old_chain);
7956 /* error call may happen here - have BKPT_CHAIN already discarded. */
7957 update_global_location_list (1);
7962 /* Set a breakpoint.
7963 ARG is a string describing breakpoint address,
7964 condition, and thread.
7965 FLAG specifies if a breakpoint is hardware on,
7966 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7970 break_command_1 (char *arg, int flag, int from_tty)
7972 int tempflag = flag & BP_TEMPFLAG;
7973 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
7974 ? bp_hardware_breakpoint
7977 create_breakpoint (get_current_arch (),
7979 NULL, 0, 1 /* parse arg */,
7980 tempflag, type_wanted,
7981 0 /* Ignore count */,
7982 pending_break_support,
7983 NULL /* breakpoint_ops */,
7990 /* Helper function for break_command_1 and disassemble_command. */
7993 resolve_sal_pc (struct symtab_and_line *sal)
7997 if (sal->pc == 0 && sal->symtab != NULL)
7999 if (!find_line_pc (sal->symtab, sal->line, &pc))
8000 error (_("No line %d in file \"%s\"."),
8001 sal->line, sal->symtab->filename);
8004 /* If this SAL corresponds to a breakpoint inserted using a line
8005 number, then skip the function prologue if necessary. */
8006 if (sal->explicit_line)
8007 skip_prologue_sal (sal);
8010 if (sal->section == 0 && sal->symtab != NULL)
8012 struct blockvector *bv;
8016 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
8019 sym = block_linkage_function (b);
8022 fixup_symbol_section (sym, sal->symtab->objfile);
8023 sal->section = SYMBOL_OBJ_SECTION (sym);
8027 /* It really is worthwhile to have the section, so we'll
8028 just have to look harder. This case can be executed
8029 if we have line numbers but no functions (as can
8030 happen in assembly source). */
8032 struct minimal_symbol *msym;
8033 struct cleanup *old_chain = save_current_space_and_thread ();
8035 switch_to_program_space_and_thread (sal->pspace);
8037 msym = lookup_minimal_symbol_by_pc (sal->pc);
8039 sal->section = SYMBOL_OBJ_SECTION (msym);
8041 do_cleanups (old_chain);
8048 break_command (char *arg, int from_tty)
8050 break_command_1 (arg, 0, from_tty);
8054 tbreak_command (char *arg, int from_tty)
8056 break_command_1 (arg, BP_TEMPFLAG, from_tty);
8060 hbreak_command (char *arg, int from_tty)
8062 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
8066 thbreak_command (char *arg, int from_tty)
8068 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
8072 stop_command (char *arg, int from_tty)
8074 printf_filtered (_("Specify the type of breakpoint to set.\n\
8075 Usage: stop in <function | address>\n\
8076 stop at <line>\n"));
8080 stopin_command (char *arg, int from_tty)
8084 if (arg == (char *) NULL)
8086 else if (*arg != '*')
8091 /* Look for a ':'. If this is a line number specification, then
8092 say it is bad, otherwise, it should be an address or
8093 function/method name. */
8094 while (*argptr && !hasColon)
8096 hasColon = (*argptr == ':');
8101 badInput = (*argptr != ':'); /* Not a class::method */
8103 badInput = isdigit (*arg); /* a simple line number */
8107 printf_filtered (_("Usage: stop in <function | address>\n"));
8109 break_command_1 (arg, 0, from_tty);
8113 stopat_command (char *arg, int from_tty)
8117 if (arg == (char *) NULL || *arg == '*') /* no line number */
8124 /* Look for a ':'. If there is a '::' then get out, otherwise
8125 it is probably a line number. */
8126 while (*argptr && !hasColon)
8128 hasColon = (*argptr == ':');
8133 badInput = (*argptr == ':'); /* we have class::method */
8135 badInput = !isdigit (*arg); /* not a line number */
8139 printf_filtered (_("Usage: stop at <line>\n"));
8141 break_command_1 (arg, 0, from_tty);
8144 /* Return non-zero if EXP is verified as constant. Returned zero
8145 means EXP is variable. Also the constant detection may fail for
8146 some constant expressions and in such case still falsely return
8149 watchpoint_exp_is_const (const struct expression *exp)
8157 /* We are only interested in the descriptor of each element. */
8158 operator_length (exp, i, &oplenp, &argsp);
8161 switch (exp->elts[i].opcode)
8171 case BINOP_LOGICAL_AND:
8172 case BINOP_LOGICAL_OR:
8173 case BINOP_BITWISE_AND:
8174 case BINOP_BITWISE_IOR:
8175 case BINOP_BITWISE_XOR:
8177 case BINOP_NOTEQUAL:
8193 case TERNOP_SLICE_COUNT:
8205 case OP_OBJC_NSSTRING:
8208 case UNOP_LOGICAL_NOT:
8209 case UNOP_COMPLEMENT:
8212 /* Unary, binary and ternary operators: We have to check
8213 their operands. If they are constant, then so is the
8214 result of that operation. For instance, if A and B are
8215 determined to be constants, then so is "A + B".
8217 UNOP_IND is one exception to the rule above, because the
8218 value of *ADDR is not necessarily a constant, even when
8223 /* Check whether the associated symbol is a constant.
8225 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8226 possible that a buggy compiler could mark a variable as
8227 constant even when it is not, and TYPE_CONST would return
8228 true in this case, while SYMBOL_CLASS wouldn't.
8230 We also have to check for function symbols because they
8231 are always constant. */
8233 struct symbol *s = exp->elts[i + 2].symbol;
8235 if (SYMBOL_CLASS (s) != LOC_BLOCK
8236 && SYMBOL_CLASS (s) != LOC_CONST
8237 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8242 /* The default action is to return 0 because we are using
8243 the optimistic approach here: If we don't know something,
8244 then it is not a constant. */
8253 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8256 insert_watchpoint (struct bp_location *bl)
8258 int length = bl->owner->exact? 1 : bl->length;
8260 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
8261 bl->owner->cond_exp);
8264 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8267 remove_watchpoint (struct bp_location *bl)
8269 int length = bl->owner->exact? 1 : bl->length;
8271 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
8272 bl->owner->cond_exp);
8275 /* Implement the "resources_needed" breakpoint_ops method for
8276 hardware watchpoints. */
8279 resources_needed_watchpoint (const struct bp_location *bl)
8281 int length = bl->owner->exact? 1 : bl->length;
8283 return target_region_ok_for_hw_watchpoint (bl->address, length);
8286 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8288 static struct breakpoint_ops watchpoint_breakpoint_ops =
8292 NULL, /* breakpoint_hit */
8293 resources_needed_watchpoint,
8294 NULL, /* print_it */
8295 NULL, /* print_one */
8296 NULL, /* print_mention */
8297 NULL /* print_recreate */
8300 /* accessflag: hw_write: watch write,
8301 hw_read: watch read,
8302 hw_access: watch access (read or write) */
8304 watch_command_1 (char *arg, int accessflag, int from_tty,
8305 int just_location, int internal)
8307 struct breakpoint *b, *scope_breakpoint = NULL;
8308 struct expression *exp;
8309 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
8310 struct value *val, *mark, *result;
8311 struct frame_info *frame;
8312 char *exp_start = NULL;
8313 char *exp_end = NULL;
8314 char *tok, *id_tok_start, *end_tok;
8316 char *cond_start = NULL;
8317 char *cond_end = NULL;
8318 int i, other_type_used, target_resources_ok = 0;
8319 enum bptype bp_type;
8324 /* Make sure that we actually have parameters to parse. */
8325 if (arg != NULL && arg[0] != '\0')
8327 toklen = strlen (arg); /* Size of argument list. */
8329 /* Points tok to the end of the argument list. */
8330 tok = arg + toklen - 1;
8332 /* Go backwards in the parameters list. Skip the last
8333 parameter. If we're expecting a 'thread <thread_num>'
8334 parameter, this should be the thread identifier. */
8335 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8337 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8340 /* Points end_tok to the beginning of the last token. */
8341 id_tok_start = tok + 1;
8343 /* Go backwards in the parameters list. Skip one more
8344 parameter. If we're expecting a 'thread <thread_num>'
8345 parameter, we should reach a "thread" token. */
8346 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8351 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8354 /* Move the pointer forward to skip the whitespace and
8355 calculate the length of the token. */
8357 toklen = end_tok - tok;
8359 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8361 /* At this point we've found a "thread" token, which means
8362 the user is trying to set a watchpoint that triggers
8363 only in a specific thread. */
8366 /* Extract the thread ID from the next token. */
8367 thread = strtol (id_tok_start, &endp, 0);
8369 /* Check if the user provided a valid numeric value for the
8371 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
8372 error (_("Invalid thread ID specification %s."), id_tok_start);
8374 /* Check if the thread actually exists. */
8375 if (!valid_thread_id (thread))
8376 error (_("Unknown thread %d."), thread);
8378 /* Truncate the string and get rid of the thread <thread_num>
8379 parameter before the parameter list is parsed by the
8380 evaluate_expression() function. */
8385 /* Parse the rest of the arguments. */
8386 innermost_block = NULL;
8388 exp = parse_exp_1 (&arg, 0, 0);
8390 /* Remove trailing whitespace from the expression before saving it.
8391 This makes the eventual display of the expression string a bit
8393 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
8396 /* Checking if the expression is not constant. */
8397 if (watchpoint_exp_is_const (exp))
8401 len = exp_end - exp_start;
8402 while (len > 0 && isspace (exp_start[len - 1]))
8404 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
8407 exp_valid_block = innermost_block;
8408 mark = value_mark ();
8409 fetch_subexp_value (exp, &pc, &val, &result, NULL);
8413 exp_valid_block = NULL;
8414 val = value_addr (result);
8415 release_value (val);
8416 value_free_to_mark (mark);
8418 else if (val != NULL)
8419 release_value (val);
8422 while (*tok == ' ' || *tok == '\t')
8426 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
8429 toklen = end_tok - tok;
8430 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8432 struct expression *cond;
8434 innermost_block = NULL;
8435 tok = cond_start = end_tok + 1;
8436 cond = parse_exp_1 (&tok, 0, 0);
8438 /* The watchpoint expression may not be local, but the condition
8439 may still be. E.g.: `watch global if local > 0'. */
8440 cond_exp_valid_block = innermost_block;
8446 error (_("Junk at end of command."));
8448 if (accessflag == hw_read)
8449 bp_type = bp_read_watchpoint;
8450 else if (accessflag == hw_access)
8451 bp_type = bp_access_watchpoint;
8453 bp_type = bp_hardware_watchpoint;
8455 reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints);
8456 if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint)
8457 error (_("Expression cannot be implemented with read/access watchpoint."));
8460 i = hw_watchpoint_used_count (bp_type, &other_type_used);
8461 target_resources_ok =
8462 target_can_use_hardware_watchpoint (bp_type, i + reg_cnt,
8464 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8465 error (_("Target does not support this type of hardware watchpoint."));
8467 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8468 error (_("Target can only support one kind "
8469 "of HW watchpoint at a time."));
8472 /* Change the type of breakpoint to an ordinary watchpoint if a
8473 hardware watchpoint could not be set. */
8474 if (!reg_cnt || target_resources_ok <= 0)
8475 bp_type = bp_watchpoint;
8477 frame = block_innermost_frame (exp_valid_block);
8479 /* If the expression is "local", then set up a "watchpoint scope"
8480 breakpoint at the point where we've left the scope of the watchpoint
8481 expression. Create the scope breakpoint before the watchpoint, so
8482 that we will encounter it first in bpstat_stop_status. */
8483 if (exp_valid_block && frame)
8485 if (frame_id_p (frame_unwind_caller_id (frame)))
8488 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
8489 frame_unwind_caller_pc (frame),
8490 bp_watchpoint_scope);
8492 scope_breakpoint->enable_state = bp_enabled;
8494 /* Automatically delete the breakpoint when it hits. */
8495 scope_breakpoint->disposition = disp_del;
8497 /* Only break in the proper frame (help with recursion). */
8498 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
8500 /* Set the address at which we will stop. */
8501 scope_breakpoint->loc->gdbarch
8502 = frame_unwind_caller_arch (frame);
8503 scope_breakpoint->loc->requested_address
8504 = frame_unwind_caller_pc (frame);
8505 scope_breakpoint->loc->address
8506 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
8507 scope_breakpoint->loc->requested_address,
8508 scope_breakpoint->type);
8512 /* Now set up the breakpoint. */
8513 b = set_raw_breakpoint_without_location (NULL, bp_type);
8514 set_breakpoint_number (internal, b);
8516 b->disposition = disp_donttouch;
8518 b->exp_valid_block = exp_valid_block;
8519 b->cond_exp_valid_block = cond_exp_valid_block;
8522 struct type *t = value_type (val);
8523 CORE_ADDR addr = value_as_address (val);
8526 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
8527 name = type_to_string (t);
8529 b->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
8530 core_addr_to_string (addr));
8533 b->exp_string = xstrprintf ("-location: %.*s",
8534 (int) (exp_end - exp_start), exp_start);
8536 /* The above expression is in C. */
8537 b->language = language_c;
8540 b->exp_string = savestring (exp_start, exp_end - exp_start);
8543 b->ops = &watchpoint_breakpoint_ops;
8545 /* Use an exact watchpoint when there's only one memory region to be
8546 watched, and only one debug register is needed to watch it. */
8547 b->exact = target_exact_watchpoints && reg_cnt == 1;
8550 b->cond_string = savestring (cond_start, cond_end - cond_start);
8556 b->watchpoint_frame = get_frame_id (frame);
8557 b->watchpoint_thread = inferior_ptid;
8561 b->watchpoint_frame = null_frame_id;
8562 b->watchpoint_thread = null_ptid;
8565 if (scope_breakpoint != NULL)
8567 /* The scope breakpoint is related to the watchpoint. We will
8568 need to act on them together. */
8569 b->related_breakpoint = scope_breakpoint;
8570 scope_breakpoint->related_breakpoint = b;
8574 value_free_to_mark (mark);
8576 /* Finally update the new watchpoint. This creates the locations
8577 that should be inserted. */
8578 update_watchpoint (b, 1);
8580 /* Do not mention breakpoints with a negative number, but do
8581 notify observers. */
8582 observer_notify_breakpoint_created (b->number);
8585 update_global_location_list (1);
8588 /* Return count of debug registers needed to watch the given expression.
8589 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8590 the start of the watched region will be monitored (i.e., all accesses
8591 will be aligned). This uses less debug registers on some targets.
8593 If the watchpoint cannot be handled in hardware return zero. */
8596 can_use_hardware_watchpoint (struct value *v, int exact_watchpoints)
8598 int found_memory_cnt = 0;
8599 struct value *head = v;
8601 /* Did the user specifically forbid us to use hardware watchpoints? */
8602 if (!can_use_hw_watchpoints)
8605 /* Make sure that the value of the expression depends only upon
8606 memory contents, and values computed from them within GDB. If we
8607 find any register references or function calls, we can't use a
8608 hardware watchpoint.
8610 The idea here is that evaluating an expression generates a series
8611 of values, one holding the value of every subexpression. (The
8612 expression a*b+c has five subexpressions: a, b, a*b, c, and
8613 a*b+c.) GDB's values hold almost enough information to establish
8614 the criteria given above --- they identify memory lvalues,
8615 register lvalues, computed values, etcetera. So we can evaluate
8616 the expression, and then scan the chain of values that leaves
8617 behind to decide whether we can detect any possible change to the
8618 expression's final value using only hardware watchpoints.
8620 However, I don't think that the values returned by inferior
8621 function calls are special in any way. So this function may not
8622 notice that an expression involving an inferior function call
8623 can't be watched with hardware watchpoints. FIXME. */
8624 for (; v; v = value_next (v))
8626 if (VALUE_LVAL (v) == lval_memory)
8628 if (v != head && value_lazy (v))
8629 /* A lazy memory lvalue in the chain is one that GDB never
8630 needed to fetch; we either just used its address (e.g.,
8631 `a' in `a.b') or we never needed it at all (e.g., `a'
8632 in `a,b'). This doesn't apply to HEAD; if that is
8633 lazy then it was not readable, but watch it anyway. */
8637 /* Ahh, memory we actually used! Check if we can cover
8638 it with hardware watchpoints. */
8639 struct type *vtype = check_typedef (value_type (v));
8641 /* We only watch structs and arrays if user asked for it
8642 explicitly, never if they just happen to appear in a
8643 middle of some value chain. */
8645 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
8646 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
8648 CORE_ADDR vaddr = value_address (v);
8652 len = (exact_watchpoints
8653 && is_scalar_type_recursive (vtype))?
8654 1 : TYPE_LENGTH (value_type (v));
8656 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
8660 found_memory_cnt += num_regs;
8664 else if (VALUE_LVAL (v) != not_lval
8665 && deprecated_value_modifiable (v) == 0)
8666 return 0; /* These are values from the history (e.g., $1). */
8667 else if (VALUE_LVAL (v) == lval_register)
8668 return 0; /* Cannot watch a register with a HW watchpoint. */
8671 /* The expression itself looks suitable for using a hardware
8672 watchpoint, but give the target machine a chance to reject it. */
8673 return found_memory_cnt;
8677 watch_command_wrapper (char *arg, int from_tty, int internal)
8679 watch_command_1 (arg, hw_write, from_tty, 0, internal);
8682 /* A helper function that looks for an argument at the start of a
8683 string. The argument must also either be at the end of the string,
8684 or be followed by whitespace. Returns 1 if it finds the argument,
8685 0 otherwise. If the argument is found, it updates *STR. */
8688 check_for_argument (char **str, char *arg, int arg_len)
8690 if (strncmp (*str, arg, arg_len) == 0
8691 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
8699 /* A helper function that looks for the "-location" argument and then
8700 calls watch_command_1. */
8703 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
8705 int just_location = 0;
8708 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
8709 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
8711 ep_skip_leading_whitespace (&arg);
8715 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
8719 watch_command (char *arg, int from_tty)
8721 watch_maybe_just_location (arg, hw_write, from_tty);
8725 rwatch_command_wrapper (char *arg, int from_tty, int internal)
8727 watch_command_1 (arg, hw_read, from_tty, 0, internal);
8731 rwatch_command (char *arg, int from_tty)
8733 watch_maybe_just_location (arg, hw_read, from_tty);
8737 awatch_command_wrapper (char *arg, int from_tty, int internal)
8739 watch_command_1 (arg, hw_access, from_tty, 0, internal);
8743 awatch_command (char *arg, int from_tty)
8745 watch_maybe_just_location (arg, hw_access, from_tty);
8749 /* Helper routines for the until_command routine in infcmd.c. Here
8750 because it uses the mechanisms of breakpoints. */
8752 struct until_break_command_continuation_args
8754 struct breakpoint *breakpoint;
8755 struct breakpoint *breakpoint2;
8759 /* This function is called by fetch_inferior_event via the
8760 cmd_continuation pointer, to complete the until command. It takes
8761 care of cleaning up the temporary breakpoints set up by the until
8764 until_break_command_continuation (void *arg)
8766 struct until_break_command_continuation_args *a = arg;
8768 delete_breakpoint (a->breakpoint);
8770 delete_breakpoint (a->breakpoint2);
8771 delete_longjmp_breakpoint (a->thread_num);
8775 until_break_command (char *arg, int from_tty, int anywhere)
8777 struct symtabs_and_lines sals;
8778 struct symtab_and_line sal;
8779 struct frame_info *frame = get_selected_frame (NULL);
8780 struct breakpoint *breakpoint;
8781 struct breakpoint *breakpoint2 = NULL;
8782 struct cleanup *old_chain;
8784 struct thread_info *tp;
8786 clear_proceed_status ();
8788 /* Set a breakpoint where the user wants it and at return from
8791 if (default_breakpoint_valid)
8792 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8793 default_breakpoint_line, (char ***) NULL, NULL);
8795 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8796 0, (char ***) NULL, NULL);
8798 if (sals.nelts != 1)
8799 error (_("Couldn't get information on specified line."));
8802 xfree (sals.sals); /* malloc'd, so freed. */
8805 error (_("Junk at end of arguments."));
8807 resolve_sal_pc (&sal);
8810 /* If the user told us to continue until a specified location,
8811 we don't specify a frame at which we need to stop. */
8812 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8813 null_frame_id, bp_until);
8815 /* Otherwise, specify the selected frame, because we want to stop
8816 only at the very same frame. */
8817 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8818 get_stack_frame_id (frame),
8821 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8823 tp = inferior_thread ();
8826 /* Keep within the current frame, or in frames called by the current
8829 if (frame_id_p (frame_unwind_caller_id (frame)))
8831 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8832 sal.pc = frame_unwind_caller_pc (frame);
8833 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8835 frame_unwind_caller_id (frame),
8837 make_cleanup_delete_breakpoint (breakpoint2);
8839 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame));
8840 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
8843 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8845 /* If we are running asynchronously, and proceed call above has
8846 actually managed to start the target, arrange for breakpoints to
8847 be deleted when the target stops. Otherwise, we're already
8848 stopped and delete breakpoints via cleanup chain. */
8850 if (target_can_async_p () && is_running (inferior_ptid))
8852 struct until_break_command_continuation_args *args;
8853 args = xmalloc (sizeof (*args));
8855 args->breakpoint = breakpoint;
8856 args->breakpoint2 = breakpoint2;
8857 args->thread_num = thread;
8859 discard_cleanups (old_chain);
8860 add_continuation (inferior_thread (),
8861 until_break_command_continuation, args,
8865 do_cleanups (old_chain);
8869 ep_skip_leading_whitespace (char **s)
8871 if ((s == NULL) || (*s == NULL))
8873 while (isspace (**s))
8877 /* This function attempts to parse an optional "if <cond>" clause
8878 from the arg string. If one is not found, it returns NULL.
8880 Else, it returns a pointer to the condition string. (It does not
8881 attempt to evaluate the string against a particular block.) And,
8882 it updates arg to point to the first character following the parsed
8883 if clause in the arg string. */
8886 ep_parse_optional_if_clause (char **arg)
8890 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8893 /* Skip the "if" keyword. */
8896 /* Skip any extra leading whitespace, and record the start of the
8897 condition string. */
8898 ep_skip_leading_whitespace (arg);
8901 /* Assume that the condition occupies the remainder of the arg
8903 (*arg) += strlen (cond_string);
8908 /* Commands to deal with catching events, such as signals, exceptions,
8909 process start/exit, etc. */
8913 catch_fork_temporary, catch_vfork_temporary,
8914 catch_fork_permanent, catch_vfork_permanent
8919 catch_fork_command_1 (char *arg, int from_tty,
8920 struct cmd_list_element *command)
8922 struct gdbarch *gdbarch = get_current_arch ();
8923 char *cond_string = NULL;
8924 catch_fork_kind fork_kind;
8927 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8928 tempflag = (fork_kind == catch_fork_temporary
8929 || fork_kind == catch_vfork_temporary);
8933 ep_skip_leading_whitespace (&arg);
8935 /* The allowed syntax is:
8937 catch [v]fork if <cond>
8939 First, check if there's an if clause. */
8940 cond_string = ep_parse_optional_if_clause (&arg);
8942 if ((*arg != '\0') && !isspace (*arg))
8943 error (_("Junk at end of arguments."));
8945 /* If this target supports it, create a fork or vfork catchpoint
8946 and enable reporting of such events. */
8949 case catch_fork_temporary:
8950 case catch_fork_permanent:
8951 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8952 &catch_fork_breakpoint_ops);
8954 case catch_vfork_temporary:
8955 case catch_vfork_permanent:
8956 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8957 &catch_vfork_breakpoint_ops);
8960 error (_("unsupported or unknown fork kind; cannot catch it"));
8966 catch_exec_command_1 (char *arg, int from_tty,
8967 struct cmd_list_element *command)
8969 struct gdbarch *gdbarch = get_current_arch ();
8971 char *cond_string = NULL;
8973 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8977 ep_skip_leading_whitespace (&arg);
8979 /* The allowed syntax is:
8981 catch exec if <cond>
8983 First, check if there's an if clause. */
8984 cond_string = ep_parse_optional_if_clause (&arg);
8986 if ((*arg != '\0') && !isspace (*arg))
8987 error (_("Junk at end of arguments."));
8989 /* If this target supports it, create an exec catchpoint
8990 and enable reporting of such events. */
8991 create_catchpoint (gdbarch, tempflag, cond_string,
8992 &catch_exec_breakpoint_ops);
8995 static enum print_stop_action
8996 print_exception_catchpoint (struct breakpoint *b)
8998 int bp_temp, bp_throw;
9000 annotate_catchpoint (b->number);
9002 bp_throw = strstr (b->addr_string, "throw") != NULL;
9003 if (b->loc->address != b->loc->requested_address)
9004 breakpoint_adjustment_warning (b->loc->requested_address,
9007 bp_temp = b->disposition == disp_del;
9009 bp_temp ? "Temporary catchpoint "
9011 if (!ui_out_is_mi_like_p (uiout))
9012 ui_out_field_int (uiout, "bkptno", b->number);
9014 bp_throw ? " (exception thrown), "
9015 : " (exception caught), ");
9016 if (ui_out_is_mi_like_p (uiout))
9018 ui_out_field_string (uiout, "reason",
9019 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9020 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9021 ui_out_field_int (uiout, "bkptno", b->number);
9023 return PRINT_SRC_AND_LOC;
9027 print_one_exception_catchpoint (struct breakpoint *b,
9028 struct bp_location **last_loc)
9030 struct value_print_options opts;
9032 get_user_print_options (&opts);
9033 if (opts.addressprint)
9036 if (b->loc == NULL || b->loc->shlib_disabled)
9037 ui_out_field_string (uiout, "addr", "<PENDING>");
9039 ui_out_field_core_addr (uiout, "addr",
9040 b->loc->gdbarch, b->loc->address);
9045 if (strstr (b->addr_string, "throw") != NULL)
9046 ui_out_field_string (uiout, "what", "exception throw");
9048 ui_out_field_string (uiout, "what", "exception catch");
9052 print_mention_exception_catchpoint (struct breakpoint *b)
9057 bp_temp = b->disposition == disp_del;
9058 bp_throw = strstr (b->addr_string, "throw") != NULL;
9059 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
9060 : _("Catchpoint "));
9061 ui_out_field_int (uiout, "bkptno", b->number);
9062 ui_out_text (uiout, bp_throw ? _(" (throw)")
9066 /* Implement the "print_recreate" breakpoint_ops method for throw and
9067 catch catchpoints. */
9070 print_recreate_exception_catchpoint (struct breakpoint *b,
9076 bp_temp = b->disposition == disp_del;
9077 bp_throw = strstr (b->addr_string, "throw") != NULL;
9078 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
9079 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
9082 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
9085 NULL, /* breakpoint_hit */
9086 NULL, /* resources_needed */
9087 print_exception_catchpoint,
9088 print_one_exception_catchpoint,
9089 print_mention_exception_catchpoint,
9090 print_recreate_exception_catchpoint
9094 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
9095 enum exception_event_kind ex_event, int from_tty)
9097 char *trigger_func_name;
9099 if (ex_event == EX_EVENT_CATCH)
9100 trigger_func_name = "__cxa_begin_catch";
9102 trigger_func_name = "__cxa_throw";
9104 create_breakpoint (get_current_arch (),
9105 trigger_func_name, cond_string, -1,
9106 0 /* condition and thread are valid. */,
9107 tempflag, bp_breakpoint,
9109 AUTO_BOOLEAN_TRUE /* pending */,
9110 &gnu_v3_exception_catchpoint_ops, from_tty,
9117 /* Deal with "catch catch" and "catch throw" commands. */
9120 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
9121 int tempflag, int from_tty)
9123 char *cond_string = NULL;
9127 ep_skip_leading_whitespace (&arg);
9129 cond_string = ep_parse_optional_if_clause (&arg);
9131 if ((*arg != '\0') && !isspace (*arg))
9132 error (_("Junk at end of arguments."));
9134 if (ex_event != EX_EVENT_THROW
9135 && ex_event != EX_EVENT_CATCH)
9136 error (_("Unsupported or unknown exception event; cannot catch it"));
9138 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
9141 warning (_("Unsupported with this platform/compiler combination."));
9144 /* Implementation of "catch catch" command. */
9147 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
9149 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9151 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
9154 /* Implementation of "catch throw" command. */
9157 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
9159 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9161 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
9164 /* Create a breakpoint struct for Ada exception catchpoints. */
9167 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
9168 struct symtab_and_line sal,
9172 struct expression *cond,
9173 struct breakpoint_ops *ops,
9177 struct breakpoint *b;
9181 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9183 loc_gdbarch = gdbarch;
9185 describe_other_breakpoints (loc_gdbarch,
9186 sal.pspace, sal.pc, sal.section, -1);
9187 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9188 version for exception catchpoints, because two catchpoints
9189 used for different exception names will use the same address.
9190 In this case, a "breakpoint ... also set at..." warning is
9191 unproductive. Besides, the warning phrasing is also a bit
9192 inapropriate, we should use the word catchpoint, and tell
9193 the user what type of catchpoint it is. The above is good
9194 enough for now, though. */
9197 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
9198 set_breakpoint_count (breakpoint_count + 1);
9200 b->enable_state = bp_enabled;
9201 b->disposition = tempflag ? disp_del : disp_donttouch;
9202 b->number = breakpoint_count;
9203 b->ignore_count = 0;
9204 b->loc->cond = cond;
9205 b->addr_string = addr_string;
9206 b->language = language_ada;
9207 b->cond_string = cond_string;
9208 b->exp_string = exp_string;
9213 update_global_location_list (1);
9216 /* Implement the "catch exception" command. */
9219 catch_ada_exception_command (char *arg, int from_tty,
9220 struct cmd_list_element *command)
9222 struct gdbarch *gdbarch = get_current_arch ();
9224 struct symtab_and_line sal;
9225 char *addr_string = NULL;
9226 char *exp_string = NULL;
9227 char *cond_string = NULL;
9228 struct expression *cond = NULL;
9229 struct breakpoint_ops *ops = NULL;
9231 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9235 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
9236 &cond_string, &cond, &ops);
9237 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
9238 cond_string, cond, ops, tempflag,
9242 /* Cleanup function for a syscall filter list. */
9244 clean_up_filters (void *arg)
9246 VEC(int) *iter = *(VEC(int) **) arg;
9247 VEC_free (int, iter);
9250 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9251 filter list, or NULL if no filtering is required. */
9253 catch_syscall_split_args (char *arg)
9255 VEC(int) *result = NULL;
9256 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
9258 while (*arg != '\0')
9260 int i, syscall_number;
9265 /* Skip whitespace. */
9266 while (isspace (*arg))
9269 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
9270 cur_name[i] = arg[i];
9274 /* Check if the user provided a syscall name or a number. */
9275 syscall_number = (int) strtol (cur_name, &endptr, 0);
9276 if (*endptr == '\0')
9277 get_syscall_by_number (syscall_number, &s);
9280 /* We have a name. Let's check if it's valid and convert it
9282 get_syscall_by_name (cur_name, &s);
9284 if (s.number == UNKNOWN_SYSCALL)
9285 /* Here we have to issue an error instead of a warning,
9286 because GDB cannot do anything useful if there's no
9287 syscall number to be caught. */
9288 error (_("Unknown syscall name '%s'."), cur_name);
9291 /* Ok, it's valid. */
9292 VEC_safe_push (int, result, s.number);
9295 discard_cleanups (cleanup);
9299 /* Implement the "catch syscall" command. */
9302 catch_syscall_command_1 (char *arg, int from_tty,
9303 struct cmd_list_element *command)
9308 struct gdbarch *gdbarch = get_current_arch ();
9310 /* Checking if the feature if supported. */
9311 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
9312 error (_("The feature 'catch syscall' is not supported on \
9313 this architeture yet."));
9315 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9317 ep_skip_leading_whitespace (&arg);
9319 /* We need to do this first "dummy" translation in order
9320 to get the syscall XML file loaded or, most important,
9321 to display a warning to the user if there's no XML file
9322 for his/her architecture. */
9323 get_syscall_by_number (0, &s);
9325 /* The allowed syntax is:
9327 catch syscall <name | number> [<name | number> ... <name | number>]
9329 Let's check if there's a syscall name. */
9332 filter = catch_syscall_split_args (arg);
9336 create_syscall_event_catchpoint (tempflag, filter,
9337 &catch_syscall_breakpoint_ops);
9340 /* Implement the "catch assert" command. */
9343 catch_assert_command (char *arg, int from_tty,
9344 struct cmd_list_element *command)
9346 struct gdbarch *gdbarch = get_current_arch ();
9348 struct symtab_and_line sal;
9349 char *addr_string = NULL;
9350 struct breakpoint_ops *ops = NULL;
9352 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
9356 sal = ada_decode_assert_location (arg, &addr_string, &ops);
9357 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
9358 ops, tempflag, from_tty);
9362 catch_command (char *arg, int from_tty)
9364 error (_("Catch requires an event name."));
9369 tcatch_command (char *arg, int from_tty)
9371 error (_("Catch requires an event name."));
9374 /* Delete breakpoints by address or line. */
9377 clear_command (char *arg, int from_tty)
9379 struct breakpoint *b;
9380 VEC(breakpoint_p) *found = 0;
9383 struct symtabs_and_lines sals;
9384 struct symtab_and_line sal;
9389 sals = decode_line_spec (arg, 1);
9394 sals.sals = (struct symtab_and_line *)
9395 xmalloc (sizeof (struct symtab_and_line));
9396 make_cleanup (xfree, sals.sals);
9397 init_sal (&sal); /* Initialize to zeroes. */
9398 sal.line = default_breakpoint_line;
9399 sal.symtab = default_breakpoint_symtab;
9400 sal.pc = default_breakpoint_address;
9401 sal.pspace = default_breakpoint_pspace;
9402 if (sal.symtab == 0)
9403 error (_("No source file specified."));
9411 /* We don't call resolve_sal_pc here. That's not as bad as it
9412 seems, because all existing breakpoints typically have both
9413 file/line and pc set. So, if clear is given file/line, we can
9414 match this to existing breakpoint without obtaining pc at all.
9416 We only support clearing given the address explicitly
9417 present in breakpoint table. Say, we've set breakpoint
9418 at file:line. There were several PC values for that file:line,
9419 due to optimization, all in one block.
9421 We've picked one PC value. If "clear" is issued with another
9422 PC corresponding to the same file:line, the breakpoint won't
9423 be cleared. We probably can still clear the breakpoint, but
9424 since the other PC value is never presented to user, user
9425 can only find it by guessing, and it does not seem important
9428 /* For each line spec given, delete bps which correspond to it. Do
9429 it in two passes, solely to preserve the current behavior that
9430 from_tty is forced true if we delete more than one
9434 for (i = 0; i < sals.nelts; i++)
9436 /* If exact pc given, clear bpts at that pc.
9437 If line given (pc == 0), clear all bpts on specified line.
9438 If defaulting, clear all bpts on default line
9441 defaulting sal.pc != 0 tests to do
9446 1 0 <can't happen> */
9450 /* Find all matching breakpoints and add them to 'found'. */
9454 /* Are we going to delete b? */
9455 if (b->type != bp_none && !is_watchpoint (b))
9457 struct bp_location *loc = b->loc;
9458 for (; loc; loc = loc->next)
9460 int pc_match = sal.pc
9461 && (loc->pspace == sal.pspace)
9462 && (loc->address == sal.pc)
9463 && (!section_is_overlay (loc->section)
9464 || loc->section == sal.section);
9465 int line_match = ((default_match || (0 == sal.pc))
9466 && b->source_file != NULL
9467 && sal.symtab != NULL
9468 && sal.pspace == loc->pspace
9469 && strcmp (b->source_file,
9470 sal.symtab->filename) == 0
9471 && b->line_number == sal.line);
9472 if (pc_match || line_match)
9481 VEC_safe_push(breakpoint_p, found, b);
9484 /* Now go thru the 'found' chain and delete them. */
9485 if (VEC_empty(breakpoint_p, found))
9488 error (_("No breakpoint at %s."), arg);
9490 error (_("No breakpoint at this line."));
9493 if (VEC_length(breakpoint_p, found) > 1)
9494 from_tty = 1; /* Always report if deleted more than one. */
9497 if (VEC_length(breakpoint_p, found) == 1)
9498 printf_unfiltered (_("Deleted breakpoint "));
9500 printf_unfiltered (_("Deleted breakpoints "));
9502 breakpoints_changed ();
9504 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
9507 printf_unfiltered ("%d ", b->number);
9508 delete_breakpoint (b);
9511 putchar_unfiltered ('\n');
9514 /* Delete breakpoint in BS if they are `delete' breakpoints and
9515 all breakpoints that are marked for deletion, whether hit or not.
9516 This is called after any breakpoint is hit, or after errors. */
9519 breakpoint_auto_delete (bpstat bs)
9521 struct breakpoint *b, *b_tmp;
9523 for (; bs; bs = bs->next)
9524 if (bs->breakpoint_at
9525 && bs->breakpoint_at->disposition == disp_del
9527 delete_breakpoint (bs->breakpoint_at);
9529 ALL_BREAKPOINTS_SAFE (b, b_tmp)
9531 if (b->disposition == disp_del_at_next_stop)
9532 delete_breakpoint (b);
9536 /* A comparison function for bp_location AP and BP being interfaced to
9537 qsort. Sort elements primarily by their ADDRESS (no matter what
9538 does breakpoint_address_is_meaningful say for its OWNER),
9539 secondarily by ordering first bp_permanent OWNERed elements and
9540 terciarily just ensuring the array is sorted stable way despite
9541 qsort being an instable algorithm. */
9544 bp_location_compare (const void *ap, const void *bp)
9546 struct bp_location *a = *(void **) ap;
9547 struct bp_location *b = *(void **) bp;
9548 /* A and B come from existing breakpoints having non-NULL OWNER. */
9549 int a_perm = a->owner->enable_state == bp_permanent;
9550 int b_perm = b->owner->enable_state == bp_permanent;
9552 if (a->address != b->address)
9553 return (a->address > b->address) - (a->address < b->address);
9555 /* Sort permanent breakpoints first. */
9556 if (a_perm != b_perm)
9557 return (a_perm < b_perm) - (a_perm > b_perm);
9559 /* Make the user-visible order stable across GDB runs. Locations of
9560 the same breakpoint can be sorted in arbitrary order. */
9562 if (a->owner->number != b->owner->number)
9563 return (a->owner->number > b->owner->number)
9564 - (a->owner->number < b->owner->number);
9566 return (a > b) - (a < b);
9569 /* Set bp_location_placed_address_before_address_max and
9570 bp_location_shadow_len_after_address_max according to the current
9571 content of the bp_location array. */
9574 bp_location_target_extensions_update (void)
9576 struct bp_location *bl, **blp_tmp;
9578 bp_location_placed_address_before_address_max = 0;
9579 bp_location_shadow_len_after_address_max = 0;
9581 ALL_BP_LOCATIONS (bl, blp_tmp)
9583 CORE_ADDR start, end, addr;
9585 if (!bp_location_has_shadow (bl))
9588 start = bl->target_info.placed_address;
9589 end = start + bl->target_info.shadow_len;
9591 gdb_assert (bl->address >= start);
9592 addr = bl->address - start;
9593 if (addr > bp_location_placed_address_before_address_max)
9594 bp_location_placed_address_before_address_max = addr;
9596 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9598 gdb_assert (bl->address < end);
9599 addr = end - bl->address;
9600 if (addr > bp_location_shadow_len_after_address_max)
9601 bp_location_shadow_len_after_address_max = addr;
9605 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9606 into the inferior, only remove already-inserted locations that no
9607 longer should be inserted. Functions that delete a breakpoint or
9608 breakpoints should pass false, so that deleting a breakpoint
9609 doesn't have the side effect of inserting the locations of other
9610 breakpoints that are marked not-inserted, but should_be_inserted
9611 returns true on them.
9613 This behaviour is useful is situations close to tear-down -- e.g.,
9614 after an exec, while the target still has execution, but breakpoint
9615 shadows of the previous executable image should *NOT* be restored
9616 to the new image; or before detaching, where the target still has
9617 execution and wants to delete breakpoints from GDB's lists, and all
9618 breakpoints had already been removed from the inferior. */
9621 update_global_location_list (int should_insert)
9623 struct breakpoint *b;
9624 struct bp_location **locp, *loc;
9625 struct cleanup *cleanups;
9627 /* Used in the duplicates detection below. When iterating over all
9628 bp_locations, points to the first bp_location of a given address.
9629 Breakpoints and watchpoints of different types are never
9630 duplicates of each other. Keep one pointer for each type of
9631 breakpoint/watchpoint, so we only need to loop over all locations
9633 struct bp_location *bp_loc_first; /* breakpoint */
9634 struct bp_location *wp_loc_first; /* hardware watchpoint */
9635 struct bp_location *awp_loc_first; /* access watchpoint */
9636 struct bp_location *rwp_loc_first; /* read watchpoint */
9638 /* Saved former bp_location array which we compare against the newly
9639 built bp_location from the current state of ALL_BREAKPOINTS. */
9640 struct bp_location **old_location, **old_locp;
9641 unsigned old_location_count;
9643 old_location = bp_location;
9644 old_location_count = bp_location_count;
9646 bp_location_count = 0;
9647 cleanups = make_cleanup (xfree, old_location);
9650 for (loc = b->loc; loc; loc = loc->next)
9651 bp_location_count++;
9653 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
9656 for (loc = b->loc; loc; loc = loc->next)
9658 qsort (bp_location, bp_location_count, sizeof (*bp_location),
9659 bp_location_compare);
9661 bp_location_target_extensions_update ();
9663 /* Identify bp_location instances that are no longer present in the
9664 new list, and therefore should be freed. Note that it's not
9665 necessary that those locations should be removed from inferior --
9666 if there's another location at the same address (previously
9667 marked as duplicate), we don't need to remove/insert the
9670 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9671 and former bp_location array state respectively. */
9674 for (old_locp = old_location; old_locp < old_location + old_location_count;
9677 struct bp_location *old_loc = *old_locp;
9678 struct bp_location **loc2p;
9680 /* Tells if 'old_loc' is found amoung the new locations. If
9681 not, we have to free it. */
9682 int found_object = 0;
9683 /* Tells if the location should remain inserted in the target. */
9684 int keep_in_target = 0;
9687 /* Skip LOCP entries which will definitely never be needed.
9688 Stop either at or being the one matching OLD_LOC. */
9689 while (locp < bp_location + bp_location_count
9690 && (*locp)->address < old_loc->address)
9694 (loc2p < bp_location + bp_location_count
9695 && (*loc2p)->address == old_loc->address);
9698 if (*loc2p == old_loc)
9705 /* If this location is no longer present, and inserted, look if
9706 there's maybe a new location at the same address. If so,
9707 mark that one inserted, and don't remove this one. This is
9708 needed so that we don't have a time window where a breakpoint
9709 at certain location is not inserted. */
9711 if (old_loc->inserted)
9713 /* If the location is inserted now, we might have to remove
9716 if (found_object && should_be_inserted (old_loc))
9718 /* The location is still present in the location list,
9719 and still should be inserted. Don't do anything. */
9724 /* The location is either no longer present, or got
9725 disabled. See if there's another location at the
9726 same address, in which case we don't need to remove
9727 this one from the target. */
9729 /* OLD_LOC comes from existing struct breakpoint. */
9730 if (breakpoint_address_is_meaningful (old_loc->owner))
9733 (loc2p < bp_location + bp_location_count
9734 && (*loc2p)->address == old_loc->address);
9737 struct bp_location *loc2 = *loc2p;
9739 if (breakpoint_locations_match (loc2, old_loc))
9741 /* For the sake of should_be_inserted.
9742 Duplicates check below will fix up this
9744 loc2->duplicate = 0;
9746 /* Read watchpoint locations are switched to
9747 access watchpoints, if the former are not
9748 supported, but the latter are. */
9749 if (is_hardware_watchpoint (old_loc->owner))
9751 gdb_assert (is_hardware_watchpoint (loc2->owner));
9752 loc2->watchpoint_type = old_loc->watchpoint_type;
9755 if (loc2 != old_loc && should_be_inserted (loc2))
9758 loc2->target_info = old_loc->target_info;
9767 if (!keep_in_target)
9769 if (remove_breakpoint (old_loc, mark_uninserted))
9771 /* This is just about all we can do. We could keep
9772 this location on the global list, and try to
9773 remove it next time, but there's no particular
9774 reason why we will succeed next time.
9776 Note that at this point, old_loc->owner is still
9777 valid, as delete_breakpoint frees the breakpoint
9778 only after calling us. */
9779 printf_filtered (_("warning: Error removing "
9781 old_loc->owner->number);
9789 if (removed && non_stop
9790 && breakpoint_address_is_meaningful (old_loc->owner)
9791 && !is_hardware_watchpoint (old_loc->owner))
9793 /* This location was removed from the target. In
9794 non-stop mode, a race condition is possible where
9795 we've removed a breakpoint, but stop events for that
9796 breakpoint are already queued and will arrive later.
9797 We apply an heuristic to be able to distinguish such
9798 SIGTRAPs from other random SIGTRAPs: we keep this
9799 breakpoint location for a bit, and will retire it
9800 after we see some number of events. The theory here
9801 is that reporting of events should, "on the average",
9802 be fair, so after a while we'll see events from all
9803 threads that have anything of interest, and no longer
9804 need to keep this breakpoint location around. We
9805 don't hold locations forever so to reduce chances of
9806 mistaking a non-breakpoint SIGTRAP for a breakpoint
9809 The heuristic failing can be disastrous on
9810 decr_pc_after_break targets.
9812 On decr_pc_after_break targets, like e.g., x86-linux,
9813 if we fail to recognize a late breakpoint SIGTRAP,
9814 because events_till_retirement has reached 0 too
9815 soon, we'll fail to do the PC adjustment, and report
9816 a random SIGTRAP to the user. When the user resumes
9817 the inferior, it will most likely immediately crash
9818 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9819 corrupted, because of being resumed e.g., in the
9820 middle of a multi-byte instruction, or skipped a
9821 one-byte instruction. This was actually seen happen
9822 on native x86-linux, and should be less rare on
9823 targets that do not support new thread events, like
9824 remote, due to the heuristic depending on
9827 Mistaking a random SIGTRAP for a breakpoint trap
9828 causes similar symptoms (PC adjustment applied when
9829 it shouldn't), but then again, playing with SIGTRAPs
9830 behind the debugger's back is asking for trouble.
9832 Since hardware watchpoint traps are always
9833 distinguishable from other traps, so we don't need to
9834 apply keep hardware watchpoint moribund locations
9835 around. We simply always ignore hardware watchpoint
9836 traps we can no longer explain. */
9838 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9839 old_loc->owner = NULL;
9841 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9845 old_loc->owner = NULL;
9846 decref_bp_location (&old_loc);
9851 /* Rescan breakpoints at the same address and section, marking the
9852 first one as "first" and any others as "duplicates". This is so
9853 that the bpt instruction is only inserted once. If we have a
9854 permanent breakpoint at the same place as BPT, make that one the
9855 official one, and the rest as duplicates. Permanent breakpoints
9856 are sorted first for the same address.
9858 Do the same for hardware watchpoints, but also considering the
9859 watchpoint's type (regular/access/read) and length. */
9861 bp_loc_first = NULL;
9862 wp_loc_first = NULL;
9863 awp_loc_first = NULL;
9864 rwp_loc_first = NULL;
9865 ALL_BP_LOCATIONS (loc, locp)
9867 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9869 struct breakpoint *b = loc->owner;
9870 struct bp_location **loc_first_p;
9872 if (b->enable_state == bp_disabled
9873 || b->enable_state == bp_call_disabled
9874 || b->enable_state == bp_startup_disabled
9876 || loc->shlib_disabled
9877 || !breakpoint_address_is_meaningful (b)
9878 || is_tracepoint (b))
9881 /* Permanent breakpoint should always be inserted. */
9882 if (b->enable_state == bp_permanent && ! loc->inserted)
9883 internal_error (__FILE__, __LINE__,
9884 _("allegedly permanent breakpoint is not "
9885 "actually inserted"));
9887 if (b->type == bp_hardware_watchpoint)
9888 loc_first_p = &wp_loc_first;
9889 else if (b->type == bp_read_watchpoint)
9890 loc_first_p = &rwp_loc_first;
9891 else if (b->type == bp_access_watchpoint)
9892 loc_first_p = &awp_loc_first;
9894 loc_first_p = &bp_loc_first;
9896 if (*loc_first_p == NULL
9897 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9898 || !breakpoint_locations_match (loc, *loc_first_p))
9907 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9908 && b->enable_state != bp_permanent)
9909 internal_error (__FILE__, __LINE__,
9910 _("another breakpoint was inserted on top of "
9911 "a permanent breakpoint"));
9914 if (breakpoints_always_inserted_mode () && should_insert
9915 && (have_live_inferiors ()
9916 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9917 insert_breakpoint_locations ();
9919 do_cleanups (cleanups);
9923 breakpoint_retire_moribund (void)
9925 struct bp_location *loc;
9928 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9929 if (--(loc->events_till_retirement) == 0)
9931 decref_bp_location (&loc);
9932 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9938 update_global_location_list_nothrow (int inserting)
9940 struct gdb_exception e;
9942 TRY_CATCH (e, RETURN_MASK_ERROR)
9943 update_global_location_list (inserting);
9946 /* Clear BKP from a BPS. */
9949 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
9953 for (bs = bps; bs; bs = bs->next)
9954 if (bs->breakpoint_at == bpt)
9956 bs->breakpoint_at = NULL;
9958 /* bs->commands will be freed later. */
9962 /* Callback for iterate_over_threads. */
9964 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
9966 struct breakpoint *bpt = data;
9968 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
9972 /* Delete a breakpoint and clean up all traces of it in the data
9976 delete_breakpoint (struct breakpoint *bpt)
9978 struct breakpoint *b;
9980 gdb_assert (bpt != NULL);
9982 /* Has this bp already been deleted? This can happen because
9983 multiple lists can hold pointers to bp's. bpstat lists are
9986 One example of this happening is a watchpoint's scope bp. When
9987 the scope bp triggers, we notice that the watchpoint is out of
9988 scope, and delete it. We also delete its scope bp. But the
9989 scope bp is marked "auto-deleting", and is already on a bpstat.
9990 That bpstat is then checked for auto-deleting bp's, which are
9993 A real solution to this problem might involve reference counts in
9994 bp's, and/or giving them pointers back to their referencing
9995 bpstat's, and teaching delete_breakpoint to only free a bp's
9996 storage when no more references were extent. A cheaper bandaid
9998 if (bpt->type == bp_none)
10001 /* At least avoid this stale reference until the reference counting
10002 of breakpoints gets resolved. */
10003 if (bpt->related_breakpoint != NULL)
10005 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
10006 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
10007 bpt->related_breakpoint->related_breakpoint = NULL;
10008 bpt->related_breakpoint = NULL;
10011 observer_notify_breakpoint_deleted (bpt->number);
10013 if (breakpoint_chain == bpt)
10014 breakpoint_chain = bpt->next;
10016 ALL_BREAKPOINTS (b)
10017 if (b->next == bpt)
10019 b->next = bpt->next;
10023 decref_counted_command_line (&bpt->commands);
10024 xfree (bpt->cond_string);
10025 xfree (bpt->cond_exp);
10026 xfree (bpt->addr_string);
10028 xfree (bpt->exp_string);
10029 xfree (bpt->exp_string_reparse);
10030 value_free (bpt->val);
10031 xfree (bpt->source_file);
10032 xfree (bpt->exec_pathname);
10033 clean_up_filters (&bpt->syscalls_to_be_caught);
10036 /* Be sure no bpstat's are pointing at the breakpoint after it's
10038 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10039 in all threeds for now. Note that we cannot just remove bpstats
10040 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10041 commands are associated with the bpstat; if we remove it here,
10042 then the later call to bpstat_do_actions (&stop_bpstat); in
10043 event-top.c won't do anything, and temporary breakpoints with
10044 commands won't work. */
10046 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
10048 /* Now that breakpoint is removed from breakpoint list, update the
10049 global location list. This will remove locations that used to
10050 belong to this breakpoint. Do this before freeing the breakpoint
10051 itself, since remove_breakpoint looks at location's owner. It
10052 might be better design to have location completely
10053 self-contained, but it's not the case now. */
10054 update_global_location_list (0);
10057 /* On the chance that someone will soon try again to delete this
10058 same bp, we mark it as deleted before freeing its storage. */
10059 bpt->type = bp_none;
10065 do_delete_breakpoint_cleanup (void *b)
10067 delete_breakpoint (b);
10071 make_cleanup_delete_breakpoint (struct breakpoint *b)
10073 return make_cleanup (do_delete_breakpoint_cleanup, b);
10076 /* A callback for map_breakpoint_numbers that calls
10077 delete_breakpoint. */
10080 do_delete_breakpoint (struct breakpoint *b, void *ignore)
10082 delete_breakpoint (b);
10086 delete_command (char *arg, int from_tty)
10088 struct breakpoint *b, *b_tmp;
10094 int breaks_to_delete = 0;
10096 /* Delete all breakpoints if no argument.
10097 Do not delete internal or call-dummy breakpoints, these have
10098 to be deleted with an explicit breakpoint number argument. */
10099 ALL_BREAKPOINTS (b)
10101 if (b->type != bp_call_dummy
10102 && b->type != bp_std_terminate
10103 && b->type != bp_shlib_event
10104 && b->type != bp_jit_event
10105 && b->type != bp_thread_event
10106 && b->type != bp_overlay_event
10107 && b->type != bp_longjmp_master
10108 && b->type != bp_std_terminate_master
10109 && b->type != bp_exception_master
10112 breaks_to_delete = 1;
10117 /* Ask user only if there are some breakpoints to delete. */
10119 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
10121 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10123 if (b->type != bp_call_dummy
10124 && b->type != bp_std_terminate
10125 && b->type != bp_shlib_event
10126 && b->type != bp_thread_event
10127 && b->type != bp_jit_event
10128 && b->type != bp_overlay_event
10129 && b->type != bp_longjmp_master
10130 && b->type != bp_std_terminate_master
10131 && b->type != bp_exception_master
10133 delete_breakpoint (b);
10138 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
10142 all_locations_are_pending (struct bp_location *loc)
10144 for (; loc; loc = loc->next)
10145 if (!loc->shlib_disabled)
10150 /* Subroutine of update_breakpoint_locations to simplify it.
10151 Return non-zero if multiple fns in list LOC have the same name.
10152 Null names are ignored. */
10155 ambiguous_names_p (struct bp_location *loc)
10157 struct bp_location *l;
10158 htab_t htab = htab_create_alloc (13, htab_hash_string,
10159 (int (*) (const void *,
10160 const void *)) streq,
10161 NULL, xcalloc, xfree);
10163 for (l = loc; l != NULL; l = l->next)
10166 const char *name = l->function_name;
10168 /* Allow for some names to be NULL, ignore them. */
10172 slot = (const char **) htab_find_slot (htab, (const void *) name,
10174 /* NOTE: We can assume slot != NULL here because xcalloc never
10178 htab_delete (htab);
10184 htab_delete (htab);
10188 /* When symbols change, it probably means the sources changed as well,
10189 and it might mean the static tracepoint markers are no longer at
10190 the same address or line numbers they used to be at last we
10191 checked. Losing your static tracepoints whenever you rebuild is
10192 undesirable. This function tries to resync/rematch gdb static
10193 tracepoints with the markers on the target, for static tracepoints
10194 that have not been set by marker id. Static tracepoint that have
10195 been set by marker id are reset by marker id in breakpoint_re_set.
10198 1) For a tracepoint set at a specific address, look for a marker at
10199 the old PC. If one is found there, assume to be the same marker.
10200 If the name / string id of the marker found is different from the
10201 previous known name, assume that means the user renamed the marker
10202 in the sources, and output a warning.
10204 2) For a tracepoint set at a given line number, look for a marker
10205 at the new address of the old line number. If one is found there,
10206 assume to be the same marker. If the name / string id of the
10207 marker found is different from the previous known name, assume that
10208 means the user renamed the marker in the sources, and output a
10211 3) If a marker is no longer found at the same address or line, it
10212 may mean the marker no longer exists. But it may also just mean
10213 the code changed a bit. Maybe the user added a few lines of code
10214 that made the marker move up or down (in line number terms). Ask
10215 the target for info about the marker with the string id as we knew
10216 it. If found, update line number and address in the matching
10217 static tracepoint. This will get confused if there's more than one
10218 marker with the same ID (possible in UST, although unadvised
10219 precisely because it confuses tools). */
10221 static struct symtab_and_line
10222 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
10224 struct static_tracepoint_marker marker;
10230 find_line_pc (sal.symtab, sal.line, &pc);
10232 if (target_static_tracepoint_marker_at (pc, &marker))
10234 if (strcmp (b->static_trace_marker_id, marker.str_id) != 0)
10235 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10237 b->static_trace_marker_id, marker.str_id);
10239 xfree (b->static_trace_marker_id);
10240 b->static_trace_marker_id = xstrdup (marker.str_id);
10241 release_static_tracepoint_marker (&marker);
10246 /* Old marker wasn't found on target at lineno. Try looking it up
10248 if (!sal.explicit_pc
10250 && sal.symtab != NULL
10251 && b->static_trace_marker_id != NULL)
10253 VEC(static_tracepoint_marker_p) *markers;
10256 = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id);
10258 if (!VEC_empty(static_tracepoint_marker_p, markers))
10260 struct symtab_and_line sal;
10261 struct symbol *sym;
10262 struct static_tracepoint_marker *marker;
10264 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
10266 xfree (b->static_trace_marker_id);
10267 b->static_trace_marker_id = xstrdup (marker->str_id);
10269 warning (_("marker for static tracepoint %d (%s) not "
10270 "found at previous line number"),
10271 b->number, b->static_trace_marker_id);
10275 sal.pc = marker->address;
10277 sal = find_pc_line (marker->address, 0);
10278 sym = find_pc_sect_function (marker->address, NULL);
10279 ui_out_text (uiout, "Now in ");
10282 ui_out_field_string (uiout, "func",
10283 SYMBOL_PRINT_NAME (sym));
10284 ui_out_text (uiout, " at ");
10286 ui_out_field_string (uiout, "file", sal.symtab->filename);
10287 ui_out_text (uiout, ":");
10289 if (ui_out_is_mi_like_p (uiout))
10291 char *fullname = symtab_to_fullname (sal.symtab);
10294 ui_out_field_string (uiout, "fullname", fullname);
10297 ui_out_field_int (uiout, "line", sal.line);
10298 ui_out_text (uiout, "\n");
10300 b->line_number = sal.line;
10302 xfree (b->source_file);
10304 b->source_file = xstrdup (sal.symtab->filename);
10306 b->source_file = NULL;
10308 xfree (b->addr_string);
10309 b->addr_string = xstrprintf ("%s:%d",
10310 sal.symtab->filename, b->line_number);
10312 /* Might be nice to check if function changed, and warn if
10315 release_static_tracepoint_marker (marker);
10322 update_breakpoint_locations (struct breakpoint *b,
10323 struct symtabs_and_lines sals)
10327 struct bp_location *existing_locations = b->loc;
10329 /* If there's no new locations, and all existing locations are
10330 pending, don't do anything. This optimizes the common case where
10331 all locations are in the same shared library, that was unloaded.
10332 We'd like to retain the location, so that when the library is
10333 loaded again, we don't loose the enabled/disabled status of the
10334 individual locations. */
10335 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
10340 for (i = 0; i < sals.nelts; ++i)
10342 struct bp_location *new_loc =
10343 add_location_to_breakpoint (b, &(sals.sals[i]));
10345 /* Reparse conditions, they might contain references to the
10347 if (b->cond_string != NULL)
10349 struct gdb_exception e;
10351 s = b->cond_string;
10352 TRY_CATCH (e, RETURN_MASK_ERROR)
10354 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
10359 warning (_("failed to reevaluate condition "
10360 "for breakpoint %d: %s"),
10361 b->number, e.message);
10362 new_loc->enabled = 0;
10366 if (b->source_file != NULL)
10367 xfree (b->source_file);
10368 if (sals.sals[i].symtab == NULL)
10369 b->source_file = NULL;
10371 b->source_file = xstrdup (sals.sals[i].symtab->filename);
10373 if (b->line_number == 0)
10374 b->line_number = sals.sals[i].line;
10377 /* Update locations of permanent breakpoints. */
10378 if (b->enable_state == bp_permanent)
10379 make_breakpoint_permanent (b);
10381 /* If possible, carry over 'disable' status from existing
10384 struct bp_location *e = existing_locations;
10385 /* If there are multiple breakpoints with the same function name,
10386 e.g. for inline functions, comparing function names won't work.
10387 Instead compare pc addresses; this is just a heuristic as things
10388 may have moved, but in practice it gives the correct answer
10389 often enough until a better solution is found. */
10390 int have_ambiguous_names = ambiguous_names_p (b->loc);
10392 for (; e; e = e->next)
10394 if (!e->enabled && e->function_name)
10396 struct bp_location *l = b->loc;
10397 if (have_ambiguous_names)
10399 for (; l; l = l->next)
10400 if (breakpoint_address_match (e->pspace->aspace, e->address,
10401 l->pspace->aspace, l->address))
10409 for (; l; l = l->next)
10410 if (l->function_name
10411 && strcmp (e->function_name, l->function_name) == 0)
10421 update_global_location_list (1);
10424 /* Reset a breakpoint given it's struct breakpoint * BINT.
10425 The value we return ends up being the return value from catch_errors.
10426 Unused in this case. */
10429 breakpoint_re_set_one (void *bint)
10431 /* Get past catch_errs. */
10432 struct breakpoint *b = (struct breakpoint *) bint;
10434 int *not_found_ptr = ¬_found;
10435 struct symtabs_and_lines sals = {0};
10436 struct symtabs_and_lines expanded = {0};
10438 struct gdb_exception e;
10439 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10440 int marker_spec = 0;
10445 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10448 case bp_breakpoint:
10449 case bp_hardware_breakpoint:
10450 case bp_tracepoint:
10451 case bp_fast_tracepoint:
10452 case bp_static_tracepoint:
10453 /* Do not attempt to re-set breakpoints disabled during startup. */
10454 if (b->enable_state == bp_startup_disabled)
10457 if (b->addr_string == NULL)
10459 /* Anything without a string can't be re-set. */
10460 delete_breakpoint (b);
10464 input_radix = b->input_radix;
10465 s = b->addr_string;
10467 save_current_space_and_thread ();
10468 switch_to_program_space_and_thread (b->pspace);
10470 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
10472 set_language (b->language);
10473 TRY_CATCH (e, RETURN_MASK_ERROR)
10477 sals = decode_static_tracepoint_spec (&s);
10478 if (sals.nelts > b->static_trace_marker_id_idx)
10480 sals.sals[0] = sals.sals[b->static_trace_marker_id_idx];
10484 error (_("marker %s not found"), b->static_trace_marker_id);
10487 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0,
10488 (char ***) NULL, not_found_ptr);
10492 int not_found_and_ok = 0;
10493 /* For pending breakpoints, it's expected that parsing will
10494 fail until the right shared library is loaded. User has
10495 already told to create pending breakpoints and don't need
10496 extra messages. If breakpoint is in bp_shlib_disabled
10497 state, then user already saw the message about that
10498 breakpoint being disabled, and don't want to see more
10501 && (b->condition_not_parsed
10502 || (b->loc && b->loc->shlib_disabled)
10503 || b->enable_state == bp_disabled))
10504 not_found_and_ok = 1;
10506 if (!not_found_and_ok)
10508 /* We surely don't want to warn about the same breakpoint
10509 10 times. One solution, implemented here, is disable
10510 the breakpoint on error. Another solution would be to
10511 have separate 'warning emitted' flag. Since this
10512 happens only when a binary has changed, I don't know
10513 which approach is better. */
10514 b->enable_state = bp_disabled;
10515 throw_exception (e);
10521 gdb_assert (sals.nelts == 1);
10523 resolve_sal_pc (&sals.sals[0]);
10524 if (b->condition_not_parsed && s && s[0])
10526 char *cond_string = 0;
10530 find_condition_and_thread (s, sals.sals[0].pc,
10531 &cond_string, &thread, &task);
10533 b->cond_string = cond_string;
10534 b->thread = thread;
10536 b->condition_not_parsed = 0;
10539 if (b->type == bp_static_tracepoint && !marker_spec)
10540 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
10542 expanded = expand_line_sal_maybe (sals.sals[0]);
10545 make_cleanup (xfree, sals.sals);
10546 update_breakpoint_locations (b, expanded);
10549 case bp_watchpoint:
10550 case bp_hardware_watchpoint:
10551 case bp_read_watchpoint:
10552 case bp_access_watchpoint:
10553 /* Watchpoint can be either on expression using entirely global
10554 variables, or it can be on local variables.
10556 Watchpoints of the first kind are never auto-deleted, and
10557 even persist across program restarts. Since they can use
10558 variables from shared libraries, we need to reparse
10559 expression as libraries are loaded and unloaded.
10561 Watchpoints on local variables can also change meaning as
10562 result of solib event. For example, if a watchpoint uses
10563 both a local and a global variables in expression, it's a
10564 local watchpoint, but unloading of a shared library will make
10565 the expression invalid. This is not a very common use case,
10566 but we still re-evaluate expression, to avoid surprises to
10569 Note that for local watchpoints, we re-evaluate it only if
10570 watchpoints frame id is still valid. If it's not, it means
10571 the watchpoint is out of scope and will be deleted soon. In
10572 fact, I'm not sure we'll ever be called in this case.
10574 If a local watchpoint's frame id is still valid, then
10575 b->exp_valid_block is likewise valid, and we can safely use it.
10577 Don't do anything about disabled watchpoints, since they will
10578 be reevaluated again when enabled. */
10579 update_watchpoint (b, 1 /* reparse */);
10581 /* We needn't really do anything to reset these, since the mask
10582 that requests them is unaffected by e.g., new libraries being
10584 case bp_catchpoint:
10588 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
10590 /* Delete overlay event and longjmp master breakpoints; they will be
10591 reset later by breakpoint_re_set. */
10592 case bp_overlay_event:
10593 case bp_longjmp_master:
10594 case bp_std_terminate_master:
10595 case bp_exception_master:
10596 delete_breakpoint (b);
10599 /* This breakpoint is special, it's set up when the inferior
10600 starts and we really don't want to touch it. */
10601 case bp_shlib_event:
10603 /* Like bp_shlib_event, this breakpoint type is special.
10604 Once it is set up, we do not want to touch it. */
10605 case bp_thread_event:
10607 /* Keep temporary breakpoints, which can be encountered when we
10608 step over a dlopen call and SOLIB_ADD is resetting the
10609 breakpoints. Otherwise these should have been blown away via
10610 the cleanup chain or by breakpoint_init_inferior when we
10611 rerun the executable. */
10614 case bp_watchpoint_scope:
10615 case bp_call_dummy:
10616 case bp_std_terminate:
10617 case bp_step_resume:
10619 case bp_longjmp_resume:
10621 case bp_exception_resume:
10626 do_cleanups (cleanups);
10630 /* Re-set all breakpoints after symbols have been re-loaded. */
10632 breakpoint_re_set (void)
10634 struct breakpoint *b, *b_tmp;
10635 enum language save_language;
10636 int save_input_radix;
10637 struct cleanup *old_chain;
10639 save_language = current_language->la_language;
10640 save_input_radix = input_radix;
10641 old_chain = save_current_program_space ();
10643 ALL_BREAKPOINTS_SAFE (b, b_tmp)
10645 /* Format possible error msg. */
10646 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
10648 struct cleanup *cleanups = make_cleanup (xfree, message);
10649 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
10650 do_cleanups (cleanups);
10652 set_language (save_language);
10653 input_radix = save_input_radix;
10655 jit_breakpoint_re_set ();
10657 do_cleanups (old_chain);
10659 create_overlay_event_breakpoint ("_ovly_debug_event");
10660 create_longjmp_master_breakpoint ("longjmp");
10661 create_longjmp_master_breakpoint ("_longjmp");
10662 create_longjmp_master_breakpoint ("siglongjmp");
10663 create_longjmp_master_breakpoint ("_siglongjmp");
10664 create_std_terminate_master_breakpoint ("std::terminate()");
10665 create_exception_master_breakpoint ();
10668 /* Reset the thread number of this breakpoint:
10670 - If the breakpoint is for all threads, leave it as-is.
10671 - Else, reset it to the current thread for inferior_ptid. */
10673 breakpoint_re_set_thread (struct breakpoint *b)
10675 if (b->thread != -1)
10677 if (in_thread_list (inferior_ptid))
10678 b->thread = pid_to_thread_id (inferior_ptid);
10680 /* We're being called after following a fork. The new fork is
10681 selected as current, and unless this was a vfork will have a
10682 different program space from the original thread. Reset that
10684 b->loc->pspace = current_program_space;
10688 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10689 If from_tty is nonzero, it prints a message to that effect,
10690 which ends with a period (no newline). */
10693 set_ignore_count (int bptnum, int count, int from_tty)
10695 struct breakpoint *b;
10700 ALL_BREAKPOINTS (b)
10701 if (b->number == bptnum)
10703 if (is_tracepoint (b))
10705 if (from_tty && count != 0)
10706 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10711 b->ignore_count = count;
10715 printf_filtered (_("Will stop next time "
10716 "breakpoint %d is reached."),
10718 else if (count == 1)
10719 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10722 printf_filtered (_("Will ignore next %d "
10723 "crossings of breakpoint %d."),
10726 breakpoints_changed ();
10727 observer_notify_breakpoint_modified (b->number);
10731 error (_("No breakpoint number %d."), bptnum);
10735 make_breakpoint_silent (struct breakpoint *b)
10737 /* Silence the breakpoint. */
10741 /* Command to set ignore-count of breakpoint N to COUNT. */
10744 ignore_command (char *args, int from_tty)
10750 error_no_arg (_("a breakpoint number"));
10752 num = get_number (&p);
10754 error (_("bad breakpoint number: '%s'"), args);
10756 error (_("Second argument (specified ignore-count) is missing."));
10758 set_ignore_count (num,
10759 longest_to_int (value_as_long (parse_and_eval (p))),
10762 printf_filtered ("\n");
10765 /* Call FUNCTION on each of the breakpoints
10766 whose numbers are given in ARGS. */
10769 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
10776 struct breakpoint *b, *tmp;
10780 error_no_arg (_("one or more breakpoint numbers"));
10787 num = get_number_or_range (&p1);
10790 warning (_("bad breakpoint number at or near '%s'"), p);
10794 ALL_BREAKPOINTS_SAFE (b, tmp)
10795 if (b->number == num)
10797 struct breakpoint *related_breakpoint = b->related_breakpoint;
10799 function (b, data);
10800 if (related_breakpoint)
10801 function (related_breakpoint, data);
10805 printf_unfiltered (_("No breakpoint number %d.\n"), num);
10811 static struct bp_location *
10812 find_location_by_number (char *number)
10814 char *dot = strchr (number, '.');
10818 struct breakpoint *b;
10819 struct bp_location *loc;
10824 bp_num = get_number_or_range (&p1);
10826 error (_("Bad breakpoint number '%s'"), number);
10828 ALL_BREAKPOINTS (b)
10829 if (b->number == bp_num)
10834 if (!b || b->number != bp_num)
10835 error (_("Bad breakpoint number '%s'"), number);
10838 loc_num = get_number_or_range (&p1);
10840 error (_("Bad breakpoint location number '%s'"), number);
10844 for (;loc_num && loc; --loc_num, loc = loc->next)
10847 error (_("Bad breakpoint location number '%s'"), dot+1);
10853 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10854 If from_tty is nonzero, it prints a message to that effect,
10855 which ends with a period (no newline). */
10858 disable_breakpoint (struct breakpoint *bpt)
10860 /* Never disable a watchpoint scope breakpoint; we want to
10861 hit them when we leave scope so we can delete both the
10862 watchpoint and its scope breakpoint at that time. */
10863 if (bpt->type == bp_watchpoint_scope)
10866 /* You can't disable permanent breakpoints. */
10867 if (bpt->enable_state == bp_permanent)
10870 bpt->enable_state = bp_disabled;
10872 update_global_location_list (0);
10874 observer_notify_breakpoint_modified (bpt->number);
10877 /* A callback for map_breakpoint_numbers that calls
10878 disable_breakpoint. */
10881 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
10883 disable_breakpoint (b);
10887 disable_command (char *args, int from_tty)
10889 struct breakpoint *bpt;
10892 ALL_BREAKPOINTS (bpt)
10896 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10899 case bp_breakpoint:
10900 case bp_tracepoint:
10901 case bp_fast_tracepoint:
10902 case bp_static_tracepoint:
10903 case bp_catchpoint:
10904 case bp_hardware_breakpoint:
10905 case bp_watchpoint:
10906 case bp_hardware_watchpoint:
10907 case bp_read_watchpoint:
10908 case bp_access_watchpoint:
10909 disable_breakpoint (bpt);
10913 else if (strchr (args, '.'))
10915 struct bp_location *loc = find_location_by_number (args);
10918 update_global_location_list (0);
10921 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
10925 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
10927 int target_resources_ok;
10929 if (bpt->type == bp_hardware_breakpoint)
10932 i = hw_breakpoint_used_count ();
10933 target_resources_ok =
10934 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10936 if (target_resources_ok == 0)
10937 error (_("No hardware breakpoint support in the target."));
10938 else if (target_resources_ok < 0)
10939 error (_("Hardware breakpoints used exceeds limit."));
10942 if (is_watchpoint (bpt))
10944 struct gdb_exception e;
10946 TRY_CATCH (e, RETURN_MASK_ALL)
10948 update_watchpoint (bpt, 1 /* reparse */);
10952 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10958 if (bpt->enable_state != bp_permanent)
10959 bpt->enable_state = bp_enabled;
10960 bpt->disposition = disposition;
10961 update_global_location_list (1);
10962 breakpoints_changed ();
10964 observer_notify_breakpoint_modified (bpt->number);
10969 enable_breakpoint (struct breakpoint *bpt)
10971 do_enable_breakpoint (bpt, bpt->disposition);
10974 /* A callback for map_breakpoint_numbers that calls
10975 enable_breakpoint. */
10978 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10980 enable_breakpoint (b);
10983 /* The enable command enables the specified breakpoints (or all defined
10984 breakpoints) so they once again become (or continue to be) effective
10985 in stopping the inferior. */
10988 enable_command (char *args, int from_tty)
10990 struct breakpoint *bpt;
10993 ALL_BREAKPOINTS (bpt)
10997 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11000 case bp_breakpoint:
11001 case bp_tracepoint:
11002 case bp_fast_tracepoint:
11003 case bp_static_tracepoint:
11004 case bp_catchpoint:
11005 case bp_hardware_breakpoint:
11006 case bp_watchpoint:
11007 case bp_hardware_watchpoint:
11008 case bp_read_watchpoint:
11009 case bp_access_watchpoint:
11010 enable_breakpoint (bpt);
11014 else if (strchr (args, '.'))
11016 struct bp_location *loc = find_location_by_number (args);
11019 update_global_location_list (1);
11022 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
11026 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
11028 do_enable_breakpoint (bpt, disp_disable);
11032 enable_once_command (char *args, int from_tty)
11034 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
11038 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
11040 do_enable_breakpoint (bpt, disp_del);
11044 enable_delete_command (char *args, int from_tty)
11046 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
11050 set_breakpoint_cmd (char *args, int from_tty)
11055 show_breakpoint_cmd (char *args, int from_tty)
11059 /* Invalidate last known value of any hardware watchpoint if
11060 the memory which that value represents has been written to by
11064 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
11065 const bfd_byte *data)
11067 struct breakpoint *bp;
11069 ALL_BREAKPOINTS (bp)
11070 if (bp->enable_state == bp_enabled
11071 && bp->type == bp_hardware_watchpoint
11072 && bp->val_valid && bp->val)
11074 struct bp_location *loc;
11076 for (loc = bp->loc; loc != NULL; loc = loc->next)
11077 if (loc->loc_type == bp_loc_hardware_watchpoint
11078 && loc->address + loc->length > addr
11079 && addr + len > loc->address)
11081 value_free (bp->val);
11088 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11090 struct symtabs_and_lines
11091 decode_line_spec_1 (char *string, int funfirstline)
11093 struct symtabs_and_lines sals;
11096 error (_("Empty line specification."));
11097 if (default_breakpoint_valid)
11098 sals = decode_line_1 (&string, funfirstline,
11099 default_breakpoint_symtab,
11100 default_breakpoint_line,
11101 (char ***) NULL, NULL);
11103 sals = decode_line_1 (&string, funfirstline,
11104 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
11106 error (_("Junk at end of line specification: %s"), string);
11110 /* Create and insert a raw software breakpoint at PC. Return an
11111 identifier, which should be used to remove the breakpoint later.
11112 In general, places which call this should be using something on the
11113 breakpoint chain instead; this function should be eliminated
11117 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
11118 struct address_space *aspace, CORE_ADDR pc)
11120 struct bp_target_info *bp_tgt;
11122 bp_tgt = XZALLOC (struct bp_target_info);
11124 bp_tgt->placed_address_space = aspace;
11125 bp_tgt->placed_address = pc;
11127 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
11129 /* Could not insert the breakpoint. */
11137 /* Remove a breakpoint BP inserted by
11138 deprecated_insert_raw_breakpoint. */
11141 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
11143 struct bp_target_info *bp_tgt = bp;
11146 ret = target_remove_breakpoint (gdbarch, bp_tgt);
11152 /* One (or perhaps two) breakpoints used for software single
11155 static void *single_step_breakpoints[2];
11156 static struct gdbarch *single_step_gdbarch[2];
11158 /* Create and insert a breakpoint for software single step. */
11161 insert_single_step_breakpoint (struct gdbarch *gdbarch,
11162 struct address_space *aspace,
11167 if (single_step_breakpoints[0] == NULL)
11169 bpt_p = &single_step_breakpoints[0];
11170 single_step_gdbarch[0] = gdbarch;
11174 gdb_assert (single_step_breakpoints[1] == NULL);
11175 bpt_p = &single_step_breakpoints[1];
11176 single_step_gdbarch[1] = gdbarch;
11179 /* NOTE drow/2006-04-11: A future improvement to this function would
11180 be to only create the breakpoints once, and actually put them on
11181 the breakpoint chain. That would let us use set_raw_breakpoint.
11182 We could adjust the addresses each time they were needed. Doing
11183 this requires corresponding changes elsewhere where single step
11184 breakpoints are handled, however. So, for now, we use this. */
11186 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
11187 if (*bpt_p == NULL)
11188 error (_("Could not insert single-step breakpoint at %s"),
11189 paddress (gdbarch, next_pc));
11192 /* Check if the breakpoints used for software single stepping
11193 were inserted or not. */
11196 single_step_breakpoints_inserted (void)
11198 return (single_step_breakpoints[0] != NULL
11199 || single_step_breakpoints[1] != NULL);
11202 /* Remove and delete any breakpoints used for software single step. */
11205 remove_single_step_breakpoints (void)
11207 gdb_assert (single_step_breakpoints[0] != NULL);
11209 /* See insert_single_step_breakpoint for more about this deprecated
11211 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
11212 single_step_breakpoints[0]);
11213 single_step_gdbarch[0] = NULL;
11214 single_step_breakpoints[0] = NULL;
11216 if (single_step_breakpoints[1] != NULL)
11218 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
11219 single_step_breakpoints[1]);
11220 single_step_gdbarch[1] = NULL;
11221 single_step_breakpoints[1] = NULL;
11225 /* Delete software single step breakpoints without removing them from
11226 the inferior. This is intended to be used if the inferior's address
11227 space where they were inserted is already gone, e.g. after exit or
11231 cancel_single_step_breakpoints (void)
11235 for (i = 0; i < 2; i++)
11236 if (single_step_breakpoints[i])
11238 xfree (single_step_breakpoints[i]);
11239 single_step_breakpoints[i] = NULL;
11240 single_step_gdbarch[i] = NULL;
11244 /* Detach software single-step breakpoints from INFERIOR_PTID without
11248 detach_single_step_breakpoints (void)
11252 for (i = 0; i < 2; i++)
11253 if (single_step_breakpoints[i])
11254 target_remove_breakpoint (single_step_gdbarch[i],
11255 single_step_breakpoints[i]);
11258 /* Check whether a software single-step breakpoint is inserted at
11262 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
11267 for (i = 0; i < 2; i++)
11269 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
11271 && breakpoint_address_match (bp_tgt->placed_address_space,
11272 bp_tgt->placed_address,
11280 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11281 non-zero otherwise. */
11283 is_syscall_catchpoint_enabled (struct breakpoint *bp)
11285 if (syscall_catchpoint_p (bp)
11286 && bp->enable_state != bp_disabled
11287 && bp->enable_state != bp_call_disabled)
11294 catch_syscall_enabled (void)
11296 struct inferior *inf = current_inferior ();
11298 return inf->total_syscalls_count != 0;
11302 catching_syscall_number (int syscall_number)
11304 struct breakpoint *bp;
11306 ALL_BREAKPOINTS (bp)
11307 if (is_syscall_catchpoint_enabled (bp))
11309 if (bp->syscalls_to_be_caught)
11313 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
11315 if (syscall_number == iter)
11325 /* Complete syscall names. Used by "catch syscall". */
11327 catch_syscall_completer (struct cmd_list_element *cmd,
11328 char *text, char *word)
11330 const char **list = get_syscall_names ();
11332 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
11335 /* Tracepoint-specific operations. */
11337 /* Set tracepoint count to NUM. */
11339 set_tracepoint_count (int num)
11341 tracepoint_count = num;
11342 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
11346 trace_command (char *arg, int from_tty)
11348 if (create_breakpoint (get_current_arch (),
11350 NULL, 0, 1 /* parse arg */,
11352 bp_tracepoint /* type_wanted */,
11353 0 /* Ignore count */,
11354 pending_break_support,
11359 set_tracepoint_count (breakpoint_count);
11363 ftrace_command (char *arg, int from_tty)
11365 if (create_breakpoint (get_current_arch (),
11367 NULL, 0, 1 /* parse arg */,
11369 bp_fast_tracepoint /* type_wanted */,
11370 0 /* Ignore count */,
11371 pending_break_support,
11376 set_tracepoint_count (breakpoint_count);
11379 /* strace command implementation. Creates a static tracepoint. */
11382 strace_command (char *arg, int from_tty)
11384 if (create_breakpoint (get_current_arch (),
11386 NULL, 0, 1 /* parse arg */,
11388 bp_static_tracepoint /* type_wanted */,
11389 0 /* Ignore count */,
11390 pending_break_support,
11395 set_tracepoint_count (breakpoint_count);
11398 /* Set up a fake reader function that gets command lines from a linked
11399 list that was acquired during tracepoint uploading. */
11401 static struct uploaded_tp *this_utp;
11402 static int next_cmd;
11405 read_uploaded_action (void)
11409 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
11416 /* Given information about a tracepoint as recorded on a target (which
11417 can be either a live system or a trace file), attempt to create an
11418 equivalent GDB tracepoint. This is not a reliable process, since
11419 the target does not necessarily have all the information used when
11420 the tracepoint was originally defined. */
11422 struct breakpoint *
11423 create_tracepoint_from_upload (struct uploaded_tp *utp)
11425 char *addr_str, small_buf[100];
11426 struct breakpoint *tp;
11428 if (utp->at_string)
11429 addr_str = utp->at_string;
11432 /* In the absence of a source location, fall back to raw
11433 address. Since there is no way to confirm that the address
11434 means the same thing as when the trace was started, warn the
11436 warning (_("Uploaded tracepoint %d has no "
11437 "source location, using raw address"),
11439 sprintf (small_buf, "*%s", hex_string (utp->addr));
11440 addr_str = small_buf;
11443 /* There's not much we can do with a sequence of bytecodes. */
11444 if (utp->cond && !utp->cond_string)
11445 warning (_("Uploaded tracepoint %d condition "
11446 "has no source form, ignoring it"),
11449 if (!create_breakpoint (get_current_arch (),
11451 utp->cond_string, -1, 0 /* parse cond/thread */,
11453 utp->type /* type_wanted */,
11454 0 /* Ignore count */,
11455 pending_break_support,
11458 utp->enabled /* enabled */,
11462 set_tracepoint_count (breakpoint_count);
11464 /* Get the tracepoint we just created. */
11465 tp = get_tracepoint (tracepoint_count);
11466 gdb_assert (tp != NULL);
11470 sprintf (small_buf, "%d %d", utp->pass, tp->number);
11472 trace_pass_command (small_buf, 0);
11475 /* If we have uploaded versions of the original commands, set up a
11476 special-purpose "reader" function and call the usual command line
11477 reader, then pass the result to the breakpoint command-setting
11479 if (!VEC_empty (char_ptr, utp->cmd_strings))
11481 struct command_line *cmd_list;
11486 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
11488 breakpoint_set_commands (tp, cmd_list);
11490 else if (!VEC_empty (char_ptr, utp->actions)
11491 || !VEC_empty (char_ptr, utp->step_actions))
11492 warning (_("Uploaded tracepoint %d actions "
11493 "have no source form, ignoring them"),
11499 /* Print information on tracepoint number TPNUM_EXP, or all if
11503 tracepoints_info (char *tpnum_exp, int from_tty)
11505 int tpnum = -1, num_printed;
11508 tpnum = parse_and_eval_long (tpnum_exp);
11510 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
11512 if (num_printed == 0)
11515 ui_out_message (uiout, 0, "No tracepoints.\n");
11517 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
11520 default_collect_info ();
11523 /* The 'enable trace' command enables tracepoints.
11524 Not supported by all targets. */
11526 enable_trace_command (char *args, int from_tty)
11528 enable_command (args, from_tty);
11531 /* The 'disable trace' command disables tracepoints.
11532 Not supported by all targets. */
11534 disable_trace_command (char *args, int from_tty)
11536 disable_command (args, from_tty);
11539 /* Remove a tracepoint (or all if no argument). */
11541 delete_trace_command (char *arg, int from_tty)
11543 struct breakpoint *b, *b_tmp;
11549 int breaks_to_delete = 0;
11551 /* Delete all breakpoints if no argument.
11552 Do not delete internal or call-dummy breakpoints, these
11553 have to be deleted with an explicit breakpoint number
11555 ALL_TRACEPOINTS (b)
11557 if (b->number >= 0)
11559 breaks_to_delete = 1;
11564 /* Ask user only if there are some breakpoints to delete. */
11566 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
11568 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11570 if (is_tracepoint (b)
11572 delete_breakpoint (b);
11577 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
11580 /* Set passcount for tracepoint.
11582 First command argument is passcount, second is tracepoint number.
11583 If tracepoint number omitted, apply to most recently defined.
11584 Also accepts special argument "all". */
11587 trace_pass_command (char *args, int from_tty)
11589 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
11590 unsigned int count;
11593 if (args == 0 || *args == 0)
11594 error (_("passcount command requires an "
11595 "argument (count + optional TP num)"));
11597 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
11599 while (*args && isspace ((int) *args))
11602 if (*args && strncasecmp (args, "all", 3) == 0)
11604 args += 3; /* Skip special argument "all". */
11607 error (_("Junk at end of arguments."));
11610 t1 = get_tracepoint_by_number (&args, 1, 1);
11616 ALL_TRACEPOINTS (t2)
11617 if (t1 == (struct breakpoint *) -1 || t1 == t2)
11619 t2->pass_count = count;
11620 observer_notify_tracepoint_modified (t2->number);
11622 printf_filtered (_("Setting tracepoint %d's "
11623 "passcount to %d\n"),
11624 t2->number, count);
11626 if (! all && *args)
11627 t1 = get_tracepoint_by_number (&args, 1, 0);
11633 struct breakpoint *
11634 get_tracepoint (int num)
11636 struct breakpoint *t;
11638 ALL_TRACEPOINTS (t)
11639 if (t->number == num)
11645 /* Find the tracepoint with the given target-side number (which may be
11646 different from the tracepoint number after disconnecting and
11649 struct breakpoint *
11650 get_tracepoint_by_number_on_target (int num)
11652 struct breakpoint *t;
11654 ALL_TRACEPOINTS (t)
11655 if (t->number_on_target == num)
11661 /* Utility: parse a tracepoint number and look it up in the list.
11662 If MULTI_P is true, there might be a range of tracepoints in ARG.
11663 if OPTIONAL_P is true, then if the argument is missing, the most
11664 recent tracepoint (tracepoint_count) is returned. */
11665 struct breakpoint *
11666 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
11668 extern int tracepoint_count;
11669 struct breakpoint *t;
11671 char *instring = arg == NULL ? NULL : *arg;
11673 if (arg == NULL || *arg == NULL || ! **arg)
11676 tpnum = tracepoint_count;
11678 error_no_arg (_("tracepoint number"));
11681 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
11685 if (instring && *instring)
11686 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11689 printf_filtered (_("Tracepoint argument missing "
11690 "and no previous tracepoint\n"));
11694 ALL_TRACEPOINTS (t)
11695 if (t->number == tpnum)
11700 /* FIXME: if we are in the middle of a range we don't want to give
11701 a message. The current interface to get_number_or_range doesn't
11702 allow us to discover this. */
11703 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
11707 /* Save information on user settable breakpoints (watchpoints, etc) to
11708 a new script file named FILENAME. If FILTER is non-NULL, call it
11709 on each breakpoint and only include the ones for which it returns
11713 save_breakpoints (char *filename, int from_tty,
11714 int (*filter) (const struct breakpoint *))
11716 struct breakpoint *tp;
11719 struct cleanup *cleanup;
11720 struct ui_file *fp;
11721 int extra_trace_bits = 0;
11723 if (filename == 0 || *filename == 0)
11724 error (_("Argument required (file name in which to save)"));
11726 /* See if we have anything to save. */
11727 ALL_BREAKPOINTS (tp)
11729 /* Skip internal and momentary breakpoints. */
11730 if (!user_settable_breakpoint (tp) || tp->number < 0)
11733 /* If we have a filter, only save the breakpoints it accepts. */
11734 if (filter && !filter (tp))
11739 if (is_tracepoint (tp))
11741 extra_trace_bits = 1;
11743 /* We can stop searching. */
11750 warning (_("Nothing to save."));
11754 pathname = tilde_expand (filename);
11755 cleanup = make_cleanup (xfree, pathname);
11756 fp = gdb_fopen (pathname, "w");
11758 error (_("Unable to open file '%s' for saving (%s)"),
11759 filename, safe_strerror (errno));
11760 make_cleanup_ui_file_delete (fp);
11762 if (extra_trace_bits)
11763 save_trace_state_variables (fp);
11765 ALL_BREAKPOINTS (tp)
11767 /* Skip internal and momentary breakpoints. */
11768 if (!user_settable_breakpoint (tp) || tp->number < 0)
11771 /* If we have a filter, only save the breakpoints it accepts. */
11772 if (filter && !filter (tp))
11775 if (tp->ops != NULL)
11776 (tp->ops->print_recreate) (tp, fp);
11779 if (tp->type == bp_fast_tracepoint)
11780 fprintf_unfiltered (fp, "ftrace");
11781 if (tp->type == bp_static_tracepoint)
11782 fprintf_unfiltered (fp, "strace");
11783 else if (tp->type == bp_tracepoint)
11784 fprintf_unfiltered (fp, "trace");
11785 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11786 fprintf_unfiltered (fp, "tbreak");
11787 else if (tp->type == bp_breakpoint)
11788 fprintf_unfiltered (fp, "break");
11789 else if (tp->type == bp_hardware_breakpoint
11790 && tp->disposition == disp_del)
11791 fprintf_unfiltered (fp, "thbreak");
11792 else if (tp->type == bp_hardware_breakpoint)
11793 fprintf_unfiltered (fp, "hbreak");
11794 else if (tp->type == bp_watchpoint)
11795 fprintf_unfiltered (fp, "watch");
11796 else if (tp->type == bp_hardware_watchpoint)
11797 fprintf_unfiltered (fp, "watch");
11798 else if (tp->type == bp_read_watchpoint)
11799 fprintf_unfiltered (fp, "rwatch");
11800 else if (tp->type == bp_access_watchpoint)
11801 fprintf_unfiltered (fp, "awatch");
11803 internal_error (__FILE__, __LINE__,
11804 _("unhandled breakpoint type %d"), (int) tp->type);
11806 if (tp->exp_string)
11807 fprintf_unfiltered (fp, " %s", tp->exp_string);
11808 else if (tp->addr_string)
11809 fprintf_unfiltered (fp, " %s", tp->addr_string);
11814 sprintf_vma (tmp, tp->loc->address);
11815 fprintf_unfiltered (fp, " *0x%s", tmp);
11819 if (tp->thread != -1)
11820 fprintf_unfiltered (fp, " thread %d", tp->thread);
11823 fprintf_unfiltered (fp, " task %d", tp->task);
11825 fprintf_unfiltered (fp, "\n");
11827 /* Note, we can't rely on tp->number for anything, as we can't
11828 assume the recreated breakpoint numbers will match. Use $bpnum
11831 if (tp->cond_string)
11832 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
11834 if (tp->ignore_count)
11835 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
11837 if (tp->pass_count)
11838 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11842 volatile struct gdb_exception ex;
11844 fprintf_unfiltered (fp, " commands\n");
11846 ui_out_redirect (uiout, fp);
11847 TRY_CATCH (ex, RETURN_MASK_ALL)
11849 print_command_lines (uiout, tp->commands->commands, 2);
11851 ui_out_redirect (uiout, NULL);
11854 throw_exception (ex);
11856 fprintf_unfiltered (fp, " end\n");
11859 if (tp->enable_state == bp_disabled)
11860 fprintf_unfiltered (fp, "disable\n");
11862 /* If this is a multi-location breakpoint, check if the locations
11863 should be individually disabled. Watchpoint locations are
11864 special, and not user visible. */
11865 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
11867 struct bp_location *loc;
11870 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
11872 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
11876 if (extra_trace_bits && *default_collect)
11877 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
11879 do_cleanups (cleanup);
11881 printf_filtered (_("Saved to file '%s'.\n"), filename);
11884 /* The `save breakpoints' command. */
11887 save_breakpoints_command (char *args, int from_tty)
11889 save_breakpoints (args, from_tty, NULL);
11892 /* The `save tracepoints' command. */
11895 save_tracepoints_command (char *args, int from_tty)
11897 save_breakpoints (args, from_tty, is_tracepoint);
11900 /* Create a vector of all tracepoints. */
11902 VEC(breakpoint_p) *
11905 VEC(breakpoint_p) *tp_vec = 0;
11906 struct breakpoint *tp;
11908 ALL_TRACEPOINTS (tp)
11910 VEC_safe_push (breakpoint_p, tp_vec, tp);
11917 /* This help string is used for the break, hbreak, tbreak and thbreak
11918 commands. It is defined as a macro to prevent duplication.
11919 COMMAND should be a string constant containing the name of the
11921 #define BREAK_ARGS_HELP(command) \
11922 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11923 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11924 If a line number is specified, break at start of code for that line.\n\
11925 If a function is specified, break at start of code for that function.\n\
11926 If an address is specified, break at that exact address.\n\
11927 With no LOCATION, uses current execution address of the selected\n\
11928 stack frame. This is useful for breaking on return to a stack frame.\n\
11930 THREADNUM is the number from \"info threads\".\n\
11931 CONDITION is a boolean expression.\n\
11933 Multiple breakpoints at one place are permitted, and useful if their\n\
11934 conditions are different.\n\
11936 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11938 /* List of subcommands for "catch". */
11939 static struct cmd_list_element *catch_cmdlist;
11941 /* List of subcommands for "tcatch". */
11942 static struct cmd_list_element *tcatch_cmdlist;
11944 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11945 lists, and pass some additional user data to the command function. */
11947 add_catch_command (char *name, char *docstring,
11948 void (*sfunc) (char *args, int from_tty,
11949 struct cmd_list_element *command),
11950 char **(*completer) (struct cmd_list_element *cmd,
11951 char *text, char *word),
11952 void *user_data_catch,
11953 void *user_data_tcatch)
11955 struct cmd_list_element *command;
11957 command = add_cmd (name, class_breakpoint, NULL, docstring,
11959 set_cmd_sfunc (command, sfunc);
11960 set_cmd_context (command, user_data_catch);
11961 set_cmd_completer (command, completer);
11963 command = add_cmd (name, class_breakpoint, NULL, docstring,
11965 set_cmd_sfunc (command, sfunc);
11966 set_cmd_context (command, user_data_tcatch);
11967 set_cmd_completer (command, completer);
11971 clear_syscall_counts (struct inferior *inf)
11973 inf->total_syscalls_count = 0;
11974 inf->any_syscall_count = 0;
11975 VEC_free (int, inf->syscalls_counts);
11979 save_command (char *arg, int from_tty)
11981 printf_unfiltered (_("\"save\" must be followed by "
11982 "the name of a save subcommand.\n"));
11983 help_list (save_cmdlist, "save ", -1, gdb_stdout);
11986 struct breakpoint *
11987 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
11990 struct breakpoint *b, *b_tmp;
11992 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11994 if ((*callback) (b, data))
12002 _initialize_breakpoint (void)
12004 struct cmd_list_element *c;
12006 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
12007 observer_attach_inferior_exit (clear_syscall_counts);
12008 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
12010 breakpoint_chain = 0;
12011 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12012 before a breakpoint is set. */
12013 breakpoint_count = 0;
12015 tracepoint_count = 0;
12017 add_com ("ignore", class_breakpoint, ignore_command, _("\
12018 Set ignore-count of breakpoint number N to COUNT.\n\
12019 Usage is `ignore N COUNT'."));
12021 add_com_alias ("bc", "ignore", class_breakpoint, 1);
12023 add_com ("commands", class_breakpoint, commands_command, _("\
12024 Set commands to be executed when a breakpoint is hit.\n\
12025 Give breakpoint number as argument after \"commands\".\n\
12026 With no argument, the targeted breakpoint is the last one set.\n\
12027 The commands themselves follow starting on the next line.\n\
12028 Type a line containing \"end\" to indicate the end of them.\n\
12029 Give \"silent\" as the first line to make the breakpoint silent;\n\
12030 then no output is printed when it is hit, except what the commands print."));
12032 add_com ("condition", class_breakpoint, condition_command, _("\
12033 Specify breakpoint number N to break only if COND is true.\n\
12034 Usage is `condition N COND', where N is an integer and COND is an\n\
12035 expression to be evaluated whenever breakpoint N is reached."));
12037 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
12038 Set a temporary breakpoint.\n\
12039 Like \"break\" except the breakpoint is only temporary,\n\
12040 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12041 by using \"enable delete\" on the breakpoint number.\n\
12043 BREAK_ARGS_HELP ("tbreak")));
12044 set_cmd_completer (c, location_completer);
12046 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
12047 Set a hardware assisted breakpoint.\n\
12048 Like \"break\" except the breakpoint requires hardware support,\n\
12049 some target hardware may not have this support.\n\
12051 BREAK_ARGS_HELP ("hbreak")));
12052 set_cmd_completer (c, location_completer);
12054 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
12055 Set a temporary hardware assisted breakpoint.\n\
12056 Like \"hbreak\" except the breakpoint is only temporary,\n\
12057 so it will be deleted when hit.\n\
12059 BREAK_ARGS_HELP ("thbreak")));
12060 set_cmd_completer (c, location_completer);
12062 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
12063 Enable some breakpoints.\n\
12064 Give breakpoint numbers (separated by spaces) as arguments.\n\
12065 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12066 This is used to cancel the effect of the \"disable\" command.\n\
12067 With a subcommand you can enable temporarily."),
12068 &enablelist, "enable ", 1, &cmdlist);
12070 add_com ("ab", class_breakpoint, enable_command, _("\
12071 Enable some breakpoints.\n\
12072 Give breakpoint numbers (separated by spaces) as arguments.\n\
12073 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12074 This is used to cancel the effect of the \"disable\" command.\n\
12075 With a subcommand you can enable temporarily."));
12077 add_com_alias ("en", "enable", class_breakpoint, 1);
12079 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
12080 Enable some breakpoints.\n\
12081 Give breakpoint numbers (separated by spaces) as arguments.\n\
12082 This is used to cancel the effect of the \"disable\" command.\n\
12083 May be abbreviated to simply \"enable\".\n"),
12084 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
12086 add_cmd ("once", no_class, enable_once_command, _("\
12087 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12088 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12091 add_cmd ("delete", no_class, enable_delete_command, _("\
12092 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12093 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12096 add_cmd ("delete", no_class, enable_delete_command, _("\
12097 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12098 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12101 add_cmd ("once", no_class, enable_once_command, _("\
12102 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12103 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12106 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
12107 Disable some breakpoints.\n\
12108 Arguments are breakpoint numbers with spaces in between.\n\
12109 To disable all breakpoints, give no argument.\n\
12110 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12111 &disablelist, "disable ", 1, &cmdlist);
12112 add_com_alias ("dis", "disable", class_breakpoint, 1);
12113 add_com_alias ("disa", "disable", class_breakpoint, 1);
12115 add_com ("sb", class_breakpoint, disable_command, _("\
12116 Disable some breakpoints.\n\
12117 Arguments are breakpoint numbers with spaces in between.\n\
12118 To disable all breakpoints, give no argument.\n\
12119 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12121 add_cmd ("breakpoints", class_alias, disable_command, _("\
12122 Disable some breakpoints.\n\
12123 Arguments are breakpoint numbers with spaces in between.\n\
12124 To disable all breakpoints, give no argument.\n\
12125 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12126 This command may be abbreviated \"disable\"."),
12129 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
12130 Delete some breakpoints or auto-display expressions.\n\
12131 Arguments are breakpoint numbers with spaces in between.\n\
12132 To delete all breakpoints, give no argument.\n\
12134 Also a prefix command for deletion of other GDB objects.\n\
12135 The \"unset\" command is also an alias for \"delete\"."),
12136 &deletelist, "delete ", 1, &cmdlist);
12137 add_com_alias ("d", "delete", class_breakpoint, 1);
12138 add_com_alias ("del", "delete", class_breakpoint, 1);
12140 add_com ("db", class_breakpoint, delete_command, _("\
12141 Delete some breakpoints.\n\
12142 Arguments are breakpoint numbers with spaces in between.\n\
12143 To delete all breakpoints, give no argument.\n"));
12145 add_cmd ("breakpoints", class_alias, delete_command, _("\
12146 Delete some breakpoints or auto-display expressions.\n\
12147 Arguments are breakpoint numbers with spaces in between.\n\
12148 To delete all breakpoints, give no argument.\n\
12149 This command may be abbreviated \"delete\"."),
12152 add_com ("clear", class_breakpoint, clear_command, _("\
12153 Clear breakpoint at specified line or function.\n\
12154 Argument may be line number, function name, or \"*\" and an address.\n\
12155 If line number is specified, all breakpoints in that line are cleared.\n\
12156 If function is specified, breakpoints at beginning of function are cleared.\n\
12157 If an address is specified, breakpoints at that address are cleared.\n\
12159 With no argument, clears all breakpoints in the line that the selected frame\n\
12160 is executing in.\n\
12162 See also the \"delete\" command which clears breakpoints by number."));
12163 add_com_alias ("cl", "clear", class_breakpoint, 1);
12165 c = add_com ("break", class_breakpoint, break_command, _("\
12166 Set breakpoint at specified line or function.\n"
12167 BREAK_ARGS_HELP ("break")));
12168 set_cmd_completer (c, location_completer);
12170 add_com_alias ("b", "break", class_run, 1);
12171 add_com_alias ("br", "break", class_run, 1);
12172 add_com_alias ("bre", "break", class_run, 1);
12173 add_com_alias ("brea", "break", class_run, 1);
12176 add_com_alias ("ba", "break", class_breakpoint, 1);
12180 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
12181 Break in function/address or break at a line in the current file."),
12182 &stoplist, "stop ", 1, &cmdlist);
12183 add_cmd ("in", class_breakpoint, stopin_command,
12184 _("Break in function or address."), &stoplist);
12185 add_cmd ("at", class_breakpoint, stopat_command,
12186 _("Break at a line in the current file."), &stoplist);
12187 add_com ("status", class_info, breakpoints_info, _("\
12188 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12189 The \"Type\" column indicates one of:\n\
12190 \tbreakpoint - normal breakpoint\n\
12191 \twatchpoint - watchpoint\n\
12192 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12193 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12194 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12195 address and file/line number respectively.\n\
12197 Convenience variable \"$_\" and default examine address for \"x\"\n\
12198 are set to the address of the last breakpoint listed unless the command\n\
12199 is prefixed with \"server \".\n\n\
12200 Convenience variable \"$bpnum\" contains the number of the last\n\
12201 breakpoint set."));
12204 add_info ("breakpoints", breakpoints_info, _("\
12205 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12206 The \"Type\" column indicates one of:\n\
12207 \tbreakpoint - normal breakpoint\n\
12208 \twatchpoint - watchpoint\n\
12209 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12210 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12211 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12212 address and file/line number respectively.\n\
12214 Convenience variable \"$_\" and default examine address for \"x\"\n\
12215 are set to the address of the last breakpoint listed unless the command\n\
12216 is prefixed with \"server \".\n\n\
12217 Convenience variable \"$bpnum\" contains the number of the last\n\
12218 breakpoint set."));
12220 add_info_alias ("b", "breakpoints", 1);
12223 add_com ("lb", class_breakpoint, breakpoints_info, _("\
12224 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12225 The \"Type\" column indicates one of:\n\
12226 \tbreakpoint - normal breakpoint\n\
12227 \twatchpoint - watchpoint\n\
12228 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12229 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12230 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12231 address and file/line number respectively.\n\
12233 Convenience variable \"$_\" and default examine address for \"x\"\n\
12234 are set to the address of the last breakpoint listed unless the command\n\
12235 is prefixed with \"server \".\n\n\
12236 Convenience variable \"$bpnum\" contains the number of the last\n\
12237 breakpoint set."));
12239 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
12240 Status of all breakpoints, or breakpoint number NUMBER.\n\
12241 The \"Type\" column indicates one of:\n\
12242 \tbreakpoint - normal breakpoint\n\
12243 \twatchpoint - watchpoint\n\
12244 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12245 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12246 \tuntil - internal breakpoint used by the \"until\" command\n\
12247 \tfinish - internal breakpoint used by the \"finish\" command\n\
12248 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12249 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12250 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12251 address and file/line number respectively.\n\
12253 Convenience variable \"$_\" and default examine address for \"x\"\n\
12254 are set to the address of the last breakpoint listed unless the command\n\
12255 is prefixed with \"server \".\n\n\
12256 Convenience variable \"$bpnum\" contains the number of the last\n\
12258 &maintenanceinfolist);
12260 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
12261 Set catchpoints to catch events."),
12262 &catch_cmdlist, "catch ",
12263 0/*allow-unknown*/, &cmdlist);
12265 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
12266 Set temporary catchpoints to catch events."),
12267 &tcatch_cmdlist, "tcatch ",
12268 0/*allow-unknown*/, &cmdlist);
12270 /* Add catch and tcatch sub-commands. */
12271 add_catch_command ("catch", _("\
12272 Catch an exception, when caught.\n\
12273 With an argument, catch only exceptions with the given name."),
12274 catch_catch_command,
12278 add_catch_command ("throw", _("\
12279 Catch an exception, when thrown.\n\
12280 With an argument, catch only exceptions with the given name."),
12281 catch_throw_command,
12285 add_catch_command ("fork", _("Catch calls to fork."),
12286 catch_fork_command_1,
12288 (void *) (uintptr_t) catch_fork_permanent,
12289 (void *) (uintptr_t) catch_fork_temporary);
12290 add_catch_command ("vfork", _("Catch calls to vfork."),
12291 catch_fork_command_1,
12293 (void *) (uintptr_t) catch_vfork_permanent,
12294 (void *) (uintptr_t) catch_vfork_temporary);
12295 add_catch_command ("exec", _("Catch calls to exec."),
12296 catch_exec_command_1,
12300 add_catch_command ("syscall", _("\
12301 Catch system calls by their names and/or numbers.\n\
12302 Arguments say which system calls to catch. If no arguments\n\
12303 are given, every system call will be caught.\n\
12304 Arguments, if given, should be one or more system call names\n\
12305 (if your system supports that), or system call numbers."),
12306 catch_syscall_command_1,
12307 catch_syscall_completer,
12310 add_catch_command ("exception", _("\
12311 Catch Ada exceptions, when raised.\n\
12312 With an argument, catch only exceptions with the given name."),
12313 catch_ada_exception_command,
12317 add_catch_command ("assert", _("\
12318 Catch failed Ada assertions, when raised.\n\
12319 With an argument, catch only exceptions with the given name."),
12320 catch_assert_command,
12325 c = add_com ("watch", class_breakpoint, watch_command, _("\
12326 Set a watchpoint for an expression.\n\
12327 Usage: watch [-l|-location] EXPRESSION\n\
12328 A watchpoint stops execution of your program whenever the value of\n\
12329 an expression changes.\n\
12330 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12331 the memory to which it refers."));
12332 set_cmd_completer (c, expression_completer);
12334 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
12335 Set a read watchpoint for an expression.\n\
12336 Usage: rwatch [-l|-location] EXPRESSION\n\
12337 A watchpoint stops execution of your program whenever the value of\n\
12338 an expression is read.\n\
12339 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12340 the memory to which it refers."));
12341 set_cmd_completer (c, expression_completer);
12343 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
12344 Set a watchpoint for an expression.\n\
12345 Usage: awatch [-l|-location] EXPRESSION\n\
12346 A watchpoint stops execution of your program whenever the value of\n\
12347 an expression is either read or written.\n\
12348 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12349 the memory to which it refers."));
12350 set_cmd_completer (c, expression_completer);
12352 add_info ("watchpoints", watchpoints_info, _("\
12353 Status of watchpoints, or watchpoint number NUMBER."));
12357 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12358 respond to changes - contrary to the description. */
12359 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
12360 &can_use_hw_watchpoints, _("\
12361 Set debugger's willingness to use watchpoint hardware."), _("\
12362 Show debugger's willingness to use watchpoint hardware."), _("\
12363 If zero, gdb will not use hardware for new watchpoints, even if\n\
12364 such is available. (However, any hardware watchpoints that were\n\
12365 created before setting this to nonzero, will continue to use watchpoint\n\
12368 show_can_use_hw_watchpoints,
12369 &setlist, &showlist);
12371 can_use_hw_watchpoints = 1;
12373 /* Tracepoint manipulation commands. */
12375 c = add_com ("trace", class_breakpoint, trace_command, _("\
12376 Set a tracepoint at specified line or function.\n\
12378 BREAK_ARGS_HELP ("trace") "\n\
12379 Do \"help tracepoints\" for info on other tracepoint commands."));
12380 set_cmd_completer (c, location_completer);
12382 add_com_alias ("tp", "trace", class_alias, 0);
12383 add_com_alias ("tr", "trace", class_alias, 1);
12384 add_com_alias ("tra", "trace", class_alias, 1);
12385 add_com_alias ("trac", "trace", class_alias, 1);
12387 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
12388 Set a fast tracepoint at specified line or function.\n\
12390 BREAK_ARGS_HELP ("ftrace") "\n\
12391 Do \"help tracepoints\" for info on other tracepoint commands."));
12392 set_cmd_completer (c, location_completer);
12394 c = add_com ("strace", class_breakpoint, strace_command, _("\
12395 Set a static tracepoint at specified line, function or marker.\n\
12397 strace [LOCATION] [if CONDITION]\n\
12398 LOCATION may be a line number, function name, \"*\" and an address,\n\
12399 or -m MARKER_ID.\n\
12400 If a line number is specified, probe the marker at start of code\n\
12401 for that line. If a function is specified, probe the marker at start\n\
12402 of code for that function. If an address is specified, probe the marker\n\
12403 at that exact address. If a marker id is specified, probe the marker\n\
12404 with that name. With no LOCATION, uses current execution address of\n\
12405 the selected stack frame.\n\
12406 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12407 This collects arbitrary user data passed in the probe point call to the\n\
12408 tracing library. You can inspect it when analyzing the trace buffer,\n\
12409 by printing the $_sdata variable like any other convenience variable.\n\
12411 CONDITION is a boolean expression.\n\
12413 Multiple tracepoints at one place are permitted, and useful if their\n\
12414 conditions are different.\n\
12416 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12417 Do \"help tracepoints\" for info on other tracepoint commands."));
12418 set_cmd_completer (c, location_completer);
12420 add_info ("tracepoints", tracepoints_info, _("\
12421 Status of tracepoints, or tracepoint number NUMBER.\n\
12422 Convenience variable \"$tpnum\" contains the number of the\n\
12423 last tracepoint set."));
12425 add_info_alias ("tp", "tracepoints", 1);
12427 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
12428 Delete specified tracepoints.\n\
12429 Arguments are tracepoint numbers, separated by spaces.\n\
12430 No argument means delete all tracepoints."),
12433 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
12434 Disable specified tracepoints.\n\
12435 Arguments are tracepoint numbers, separated by spaces.\n\
12436 No argument means disable all tracepoints."),
12438 deprecate_cmd (c, "disable");
12440 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
12441 Enable specified tracepoints.\n\
12442 Arguments are tracepoint numbers, separated by spaces.\n\
12443 No argument means enable all tracepoints."),
12445 deprecate_cmd (c, "enable");
12447 add_com ("passcount", class_trace, trace_pass_command, _("\
12448 Set the passcount for a tracepoint.\n\
12449 The trace will end when the tracepoint has been passed 'count' times.\n\
12450 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12451 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12453 add_prefix_cmd ("save", class_breakpoint, save_command,
12454 _("Save breakpoint definitions as a script."),
12455 &save_cmdlist, "save ",
12456 0/*allow-unknown*/, &cmdlist);
12458 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
12459 Save current breakpoint definitions as a script.\n\
12460 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12461 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12462 session to restore them."),
12464 set_cmd_completer (c, filename_completer);
12466 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
12467 Save current tracepoint definitions as a script.\n\
12468 Use the 'source' command in another debug session to restore them."),
12470 set_cmd_completer (c, filename_completer);
12472 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
12473 deprecate_cmd (c, "save tracepoints");
12475 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
12476 Breakpoint specific settings\n\
12477 Configure various breakpoint-specific variables such as\n\
12478 pending breakpoint behavior"),
12479 &breakpoint_set_cmdlist, "set breakpoint ",
12480 0/*allow-unknown*/, &setlist);
12481 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
12482 Breakpoint specific settings\n\
12483 Configure various breakpoint-specific variables such as\n\
12484 pending breakpoint behavior"),
12485 &breakpoint_show_cmdlist, "show breakpoint ",
12486 0/*allow-unknown*/, &showlist);
12488 add_setshow_auto_boolean_cmd ("pending", no_class,
12489 &pending_break_support, _("\
12490 Set debugger's behavior regarding pending breakpoints."), _("\
12491 Show debugger's behavior regarding pending breakpoints."), _("\
12492 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12493 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12494 an error. If auto, an unrecognized breakpoint location results in a\n\
12495 user-query to see if a pending breakpoint should be created."),
12497 show_pending_break_support,
12498 &breakpoint_set_cmdlist,
12499 &breakpoint_show_cmdlist);
12501 pending_break_support = AUTO_BOOLEAN_AUTO;
12503 add_setshow_boolean_cmd ("auto-hw", no_class,
12504 &automatic_hardware_breakpoints, _("\
12505 Set automatic usage of hardware breakpoints."), _("\
12506 Show automatic usage of hardware breakpoints."), _("\
12507 If set, the debugger will automatically use hardware breakpoints for\n\
12508 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12509 a warning will be emitted for such breakpoints."),
12511 show_automatic_hardware_breakpoints,
12512 &breakpoint_set_cmdlist,
12513 &breakpoint_show_cmdlist);
12515 add_setshow_enum_cmd ("always-inserted", class_support,
12516 always_inserted_enums, &always_inserted_mode, _("\
12517 Set mode for inserting breakpoints."), _("\
12518 Show mode for inserting breakpoints."), _("\
12519 When this mode is off, breakpoints are inserted in inferior when it is\n\
12520 resumed, and removed when execution stops. When this mode is on,\n\
12521 breakpoints are inserted immediately and removed only when the user\n\
12522 deletes the breakpoint. When this mode is auto (which is the default),\n\
12523 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12524 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12525 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12526 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12528 &show_always_inserted_mode,
12529 &breakpoint_set_cmdlist,
12530 &breakpoint_show_cmdlist);
12532 automatic_hardware_breakpoints = 1;
12534 observer_attach_about_to_proceed (breakpoint_about_to_proceed);