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 static 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 /* Find the current value of a watchpoint on EXP. Return the value in
1238 *VALP and *RESULTP and the chain of intermediate and final values
1239 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1242 If a memory error occurs while evaluating the expression, *RESULTP will
1243 be set to NULL. *RESULTP may be a lazy value, if the result could
1244 not be read from memory. It is used to determine whether a value
1245 is user-specified (we should watch the whole value) or intermediate
1246 (we should watch only the bit used to locate the final value).
1248 If the final value, or any intermediate value, could not be read
1249 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1250 set to any referenced values. *VALP will never be a lazy value.
1251 This is the value which we store in struct breakpoint.
1253 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1254 value chain. The caller must free the values individually. If
1255 VAL_CHAIN is NULL, all generated values will be left on the value
1259 fetch_watchpoint_value (struct expression *exp, struct value **valp,
1260 struct value **resultp, struct value **val_chain)
1262 struct value *mark, *new_mark, *result;
1263 volatile struct gdb_exception ex;
1271 /* Evaluate the expression. */
1272 mark = value_mark ();
1275 TRY_CATCH (ex, RETURN_MASK_ALL)
1277 result = evaluate_expression (exp);
1281 /* Ignore memory errors, we want watchpoints pointing at
1282 inaccessible memory to still be created; otherwise, throw the
1283 error to some higher catcher. */
1289 throw_exception (ex);
1294 new_mark = value_mark ();
1295 if (mark == new_mark)
1300 /* Make sure it's not lazy, so that after the target stops again we
1301 have a non-lazy previous value to compare with. */
1303 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
1308 /* Return the chain of intermediate values. We use this to
1309 decide which addresses to watch. */
1310 *val_chain = new_mark;
1311 value_release_to_mark (mark);
1315 /* Assuming that B is a watchpoint: returns true if the current thread
1316 and its running state are safe to evaluate or update watchpoint B.
1317 Watchpoints on local expressions need to be evaluated in the
1318 context of the thread that was current when the watchpoint was
1319 created, and, that thread needs to be stopped to be able to select
1320 the correct frame context. Watchpoints on global expressions can
1321 be evaluated on any thread, and in any state. It is presently left
1322 to the target allowing memory accesses when threads are
1326 watchpoint_in_thread_scope (struct breakpoint *b)
1328 return (ptid_equal (b->watchpoint_thread, null_ptid)
1329 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1330 && !is_executing (inferior_ptid)));
1333 /* Assuming that B is a watchpoint:
1334 - Reparse watchpoint expression, if REPARSE is non-zero
1335 - Evaluate expression and store the result in B->val
1336 - Evaluate the condition if there is one, and store the result
1338 - Update the list of values that must be watched in B->loc.
1340 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1341 If this is local watchpoint that is out of scope, delete it.
1343 Even with `set breakpoint always-inserted on' the watchpoints are removed
1344 + inserted on each stop here. Normal breakpoints must never be removed
1345 because they might be missed by a running thread when debugging in non-stop
1346 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1347 processed here) are specific to each LWP since they are stored in each LWP's
1348 hardware debug registers. Therefore, such LWP must be stopped first in
1349 order to be able to modify its hardware watchpoints.
1351 Hardware watchpoints must be reset exactly once after being presented to the
1352 user. It cannot be done sooner, because it would reset the data used to
1353 present the watchpoint hit to the user. And it must not be done later
1354 because it could display the same single watchpoint hit during multiple GDB
1355 stops. Note that the latter is relevant only to the hardware watchpoint
1356 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1357 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1358 memory content has not changed.
1360 The following constraints influence the location where we can reset hardware
1363 * target_stopped_by_watchpoint and target_stopped_data_address are called
1364 several times when GDB stops.
1367 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1368 stop. GDB only presents one hardware watchpoint hit at a time as the
1369 reason for stopping, and all the other hits are presented later, one after
1370 the other, each time the user requests the execution to be resumed.
1371 Execution is not resumed for the threads still having pending hit event
1372 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1373 the inferior on the first stop the thread hit event is kept being reported
1374 from its cached value by linux_nat_stopped_data_address until the real
1375 thread resume happens after the watchpoint gets presented and thus its
1376 LWP_INFO->STATUS gets reset.
1378 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1379 removal from inferior. */
1382 update_watchpoint (struct breakpoint *b, int reparse)
1384 int within_current_scope;
1385 struct frame_id saved_frame_id;
1388 /* If this is a local watchpoint, we only want to check if the
1389 watchpoint frame is in scope if the current thread is the thread
1390 that was used to create the watchpoint. */
1391 if (!watchpoint_in_thread_scope (b))
1394 /* We don't free locations. They are stored in bp_location array and
1395 update_global_locations will eventually delete them and remove
1396 breakpoints if needed. */
1399 if (b->disposition == disp_del_at_next_stop)
1404 /* Determine if the watchpoint is within scope. */
1405 if (b->exp_valid_block == NULL)
1406 within_current_scope = 1;
1409 struct frame_info *fi;
1411 /* Save the current frame's ID so we can restore it after
1412 evaluating the watchpoint expression on its own frame. */
1413 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1414 took a frame parameter, so that we didn't have to change the
1417 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1419 fi = frame_find_by_id (b->watchpoint_frame);
1420 within_current_scope = (fi != NULL);
1421 if (within_current_scope)
1425 if (within_current_scope && reparse)
1434 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1435 /* If the meaning of expression itself changed, the old value is
1436 no longer relevant. We don't want to report a watchpoint hit
1437 to the user when the old value and the new value may actually
1438 be completely different objects. */
1439 value_free (b->val);
1443 /* Note that unlike with breakpoints, the watchpoint's condition
1444 expression is stored in the breakpoint object, not in the
1445 locations (re)created below. */
1446 if (b->cond_string != NULL)
1448 if (b->cond_exp != NULL)
1450 xfree (b->cond_exp);
1455 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1459 /* If we failed to parse the expression, for example because
1460 it refers to a global variable in a not-yet-loaded shared library,
1461 don't try to insert watchpoint. We don't automatically delete
1462 such watchpoint, though, since failure to parse expression
1463 is different from out-of-scope watchpoint. */
1464 if ( !target_has_execution)
1466 /* Without execution, memory can't change. No use to try and
1467 set watchpoint locations. The watchpoint will be reset when
1468 the target gains execution, through breakpoint_re_set. */
1470 else if (within_current_scope && b->exp)
1472 struct value *val_chain, *v, *result, *next;
1473 struct program_space *frame_pspace;
1475 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
1477 /* Avoid setting b->val if it's already set. The meaning of
1478 b->val is 'the last value' user saw, and we should update
1479 it only if we reported that last value to user. As it
1480 happens, the code that reports it updates b->val directly. */
1487 /* Change the type of breakpoint between hardware assisted or an
1488 ordinary watchpoint depending on the hardware support and free
1489 hardware slots. REPARSE is set when the inferior is started. */
1490 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1493 int i, mem_cnt, other_type_used;
1495 /* We need to determine how many resources are already used
1496 for all other hardware watchpoints to see if we still have
1497 enough resources to also fit this watchpoint in as well.
1498 To avoid the hw_watchpoint_used_count call below from counting
1499 this watchpoint, make sure that it is marked as a software
1501 b->type = bp_watchpoint;
1502 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
1504 mem_cnt = can_use_hardware_watchpoint (val_chain);
1507 b->type = bp_watchpoint;
1510 int target_resources_ok = target_can_use_hardware_watchpoint
1511 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
1512 if (target_resources_ok <= 0)
1513 b->type = bp_watchpoint;
1515 b->type = bp_hardware_watchpoint;
1519 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1521 /* Look at each value on the value chain. */
1522 for (v = val_chain; v; v = next)
1524 /* If it's a memory location, and GDB actually needed
1525 its contents to evaluate the expression, then we
1526 must watch it. If the first value returned is
1527 still lazy, that means an error occurred reading it;
1528 watch it anyway in case it becomes readable. */
1529 if (VALUE_LVAL (v) == lval_memory
1530 && (v == val_chain || ! value_lazy (v)))
1532 struct type *vtype = check_typedef (value_type (v));
1534 /* We only watch structs and arrays if user asked
1535 for it explicitly, never if they just happen to
1536 appear in the middle of some value chain. */
1538 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1539 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1543 struct bp_location *loc, **tmp;
1545 addr = value_address (v);
1546 len = TYPE_LENGTH (value_type (v));
1548 if (b->type == bp_read_watchpoint)
1550 else if (b->type == bp_access_watchpoint)
1553 loc = allocate_bp_location (b);
1554 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1557 loc->gdbarch = get_type_arch (value_type (v));
1559 loc->pspace = frame_pspace;
1560 loc->address = addr;
1562 loc->watchpoint_type = type;
1566 next = value_next (v);
1571 /* If a software watchpoint is not watching any memory, then the
1572 above left it without any location set up. But,
1573 bpstat_stop_status requires a location to be able to report
1574 stops, so make sure there's at least a dummy one. */
1575 if (b->type == bp_watchpoint && b->loc == NULL)
1577 b->loc = allocate_bp_location (b);
1578 b->loc->pspace = frame_pspace;
1579 b->loc->address = -1;
1580 b->loc->length = -1;
1581 b->loc->watchpoint_type = -1;
1584 else if (!within_current_scope)
1586 printf_filtered (_("\
1587 Watchpoint %d deleted because the program has left the block\n\
1588 in which its expression is valid.\n"),
1590 if (b->related_breakpoint)
1592 b->related_breakpoint->disposition = disp_del_at_next_stop;
1593 b->related_breakpoint->related_breakpoint = NULL;
1594 b->related_breakpoint= NULL;
1596 b->disposition = disp_del_at_next_stop;
1599 /* Restore the selected frame. */
1601 select_frame (frame_find_by_id (saved_frame_id));
1605 /* Returns 1 iff breakpoint location should be
1606 inserted in the inferior. */
1608 should_be_inserted (struct bp_location *bpt)
1610 if (bpt->owner == NULL || !breakpoint_enabled (bpt->owner))
1613 if (bpt->owner->disposition == disp_del_at_next_stop)
1616 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1619 /* This is set for example, when we're attached to the parent of a
1620 vfork, and have detached from the child. The child is running
1621 free, and we expect it to do an exec or exit, at which point the
1622 OS makes the parent schedulable again (and the target reports
1623 that the vfork is done). Until the child is done with the shared
1624 memory region, do not insert breakpoints in the parent, otherwise
1625 the child could still trip on the parent's breakpoints. Since
1626 the parent is blocked anyway, it won't miss any breakpoint. */
1627 if (bpt->pspace->breakpoints_not_allowed)
1630 /* Tracepoints are inserted by the target at a time of its choosing,
1632 if (is_tracepoint (bpt->owner))
1638 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1639 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1640 and HW_BREAKPOINT_ERROR are used to report problems.
1642 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1643 method for each breakpoint or catchpoint type. */
1645 insert_bp_location (struct bp_location *bpt,
1646 struct ui_file *tmp_error_stream,
1647 int *disabled_breaks,
1648 int *hw_breakpoint_error)
1652 if (!should_be_inserted (bpt) || bpt->inserted)
1655 /* Initialize the target-specific information. */
1656 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1657 bpt->target_info.placed_address = bpt->address;
1658 bpt->target_info.placed_address_space = bpt->pspace->aspace;
1660 if (bpt->loc_type == bp_loc_software_breakpoint
1661 || bpt->loc_type == bp_loc_hardware_breakpoint)
1663 if (bpt->owner->type != bp_hardware_breakpoint)
1665 /* If the explicitly specified breakpoint type
1666 is not hardware breakpoint, check the memory map to see
1667 if the breakpoint address is in read only memory or not.
1668 Two important cases are:
1669 - location type is not hardware breakpoint, memory
1670 is readonly. We change the type of the location to
1671 hardware breakpoint.
1672 - location type is hardware breakpoint, memory is read-write.
1673 This means we've previously made the location hardware one, but
1674 then the memory map changed, so we undo.
1676 When breakpoints are removed, remove_breakpoints will
1677 use location types we've just set here, the only possible
1678 problem is that memory map has changed during running program,
1679 but it's not going to work anyway with current gdb. */
1680 struct mem_region *mr
1681 = lookup_mem_region (bpt->target_info.placed_address);
1685 if (automatic_hardware_breakpoints)
1687 enum bp_loc_type new_type;
1689 if (mr->attrib.mode != MEM_RW)
1690 new_type = bp_loc_hardware_breakpoint;
1692 new_type = bp_loc_software_breakpoint;
1694 if (new_type != bpt->loc_type)
1696 static int said = 0;
1698 bpt->loc_type = new_type;
1701 fprintf_filtered (gdb_stdout, _("\
1702 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1707 else if (bpt->loc_type == bp_loc_software_breakpoint
1708 && mr->attrib.mode != MEM_RW)
1709 warning (_("cannot set software breakpoint at readonly address %s"),
1710 paddress (bpt->gdbarch, bpt->address));
1714 /* First check to see if we have to handle an overlay. */
1715 if (overlay_debugging == ovly_off
1716 || bpt->section == NULL
1717 || !(section_is_overlay (bpt->section)))
1719 /* No overlay handling: just set the breakpoint. */
1721 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1722 val = target_insert_hw_breakpoint (bpt->gdbarch,
1725 val = target_insert_breakpoint (bpt->gdbarch,
1730 /* This breakpoint is in an overlay section.
1731 Shall we set a breakpoint at the LMA? */
1732 if (!overlay_events_enabled)
1734 /* Yes -- overlay event support is not active,
1735 so we must try to set a breakpoint at the LMA.
1736 This will not work for a hardware breakpoint. */
1737 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1738 warning (_("hardware breakpoint %d not supported in overlay!"),
1739 bpt->owner->number);
1742 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1744 /* Set a software (trap) breakpoint at the LMA. */
1745 bpt->overlay_target_info = bpt->target_info;
1746 bpt->overlay_target_info.placed_address = addr;
1747 val = target_insert_breakpoint (bpt->gdbarch,
1748 &bpt->overlay_target_info);
1750 fprintf_unfiltered (tmp_error_stream,
1751 "Overlay breakpoint %d failed: in ROM?\n",
1752 bpt->owner->number);
1755 /* Shall we set a breakpoint at the VMA? */
1756 if (section_is_mapped (bpt->section))
1758 /* Yes. This overlay section is mapped into memory. */
1759 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1760 val = target_insert_hw_breakpoint (bpt->gdbarch,
1763 val = target_insert_breakpoint (bpt->gdbarch,
1768 /* No. This breakpoint will not be inserted.
1769 No error, but do not mark the bp as 'inserted'. */
1776 /* Can't set the breakpoint. */
1777 if (solib_name_from_address (bpt->pspace, bpt->address))
1779 /* See also: disable_breakpoints_in_shlibs. */
1781 bpt->shlib_disabled = 1;
1782 if (!*disabled_breaks)
1784 fprintf_unfiltered (tmp_error_stream,
1785 "Cannot insert breakpoint %d.\n",
1786 bpt->owner->number);
1787 fprintf_unfiltered (tmp_error_stream,
1788 "Temporarily disabling shared library breakpoints:\n");
1790 *disabled_breaks = 1;
1791 fprintf_unfiltered (tmp_error_stream,
1792 "breakpoint #%d\n", bpt->owner->number);
1796 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1798 *hw_breakpoint_error = 1;
1799 fprintf_unfiltered (tmp_error_stream,
1800 "Cannot insert hardware breakpoint %d.\n",
1801 bpt->owner->number);
1805 fprintf_unfiltered (tmp_error_stream,
1806 "Cannot insert breakpoint %d.\n",
1807 bpt->owner->number);
1808 fprintf_filtered (tmp_error_stream,
1809 "Error accessing memory address ");
1810 fputs_filtered (paddress (bpt->gdbarch, bpt->address),
1812 fprintf_filtered (tmp_error_stream, ": %s.\n",
1813 safe_strerror (val));
1824 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1825 /* NOTE drow/2003-09-08: This state only exists for removing
1826 watchpoints. It's not clear that it's necessary... */
1827 && bpt->owner->disposition != disp_del_at_next_stop)
1829 val = target_insert_watchpoint (bpt->address,
1831 bpt->watchpoint_type);
1833 /* If trying to set a read-watchpoint, and it turns out it's not
1834 supported, try emulating one with an access watchpoint. */
1835 if (val == 1 && bpt->watchpoint_type == hw_read)
1837 struct bp_location *loc, **loc_temp;
1839 /* But don't try to insert it, if there's already another
1840 hw_access location that would be considered a duplicate
1842 ALL_BP_LOCATIONS (loc, loc_temp)
1844 && loc->watchpoint_type == hw_access
1845 && watchpoint_locations_match (bpt, loc))
1849 bpt->target_info = loc->target_info;
1850 bpt->watchpoint_type = hw_access;
1857 val = target_insert_watchpoint (bpt->address,
1861 bpt->watchpoint_type = hw_access;
1865 bpt->inserted = (val == 0);
1868 else if (bpt->owner->type == bp_catchpoint)
1870 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1871 bpt->owner, RETURN_MASK_ERROR);
1872 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1873 bpt->owner->number);
1875 bpt->owner->enable_state = bp_disabled;
1879 /* We've already printed an error message if there was a problem
1880 inserting this catchpoint, and we've disabled the catchpoint,
1881 so just return success. */
1888 /* This function is called when program space PSPACE is about to be
1889 deleted. It takes care of updating breakpoints to not reference
1893 breakpoint_program_space_exit (struct program_space *pspace)
1895 struct breakpoint *b, *b_temp;
1896 struct bp_location *loc, **loc_temp;
1898 /* Remove any breakpoint that was set through this program space. */
1899 ALL_BREAKPOINTS_SAFE (b, b_temp)
1901 if (b->pspace == pspace)
1902 delete_breakpoint (b);
1905 /* Breakpoints set through other program spaces could have locations
1906 bound to PSPACE as well. Remove those. */
1907 ALL_BP_LOCATIONS (loc, loc_temp)
1909 struct bp_location *tmp;
1911 if (loc->pspace == pspace)
1913 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1914 if (loc->owner->loc == loc)
1915 loc->owner->loc = loc->next;
1917 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
1918 if (tmp->next == loc)
1920 tmp->next = loc->next;
1926 /* Now update the global location list to permanently delete the
1927 removed locations above. */
1928 update_global_location_list (0);
1931 /* Make sure all breakpoints are inserted in inferior.
1932 Throws exception on any error.
1933 A breakpoint that is already inserted won't be inserted
1934 again, so calling this function twice is safe. */
1936 insert_breakpoints (void)
1938 struct breakpoint *bpt;
1940 ALL_BREAKPOINTS (bpt)
1941 if (is_hardware_watchpoint (bpt))
1942 update_watchpoint (bpt, 0 /* don't reparse. */);
1944 update_global_location_list (1);
1946 /* update_global_location_list does not insert breakpoints when
1947 always_inserted_mode is not enabled. Explicitly insert them
1949 if (!breakpoints_always_inserted_mode ())
1950 insert_breakpoint_locations ();
1953 /* insert_breakpoints is used when starting or continuing the program.
1954 remove_breakpoints is used when the program stops.
1955 Both return zero if successful,
1956 or an `errno' value if could not write the inferior. */
1959 insert_breakpoint_locations (void)
1961 struct breakpoint *bpt;
1962 struct bp_location *b, **bp_tmp;
1965 int disabled_breaks = 0;
1966 int hw_breakpoint_error = 0;
1968 struct ui_file *tmp_error_stream = mem_fileopen ();
1969 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
1971 /* Explicitly mark the warning -- this will only be printed if
1972 there was an error. */
1973 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1975 save_current_space_and_thread ();
1977 ALL_BP_LOCATIONS (b, bp_tmp)
1979 if (!should_be_inserted (b) || b->inserted)
1982 /* There is no point inserting thread-specific breakpoints if the
1983 thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER
1985 if (b->owner->thread != -1
1986 && !valid_thread_id (b->owner->thread))
1989 switch_to_program_space_and_thread (b->pspace);
1991 /* For targets that support global breakpoints, there's no need
1992 to select an inferior to insert breakpoint to. In fact, even
1993 if we aren't attached to any process yet, we should still
1994 insert breakpoints. */
1995 if (!gdbarch_has_global_breakpoints (target_gdbarch)
1996 && ptid_equal (inferior_ptid, null_ptid))
1999 val = insert_bp_location (b, tmp_error_stream,
2001 &hw_breakpoint_error);
2006 /* If we failed to insert all locations of a watchpoint,
2007 remove them, as half-inserted watchpoint is of limited use. */
2008 ALL_BREAKPOINTS (bpt)
2010 int some_failed = 0;
2011 struct bp_location *loc;
2013 if (!is_hardware_watchpoint (bpt))
2016 if (!breakpoint_enabled (bpt))
2019 if (bpt->disposition == disp_del_at_next_stop)
2022 for (loc = bpt->loc; loc; loc = loc->next)
2023 if (!loc->inserted && should_be_inserted (loc))
2030 for (loc = bpt->loc; loc; loc = loc->next)
2032 remove_breakpoint (loc, mark_uninserted);
2034 hw_breakpoint_error = 1;
2035 fprintf_unfiltered (tmp_error_stream,
2036 "Could not insert hardware watchpoint %d.\n",
2044 /* If a hardware breakpoint or watchpoint was inserted, add a
2045 message about possibly exhausted resources. */
2046 if (hw_breakpoint_error)
2048 fprintf_unfiltered (tmp_error_stream,
2049 "Could not insert hardware breakpoints:\n\
2050 You may have requested too many hardware breakpoints/watchpoints.\n");
2052 target_terminal_ours_for_output ();
2053 error_stream (tmp_error_stream);
2056 do_cleanups (cleanups);
2060 remove_breakpoints (void)
2062 struct bp_location *b, **bp_tmp;
2065 ALL_BP_LOCATIONS (b, bp_tmp)
2068 val |= remove_breakpoint (b, mark_uninserted);
2073 /* Remove breakpoints of process PID. */
2076 remove_breakpoints_pid (int pid)
2078 struct bp_location *b, **b_tmp;
2080 struct inferior *inf = find_inferior_pid (pid);
2082 ALL_BP_LOCATIONS (b, b_tmp)
2084 if (b->pspace != inf->pspace)
2089 val = remove_breakpoint (b, mark_uninserted);
2098 remove_hw_watchpoints (void)
2100 struct bp_location *b, **bp_tmp;
2103 ALL_BP_LOCATIONS (b, bp_tmp)
2105 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
2106 val |= remove_breakpoint (b, mark_uninserted);
2112 reattach_breakpoints (int pid)
2114 struct cleanup *old_chain;
2115 struct bp_location *b, **bp_tmp;
2117 struct ui_file *tmp_error_stream = mem_fileopen ();
2118 int dummy1 = 0, dummy2 = 0;
2119 struct inferior *inf;
2120 struct thread_info *tp;
2122 tp = any_live_thread_of_process (pid);
2126 inf = find_inferior_pid (pid);
2127 old_chain = save_inferior_ptid ();
2129 inferior_ptid = tp->ptid;
2131 make_cleanup_ui_file_delete (tmp_error_stream);
2133 ALL_BP_LOCATIONS (b, bp_tmp)
2135 if (b->pspace != inf->pspace)
2141 val = insert_bp_location (b, tmp_error_stream,
2145 do_cleanups (old_chain);
2150 do_cleanups (old_chain);
2154 static int internal_breakpoint_number = -1;
2156 static struct breakpoint *
2157 create_internal_breakpoint (struct gdbarch *gdbarch,
2158 CORE_ADDR address, enum bptype type)
2160 struct symtab_and_line sal;
2161 struct breakpoint *b;
2163 init_sal (&sal); /* initialize to zeroes */
2166 sal.section = find_pc_overlay (sal.pc);
2167 sal.pspace = current_program_space;
2169 b = set_raw_breakpoint (gdbarch, sal, type);
2170 b->number = internal_breakpoint_number--;
2171 b->disposition = disp_donttouch;
2177 create_overlay_event_breakpoint (char *func_name)
2179 struct objfile *objfile;
2181 ALL_OBJFILES (objfile)
2183 struct breakpoint *b;
2184 struct minimal_symbol *m;
2186 m = lookup_minimal_symbol_text (func_name, objfile);
2190 b = create_internal_breakpoint (get_objfile_arch (objfile),
2191 SYMBOL_VALUE_ADDRESS (m),
2193 b->addr_string = xstrdup (func_name);
2195 if (overlay_debugging == ovly_auto)
2197 b->enable_state = bp_enabled;
2198 overlay_events_enabled = 1;
2202 b->enable_state = bp_disabled;
2203 overlay_events_enabled = 0;
2206 update_global_location_list (1);
2210 create_longjmp_master_breakpoint (char *func_name)
2212 struct program_space *pspace;
2213 struct objfile *objfile;
2214 struct cleanup *old_chain;
2216 old_chain = save_current_program_space ();
2218 ALL_PSPACES (pspace)
2219 ALL_OBJFILES (objfile)
2221 struct breakpoint *b;
2222 struct minimal_symbol *m;
2224 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile)))
2227 set_current_program_space (pspace);
2229 m = lookup_minimal_symbol_text (func_name, objfile);
2233 b = create_internal_breakpoint (get_objfile_arch (objfile),
2234 SYMBOL_VALUE_ADDRESS (m),
2236 b->addr_string = xstrdup (func_name);
2237 b->enable_state = bp_disabled;
2239 update_global_location_list (1);
2241 do_cleanups (old_chain);
2244 /* Create a master std::terminate breakpoint. The actual function
2245 looked for is named FUNC_NAME. */
2247 create_std_terminate_master_breakpoint (const char *func_name)
2249 struct program_space *pspace;
2250 struct objfile *objfile;
2251 struct cleanup *old_chain;
2253 old_chain = save_current_program_space ();
2255 ALL_PSPACES (pspace)
2256 ALL_OBJFILES (objfile)
2258 struct breakpoint *b;
2259 struct minimal_symbol *m;
2261 set_current_program_space (pspace);
2263 m = lookup_minimal_symbol (func_name, NULL, objfile);
2264 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2265 && MSYMBOL_TYPE (m) != mst_file_text))
2268 b = create_internal_breakpoint (get_objfile_arch (objfile),
2269 SYMBOL_VALUE_ADDRESS (m),
2270 bp_std_terminate_master);
2271 b->addr_string = xstrdup (func_name);
2272 b->enable_state = bp_disabled;
2274 update_global_location_list (1);
2276 do_cleanups (old_chain);
2280 update_breakpoints_after_exec (void)
2282 struct breakpoint *b;
2283 struct breakpoint *temp;
2284 struct bp_location *bploc, **bplocp_tmp;
2286 /* We're about to delete breakpoints from GDB's lists. If the
2287 INSERTED flag is true, GDB will try to lift the breakpoints by
2288 writing the breakpoints' "shadow contents" back into memory. The
2289 "shadow contents" are NOT valid after an exec, so GDB should not
2290 do that. Instead, the target is responsible from marking
2291 breakpoints out as soon as it detects an exec. We don't do that
2292 here instead, because there may be other attempts to delete
2293 breakpoints after detecting an exec and before reaching here. */
2294 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
2295 if (bploc->pspace == current_program_space)
2296 gdb_assert (!bploc->inserted);
2298 ALL_BREAKPOINTS_SAFE (b, temp)
2300 if (b->pspace != current_program_space)
2303 /* Solib breakpoints must be explicitly reset after an exec(). */
2304 if (b->type == bp_shlib_event)
2306 delete_breakpoint (b);
2310 /* JIT breakpoints must be explicitly reset after an exec(). */
2311 if (b->type == bp_jit_event)
2313 delete_breakpoint (b);
2317 /* Thread event breakpoints must be set anew after an exec(),
2318 as must overlay event and longjmp master breakpoints. */
2319 if (b->type == bp_thread_event || b->type == bp_overlay_event
2320 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
2322 delete_breakpoint (b);
2326 /* Step-resume breakpoints are meaningless after an exec(). */
2327 if (b->type == bp_step_resume)
2329 delete_breakpoint (b);
2333 /* Longjmp and longjmp-resume breakpoints are also meaningless
2335 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
2337 delete_breakpoint (b);
2341 if (b->type == bp_catchpoint)
2343 /* For now, none of the bp_catchpoint breakpoints need to
2344 do anything at this point. In the future, if some of
2345 the catchpoints need to something, we will need to add
2346 a new method, and call this method from here. */
2350 /* bp_finish is a special case. The only way we ought to be able
2351 to see one of these when an exec() has happened, is if the user
2352 caught a vfork, and then said "finish". Ordinarily a finish just
2353 carries them to the call-site of the current callee, by setting
2354 a temporary bp there and resuming. But in this case, the finish
2355 will carry them entirely through the vfork & exec.
2357 We don't want to allow a bp_finish to remain inserted now. But
2358 we can't safely delete it, 'cause finish_command has a handle to
2359 the bp on a bpstat, and will later want to delete it. There's a
2360 chance (and I've seen it happen) that if we delete the bp_finish
2361 here, that its storage will get reused by the time finish_command
2362 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2363 We really must allow finish_command to delete a bp_finish.
2365 In the absense of a general solution for the "how do we know
2366 it's safe to delete something others may have handles to?"
2367 problem, what we'll do here is just uninsert the bp_finish, and
2368 let finish_command delete it.
2370 (We know the bp_finish is "doomed" in the sense that it's
2371 momentary, and will be deleted as soon as finish_command sees
2372 the inferior stopped. So it doesn't matter that the bp's
2373 address is probably bogus in the new a.out, unlike e.g., the
2374 solib breakpoints.) */
2376 if (b->type == bp_finish)
2381 /* Without a symbolic address, we have little hope of the
2382 pre-exec() address meaning the same thing in the post-exec()
2384 if (b->addr_string == NULL)
2386 delete_breakpoint (b);
2390 /* FIXME what about longjmp breakpoints? Re-create them here? */
2391 create_overlay_event_breakpoint ("_ovly_debug_event");
2392 create_longjmp_master_breakpoint ("longjmp");
2393 create_longjmp_master_breakpoint ("_longjmp");
2394 create_longjmp_master_breakpoint ("siglongjmp");
2395 create_longjmp_master_breakpoint ("_siglongjmp");
2396 create_std_terminate_master_breakpoint ("std::terminate()");
2400 detach_breakpoints (int pid)
2402 struct bp_location *b, **bp_tmp;
2404 struct cleanup *old_chain = save_inferior_ptid ();
2405 struct inferior *inf = current_inferior ();
2407 if (pid == PIDGET (inferior_ptid))
2408 error (_("Cannot detach breakpoints of inferior_ptid"));
2410 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2411 inferior_ptid = pid_to_ptid (pid);
2412 ALL_BP_LOCATIONS (b, bp_tmp)
2414 if (b->pspace != inf->pspace)
2418 val |= remove_breakpoint_1 (b, mark_inserted);
2421 /* Detach single-step breakpoints as well. */
2422 detach_single_step_breakpoints ();
2424 do_cleanups (old_chain);
2428 /* Remove the breakpoint location B from the current address space.
2429 Note that this is used to detach breakpoints from a child fork.
2430 When we get here, the child isn't in the inferior list, and neither
2431 do we have objects to represent its address space --- we should
2432 *not* look at b->pspace->aspace here. */
2435 remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
2439 /* B is never in moribund_locations by our callers. */
2440 gdb_assert (b->owner != NULL);
2442 if (b->owner->enable_state == bp_permanent)
2443 /* Permanent breakpoints cannot be inserted or removed. */
2446 /* The type of none suggests that owner is actually deleted.
2447 This should not ever happen. */
2448 gdb_assert (b->owner->type != bp_none);
2450 if (b->loc_type == bp_loc_software_breakpoint
2451 || b->loc_type == bp_loc_hardware_breakpoint)
2453 /* "Normal" instruction breakpoint: either the standard
2454 trap-instruction bp (bp_breakpoint), or a
2455 bp_hardware_breakpoint. */
2457 /* First check to see if we have to handle an overlay. */
2458 if (overlay_debugging == ovly_off
2459 || b->section == NULL
2460 || !(section_is_overlay (b->section)))
2462 /* No overlay handling: just remove the breakpoint. */
2464 if (b->loc_type == bp_loc_hardware_breakpoint)
2465 val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info);
2467 val = target_remove_breakpoint (b->gdbarch, &b->target_info);
2471 /* This breakpoint is in an overlay section.
2472 Did we set a breakpoint at the LMA? */
2473 if (!overlay_events_enabled)
2475 /* Yes -- overlay event support is not active, so we
2476 should have set a breakpoint at the LMA. Remove it.
2478 /* Ignore any failures: if the LMA is in ROM, we will
2479 have already warned when we failed to insert it. */
2480 if (b->loc_type == bp_loc_hardware_breakpoint)
2481 target_remove_hw_breakpoint (b->gdbarch,
2482 &b->overlay_target_info);
2484 target_remove_breakpoint (b->gdbarch,
2485 &b->overlay_target_info);
2487 /* Did we set a breakpoint at the VMA?
2488 If so, we will have marked the breakpoint 'inserted'. */
2491 /* Yes -- remove it. Previously we did not bother to
2492 remove the breakpoint if the section had been
2493 unmapped, but let's not rely on that being safe. We
2494 don't know what the overlay manager might do. */
2495 if (b->loc_type == bp_loc_hardware_breakpoint)
2496 val = target_remove_hw_breakpoint (b->gdbarch,
2499 /* However, we should remove *software* breakpoints only
2500 if the section is still mapped, or else we overwrite
2501 wrong code with the saved shadow contents. */
2502 else if (section_is_mapped (b->section))
2503 val = target_remove_breakpoint (b->gdbarch,
2510 /* No -- not inserted, so no need to remove. No error. */
2515 /* In some cases, we might not be able to remove a breakpoint
2516 in a shared library that has already been removed, but we
2517 have not yet processed the shlib unload event. */
2518 if (val && solib_name_from_address (b->pspace, b->address))
2523 b->inserted = (is == mark_inserted);
2525 else if (b->loc_type == bp_loc_hardware_watchpoint)
2527 b->inserted = (is == mark_inserted);
2528 val = target_remove_watchpoint (b->address, b->length,
2529 b->watchpoint_type);
2531 /* Failure to remove any of the hardware watchpoints comes here. */
2532 if ((is == mark_uninserted) && (b->inserted))
2533 warning (_("Could not remove hardware watchpoint %d."),
2536 else if (b->owner->type == bp_catchpoint
2537 && breakpoint_enabled (b->owner)
2540 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
2542 val = b->owner->ops->remove (b->owner);
2545 b->inserted = (is == mark_inserted);
2552 remove_breakpoint (struct bp_location *b, insertion_state_t is)
2555 struct cleanup *old_chain;
2557 /* B is never in moribund_locations by our callers. */
2558 gdb_assert (b->owner != NULL);
2560 if (b->owner->enable_state == bp_permanent)
2561 /* Permanent breakpoints cannot be inserted or removed. */
2564 /* The type of none suggests that owner is actually deleted.
2565 This should not ever happen. */
2566 gdb_assert (b->owner->type != bp_none);
2568 old_chain = save_current_space_and_thread ();
2570 switch_to_program_space_and_thread (b->pspace);
2572 ret = remove_breakpoint_1 (b, is);
2574 do_cleanups (old_chain);
2578 /* Clear the "inserted" flag in all breakpoints. */
2581 mark_breakpoints_out (void)
2583 struct bp_location *bpt, **bptp_tmp;
2585 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2586 if (bpt->pspace == current_program_space)
2590 /* Clear the "inserted" flag in all breakpoints and delete any
2591 breakpoints which should go away between runs of the program.
2593 Plus other such housekeeping that has to be done for breakpoints
2596 Note: this function gets called at the end of a run (by
2597 generic_mourn_inferior) and when a run begins (by
2598 init_wait_for_inferior). */
2603 breakpoint_init_inferior (enum inf_context context)
2605 struct breakpoint *b, *temp;
2606 struct bp_location *bpt, **bptp_tmp;
2608 struct program_space *pspace = current_program_space;
2610 /* If breakpoint locations are shared across processes, then there's
2612 if (gdbarch_has_global_breakpoints (target_gdbarch))
2615 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2617 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2618 if (bpt->pspace == pspace
2619 && bpt->owner->enable_state != bp_permanent)
2623 ALL_BREAKPOINTS_SAFE (b, temp)
2625 if (b->loc && b->loc->pspace != pspace)
2632 /* If the call dummy breakpoint is at the entry point it will
2633 cause problems when the inferior is rerun, so we better get
2636 case bp_watchpoint_scope:
2638 /* Also get rid of scope breakpoints. */
2640 case bp_shlib_event:
2642 /* Also remove solib event breakpoints. Their addresses may
2643 have changed since the last time we ran the program.
2644 Actually we may now be debugging against different target;
2645 and so the solib backend that installed this breakpoint may
2646 not be used in by the target. E.g.,
2648 (gdb) file prog-linux
2649 (gdb) run # native linux target
2652 (gdb) file prog-win.exe
2653 (gdb) tar rem :9999 # remote Windows gdbserver.
2656 delete_breakpoint (b);
2660 case bp_hardware_watchpoint:
2661 case bp_read_watchpoint:
2662 case bp_access_watchpoint:
2664 /* Likewise for watchpoints on local expressions. */
2665 if (b->exp_valid_block != NULL)
2666 delete_breakpoint (b);
2667 else if (context == inf_starting)
2669 /* Reset val field to force reread of starting value
2670 in insert_breakpoints. */
2672 value_free (b->val);
2682 /* Get rid of the moribund locations. */
2683 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
2684 free_bp_location (bpt);
2685 VEC_free (bp_location_p, moribund_locations);
2688 /* These functions concern about actual breakpoints inserted in the
2689 target --- to e.g. check if we need to do decr_pc adjustment or if
2690 we need to hop over the bkpt --- so we check for address space
2691 match, not program space. */
2693 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2694 exists at PC. It returns ordinary_breakpoint_here if it's an
2695 ordinary breakpoint, or permanent_breakpoint_here if it's a
2696 permanent breakpoint.
2697 - When continuing from a location with an ordinary breakpoint, we
2698 actually single step once before calling insert_breakpoints.
2699 - When continuing from a localion with a permanent breakpoint, we
2700 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2701 the target, to advance the PC past the breakpoint. */
2703 enum breakpoint_here
2704 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2706 struct bp_location *bpt, **bptp_tmp;
2707 int any_breakpoint_here = 0;
2709 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2711 if (bpt->loc_type != bp_loc_software_breakpoint
2712 && bpt->loc_type != bp_loc_hardware_breakpoint)
2715 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2716 if ((breakpoint_enabled (bpt->owner)
2717 || bpt->owner->enable_state == bp_permanent)
2718 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2721 if (overlay_debugging
2722 && section_is_overlay (bpt->section)
2723 && !section_is_mapped (bpt->section))
2724 continue; /* unmapped overlay -- can't be a match */
2725 else if (bpt->owner->enable_state == bp_permanent)
2726 return permanent_breakpoint_here;
2728 any_breakpoint_here = 1;
2732 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
2735 /* Return true if there's a moribund breakpoint at PC. */
2738 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
2740 struct bp_location *loc;
2743 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
2744 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
2751 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2752 inserted using regular breakpoint_chain / bp_location array mechanism.
2753 This does not check for single-step breakpoints, which are
2754 inserted and removed using direct target manipulation. */
2757 regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2759 struct bp_location *bpt, **bptp_tmp;
2761 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2763 if (bpt->loc_type != bp_loc_software_breakpoint
2764 && bpt->loc_type != bp_loc_hardware_breakpoint)
2768 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2771 if (overlay_debugging
2772 && section_is_overlay (bpt->section)
2773 && !section_is_mapped (bpt->section))
2774 continue; /* unmapped overlay -- can't be a match */
2782 /* Returns non-zero iff there's either regular breakpoint
2783 or a single step breakpoint inserted at PC. */
2786 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2788 if (regular_breakpoint_inserted_here_p (aspace, pc))
2791 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2797 /* This function returns non-zero iff there is a software breakpoint
2801 software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
2803 struct bp_location *bpt, **bptp_tmp;
2805 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2807 if (bpt->loc_type != bp_loc_software_breakpoint)
2811 && breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2814 if (overlay_debugging
2815 && section_is_overlay (bpt->section)
2816 && !section_is_mapped (bpt->section))
2817 continue; /* unmapped overlay -- can't be a match */
2823 /* Also check for software single-step breakpoints. */
2824 if (single_step_breakpoint_inserted_here_p (aspace, pc))
2831 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
2832 CORE_ADDR addr, ULONGEST len)
2834 struct breakpoint *bpt;
2836 ALL_BREAKPOINTS (bpt)
2838 struct bp_location *loc;
2840 if (bpt->type != bp_hardware_watchpoint
2841 && bpt->type != bp_access_watchpoint)
2844 if (!breakpoint_enabled (bpt))
2847 for (loc = bpt->loc; loc; loc = loc->next)
2848 if (loc->pspace->aspace == aspace && loc->inserted)
2852 /* Check for intersection. */
2853 l = max (loc->address, addr);
2854 h = min (loc->address + loc->length, addr + len);
2862 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2863 PC is valid for process/thread PTID. */
2866 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
2869 struct bp_location *bpt, **bptp_tmp;
2870 /* The thread and task IDs associated to PTID, computed lazily. */
2874 ALL_BP_LOCATIONS (bpt, bptp_tmp)
2876 if (bpt->loc_type != bp_loc_software_breakpoint
2877 && bpt->loc_type != bp_loc_hardware_breakpoint)
2880 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2881 if (!breakpoint_enabled (bpt->owner)
2882 && bpt->owner->enable_state != bp_permanent)
2885 if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address,
2889 if (bpt->owner->thread != -1)
2891 /* This is a thread-specific breakpoint. Check that ptid
2892 matches that thread. If thread hasn't been computed yet,
2893 it is now time to do so. */
2895 thread = pid_to_thread_id (ptid);
2896 if (bpt->owner->thread != thread)
2900 if (bpt->owner->task != 0)
2902 /* This is a task-specific breakpoint. Check that ptid
2903 matches that task. If task hasn't been computed yet,
2904 it is now time to do so. */
2906 task = ada_get_task_number (ptid);
2907 if (bpt->owner->task != task)
2911 if (overlay_debugging
2912 && section_is_overlay (bpt->section)
2913 && !section_is_mapped (bpt->section))
2914 continue; /* unmapped overlay -- can't be a match */
2923 /* bpstat stuff. External routines' interfaces are documented
2927 ep_is_catchpoint (struct breakpoint *ep)
2929 return (ep->type == bp_catchpoint);
2933 bpstat_free (bpstat bs)
2935 if (bs->old_val != NULL)
2936 value_free (bs->old_val);
2937 decref_counted_command_line (&bs->commands);
2941 /* Clear a bpstat so that it says we are not at any breakpoint.
2942 Also free any storage that is part of a bpstat. */
2945 bpstat_clear (bpstat *bsp)
2962 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2963 is part of the bpstat is copied as well. */
2966 bpstat_copy (bpstat bs)
2970 bpstat retval = NULL;
2975 for (; bs != NULL; bs = bs->next)
2977 tmp = (bpstat) xmalloc (sizeof (*tmp));
2978 memcpy (tmp, bs, sizeof (*tmp));
2979 incref_counted_command_line (tmp->commands);
2980 if (bs->old_val != NULL)
2982 tmp->old_val = value_copy (bs->old_val);
2983 release_value (tmp->old_val);
2987 /* This is the first thing in the chain. */
2997 /* Find the bpstat associated with this breakpoint */
3000 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3005 for (; bsp != NULL; bsp = bsp->next)
3007 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
3013 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
3014 at. *BSP upon return is a bpstat which points to the remaining
3015 breakpoints stopped at (but which is not guaranteed to be good for
3016 anything but further calls to bpstat_num).
3017 Return 0 if passed a bpstat which does not indicate any breakpoints.
3018 Return -1 if stopped at a breakpoint that has been deleted since
3020 Return 1 otherwise. */
3023 bpstat_num (bpstat *bsp, int *num)
3025 struct breakpoint *b;
3028 return 0; /* No more breakpoint values */
3030 /* We assume we'll never have several bpstats that
3031 correspond to a single breakpoint -- otherwise,
3032 this function might return the same number more
3033 than once and this will look ugly. */
3034 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
3035 *bsp = (*bsp)->next;
3037 return -1; /* breakpoint that's been deleted since */
3039 *num = b->number; /* We have its number */
3043 /* Modify BS so that the actions will not be performed. */
3046 bpstat_clear_actions (bpstat bs)
3048 for (; bs != NULL; bs = bs->next)
3050 decref_counted_command_line (&bs->commands);
3051 bs->commands_left = NULL;
3052 if (bs->old_val != NULL)
3054 value_free (bs->old_val);
3060 /* Called when a command is about to proceed the inferior. */
3063 breakpoint_about_to_proceed (void)
3065 if (!ptid_equal (inferior_ptid, null_ptid))
3067 struct thread_info *tp = inferior_thread ();
3069 /* Allow inferior function calls in breakpoint commands to not
3070 interrupt the command list. When the call finishes
3071 successfully, the inferior will be standing at the same
3072 breakpoint as if nothing happened. */
3077 breakpoint_proceeded = 1;
3080 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3082 cleanup_executing_breakpoints (void *ignore)
3084 executing_breakpoint_commands = 0;
3087 /* Execute all the commands associated with all the breakpoints at this
3088 location. Any of these commands could cause the process to proceed
3089 beyond this point, etc. We look out for such changes by checking
3090 the global "breakpoint_proceeded" after each command.
3092 Returns true if a breakpoint command resumed the inferior. In that
3093 case, it is the caller's responsibility to recall it again with the
3094 bpstat of the current thread. */
3097 bpstat_do_actions_1 (bpstat *bsp)
3100 struct cleanup *old_chain;
3103 /* Avoid endless recursion if a `source' command is contained
3105 if (executing_breakpoint_commands)
3108 executing_breakpoint_commands = 1;
3109 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3111 /* This pointer will iterate over the list of bpstat's. */
3114 breakpoint_proceeded = 0;
3115 for (; bs != NULL; bs = bs->next)
3117 struct counted_command_line *ccmd;
3118 struct command_line *cmd;
3119 struct cleanup *this_cmd_tree_chain;
3121 /* Take ownership of the BSP's command tree, if it has one.
3123 The command tree could legitimately contain commands like
3124 'step' and 'next', which call clear_proceed_status, which
3125 frees stop_bpstat's command tree. To make sure this doesn't
3126 free the tree we're executing out from under us, we need to
3127 take ownership of the tree ourselves. Since a given bpstat's
3128 commands are only executed once, we don't need to copy it; we
3129 can clear the pointer in the bpstat, and make sure we free
3130 the tree when we're done. */
3131 ccmd = bs->commands;
3132 bs->commands = NULL;
3134 = make_cleanup_decref_counted_command_line (&ccmd);
3135 cmd = bs->commands_left;
3136 bs->commands_left = NULL;
3140 execute_control_command (cmd);
3142 if (breakpoint_proceeded)
3148 /* We can free this command tree now. */
3149 do_cleanups (this_cmd_tree_chain);
3151 if (breakpoint_proceeded)
3153 if (target_can_async_p ())
3154 /* If we are in async mode, then the target might be still
3155 running, not stopped at any breakpoint, so nothing for
3156 us to do here -- just return to the event loop. */
3159 /* In sync mode, when execute_control_command returns
3160 we're already standing on the next breakpoint.
3161 Breakpoint commands for that stop were not run, since
3162 execute_command does not run breakpoint commands --
3163 only command_line_handler does, but that one is not
3164 involved in execution of breakpoint commands. So, we
3165 can now execute breakpoint commands. It should be
3166 noted that making execute_command do bpstat actions is
3167 not an option -- in this case we'll have recursive
3168 invocation of bpstat for each breakpoint with a
3169 command, and can easily blow up GDB stack. Instead, we
3170 return true, which will trigger the caller to recall us
3171 with the new stop_bpstat. */
3176 do_cleanups (old_chain);
3181 bpstat_do_actions (void)
3183 /* Do any commands attached to breakpoint we are stopped at. */
3184 while (!ptid_equal (inferior_ptid, null_ptid)
3185 && target_has_execution
3186 && !is_exited (inferior_ptid)
3187 && !is_executing (inferior_ptid))
3188 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3189 and only return when it is stopped at the next breakpoint, we
3190 keep doing breakpoint actions until it returns false to
3191 indicate the inferior was not resumed. */
3192 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
3196 /* Print out the (old or new) value associated with a watchpoint. */
3199 watchpoint_value_print (struct value *val, struct ui_file *stream)
3202 fprintf_unfiltered (stream, _("<unreadable>"));
3205 struct value_print_options opts;
3206 get_user_print_options (&opts);
3207 value_print (val, stream, &opts);
3211 /* This is the normal print function for a bpstat. In the future,
3212 much of this logic could (should?) be moved to bpstat_stop_status,
3213 by having it set different print_it values.
3215 Current scheme: When we stop, bpstat_print() is called. It loops
3216 through the bpstat list of things causing this stop, calling the
3217 print_bp_stop_message function on each one. The behavior of the
3218 print_bp_stop_message function depends on the print_it field of
3219 bpstat. If such field so indicates, call this function here.
3221 Return values from this routine (ultimately used by bpstat_print()
3222 and normal_stop() to decide what to do):
3223 PRINT_NOTHING: Means we already printed all we needed to print,
3224 don't print anything else.
3225 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3226 that something to be followed by a location.
3227 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3228 that something to be followed by a location.
3229 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3232 static enum print_stop_action
3233 print_it_typical (bpstat bs)
3235 struct cleanup *old_chain;
3236 struct breakpoint *b;
3237 const struct bp_location *bl;
3238 struct ui_stream *stb;
3240 enum print_stop_action result;
3242 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3243 which has since been deleted. */
3244 if (bs->breakpoint_at == NULL)
3245 return PRINT_UNKNOWN;
3246 bl = bs->breakpoint_at;
3248 /* bl->owner can be NULL if it was a momentary breakpoint
3249 which has since been placed into moribund_locations. */
3250 if (bl->owner == NULL)
3251 return PRINT_UNKNOWN;
3254 stb = ui_out_stream_new (uiout);
3255 old_chain = make_cleanup_ui_out_stream_delete (stb);
3260 case bp_hardware_breakpoint:
3261 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
3262 if (bl->address != bl->requested_address)
3263 breakpoint_adjustment_warning (bl->requested_address,
3266 annotate_breakpoint (b->number);
3268 ui_out_text (uiout, "\nTemporary breakpoint ");
3270 ui_out_text (uiout, "\nBreakpoint ");
3271 if (ui_out_is_mi_like_p (uiout))
3273 ui_out_field_string (uiout, "reason",
3274 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
3275 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3277 ui_out_field_int (uiout, "bkptno", b->number);
3278 ui_out_text (uiout, ", ");
3279 result = PRINT_SRC_AND_LOC;
3282 case bp_shlib_event:
3283 /* Did we stop because the user set the stop_on_solib_events
3284 variable? (If so, we report this as a generic, "Stopped due
3285 to shlib event" message.) */
3286 printf_filtered (_("Stopped due to shared library event\n"));
3287 result = PRINT_NOTHING;
3290 case bp_thread_event:
3291 /* Not sure how we will get here.
3292 GDB should not stop for these breakpoints. */
3293 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3294 result = PRINT_NOTHING;
3297 case bp_overlay_event:
3298 /* By analogy with the thread event, GDB should not stop for these. */
3299 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3300 result = PRINT_NOTHING;
3303 case bp_longjmp_master:
3304 /* These should never be enabled. */
3305 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3306 result = PRINT_NOTHING;
3309 case bp_std_terminate_master:
3310 /* These should never be enabled. */
3311 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3312 result = PRINT_NOTHING;
3316 case bp_hardware_watchpoint:
3317 annotate_watchpoint (b->number);
3318 if (ui_out_is_mi_like_p (uiout))
3321 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
3323 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3324 ui_out_text (uiout, "\nOld value = ");
3325 watchpoint_value_print (bs->old_val, stb->stream);
3326 ui_out_field_stream (uiout, "old", stb);
3327 ui_out_text (uiout, "\nNew value = ");
3328 watchpoint_value_print (b->val, stb->stream);
3329 ui_out_field_stream (uiout, "new", stb);
3330 ui_out_text (uiout, "\n");
3331 /* More than one watchpoint may have been triggered. */
3332 result = PRINT_UNKNOWN;
3335 case bp_read_watchpoint:
3336 if (ui_out_is_mi_like_p (uiout))
3339 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
3341 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3342 ui_out_text (uiout, "\nValue = ");
3343 watchpoint_value_print (b->val, stb->stream);
3344 ui_out_field_stream (uiout, "value", stb);
3345 ui_out_text (uiout, "\n");
3346 result = PRINT_UNKNOWN;
3349 case bp_access_watchpoint:
3350 if (bs->old_val != NULL)
3352 annotate_watchpoint (b->number);
3353 if (ui_out_is_mi_like_p (uiout))
3356 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3358 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3359 ui_out_text (uiout, "\nOld value = ");
3360 watchpoint_value_print (bs->old_val, stb->stream);
3361 ui_out_field_stream (uiout, "old", stb);
3362 ui_out_text (uiout, "\nNew value = ");
3367 if (ui_out_is_mi_like_p (uiout))
3370 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
3371 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
3372 ui_out_text (uiout, "\nValue = ");
3374 watchpoint_value_print (b->val, stb->stream);
3375 ui_out_field_stream (uiout, "new", stb);
3376 ui_out_text (uiout, "\n");
3377 result = PRINT_UNKNOWN;
3380 /* Fall through, we don't deal with these types of breakpoints
3384 if (ui_out_is_mi_like_p (uiout))
3387 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
3388 result = PRINT_UNKNOWN;
3392 if (ui_out_is_mi_like_p (uiout))
3395 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
3396 result = PRINT_UNKNOWN;
3401 case bp_longjmp_resume:
3402 case bp_step_resume:
3403 case bp_watchpoint_scope:
3405 case bp_std_terminate:
3407 case bp_fast_tracepoint:
3410 result = PRINT_UNKNOWN;
3414 do_cleanups (old_chain);
3418 /* Generic routine for printing messages indicating why we
3419 stopped. The behavior of this function depends on the value
3420 'print_it' in the bpstat structure. Under some circumstances we
3421 may decide not to print anything here and delegate the task to
3424 static enum print_stop_action
3425 print_bp_stop_message (bpstat bs)
3427 switch (bs->print_it)
3430 /* Nothing should be printed for this bpstat entry. */
3431 return PRINT_UNKNOWN;
3435 /* We still want to print the frame, but we already printed the
3436 relevant messages. */
3437 return PRINT_SRC_AND_LOC;
3440 case print_it_normal:
3442 const struct bp_location *bl = bs->breakpoint_at;
3443 struct breakpoint *b = bl ? bl->owner : NULL;
3445 /* Normal case. Call the breakpoint's print_it method, or
3446 print_it_typical. */
3447 /* FIXME: how breakpoint can ever be NULL here? */
3448 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
3449 return b->ops->print_it (b);
3451 return print_it_typical (bs);
3456 internal_error (__FILE__, __LINE__,
3457 _("print_bp_stop_message: unrecognized enum value"));
3462 /* Print a message indicating what happened. This is called from
3463 normal_stop(). The input to this routine is the head of the bpstat
3464 list - a list of the eventpoints that caused this stop. This
3465 routine calls the generic print routine for printing a message
3466 about reasons for stopping. This will print (for example) the
3467 "Breakpoint n," part of the output. The return value of this
3470 PRINT_UNKNOWN: Means we printed nothing
3471 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3472 code to print the location. An example is
3473 "Breakpoint 1, " which should be followed by
3475 PRINT_SRC_ONLY: Means we printed something, but there is no need
3476 to also print the location part of the message.
3477 An example is the catch/throw messages, which
3478 don't require a location appended to the end.
3479 PRINT_NOTHING: We have done some printing and we don't need any
3480 further info to be printed.*/
3482 enum print_stop_action
3483 bpstat_print (bpstat bs)
3487 /* Maybe another breakpoint in the chain caused us to stop.
3488 (Currently all watchpoints go on the bpstat whether hit or not.
3489 That probably could (should) be changed, provided care is taken
3490 with respect to bpstat_explains_signal). */
3491 for (; bs; bs = bs->next)
3493 val = print_bp_stop_message (bs);
3494 if (val == PRINT_SRC_ONLY
3495 || val == PRINT_SRC_AND_LOC
3496 || val == PRINT_NOTHING)
3500 /* We reached the end of the chain, or we got a null BS to start
3501 with and nothing was printed. */
3502 return PRINT_UNKNOWN;
3505 /* Evaluate the expression EXP and return 1 if value is zero.
3506 This is used inside a catch_errors to evaluate the breakpoint condition.
3507 The argument is a "struct expression *" that has been cast to char * to
3508 make it pass through catch_errors. */
3511 breakpoint_cond_eval (void *exp)
3513 struct value *mark = value_mark ();
3514 int i = !value_true (evaluate_expression ((struct expression *) exp));
3516 value_free_to_mark (mark);
3520 /* Allocate a new bpstat and chain it to the current one. */
3523 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
3527 bs = (bpstat) xmalloc (sizeof (*bs));
3529 bs->breakpoint_at = bl;
3530 /* If the condition is false, etc., don't do the commands. */
3531 bs->commands = NULL;
3532 bs->commands_left = NULL;
3534 bs->print_it = print_it_normal;
3538 /* The target has stopped with waitstatus WS. Check if any hardware
3539 watchpoints have triggered, according to the target. */
3542 watchpoints_triggered (struct target_waitstatus *ws)
3544 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
3546 struct breakpoint *b;
3548 if (!stopped_by_watchpoint)
3550 /* We were not stopped by a watchpoint. Mark all watchpoints
3551 as not triggered. */
3553 if (is_hardware_watchpoint (b))
3554 b->watchpoint_triggered = watch_triggered_no;
3559 if (!target_stopped_data_address (¤t_target, &addr))
3561 /* We were stopped by a watchpoint, but we don't know where.
3562 Mark all watchpoints as unknown. */
3564 if (is_hardware_watchpoint (b))
3565 b->watchpoint_triggered = watch_triggered_unknown;
3567 return stopped_by_watchpoint;
3570 /* The target could report the data address. Mark watchpoints
3571 affected by this data address as triggered, and all others as not
3575 if (is_hardware_watchpoint (b))
3577 struct bp_location *loc;
3579 b->watchpoint_triggered = watch_triggered_no;
3580 for (loc = b->loc; loc; loc = loc->next)
3581 /* Exact match not required. Within range is
3583 if (target_watchpoint_addr_within_range (¤t_target,
3587 b->watchpoint_triggered = watch_triggered_yes;
3595 /* Possible return values for watchpoint_check (this can't be an enum
3596 because of check_errors). */
3597 /* The watchpoint has been deleted. */
3598 #define WP_DELETED 1
3599 /* The value has changed. */
3600 #define WP_VALUE_CHANGED 2
3601 /* The value has not changed. */
3602 #define WP_VALUE_NOT_CHANGED 3
3603 /* Ignore this watchpoint, no matter if the value changed or not. */
3606 #define BP_TEMPFLAG 1
3607 #define BP_HARDWAREFLAG 2
3609 /* Evaluate watchpoint condition expression and check if its value changed.
3611 P should be a pointer to struct bpstat, but is defined as a void *
3612 in order for this function to be usable with catch_errors. */
3615 watchpoint_check (void *p)
3617 bpstat bs = (bpstat) p;
3618 struct breakpoint *b;
3619 struct frame_info *fr;
3620 int within_current_scope;
3622 /* BS is built for existing struct breakpoint. */
3623 gdb_assert (bs->breakpoint_at != NULL);
3624 gdb_assert (bs->breakpoint_at->owner != NULL);
3625 b = bs->breakpoint_at->owner;
3627 /* If this is a local watchpoint, we only want to check if the
3628 watchpoint frame is in scope if the current thread is the thread
3629 that was used to create the watchpoint. */
3630 if (!watchpoint_in_thread_scope (b))
3633 if (b->exp_valid_block == NULL)
3634 within_current_scope = 1;
3637 struct frame_info *frame = get_current_frame ();
3638 struct gdbarch *frame_arch = get_frame_arch (frame);
3639 CORE_ADDR frame_pc = get_frame_pc (frame);
3641 /* in_function_epilogue_p() returns a non-zero value if we're still
3642 in the function but the stack frame has already been invalidated.
3643 Since we can't rely on the values of local variables after the
3644 stack has been destroyed, we are treating the watchpoint in that
3645 state as `not changed' without further checking. Don't mark
3646 watchpoints as changed if the current frame is in an epilogue -
3647 even if they are in some other frame, our view of the stack
3648 is likely to be wrong and frame_find_by_id could error out. */
3649 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
3652 fr = frame_find_by_id (b->watchpoint_frame);
3653 within_current_scope = (fr != NULL);
3655 /* If we've gotten confused in the unwinder, we might have
3656 returned a frame that can't describe this variable. */
3657 if (within_current_scope)
3659 struct symbol *function;
3661 function = get_frame_function (fr);
3662 if (function == NULL
3663 || !contained_in (b->exp_valid_block,
3664 SYMBOL_BLOCK_VALUE (function)))
3665 within_current_scope = 0;
3668 if (within_current_scope)
3669 /* If we end up stopping, the current frame will get selected
3670 in normal_stop. So this call to select_frame won't affect
3675 if (within_current_scope)
3677 /* We use value_{,free_to_}mark because it could be a
3678 *long* time before we return to the command level and
3679 call free_all_values. We can't call free_all_values because
3680 we might be in the middle of evaluating a function call. */
3682 struct value *mark = value_mark ();
3683 struct value *new_val;
3685 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
3687 /* We use value_equal_contents instead of value_equal because the latter
3688 coerces an array to a pointer, thus comparing just the address of the
3689 array instead of its contents. This is not what we want. */
3690 if ((b->val != NULL) != (new_val != NULL)
3691 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
3693 if (new_val != NULL)
3695 release_value (new_val);
3696 value_free_to_mark (mark);
3698 bs->old_val = b->val;
3701 return WP_VALUE_CHANGED;
3705 /* Nothing changed. */
3706 value_free_to_mark (mark);
3707 return WP_VALUE_NOT_CHANGED;
3712 /* This seems like the only logical thing to do because
3713 if we temporarily ignored the watchpoint, then when
3714 we reenter the block in which it is valid it contains
3715 garbage (in the case of a function, it may have two
3716 garbage values, one before and one after the prologue).
3717 So we can't even detect the first assignment to it and
3718 watch after that (since the garbage may or may not equal
3719 the first value assigned). */
3720 /* We print all the stop information in print_it_typical(), but
3721 in this case, by the time we call print_it_typical() this bp
3722 will be deleted already. So we have no choice but print the
3723 information here. */
3724 if (ui_out_is_mi_like_p (uiout))
3726 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
3727 ui_out_text (uiout, "\nWatchpoint ");
3728 ui_out_field_int (uiout, "wpnum", b->number);
3729 ui_out_text (uiout, " deleted because the program has left the block in\n\
3730 which its expression is valid.\n");
3732 if (b->related_breakpoint)
3734 b->related_breakpoint->disposition = disp_del_at_next_stop;
3735 b->related_breakpoint->related_breakpoint = NULL;
3736 b->related_breakpoint = NULL;
3738 b->disposition = disp_del_at_next_stop;
3744 /* Return true if it looks like target has stopped due to hitting
3745 breakpoint location BL. This function does not check if we
3746 should stop, only if BL explains the stop. */
3748 bpstat_check_location (const struct bp_location *bl,
3749 struct address_space *aspace, CORE_ADDR bp_addr)
3751 struct breakpoint *b = bl->owner;
3753 /* BL is from existing struct breakpoint. */
3754 gdb_assert (b != NULL);
3756 /* By definition, the inferior does not report stops at
3758 if (is_tracepoint (b))
3761 if (!is_watchpoint (b)
3762 && b->type != bp_hardware_breakpoint
3763 && b->type != bp_catchpoint) /* a non-watchpoint bp */
3765 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
3768 if (overlay_debugging /* unmapped overlay section */
3769 && section_is_overlay (bl->section)
3770 && !section_is_mapped (bl->section))
3774 /* Continuable hardware watchpoints are treated as non-existent if the
3775 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3776 some data address). Otherwise gdb won't stop on a break instruction
3777 in the code (not from a breakpoint) when a hardware watchpoint has
3778 been defined. Also skip watchpoints which we know did not trigger
3779 (did not match the data address). */
3781 if (is_hardware_watchpoint (b)
3782 && b->watchpoint_triggered == watch_triggered_no)
3785 if (b->type == bp_hardware_breakpoint)
3787 if (bl->address != bp_addr)
3789 if (overlay_debugging /* unmapped overlay section */
3790 && section_is_overlay (bl->section)
3791 && !section_is_mapped (bl->section))
3795 if (b->type == bp_catchpoint)
3797 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
3798 if (!b->ops->breakpoint_hit (b))
3805 /* If BS refers to a watchpoint, determine if the watched values
3806 has actually changed, and we should stop. If not, set BS->stop
3809 bpstat_check_watchpoint (bpstat bs)
3811 const struct bp_location *bl;
3812 struct breakpoint *b;
3814 /* BS is built for existing struct breakpoint. */
3815 bl = bs->breakpoint_at;
3816 gdb_assert (bl != NULL);
3818 gdb_assert (b != NULL);
3820 if (is_watchpoint (b))
3822 int must_check_value = 0;
3824 if (b->type == bp_watchpoint)
3825 /* For a software watchpoint, we must always check the
3827 must_check_value = 1;
3828 else if (b->watchpoint_triggered == watch_triggered_yes)
3829 /* We have a hardware watchpoint (read, write, or access)
3830 and the target earlier reported an address watched by
3832 must_check_value = 1;
3833 else if (b->watchpoint_triggered == watch_triggered_unknown
3834 && b->type == bp_hardware_watchpoint)
3835 /* We were stopped by a hardware watchpoint, but the target could
3836 not report the data address. We must check the watchpoint's
3837 value. Access and read watchpoints are out of luck; without
3838 a data address, we can't figure it out. */
3839 must_check_value = 1;
3841 if (must_check_value)
3843 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3845 struct cleanup *cleanups = make_cleanup (xfree, message);
3846 int e = catch_errors (watchpoint_check, bs, message,
3848 do_cleanups (cleanups);
3852 /* We've already printed what needs to be printed. */
3853 bs->print_it = print_it_done;
3857 bs->print_it = print_it_noop;
3860 case WP_VALUE_CHANGED:
3861 if (b->type == bp_read_watchpoint)
3863 /* There are two cases to consider here:
3865 1. we're watching the triggered memory for reads.
3866 In that case, trust the target, and always report
3867 the watchpoint hit to the user. Even though
3868 reads don't cause value changes, the value may
3869 have changed since the last time it was read, and
3870 since we're not trapping writes, we will not see
3871 those, and as such we should ignore our notion of
3874 2. we're watching the triggered memory for both
3875 reads and writes. There are two ways this may
3878 2.1. this is a target that can't break on data
3879 reads only, but can break on accesses (reads or
3880 writes), such as e.g., x86. We detect this case
3881 at the time we try to insert read watchpoints.
3883 2.2. otherwise, the target supports read
3884 watchpoints, but, the user set an access or write
3885 watchpoint watching the same memory as this read
3888 If we're watching memory writes as well as reads,
3889 ignore watchpoint hits when we find that the
3890 value hasn't changed, as reads don't cause
3891 changes. This still gives false positives when
3892 the program writes the same value to memory as
3893 what there was already in memory (we will confuse
3894 it for a read), but it's much better than
3897 int other_write_watchpoint = 0;
3899 if (bl->watchpoint_type == hw_read)
3901 struct breakpoint *other_b;
3903 ALL_BREAKPOINTS (other_b)
3904 if ((other_b->type == bp_hardware_watchpoint
3905 || other_b->type == bp_access_watchpoint)
3906 && (other_b->watchpoint_triggered
3907 == watch_triggered_yes))
3909 other_write_watchpoint = 1;
3914 if (other_write_watchpoint
3915 || bl->watchpoint_type == hw_access)
3917 /* We're watching the same memory for writes,
3918 and the value changed since the last time we
3919 updated it, so this trap must be for a write.
3921 bs->print_it = print_it_noop;
3926 case WP_VALUE_NOT_CHANGED:
3927 if (b->type == bp_hardware_watchpoint
3928 || b->type == bp_watchpoint)
3930 /* Don't stop: write watchpoints shouldn't fire if
3931 the value hasn't changed. */
3932 bs->print_it = print_it_noop;
3940 /* Error from catch_errors. */
3941 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
3942 if (b->related_breakpoint)
3943 b->related_breakpoint->disposition = disp_del_at_next_stop;
3944 b->disposition = disp_del_at_next_stop;
3945 /* We've already printed what needs to be printed. */
3946 bs->print_it = print_it_done;
3950 else /* must_check_value == 0 */
3952 /* This is a case where some watchpoint(s) triggered, but
3953 not at the address of this watchpoint, or else no
3954 watchpoint triggered after all. So don't print
3955 anything for this watchpoint. */
3956 bs->print_it = print_it_noop;
3963 /* Check conditions (condition proper, frame, thread and ignore count)
3964 of breakpoint referred to by BS. If we should not stop for this
3965 breakpoint, set BS->stop to 0. */
3967 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3969 int thread_id = pid_to_thread_id (ptid);
3970 const struct bp_location *bl;
3971 struct breakpoint *b;
3973 /* BS is built for existing struct breakpoint. */
3974 bl = bs->breakpoint_at;
3975 gdb_assert (bl != NULL);
3977 gdb_assert (b != NULL);
3979 if (frame_id_p (b->frame_id)
3980 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
3984 int value_is_zero = 0;
3985 struct expression *cond;
3987 /* If this is a scope breakpoint, mark the associated
3988 watchpoint as triggered so that we will handle the
3989 out-of-scope event. We'll get to the watchpoint next
3991 if (b->type == bp_watchpoint_scope)
3992 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3994 if (is_watchpoint (b))
3999 if (cond && bl->owner->disposition != disp_del_at_next_stop)
4001 int within_current_scope = 1;
4003 /* We use value_mark and value_free_to_mark because it could
4004 be a long time before we return to the command level and
4005 call free_all_values. We can't call free_all_values
4006 because we might be in the middle of evaluating a
4008 struct value *mark = value_mark ();
4010 /* Need to select the frame, with all that implies so that
4011 the conditions will have the right context. Because we
4012 use the frame, we will not see an inlined function's
4013 variables when we arrive at a breakpoint at the start
4014 of the inlined function; the current frame will be the
4016 if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL)
4017 select_frame (get_current_frame ());
4020 struct frame_info *frame;
4022 /* For local watchpoint expressions, which particular
4023 instance of a local is being watched matters, so we
4024 keep track of the frame to evaluate the expression
4025 in. To evaluate the condition however, it doesn't
4026 really matter which instantiation of the function
4027 where the condition makes sense triggers the
4028 watchpoint. This allows an expression like "watch
4029 global if q > 10" set in `func', catch writes to
4030 global on all threads that call `func', or catch
4031 writes on all recursive calls of `func' by a single
4032 thread. We simply always evaluate the condition in
4033 the innermost frame that's executing where it makes
4034 sense to evaluate the condition. It seems
4036 frame = block_innermost_frame (b->cond_exp_valid_block);
4038 select_frame (frame);
4040 within_current_scope = 0;
4042 if (within_current_scope)
4044 = catch_errors (breakpoint_cond_eval, cond,
4045 "Error in testing breakpoint condition:\n",
4049 warning (_("Watchpoint condition cannot be tested "
4050 "in the current scope"));
4051 /* If we failed to set the right context for this
4052 watchpoint, unconditionally report it. */
4055 /* FIXME-someday, should give breakpoint # */
4056 value_free_to_mark (mark);
4059 if (cond && value_is_zero)
4063 else if (b->thread != -1 && b->thread != thread_id)
4067 else if (b->ignore_count > 0)
4070 annotate_ignore_count_change ();
4072 /* Increase the hit count even though we don't
4080 /* Get a bpstat associated with having just stopped at address
4081 BP_ADDR in thread PTID.
4083 Determine whether we stopped at a breakpoint, etc, or whether we
4084 don't understand this stop. Result is a chain of bpstat's such that:
4086 if we don't understand the stop, the result is a null pointer.
4088 if we understand why we stopped, the result is not null.
4090 Each element of the chain refers to a particular breakpoint or
4091 watchpoint at which we have stopped. (We may have stopped for
4092 several reasons concurrently.)
4094 Each element of the chain has valid next, breakpoint_at,
4095 commands, FIXME??? fields. */
4098 bpstat_stop_status (struct address_space *aspace,
4099 CORE_ADDR bp_addr, ptid_t ptid)
4101 struct breakpoint *b = NULL;
4102 struct bp_location *bl;
4103 struct bp_location *loc;
4104 /* Root of the chain of bpstat's */
4105 struct bpstats root_bs[1];
4106 /* Pointer to the last thing in the chain currently. */
4107 bpstat bs = root_bs;
4109 int need_remove_insert;
4111 /* ALL_BP_LOCATIONS iteration would break across
4112 update_global_location_list possibly executed by
4113 bpstat_check_breakpoint_conditions's inferior call. */
4117 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4120 for (bl = b->loc; bl != NULL; bl = bl->next)
4122 /* For hardware watchpoints, we look only at the first location.
4123 The watchpoint_check function will work on the entire expression,
4124 not the individual locations. For read watchpoints, the
4125 watchpoints_triggered function has checked all locations
4127 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4130 if (bl->shlib_disabled)
4133 if (!bpstat_check_location (bl, aspace, bp_addr))
4136 /* Come here if it's a watchpoint, or if the break address matches */
4138 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
4140 /* Assume we stop. Should we find watchpoint that is not actually
4141 triggered, or if condition of breakpoint is false, we'll reset
4146 bpstat_check_watchpoint (bs);
4150 if (b->type == bp_thread_event || b->type == bp_overlay_event
4151 || b->type == bp_longjmp_master
4152 || b->type == bp_std_terminate_master)
4153 /* We do not stop for these. */
4156 bpstat_check_breakpoint_conditions (bs, ptid);
4162 /* We will stop here */
4163 if (b->disposition == disp_disable)
4165 if (b->enable_state != bp_permanent)
4166 b->enable_state = bp_disabled;
4167 update_global_location_list (0);
4171 bs->commands = b->commands;
4172 incref_counted_command_line (bs->commands);
4173 bs->commands_left = bs->commands ? bs->commands->commands : NULL;
4174 if (bs->commands_left
4175 && (strcmp ("silent", bs->commands_left->line) == 0
4178 bs->commands_left->line) == 0)))
4180 bs->commands_left = bs->commands_left->next;
4185 /* Print nothing for this entry if we dont stop or dont print. */
4186 if (bs->stop == 0 || bs->print == 0)
4187 bs->print_it = print_it_noop;
4191 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4193 if (breakpoint_address_match (loc->pspace->aspace, loc->address,
4196 bs = bpstat_alloc (loc, bs);
4197 /* For hits of moribund locations, we should just proceed. */
4200 bs->print_it = print_it_noop;
4204 bs->next = NULL; /* Terminate the chain */
4206 /* If we aren't stopping, the value of some hardware watchpoint may
4207 not have changed, but the intermediate memory locations we are
4208 watching may have. Don't bother if we're stopping; this will get
4210 need_remove_insert = 0;
4211 if (! bpstat_causes_stop (root_bs->next))
4212 for (bs = root_bs->next; bs != NULL; bs = bs->next)
4214 && bs->breakpoint_at->owner
4215 && is_hardware_watchpoint (bs->breakpoint_at->owner))
4217 update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */);
4218 /* Updating watchpoints invalidates bs->breakpoint_at.
4219 Prevent further code from trying to use it. */
4220 bs->breakpoint_at = NULL;
4221 need_remove_insert = 1;
4224 if (need_remove_insert)
4225 update_global_location_list (1);
4227 return root_bs->next;
4231 handle_jit_event (void)
4233 struct frame_info *frame;
4234 struct gdbarch *gdbarch;
4236 /* Switch terminal for any messages produced by
4237 breakpoint_re_set. */
4238 target_terminal_ours_for_output ();
4240 frame = get_current_frame ();
4241 gdbarch = get_frame_arch (frame);
4243 jit_event_handler (gdbarch);
4245 target_terminal_inferior ();
4248 /* Prepare WHAT final decision for infrun. */
4250 /* Decide what infrun needs to do with this bpstat. */
4253 bpstat_what (bpstat bs)
4255 struct bpstat_what retval;
4256 /* We need to defer calling `solib_add', as adding new symbols
4257 resets breakpoints, which in turn deletes breakpoint locations,
4258 and hence may clear unprocessed entries in the BS chain. */
4259 int shlib_event = 0;
4262 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
4263 retval.call_dummy = STOP_NONE;
4265 for (; bs != NULL; bs = bs->next)
4267 /* Extract this BS's action. After processing each BS, we check
4268 if its action overrides all we've seem so far. */
4269 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
4272 if (bs->breakpoint_at == NULL)
4274 /* I suspect this can happen if it was a momentary
4275 breakpoint which has since been deleted. */
4278 else if (bs->breakpoint_at->owner == NULL)
4281 bptype = bs->breakpoint_at->owner->type;
4288 case bp_hardware_breakpoint:
4294 this_action = BPSTAT_WHAT_STOP_NOISY;
4296 this_action = BPSTAT_WHAT_STOP_SILENT;
4299 this_action = BPSTAT_WHAT_SINGLE;
4302 case bp_hardware_watchpoint:
4303 case bp_read_watchpoint:
4304 case bp_access_watchpoint:
4308 this_action = BPSTAT_WHAT_STOP_NOISY;
4310 this_action = BPSTAT_WHAT_STOP_SILENT;
4314 /* There was a watchpoint, but we're not stopping.
4315 This requires no further action. */
4319 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
4321 case bp_longjmp_resume:
4322 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
4324 case bp_step_resume:
4326 this_action = BPSTAT_WHAT_STEP_RESUME;
4329 /* It is for the wrong frame. */
4330 this_action = BPSTAT_WHAT_SINGLE;
4333 case bp_watchpoint_scope:
4334 case bp_thread_event:
4335 case bp_overlay_event:
4336 case bp_longjmp_master:
4337 case bp_std_terminate_master:
4338 this_action = BPSTAT_WHAT_SINGLE;
4344 this_action = BPSTAT_WHAT_STOP_NOISY;
4346 this_action = BPSTAT_WHAT_STOP_SILENT;
4350 /* There was a catchpoint, but we're not stopping.
4351 This requires no further action. */
4354 case bp_shlib_event:
4357 /* If requested, stop when the dynamic linker notifies GDB
4358 of events. This allows the user to get control and place
4359 breakpoints in initializer routines for dynamically
4360 loaded objects (among other things). */
4361 if (stop_on_solib_events)
4362 this_action = BPSTAT_WHAT_STOP_NOISY;
4364 this_action = BPSTAT_WHAT_SINGLE;
4368 this_action = BPSTAT_WHAT_SINGLE;
4371 /* Make sure the action is stop (silent or noisy),
4372 so infrun.c pops the dummy frame. */
4373 retval.call_dummy = STOP_STACK_DUMMY;
4374 this_action = BPSTAT_WHAT_STOP_SILENT;
4376 case bp_std_terminate:
4377 /* Make sure the action is stop (silent or noisy),
4378 so infrun.c pops the dummy frame. */
4379 retval.call_dummy = STOP_STD_TERMINATE;
4380 this_action = BPSTAT_WHAT_STOP_SILENT;
4383 case bp_fast_tracepoint:
4384 case bp_static_tracepoint:
4385 /* Tracepoint hits should not be reported back to GDB, and
4386 if one got through somehow, it should have been filtered
4388 internal_error (__FILE__, __LINE__,
4389 _("bpstat_what: tracepoint encountered"));
4391 internal_error (__FILE__, __LINE__,
4392 _("bpstat_what: unhandled bptype %d"), (int) bptype);
4395 retval.main_action = max (retval.main_action, this_action);
4401 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n");
4403 /* Check for any newly added shared libraries if we're supposed
4404 to be adding them automatically. */
4406 /* Switch terminal for any messages produced by
4407 breakpoint_re_set. */
4408 target_terminal_ours_for_output ();
4411 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
4413 solib_add (NULL, 0, ¤t_target, auto_solib_add);
4416 target_terminal_inferior ();
4422 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
4424 handle_jit_event ();
4430 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4431 without hardware support). This isn't related to a specific bpstat,
4432 just to things like whether watchpoints are set. */
4435 bpstat_should_step (void)
4437 struct breakpoint *b;
4440 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
4446 bpstat_causes_stop (bpstat bs)
4448 for (; bs != NULL; bs = bs->next)
4457 /* Print the LOC location out of the list of B->LOC locations. */
4459 static void print_breakpoint_location (struct breakpoint *b,
4460 struct bp_location *loc,
4462 struct ui_stream *stb)
4464 struct cleanup *old_chain = save_current_program_space ();
4466 if (loc != NULL && loc->shlib_disabled)
4470 set_current_program_space (loc->pspace);
4472 if (b->source_file && loc)
4475 = find_pc_sect_function (loc->address, loc->section);
4478 ui_out_text (uiout, "in ");
4479 ui_out_field_string (uiout, "func",
4480 SYMBOL_PRINT_NAME (sym));
4481 ui_out_wrap_hint (uiout, wrap_indent);
4482 ui_out_text (uiout, " at ");
4484 ui_out_field_string (uiout, "file", b->source_file);
4485 ui_out_text (uiout, ":");
4487 if (ui_out_is_mi_like_p (uiout))
4489 struct symtab_and_line sal = find_pc_line (loc->address, 0);
4490 char *fullname = symtab_to_fullname (sal.symtab);
4493 ui_out_field_string (uiout, "fullname", fullname);
4496 ui_out_field_int (uiout, "line", b->line_number);
4500 print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
4502 ui_out_field_stream (uiout, "at", stb);
4505 ui_out_field_string (uiout, "pending", b->addr_string);
4507 do_cleanups (old_chain);
4510 /* Print B to gdb_stdout. */
4512 print_one_breakpoint_location (struct breakpoint *b,
4513 struct bp_location *loc,
4515 struct bp_location **last_loc,
4516 int print_address_bits,
4519 struct command_line *l;
4520 struct ep_type_description
4525 static struct ep_type_description bptypes[] =
4527 {bp_none, "?deleted?"},
4528 {bp_breakpoint, "breakpoint"},
4529 {bp_hardware_breakpoint, "hw breakpoint"},
4530 {bp_until, "until"},
4531 {bp_finish, "finish"},
4532 {bp_watchpoint, "watchpoint"},
4533 {bp_hardware_watchpoint, "hw watchpoint"},
4534 {bp_read_watchpoint, "read watchpoint"},
4535 {bp_access_watchpoint, "acc watchpoint"},
4536 {bp_longjmp, "longjmp"},
4537 {bp_longjmp_resume, "longjmp resume"},
4538 {bp_step_resume, "step resume"},
4539 {bp_watchpoint_scope, "watchpoint scope"},
4540 {bp_call_dummy, "call dummy"},
4541 {bp_std_terminate, "std::terminate"},
4542 {bp_shlib_event, "shlib events"},
4543 {bp_thread_event, "thread events"},
4544 {bp_overlay_event, "overlay events"},
4545 {bp_longjmp_master, "longjmp master"},
4546 {bp_std_terminate_master, "std::terminate master"},
4547 {bp_catchpoint, "catchpoint"},
4548 {bp_tracepoint, "tracepoint"},
4549 {bp_fast_tracepoint, "fast tracepoint"},
4550 {bp_static_tracepoint, "static tracepoint"},
4551 {bp_jit_event, "jit events"},
4554 static char bpenables[] = "nynny";
4555 char wrap_indent[80];
4556 struct ui_stream *stb = ui_out_stream_new (uiout);
4557 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
4558 struct cleanup *bkpt_chain;
4560 int header_of_multiple = 0;
4561 int part_of_multiple = (loc != NULL);
4562 struct value_print_options opts;
4564 get_user_print_options (&opts);
4566 gdb_assert (!loc || loc_number != 0);
4567 /* See comment in print_one_breakpoint concerning
4568 treatment of breakpoints with single disabled
4572 && (b->loc->next != NULL || !b->loc->enabled)))
4573 header_of_multiple = 1;
4578 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
4582 if (part_of_multiple)
4585 formatted = xstrprintf ("%d.%d", b->number, loc_number);
4586 ui_out_field_string (uiout, "number", formatted);
4591 ui_out_field_int (uiout, "number", b->number);
4596 if (part_of_multiple)
4597 ui_out_field_skip (uiout, "type");
4600 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
4601 || ((int) b->type != bptypes[(int) b->type].type))
4602 internal_error (__FILE__, __LINE__,
4603 _("bptypes table does not describe type #%d."),
4605 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
4610 if (part_of_multiple)
4611 ui_out_field_skip (uiout, "disp");
4613 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
4618 if (part_of_multiple)
4619 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
4621 ui_out_field_fmt (uiout, "enabled", "%c",
4622 bpenables[(int) b->enable_state]);
4623 ui_out_spaces (uiout, 2);
4627 strcpy (wrap_indent, " ");
4628 if (opts.addressprint)
4630 if (print_address_bits <= 32)
4631 strcat (wrap_indent, " ");
4633 strcat (wrap_indent, " ");
4636 if (b->ops != NULL && b->ops->print_one != NULL)
4638 /* Although the print_one can possibly print
4639 all locations, calling it here is not likely
4640 to get any nice result. So, make sure there's
4641 just one location. */
4642 gdb_assert (b->loc == NULL || b->loc->next == NULL);
4643 b->ops->print_one (b, last_loc);
4649 internal_error (__FILE__, __LINE__,
4650 _("print_one_breakpoint: bp_none encountered\n"));
4654 case bp_hardware_watchpoint:
4655 case bp_read_watchpoint:
4656 case bp_access_watchpoint:
4657 /* Field 4, the address, is omitted (which makes the columns
4658 not line up too nicely with the headers, but the effect
4659 is relatively readable). */
4660 if (opts.addressprint)
4661 ui_out_field_skip (uiout, "addr");
4663 ui_out_field_string (uiout, "what", b->exp_string);
4667 case bp_hardware_breakpoint:
4671 case bp_longjmp_resume:
4672 case bp_step_resume:
4673 case bp_watchpoint_scope:
4675 case bp_std_terminate:
4676 case bp_shlib_event:
4677 case bp_thread_event:
4678 case bp_overlay_event:
4679 case bp_longjmp_master:
4680 case bp_std_terminate_master:
4682 case bp_fast_tracepoint:
4683 case bp_static_tracepoint:
4685 if (opts.addressprint)
4688 if (header_of_multiple)
4689 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
4690 else if (b->loc == NULL || loc->shlib_disabled)
4691 ui_out_field_string (uiout, "addr", "<PENDING>");
4693 ui_out_field_core_addr (uiout, "addr",
4694 loc->gdbarch, loc->address);
4697 if (!header_of_multiple)
4698 print_breakpoint_location (b, loc, wrap_indent, stb);
4705 /* For backward compatibility, don't display inferiors unless there
4708 && !header_of_multiple
4710 || (!gdbarch_has_global_breakpoints (target_gdbarch)
4711 && (number_of_program_spaces () > 1
4712 || number_of_inferiors () > 1)
4713 /* LOC is for existing B, it cannot be in moribund_locations and
4714 thus having NULL OWNER. */
4715 && loc->owner->type != bp_catchpoint)))
4717 struct inferior *inf;
4720 for (inf = inferior_list; inf != NULL; inf = inf->next)
4722 if (inf->pspace == loc->pspace)
4727 ui_out_text (uiout, " inf ");
4730 ui_out_text (uiout, ", ");
4731 ui_out_text (uiout, plongest (inf->num));
4736 if (!part_of_multiple)
4738 if (b->thread != -1)
4740 /* FIXME: This seems to be redundant and lost here; see the
4741 "stop only in" line a little further down. */
4742 ui_out_text (uiout, " thread ");
4743 ui_out_field_int (uiout, "thread", b->thread);
4745 else if (b->task != 0)
4747 ui_out_text (uiout, " task ");
4748 ui_out_field_int (uiout, "task", b->task);
4752 ui_out_text (uiout, "\n");
4754 if (!part_of_multiple && b->static_trace_marker_id)
4756 gdb_assert (b->type == bp_static_tracepoint);
4758 ui_out_text (uiout, "\tmarker id is ");
4759 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
4760 b->static_trace_marker_id);
4761 ui_out_text (uiout, "\n");
4764 if (part_of_multiple && frame_id_p (b->frame_id))
4767 ui_out_text (uiout, "\tstop only in stack frame at ");
4768 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4770 ui_out_field_core_addr (uiout, "frame",
4771 b->gdbarch, b->frame_id.stack_addr);
4772 ui_out_text (uiout, "\n");
4775 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
4777 /* We do not print the condition for Ada exception catchpoints
4778 because the condition is an internal implementation detail
4779 that we do not want to expose to the user. */
4781 if (is_tracepoint (b))
4782 ui_out_text (uiout, "\ttrace only if ");
4784 ui_out_text (uiout, "\tstop only if ");
4785 ui_out_field_string (uiout, "cond", b->cond_string);
4786 ui_out_text (uiout, "\n");
4789 if (!part_of_multiple && b->thread != -1)
4791 /* FIXME should make an annotation for this */
4792 ui_out_text (uiout, "\tstop only in thread ");
4793 ui_out_field_int (uiout, "thread", b->thread);
4794 ui_out_text (uiout, "\n");
4797 if (!part_of_multiple && b->hit_count)
4799 /* FIXME should make an annotation for this */
4800 if (ep_is_catchpoint (b))
4801 ui_out_text (uiout, "\tcatchpoint");
4803 ui_out_text (uiout, "\tbreakpoint");
4804 ui_out_text (uiout, " already hit ");
4805 ui_out_field_int (uiout, "times", b->hit_count);
4806 if (b->hit_count == 1)
4807 ui_out_text (uiout, " time\n");
4809 ui_out_text (uiout, " times\n");
4812 /* Output the count also if it is zero, but only if this is
4813 mi. FIXME: Should have a better test for this. */
4814 if (ui_out_is_mi_like_p (uiout))
4815 if (!part_of_multiple && b->hit_count == 0)
4816 ui_out_field_int (uiout, "times", b->hit_count);
4818 if (!part_of_multiple && b->ignore_count)
4821 ui_out_text (uiout, "\tignore next ");
4822 ui_out_field_int (uiout, "ignore", b->ignore_count);
4823 ui_out_text (uiout, " hits\n");
4826 l = b->commands ? b->commands->commands : NULL;
4827 if (!part_of_multiple && l)
4829 struct cleanup *script_chain;
4832 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
4833 print_command_lines (uiout, l, 4);
4834 do_cleanups (script_chain);
4837 if (!part_of_multiple && b->pass_count)
4839 annotate_field (10);
4840 ui_out_text (uiout, "\tpass count ");
4841 ui_out_field_int (uiout, "pass", b->pass_count);
4842 ui_out_text (uiout, " \n");
4845 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
4848 ui_out_field_string (uiout, "original-location", b->addr_string);
4849 else if (b->exp_string)
4850 ui_out_field_string (uiout, "original-location", b->exp_string);
4853 do_cleanups (bkpt_chain);
4854 do_cleanups (old_chain);
4858 print_one_breakpoint (struct breakpoint *b,
4859 struct bp_location **last_loc, int print_address_bits,
4862 print_one_breakpoint_location (b, NULL, 0, last_loc,
4863 print_address_bits, allflag);
4865 /* If this breakpoint has custom print function,
4866 it's already printed. Otherwise, print individual
4867 locations, if any. */
4868 if (b->ops == NULL || b->ops->print_one == NULL)
4870 /* If breakpoint has a single location that is
4871 disabled, we print it as if it had
4872 several locations, since otherwise it's hard to
4873 represent "breakpoint enabled, location disabled"
4875 Note that while hardware watchpoints have
4876 several locations internally, that's no a property
4879 && !is_hardware_watchpoint (b)
4880 && (b->loc->next || !b->loc->enabled)
4881 && !ui_out_is_mi_like_p (uiout))
4883 struct bp_location *loc;
4885 for (loc = b->loc; loc; loc = loc->next, ++n)
4886 print_one_breakpoint_location (b, loc, n, last_loc,
4887 print_address_bits, allflag);
4893 breakpoint_address_bits (struct breakpoint *b)
4895 int print_address_bits = 0;
4896 struct bp_location *loc;
4898 for (loc = b->loc; loc; loc = loc->next)
4902 /* Software watchpoints that aren't watching memory don't have
4903 an address to print. */
4904 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
4907 addr_bit = gdbarch_addr_bit (loc->gdbarch);
4908 if (addr_bit > print_address_bits)
4909 print_address_bits = addr_bit;
4912 return print_address_bits;
4915 struct captured_breakpoint_query_args
4921 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
4923 struct captured_breakpoint_query_args *args = data;
4924 struct breakpoint *b;
4925 struct bp_location *dummy_loc = NULL;
4929 if (args->bnum == b->number)
4931 int print_address_bits = breakpoint_address_bits (b);
4933 print_one_breakpoint (b, &dummy_loc, print_address_bits, 0);
4941 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
4943 struct captured_breakpoint_query_args args;
4946 /* For the moment we don't trust print_one_breakpoint() to not throw
4948 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
4949 error_message, RETURN_MASK_ALL) < 0)
4955 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4956 catchpoints, et.al.). */
4959 user_settable_breakpoint (const struct breakpoint *b)
4961 return (b->type == bp_breakpoint
4962 || b->type == bp_catchpoint
4963 || b->type == bp_hardware_breakpoint
4964 || is_tracepoint (b)
4965 || is_watchpoint (b));
4968 /* Print information on user settable breakpoint (watchpoint, etc)
4969 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4970 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4971 FILTER is non-NULL, call it on each breakpoint and only include the
4972 ones for which it returns non-zero. Return the total number of
4973 breakpoints listed. */
4976 breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *))
4978 struct breakpoint *b;
4979 struct bp_location *last_loc = NULL;
4980 int nr_printable_breakpoints;
4981 struct cleanup *bkpttbl_chain;
4982 struct value_print_options opts;
4983 int print_address_bits = 0;
4985 get_user_print_options (&opts);
4987 /* Compute the number of rows in the table, as well as the
4988 size required for address fields. */
4989 nr_printable_breakpoints = 0;
4992 || bnum == b->number)
4994 /* If we have a filter, only list the breakpoints it accepts. */
4995 if (filter && !filter (b))
4998 if (allflag || user_settable_breakpoint (b))
5000 int addr_bit = breakpoint_address_bits (b);
5001 if (addr_bit > print_address_bits)
5002 print_address_bits = addr_bit;
5004 nr_printable_breakpoints++;
5008 if (opts.addressprint)
5010 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
5014 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
5017 if (nr_printable_breakpoints > 0)
5018 annotate_breakpoints_headers ();
5019 if (nr_printable_breakpoints > 0)
5021 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5022 if (nr_printable_breakpoints > 0)
5024 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
5025 if (nr_printable_breakpoints > 0)
5027 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
5028 if (nr_printable_breakpoints > 0)
5030 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
5031 if (opts.addressprint)
5033 if (nr_printable_breakpoints > 0)
5035 if (print_address_bits <= 32)
5036 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
5038 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
5040 if (nr_printable_breakpoints > 0)
5042 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
5043 ui_out_table_body (uiout);
5044 if (nr_printable_breakpoints > 0)
5045 annotate_breakpoints_table ();
5051 || bnum == b->number)
5053 /* If we have a filter, only list the breakpoints it accepts. */
5054 if (filter && !filter (b))
5057 /* We only print out user settable breakpoints unless the
5059 if (allflag || user_settable_breakpoint (b))
5060 print_one_breakpoint (b, &last_loc, print_address_bits, allflag);
5064 do_cleanups (bkpttbl_chain);
5066 if (nr_printable_breakpoints == 0)
5068 /* If there's a filter, let the caller decide how to report empty list. */
5072 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
5074 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
5080 if (last_loc && !server_command)
5081 set_next_address (last_loc->gdbarch, last_loc->address);
5084 /* FIXME? Should this be moved up so that it is only called when
5085 there have been breakpoints? */
5086 annotate_breakpoints_table_end ();
5088 return nr_printable_breakpoints;
5091 /* Display the value of default-collect in a way that is generally
5092 compatible with the breakpoint list. */
5095 default_collect_info (void)
5097 /* If it has no value (which is frequently the case), say nothing; a
5098 message like "No default-collect." gets in user's face when it's
5100 if (!*default_collect)
5103 /* The following phrase lines up nicely with per-tracepoint collect
5105 ui_out_text (uiout, "default collect ");
5106 ui_out_field_string (uiout, "default-collect", default_collect);
5107 ui_out_text (uiout, " \n");
5111 breakpoints_info (char *bnum_exp, int from_tty)
5116 bnum = parse_and_eval_long (bnum_exp);
5118 breakpoint_1 (bnum, 0, NULL);
5120 default_collect_info ();
5124 watchpoints_info (char *wpnum_exp, int from_tty)
5126 int wpnum = -1, num_printed;
5129 wpnum = parse_and_eval_long (wpnum_exp);
5131 num_printed = breakpoint_1 (wpnum, 0, is_watchpoint);
5133 if (num_printed == 0)
5136 ui_out_message (uiout, 0, "No watchpoints.\n");
5138 ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum);
5143 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
5148 bnum = parse_and_eval_long (bnum_exp);
5150 breakpoint_1 (bnum, 1, NULL);
5152 default_collect_info ();
5156 breakpoint_has_pc (struct breakpoint *b,
5157 struct program_space *pspace,
5158 CORE_ADDR pc, struct obj_section *section)
5160 struct bp_location *bl = b->loc;
5162 for (; bl; bl = bl->next)
5164 if (bl->pspace == pspace
5165 && bl->address == pc
5166 && (!overlay_debugging || bl->section == section))
5172 /* Print a message describing any breakpoints set at PC. This
5173 concerns with logical breakpoints, so we match program spaces, not
5177 describe_other_breakpoints (struct gdbarch *gdbarch,
5178 struct program_space *pspace, CORE_ADDR pc,
5179 struct obj_section *section, int thread)
5182 struct breakpoint *b;
5185 others += breakpoint_has_pc (b, pspace, pc, section);
5189 printf_filtered (_("Note: breakpoint "));
5190 else /* if (others == ???) */
5191 printf_filtered (_("Note: breakpoints "));
5193 if (breakpoint_has_pc (b, pspace, pc, section))
5196 printf_filtered ("%d", b->number);
5197 if (b->thread == -1 && thread != -1)
5198 printf_filtered (" (all threads)");
5199 else if (b->thread != -1)
5200 printf_filtered (" (thread %d)", b->thread);
5201 printf_filtered ("%s%s ",
5202 ((b->enable_state == bp_disabled
5203 || b->enable_state == bp_call_disabled
5204 || b->enable_state == bp_startup_disabled)
5206 : b->enable_state == bp_permanent
5210 : ((others == 1) ? " and" : ""));
5212 printf_filtered (_("also set at pc "));
5213 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
5214 printf_filtered (".\n");
5218 /* Set the default place to put a breakpoint
5219 for the `break' command with no arguments. */
5222 set_default_breakpoint (int valid, struct program_space *pspace,
5223 CORE_ADDR addr, struct symtab *symtab,
5226 default_breakpoint_valid = valid;
5227 default_breakpoint_pspace = pspace;
5228 default_breakpoint_address = addr;
5229 default_breakpoint_symtab = symtab;
5230 default_breakpoint_line = line;
5233 /* Return true iff it is meaningful to use the address member of
5234 BPT. For some breakpoint types, the address member is irrelevant
5235 and it makes no sense to attempt to compare it to other addresses
5236 (or use it for any other purpose either).
5238 More specifically, each of the following breakpoint types will always
5239 have a zero valued address and we don't want to mark breakpoints of any of
5240 these types to be a duplicate of an actual breakpoint at address zero:
5248 breakpoint_address_is_meaningful (struct breakpoint *bpt)
5250 enum bptype type = bpt->type;
5252 return (type != bp_watchpoint && type != bp_catchpoint);
5255 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5256 true if LOC1 and LOC2 represent the same watchpoint location. */
5259 watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5261 /* Both of them must not be in moribund_locations. */
5262 gdb_assert (loc1->owner != NULL);
5263 gdb_assert (loc2->owner != NULL);
5265 /* Note that this checks the owner's type, not the location's. In
5266 case the target does not support read watchpoints, but does
5267 support access watchpoints, we'll have bp_read_watchpoint
5268 watchpoints with hw_access locations. Those should be considered
5269 duplicates of hw_read locations. The hw_read locations will
5270 become hw_access locations later. */
5271 return (loc1->owner->type == loc2->owner->type
5272 && loc1->pspace->aspace == loc2->pspace->aspace
5273 && loc1->address == loc2->address
5274 && loc1->length == loc2->length);
5277 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5278 same breakpoint location. In most targets, this can only be true
5279 if ASPACE1 matches ASPACE2. On targets that have global
5280 breakpoints, the address space doesn't really matter. */
5283 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
5284 struct address_space *aspace2, CORE_ADDR addr2)
5286 return ((gdbarch_has_global_breakpoints (target_gdbarch)
5287 || aspace1 == aspace2)
5291 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5292 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5293 represent the same location. */
5296 breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2)
5298 int hw_point1, hw_point2;
5300 /* Both of them must not be in moribund_locations. */
5301 gdb_assert (loc1->owner != NULL);
5302 gdb_assert (loc2->owner != NULL);
5304 hw_point1 = is_hardware_watchpoint (loc1->owner);
5305 hw_point2 = is_hardware_watchpoint (loc2->owner);
5307 if (hw_point1 != hw_point2)
5310 return watchpoint_locations_match (loc1, loc2);
5312 return breakpoint_address_match (loc1->pspace->aspace, loc1->address,
5313 loc2->pspace->aspace, loc2->address);
5317 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
5318 int bnum, int have_bnum)
5323 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
5324 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
5326 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5327 bnum, astr1, astr2);
5329 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
5332 /* Adjust a breakpoint's address to account for architectural constraints
5333 on breakpoint placement. Return the adjusted address. Note: Very
5334 few targets require this kind of adjustment. For most targets,
5335 this function is simply the identity function. */
5338 adjust_breakpoint_address (struct gdbarch *gdbarch,
5339 CORE_ADDR bpaddr, enum bptype bptype)
5341 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
5343 /* Very few targets need any kind of breakpoint adjustment. */
5346 else if (bptype == bp_watchpoint
5347 || bptype == bp_hardware_watchpoint
5348 || bptype == bp_read_watchpoint
5349 || bptype == bp_access_watchpoint
5350 || bptype == bp_catchpoint)
5352 /* Watchpoints and the various bp_catch_* eventpoints should not
5353 have their addresses modified. */
5358 CORE_ADDR adjusted_bpaddr;
5360 /* Some targets have architectural constraints on the placement
5361 of breakpoint instructions. Obtain the adjusted address. */
5362 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
5364 /* An adjusted breakpoint address can significantly alter
5365 a user's expectations. Print a warning if an adjustment
5367 if (adjusted_bpaddr != bpaddr)
5368 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
5370 return adjusted_bpaddr;
5374 /* Allocate a struct bp_location. */
5376 static struct bp_location *
5377 allocate_bp_location (struct breakpoint *bpt)
5379 struct bp_location *loc;
5381 loc = xmalloc (sizeof (struct bp_location));
5382 memset (loc, 0, sizeof (*loc));
5386 loc->shlib_disabled = 0;
5395 case bp_longjmp_resume:
5396 case bp_step_resume:
5397 case bp_watchpoint_scope:
5399 case bp_std_terminate:
5400 case bp_shlib_event:
5401 case bp_thread_event:
5402 case bp_overlay_event:
5404 case bp_longjmp_master:
5405 case bp_std_terminate_master:
5406 loc->loc_type = bp_loc_software_breakpoint;
5408 case bp_hardware_breakpoint:
5409 loc->loc_type = bp_loc_hardware_breakpoint;
5411 case bp_hardware_watchpoint:
5412 case bp_read_watchpoint:
5413 case bp_access_watchpoint:
5414 loc->loc_type = bp_loc_hardware_watchpoint;
5419 case bp_fast_tracepoint:
5420 case bp_static_tracepoint:
5421 loc->loc_type = bp_loc_other;
5424 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
5430 static void free_bp_location (struct bp_location *loc)
5432 /* Be sure no bpstat's are pointing at it after it's been freed. */
5433 /* FIXME, how can we find all bpstat's?
5434 We just check stop_bpstat for now. Note that we cannot just
5435 remove bpstats pointing at bpt from the stop_bpstat list
5436 entirely, as breakpoint commands are associated with the bpstat;
5437 if we remove it here, then the later call to
5438 bpstat_do_actions (&stop_bpstat);
5439 in event-top.c won't do anything, and temporary breakpoints
5440 with commands won't work. */
5442 iterate_over_threads (bpstat_remove_bp_location_callback, loc);
5447 if (loc->function_name)
5448 xfree (loc->function_name);
5453 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5454 that has type BPTYPE and has no locations as yet. */
5455 /* This function is used in gdbtk sources and thus can not be made static. */
5457 static struct breakpoint *
5458 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
5461 struct breakpoint *b, *b1;
5463 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
5464 memset (b, 0, sizeof (*b));
5467 b->gdbarch = gdbarch;
5468 b->language = current_language->la_language;
5469 b->input_radix = input_radix;
5471 b->enable_state = bp_enabled;
5474 b->ignore_count = 0;
5476 b->frame_id = null_frame_id;
5477 b->forked_inferior_pid = null_ptid;
5478 b->exec_pathname = NULL;
5479 b->syscalls_to_be_caught = NULL;
5481 b->condition_not_parsed = 0;
5483 /* Add this breakpoint to the end of the chain
5484 so that a list of breakpoints will come out in order
5485 of increasing numbers. */
5487 b1 = breakpoint_chain;
5489 breakpoint_chain = b;
5499 /* Initialize loc->function_name. */
5501 set_breakpoint_location_function (struct bp_location *loc)
5503 gdb_assert (loc->owner != NULL);
5505 if (loc->owner->type == bp_breakpoint
5506 || loc->owner->type == bp_hardware_breakpoint
5507 || is_tracepoint (loc->owner))
5509 find_pc_partial_function (loc->address, &(loc->function_name),
5511 if (loc->function_name)
5512 loc->function_name = xstrdup (loc->function_name);
5516 /* Attempt to determine architecture of location identified by SAL. */
5517 static struct gdbarch *
5518 get_sal_arch (struct symtab_and_line sal)
5521 return get_objfile_arch (sal.section->objfile);
5523 return get_objfile_arch (sal.symtab->objfile);
5528 /* set_raw_breakpoint is a low level routine for allocating and
5529 partially initializing a breakpoint of type BPTYPE. The newly
5530 created breakpoint's address, section, source file name, and line
5531 number are provided by SAL. The newly created and partially
5532 initialized breakpoint is added to the breakpoint chain and
5533 is also returned as the value of this function.
5535 It is expected that the caller will complete the initialization of
5536 the newly created breakpoint struct as well as output any status
5537 information regarding the creation of a new breakpoint. In
5538 particular, set_raw_breakpoint does NOT set the breakpoint
5539 number! Care should be taken to not allow an error to occur
5540 prior to completing the initialization of the breakpoint. If this
5541 should happen, a bogus breakpoint will be left on the chain. */
5544 set_raw_breakpoint (struct gdbarch *gdbarch,
5545 struct symtab_and_line sal, enum bptype bptype)
5547 struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype);
5548 CORE_ADDR adjusted_address;
5549 struct gdbarch *loc_gdbarch;
5551 loc_gdbarch = get_sal_arch (sal);
5553 loc_gdbarch = b->gdbarch;
5555 if (bptype != bp_catchpoint)
5556 gdb_assert (sal.pspace != NULL);
5558 /* Adjust the breakpoint's address prior to allocating a location.
5559 Once we call allocate_bp_location(), that mostly uninitialized
5560 location will be placed on the location chain. Adjustment of the
5561 breakpoint may cause target_read_memory() to be called and we do
5562 not want its scan of the location chain to find a breakpoint and
5563 location that's only been partially initialized. */
5564 adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type);
5566 b->loc = allocate_bp_location (b);
5567 b->loc->gdbarch = loc_gdbarch;
5568 b->loc->requested_address = sal.pc;
5569 b->loc->address = adjusted_address;
5570 b->loc->pspace = sal.pspace;
5572 /* Store the program space that was used to set the breakpoint, for
5573 breakpoint resetting. */
5574 b->pspace = sal.pspace;
5576 if (sal.symtab == NULL)
5577 b->source_file = NULL;
5579 b->source_file = xstrdup (sal.symtab->filename);
5580 b->loc->section = sal.section;
5581 b->line_number = sal.line;
5583 set_breakpoint_location_function (b->loc);
5585 breakpoints_changed ();
5591 /* Note that the breakpoint object B describes a permanent breakpoint
5592 instruction, hard-wired into the inferior's code. */
5594 make_breakpoint_permanent (struct breakpoint *b)
5596 struct bp_location *bl;
5598 b->enable_state = bp_permanent;
5600 /* By definition, permanent breakpoints are already present in the code.
5601 Mark all locations as inserted. For now, make_breakpoint_permanent
5602 is called in just one place, so it's hard to say if it's reasonable
5603 to have permanent breakpoint with multiple locations or not,
5604 but it's easy to implmement. */
5605 for (bl = b->loc; bl; bl = bl->next)
5609 /* Call this routine when stepping and nexting to enable a breakpoint
5610 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5611 set_longjmp_resume_breakpoint() to figure out where we are going. */
5614 set_longjmp_breakpoint (int thread)
5616 struct breakpoint *b, *temp;
5618 /* To avoid having to rescan all objfile symbols at every step,
5619 we maintain a list of continually-inserted but always disabled
5620 longjmp "master" breakpoints. Here, we simply create momentary
5621 clones of those and enable them for the requested thread. */
5622 ALL_BREAKPOINTS_SAFE (b, temp)
5623 if (b->pspace == current_program_space
5624 && b->type == bp_longjmp_master)
5626 struct breakpoint *clone = clone_momentary_breakpoint (b);
5628 clone->type = bp_longjmp;
5629 clone->thread = thread;
5633 /* Delete all longjmp breakpoints from THREAD. */
5635 delete_longjmp_breakpoint (int thread)
5637 struct breakpoint *b, *temp;
5639 ALL_BREAKPOINTS_SAFE (b, temp)
5640 if (b->type == bp_longjmp)
5642 if (b->thread == thread)
5643 delete_breakpoint (b);
5648 enable_overlay_breakpoints (void)
5650 struct breakpoint *b;
5653 if (b->type == bp_overlay_event)
5655 b->enable_state = bp_enabled;
5656 update_global_location_list (1);
5657 overlay_events_enabled = 1;
5662 disable_overlay_breakpoints (void)
5664 struct breakpoint *b;
5667 if (b->type == bp_overlay_event)
5669 b->enable_state = bp_disabled;
5670 update_global_location_list (0);
5671 overlay_events_enabled = 0;
5675 /* Set an active std::terminate breakpoint for each std::terminate
5676 master breakpoint. */
5678 set_std_terminate_breakpoint (void)
5680 struct breakpoint *b, *temp;
5682 ALL_BREAKPOINTS_SAFE (b, temp)
5683 if (b->pspace == current_program_space
5684 && b->type == bp_std_terminate_master)
5686 struct breakpoint *clone = clone_momentary_breakpoint (b);
5687 clone->type = bp_std_terminate;
5691 /* Delete all the std::terminate breakpoints. */
5693 delete_std_terminate_breakpoint (void)
5695 struct breakpoint *b, *temp;
5697 ALL_BREAKPOINTS_SAFE (b, temp)
5698 if (b->type == bp_std_terminate)
5699 delete_breakpoint (b);
5703 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5705 struct breakpoint *b;
5707 b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
5709 b->enable_state = bp_enabled;
5710 /* addr_string has to be used or breakpoint_re_set will delete me. */
5712 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
5714 update_global_location_list_nothrow (1);
5720 remove_thread_event_breakpoints (void)
5722 struct breakpoint *b, *temp;
5724 ALL_BREAKPOINTS_SAFE (b, temp)
5725 if (b->type == bp_thread_event
5726 && b->loc->pspace == current_program_space)
5727 delete_breakpoint (b);
5730 struct captured_parse_breakpoint_args
5733 struct symtabs_and_lines *sals_p;
5734 char ***addr_string_p;
5738 struct lang_and_radix
5744 /* Create a breakpoint for JIT code registration and unregistration. */
5747 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5749 struct breakpoint *b;
5751 b = create_internal_breakpoint (gdbarch, address, bp_jit_event);
5752 update_global_location_list_nothrow (1);
5757 remove_solib_event_breakpoints (void)
5759 struct breakpoint *b, *temp;
5761 ALL_BREAKPOINTS_SAFE (b, temp)
5762 if (b->type == bp_shlib_event
5763 && b->loc->pspace == current_program_space)
5764 delete_breakpoint (b);
5768 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
5770 struct breakpoint *b;
5772 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event);
5773 update_global_location_list_nothrow (1);
5777 /* Disable any breakpoints that are on code in shared libraries. Only
5778 apply to enabled breakpoints, disabled ones can just stay disabled. */
5781 disable_breakpoints_in_shlibs (void)
5783 struct bp_location *loc, **locp_tmp;
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 /* We apply the check to all breakpoints, including disabled
5791 for those with loc->duplicate set. This is so that when breakpoint
5792 becomes enabled, or the duplicate is removed, gdb will try to insert
5793 all breakpoints. If we don't set shlib_disabled here, we'll try
5794 to insert those breakpoints and fail. */
5795 if (((b->type == bp_breakpoint)
5796 || (b->type == bp_jit_event)
5797 || (b->type == bp_hardware_breakpoint)
5798 || (is_tracepoint (b)))
5799 && loc->pspace == current_program_space
5800 && !loc->shlib_disabled
5802 && PC_SOLIB (loc->address)
5804 && solib_name_from_address (loc->pspace, loc->address)
5808 loc->shlib_disabled = 1;
5813 /* Disable any breakpoints that are in in an unloaded shared library. Only
5814 apply to enabled breakpoints, disabled ones can just stay disabled. */
5817 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
5819 struct bp_location *loc, **locp_tmp;
5820 int disabled_shlib_breaks = 0;
5822 /* SunOS a.out shared libraries are always mapped, so do not
5823 disable breakpoints; they will only be reported as unloaded
5824 through clear_solib when GDB discards its shared library
5825 list. See clear_solib for more information. */
5826 if (exec_bfd != NULL
5827 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
5830 ALL_BP_LOCATIONS (loc, locp_tmp)
5832 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5833 struct breakpoint *b = loc->owner;
5835 if ((loc->loc_type == bp_loc_hardware_breakpoint
5836 || loc->loc_type == bp_loc_software_breakpoint)
5837 && solib->pspace == loc->pspace
5838 && !loc->shlib_disabled
5839 && (b->type == bp_breakpoint
5840 || b->type == bp_jit_event
5841 || b->type == bp_hardware_breakpoint)
5842 && solib_contains_address_p (solib, loc->address))
5844 loc->shlib_disabled = 1;
5845 /* At this point, we cannot rely on remove_breakpoint
5846 succeeding so we must mark the breakpoint as not inserted
5847 to prevent future errors occurring in remove_breakpoints. */
5849 if (!disabled_shlib_breaks)
5851 target_terminal_ours_for_output ();
5852 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5855 disabled_shlib_breaks = 1;
5860 /* FORK & VFORK catchpoints. */
5862 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5865 insert_catch_fork (struct breakpoint *b)
5867 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
5870 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5873 remove_catch_fork (struct breakpoint *b)
5875 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
5878 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5882 breakpoint_hit_catch_fork (struct breakpoint *b)
5884 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
5887 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5889 static enum print_stop_action
5890 print_it_catch_fork (struct breakpoint *b)
5892 annotate_catchpoint (b->number);
5893 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5894 b->number, ptid_get_pid (b->forked_inferior_pid));
5895 return PRINT_SRC_AND_LOC;
5898 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5901 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
5903 struct value_print_options opts;
5905 get_user_print_options (&opts);
5907 /* Field 4, the address, is omitted (which makes the columns
5908 not line up too nicely with the headers, but the effect
5909 is relatively readable). */
5910 if (opts.addressprint)
5911 ui_out_field_skip (uiout, "addr");
5913 ui_out_text (uiout, "fork");
5914 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
5916 ui_out_text (uiout, ", process ");
5917 ui_out_field_int (uiout, "what",
5918 ptid_get_pid (b->forked_inferior_pid));
5919 ui_out_spaces (uiout, 1);
5923 /* Implement the "print_mention" breakpoint_ops method for fork
5927 print_mention_catch_fork (struct breakpoint *b)
5929 printf_filtered (_("Catchpoint %d (fork)"), b->number);
5932 /* Implement the "print_recreate" breakpoint_ops method for fork
5936 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
5938 fprintf_unfiltered (fp, "catch fork");
5941 /* The breakpoint_ops structure to be used in fork catchpoints. */
5943 static struct breakpoint_ops catch_fork_breakpoint_ops =
5947 breakpoint_hit_catch_fork,
5948 print_it_catch_fork,
5949 print_one_catch_fork,
5950 print_mention_catch_fork,
5951 print_recreate_catch_fork
5954 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5957 insert_catch_vfork (struct breakpoint *b)
5959 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
5962 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5965 remove_catch_vfork (struct breakpoint *b)
5967 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
5970 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5974 breakpoint_hit_catch_vfork (struct breakpoint *b)
5976 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
5979 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5981 static enum print_stop_action
5982 print_it_catch_vfork (struct breakpoint *b)
5984 annotate_catchpoint (b->number);
5985 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5986 b->number, ptid_get_pid (b->forked_inferior_pid));
5987 return PRINT_SRC_AND_LOC;
5990 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5993 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
5995 struct value_print_options opts;
5997 get_user_print_options (&opts);
5998 /* Field 4, the address, is omitted (which makes the columns
5999 not line up too nicely with the headers, but the effect
6000 is relatively readable). */
6001 if (opts.addressprint)
6002 ui_out_field_skip (uiout, "addr");
6004 ui_out_text (uiout, "vfork");
6005 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
6007 ui_out_text (uiout, ", process ");
6008 ui_out_field_int (uiout, "what",
6009 ptid_get_pid (b->forked_inferior_pid));
6010 ui_out_spaces (uiout, 1);
6014 /* Implement the "print_mention" breakpoint_ops method for vfork
6018 print_mention_catch_vfork (struct breakpoint *b)
6020 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
6023 /* Implement the "print_recreate" breakpoint_ops method for vfork
6027 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
6029 fprintf_unfiltered (fp, "catch vfork");
6032 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6034 static struct breakpoint_ops catch_vfork_breakpoint_ops =
6038 breakpoint_hit_catch_vfork,
6039 print_it_catch_vfork,
6040 print_one_catch_vfork,
6041 print_mention_catch_vfork,
6042 print_recreate_catch_vfork
6045 /* Implement the "insert" breakpoint_ops method for syscall
6049 insert_catch_syscall (struct breakpoint *b)
6051 struct inferior *inf = current_inferior ();
6053 ++inf->total_syscalls_count;
6054 if (!b->syscalls_to_be_caught)
6055 ++inf->any_syscall_count;
6061 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6066 if (iter >= VEC_length (int, inf->syscalls_counts))
6068 int old_size = VEC_length (int, inf->syscalls_counts);
6069 uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int));
6071 VEC_safe_grow (int, inf->syscalls_counts, iter + 1);
6072 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) +
6074 memset ((void *) vec_addr, 0,
6075 (iter + 1 - old_size) * sizeof (int));
6077 elem = VEC_index (int, inf->syscalls_counts, iter);
6078 VEC_replace (int, inf->syscalls_counts, iter, ++elem);
6082 target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6083 inf->total_syscalls_count != 0,
6084 inf->any_syscall_count,
6085 VEC_length (int, inf->syscalls_counts),
6086 VEC_address (int, inf->syscalls_counts));
6089 /* Implement the "remove" breakpoint_ops method for syscall
6093 remove_catch_syscall (struct breakpoint *b)
6095 struct inferior *inf = current_inferior ();
6097 --inf->total_syscalls_count;
6098 if (!b->syscalls_to_be_caught)
6099 --inf->any_syscall_count;
6105 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6109 if (iter >= VEC_length (int, inf->syscalls_counts))
6110 /* Shouldn't happen. */
6112 elem = VEC_index (int, inf->syscalls_counts, iter);
6113 VEC_replace (int, inf->syscalls_counts, iter, --elem);
6117 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
6118 inf->total_syscalls_count != 0,
6119 inf->any_syscall_count,
6120 VEC_length (int, inf->syscalls_counts),
6121 VEC_address (int, inf->syscalls_counts));
6124 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6128 breakpoint_hit_catch_syscall (struct breakpoint *b)
6130 /* We must check if we are catching specific syscalls in this breakpoint.
6131 If we are, then we must guarantee that the called syscall is the same
6132 syscall we are catching. */
6133 int syscall_number = 0;
6135 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number))
6138 /* Now, checking if the syscall is the same. */
6139 if (b->syscalls_to_be_caught)
6144 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6146 if (syscall_number == iter)
6156 /* Implement the "print_it" breakpoint_ops method for syscall
6159 static enum print_stop_action
6160 print_it_catch_syscall (struct breakpoint *b)
6162 /* These are needed because we want to know in which state a
6163 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6164 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6165 must print "called syscall" or "returned from syscall". */
6167 struct target_waitstatus last;
6169 struct cleanup *old_chain;
6172 get_last_target_status (&ptid, &last);
6174 get_syscall_by_number (last.value.syscall_number, &s);
6176 annotate_catchpoint (b->number);
6179 syscall_id = xstrprintf ("%d", last.value.syscall_number);
6181 syscall_id = xstrprintf ("'%s'", s.name);
6183 old_chain = make_cleanup (xfree, syscall_id);
6185 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
6186 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6187 b->number, syscall_id);
6188 else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
6189 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6190 b->number, syscall_id);
6192 do_cleanups (old_chain);
6194 return PRINT_SRC_AND_LOC;
6197 /* Implement the "print_one" breakpoint_ops method for syscall
6201 print_one_catch_syscall (struct breakpoint *b,
6202 struct bp_location **last_loc)
6204 struct value_print_options opts;
6206 get_user_print_options (&opts);
6207 /* Field 4, the address, is omitted (which makes the columns
6208 not line up too nicely with the headers, but the effect
6209 is relatively readable). */
6210 if (opts.addressprint)
6211 ui_out_field_skip (uiout, "addr");
6214 if (b->syscalls_to_be_caught
6215 && VEC_length (int, b->syscalls_to_be_caught) > 1)
6216 ui_out_text (uiout, "syscalls \"");
6218 ui_out_text (uiout, "syscall \"");
6220 if (b->syscalls_to_be_caught)
6223 char *text = xstrprintf ("%s", "");
6226 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6231 get_syscall_by_number (iter, &s);
6234 text = xstrprintf ("%s%s, ", text, s.name);
6236 text = xstrprintf ("%s%d, ", text, iter);
6238 /* We have to xfree the last 'text' (now stored at 'x')
6239 because xstrprintf dinamically allocates new space for it
6243 /* Remove the last comma. */
6244 text[strlen (text) - 2] = '\0';
6245 ui_out_field_string (uiout, "what", text);
6248 ui_out_field_string (uiout, "what", "<any syscall>");
6249 ui_out_text (uiout, "\" ");
6252 /* Implement the "print_mention" breakpoint_ops method for syscall
6256 print_mention_catch_syscall (struct breakpoint *b)
6258 if (b->syscalls_to_be_caught)
6262 if (VEC_length (int, b->syscalls_to_be_caught) > 1)
6263 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
6265 printf_filtered (_("Catchpoint %d (syscall"), b->number);
6268 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6272 get_syscall_by_number (iter, &s);
6275 printf_filtered (" '%s' [%d]", s.name, s.number);
6277 printf_filtered (" %d", s.number);
6279 printf_filtered (")");
6282 printf_filtered (_("Catchpoint %d (any syscall)"),
6286 /* Implement the "print_recreate" breakpoint_ops method for syscall
6290 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
6292 fprintf_unfiltered (fp, "catch syscall");
6294 if (b->syscalls_to_be_caught)
6299 VEC_iterate (int, b->syscalls_to_be_caught, i, iter);
6304 get_syscall_by_number (iter, &s);
6306 fprintf_unfiltered (fp, " %s", s.name);
6308 fprintf_unfiltered (fp, " %d", s.number);
6313 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6315 static struct breakpoint_ops catch_syscall_breakpoint_ops =
6317 insert_catch_syscall,
6318 remove_catch_syscall,
6319 breakpoint_hit_catch_syscall,
6320 print_it_catch_syscall,
6321 print_one_catch_syscall,
6322 print_mention_catch_syscall,
6323 print_recreate_catch_syscall
6326 /* Returns non-zero if 'b' is a syscall catchpoint. */
6329 syscall_catchpoint_p (struct breakpoint *b)
6331 return (b->ops == &catch_syscall_breakpoint_ops);
6334 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6335 but does NOT mention it nor update the global location list.
6336 This is useful if you need to fill more fields in the
6337 struct breakpoint before calling mention.
6339 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6340 If COND_STRING is not NULL, then store it in the breakpoint.
6341 OPS, if not NULL, is the breakpoint_ops structure associated
6342 to the catchpoint. */
6344 static struct breakpoint *
6345 create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
6347 struct breakpoint_ops *ops)
6349 struct symtab_and_line sal;
6350 struct breakpoint *b;
6353 sal.pspace = current_program_space;
6355 b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
6356 set_breakpoint_count (breakpoint_count + 1);
6357 b->number = breakpoint_count;
6359 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
6361 b->addr_string = NULL;
6362 b->enable_state = bp_enabled;
6363 b->disposition = tempflag ? disp_del : disp_donttouch;
6369 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6371 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6372 If COND_STRING is not NULL, then store it in the breakpoint.
6373 OPS, if not NULL, is the breakpoint_ops structure associated
6374 to the catchpoint. */
6376 static struct breakpoint *
6377 create_catchpoint (struct gdbarch *gdbarch, int tempflag,
6378 char *cond_string, struct breakpoint_ops *ops)
6380 struct breakpoint *b =
6381 create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops);
6384 update_global_location_list (1);
6390 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
6391 int tempflag, char *cond_string,
6392 struct breakpoint_ops *ops)
6394 struct breakpoint *b
6395 = create_catchpoint (gdbarch, tempflag, cond_string, ops);
6397 /* FIXME: We should put this information in a breakpoint private data
6399 b->forked_inferior_pid = null_ptid;
6402 /* Exec catchpoints. */
6405 insert_catch_exec (struct breakpoint *b)
6407 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
6411 remove_catch_exec (struct breakpoint *b)
6413 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
6417 breakpoint_hit_catch_exec (struct breakpoint *b)
6419 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
6422 static enum print_stop_action
6423 print_it_catch_exec (struct breakpoint *b)
6425 annotate_catchpoint (b->number);
6426 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
6428 return PRINT_SRC_AND_LOC;
6432 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
6434 struct value_print_options opts;
6436 get_user_print_options (&opts);
6438 /* Field 4, the address, is omitted (which makes the columns
6439 not line up too nicely with the headers, but the effect
6440 is relatively readable). */
6441 if (opts.addressprint)
6442 ui_out_field_skip (uiout, "addr");
6444 ui_out_text (uiout, "exec");
6445 if (b->exec_pathname != NULL)
6447 ui_out_text (uiout, ", program \"");
6448 ui_out_field_string (uiout, "what", b->exec_pathname);
6449 ui_out_text (uiout, "\" ");
6454 print_mention_catch_exec (struct breakpoint *b)
6456 printf_filtered (_("Catchpoint %d (exec)"), b->number);
6459 /* Implement the "print_recreate" breakpoint_ops method for exec
6463 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
6465 fprintf_unfiltered (fp, "catch exec");
6468 static struct breakpoint_ops catch_exec_breakpoint_ops =
6472 breakpoint_hit_catch_exec,
6473 print_it_catch_exec,
6474 print_one_catch_exec,
6475 print_mention_catch_exec,
6476 print_recreate_catch_exec
6480 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
6481 struct breakpoint_ops *ops)
6483 struct gdbarch *gdbarch = get_current_arch ();
6484 struct breakpoint *b =
6485 create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops);
6487 b->syscalls_to_be_caught = filter;
6489 /* Now, we have to mention the breakpoint and update the global
6492 update_global_location_list (1);
6496 hw_breakpoint_used_count (void)
6498 struct breakpoint *b;
6503 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
6511 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
6513 struct breakpoint *b;
6516 *other_type_used = 0;
6519 if (breakpoint_enabled (b))
6521 if (b->type == type)
6523 else if (is_hardware_watchpoint (b))
6524 *other_type_used = 1;
6531 disable_watchpoints_before_interactive_call_start (void)
6533 struct breakpoint *b;
6537 if (is_watchpoint (b) && breakpoint_enabled (b))
6539 b->enable_state = bp_call_disabled;
6540 update_global_location_list (0);
6546 enable_watchpoints_after_interactive_call_stop (void)
6548 struct breakpoint *b;
6552 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
6554 b->enable_state = bp_enabled;
6555 update_global_location_list (1);
6561 disable_breakpoints_before_startup (void)
6563 struct breakpoint *b;
6568 if (b->pspace != current_program_space)
6571 if ((b->type == bp_breakpoint
6572 || b->type == bp_hardware_breakpoint)
6573 && breakpoint_enabled (b))
6575 b->enable_state = bp_startup_disabled;
6581 update_global_location_list (0);
6583 current_program_space->executing_startup = 1;
6587 enable_breakpoints_after_startup (void)
6589 struct breakpoint *b;
6592 current_program_space->executing_startup = 0;
6596 if (b->pspace != current_program_space)
6599 if ((b->type == bp_breakpoint
6600 || b->type == bp_hardware_breakpoint)
6601 && b->enable_state == bp_startup_disabled)
6603 b->enable_state = bp_enabled;
6609 breakpoint_re_set ();
6613 /* Set a breakpoint that will evaporate an end of command
6614 at address specified by SAL.
6615 Restrict it to frame FRAME if FRAME is nonzero. */
6618 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
6619 struct frame_id frame_id, enum bptype type)
6621 struct breakpoint *b;
6623 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6625 gdb_assert (!frame_id_inlined_p (frame_id));
6627 b = set_raw_breakpoint (gdbarch, sal, type);
6628 b->enable_state = bp_enabled;
6629 b->disposition = disp_donttouch;
6630 b->frame_id = frame_id;
6632 /* If we're debugging a multi-threaded program, then we
6633 want momentary breakpoints to be active in only a
6634 single thread of control. */
6635 if (in_thread_list (inferior_ptid))
6636 b->thread = pid_to_thread_id (inferior_ptid);
6638 update_global_location_list_nothrow (1);
6643 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6647 clone_momentary_breakpoint (struct breakpoint *orig)
6649 struct breakpoint *copy;
6651 /* If there's nothing to clone, then return nothing. */
6655 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
6656 copy->loc = allocate_bp_location (copy);
6657 set_breakpoint_location_function (copy->loc);
6659 copy->loc->gdbarch = orig->loc->gdbarch;
6660 copy->loc->requested_address = orig->loc->requested_address;
6661 copy->loc->address = orig->loc->address;
6662 copy->loc->section = orig->loc->section;
6663 copy->loc->pspace = orig->loc->pspace;
6665 if (orig->source_file == NULL)
6666 copy->source_file = NULL;
6668 copy->source_file = xstrdup (orig->source_file);
6670 copy->line_number = orig->line_number;
6671 copy->frame_id = orig->frame_id;
6672 copy->thread = orig->thread;
6673 copy->pspace = orig->pspace;
6675 copy->enable_state = bp_enabled;
6676 copy->disposition = disp_donttouch;
6677 copy->number = internal_breakpoint_number--;
6679 update_global_location_list_nothrow (0);
6684 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
6687 struct symtab_and_line sal;
6689 sal = find_pc_line (pc, 0);
6691 sal.section = find_pc_overlay (pc);
6692 sal.explicit_pc = 1;
6694 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
6698 /* Tell the user we have just set a breakpoint B. */
6701 mention (struct breakpoint *b)
6704 struct cleanup *ui_out_chain;
6705 struct value_print_options opts;
6707 get_user_print_options (&opts);
6709 /* FIXME: This is misplaced; mention() is called by things (like
6710 hitting a watchpoint) other than breakpoint creation. It should
6711 be possible to clean this up and at the same time replace the
6712 random calls to breakpoint_changed with this hook. */
6713 observer_notify_breakpoint_created (b->number);
6715 if (b->ops != NULL && b->ops->print_mention != NULL)
6716 b->ops->print_mention (b);
6721 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
6724 ui_out_text (uiout, "Watchpoint ");
6725 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6726 ui_out_field_int (uiout, "number", b->number);
6727 ui_out_text (uiout, ": ");
6728 ui_out_field_string (uiout, "exp", b->exp_string);
6729 do_cleanups (ui_out_chain);
6731 case bp_hardware_watchpoint:
6732 ui_out_text (uiout, "Hardware watchpoint ");
6733 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
6734 ui_out_field_int (uiout, "number", b->number);
6735 ui_out_text (uiout, ": ");
6736 ui_out_field_string (uiout, "exp", b->exp_string);
6737 do_cleanups (ui_out_chain);
6739 case bp_read_watchpoint:
6740 ui_out_text (uiout, "Hardware read watchpoint ");
6741 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
6742 ui_out_field_int (uiout, "number", b->number);
6743 ui_out_text (uiout, ": ");
6744 ui_out_field_string (uiout, "exp", b->exp_string);
6745 do_cleanups (ui_out_chain);
6747 case bp_access_watchpoint:
6748 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
6749 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
6750 ui_out_field_int (uiout, "number", b->number);
6751 ui_out_text (uiout, ": ");
6752 ui_out_field_string (uiout, "exp", b->exp_string);
6753 do_cleanups (ui_out_chain);
6756 if (ui_out_is_mi_like_p (uiout))
6761 if (b->disposition == disp_del)
6762 printf_filtered (_("Temporary breakpoint"));
6764 printf_filtered (_("Breakpoint"));
6765 printf_filtered (_(" %d"), b->number);
6768 case bp_hardware_breakpoint:
6769 if (ui_out_is_mi_like_p (uiout))
6774 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
6778 if (ui_out_is_mi_like_p (uiout))
6783 printf_filtered (_("Tracepoint"));
6784 printf_filtered (_(" %d"), b->number);
6787 case bp_fast_tracepoint:
6788 if (ui_out_is_mi_like_p (uiout))
6793 printf_filtered (_("Fast tracepoint"));
6794 printf_filtered (_(" %d"), b->number);
6797 case bp_static_tracepoint:
6798 if (ui_out_is_mi_like_p (uiout))
6803 printf_filtered (_("Static tracepoint"));
6804 printf_filtered (_(" %d"), b->number);
6811 case bp_longjmp_resume:
6812 case bp_step_resume:
6814 case bp_std_terminate:
6815 case bp_watchpoint_scope:
6816 case bp_shlib_event:
6817 case bp_thread_event:
6818 case bp_overlay_event:
6820 case bp_longjmp_master:
6821 case bp_std_terminate_master:
6827 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6831 printf_filtered (_(" (%s) pending."), b->addr_string);
6835 if (opts.addressprint || b->source_file == NULL)
6837 printf_filtered (" at ");
6838 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
6842 printf_filtered (": file %s, line %d.",
6843 b->source_file, b->line_number);
6847 struct bp_location *loc = b->loc;
6849 for (; loc; loc = loc->next)
6851 printf_filtered (" (%d locations)", n);
6856 if (ui_out_is_mi_like_p (uiout))
6858 printf_filtered ("\n");
6862 static struct bp_location *
6863 add_location_to_breakpoint (struct breakpoint *b,
6864 const struct symtab_and_line *sal)
6866 struct bp_location *loc, **tmp;
6868 loc = allocate_bp_location (b);
6869 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
6872 loc->gdbarch = get_sal_arch (*sal);
6874 loc->gdbarch = b->gdbarch;
6875 loc->requested_address = sal->pc;
6876 loc->address = adjust_breakpoint_address (loc->gdbarch,
6877 loc->requested_address, b->type);
6878 loc->pspace = sal->pspace;
6879 gdb_assert (loc->pspace != NULL);
6880 loc->section = sal->section;
6882 set_breakpoint_location_function (loc);
6887 /* Return 1 if LOC is pointing to a permanent breakpoint,
6888 return 0 otherwise. */
6891 bp_loc_is_permanent (struct bp_location *loc)
6895 const gdb_byte *brk;
6896 gdb_byte *target_mem;
6897 struct cleanup *cleanup;
6900 gdb_assert (loc != NULL);
6902 addr = loc->address;
6903 brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
6905 /* Software breakpoints unsupported? */
6909 target_mem = alloca (len);
6911 /* Enable the automatic memory restoration from breakpoints while
6912 we read the memory. Otherwise we could say about our temporary
6913 breakpoints they are permanent. */
6914 cleanup = save_current_space_and_thread ();
6916 switch_to_program_space_and_thread (loc->pspace);
6917 make_show_memory_breakpoints_cleanup (0);
6919 if (target_read_memory (loc->address, target_mem, len) == 0
6920 && memcmp (target_mem, brk, len) == 0)
6923 do_cleanups (cleanup);
6930 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6931 as textual description of the location, and COND_STRING
6932 as condition expression. */
6935 create_breakpoint_sal (struct gdbarch *gdbarch,
6936 struct symtabs_and_lines sals, char *addr_string,
6938 enum bptype type, enum bpdisp disposition,
6939 int thread, int task, int ignore_count,
6940 struct breakpoint_ops *ops, int from_tty, int enabled)
6942 struct breakpoint *b = NULL;
6945 if (type == bp_hardware_breakpoint)
6947 int i = hw_breakpoint_used_count ();
6948 int target_resources_ok =
6949 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
6951 if (target_resources_ok == 0)
6952 error (_("No hardware breakpoint support in the target."));
6953 else if (target_resources_ok < 0)
6954 error (_("Hardware breakpoints used exceeds limit."));
6957 gdb_assert (sals.nelts > 0);
6959 for (i = 0; i < sals.nelts; ++i)
6961 struct symtab_and_line sal = sals.sals[i];
6962 struct bp_location *loc;
6966 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
6968 loc_gdbarch = gdbarch;
6970 describe_other_breakpoints (loc_gdbarch,
6971 sal.pspace, sal.pc, sal.section, thread);
6976 b = set_raw_breakpoint (gdbarch, sal, type);
6977 set_breakpoint_count (breakpoint_count + 1);
6978 b->number = breakpoint_count;
6982 b->cond_string = cond_string;
6983 b->ignore_count = ignore_count;
6984 b->enable_state = enabled ? bp_enabled : bp_disabled;
6985 b->disposition = disposition;
6986 b->pspace = sals.sals[0].pspace;
6988 if (type == bp_static_tracepoint)
6990 struct static_tracepoint_marker marker;
6992 if (is_marker_spec (addr_string))
6994 /* We already know the marker exists, otherwise, we
6995 wouldn't see a sal for it. */
6996 char *p = &addr_string[3];
7001 while (*p == ' ' || *p == '\t')
7005 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7008 marker_str = savestring (p, endp - p);
7009 b->static_trace_marker_id = marker_str;
7011 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7012 b->static_trace_marker_id);
7014 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
7016 b->static_trace_marker_id = xstrdup (marker.str_id);
7017 release_static_tracepoint_marker (&marker);
7019 printf_filtered (_("Probed static tracepoint marker \"%s\"\n"),
7020 b->static_trace_marker_id);
7024 Couldn't determine the static tracepoint marker to probe"));
7027 if (enabled && b->pspace->executing_startup
7028 && (b->type == bp_breakpoint
7029 || b->type == bp_hardware_breakpoint))
7030 b->enable_state = bp_startup_disabled;
7036 loc = add_location_to_breakpoint (b, &sal);
7039 if (bp_loc_is_permanent (loc))
7040 make_breakpoint_permanent (b);
7044 char *arg = b->cond_string;
7045 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
7047 error (_("Garbage %s follows condition"), arg);
7052 b->addr_string = addr_string;
7054 /* addr_string has to be used or breakpoint_re_set will delete
7057 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7063 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7064 elements to fill the void space. */
7066 remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
7068 int i = index_to_remove+1;
7069 int last_index = sal->nelts-1;
7071 for (;i <= last_index; ++i)
7072 sal->sals[i-1] = sal->sals[i];
7077 /* If appropriate, obtains all sals that correspond to the same file
7078 and line as SAL, in all program spaces. Users debugging with IDEs,
7079 will want to set a breakpoint at foo.c:line, and not really care
7080 about program spaces. This is done only if SAL does not have
7081 explicit PC and has line and file information. If we got just a
7082 single expanded sal, return the original.
7084 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7085 which the name of enclosing function is different from SAL. This
7086 makes sure that if we have breakpoint originally set in template
7087 instantiation, say foo<int>(), we won't expand SAL to locations at
7088 the same line in all existing instantiations of 'foo'. */
7090 static struct symtabs_and_lines
7091 expand_line_sal_maybe (struct symtab_and_line sal)
7093 struct symtabs_and_lines expanded;
7094 CORE_ADDR original_pc = sal.pc;
7095 char *original_function = NULL;
7098 struct cleanup *old_chain;
7100 /* If we have explicit pc, don't expand.
7101 If we have no line number, we can't expand. */
7102 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
7105 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7106 expanded.sals[0] = sal;
7112 old_chain = save_current_space_and_thread ();
7114 switch_to_program_space_and_thread (sal.pspace);
7116 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
7118 /* Note that expand_line_sal visits *all* program spaces. */
7119 expanded = expand_line_sal (sal);
7121 if (expanded.nelts == 1)
7123 /* We had one sal, we got one sal. Return that sal, adjusting it
7124 past the function prologue if necessary. */
7125 xfree (expanded.sals);
7127 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7128 sal.pc = original_pc;
7129 expanded.sals[0] = sal;
7130 skip_prologue_sal (&expanded.sals[0]);
7131 do_cleanups (old_chain);
7135 if (!sal.explicit_line)
7137 CORE_ADDR func_addr, func_end;
7138 for (i = 0; i < expanded.nelts; ++i)
7140 CORE_ADDR pc = expanded.sals[i].pc;
7141 char *this_function;
7143 /* We need to switch threads as well since we're about to
7145 switch_to_program_space_and_thread (expanded.sals[i].pspace);
7147 if (find_pc_partial_function (pc, &this_function,
7148 &func_addr, &func_end))
7151 && strcmp (this_function, original_function) != 0)
7153 remove_sal (&expanded, i);
7160 /* Skip the function prologue if necessary. */
7161 for (i = 0; i < expanded.nelts; ++i)
7162 skip_prologue_sal (&expanded.sals[i]);
7164 do_cleanups (old_chain);
7166 if (expanded.nelts <= 1)
7168 /* This is un ugly workaround. If we get zero
7169 expanded sals then something is really wrong.
7170 Fix that by returnign the original sal. */
7171 xfree (expanded.sals);
7173 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7174 sal.pc = original_pc;
7175 expanded.sals[0] = sal;
7182 for (i = 0; i < expanded.nelts; ++i)
7183 if (expanded.sals[i].pc == original_pc)
7194 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7195 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7196 value. COND_STRING, if not NULL, specified the condition to be
7197 used for all breakpoints. Essentially the only case where
7198 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7199 function. In that case, it's still not possible to specify
7200 separate conditions for different overloaded functions, so
7201 we take just a single condition string.
7203 NOTE: If the function succeeds, the caller is expected to cleanup
7204 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7205 array contents). If the function fails (error() is called), the
7206 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7207 COND and SALS arrays and each of those arrays contents. */
7210 create_breakpoints_sal (struct gdbarch *gdbarch,
7211 struct symtabs_and_lines sals, char **addr_string,
7213 enum bptype type, enum bpdisp disposition,
7214 int thread, int task, int ignore_count,
7215 struct breakpoint_ops *ops, int from_tty,
7220 for (i = 0; i < sals.nelts; ++i)
7222 struct symtabs_and_lines expanded =
7223 expand_line_sal_maybe (sals.sals[i]);
7225 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7226 cond_string, type, disposition,
7227 thread, task, ignore_count, ops, from_tty, enabled);
7231 /* Parse ARG which is assumed to be a SAL specification possibly
7232 followed by conditionals. On return, SALS contains an array of SAL
7233 addresses found. ADDR_STRING contains a vector of (canonical)
7234 address strings. ARG points to the end of the SAL. */
7237 parse_breakpoint_sals (char **address,
7238 struct symtabs_and_lines *sals,
7239 char ***addr_string,
7242 char *addr_start = *address;
7244 *addr_string = NULL;
7245 /* If no arg given, or if first arg is 'if ', use the default
7247 if ((*address) == NULL
7248 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
7250 if (default_breakpoint_valid)
7252 struct symtab_and_line sal;
7254 init_sal (&sal); /* initialize to zeroes */
7255 sals->sals = (struct symtab_and_line *)
7256 xmalloc (sizeof (struct symtab_and_line));
7257 sal.pc = default_breakpoint_address;
7258 sal.line = default_breakpoint_line;
7259 sal.symtab = default_breakpoint_symtab;
7260 sal.pspace = default_breakpoint_pspace;
7261 sal.section = find_pc_overlay (sal.pc);
7263 /* "break" without arguments is equivalent to "break *PC" where PC is
7264 the default_breakpoint_address. So make sure to set
7265 sal.explicit_pc to prevent GDB from trying to expand the list of
7266 sals to include all other instances with the same symtab and line.
7268 sal.explicit_pc = 1;
7270 sals->sals[0] = sal;
7274 error (_("No default breakpoint address now."));
7278 /* Force almost all breakpoints to be in terms of the
7279 current_source_symtab (which is decode_line_1's default). This
7280 should produce the results we want almost all of the time while
7281 leaving default_breakpoint_* alone.
7282 ObjC: However, don't match an Objective-C method name which
7283 may have a '+' or '-' succeeded by a '[' */
7285 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
7287 if (default_breakpoint_valid
7289 || ((strchr ("+-", (*address)[0]) != NULL)
7290 && ((*address)[1] != '['))))
7291 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
7292 default_breakpoint_line, addr_string,
7295 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
7296 addr_string, not_found_ptr);
7298 /* For any SAL that didn't have a canonical string, fill one in. */
7299 if (sals->nelts > 0 && *addr_string == NULL)
7300 *addr_string = xcalloc (sals->nelts, sizeof (char **));
7301 if (addr_start != (*address))
7305 for (i = 0; i < sals->nelts; i++)
7307 /* Add the string if not present. */
7308 if ((*addr_string)[i] == NULL)
7309 (*addr_string)[i] = savestring (addr_start,
7310 (*address) - addr_start);
7316 /* Convert each SAL into a real PC. Verify that the PC can be
7317 inserted as a breakpoint. If it can't throw an error. */
7320 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
7324 for (i = 0; i < sals->nelts; i++)
7325 resolve_sal_pc (&sals->sals[i]);
7328 /* Fast tracepoints may have restrictions on valid locations. For
7329 instance, a fast tracepoint using a jump instead of a trap will
7330 likely have to overwrite more bytes than a trap would, and so can
7331 only be placed where the instruction is longer than the jump, or a
7332 multi-instruction sequence does not have a jump into the middle of
7336 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
7337 struct symtabs_and_lines *sals)
7340 struct symtab_and_line *sal;
7342 struct cleanup *old_chain;
7344 for (i = 0; i < sals->nelts; i++)
7346 sal = &sals->sals[i];
7348 rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc,
7350 old_chain = make_cleanup (xfree, msg);
7353 error (_("May not have a fast tracepoint at 0x%s%s"),
7354 paddress (gdbarch, sal->pc), (msg ? msg : ""));
7356 do_cleanups (old_chain);
7361 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
7363 struct captured_parse_breakpoint_args *args = data;
7365 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
7366 args->not_found_ptr);
7369 /* Given TOK, a string specification of condition and thread, as
7370 accepted by the 'break' command, extract the condition
7371 string and thread number and set *COND_STRING and *THREAD.
7372 PC identifies the context at which the condition should be parsed.
7373 If no condition is found, *COND_STRING is set to NULL.
7374 If no thread is found, *THREAD is set to -1. */
7376 find_condition_and_thread (char *tok, CORE_ADDR pc,
7377 char **cond_string, int *thread, int *task)
7379 *cond_string = NULL;
7385 char *cond_start = NULL;
7386 char *cond_end = NULL;
7388 while (*tok == ' ' || *tok == '\t')
7393 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
7396 toklen = end_tok - tok;
7398 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
7400 struct expression *expr;
7402 tok = cond_start = end_tok + 1;
7403 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
7406 *cond_string = savestring (cond_start,
7407 cond_end - cond_start);
7409 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
7415 *thread = strtol (tok, &tok, 0);
7417 error (_("Junk after thread keyword."));
7418 if (!valid_thread_id (*thread))
7419 error (_("Unknown thread %d."), *thread);
7421 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
7427 *task = strtol (tok, &tok, 0);
7429 error (_("Junk after task keyword."));
7430 if (!valid_task_id (*task))
7431 error (_("Unknown task %d."), *task);
7434 error (_("Junk at end of arguments."));
7438 /* Decode a static tracepoint marker spec. */
7440 static struct symtabs_and_lines
7441 decode_static_tracepoint_spec (char **arg_p)
7443 VEC(static_tracepoint_marker_p) *markers = NULL;
7444 struct symtabs_and_lines sals;
7445 struct symtab_and_line sal;
7447 struct cleanup *old_chain;
7448 char *p = &(*arg_p)[3];
7453 while (*p == ' ' || *p == '\t')
7457 while (*endp != ' ' && *endp != '\t' && *endp != '\0')
7460 marker_str = savestring (p, endp - p);
7461 old_chain = make_cleanup (xfree, marker_str);
7463 markers = target_static_tracepoint_markers_by_strid (marker_str);
7464 if (VEC_empty(static_tracepoint_marker_p, markers))
7465 error (_("No known static tracepoint marker named %s"), marker_str);
7467 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
7468 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
7470 for (i = 0; i < sals.nelts; i++)
7472 struct static_tracepoint_marker *marker;
7474 marker = VEC_index (static_tracepoint_marker_p, markers, i);
7476 init_sal (&sals.sals[i]);
7478 sals.sals[i] = find_pc_line (marker->address, 0);
7479 sals.sals[i].pc = marker->address;
7481 release_static_tracepoint_marker (marker);
7484 do_cleanups (old_chain);
7490 /* Set a breakpoint. This function is shared between CLI and MI
7491 functions for setting a breakpoint. This function has two major
7492 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7493 parameter. If non-zero, the function will parse arg, extracting
7494 breakpoint location, address and thread. Otherwise, ARG is just the
7495 location of breakpoint, with condition and thread specified by the
7496 COND_STRING and THREAD parameters. Returns true if any breakpoint
7497 was created; false otherwise. */
7500 create_breakpoint (struct gdbarch *gdbarch,
7501 char *arg, char *cond_string, int thread,
7502 int parse_condition_and_thread,
7503 int tempflag, enum bptype type_wanted,
7505 enum auto_boolean pending_break_support,
7506 struct breakpoint_ops *ops,
7510 struct gdb_exception e;
7511 struct symtabs_and_lines sals;
7512 struct symtab_and_line pending_sal;
7514 char *addr_start = arg;
7516 struct cleanup *old_chain;
7517 struct cleanup *bkpt_chain = NULL;
7518 struct captured_parse_breakpoint_args parse_args;
7523 int prev_bkpt_count = breakpoint_count;
7529 parse_args.arg_p = &arg;
7530 parse_args.sals_p = &sals;
7531 parse_args.addr_string_p = &addr_string;
7532 parse_args.not_found_ptr = ¬_found;
7534 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
7538 sals = decode_static_tracepoint_spec (&arg);
7540 copy_arg = savestring (addr_start, arg - addr_start);
7541 addr_string = xcalloc (sals.nelts, sizeof (char **));
7542 for (i = 0; i < sals.nelts; i++)
7543 addr_string[i] = xstrdup (copy_arg);
7547 e = catch_exception (uiout, do_captured_parse_breakpoint,
7548 &parse_args, RETURN_MASK_ALL);
7550 /* If caller is interested in rc value from parse, set value. */
7554 throw_exception (e);
7558 case NOT_FOUND_ERROR:
7560 /* If pending breakpoint support is turned off, throw
7563 if (pending_break_support == AUTO_BOOLEAN_FALSE)
7564 throw_exception (e);
7566 exception_print (gdb_stderr, e);
7568 /* If pending breakpoint support is auto query and the user
7569 selects no, then simply return the error code. */
7570 if (pending_break_support == AUTO_BOOLEAN_AUTO
7571 && !nquery ("Make breakpoint pending on future shared library load? "))
7574 /* At this point, either the user was queried about setting
7575 a pending breakpoint and selected yes, or pending
7576 breakpoint behavior is on and thus a pending breakpoint
7577 is defaulted on behalf of the user. */
7578 copy_arg = xstrdup (addr_start);
7579 addr_string = ©_arg;
7581 sals.sals = &pending_sal;
7586 throw_exception (e);
7595 /* Create a chain of things that always need to be cleaned up. */
7596 old_chain = make_cleanup (null_cleanup, 0);
7600 /* Make sure that all storage allocated to SALS gets freed. */
7601 make_cleanup (xfree, sals.sals);
7603 /* Cleanup the addr_string array but not its contents. */
7604 make_cleanup (xfree, addr_string);
7607 /* ----------------------------- SNIP -----------------------------
7608 Anything added to the cleanup chain beyond this point is assumed
7609 to be part of a breakpoint. If the breakpoint create succeeds
7610 then the memory is not reclaimed. */
7611 bkpt_chain = make_cleanup (null_cleanup, 0);
7613 /* Mark the contents of the addr_string for cleanup. These go on
7614 the bkpt_chain and only occur if the breakpoint create fails. */
7615 for (i = 0; i < sals.nelts; i++)
7617 if (addr_string[i] != NULL)
7618 make_cleanup (xfree, addr_string[i]);
7621 /* Resolve all line numbers to PC's and verify that the addresses
7622 are ok for the target. */
7624 breakpoint_sals_to_pc (&sals);
7626 /* Fast tracepoints may have additional restrictions on location. */
7627 if (type_wanted == bp_fast_tracepoint)
7628 check_fast_tracepoint_sals (gdbarch, &sals);
7630 /* Verify that condition can be parsed, before setting any
7631 breakpoints. Allocate a separate condition expression for each
7635 if (parse_condition_and_thread)
7637 /* Here we only parse 'arg' to separate condition
7638 from thread number, so parsing in context of first
7639 sal is OK. When setting the breakpoint we'll
7640 re-parse it in context of each sal. */
7643 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
7646 make_cleanup (xfree, cond_string);
7650 /* Create a private copy of condition string. */
7653 cond_string = xstrdup (cond_string);
7654 make_cleanup (xfree, cond_string);
7658 /* If the user is creating a static tracepoint by marker id
7659 (strace -m MARKER_ID), then store the sals index, so that
7660 breakpoint_re_set can try to match up which of the newly
7661 found markers corresponds to this one, and, don't try to
7662 expand multiple locations for each sal, given than SALS
7663 already should contain all sals for MARKER_ID. */
7664 if (type_wanted == bp_static_tracepoint
7665 && is_marker_spec (addr_string[0]))
7669 for (i = 0; i < sals.nelts; ++i)
7671 struct symtabs_and_lines expanded;
7672 struct breakpoint *tp;
7673 struct cleanup *old_chain;
7676 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
7677 expanded.sals[0] = sals.sals[i];
7678 old_chain = make_cleanup (xfree, expanded.sals);
7680 create_breakpoint_sal (gdbarch, expanded, addr_string[i],
7681 cond_string, type_wanted,
7682 tempflag ? disp_del : disp_donttouch,
7683 thread, task, ignore_count, ops,
7686 do_cleanups (old_chain);
7688 /* Get the tracepoint we just created. */
7689 tp = get_breakpoint (breakpoint_count);
7690 gdb_assert (tp != NULL);
7692 /* Given that its possible to have multiple markers with
7693 the same string id, if the user is creating a static
7694 tracepoint by marker id ("strace -m MARKER_ID"), then
7695 store the sals index, so that breakpoint_re_set can
7696 try to match up which of the newly found markers
7697 corresponds to this one */
7698 tp->static_trace_marker_id_idx = i;
7702 create_breakpoints_sal (gdbarch, sals, addr_string, cond_string,
7703 type_wanted, tempflag ? disp_del : disp_donttouch,
7704 thread, task, ignore_count, ops, from_tty,
7709 struct breakpoint *b;
7711 make_cleanup (xfree, copy_arg);
7713 b = set_raw_breakpoint_without_location (gdbarch, type_wanted);
7714 set_breakpoint_count (breakpoint_count + 1);
7715 b->number = breakpoint_count;
7717 b->addr_string = addr_string[0];
7718 b->cond_string = NULL;
7719 b->ignore_count = ignore_count;
7720 b->disposition = tempflag ? disp_del : disp_donttouch;
7721 b->condition_not_parsed = 1;
7723 b->enable_state = enabled ? bp_enabled : bp_disabled;
7724 b->pspace = current_program_space;
7726 if (enabled && b->pspace->executing_startup
7727 && (b->type == bp_breakpoint
7728 || b->type == bp_hardware_breakpoint))
7729 b->enable_state = bp_startup_disabled;
7736 warning (_("Multiple breakpoints were set.\n"
7737 "Use the \"delete\" command to delete unwanted breakpoints."));
7738 prev_breakpoint_count = prev_bkpt_count;
7741 /* That's it. Discard the cleanups for data inserted into the
7743 discard_cleanups (bkpt_chain);
7744 /* But cleanup everything else. */
7745 do_cleanups (old_chain);
7747 /* error call may happen here - have BKPT_CHAIN already discarded. */
7748 update_global_location_list (1);
7753 /* Set a breakpoint.
7754 ARG is a string describing breakpoint address,
7755 condition, and thread.
7756 FLAG specifies if a breakpoint is hardware on,
7757 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7761 break_command_1 (char *arg, int flag, int from_tty)
7763 int tempflag = flag & BP_TEMPFLAG;
7764 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
7765 ? bp_hardware_breakpoint
7768 create_breakpoint (get_current_arch (),
7770 NULL, 0, 1 /* parse arg */,
7771 tempflag, type_wanted,
7772 0 /* Ignore count */,
7773 pending_break_support,
7774 NULL /* breakpoint_ops */,
7780 /* Helper function for break_command_1 and disassemble_command. */
7783 resolve_sal_pc (struct symtab_and_line *sal)
7787 if (sal->pc == 0 && sal->symtab != NULL)
7789 if (!find_line_pc (sal->symtab, sal->line, &pc))
7790 error (_("No line %d in file \"%s\"."),
7791 sal->line, sal->symtab->filename);
7794 /* If this SAL corresponds to a breakpoint inserted using
7795 a line number, then skip the function prologue if necessary. */
7796 if (sal->explicit_line)
7797 skip_prologue_sal (sal);
7800 if (sal->section == 0 && sal->symtab != NULL)
7802 struct blockvector *bv;
7806 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
7809 sym = block_linkage_function (b);
7812 fixup_symbol_section (sym, sal->symtab->objfile);
7813 sal->section = SYMBOL_OBJ_SECTION (sym);
7817 /* It really is worthwhile to have the section, so we'll just
7818 have to look harder. This case can be executed if we have
7819 line numbers but no functions (as can happen in assembly
7822 struct minimal_symbol *msym;
7823 struct cleanup *old_chain = save_current_space_and_thread ();
7825 switch_to_program_space_and_thread (sal->pspace);
7827 msym = lookup_minimal_symbol_by_pc (sal->pc);
7829 sal->section = SYMBOL_OBJ_SECTION (msym);
7831 do_cleanups (old_chain);
7838 break_command (char *arg, int from_tty)
7840 break_command_1 (arg, 0, from_tty);
7844 tbreak_command (char *arg, int from_tty)
7846 break_command_1 (arg, BP_TEMPFLAG, from_tty);
7850 hbreak_command (char *arg, int from_tty)
7852 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
7856 thbreak_command (char *arg, int from_tty)
7858 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
7862 stop_command (char *arg, int from_tty)
7864 printf_filtered (_("Specify the type of breakpoint to set.\n\
7865 Usage: stop in <function | address>\n\
7866 stop at <line>\n"));
7870 stopin_command (char *arg, int from_tty)
7874 if (arg == (char *) NULL)
7876 else if (*arg != '*')
7881 /* look for a ':'. If this is a line number specification, then
7882 say it is bad, otherwise, it should be an address or
7883 function/method name */
7884 while (*argptr && !hasColon)
7886 hasColon = (*argptr == ':');
7891 badInput = (*argptr != ':'); /* Not a class::method */
7893 badInput = isdigit (*arg); /* a simple line number */
7897 printf_filtered (_("Usage: stop in <function | address>\n"));
7899 break_command_1 (arg, 0, from_tty);
7903 stopat_command (char *arg, int from_tty)
7907 if (arg == (char *) NULL || *arg == '*') /* no line number */
7914 /* look for a ':'. If there is a '::' then get out, otherwise
7915 it is probably a line number. */
7916 while (*argptr && !hasColon)
7918 hasColon = (*argptr == ':');
7923 badInput = (*argptr == ':'); /* we have class::method */
7925 badInput = !isdigit (*arg); /* not a line number */
7929 printf_filtered (_("Usage: stop at <line>\n"));
7931 break_command_1 (arg, 0, from_tty);
7934 /* Return non-zero if EXP is verified as constant. Returned zero means EXP is
7935 variable. Also the constant detection may fail for some constant
7936 expressions and in such case still falsely return zero. */
7938 watchpoint_exp_is_const (const struct expression *exp)
7946 /* We are only interested in the descriptor of each element. */
7947 operator_length (exp, i, &oplenp, &argsp);
7950 switch (exp->elts[i].opcode)
7960 case BINOP_LOGICAL_AND:
7961 case BINOP_LOGICAL_OR:
7962 case BINOP_BITWISE_AND:
7963 case BINOP_BITWISE_IOR:
7964 case BINOP_BITWISE_XOR:
7966 case BINOP_NOTEQUAL:
7982 case TERNOP_SLICE_COUNT:
7994 case OP_OBJC_NSSTRING:
7997 case UNOP_LOGICAL_NOT:
7998 case UNOP_COMPLEMENT:
8001 /* Unary, binary and ternary operators: We have to check their
8002 operands. If they are constant, then so is the result of
8003 that operation. For instance, if A and B are determined to be
8004 constants, then so is "A + B".
8006 UNOP_IND is one exception to the rule above, because the value
8007 of *ADDR is not necessarily a constant, even when ADDR is. */
8011 /* Check whether the associated symbol is a constant.
8012 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8013 possible that a buggy compiler could mark a variable as constant
8014 even when it is not, and TYPE_CONST would return true in this
8015 case, while SYMBOL_CLASS wouldn't.
8016 We also have to check for function symbols because they are
8019 struct symbol *s = exp->elts[i + 2].symbol;
8021 if (SYMBOL_CLASS (s) != LOC_BLOCK
8022 && SYMBOL_CLASS (s) != LOC_CONST
8023 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
8028 /* The default action is to return 0 because we are using
8029 the optimistic approach here: If we don't know something,
8030 then it is not a constant. */
8039 /* accessflag: hw_write: watch write,
8040 hw_read: watch read,
8041 hw_access: watch access (read or write) */
8043 watch_command_1 (char *arg, int accessflag, int from_tty)
8045 struct breakpoint *b, *scope_breakpoint = NULL;
8046 struct expression *exp;
8047 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
8048 struct value *val, *mark;
8049 struct frame_info *frame;
8050 char *exp_start = NULL;
8051 char *exp_end = NULL;
8052 char *tok, *id_tok_start, *end_tok;
8054 char *cond_start = NULL;
8055 char *cond_end = NULL;
8056 int i, other_type_used, target_resources_ok = 0;
8057 enum bptype bp_type;
8061 /* Make sure that we actually have parameters to parse. */
8062 if (arg != NULL && arg[0] != '\0')
8064 toklen = strlen (arg); /* Size of argument list. */
8066 /* Points tok to the end of the argument list. */
8067 tok = arg + toklen - 1;
8069 /* Go backwards in the parameters list. Skip the last parameter.
8070 If we're expecting a 'thread <thread_num>' parameter, this should
8071 be the thread identifier. */
8072 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8074 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8077 /* Points end_tok to the beginning of the last token. */
8078 id_tok_start = tok + 1;
8080 /* Go backwards in the parameters list. Skip one more parameter.
8081 If we're expecting a 'thread <thread_num>' parameter, we should
8082 reach a "thread" token. */
8083 while (tok > arg && (*tok == ' ' || *tok == '\t'))
8088 while (tok > arg && (*tok != ' ' && *tok != '\t'))
8091 /* Move the pointer forward to skip the whitespace and
8092 calculate the length of the token. */
8094 toklen = end_tok - tok;
8096 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8098 /* At this point we've found a "thread" token, which means
8099 the user is trying to set a watchpoint that triggers
8100 only in a specific thread. */
8103 /* Extract the thread ID from the next token. */
8104 thread = strtol (id_tok_start, &endp, 0);
8106 /* Check if the user provided a valid numeric value for the
8108 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
8109 error (_("Invalid thread ID specification %s."), id_tok_start);
8111 /* Check if the thread actually exists. */
8112 if (!valid_thread_id (thread))
8113 error (_("Unknown thread %d."), thread);
8115 /* Truncate the string and get rid of the thread <thread_num>
8116 parameter before the parameter list is parsed by the
8117 evaluate_expression() function. */
8122 /* Parse the rest of the arguments. */
8123 innermost_block = NULL;
8125 exp = parse_exp_1 (&arg, 0, 0);
8127 /* Remove trailing whitespace from the expression before saving it.
8128 This makes the eventual display of the expression string a bit
8130 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
8133 /* Checking if the expression is not constant. */
8134 if (watchpoint_exp_is_const (exp))
8138 len = exp_end - exp_start;
8139 while (len > 0 && isspace (exp_start[len - 1]))
8141 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
8144 exp_valid_block = innermost_block;
8145 mark = value_mark ();
8146 fetch_watchpoint_value (exp, &val, NULL, NULL);
8148 release_value (val);
8151 while (*tok == ' ' || *tok == '\t')
8155 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
8158 toklen = end_tok - tok;
8159 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8161 struct expression *cond;
8163 innermost_block = NULL;
8164 tok = cond_start = end_tok + 1;
8165 cond = parse_exp_1 (&tok, 0, 0);
8167 /* The watchpoint expression may not be local, but the condition
8168 may still be. E.g.: `watch global if local > 0'. */
8169 cond_exp_valid_block = innermost_block;
8175 error (_("Junk at end of command."));
8177 if (accessflag == hw_read)
8178 bp_type = bp_read_watchpoint;
8179 else if (accessflag == hw_access)
8180 bp_type = bp_access_watchpoint;
8182 bp_type = bp_hardware_watchpoint;
8184 mem_cnt = can_use_hardware_watchpoint (val);
8185 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
8186 error (_("Expression cannot be implemented with read/access watchpoint."));
8189 i = hw_watchpoint_used_count (bp_type, &other_type_used);
8190 target_resources_ok =
8191 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
8193 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8194 error (_("Target does not support this type of hardware watchpoint."));
8196 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8197 error (_("Target can only support one kind of HW watchpoint at a time."));
8200 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
8201 watchpoint could not be set. */
8202 if (!mem_cnt || target_resources_ok <= 0)
8203 bp_type = bp_watchpoint;
8205 frame = block_innermost_frame (exp_valid_block);
8207 /* If the expression is "local", then set up a "watchpoint scope"
8208 breakpoint at the point where we've left the scope of the watchpoint
8209 expression. Create the scope breakpoint before the watchpoint, so
8210 that we will encounter it first in bpstat_stop_status. */
8211 if (exp_valid_block && frame)
8213 if (frame_id_p (frame_unwind_caller_id (frame)))
8216 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
8217 frame_unwind_caller_pc (frame),
8218 bp_watchpoint_scope);
8220 scope_breakpoint->enable_state = bp_enabled;
8222 /* Automatically delete the breakpoint when it hits. */
8223 scope_breakpoint->disposition = disp_del;
8225 /* Only break in the proper frame (help with recursion). */
8226 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
8228 /* Set the address at which we will stop. */
8229 scope_breakpoint->loc->gdbarch
8230 = frame_unwind_caller_arch (frame);
8231 scope_breakpoint->loc->requested_address
8232 = frame_unwind_caller_pc (frame);
8233 scope_breakpoint->loc->address
8234 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
8235 scope_breakpoint->loc->requested_address,
8236 scope_breakpoint->type);
8240 /* Now set up the breakpoint. */
8241 b = set_raw_breakpoint_without_location (NULL, bp_type);
8242 set_breakpoint_count (breakpoint_count + 1);
8243 b->number = breakpoint_count;
8245 b->disposition = disp_donttouch;
8247 b->exp_valid_block = exp_valid_block;
8248 b->cond_exp_valid_block = cond_exp_valid_block;
8249 b->exp_string = savestring (exp_start, exp_end - exp_start);
8253 b->cond_string = savestring (cond_start, cond_end - cond_start);
8259 b->watchpoint_frame = get_frame_id (frame);
8260 b->watchpoint_thread = inferior_ptid;
8264 b->watchpoint_frame = null_frame_id;
8265 b->watchpoint_thread = null_ptid;
8268 if (scope_breakpoint != NULL)
8270 /* The scope breakpoint is related to the watchpoint. We will
8271 need to act on them together. */
8272 b->related_breakpoint = scope_breakpoint;
8273 scope_breakpoint->related_breakpoint = b;
8276 value_free_to_mark (mark);
8278 /* Finally update the new watchpoint. This creates the locations
8279 that should be inserted. */
8280 update_watchpoint (b, 1);
8283 update_global_location_list (1);
8286 /* Return count of locations need to be watched and can be handled
8287 in hardware. If the watchpoint can not be handled
8288 in hardware return zero. */
8291 can_use_hardware_watchpoint (struct value *v)
8293 int found_memory_cnt = 0;
8294 struct value *head = v;
8296 /* Did the user specifically forbid us to use hardware watchpoints? */
8297 if (!can_use_hw_watchpoints)
8300 /* Make sure that the value of the expression depends only upon
8301 memory contents, and values computed from them within GDB. If we
8302 find any register references or function calls, we can't use a
8303 hardware watchpoint.
8305 The idea here is that evaluating an expression generates a series
8306 of values, one holding the value of every subexpression. (The
8307 expression a*b+c has five subexpressions: a, b, a*b, c, and
8308 a*b+c.) GDB's values hold almost enough information to establish
8309 the criteria given above --- they identify memory lvalues,
8310 register lvalues, computed values, etcetera. So we can evaluate
8311 the expression, and then scan the chain of values that leaves
8312 behind to decide whether we can detect any possible change to the
8313 expression's final value using only hardware watchpoints.
8315 However, I don't think that the values returned by inferior
8316 function calls are special in any way. So this function may not
8317 notice that an expression involving an inferior function call
8318 can't be watched with hardware watchpoints. FIXME. */
8319 for (; v; v = value_next (v))
8321 if (VALUE_LVAL (v) == lval_memory)
8324 /* A lazy memory lvalue is one that GDB never needed to fetch;
8325 we either just used its address (e.g., `a' in `a.b') or
8326 we never needed it at all (e.g., `a' in `a,b'). */
8330 /* Ahh, memory we actually used! Check if we can cover
8331 it with hardware watchpoints. */
8332 struct type *vtype = check_typedef (value_type (v));
8334 /* We only watch structs and arrays if user asked for it
8335 explicitly, never if they just happen to appear in a
8336 middle of some value chain. */
8338 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
8339 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
8341 CORE_ADDR vaddr = value_address (v);
8342 int len = TYPE_LENGTH (value_type (v));
8344 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
8351 else if (VALUE_LVAL (v) != not_lval
8352 && deprecated_value_modifiable (v) == 0)
8353 return 0; /* ??? What does this represent? */
8354 else if (VALUE_LVAL (v) == lval_register)
8355 return 0; /* cannot watch a register with a HW watchpoint */
8358 /* The expression itself looks suitable for using a hardware
8359 watchpoint, but give the target machine a chance to reject it. */
8360 return found_memory_cnt;
8364 watch_command_wrapper (char *arg, int from_tty)
8366 watch_command (arg, from_tty);
8370 watch_command (char *arg, int from_tty)
8372 watch_command_1 (arg, hw_write, from_tty);
8376 rwatch_command_wrapper (char *arg, int from_tty)
8378 rwatch_command (arg, from_tty);
8382 rwatch_command (char *arg, int from_tty)
8384 watch_command_1 (arg, hw_read, from_tty);
8388 awatch_command_wrapper (char *arg, int from_tty)
8390 awatch_command (arg, from_tty);
8394 awatch_command (char *arg, int from_tty)
8396 watch_command_1 (arg, hw_access, from_tty);
8400 /* Helper routines for the until_command routine in infcmd.c. Here
8401 because it uses the mechanisms of breakpoints. */
8403 struct until_break_command_continuation_args
8405 struct breakpoint *breakpoint;
8406 struct breakpoint *breakpoint2;
8409 /* This function is called by fetch_inferior_event via the
8410 cmd_continuation pointer, to complete the until command. It takes
8411 care of cleaning up the temporary breakpoints set up by the until
8414 until_break_command_continuation (void *arg)
8416 struct until_break_command_continuation_args *a = arg;
8418 delete_breakpoint (a->breakpoint);
8420 delete_breakpoint (a->breakpoint2);
8424 until_break_command (char *arg, int from_tty, int anywhere)
8426 struct symtabs_and_lines sals;
8427 struct symtab_and_line sal;
8428 struct frame_info *frame = get_selected_frame (NULL);
8429 struct breakpoint *breakpoint;
8430 struct breakpoint *breakpoint2 = NULL;
8431 struct cleanup *old_chain;
8433 clear_proceed_status ();
8435 /* Set a breakpoint where the user wants it and at return from
8438 if (default_breakpoint_valid)
8439 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
8440 default_breakpoint_line, (char ***) NULL, NULL);
8442 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
8443 0, (char ***) NULL, NULL);
8445 if (sals.nelts != 1)
8446 error (_("Couldn't get information on specified line."));
8449 xfree (sals.sals); /* malloc'd, so freed */
8452 error (_("Junk at end of arguments."));
8454 resolve_sal_pc (&sal);
8457 /* If the user told us to continue until a specified location,
8458 we don't specify a frame at which we need to stop. */
8459 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8460 null_frame_id, bp_until);
8462 /* Otherwise, specify the selected frame, because we want to stop only
8463 at the very same frame. */
8464 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal,
8465 get_stack_frame_id (frame),
8468 old_chain = make_cleanup_delete_breakpoint (breakpoint);
8470 /* Keep within the current frame, or in frames called by the current
8473 if (frame_id_p (frame_unwind_caller_id (frame)))
8475 sal = find_pc_line (frame_unwind_caller_pc (frame), 0);
8476 sal.pc = frame_unwind_caller_pc (frame);
8477 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
8479 frame_unwind_caller_id (frame),
8481 make_cleanup_delete_breakpoint (breakpoint2);
8484 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
8486 /* If we are running asynchronously, and proceed call above has actually
8487 managed to start the target, arrange for breakpoints to be
8488 deleted when the target stops. Otherwise, we're already stopped and
8489 delete breakpoints via cleanup chain. */
8491 if (target_can_async_p () && is_running (inferior_ptid))
8493 struct until_break_command_continuation_args *args;
8494 args = xmalloc (sizeof (*args));
8496 args->breakpoint = breakpoint;
8497 args->breakpoint2 = breakpoint2;
8499 discard_cleanups (old_chain);
8500 add_continuation (inferior_thread (),
8501 until_break_command_continuation, args,
8505 do_cleanups (old_chain);
8509 ep_skip_leading_whitespace (char **s)
8511 if ((s == NULL) || (*s == NULL))
8513 while (isspace (**s))
8517 /* This function attempts to parse an optional "if <cond>" clause
8518 from the arg string. If one is not found, it returns NULL.
8520 Else, it returns a pointer to the condition string. (It does not
8521 attempt to evaluate the string against a particular block.) And,
8522 it updates arg to point to the first character following the parsed
8523 if clause in the arg string. */
8526 ep_parse_optional_if_clause (char **arg)
8530 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
8533 /* Skip the "if" keyword. */
8536 /* Skip any extra leading whitespace, and record the start of the
8537 condition string. */
8538 ep_skip_leading_whitespace (arg);
8541 /* Assume that the condition occupies the remainder of the arg string. */
8542 (*arg) += strlen (cond_string);
8547 /* Commands to deal with catching events, such as signals, exceptions,
8548 process start/exit, etc. */
8552 catch_fork_temporary, catch_vfork_temporary,
8553 catch_fork_permanent, catch_vfork_permanent
8558 catch_fork_command_1 (char *arg, int from_tty,
8559 struct cmd_list_element *command)
8561 struct gdbarch *gdbarch = get_current_arch ();
8562 char *cond_string = NULL;
8563 catch_fork_kind fork_kind;
8566 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
8567 tempflag = (fork_kind == catch_fork_temporary
8568 || fork_kind == catch_vfork_temporary);
8572 ep_skip_leading_whitespace (&arg);
8574 /* The allowed syntax is:
8576 catch [v]fork 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 a fork or vfork catchpoint
8585 and enable reporting of such events. */
8588 case catch_fork_temporary:
8589 case catch_fork_permanent:
8590 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8591 &catch_fork_breakpoint_ops);
8593 case catch_vfork_temporary:
8594 case catch_vfork_permanent:
8595 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
8596 &catch_vfork_breakpoint_ops);
8599 error (_("unsupported or unknown fork kind; cannot catch it"));
8605 catch_exec_command_1 (char *arg, int from_tty,
8606 struct cmd_list_element *command)
8608 struct gdbarch *gdbarch = get_current_arch ();
8610 char *cond_string = NULL;
8612 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8616 ep_skip_leading_whitespace (&arg);
8618 /* The allowed syntax is:
8620 catch exec if <cond>
8622 First, check if there's an if clause. */
8623 cond_string = ep_parse_optional_if_clause (&arg);
8625 if ((*arg != '\0') && !isspace (*arg))
8626 error (_("Junk at end of arguments."));
8628 /* If this target supports it, create an exec catchpoint
8629 and enable reporting of such events. */
8630 create_catchpoint (gdbarch, tempflag, cond_string,
8631 &catch_exec_breakpoint_ops);
8634 static enum print_stop_action
8635 print_exception_catchpoint (struct breakpoint *b)
8637 int bp_temp, bp_throw;
8639 annotate_catchpoint (b->number);
8641 bp_throw = strstr (b->addr_string, "throw") != NULL;
8642 if (b->loc->address != b->loc->requested_address)
8643 breakpoint_adjustment_warning (b->loc->requested_address,
8646 bp_temp = b->disposition == disp_del;
8648 bp_temp ? "Temporary catchpoint "
8650 if (!ui_out_is_mi_like_p (uiout))
8651 ui_out_field_int (uiout, "bkptno", b->number);
8653 bp_throw ? " (exception thrown), "
8654 : " (exception caught), ");
8655 if (ui_out_is_mi_like_p (uiout))
8657 ui_out_field_string (uiout, "reason",
8658 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
8659 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8660 ui_out_field_int (uiout, "bkptno", b->number);
8662 return PRINT_SRC_AND_LOC;
8666 print_one_exception_catchpoint (struct breakpoint *b,
8667 struct bp_location **last_loc)
8669 struct value_print_options opts;
8671 get_user_print_options (&opts);
8672 if (opts.addressprint)
8675 if (b->loc == NULL || b->loc->shlib_disabled)
8676 ui_out_field_string (uiout, "addr", "<PENDING>");
8678 ui_out_field_core_addr (uiout, "addr",
8679 b->loc->gdbarch, b->loc->address);
8684 if (strstr (b->addr_string, "throw") != NULL)
8685 ui_out_field_string (uiout, "what", "exception throw");
8687 ui_out_field_string (uiout, "what", "exception catch");
8691 print_mention_exception_catchpoint (struct breakpoint *b)
8696 bp_temp = b->disposition == disp_del;
8697 bp_throw = strstr (b->addr_string, "throw") != NULL;
8698 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
8699 : _("Catchpoint "));
8700 ui_out_field_int (uiout, "bkptno", b->number);
8701 ui_out_text (uiout, bp_throw ? _(" (throw)")
8705 /* Implement the "print_recreate" breakpoint_ops method for throw and
8706 catch catchpoints. */
8709 print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp)
8714 bp_temp = b->disposition == disp_del;
8715 bp_throw = strstr (b->addr_string, "throw") != NULL;
8716 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
8717 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
8720 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
8723 NULL, /* breakpoint_hit */
8724 print_exception_catchpoint,
8725 print_one_exception_catchpoint,
8726 print_mention_exception_catchpoint,
8727 print_recreate_exception_catchpoint
8731 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
8732 enum exception_event_kind ex_event, int from_tty)
8734 char *trigger_func_name;
8736 if (ex_event == EX_EVENT_CATCH)
8737 trigger_func_name = "__cxa_begin_catch";
8739 trigger_func_name = "__cxa_throw";
8741 create_breakpoint (get_current_arch (),
8742 trigger_func_name, cond_string, -1,
8743 0 /* condition and thread are valid. */,
8744 tempflag, bp_breakpoint,
8746 AUTO_BOOLEAN_TRUE /* pending */,
8747 &gnu_v3_exception_catchpoint_ops, from_tty,
8753 /* Deal with "catch catch" and "catch throw" commands */
8756 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
8757 int tempflag, int from_tty)
8759 char *cond_string = NULL;
8763 ep_skip_leading_whitespace (&arg);
8765 cond_string = ep_parse_optional_if_clause (&arg);
8767 if ((*arg != '\0') && !isspace (*arg))
8768 error (_("Junk at end of arguments."));
8770 if (ex_event != EX_EVENT_THROW
8771 && ex_event != EX_EVENT_CATCH)
8772 error (_("Unsupported or unknown exception event; cannot catch it"));
8774 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
8777 warning (_("Unsupported with this platform/compiler combination."));
8780 /* Implementation of "catch catch" command. */
8783 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
8785 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8787 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
8790 /* Implementation of "catch throw" command. */
8793 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
8795 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8797 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
8800 /* Create a breakpoint struct for Ada exception catchpoints. */
8803 create_ada_exception_breakpoint (struct gdbarch *gdbarch,
8804 struct symtab_and_line sal,
8808 struct expression *cond,
8809 struct breakpoint_ops *ops,
8813 struct breakpoint *b;
8817 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8819 loc_gdbarch = gdbarch;
8821 describe_other_breakpoints (loc_gdbarch,
8822 sal.pspace, sal.pc, sal.section, -1);
8823 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8824 version for exception catchpoints, because two catchpoints
8825 used for different exception names will use the same address.
8826 In this case, a "breakpoint ... also set at..." warning is
8827 unproductive. Besides. the warning phrasing is also a bit
8828 inapropriate, we should use the word catchpoint, and tell
8829 the user what type of catchpoint it is. The above is good
8830 enough for now, though. */
8833 b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint);
8834 set_breakpoint_count (breakpoint_count + 1);
8836 b->enable_state = bp_enabled;
8837 b->disposition = tempflag ? disp_del : disp_donttouch;
8838 b->number = breakpoint_count;
8839 b->ignore_count = 0;
8840 b->loc->cond = cond;
8841 b->addr_string = addr_string;
8842 b->language = language_ada;
8843 b->cond_string = cond_string;
8844 b->exp_string = exp_string;
8849 update_global_location_list (1);
8852 /* Implement the "catch exception" command. */
8855 catch_ada_exception_command (char *arg, int from_tty,
8856 struct cmd_list_element *command)
8858 struct gdbarch *gdbarch = get_current_arch ();
8860 struct symtab_and_line sal;
8861 char *addr_string = NULL;
8862 char *exp_string = NULL;
8863 char *cond_string = NULL;
8864 struct expression *cond = NULL;
8865 struct breakpoint_ops *ops = NULL;
8867 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8871 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
8872 &cond_string, &cond, &ops);
8873 create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string,
8874 cond_string, cond, ops, tempflag,
8878 /* Cleanup function for a syscall filter list. */
8880 clean_up_filters (void *arg)
8882 VEC(int) *iter = *(VEC(int) **) arg;
8883 VEC_free (int, iter);
8886 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8887 filter list, or NULL if no filtering is required. */
8889 catch_syscall_split_args (char *arg)
8891 VEC(int) *result = NULL;
8892 struct cleanup *cleanup = make_cleanup (clean_up_filters, &result);
8894 while (*arg != '\0')
8896 int i, syscall_number;
8901 /* Skip whitespace. */
8902 while (isspace (*arg))
8905 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
8906 cur_name[i] = arg[i];
8910 /* Check if the user provided a syscall name or a number. */
8911 syscall_number = (int) strtol (cur_name, &endptr, 0);
8912 if (*endptr == '\0')
8913 get_syscall_by_number (syscall_number, &s);
8916 /* We have a name. Let's check if it's valid and convert it
8918 get_syscall_by_name (cur_name, &s);
8920 if (s.number == UNKNOWN_SYSCALL)
8921 /* Here we have to issue an error instead of a warning, because
8922 GDB cannot do anything useful if there's no syscall number to
8924 error (_("Unknown syscall name '%s'."), cur_name);
8927 /* Ok, it's valid. */
8928 VEC_safe_push (int, result, s.number);
8931 discard_cleanups (cleanup);
8935 /* Implement the "catch syscall" command. */
8938 catch_syscall_command_1 (char *arg, int from_tty,
8939 struct cmd_list_element *command)
8944 struct gdbarch *gdbarch = get_current_arch ();
8946 /* Checking if the feature if supported. */
8947 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
8948 error (_("The feature 'catch syscall' is not supported on \
8949 this architeture yet."));
8951 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8953 ep_skip_leading_whitespace (&arg);
8955 /* We need to do this first "dummy" translation in order
8956 to get the syscall XML file loaded or, most important,
8957 to display a warning to the user if there's no XML file
8958 for his/her architecture. */
8959 get_syscall_by_number (0, &s);
8961 /* The allowed syntax is:
8963 catch syscall <name | number> [<name | number> ... <name | number>]
8965 Let's check if there's a syscall name. */
8968 filter = catch_syscall_split_args (arg);
8972 create_syscall_event_catchpoint (tempflag, filter,
8973 &catch_syscall_breakpoint_ops);
8976 /* Implement the "catch assert" command. */
8979 catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
8981 struct gdbarch *gdbarch = get_current_arch ();
8983 struct symtab_and_line sal;
8984 char *addr_string = NULL;
8985 struct breakpoint_ops *ops = NULL;
8987 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8991 sal = ada_decode_assert_location (arg, &addr_string, &ops);
8992 create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL,
8993 ops, tempflag, from_tty);
8997 catch_command (char *arg, int from_tty)
8999 error (_("Catch requires an event name."));
9004 tcatch_command (char *arg, int from_tty)
9006 error (_("Catch requires an event name."));
9009 /* Delete breakpoints by address or line. */
9012 clear_command (char *arg, int from_tty)
9014 struct breakpoint *b;
9015 VEC(breakpoint_p) *found = 0;
9018 struct symtabs_and_lines sals;
9019 struct symtab_and_line sal;
9024 sals = decode_line_spec (arg, 1);
9029 sals.sals = (struct symtab_and_line *)
9030 xmalloc (sizeof (struct symtab_and_line));
9031 make_cleanup (xfree, sals.sals);
9032 init_sal (&sal); /* initialize to zeroes */
9033 sal.line = default_breakpoint_line;
9034 sal.symtab = default_breakpoint_symtab;
9035 sal.pc = default_breakpoint_address;
9036 sal.pspace = default_breakpoint_pspace;
9037 if (sal.symtab == 0)
9038 error (_("No source file specified."));
9046 /* We don't call resolve_sal_pc here. That's not
9047 as bad as it seems, because all existing breakpoints
9048 typically have both file/line and pc set. So, if
9049 clear is given file/line, we can match this to existing
9050 breakpoint without obtaining pc at all.
9052 We only support clearing given the address explicitly
9053 present in breakpoint table. Say, we've set breakpoint
9054 at file:line. There were several PC values for that file:line,
9055 due to optimization, all in one block.
9056 We've picked one PC value. If "clear" is issued with another
9057 PC corresponding to the same file:line, the breakpoint won't
9058 be cleared. We probably can still clear the breakpoint, but
9059 since the other PC value is never presented to user, user
9060 can only find it by guessing, and it does not seem important
9063 /* For each line spec given, delete bps which correspond
9064 to it. Do it in two passes, solely to preserve the current
9065 behavior that from_tty is forced true if we delete more than
9069 for (i = 0; i < sals.nelts; i++)
9071 /* If exact pc given, clear bpts at that pc.
9072 If line given (pc == 0), clear all bpts on specified line.
9073 If defaulting, clear all bpts on default line
9076 defaulting sal.pc != 0 tests to do
9081 1 0 <can't happen> */
9085 /* Find all matching breakpoints and add them to
9090 /* Are we going to delete b? */
9091 if (b->type != bp_none && !is_watchpoint (b))
9093 struct bp_location *loc = b->loc;
9094 for (; loc; loc = loc->next)
9096 int pc_match = sal.pc
9097 && (loc->pspace == sal.pspace)
9098 && (loc->address == sal.pc)
9099 && (!section_is_overlay (loc->section)
9100 || loc->section == sal.section);
9101 int line_match = ((default_match || (0 == sal.pc))
9102 && b->source_file != NULL
9103 && sal.symtab != NULL
9104 && sal.pspace == loc->pspace
9105 && strcmp (b->source_file, sal.symtab->filename) == 0
9106 && b->line_number == sal.line);
9107 if (pc_match || line_match)
9116 VEC_safe_push(breakpoint_p, found, b);
9119 /* Now go thru the 'found' chain and delete them. */
9120 if (VEC_empty(breakpoint_p, found))
9123 error (_("No breakpoint at %s."), arg);
9125 error (_("No breakpoint at this line."));
9128 if (VEC_length(breakpoint_p, found) > 1)
9129 from_tty = 1; /* Always report if deleted more than one */
9132 if (VEC_length(breakpoint_p, found) == 1)
9133 printf_unfiltered (_("Deleted breakpoint "));
9135 printf_unfiltered (_("Deleted breakpoints "));
9137 breakpoints_changed ();
9139 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
9142 printf_unfiltered ("%d ", b->number);
9143 delete_breakpoint (b);
9146 putchar_unfiltered ('\n');
9149 /* Delete breakpoint in BS if they are `delete' breakpoints and
9150 all breakpoints that are marked for deletion, whether hit or not.
9151 This is called after any breakpoint is hit, or after errors. */
9154 breakpoint_auto_delete (bpstat bs)
9156 struct breakpoint *b, *temp;
9158 for (; bs; bs = bs->next)
9159 if (bs->breakpoint_at
9160 && bs->breakpoint_at->owner
9161 && bs->breakpoint_at->owner->disposition == disp_del
9163 delete_breakpoint (bs->breakpoint_at->owner);
9165 ALL_BREAKPOINTS_SAFE (b, temp)
9167 if (b->disposition == disp_del_at_next_stop)
9168 delete_breakpoint (b);
9172 /* A comparison function for bp_location AP and BP being interfaced to qsort.
9173 Sort elements primarily by their ADDRESS (no matter what does
9174 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
9175 first bp_permanent OWNERed elements and terciarily just ensuring the array
9176 is sorted stable way despite qsort being an instable algorithm. */
9179 bp_location_compare (const void *ap, const void *bp)
9181 struct bp_location *a = *(void **) ap;
9182 struct bp_location *b = *(void **) bp;
9183 /* A and B come from existing breakpoints having non-NULL OWNER. */
9184 int a_perm = a->owner->enable_state == bp_permanent;
9185 int b_perm = b->owner->enable_state == bp_permanent;
9187 if (a->address != b->address)
9188 return (a->address > b->address) - (a->address < b->address);
9190 /* Sort permanent breakpoints first. */
9191 if (a_perm != b_perm)
9192 return (a_perm < b_perm) - (a_perm > b_perm);
9194 /* Make the user-visible order stable across GDB runs. Locations of the same
9195 breakpoint can be sorted in arbitrary order. */
9197 if (a->owner->number != b->owner->number)
9198 return (a->owner->number > b->owner->number)
9199 - (a->owner->number < b->owner->number);
9201 return (a > b) - (a < b);
9204 /* Set bp_location_placed_address_before_address_max and
9205 bp_location_shadow_len_after_address_max according to the current content of
9206 the bp_location array. */
9209 bp_location_target_extensions_update (void)
9211 struct bp_location *bl, **blp_tmp;
9213 bp_location_placed_address_before_address_max = 0;
9214 bp_location_shadow_len_after_address_max = 0;
9216 ALL_BP_LOCATIONS (bl, blp_tmp)
9218 CORE_ADDR start, end, addr;
9220 if (!bp_location_has_shadow (bl))
9223 start = bl->target_info.placed_address;
9224 end = start + bl->target_info.shadow_len;
9226 gdb_assert (bl->address >= start);
9227 addr = bl->address - start;
9228 if (addr > bp_location_placed_address_before_address_max)
9229 bp_location_placed_address_before_address_max = addr;
9231 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9233 gdb_assert (bl->address < end);
9234 addr = end - bl->address;
9235 if (addr > bp_location_shadow_len_after_address_max)
9236 bp_location_shadow_len_after_address_max = addr;
9240 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9241 into the inferior, only remove already-inserted locations that no
9242 longer should be inserted. Functions that delete a breakpoint or
9243 breakpoints should pass false, so that deleting a breakpoint
9244 doesn't have the side effect of inserting the locations of other
9245 breakpoints that are marked not-inserted, but should_be_inserted
9246 returns true on them.
9248 This behaviour is useful is situations close to tear-down -- e.g.,
9249 after an exec, while the target still has execution, but breakpoint
9250 shadows of the previous executable image should *NOT* be restored
9251 to the new image; or before detaching, where the target still has
9252 execution and wants to delete breakpoints from GDB's lists, and all
9253 breakpoints had already been removed from the inferior. */
9256 update_global_location_list (int should_insert)
9258 struct breakpoint *b;
9259 struct bp_location **locp, *loc;
9260 struct cleanup *cleanups;
9262 /* Used in the duplicates detection below. When iterating over all
9263 bp_locations, points to the first bp_location of a given address.
9264 Breakpoints and watchpoints of different types are never
9265 duplicates of each other. Keep one pointer for each type of
9266 breakpoint/watchpoint, so we only need to loop over all locations
9268 struct bp_location *bp_loc_first; /* breakpoint */
9269 struct bp_location *wp_loc_first; /* hardware watchpoint */
9270 struct bp_location *awp_loc_first; /* access watchpoint */
9271 struct bp_location *rwp_loc_first; /* read watchpoint */
9273 /* Saved former bp_location array which we compare against the newly built
9274 bp_location from the current state of ALL_BREAKPOINTS. */
9275 struct bp_location **old_location, **old_locp;
9276 unsigned old_location_count;
9278 old_location = bp_location;
9279 old_location_count = bp_location_count;
9281 bp_location_count = 0;
9282 cleanups = make_cleanup (xfree, old_location);
9285 for (loc = b->loc; loc; loc = loc->next)
9286 bp_location_count++;
9288 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
9291 for (loc = b->loc; loc; loc = loc->next)
9293 qsort (bp_location, bp_location_count, sizeof (*bp_location),
9294 bp_location_compare);
9296 bp_location_target_extensions_update ();
9298 /* Identify bp_location instances that are no longer present in the new
9299 list, and therefore should be freed. Note that it's not necessary that
9300 those locations should be removed from inferior -- if there's another
9301 location at the same address (previously marked as duplicate),
9302 we don't need to remove/insert the location.
9304 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9305 former bp_location array state respectively. */
9308 for (old_locp = old_location; old_locp < old_location + old_location_count;
9311 struct bp_location *old_loc = *old_locp;
9312 struct bp_location **loc2p;
9314 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9316 int found_object = 0;
9317 /* Tells if the location should remain inserted in the target. */
9318 int keep_in_target = 0;
9321 /* Skip LOCP entries which will definitely never be needed. Stop either
9322 at or being the one matching OLD_LOC. */
9323 while (locp < bp_location + bp_location_count
9324 && (*locp)->address < old_loc->address)
9328 (loc2p < bp_location + bp_location_count
9329 && (*loc2p)->address == old_loc->address);
9332 if (*loc2p == old_loc)
9339 /* If this location is no longer present, and inserted, look if there's
9340 maybe a new location at the same address. If so, mark that one
9341 inserted, and don't remove this one. This is needed so that we
9342 don't have a time window where a breakpoint at certain location is not
9345 if (old_loc->inserted)
9347 /* If the location is inserted now, we might have to remove it. */
9349 if (found_object && should_be_inserted (old_loc))
9351 /* The location is still present in the location list, and still
9352 should be inserted. Don't do anything. */
9357 /* The location is either no longer present, or got disabled.
9358 See if there's another location at the same address, in which
9359 case we don't need to remove this one from the target. */
9361 /* OLD_LOC comes from existing struct breakpoint. */
9362 if (breakpoint_address_is_meaningful (old_loc->owner))
9365 (loc2p < bp_location + bp_location_count
9366 && (*loc2p)->address == old_loc->address);
9369 struct bp_location *loc2 = *loc2p;
9371 if (breakpoint_locations_match (loc2, old_loc))
9373 /* For the sake of should_be_inserted.
9374 Duplicates check below will fix up this later. */
9375 loc2->duplicate = 0;
9377 /* Read watchpoint locations are switched to
9378 access watchpoints, if the former are not
9379 supported, but the latter are. */
9380 if (is_hardware_watchpoint (old_loc->owner))
9382 gdb_assert (is_hardware_watchpoint (loc2->owner));
9383 loc2->watchpoint_type = old_loc->watchpoint_type;
9386 if (loc2 != old_loc && should_be_inserted (loc2))
9389 loc2->target_info = old_loc->target_info;
9398 if (!keep_in_target)
9400 if (remove_breakpoint (old_loc, mark_uninserted))
9402 /* This is just about all we can do. We could keep this
9403 location on the global list, and try to remove it next
9404 time, but there's no particular reason why we will
9407 Note that at this point, old_loc->owner is still valid,
9408 as delete_breakpoint frees the breakpoint only
9409 after calling us. */
9410 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9411 old_loc->owner->number);
9419 if (removed && non_stop
9420 && breakpoint_address_is_meaningful (old_loc->owner)
9421 && !is_hardware_watchpoint (old_loc->owner))
9423 /* This location was removed from the target. In
9424 non-stop mode, a race condition is possible where
9425 we've removed a breakpoint, but stop events for that
9426 breakpoint are already queued and will arrive later.
9427 We apply an heuristic to be able to distinguish such
9428 SIGTRAPs from other random SIGTRAPs: we keep this
9429 breakpoint location for a bit, and will retire it
9430 after we see some number of events. The theory here
9431 is that reporting of events should, "on the average",
9432 be fair, so after a while we'll see events from all
9433 threads that have anything of interest, and no longer
9434 need to keep this breakpoint location around. We
9435 don't hold locations forever so to reduce chances of
9436 mistaking a non-breakpoint SIGTRAP for a breakpoint
9439 The heuristic failing can be disastrous on
9440 decr_pc_after_break targets.
9442 On decr_pc_after_break targets, like e.g., x86-linux,
9443 if we fail to recognize a late breakpoint SIGTRAP,
9444 because events_till_retirement has reached 0 too
9445 soon, we'll fail to do the PC adjustment, and report
9446 a random SIGTRAP to the user. When the user resumes
9447 the inferior, it will most likely immediately crash
9448 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9449 corrupted, because of being resumed e.g., in the
9450 middle of a multi-byte instruction, or skipped a
9451 one-byte instruction. This was actually seen happen
9452 on native x86-linux, and should be less rare on
9453 targets that do not support new thread events, like
9454 remote, due to the heuristic depending on
9457 Mistaking a random SIGTRAP for a breakpoint trap
9458 causes similar symptoms (PC adjustment applied when
9459 it shouldn't), but then again, playing with SIGTRAPs
9460 behind the debugger's back is asking for trouble.
9462 Since hardware watchpoint traps are always
9463 distinguishable from other traps, so we don't need to
9464 apply keep hardware watchpoint moribund locations
9465 around. We simply always ignore hardware watchpoint
9466 traps we can no longer explain. */
9468 old_loc->events_till_retirement = 3 * (thread_count () + 1);
9469 old_loc->owner = NULL;
9471 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
9474 free_bp_location (old_loc);
9478 /* Rescan breakpoints at the same address and section, marking the
9479 first one as "first" and any others as "duplicates". This is so
9480 that the bpt instruction is only inserted once. If we have a
9481 permanent breakpoint at the same place as BPT, make that one the
9482 official one, and the rest as duplicates. Permanent breakpoints
9483 are sorted first for the same address.
9485 Do the same for hardware watchpoints, but also considering the
9486 watchpoint's type (regular/access/read) and length. */
9488 bp_loc_first = NULL;
9489 wp_loc_first = NULL;
9490 awp_loc_first = NULL;
9491 rwp_loc_first = NULL;
9492 ALL_BP_LOCATIONS (loc, locp)
9494 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9495 struct breakpoint *b = loc->owner;
9496 struct bp_location **loc_first_p;
9498 if (b->enable_state == bp_disabled
9499 || b->enable_state == bp_call_disabled
9500 || b->enable_state == bp_startup_disabled
9502 || loc->shlib_disabled
9503 || !breakpoint_address_is_meaningful (b)
9504 || is_tracepoint (b))
9507 /* Permanent breakpoint should always be inserted. */
9508 if (b->enable_state == bp_permanent && ! loc->inserted)
9509 internal_error (__FILE__, __LINE__,
9510 _("allegedly permanent breakpoint is not "
9511 "actually inserted"));
9513 if (b->type == bp_hardware_watchpoint)
9514 loc_first_p = &wp_loc_first;
9515 else if (b->type == bp_read_watchpoint)
9516 loc_first_p = &rwp_loc_first;
9517 else if (b->type == bp_access_watchpoint)
9518 loc_first_p = &awp_loc_first;
9520 loc_first_p = &bp_loc_first;
9522 if (*loc_first_p == NULL
9523 || (overlay_debugging && loc->section != (*loc_first_p)->section)
9524 || !breakpoint_locations_match (loc, *loc_first_p))
9533 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
9534 && b->enable_state != bp_permanent)
9535 internal_error (__FILE__, __LINE__,
9536 _("another breakpoint was inserted on top of "
9537 "a permanent breakpoint"));
9540 if (breakpoints_always_inserted_mode () && should_insert
9541 && (have_live_inferiors ()
9542 || (gdbarch_has_global_breakpoints (target_gdbarch))))
9543 insert_breakpoint_locations ();
9545 do_cleanups (cleanups);
9549 breakpoint_retire_moribund (void)
9551 struct bp_location *loc;
9554 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
9555 if (--(loc->events_till_retirement) == 0)
9557 free_bp_location (loc);
9558 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
9564 update_global_location_list_nothrow (int inserting)
9566 struct gdb_exception e;
9568 TRY_CATCH (e, RETURN_MASK_ERROR)
9569 update_global_location_list (inserting);
9572 /* Clear LOC from a BPS. */
9574 bpstat_remove_bp_location (bpstat bps, struct bp_location *loc)
9578 for (bs = bps; bs; bs = bs->next)
9579 if (bs->breakpoint_at == loc)
9581 bs->breakpoint_at = NULL;
9583 /* bs->commands will be freed later. */
9587 /* Callback for iterate_over_threads. */
9589 bpstat_remove_bp_location_callback (struct thread_info *th, void *data)
9591 struct bp_location *loc = data;
9593 bpstat_remove_bp_location (th->stop_bpstat, loc);
9597 /* Delete a breakpoint and clean up all traces of it in the data
9601 delete_breakpoint (struct breakpoint *bpt)
9603 struct breakpoint *b;
9605 gdb_assert (bpt != NULL);
9607 /* Has this bp already been deleted? This can happen because multiple
9608 lists can hold pointers to bp's. bpstat lists are especial culprits.
9610 One example of this happening is a watchpoint's scope bp. When the
9611 scope bp triggers, we notice that the watchpoint is out of scope, and
9612 delete it. We also delete its scope bp. But the scope bp is marked
9613 "auto-deleting", and is already on a bpstat. That bpstat is then
9614 checked for auto-deleting bp's, which are deleted.
9616 A real solution to this problem might involve reference counts in bp's,
9617 and/or giving them pointers back to their referencing bpstat's, and
9618 teaching delete_breakpoint to only free a bp's storage when no more
9619 references were extent. A cheaper bandaid was chosen. */
9620 if (bpt->type == bp_none)
9623 /* At least avoid this stale reference until the reference counting of
9624 breakpoints gets resolved. */
9625 if (bpt->related_breakpoint != NULL)
9627 gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
9628 bpt->related_breakpoint->disposition = disp_del_at_next_stop;
9629 bpt->related_breakpoint->related_breakpoint = NULL;
9630 bpt->related_breakpoint = NULL;
9633 observer_notify_breakpoint_deleted (bpt->number);
9635 if (breakpoint_chain == bpt)
9636 breakpoint_chain = bpt->next;
9641 b->next = bpt->next;
9645 decref_counted_command_line (&bpt->commands);
9646 xfree (bpt->cond_string);
9647 xfree (bpt->cond_exp);
9648 xfree (bpt->addr_string);
9650 xfree (bpt->exp_string);
9651 value_free (bpt->val);
9652 xfree (bpt->source_file);
9653 xfree (bpt->exec_pathname);
9654 clean_up_filters (&bpt->syscalls_to_be_caught);
9656 /* Now that breakpoint is removed from breakpoint
9657 list, update the global location list. This
9658 will remove locations that used to belong to
9659 this breakpoint. Do this before freeing
9660 the breakpoint itself, since remove_breakpoint
9661 looks at location's owner. It might be better
9662 design to have location completely self-contained,
9663 but it's not the case now. */
9664 update_global_location_list (0);
9667 /* On the chance that someone will soon try again to delete this same
9668 bp, we mark it as deleted before freeing its storage. */
9669 bpt->type = bp_none;
9675 do_delete_breakpoint_cleanup (void *b)
9677 delete_breakpoint (b);
9681 make_cleanup_delete_breakpoint (struct breakpoint *b)
9683 return make_cleanup (do_delete_breakpoint_cleanup, b);
9686 /* A callback for map_breakpoint_numbers that calls
9687 delete_breakpoint. */
9690 do_delete_breakpoint (struct breakpoint *b, void *ignore)
9692 delete_breakpoint (b);
9696 delete_command (char *arg, int from_tty)
9698 struct breakpoint *b, *temp;
9704 int breaks_to_delete = 0;
9706 /* Delete all breakpoints if no argument.
9707 Do not delete internal or call-dummy breakpoints, these
9708 have to be deleted with an explicit breakpoint number argument. */
9711 if (b->type != bp_call_dummy
9712 && b->type != bp_std_terminate
9713 && b->type != bp_shlib_event
9714 && b->type != bp_jit_event
9715 && b->type != bp_thread_event
9716 && b->type != bp_overlay_event
9717 && b->type != bp_longjmp_master
9718 && b->type != bp_std_terminate_master
9721 breaks_to_delete = 1;
9726 /* Ask user only if there are some breakpoints to delete. */
9728 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
9730 ALL_BREAKPOINTS_SAFE (b, temp)
9732 if (b->type != bp_call_dummy
9733 && b->type != bp_std_terminate
9734 && b->type != bp_shlib_event
9735 && b->type != bp_thread_event
9736 && b->type != bp_jit_event
9737 && b->type != bp_overlay_event
9738 && b->type != bp_longjmp_master
9739 && b->type != bp_std_terminate_master
9741 delete_breakpoint (b);
9746 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
9750 all_locations_are_pending (struct bp_location *loc)
9752 for (; loc; loc = loc->next)
9753 if (!loc->shlib_disabled)
9758 /* Subroutine of update_breakpoint_locations to simplify it.
9759 Return non-zero if multiple fns in list LOC have the same name.
9760 Null names are ignored. */
9763 ambiguous_names_p (struct bp_location *loc)
9765 struct bp_location *l;
9766 htab_t htab = htab_create_alloc (13, htab_hash_string,
9767 (int (*) (const void *,
9768 const void *)) streq,
9769 NULL, xcalloc, xfree);
9771 for (l = loc; l != NULL; l = l->next)
9774 const char *name = l->function_name;
9776 /* Allow for some names to be NULL, ignore them. */
9780 slot = (const char **) htab_find_slot (htab, (const void *) name,
9782 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9796 /* When symbols change, it probably means the sources changed as well,
9797 and it might mean the static tracepoint markers are no longer at
9798 the same address or line numbers they used to be at last we
9799 checked. Losing your static tracepoints whenever you rebuild is
9800 undesirable. This function tries to resync/rematch gdb static
9801 tracepoints with the markers on the target, for static tracepoints
9802 that have not been set by marker id. Static tracepoint that have
9803 been set by marker id are reset by marker id in breakpoint_re_set.
9806 1) For a tracepoint set at a specific address, look for a marker at
9807 the old PC. If one is found there, assume to be the same marker.
9808 If the name / string id of the marker found is different from the
9809 previous known name, assume that means the user renamed the marker
9810 in the sources, and output a warning.
9812 2) For a tracepoint set at a given line number, look for a marker
9813 at the new address of the old line number. If one is found there,
9814 assume to be the same marker. If the name / string id of the
9815 marker found is different from the previous known name, assume that
9816 means the user renamed the marker in the sources, and output a
9819 3) If a marker is no longer found at the same address or line, it
9820 may mean the marker no longer exists. But it may also just mean
9821 the code changed a bit. Maybe the user added a few lines of code
9822 that made the marker move up or down (in line number terms). Ask
9823 the target for info about the marker with the string id as we knew
9824 it. If found, update line number and address in the matching
9825 static tracepoint. This will get confused if there's more than one
9826 marker with the same ID (possible in UST, although unadvised
9827 precisely because it confuses tools). */
9829 static struct symtab_and_line
9830 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
9832 struct static_tracepoint_marker marker;
9838 find_line_pc (sal.symtab, sal.line, &pc);
9840 if (target_static_tracepoint_marker_at (pc, &marker))
9842 if (strcmp (b->static_trace_marker_id, marker.str_id) != 0)
9843 warning (_("static tracepoint %d changed probed marker from %s to %s"),
9845 b->static_trace_marker_id, marker.str_id);
9847 xfree (b->static_trace_marker_id);
9848 b->static_trace_marker_id = xstrdup (marker.str_id);
9849 release_static_tracepoint_marker (&marker);
9854 /* Old marker wasn't found on target at lineno. Try looking it up
9856 if (!sal.explicit_pc
9858 && sal.symtab != NULL
9859 && b->static_trace_marker_id != NULL)
9861 VEC(static_tracepoint_marker_p) *markers;
9864 = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id);
9866 if (!VEC_empty(static_tracepoint_marker_p, markers))
9868 struct symtab_and_line sal;
9870 struct static_tracepoint_marker *marker;
9872 marker = VEC_index (static_tracepoint_marker_p, markers, 0);
9874 xfree (b->static_trace_marker_id);
9875 b->static_trace_marker_id = xstrdup (marker->str_id);
9877 warning (_("marker for static tracepoint %d (%s) not "
9878 "found at previous line number"),
9879 b->number, b->static_trace_marker_id);
9883 sal.pc = marker->address;
9885 sal = find_pc_line (marker->address, 0);
9886 sym = find_pc_sect_function (marker->address, NULL);
9887 ui_out_text (uiout, "Now in ");
9890 ui_out_field_string (uiout, "func",
9891 SYMBOL_PRINT_NAME (sym));
9892 ui_out_text (uiout, " at ");
9894 ui_out_field_string (uiout, "file", sal.symtab->filename);
9895 ui_out_text (uiout, ":");
9897 if (ui_out_is_mi_like_p (uiout))
9899 char *fullname = symtab_to_fullname (sal.symtab);
9902 ui_out_field_string (uiout, "fullname", fullname);
9905 ui_out_field_int (uiout, "line", sal.line);
9906 ui_out_text (uiout, "\n");
9908 b->line_number = sal.line;
9910 xfree (b->source_file);
9912 b->source_file = xstrdup (sal.symtab->filename);
9914 b->source_file = NULL;
9916 xfree (b->addr_string);
9917 b->addr_string = xstrprintf ("%s:%d",
9918 sal.symtab->filename, b->line_number);
9920 /* Might be nice to check if function changed, and warn if
9923 release_static_tracepoint_marker (marker);
9930 update_breakpoint_locations (struct breakpoint *b,
9931 struct symtabs_and_lines sals)
9935 struct bp_location *existing_locations = b->loc;
9937 /* If there's no new locations, and all existing locations
9938 are pending, don't do anything. This optimizes
9939 the common case where all locations are in the same
9940 shared library, that was unloaded. We'd like to
9941 retain the location, so that when the library
9942 is loaded again, we don't loose the enabled/disabled
9943 status of the individual locations. */
9944 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
9949 for (i = 0; i < sals.nelts; ++i)
9951 struct bp_location *new_loc =
9952 add_location_to_breakpoint (b, &(sals.sals[i]));
9954 /* Reparse conditions, they might contain references to the
9956 if (b->cond_string != NULL)
9958 struct gdb_exception e;
9961 TRY_CATCH (e, RETURN_MASK_ERROR)
9963 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
9968 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9969 b->number, e.message);
9970 new_loc->enabled = 0;
9974 if (b->source_file != NULL)
9975 xfree (b->source_file);
9976 if (sals.sals[i].symtab == NULL)
9977 b->source_file = NULL;
9979 b->source_file = xstrdup (sals.sals[i].symtab->filename);
9981 if (b->line_number == 0)
9982 b->line_number = sals.sals[i].line;
9985 /* Update locations of permanent breakpoints. */
9986 if (b->enable_state == bp_permanent)
9987 make_breakpoint_permanent (b);
9989 /* If possible, carry over 'disable' status from existing breakpoints. */
9991 struct bp_location *e = existing_locations;
9992 /* If there are multiple breakpoints with the same function name,
9993 e.g. for inline functions, comparing function names won't work.
9994 Instead compare pc addresses; this is just a heuristic as things
9995 may have moved, but in practice it gives the correct answer
9996 often enough until a better solution is found. */
9997 int have_ambiguous_names = ambiguous_names_p (b->loc);
9999 for (; e; e = e->next)
10001 if (!e->enabled && e->function_name)
10003 struct bp_location *l = b->loc;
10004 if (have_ambiguous_names)
10006 for (; l; l = l->next)
10007 if (breakpoint_address_match (e->pspace->aspace, e->address,
10008 l->pspace->aspace, l->address))
10016 for (; l; l = l->next)
10017 if (l->function_name
10018 && strcmp (e->function_name, l->function_name) == 0)
10028 update_global_location_list (1);
10031 /* Reset a breakpoint given it's struct breakpoint * BINT.
10032 The value we return ends up being the return value from catch_errors.
10033 Unused in this case. */
10036 breakpoint_re_set_one (void *bint)
10038 /* get past catch_errs */
10039 struct breakpoint *b = (struct breakpoint *) bint;
10041 int *not_found_ptr = ¬_found;
10042 struct symtabs_and_lines sals = {0};
10043 struct symtabs_and_lines expanded = {0};
10045 struct gdb_exception e;
10046 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
10047 int marker_spec = 0;
10052 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10055 case bp_breakpoint:
10056 case bp_hardware_breakpoint:
10057 case bp_tracepoint:
10058 case bp_fast_tracepoint:
10059 case bp_static_tracepoint:
10060 /* Do not attempt to re-set breakpoints disabled during startup. */
10061 if (b->enable_state == bp_startup_disabled)
10064 if (b->addr_string == NULL)
10066 /* Anything without a string can't be re-set. */
10067 delete_breakpoint (b);
10071 set_language (b->language);
10072 input_radix = b->input_radix;
10073 s = b->addr_string;
10075 save_current_space_and_thread ();
10076 switch_to_program_space_and_thread (b->pspace);
10078 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s);
10080 TRY_CATCH (e, RETURN_MASK_ERROR)
10084 sals = decode_static_tracepoint_spec (&s);
10085 if (sals.nelts > b->static_trace_marker_id_idx)
10087 sals.sals[0] = sals.sals[b->static_trace_marker_id_idx];
10091 error (_("marker %s not found"), b->static_trace_marker_id);
10094 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
10099 int not_found_and_ok = 0;
10100 /* For pending breakpoints, it's expected that parsing
10101 will fail until the right shared library is loaded.
10102 User has already told to create pending breakpoints and
10103 don't need extra messages. If breakpoint is in bp_shlib_disabled
10104 state, then user already saw the message about that breakpoint
10105 being disabled, and don't want to see more errors. */
10107 && (b->condition_not_parsed
10108 || (b->loc && b->loc->shlib_disabled)
10109 || b->enable_state == bp_disabled))
10110 not_found_and_ok = 1;
10112 if (!not_found_and_ok)
10114 /* We surely don't want to warn about the same breakpoint
10115 10 times. One solution, implemented here, is disable
10116 the breakpoint on error. Another solution would be to
10117 have separate 'warning emitted' flag. Since this
10118 happens only when a binary has changed, I don't know
10119 which approach is better. */
10120 b->enable_state = bp_disabled;
10121 throw_exception (e);
10127 gdb_assert (sals.nelts == 1);
10129 resolve_sal_pc (&sals.sals[0]);
10130 if (b->condition_not_parsed && s && s[0])
10132 char *cond_string = 0;
10136 find_condition_and_thread (s, sals.sals[0].pc,
10137 &cond_string, &thread, &task);
10139 b->cond_string = cond_string;
10140 b->thread = thread;
10142 b->condition_not_parsed = 0;
10145 if (b->type == bp_static_tracepoint && !marker_spec)
10146 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
10148 expanded = expand_line_sal_maybe (sals.sals[0]);
10151 make_cleanup (xfree, sals.sals);
10152 update_breakpoint_locations (b, expanded);
10155 case bp_watchpoint:
10156 case bp_hardware_watchpoint:
10157 case bp_read_watchpoint:
10158 case bp_access_watchpoint:
10159 /* Watchpoint can be either on expression using entirely global variables,
10160 or it can be on local variables.
10162 Watchpoints of the first kind are never auto-deleted, and even persist
10163 across program restarts. Since they can use variables from shared
10164 libraries, we need to reparse expression as libraries are loaded
10167 Watchpoints on local variables can also change meaning as result
10168 of solib event. For example, if a watchpoint uses both a local and
10169 a global variables in expression, it's a local watchpoint, but
10170 unloading of a shared library will make the expression invalid.
10171 This is not a very common use case, but we still re-evaluate
10172 expression, to avoid surprises to the user.
10174 Note that for local watchpoints, we re-evaluate it only if
10175 watchpoints frame id is still valid. If it's not, it means
10176 the watchpoint is out of scope and will be deleted soon. In fact,
10177 I'm not sure we'll ever be called in this case.
10179 If a local watchpoint's frame id is still valid, then
10180 b->exp_valid_block is likewise valid, and we can safely use it.
10182 Don't do anything about disabled watchpoints, since they will
10183 be reevaluated again when enabled. */
10184 update_watchpoint (b, 1 /* reparse */);
10186 /* We needn't really do anything to reset these, since the mask
10187 that requests them is unaffected by e.g., new libraries being
10189 case bp_catchpoint:
10193 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
10195 /* Delete overlay event and longjmp master breakpoints; they will be
10196 reset later by breakpoint_re_set. */
10197 case bp_overlay_event:
10198 case bp_longjmp_master:
10199 case bp_std_terminate_master:
10200 delete_breakpoint (b);
10203 /* This breakpoint is special, it's set up when the inferior
10204 starts and we really don't want to touch it. */
10205 case bp_shlib_event:
10207 /* Like bp_shlib_event, this breakpoint type is special.
10208 Once it is set up, we do not want to touch it. */
10209 case bp_thread_event:
10211 /* Keep temporary breakpoints, which can be encountered when we step
10212 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10213 Otherwise these should have been blown away via the cleanup chain
10214 or by breakpoint_init_inferior when we rerun the executable. */
10217 case bp_watchpoint_scope:
10218 case bp_call_dummy:
10219 case bp_std_terminate:
10220 case bp_step_resume:
10222 case bp_longjmp_resume:
10227 do_cleanups (cleanups);
10231 /* Re-set all breakpoints after symbols have been re-loaded. */
10233 breakpoint_re_set (void)
10235 struct breakpoint *b, *temp;
10236 enum language save_language;
10237 int save_input_radix;
10238 struct cleanup *old_chain;
10240 save_language = current_language->la_language;
10241 save_input_radix = input_radix;
10242 old_chain = save_current_program_space ();
10244 ALL_BREAKPOINTS_SAFE (b, temp)
10246 /* Format possible error msg */
10247 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
10249 struct cleanup *cleanups = make_cleanup (xfree, message);
10250 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
10251 do_cleanups (cleanups);
10253 set_language (save_language);
10254 input_radix = save_input_radix;
10256 jit_breakpoint_re_set ();
10258 do_cleanups (old_chain);
10260 create_overlay_event_breakpoint ("_ovly_debug_event");
10261 create_longjmp_master_breakpoint ("longjmp");
10262 create_longjmp_master_breakpoint ("_longjmp");
10263 create_longjmp_master_breakpoint ("siglongjmp");
10264 create_longjmp_master_breakpoint ("_siglongjmp");
10265 create_std_terminate_master_breakpoint ("std::terminate()");
10268 /* Reset the thread number of this breakpoint:
10270 - If the breakpoint is for all threads, leave it as-is.
10271 - Else, reset it to the current thread for inferior_ptid. */
10273 breakpoint_re_set_thread (struct breakpoint *b)
10275 if (b->thread != -1)
10277 if (in_thread_list (inferior_ptid))
10278 b->thread = pid_to_thread_id (inferior_ptid);
10280 /* We're being called after following a fork. The new fork is
10281 selected as current, and unless this was a vfork will have a
10282 different program space from the original thread. Reset that
10284 b->loc->pspace = current_program_space;
10288 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10289 If from_tty is nonzero, it prints a message to that effect,
10290 which ends with a period (no newline). */
10293 set_ignore_count (int bptnum, int count, int from_tty)
10295 struct breakpoint *b;
10300 ALL_BREAKPOINTS (b)
10301 if (b->number == bptnum)
10303 if (is_tracepoint (b))
10305 if (from_tty && count != 0)
10306 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10311 b->ignore_count = count;
10315 printf_filtered (_("Will stop next time breakpoint %d is reached."),
10317 else if (count == 1)
10318 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10321 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
10324 breakpoints_changed ();
10325 observer_notify_breakpoint_modified (b->number);
10329 error (_("No breakpoint number %d."), bptnum);
10333 make_breakpoint_silent (struct breakpoint *b)
10335 /* Silence the breakpoint. */
10339 /* Command to set ignore-count of breakpoint N to COUNT. */
10342 ignore_command (char *args, int from_tty)
10348 error_no_arg (_("a breakpoint number"));
10350 num = get_number (&p);
10352 error (_("bad breakpoint number: '%s'"), args);
10354 error (_("Second argument (specified ignore-count) is missing."));
10356 set_ignore_count (num,
10357 longest_to_int (value_as_long (parse_and_eval (p))),
10360 printf_filtered ("\n");
10363 /* Call FUNCTION on each of the breakpoints
10364 whose numbers are given in ARGS. */
10367 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
10374 struct breakpoint *b, *tmp;
10378 error_no_arg (_("one or more breakpoint numbers"));
10385 num = get_number_or_range (&p1);
10388 warning (_("bad breakpoint number at or near '%s'"), p);
10392 ALL_BREAKPOINTS_SAFE (b, tmp)
10393 if (b->number == num)
10395 struct breakpoint *related_breakpoint = b->related_breakpoint;
10397 function (b, data);
10398 if (related_breakpoint)
10399 function (related_breakpoint, data);
10403 printf_unfiltered (_("No breakpoint number %d.\n"), num);
10409 static struct bp_location *
10410 find_location_by_number (char *number)
10412 char *dot = strchr (number, '.');
10416 struct breakpoint *b;
10417 struct bp_location *loc;
10422 bp_num = get_number_or_range (&p1);
10424 error (_("Bad breakpoint number '%s'"), number);
10426 ALL_BREAKPOINTS (b)
10427 if (b->number == bp_num)
10432 if (!b || b->number != bp_num)
10433 error (_("Bad breakpoint number '%s'"), number);
10436 loc_num = get_number_or_range (&p1);
10438 error (_("Bad breakpoint location number '%s'"), number);
10442 for (;loc_num && loc; --loc_num, loc = loc->next)
10445 error (_("Bad breakpoint location number '%s'"), dot+1);
10451 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10452 If from_tty is nonzero, it prints a message to that effect,
10453 which ends with a period (no newline). */
10456 disable_breakpoint (struct breakpoint *bpt)
10458 /* Never disable a watchpoint scope breakpoint; we want to
10459 hit them when we leave scope so we can delete both the
10460 watchpoint and its scope breakpoint at that time. */
10461 if (bpt->type == bp_watchpoint_scope)
10464 /* You can't disable permanent breakpoints. */
10465 if (bpt->enable_state == bp_permanent)
10468 bpt->enable_state = bp_disabled;
10470 update_global_location_list (0);
10472 observer_notify_breakpoint_modified (bpt->number);
10475 /* A callback for map_breakpoint_numbers that calls
10476 disable_breakpoint. */
10479 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
10481 disable_breakpoint (b);
10485 disable_command (char *args, int from_tty)
10487 struct breakpoint *bpt;
10490 ALL_BREAKPOINTS (bpt)
10494 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10497 case bp_breakpoint:
10498 case bp_tracepoint:
10499 case bp_fast_tracepoint:
10500 case bp_static_tracepoint:
10501 case bp_catchpoint:
10502 case bp_hardware_breakpoint:
10503 case bp_watchpoint:
10504 case bp_hardware_watchpoint:
10505 case bp_read_watchpoint:
10506 case bp_access_watchpoint:
10507 disable_breakpoint (bpt);
10511 else if (strchr (args, '.'))
10513 struct bp_location *loc = find_location_by_number (args);
10516 update_global_location_list (0);
10519 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
10523 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
10525 int target_resources_ok;
10527 if (bpt->type == bp_hardware_breakpoint)
10530 i = hw_breakpoint_used_count ();
10531 target_resources_ok =
10532 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10534 if (target_resources_ok == 0)
10535 error (_("No hardware breakpoint support in the target."));
10536 else if (target_resources_ok < 0)
10537 error (_("Hardware breakpoints used exceeds limit."));
10540 if (is_watchpoint (bpt))
10542 struct gdb_exception e;
10544 TRY_CATCH (e, RETURN_MASK_ALL)
10546 update_watchpoint (bpt, 1 /* reparse */);
10550 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
10556 if (bpt->enable_state != bp_permanent)
10557 bpt->enable_state = bp_enabled;
10558 bpt->disposition = disposition;
10559 update_global_location_list (1);
10560 breakpoints_changed ();
10562 observer_notify_breakpoint_modified (bpt->number);
10567 enable_breakpoint (struct breakpoint *bpt)
10569 do_enable_breakpoint (bpt, bpt->disposition);
10572 /* A callback for map_breakpoint_numbers that calls
10573 enable_breakpoint. */
10576 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
10578 enable_breakpoint (b);
10581 /* The enable command enables the specified breakpoints (or all defined
10582 breakpoints) so they once again become (or continue to be) effective
10583 in stopping the inferior. */
10586 enable_command (char *args, int from_tty)
10588 struct breakpoint *bpt;
10591 ALL_BREAKPOINTS (bpt)
10595 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10598 case bp_breakpoint:
10599 case bp_tracepoint:
10600 case bp_fast_tracepoint:
10601 case bp_static_tracepoint:
10602 case bp_catchpoint:
10603 case bp_hardware_breakpoint:
10604 case bp_watchpoint:
10605 case bp_hardware_watchpoint:
10606 case bp_read_watchpoint:
10607 case bp_access_watchpoint:
10608 enable_breakpoint (bpt);
10612 else if (strchr (args, '.'))
10614 struct bp_location *loc = find_location_by_number (args);
10617 update_global_location_list (1);
10620 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
10624 enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
10626 do_enable_breakpoint (bpt, disp_disable);
10630 enable_once_command (char *args, int from_tty)
10632 map_breakpoint_numbers (args, enable_once_breakpoint, NULL);
10636 enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
10638 do_enable_breakpoint (bpt, disp_del);
10642 enable_delete_command (char *args, int from_tty)
10644 map_breakpoint_numbers (args, enable_delete_breakpoint, NULL);
10648 set_breakpoint_cmd (char *args, int from_tty)
10653 show_breakpoint_cmd (char *args, int from_tty)
10657 /* Invalidate last known value of any hardware watchpoint if
10658 the memory which that value represents has been written to by
10662 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
10663 const bfd_byte *data)
10665 struct breakpoint *bp;
10667 ALL_BREAKPOINTS (bp)
10668 if (bp->enable_state == bp_enabled
10669 && bp->type == bp_hardware_watchpoint
10670 && bp->val_valid && bp->val)
10672 struct bp_location *loc;
10674 for (loc = bp->loc; loc != NULL; loc = loc->next)
10675 if (loc->loc_type == bp_loc_hardware_watchpoint
10676 && loc->address + loc->length > addr
10677 && addr + len > loc->address)
10679 value_free (bp->val);
10686 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10688 struct symtabs_and_lines
10689 decode_line_spec_1 (char *string, int funfirstline)
10691 struct symtabs_and_lines sals;
10694 error (_("Empty line specification."));
10695 if (default_breakpoint_valid)
10696 sals = decode_line_1 (&string, funfirstline,
10697 default_breakpoint_symtab,
10698 default_breakpoint_line,
10699 (char ***) NULL, NULL);
10701 sals = decode_line_1 (&string, funfirstline,
10702 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
10704 error (_("Junk at end of line specification: %s"), string);
10708 /* Create and insert a raw software breakpoint at PC. Return an
10709 identifier, which should be used to remove the breakpoint later.
10710 In general, places which call this should be using something on the
10711 breakpoint chain instead; this function should be eliminated
10715 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
10716 struct address_space *aspace, CORE_ADDR pc)
10718 struct bp_target_info *bp_tgt;
10720 bp_tgt = XZALLOC (struct bp_target_info);
10722 bp_tgt->placed_address_space = aspace;
10723 bp_tgt->placed_address = pc;
10725 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
10727 /* Could not insert the breakpoint. */
10735 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10738 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
10740 struct bp_target_info *bp_tgt = bp;
10743 ret = target_remove_breakpoint (gdbarch, bp_tgt);
10749 /* One (or perhaps two) breakpoints used for software single stepping. */
10751 static void *single_step_breakpoints[2];
10752 static struct gdbarch *single_step_gdbarch[2];
10754 /* Create and insert a breakpoint for software single step. */
10757 insert_single_step_breakpoint (struct gdbarch *gdbarch,
10758 struct address_space *aspace, CORE_ADDR next_pc)
10762 if (single_step_breakpoints[0] == NULL)
10764 bpt_p = &single_step_breakpoints[0];
10765 single_step_gdbarch[0] = gdbarch;
10769 gdb_assert (single_step_breakpoints[1] == NULL);
10770 bpt_p = &single_step_breakpoints[1];
10771 single_step_gdbarch[1] = gdbarch;
10774 /* NOTE drow/2006-04-11: A future improvement to this function would be
10775 to only create the breakpoints once, and actually put them on the
10776 breakpoint chain. That would let us use set_raw_breakpoint. We could
10777 adjust the addresses each time they were needed. Doing this requires
10778 corresponding changes elsewhere where single step breakpoints are
10779 handled, however. So, for now, we use this. */
10781 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
10782 if (*bpt_p == NULL)
10783 error (_("Could not insert single-step breakpoint at %s"),
10784 paddress (gdbarch, next_pc));
10787 /* Remove and delete any breakpoints used for software single step. */
10790 remove_single_step_breakpoints (void)
10792 gdb_assert (single_step_breakpoints[0] != NULL);
10794 /* See insert_single_step_breakpoint for more about this deprecated
10796 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
10797 single_step_breakpoints[0]);
10798 single_step_gdbarch[0] = NULL;
10799 single_step_breakpoints[0] = NULL;
10801 if (single_step_breakpoints[1] != NULL)
10803 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
10804 single_step_breakpoints[1]);
10805 single_step_gdbarch[1] = NULL;
10806 single_step_breakpoints[1] = NULL;
10810 /* Delete software single step breakpoints without removing them from
10811 the inferior. This is intended to be used if the inferior's address
10812 space where they were inserted is already gone, e.g. after exit or
10816 cancel_single_step_breakpoints (void)
10820 for (i = 0; i < 2; i++)
10821 if (single_step_breakpoints[i])
10823 xfree (single_step_breakpoints[i]);
10824 single_step_breakpoints[i] = NULL;
10825 single_step_gdbarch[i] = NULL;
10829 /* Detach software single-step breakpoints from INFERIOR_PTID without
10833 detach_single_step_breakpoints (void)
10837 for (i = 0; i < 2; i++)
10838 if (single_step_breakpoints[i])
10839 target_remove_breakpoint (single_step_gdbarch[i],
10840 single_step_breakpoints[i]);
10843 /* Check whether a software single-step breakpoint is inserted at PC. */
10846 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
10851 for (i = 0; i < 2; i++)
10853 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
10855 && breakpoint_address_match (bp_tgt->placed_address_space,
10856 bp_tgt->placed_address,
10864 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10865 non-zero otherwise. */
10867 is_syscall_catchpoint_enabled (struct breakpoint *bp)
10869 if (syscall_catchpoint_p (bp)
10870 && bp->enable_state != bp_disabled
10871 && bp->enable_state != bp_call_disabled)
10878 catch_syscall_enabled (void)
10880 struct inferior *inf = current_inferior ();
10882 return inf->total_syscalls_count != 0;
10886 catching_syscall_number (int syscall_number)
10888 struct breakpoint *bp;
10890 ALL_BREAKPOINTS (bp)
10891 if (is_syscall_catchpoint_enabled (bp))
10893 if (bp->syscalls_to_be_caught)
10897 VEC_iterate (int, bp->syscalls_to_be_caught, i, iter);
10899 if (syscall_number == iter)
10909 /* Complete syscall names. Used by "catch syscall". */
10911 catch_syscall_completer (struct cmd_list_element *cmd,
10912 char *text, char *word)
10914 const char **list = get_syscall_names ();
10916 return (list == NULL) ? NULL : complete_on_enum (list, text, word);
10919 /* Tracepoint-specific operations. */
10921 /* Set tracepoint count to NUM. */
10923 set_tracepoint_count (int num)
10925 tracepoint_count = num;
10926 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
10930 trace_command (char *arg, int from_tty)
10932 if (create_breakpoint (get_current_arch (),
10934 NULL, 0, 1 /* parse arg */,
10936 bp_tracepoint /* type_wanted */,
10937 0 /* Ignore count */,
10938 pending_break_support,
10942 set_tracepoint_count (breakpoint_count);
10946 ftrace_command (char *arg, int from_tty)
10948 if (create_breakpoint (get_current_arch (),
10950 NULL, 0, 1 /* parse arg */,
10952 bp_fast_tracepoint /* type_wanted */,
10953 0 /* Ignore count */,
10954 pending_break_support,
10958 set_tracepoint_count (breakpoint_count);
10961 /* strace command implementation. Creates a static tracepoint. */
10964 strace_command (char *arg, int from_tty)
10966 if (create_breakpoint (get_current_arch (),
10968 NULL, 0, 1 /* parse arg */,
10970 bp_static_tracepoint /* type_wanted */,
10971 0 /* Ignore count */,
10972 pending_break_support,
10976 set_tracepoint_count (breakpoint_count);
10979 /* Set up a fake reader function that gets command lines from a linked
10980 list that was acquired during tracepoint uploading. */
10982 static struct uploaded_tp *this_utp;
10983 static int next_cmd;
10986 read_uploaded_action (void)
10990 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
10997 /* Given information about a tracepoint as recorded on a target (which
10998 can be either a live system or a trace file), attempt to create an
10999 equivalent GDB tracepoint. This is not a reliable process, since
11000 the target does not necessarily have all the information used when
11001 the tracepoint was originally defined. */
11003 struct breakpoint *
11004 create_tracepoint_from_upload (struct uploaded_tp *utp)
11006 char *addr_str, small_buf[100];
11007 struct breakpoint *tp;
11009 if (utp->at_string)
11010 addr_str = utp->at_string;
11013 /* In the absence of a source location, fall back to raw
11014 address. Since there is no way to confirm that the address
11015 means the same thing as when the trace was started, warn the
11017 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
11019 sprintf (small_buf, "*%s", hex_string (utp->addr));
11020 addr_str = small_buf;
11023 /* There's not much we can do with a sequence of bytecodes. */
11024 if (utp->cond && !utp->cond_string)
11025 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
11028 if (!create_breakpoint (get_current_arch (),
11030 utp->cond_string, -1, 0 /* parse cond/thread */,
11032 utp->type /* type_wanted */,
11033 0 /* Ignore count */,
11034 pending_break_support,
11037 utp->enabled /* enabled */))
11040 set_tracepoint_count (breakpoint_count);
11042 /* Get the tracepoint we just created. */
11043 tp = get_tracepoint (tracepoint_count);
11044 gdb_assert (tp != NULL);
11048 sprintf (small_buf, "%d %d", utp->pass, tp->number);
11050 trace_pass_command (small_buf, 0);
11053 /* If we have uploaded versions of the original commands, set up a
11054 special-purpose "reader" function and call the usual command line
11055 reader, then pass the result to the breakpoint command-setting
11057 if (!VEC_empty (char_ptr, utp->cmd_strings))
11059 struct command_line *cmd_list;
11064 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
11066 breakpoint_set_commands (tp, cmd_list);
11068 else if (!VEC_empty (char_ptr, utp->actions)
11069 || !VEC_empty (char_ptr, utp->step_actions))
11070 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
11076 /* Print information on tracepoint number TPNUM_EXP, or all if
11080 tracepoints_info (char *tpnum_exp, int from_tty)
11082 int tpnum = -1, num_printed;
11085 tpnum = parse_and_eval_long (tpnum_exp);
11087 num_printed = breakpoint_1 (tpnum, 0, is_tracepoint);
11089 if (num_printed == 0)
11092 ui_out_message (uiout, 0, "No tracepoints.\n");
11094 ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum);
11097 default_collect_info ();
11100 /* The 'enable trace' command enables tracepoints.
11101 Not supported by all targets. */
11103 enable_trace_command (char *args, int from_tty)
11105 enable_command (args, from_tty);
11108 /* The 'disable trace' command disables tracepoints.
11109 Not supported by all targets. */
11111 disable_trace_command (char *args, int from_tty)
11113 disable_command (args, from_tty);
11116 /* Remove a tracepoint (or all if no argument) */
11118 delete_trace_command (char *arg, int from_tty)
11120 struct breakpoint *b, *temp;
11126 int breaks_to_delete = 0;
11128 /* Delete all breakpoints if no argument.
11129 Do not delete internal or call-dummy breakpoints, these
11130 have to be deleted with an explicit breakpoint number argument. */
11131 ALL_TRACEPOINTS (b)
11133 if (b->number >= 0)
11135 breaks_to_delete = 1;
11140 /* Ask user only if there are some breakpoints to delete. */
11142 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
11144 ALL_BREAKPOINTS_SAFE (b, temp)
11146 if (is_tracepoint (b)
11148 delete_breakpoint (b);
11153 map_breakpoint_numbers (arg, do_delete_breakpoint, NULL);
11156 /* Set passcount for tracepoint.
11158 First command argument is passcount, second is tracepoint number.
11159 If tracepoint number omitted, apply to most recently defined.
11160 Also accepts special argument "all". */
11163 trace_pass_command (char *args, int from_tty)
11165 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
11166 unsigned int count;
11169 if (args == 0 || *args == 0)
11170 error (_("passcount command requires an argument (count + optional TP num)"));
11172 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
11174 while (*args && isspace ((int) *args))
11177 if (*args && strncasecmp (args, "all", 3) == 0)
11179 args += 3; /* Skip special argument "all". */
11182 error (_("Junk at end of arguments."));
11185 t1 = get_tracepoint_by_number (&args, 1, 1);
11191 ALL_TRACEPOINTS (t2)
11192 if (t1 == (struct breakpoint *) -1 || t1 == t2)
11194 t2->pass_count = count;
11195 observer_notify_tracepoint_modified (t2->number);
11197 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
11198 t2->number, count);
11200 if (! all && *args)
11201 t1 = get_tracepoint_by_number (&args, 1, 0);
11207 struct breakpoint *
11208 get_tracepoint (int num)
11210 struct breakpoint *t;
11212 ALL_TRACEPOINTS (t)
11213 if (t->number == num)
11219 /* Find the tracepoint with the given target-side number (which may be
11220 different from the tracepoint number after disconnecting and
11223 struct breakpoint *
11224 get_tracepoint_by_number_on_target (int num)
11226 struct breakpoint *t;
11228 ALL_TRACEPOINTS (t)
11229 if (t->number_on_target == num)
11235 /* Utility: parse a tracepoint number and look it up in the list.
11236 If MULTI_P is true, there might be a range of tracepoints in ARG.
11237 if OPTIONAL_P is true, then if the argument is missing, the most
11238 recent tracepoint (tracepoint_count) is returned. */
11239 struct breakpoint *
11240 get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
11242 extern int tracepoint_count;
11243 struct breakpoint *t;
11245 char *instring = arg == NULL ? NULL : *arg;
11247 if (arg == NULL || *arg == NULL || ! **arg)
11250 tpnum = tracepoint_count;
11252 error_no_arg (_("tracepoint number"));
11255 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
11259 if (instring && *instring)
11260 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11263 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
11267 ALL_TRACEPOINTS (t)
11268 if (t->number == tpnum)
11273 /* FIXME: if we are in the middle of a range we don't want to give
11274 a message. The current interface to get_number_or_range doesn't
11275 allow us to discover this. */
11276 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
11280 /* Save information on user settable breakpoints (watchpoints, etc) to
11281 a new script file named FILENAME. If FILTER is non-NULL, call it
11282 on each breakpoint and only include the ones for which it returns
11286 save_breakpoints (char *filename, int from_tty,
11287 int (*filter) (const struct breakpoint *))
11289 struct breakpoint *tp;
11292 struct cleanup *cleanup;
11293 struct ui_file *fp;
11294 int extra_trace_bits = 0;
11296 if (filename == 0 || *filename == 0)
11297 error (_("Argument required (file name in which to save)"));
11299 /* See if we have anything to save. */
11300 ALL_BREAKPOINTS (tp)
11302 /* Skip internal and momentary breakpoints. */
11303 if (!user_settable_breakpoint (tp))
11306 /* If we have a filter, only save the breakpoints it accepts. */
11307 if (filter && !filter (tp))
11312 if (is_tracepoint (tp))
11314 extra_trace_bits = 1;
11316 /* We can stop searching. */
11323 warning (_("Nothing to save."));
11327 pathname = tilde_expand (filename);
11328 cleanup = make_cleanup (xfree, pathname);
11329 fp = gdb_fopen (pathname, "w");
11331 error (_("Unable to open file '%s' for saving (%s)"),
11332 filename, safe_strerror (errno));
11333 make_cleanup_ui_file_delete (fp);
11335 if (extra_trace_bits)
11336 save_trace_state_variables (fp);
11338 ALL_BREAKPOINTS (tp)
11340 /* Skip internal and momentary breakpoints. */
11341 if (!user_settable_breakpoint (tp))
11344 /* If we have a filter, only save the breakpoints it accepts. */
11345 if (filter && !filter (tp))
11348 if (tp->ops != NULL)
11349 (tp->ops->print_recreate) (tp, fp);
11352 if (tp->type == bp_fast_tracepoint)
11353 fprintf_unfiltered (fp, "ftrace");
11354 if (tp->type == bp_static_tracepoint)
11355 fprintf_unfiltered (fp, "strace");
11356 else if (tp->type == bp_tracepoint)
11357 fprintf_unfiltered (fp, "trace");
11358 else if (tp->type == bp_breakpoint && tp->disposition == disp_del)
11359 fprintf_unfiltered (fp, "tbreak");
11360 else if (tp->type == bp_breakpoint)
11361 fprintf_unfiltered (fp, "break");
11362 else if (tp->type == bp_hardware_breakpoint
11363 && tp->disposition == disp_del)
11364 fprintf_unfiltered (fp, "thbreak");
11365 else if (tp->type == bp_hardware_breakpoint)
11366 fprintf_unfiltered (fp, "hbreak");
11367 else if (tp->type == bp_watchpoint)
11368 fprintf_unfiltered (fp, "watch");
11369 else if (tp->type == bp_hardware_watchpoint)
11370 fprintf_unfiltered (fp, "watch");
11371 else if (tp->type == bp_read_watchpoint)
11372 fprintf_unfiltered (fp, "rwatch");
11373 else if (tp->type == bp_access_watchpoint)
11374 fprintf_unfiltered (fp, "awatch");
11376 internal_error (__FILE__, __LINE__,
11377 _("unhandled breakpoint type %d"), (int) tp->type);
11379 if (tp->exp_string)
11380 fprintf_unfiltered (fp, " %s", tp->exp_string);
11381 else if (tp->addr_string)
11382 fprintf_unfiltered (fp, " %s", tp->addr_string);
11387 sprintf_vma (tmp, tp->loc->address);
11388 fprintf_unfiltered (fp, " *0x%s", tmp);
11392 if (tp->thread != -1)
11393 fprintf_unfiltered (fp, " thread %d", tp->thread);
11396 fprintf_unfiltered (fp, " task %d", tp->task);
11398 fprintf_unfiltered (fp, "\n");
11400 /* Note, we can't rely on tp->number for anything, as we can't
11401 assume the recreated breakpoint numbers will match. Use $bpnum
11404 if (tp->cond_string)
11405 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
11407 if (tp->ignore_count)
11408 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
11410 if (tp->pass_count)
11411 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
11415 volatile struct gdb_exception ex;
11417 fprintf_unfiltered (fp, " commands\n");
11419 ui_out_redirect (uiout, fp);
11420 TRY_CATCH (ex, RETURN_MASK_ERROR)
11422 print_command_lines (uiout, tp->commands->commands, 2);
11424 ui_out_redirect (uiout, NULL);
11427 throw_exception (ex);
11429 fprintf_unfiltered (fp, " end\n");
11432 if (tp->enable_state == bp_disabled)
11433 fprintf_unfiltered (fp, "disable\n");
11435 /* If this is a multi-location breakpoint, check if the locations
11436 should be individually disabled. Watchpoint locations are
11437 special, and not user visible. */
11438 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
11440 struct bp_location *loc;
11443 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
11445 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
11449 if (extra_trace_bits && *default_collect)
11450 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
11452 do_cleanups (cleanup);
11454 printf_filtered (_("Saved to file '%s'.\n"), filename);
11457 /* The `save breakpoints' command. */
11460 save_breakpoints_command (char *args, int from_tty)
11462 save_breakpoints (args, from_tty, NULL);
11465 /* The `save tracepoints' command. */
11468 save_tracepoints_command (char *args, int from_tty)
11470 save_breakpoints (args, from_tty, is_tracepoint);
11473 /* Create a vector of all tracepoints. */
11475 VEC(breakpoint_p) *
11478 VEC(breakpoint_p) *tp_vec = 0;
11479 struct breakpoint *tp;
11481 ALL_TRACEPOINTS (tp)
11483 VEC_safe_push (breakpoint_p, tp_vec, tp);
11490 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11491 It is defined as a macro to prevent duplication.
11492 COMMAND should be a string constant containing the name of the command. */
11493 #define BREAK_ARGS_HELP(command) \
11494 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11495 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11496 If a line number is specified, break at start of code for that line.\n\
11497 If a function is specified, break at start of code for that function.\n\
11498 If an address is specified, break at that exact address.\n\
11499 With no LOCATION, uses current execution address of the selected\n\
11500 stack frame. This is useful for breaking on return to a stack frame.\n\
11502 THREADNUM is the number from \"info threads\".\n\
11503 CONDITION is a boolean expression.\n\
11505 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
11507 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11509 /* List of subcommands for "catch". */
11510 static struct cmd_list_element *catch_cmdlist;
11512 /* List of subcommands for "tcatch". */
11513 static struct cmd_list_element *tcatch_cmdlist;
11515 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11516 lists, and pass some additional user data to the command function. */
11518 add_catch_command (char *name, char *docstring,
11519 void (*sfunc) (char *args, int from_tty,
11520 struct cmd_list_element *command),
11521 char **(*completer) (struct cmd_list_element *cmd,
11522 char *text, char *word),
11523 void *user_data_catch,
11524 void *user_data_tcatch)
11526 struct cmd_list_element *command;
11528 command = add_cmd (name, class_breakpoint, NULL, docstring,
11530 set_cmd_sfunc (command, sfunc);
11531 set_cmd_context (command, user_data_catch);
11532 set_cmd_completer (command, completer);
11534 command = add_cmd (name, class_breakpoint, NULL, docstring,
11536 set_cmd_sfunc (command, sfunc);
11537 set_cmd_context (command, user_data_tcatch);
11538 set_cmd_completer (command, completer);
11542 clear_syscall_counts (struct inferior *inf)
11544 inf->total_syscalls_count = 0;
11545 inf->any_syscall_count = 0;
11546 VEC_free (int, inf->syscalls_counts);
11550 save_command (char *arg, int from_tty)
11552 printf_unfiltered (_("\
11553 \"save\" must be followed by the name of a save subcommand.\n"));
11554 help_list (save_cmdlist, "save ", -1, gdb_stdout);
11558 _initialize_breakpoint (void)
11560 struct cmd_list_element *c;
11562 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
11563 observer_attach_inferior_exit (clear_syscall_counts);
11564 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
11566 breakpoint_chain = 0;
11567 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11568 before a breakpoint is set. */
11569 breakpoint_count = 0;
11571 tracepoint_count = 0;
11573 add_com ("ignore", class_breakpoint, ignore_command, _("\
11574 Set ignore-count of breakpoint number N to COUNT.\n\
11575 Usage is `ignore N COUNT'."));
11577 add_com_alias ("bc", "ignore", class_breakpoint, 1);
11579 add_com ("commands", class_breakpoint, commands_command, _("\
11580 Set commands to be executed when a breakpoint is hit.\n\
11581 Give breakpoint number as argument after \"commands\".\n\
11582 With no argument, the targeted breakpoint is the last one set.\n\
11583 The commands themselves follow starting on the next line.\n\
11584 Type a line containing \"end\" to indicate the end of them.\n\
11585 Give \"silent\" as the first line to make the breakpoint silent;\n\
11586 then no output is printed when it is hit, except what the commands print."));
11588 add_com ("condition", class_breakpoint, condition_command, _("\
11589 Specify breakpoint number N to break only if COND is true.\n\
11590 Usage is `condition N COND', where N is an integer and COND is an\n\
11591 expression to be evaluated whenever breakpoint N is reached."));
11593 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
11594 Set a temporary breakpoint.\n\
11595 Like \"break\" except the breakpoint is only temporary,\n\
11596 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11597 by using \"enable delete\" on the breakpoint number.\n\
11599 BREAK_ARGS_HELP ("tbreak")));
11600 set_cmd_completer (c, location_completer);
11602 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
11603 Set a hardware assisted breakpoint.\n\
11604 Like \"break\" except the breakpoint requires hardware support,\n\
11605 some target hardware may not have this support.\n\
11607 BREAK_ARGS_HELP ("hbreak")));
11608 set_cmd_completer (c, location_completer);
11610 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
11611 Set a temporary hardware assisted breakpoint.\n\
11612 Like \"hbreak\" except the breakpoint is only temporary,\n\
11613 so it will be deleted when hit.\n\
11615 BREAK_ARGS_HELP ("thbreak")));
11616 set_cmd_completer (c, location_completer);
11618 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
11619 Enable some breakpoints.\n\
11620 Give breakpoint numbers (separated by spaces) as arguments.\n\
11621 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11622 This is used to cancel the effect of the \"disable\" command.\n\
11623 With a subcommand you can enable temporarily."),
11624 &enablelist, "enable ", 1, &cmdlist);
11626 add_com ("ab", class_breakpoint, enable_command, _("\
11627 Enable some breakpoints.\n\
11628 Give breakpoint numbers (separated by spaces) as arguments.\n\
11629 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11630 This is used to cancel the effect of the \"disable\" command.\n\
11631 With a subcommand you can enable temporarily."));
11633 add_com_alias ("en", "enable", class_breakpoint, 1);
11635 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
11636 Enable some breakpoints.\n\
11637 Give breakpoint numbers (separated by spaces) as arguments.\n\
11638 This is used to cancel the effect of the \"disable\" command.\n\
11639 May be abbreviated to simply \"enable\".\n"),
11640 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
11642 add_cmd ("once", no_class, enable_once_command, _("\
11643 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11644 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11647 add_cmd ("delete", no_class, enable_delete_command, _("\
11648 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11649 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11652 add_cmd ("delete", no_class, enable_delete_command, _("\
11653 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11654 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11657 add_cmd ("once", no_class, enable_once_command, _("\
11658 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11659 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11662 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
11663 Disable some breakpoints.\n\
11664 Arguments are breakpoint numbers with spaces in between.\n\
11665 To disable all breakpoints, give no argument.\n\
11666 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11667 &disablelist, "disable ", 1, &cmdlist);
11668 add_com_alias ("dis", "disable", class_breakpoint, 1);
11669 add_com_alias ("disa", "disable", class_breakpoint, 1);
11671 add_com ("sb", class_breakpoint, disable_command, _("\
11672 Disable some breakpoints.\n\
11673 Arguments are breakpoint numbers with spaces in between.\n\
11674 To disable all breakpoints, give no argument.\n\
11675 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11677 add_cmd ("breakpoints", class_alias, disable_command, _("\
11678 Disable some breakpoints.\n\
11679 Arguments are breakpoint numbers with spaces in between.\n\
11680 To disable all breakpoints, give no argument.\n\
11681 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11682 This command may be abbreviated \"disable\"."),
11685 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
11686 Delete some breakpoints or auto-display expressions.\n\
11687 Arguments are breakpoint numbers with spaces in between.\n\
11688 To delete all breakpoints, give no argument.\n\
11690 Also a prefix command for deletion of other GDB objects.\n\
11691 The \"unset\" command is also an alias for \"delete\"."),
11692 &deletelist, "delete ", 1, &cmdlist);
11693 add_com_alias ("d", "delete", class_breakpoint, 1);
11694 add_com_alias ("del", "delete", class_breakpoint, 1);
11696 add_com ("db", class_breakpoint, delete_command, _("\
11697 Delete some breakpoints.\n\
11698 Arguments are breakpoint numbers with spaces in between.\n\
11699 To delete all breakpoints, give no argument.\n"));
11701 add_cmd ("breakpoints", class_alias, delete_command, _("\
11702 Delete some breakpoints or auto-display expressions.\n\
11703 Arguments are breakpoint numbers with spaces in between.\n\
11704 To delete all breakpoints, give no argument.\n\
11705 This command may be abbreviated \"delete\"."),
11708 add_com ("clear", class_breakpoint, clear_command, _("\
11709 Clear breakpoint at specified line or function.\n\
11710 Argument may be line number, function name, or \"*\" and an address.\n\
11711 If line number is specified, all breakpoints in that line are cleared.\n\
11712 If function is specified, breakpoints at beginning of function are cleared.\n\
11713 If an address is specified, breakpoints at that address are cleared.\n\
11715 With no argument, clears all breakpoints in the line that the selected frame\n\
11716 is executing in.\n\
11718 See also the \"delete\" command which clears breakpoints by number."));
11720 c = add_com ("break", class_breakpoint, break_command, _("\
11721 Set breakpoint at specified line or function.\n"
11722 BREAK_ARGS_HELP ("break")));
11723 set_cmd_completer (c, location_completer);
11725 add_com_alias ("b", "break", class_run, 1);
11726 add_com_alias ("br", "break", class_run, 1);
11727 add_com_alias ("bre", "break", class_run, 1);
11728 add_com_alias ("brea", "break", class_run, 1);
11731 add_com_alias ("ba", "break", class_breakpoint, 1);
11735 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
11736 Break in function/address or break at a line in the current file."),
11737 &stoplist, "stop ", 1, &cmdlist);
11738 add_cmd ("in", class_breakpoint, stopin_command,
11739 _("Break in function or address."), &stoplist);
11740 add_cmd ("at", class_breakpoint, stopat_command,
11741 _("Break at a line in the current file."), &stoplist);
11742 add_com ("status", class_info, breakpoints_info, _("\
11743 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11744 The \"Type\" column indicates one of:\n\
11745 \tbreakpoint - normal breakpoint\n\
11746 \twatchpoint - watchpoint\n\
11747 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11748 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11749 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11750 address and file/line number respectively.\n\
11752 Convenience variable \"$_\" and default examine address for \"x\"\n\
11753 are set to the address of the last breakpoint listed unless the command\n\
11754 is prefixed with \"server \".\n\n\
11755 Convenience variable \"$bpnum\" contains the number of the last\n\
11756 breakpoint set."));
11759 add_info ("breakpoints", breakpoints_info, _("\
11760 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11761 The \"Type\" column indicates one of:\n\
11762 \tbreakpoint - normal breakpoint\n\
11763 \twatchpoint - watchpoint\n\
11764 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11765 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11766 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11767 address and file/line number respectively.\n\
11769 Convenience variable \"$_\" and default examine address for \"x\"\n\
11770 are set to the address of the last breakpoint listed unless the command\n\
11771 is prefixed with \"server \".\n\n\
11772 Convenience variable \"$bpnum\" contains the number of the last\n\
11773 breakpoint set."));
11775 add_info_alias ("b", "breakpoints", 1);
11778 add_com ("lb", class_breakpoint, breakpoints_info, _("\
11779 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11780 The \"Type\" column indicates one of:\n\
11781 \tbreakpoint - normal breakpoint\n\
11782 \twatchpoint - watchpoint\n\
11783 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11784 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11785 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11786 address and file/line number respectively.\n\
11788 Convenience variable \"$_\" and default examine address for \"x\"\n\
11789 are set to the address of the last breakpoint listed unless the command\n\
11790 is prefixed with \"server \".\n\n\
11791 Convenience variable \"$bpnum\" contains the number of the last\n\
11792 breakpoint set."));
11794 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
11795 Status of all breakpoints, or breakpoint number NUMBER.\n\
11796 The \"Type\" column indicates one of:\n\
11797 \tbreakpoint - normal breakpoint\n\
11798 \twatchpoint - watchpoint\n\
11799 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11800 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11801 \tuntil - internal breakpoint used by the \"until\" command\n\
11802 \tfinish - internal breakpoint used by the \"finish\" command\n\
11803 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11804 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11805 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11806 address and file/line number respectively.\n\
11808 Convenience variable \"$_\" and default examine address for \"x\"\n\
11809 are set to the address of the last breakpoint listed unless the command\n\
11810 is prefixed with \"server \".\n\n\
11811 Convenience variable \"$bpnum\" contains the number of the last\n\
11813 &maintenanceinfolist);
11815 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
11816 Set catchpoints to catch events."),
11817 &catch_cmdlist, "catch ",
11818 0/*allow-unknown*/, &cmdlist);
11820 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
11821 Set temporary catchpoints to catch events."),
11822 &tcatch_cmdlist, "tcatch ",
11823 0/*allow-unknown*/, &cmdlist);
11825 /* Add catch and tcatch sub-commands. */
11826 add_catch_command ("catch", _("\
11827 Catch an exception, when caught.\n\
11828 With an argument, catch only exceptions with the given name."),
11829 catch_catch_command,
11833 add_catch_command ("throw", _("\
11834 Catch an exception, when thrown.\n\
11835 With an argument, catch only exceptions with the given name."),
11836 catch_throw_command,
11840 add_catch_command ("fork", _("Catch calls to fork."),
11841 catch_fork_command_1,
11843 (void *) (uintptr_t) catch_fork_permanent,
11844 (void *) (uintptr_t) catch_fork_temporary);
11845 add_catch_command ("vfork", _("Catch calls to vfork."),
11846 catch_fork_command_1,
11848 (void *) (uintptr_t) catch_vfork_permanent,
11849 (void *) (uintptr_t) catch_vfork_temporary);
11850 add_catch_command ("exec", _("Catch calls to exec."),
11851 catch_exec_command_1,
11855 add_catch_command ("syscall", _("\
11856 Catch system calls by their names and/or numbers.\n\
11857 Arguments say which system calls to catch. If no arguments\n\
11858 are given, every system call will be caught.\n\
11859 Arguments, if given, should be one or more system call names\n\
11860 (if your system supports that), or system call numbers."),
11861 catch_syscall_command_1,
11862 catch_syscall_completer,
11865 add_catch_command ("exception", _("\
11866 Catch Ada exceptions, when raised.\n\
11867 With an argument, catch only exceptions with the given name."),
11868 catch_ada_exception_command,
11872 add_catch_command ("assert", _("\
11873 Catch failed Ada assertions, when raised.\n\
11874 With an argument, catch only exceptions with the given name."),
11875 catch_assert_command,
11880 c = add_com ("watch", class_breakpoint, watch_command, _("\
11881 Set a watchpoint for an expression.\n\
11882 A watchpoint stops execution of your program whenever the value of\n\
11883 an expression changes."));
11884 set_cmd_completer (c, expression_completer);
11886 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
11887 Set a read watchpoint for an expression.\n\
11888 A watchpoint stops execution of your program whenever the value of\n\
11889 an expression is read."));
11890 set_cmd_completer (c, expression_completer);
11892 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
11893 Set a watchpoint for an expression.\n\
11894 A watchpoint stops execution of your program whenever the value of\n\
11895 an expression is either read or written."));
11896 set_cmd_completer (c, expression_completer);
11898 add_info ("watchpoints", watchpoints_info, _("\
11899 Status of watchpoints, or watchpoint number NUMBER."));
11903 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11904 respond to changes - contrary to the description. */
11905 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
11906 &can_use_hw_watchpoints, _("\
11907 Set debugger's willingness to use watchpoint hardware."), _("\
11908 Show debugger's willingness to use watchpoint hardware."), _("\
11909 If zero, gdb will not use hardware for new watchpoints, even if\n\
11910 such is available. (However, any hardware watchpoints that were\n\
11911 created before setting this to nonzero, will continue to use watchpoint\n\
11914 show_can_use_hw_watchpoints,
11915 &setlist, &showlist);
11917 can_use_hw_watchpoints = 1;
11919 /* Tracepoint manipulation commands. */
11921 c = add_com ("trace", class_breakpoint, trace_command, _("\
11922 Set a tracepoint at specified line or function.\n\
11924 BREAK_ARGS_HELP ("trace") "\n\
11925 Do \"help tracepoints\" for info on other tracepoint commands."));
11926 set_cmd_completer (c, location_completer);
11928 add_com_alias ("tp", "trace", class_alias, 0);
11929 add_com_alias ("tr", "trace", class_alias, 1);
11930 add_com_alias ("tra", "trace", class_alias, 1);
11931 add_com_alias ("trac", "trace", class_alias, 1);
11933 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
11934 Set a fast tracepoint at specified line or function.\n\
11936 BREAK_ARGS_HELP ("ftrace") "\n\
11937 Do \"help tracepoints\" for info on other tracepoint commands."));
11938 set_cmd_completer (c, location_completer);
11940 c = add_com ("strace", class_breakpoint, strace_command, _("\
11941 Set a static tracepoint at specified line, function or marker.\n\
11943 strace [LOCATION] [if CONDITION]\n\
11944 LOCATION may be a line number, function name, \"*\" and an address,\n\
11945 or -m MARKER_ID.\n\
11946 If a line number is specified, probe the marker at start of code\n\
11947 for that line. If a function is specified, probe the marker at start\n\
11948 of code for that function. If an address is specified, probe the marker\n\
11949 at that exact address. If a marker id is specified, probe the marker\n\
11950 with that name. With no LOCATION, uses current execution address of\n\
11951 the selected stack frame.\n\
11952 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
11953 This collects arbitrary user data passed in the probe point call to the\n\
11954 tracing library. You can inspect it when analyzing the trace buffer,\n\
11955 by printing the $_sdata variable like any other convenience variable.\n\
11957 CONDITION is a boolean expression.\n\
11959 Multiple tracepoints at one place are permitted, and useful if conditional.\n\
11961 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
11962 Do \"help tracepoints\" for info on other tracepoint commands."));
11963 set_cmd_completer (c, location_completer);
11965 add_info ("tracepoints", tracepoints_info, _("\
11966 Status of tracepoints, or tracepoint number NUMBER.\n\
11967 Convenience variable \"$tpnum\" contains the number of the\n\
11968 last tracepoint set."));
11970 add_info_alias ("tp", "tracepoints", 1);
11972 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
11973 Delete specified tracepoints.\n\
11974 Arguments are tracepoint numbers, separated by spaces.\n\
11975 No argument means delete all tracepoints."),
11978 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
11979 Disable specified tracepoints.\n\
11980 Arguments are tracepoint numbers, separated by spaces.\n\
11981 No argument means disable all tracepoints."),
11983 deprecate_cmd (c, "disable");
11985 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
11986 Enable specified tracepoints.\n\
11987 Arguments are tracepoint numbers, separated by spaces.\n\
11988 No argument means enable all tracepoints."),
11990 deprecate_cmd (c, "enable");
11992 add_com ("passcount", class_trace, trace_pass_command, _("\
11993 Set the passcount for a tracepoint.\n\
11994 The trace will end when the tracepoint has been passed 'count' times.\n\
11995 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11996 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11998 add_prefix_cmd ("save", class_breakpoint, save_command,
11999 _("Save breakpoint definitions as a script."),
12000 &save_cmdlist, "save ",
12001 0/*allow-unknown*/, &cmdlist);
12003 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
12004 Save current breakpoint definitions as a script.\n\
12005 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12006 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12007 session to restore them."),
12009 set_cmd_completer (c, filename_completer);
12011 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
12012 Save current tracepoint definitions as a script.\n\
12013 Use the 'source' command in another debug session to restore them."),
12015 set_cmd_completer (c, filename_completer);
12017 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
12018 deprecate_cmd (c, "save tracepoints");
12020 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
12021 Breakpoint specific settings\n\
12022 Configure various breakpoint-specific variables such as\n\
12023 pending breakpoint behavior"),
12024 &breakpoint_set_cmdlist, "set breakpoint ",
12025 0/*allow-unknown*/, &setlist);
12026 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
12027 Breakpoint specific settings\n\
12028 Configure various breakpoint-specific variables such as\n\
12029 pending breakpoint behavior"),
12030 &breakpoint_show_cmdlist, "show breakpoint ",
12031 0/*allow-unknown*/, &showlist);
12033 add_setshow_auto_boolean_cmd ("pending", no_class,
12034 &pending_break_support, _("\
12035 Set debugger's behavior regarding pending breakpoints."), _("\
12036 Show debugger's behavior regarding pending breakpoints."), _("\
12037 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12038 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12039 an error. If auto, an unrecognized breakpoint location results in a\n\
12040 user-query to see if a pending breakpoint should be created."),
12042 show_pending_break_support,
12043 &breakpoint_set_cmdlist,
12044 &breakpoint_show_cmdlist);
12046 pending_break_support = AUTO_BOOLEAN_AUTO;
12048 add_setshow_boolean_cmd ("auto-hw", no_class,
12049 &automatic_hardware_breakpoints, _("\
12050 Set automatic usage of hardware breakpoints."), _("\
12051 Show automatic usage of hardware breakpoints."), _("\
12052 If set, the debugger will automatically use hardware breakpoints for\n\
12053 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12054 a warning will be emitted for such breakpoints."),
12056 show_automatic_hardware_breakpoints,
12057 &breakpoint_set_cmdlist,
12058 &breakpoint_show_cmdlist);
12060 add_setshow_enum_cmd ("always-inserted", class_support,
12061 always_inserted_enums, &always_inserted_mode, _("\
12062 Set mode for inserting breakpoints."), _("\
12063 Show mode for inserting breakpoints."), _("\
12064 When this mode is off, breakpoints are inserted in inferior when it is\n\
12065 resumed, and removed when execution stops. When this mode is on,\n\
12066 breakpoints are inserted immediately and removed only when the user\n\
12067 deletes the breakpoint. When this mode is auto (which is the default),\n\
12068 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12069 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12070 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12071 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12073 &show_always_inserted_mode,
12074 &breakpoint_set_cmdlist,
12075 &breakpoint_show_cmdlist);
12077 automatic_hardware_breakpoints = 1;
12079 observer_attach_about_to_proceed (breakpoint_about_to_proceed);