1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void clear_command (char *, int);
99 static void catch_command (char *, int);
101 static void watch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value *);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint *);
109 /* This function is used in gdbtk sources and thus can not be made static. */
110 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
111 struct symtab_and_line,
114 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
116 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
120 static void describe_other_breakpoints (struct gdbarch *,
121 struct program_space *, CORE_ADDR,
122 struct obj_section *, int);
124 static int breakpoint_address_match (struct address_space *aspace1,
126 struct address_space *aspace2,
129 static int watchpoint_locations_match (struct bp_location *loc1,
130 struct bp_location *loc2);
132 static void breakpoints_info (char *, int);
134 static void watchpoints_info (char *, int);
136 static int breakpoint_1 (int, int, int (*) (const struct breakpoint *));
138 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
140 static int breakpoint_cond_eval (void *);
142 static void cleanup_executing_breakpoints (void *);
144 static void commands_command (char *, int);
146 static void condition_command (char *, int);
148 static int get_number_trailer (char **, int);
157 static int remove_breakpoint (struct bp_location *, insertion_state_t);
158 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
160 static enum print_stop_action print_it_typical (bpstat);
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
164 static int watchpoint_check (void *);
166 static void maintenance_info_breakpoints (char *, int);
168 static int hw_breakpoint_used_count (void);
170 static int hw_watchpoint_used_count (enum bptype, int *);
172 static void hbreak_command (char *, int);
174 static void thbreak_command (char *, int);
176 static void watch_command_1 (char *, int, int);
178 static void rwatch_command (char *, int);
180 static void awatch_command (char *, int);
182 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_parse_optional_if_clause (char **arg);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event,
193 char *arg, int tempflag, int from_tty);
195 static void tcatch_command (char *arg, int from_tty);
197 static void ep_skip_leading_whitespace (char **s);
199 static void detach_single_step_breakpoints (void);
201 static int single_step_breakpoint_inserted_here_p (struct address_space *,
204 static void free_bp_location (struct bp_location *loc);
206 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
208 static void update_global_location_list (int);
210 static void update_global_location_list_nothrow (int);
212 static int bpstat_remove_bp_location_callback (struct thread_info *th,
215 static int is_hardware_watchpoint (const struct breakpoint *bpt);
217 static int is_watchpoint (const struct breakpoint *bpt);
219 static void insert_breakpoint_locations (void);
221 static int syscall_catchpoint_p (struct breakpoint *b);
223 static void tracepoints_info (char *, int);
225 static void delete_trace_command (char *, int);
227 static void enable_trace_command (char *, int);
229 static void disable_trace_command (char *, int);
231 static void trace_pass_command (char *, int);
233 /* Assuming we're creating a static tracepoint, does S look like a
234 static tracepoint marker spec ("-m MARKER_ID")? */
235 #define is_marker_spec(s) \
236 (strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
238 /* A reference-counted struct command_line. This lets multiple
239 breakpoints share a single command list. */
240 struct counted_command_line
242 /* The reference count. */
245 /* The command list. */
246 struct command_line *commands;
249 struct command_line *
250 breakpoint_commands (struct breakpoint *b)
252 return b->commands ? b->commands->commands : NULL;
255 /* Flag indicating that a command has proceeded the inferior past the
256 current breakpoint. */
258 static int breakpoint_proceeded;
261 bpdisp_text (enum bpdisp disp)
263 /* NOTE: the following values are a part of MI protocol and represent
264 values of 'disp' field returned when inferior stops at a breakpoint. */
265 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
267 return bpdisps[(int) disp];
270 /* Prototypes for exported functions. */
271 /* If FALSE, gdb will not use hardware support for watchpoints, even
272 if such is available. */
273 static int can_use_hw_watchpoints;
276 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
277 struct cmd_list_element *c,
280 fprintf_filtered (file, _("\
281 Debugger's willingness to use watchpoint hardware is %s.\n"),
285 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
286 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
287 for unrecognized breakpoint locations.
288 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
289 static enum auto_boolean pending_break_support;
291 show_pending_break_support (struct ui_file *file, int from_tty,
292 struct cmd_list_element *c,
295 fprintf_filtered (file, _("\
296 Debugger's behavior regarding pending breakpoints is %s.\n"),
300 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
301 set with "break" but falling in read-only memory.
302 If 0, gdb will warn about such breakpoints, but won't automatically
303 use hardware breakpoints. */
304 static int automatic_hardware_breakpoints;
306 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
307 struct cmd_list_element *c,
310 fprintf_filtered (file, _("\
311 Automatic usage of hardware breakpoints is %s.\n"),
315 /* If on, gdb will keep breakpoints inserted even as inferior is
316 stopped, and immediately insert any new breakpoints. If off, gdb
317 will insert breakpoints into inferior only when resuming it, and
318 will remove breakpoints upon stop. If auto, GDB will behave as ON
319 if in non-stop mode, and as OFF if all-stop mode.*/
321 static const char always_inserted_auto[] = "auto";
322 static const char always_inserted_on[] = "on";
323 static const char always_inserted_off[] = "off";
324 static const char *always_inserted_enums[] = {
325 always_inserted_auto,
330 static const char *always_inserted_mode = always_inserted_auto;
332 show_always_inserted_mode (struct ui_file *file, int from_tty,
333 struct cmd_list_element *c, const char *value)
335 if (always_inserted_mode == always_inserted_auto)
336 fprintf_filtered (file, _("\
337 Always inserted breakpoint mode is %s (currently %s).\n"),
339 breakpoints_always_inserted_mode () ? "on" : "off");
341 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
345 breakpoints_always_inserted_mode (void)
347 return (always_inserted_mode == always_inserted_on
348 || (always_inserted_mode == always_inserted_auto && non_stop));
351 void _initialize_breakpoint (void);
353 /* Are we executing breakpoint commands? */
354 static int executing_breakpoint_commands;
356 /* Are overlay event breakpoints enabled? */
357 static int overlay_events_enabled;
359 /* Walk the following statement or block through all breakpoints.
360 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
363 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
365 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
366 for (B = breakpoint_chain; \
367 B ? (TMP=B->next, 1): 0; \
370 /* Similar iterator for the low-level breakpoints. SAFE variant is not
371 provided so update_global_location_list must not be called while executing
372 the block of ALL_BP_LOCATIONS. */
374 #define ALL_BP_LOCATIONS(B,BP_TMP) \
375 for (BP_TMP = bp_location; \
376 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
379 /* Iterator for tracepoints only. */
381 #define ALL_TRACEPOINTS(B) \
382 for (B = breakpoint_chain; B; B = B->next) \
383 if (is_tracepoint (B))
385 /* Chains of all breakpoints defined. */
387 struct breakpoint *breakpoint_chain;
389 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
391 static struct bp_location **bp_location;
393 /* Number of elements of BP_LOCATION. */
395 static unsigned bp_location_count;
397 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
398 for the current elements of BP_LOCATION which get a valid result from
399 bp_location_has_shadow. You can use it for roughly limiting the subrange of
400 BP_LOCATION to scan for shadow bytes for an address you need to read. */
402 static CORE_ADDR bp_location_placed_address_before_address_max;
404 /* Maximum offset plus alignment between
405 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
406 the current elements of BP_LOCATION which get a valid result from
407 bp_location_has_shadow. You can use it for roughly limiting the subrange of
408 BP_LOCATION to scan for shadow bytes for an address you need to read. */
410 static CORE_ADDR bp_location_shadow_len_after_address_max;
412 /* The locations that no longer correspond to any breakpoint,
413 unlinked from bp_location array, but for which a hit
414 may still be reported by a target. */
415 VEC(bp_location_p) *moribund_locations = NULL;
417 /* Number of last breakpoint made. */
419 static int breakpoint_count;
421 /* The value of `breakpoint_count' before the last command that
422 created breakpoints. If the last (break-like) command created more
423 than one breakpoint, then the difference between BREAKPOINT_COUNT
424 and PREV_BREAKPOINT_COUNT is more than one. */
425 static int prev_breakpoint_count;
427 /* Number of last tracepoint made. */
429 static int tracepoint_count;
431 static struct cmd_list_element *breakpoint_set_cmdlist;
432 static struct cmd_list_element *breakpoint_show_cmdlist;
433 struct cmd_list_element *save_cmdlist;
435 /* Return whether a breakpoint is an active enabled breakpoint. */
437 breakpoint_enabled (struct breakpoint *b)
439 return (b->enable_state == bp_enabled);
442 /* Set breakpoint count to NUM. */
445 set_breakpoint_count (int num)
447 prev_breakpoint_count = breakpoint_count;
448 breakpoint_count = num;
449 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
452 /* Used by `start_rbreak_breakpoints' below, to record the current
453 breakpoint count before "rbreak" creates any breakpoint. */
454 static int rbreak_start_breakpoint_count;
456 /* Called at the start an "rbreak" command to record the first
460 start_rbreak_breakpoints (void)
462 rbreak_start_breakpoint_count = breakpoint_count;
465 /* Called at the end of an "rbreak" command to record the last
469 end_rbreak_breakpoints (void)
471 prev_breakpoint_count = rbreak_start_breakpoint_count;
474 /* Used in run_command to zero the hit count when a new run starts. */
477 clear_breakpoint_hit_counts (void)
479 struct breakpoint *b;
485 /* Allocate a new counted_command_line with reference count of 1.
486 The new structure owns COMMANDS. */
488 static struct counted_command_line *
489 alloc_counted_command_line (struct command_line *commands)
491 struct counted_command_line *result
492 = xmalloc (sizeof (struct counted_command_line));
495 result->commands = commands;
499 /* Increment reference count. This does nothing if CMD is NULL. */
502 incref_counted_command_line (struct counted_command_line *cmd)
508 /* Decrement reference count. If the reference count reaches 0,
509 destroy the counted_command_line. Sets *CMDP to NULL. This does
510 nothing if *CMDP is NULL. */
513 decref_counted_command_line (struct counted_command_line **cmdp)
517 if (--(*cmdp)->refc == 0)
519 free_command_lines (&(*cmdp)->commands);
526 /* A cleanup function that calls decref_counted_command_line. */
529 do_cleanup_counted_command_line (void *arg)
531 decref_counted_command_line (arg);
534 /* Create a cleanup that calls decref_counted_command_line on the
537 static struct cleanup *
538 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
540 return make_cleanup (do_cleanup_counted_command_line, cmdp);
543 /* Default address, symtab and line to put a breakpoint at
544 for "break" command with no arg.
545 if default_breakpoint_valid is zero, the other three are
546 not valid, and "break" with no arg is an error.
548 This set by print_stack_frame, which calls set_default_breakpoint. */
550 int default_breakpoint_valid;
551 CORE_ADDR default_breakpoint_address;
552 struct symtab *default_breakpoint_symtab;
553 int default_breakpoint_line;
554 struct program_space *default_breakpoint_pspace;
557 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
558 Advance *PP after the string and any trailing whitespace.
560 Currently the string can either be a number or "$" followed by the name
561 of a convenience variable. Making it an expression wouldn't work well
562 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. */
569 get_number_trailer (char **pp, int trailer)
571 int retval = 0; /* default */
575 /* Empty line means refer to the last breakpoint. */
576 return breakpoint_count;
579 /* Make a copy of the name, so we can null-terminate it
580 to pass to lookup_internalvar(). */
585 while (isalnum (*p) || *p == '_')
587 varname = (char *) alloca (p - start + 1);
588 strncpy (varname, start, p - start);
589 varname[p - start] = '\0';
590 if (get_internalvar_integer (lookup_internalvar (varname), &val))
594 printf_filtered (_("Convenience variable must have integer value.\n"));
602 while (*p >= '0' && *p <= '9')
605 /* There is no number here. (e.g. "cond a == b"). */
607 /* Skip non-numeric token */
608 while (*p && !isspace((int) *p))
610 /* Return zero, which caller must interpret as error. */
616 if (!(isspace (*p) || *p == '\0' || *p == trailer))
618 /* Trailing junk: return 0 and let caller print error msg. */
619 while (!(isspace (*p) || *p == '\0' || *p == trailer))
630 /* Like get_number_trailer, but don't allow a trailer. */
632 get_number (char **pp)
634 return get_number_trailer (pp, '\0');
637 /* Parse a number or a range.
638 * A number will be of the form handled by get_number.
639 * A range will be of the form <number1> - <number2>, and
640 * will represent all the integers between number1 and number2,
643 * While processing a range, this fuction is called iteratively;
644 * At each call it will return the next value in the range.
646 * At the beginning of parsing a range, the char pointer PP will
647 * be advanced past <number1> and left pointing at the '-' token.
648 * Subsequent calls will not advance the pointer until the range
649 * is completed. The call that completes the range will advance
650 * pointer PP past <number2>.
654 get_number_or_range (char **pp)
656 static int last_retval, end_value;
657 static char *end_ptr;
658 static int in_range = 0;
662 /* Default case: pp is pointing either to a solo number,
663 or to the first number of a range. */
664 last_retval = get_number_trailer (pp, '-');
669 /* This is the start of a range (<number1> - <number2>).
670 Skip the '-', parse and remember the second number,
671 and also remember the end of the final token. */
675 while (isspace ((int) *end_ptr))
676 end_ptr++; /* skip white space */
677 end_value = get_number (temp);
678 if (end_value < last_retval)
680 error (_("inverted range"));
682 else if (end_value == last_retval)
684 /* degenerate range (number1 == number2). Advance the
685 token pointer so that the range will be treated as a
694 error (_("negative value"));
697 /* pp points to the '-' that betokens a range. All
698 number-parsing has already been done. Return the next
699 integer value (one greater than the saved previous value).
700 Do not advance the token pointer 'pp' until the end of range
703 if (++last_retval == end_value)
705 /* End of range reached; advance token pointer. */
713 /* Return the breakpoint with the specified number, or NULL
714 if the number does not refer to an existing breakpoint. */
717 get_breakpoint (int num)
719 struct breakpoint *b;
722 if (b->number == num)
731 set_breakpoint_condition (struct breakpoint *b, char *exp,
734 struct bp_location *loc = b->loc;
736 for (; loc; loc = loc->next)
741 xfree (b->cond_string);
742 b->cond_string = NULL;
749 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
755 /* I don't know if it matters whether this is the string the user
756 typed in or the decompiled expression. */
757 b->cond_string = xstrdup (arg);
758 b->condition_not_parsed = 0;
760 if (is_watchpoint (b))
762 innermost_block = NULL;
764 b->cond_exp = parse_exp_1 (&arg, 0, 0);
766 error (_("Junk at end of expression"));
767 b->cond_exp_valid_block = innermost_block;
771 for (loc = b->loc; loc; loc = loc->next)
775 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
777 error (_("Junk at end of expression"));
781 breakpoints_changed ();
782 observer_notify_breakpoint_modified (b->number);
785 /* condition N EXP -- set break condition of breakpoint N to EXP. */
788 condition_command (char *arg, int from_tty)
790 struct breakpoint *b;
795 error_no_arg (_("breakpoint number"));
798 bnum = get_number (&p);
800 error (_("Bad breakpoint argument: '%s'"), arg);
803 if (b->number == bnum)
805 set_breakpoint_condition (b, p, from_tty);
809 error (_("No breakpoint number %d."), bnum);
812 /* Check that COMMAND do not contain commands that are suitable
813 only for tracepoints and not suitable for ordinary breakpoints.
814 Throw if any such commands is found.
817 check_no_tracepoint_commands (struct command_line *commands)
819 struct command_line *c;
821 for (c = commands; c; c = c->next)
825 if (c->control_type == while_stepping_control)
826 error (_("The 'while-stepping' command can only be used for tracepoints"));
828 for (i = 0; i < c->body_count; ++i)
829 check_no_tracepoint_commands ((c->body_list)[i]);
831 /* Not that command parsing removes leading whitespace and comment
832 lines and also empty lines. So, we only need to check for
834 if (strstr (c->line, "collect ") == c->line)
835 error (_("The 'collect' command can only be used for tracepoints"));
837 if (strstr (c->line, "teval ") == c->line)
838 error (_("The 'teval' command can only be used for tracepoints"));
842 /* Encapsulate tests for different types of tracepoints. */
845 is_tracepoint (const struct breakpoint *b)
847 return (b->type == bp_tracepoint
848 || b->type == bp_fast_tracepoint
849 || b->type == bp_static_tracepoint);
852 /* A helper function that validsates that COMMANDS are valid for a
853 breakpoint. This function will throw an exception if a problem is
857 validate_commands_for_breakpoint (struct breakpoint *b,
858 struct command_line *commands)
860 if (is_tracepoint (b))
862 /* We need to verify that each top-level element of commands
863 is valid for tracepoints, that there's at most one while-stepping
864 element, and that while-stepping's body has valid tracing commands
865 excluding nested while-stepping. */
866 struct command_line *c;
867 struct command_line *while_stepping = 0;
868 for (c = commands; c; c = c->next)
870 if (c->control_type == while_stepping_control)
872 if (b->type == bp_fast_tracepoint)
874 The 'while-stepping' command cannot be used for fast tracepoint"));
875 else if (b->type == bp_static_tracepoint)
877 The 'while-stepping' command cannot be used for static tracepoint"));
880 error (_("The 'while-stepping' command can be used only once"));
887 struct command_line *c2;
889 gdb_assert (while_stepping->body_count == 1);
890 c2 = while_stepping->body_list[0];
891 for (; c2; c2 = c2->next)
893 if (c2->control_type == while_stepping_control)
894 error (_("The 'while-stepping' command cannot be nested"));
900 check_no_tracepoint_commands (commands);
904 /* Return a vector of all the static tracepoints set at ADDR. The
905 caller is responsible for releasing the vector. */
908 static_tracepoints_here (CORE_ADDR addr)
910 struct breakpoint *b;
911 VEC(breakpoint_p) *found = 0;
912 struct bp_location *loc;
915 if (b->type == bp_static_tracepoint)
917 for (loc = b->loc; loc; loc = loc->next)
918 if (loc->address == addr)
919 VEC_safe_push(breakpoint_p, found, b);
925 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
926 validate that only allowed commands are included.
930 breakpoint_set_commands (struct breakpoint *b, struct command_line *commands)
932 validate_commands_for_breakpoint (b, commands);
934 decref_counted_command_line (&b->commands);
935 b->commands = alloc_counted_command_line (commands);
936 breakpoints_changed ();
937 observer_notify_breakpoint_modified (b->number);
941 check_tracepoint_command (char *line, void *closure)
943 struct breakpoint *b = closure;
945 validate_actionline (&line, b);
948 /* A structure used to pass information through
949 map_breakpoint_numbers. */
953 /* True if the command was typed at a tty. */
956 /* The breakpoint range spec. */
959 /* Non-NULL if the body of the commands are being read from this
960 already-parsed command. */
961 struct command_line *control;
963 /* The command lines read from the user, or NULL if they have not
965 struct counted_command_line *cmd;
968 /* A callback for map_breakpoint_numbers that sets the commands for
972 do_map_commands_command (struct breakpoint *b, void *data)
974 struct commands_info *info = data;
976 if (info->cmd == NULL)
978 struct command_line *l;
980 if (info->control != NULL)
981 l = copy_command_lines (info->control->body_list[0]);
984 struct cleanup *old_chain;
987 str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
990 old_chain = make_cleanup (xfree, str);
992 l = read_command_lines (str,
995 ? check_tracepoint_command : 0),
998 do_cleanups (old_chain);
1001 info->cmd = alloc_counted_command_line (l);
1004 /* If a breakpoint was on the list more than once, we don't need to
1006 if (b->commands != info->cmd)
1008 validate_commands_for_breakpoint (b, info->cmd->commands);
1009 incref_counted_command_line (info->cmd);
1010 decref_counted_command_line (&b->commands);
1011 b->commands = info->cmd;
1012 breakpoints_changed ();
1013 observer_notify_breakpoint_modified (b->number);
1018 commands_command_1 (char *arg, int from_tty, struct command_line *control)
1020 struct cleanup *cleanups;
1021 struct commands_info info;
1023 info.from_tty = from_tty;
1024 info.control = control;
1026 /* If we read command lines from the user, then `info' will hold an
1027 extra reference to the commands that we must clean up. */
1028 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1030 if (arg == NULL || !*arg)
1032 if (breakpoint_count - prev_breakpoint_count > 1)
1033 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count);
1034 else if (breakpoint_count > 0)
1035 arg = xstrprintf ("%d", breakpoint_count);
1038 /* So that we don't try to free the incoming non-NULL
1039 argument in the cleanup below. Mapping breakpoint
1040 numbers will fail in this case. */
1045 /* The command loop has some static state, so we need to preserve
1047 arg = xstrdup (arg);
1050 make_cleanup (xfree, arg);
1054 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1056 if (info.cmd == NULL)
1057 error (_("No breakpoints specified."));
1059 do_cleanups (cleanups);
1063 commands_command (char *arg, int from_tty)
1065 commands_command_1 (arg, from_tty, NULL);
1068 /* Like commands_command, but instead of reading the commands from
1069 input stream, takes them from an already parsed command structure.
1071 This is used by cli-script.c to DTRT with breakpoint commands
1072 that are part of if and while bodies. */
1073 enum command_control_type
1074 commands_from_control_command (char *arg, struct command_line *cmd)
1076 commands_command_1 (arg, 0, cmd);
1077 return simple_control;
1080 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1083 bp_location_has_shadow (struct bp_location *bl)
1085 if (bl->loc_type != bp_loc_software_breakpoint)
1089 if (bl->target_info.shadow_len == 0)
1090 /* bp isn't valid, or doesn't shadow memory. */
1095 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1096 by replacing any memory breakpoints with their shadowed contents.
1098 The range of shadowed area by each bp_location is:
1099 b->address - bp_location_placed_address_before_address_max
1100 up to b->address + bp_location_shadow_len_after_address_max
1101 The range we were requested to resolve shadows for is:
1102 memaddr ... memaddr + len
1103 Thus the safe cutoff boundaries for performance optimization are
1104 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1106 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1109 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
1111 /* Left boundary, right boundary and median element of our binary search. */
1112 unsigned bc_l, bc_r, bc;
1114 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1115 safe to report lower value but a failure to report higher one. */
1118 bc_r = bp_location_count;
1119 while (bc_l + 1 < bc_r)
1121 struct bp_location *b;
1123 bc = (bc_l + bc_r) / 2;
1124 b = bp_location[bc];
1126 /* Check first B->ADDRESS will not overflow due to the added constant.
1127 Then advance the left boundary only if we are sure the BC element can
1128 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1130 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1131 we cannot miss a breakpoint with its shadow range tail still reaching
1134 if (b->address + bp_location_shadow_len_after_address_max >= b->address
1135 && b->address + bp_location_shadow_len_after_address_max <= memaddr)
1141 /* Now do full processing of the found relevant range of elements. */
1143 for (bc = bc_l; bc < bp_location_count; bc++)
1145 struct bp_location *b = bp_location[bc];
1146 CORE_ADDR bp_addr = 0;
1150 /* bp_location array has B->OWNER always non-NULL. */
1151 if (b->owner->type == bp_none)
1152 warning (_("reading through apparently deleted breakpoint #%d?"),
1155 /* Performance optimization: any futher element can no longer affect BUF
1158 if (b->address >= bp_location_placed_address_before_address_max
1159 && memaddr + len <= b->address
1160 - bp_location_placed_address_before_address_max)
1163 if (!bp_location_has_shadow (b))
1165 if (!breakpoint_address_match (b->target_info.placed_address_space, 0,
1166 current_program_space->aspace, 0))
1169 /* Addresses and length of the part of the breakpoint that
1171 bp_addr = b->target_info.placed_address;
1172 bp_size = b->target_info.shadow_len;
1174 if (bp_addr + bp_size <= memaddr)
1175 /* The breakpoint is entirely before the chunk of memory we
1179 if (bp_addr >= memaddr + len)
1180 /* The breakpoint is entirely after the chunk of memory we are
1184 /* Offset within shadow_contents. */
1185 if (bp_addr < memaddr)
1187 /* Only copy the second part of the breakpoint. */
1188 bp_size -= memaddr - bp_addr;
1189 bptoffset = memaddr - bp_addr;
1193 if (bp_addr + bp_size > memaddr + len)
1195 /* Only copy the first part of the breakpoint. */
1196 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1199 memcpy (buf + bp_addr - memaddr,
1200 b->target_info.shadow_contents + bptoffset, bp_size);
1205 /* A wrapper function for inserting catchpoints. */
1207 insert_catchpoint (struct ui_out *uo, void *args)
1209 struct breakpoint *b = (struct breakpoint *) args;
1211 gdb_assert (b->type == bp_catchpoint);
1212 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
1217 /* Return true if BPT is of any hardware watchpoint kind. */
1220 is_hardware_watchpoint (const struct breakpoint *bpt)
1222 return (bpt->type == bp_hardware_watchpoint
1223 || bpt->type == bp_read_watchpoint
1224 || bpt->type == bp_access_watchpoint);
1227 /* Return true if BPT is of any watchpoint kind, hardware or
1231 is_watchpoint (const struct breakpoint *bpt)
1233 return (is_hardware_watchpoint (bpt)
1234 || bpt->type == bp_watchpoint);
1237 /* Assuming that B is a watchpoint: returns true if the current thread
1238 and its running state are safe to evaluate or update watchpoint B.
1239 Watchpoints on local expressions need to be evaluated in the
1240 context of the thread that was current when the watchpoint was
1241 created, and, that thread needs to be stopped to be able to select
1242 the correct frame context. Watchpoints on global expressions can
1243 be evaluated on any thread, and in any state. It is presently left
1244 to the target allowing memory accesses when threads are
1248 watchpoint_in_thread_scope (struct breakpoint *b)
1250 return (ptid_equal (b->watchpoint_thread, null_ptid)
1251 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1252 && !is_executing (inferior_ptid)));
1255 /* Assuming that B is a watchpoint:
1256 - Reparse watchpoint expression, if REPARSE is non-zero
1257 - Evaluate expression and store the result in B->val
1258 - Evaluate the condition if there is one, and store the result
1260 - Update the list of values that must be watched in B->loc.
1262 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1263 If this is local watchpoint that is out of scope, delete it.
1265 Even with `set breakpoint always-inserted on' the watchpoints are removed
1266 + inserted on each stop here. Normal breakpoints must never be removed
1267 because they might be missed by a running thread when debugging in non-stop
1268 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1269 processed here) are specific to each LWP since they are stored in each LWP's
1270 hardware debug registers. Therefore, such LWP must be stopped first in
1271 order to be able to modify its hardware watchpoints.
1273 Hardware watchpoints must be reset exactly once after being presented to the
1274 user. It cannot be done sooner, because it would reset the data used to
1275 present the watchpoint hit to the user. And it must not be done later
1276 because it could display the same single watchpoint hit during multiple GDB
1277 stops. Note that the latter is relevant only to the hardware watchpoint
1278 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1279 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1280 memory content has not changed.
1282 The following constraints influence the location where we can reset hardware
1285 * target_stopped_by_watchpoint and target_stopped_data_address are called
1286 several times when GDB stops.
1289 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1290 stop. GDB only presents one hardware watchpoint hit at a time as the
1291 reason for stopping, and all the other hits are presented later, one after
1292 the other, each time the user requests the execution to be resumed.
1293 Execution is not resumed for the threads still having pending hit event
1294 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1295 the inferior on the first stop the thread hit event is kept being reported
1296 from its cached value by linux_nat_stopped_data_address until the real
1297 thread resume happens after the watchpoint gets presented and thus its
1298 LWP_INFO->STATUS gets reset.
1300 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1301 removal from inferior. */
1304 update_watchpoint (struct breakpoint *b, int reparse)
1306 int within_current_scope;
1307 struct frame_id saved_frame_id;
1310 /* If this is a local watchpoint, we only want to check if the
1311 watchpoint frame is in scope if the current thread is the thread
1312 that was used to create the watchpoint. */
1313 if (!watchpoint_in_thread_scope (b))
1316 /* We don't free locations. They are stored in bp_location array and
1317 update_global_locations will eventually delete them and remove
1318 breakpoints if needed. */
1321 if (b->disposition == disp_del_at_next_stop)
1326 /* Determine if the watchpoint is within scope. */
1327 if (b->exp_valid_block == NULL)
1328 within_current_scope = 1;
1331 struct frame_info *fi;
1333 /* Save the current frame's ID so we can restore it after
1334 evaluating the watchpoint expression on its own frame. */
1335 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1336 took a frame parameter, so that we didn't have to change the
1339 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1341 fi = frame_find_by_id (b->watchpoint_frame);
1342 within_current_scope = (fi != NULL);
1343 if (within_current_scope)
1347 if (within_current_scope && reparse)
1356 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1357 /* If the meaning of expression itself changed, the old value is
1358 no longer relevant. We don't want to report a watchpoint hit
1359 to the user when the old value and the new value may actually
1360 be completely different objects. */
1361 value_free (b->val);
1365 /* Note that unlike with breakpoints, the watchpoint's condition
1366 expression is stored in the breakpoint object, not in the
1367 locations (re)created below. */
1368 if (b->cond_string != NULL)
1370 if (b->cond_exp != NULL)
1372 xfree (b->cond_exp);
1377 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1381 /* If we failed to parse the expression, for example because
1382 it refers to a global variable in a not-yet-loaded shared library,
1383 don't try to insert watchpoint. We don't automatically delete
1384 such watchpoint, though, since failure to parse expression
1385 is different from out-of-scope watchpoint. */
1386 if ( !target_has_execution)
1388 /* Without execution, memory can't change. No use to try and
1389 set watchpoint locations. The watchpoint will be reset when
1390 the target gains execution, through breakpoint_re_set. */
1392 else if (within_current_scope && b->exp)
1395 struct value *val_chain, *v, *result, *next;
1396 struct program_space *frame_pspace;
1398 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1400 /* Avoid setting b->val if it's already set. The meaning of
1401 b->val is 'the last value' user saw, and we should update
1402 it only if we reported that last value to user. As it
1403 happens, the code that reports it updates b->val directly. */
1410 /* Change the type of breakpoint between hardware assisted or an
1411 ordinary watchpoint depending on the hardware support and free
1412 hardware slots. REPARSE is set when the inferior is started. */
1413 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1416 int i, mem_cnt, other_type_used;
1418 /* We need to determine how many resources are already used
1419 for all other hardware watchpoints to see if we still have
1420 enough resources to also fit this watchpoint in as well.
1421 To avoid the hw_watchpoint_used_count call below from counting
1422 this watchpoint, make sure that it is marked as a software
1424 b->type = bp_watchpoint;
1425 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1427 mem_cnt = can_use_hardware_watchpoint (val_chain);
1430 b->type = bp_watchpoint;
1433 int target_resources_ok = target_can_use_hardware_watchpoint
1434 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1435 if (target_resources_ok <= 0)
1436 b->type = bp_watchpoint;
1438 b->type = bp_hardware_watchpoint;
1442 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1444 /* Look at each value on the value chain. */
1445 for (v = val_chain; v; v = next)
1447 /* If it's a memory location, and GDB actually needed
1448 its contents to evaluate the expression, then we
1449 must watch it. If the first value returned is
1450 still lazy, that means an error occurred reading it;
1451 watch it anyway in case it becomes readable. */
1452 if (VALUE_LVAL (v) == lval_memory
1453 && (v == val_chain || ! value_lazy (v)))
1455 struct type *vtype = check_typedef (value_type (v));
1457 /* We only watch structs and arrays if user asked
1458 for it explicitly, never if they just happen to
1459 appear in the middle of some value chain. */
1461 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1462 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1466 struct bp_location *loc, **tmp;
1468 addr = value_address (v);
1469 len = TYPE_LENGTH (value_type (v));
1471 if (b->type == bp_read_watchpoint)
1473 else if (b->type == bp_access_watchpoint)
1476 loc = allocate_bp_location (b);
1477 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1480 loc->gdbarch = get_type_arch (value_type (v));
1482 loc->pspace = frame_pspace;
1483 loc->address = addr;
1485 loc->watchpoint_type = type;
1489 next = value_next (v);
1494 /* If a software watchpoint is not watching any memory, then the
1495 above left it without any location set up. But,
1496 bpstat_stop_status requires a location to be able to report
1497 stops, so make sure there's at least a dummy one. */
1498 if (b->type == bp_watchpoint && b->loc == NULL)
1500 b->loc = allocate_bp_location (b);
1501 b->loc->pspace = frame_pspace;
1502 b->loc->address = -1;
1503 b->loc->length = -1;
1504 b->loc->watchpoint_type = -1;
1507 else if (!within_current_scope)
1509 printf_filtered (_("\
1510 Watchpoint %d deleted because the program has left the block\n\
1511 in which its expression is valid.\n"),
1513 if (b->related_breakpoint)
1515 b->related_breakpoint->disposition = disp_del_at_next_stop;
1516 b->related_breakpoint->related_breakpoint = NULL;
1517 b->related_breakpoint= NULL;
1519 b->disposition = disp_del_at_next_stop;
1522 /* Restore the selected frame. */
1524 select_frame (frame_find_by_id (saved_frame_id));
1528 /* Returns 1 iff breakpoint location should be
1529 inserted in the inferior. */
1531 should_be_inserted (struct bp_location *bpt)
1533 if (bpt->owner == NULL || !breakpoint_enabled (bpt->owner))
1536 if (bpt->owner->disposition == disp_del_at_next_stop)
1539 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1542 /* This is set for example, when we're attached to the parent of a
1543 vfork, and have detached from the child. The child is running
1544 free, and we expect it to do an exec or exit, at which point the
1545 OS makes the parent schedulable again (and the target reports
1546 that the vfork is done). Until the child is done with the shared
1547 memory region, do not insert breakpoints in the parent, otherwise
1548 the child could still trip on the parent's breakpoints. Since
1549 the parent is blocked anyway, it won't miss any breakpoint. */
1550 if (bpt->pspace->breakpoints_not_allowed)
1553 /* Tracepoints are inserted by the target at a time of its choosing,
1555 if (is_tracepoint (bpt->owner))
1561 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1562 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1563 and HW_BREAKPOINT_ERROR are used to report problems.
1565 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1566 method for each breakpoint or catchpoint type. */
1568 insert_bp_location (struct bp_location *bpt,
1569 struct ui_file *tmp_error_stream,
1570 int *disabled_breaks,
1571 int *hw_breakpoint_error)
1575 if (!should_be_inserted (bpt) || bpt->inserted)
1578 /* Initialize the target-specific information. */
1579 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1580 bpt->target_info.placed_address = bpt->address;
1581 bpt->target_info.placed_address_space = bpt->pspace->aspace;
1583 if (bpt->loc_type == bp_loc_software_breakpoint
1584 || bpt->loc_type == bp_loc_hardware_breakpoint)
1586 if (bpt->owner->type != bp_hardware_breakpoint)
1588 /* If the explicitly specified breakpoint type
1589 is not hardware breakpoint, check the memory map to see
1590 if the breakpoint address is in read only memory or not.
1591 Two important cases are:
1592 - location type is not hardware breakpoint, memory
1593 is readonly. We change the type of the location to
1594 hardware breakpoint.
1595 - location type is hardware breakpoint, memory is read-write.
1596 This means we've previously made the location hardware one, but
1597 then the memory map changed, so we undo.
1599 When breakpoints are removed, remove_breakpoints will
1600 use location types we've just set here, the only possible
1601 problem is that memory map has changed during running program,
1602 but it's not going to work anyway with current gdb. */
1603 struct mem_region *mr
1604 = lookup_mem_region (bpt->target_info.placed_address);
1608 if (automatic_hardware_breakpoints)
1610 enum bp_loc_type new_type;
1612 if (mr->attrib.mode != MEM_RW)
1613 new_type = bp_loc_hardware_breakpoint;
1615 new_type = bp_loc_software_breakpoint;
1617 if (new_type != bpt->loc_type)
1619 static int said = 0;
1621 bpt->loc_type = new_type;
1624 fprintf_filtered (gdb_stdout, _("\
1625 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1630 else if (bpt->loc_type == bp_loc_software_breakpoint
1631 && mr->attrib.mode != MEM_RW)
1632 warning (_("cannot set software breakpoint at readonly address %s"),
1633 paddress (bpt->gdbarch, bpt->address));
1637 /* First check to see if we have to handle an overlay. */
1638 if (overlay_debugging == ovly_off
1639 || bpt->section == NULL
1640 || !(section_is_overlay (bpt->section)))
1642 /* No overlay handling: just set the breakpoint. */
1644 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1645 val = target_insert_hw_breakpoint (bpt->gdbarch,
1648 val = target_insert_breakpoint (bpt->gdbarch,
1653 /* This breakpoint is in an overlay section.
1654 Shall we set a breakpoint at the LMA? */
1655 if (!overlay_events_enabled)
1657 /* Yes -- overlay event support is not active,
1658 so we must try to set a breakpoint at the LMA.
1659 This will not work for a hardware breakpoint. */
1660 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1661 warning (_("hardware breakpoint %d not supported in overlay!"),
1662 bpt->owner->number);
1665 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1667 /* Set a software (trap) breakpoint at the LMA. */
1668 bpt->overlay_target_info = bpt->target_info;
1669 bpt->overlay_target_info.placed_address = addr;
1670 val = target_insert_breakpoint (bpt->gdbarch,
1671 &bpt->overlay_target_info);
1673 fprintf_unfiltered (tmp_error_stream,
1674 "Overlay breakpoint %d failed: in ROM?\n",
1675 bpt->owner->number);
1678 /* Shall we set a breakpoint at the VMA? */
1679 if (section_is_mapped (bpt->section))
1681 /* Yes. This overlay section is mapped into memory. */
1682 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1683 val = target_insert_hw_breakpoint (bpt->gdbarch,
1686 val = target_insert_breakpoint (bpt->gdbarch,
1691 /* No. This breakpoint will not be inserted.
1692 No error, but do not mark the bp as 'inserted'. */
1699 /* Can't set the breakpoint. */
1700 if (solib_name_from_address (bpt->pspace, bpt->address))
1702 /* See also: disable_breakpoints_in_shlibs. */
1704 bpt->shlib_disabled = 1;
1705 if (!*disabled_breaks)
1707 fprintf_unfiltered (tmp_error_stream,
1708 "Cannot insert breakpoint %d.\n",
1709 bpt->owner->number);
1710 fprintf_unfiltered (tmp_error_stream,
1711 "Temporarily disabling shared library breakpoints:\n");
1713 *disabled_breaks = 1;
1714 fprintf_unfiltered (tmp_error_stream,
1715 "breakpoint #%d\n", bpt->owner->number);
1719 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1721 *hw_breakpoint_error = 1;
1722 fprintf_unfiltered (tmp_error_stream,
1723 "Cannot insert hardware breakpoint %d.\n",
1724 bpt->owner->number);
1728 fprintf_unfiltered (tmp_error_stream,
1729 "Cannot insert breakpoint %d.\n",
1730 bpt->owner->number);
1731 fprintf_filtered (tmp_error_stream,
1732 "Error accessing memory address ");
1733 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1735 fprintf_filtered (tmp_error_stream, ": %s.\n",
1736 safe_strerror (val));
1747 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1748 /* NOTE drow/2003-09-08: This state only exists for removing
1749 watchpoints. It's not clear that it's necessary... */
1750 && bpt->owner->disposition != disp_del_at_next_stop)
1752 val = target_insert_watchpoint (bpt->address,
1754 bpt->watchpoint_type,
1755 bpt->owner->cond_exp);
1757 /* If trying to set a read-watchpoint, and it turns out it's not
1758 supported, try emulating one with an access watchpoint. */
1759 if (val == 1 && bpt->watchpoint_type == hw_read)
1761 struct bp_location *loc, **loc_temp;
1763 /* But don't try to insert it, if there's already another
1764 hw_access location that would be considered a duplicate
1766 ALL_BP_LOCATIONS (loc, loc_temp)
1768 && loc->watchpoint_type == hw_access
1769 && watchpoint_locations_match (bpt, loc))
1773 bpt->target_info = loc->target_info;
1774 bpt->watchpoint_type = hw_access;
1781 val = target_insert_watchpoint (bpt->address,
1784 bpt->owner->cond_exp);
1786 bpt->watchpoint_type = hw_access;
1790 bpt->inserted = (val == 0);
1793 else if (bpt->owner->type == bp_catchpoint)
1795 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1796 bpt->owner, RETURN_MASK_ERROR);
1797 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1798 bpt->owner->number);
1800 bpt->owner->enable_state = bp_disabled;
1804 /* We've already printed an error message if there was a problem
1805 inserting this catchpoint, and we've disabled the catchpoint,
1806 so just return success. */
1813 /* This function is called when program space PSPACE is about to be
1814 deleted. It takes care of updating breakpoints to not reference
1818 breakpoint_program_space_exit (struct program_space *pspace)
1820 struct breakpoint *b, *b_temp;
1821 struct bp_location *loc, **loc_temp;
1823 /* Remove any breakpoint that was set through this program space. */
1824 ALL_BREAKPOINTS_SAFE (b, b_temp)
1826 if (b->pspace == pspace)
1827 delete_breakpoint (b);
1830 /* Breakpoints set through other program spaces could have locations
1831 bound to PSPACE as well. Remove those. */
1832 ALL_BP_LOCATIONS (loc, loc_temp)
1834 struct bp_location *tmp;
1836 if (loc->pspace == pspace)
1838 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1839 if (loc->owner->loc == loc)
1840 loc->owner->loc = loc->next;
1842 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1843 if (tmp->next == loc)
1845 tmp->next = loc->next;
1851 /* Now update the global location list to permanently delete the
1852 removed locations above. */
1853 update_global_location_list (0);
1856 /* Make sure all breakpoints are inserted in inferior.
1857 Throws exception on any error.
1858 A breakpoint that is already inserted won't be inserted
1859 again, so calling this function twice is safe. */
1861 insert_breakpoints (void)
1863 struct breakpoint *bpt;
1865 ALL_BREAKPOINTS (bpt)
1866 if (is_hardware_watchpoint (bpt))
1867 update_watchpoint (bpt, 0 /* don't reparse. */);
1869 update_global_location_list (1);
1871 /* update_global_location_list does not insert breakpoints when
1872 always_inserted_mode is not enabled. Explicitly insert them
1874 if (!breakpoints_always_inserted_mode ())
1875 insert_breakpoint_locations ();
1878 /* insert_breakpoints is used when starting or continuing the program.
1879 remove_breakpoints is used when the program stops.
1880 Both return zero if successful,
1881 or an `errno' value if could not write the inferior. */
1884 insert_breakpoint_locations (void)
1886 struct breakpoint *bpt;
1887 struct bp_location *b, **bp_tmp;
1890 int disabled_breaks = 0;
1891 int hw_breakpoint_error = 0;
1893 struct ui_file *tmp_error_stream = mem_fileopen ();
1894 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1896 /* Explicitly mark the warning -- this will only be printed if
1897 there was an error. */
1898 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1900 save_current_space_and_thread ();
1902 ALL_BP_LOCATIONS (b, bp_tmp)
1904 if (!should_be_inserted (b) || b->inserted)
1907 /* There is no point inserting thread-specific breakpoints if the
1908 thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER
1910 if (b->owner->thread != -1
1911 && !valid_thread_id (b->owner->thread))
1914 switch_to_program_space_and_thread (b->pspace);
1916 /* For targets that support global breakpoints, there's no need
1917 to select an inferior to insert breakpoint to. In fact, even
1918 if we aren't attached to any process yet, we should still
1919 insert breakpoints. */
1920 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1921 && ptid_equal (inferior_ptid, null_ptid))
1924 val = insert_bp_location (b, tmp_error_stream,
1926 &hw_breakpoint_error);
1931 /* If we failed to insert all locations of a watchpoint,
1932 remove them, as half-inserted watchpoint is of limited use. */
1933 ALL_BREAKPOINTS (bpt)
1935 int some_failed = 0;
1936 struct bp_location *loc;
1938 if (!is_hardware_watchpoint (bpt))
1941 if (!breakpoint_enabled (bpt))
1944 if (bpt->disposition == disp_del_at_next_stop)
1947 for (loc = bpt->loc; loc; loc = loc->next)
1948 if (!loc->inserted && should_be_inserted (loc))
1955 for (loc = bpt->loc; loc; loc = loc->next)
1957 remove_breakpoint (loc, mark_uninserted);
1959 hw_breakpoint_error = 1;
1960 fprintf_unfiltered (tmp_error_stream,
1961 "Could not insert hardware watchpoint %d.\n",
1969 /* If a hardware breakpoint or watchpoint was inserted, add a
1970 message about possibly exhausted resources. */
1971 if (hw_breakpoint_error)
1973 fprintf_unfiltered (tmp_error_stream,
1974 "Could not insert hardware breakpoints:\n\
1975 You may have requested too many hardware breakpoints/watchpoints.\n");
1977 target_terminal_ours_for_output ();
1978 error_stream (tmp_error_stream);
1981 do_cleanups (cleanups);
1985 remove_breakpoints (void)
1987 struct bp_location *b, **bp_tmp;
1990 ALL_BP_LOCATIONS (b, bp_tmp)
1993 val |= remove_breakpoint (b, mark_uninserted);
1998 /* Remove breakpoints of process PID. */
2001 remove_breakpoints_pid (int pid)
2003 struct bp_location *b, **b_tmp;
2005 struct inferior *inf = find_inferior_pid (pid);
2007 ALL_BP_LOCATIONS (b, b_tmp)
2009 if (b->pspace != inf->pspace)
2014 val = remove_breakpoint (b, mark_uninserted);
2023 remove_hw_watchpoints (void)
2025 struct bp_location *b, **bp_tmp;
2028 ALL_BP_LOCATIONS (b, bp_tmp)
2030 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
2031 val |= remove_breakpoint (b, mark_uninserted);
2037 reattach_breakpoints (int pid)
2039 struct cleanup *old_chain;
2040 struct bp_location *b, **bp_tmp;
2042 struct ui_file *tmp_error_stream = mem_fileopen ();
2043 int dummy1 = 0, dummy2 = 0;
2044 struct inferior *inf;
2045 struct thread_info *tp;
2047 tp = any_live_thread_of_process (pid);
2051 inf = find_inferior_pid (pid);
2052 old_chain = save_inferior_ptid ();
2054 inferior_ptid = tp->ptid;
2056 make_cleanup_ui_file_delete (tmp_error_stream);
2058 ALL_BP_LOCATIONS (b, bp_tmp)
2060 if (b->pspace != inf->pspace)
2066 val = insert_bp_location (b, tmp_error_stream,
2070 do_cleanups (old_chain);
2075 do_cleanups (old_chain);
2079 static int internal_breakpoint_number = -1;
2081 static struct breakpoint *
2082 create_internal_breakpoint (struct gdbarch *gdbarch,
2083 CORE_ADDR address, enum bptype type)
2085 struct symtab_and_line sal;
2086 struct breakpoint *b;
2088 init_sal (&sal); /* initialize to zeroes */
2091 sal.section = find_pc_overlay (sal.pc);
2092 sal.pspace = current_program_space;
2094 b = set_raw_breakpoint (gdbarch, sal, type);
2095 b->number = internal_breakpoint_number--;
2096 b->disposition = disp_donttouch;
2102 create_overlay_event_breakpoint (char *func_name)
2104 struct objfile *objfile;
2106 ALL_OBJFILES (objfile)
2108 struct breakpoint *b;
2109 struct minimal_symbol *m;
2111 m = lookup_minimal_symbol_text (func_name, objfile);
2115 b = create_internal_breakpoint (get_objfile_arch (objfile),
2116 SYMBOL_VALUE_ADDRESS (m),
2118 b->addr_string = xstrdup (func_name);
2120 if (overlay_debugging == ovly_auto)
2122 b->enable_state = bp_enabled;
2123 overlay_events_enabled = 1;
2127 b->enable_state = bp_disabled;
2128 overlay_events_enabled = 0;
2131 update_global_location_list (1);
2135 create_longjmp_master_breakpoint (char *func_name)
2137 struct program_space *pspace;
2138 struct objfile *objfile;
2139 struct cleanup *old_chain;
2141 old_chain = save_current_program_space ();
2143 ALL_PSPACES (pspace)
2144 ALL_OBJFILES (objfile)
2146 struct breakpoint *b;
2147 struct minimal_symbol *m;
2149 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2152 set_current_program_space (pspace);
2154 m = lookup_minimal_symbol_text (func_name, objfile);
2158 b = create_internal_breakpoint (get_objfile_arch (objfile),
2159 SYMBOL_VALUE_ADDRESS (m),
2161 b->addr_string = xstrdup (func_name);
2162 b->enable_state = bp_disabled;
2164 update_global_location_list (1);
2166 do_cleanups (old_chain);
2169 /* Create a master std::terminate breakpoint. The actual function
2170 looked for is named FUNC_NAME. */
2172 create_std_terminate_master_breakpoint (const char *func_name)
2174 struct program_space *pspace;
2175 struct objfile *objfile;
2176 struct cleanup *old_chain;
2178 old_chain = save_current_program_space ();
2180 ALL_PSPACES (pspace)
2181 ALL_OBJFILES (objfile)
2183 struct breakpoint *b;
2184 struct minimal_symbol *m;
2186 set_current_program_space (pspace);
2188 m = lookup_minimal_symbol (func_name, NULL, objfile);
2189 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2190 && MSYMBOL_TYPE (m) != mst_file_text))
2193 b = create_internal_breakpoint (get_objfile_arch (objfile),
2194 SYMBOL_VALUE_ADDRESS (m),
2195 bp_std_terminate_master);
2196 b->addr_string = xstrdup (func_name);
2197 b->enable_state = bp_disabled;
2199 update_global_location_list (1);
2201 do_cleanups (old_chain);
2205 update_breakpoints_after_exec (void)
2207 struct breakpoint *b;
2208 struct breakpoint *temp;
2209 struct bp_location *bploc, **bplocp_tmp;
2211 /* We're about to delete breakpoints from GDB's lists. If the
2212 INSERTED flag is true, GDB will try to lift the breakpoints by
2213 writing the breakpoints' "shadow contents" back into memory. The
2214 "shadow contents" are NOT valid after an exec, so GDB should not
2215 do that. Instead, the target is responsible from marking
2216 breakpoints out as soon as it detects an exec. We don't do that
2217 here instead, because there may be other attempts to delete
2218 breakpoints after detecting an exec and before reaching here. */
2219 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2220 if (bploc->pspace == current_program_space)
2221 gdb_assert (!bploc->inserted);
2223 ALL_BREAKPOINTS_SAFE (b, temp)
2225 if (b->pspace != current_program_space)
2228 /* Solib breakpoints must be explicitly reset after an exec(). */
2229 if (b->type == bp_shlib_event)
2231 delete_breakpoint (b);
2235 /* JIT breakpoints must be explicitly reset after an exec(). */
2236 if (b->type == bp_jit_event)
2238 delete_breakpoint (b);
2242 /* Thread event breakpoints must be set anew after an exec(),
2243 as must overlay event and longjmp master breakpoints. */
2244 if (b->type == bp_thread_event || b->type == bp_overlay_event
2245 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
2247 delete_breakpoint (b);
2251 /* Step-resume breakpoints are meaningless after an exec(). */
2252 if (b->type == bp_step_resume)
2254 delete_breakpoint (b);
2258 /* Longjmp and longjmp-resume breakpoints are also meaningless
2260 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
2262 delete_breakpoint (b);
2266 if (b->type == bp_catchpoint)
2268 /* For now, none of the bp_catchpoint breakpoints need to
2269 do anything at this point. In the future, if some of
2270 the catchpoints need to something, we will need to add
2271 a new method, and call this method from here. */
2275 /* bp_finish is a special case. The only way we ought to be able
2276 to see one of these when an exec() has happened, is if the user
2277 caught a vfork, and then said "finish". Ordinarily a finish just
2278 carries them to the call-site of the current callee, by setting
2279 a temporary bp there and resuming. But in this case, the finish
2280 will carry them entirely through the vfork & exec.
2282 We don't want to allow a bp_finish to remain inserted now. But
2283 we can't safely delete it, 'cause finish_command has a handle to
2284 the bp on a bpstat, and will later want to delete it. There's a
2285 chance (and I've seen it happen) that if we delete the bp_finish
2286 here, that its storage will get reused by the time finish_command
2287 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2288 We really must allow finish_command to delete a bp_finish.
2290 In the absense of a general solution for the "how do we know
2291 it's safe to delete something others may have handles to?"
2292 problem, what we'll do here is just uninsert the bp_finish, and
2293 let finish_command delete it.
2295 (We know the bp_finish is "doomed" in the sense that it's
2296 momentary, and will be deleted as soon as finish_command sees
2297 the inferior stopped. So it doesn't matter that the bp's
2298 address is probably bogus in the new a.out, unlike e.g., the
2299 solib breakpoints.) */
2301 if (b->type == bp_finish)
2306 /* Without a symbolic address, we have little hope of the
2307 pre-exec() address meaning the same thing in the post-exec()
2309 if (b->addr_string == NULL)
2311 delete_breakpoint (b);
2315 /* FIXME what about longjmp breakpoints? Re-create them here? */
2316 create_overlay_event_breakpoint ("_ovly_debug_event");
2317 create_longjmp_master_breakpoint ("longjmp");
2318 create_longjmp_master_breakpoint ("_longjmp");
2319 create_longjmp_master_breakpoint ("siglongjmp");
2320 create_longjmp_master_breakpoint ("_siglongjmp");
2321 create_std_terminate_master_breakpoint ("std::terminate()");
2325 detach_breakpoints (int pid)
2327 struct bp_location *b, **bp_tmp;
2329 struct cleanup *old_chain = save_inferior_ptid ();
2330 struct inferior *inf = current_inferior ();
2332 if (pid == PIDGET (inferior_ptid))
2333 error (_("Cannot detach breakpoints of inferior_ptid"));
2335 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2336 inferior_ptid = pid_to_ptid (pid);
2337 ALL_BP_LOCATIONS (b, bp_tmp)
2339 if (b->pspace != inf->pspace)
2343 val |= remove_breakpoint_1 (b, mark_inserted);
2346 /* Detach single-step breakpoints as well. */
2347 detach_single_step_breakpoints ();
2349 do_cleanups (old_chain);
2353 /* Remove the breakpoint location B from the current address space.
2354 Note that this is used to detach breakpoints from a child fork.
2355 When we get here, the child isn't in the inferior list, and neither
2356 do we have objects to represent its address space --- we should
2357 *not* look at b->pspace->aspace here. */
2360 remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
2364 /* B is never in moribund_locations by our callers. */
2365 gdb_assert (b->owner != NULL);
2367 if (b->owner->enable_state == bp_permanent)
2368 /* Permanent breakpoints cannot be inserted or removed. */
2371 /* The type of none suggests that owner is actually deleted.
2372 This should not ever happen. */
2373 gdb_assert (b->owner->type != bp_none);
2375 if (b->loc_type == bp_loc_software_breakpoint
2376 || b->loc_type == bp_loc_hardware_breakpoint)
2378 /* "Normal" instruction breakpoint: either the standard
2379 trap-instruction bp (bp_breakpoint), or a
2380 bp_hardware_breakpoint. */
2382 /* First check to see if we have to handle an overlay. */
2383 if (overlay_debugging == ovly_off
2384 || b->section == NULL
2385 || !(section_is_overlay (b->section)))
2387 /* No overlay handling: just remove the breakpoint. */
2389 if (b->loc_type == bp_loc_hardware_breakpoint)
2390 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
2392 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
2396 /* This breakpoint is in an overlay section.
2397 Did we set a breakpoint at the LMA? */
2398 if (!overlay_events_enabled)
2400 /* Yes -- overlay event support is not active, so we
2401 should have set a breakpoint at the LMA. Remove it.
2403 /* Ignore any failures: if the LMA is in ROM, we will
2404 have already warned when we failed to insert it. */
2405 if (b->loc_type == bp_loc_hardware_breakpoint)
2406 target_remove_hw_breakpoint (b->gdbarch,
2407 &b->overlay_target_info);
2409 target_remove_breakpoint (b->gdbarch,
2410 &b->overlay_target_info);
2412 /* Did we set a breakpoint at the VMA?
2413 If so, we will have marked the breakpoint 'inserted'. */
2416 /* Yes -- remove it. Previously we did not bother to
2417 remove the breakpoint if the section had been
2418 unmapped, but let's not rely on that being safe. We
2419 don't know what the overlay manager might do. */
2420 if (b->loc_type == bp_loc_hardware_breakpoint)
2421 val = target_remove_hw_breakpoint (b->gdbarch,
2424 /* However, we should remove *software* breakpoints only
2425 if the section is still mapped, or else we overwrite
2426 wrong code with the saved shadow contents. */
2427 else if (section_is_mapped (b->section))
2428 val = target_remove_breakpoint (b->gdbarch,
2435 /* No -- not inserted, so no need to remove. No error. */
2440 /* In some cases, we might not be able to remove a breakpoint
2441 in a shared library that has already been removed, but we
2442 have not yet processed the shlib unload event. */
2443 if (val && solib_name_from_address (b->pspace, b->address))
2448 b->inserted = (is == mark_inserted);
2450 else if (b->loc_type == bp_loc_hardware_watchpoint)
2452 b->inserted = (is == mark_inserted);
2453 val = target_remove_watchpoint (b->address, b->length,
2454 b->watchpoint_type, b->owner->cond_exp);
2456 /* Failure to remove any of the hardware watchpoints comes here. */
2457 if ((is == mark_uninserted) && (b->inserted))
2458 warning (_("Could not remove hardware watchpoint %d."),
2461 else if (b->owner->type == bp_catchpoint
2462 && breakpoint_enabled (b->owner)
2465 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
2467 val = b->owner->ops->remove (b->owner);
2470 b->inserted = (is == mark_inserted);
2477 remove_breakpoint (struct bp_location *b, insertion_state_t is)
2480 struct cleanup *old_chain;
2482 /* B is never in moribund_locations by our callers. */
2483 gdb_assert (b->owner != NULL);
2485 if (b->owner->enable_state == bp_permanent)
2486 /* Permanent breakpoints cannot be inserted or removed. */
2489 /* The type of none suggests that owner is actually deleted.
2490 This should not ever happen. */
2491 gdb_assert (b->owner->type != bp_none);
2493 old_chain = save_current_space_and_thread ();
2495 switch_to_program_space_and_thread (b->pspace);
2497 ret = remove_breakpoint_1 (b, is);
2499 do_cleanups (old_chain);
2503 /* Clear the "inserted" flag in all breakpoints. */
2506 mark_breakpoints_out (void)
2508 struct bp_location *bpt, **bptp_tmp;
2510 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2511 if (bpt->pspace == current_program_space)
2515 /* Clear the "inserted" flag in all breakpoints and delete any
2516 breakpoints which should go away between runs of the program.
2518 Plus other such housekeeping that has to be done for breakpoints
2521 Note: this function gets called at the end of a run (by
2522 generic_mourn_inferior) and when a run begins (by
2523 init_wait_for_inferior). */
2528 breakpoint_init_inferior (enum inf_context context)
2530 struct breakpoint *b, *temp;
2531 struct bp_location *bpt, **bptp_tmp;
2533 struct program_space *pspace = current_program_space;
2535 /* If breakpoint locations are shared across processes, then there's
2537 if (gdbarch_has_global_breakpoints (target_gdbarch))
2540 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2542 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2543 if (bpt->pspace == pspace
2544 && bpt->owner->enable_state != bp_permanent)
2548 ALL_BREAKPOINTS_SAFE (b, temp)
2550 if (b->loc && b->loc->pspace != pspace)
2557 /* If the call dummy breakpoint is at the entry point it will
2558 cause problems when the inferior is rerun, so we better get
2561 case bp_watchpoint_scope:
2563 /* Also get rid of scope breakpoints. */
2565 case bp_shlib_event:
2567 /* Also remove solib event breakpoints. Their addresses may
2568 have changed since the last time we ran the program.
2569 Actually we may now be debugging against different target;
2570 and so the solib backend that installed this breakpoint may
2571 not be used in by the target. E.g.,
2573 (gdb) file prog-linux
2574 (gdb) run # native linux target
2577 (gdb) file prog-win.exe
2578 (gdb) tar rem :9999 # remote Windows gdbserver.
2581 delete_breakpoint (b);
2585 case bp_hardware_watchpoint:
2586 case bp_read_watchpoint:
2587 case bp_access_watchpoint:
2589 /* Likewise for watchpoints on local expressions. */
2590 if (b->exp_valid_block != NULL)
2591 delete_breakpoint (b);
2592 else if (context == inf_starting)
2594 /* Reset val field to force reread of starting value
2595 in insert_breakpoints. */
2597 value_free (b->val);
2607 /* Get rid of the moribund locations. */
2608 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
2609 free_bp_location (bpt);
2610 VEC_free (bp_location_p, moribund_locations);
2613 /* These functions concern about actual breakpoints inserted in the
2614 target --- to e.g. check if we need to do decr_pc adjustment or if
2615 we need to hop over the bkpt --- so we check for address space
2616 match, not program space. */
2618 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2619 exists at PC. It returns ordinary_breakpoint_here if it's an
2620 ordinary breakpoint, or permanent_breakpoint_here if it's a
2621 permanent breakpoint.
2622 - When continuing from a location with an ordinary breakpoint, we
2623 actually single step once before calling insert_breakpoints.
2624 - When continuing from a localion with a permanent breakpoint, we
2625 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2626 the target, to advance the PC past the breakpoint. */
2628 enum breakpoint_here
2629 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2631 struct bp_location *bpt, **bptp_tmp;
2632 int any_breakpoint_here = 0;
2634 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2636 if (bpt->loc_type != bp_loc_software_breakpoint
2637 && bpt->loc_type != bp_loc_hardware_breakpoint)
2640 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2641 if ((breakpoint_enabled (bpt->owner)
2642 || bpt->owner->enable_state == bp_permanent)
2643 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2646 if (overlay_debugging
2647 && section_is_overlay (bpt->section)
2648 && !section_is_mapped (bpt->section))
2649 continue; /* unmapped overlay -- can't be a match */
2650 else if (bpt->owner->enable_state == bp_permanent)
2651 return permanent_breakpoint_here;
2653 any_breakpoint_here = 1;
2657 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2660 /* Return true if there's a moribund breakpoint at PC. */
2663 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2665 struct bp_location *loc;
2668 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2669 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2676 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2677 inserted using regular breakpoint_chain / bp_location array mechanism.
2678 This does not check for single-step breakpoints, which are
2679 inserted and removed using direct target manipulation. */
2682 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2684 struct bp_location *bpt, **bptp_tmp;
2686 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2688 if (bpt->loc_type != bp_loc_software_breakpoint
2689 && bpt->loc_type != bp_loc_hardware_breakpoint)
2693 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2696 if (overlay_debugging
2697 && section_is_overlay (bpt->section)
2698 && !section_is_mapped (bpt->section))
2699 continue; /* unmapped overlay -- can't be a match */
2707 /* Returns non-zero iff there's either regular breakpoint
2708 or a single step breakpoint inserted at PC. */
2711 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2713 if (regular_breakpoint_inserted_here_p (aspace, pc))
2716 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2722 /* This function returns non-zero iff there is a software breakpoint
2726 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2728 struct bp_location *bpt, **bptp_tmp;
2730 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2732 if (bpt->loc_type != bp_loc_software_breakpoint)
2736 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2739 if (overlay_debugging
2740 && section_is_overlay (bpt->section)
2741 && !section_is_mapped (bpt->section))
2742 continue; /* unmapped overlay -- can't be a match */
2748 /* Also check for software single-step breakpoints. */
2749 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2756 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2757 CORE_ADDR addr, ULONGEST len)
2759 struct breakpoint *bpt;
2761 ALL_BREAKPOINTS (bpt)
2763 struct bp_location *loc;
2765 if (bpt->type != bp_hardware_watchpoint
2766 && bpt->type != bp_access_watchpoint)
2769 if (!breakpoint_enabled (bpt))
2772 for (loc = bpt->loc; loc; loc = loc->next)
2773 if (loc->pspace->aspace == aspace && loc->inserted)
2777 /* Check for intersection. */
2778 l = max (loc->address, addr);
2779 h = min (loc->address + loc->length, addr + len);
2787 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2788 PC is valid for process/thread PTID. */
2791 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2794 struct bp_location *bpt, **bptp_tmp;
2795 /* The thread and task IDs associated to PTID, computed lazily. */
2799 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2801 if (bpt->loc_type != bp_loc_software_breakpoint
2802 && bpt->loc_type != bp_loc_hardware_breakpoint)
2805 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2806 if (!breakpoint_enabled (bpt->owner)
2807 && bpt->owner->enable_state != bp_permanent)
2810 if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2814 if (bpt->owner->thread != -1)
2816 /* This is a thread-specific breakpoint. Check that ptid
2817 matches that thread. If thread hasn't been computed yet,
2818 it is now time to do so. */
2820 thread = pid_to_thread_id (ptid);
2821 if (bpt->owner->thread != thread)
2825 if (bpt->owner->task != 0)
2827 /* This is a task-specific breakpoint. Check that ptid
2828 matches that task. If task hasn't been computed yet,
2829 it is now time to do so. */
2831 task = ada_get_task_number (ptid);
2832 if (bpt->owner->task != task)
2836 if (overlay_debugging
2837 && section_is_overlay (bpt->section)
2838 && !section_is_mapped (bpt->section))
2839 continue; /* unmapped overlay -- can't be a match */
2848 /* bpstat stuff. External routines' interfaces are documented
2852 ep_is_catchpoint (struct breakpoint *ep)
2854 return (ep->type == bp_catchpoint);
2858 bpstat_free (bpstat bs)
2860 if (bs->old_val != NULL)
2861 value_free (bs->old_val);
2862 decref_counted_command_line (&bs->commands);
2866 /* Clear a bpstat so that it says we are not at any breakpoint.
2867 Also free any storage that is part of a bpstat. */
2870 bpstat_clear (bpstat *bsp)
2887 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2888 is part of the bpstat is copied as well. */
2891 bpstat_copy (bpstat bs)
2895 bpstat retval = NULL;
2900 for (; bs != NULL; bs = bs->next)
2902 tmp = (bpstat) xmalloc (sizeof (*tmp));
2903 memcpy (tmp, bs, sizeof (*tmp));
2904 incref_counted_command_line (tmp->commands);
2905 if (bs->old_val != NULL)
2907 tmp->old_val = value_copy (bs->old_val);
2908 release_value (tmp->old_val);
2912 /* This is the first thing in the chain. */
2922 /* Find the bpstat associated with this breakpoint */
2925 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2930 for (; bsp != NULL; bsp = bsp->next)
2932 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2938 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2939 at. *BSP upon return is a bpstat which points to the remaining
2940 breakpoints stopped at (but which is not guaranteed to be good for
2941 anything but further calls to bpstat_num).
2942 Return 0 if passed a bpstat which does not indicate any breakpoints.
2943 Return -1 if stopped at a breakpoint that has been deleted since
2945 Return 1 otherwise. */
2948 bpstat_num (bpstat *bsp, int *num)
2950 struct breakpoint *b;
2953 return 0; /* No more breakpoint values */
2955 /* We assume we'll never have several bpstats that
2956 correspond to a single breakpoint -- otherwise,
2957 this function might return the same number more
2958 than once and this will look ugly. */
2959 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2960 *bsp = (*bsp)->next;
2962 return -1; /* breakpoint that's been deleted since */
2964 *num = b->number; /* We have its number */
2968 /* Modify BS so that the actions will not be performed. */
2971 bpstat_clear_actions (bpstat bs)
2973 for (; bs != NULL; bs = bs->next)
2975 decref_counted_command_line (&bs->commands);
2976 bs->commands_left = NULL;
2977 if (bs->old_val != NULL)
2979 value_free (bs->old_val);
2985 /* Called when a command is about to proceed the inferior. */
2988 breakpoint_about_to_proceed (void)
2990 if (!ptid_equal (inferior_ptid, null_ptid))
2992 struct thread_info *tp = inferior_thread ();
2994 /* Allow inferior function calls in breakpoint commands to not
2995 interrupt the command list. When the call finishes
2996 successfully, the inferior will be standing at the same
2997 breakpoint as if nothing happened. */
3002 breakpoint_proceeded = 1;
3005 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3007 cleanup_executing_breakpoints (void *ignore)
3009 executing_breakpoint_commands = 0;
3012 /* Execute all the commands associated with all the breakpoints at this
3013 location. Any of these commands could cause the process to proceed
3014 beyond this point, etc. We look out for such changes by checking
3015 the global "breakpoint_proceeded" after each command.
3017 Returns true if a breakpoint command resumed the inferior. In that
3018 case, it is the caller's responsibility to recall it again with the
3019 bpstat of the current thread. */
3022 bpstat_do_actions_1 (bpstat *bsp)
3025 struct cleanup *old_chain;
3028 /* Avoid endless recursion if a `source' command is contained
3030 if (executing_breakpoint_commands)
3033 executing_breakpoint_commands = 1;
3034 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3036 /* This pointer will iterate over the list of bpstat's. */
3039 breakpoint_proceeded = 0;
3040 for (; bs != NULL; bs = bs->next)
3042 struct counted_command_line *ccmd;
3043 struct command_line *cmd;
3044 struct cleanup *this_cmd_tree_chain;
3046 /* Take ownership of the BSP's command tree, if it has one.
3048 The command tree could legitimately contain commands like
3049 'step' and 'next', which call clear_proceed_status, which
3050 frees stop_bpstat's command tree. To make sure this doesn't
3051 free the tree we're executing out from under us, we need to
3052 take ownership of the tree ourselves. Since a given bpstat's
3053 commands are only executed once, we don't need to copy it; we
3054 can clear the pointer in the bpstat, and make sure we free
3055 the tree when we're done. */
3056 ccmd = bs->commands;
3057 bs->commands = NULL;
3059 = make_cleanup_decref_counted_command_line (&ccmd);
3060 cmd = bs->commands_left;
3061 bs->commands_left = NULL;
3065 execute_control_command (cmd);
3067 if (breakpoint_proceeded)
3073 /* We can free this command tree now. */
3074 do_cleanups (this_cmd_tree_chain);
3076 if (breakpoint_proceeded)
3078 if (target_can_async_p ())
3079 /* If we are in async mode, then the target might be still
3080 running, not stopped at any breakpoint, so nothing for
3081 us to do here -- just return to the event loop. */
3084 /* In sync mode, when execute_control_command returns
3085 we're already standing on the next breakpoint.
3086 Breakpoint commands for that stop were not run, since
3087 execute_command does not run breakpoint commands --
3088 only command_line_handler does, but that one is not
3089 involved in execution of breakpoint commands. So, we
3090 can now execute breakpoint commands. It should be
3091 noted that making execute_command do bpstat actions is
3092 not an option -- in this case we'll have recursive
3093 invocation of bpstat for each breakpoint with a
3094 command, and can easily blow up GDB stack. Instead, we
3095 return true, which will trigger the caller to recall us
3096 with the new stop_bpstat. */
3101 do_cleanups (old_chain);
3106 bpstat_do_actions (void)
3108 /* Do any commands attached to breakpoint we are stopped at. */
3109 while (!ptid_equal (inferior_ptid, null_ptid)
3110 && target_has_execution
3111 && !is_exited (inferior_ptid)
3112 && !is_executing (inferior_ptid))
3113 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3114 and only return when it is stopped at the next breakpoint, we
3115 keep doing breakpoint actions until it returns false to
3116 indicate the inferior was not resumed. */
3117 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
3121 /* Print out the (old or new) value associated with a watchpoint. */
3124 watchpoint_value_print (struct value *val, struct ui_file *stream)
3127 fprintf_unfiltered (stream, _("<unreadable>"));
3130 struct value_print_options opts;
3131 get_user_print_options (&opts);
3132 value_print (val, stream, &opts);
3136 /* This is the normal print function for a bpstat. In the future,
3137 much of this logic could (should?) be moved to bpstat_stop_status,
3138 by having it set different print_it values.
3140 Current scheme: When we stop, bpstat_print() is called. It loops
3141 through the bpstat list of things causing this stop, calling the
3142 print_bp_stop_message function on each one. The behavior of the
3143 print_bp_stop_message function depends on the print_it field of
3144 bpstat. If such field so indicates, call this function here.
3146 Return values from this routine (ultimately used by bpstat_print()
3147 and normal_stop() to decide what to do):
3148 PRINT_NOTHING: Means we already printed all we needed to print,
3149 don't print anything else.
3150 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3151 that something to be followed by a location.
3152 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3153 that something to be followed by a location.
3154 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3157 static enum print_stop_action
3158 print_it_typical (bpstat bs)
3160 struct cleanup *old_chain;
3161 struct breakpoint *b;
3162 const struct bp_location *bl;
3163 struct ui_stream *stb;
3165 enum print_stop_action result;
3167 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3168 which has since been deleted. */
3169 if (bs->breakpoint_at == NULL)
3170 return PRINT_UNKNOWN;
3171 bl = bs->breakpoint_at;
3173 /* bl->owner can be NULL if it was a momentary breakpoint
3174 which has since been placed into moribund_locations. */
3175 if (bl->owner == NULL)
3176 return PRINT_UNKNOWN;
3179 stb = ui_out_stream_new (uiout);
3180 old_chain = make_cleanup_ui_out_stream_delete (stb);
3185 case bp_hardware_breakpoint:
3186 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
3187 if (bl->address != bl->requested_address)
3188 breakpoint_adjustment_warning (bl->requested_address,
3191 annotate_breakpoint (b->number);
3193 ui_out_text (uiout, "\nTemporary breakpoint ");
3195 ui_out_text (uiout, "\nBreakpoint ");
3196 if (ui_out_is_mi_like_p (uiout))
3198 ui_out_field_string (uiout, "reason",
3199 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3200 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3202 ui_out_field_int (uiout, "bkptno", b->number);
3203 ui_out_text (uiout, ", ");
3204 result = PRINT_SRC_AND_LOC;
3207 case bp_shlib_event:
3208 /* Did we stop because the user set the stop_on_solib_events
3209 variable? (If so, we report this as a generic, "Stopped due
3210 to shlib event" message.) */
3211 printf_filtered (_("Stopped due to shared library event\n"));
3212 result = PRINT_NOTHING;
3215 case bp_thread_event:
3216 /* Not sure how we will get here.
3217 GDB should not stop for these breakpoints. */
3218 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3219 result = PRINT_NOTHING;
3222 case bp_overlay_event:
3223 /* By analogy with the thread event, GDB should not stop for these. */
3224 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3225 result = PRINT_NOTHING;
3228 case bp_longjmp_master:
3229 /* These should never be enabled. */
3230 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3231 result = PRINT_NOTHING;
3234 case bp_std_terminate_master:
3235 /* These should never be enabled. */
3236 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3237 result = PRINT_NOTHING;
3241 case bp_hardware_watchpoint:
3242 annotate_watchpoint (b->number);
3243 if (ui_out_is_mi_like_p (uiout))
3246 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3248 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3249 ui_out_text (uiout, "\nOld value = ");
3250 watchpoint_value_print (bs->old_val, stb->stream);
3251 ui_out_field_stream (uiout, "old", stb);
3252 ui_out_text (uiout, "\nNew value = ");
3253 watchpoint_value_print (b->val, stb->stream);
3254 ui_out_field_stream (uiout, "new", stb);
3255 ui_out_text (uiout, "\n");
3256 /* More than one watchpoint may have been triggered. */
3257 result = PRINT_UNKNOWN;
3260 case bp_read_watchpoint:
3261 if (ui_out_is_mi_like_p (uiout))
3264 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3266 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3267 ui_out_text (uiout, "\nValue = ");
3268 watchpoint_value_print (b->val, stb->stream);
3269 ui_out_field_stream (uiout, "value", stb);
3270 ui_out_text (uiout, "\n");
3271 result = PRINT_UNKNOWN;
3274 case bp_access_watchpoint:
3275 if (bs->old_val != NULL)
3277 annotate_watchpoint (b->number);
3278 if (ui_out_is_mi_like_p (uiout))
3281 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3283 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3284 ui_out_text (uiout, "\nOld value = ");
3285 watchpoint_value_print (bs->old_val, stb->stream);
3286 ui_out_field_stream (uiout, "old", stb);
3287 ui_out_text (uiout, "\nNew value = ");
3292 if (ui_out_is_mi_like_p (uiout))
3295 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3296 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3297 ui_out_text (uiout, "\nValue = ");
3299 watchpoint_value_print (b->val, stb->stream);
3300 ui_out_field_stream (uiout, "new", stb);
3301 ui_out_text (uiout, "\n");
3302 result = PRINT_UNKNOWN;
3305 /* Fall through, we don't deal with these types of breakpoints
3309 if (ui_out_is_mi_like_p (uiout))
3312 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3313 result = PRINT_UNKNOWN;
3317 if (ui_out_is_mi_like_p (uiout))
3320 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3321 result = PRINT_UNKNOWN;
3326 case bp_longjmp_resume:
3327 case bp_step_resume:
3328 case bp_watchpoint_scope:
3330 case bp_std_terminate:
3332 case bp_fast_tracepoint:
3335 result = PRINT_UNKNOWN;
3339 do_cleanups (old_chain);
3343 /* Generic routine for printing messages indicating why we
3344 stopped. The behavior of this function depends on the value
3345 'print_it' in the bpstat structure. Under some circumstances we
3346 may decide not to print anything here and delegate the task to
3349 static enum print_stop_action
3350 print_bp_stop_message (bpstat bs)
3352 switch (bs->print_it)
3355 /* Nothing should be printed for this bpstat entry. */
3356 return PRINT_UNKNOWN;
3360 /* We still want to print the frame, but we already printed the
3361 relevant messages. */
3362 return PRINT_SRC_AND_LOC;
3365 case print_it_normal:
3367 const struct bp_location *bl = bs->breakpoint_at;
3368 struct breakpoint *b = bl ? bl->owner : NULL;
3370 /* Normal case. Call the breakpoint's print_it method, or
3371 print_it_typical. */
3372 /* FIXME: how breakpoint can ever be NULL here? */
3373 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3374 return b->ops->print_it (b);
3376 return print_it_typical (bs);
3381 internal_error (__FILE__, __LINE__,
3382 _("print_bp_stop_message: unrecognized enum value"));
3387 /* Print a message indicating what happened. This is called from
3388 normal_stop(). The input to this routine is the head of the bpstat
3389 list - a list of the eventpoints that caused this stop. This
3390 routine calls the generic print routine for printing a message
3391 about reasons for stopping. This will print (for example) the
3392 "Breakpoint n," part of the output. The return value of this
3395 PRINT_UNKNOWN: Means we printed nothing
3396 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3397 code to print the location. An example is
3398 "Breakpoint 1, " which should be followed by
3400 PRINT_SRC_ONLY: Means we printed something, but there is no need
3401 to also print the location part of the message.
3402 An example is the catch/throw messages, which
3403 don't require a location appended to the end.
3404 PRINT_NOTHING: We have done some printing and we don't need any
3405 further info to be printed.*/
3407 enum print_stop_action
3408 bpstat_print (bpstat bs)
3412 /* Maybe another breakpoint in the chain caused us to stop.
3413 (Currently all watchpoints go on the bpstat whether hit or not.
3414 That probably could (should) be changed, provided care is taken
3415 with respect to bpstat_explains_signal). */
3416 for (; bs; bs = bs->next)
3418 val = print_bp_stop_message (bs);
3419 if (val == PRINT_SRC_ONLY
3420 || val == PRINT_SRC_AND_LOC
3421 || val == PRINT_NOTHING)
3425 /* We reached the end of the chain, or we got a null BS to start
3426 with and nothing was printed. */
3427 return PRINT_UNKNOWN;
3430 /* Evaluate the expression EXP and return 1 if value is zero.
3431 This is used inside a catch_errors to evaluate the breakpoint condition.
3432 The argument is a "struct expression *" that has been cast to char * to
3433 make it pass through catch_errors. */
3436 breakpoint_cond_eval (void *exp)
3438 struct value *mark = value_mark ();
3439 int i = !value_true (evaluate_expression ((struct expression *) exp));
3441 value_free_to_mark (mark);
3445 /* Allocate a new bpstat and chain it to the current one. */
3448 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
3452 bs = (bpstat) xmalloc (sizeof (*bs));
3454 bs->breakpoint_at = bl;
3455 /* If the condition is false, etc., don't do the commands. */
3456 bs->commands = NULL;
3457 bs->commands_left = NULL;
3459 bs->print_it = print_it_normal;
3463 /* The target has stopped with waitstatus WS. Check if any hardware
3464 watchpoints have triggered, according to the target. */
3467 watchpoints_triggered (struct target_waitstatus *ws)
3469 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3471 struct breakpoint *b;
3473 if (!stopped_by_watchpoint)
3475 /* We were not stopped by a watchpoint. Mark all watchpoints
3476 as not triggered. */
3478 if (is_hardware_watchpoint (b))
3479 b->watchpoint_triggered = watch_triggered_no;
3484 if (!target_stopped_data_address (¤t_target, &addr))
3486 /* We were stopped by a watchpoint, but we don't know where.
3487 Mark all watchpoints as unknown. */
3489 if (is_hardware_watchpoint (b))
3490 b->watchpoint_triggered = watch_triggered_unknown;
3492 return stopped_by_watchpoint;
3495 /* The target could report the data address. Mark watchpoints
3496 affected by this data address as triggered, and all others as not
3500 if (is_hardware_watchpoint (b))
3502 struct bp_location *loc;
3504 b->watchpoint_triggered = watch_triggered_no;
3505 for (loc = b->loc; loc; loc = loc->next)
3506 /* Exact match not required. Within range is
3508 if (target_watchpoint_addr_within_range (¤t_target,
3512 b->watchpoint_triggered = watch_triggered_yes;
3520 /* Possible return values for watchpoint_check (this can't be an enum
3521 because of check_errors). */
3522 /* The watchpoint has been deleted. */
3523 #define WP_DELETED 1
3524 /* The value has changed. */
3525 #define WP_VALUE_CHANGED 2
3526 /* The value has not changed. */
3527 #define WP_VALUE_NOT_CHANGED 3
3528 /* Ignore this watchpoint, no matter if the value changed or not. */
3531 #define BP_TEMPFLAG 1
3532 #define BP_HARDWAREFLAG 2
3534 /* Evaluate watchpoint condition expression and check if its value changed.
3536 P should be a pointer to struct bpstat, but is defined as a void *
3537 in order for this function to be usable with catch_errors. */
3540 watchpoint_check (void *p)
3542 bpstat bs = (bpstat) p;
3543 struct breakpoint *b;
3544 struct frame_info *fr;
3545 int within_current_scope;
3547 /* BS is built for existing struct breakpoint. */
3548 gdb_assert (bs->breakpoint_at != NULL);
3549 gdb_assert (bs->breakpoint_at->owner != NULL);
3550 b = bs->breakpoint_at->owner;
3552 /* If this is a local watchpoint, we only want to check if the
3553 watchpoint frame is in scope if the current thread is the thread
3554 that was used to create the watchpoint. */
3555 if (!watchpoint_in_thread_scope (b))
3558 if (b->exp_valid_block == NULL)
3559 within_current_scope = 1;
3562 struct frame_info *frame = get_current_frame ();
3563 struct gdbarch *frame_arch = get_frame_arch (frame);
3564 CORE_ADDR frame_pc = get_frame_pc (frame);
3566 /* in_function_epilogue_p() returns a non-zero value if we're still
3567 in the function but the stack frame has already been invalidated.
3568 Since we can't rely on the values of local variables after the
3569 stack has been destroyed, we are treating the watchpoint in that
3570 state as `not changed' without further checking. Don't mark
3571 watchpoints as changed if the current frame is in an epilogue -
3572 even if they are in some other frame, our view of the stack
3573 is likely to be wrong and frame_find_by_id could error out. */
3574 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3577 fr = frame_find_by_id (b->watchpoint_frame);
3578 within_current_scope = (fr != NULL);
3580 /* If we've gotten confused in the unwinder, we might have
3581 returned a frame that can't describe this variable. */
3582 if (within_current_scope)
3584 struct symbol *function;
3586 function = get_frame_function (fr);
3587 if (function == NULL
3588 || !contained_in (b->exp_valid_block,
3589 SYMBOL_BLOCK_VALUE (function)))
3590 within_current_scope = 0;
3593 if (within_current_scope)
3594 /* If we end up stopping, the current frame will get selected
3595 in normal_stop. So this call to select_frame won't affect
3600 if (within_current_scope)
3602 /* We use value_{,free_to_}mark because it could be a
3603 *long* time before we return to the command level and
3604 call free_all_values. We can't call free_all_values because
3605 we might be in the middle of evaluating a function call. */
3608 struct value *mark = value_mark ();
3609 struct value *new_val;
3611 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
3613 /* We use value_equal_contents instead of value_equal because the latter
3614 coerces an array to a pointer, thus comparing just the address of the
3615 array instead of its contents. This is not what we want. */
3616 if ((b->val != NULL) != (new_val != NULL)
3617 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3619 if (new_val != NULL)
3621 release_value (new_val);
3622 value_free_to_mark (mark);
3624 bs->old_val = b->val;
3627 return WP_VALUE_CHANGED;
3631 /* Nothing changed. */
3632 value_free_to_mark (mark);
3633 return WP_VALUE_NOT_CHANGED;
3638 /* This seems like the only logical thing to do because
3639 if we temporarily ignored the watchpoint, then when
3640 we reenter the block in which it is valid it contains
3641 garbage (in the case of a function, it may have two
3642 garbage values, one before and one after the prologue).
3643 So we can't even detect the first assignment to it and
3644 watch after that (since the garbage may or may not equal
3645 the first value assigned). */
3646 /* We print all the stop information in print_it_typical(), but
3647 in this case, by the time we call print_it_typical() this bp
3648 will be deleted already. So we have no choice but print the
3649 information here. */
3650 if (ui_out_is_mi_like_p (uiout))
3652 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3653 ui_out_text (uiout, "\nWatchpoint ");
3654 ui_out_field_int (uiout, "wpnum", b->number);
3655 ui_out_text (uiout, " deleted because the program has left the block in\n\
3656 which its expression is valid.\n");
3658 if (b->related_breakpoint)
3660 b->related_breakpoint->disposition = disp_del_at_next_stop;
3661 b->related_breakpoint->related_breakpoint = NULL;
3662 b->related_breakpoint = NULL;
3664 b->disposition = disp_del_at_next_stop;
3670 /* Return true if it looks like target has stopped due to hitting
3671 breakpoint location BL. This function does not check if we
3672 should stop, only if BL explains the stop. */
3674 bpstat_check_location (const struct bp_location *bl,
3675 struct address_space *aspace, CORE_ADDR bp_addr)
3677 struct breakpoint *b = bl->owner;
3679 /* BL is from existing struct breakpoint. */
3680 gdb_assert (b != NULL);
3682 /* By definition, the inferior does not report stops at
3684 if (is_tracepoint (b))
3687 if (!is_watchpoint (b)
3688 && b->type != bp_hardware_breakpoint
3689 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3691 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3694 if (overlay_debugging /* unmapped overlay section */
3695 && section_is_overlay (bl->section)
3696 && !section_is_mapped (bl->section))
3700 /* Continuable hardware watchpoints are treated as non-existent if the
3701 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3702 some data address). Otherwise gdb won't stop on a break instruction
3703 in the code (not from a breakpoint) when a hardware watchpoint has
3704 been defined. Also skip watchpoints which we know did not trigger
3705 (did not match the data address). */
3707 if (is_hardware_watchpoint (b)
3708 && b->watchpoint_triggered == watch_triggered_no)
3711 if (b->type == bp_hardware_breakpoint)
3713 if (bl->address != bp_addr)
3715 if (overlay_debugging /* unmapped overlay section */
3716 && section_is_overlay (bl->section)
3717 && !section_is_mapped (bl->section))
3721 if (b->type == bp_catchpoint)
3723 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3724 if (!b->ops->breakpoint_hit (b))
3731 /* If BS refers to a watchpoint, determine if the watched values
3732 has actually changed, and we should stop. If not, set BS->stop
3735 bpstat_check_watchpoint (bpstat bs)
3737 const struct bp_location *bl;
3738 struct breakpoint *b;
3740 /* BS is built for existing struct breakpoint. */
3741 bl = bs->breakpoint_at;
3742 gdb_assert (bl != NULL);
3744 gdb_assert (b != NULL);
3746 if (is_watchpoint (b))
3748 int must_check_value = 0;
3750 if (b->type == bp_watchpoint)
3751 /* For a software watchpoint, we must always check the
3753 must_check_value = 1;
3754 else if (b->watchpoint_triggered == watch_triggered_yes)
3755 /* We have a hardware watchpoint (read, write, or access)
3756 and the target earlier reported an address watched by
3758 must_check_value = 1;
3759 else if (b->watchpoint_triggered == watch_triggered_unknown
3760 && b->type == bp_hardware_watchpoint)
3761 /* We were stopped by a hardware watchpoint, but the target could
3762 not report the data address. We must check the watchpoint's
3763 value. Access and read watchpoints are out of luck; without
3764 a data address, we can't figure it out. */
3765 must_check_value = 1;
3767 if (must_check_value)
3769 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3771 struct cleanup *cleanups = make_cleanup (xfree, message);
3772 int e = catch_errors (watchpoint_check, bs, message,
3774 do_cleanups (cleanups);
3778 /* We've already printed what needs to be printed. */
3779 bs->print_it = print_it_done;
3783 bs->print_it = print_it_noop;
3786 case WP_VALUE_CHANGED:
3787 if (b->type == bp_read_watchpoint)
3789 /* There are two cases to consider here:
3791 1. we're watching the triggered memory for reads.
3792 In that case, trust the target, and always report
3793 the watchpoint hit to the user. Even though
3794 reads don't cause value changes, the value may
3795 have changed since the last time it was read, and
3796 since we're not trapping writes, we will not see
3797 those, and as such we should ignore our notion of
3800 2. we're watching the triggered memory for both
3801 reads and writes. There are two ways this may
3804 2.1. this is a target that can't break on data
3805 reads only, but can break on accesses (reads or
3806 writes), such as e.g., x86. We detect this case
3807 at the time we try to insert read watchpoints.
3809 2.2. otherwise, the target supports read
3810 watchpoints, but, the user set an access or write
3811 watchpoint watching the same memory as this read
3814 If we're watching memory writes as well as reads,
3815 ignore watchpoint hits when we find that the
3816 value hasn't changed, as reads don't cause
3817 changes. This still gives false positives when
3818 the program writes the same value to memory as
3819 what there was already in memory (we will confuse
3820 it for a read), but it's much better than
3823 int other_write_watchpoint = 0;
3825 if (bl->watchpoint_type == hw_read)
3827 struct breakpoint *other_b;
3829 ALL_BREAKPOINTS (other_b)
3830 if ((other_b->type == bp_hardware_watchpoint
3831 || other_b->type == bp_access_watchpoint)
3832 && (other_b->watchpoint_triggered
3833 == watch_triggered_yes))
3835 other_write_watchpoint = 1;
3840 if (other_write_watchpoint
3841 || bl->watchpoint_type == hw_access)
3843 /* We're watching the same memory for writes,
3844 and the value changed since the last time we
3845 updated it, so this trap must be for a write.
3847 bs->print_it = print_it_noop;
3852 case WP_VALUE_NOT_CHANGED:
3853 if (b->type == bp_hardware_watchpoint
3854 || b->type == bp_watchpoint)
3856 /* Don't stop: write watchpoints shouldn't fire if
3857 the value hasn't changed. */
3858 bs->print_it = print_it_noop;
3866 /* Error from catch_errors. */
3867 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3868 if (b->related_breakpoint)
3869 b->related_breakpoint->disposition = disp_del_at_next_stop;
3870 b->disposition = disp_del_at_next_stop;
3871 /* We've already printed what needs to be printed. */
3872 bs->print_it = print_it_done;
3876 else /* must_check_value == 0 */
3878 /* This is a case where some watchpoint(s) triggered, but
3879 not at the address of this watchpoint, or else no
3880 watchpoint triggered after all. So don't print
3881 anything for this watchpoint. */
3882 bs->print_it = print_it_noop;
3889 /* Check conditions (condition proper, frame, thread and ignore count)
3890 of breakpoint referred to by BS. If we should not stop for this
3891 breakpoint, set BS->stop to 0. */
3893 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3895 int thread_id = pid_to_thread_id (ptid);
3896 const struct bp_location *bl;
3897 struct breakpoint *b;
3899 /* BS is built for existing struct breakpoint. */
3900 bl = bs->breakpoint_at;
3901 gdb_assert (bl != NULL);
3903 gdb_assert (b != NULL);
3905 if (frame_id_p (b->frame_id)
3906 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3910 int value_is_zero = 0;
3911 struct expression *cond;
3913 /* If this is a scope breakpoint, mark the associated
3914 watchpoint as triggered so that we will handle the
3915 out-of-scope event. We'll get to the watchpoint next
3917 if (b->type == bp_watchpoint_scope)
3918 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3920 if (is_watchpoint (b))
3925 if (cond && bl->owner->disposition != disp_del_at_next_stop)
3927 int within_current_scope = 1;
3929 /* We use value_mark and value_free_to_mark because it could
3930 be a long time before we return to the command level and
3931 call free_all_values. We can't call free_all_values
3932 because we might be in the middle of evaluating a
3934 struct value *mark = value_mark ();
3936 /* Need to select the frame, with all that implies so that
3937 the conditions will have the right context. Because we
3938 use the frame, we will not see an inlined function's
3939 variables when we arrive at a breakpoint at the start
3940 of the inlined function; the current frame will be the
3942 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
3943 select_frame (get_current_frame ());
3946 struct frame_info *frame;
3948 /* For local watchpoint expressions, which particular
3949 instance of a local is being watched matters, so we
3950 keep track of the frame to evaluate the expression
3951 in. To evaluate the condition however, it doesn't
3952 really matter which instantiation of the function
3953 where the condition makes sense triggers the
3954 watchpoint. This allows an expression like "watch
3955 global if q > 10" set in `func', catch writes to
3956 global on all threads that call `func', or catch
3957 writes on all recursive calls of `func' by a single
3958 thread. We simply always evaluate the condition in
3959 the innermost frame that's executing where it makes
3960 sense to evaluate the condition. It seems
3962 frame = block_innermost_frame (b->cond_exp_valid_block);
3964 select_frame (frame);
3966 within_current_scope = 0;
3968 if (within_current_scope)
3970 = catch_errors (breakpoint_cond_eval, cond,
3971 "Error in testing breakpoint condition:\n",
3975 warning (_("Watchpoint condition cannot be tested "
3976 "in the current scope"));
3977 /* If we failed to set the right context for this
3978 watchpoint, unconditionally report it. */
3981 /* FIXME-someday, should give breakpoint # */
3982 value_free_to_mark (mark);
3985 if (cond && value_is_zero)
3989 else if (b->thread != -1 && b->thread != thread_id)
3993 else if (b->ignore_count > 0)
3996 annotate_ignore_count_change ();
3998 /* Increase the hit count even though we don't
4006 /* Get a bpstat associated with having just stopped at address
4007 BP_ADDR in thread PTID.
4009 Determine whether we stopped at a breakpoint, etc, or whether we
4010 don't understand this stop. Result is a chain of bpstat's such that:
4012 if we don't understand the stop, the result is a null pointer.
4014 if we understand why we stopped, the result is not null.
4016 Each element of the chain refers to a particular breakpoint or
4017 watchpoint at which we have stopped. (We may have stopped for
4018 several reasons concurrently.)
4020 Each element of the chain has valid next, breakpoint_at,
4021 commands, FIXME??? fields. */
4024 bpstat_stop_status (struct address_space *aspace,
4025 CORE_ADDR bp_addr, ptid_t ptid)
4027 struct breakpoint *b = NULL;
4028 struct bp_location *bl;
4029 struct bp_location *loc;
4030 /* Root of the chain of bpstat's */
4031 struct bpstats root_bs[1];
4032 /* Pointer to the last thing in the chain currently. */
4033 bpstat bs = root_bs;
4035 int need_remove_insert;
4037 /* ALL_BP_LOCATIONS iteration would break across
4038 update_global_location_list possibly executed by
4039 bpstat_check_breakpoint_conditions's inferior call. */
4043 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4046 for (bl = b->loc; bl != NULL; bl = bl->next)
4048 /* For hardware watchpoints, we look only at the first location.
4049 The watchpoint_check function will work on the entire expression,
4050 not the individual locations. For read watchpoints, the
4051 watchpoints_triggered function has checked all locations
4053 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4056 if (bl->shlib_disabled)
4059 if (!bpstat_check_location (bl, aspace, bp_addr))
4062 /* Come here if it's a watchpoint, or if the break address matches */
4064 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
4066 /* Assume we stop. Should we find watchpoint that is not actually
4067 triggered, or if condition of breakpoint is false, we'll reset
4072 bpstat_check_watchpoint (bs);
4076 if (b->type == bp_thread_event || b->type == bp_overlay_event
4077 || b->type == bp_longjmp_master
4078 || b->type == bp_std_terminate_master)
4079 /* We do not stop for these. */
4082 bpstat_check_breakpoint_conditions (bs, ptid);
4088 /* We will stop here */
4089 if (b->disposition == disp_disable)
4091 if (b->enable_state != bp_permanent)
4092 b->enable_state = bp_disabled;
4093 update_global_location_list (0);
4097 bs->commands = b->commands;
4098 incref_counted_command_line (bs->commands);
4099 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4100 if (bs->commands_left
4101 && (strcmp ("silent", bs->commands_left->line) == 0
4104 bs->commands_left->line) == 0)))
4106 bs->commands_left = bs->commands_left->next;
4111 /* Print nothing for this entry if we dont stop or dont print. */
4112 if (bs->stop == 0 || bs->print == 0)
4113 bs->print_it = print_it_noop;
4117 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4119 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4122 bs = bpstat_alloc (loc, bs);
4123 /* For hits of moribund locations, we should just proceed. */
4126 bs->print_it = print_it_noop;
4130 bs->next = NULL; /* Terminate the chain */
4132 /* If we aren't stopping, the value of some hardware watchpoint may
4133 not have changed, but the intermediate memory locations we are
4134 watching may have. Don't bother if we're stopping; this will get
4136 need_remove_insert = 0;
4137 if (! bpstat_causes_stop (root_bs->next))
4138 for (bs = root_bs->next; bs != NULL; bs = bs->next)
4140 && bs->breakpoint_at->owner
4141 && is_hardware_watchpoint (bs->breakpoint_at->owner))
4143 update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */);
4144 /* Updating watchpoints invalidates bs->breakpoint_at.
4145 Prevent further code from trying to use it. */
4146 bs->breakpoint_at = NULL;
4147 need_remove_insert = 1;
4150 if (need_remove_insert)
4151 update_global_location_list (1);
4153 return root_bs->next;
4157 handle_jit_event (void)
4159 struct frame_info *frame;
4160 struct gdbarch *gdbarch;
4162 /* Switch terminal for any messages produced by
4163 breakpoint_re_set. */
4164 target_terminal_ours_for_output ();
4166 frame = get_current_frame ();
4167 gdbarch = get_frame_arch (frame);
4169 jit_event_handler (gdbarch);
4171 target_terminal_inferior ();
4174 /* Prepare WHAT final decision for infrun. */
4176 /* Decide what infrun needs to do with this bpstat. */
4179 bpstat_what (bpstat bs)
4181 struct bpstat_what retval;
4182 /* We need to defer calling `solib_add', as adding new symbols
4183 resets breakpoints, which in turn deletes breakpoint locations,
4184 and hence may clear unprocessed entries in the BS chain. */
4185 int shlib_event = 0;
4188 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4189 retval.call_dummy = STOP_NONE;
4191 for (; bs != NULL; bs = bs->next)
4193 /* Extract this BS's action. After processing each BS, we check
4194 if its action overrides all we've seem so far. */
4195 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4198 if (bs->breakpoint_at == NULL)
4200 /* I suspect this can happen if it was a momentary
4201 breakpoint which has since been deleted. */
4204 else if (bs->breakpoint_at->owner == NULL)
4207 bptype = bs->breakpoint_at->owner->type;
4214 case bp_hardware_breakpoint:
4220 this_action = BPSTAT_WHAT_STOP_NOISY;
4222 this_action = BPSTAT_WHAT_STOP_SILENT;
4225 this_action = BPSTAT_WHAT_SINGLE;
4228 case bp_hardware_watchpoint:
4229 case bp_read_watchpoint:
4230 case bp_access_watchpoint:
4234 this_action = BPSTAT_WHAT_STOP_NOISY;
4236 this_action = BPSTAT_WHAT_STOP_SILENT;
4240 /* There was a watchpoint, but we're not stopping.
4241 This requires no further action. */
4245 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4247 case bp_longjmp_resume:
4248 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4250 case bp_step_resume:
4252 this_action = BPSTAT_WHAT_STEP_RESUME;
4255 /* It is for the wrong frame. */
4256 this_action = BPSTAT_WHAT_SINGLE;
4259 case bp_watchpoint_scope:
4260 case bp_thread_event:
4261 case bp_overlay_event:
4262 case bp_longjmp_master:
4263 case bp_std_terminate_master:
4264 this_action = BPSTAT_WHAT_SINGLE;
4270 this_action = BPSTAT_WHAT_STOP_NOISY;
4272 this_action = BPSTAT_WHAT_STOP_SILENT;
4276 /* There was a catchpoint, but we're not stopping.
4277 This requires no further action. */
4280 case bp_shlib_event:
4283 /* If requested, stop when the dynamic linker notifies GDB
4284 of events. This allows the user to get control and place
4285 breakpoints in initializer routines for dynamically
4286 loaded objects (among other things). */
4287 if (stop_on_solib_events)
4288 this_action = BPSTAT_WHAT_STOP_NOISY;
4290 this_action = BPSTAT_WHAT_SINGLE;
4294 this_action = BPSTAT_WHAT_SINGLE;
4297 /* Make sure the action is stop (silent or noisy),
4298 so infrun.c pops the dummy frame. */
4299 retval.call_dummy = STOP_STACK_DUMMY;
4300 this_action = BPSTAT_WHAT_STOP_SILENT;
4302 case bp_std_terminate:
4303 /* Make sure the action is stop (silent or noisy),
4304 so infrun.c pops the dummy frame. */
4305 retval.call_dummy = STOP_STD_TERMINATE;
4306 this_action = BPSTAT_WHAT_STOP_SILENT;
4309 case bp_fast_tracepoint:
4310 case bp_static_tracepoint:
4311 /* Tracepoint hits should not be reported back to GDB, and
4312 if one got through somehow, it should have been filtered
4314 internal_error (__FILE__, __LINE__,
4315 _("bpstat_what: tracepoint encountered"));
4317 internal_error (__FILE__, __LINE__,
4318 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4321 retval.main_action = max (retval.main_action, this_action);
4327 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4329 /* Check for any newly added shared libraries if we're supposed
4330 to be adding them automatically. */
4332 /* Switch terminal for any messages produced by
4333 breakpoint_re_set. */
4334 target_terminal_ours_for_output ();
4337 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4339 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4342 target_terminal_inferior ();
4348 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4350 handle_jit_event ();
4356 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4357 without hardware support). This isn't related to a specific bpstat,
4358 just to things like whether watchpoints are set. */
4361 bpstat_should_step (void)
4363 struct breakpoint *b;
4366 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4372 bpstat_causes_stop (bpstat bs)
4374 for (; bs != NULL; bs = bs->next)
4383 /* Print the LOC location out of the list of B->LOC locations. */
4385 static void print_breakpoint_location (struct breakpoint *b,
4386 struct bp_location *loc,
4388 struct ui_stream *stb)
4390 struct cleanup *old_chain = save_current_program_space ();
4392 if (loc != NULL && loc->shlib_disabled)
4396 set_current_program_space (loc->pspace);
4398 if (b->source_file && loc)
4401 = find_pc_sect_function (loc->address, loc->section);
4404 ui_out_text (uiout, "in ");
4405 ui_out_field_string (uiout, "func",
4406 SYMBOL_PRINT_NAME (sym));
4407 ui_out_wrap_hint (uiout, wrap_indent);
4408 ui_out_text (uiout, " at ");
4410 ui_out_field_string (uiout, "file", b->source_file);
4411 ui_out_text (uiout, ":");
4413 if (ui_out_is_mi_like_p (uiout))
4415 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4416 char *fullname = symtab_to_fullname (sal.symtab);
4419 ui_out_field_string (uiout, "fullname", fullname);
4422 ui_out_field_int (uiout, "line", b->line_number);
4426 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4428 ui_out_field_stream (uiout, "at", stb);
4431 ui_out_field_string (uiout, "pending", b->addr_string);
4433 do_cleanups (old_chain);
4437 bptype_string (enum bptype type)
4439 struct ep_type_description
4444 static struct ep_type_description bptypes[] =
4446 {bp_none, "?deleted?"},
4447 {bp_breakpoint, "breakpoint"},
4448 {bp_hardware_breakpoint, "hw breakpoint"},
4449 {bp_until, "until"},
4450 {bp_finish, "finish"},
4451 {bp_watchpoint, "watchpoint"},
4452 {bp_hardware_watchpoint, "hw watchpoint"},
4453 {bp_read_watchpoint, "read watchpoint"},
4454 {bp_access_watchpoint, "acc watchpoint"},
4455 {bp_longjmp, "longjmp"},
4456 {bp_longjmp_resume, "longjmp resume"},
4457 {bp_step_resume, "step resume"},
4458 {bp_watchpoint_scope, "watchpoint scope"},
4459 {bp_call_dummy, "call dummy"},
4460 {bp_std_terminate, "std::terminate"},
4461 {bp_shlib_event, "shlib events"},
4462 {bp_thread_event, "thread events"},
4463 {bp_overlay_event, "overlay events"},
4464 {bp_longjmp_master, "longjmp master"},
4465 {bp_std_terminate_master, "std::terminate master"},
4466 {bp_catchpoint, "catchpoint"},
4467 {bp_tracepoint, "tracepoint"},
4468 {bp_fast_tracepoint, "fast tracepoint"},
4469 {bp_static_tracepoint, "static tracepoint"},
4470 {bp_jit_event, "jit events"},
4473 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4474 || ((int) type != bptypes[(int) type].type))
4475 internal_error (__FILE__, __LINE__,
4476 _("bptypes table does not describe type #%d."),
4479 return bptypes[(int) type].description;
4482 /* Print B to gdb_stdout. */
4485 print_one_breakpoint_location (struct breakpoint *b,
4486 struct bp_location *loc,
4488 struct bp_location **last_loc,
4489 int print_address_bits,
4492 struct command_line *l;
4493 static char bpenables[] = "nynny";
4494 char wrap_indent[80];
4495 struct ui_stream *stb = ui_out_stream_new (uiout);
4496 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4497 struct cleanup *bkpt_chain;
4499 int header_of_multiple = 0;
4500 int part_of_multiple = (loc != NULL);
4501 struct value_print_options opts;
4503 get_user_print_options (&opts);
4505 gdb_assert (!loc || loc_number != 0);
4506 /* See comment in print_one_breakpoint concerning
4507 treatment of breakpoints with single disabled
4511 && (b->loc->next != NULL || !b->loc->enabled)))
4512 header_of_multiple = 1;
4517 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4521 if (part_of_multiple)
4524 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4525 ui_out_field_string (uiout, "number", formatted);
4530 ui_out_field_int (uiout, "number", b->number);
4535 if (part_of_multiple)
4536 ui_out_field_skip (uiout, "type");
4538 ui_out_field_string (uiout, "type", bptype_string (b->type));
4542 if (part_of_multiple)
4543 ui_out_field_skip (uiout, "disp");
4545 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4550 if (part_of_multiple)
4551 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4553 ui_out_field_fmt (uiout, "enabled", "%c",
4554 bpenables[(int) b->enable_state]);
4555 ui_out_spaces (uiout, 2);
4559 strcpy (wrap_indent, " ");
4560 if (opts.addressprint)
4562 if (print_address_bits <= 32)
4563 strcat (wrap_indent, " ");
4565 strcat (wrap_indent, " ");
4568 if (b->ops != NULL && b->ops->print_one != NULL)
4570 /* Although the print_one can possibly print
4571 all locations, calling it here is not likely
4572 to get any nice result. So, make sure there's
4573 just one location. */
4574 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4575 b->ops->print_one (b, last_loc);
4581 internal_error (__FILE__, __LINE__,
4582 _("print_one_breakpoint: bp_none encountered\n"));
4586 case bp_hardware_watchpoint:
4587 case bp_read_watchpoint:
4588 case bp_access_watchpoint:
4589 /* Field 4, the address, is omitted (which makes the columns
4590 not line up too nicely with the headers, but the effect
4591 is relatively readable). */
4592 if (opts.addressprint)
4593 ui_out_field_skip (uiout, "addr");
4595 ui_out_field_string (uiout, "what", b->exp_string);
4599 case bp_hardware_breakpoint:
4603 case bp_longjmp_resume:
4604 case bp_step_resume:
4605 case bp_watchpoint_scope:
4607 case bp_std_terminate:
4608 case bp_shlib_event:
4609 case bp_thread_event:
4610 case bp_overlay_event:
4611 case bp_longjmp_master:
4612 case bp_std_terminate_master:
4614 case bp_fast_tracepoint:
4615 case bp_static_tracepoint:
4617 if (opts.addressprint)
4620 if (header_of_multiple)
4621 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4622 else if (b->loc == NULL || loc->shlib_disabled)
4623 ui_out_field_string (uiout, "addr", "<PENDING>");
4625 ui_out_field_core_addr (uiout, "addr",
4626 loc->gdbarch, loc->address);
4629 if (!header_of_multiple)
4630 print_breakpoint_location (b, loc, wrap_indent, stb);
4637 /* For backward compatibility, don't display inferiors unless there
4640 && !header_of_multiple
4642 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4643 && (number_of_program_spaces () > 1
4644 || number_of_inferiors () > 1)
4645 /* LOC is for existing B, it cannot be in moribund_locations and
4646 thus having NULL OWNER. */
4647 && loc->owner->type != bp_catchpoint)))
4649 struct inferior *inf;
4652 for (inf = inferior_list; inf != NULL; inf = inf->next)
4654 if (inf->pspace == loc->pspace)
4659 ui_out_text (uiout, " inf ");
4662 ui_out_text (uiout, ", ");
4663 ui_out_text (uiout, plongest (inf->num));
4668 if (!part_of_multiple)
4670 if (b->thread != -1)
4672 /* FIXME: This seems to be redundant and lost here; see the
4673 "stop only in" line a little further down. */
4674 ui_out_text (uiout, " thread ");
4675 ui_out_field_int (uiout, "thread", b->thread);
4677 else if (b->task != 0)
4679 ui_out_text (uiout, " task ");
4680 ui_out_field_int (uiout, "task", b->task);
4684 ui_out_text (uiout, "\n");
4686 if (!part_of_multiple && b->static_trace_marker_id)
4688 gdb_assert (b->type == bp_static_tracepoint);
4690 ui_out_text (uiout, "\tmarker id is ");
4691 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
4692 b->static_trace_marker_id);
4693 ui_out_text (uiout, "\n");
4696 if (part_of_multiple && frame_id_p (b->frame_id))
4699 ui_out_text (uiout, "\tstop only in stack frame at ");
4700 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4702 ui_out_field_core_addr (uiout, "frame",
4703 b->gdbarch, b->frame_id.stack_addr);
4704 ui_out_text (uiout, "\n");
4707 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4709 /* We do not print the condition for Ada exception catchpoints
4710 because the condition is an internal implementation detail
4711 that we do not want to expose to the user. */
4713 if (is_tracepoint (b))
4714 ui_out_text (uiout, "\ttrace only if ");
4716 ui_out_text (uiout, "\tstop only if ");
4717 ui_out_field_string (uiout, "cond", b->cond_string);
4718 ui_out_text (uiout, "\n");
4721 if (!part_of_multiple && b->thread != -1)
4723 /* FIXME should make an annotation for this */
4724 ui_out_text (uiout, "\tstop only in thread ");
4725 ui_out_field_int (uiout, "thread", b->thread);
4726 ui_out_text (uiout, "\n");
4729 if (!part_of_multiple && b->hit_count)
4731 /* FIXME should make an annotation for this */
4732 if (ep_is_catchpoint (b))
4733 ui_out_text (uiout, "\tcatchpoint");
4735 ui_out_text (uiout, "\tbreakpoint");
4736 ui_out_text (uiout, " already hit ");
4737 ui_out_field_int (uiout, "times", b->hit_count);
4738 if (b->hit_count == 1)
4739 ui_out_text (uiout, " time\n");
4741 ui_out_text (uiout, " times\n");
4744 /* Output the count also if it is zero, but only if this is
4745 mi. FIXME: Should have a better test for this. */
4746 if (ui_out_is_mi_like_p (uiout))
4747 if (!part_of_multiple && b->hit_count == 0)
4748 ui_out_field_int (uiout, "times", b->hit_count);
4750 if (!part_of_multiple && b->ignore_count)
4753 ui_out_text (uiout, "\tignore next ");
4754 ui_out_field_int (uiout, "ignore", b->ignore_count);
4755 ui_out_text (uiout, " hits\n");
4758 l = b->commands ? b->commands->commands : NULL;
4759 if (!part_of_multiple && l)
4761 struct cleanup *script_chain;
4764 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4765 print_command_lines (uiout, l, 4);
4766 do_cleanups (script_chain);
4769 if (!part_of_multiple && b->pass_count)
4771 annotate_field (10);
4772 ui_out_text (uiout, "\tpass count ");
4773 ui_out_field_int (uiout, "pass", b->pass_count);
4774 ui_out_text (uiout, " \n");
4777 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4780 ui_out_field_string (uiout, "original-location", b->addr_string);
4781 else if (b->exp_string)
4782 ui_out_field_string (uiout, "original-location", b->exp_string);
4785 do_cleanups (bkpt_chain);
4786 do_cleanups (old_chain);
4790 print_one_breakpoint (struct breakpoint *b,
4791 struct bp_location **last_loc, int print_address_bits,
4794 print_one_breakpoint_location (b, NULL, 0, last_loc,
4795 print_address_bits, allflag);
4797 /* If this breakpoint has custom print function,
4798 it's already printed. Otherwise, print individual
4799 locations, if any. */
4800 if (b->ops == NULL || b->ops->print_one == NULL)
4802 /* If breakpoint has a single location that is
4803 disabled, we print it as if it had
4804 several locations, since otherwise it's hard to
4805 represent "breakpoint enabled, location disabled"
4807 Note that while hardware watchpoints have
4808 several locations internally, that's no a property
4811 && !is_hardware_watchpoint (b)
4812 && (b->loc->next || !b->loc->enabled)
4813 && !ui_out_is_mi_like_p (uiout))
4815 struct bp_location *loc;
4817 for (loc = b->loc; loc; loc = loc->next, ++n)
4818 print_one_breakpoint_location (b, loc, n, last_loc,
4819 print_address_bits, allflag);
4825 breakpoint_address_bits (struct breakpoint *b)
4827 int print_address_bits = 0;
4828 struct bp_location *loc;
4830 for (loc = b->loc; loc; loc = loc->next)
4834 /* Software watchpoints that aren't watching memory don't have
4835 an address to print. */
4836 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4839 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4840 if (addr_bit > print_address_bits)
4841 print_address_bits = addr_bit;
4844 return print_address_bits;
4847 struct captured_breakpoint_query_args
4853 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4855 struct captured_breakpoint_query_args *args = data;
4856 struct breakpoint *b;
4857 struct bp_location *dummy_loc = NULL;
4861 if (args->bnum == b->number)
4863 int print_address_bits = breakpoint_address_bits (b);
4865 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4873 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4875 struct captured_breakpoint_query_args args;
4878 /* For the moment we don't trust print_one_breakpoint() to not throw
4880 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4881 error_message, RETURN_MASK_ALL) < 0)
4887 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4888 catchpoints, et.al.). */
4891 user_settable_breakpoint (const struct breakpoint *b)
4893 return (b->type == bp_breakpoint
4894 || b->type == bp_catchpoint
4895 || b->type == bp_hardware_breakpoint
4896 || is_tracepoint (b)
4897 || is_watchpoint (b));
4900 /* Print information on user settable breakpoint (watchpoint, etc)
4901 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4902 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4903 FILTER is non-NULL, call it on each breakpoint and only include the
4904 ones for which it returns non-zero. Return the total number of
4905 breakpoints listed. */
4908 breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
4910 struct breakpoint *b;
4911 struct bp_location *last_loc = NULL;
4912 int nr_printable_breakpoints;
4913 struct cleanup *bkpttbl_chain;
4914 struct value_print_options opts;
4915 int print_address_bits = 0;
4916 int print_type_col_width = 14;
4918 get_user_print_options (&opts);
4920 /* Compute the number of rows in the table, as well as the
4921 size required for address fields. */
4922 nr_printable_breakpoints = 0;
4925 || bnum == b->number)
4927 /* If we have a filter, only list the breakpoints it accepts. */
4928 if (filter && !filter (b))
4931 if (allflag || user_settable_breakpoint (b))
4933 int addr_bit, type_len;
4935 addr_bit = breakpoint_address_bits (b);
4936 if (addr_bit > print_address_bits)
4937 print_address_bits = addr_bit;
4939 type_len = strlen (bptype_string (b->type));
4940 if (type_len > print_type_col_width)
4941 print_type_col_width = type_len;
4943 nr_printable_breakpoints++;
4947 if (opts.addressprint)
4949 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
4953 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
4956 if (nr_printable_breakpoints > 0)
4957 annotate_breakpoints_headers ();
4958 if (nr_printable_breakpoints > 0)
4960 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
4961 if (nr_printable_breakpoints > 0)
4963 ui_out_table_header (uiout, print_type_col_width, ui_left,
4964 "type", "Type"); /* 2 */
4965 if (nr_printable_breakpoints > 0)
4967 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
4968 if (nr_printable_breakpoints > 0)
4970 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
4971 if (opts.addressprint)
4973 if (nr_printable_breakpoints > 0)
4975 if (print_address_bits <= 32)
4976 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
4978 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
4980 if (nr_printable_breakpoints > 0)
4982 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
4983 ui_out_table_body (uiout);
4984 if (nr_printable_breakpoints > 0)
4985 annotate_breakpoints_table ();
4991 || bnum == b->number)
4993 /* If we have a filter, only list the breakpoints it accepts. */
4994 if (filter && !filter (b))
4997 /* We only print out user settable breakpoints unless the
4999 if (allflag || user_settable_breakpoint (b))
5000 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5004 do_cleanups (bkpttbl_chain);
5006 if (nr_printable_breakpoints == 0)
5008 /* If there's a filter, let the caller decide how to report empty list. */
5012 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5014 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
5020 if (last_loc && !server_command)
5021 set_next_address (last_loc->gdbarch, last_loc->address);
5024 /* FIXME? Should this be moved up so that it is only called when
5025 there have been breakpoints? */
5026 annotate_breakpoints_table_end ();
5028 return nr_printable_breakpoints;
5031 /* Display the value of default-collect in a way that is generally
5032 compatible with the breakpoint list. */
5035 default_collect_info (void)
5037 /* If it has no value (which is frequently the case), say nothing; a
5038 message like "No default-collect." gets in user's face when it's
5040 if (!*default_collect)
5043 /* The following phrase lines up nicely with per-tracepoint collect
5045 ui_out_text (uiout, "default collect ");
5046 ui_out_field_string (uiout, "default-collect", default_collect);
5047 ui_out_text (uiout, " \n");
5051 breakpoints_info (char *bnum_exp, int from_tty)
5056 bnum = parse_and_eval_long (bnum_exp);
5058 breakpoint_1 (bnum, 0, NULL);
5060 default_collect_info ();
5064 watchpoints_info (char *wpnum_exp, int from_tty)
5066 int wpnum = -1, num_printed;
5069 wpnum = parse_and_eval_long (wpnum_exp);
5071 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5073 if (num_printed == 0)
5076 ui_out_message (uiout, 0, "No watchpoints.\n");
5078 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5083 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5088 bnum = parse_and_eval_long (bnum_exp);
5090 breakpoint_1 (bnum, 1, NULL);
5092 default_collect_info ();
5096 breakpoint_has_pc (struct breakpoint *b,
5097 struct program_space *pspace,
5098 CORE_ADDR pc, struct obj_section *section)
5100 struct bp_location *bl = b->loc;
5102 for (; bl; bl = bl->next)
5104 if (bl->pspace == pspace
5105 && bl->address == pc
5106 && (!overlay_debugging || bl->section == section))
5112 /* Print a message describing any breakpoints set at PC. This
5113 concerns with logical breakpoints, so we match program spaces, not
5117 describe_other_breakpoints (struct gdbarch *gdbarch,
5118 struct program_space *pspace, CORE_ADDR pc,
5119 struct obj_section *section, int thread)
5122 struct breakpoint *b;
5125 others += breakpoint_has_pc (b, pspace, pc, section);
5129 printf_filtered (_("Note: breakpoint "));
5130 else /* if (others == ???) */
5131 printf_filtered (_("Note: breakpoints "));
5133 if (breakpoint_has_pc (b, pspace, pc, section))
5136 printf_filtered ("%d", b->number);
5137 if (b->thread == -1 && thread != -1)
5138 printf_filtered (" (all threads)");
5139 else if (b->thread != -1)
5140 printf_filtered (" (thread %d)", b->thread);
5141 printf_filtered ("%s%s ",
5142 ((b->enable_state == bp_disabled
5143 || b->enable_state == bp_call_disabled
5144 || b->enable_state == bp_startup_disabled)
5146 : b->enable_state == bp_permanent
5150 : ((others == 1) ? " and" : ""));
5152 printf_filtered (_("also set at pc "));
5153 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5154 printf_filtered (".\n");
5158 /* Set the default place to put a breakpoint
5159 for the `break' command with no arguments. */
5162 set_default_breakpoint (int valid, struct program_space *pspace,
5163 CORE_ADDR addr, struct symtab *symtab,
5166 default_breakpoint_valid = valid;
5167 default_breakpoint_pspace = pspace;
5168 default_breakpoint_address = addr;
5169 default_breakpoint_symtab = symtab;
5170 default_breakpoint_line = line;
5173 /* Return true iff it is meaningful to use the address member of
5174 BPT. For some breakpoint types, the address member is irrelevant
5175 and it makes no sense to attempt to compare it to other addresses
5176 (or use it for any other purpose either).
5178 More specifically, each of the following breakpoint types will always
5179 have a zero valued address and we don't want to mark breakpoints of any of
5180 these types to be a duplicate of an actual breakpoint at address zero:
5188 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5190 enum bptype type = bpt->type;
5192 return (type != bp_watchpoint && type != bp_catchpoint);
5195 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5196 true if LOC1 and LOC2 represent the same watchpoint location. */
5199 watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5201 /* Both of them must not be in moribund_locations. */
5202 gdb_assert (loc1->owner != NULL);
5203 gdb_assert (loc2->owner != NULL);
5205 /* If the target can evaluate the condition expression in hardware, then we
5206 we need to insert both watchpoints even if they are at the same place.
5207 Otherwise the watchpoint will only trigger when the condition of whichever
5208 watchpoint was inserted evaluates to true, not giving a chance for GDB to
5209 check the condition of the other watchpoint. */
5210 if ((loc1->owner->cond_exp
5211 && target_can_accel_watchpoint_condition (loc1->address, loc1->length,
5212 loc1->watchpoint_type,
5213 loc1->owner->cond_exp))
5214 || (loc2->owner->cond_exp
5215 && target_can_accel_watchpoint_condition (loc2->address, loc2->length,
5216 loc2->watchpoint_type,
5217 loc2->owner->cond_exp)))
5220 /* Note that this checks the owner's type, not the location's. In
5221 case the target does not support read watchpoints, but does
5222 support access watchpoints, we'll have bp_read_watchpoint
5223 watchpoints with hw_access locations. Those should be considered
5224 duplicates of hw_read locations. The hw_read locations will
5225 become hw_access locations later. */
5226 return (loc1->owner->type == loc2->owner->type
5227 && loc1->pspace->aspace == loc2->pspace->aspace
5228 && loc1->address == loc2->address
5229 && loc1->length == loc2->length);
5232 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5233 same breakpoint location. In most targets, this can only be true
5234 if ASPACE1 matches ASPACE2. On targets that have global
5235 breakpoints, the address space doesn't really matter. */
5238 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5239 struct address_space *aspace2, CORE_ADDR addr2)
5241 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5242 || aspace1 == aspace2)
5246 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5247 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5248 represent the same location. */
5251 breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5253 int hw_point1, hw_point2;
5255 /* Both of them must not be in moribund_locations. */
5256 gdb_assert (loc1->owner != NULL);
5257 gdb_assert (loc2->owner != NULL);
5259 hw_point1 = is_hardware_watchpoint (loc1->owner);
5260 hw_point2 = is_hardware_watchpoint (loc2->owner);
5262 if (hw_point1 != hw_point2)
5265 return watchpoint_locations_match (loc1, loc2);
5267 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5268 loc2->pspace->aspace, loc2->address);
5272 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5273 int bnum, int have_bnum)
5278 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5279 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5281 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5282 bnum, astr1, astr2);
5284 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5287 /* Adjust a breakpoint's address to account for architectural constraints
5288 on breakpoint placement. Return the adjusted address. Note: Very
5289 few targets require this kind of adjustment. For most targets,
5290 this function is simply the identity function. */
5293 adjust_breakpoint_address (struct gdbarch *gdbarch,
5294 CORE_ADDR bpaddr, enum bptype bptype)
5296 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5298 /* Very few targets need any kind of breakpoint adjustment. */
5301 else if (bptype == bp_watchpoint
5302 || bptype == bp_hardware_watchpoint
5303 || bptype == bp_read_watchpoint
5304 || bptype == bp_access_watchpoint
5305 || bptype == bp_catchpoint)
5307 /* Watchpoints and the various bp_catch_* eventpoints should not
5308 have their addresses modified. */
5313 CORE_ADDR adjusted_bpaddr;
5315 /* Some targets have architectural constraints on the placement
5316 of breakpoint instructions. Obtain the adjusted address. */
5317 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5319 /* An adjusted breakpoint address can significantly alter
5320 a user's expectations. Print a warning if an adjustment
5322 if (adjusted_bpaddr != bpaddr)
5323 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5325 return adjusted_bpaddr;
5329 /* Allocate a struct bp_location. */
5331 static struct bp_location *
5332 allocate_bp_location (struct breakpoint *bpt)
5334 struct bp_location *loc;
5336 loc = xmalloc (sizeof (struct bp_location));
5337 memset (loc, 0, sizeof (*loc));
5341 loc->shlib_disabled = 0;
5350 case bp_longjmp_resume:
5351 case bp_step_resume:
5352 case bp_watchpoint_scope:
5354 case bp_std_terminate:
5355 case bp_shlib_event:
5356 case bp_thread_event:
5357 case bp_overlay_event:
5359 case bp_longjmp_master:
5360 case bp_std_terminate_master:
5361 loc->loc_type = bp_loc_software_breakpoint;
5363 case bp_hardware_breakpoint:
5364 loc->loc_type = bp_loc_hardware_breakpoint;
5366 case bp_hardware_watchpoint:
5367 case bp_read_watchpoint:
5368 case bp_access_watchpoint:
5369 loc->loc_type = bp_loc_hardware_watchpoint;
5374 case bp_fast_tracepoint:
5375 case bp_static_tracepoint:
5376 loc->loc_type = bp_loc_other;
5379 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5385 static void free_bp_location (struct bp_location *loc)
5387 /* Be sure no bpstat's are pointing at it after it's been freed. */
5388 /* FIXME, how can we find all bpstat's?
5389 We just check stop_bpstat for now. Note that we cannot just
5390 remove bpstats pointing at bpt from the stop_bpstat list
5391 entirely, as breakpoint commands are associated with the bpstat;
5392 if we remove it here, then the later call to
5393 bpstat_do_actions (&stop_bpstat);
5394 in event-top.c won't do anything, and temporary breakpoints
5395 with commands won't work. */
5397 iterate_over_threads (bpstat_remove_bp_location_callback, loc);
5402 if (loc->function_name)
5403 xfree (loc->function_name);
5408 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5409 that has type BPTYPE and has no locations as yet. */
5410 /* This function is used in gdbtk sources and thus can not be made static. */
5412 static struct breakpoint *
5413 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5416 struct breakpoint *b, *b1;
5418 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5419 memset (b, 0, sizeof (*b));
5422 b->gdbarch = gdbarch;
5423 b->language = current_language->la_language;
5424 b->input_radix = input_radix;
5426 b->enable_state = bp_enabled;
5429 b->ignore_count = 0;
5431 b->frame_id = null_frame_id;
5432 b->forked_inferior_pid = null_ptid;
5433 b->exec_pathname = NULL;
5434 b->syscalls_to_be_caught = NULL;
5436 b->condition_not_parsed = 0;
5438 /* Add this breakpoint to the end of the chain
5439 so that a list of breakpoints will come out in order
5440 of increasing numbers. */
5442 b1 = breakpoint_chain;
5444 breakpoint_chain = b;
5454 /* Initialize loc->function_name. */
5456 set_breakpoint_location_function (struct bp_location *loc)
5458 gdb_assert (loc->owner != NULL);
5460 if (loc->owner->type == bp_breakpoint
5461 || loc->owner->type == bp_hardware_breakpoint
5462 || is_tracepoint (loc->owner))
5464 find_pc_partial_function (loc->address, &(loc->function_name),
5466 if (loc->function_name)
5467 loc->function_name = xstrdup (loc->function_name);
5471 /* Attempt to determine architecture of location identified by SAL. */
5472 static struct gdbarch *
5473 get_sal_arch (struct symtab_and_line sal)
5476 return get_objfile_arch (sal.section->objfile);
5478 return get_objfile_arch (sal.symtab->objfile);
5483 /* set_raw_breakpoint is a low level routine for allocating and
5484 partially initializing a breakpoint of type BPTYPE. The newly
5485 created breakpoint's address, section, source file name, and line
5486 number are provided by SAL. The newly created and partially
5487 initialized breakpoint is added to the breakpoint chain and
5488 is also returned as the value of this function.
5490 It is expected that the caller will complete the initialization of
5491 the newly created breakpoint struct as well as output any status
5492 information regarding the creation of a new breakpoint. In
5493 particular, set_raw_breakpoint does NOT set the breakpoint
5494 number! Care should be taken to not allow an error to occur
5495 prior to completing the initialization of the breakpoint. If this
5496 should happen, a bogus breakpoint will be left on the chain. */
5499 set_raw_breakpoint (struct gdbarch *gdbarch,
5500 struct symtab_and_line sal, enum bptype bptype)
5502 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
5503 CORE_ADDR adjusted_address;
5504 struct gdbarch *loc_gdbarch;
5506 loc_gdbarch = get_sal_arch (sal);
5508 loc_gdbarch = b->gdbarch;
5510 if (bptype != bp_catchpoint)
5511 gdb_assert (sal.pspace != NULL);
5513 /* Adjust the breakpoint's address prior to allocating a location.
5514 Once we call allocate_bp_location(), that mostly uninitialized
5515 location will be placed on the location chain. Adjustment of the
5516 breakpoint may cause target_read_memory() to be called and we do
5517 not want its scan of the location chain to find a breakpoint and
5518 location that's only been partially initialized. */
5519 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
5521 b->loc = allocate_bp_location (b);
5522 b->loc->gdbarch = loc_gdbarch;
5523 b->loc->requested_address = sal.pc;
5524 b->loc->address = adjusted_address;
5525 b->loc->pspace = sal.pspace;
5527 /* Store the program space that was used to set the breakpoint, for
5528 breakpoint resetting. */
5529 b->pspace = sal.pspace;
5531 if (sal.symtab == NULL)
5532 b->source_file = NULL;
5534 b->source_file = xstrdup (sal.symtab->filename);
5535 b->loc->section = sal.section;
5536 b->line_number = sal.line;
5538 set_breakpoint_location_function (b->loc);
5540 breakpoints_changed ();
5546 /* Note that the breakpoint object B describes a permanent breakpoint
5547 instruction, hard-wired into the inferior's code. */
5549 make_breakpoint_permanent (struct breakpoint *b)
5551 struct bp_location *bl;
5553 b->enable_state = bp_permanent;
5555 /* By definition, permanent breakpoints are already present in the code.
5556 Mark all locations as inserted. For now, make_breakpoint_permanent
5557 is called in just one place, so it's hard to say if it's reasonable
5558 to have permanent breakpoint with multiple locations or not,
5559 but it's easy to implmement. */
5560 for (bl = b->loc; bl; bl = bl->next)
5564 /* Call this routine when stepping and nexting to enable a breakpoint
5565 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5566 set_longjmp_resume_breakpoint() to figure out where we are going. */
5569 set_longjmp_breakpoint (int thread)
5571 struct breakpoint *b, *temp;
5573 /* To avoid having to rescan all objfile symbols at every step,
5574 we maintain a list of continually-inserted but always disabled
5575 longjmp "master" breakpoints. Here, we simply create momentary
5576 clones of those and enable them for the requested thread. */
5577 ALL_BREAKPOINTS_SAFE (b, temp)
5578 if (b->pspace == current_program_space
5579 && b->type == bp_longjmp_master)
5581 struct breakpoint *clone = clone_momentary_breakpoint (b);
5583 clone->type = bp_longjmp;
5584 clone->thread = thread;
5588 /* Delete all longjmp breakpoints from THREAD. */
5590 delete_longjmp_breakpoint (int thread)
5592 struct breakpoint *b, *temp;
5594 ALL_BREAKPOINTS_SAFE (b, temp)
5595 if (b->type == bp_longjmp)
5597 if (b->thread == thread)
5598 delete_breakpoint (b);
5603 enable_overlay_breakpoints (void)
5605 struct breakpoint *b;
5608 if (b->type == bp_overlay_event)
5610 b->enable_state = bp_enabled;
5611 update_global_location_list (1);
5612 overlay_events_enabled = 1;
5617 disable_overlay_breakpoints (void)
5619 struct breakpoint *b;
5622 if (b->type == bp_overlay_event)
5624 b->enable_state = bp_disabled;
5625 update_global_location_list (0);
5626 overlay_events_enabled = 0;
5630 /* Set an active std::terminate breakpoint for each std::terminate
5631 master breakpoint. */
5633 set_std_terminate_breakpoint (void)
5635 struct breakpoint *b, *temp;
5637 ALL_BREAKPOINTS_SAFE (b, temp)
5638 if (b->pspace == current_program_space
5639 && b->type == bp_std_terminate_master)
5641 struct breakpoint *clone = clone_momentary_breakpoint (b);
5642 clone->type = bp_std_terminate;
5646 /* Delete all the std::terminate breakpoints. */
5648 delete_std_terminate_breakpoint (void)
5650 struct breakpoint *b, *temp;
5652 ALL_BREAKPOINTS_SAFE (b, temp)
5653 if (b->type == bp_std_terminate)
5654 delete_breakpoint (b);
5658 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5660 struct breakpoint *b;
5662 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5664 b->enable_state = bp_enabled;
5665 /* addr_string has to be used or breakpoint_re_set will delete me. */
5667 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5669 update_global_location_list_nothrow (1);
5675 remove_thread_event_breakpoints (void)
5677 struct breakpoint *b, *temp;
5679 ALL_BREAKPOINTS_SAFE (b, temp)
5680 if (b->type == bp_thread_event
5681 && b->loc->pspace == current_program_space)
5682 delete_breakpoint (b);
5685 struct captured_parse_breakpoint_args
5688 struct symtabs_and_lines *sals_p;
5689 char ***addr_string_p;
5693 struct lang_and_radix
5699 /* Create a breakpoint for JIT code registration and unregistration. */
5702 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5704 struct breakpoint *b;
5706 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5707 update_global_location_list_nothrow (1);
5712 remove_solib_event_breakpoints (void)
5714 struct breakpoint *b, *temp;
5716 ALL_BREAKPOINTS_SAFE (b, temp)
5717 if (b->type == bp_shlib_event
5718 && b->loc->pspace == current_program_space)
5719 delete_breakpoint (b);
5723 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5725 struct breakpoint *b;
5727 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5728 update_global_location_list_nothrow (1);
5732 /* Disable any breakpoints that are on code in shared libraries. Only
5733 apply to enabled breakpoints, disabled ones can just stay disabled. */
5736 disable_breakpoints_in_shlibs (void)
5738 struct bp_location *loc, **locp_tmp;
5740 ALL_BP_LOCATIONS (loc, locp_tmp)
5742 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5743 struct breakpoint *b = loc->owner;
5745 /* We apply the check to all breakpoints, including disabled
5746 for those with loc->duplicate set. This is so that when breakpoint
5747 becomes enabled, or the duplicate is removed, gdb will try to insert
5748 all breakpoints. If we don't set shlib_disabled here, we'll try
5749 to insert those breakpoints and fail. */
5750 if (((b->type == bp_breakpoint)
5751 || (b->type == bp_jit_event)
5752 || (b->type == bp_hardware_breakpoint)
5753 || (is_tracepoint (b)))
5754 && loc->pspace == current_program_space
5755 && !loc->shlib_disabled
5757 && PC_SOLIB (loc->address)
5759 && solib_name_from_address (loc->pspace, loc->address)
5763 loc->shlib_disabled = 1;
5768 /* Disable any breakpoints that are in in an unloaded shared library. Only
5769 apply to enabled breakpoints, disabled ones can just stay disabled. */
5772 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5774 struct bp_location *loc, **locp_tmp;
5775 int disabled_shlib_breaks = 0;
5777 /* SunOS a.out shared libraries are always mapped, so do not
5778 disable breakpoints; they will only be reported as unloaded
5779 through clear_solib when GDB discards its shared library
5780 list. See clear_solib for more information. */
5781 if (exec_bfd != NULL
5782 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5785 ALL_BP_LOCATIONS (loc, locp_tmp)
5787 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5788 struct breakpoint *b = loc->owner;
5790 if ((loc->loc_type == bp_loc_hardware_breakpoint
5791 || loc->loc_type == bp_loc_software_breakpoint)
5792 && solib->pspace == loc->pspace
5793 && !loc->shlib_disabled
5794 && (b->type == bp_breakpoint
5795 || b->type == bp_jit_event
5796 || b->type == bp_hardware_breakpoint)
5797 && solib_contains_address_p (solib, loc->address))
5799 loc->shlib_disabled = 1;
5800 /* At this point, we cannot rely on remove_breakpoint
5801 succeeding so we must mark the breakpoint as not inserted
5802 to prevent future errors occurring in remove_breakpoints. */
5804 if (!disabled_shlib_breaks)
5806 target_terminal_ours_for_output ();
5807 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5810 disabled_shlib_breaks = 1;
5815 /* FORK & VFORK catchpoints. */
5817 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5820 insert_catch_fork (struct breakpoint *b)
5822 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5825 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5828 remove_catch_fork (struct breakpoint *b)
5830 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5833 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5837 breakpoint_hit_catch_fork (struct breakpoint *b)
5839 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5842 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5844 static enum print_stop_action
5845 print_it_catch_fork (struct breakpoint *b)
5847 annotate_catchpoint (b->number);
5848 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5849 b->number, ptid_get_pid (b->forked_inferior_pid));
5850 return PRINT_SRC_AND_LOC;
5853 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5856 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5858 struct value_print_options opts;
5860 get_user_print_options (&opts);
5862 /* Field 4, the address, is omitted (which makes the columns
5863 not line up too nicely with the headers, but the effect
5864 is relatively readable). */
5865 if (opts.addressprint)
5866 ui_out_field_skip (uiout, "addr");
5868 ui_out_text (uiout, "fork");
5869 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5871 ui_out_text (uiout, ", process ");
5872 ui_out_field_int (uiout, "what",
5873 ptid_get_pid (b->forked_inferior_pid));
5874 ui_out_spaces (uiout, 1);
5878 /* Implement the "print_mention" breakpoint_ops method for fork
5882 print_mention_catch_fork (struct breakpoint *b)
5884 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5887 /* Implement the "print_recreate" breakpoint_ops method for fork
5891 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
5893 fprintf_unfiltered (fp, "catch fork");
5896 /* The breakpoint_ops structure to be used in fork catchpoints. */
5898 static struct breakpoint_ops catch_fork_breakpoint_ops =
5902 breakpoint_hit_catch_fork,
5903 print_it_catch_fork,
5904 print_one_catch_fork,
5905 print_mention_catch_fork,
5906 print_recreate_catch_fork
5909 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5912 insert_catch_vfork (struct breakpoint *b)
5914 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
5917 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5920 remove_catch_vfork (struct breakpoint *b)
5922 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
5925 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5929 breakpoint_hit_catch_vfork (struct breakpoint *b)
5931 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
5934 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5936 static enum print_stop_action
5937 print_it_catch_vfork (struct breakpoint *b)
5939 annotate_catchpoint (b->number);
5940 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5941 b->number, ptid_get_pid (b->forked_inferior_pid));
5942 return PRINT_SRC_AND_LOC;
5945 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5948 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
5950 struct value_print_options opts;
5952 get_user_print_options (&opts);
5953 /* Field 4, the address, is omitted (which makes the columns
5954 not line up too nicely with the headers, but the effect
5955 is relatively readable). */
5956 if (opts.addressprint)
5957 ui_out_field_skip (uiout, "addr");
5959 ui_out_text (uiout, "vfork");
5960 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5962 ui_out_text (uiout, ", process ");
5963 ui_out_field_int (uiout, "what",
5964 ptid_get_pid (b->forked_inferior_pid));
5965 ui_out_spaces (uiout, 1);
5969 /* Implement the "print_mention" breakpoint_ops method for vfork
5973 print_mention_catch_vfork (struct breakpoint *b)
5975 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
5978 /* Implement the "print_recreate" breakpoint_ops method for vfork
5982 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
5984 fprintf_unfiltered (fp, "catch vfork");
5987 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5989 static struct breakpoint_ops catch_vfork_breakpoint_ops =
5993 breakpoint_hit_catch_vfork,
5994 print_it_catch_vfork,
5995 print_one_catch_vfork,
5996 print_mention_catch_vfork,
5997 print_recreate_catch_vfork
6000 /* Implement the "insert" breakpoint_ops method for syscall
6004 insert_catch_syscall (struct breakpoint *b)
6006 struct inferior *inf = current_inferior ();
6008 ++inf->total_syscalls_count;
6009 if (!b->syscalls_to_be_caught)
6010 ++inf->any_syscall_count;
6016 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6021 if (iter >= VEC_length (int, inf->syscalls_counts))
6023 int old_size = VEC_length (int, inf->syscalls_counts);
6024 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
6026 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6027 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6029 memset ((void *) vec_addr, 0,
6030 (iter + 1 - old_size) * sizeof (int));
6032 elem = VEC_index (int, inf->syscalls_counts, iter);
6033 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6037 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6038 inf->total_syscalls_count != 0,
6039 inf->any_syscall_count,
6040 VEC_length (int, inf->syscalls_counts),
6041 VEC_address (int, inf->syscalls_counts));
6044 /* Implement the "remove" breakpoint_ops method for syscall
6048 remove_catch_syscall (struct breakpoint *b)
6050 struct inferior *inf = current_inferior ();
6052 --inf->total_syscalls_count;
6053 if (!b->syscalls_to_be_caught)
6054 --inf->any_syscall_count;
6060 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6064 if (iter >= VEC_length (int, inf->syscalls_counts))
6065 /* Shouldn't happen. */
6067 elem = VEC_index (int, inf->syscalls_counts, iter);
6068 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6072 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6073 inf->total_syscalls_count != 0,
6074 inf->any_syscall_count,
6075 VEC_length (int, inf->syscalls_counts),
6076 VEC_address (int, inf->syscalls_counts));
6079 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6083 breakpoint_hit_catch_syscall (struct breakpoint *b)
6085 /* We must check if we are catching specific syscalls in this breakpoint.
6086 If we are, then we must guarantee that the called syscall is the same
6087 syscall we are catching. */
6088 int syscall_number = 0;
6090 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6093 /* Now, checking if the syscall is the same. */
6094 if (b->syscalls_to_be_caught)
6099 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6101 if (syscall_number == iter)
6111 /* Implement the "print_it" breakpoint_ops method for syscall
6114 static enum print_stop_action
6115 print_it_catch_syscall (struct breakpoint *b)
6117 /* These are needed because we want to know in which state a
6118 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6119 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6120 must print "called syscall" or "returned from syscall". */
6122 struct target_waitstatus last;
6124 struct cleanup *old_chain;
6127 get_last_target_status (&ptid, &last);
6129 get_syscall_by_number (last.value.syscall_number, &s);
6131 annotate_catchpoint (b->number);
6134 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6136 syscall_id = xstrprintf ("'%s'", s.name);
6138 old_chain = make_cleanup (xfree, syscall_id);
6140 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6141 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6142 b->number, syscall_id);
6143 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6144 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6145 b->number, syscall_id);
6147 do_cleanups (old_chain);
6149 return PRINT_SRC_AND_LOC;
6152 /* Implement the "print_one" breakpoint_ops method for syscall
6156 print_one_catch_syscall (struct breakpoint *b,
6157 struct bp_location **last_loc)
6159 struct value_print_options opts;
6161 get_user_print_options (&opts);
6162 /* Field 4, the address, is omitted (which makes the columns
6163 not line up too nicely with the headers, but the effect
6164 is relatively readable). */
6165 if (opts.addressprint)
6166 ui_out_field_skip (uiout, "addr");
6169 if (b->syscalls_to_be_caught
6170 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6171 ui_out_text (uiout, "syscalls \"");
6173 ui_out_text (uiout, "syscall \"");
6175 if (b->syscalls_to_be_caught)
6178 char *text = xstrprintf ("%s", "");
6181 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6186 get_syscall_by_number (iter, &s);
6189 text = xstrprintf ("%s%s, ", text, s.name);
6191 text = xstrprintf ("%s%d, ", text, iter);
6193 /* We have to xfree the last 'text' (now stored at 'x')
6194 because xstrprintf dinamically allocates new space for it
6198 /* Remove the last comma. */
6199 text[strlen (text) - 2] = '\0';
6200 ui_out_field_string (uiout, "what", text);
6203 ui_out_field_string (uiout, "what", "<any syscall>");
6204 ui_out_text (uiout, "\" ");
6207 /* Implement the "print_mention" breakpoint_ops method for syscall
6211 print_mention_catch_syscall (struct breakpoint *b)
6213 if (b->syscalls_to_be_caught)
6217 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6218 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6220 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6223 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6227 get_syscall_by_number (iter, &s);
6230 printf_filtered (" '%s' [%d]", s.name, s.number);
6232 printf_filtered (" %d", s.number);
6234 printf_filtered (")");
6237 printf_filtered (_("Catchpoint %d (any syscall)"),
6241 /* Implement the "print_recreate" breakpoint_ops method for syscall
6245 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6247 fprintf_unfiltered (fp, "catch syscall");
6249 if (b->syscalls_to_be_caught)
6254 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6259 get_syscall_by_number (iter, &s);
6261 fprintf_unfiltered (fp, " %s", s.name);
6263 fprintf_unfiltered (fp, " %d", s.number);
6268 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6270 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6272 insert_catch_syscall,
6273 remove_catch_syscall,
6274 breakpoint_hit_catch_syscall,
6275 print_it_catch_syscall,
6276 print_one_catch_syscall,
6277 print_mention_catch_syscall,
6278 print_recreate_catch_syscall
6281 /* Returns non-zero if 'b' is a syscall catchpoint. */
6284 syscall_catchpoint_p (struct breakpoint *b)
6286 return (b->ops == &catch_syscall_breakpoint_ops);
6289 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6290 but does NOT mention it nor update the global location list.
6291 This is useful if you need to fill more fields in the
6292 struct breakpoint before calling mention.
6294 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6295 If COND_STRING is not NULL, then store it in the breakpoint.
6296 OPS, if not NULL, is the breakpoint_ops structure associated
6297 to the catchpoint. */
6299 static struct breakpoint *
6300 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6302 struct breakpoint_ops *ops)
6304 struct symtab_and_line sal;
6305 struct breakpoint *b;
6308 sal.pspace = current_program_space;
6310 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6311 set_breakpoint_count (breakpoint_count + 1);
6312 b->number = breakpoint_count;
6314 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6316 b->addr_string = NULL;
6317 b->enable_state = bp_enabled;
6318 b->disposition = tempflag ? disp_del : disp_donttouch;
6324 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6326 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6327 If COND_STRING is not NULL, then store it in the breakpoint.
6328 OPS, if not NULL, is the breakpoint_ops structure associated
6329 to the catchpoint. */
6331 static struct breakpoint *
6332 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6333 char *cond_string, struct breakpoint_ops *ops)
6335 struct breakpoint *b =
6336 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6339 update_global_location_list (1);
6345 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6346 int tempflag, char *cond_string,
6347 struct breakpoint_ops *ops)
6349 struct breakpoint *b
6350 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6352 /* FIXME: We should put this information in a breakpoint private data
6354 b->forked_inferior_pid = null_ptid;
6357 /* Exec catchpoints. */
6360 insert_catch_exec (struct breakpoint *b)
6362 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6366 remove_catch_exec (struct breakpoint *b)
6368 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6372 breakpoint_hit_catch_exec (struct breakpoint *b)
6374 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6377 static enum print_stop_action
6378 print_it_catch_exec (struct breakpoint *b)
6380 annotate_catchpoint (b->number);
6381 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6383 return PRINT_SRC_AND_LOC;
6387 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6389 struct value_print_options opts;
6391 get_user_print_options (&opts);
6393 /* Field 4, the address, is omitted (which makes the columns
6394 not line up too nicely with the headers, but the effect
6395 is relatively readable). */
6396 if (opts.addressprint)
6397 ui_out_field_skip (uiout, "addr");
6399 ui_out_text (uiout, "exec");
6400 if (b->exec_pathname != NULL)
6402 ui_out_text (uiout, ", program \"");
6403 ui_out_field_string (uiout, "what", b->exec_pathname);
6404 ui_out_text (uiout, "\" ");
6409 print_mention_catch_exec (struct breakpoint *b)
6411 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6414 /* Implement the "print_recreate" breakpoint_ops method for exec
6418 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6420 fprintf_unfiltered (fp, "catch exec");
6423 static struct breakpoint_ops catch_exec_breakpoint_ops =
6427 breakpoint_hit_catch_exec,
6428 print_it_catch_exec,
6429 print_one_catch_exec,
6430 print_mention_catch_exec,
6431 print_recreate_catch_exec
6435 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6436 struct breakpoint_ops *ops)
6438 struct gdbarch *gdbarch = get_current_arch ();
6439 struct breakpoint *b =
6440 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6442 b->syscalls_to_be_caught = filter;
6444 /* Now, we have to mention the breakpoint and update the global
6447 update_global_location_list (1);
6451 hw_breakpoint_used_count (void)
6453 struct breakpoint *b;
6458 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6466 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6468 struct breakpoint *b;
6471 *other_type_used = 0;
6474 if (breakpoint_enabled (b))
6476 if (b->type == type)
6478 else if (is_hardware_watchpoint (b))
6479 *other_type_used = 1;
6486 disable_watchpoints_before_interactive_call_start (void)
6488 struct breakpoint *b;
6492 if (is_watchpoint (b) && breakpoint_enabled (b))
6494 b->enable_state = bp_call_disabled;
6495 update_global_location_list (0);
6501 enable_watchpoints_after_interactive_call_stop (void)
6503 struct breakpoint *b;
6507 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6509 b->enable_state = bp_enabled;
6510 update_global_location_list (1);
6516 disable_breakpoints_before_startup (void)
6518 struct breakpoint *b;
6523 if (b->pspace != current_program_space)
6526 if ((b->type == bp_breakpoint
6527 || b->type == bp_hardware_breakpoint)
6528 && breakpoint_enabled (b))
6530 b->enable_state = bp_startup_disabled;
6536 update_global_location_list (0);
6538 current_program_space->executing_startup = 1;
6542 enable_breakpoints_after_startup (void)
6544 struct breakpoint *b;
6547 current_program_space->executing_startup = 0;
6551 if (b->pspace != current_program_space)
6554 if ((b->type == bp_breakpoint
6555 || b->type == bp_hardware_breakpoint)
6556 && b->enable_state == bp_startup_disabled)
6558 b->enable_state = bp_enabled;
6564 breakpoint_re_set ();
6568 /* Set a breakpoint that will evaporate an end of command
6569 at address specified by SAL.
6570 Restrict it to frame FRAME if FRAME is nonzero. */
6573 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6574 struct frame_id frame_id, enum bptype type)
6576 struct breakpoint *b;
6578 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6580 gdb_assert (!frame_id_inlined_p (frame_id));
6582 b = set_raw_breakpoint (gdbarch, sal, type);
6583 b->enable_state = bp_enabled;
6584 b->disposition = disp_donttouch;
6585 b->frame_id = frame_id;
6587 /* If we're debugging a multi-threaded program, then we
6588 want momentary breakpoints to be active in only a
6589 single thread of control. */
6590 if (in_thread_list (inferior_ptid))
6591 b->thread = pid_to_thread_id (inferior_ptid);
6593 update_global_location_list_nothrow (1);
6598 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6602 clone_momentary_breakpoint (struct breakpoint *orig)
6604 struct breakpoint *copy;
6606 /* If there's nothing to clone, then return nothing. */
6610 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6611 copy->loc = allocate_bp_location (copy);
6612 set_breakpoint_location_function (copy->loc);
6614 copy->loc->gdbarch = orig->loc->gdbarch;
6615 copy->loc->requested_address = orig->loc->requested_address;
6616 copy->loc->address = orig->loc->address;
6617 copy->loc->section = orig->loc->section;
6618 copy->loc->pspace = orig->loc->pspace;
6620 if (orig->source_file == NULL)
6621 copy->source_file = NULL;
6623 copy->source_file = xstrdup (orig->source_file);
6625 copy->line_number = orig->line_number;
6626 copy->frame_id = orig->frame_id;
6627 copy->thread = orig->thread;
6628 copy->pspace = orig->pspace;
6630 copy->enable_state = bp_enabled;
6631 copy->disposition = disp_donttouch;
6632 copy->number = internal_breakpoint_number--;
6634 update_global_location_list_nothrow (0);
6639 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6642 struct symtab_and_line sal;
6644 sal = find_pc_line (pc, 0);
6646 sal.section = find_pc_overlay (pc);
6647 sal.explicit_pc = 1;
6649 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6653 /* Tell the user we have just set a breakpoint B. */
6656 mention (struct breakpoint *b)
6659 struct cleanup *ui_out_chain;
6660 struct value_print_options opts;
6662 get_user_print_options (&opts);
6664 /* FIXME: This is misplaced; mention() is called by things (like
6665 hitting a watchpoint) other than breakpoint creation. It should
6666 be possible to clean this up and at the same time replace the
6667 random calls to breakpoint_changed with this hook. */
6668 observer_notify_breakpoint_created (b->number);
6670 if (b->ops != NULL && b->ops->print_mention != NULL)
6671 b->ops->print_mention (b);
6676 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
6679 ui_out_text (uiout, "Watchpoint ");
6680 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6681 ui_out_field_int (uiout, "number", b->number);
6682 ui_out_text (uiout, ": ");
6683 ui_out_field_string (uiout, "exp", b->exp_string);
6684 do_cleanups (ui_out_chain);
6686 case bp_hardware_watchpoint:
6687 ui_out_text (uiout, "Hardware watchpoint ");
6688 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6689 ui_out_field_int (uiout, "number", b->number);
6690 ui_out_text (uiout, ": ");
6691 ui_out_field_string (uiout, "exp", b->exp_string);
6692 do_cleanups (ui_out_chain);
6694 case bp_read_watchpoint:
6695 ui_out_text (uiout, "Hardware read watchpoint ");
6696 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6697 ui_out_field_int (uiout, "number", b->number);
6698 ui_out_text (uiout, ": ");
6699 ui_out_field_string (uiout, "exp", b->exp_string);
6700 do_cleanups (ui_out_chain);
6702 case bp_access_watchpoint:
6703 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6704 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6705 ui_out_field_int (uiout, "number", b->number);
6706 ui_out_text (uiout, ": ");
6707 ui_out_field_string (uiout, "exp", b->exp_string);
6708 do_cleanups (ui_out_chain);
6711 if (ui_out_is_mi_like_p (uiout))
6716 if (b->disposition == disp_del)
6717 printf_filtered (_("Temporary breakpoint"));
6719 printf_filtered (_("Breakpoint"));
6720 printf_filtered (_(" %d"), b->number);
6723 case bp_hardware_breakpoint:
6724 if (ui_out_is_mi_like_p (uiout))
6729 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6733 if (ui_out_is_mi_like_p (uiout))
6738 printf_filtered (_("Tracepoint"));
6739 printf_filtered (_(" %d"), b->number);
6742 case bp_fast_tracepoint:
6743 if (ui_out_is_mi_like_p (uiout))
6748 printf_filtered (_("Fast tracepoint"));
6749 printf_filtered (_(" %d"), b->number);
6752 case bp_static_tracepoint:
6753 if (ui_out_is_mi_like_p (uiout))
6758 printf_filtered (_("Static tracepoint"));
6759 printf_filtered (_(" %d"), b->number);
6766 case bp_longjmp_resume:
6767 case bp_step_resume:
6769 case bp_std_terminate:
6770 case bp_watchpoint_scope:
6771 case bp_shlib_event:
6772 case bp_thread_event:
6773 case bp_overlay_event:
6775 case bp_longjmp_master:
6776 case bp_std_terminate_master:
6782 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6786 printf_filtered (_(" (%s) pending."), b->addr_string);
6790 if (opts.addressprint || b->source_file == NULL)
6792 printf_filtered (" at ");
6793 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
6797 printf_filtered (": file %s, line %d.",
6798 b->source_file, b->line_number);
6802 struct bp_location *loc = b->loc;
6804 for (; loc; loc = loc->next)
6806 printf_filtered (" (%d locations)", n);
6811 if (ui_out_is_mi_like_p (uiout))
6813 printf_filtered ("\n");
6817 static struct bp_location *
6818 add_location_to_breakpoint (struct breakpoint *b,
6819 const struct symtab_and_line *sal)
6821 struct bp_location *loc, **tmp;
6823 loc = allocate_bp_location (b);
6824 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
6827 loc->gdbarch = get_sal_arch (*sal);
6829 loc->gdbarch = b->gdbarch;
6830 loc->requested_address = sal->pc;
6831 loc->address = adjust_breakpoint_address (loc->gdbarch,
6832 loc->requested_address, b->type);
6833 loc->pspace = sal->pspace;
6834 gdb_assert (loc->pspace != NULL);
6835 loc->section = sal->section;
6837 set_breakpoint_location_function (loc);
6842 /* Return 1 if LOC is pointing to a permanent breakpoint,
6843 return 0 otherwise. */
6846 bp_loc_is_permanent (struct bp_location *loc)
6850 const gdb_byte *brk;
6851 gdb_byte *target_mem;
6852 struct cleanup *cleanup;
6855 gdb_assert (loc != NULL);
6857 addr = loc->address;
6858 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6860 /* Software breakpoints unsupported? */
6864 target_mem = alloca (len);
6866 /* Enable the automatic memory restoration from breakpoints while
6867 we read the memory. Otherwise we could say about our temporary
6868 breakpoints they are permanent. */
6869 cleanup = save_current_space_and_thread ();
6871 switch_to_program_space_and_thread (loc->pspace);
6872 make_show_memory_breakpoints_cleanup (0);
6874 if (target_read_memory (loc->address, target_mem, len) == 0
6875 && memcmp (target_mem, brk, len) == 0)
6878 do_cleanups (cleanup);
6885 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6886 as textual description of the location, and COND_STRING
6887 as condition expression. */
6890 create_breakpoint_sal (struct gdbarch *gdbarch,
6891 struct symtabs_and_lines sals, char *addr_string,
6893 enum bptype type, enum bpdisp disposition,
6894 int thread, int task, int ignore_count,
6895 struct breakpoint_ops *ops, int from_tty, int enabled)
6897 struct breakpoint *b = NULL;
6900 if (type == bp_hardware_breakpoint)
6902 int i = hw_breakpoint_used_count ();
6903 int target_resources_ok =
6904 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
6906 if (target_resources_ok == 0)
6907 error (_("No hardware breakpoint support in the target."));
6908 else if (target_resources_ok < 0)
6909 error (_("Hardware breakpoints used exceeds limit."));
6912 gdb_assert (sals.nelts > 0);
6914 for (i = 0; i < sals.nelts; ++i)
6916 struct symtab_and_line sal = sals.sals[i];
6917 struct bp_location *loc;
6921 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
6923 loc_gdbarch = gdbarch;
6925 describe_other_breakpoints (loc_gdbarch,
6926 sal.pspace, sal.pc, sal.section, thread);
6931 b = set_raw_breakpoint (gdbarch, sal, type);
6932 set_breakpoint_count (breakpoint_count + 1);
6933 b->number = breakpoint_count;
6937 b->cond_string = cond_string;
6938 b->ignore_count = ignore_count;
6939 b->enable_state = enabled ? bp_enabled : bp_disabled;
6940 b->disposition = disposition;
6941 b->pspace = sals.sals[0].pspace;
6943 if (type == bp_static_tracepoint)
6945 struct static_tracepoint_marker marker;
6947 if (is_marker_spec (addr_string))
6949 /* We already know the marker exists, otherwise, we
6950 wouldn't see a sal for it. */
6951 char *p = &addr_string[3];
6956 while (*p == ' ' || *p == '\t')
6960 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
6963 marker_str = savestring (p, endp - p);
6964 b->static_trace_marker_id = marker_str;
6966 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
6967 b->static_trace_marker_id);
6969 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
6971 b->static_trace_marker_id = xstrdup (marker.str_id);
6972 release_static_tracepoint_marker (&marker);
6974 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
6975 b->static_trace_marker_id);
6979 Couldn't determine the static tracepoint marker to probe"));
6982 if (enabled && b->pspace->executing_startup
6983 && (b->type == bp_breakpoint
6984 || b->type == bp_hardware_breakpoint))
6985 b->enable_state = bp_startup_disabled;
6991 loc = add_location_to_breakpoint (b, &sal);
6994 if (bp_loc_is_permanent (loc))
6995 make_breakpoint_permanent (b);
6999 char *arg = b->cond_string;
7000 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7002 error (_("Garbage %s follows condition"), arg);
7007 b->addr_string = addr_string;
7009 /* addr_string has to be used or breakpoint_re_set will delete
7012 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7018 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7019 elements to fill the void space. */
7021 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7023 int i = index_to_remove+1;
7024 int last_index = sal->nelts-1;
7026 for (;i <= last_index; ++i)
7027 sal->sals[i-1] = sal->sals[i];
7032 /* If appropriate, obtains all sals that correspond to the same file
7033 and line as SAL, in all program spaces. Users debugging with IDEs,
7034 will want to set a breakpoint at foo.c:line, and not really care
7035 about program spaces. This is done only if SAL does not have
7036 explicit PC and has line and file information. If we got just a
7037 single expanded sal, return the original.
7039 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7040 which the name of enclosing function is different from SAL. This
7041 makes sure that if we have breakpoint originally set in template
7042 instantiation, say foo<int>(), we won't expand SAL to locations at
7043 the same line in all existing instantiations of 'foo'. */
7045 static struct symtabs_and_lines
7046 expand_line_sal_maybe (struct symtab_and_line sal)
7048 struct symtabs_and_lines expanded;
7049 CORE_ADDR original_pc = sal.pc;
7050 char *original_function = NULL;
7053 struct cleanup *old_chain;
7055 /* If we have explicit pc, don't expand.
7056 If we have no line number, we can't expand. */
7057 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7060 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7061 expanded.sals[0] = sal;
7067 old_chain = save_current_space_and_thread ();
7069 switch_to_program_space_and_thread (sal.pspace);
7071 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7073 /* Note that expand_line_sal visits *all* program spaces. */
7074 expanded = expand_line_sal (sal);
7076 if (expanded.nelts == 1)
7078 /* We had one sal, we got one sal. Return that sal, adjusting it
7079 past the function prologue if necessary. */
7080 xfree (expanded.sals);
7082 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7083 sal.pc = original_pc;
7084 expanded.sals[0] = sal;
7085 skip_prologue_sal (&expanded.sals[0]);
7086 do_cleanups (old_chain);
7090 if (!sal.explicit_line)
7092 CORE_ADDR func_addr, func_end;
7093 for (i = 0; i < expanded.nelts; ++i)
7095 CORE_ADDR pc = expanded.sals[i].pc;
7096 char *this_function;
7098 /* We need to switch threads as well since we're about to
7100 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7102 if (find_pc_partial_function (pc, &this_function,
7103 &func_addr, &func_end))
7106 && strcmp (this_function, original_function) != 0)
7108 remove_sal (&expanded, i);
7115 /* Skip the function prologue if necessary. */
7116 for (i = 0; i < expanded.nelts; ++i)
7117 skip_prologue_sal (&expanded.sals[i]);
7119 do_cleanups (old_chain);
7121 if (expanded.nelts <= 1)
7123 /* This is un ugly workaround. If we get zero
7124 expanded sals then something is really wrong.
7125 Fix that by returnign the original sal. */
7126 xfree (expanded.sals);
7128 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7129 sal.pc = original_pc;
7130 expanded.sals[0] = sal;
7137 for (i = 0; i < expanded.nelts; ++i)
7138 if (expanded.sals[i].pc == original_pc)
7149 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7150 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7151 value. COND_STRING, if not NULL, specified the condition to be
7152 used for all breakpoints. Essentially the only case where
7153 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7154 function. In that case, it's still not possible to specify
7155 separate conditions for different overloaded functions, so
7156 we take just a single condition string.
7158 NOTE: If the function succeeds, the caller is expected to cleanup
7159 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7160 array contents). If the function fails (error() is called), the
7161 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7162 COND and SALS arrays and each of those arrays contents. */
7165 create_breakpoints_sal (struct gdbarch *gdbarch,
7166 struct symtabs_and_lines sals, char **addr_string,
7168 enum bptype type, enum bpdisp disposition,
7169 int thread, int task, int ignore_count,
7170 struct breakpoint_ops *ops, int from_tty,
7175 for (i = 0; i < sals.nelts; ++i)
7177 struct symtabs_and_lines expanded =
7178 expand_line_sal_maybe (sals.sals[i]);
7180 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7181 cond_string, type, disposition,
7182 thread, task, ignore_count, ops, from_tty, enabled);
7186 /* Parse ARG which is assumed to be a SAL specification possibly
7187 followed by conditionals. On return, SALS contains an array of SAL
7188 addresses found. ADDR_STRING contains a vector of (canonical)
7189 address strings. ARG points to the end of the SAL. */
7192 parse_breakpoint_sals (char **address,
7193 struct symtabs_and_lines *sals,
7194 char ***addr_string,
7197 char *addr_start = *address;
7199 *addr_string = NULL;
7200 /* If no arg given, or if first arg is 'if ', use the default
7202 if ((*address) == NULL
7203 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7205 if (default_breakpoint_valid)
7207 struct symtab_and_line sal;
7209 init_sal (&sal); /* initialize to zeroes */
7210 sals->sals = (struct symtab_and_line *)
7211 xmalloc (sizeof (struct symtab_and_line));
7212 sal.pc = default_breakpoint_address;
7213 sal.line = default_breakpoint_line;
7214 sal.symtab = default_breakpoint_symtab;
7215 sal.pspace = default_breakpoint_pspace;
7216 sal.section = find_pc_overlay (sal.pc);
7218 /* "break" without arguments is equivalent to "break *PC" where PC is
7219 the default_breakpoint_address. So make sure to set
7220 sal.explicit_pc to prevent GDB from trying to expand the list of
7221 sals to include all other instances with the same symtab and line.
7223 sal.explicit_pc = 1;
7225 sals->sals[0] = sal;
7229 error (_("No default breakpoint address now."));
7233 /* Force almost all breakpoints to be in terms of the
7234 current_source_symtab (which is decode_line_1's default). This
7235 should produce the results we want almost all of the time while
7236 leaving default_breakpoint_* alone.
7237 ObjC: However, don't match an Objective-C method name which
7238 may have a '+' or '-' succeeded by a '[' */
7240 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7242 if (default_breakpoint_valid
7244 || ((strchr ("+-", (*address)[0]) != NULL)
7245 && ((*address)[1] != '['))))
7246 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7247 default_breakpoint_line, addr_string,
7250 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7251 addr_string, not_found_ptr);
7253 /* For any SAL that didn't have a canonical string, fill one in. */
7254 if (sals->nelts > 0 && *addr_string == NULL)
7255 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7256 if (addr_start != (*address))
7260 for (i = 0; i < sals->nelts; i++)
7262 /* Add the string if not present. */
7263 if ((*addr_string)[i] == NULL)
7264 (*addr_string)[i] = savestring (addr_start,
7265 (*address) - addr_start);
7271 /* Convert each SAL into a real PC. Verify that the PC can be
7272 inserted as a breakpoint. If it can't throw an error. */
7275 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7279 for (i = 0; i < sals->nelts; i++)
7280 resolve_sal_pc (&sals->sals[i]);
7283 /* Fast tracepoints may have restrictions on valid locations. For
7284 instance, a fast tracepoint using a jump instead of a trap will
7285 likely have to overwrite more bytes than a trap would, and so can
7286 only be placed where the instruction is longer than the jump, or a
7287 multi-instruction sequence does not have a jump into the middle of
7291 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7292 struct symtabs_and_lines *sals)
7295 struct symtab_and_line *sal;
7297 struct cleanup *old_chain;
7299 for (i = 0; i < sals->nelts; i++)
7301 sal = &sals->sals[i];
7303 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7305 old_chain = make_cleanup (xfree, msg);
7308 error (_("May not have a fast tracepoint at 0x%s%s"),
7309 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7311 do_cleanups (old_chain);
7316 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7318 struct captured_parse_breakpoint_args *args = data;
7320 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7321 args->not_found_ptr);
7324 /* Given TOK, a string specification of condition and thread, as
7325 accepted by the 'break' command, extract the condition
7326 string and thread number and set *COND_STRING and *THREAD.
7327 PC identifies the context at which the condition should be parsed.
7328 If no condition is found, *COND_STRING is set to NULL.
7329 If no thread is found, *THREAD is set to -1. */
7331 find_condition_and_thread (char *tok, CORE_ADDR pc,
7332 char **cond_string, int *thread, int *task)
7334 *cond_string = NULL;
7340 char *cond_start = NULL;
7341 char *cond_end = NULL;
7343 while (*tok == ' ' || *tok == '\t')
7348 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7351 toklen = end_tok - tok;
7353 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7355 struct expression *expr;
7357 tok = cond_start = end_tok + 1;
7358 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7361 *cond_string = savestring (cond_start,
7362 cond_end - cond_start);
7364 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7370 *thread = strtol (tok, &tok, 0);
7372 error (_("Junk after thread keyword."));
7373 if (!valid_thread_id (*thread))
7374 error (_("Unknown thread %d."), *thread);
7376 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7382 *task = strtol (tok, &tok, 0);
7384 error (_("Junk after task keyword."));
7385 if (!valid_task_id (*task))
7386 error (_("Unknown task %d."), *task);
7389 error (_("Junk at end of arguments."));
7393 /* Decode a static tracepoint marker spec. */
7395 static struct symtabs_and_lines
7396 decode_static_tracepoint_spec (char **arg_p)
7398 VEC(static_tracepoint_marker_p) *markers = NULL;
7399 struct symtabs_and_lines sals;
7400 struct symtab_and_line sal;
7402 struct cleanup *old_chain;
7403 char *p = &(*arg_p)[3];
7408 while (*p == ' ' || *p == '\t')
7412 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7415 marker_str = savestring (p, endp - p);
7416 old_chain = make_cleanup (xfree, marker_str);
7418 markers = target_static_tracepoint_markers_by_strid (marker_str);
7419 if (VEC_empty(static_tracepoint_marker_p, markers))
7420 error (_("No known static tracepoint marker named %s"), marker_str);
7422 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7423 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7425 for (i = 0; i < sals.nelts; i++)
7427 struct static_tracepoint_marker *marker;
7429 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7431 init_sal (&sals.sals[i]);
7433 sals.sals[i] = find_pc_line (marker->address, 0);
7434 sals.sals[i].pc = marker->address;
7436 release_static_tracepoint_marker (marker);
7439 do_cleanups (old_chain);
7445 /* Set a breakpoint. This function is shared between CLI and MI
7446 functions for setting a breakpoint. This function has two major
7447 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7448 parameter. If non-zero, the function will parse arg, extracting
7449 breakpoint location, address and thread. Otherwise, ARG is just the
7450 location of breakpoint, with condition and thread specified by the
7451 COND_STRING and THREAD parameters. Returns true if any breakpoint
7452 was created; false otherwise. */
7455 create_breakpoint (struct gdbarch *gdbarch,
7456 char *arg, char *cond_string, int thread,
7457 int parse_condition_and_thread,
7458 int tempflag, enum bptype type_wanted,
7460 enum auto_boolean pending_break_support,
7461 struct breakpoint_ops *ops,
7465 struct gdb_exception e;
7466 struct symtabs_and_lines sals;
7467 struct symtab_and_line pending_sal;
7469 char *addr_start = arg;
7471 struct cleanup *old_chain;
7472 struct cleanup *bkpt_chain = NULL;
7473 struct captured_parse_breakpoint_args parse_args;
7478 int prev_bkpt_count = breakpoint_count;
7484 parse_args.arg_p = &arg;
7485 parse_args.sals_p = &sals;
7486 parse_args.addr_string_p = &addr_string;
7487 parse_args.not_found_ptr = ¬_found;
7489 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7493 sals = decode_static_tracepoint_spec (&arg);
7495 copy_arg = savestring (addr_start, arg - addr_start);
7496 addr_string = xcalloc (sals.nelts, sizeof (char **));
7497 for (i = 0; i < sals.nelts; i++)
7498 addr_string[i] = xstrdup (copy_arg);
7502 e = catch_exception (uiout, do_captured_parse_breakpoint,
7503 &parse_args, RETURN_MASK_ALL);
7505 /* If caller is interested in rc value from parse, set value. */
7509 throw_exception (e);
7513 case NOT_FOUND_ERROR:
7515 /* If pending breakpoint support is turned off, throw
7518 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7519 throw_exception (e);
7521 exception_print (gdb_stderr, e);
7523 /* If pending breakpoint support is auto query and the user
7524 selects no, then simply return the error code. */
7525 if (pending_break_support == AUTO_BOOLEAN_AUTO
7526 && !nquery ("Make breakpoint pending on future shared library load? "))
7529 /* At this point, either the user was queried about setting
7530 a pending breakpoint and selected yes, or pending
7531 breakpoint behavior is on and thus a pending breakpoint
7532 is defaulted on behalf of the user. */
7533 copy_arg = xstrdup (addr_start);
7534 addr_string = ©_arg;
7536 sals.sals = &pending_sal;
7541 throw_exception (e);
7550 /* Create a chain of things that always need to be cleaned up. */
7551 old_chain = make_cleanup (null_cleanup, 0);
7555 /* Make sure that all storage allocated to SALS gets freed. */
7556 make_cleanup (xfree, sals.sals);
7558 /* Cleanup the addr_string array but not its contents. */
7559 make_cleanup (xfree, addr_string);
7562 /* ----------------------------- SNIP -----------------------------
7563 Anything added to the cleanup chain beyond this point is assumed
7564 to be part of a breakpoint. If the breakpoint create succeeds
7565 then the memory is not reclaimed. */
7566 bkpt_chain = make_cleanup (null_cleanup, 0);
7568 /* Mark the contents of the addr_string for cleanup. These go on
7569 the bkpt_chain and only occur if the breakpoint create fails. */
7570 for (i = 0; i < sals.nelts; i++)
7572 if (addr_string[i] != NULL)
7573 make_cleanup (xfree, addr_string[i]);
7576 /* Resolve all line numbers to PC's and verify that the addresses
7577 are ok for the target. */
7579 breakpoint_sals_to_pc (&sals);
7581 /* Fast tracepoints may have additional restrictions on location. */
7582 if (type_wanted == bp_fast_tracepoint)
7583 check_fast_tracepoint_sals (gdbarch, &sals);
7585 /* Verify that condition can be parsed, before setting any
7586 breakpoints. Allocate a separate condition expression for each
7590 if (parse_condition_and_thread)
7592 /* Here we only parse 'arg' to separate condition
7593 from thread number, so parsing in context of first
7594 sal is OK. When setting the breakpoint we'll
7595 re-parse it in context of each sal. */
7598 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7601 make_cleanup (xfree, cond_string);
7605 /* Create a private copy of condition string. */
7608 cond_string = xstrdup (cond_string);
7609 make_cleanup (xfree, cond_string);
7613 /* If the user is creating a static tracepoint by marker id
7614 (strace -m MARKER_ID), then store the sals index, so that
7615 breakpoint_re_set can try to match up which of the newly
7616 found markers corresponds to this one, and, don't try to
7617 expand multiple locations for each sal, given than SALS
7618 already should contain all sals for MARKER_ID. */
7619 if (type_wanted == bp_static_tracepoint
7620 && is_marker_spec (addr_string[0]))
7624 for (i = 0; i < sals.nelts; ++i)
7626 struct symtabs_and_lines expanded;
7627 struct breakpoint *tp;
7628 struct cleanup *old_chain;
7631 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7632 expanded.sals[0] = sals.sals[i];
7633 old_chain = make_cleanup (xfree, expanded.sals);
7635 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7636 cond_string, type_wanted,
7637 tempflag ? disp_del : disp_donttouch,
7638 thread, task, ignore_count, ops,
7641 do_cleanups (old_chain);
7643 /* Get the tracepoint we just created. */
7644 tp = get_breakpoint (breakpoint_count);
7645 gdb_assert (tp != NULL);
7647 /* Given that its possible to have multiple markers with
7648 the same string id, if the user is creating a static
7649 tracepoint by marker id ("strace -m MARKER_ID"), then
7650 store the sals index, so that breakpoint_re_set can
7651 try to match up which of the newly found markers
7652 corresponds to this one */
7653 tp->static_trace_marker_id_idx = i;
7657 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7658 type_wanted, tempflag ? disp_del : disp_donttouch,
7659 thread, task, ignore_count, ops, from_tty,
7664 struct breakpoint *b;
7666 make_cleanup (xfree, copy_arg);
7668 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7669 set_breakpoint_count (breakpoint_count + 1);
7670 b->number = breakpoint_count;
7672 b->addr_string = addr_string[0];
7673 b->cond_string = NULL;
7674 b->ignore_count = ignore_count;
7675 b->disposition = tempflag ? disp_del : disp_donttouch;
7676 b->condition_not_parsed = 1;
7678 b->enable_state = enabled ? bp_enabled : bp_disabled;
7679 b->pspace = current_program_space;
7681 if (enabled && b->pspace->executing_startup
7682 && (b->type == bp_breakpoint
7683 || b->type == bp_hardware_breakpoint))
7684 b->enable_state = bp_startup_disabled;
7691 warning (_("Multiple breakpoints were set.\n"
7692 "Use the \"delete\" command to delete unwanted breakpoints."));
7693 prev_breakpoint_count = prev_bkpt_count;
7696 /* That's it. Discard the cleanups for data inserted into the
7698 discard_cleanups (bkpt_chain);
7699 /* But cleanup everything else. */
7700 do_cleanups (old_chain);
7702 /* error call may happen here - have BKPT_CHAIN already discarded. */
7703 update_global_location_list (1);
7708 /* Set a breakpoint.
7709 ARG is a string describing breakpoint address,
7710 condition, and thread.
7711 FLAG specifies if a breakpoint is hardware on,
7712 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7716 break_command_1 (char *arg, int flag, int from_tty)
7718 int tempflag = flag & BP_TEMPFLAG;
7719 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
7720 ? bp_hardware_breakpoint
7723 create_breakpoint (get_current_arch (),
7725 NULL, 0, 1 /* parse arg */,
7726 tempflag, type_wanted,
7727 0 /* Ignore count */,
7728 pending_break_support,
7729 NULL /* breakpoint_ops */,
7735 /* Helper function for break_command_1 and disassemble_command. */
7738 resolve_sal_pc (struct symtab_and_line *sal)
7742 if (sal->pc == 0 && sal->symtab != NULL)
7744 if (!find_line_pc (sal->symtab, sal->line, &pc))
7745 error (_("No line %d in file \"%s\"."),
7746 sal->line, sal->symtab->filename);
7749 /* If this SAL corresponds to a breakpoint inserted using
7750 a line number, then skip the function prologue if necessary. */
7751 if (sal->explicit_line)
7752 skip_prologue_sal (sal);
7755 if (sal->section == 0 && sal->symtab != NULL)
7757 struct blockvector *bv;
7761 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7764 sym = block_linkage_function (b);
7767 fixup_symbol_section (sym, sal->symtab->objfile);
7768 sal->section = SYMBOL_OBJ_SECTION (sym);
7772 /* It really is worthwhile to have the section, so we'll just
7773 have to look harder. This case can be executed if we have
7774 line numbers but no functions (as can happen in assembly
7777 struct minimal_symbol *msym;
7778 struct cleanup *old_chain = save_current_space_and_thread ();
7780 switch_to_program_space_and_thread (sal->pspace);
7782 msym = lookup_minimal_symbol_by_pc (sal->pc);
7784 sal->section = SYMBOL_OBJ_SECTION (msym);
7786 do_cleanups (old_chain);
7793 break_command (char *arg, int from_tty)
7795 break_command_1 (arg, 0, from_tty);
7799 tbreak_command (char *arg, int from_tty)
7801 break_command_1 (arg, BP_TEMPFLAG, from_tty);
7805 hbreak_command (char *arg, int from_tty)
7807 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
7811 thbreak_command (char *arg, int from_tty)
7813 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
7817 stop_command (char *arg, int from_tty)
7819 printf_filtered (_("Specify the type of breakpoint to set.\n\
7820 Usage: stop in <function | address>\n\
7821 stop at <line>\n"));
7825 stopin_command (char *arg, int from_tty)
7829 if (arg == (char *) NULL)
7831 else if (*arg != '*')
7836 /* look for a ':'. If this is a line number specification, then
7837 say it is bad, otherwise, it should be an address or
7838 function/method name */
7839 while (*argptr && !hasColon)
7841 hasColon = (*argptr == ':');
7846 badInput = (*argptr != ':'); /* Not a class::method */
7848 badInput = isdigit (*arg); /* a simple line number */
7852 printf_filtered (_("Usage: stop in <function | address>\n"));
7854 break_command_1 (arg, 0, from_tty);
7858 stopat_command (char *arg, int from_tty)
7862 if (arg == (char *) NULL || *arg == '*') /* no line number */
7869 /* look for a ':'. If there is a '::' then get out, otherwise
7870 it is probably a line number. */
7871 while (*argptr && !hasColon)
7873 hasColon = (*argptr == ':');
7878 badInput = (*argptr == ':'); /* we have class::method */
7880 badInput = !isdigit (*arg); /* not a line number */
7884 printf_filtered (_("Usage: stop at <line>\n"));
7886 break_command_1 (arg, 0, from_tty);
7889 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
7890 variable. Also the constant detection may fail for some constant
7891 expressions and in such case still falsely return zero. */
7893 watchpoint_exp_is_const (const struct expression *exp)
7901 /* We are only interested in the descriptor of each element. */
7902 operator_length (exp, i, &oplenp, &argsp);
7905 switch (exp->elts[i].opcode)
7915 case BINOP_LOGICAL_AND:
7916 case BINOP_LOGICAL_OR:
7917 case BINOP_BITWISE_AND:
7918 case BINOP_BITWISE_IOR:
7919 case BINOP_BITWISE_XOR:
7921 case BINOP_NOTEQUAL:
7937 case TERNOP_SLICE_COUNT:
7949 case OP_OBJC_NSSTRING:
7952 case UNOP_LOGICAL_NOT:
7953 case UNOP_COMPLEMENT:
7956 /* Unary, binary and ternary operators: We have to check their
7957 operands. If they are constant, then so is the result of
7958 that operation. For instance, if A and B are determined to be
7959 constants, then so is "A + B".
7961 UNOP_IND is one exception to the rule above, because the value
7962 of *ADDR is not necessarily a constant, even when ADDR is. */
7966 /* Check whether the associated symbol is a constant.
7967 We use SYMBOL_CLASS rather than TYPE_CONST because it's
7968 possible that a buggy compiler could mark a variable as constant
7969 even when it is not, and TYPE_CONST would return true in this
7970 case, while SYMBOL_CLASS wouldn't.
7971 We also have to check for function symbols because they are
7974 struct symbol *s = exp->elts[i + 2].symbol;
7976 if (SYMBOL_CLASS (s) != LOC_BLOCK
7977 && SYMBOL_CLASS (s) != LOC_CONST
7978 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
7983 /* The default action is to return 0 because we are using
7984 the optimistic approach here: If we don't know something,
7985 then it is not a constant. */
7994 /* accessflag: hw_write: watch write,
7995 hw_read: watch read,
7996 hw_access: watch access (read or write) */
7998 watch_command_1 (char *arg, int accessflag, int from_tty)
8000 struct breakpoint *b, *scope_breakpoint = NULL;
8001 struct expression *exp;
8002 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
8003 struct value *val, *mark;
8004 struct frame_info *frame;
8005 char *exp_start = NULL;
8006 char *exp_end = NULL;
8007 char *tok, *id_tok_start, *end_tok;
8009 char *cond_start = NULL;
8010 char *cond_end = NULL;
8011 int i, other_type_used, target_resources_ok = 0;
8012 enum bptype bp_type;
8017 /* Make sure that we actually have parameters to parse. */
8018 if (arg != NULL && arg[0] != '\0')
8020 toklen = strlen (arg); /* Size of argument list. */
8022 /* Points tok to the end of the argument list. */
8023 tok = arg + toklen - 1;
8025 /* Go backwards in the parameters list. Skip the last parameter.
8026 If we're expecting a 'thread <thread_num>' parameter, this should
8027 be the thread identifier. */
8028 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8030 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8033 /* Points end_tok to the beginning of the last token. */
8034 id_tok_start = tok + 1;
8036 /* Go backwards in the parameters list. Skip one more parameter.
8037 If we're expecting a 'thread <thread_num>' parameter, we should
8038 reach a "thread" token. */
8039 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8044 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8047 /* Move the pointer forward to skip the whitespace and
8048 calculate the length of the token. */
8050 toklen = end_tok - tok;
8052 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8054 /* At this point we've found a "thread" token, which means
8055 the user is trying to set a watchpoint that triggers
8056 only in a specific thread. */
8059 /* Extract the thread ID from the next token. */
8060 thread = strtol (id_tok_start, &endp, 0);
8062 /* Check if the user provided a valid numeric value for the
8064 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
8065 error (_("Invalid thread ID specification %s."), id_tok_start);
8067 /* Check if the thread actually exists. */
8068 if (!valid_thread_id (thread))
8069 error (_("Unknown thread %d."), thread);
8071 /* Truncate the string and get rid of the thread <thread_num>
8072 parameter before the parameter list is parsed by the
8073 evaluate_expression() function. */
8078 /* Parse the rest of the arguments. */
8079 innermost_block = NULL;
8081 exp = parse_exp_1 (&arg, 0, 0);
8083 /* Remove trailing whitespace from the expression before saving it.
8084 This makes the eventual display of the expression string a bit
8086 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
8089 /* Checking if the expression is not constant. */
8090 if (watchpoint_exp_is_const (exp))
8094 len = exp_end - exp_start;
8095 while (len > 0 && isspace (exp_start[len - 1]))
8097 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
8100 exp_valid_block = innermost_block;
8101 mark = value_mark ();
8102 fetch_subexp_value (exp, &pc, &val, NULL, NULL);
8104 release_value (val);
8107 while (*tok == ' ' || *tok == '\t')
8111 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
8114 toklen = end_tok - tok;
8115 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8117 struct expression *cond;
8119 innermost_block = NULL;
8120 tok = cond_start = end_tok + 1;
8121 cond = parse_exp_1 (&tok, 0, 0);
8123 /* The watchpoint expression may not be local, but the condition
8124 may still be. E.g.: `watch global if local > 0'. */
8125 cond_exp_valid_block = innermost_block;
8131 error (_("Junk at end of command."));
8133 if (accessflag == hw_read)
8134 bp_type = bp_read_watchpoint;
8135 else if (accessflag == hw_access)
8136 bp_type = bp_access_watchpoint;
8138 bp_type = bp_hardware_watchpoint;
8140 mem_cnt = can_use_hardware_watchpoint (val);
8141 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
8142 error (_("Expression cannot be implemented with read/access watchpoint."));
8145 i = hw_watchpoint_used_count (bp_type, &other_type_used);
8146 target_resources_ok =
8147 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
8149 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8150 error (_("Target does not support this type of hardware watchpoint."));
8152 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8153 error (_("Target can only support one kind of HW watchpoint at a time."));
8156 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8157 watchpoint could not be set. */
8158 if (!mem_cnt || target_resources_ok <= 0)
8159 bp_type = bp_watchpoint;
8161 frame = block_innermost_frame (exp_valid_block);
8163 /* If the expression is "local", then set up a "watchpoint scope"
8164 breakpoint at the point where we've left the scope of the watchpoint
8165 expression. Create the scope breakpoint before the watchpoint, so
8166 that we will encounter it first in bpstat_stop_status. */
8167 if (exp_valid_block && frame)
8169 if (frame_id_p (frame_unwind_caller_id (frame)))
8172 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
8173 frame_unwind_caller_pc (frame),
8174 bp_watchpoint_scope);
8176 scope_breakpoint->enable_state = bp_enabled;
8178 /* Automatically delete the breakpoint when it hits. */
8179 scope_breakpoint->disposition = disp_del;
8181 /* Only break in the proper frame (help with recursion). */
8182 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
8184 /* Set the address at which we will stop. */
8185 scope_breakpoint->loc->gdbarch
8186 = frame_unwind_caller_arch (frame);
8187 scope_breakpoint->loc->requested_address
8188 = frame_unwind_caller_pc (frame);
8189 scope_breakpoint->loc->address
8190 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
8191 scope_breakpoint->loc->requested_address,
8192 scope_breakpoint->type);
8196 /* Now set up the breakpoint. */
8197 b = set_raw_breakpoint_without_location (NULL, bp_type);
8198 set_breakpoint_count (breakpoint_count + 1);
8199 b->number = breakpoint_count;
8201 b->disposition = disp_donttouch;
8203 b->exp_valid_block = exp_valid_block;
8204 b->cond_exp_valid_block = cond_exp_valid_block;
8205 b->exp_string = savestring (exp_start, exp_end - exp_start);
8209 b->cond_string = savestring (cond_start, cond_end - cond_start);
8215 b->watchpoint_frame = get_frame_id (frame);
8216 b->watchpoint_thread = inferior_ptid;
8220 b->watchpoint_frame = null_frame_id;
8221 b->watchpoint_thread = null_ptid;
8224 if (scope_breakpoint != NULL)
8226 /* The scope breakpoint is related to the watchpoint. We will
8227 need to act on them together. */
8228 b->related_breakpoint = scope_breakpoint;
8229 scope_breakpoint->related_breakpoint = b;
8232 value_free_to_mark (mark);
8234 /* Finally update the new watchpoint. This creates the locations
8235 that should be inserted. */
8236 update_watchpoint (b, 1);
8239 update_global_location_list (1);
8242 /* Return count of locations need to be watched and can be handled
8243 in hardware. If the watchpoint can not be handled
8244 in hardware return zero. */
8247 can_use_hardware_watchpoint (struct value *v)
8249 int found_memory_cnt = 0;
8250 struct value *head = v;
8252 /* Did the user specifically forbid us to use hardware watchpoints? */
8253 if (!can_use_hw_watchpoints)
8256 /* Make sure that the value of the expression depends only upon
8257 memory contents, and values computed from them within GDB. If we
8258 find any register references or function calls, we can't use a
8259 hardware watchpoint.
8261 The idea here is that evaluating an expression generates a series
8262 of values, one holding the value of every subexpression. (The
8263 expression a*b+c has five subexpressions: a, b, a*b, c, and
8264 a*b+c.) GDB's values hold almost enough information to establish
8265 the criteria given above --- they identify memory lvalues,
8266 register lvalues, computed values, etcetera. So we can evaluate
8267 the expression, and then scan the chain of values that leaves
8268 behind to decide whether we can detect any possible change to the
8269 expression's final value using only hardware watchpoints.
8271 However, I don't think that the values returned by inferior
8272 function calls are special in any way. So this function may not
8273 notice that an expression involving an inferior function call
8274 can't be watched with hardware watchpoints. FIXME. */
8275 for (; v; v = value_next (v))
8277 if (VALUE_LVAL (v) == lval_memory)
8280 /* A lazy memory lvalue is one that GDB never needed to fetch;
8281 we either just used its address (e.g., `a' in `a.b') or
8282 we never needed it at all (e.g., `a' in `a,b'). */
8286 /* Ahh, memory we actually used! Check if we can cover
8287 it with hardware watchpoints. */
8288 struct type *vtype = check_typedef (value_type (v));
8290 /* We only watch structs and arrays if user asked for it
8291 explicitly, never if they just happen to appear in a
8292 middle of some value chain. */
8294 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
8295 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
8297 CORE_ADDR vaddr = value_address (v);
8298 int len = TYPE_LENGTH (value_type (v));
8300 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
8307 else if (VALUE_LVAL (v) != not_lval
8308 && deprecated_value_modifiable (v) == 0)
8309 return 0; /* These are values from the history (e.g., $1). */
8310 else if (VALUE_LVAL (v) == lval_register)
8311 return 0; /* Cannot watch a register with a HW watchpoint. */
8314 /* The expression itself looks suitable for using a hardware
8315 watchpoint, but give the target machine a chance to reject it. */
8316 return found_memory_cnt;
8320 watch_command_wrapper (char *arg, int from_tty)
8322 watch_command (arg, from_tty);
8326 watch_command (char *arg, int from_tty)
8328 watch_command_1 (arg, hw_write, from_tty);
8332 rwatch_command_wrapper (char *arg, int from_tty)
8334 rwatch_command (arg, from_tty);
8338 rwatch_command (char *arg, int from_tty)
8340 watch_command_1 (arg, hw_read, from_tty);
8344 awatch_command_wrapper (char *arg, int from_tty)
8346 awatch_command (arg, from_tty);
8350 awatch_command (char *arg, int from_tty)
8352 watch_command_1 (arg, hw_access, from_tty);
8356 /* Helper routines for the until_command routine in infcmd.c. Here
8357 because it uses the mechanisms of breakpoints. */
8359 struct until_break_command_continuation_args
8361 struct breakpoint *breakpoint;
8362 struct breakpoint *breakpoint2;
8365 /* This function is called by fetch_inferior_event via the
8366 cmd_continuation pointer, to complete the until command. It takes
8367 care of cleaning up the temporary breakpoints set up by the until
8370 until_break_command_continuation (void *arg)
8372 struct until_break_command_continuation_args *a = arg;
8374 delete_breakpoint (a->breakpoint);
8376 delete_breakpoint (a->breakpoint2);
8380 until_break_command (char *arg, int from_tty, int anywhere)
8382 struct symtabs_and_lines sals;
8383 struct symtab_and_line sal;
8384 struct frame_info *frame = get_selected_frame (NULL);
8385 struct breakpoint *breakpoint;
8386 struct breakpoint *breakpoint2 = NULL;
8387 struct cleanup *old_chain;
8389 clear_proceed_status ();
8391 /* Set a breakpoint where the user wants it and at return from
8394 if (default_breakpoint_valid)
8395 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8396 default_breakpoint_line, (char ***) NULL, NULL);
8398 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8399 0, (char ***) NULL, NULL);
8401 if (sals.nelts != 1)
8402 error (_("Couldn't get information on specified line."));
8405 xfree (sals.sals); /* malloc'd, so freed */
8408 error (_("Junk at end of arguments."));
8410 resolve_sal_pc (&sal);
8413 /* If the user told us to continue until a specified location,
8414 we don't specify a frame at which we need to stop. */
8415 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8416 null_frame_id, bp_until);
8418 /* Otherwise, specify the selected frame, because we want to stop only
8419 at the very same frame. */
8420 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8421 get_stack_frame_id (frame),
8424 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8426 /* Keep within the current frame, or in frames called by the current
8429 if (frame_id_p (frame_unwind_caller_id (frame)))
8431 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8432 sal.pc = frame_unwind_caller_pc (frame);
8433 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8435 frame_unwind_caller_id (frame),
8437 make_cleanup_delete_breakpoint (breakpoint2);
8440 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8442 /* If we are running asynchronously, and proceed call above has actually
8443 managed to start the target, arrange for breakpoints to be
8444 deleted when the target stops. Otherwise, we're already stopped and
8445 delete breakpoints via cleanup chain. */
8447 if (target_can_async_p () && is_running (inferior_ptid))
8449 struct until_break_command_continuation_args *args;
8450 args = xmalloc (sizeof (*args));
8452 args->breakpoint = breakpoint;
8453 args->breakpoint2 = breakpoint2;
8455 discard_cleanups (old_chain);
8456 add_continuation (inferior_thread (),
8457 until_break_command_continuation, args,
8461 do_cleanups (old_chain);
8465 ep_skip_leading_whitespace (char **s)
8467 if ((s == NULL) || (*s == NULL))
8469 while (isspace (**s))
8473 /* This function attempts to parse an optional "if <cond>" clause
8474 from the arg string. If one is not found, it returns NULL.
8476 Else, it returns a pointer to the condition string. (It does not
8477 attempt to evaluate the string against a particular block.) And,
8478 it updates arg to point to the first character following the parsed
8479 if clause in the arg string. */
8482 ep_parse_optional_if_clause (char **arg)
8486 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8489 /* Skip the "if" keyword. */
8492 /* Skip any extra leading whitespace, and record the start of the
8493 condition string. */
8494 ep_skip_leading_whitespace (arg);
8497 /* Assume that the condition occupies the remainder of the arg string. */
8498 (*arg) += strlen (cond_string);
8503 /* Commands to deal with catching events, such as signals, exceptions,
8504 process start/exit, etc. */
8508 catch_fork_temporary, catch_vfork_temporary,
8509 catch_fork_permanent, catch_vfork_permanent
8514 catch_fork_command_1 (char *arg, int from_tty,
8515 struct cmd_list_element *command)
8517 struct gdbarch *gdbarch = get_current_arch ();
8518 char *cond_string = NULL;
8519 catch_fork_kind fork_kind;
8522 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8523 tempflag = (fork_kind == catch_fork_temporary
8524 || fork_kind == catch_vfork_temporary);
8528 ep_skip_leading_whitespace (&arg);
8530 /* The allowed syntax is:
8532 catch [v]fork if <cond>
8534 First, check if there's an if clause. */
8535 cond_string = ep_parse_optional_if_clause (&arg);
8537 if ((*arg != '\0') && !isspace (*arg))
8538 error (_("Junk at end of arguments."));
8540 /* If this target supports it, create a fork or vfork catchpoint
8541 and enable reporting of such events. */
8544 case catch_fork_temporary:
8545 case catch_fork_permanent:
8546 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8547 &catch_fork_breakpoint_ops);
8549 case catch_vfork_temporary:
8550 case catch_vfork_permanent:
8551 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8552 &catch_vfork_breakpoint_ops);
8555 error (_("unsupported or unknown fork kind; cannot catch it"));
8561 catch_exec_command_1 (char *arg, int from_tty,
8562 struct cmd_list_element *command)
8564 struct gdbarch *gdbarch = get_current_arch ();
8566 char *cond_string = NULL;
8568 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8572 ep_skip_leading_whitespace (&arg);
8574 /* The allowed syntax is:
8576 catch exec if <cond>
8578 First, check if there's an if clause. */
8579 cond_string = ep_parse_optional_if_clause (&arg);
8581 if ((*arg != '\0') && !isspace (*arg))
8582 error (_("Junk at end of arguments."));
8584 /* If this target supports it, create an exec catchpoint
8585 and enable reporting of such events. */
8586 create_catchpoint (gdbarch, tempflag, cond_string,
8587 &catch_exec_breakpoint_ops);
8590 static enum print_stop_action
8591 print_exception_catchpoint (struct breakpoint *b)
8593 int bp_temp, bp_throw;
8595 annotate_catchpoint (b->number);
8597 bp_throw = strstr (b->addr_string, "throw") != NULL;
8598 if (b->loc->address != b->loc->requested_address)
8599 breakpoint_adjustment_warning (b->loc->requested_address,
8602 bp_temp = b->disposition == disp_del;
8604 bp_temp ? "Temporary catchpoint "
8606 if (!ui_out_is_mi_like_p (uiout))
8607 ui_out_field_int (uiout, "bkptno", b->number);
8609 bp_throw ? " (exception thrown), "
8610 : " (exception caught), ");
8611 if (ui_out_is_mi_like_p (uiout))
8613 ui_out_field_string (uiout, "reason",
8614 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8615 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8616 ui_out_field_int (uiout, "bkptno", b->number);
8618 return PRINT_SRC_AND_LOC;
8622 print_one_exception_catchpoint (struct breakpoint *b,
8623 struct bp_location **last_loc)
8625 struct value_print_options opts;
8627 get_user_print_options (&opts);
8628 if (opts.addressprint)
8631 if (b->loc == NULL || b->loc->shlib_disabled)
8632 ui_out_field_string (uiout, "addr", "<PENDING>");
8634 ui_out_field_core_addr (uiout, "addr",
8635 b->loc->gdbarch, b->loc->address);
8640 if (strstr (b->addr_string, "throw") != NULL)
8641 ui_out_field_string (uiout, "what", "exception throw");
8643 ui_out_field_string (uiout, "what", "exception catch");
8647 print_mention_exception_catchpoint (struct breakpoint *b)
8652 bp_temp = b->disposition == disp_del;
8653 bp_throw = strstr (b->addr_string, "throw") != NULL;
8654 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
8655 : _("Catchpoint "));
8656 ui_out_field_int (uiout, "bkptno", b->number);
8657 ui_out_text (uiout, bp_throw ? _(" (throw)")
8661 /* Implement the "print_recreate" breakpoint_ops method for throw and
8662 catch catchpoints. */
8665 print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
8670 bp_temp = b->disposition == disp_del;
8671 bp_throw = strstr (b->addr_string, "throw") != NULL;
8672 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
8673 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
8676 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
8679 NULL, /* breakpoint_hit */
8680 print_exception_catchpoint,
8681 print_one_exception_catchpoint,
8682 print_mention_exception_catchpoint,
8683 print_recreate_exception_catchpoint
8687 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
8688 enum exception_event_kind ex_event, int from_tty)
8690 char *trigger_func_name;
8692 if (ex_event == EX_EVENT_CATCH)
8693 trigger_func_name = "__cxa_begin_catch";
8695 trigger_func_name = "__cxa_throw";
8697 create_breakpoint (get_current_arch (),
8698 trigger_func_name, cond_string, -1,
8699 0 /* condition and thread are valid. */,
8700 tempflag, bp_breakpoint,
8702 AUTO_BOOLEAN_TRUE /* pending */,
8703 &gnu_v3_exception_catchpoint_ops, from_tty,
8709 /* Deal with "catch catch" and "catch throw" commands */
8712 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
8713 int tempflag, int from_tty)
8715 char *cond_string = NULL;
8719 ep_skip_leading_whitespace (&arg);
8721 cond_string = ep_parse_optional_if_clause (&arg);
8723 if ((*arg != '\0') && !isspace (*arg))
8724 error (_("Junk at end of arguments."));
8726 if (ex_event != EX_EVENT_THROW
8727 && ex_event != EX_EVENT_CATCH)
8728 error (_("Unsupported or unknown exception event; cannot catch it"));
8730 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
8733 warning (_("Unsupported with this platform/compiler combination."));
8736 /* Implementation of "catch catch" command. */
8739 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
8741 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8743 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
8746 /* Implementation of "catch throw" command. */
8749 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
8751 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8753 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
8756 /* Create a breakpoint struct for Ada exception catchpoints. */
8759 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
8760 struct symtab_and_line sal,
8764 struct expression *cond,
8765 struct breakpoint_ops *ops,
8769 struct breakpoint *b;
8773 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8775 loc_gdbarch = gdbarch;
8777 describe_other_breakpoints (loc_gdbarch,
8778 sal.pspace, sal.pc, sal.section, -1);
8779 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8780 version for exception catchpoints, because two catchpoints
8781 used for different exception names will use the same address.
8782 In this case, a "breakpoint ... also set at..." warning is
8783 unproductive. Besides. the warning phrasing is also a bit
8784 inapropriate, we should use the word catchpoint, and tell
8785 the user what type of catchpoint it is. The above is good
8786 enough for now, though. */
8789 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
8790 set_breakpoint_count (breakpoint_count + 1);
8792 b->enable_state = bp_enabled;
8793 b->disposition = tempflag ? disp_del : disp_donttouch;
8794 b->number = breakpoint_count;
8795 b->ignore_count = 0;
8796 b->loc->cond = cond;
8797 b->addr_string = addr_string;
8798 b->language = language_ada;
8799 b->cond_string = cond_string;
8800 b->exp_string = exp_string;
8805 update_global_location_list (1);
8808 /* Implement the "catch exception" command. */
8811 catch_ada_exception_command (char *arg, int from_tty,
8812 struct cmd_list_element *command)
8814 struct gdbarch *gdbarch = get_current_arch ();
8816 struct symtab_and_line sal;
8817 char *addr_string = NULL;
8818 char *exp_string = NULL;
8819 char *cond_string = NULL;
8820 struct expression *cond = NULL;
8821 struct breakpoint_ops *ops = NULL;
8823 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8827 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
8828 &cond_string, &cond, &ops);
8829 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
8830 cond_string, cond, ops, tempflag,
8834 /* Cleanup function for a syscall filter list. */
8836 clean_up_filters (void *arg)
8838 VEC(int) *iter = *(VEC(int) **) arg;
8839 VEC_free (int, iter);
8842 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8843 filter list, or NULL if no filtering is required. */
8845 catch_syscall_split_args (char *arg)
8847 VEC(int) *result = NULL;
8848 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
8850 while (*arg != '\0')
8852 int i, syscall_number;
8857 /* Skip whitespace. */
8858 while (isspace (*arg))
8861 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
8862 cur_name[i] = arg[i];
8866 /* Check if the user provided a syscall name or a number. */
8867 syscall_number = (int) strtol (cur_name, &endptr, 0);
8868 if (*endptr == '\0')
8869 get_syscall_by_number (syscall_number, &s);
8872 /* We have a name. Let's check if it's valid and convert it
8874 get_syscall_by_name (cur_name, &s);
8876 if (s.number == UNKNOWN_SYSCALL)
8877 /* Here we have to issue an error instead of a warning, because
8878 GDB cannot do anything useful if there's no syscall number to
8880 error (_("Unknown syscall name '%s'."), cur_name);
8883 /* Ok, it's valid. */
8884 VEC_safe_push (int, result, s.number);
8887 discard_cleanups (cleanup);
8891 /* Implement the "catch syscall" command. */
8894 catch_syscall_command_1 (char *arg, int from_tty,
8895 struct cmd_list_element *command)
8900 struct gdbarch *gdbarch = get_current_arch ();
8902 /* Checking if the feature if supported. */
8903 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
8904 error (_("The feature 'catch syscall' is not supported on \
8905 this architeture yet."));
8907 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8909 ep_skip_leading_whitespace (&arg);
8911 /* We need to do this first "dummy" translation in order
8912 to get the syscall XML file loaded or, most important,
8913 to display a warning to the user if there's no XML file
8914 for his/her architecture. */
8915 get_syscall_by_number (0, &s);
8917 /* The allowed syntax is:
8919 catch syscall <name | number> [<name | number> ... <name | number>]
8921 Let's check if there's a syscall name. */
8924 filter = catch_syscall_split_args (arg);
8928 create_syscall_event_catchpoint (tempflag, filter,
8929 &catch_syscall_breakpoint_ops);
8932 /* Implement the "catch assert" command. */
8935 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
8937 struct gdbarch *gdbarch = get_current_arch ();
8939 struct symtab_and_line sal;
8940 char *addr_string = NULL;
8941 struct breakpoint_ops *ops = NULL;
8943 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8947 sal = ada_decode_assert_location (arg, &addr_string, &ops);
8948 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
8949 ops, tempflag, from_tty);
8953 catch_command (char *arg, int from_tty)
8955 error (_("Catch requires an event name."));
8960 tcatch_command (char *arg, int from_tty)
8962 error (_("Catch requires an event name."));
8965 /* Delete breakpoints by address or line. */
8968 clear_command (char *arg, int from_tty)
8970 struct breakpoint *b;
8971 VEC(breakpoint_p) *found = 0;
8974 struct symtabs_and_lines sals;
8975 struct symtab_and_line sal;
8980 sals = decode_line_spec (arg, 1);
8985 sals.sals = (struct symtab_and_line *)
8986 xmalloc (sizeof (struct symtab_and_line));
8987 make_cleanup (xfree, sals.sals);
8988 init_sal (&sal); /* initialize to zeroes */
8989 sal.line = default_breakpoint_line;
8990 sal.symtab = default_breakpoint_symtab;
8991 sal.pc = default_breakpoint_address;
8992 sal.pspace = default_breakpoint_pspace;
8993 if (sal.symtab == 0)
8994 error (_("No source file specified."));
9002 /* We don't call resolve_sal_pc here. That's not
9003 as bad as it seems, because all existing breakpoints
9004 typically have both file/line and pc set. So, if
9005 clear is given file/line, we can match this to existing
9006 breakpoint without obtaining pc at all.
9008 We only support clearing given the address explicitly
9009 present in breakpoint table. Say, we've set breakpoint
9010 at file:line. There were several PC values for that file:line,
9011 due to optimization, all in one block.
9012 We've picked one PC value. If "clear" is issued with another
9013 PC corresponding to the same file:line, the breakpoint won't
9014 be cleared. We probably can still clear the breakpoint, but
9015 since the other PC value is never presented to user, user
9016 can only find it by guessing, and it does not seem important
9019 /* For each line spec given, delete bps which correspond
9020 to it. Do it in two passes, solely to preserve the current
9021 behavior that from_tty is forced true if we delete more than
9025 for (i = 0; i < sals.nelts; i++)
9027 /* If exact pc given, clear bpts at that pc.
9028 If line given (pc == 0), clear all bpts on specified line.
9029 If defaulting, clear all bpts on default line
9032 defaulting sal.pc != 0 tests to do
9037 1 0 <can't happen> */
9041 /* Find all matching breakpoints and add them to
9046 /* Are we going to delete b? */
9047 if (b->type != bp_none && !is_watchpoint (b))
9049 struct bp_location *loc = b->loc;
9050 for (; loc; loc = loc->next)
9052 int pc_match = sal.pc
9053 && (loc->pspace == sal.pspace)
9054 && (loc->address == sal.pc)
9055 && (!section_is_overlay (loc->section)
9056 || loc->section == sal.section);
9057 int line_match = ((default_match || (0 == sal.pc))
9058 && b->source_file != NULL
9059 && sal.symtab != NULL
9060 && sal.pspace == loc->pspace
9061 && strcmp (b->source_file, sal.symtab->filename) == 0
9062 && b->line_number == sal.line);
9063 if (pc_match || line_match)
9072 VEC_safe_push(breakpoint_p, found, b);
9075 /* Now go thru the 'found' chain and delete them. */
9076 if (VEC_empty(breakpoint_p, found))
9079 error (_("No breakpoint at %s."), arg);
9081 error (_("No breakpoint at this line."));
9084 if (VEC_length(breakpoint_p, found) > 1)
9085 from_tty = 1; /* Always report if deleted more than one */
9088 if (VEC_length(breakpoint_p, found) == 1)
9089 printf_unfiltered (_("Deleted breakpoint "));
9091 printf_unfiltered (_("Deleted breakpoints "));
9093 breakpoints_changed ();
9095 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
9098 printf_unfiltered ("%d ", b->number);
9099 delete_breakpoint (b);
9102 putchar_unfiltered ('\n');
9105 /* Delete breakpoint in BS if they are `delete' breakpoints and
9106 all breakpoints that are marked for deletion, whether hit or not.
9107 This is called after any breakpoint is hit, or after errors. */
9110 breakpoint_auto_delete (bpstat bs)
9112 struct breakpoint *b, *temp;
9114 for (; bs; bs = bs->next)
9115 if (bs->breakpoint_at
9116 && bs->breakpoint_at->owner
9117 && bs->breakpoint_at->owner->disposition == disp_del
9119 delete_breakpoint (bs->breakpoint_at->owner);
9121 ALL_BREAKPOINTS_SAFE (b, temp)
9123 if (b->disposition == disp_del_at_next_stop)
9124 delete_breakpoint (b);
9128 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9129 Sort elements primarily by their ADDRESS (no matter what does
9130 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9131 first bp_permanent OWNERed elements and terciarily just ensuring the array
9132 is sorted stable way despite qsort being an instable algorithm. */
9135 bp_location_compare (const void *ap, const void *bp)
9137 struct bp_location *a = *(void **) ap;
9138 struct bp_location *b = *(void **) bp;
9139 /* A and B come from existing breakpoints having non-NULL OWNER. */
9140 int a_perm = a->owner->enable_state == bp_permanent;
9141 int b_perm = b->owner->enable_state == bp_permanent;
9143 if (a->address != b->address)
9144 return (a->address > b->address) - (a->address < b->address);
9146 /* Sort permanent breakpoints first. */
9147 if (a_perm != b_perm)
9148 return (a_perm < b_perm) - (a_perm > b_perm);
9150 /* Make the user-visible order stable across GDB runs. Locations of the same
9151 breakpoint can be sorted in arbitrary order. */
9153 if (a->owner->number != b->owner->number)
9154 return (a->owner->number > b->owner->number)
9155 - (a->owner->number < b->owner->number);
9157 return (a > b) - (a < b);
9160 /* Set bp_location_placed_address_before_address_max and
9161 bp_location_shadow_len_after_address_max according to the current content of
9162 the bp_location array. */
9165 bp_location_target_extensions_update (void)
9167 struct bp_location *bl, **blp_tmp;
9169 bp_location_placed_address_before_address_max = 0;
9170 bp_location_shadow_len_after_address_max = 0;
9172 ALL_BP_LOCATIONS (bl, blp_tmp)
9174 CORE_ADDR start, end, addr;
9176 if (!bp_location_has_shadow (bl))
9179 start = bl->target_info.placed_address;
9180 end = start + bl->target_info.shadow_len;
9182 gdb_assert (bl->address >= start);
9183 addr = bl->address - start;
9184 if (addr > bp_location_placed_address_before_address_max)
9185 bp_location_placed_address_before_address_max = addr;
9187 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9189 gdb_assert (bl->address < end);
9190 addr = end - bl->address;
9191 if (addr > bp_location_shadow_len_after_address_max)
9192 bp_location_shadow_len_after_address_max = addr;
9196 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9197 into the inferior, only remove already-inserted locations that no
9198 longer should be inserted. Functions that delete a breakpoint or
9199 breakpoints should pass false, so that deleting a breakpoint
9200 doesn't have the side effect of inserting the locations of other
9201 breakpoints that are marked not-inserted, but should_be_inserted
9202 returns true on them.
9204 This behaviour is useful is situations close to tear-down -- e.g.,
9205 after an exec, while the target still has execution, but breakpoint
9206 shadows of the previous executable image should *NOT* be restored
9207 to the new image; or before detaching, where the target still has
9208 execution and wants to delete breakpoints from GDB's lists, and all
9209 breakpoints had already been removed from the inferior. */
9212 update_global_location_list (int should_insert)
9214 struct breakpoint *b;
9215 struct bp_location **locp, *loc;
9216 struct cleanup *cleanups;
9218 /* Used in the duplicates detection below. When iterating over all
9219 bp_locations, points to the first bp_location of a given address.
9220 Breakpoints and watchpoints of different types are never
9221 duplicates of each other. Keep one pointer for each type of
9222 breakpoint/watchpoint, so we only need to loop over all locations
9224 struct bp_location *bp_loc_first; /* breakpoint */
9225 struct bp_location *wp_loc_first; /* hardware watchpoint */
9226 struct bp_location *awp_loc_first; /* access watchpoint */
9227 struct bp_location *rwp_loc_first; /* read watchpoint */
9229 /* Saved former bp_location array which we compare against the newly built
9230 bp_location from the current state of ALL_BREAKPOINTS. */
9231 struct bp_location **old_location, **old_locp;
9232 unsigned old_location_count;
9234 old_location = bp_location;
9235 old_location_count = bp_location_count;
9237 bp_location_count = 0;
9238 cleanups = make_cleanup (xfree, old_location);
9241 for (loc = b->loc; loc; loc = loc->next)
9242 bp_location_count++;
9244 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
9247 for (loc = b->loc; loc; loc = loc->next)
9249 qsort (bp_location, bp_location_count, sizeof (*bp_location),
9250 bp_location_compare);
9252 bp_location_target_extensions_update ();
9254 /* Identify bp_location instances that are no longer present in the new
9255 list, and therefore should be freed. Note that it's not necessary that
9256 those locations should be removed from inferior -- if there's another
9257 location at the same address (previously marked as duplicate),
9258 we don't need to remove/insert the location.
9260 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9261 former bp_location array state respectively. */
9264 for (old_locp = old_location; old_locp < old_location + old_location_count;
9267 struct bp_location *old_loc = *old_locp;
9268 struct bp_location **loc2p;
9270 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9272 int found_object = 0;
9273 /* Tells if the location should remain inserted in the target. */
9274 int keep_in_target = 0;
9277 /* Skip LOCP entries which will definitely never be needed. Stop either
9278 at or being the one matching OLD_LOC. */
9279 while (locp < bp_location + bp_location_count
9280 && (*locp)->address < old_loc->address)
9284 (loc2p < bp_location + bp_location_count
9285 && (*loc2p)->address == old_loc->address);
9288 if (*loc2p == old_loc)
9295 /* If this location is no longer present, and inserted, look if there's
9296 maybe a new location at the same address. If so, mark that one
9297 inserted, and don't remove this one. This is needed so that we
9298 don't have a time window where a breakpoint at certain location is not
9301 if (old_loc->inserted)
9303 /* If the location is inserted now, we might have to remove it. */
9305 if (found_object && should_be_inserted (old_loc))
9307 /* The location is still present in the location list, and still
9308 should be inserted. Don't do anything. */
9313 /* The location is either no longer present, or got disabled.
9314 See if there's another location at the same address, in which
9315 case we don't need to remove this one from the target. */
9317 /* OLD_LOC comes from existing struct breakpoint. */
9318 if (breakpoint_address_is_meaningful (old_loc->owner))
9321 (loc2p < bp_location + bp_location_count
9322 && (*loc2p)->address == old_loc->address);
9325 struct bp_location *loc2 = *loc2p;
9327 if (breakpoint_locations_match (loc2, old_loc))
9329 /* For the sake of should_be_inserted.
9330 Duplicates check below will fix up this later. */
9331 loc2->duplicate = 0;
9333 /* Read watchpoint locations are switched to
9334 access watchpoints, if the former are not
9335 supported, but the latter are. */
9336 if (is_hardware_watchpoint (old_loc->owner))
9338 gdb_assert (is_hardware_watchpoint (loc2->owner));
9339 loc2->watchpoint_type = old_loc->watchpoint_type;
9342 if (loc2 != old_loc && should_be_inserted (loc2))
9345 loc2->target_info = old_loc->target_info;
9354 if (!keep_in_target)
9356 if (remove_breakpoint (old_loc, mark_uninserted))
9358 /* This is just about all we can do. We could keep this
9359 location on the global list, and try to remove it next
9360 time, but there's no particular reason why we will
9363 Note that at this point, old_loc->owner is still valid,
9364 as delete_breakpoint frees the breakpoint only
9365 after calling us. */
9366 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9367 old_loc->owner->number);
9375 if (removed && non_stop
9376 && breakpoint_address_is_meaningful (old_loc->owner)
9377 && !is_hardware_watchpoint (old_loc->owner))
9379 /* This location was removed from the target. In
9380 non-stop mode, a race condition is possible where
9381 we've removed a breakpoint, but stop events for that
9382 breakpoint are already queued and will arrive later.
9383 We apply an heuristic to be able to distinguish such
9384 SIGTRAPs from other random SIGTRAPs: we keep this
9385 breakpoint location for a bit, and will retire it
9386 after we see some number of events. The theory here
9387 is that reporting of events should, "on the average",
9388 be fair, so after a while we'll see events from all
9389 threads that have anything of interest, and no longer
9390 need to keep this breakpoint location around. We
9391 don't hold locations forever so to reduce chances of
9392 mistaking a non-breakpoint SIGTRAP for a breakpoint
9395 The heuristic failing can be disastrous on
9396 decr_pc_after_break targets.
9398 On decr_pc_after_break targets, like e.g., x86-linux,
9399 if we fail to recognize a late breakpoint SIGTRAP,
9400 because events_till_retirement has reached 0 too
9401 soon, we'll fail to do the PC adjustment, and report
9402 a random SIGTRAP to the user. When the user resumes
9403 the inferior, it will most likely immediately crash
9404 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9405 corrupted, because of being resumed e.g., in the
9406 middle of a multi-byte instruction, or skipped a
9407 one-byte instruction. This was actually seen happen
9408 on native x86-linux, and should be less rare on
9409 targets that do not support new thread events, like
9410 remote, due to the heuristic depending on
9413 Mistaking a random SIGTRAP for a breakpoint trap
9414 causes similar symptoms (PC adjustment applied when
9415 it shouldn't), but then again, playing with SIGTRAPs
9416 behind the debugger's back is asking for trouble.
9418 Since hardware watchpoint traps are always
9419 distinguishable from other traps, so we don't need to
9420 apply keep hardware watchpoint moribund locations
9421 around. We simply always ignore hardware watchpoint
9422 traps we can no longer explain. */
9424 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9425 old_loc->owner = NULL;
9427 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9430 free_bp_location (old_loc);
9434 /* Rescan breakpoints at the same address and section, marking the
9435 first one as "first" and any others as "duplicates". This is so
9436 that the bpt instruction is only inserted once. If we have a
9437 permanent breakpoint at the same place as BPT, make that one the
9438 official one, and the rest as duplicates. Permanent breakpoints
9439 are sorted first for the same address.
9441 Do the same for hardware watchpoints, but also considering the
9442 watchpoint's type (regular/access/read) and length. */
9444 bp_loc_first = NULL;
9445 wp_loc_first = NULL;
9446 awp_loc_first = NULL;
9447 rwp_loc_first = NULL;
9448 ALL_BP_LOCATIONS (loc, locp)
9450 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9451 struct breakpoint *b = loc->owner;
9452 struct bp_location **loc_first_p;
9454 if (b->enable_state == bp_disabled
9455 || b->enable_state == bp_call_disabled
9456 || b->enable_state == bp_startup_disabled
9458 || loc->shlib_disabled
9459 || !breakpoint_address_is_meaningful (b)
9460 || is_tracepoint (b))
9463 /* Permanent breakpoint should always be inserted. */
9464 if (b->enable_state == bp_permanent && ! loc->inserted)
9465 internal_error (__FILE__, __LINE__,
9466 _("allegedly permanent breakpoint is not "
9467 "actually inserted"));
9469 if (b->type == bp_hardware_watchpoint)
9470 loc_first_p = &wp_loc_first;
9471 else if (b->type == bp_read_watchpoint)
9472 loc_first_p = &rwp_loc_first;
9473 else if (b->type == bp_access_watchpoint)
9474 loc_first_p = &awp_loc_first;
9476 loc_first_p = &bp_loc_first;
9478 if (*loc_first_p == NULL
9479 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9480 || !breakpoint_locations_match (loc, *loc_first_p))
9489 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9490 && b->enable_state != bp_permanent)
9491 internal_error (__FILE__, __LINE__,
9492 _("another breakpoint was inserted on top of "
9493 "a permanent breakpoint"));
9496 if (breakpoints_always_inserted_mode () && should_insert
9497 && (have_live_inferiors ()
9498 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9499 insert_breakpoint_locations ();
9501 do_cleanups (cleanups);
9505 breakpoint_retire_moribund (void)
9507 struct bp_location *loc;
9510 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9511 if (--(loc->events_till_retirement) == 0)
9513 free_bp_location (loc);
9514 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9520 update_global_location_list_nothrow (int inserting)
9522 struct gdb_exception e;
9524 TRY_CATCH (e, RETURN_MASK_ERROR)
9525 update_global_location_list (inserting);
9528 /* Clear LOC from a BPS. */
9530 bpstat_remove_bp_location (bpstat bps, struct bp_location *loc)
9534 for (bs = bps; bs; bs = bs->next)
9535 if (bs->breakpoint_at == loc)
9537 bs->breakpoint_at = NULL;
9539 /* bs->commands will be freed later. */
9543 /* Callback for iterate_over_threads. */
9545 bpstat_remove_bp_location_callback (struct thread_info *th, void *data)
9547 struct bp_location *loc = data;
9549 bpstat_remove_bp_location (th->stop_bpstat, loc);
9553 /* Delete a breakpoint and clean up all traces of it in the data
9557 delete_breakpoint (struct breakpoint *bpt)
9559 struct breakpoint *b;
9561 gdb_assert (bpt != NULL);
9563 /* Has this bp already been deleted? This can happen because multiple
9564 lists can hold pointers to bp's. bpstat lists are especial culprits.
9566 One example of this happening is a watchpoint's scope bp. When the
9567 scope bp triggers, we notice that the watchpoint is out of scope, and
9568 delete it. We also delete its scope bp. But the scope bp is marked
9569 "auto-deleting", and is already on a bpstat. That bpstat is then
9570 checked for auto-deleting bp's, which are deleted.
9572 A real solution to this problem might involve reference counts in bp's,
9573 and/or giving them pointers back to their referencing bpstat's, and
9574 teaching delete_breakpoint to only free a bp's storage when no more
9575 references were extent. A cheaper bandaid was chosen. */
9576 if (bpt->type == bp_none)
9579 /* At least avoid this stale reference until the reference counting of
9580 breakpoints gets resolved. */
9581 if (bpt->related_breakpoint != NULL)
9583 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
9584 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
9585 bpt->related_breakpoint->related_breakpoint = NULL;
9586 bpt->related_breakpoint = NULL;
9589 observer_notify_breakpoint_deleted (bpt->number);
9591 if (breakpoint_chain == bpt)
9592 breakpoint_chain = bpt->next;
9597 b->next = bpt->next;
9601 decref_counted_command_line (&bpt->commands);
9602 xfree (bpt->cond_string);
9603 xfree (bpt->cond_exp);
9604 xfree (bpt->addr_string);
9606 xfree (bpt->exp_string);
9607 value_free (bpt->val);
9608 xfree (bpt->source_file);
9609 xfree (bpt->exec_pathname);
9610 clean_up_filters (&bpt->syscalls_to_be_caught);
9612 /* Now that breakpoint is removed from breakpoint
9613 list, update the global location list. This
9614 will remove locations that used to belong to
9615 this breakpoint. Do this before freeing
9616 the breakpoint itself, since remove_breakpoint
9617 looks at location's owner. It might be better
9618 design to have location completely self-contained,
9619 but it's not the case now. */
9620 update_global_location_list (0);
9623 /* On the chance that someone will soon try again to delete this same
9624 bp, we mark it as deleted before freeing its storage. */
9625 bpt->type = bp_none;
9631 do_delete_breakpoint_cleanup (void *b)
9633 delete_breakpoint (b);
9637 make_cleanup_delete_breakpoint (struct breakpoint *b)
9639 return make_cleanup (do_delete_breakpoint_cleanup, b);
9642 /* A callback for map_breakpoint_numbers that calls
9643 delete_breakpoint. */
9646 do_delete_breakpoint (struct breakpoint *b, void *ignore)
9648 delete_breakpoint (b);
9652 delete_command (char *arg, int from_tty)
9654 struct breakpoint *b, *temp;
9660 int breaks_to_delete = 0;
9662 /* Delete all breakpoints if no argument.
9663 Do not delete internal or call-dummy breakpoints, these
9664 have to be deleted with an explicit breakpoint number argument. */
9667 if (b->type != bp_call_dummy
9668 && b->type != bp_std_terminate
9669 && b->type != bp_shlib_event
9670 && b->type != bp_jit_event
9671 && b->type != bp_thread_event
9672 && b->type != bp_overlay_event
9673 && b->type != bp_longjmp_master
9674 && b->type != bp_std_terminate_master
9677 breaks_to_delete = 1;
9682 /* Ask user only if there are some breakpoints to delete. */
9684 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
9686 ALL_BREAKPOINTS_SAFE (b, temp)
9688 if (b->type != bp_call_dummy
9689 && b->type != bp_std_terminate
9690 && b->type != bp_shlib_event
9691 && b->type != bp_thread_event
9692 && b->type != bp_jit_event
9693 && b->type != bp_overlay_event
9694 && b->type != bp_longjmp_master
9695 && b->type != bp_std_terminate_master
9697 delete_breakpoint (b);
9702 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
9706 all_locations_are_pending (struct bp_location *loc)
9708 for (; loc; loc = loc->next)
9709 if (!loc->shlib_disabled)
9714 /* Subroutine of update_breakpoint_locations to simplify it.
9715 Return non-zero if multiple fns in list LOC have the same name.
9716 Null names are ignored. */
9719 ambiguous_names_p (struct bp_location *loc)
9721 struct bp_location *l;
9722 htab_t htab = htab_create_alloc (13, htab_hash_string,
9723 (int (*) (const void *,
9724 const void *)) streq,
9725 NULL, xcalloc, xfree);
9727 for (l = loc; l != NULL; l = l->next)
9730 const char *name = l->function_name;
9732 /* Allow for some names to be NULL, ignore them. */
9736 slot = (const char **) htab_find_slot (htab, (const void *) name,
9738 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9752 /* When symbols change, it probably means the sources changed as well,
9753 and it might mean the static tracepoint markers are no longer at
9754 the same address or line numbers they used to be at last we
9755 checked. Losing your static tracepoints whenever you rebuild is
9756 undesirable. This function tries to resync/rematch gdb static
9757 tracepoints with the markers on the target, for static tracepoints
9758 that have not been set by marker id. Static tracepoint that have
9759 been set by marker id are reset by marker id in breakpoint_re_set.
9762 1) For a tracepoint set at a specific address, look for a marker at
9763 the old PC. If one is found there, assume to be the same marker.
9764 If the name / string id of the marker found is different from the
9765 previous known name, assume that means the user renamed the marker
9766 in the sources, and output a warning.
9768 2) For a tracepoint set at a given line number, look for a marker
9769 at the new address of the old line number. If one is found there,
9770 assume to be the same marker. If the name / string id of the
9771 marker found is different from the previous known name, assume that
9772 means the user renamed the marker in the sources, and output a
9775 3) If a marker is no longer found at the same address or line, it
9776 may mean the marker no longer exists. But it may also just mean
9777 the code changed a bit. Maybe the user added a few lines of code
9778 that made the marker move up or down (in line number terms). Ask
9779 the target for info about the marker with the string id as we knew
9780 it. If found, update line number and address in the matching
9781 static tracepoint. This will get confused if there's more than one
9782 marker with the same ID (possible in UST, although unadvised
9783 precisely because it confuses tools). */
9785 static struct symtab_and_line
9786 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
9788 struct static_tracepoint_marker marker;
9794 find_line_pc (sal.symtab, sal.line, &pc);
9796 if (target_static_tracepoint_marker_at (pc, &marker))
9798 if (strcmp (b->static_trace_marker_id, marker.str_id) != 0)
9799 warning (_("static tracepoint %d changed probed marker from %s to %s"),
9801 b->static_trace_marker_id, marker.str_id);
9803 xfree (b->static_trace_marker_id);
9804 b->static_trace_marker_id = xstrdup (marker.str_id);
9805 release_static_tracepoint_marker (&marker);
9810 /* Old marker wasn't found on target at lineno. Try looking it up
9812 if (!sal.explicit_pc
9814 && sal.symtab != NULL
9815 && b->static_trace_marker_id != NULL)
9817 VEC(static_tracepoint_marker_p) *markers;
9820 = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id);
9822 if (!VEC_empty(static_tracepoint_marker_p, markers))
9824 struct symtab_and_line sal;
9826 struct static_tracepoint_marker *marker;
9828 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
9830 xfree (b->static_trace_marker_id);
9831 b->static_trace_marker_id = xstrdup (marker->str_id);
9833 warning (_("marker for static tracepoint %d (%s) not "
9834 "found at previous line number"),
9835 b->number, b->static_trace_marker_id);
9839 sal.pc = marker->address;
9841 sal = find_pc_line (marker->address, 0);
9842 sym = find_pc_sect_function (marker->address, NULL);
9843 ui_out_text (uiout, "Now in ");
9846 ui_out_field_string (uiout, "func",
9847 SYMBOL_PRINT_NAME (sym));
9848 ui_out_text (uiout, " at ");
9850 ui_out_field_string (uiout, "file", sal.symtab->filename);
9851 ui_out_text (uiout, ":");
9853 if (ui_out_is_mi_like_p (uiout))
9855 char *fullname = symtab_to_fullname (sal.symtab);
9858 ui_out_field_string (uiout, "fullname", fullname);
9861 ui_out_field_int (uiout, "line", sal.line);
9862 ui_out_text (uiout, "\n");
9864 b->line_number = sal.line;
9866 xfree (b->source_file);
9868 b->source_file = xstrdup (sal.symtab->filename);
9870 b->source_file = NULL;
9872 xfree (b->addr_string);
9873 b->addr_string = xstrprintf ("%s:%d",
9874 sal.symtab->filename, b->line_number);
9876 /* Might be nice to check if function changed, and warn if
9879 release_static_tracepoint_marker (marker);
9886 update_breakpoint_locations (struct breakpoint *b,
9887 struct symtabs_and_lines sals)
9891 struct bp_location *existing_locations = b->loc;
9893 /* If there's no new locations, and all existing locations
9894 are pending, don't do anything. This optimizes
9895 the common case where all locations are in the same
9896 shared library, that was unloaded. We'd like to
9897 retain the location, so that when the library
9898 is loaded again, we don't loose the enabled/disabled
9899 status of the individual locations. */
9900 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
9905 for (i = 0; i < sals.nelts; ++i)
9907 struct bp_location *new_loc =
9908 add_location_to_breakpoint (b, &(sals.sals[i]));
9910 /* Reparse conditions, they might contain references to the
9912 if (b->cond_string != NULL)
9914 struct gdb_exception e;
9917 TRY_CATCH (e, RETURN_MASK_ERROR)
9919 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
9924 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9925 b->number, e.message);
9926 new_loc->enabled = 0;
9930 if (b->source_file != NULL)
9931 xfree (b->source_file);
9932 if (sals.sals[i].symtab == NULL)
9933 b->source_file = NULL;
9935 b->source_file = xstrdup (sals.sals[i].symtab->filename);
9937 if (b->line_number == 0)
9938 b->line_number = sals.sals[i].line;
9941 /* Update locations of permanent breakpoints. */
9942 if (b->enable_state == bp_permanent)
9943 make_breakpoint_permanent (b);
9945 /* If possible, carry over 'disable' status from existing breakpoints. */
9947 struct bp_location *e = existing_locations;
9948 /* If there are multiple breakpoints with the same function name,
9949 e.g. for inline functions, comparing function names won't work.
9950 Instead compare pc addresses; this is just a heuristic as things
9951 may have moved, but in practice it gives the correct answer
9952 often enough until a better solution is found. */
9953 int have_ambiguous_names = ambiguous_names_p (b->loc);
9955 for (; e; e = e->next)
9957 if (!e->enabled && e->function_name)
9959 struct bp_location *l = b->loc;
9960 if (have_ambiguous_names)
9962 for (; l; l = l->next)
9963 if (breakpoint_address_match (e->pspace->aspace, e->address,
9964 l->pspace->aspace, l->address))
9972 for (; l; l = l->next)
9973 if (l->function_name
9974 && strcmp (e->function_name, l->function_name) == 0)
9984 update_global_location_list (1);
9987 /* Reset a breakpoint given it's struct breakpoint * BINT.
9988 The value we return ends up being the return value from catch_errors.
9989 Unused in this case. */
9992 breakpoint_re_set_one (void *bint)
9994 /* get past catch_errs */
9995 struct breakpoint *b = (struct breakpoint *) bint;
9997 int *not_found_ptr = ¬_found;
9998 struct symtabs_and_lines sals = {0};
9999 struct symtabs_and_lines expanded = {0};
10001 struct gdb_exception e;
10002 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10003 int marker_spec = 0;
10008 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10011 case bp_breakpoint:
10012 case bp_hardware_breakpoint:
10013 case bp_tracepoint:
10014 case bp_fast_tracepoint:
10015 case bp_static_tracepoint:
10016 /* Do not attempt to re-set breakpoints disabled during startup. */
10017 if (b->enable_state == bp_startup_disabled)
10020 if (b->addr_string == NULL)
10022 /* Anything without a string can't be re-set. */
10023 delete_breakpoint (b);
10027 set_language (b->language);
10028 input_radix = b->input_radix;
10029 s = b->addr_string;
10031 save_current_space_and_thread ();
10032 switch_to_program_space_and_thread (b->pspace);
10034 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
10036 TRY_CATCH (e, RETURN_MASK_ERROR)
10040 sals = decode_static_tracepoint_spec (&s);
10041 if (sals.nelts > b->static_trace_marker_id_idx)
10043 sals.sals[0] = sals.sals[b->static_trace_marker_id_idx];
10047 error (_("marker %s not found"), b->static_trace_marker_id);
10050 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
10055 int not_found_and_ok = 0;
10056 /* For pending breakpoints, it's expected that parsing
10057 will fail until the right shared library is loaded.
10058 User has already told to create pending breakpoints and
10059 don't need extra messages. If breakpoint is in bp_shlib_disabled
10060 state, then user already saw the message about that breakpoint
10061 being disabled, and don't want to see more errors. */
10063 && (b->condition_not_parsed
10064 || (b->loc && b->loc->shlib_disabled)
10065 || b->enable_state == bp_disabled))
10066 not_found_and_ok = 1;
10068 if (!not_found_and_ok)
10070 /* We surely don't want to warn about the same breakpoint
10071 10 times. One solution, implemented here, is disable
10072 the breakpoint on error. Another solution would be to
10073 have separate 'warning emitted' flag. Since this
10074 happens only when a binary has changed, I don't know
10075 which approach is better. */
10076 b->enable_state = bp_disabled;
10077 throw_exception (e);
10083 gdb_assert (sals.nelts == 1);
10085 resolve_sal_pc (&sals.sals[0]);
10086 if (b->condition_not_parsed && s && s[0])
10088 char *cond_string = 0;
10092 find_condition_and_thread (s, sals.sals[0].pc,
10093 &cond_string, &thread, &task);
10095 b->cond_string = cond_string;
10096 b->thread = thread;
10098 b->condition_not_parsed = 0;
10101 if (b->type == bp_static_tracepoint && !marker_spec)
10102 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
10104 expanded = expand_line_sal_maybe (sals.sals[0]);
10107 make_cleanup (xfree, sals.sals);
10108 update_breakpoint_locations (b, expanded);
10111 case bp_watchpoint:
10112 case bp_hardware_watchpoint:
10113 case bp_read_watchpoint:
10114 case bp_access_watchpoint:
10115 /* Watchpoint can be either on expression using entirely global variables,
10116 or it can be on local variables.
10118 Watchpoints of the first kind are never auto-deleted, and even persist
10119 across program restarts. Since they can use variables from shared
10120 libraries, we need to reparse expression as libraries are loaded
10123 Watchpoints on local variables can also change meaning as result
10124 of solib event. For example, if a watchpoint uses both a local and
10125 a global variables in expression, it's a local watchpoint, but
10126 unloading of a shared library will make the expression invalid.
10127 This is not a very common use case, but we still re-evaluate
10128 expression, to avoid surprises to the user.
10130 Note that for local watchpoints, we re-evaluate it only if
10131 watchpoints frame id is still valid. If it's not, it means
10132 the watchpoint is out of scope and will be deleted soon. In fact,
10133 I'm not sure we'll ever be called in this case.
10135 If a local watchpoint's frame id is still valid, then
10136 b->exp_valid_block is likewise valid, and we can safely use it.
10138 Don't do anything about disabled watchpoints, since they will
10139 be reevaluated again when enabled. */
10140 update_watchpoint (b, 1 /* reparse */);
10142 /* We needn't really do anything to reset these, since the mask
10143 that requests them is unaffected by e.g., new libraries being
10145 case bp_catchpoint:
10149 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
10151 /* Delete overlay event and longjmp master breakpoints; they will be
10152 reset later by breakpoint_re_set. */
10153 case bp_overlay_event:
10154 case bp_longjmp_master:
10155 case bp_std_terminate_master:
10156 delete_breakpoint (b);
10159 /* This breakpoint is special, it's set up when the inferior
10160 starts and we really don't want to touch it. */
10161 case bp_shlib_event:
10163 /* Like bp_shlib_event, this breakpoint type is special.
10164 Once it is set up, we do not want to touch it. */
10165 case bp_thread_event:
10167 /* Keep temporary breakpoints, which can be encountered when we step
10168 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10169 Otherwise these should have been blown away via the cleanup chain
10170 or by breakpoint_init_inferior when we rerun the executable. */
10173 case bp_watchpoint_scope:
10174 case bp_call_dummy:
10175 case bp_std_terminate:
10176 case bp_step_resume:
10178 case bp_longjmp_resume:
10183 do_cleanups (cleanups);
10187 /* Re-set all breakpoints after symbols have been re-loaded. */
10189 breakpoint_re_set (void)
10191 struct breakpoint *b, *temp;
10192 enum language save_language;
10193 int save_input_radix;
10194 struct cleanup *old_chain;
10196 save_language = current_language->la_language;
10197 save_input_radix = input_radix;
10198 old_chain = save_current_program_space ();
10200 ALL_BREAKPOINTS_SAFE (b, temp)
10202 /* Format possible error msg */
10203 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
10205 struct cleanup *cleanups = make_cleanup (xfree, message);
10206 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
10207 do_cleanups (cleanups);
10209 set_language (save_language);
10210 input_radix = save_input_radix;
10212 jit_breakpoint_re_set ();
10214 do_cleanups (old_chain);
10216 create_overlay_event_breakpoint ("_ovly_debug_event");
10217 create_longjmp_master_breakpoint ("longjmp");
10218 create_longjmp_master_breakpoint ("_longjmp");
10219 create_longjmp_master_breakpoint ("siglongjmp");
10220 create_longjmp_master_breakpoint ("_siglongjmp");
10221 create_std_terminate_master_breakpoint ("std::terminate()");
10224 /* Reset the thread number of this breakpoint:
10226 - If the breakpoint is for all threads, leave it as-is.
10227 - Else, reset it to the current thread for inferior_ptid. */
10229 breakpoint_re_set_thread (struct breakpoint *b)
10231 if (b->thread != -1)
10233 if (in_thread_list (inferior_ptid))
10234 b->thread = pid_to_thread_id (inferior_ptid);
10236 /* We're being called after following a fork. The new fork is
10237 selected as current, and unless this was a vfork will have a
10238 different program space from the original thread. Reset that
10240 b->loc->pspace = current_program_space;
10244 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10245 If from_tty is nonzero, it prints a message to that effect,
10246 which ends with a period (no newline). */
10249 set_ignore_count (int bptnum, int count, int from_tty)
10251 struct breakpoint *b;
10256 ALL_BREAKPOINTS (b)
10257 if (b->number == bptnum)
10259 if (is_tracepoint (b))
10261 if (from_tty && count != 0)
10262 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10267 b->ignore_count = count;
10271 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10273 else if (count == 1)
10274 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10277 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10280 breakpoints_changed ();
10281 observer_notify_breakpoint_modified (b->number);
10285 error (_("No breakpoint number %d."), bptnum);
10289 make_breakpoint_silent (struct breakpoint *b)
10291 /* Silence the breakpoint. */
10295 /* Command to set ignore-count of breakpoint N to COUNT. */
10298 ignore_command (char *args, int from_tty)
10304 error_no_arg (_("a breakpoint number"));
10306 num = get_number (&p);
10308 error (_("bad breakpoint number: '%s'"), args);
10310 error (_("Second argument (specified ignore-count) is missing."));
10312 set_ignore_count (num,
10313 longest_to_int (value_as_long (parse_and_eval (p))),
10316 printf_filtered ("\n");
10319 /* Call FUNCTION on each of the breakpoints
10320 whose numbers are given in ARGS. */
10323 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
10330 struct breakpoint *b, *tmp;
10334 error_no_arg (_("one or more breakpoint numbers"));
10341 num = get_number_or_range (&p1);
10344 warning (_("bad breakpoint number at or near '%s'"), p);
10348 ALL_BREAKPOINTS_SAFE (b, tmp)
10349 if (b->number == num)
10351 struct breakpoint *related_breakpoint = b->related_breakpoint;
10353 function (b, data);
10354 if (related_breakpoint)
10355 function (related_breakpoint, data);
10359 printf_unfiltered (_("No breakpoint number %d.\n"), num);
10365 static struct bp_location *
10366 find_location_by_number (char *number)
10368 char *dot = strchr (number, '.');
10372 struct breakpoint *b;
10373 struct bp_location *loc;
10378 bp_num = get_number_or_range (&p1);
10380 error (_("Bad breakpoint number '%s'"), number);
10382 ALL_BREAKPOINTS (b)
10383 if (b->number == bp_num)
10388 if (!b || b->number != bp_num)
10389 error (_("Bad breakpoint number '%s'"), number);
10392 loc_num = get_number_or_range (&p1);
10394 error (_("Bad breakpoint location number '%s'"), number);
10398 for (;loc_num && loc; --loc_num, loc = loc->next)
10401 error (_("Bad breakpoint location number '%s'"), dot+1);
10407 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10408 If from_tty is nonzero, it prints a message to that effect,
10409 which ends with a period (no newline). */
10412 disable_breakpoint (struct breakpoint *bpt)
10414 /* Never disable a watchpoint scope breakpoint; we want to
10415 hit them when we leave scope so we can delete both the
10416 watchpoint and its scope breakpoint at that time. */
10417 if (bpt->type == bp_watchpoint_scope)
10420 /* You can't disable permanent breakpoints. */
10421 if (bpt->enable_state == bp_permanent)
10424 bpt->enable_state = bp_disabled;
10426 update_global_location_list (0);
10428 observer_notify_breakpoint_modified (bpt->number);
10431 /* A callback for map_breakpoint_numbers that calls
10432 disable_breakpoint. */
10435 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
10437 disable_breakpoint (b);
10441 disable_command (char *args, int from_tty)
10443 struct breakpoint *bpt;
10446 ALL_BREAKPOINTS (bpt)
10450 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10453 case bp_breakpoint:
10454 case bp_tracepoint:
10455 case bp_fast_tracepoint:
10456 case bp_static_tracepoint:
10457 case bp_catchpoint:
10458 case bp_hardware_breakpoint:
10459 case bp_watchpoint:
10460 case bp_hardware_watchpoint:
10461 case bp_read_watchpoint:
10462 case bp_access_watchpoint:
10463 disable_breakpoint (bpt);
10467 else if (strchr (args, '.'))
10469 struct bp_location *loc = find_location_by_number (args);
10472 update_global_location_list (0);
10475 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
10479 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
10481 int target_resources_ok;
10483 if (bpt->type == bp_hardware_breakpoint)
10486 i = hw_breakpoint_used_count ();
10487 target_resources_ok =
10488 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10490 if (target_resources_ok == 0)
10491 error (_("No hardware breakpoint support in the target."));
10492 else if (target_resources_ok < 0)
10493 error (_("Hardware breakpoints used exceeds limit."));
10496 if (is_watchpoint (bpt))
10498 struct gdb_exception e;
10500 TRY_CATCH (e, RETURN_MASK_ALL)
10502 update_watchpoint (bpt, 1 /* reparse */);
10506 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10512 if (bpt->enable_state != bp_permanent)
10513 bpt->enable_state = bp_enabled;
10514 bpt->disposition = disposition;
10515 update_global_location_list (1);
10516 breakpoints_changed ();
10518 observer_notify_breakpoint_modified (bpt->number);
10523 enable_breakpoint (struct breakpoint *bpt)
10525 do_enable_breakpoint (bpt, bpt->disposition);
10528 /* A callback for map_breakpoint_numbers that calls
10529 enable_breakpoint. */
10532 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10534 enable_breakpoint (b);
10537 /* The enable command enables the specified breakpoints (or all defined
10538 breakpoints) so they once again become (or continue to be) effective
10539 in stopping the inferior. */
10542 enable_command (char *args, int from_tty)
10544 struct breakpoint *bpt;
10547 ALL_BREAKPOINTS (bpt)
10551 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10554 case bp_breakpoint:
10555 case bp_tracepoint:
10556 case bp_fast_tracepoint:
10557 case bp_static_tracepoint:
10558 case bp_catchpoint:
10559 case bp_hardware_breakpoint:
10560 case bp_watchpoint:
10561 case bp_hardware_watchpoint:
10562 case bp_read_watchpoint:
10563 case bp_access_watchpoint:
10564 enable_breakpoint (bpt);
10568 else if (strchr (args, '.'))
10570 struct bp_location *loc = find_location_by_number (args);
10573 update_global_location_list (1);
10576 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
10580 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
10582 do_enable_breakpoint (bpt, disp_disable);
10586 enable_once_command (char *args, int from_tty)
10588 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
10592 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
10594 do_enable_breakpoint (bpt, disp_del);
10598 enable_delete_command (char *args, int from_tty)
10600 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
10604 set_breakpoint_cmd (char *args, int from_tty)
10609 show_breakpoint_cmd (char *args, int from_tty)
10613 /* Invalidate last known value of any hardware watchpoint if
10614 the memory which that value represents has been written to by
10618 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
10619 const bfd_byte *data)
10621 struct breakpoint *bp;
10623 ALL_BREAKPOINTS (bp)
10624 if (bp->enable_state == bp_enabled
10625 && bp->type == bp_hardware_watchpoint
10626 && bp->val_valid && bp->val)
10628 struct bp_location *loc;
10630 for (loc = bp->loc; loc != NULL; loc = loc->next)
10631 if (loc->loc_type == bp_loc_hardware_watchpoint
10632 && loc->address + loc->length > addr
10633 && addr + len > loc->address)
10635 value_free (bp->val);
10642 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10644 struct symtabs_and_lines
10645 decode_line_spec_1 (char *string, int funfirstline)
10647 struct symtabs_and_lines sals;
10650 error (_("Empty line specification."));
10651 if (default_breakpoint_valid)
10652 sals = decode_line_1 (&string, funfirstline,
10653 default_breakpoint_symtab,
10654 default_breakpoint_line,
10655 (char ***) NULL, NULL);
10657 sals = decode_line_1 (&string, funfirstline,
10658 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
10660 error (_("Junk at end of line specification: %s"), string);
10664 /* Create and insert a raw software breakpoint at PC. Return an
10665 identifier, which should be used to remove the breakpoint later.
10666 In general, places which call this should be using something on the
10667 breakpoint chain instead; this function should be eliminated
10671 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
10672 struct address_space *aspace, CORE_ADDR pc)
10674 struct bp_target_info *bp_tgt;
10676 bp_tgt = XZALLOC (struct bp_target_info);
10678 bp_tgt->placed_address_space = aspace;
10679 bp_tgt->placed_address = pc;
10681 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
10683 /* Could not insert the breakpoint. */
10691 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10694 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
10696 struct bp_target_info *bp_tgt = bp;
10699 ret = target_remove_breakpoint (gdbarch, bp_tgt);
10705 /* One (or perhaps two) breakpoints used for software single stepping. */
10707 static void *single_step_breakpoints[2];
10708 static struct gdbarch *single_step_gdbarch[2];
10710 /* Create and insert a breakpoint for software single step. */
10713 insert_single_step_breakpoint (struct gdbarch *gdbarch,
10714 struct address_space *aspace, CORE_ADDR next_pc)
10718 if (single_step_breakpoints[0] == NULL)
10720 bpt_p = &single_step_breakpoints[0];
10721 single_step_gdbarch[0] = gdbarch;
10725 gdb_assert (single_step_breakpoints[1] == NULL);
10726 bpt_p = &single_step_breakpoints[1];
10727 single_step_gdbarch[1] = gdbarch;
10730 /* NOTE drow/2006-04-11: A future improvement to this function would be
10731 to only create the breakpoints once, and actually put them on the
10732 breakpoint chain. That would let us use set_raw_breakpoint. We could
10733 adjust the addresses each time they were needed. Doing this requires
10734 corresponding changes elsewhere where single step breakpoints are
10735 handled, however. So, for now, we use this. */
10737 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
10738 if (*bpt_p == NULL)
10739 error (_("Could not insert single-step breakpoint at %s"),
10740 paddress (gdbarch, next_pc));
10743 /* Check if the breakpoints used for software single stepping
10744 were inserted or not. */
10747 single_step_breakpoints_inserted (void)
10749 return (single_step_breakpoints[0] != NULL
10750 || single_step_breakpoints[1] != NULL);
10753 /* Remove and delete any breakpoints used for software single step. */
10756 remove_single_step_breakpoints (void)
10758 gdb_assert (single_step_breakpoints[0] != NULL);
10760 /* See insert_single_step_breakpoint for more about this deprecated
10762 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
10763 single_step_breakpoints[0]);
10764 single_step_gdbarch[0] = NULL;
10765 single_step_breakpoints[0] = NULL;
10767 if (single_step_breakpoints[1] != NULL)
10769 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
10770 single_step_breakpoints[1]);
10771 single_step_gdbarch[1] = NULL;
10772 single_step_breakpoints[1] = NULL;
10776 /* Delete software single step breakpoints without removing them from
10777 the inferior. This is intended to be used if the inferior's address
10778 space where they were inserted is already gone, e.g. after exit or
10782 cancel_single_step_breakpoints (void)
10786 for (i = 0; i < 2; i++)
10787 if (single_step_breakpoints[i])
10789 xfree (single_step_breakpoints[i]);
10790 single_step_breakpoints[i] = NULL;
10791 single_step_gdbarch[i] = NULL;
10795 /* Detach software single-step breakpoints from INFERIOR_PTID without
10799 detach_single_step_breakpoints (void)
10803 for (i = 0; i < 2; i++)
10804 if (single_step_breakpoints[i])
10805 target_remove_breakpoint (single_step_gdbarch[i],
10806 single_step_breakpoints[i]);
10809 /* Check whether a software single-step breakpoint is inserted at PC. */
10812 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
10817 for (i = 0; i < 2; i++)
10819 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
10821 && breakpoint_address_match (bp_tgt->placed_address_space,
10822 bp_tgt->placed_address,
10830 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10831 non-zero otherwise. */
10833 is_syscall_catchpoint_enabled (struct breakpoint *bp)
10835 if (syscall_catchpoint_p (bp)
10836 && bp->enable_state != bp_disabled
10837 && bp->enable_state != bp_call_disabled)
10844 catch_syscall_enabled (void)
10846 struct inferior *inf = current_inferior ();
10848 return inf->total_syscalls_count != 0;
10852 catching_syscall_number (int syscall_number)
10854 struct breakpoint *bp;
10856 ALL_BREAKPOINTS (bp)
10857 if (is_syscall_catchpoint_enabled (bp))
10859 if (bp->syscalls_to_be_caught)
10863 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
10865 if (syscall_number == iter)
10875 /* Complete syscall names. Used by "catch syscall". */
10877 catch_syscall_completer (struct cmd_list_element *cmd,
10878 char *text, char *word)
10880 const char **list = get_syscall_names ();
10882 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
10885 /* Tracepoint-specific operations. */
10887 /* Set tracepoint count to NUM. */
10889 set_tracepoint_count (int num)
10891 tracepoint_count = num;
10892 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
10896 trace_command (char *arg, int from_tty)
10898 if (create_breakpoint (get_current_arch (),
10900 NULL, 0, 1 /* parse arg */,
10902 bp_tracepoint /* type_wanted */,
10903 0 /* Ignore count */,
10904 pending_break_support,
10908 set_tracepoint_count (breakpoint_count);
10912 ftrace_command (char *arg, int from_tty)
10914 if (create_breakpoint (get_current_arch (),
10916 NULL, 0, 1 /* parse arg */,
10918 bp_fast_tracepoint /* type_wanted */,
10919 0 /* Ignore count */,
10920 pending_break_support,
10924 set_tracepoint_count (breakpoint_count);
10927 /* strace command implementation. Creates a static tracepoint. */
10930 strace_command (char *arg, int from_tty)
10932 if (create_breakpoint (get_current_arch (),
10934 NULL, 0, 1 /* parse arg */,
10936 bp_static_tracepoint /* type_wanted */,
10937 0 /* Ignore count */,
10938 pending_break_support,
10942 set_tracepoint_count (breakpoint_count);
10945 /* Set up a fake reader function that gets command lines from a linked
10946 list that was acquired during tracepoint uploading. */
10948 static struct uploaded_tp *this_utp;
10949 static int next_cmd;
10952 read_uploaded_action (void)
10956 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
10963 /* Given information about a tracepoint as recorded on a target (which
10964 can be either a live system or a trace file), attempt to create an
10965 equivalent GDB tracepoint. This is not a reliable process, since
10966 the target does not necessarily have all the information used when
10967 the tracepoint was originally defined. */
10969 struct breakpoint *
10970 create_tracepoint_from_upload (struct uploaded_tp *utp)
10972 char *addr_str, small_buf[100];
10973 struct breakpoint *tp;
10975 if (utp->at_string)
10976 addr_str = utp->at_string;
10979 /* In the absence of a source location, fall back to raw
10980 address. Since there is no way to confirm that the address
10981 means the same thing as when the trace was started, warn the
10983 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10985 sprintf (small_buf, "*%s", hex_string (utp->addr));
10986 addr_str = small_buf;
10989 /* There's not much we can do with a sequence of bytecodes. */
10990 if (utp->cond && !utp->cond_string)
10991 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10994 if (!create_breakpoint (get_current_arch (),
10996 utp->cond_string, -1, 0 /* parse cond/thread */,
10998 utp->type /* type_wanted */,
10999 0 /* Ignore count */,
11000 pending_break_support,
11003 utp->enabled /* enabled */))
11006 set_tracepoint_count (breakpoint_count);
11008 /* Get the tracepoint we just created. */
11009 tp = get_tracepoint (tracepoint_count);
11010 gdb_assert (tp != NULL);
11014 sprintf (small_buf, "%d %d", utp->pass, tp->number);
11016 trace_pass_command (small_buf, 0);
11019 /* If we have uploaded versions of the original commands, set up a
11020 special-purpose "reader" function and call the usual command line
11021 reader, then pass the result to the breakpoint command-setting
11023 if (!VEC_empty (char_ptr, utp->cmd_strings))
11025 struct command_line *cmd_list;
11030 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
11032 breakpoint_set_commands (tp, cmd_list);
11034 else if (!VEC_empty (char_ptr, utp->actions)
11035 || !VEC_empty (char_ptr, utp->step_actions))
11036 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
11042 /* Print information on tracepoint number TPNUM_EXP, or all if
11046 tracepoints_info (char *tpnum_exp, int from_tty)
11048 int tpnum = -1, num_printed;
11051 tpnum = parse_and_eval_long (tpnum_exp);
11053 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
11055 if (num_printed == 0)
11058 ui_out_message (uiout, 0, "No tracepoints.\n");
11060 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
11063 default_collect_info ();
11066 /* The 'enable trace' command enables tracepoints.
11067 Not supported by all targets. */
11069 enable_trace_command (char *args, int from_tty)
11071 enable_command (args, from_tty);
11074 /* The 'disable trace' command disables tracepoints.
11075 Not supported by all targets. */
11077 disable_trace_command (char *args, int from_tty)
11079 disable_command (args, from_tty);
11082 /* Remove a tracepoint (or all if no argument) */
11084 delete_trace_command (char *arg, int from_tty)
11086 struct breakpoint *b, *temp;
11092 int breaks_to_delete = 0;
11094 /* Delete all breakpoints if no argument.
11095 Do not delete internal or call-dummy breakpoints, these
11096 have to be deleted with an explicit breakpoint number argument. */
11097 ALL_TRACEPOINTS (b)
11099 if (b->number >= 0)
11101 breaks_to_delete = 1;
11106 /* Ask user only if there are some breakpoints to delete. */
11108 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
11110 ALL_BREAKPOINTS_SAFE (b, temp)
11112 if (is_tracepoint (b)
11114 delete_breakpoint (b);
11119 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
11122 /* Set passcount for tracepoint.
11124 First command argument is passcount, second is tracepoint number.
11125 If tracepoint number omitted, apply to most recently defined.
11126 Also accepts special argument "all". */
11129 trace_pass_command (char *args, int from_tty)
11131 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
11132 unsigned int count;
11135 if (args == 0 || *args == 0)
11136 error (_("passcount command requires an argument (count + optional TP num)"));
11138 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
11140 while (*args && isspace ((int) *args))
11143 if (*args && strncasecmp (args, "all", 3) == 0)
11145 args += 3; /* Skip special argument "all". */
11148 error (_("Junk at end of arguments."));
11151 t1 = get_tracepoint_by_number (&args, 1, 1);
11157 ALL_TRACEPOINTS (t2)
11158 if (t1 == (struct breakpoint *) -1 || t1 == t2)
11160 t2->pass_count = count;
11161 observer_notify_tracepoint_modified (t2->number);
11163 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
11164 t2->number, count);
11166 if (! all && *args)
11167 t1 = get_tracepoint_by_number (&args, 1, 0);
11173 struct breakpoint *
11174 get_tracepoint (int num)
11176 struct breakpoint *t;
11178 ALL_TRACEPOINTS (t)
11179 if (t->number == num)
11185 /* Find the tracepoint with the given target-side number (which may be
11186 different from the tracepoint number after disconnecting and
11189 struct breakpoint *
11190 get_tracepoint_by_number_on_target (int num)
11192 struct breakpoint *t;
11194 ALL_TRACEPOINTS (t)
11195 if (t->number_on_target == num)
11201 /* Utility: parse a tracepoint number and look it up in the list.
11202 If MULTI_P is true, there might be a range of tracepoints in ARG.
11203 if OPTIONAL_P is true, then if the argument is missing, the most
11204 recent tracepoint (tracepoint_count) is returned. */
11205 struct breakpoint *
11206 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
11208 extern int tracepoint_count;
11209 struct breakpoint *t;
11211 char *instring = arg == NULL ? NULL : *arg;
11213 if (arg == NULL || *arg == NULL || ! **arg)
11216 tpnum = tracepoint_count;
11218 error_no_arg (_("tracepoint number"));
11221 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
11225 if (instring && *instring)
11226 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11229 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
11233 ALL_TRACEPOINTS (t)
11234 if (t->number == tpnum)
11239 /* FIXME: if we are in the middle of a range we don't want to give
11240 a message. The current interface to get_number_or_range doesn't
11241 allow us to discover this. */
11242 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
11246 /* Save information on user settable breakpoints (watchpoints, etc) to
11247 a new script file named FILENAME. If FILTER is non-NULL, call it
11248 on each breakpoint and only include the ones for which it returns
11252 save_breakpoints (char *filename, int from_tty,
11253 int (*filter) (const struct breakpoint *))
11255 struct breakpoint *tp;
11258 struct cleanup *cleanup;
11259 struct ui_file *fp;
11260 int extra_trace_bits = 0;
11262 if (filename == 0 || *filename == 0)
11263 error (_("Argument required (file name in which to save)"));
11265 /* See if we have anything to save. */
11266 ALL_BREAKPOINTS (tp)
11268 /* Skip internal and momentary breakpoints. */
11269 if (!user_settable_breakpoint (tp))
11272 /* If we have a filter, only save the breakpoints it accepts. */
11273 if (filter && !filter (tp))
11278 if (is_tracepoint (tp))
11280 extra_trace_bits = 1;
11282 /* We can stop searching. */
11289 warning (_("Nothing to save."));
11293 pathname = tilde_expand (filename);
11294 cleanup = make_cleanup (xfree, pathname);
11295 fp = gdb_fopen (pathname, "w");
11297 error (_("Unable to open file '%s' for saving (%s)"),
11298 filename, safe_strerror (errno));
11299 make_cleanup_ui_file_delete (fp);
11301 if (extra_trace_bits)
11302 save_trace_state_variables (fp);
11304 ALL_BREAKPOINTS (tp)
11306 /* Skip internal and momentary breakpoints. */
11307 if (!user_settable_breakpoint (tp))
11310 /* If we have a filter, only save the breakpoints it accepts. */
11311 if (filter && !filter (tp))
11314 if (tp->ops != NULL)
11315 (tp->ops->print_recreate) (tp, fp);
11318 if (tp->type == bp_fast_tracepoint)
11319 fprintf_unfiltered (fp, "ftrace");
11320 if (tp->type == bp_static_tracepoint)
11321 fprintf_unfiltered (fp, "strace");
11322 else if (tp->type == bp_tracepoint)
11323 fprintf_unfiltered (fp, "trace");
11324 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11325 fprintf_unfiltered (fp, "tbreak");
11326 else if (tp->type == bp_breakpoint)
11327 fprintf_unfiltered (fp, "break");
11328 else if (tp->type == bp_hardware_breakpoint
11329 && tp->disposition == disp_del)
11330 fprintf_unfiltered (fp, "thbreak");
11331 else if (tp->type == bp_hardware_breakpoint)
11332 fprintf_unfiltered (fp, "hbreak");
11333 else if (tp->type == bp_watchpoint)
11334 fprintf_unfiltered (fp, "watch");
11335 else if (tp->type == bp_hardware_watchpoint)
11336 fprintf_unfiltered (fp, "watch");
11337 else if (tp->type == bp_read_watchpoint)
11338 fprintf_unfiltered (fp, "rwatch");
11339 else if (tp->type == bp_access_watchpoint)
11340 fprintf_unfiltered (fp, "awatch");
11342 internal_error (__FILE__, __LINE__,
11343 _("unhandled breakpoint type %d"), (int) tp->type);
11345 if (tp->exp_string)
11346 fprintf_unfiltered (fp, " %s", tp->exp_string);
11347 else if (tp->addr_string)
11348 fprintf_unfiltered (fp, " %s", tp->addr_string);
11353 sprintf_vma (tmp, tp->loc->address);
11354 fprintf_unfiltered (fp, " *0x%s", tmp);
11358 if (tp->thread != -1)
11359 fprintf_unfiltered (fp, " thread %d", tp->thread);
11362 fprintf_unfiltered (fp, " task %d", tp->task);
11364 fprintf_unfiltered (fp, "\n");
11366 /* Note, we can't rely on tp->number for anything, as we can't
11367 assume the recreated breakpoint numbers will match. Use $bpnum
11370 if (tp->cond_string)
11371 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
11373 if (tp->ignore_count)
11374 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
11376 if (tp->pass_count)
11377 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11381 volatile struct gdb_exception ex;
11383 fprintf_unfiltered (fp, " commands\n");
11385 ui_out_redirect (uiout, fp);
11386 TRY_CATCH (ex, RETURN_MASK_ERROR)
11388 print_command_lines (uiout, tp->commands->commands, 2);
11390 ui_out_redirect (uiout, NULL);
11393 throw_exception (ex);
11395 fprintf_unfiltered (fp, " end\n");
11398 if (tp->enable_state == bp_disabled)
11399 fprintf_unfiltered (fp, "disable\n");
11401 /* If this is a multi-location breakpoint, check if the locations
11402 should be individually disabled. Watchpoint locations are
11403 special, and not user visible. */
11404 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
11406 struct bp_location *loc;
11409 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
11411 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
11415 if (extra_trace_bits && *default_collect)
11416 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
11418 do_cleanups (cleanup);
11420 printf_filtered (_("Saved to file '%s'.\n"), filename);
11423 /* The `save breakpoints' command. */
11426 save_breakpoints_command (char *args, int from_tty)
11428 save_breakpoints (args, from_tty, NULL);
11431 /* The `save tracepoints' command. */
11434 save_tracepoints_command (char *args, int from_tty)
11436 save_breakpoints (args, from_tty, is_tracepoint);
11439 /* Create a vector of all tracepoints. */
11441 VEC(breakpoint_p) *
11444 VEC(breakpoint_p) *tp_vec = 0;
11445 struct breakpoint *tp;
11447 ALL_TRACEPOINTS (tp)
11449 VEC_safe_push (breakpoint_p, tp_vec, tp);
11456 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11457 It is defined as a macro to prevent duplication.
11458 COMMAND should be a string constant containing the name of the command. */
11459 #define BREAK_ARGS_HELP(command) \
11460 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11461 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11462 If a line number is specified, break at start of code for that line.\n\
11463 If a function is specified, break at start of code for that function.\n\
11464 If an address is specified, break at that exact address.\n\
11465 With no LOCATION, uses current execution address of the selected\n\
11466 stack frame. This is useful for breaking on return to a stack frame.\n\
11468 THREADNUM is the number from \"info threads\".\n\
11469 CONDITION is a boolean expression.\n\
11471 Multiple breakpoints at one place are permitted, and useful if their\n\
11472 conditions are different.\n\
11474 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11476 /* List of subcommands for "catch". */
11477 static struct cmd_list_element *catch_cmdlist;
11479 /* List of subcommands for "tcatch". */
11480 static struct cmd_list_element *tcatch_cmdlist;
11482 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11483 lists, and pass some additional user data to the command function. */
11485 add_catch_command (char *name, char *docstring,
11486 void (*sfunc) (char *args, int from_tty,
11487 struct cmd_list_element *command),
11488 char **(*completer) (struct cmd_list_element *cmd,
11489 char *text, char *word),
11490 void *user_data_catch,
11491 void *user_data_tcatch)
11493 struct cmd_list_element *command;
11495 command = add_cmd (name, class_breakpoint, NULL, docstring,
11497 set_cmd_sfunc (command, sfunc);
11498 set_cmd_context (command, user_data_catch);
11499 set_cmd_completer (command, completer);
11501 command = add_cmd (name, class_breakpoint, NULL, docstring,
11503 set_cmd_sfunc (command, sfunc);
11504 set_cmd_context (command, user_data_tcatch);
11505 set_cmd_completer (command, completer);
11509 clear_syscall_counts (struct inferior *inf)
11511 inf->total_syscalls_count = 0;
11512 inf->any_syscall_count = 0;
11513 VEC_free (int, inf->syscalls_counts);
11517 save_command (char *arg, int from_tty)
11519 printf_unfiltered (_("\
11520 \"save\" must be followed by the name of a save subcommand.\n"));
11521 help_list (save_cmdlist, "save ", -1, gdb_stdout);
11525 _initialize_breakpoint (void)
11527 struct cmd_list_element *c;
11529 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
11530 observer_attach_inferior_exit (clear_syscall_counts);
11531 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
11533 breakpoint_chain = 0;
11534 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11535 before a breakpoint is set. */
11536 breakpoint_count = 0;
11538 tracepoint_count = 0;
11540 add_com ("ignore", class_breakpoint, ignore_command, _("\
11541 Set ignore-count of breakpoint number N to COUNT.\n\
11542 Usage is `ignore N COUNT'."));
11544 add_com_alias ("bc", "ignore", class_breakpoint, 1);
11546 add_com ("commands", class_breakpoint, commands_command, _("\
11547 Set commands to be executed when a breakpoint is hit.\n\
11548 Give breakpoint number as argument after \"commands\".\n\
11549 With no argument, the targeted breakpoint is the last one set.\n\
11550 The commands themselves follow starting on the next line.\n\
11551 Type a line containing \"end\" to indicate the end of them.\n\
11552 Give \"silent\" as the first line to make the breakpoint silent;\n\
11553 then no output is printed when it is hit, except what the commands print."));
11555 add_com ("condition", class_breakpoint, condition_command, _("\
11556 Specify breakpoint number N to break only if COND is true.\n\
11557 Usage is `condition N COND', where N is an integer and COND is an\n\
11558 expression to be evaluated whenever breakpoint N is reached."));
11560 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
11561 Set a temporary breakpoint.\n\
11562 Like \"break\" except the breakpoint is only temporary,\n\
11563 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11564 by using \"enable delete\" on the breakpoint number.\n\
11566 BREAK_ARGS_HELP ("tbreak")));
11567 set_cmd_completer (c, location_completer);
11569 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
11570 Set a hardware assisted breakpoint.\n\
11571 Like \"break\" except the breakpoint requires hardware support,\n\
11572 some target hardware may not have this support.\n\
11574 BREAK_ARGS_HELP ("hbreak")));
11575 set_cmd_completer (c, location_completer);
11577 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
11578 Set a temporary hardware assisted breakpoint.\n\
11579 Like \"hbreak\" except the breakpoint is only temporary,\n\
11580 so it will be deleted when hit.\n\
11582 BREAK_ARGS_HELP ("thbreak")));
11583 set_cmd_completer (c, location_completer);
11585 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
11586 Enable some breakpoints.\n\
11587 Give breakpoint numbers (separated by spaces) as arguments.\n\
11588 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11589 This is used to cancel the effect of the \"disable\" command.\n\
11590 With a subcommand you can enable temporarily."),
11591 &enablelist, "enable ", 1, &cmdlist);
11593 add_com ("ab", class_breakpoint, enable_command, _("\
11594 Enable some breakpoints.\n\
11595 Give breakpoint numbers (separated by spaces) as arguments.\n\
11596 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11597 This is used to cancel the effect of the \"disable\" command.\n\
11598 With a subcommand you can enable temporarily."));
11600 add_com_alias ("en", "enable", class_breakpoint, 1);
11602 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
11603 Enable some breakpoints.\n\
11604 Give breakpoint numbers (separated by spaces) as arguments.\n\
11605 This is used to cancel the effect of the \"disable\" command.\n\
11606 May be abbreviated to simply \"enable\".\n"),
11607 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
11609 add_cmd ("once", no_class, enable_once_command, _("\
11610 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11611 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11614 add_cmd ("delete", no_class, enable_delete_command, _("\
11615 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11616 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11619 add_cmd ("delete", no_class, enable_delete_command, _("\
11620 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11621 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11624 add_cmd ("once", no_class, enable_once_command, _("\
11625 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11626 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11629 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
11630 Disable some breakpoints.\n\
11631 Arguments are breakpoint numbers with spaces in between.\n\
11632 To disable all breakpoints, give no argument.\n\
11633 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11634 &disablelist, "disable ", 1, &cmdlist);
11635 add_com_alias ("dis", "disable", class_breakpoint, 1);
11636 add_com_alias ("disa", "disable", class_breakpoint, 1);
11638 add_com ("sb", class_breakpoint, disable_command, _("\
11639 Disable some breakpoints.\n\
11640 Arguments are breakpoint numbers with spaces in between.\n\
11641 To disable all breakpoints, give no argument.\n\
11642 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11644 add_cmd ("breakpoints", class_alias, disable_command, _("\
11645 Disable some breakpoints.\n\
11646 Arguments are breakpoint numbers with spaces in between.\n\
11647 To disable all breakpoints, give no argument.\n\
11648 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11649 This command may be abbreviated \"disable\"."),
11652 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
11653 Delete some breakpoints or auto-display expressions.\n\
11654 Arguments are breakpoint numbers with spaces in between.\n\
11655 To delete all breakpoints, give no argument.\n\
11657 Also a prefix command for deletion of other GDB objects.\n\
11658 The \"unset\" command is also an alias for \"delete\"."),
11659 &deletelist, "delete ", 1, &cmdlist);
11660 add_com_alias ("d", "delete", class_breakpoint, 1);
11661 add_com_alias ("del", "delete", class_breakpoint, 1);
11663 add_com ("db", class_breakpoint, delete_command, _("\
11664 Delete some breakpoints.\n\
11665 Arguments are breakpoint numbers with spaces in between.\n\
11666 To delete all breakpoints, give no argument.\n"));
11668 add_cmd ("breakpoints", class_alias, delete_command, _("\
11669 Delete some breakpoints or auto-display expressions.\n\
11670 Arguments are breakpoint numbers with spaces in between.\n\
11671 To delete all breakpoints, give no argument.\n\
11672 This command may be abbreviated \"delete\"."),
11675 add_com ("clear", class_breakpoint, clear_command, _("\
11676 Clear breakpoint at specified line or function.\n\
11677 Argument may be line number, function name, or \"*\" and an address.\n\
11678 If line number is specified, all breakpoints in that line are cleared.\n\
11679 If function is specified, breakpoints at beginning of function are cleared.\n\
11680 If an address is specified, breakpoints at that address are cleared.\n\
11682 With no argument, clears all breakpoints in the line that the selected frame\n\
11683 is executing in.\n\
11685 See also the \"delete\" command which clears breakpoints by number."));
11686 add_com_alias ("cl", "clear", class_breakpoint, 1);
11688 c = add_com ("break", class_breakpoint, break_command, _("\
11689 Set breakpoint at specified line or function.\n"
11690 BREAK_ARGS_HELP ("break")));
11691 set_cmd_completer (c, location_completer);
11693 add_com_alias ("b", "break", class_run, 1);
11694 add_com_alias ("br", "break", class_run, 1);
11695 add_com_alias ("bre", "break", class_run, 1);
11696 add_com_alias ("brea", "break", class_run, 1);
11699 add_com_alias ("ba", "break", class_breakpoint, 1);
11703 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
11704 Break in function/address or break at a line in the current file."),
11705 &stoplist, "stop ", 1, &cmdlist);
11706 add_cmd ("in", class_breakpoint, stopin_command,
11707 _("Break in function or address."), &stoplist);
11708 add_cmd ("at", class_breakpoint, stopat_command,
11709 _("Break at a line in the current file."), &stoplist);
11710 add_com ("status", class_info, breakpoints_info, _("\
11711 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11712 The \"Type\" column indicates one of:\n\
11713 \tbreakpoint - normal breakpoint\n\
11714 \twatchpoint - watchpoint\n\
11715 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11716 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11717 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11718 address and file/line number respectively.\n\
11720 Convenience variable \"$_\" and default examine address for \"x\"\n\
11721 are set to the address of the last breakpoint listed unless the command\n\
11722 is prefixed with \"server \".\n\n\
11723 Convenience variable \"$bpnum\" contains the number of the last\n\
11724 breakpoint set."));
11727 add_info ("breakpoints", breakpoints_info, _("\
11728 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11729 The \"Type\" column indicates one of:\n\
11730 \tbreakpoint - normal breakpoint\n\
11731 \twatchpoint - watchpoint\n\
11732 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11733 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11734 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11735 address and file/line number respectively.\n\
11737 Convenience variable \"$_\" and default examine address for \"x\"\n\
11738 are set to the address of the last breakpoint listed unless the command\n\
11739 is prefixed with \"server \".\n\n\
11740 Convenience variable \"$bpnum\" contains the number of the last\n\
11741 breakpoint set."));
11743 add_info_alias ("b", "breakpoints", 1);
11746 add_com ("lb", class_breakpoint, breakpoints_info, _("\
11747 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11748 The \"Type\" column indicates one of:\n\
11749 \tbreakpoint - normal breakpoint\n\
11750 \twatchpoint - watchpoint\n\
11751 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11752 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11753 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11754 address and file/line number respectively.\n\
11756 Convenience variable \"$_\" and default examine address for \"x\"\n\
11757 are set to the address of the last breakpoint listed unless the command\n\
11758 is prefixed with \"server \".\n\n\
11759 Convenience variable \"$bpnum\" contains the number of the last\n\
11760 breakpoint set."));
11762 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
11763 Status of all breakpoints, or breakpoint number NUMBER.\n\
11764 The \"Type\" column indicates one of:\n\
11765 \tbreakpoint - normal breakpoint\n\
11766 \twatchpoint - watchpoint\n\
11767 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11768 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11769 \tuntil - internal breakpoint used by the \"until\" command\n\
11770 \tfinish - internal breakpoint used by the \"finish\" command\n\
11771 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11772 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11773 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11774 address and file/line number respectively.\n\
11776 Convenience variable \"$_\" and default examine address for \"x\"\n\
11777 are set to the address of the last breakpoint listed unless the command\n\
11778 is prefixed with \"server \".\n\n\
11779 Convenience variable \"$bpnum\" contains the number of the last\n\
11781 &maintenanceinfolist);
11783 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
11784 Set catchpoints to catch events."),
11785 &catch_cmdlist, "catch ",
11786 0/*allow-unknown*/, &cmdlist);
11788 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
11789 Set temporary catchpoints to catch events."),
11790 &tcatch_cmdlist, "tcatch ",
11791 0/*allow-unknown*/, &cmdlist);
11793 /* Add catch and tcatch sub-commands. */
11794 add_catch_command ("catch", _("\
11795 Catch an exception, when caught.\n\
11796 With an argument, catch only exceptions with the given name."),
11797 catch_catch_command,
11801 add_catch_command ("throw", _("\
11802 Catch an exception, when thrown.\n\
11803 With an argument, catch only exceptions with the given name."),
11804 catch_throw_command,
11808 add_catch_command ("fork", _("Catch calls to fork."),
11809 catch_fork_command_1,
11811 (void *) (uintptr_t) catch_fork_permanent,
11812 (void *) (uintptr_t) catch_fork_temporary);
11813 add_catch_command ("vfork", _("Catch calls to vfork."),
11814 catch_fork_command_1,
11816 (void *) (uintptr_t) catch_vfork_permanent,
11817 (void *) (uintptr_t) catch_vfork_temporary);
11818 add_catch_command ("exec", _("Catch calls to exec."),
11819 catch_exec_command_1,
11823 add_catch_command ("syscall", _("\
11824 Catch system calls by their names and/or numbers.\n\
11825 Arguments say which system calls to catch. If no arguments\n\
11826 are given, every system call will be caught.\n\
11827 Arguments, if given, should be one or more system call names\n\
11828 (if your system supports that), or system call numbers."),
11829 catch_syscall_command_1,
11830 catch_syscall_completer,
11833 add_catch_command ("exception", _("\
11834 Catch Ada exceptions, when raised.\n\
11835 With an argument, catch only exceptions with the given name."),
11836 catch_ada_exception_command,
11840 add_catch_command ("assert", _("\
11841 Catch failed Ada assertions, when raised.\n\
11842 With an argument, catch only exceptions with the given name."),
11843 catch_assert_command,
11848 c = add_com ("watch", class_breakpoint, watch_command, _("\
11849 Set a watchpoint for an expression.\n\
11850 A watchpoint stops execution of your program whenever the value of\n\
11851 an expression changes."));
11852 set_cmd_completer (c, expression_completer);
11854 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
11855 Set a read watchpoint for an expression.\n\
11856 A watchpoint stops execution of your program whenever the value of\n\
11857 an expression is read."));
11858 set_cmd_completer (c, expression_completer);
11860 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
11861 Set a watchpoint for an expression.\n\
11862 A watchpoint stops execution of your program whenever the value of\n\
11863 an expression is either read or written."));
11864 set_cmd_completer (c, expression_completer);
11866 add_info ("watchpoints", watchpoints_info, _("\
11867 Status of watchpoints, or watchpoint number NUMBER."));
11871 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11872 respond to changes - contrary to the description. */
11873 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
11874 &can_use_hw_watchpoints, _("\
11875 Set debugger's willingness to use watchpoint hardware."), _("\
11876 Show debugger's willingness to use watchpoint hardware."), _("\
11877 If zero, gdb will not use hardware for new watchpoints, even if\n\
11878 such is available. (However, any hardware watchpoints that were\n\
11879 created before setting this to nonzero, will continue to use watchpoint\n\
11882 show_can_use_hw_watchpoints,
11883 &setlist, &showlist);
11885 can_use_hw_watchpoints = 1;
11887 /* Tracepoint manipulation commands. */
11889 c = add_com ("trace", class_breakpoint, trace_command, _("\
11890 Set a tracepoint at specified line or function.\n\
11892 BREAK_ARGS_HELP ("trace") "\n\
11893 Do \"help tracepoints\" for info on other tracepoint commands."));
11894 set_cmd_completer (c, location_completer);
11896 add_com_alias ("tp", "trace", class_alias, 0);
11897 add_com_alias ("tr", "trace", class_alias, 1);
11898 add_com_alias ("tra", "trace", class_alias, 1);
11899 add_com_alias ("trac", "trace", class_alias, 1);
11901 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
11902 Set a fast tracepoint at specified line or function.\n\
11904 BREAK_ARGS_HELP ("ftrace") "\n\
11905 Do \"help tracepoints\" for info on other tracepoint commands."));
11906 set_cmd_completer (c, location_completer);
11908 c = add_com ("strace", class_breakpoint, strace_command, _("\
11909 Set a static tracepoint at specified line, function or marker.\n\
11911 strace [LOCATION] [if CONDITION]\n\
11912 LOCATION may be a line number, function name, \"*\" and an address,\n\
11913 or -m MARKER_ID.\n\
11914 If a line number is specified, probe the marker at start of code\n\
11915 for that line. If a function is specified, probe the marker at start\n\
11916 of code for that function. If an address is specified, probe the marker\n\
11917 at that exact address. If a marker id is specified, probe the marker\n\
11918 with that name. With no LOCATION, uses current execution address of\n\
11919 the selected stack frame.\n\
11920 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
11921 This collects arbitrary user data passed in the probe point call to the\n\
11922 tracing library. You can inspect it when analyzing the trace buffer,\n\
11923 by printing the $_sdata variable like any other convenience variable.\n\
11925 CONDITION is a boolean expression.\n\
11927 Multiple tracepoints at one place are permitted, and useful if their\n\
11928 conditions are different.\n\
11930 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
11931 Do \"help tracepoints\" for info on other tracepoint commands."));
11932 set_cmd_completer (c, location_completer);
11934 add_info ("tracepoints", tracepoints_info, _("\
11935 Status of tracepoints, or tracepoint number NUMBER.\n\
11936 Convenience variable \"$tpnum\" contains the number of the\n\
11937 last tracepoint set."));
11939 add_info_alias ("tp", "tracepoints", 1);
11941 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
11942 Delete specified tracepoints.\n\
11943 Arguments are tracepoint numbers, separated by spaces.\n\
11944 No argument means delete all tracepoints."),
11947 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
11948 Disable specified tracepoints.\n\
11949 Arguments are tracepoint numbers, separated by spaces.\n\
11950 No argument means disable all tracepoints."),
11952 deprecate_cmd (c, "disable");
11954 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
11955 Enable specified tracepoints.\n\
11956 Arguments are tracepoint numbers, separated by spaces.\n\
11957 No argument means enable all tracepoints."),
11959 deprecate_cmd (c, "enable");
11961 add_com ("passcount", class_trace, trace_pass_command, _("\
11962 Set the passcount for a tracepoint.\n\
11963 The trace will end when the tracepoint has been passed 'count' times.\n\
11964 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11965 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11967 add_prefix_cmd ("save", class_breakpoint, save_command,
11968 _("Save breakpoint definitions as a script."),
11969 &save_cmdlist, "save ",
11970 0/*allow-unknown*/, &cmdlist);
11972 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
11973 Save current breakpoint definitions as a script.\n\
11974 This includes all types of breakpoints (breakpoints, watchpoints,\n\
11975 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11976 session to restore them."),
11978 set_cmd_completer (c, filename_completer);
11980 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
11981 Save current tracepoint definitions as a script.\n\
11982 Use the 'source' command in another debug session to restore them."),
11984 set_cmd_completer (c, filename_completer);
11986 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
11987 deprecate_cmd (c, "save tracepoints");
11989 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
11990 Breakpoint specific settings\n\
11991 Configure various breakpoint-specific variables such as\n\
11992 pending breakpoint behavior"),
11993 &breakpoint_set_cmdlist, "set breakpoint ",
11994 0/*allow-unknown*/, &setlist);
11995 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
11996 Breakpoint specific settings\n\
11997 Configure various breakpoint-specific variables such as\n\
11998 pending breakpoint behavior"),
11999 &breakpoint_show_cmdlist, "show breakpoint ",
12000 0/*allow-unknown*/, &showlist);
12002 add_setshow_auto_boolean_cmd ("pending", no_class,
12003 &pending_break_support, _("\
12004 Set debugger's behavior regarding pending breakpoints."), _("\
12005 Show debugger's behavior regarding pending breakpoints."), _("\
12006 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12007 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12008 an error. If auto, an unrecognized breakpoint location results in a\n\
12009 user-query to see if a pending breakpoint should be created."),
12011 show_pending_break_support,
12012 &breakpoint_set_cmdlist,
12013 &breakpoint_show_cmdlist);
12015 pending_break_support = AUTO_BOOLEAN_AUTO;
12017 add_setshow_boolean_cmd ("auto-hw", no_class,
12018 &automatic_hardware_breakpoints, _("\
12019 Set automatic usage of hardware breakpoints."), _("\
12020 Show automatic usage of hardware breakpoints."), _("\
12021 If set, the debugger will automatically use hardware breakpoints for\n\
12022 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12023 a warning will be emitted for such breakpoints."),
12025 show_automatic_hardware_breakpoints,
12026 &breakpoint_set_cmdlist,
12027 &breakpoint_show_cmdlist);
12029 add_setshow_enum_cmd ("always-inserted", class_support,
12030 always_inserted_enums, &always_inserted_mode, _("\
12031 Set mode for inserting breakpoints."), _("\
12032 Show mode for inserting breakpoints."), _("\
12033 When this mode is off, breakpoints are inserted in inferior when it is\n\
12034 resumed, and removed when execution stops. When this mode is on,\n\
12035 breakpoints are inserted immediately and removed only when the user\n\
12036 deletes the breakpoint. When this mode is auto (which is the default),\n\
12037 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12038 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12039 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12040 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12042 &show_always_inserted_mode,
12043 &breakpoint_set_cmdlist,
12044 &breakpoint_show_cmdlist);
12046 automatic_hardware_breakpoints = 1;
12048 observer_attach_about_to_proceed (breakpoint_about_to_proceed);