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"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_once_command (char *, int);
84 static void disable_command (char *, int);
86 static void enable_command (char *, int);
88 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 /* This function is used in gdbtk sources and thus can not be made static. */
109 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
110 struct symtab_and_line
,
113 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
115 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
119 static void describe_other_breakpoints (struct gdbarch
*,
120 struct program_space
*, CORE_ADDR
,
121 struct obj_section
*, int);
123 static int breakpoint_address_match (struct address_space
*aspace1
,
125 struct address_space
*aspace2
,
128 static int watchpoint_locations_match (struct bp_location
*loc1
,
129 struct bp_location
*loc2
);
131 static void breakpoints_info (char *, int);
133 static void watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
137 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
147 static int get_number_trailer (char **, int);
156 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
157 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
159 static enum print_stop_action
print_it_typical (bpstat
);
161 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
163 static int watchpoint_check (void *);
165 static void maintenance_info_breakpoints (char *, int);
167 static int hw_breakpoint_used_count (void);
169 static int hw_watchpoint_used_count (enum bptype
, int *);
171 static void hbreak_command (char *, int);
173 static void thbreak_command (char *, int);
175 static void watch_command_1 (char *, int, int);
177 static void rwatch_command (char *, int);
179 static void awatch_command (char *, int);
181 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
183 static void stop_command (char *arg
, int from_tty
);
185 static void stopin_command (char *arg
, int from_tty
);
187 static void stopat_command (char *arg
, int from_tty
);
189 static char *ep_parse_optional_if_clause (char **arg
);
191 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
192 char *arg
, int tempflag
, int from_tty
);
194 static void tcatch_command (char *arg
, int from_tty
);
196 static void ep_skip_leading_whitespace (char **s
);
198 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
201 static void free_bp_location (struct bp_location
*loc
);
203 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
205 static void update_global_location_list (int);
207 static void update_global_location_list_nothrow (int);
209 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
211 static int is_watchpoint (const struct breakpoint
*bpt
);
213 static void insert_breakpoint_locations (void);
215 static int syscall_catchpoint_p (struct breakpoint
*b
);
217 static void tracepoints_info (char *, int);
219 static void delete_trace_command (char *, int);
221 static void enable_trace_command (char *, int);
223 static void disable_trace_command (char *, int);
225 static void trace_pass_command (char *, int);
227 /* A reference-counted struct command_line. This lets multiple
228 breakpoints share a single command list. */
229 struct counted_command_line
231 /* The reference count. */
234 /* The command list. */
235 struct command_line
*commands
;
238 struct command_line
*
239 breakpoint_commands (struct breakpoint
*b
)
241 return b
->commands
? b
->commands
->commands
: NULL
;
244 /* Flag indicating that a command has proceeded the inferior past the
245 current breakpoint. */
247 static int breakpoint_proceeded
;
250 bpdisp_text (enum bpdisp disp
)
252 /* NOTE: the following values are a part of MI protocol and represent
253 values of 'disp' field returned when inferior stops at a breakpoint. */
254 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
255 return bpdisps
[(int) disp
];
258 /* Prototypes for exported functions. */
259 /* If FALSE, gdb will not use hardware support for watchpoints, even
260 if such is available. */
261 static int can_use_hw_watchpoints
;
264 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
,
268 fprintf_filtered (file
, _("\
269 Debugger's willingness to use watchpoint hardware is %s.\n"),
273 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
274 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
275 for unrecognized breakpoint locations.
276 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
277 static enum auto_boolean pending_break_support
;
279 show_pending_break_support (struct ui_file
*file
, int from_tty
,
280 struct cmd_list_element
*c
,
283 fprintf_filtered (file
, _("\
284 Debugger's behavior regarding pending breakpoints is %s.\n"),
288 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
289 set with "break" but falling in read-only memory.
290 If 0, gdb will warn about such breakpoints, but won't automatically
291 use hardware breakpoints. */
292 static int automatic_hardware_breakpoints
;
294 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
295 struct cmd_list_element
*c
,
298 fprintf_filtered (file
, _("\
299 Automatic usage of hardware breakpoints is %s.\n"),
303 /* If on, gdb will keep breakpoints inserted even as inferior is
304 stopped, and immediately insert any new breakpoints. If off, gdb
305 will insert breakpoints into inferior only when resuming it, and
306 will remove breakpoints upon stop. If auto, GDB will behave as ON
307 if in non-stop mode, and as OFF if all-stop mode.*/
309 static const char always_inserted_auto
[] = "auto";
310 static const char always_inserted_on
[] = "on";
311 static const char always_inserted_off
[] = "off";
312 static const char *always_inserted_enums
[] = {
313 always_inserted_auto
,
318 static const char *always_inserted_mode
= always_inserted_auto
;
320 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
321 struct cmd_list_element
*c
, const char *value
)
323 if (always_inserted_mode
== always_inserted_auto
)
324 fprintf_filtered (file
, _("\
325 Always inserted breakpoint mode is %s (currently %s).\n"),
327 breakpoints_always_inserted_mode () ? "on" : "off");
329 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
333 breakpoints_always_inserted_mode (void)
335 return (always_inserted_mode
== always_inserted_on
336 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
339 void _initialize_breakpoint (void);
341 /* Are we executing breakpoint commands? */
342 static int executing_breakpoint_commands
;
344 /* Are overlay event breakpoints enabled? */
345 static int overlay_events_enabled
;
347 /* Walk the following statement or block through all breakpoints.
348 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
351 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
353 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
354 for (B = breakpoint_chain; \
355 B ? (TMP=B->next, 1): 0; \
358 /* Similar iterator for the low-level breakpoints. SAFE variant is not
359 provided so update_global_location_list must not be called while executing
360 the block of ALL_BP_LOCATIONS. */
362 #define ALL_BP_LOCATIONS(B,BP_TMP) \
363 for (BP_TMP = bp_location; \
364 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
367 /* Iterator for tracepoints only. */
369 #define ALL_TRACEPOINTS(B) \
370 for (B = breakpoint_chain; B; B = B->next) \
371 if (is_tracepoint (B))
373 /* Chains of all breakpoints defined. */
375 struct breakpoint
*breakpoint_chain
;
377 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
379 static struct bp_location
**bp_location
;
381 /* Number of elements of BP_LOCATION. */
383 static unsigned bp_location_count
;
385 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
386 for the current elements of BP_LOCATION which get a valid result from
387 bp_location_has_shadow. You can use it for roughly limiting the subrange of
388 BP_LOCATION to scan for shadow bytes for an address you need to read. */
390 static CORE_ADDR bp_location_placed_address_before_address_max
;
392 /* Maximum offset plus alignment between
393 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
394 the current elements of BP_LOCATION which get a valid result from
395 bp_location_has_shadow. You can use it for roughly limiting the subrange of
396 BP_LOCATION to scan for shadow bytes for an address you need to read. */
398 static CORE_ADDR bp_location_shadow_len_after_address_max
;
400 /* The locations that no longer correspond to any breakpoint,
401 unlinked from bp_location array, but for which a hit
402 may still be reported by a target. */
403 VEC(bp_location_p
) *moribund_locations
= NULL
;
405 /* Number of last breakpoint made. */
407 static int breakpoint_count
;
409 /* The value of `breakpoint_count' before the last command that
410 created breakpoints. If the last (break-like) command created more
411 than one breakpoint, then the difference between BREAKPOINT_COUNT
412 and PREV_BREAKPOINT_COUNT is more than one. */
413 static int prev_breakpoint_count
;
415 /* Number of last tracepoint made. */
417 static int tracepoint_count
;
419 static struct cmd_list_element
*breakpoint_set_cmdlist
;
420 static struct cmd_list_element
*breakpoint_show_cmdlist
;
421 static struct cmd_list_element
*save_cmdlist
;
423 /* Return whether a breakpoint is an active enabled breakpoint. */
425 breakpoint_enabled (struct breakpoint
*b
)
427 return (b
->enable_state
== bp_enabled
);
430 /* Set breakpoint count to NUM. */
433 set_breakpoint_count (int num
)
435 prev_breakpoint_count
= breakpoint_count
;
436 breakpoint_count
= num
;
437 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
440 /* Used by `start_rbreak_breakpoints' below, to record the current
441 breakpoint count before "rbreak" creates any breakpoint. */
442 static int rbreak_start_breakpoint_count
;
444 /* Called at the start an "rbreak" command to record the first
448 start_rbreak_breakpoints (void)
450 rbreak_start_breakpoint_count
= breakpoint_count
;
453 /* Called at the end of an "rbreak" command to record the last
457 end_rbreak_breakpoints (void)
459 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
462 /* Used in run_command to zero the hit count when a new run starts. */
465 clear_breakpoint_hit_counts (void)
467 struct breakpoint
*b
;
473 /* Allocate a new counted_command_line with reference count of 1.
474 The new structure owns COMMANDS. */
476 static struct counted_command_line
*
477 alloc_counted_command_line (struct command_line
*commands
)
479 struct counted_command_line
*result
480 = xmalloc (sizeof (struct counted_command_line
));
482 result
->commands
= commands
;
486 /* Increment reference count. This does nothing if CMD is NULL. */
489 incref_counted_command_line (struct counted_command_line
*cmd
)
495 /* Decrement reference count. If the reference count reaches 0,
496 destroy the counted_command_line. Sets *CMDP to NULL. This does
497 nothing if *CMDP is NULL. */
500 decref_counted_command_line (struct counted_command_line
**cmdp
)
504 if (--(*cmdp
)->refc
== 0)
506 free_command_lines (&(*cmdp
)->commands
);
513 /* A cleanup function that calls decref_counted_command_line. */
516 do_cleanup_counted_command_line (void *arg
)
518 decref_counted_command_line (arg
);
521 /* Create a cleanup that calls decref_counted_command_line on the
524 static struct cleanup
*
525 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
527 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
530 /* Default address, symtab and line to put a breakpoint at
531 for "break" command with no arg.
532 if default_breakpoint_valid is zero, the other three are
533 not valid, and "break" with no arg is an error.
535 This set by print_stack_frame, which calls set_default_breakpoint. */
537 int default_breakpoint_valid
;
538 CORE_ADDR default_breakpoint_address
;
539 struct symtab
*default_breakpoint_symtab
;
540 int default_breakpoint_line
;
541 struct program_space
*default_breakpoint_pspace
;
544 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
545 Advance *PP after the string and any trailing whitespace.
547 Currently the string can either be a number or "$" followed by the name
548 of a convenience variable. Making it an expression wouldn't work well
549 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
551 If the string is a NULL pointer, that denotes the last breakpoint.
553 TRAILER is a character which can be found after the number; most
554 commonly this is `-'. If you don't want a trailer, use \0. */
556 get_number_trailer (char **pp
, int trailer
)
558 int retval
= 0; /* default */
562 /* Empty line means refer to the last breakpoint. */
563 return breakpoint_count
;
566 /* Make a copy of the name, so we can null-terminate it
567 to pass to lookup_internalvar(). */
572 while (isalnum (*p
) || *p
== '_')
574 varname
= (char *) alloca (p
- start
+ 1);
575 strncpy (varname
, start
, p
- start
);
576 varname
[p
- start
] = '\0';
577 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
581 printf_filtered (_("Convenience variable must have integer value.\n"));
589 while (*p
>= '0' && *p
<= '9')
592 /* There is no number here. (e.g. "cond a == b"). */
594 /* Skip non-numeric token */
595 while (*p
&& !isspace((int) *p
))
597 /* Return zero, which caller must interpret as error. */
603 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
605 /* Trailing junk: return 0 and let caller print error msg. */
606 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
617 /* Like get_number_trailer, but don't allow a trailer. */
619 get_number (char **pp
)
621 return get_number_trailer (pp
, '\0');
624 /* Parse a number or a range.
625 * A number will be of the form handled by get_number.
626 * A range will be of the form <number1> - <number2>, and
627 * will represent all the integers between number1 and number2,
630 * While processing a range, this fuction is called iteratively;
631 * At each call it will return the next value in the range.
633 * At the beginning of parsing a range, the char pointer PP will
634 * be advanced past <number1> and left pointing at the '-' token.
635 * Subsequent calls will not advance the pointer until the range
636 * is completed. The call that completes the range will advance
637 * pointer PP past <number2>.
641 get_number_or_range (char **pp
)
643 static int last_retval
, end_value
;
644 static char *end_ptr
;
645 static int in_range
= 0;
649 /* Default case: pp is pointing either to a solo number,
650 or to the first number of a range. */
651 last_retval
= get_number_trailer (pp
, '-');
656 /* This is the start of a range (<number1> - <number2>).
657 Skip the '-', parse and remember the second number,
658 and also remember the end of the final token. */
662 while (isspace ((int) *end_ptr
))
663 end_ptr
++; /* skip white space */
664 end_value
= get_number (temp
);
665 if (end_value
< last_retval
)
667 error (_("inverted range"));
669 else if (end_value
== last_retval
)
671 /* degenerate range (number1 == number2). Advance the
672 token pointer so that the range will be treated as a
681 error (_("negative value"));
684 /* pp points to the '-' that betokens a range. All
685 number-parsing has already been done. Return the next
686 integer value (one greater than the saved previous value).
687 Do not advance the token pointer 'pp' until the end of range
690 if (++last_retval
== end_value
)
692 /* End of range reached; advance token pointer. */
700 /* Return the breakpoint with the specified number, or NULL
701 if the number does not refer to an existing breakpoint. */
704 get_breakpoint (int num
)
706 struct breakpoint
*b
;
709 if (b
->number
== num
)
718 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
721 struct bp_location
*loc
= b
->loc
;
723 for (; loc
; loc
= loc
->next
)
728 xfree (b
->cond_string
);
729 b
->cond_string
= NULL
;
736 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
741 /* I don't know if it matters whether this is the string the user
742 typed in or the decompiled expression. */
743 b
->cond_string
= xstrdup (arg
);
744 b
->condition_not_parsed
= 0;
746 if (is_watchpoint (b
))
748 innermost_block
= NULL
;
750 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
752 error (_("Junk at end of expression"));
753 b
->cond_exp_valid_block
= innermost_block
;
757 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
761 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
763 error (_("Junk at end of expression"));
767 breakpoints_changed ();
768 observer_notify_breakpoint_modified (b
->number
);
771 /* condition N EXP -- set break condition of breakpoint N to EXP. */
774 condition_command (char *arg
, int from_tty
)
776 struct breakpoint
*b
;
781 error_no_arg (_("breakpoint number"));
784 bnum
= get_number (&p
);
786 error (_("Bad breakpoint argument: '%s'"), arg
);
789 if (b
->number
== bnum
)
791 set_breakpoint_condition (b
, p
, from_tty
);
795 error (_("No breakpoint number %d."), bnum
);
798 /* Check that COMMAND do not contain commands that are suitable
799 only for tracepoints and not suitable for ordinary breakpoints.
800 Throw if any such commands is found.
803 check_no_tracepoint_commands (struct command_line
*commands
)
805 struct command_line
*c
;
806 for (c
= commands
; c
; c
= c
->next
)
810 if (c
->control_type
== while_stepping_control
)
811 error (_("The 'while-stepping' command can only be used for tracepoints"));
813 for (i
= 0; i
< c
->body_count
; ++i
)
814 check_no_tracepoint_commands ((c
->body_list
)[i
]);
816 /* Not that command parsing removes leading whitespace and comment
817 lines and also empty lines. So, we only need to check for
819 if (strstr (c
->line
, "collect ") == c
->line
)
820 error (_("The 'collect' command can only be used for tracepoints"));
822 if (strstr (c
->line
, "teval ") == c
->line
)
823 error (_("The 'teval' command can only be used for tracepoints"));
827 /* Encapsulate tests for different types of tracepoints. */
830 is_tracepoint (const struct breakpoint
*b
)
832 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
835 /* A helper function that validsates that COMMANDS are valid for a
836 breakpoint. This function will throw an exception if a problem is
840 validate_commands_for_breakpoint (struct breakpoint
*b
,
841 struct command_line
*commands
)
843 if (is_tracepoint (b
))
845 /* We need to verify that each top-level element of commands
846 is valid for tracepoints, that there's at most one while-stepping
847 element, and that while-stepping's body has valid tracing commands
848 excluding nested while-stepping. */
849 struct command_line
*c
;
850 struct command_line
*while_stepping
= 0;
851 for (c
= commands
; c
; c
= c
->next
)
854 if (c
->control_type
== while_stepping_control
)
856 if (b
->type
== bp_fast_tracepoint
)
857 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
860 error (_("The 'while-stepping' command can be used only once"));
867 struct command_line
*c2
;
869 gdb_assert (while_stepping
->body_count
== 1);
870 c2
= while_stepping
->body_list
[0];
871 for (; c2
; c2
= c2
->next
)
874 if (c2
->control_type
== while_stepping_control
)
875 error (_("The 'while-stepping' command cannot be nested"));
881 check_no_tracepoint_commands (commands
);
885 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
886 validate that only allowed commands are included.
890 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
892 validate_commands_for_breakpoint (b
, commands
);
894 decref_counted_command_line (&b
->commands
);
895 b
->commands
= alloc_counted_command_line (commands
);
896 breakpoints_changed ();
897 observer_notify_breakpoint_modified (b
->number
);
901 check_tracepoint_command (char *line
, void *closure
)
903 struct breakpoint
*b
= closure
;
904 validate_actionline (&line
, b
);
907 /* A structure used to pass information through
908 map_breakpoint_numbers. */
912 /* True if the command was typed at a tty. */
915 /* The breakpoint range spec. */
918 /* Non-NULL if the body of the commands are being read from this
919 already-parsed command. */
920 struct command_line
*control
;
922 /* The command lines read from the user, or NULL if they have not
924 struct counted_command_line
*cmd
;
927 /* A callback for map_breakpoint_numbers that sets the commands for
931 do_map_commands_command (struct breakpoint
*b
, void *data
)
933 struct commands_info
*info
= data
;
935 if (info
->cmd
== NULL
)
937 struct command_line
*l
;
939 if (info
->control
!= NULL
)
940 l
= copy_command_lines (info
->control
->body_list
[0]);
943 struct cleanup
*old_chain
;
946 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
949 old_chain
= make_cleanup (xfree
, str
);
951 l
= read_command_lines (str
,
954 ? check_tracepoint_command
: 0),
957 do_cleanups (old_chain
);
960 info
->cmd
= alloc_counted_command_line (l
);
963 /* If a breakpoint was on the list more than once, we don't need to
965 if (b
->commands
!= info
->cmd
)
967 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
968 incref_counted_command_line (info
->cmd
);
969 decref_counted_command_line (&b
->commands
);
970 b
->commands
= info
->cmd
;
971 breakpoints_changed ();
972 observer_notify_breakpoint_modified (b
->number
);
977 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
979 struct cleanup
*cleanups
;
980 struct commands_info info
;
982 info
.from_tty
= from_tty
;
983 info
.control
= control
;
985 /* If we read command lines from the user, then `info' will hold an
986 extra reference to the commands that we must clean up. */
987 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
989 if (arg
== NULL
|| !*arg
)
991 if (breakpoint_count
- prev_breakpoint_count
> 1)
992 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
993 else if (breakpoint_count
> 0)
994 arg
= xstrprintf ("%d", breakpoint_count
);
997 /* So that we don't try to free the incoming non-NULL
998 argument in the cleanup below. Mapping breakpoint
999 numbers will fail in this case. */
1004 /* The command loop has some static state, so we need to preserve
1006 arg
= xstrdup (arg
);
1009 make_cleanup (xfree
, arg
);
1013 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1015 if (info
.cmd
== NULL
)
1016 error (_("No breakpoints specified."));
1018 do_cleanups (cleanups
);
1022 commands_command (char *arg
, int from_tty
)
1024 commands_command_1 (arg
, from_tty
, NULL
);
1027 /* Like commands_command, but instead of reading the commands from
1028 input stream, takes them from an already parsed command structure.
1030 This is used by cli-script.c to DTRT with breakpoint commands
1031 that are part of if and while bodies. */
1032 enum command_control_type
1033 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1035 commands_command_1 (arg
, 0, cmd
);
1036 return simple_control
;
1039 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1042 bp_location_has_shadow (struct bp_location
*bl
)
1044 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1048 if (bl
->target_info
.shadow_len
== 0)
1049 /* bp isn't valid, or doesn't shadow memory. */
1054 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1055 by replacing any memory breakpoints with their shadowed contents.
1057 The range of shadowed area by each bp_location is:
1058 b->address - bp_location_placed_address_before_address_max
1059 up to b->address + bp_location_shadow_len_after_address_max
1060 The range we were requested to resolve shadows for is:
1061 memaddr ... memaddr + len
1062 Thus the safe cutoff boundaries for performance optimization are
1063 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1065 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1068 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1070 /* Left boundary, right boundary and median element of our binary search. */
1071 unsigned bc_l
, bc_r
, bc
;
1073 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1074 safe to report lower value but a failure to report higher one. */
1077 bc_r
= bp_location_count
;
1078 while (bc_l
+ 1 < bc_r
)
1080 struct bp_location
*b
;
1082 bc
= (bc_l
+ bc_r
) / 2;
1083 b
= bp_location
[bc
];
1085 /* Check first B->ADDRESS will not overflow due to the added constant.
1086 Then advance the left boundary only if we are sure the BC element can
1087 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1089 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1090 we cannot miss a breakpoint with its shadow range tail still reaching
1093 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1094 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1100 /* Now do full processing of the found relevant range of elements. */
1102 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1104 struct bp_location
*b
= bp_location
[bc
];
1105 CORE_ADDR bp_addr
= 0;
1109 if (b
->owner
->type
== bp_none
)
1110 warning (_("reading through apparently deleted breakpoint #%d?"),
1113 /* Performance optimization: any futher element can no longer affect BUF
1116 if (b
->address
>= bp_location_placed_address_before_address_max
1117 && memaddr
+ len
<= b
->address
1118 - bp_location_placed_address_before_address_max
)
1121 if (!bp_location_has_shadow (b
))
1123 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1124 current_program_space
->aspace
, 0))
1127 /* Addresses and length of the part of the breakpoint that
1129 bp_addr
= b
->target_info
.placed_address
;
1130 bp_size
= b
->target_info
.shadow_len
;
1132 if (bp_addr
+ bp_size
<= memaddr
)
1133 /* The breakpoint is entirely before the chunk of memory we
1137 if (bp_addr
>= memaddr
+ len
)
1138 /* The breakpoint is entirely after the chunk of memory we are
1142 /* Offset within shadow_contents. */
1143 if (bp_addr
< memaddr
)
1145 /* Only copy the second part of the breakpoint. */
1146 bp_size
-= memaddr
- bp_addr
;
1147 bptoffset
= memaddr
- bp_addr
;
1151 if (bp_addr
+ bp_size
> memaddr
+ len
)
1153 /* Only copy the first part of the breakpoint. */
1154 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1157 memcpy (buf
+ bp_addr
- memaddr
,
1158 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1163 /* A wrapper function for inserting catchpoints. */
1165 insert_catchpoint (struct ui_out
*uo
, void *args
)
1167 struct breakpoint
*b
= (struct breakpoint
*) args
;
1170 gdb_assert (b
->type
== bp_catchpoint
);
1171 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1176 /* Return true if BPT is of any hardware watchpoint kind. */
1179 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1181 return (bpt
->type
== bp_hardware_watchpoint
1182 || bpt
->type
== bp_read_watchpoint
1183 || bpt
->type
== bp_access_watchpoint
);
1186 /* Return true if BPT is of any watchpoint kind, hardware or
1190 is_watchpoint (const struct breakpoint
*bpt
)
1192 return (is_hardware_watchpoint (bpt
)
1193 || bpt
->type
== bp_watchpoint
);
1196 /* Find the current value of a watchpoint on EXP. Return the value in
1197 *VALP and *RESULTP and the chain of intermediate and final values
1198 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1201 If a memory error occurs while evaluating the expression, *RESULTP will
1202 be set to NULL. *RESULTP may be a lazy value, if the result could
1203 not be read from memory. It is used to determine whether a value
1204 is user-specified (we should watch the whole value) or intermediate
1205 (we should watch only the bit used to locate the final value).
1207 If the final value, or any intermediate value, could not be read
1208 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1209 set to any referenced values. *VALP will never be a lazy value.
1210 This is the value which we store in struct breakpoint.
1212 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1213 value chain. The caller must free the values individually. If
1214 VAL_CHAIN is NULL, all generated values will be left on the value
1218 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1219 struct value
**resultp
, struct value
**val_chain
)
1221 struct value
*mark
, *new_mark
, *result
;
1222 volatile struct gdb_exception ex
;
1230 /* Evaluate the expression. */
1231 mark
= value_mark ();
1234 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1236 result
= evaluate_expression (exp
);
1240 /* Ignore memory errors, we want watchpoints pointing at
1241 inaccessible memory to still be created; otherwise, throw the
1242 error to some higher catcher. */
1248 throw_exception (ex
);
1253 new_mark
= value_mark ();
1254 if (mark
== new_mark
)
1259 /* Make sure it's not lazy, so that after the target stops again we
1260 have a non-lazy previous value to compare with. */
1262 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1267 /* Return the chain of intermediate values. We use this to
1268 decide which addresses to watch. */
1269 *val_chain
= new_mark
;
1270 value_release_to_mark (mark
);
1274 /* Assuming that B is a watchpoint: returns true if the current thread
1275 and its running state are safe to evaluate or update watchpoint B.
1276 Watchpoints on local expressions need to be evaluated in the
1277 context of the thread that was current when the watchpoint was
1278 created, and, that thread needs to be stopped to be able to select
1279 the correct frame context. Watchpoints on global expressions can
1280 be evaluated on any thread, and in any state. It is presently left
1281 to the target allowing memory accesses when threads are
1285 watchpoint_in_thread_scope (struct breakpoint
*b
)
1287 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1288 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1289 && !is_executing (inferior_ptid
)));
1292 /* Assuming that B is a watchpoint:
1293 - Reparse watchpoint expression, if REPARSE is non-zero
1294 - Evaluate expression and store the result in B->val
1295 - Evaluate the condition if there is one, and store the result
1297 - Update the list of values that must be watched in B->loc.
1299 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1300 If this is local watchpoint that is out of scope, delete it.
1302 Even with `set breakpoint always-inserted on' the watchpoints are removed
1303 + inserted on each stop here. Normal breakpoints must never be removed
1304 because they might be missed by a running thread when debugging in non-stop
1305 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1306 processed here) are specific to each LWP since they are stored in each LWP's
1307 hardware debug registers. Therefore, such LWP must be stopped first in
1308 order to be able to modify its hardware watchpoints.
1310 Hardware watchpoints must be reset exactly once after being presented to the
1311 user. It cannot be done sooner, because it would reset the data used to
1312 present the watchpoint hit to the user. And it must not be done later
1313 because it could display the same single watchpoint hit during multiple GDB
1314 stops. Note that the latter is relevant only to the hardware watchpoint
1315 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1316 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1317 memory content has not changed.
1319 The following constraints influence the location where we can reset hardware
1322 * target_stopped_by_watchpoint and target_stopped_data_address are called
1323 several times when GDB stops.
1326 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1327 stop. GDB only presents one hardware watchpoint hit at a time as the
1328 reason for stopping, and all the other hits are presented later, one after
1329 the other, each time the user requests the execution to be resumed.
1330 Execution is not resumed for the threads still having pending hit event
1331 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1332 the inferior on the first stop the thread hit event is kept being reported
1333 from its cached value by linux_nat_stopped_data_address until the real
1334 thread resume happens after the watchpoint gets presented and thus its
1335 LWP_INFO->STATUS gets reset.
1337 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1338 removal from inferior. */
1341 update_watchpoint (struct breakpoint
*b
, int reparse
)
1343 int within_current_scope
;
1344 struct frame_id saved_frame_id
;
1345 struct bp_location
*loc
;
1349 /* If this is a local watchpoint, we only want to check if the
1350 watchpoint frame is in scope if the current thread is the thread
1351 that was used to create the watchpoint. */
1352 if (!watchpoint_in_thread_scope (b
))
1355 /* We don't free locations. They are stored in bp_location array and
1356 update_global_locations will eventually delete them and remove
1357 breakpoints if needed. */
1360 if (b
->disposition
== disp_del_at_next_stop
)
1365 /* Determine if the watchpoint is within scope. */
1366 if (b
->exp_valid_block
== NULL
)
1367 within_current_scope
= 1;
1370 struct frame_info
*fi
;
1372 /* Save the current frame's ID so we can restore it after
1373 evaluating the watchpoint expression on its own frame. */
1374 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1375 took a frame parameter, so that we didn't have to change the
1378 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1380 fi
= frame_find_by_id (b
->watchpoint_frame
);
1381 within_current_scope
= (fi
!= NULL
);
1382 if (within_current_scope
)
1386 if (within_current_scope
&& reparse
)
1395 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1396 /* If the meaning of expression itself changed, the old value is
1397 no longer relevant. We don't want to report a watchpoint hit
1398 to the user when the old value and the new value may actually
1399 be completely different objects. */
1400 value_free (b
->val
);
1404 /* Note that unlike with breakpoints, the watchpoint's condition
1405 expression is stored in the breakpoint object, not in the
1406 locations (re)created below. */
1407 if (b
->cond_string
!= NULL
)
1409 if (b
->cond_exp
!= NULL
)
1411 xfree (b
->cond_exp
);
1416 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1420 /* If we failed to parse the expression, for example because
1421 it refers to a global variable in a not-yet-loaded shared library,
1422 don't try to insert watchpoint. We don't automatically delete
1423 such watchpoint, though, since failure to parse expression
1424 is different from out-of-scope watchpoint. */
1425 if ( !target_has_execution
)
1427 /* Without execution, memory can't change. No use to try and
1428 set watchpoint locations. The watchpoint will be reset when
1429 the target gains execution, through breakpoint_re_set. */
1431 else if (within_current_scope
&& b
->exp
)
1433 struct value
*val_chain
, *v
, *result
, *next
;
1434 struct program_space
*frame_pspace
;
1436 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1438 /* Avoid setting b->val if it's already set. The meaning of
1439 b->val is 'the last value' user saw, and we should update
1440 it only if we reported that last value to user. As it
1441 happens, the code that reports it updates b->val directly. */
1448 /* Change the type of breakpoint between hardware assisted or an
1449 ordinary watchpoint depending on the hardware support and free
1450 hardware slots. REPARSE is set when the inferior is started. */
1451 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1454 int i
, mem_cnt
, other_type_used
;
1456 /* We need to determine how many resources are already used
1457 for all other hardware watchpoints to see if we still have
1458 enough resources to also fit this watchpoint in as well.
1459 To avoid the hw_watchpoint_used_count call below from counting
1460 this watchpoint, make sure that it is marked as a software
1462 b
->type
= bp_watchpoint
;
1463 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1465 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1468 b
->type
= bp_watchpoint
;
1471 int target_resources_ok
= target_can_use_hardware_watchpoint
1472 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1473 if (target_resources_ok
<= 0)
1474 b
->type
= bp_watchpoint
;
1476 b
->type
= bp_hardware_watchpoint
;
1480 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1482 /* Look at each value on the value chain. */
1483 for (v
= val_chain
; v
; v
= next
)
1485 /* If it's a memory location, and GDB actually needed
1486 its contents to evaluate the expression, then we
1487 must watch it. If the first value returned is
1488 still lazy, that means an error occurred reading it;
1489 watch it anyway in case it becomes readable. */
1490 if (VALUE_LVAL (v
) == lval_memory
1491 && (v
== val_chain
|| ! value_lazy (v
)))
1493 struct type
*vtype
= check_typedef (value_type (v
));
1495 /* We only watch structs and arrays if user asked
1496 for it explicitly, never if they just happen to
1497 appear in the middle of some value chain. */
1499 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1500 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1504 struct bp_location
*loc
, **tmp
;
1506 addr
= value_address (v
);
1507 len
= TYPE_LENGTH (value_type (v
));
1509 if (b
->type
== bp_read_watchpoint
)
1511 else if (b
->type
== bp_access_watchpoint
)
1514 loc
= allocate_bp_location (b
);
1515 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1518 loc
->gdbarch
= get_type_arch (value_type (v
));
1520 loc
->pspace
= frame_pspace
;
1521 loc
->address
= addr
;
1523 loc
->watchpoint_type
= type
;
1527 next
= value_next (v
);
1532 /* If a software watchpoint is not watching any memory, then the
1533 above left it without any location set up. But,
1534 bpstat_stop_status requires a location to be able to report
1535 stops, so make sure there's at least a dummy one. */
1536 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1538 b
->loc
= allocate_bp_location (b
);
1539 b
->loc
->pspace
= frame_pspace
;
1540 b
->loc
->address
= -1;
1541 b
->loc
->length
= -1;
1542 b
->loc
->watchpoint_type
= -1;
1545 else if (!within_current_scope
)
1547 printf_filtered (_("\
1548 Watchpoint %d deleted because the program has left the block \n\
1549 in which its expression is valid.\n"),
1551 if (b
->related_breakpoint
)
1553 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1554 b
->related_breakpoint
->related_breakpoint
= NULL
;
1555 b
->related_breakpoint
= NULL
;
1557 b
->disposition
= disp_del_at_next_stop
;
1560 /* Restore the selected frame. */
1562 select_frame (frame_find_by_id (saved_frame_id
));
1566 /* Returns 1 iff breakpoint location should be
1567 inserted in the inferior. */
1569 should_be_inserted (struct bp_location
*bpt
)
1571 if (!breakpoint_enabled (bpt
->owner
))
1574 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1577 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1580 /* This is set for example, when we're attached to the parent of a
1581 vfork, and have detached from the child. The child is running
1582 free, and we expect it to do an exec or exit, at which point the
1583 OS makes the parent schedulable again (and the target reports
1584 that the vfork is done). Until the child is done with the shared
1585 memory region, do not insert breakpoints in the parent, otherwise
1586 the child could still trip on the parent's breakpoints. Since
1587 the parent is blocked anyway, it won't miss any breakpoint. */
1588 if (bpt
->pspace
->breakpoints_not_allowed
)
1591 /* Tracepoints are inserted by the target at a time of its choosing,
1593 if (is_tracepoint (bpt
->owner
))
1599 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1600 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1601 and HW_BREAKPOINT_ERROR are used to report problems.
1603 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1604 method for each breakpoint or catchpoint type. */
1606 insert_bp_location (struct bp_location
*bpt
,
1607 struct ui_file
*tmp_error_stream
,
1608 int *disabled_breaks
,
1609 int *hw_breakpoint_error
)
1613 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1616 /* Initialize the target-specific information. */
1617 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1618 bpt
->target_info
.placed_address
= bpt
->address
;
1619 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1621 if (bpt
->loc_type
== bp_loc_software_breakpoint
1622 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1624 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1626 /* If the explicitly specified breakpoint type
1627 is not hardware breakpoint, check the memory map to see
1628 if the breakpoint address is in read only memory or not.
1629 Two important cases are:
1630 - location type is not hardware breakpoint, memory
1631 is readonly. We change the type of the location to
1632 hardware breakpoint.
1633 - location type is hardware breakpoint, memory is read-write.
1634 This means we've previously made the location hardware one, but
1635 then the memory map changed, so we undo.
1637 When breakpoints are removed, remove_breakpoints will
1638 use location types we've just set here, the only possible
1639 problem is that memory map has changed during running program,
1640 but it's not going to work anyway with current gdb. */
1641 struct mem_region
*mr
1642 = lookup_mem_region (bpt
->target_info
.placed_address
);
1646 if (automatic_hardware_breakpoints
)
1649 enum bp_loc_type new_type
;
1651 if (mr
->attrib
.mode
!= MEM_RW
)
1652 new_type
= bp_loc_hardware_breakpoint
;
1654 new_type
= bp_loc_software_breakpoint
;
1656 if (new_type
!= bpt
->loc_type
)
1658 static int said
= 0;
1659 bpt
->loc_type
= new_type
;
1662 fprintf_filtered (gdb_stdout
, _("\
1663 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1668 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1669 && mr
->attrib
.mode
!= MEM_RW
)
1670 warning (_("cannot set software breakpoint at readonly address %s"),
1671 paddress (bpt
->gdbarch
, bpt
->address
));
1675 /* First check to see if we have to handle an overlay. */
1676 if (overlay_debugging
== ovly_off
1677 || bpt
->section
== NULL
1678 || !(section_is_overlay (bpt
->section
)))
1680 /* No overlay handling: just set the breakpoint. */
1682 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1683 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1686 val
= target_insert_breakpoint (bpt
->gdbarch
,
1691 /* This breakpoint is in an overlay section.
1692 Shall we set a breakpoint at the LMA? */
1693 if (!overlay_events_enabled
)
1695 /* Yes -- overlay event support is not active,
1696 so we must try to set a breakpoint at the LMA.
1697 This will not work for a hardware breakpoint. */
1698 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1699 warning (_("hardware breakpoint %d not supported in overlay!"),
1700 bpt
->owner
->number
);
1703 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1705 /* Set a software (trap) breakpoint at the LMA. */
1706 bpt
->overlay_target_info
= bpt
->target_info
;
1707 bpt
->overlay_target_info
.placed_address
= addr
;
1708 val
= target_insert_breakpoint (bpt
->gdbarch
,
1709 &bpt
->overlay_target_info
);
1711 fprintf_unfiltered (tmp_error_stream
,
1712 "Overlay breakpoint %d failed: in ROM?\n",
1713 bpt
->owner
->number
);
1716 /* Shall we set a breakpoint at the VMA? */
1717 if (section_is_mapped (bpt
->section
))
1719 /* Yes. This overlay section is mapped into memory. */
1720 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1721 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1724 val
= target_insert_breakpoint (bpt
->gdbarch
,
1729 /* No. This breakpoint will not be inserted.
1730 No error, but do not mark the bp as 'inserted'. */
1737 /* Can't set the breakpoint. */
1738 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1740 /* See also: disable_breakpoints_in_shlibs. */
1742 bpt
->shlib_disabled
= 1;
1743 if (!*disabled_breaks
)
1745 fprintf_unfiltered (tmp_error_stream
,
1746 "Cannot insert breakpoint %d.\n",
1747 bpt
->owner
->number
);
1748 fprintf_unfiltered (tmp_error_stream
,
1749 "Temporarily disabling shared library breakpoints:\n");
1751 *disabled_breaks
= 1;
1752 fprintf_unfiltered (tmp_error_stream
,
1753 "breakpoint #%d\n", bpt
->owner
->number
);
1757 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1759 *hw_breakpoint_error
= 1;
1760 fprintf_unfiltered (tmp_error_stream
,
1761 "Cannot insert hardware breakpoint %d.\n",
1762 bpt
->owner
->number
);
1766 fprintf_unfiltered (tmp_error_stream
,
1767 "Cannot insert breakpoint %d.\n",
1768 bpt
->owner
->number
);
1769 fprintf_filtered (tmp_error_stream
,
1770 "Error accessing memory address ");
1771 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1773 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1774 safe_strerror (val
));
1785 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1786 /* NOTE drow/2003-09-08: This state only exists for removing
1787 watchpoints. It's not clear that it's necessary... */
1788 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1790 val
= target_insert_watchpoint (bpt
->address
,
1792 bpt
->watchpoint_type
);
1794 /* If trying to set a read-watchpoint, and it turns out it's not
1795 supported, try emulating one with an access watchpoint. */
1796 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1798 struct bp_location
*loc
, **loc_temp
;
1800 /* But don't try to insert it, if there's already another
1801 hw_access location that would be considered a duplicate
1803 ALL_BP_LOCATIONS (loc
, loc_temp
)
1805 && loc
->watchpoint_type
== hw_access
1806 && watchpoint_locations_match (bpt
, loc
))
1810 bpt
->target_info
= loc
->target_info
;
1811 bpt
->watchpoint_type
= hw_access
;
1818 val
= target_insert_watchpoint (bpt
->address
,
1822 bpt
->watchpoint_type
= hw_access
;
1826 bpt
->inserted
= (val
== 0);
1829 else if (bpt
->owner
->type
== bp_catchpoint
)
1831 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1832 bpt
->owner
, RETURN_MASK_ERROR
);
1833 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1834 bpt
->owner
->number
);
1836 bpt
->owner
->enable_state
= bp_disabled
;
1840 /* We've already printed an error message if there was a problem
1841 inserting this catchpoint, and we've disabled the catchpoint,
1842 so just return success. */
1849 /* This function is called when program space PSPACE is about to be
1850 deleted. It takes care of updating breakpoints to not reference
1854 breakpoint_program_space_exit (struct program_space
*pspace
)
1856 struct breakpoint
*b
, *b_temp
;
1857 struct bp_location
*loc
, **loc_temp
;
1859 /* Remove any breakpoint that was set through this program space. */
1860 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1862 if (b
->pspace
== pspace
)
1863 delete_breakpoint (b
);
1866 /* Breakpoints set through other program spaces could have locations
1867 bound to PSPACE as well. Remove those. */
1868 ALL_BP_LOCATIONS (loc
, loc_temp
)
1870 struct bp_location
*tmp
;
1872 if (loc
->pspace
== pspace
)
1874 if (loc
->owner
->loc
== loc
)
1875 loc
->owner
->loc
= loc
->next
;
1877 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1878 if (tmp
->next
== loc
)
1880 tmp
->next
= loc
->next
;
1886 /* Now update the global location list to permanently delete the
1887 removed locations above. */
1888 update_global_location_list (0);
1891 /* Make sure all breakpoints are inserted in inferior.
1892 Throws exception on any error.
1893 A breakpoint that is already inserted won't be inserted
1894 again, so calling this function twice is safe. */
1896 insert_breakpoints (void)
1898 struct breakpoint
*bpt
;
1900 ALL_BREAKPOINTS (bpt
)
1901 if (is_hardware_watchpoint (bpt
))
1902 update_watchpoint (bpt
, 0 /* don't reparse. */);
1904 update_global_location_list (1);
1906 /* update_global_location_list does not insert breakpoints when
1907 always_inserted_mode is not enabled. Explicitly insert them
1909 if (!breakpoints_always_inserted_mode ())
1910 insert_breakpoint_locations ();
1913 /* insert_breakpoints is used when starting or continuing the program.
1914 remove_breakpoints is used when the program stops.
1915 Both return zero if successful,
1916 or an `errno' value if could not write the inferior. */
1919 insert_breakpoint_locations (void)
1921 struct breakpoint
*bpt
;
1922 struct bp_location
*b
, **bp_tmp
;
1925 int disabled_breaks
= 0;
1926 int hw_breakpoint_error
= 0;
1928 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1929 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1931 /* Explicitly mark the warning -- this will only be printed if
1932 there was an error. */
1933 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1935 save_current_space_and_thread ();
1937 ALL_BP_LOCATIONS (b
, bp_tmp
)
1939 struct thread_info
*tp
;
1940 CORE_ADDR last_addr
;
1942 if (!should_be_inserted (b
) || b
->inserted
)
1945 /* There is no point inserting thread-specific breakpoints if the
1946 thread no longer exists. */
1947 if (b
->owner
->thread
!= -1
1948 && !valid_thread_id (b
->owner
->thread
))
1951 switch_to_program_space_and_thread (b
->pspace
);
1953 /* For targets that support global breakpoints, there's no need
1954 to select an inferior to insert breakpoint to. In fact, even
1955 if we aren't attached to any process yet, we should still
1956 insert breakpoints. */
1957 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1958 && ptid_equal (inferior_ptid
, null_ptid
))
1961 val
= insert_bp_location (b
, tmp_error_stream
,
1963 &hw_breakpoint_error
);
1968 /* If we failed to insert all locations of a watchpoint,
1969 remove them, as half-inserted watchpoint is of limited use. */
1970 ALL_BREAKPOINTS (bpt
)
1972 int some_failed
= 0;
1973 struct bp_location
*loc
;
1975 if (!is_hardware_watchpoint (bpt
))
1978 if (!breakpoint_enabled (bpt
))
1981 if (bpt
->disposition
== disp_del_at_next_stop
)
1984 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1985 if (!loc
->inserted
&& should_be_inserted (loc
))
1992 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1994 remove_breakpoint (loc
, mark_uninserted
);
1996 hw_breakpoint_error
= 1;
1997 fprintf_unfiltered (tmp_error_stream
,
1998 "Could not insert hardware watchpoint %d.\n",
2006 /* If a hardware breakpoint or watchpoint was inserted, add a
2007 message about possibly exhausted resources. */
2008 if (hw_breakpoint_error
)
2010 fprintf_unfiltered (tmp_error_stream
,
2011 "Could not insert hardware breakpoints:\n\
2012 You may have requested too many hardware breakpoints/watchpoints.\n");
2014 target_terminal_ours_for_output ();
2015 error_stream (tmp_error_stream
);
2018 do_cleanups (cleanups
);
2022 remove_breakpoints (void)
2024 struct bp_location
*b
, **bp_tmp
;
2027 ALL_BP_LOCATIONS (b
, bp_tmp
)
2030 val
|= remove_breakpoint (b
, mark_uninserted
);
2035 /* Remove breakpoints of process PID. */
2038 remove_breakpoints_pid (int pid
)
2040 struct bp_location
*b
, **b_tmp
;
2042 struct inferior
*inf
= find_inferior_pid (pid
);
2044 ALL_BP_LOCATIONS (b
, b_tmp
)
2046 if (b
->pspace
!= inf
->pspace
)
2051 val
= remove_breakpoint (b
, mark_uninserted
);
2060 remove_hw_watchpoints (void)
2062 struct bp_location
*b
, **bp_tmp
;
2065 ALL_BP_LOCATIONS (b
, bp_tmp
)
2067 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2068 val
|= remove_breakpoint (b
, mark_uninserted
);
2074 reattach_breakpoints (int pid
)
2076 struct cleanup
*old_chain
;
2077 struct bp_location
*b
, **bp_tmp
;
2079 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2080 int dummy1
= 0, dummy2
= 0;
2081 struct inferior
*inf
;
2082 struct thread_info
*tp
;
2084 tp
= any_live_thread_of_process (pid
);
2088 inf
= find_inferior_pid (pid
);
2089 old_chain
= save_inferior_ptid ();
2091 inferior_ptid
= tp
->ptid
;
2093 make_cleanup_ui_file_delete (tmp_error_stream
);
2095 ALL_BP_LOCATIONS (b
, bp_tmp
)
2097 if (b
->pspace
!= inf
->pspace
)
2103 val
= insert_bp_location (b
, tmp_error_stream
,
2107 do_cleanups (old_chain
);
2112 do_cleanups (old_chain
);
2116 static int internal_breakpoint_number
= -1;
2118 static struct breakpoint
*
2119 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2120 CORE_ADDR address
, enum bptype type
)
2122 struct symtab_and_line sal
;
2123 struct breakpoint
*b
;
2125 init_sal (&sal
); /* initialize to zeroes */
2128 sal
.section
= find_pc_overlay (sal
.pc
);
2129 sal
.pspace
= current_program_space
;
2131 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2132 b
->number
= internal_breakpoint_number
--;
2133 b
->disposition
= disp_donttouch
;
2139 create_overlay_event_breakpoint (char *func_name
)
2141 struct objfile
*objfile
;
2143 ALL_OBJFILES (objfile
)
2145 struct breakpoint
*b
;
2146 struct minimal_symbol
*m
;
2148 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2152 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2153 SYMBOL_VALUE_ADDRESS (m
),
2155 b
->addr_string
= xstrdup (func_name
);
2157 if (overlay_debugging
== ovly_auto
)
2159 b
->enable_state
= bp_enabled
;
2160 overlay_events_enabled
= 1;
2164 b
->enable_state
= bp_disabled
;
2165 overlay_events_enabled
= 0;
2168 update_global_location_list (1);
2172 create_longjmp_master_breakpoint (char *func_name
)
2174 struct program_space
*pspace
;
2175 struct objfile
*objfile
;
2176 struct cleanup
*old_chain
;
2178 old_chain
= save_current_program_space ();
2180 ALL_PSPACES (pspace
)
2181 ALL_OBJFILES (objfile
)
2183 struct breakpoint
*b
;
2184 struct minimal_symbol
*m
;
2186 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2189 set_current_program_space (pspace
);
2191 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2195 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2196 SYMBOL_VALUE_ADDRESS (m
),
2198 b
->addr_string
= xstrdup (func_name
);
2199 b
->enable_state
= bp_disabled
;
2201 update_global_location_list (1);
2203 do_cleanups (old_chain
);
2206 /* Create a master std::terminate breakpoint. The actual function
2207 looked for is named FUNC_NAME. */
2209 create_std_terminate_master_breakpoint (const char *func_name
)
2211 struct program_space
*pspace
;
2212 struct objfile
*objfile
;
2213 struct cleanup
*old_chain
;
2215 old_chain
= save_current_program_space ();
2217 ALL_PSPACES (pspace
)
2218 ALL_OBJFILES (objfile
)
2220 struct breakpoint
*b
;
2221 struct minimal_symbol
*m
;
2223 set_current_program_space (pspace
);
2225 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2226 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2227 && MSYMBOL_TYPE (m
) != mst_file_text
))
2230 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2231 SYMBOL_VALUE_ADDRESS (m
),
2232 bp_std_terminate_master
);
2233 b
->addr_string
= xstrdup (func_name
);
2234 b
->enable_state
= bp_disabled
;
2236 update_global_location_list (1);
2238 do_cleanups (old_chain
);
2242 update_breakpoints_after_exec (void)
2244 struct breakpoint
*b
;
2245 struct breakpoint
*temp
;
2246 struct bp_location
*bploc
, **bplocp_tmp
;
2248 /* We're about to delete breakpoints from GDB's lists. If the
2249 INSERTED flag is true, GDB will try to lift the breakpoints by
2250 writing the breakpoints' "shadow contents" back into memory. The
2251 "shadow contents" are NOT valid after an exec, so GDB should not
2252 do that. Instead, the target is responsible from marking
2253 breakpoints out as soon as it detects an exec. We don't do that
2254 here instead, because there may be other attempts to delete
2255 breakpoints after detecting an exec and before reaching here. */
2256 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2257 if (bploc
->pspace
== current_program_space
)
2258 gdb_assert (!bploc
->inserted
);
2260 ALL_BREAKPOINTS_SAFE (b
, temp
)
2262 if (b
->pspace
!= current_program_space
)
2265 /* Solib breakpoints must be explicitly reset after an exec(). */
2266 if (b
->type
== bp_shlib_event
)
2268 delete_breakpoint (b
);
2272 /* JIT breakpoints must be explicitly reset after an exec(). */
2273 if (b
->type
== bp_jit_event
)
2275 delete_breakpoint (b
);
2279 /* Thread event breakpoints must be set anew after an exec(),
2280 as must overlay event and longjmp master breakpoints. */
2281 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2282 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2284 delete_breakpoint (b
);
2288 /* Step-resume breakpoints are meaningless after an exec(). */
2289 if (b
->type
== bp_step_resume
)
2291 delete_breakpoint (b
);
2295 /* Longjmp and longjmp-resume breakpoints are also meaningless
2297 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2299 delete_breakpoint (b
);
2303 if (b
->type
== bp_catchpoint
)
2305 /* For now, none of the bp_catchpoint breakpoints need to
2306 do anything at this point. In the future, if some of
2307 the catchpoints need to something, we will need to add
2308 a new method, and call this method from here. */
2312 /* bp_finish is a special case. The only way we ought to be able
2313 to see one of these when an exec() has happened, is if the user
2314 caught a vfork, and then said "finish". Ordinarily a finish just
2315 carries them to the call-site of the current callee, by setting
2316 a temporary bp there and resuming. But in this case, the finish
2317 will carry them entirely through the vfork & exec.
2319 We don't want to allow a bp_finish to remain inserted now. But
2320 we can't safely delete it, 'cause finish_command has a handle to
2321 the bp on a bpstat, and will later want to delete it. There's a
2322 chance (and I've seen it happen) that if we delete the bp_finish
2323 here, that its storage will get reused by the time finish_command
2324 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2325 We really must allow finish_command to delete a bp_finish.
2327 In the absense of a general solution for the "how do we know
2328 it's safe to delete something others may have handles to?"
2329 problem, what we'll do here is just uninsert the bp_finish, and
2330 let finish_command delete it.
2332 (We know the bp_finish is "doomed" in the sense that it's
2333 momentary, and will be deleted as soon as finish_command sees
2334 the inferior stopped. So it doesn't matter that the bp's
2335 address is probably bogus in the new a.out, unlike e.g., the
2336 solib breakpoints.) */
2338 if (b
->type
== bp_finish
)
2343 /* Without a symbolic address, we have little hope of the
2344 pre-exec() address meaning the same thing in the post-exec()
2346 if (b
->addr_string
== NULL
)
2348 delete_breakpoint (b
);
2352 /* FIXME what about longjmp breakpoints? Re-create them here? */
2353 create_overlay_event_breakpoint ("_ovly_debug_event");
2354 create_longjmp_master_breakpoint ("longjmp");
2355 create_longjmp_master_breakpoint ("_longjmp");
2356 create_longjmp_master_breakpoint ("siglongjmp");
2357 create_longjmp_master_breakpoint ("_siglongjmp");
2358 create_std_terminate_master_breakpoint ("std::terminate()");
2362 detach_breakpoints (int pid
)
2364 struct bp_location
*b
, **bp_tmp
;
2366 struct cleanup
*old_chain
= save_inferior_ptid ();
2367 struct inferior
*inf
= current_inferior ();
2369 if (pid
== PIDGET (inferior_ptid
))
2370 error (_("Cannot detach breakpoints of inferior_ptid"));
2372 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2373 inferior_ptid
= pid_to_ptid (pid
);
2374 ALL_BP_LOCATIONS (b
, bp_tmp
)
2376 if (b
->pspace
!= inf
->pspace
)
2380 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2382 do_cleanups (old_chain
);
2386 /* Remove the breakpoint location B from the current address space.
2387 Note that this is used to detach breakpoints from a child fork.
2388 When we get here, the child isn't in the inferior list, and neither
2389 do we have objects to represent its address space --- we should
2390 *not* look at b->pspace->aspace here. */
2393 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2396 struct cleanup
*old_chain
;
2398 if (b
->owner
->enable_state
== bp_permanent
)
2399 /* Permanent breakpoints cannot be inserted or removed. */
2402 /* The type of none suggests that owner is actually deleted.
2403 This should not ever happen. */
2404 gdb_assert (b
->owner
->type
!= bp_none
);
2406 if (b
->loc_type
== bp_loc_software_breakpoint
2407 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2409 /* "Normal" instruction breakpoint: either the standard
2410 trap-instruction bp (bp_breakpoint), or a
2411 bp_hardware_breakpoint. */
2413 /* First check to see if we have to handle an overlay. */
2414 if (overlay_debugging
== ovly_off
2415 || b
->section
== NULL
2416 || !(section_is_overlay (b
->section
)))
2418 /* No overlay handling: just remove the breakpoint. */
2420 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2421 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2423 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2427 /* This breakpoint is in an overlay section.
2428 Did we set a breakpoint at the LMA? */
2429 if (!overlay_events_enabled
)
2431 /* Yes -- overlay event support is not active, so we
2432 should have set a breakpoint at the LMA. Remove it.
2434 /* Ignore any failures: if the LMA is in ROM, we will
2435 have already warned when we failed to insert it. */
2436 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2437 target_remove_hw_breakpoint (b
->gdbarch
,
2438 &b
->overlay_target_info
);
2440 target_remove_breakpoint (b
->gdbarch
,
2441 &b
->overlay_target_info
);
2443 /* Did we set a breakpoint at the VMA?
2444 If so, we will have marked the breakpoint 'inserted'. */
2447 /* Yes -- remove it. Previously we did not bother to
2448 remove the breakpoint if the section had been
2449 unmapped, but let's not rely on that being safe. We
2450 don't know what the overlay manager might do. */
2451 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2452 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2455 /* However, we should remove *software* breakpoints only
2456 if the section is still mapped, or else we overwrite
2457 wrong code with the saved shadow contents. */
2458 else if (section_is_mapped (b
->section
))
2459 val
= target_remove_breakpoint (b
->gdbarch
,
2466 /* No -- not inserted, so no need to remove. No error. */
2471 /* In some cases, we might not be able to remove a breakpoint
2472 in a shared library that has already been removed, but we
2473 have not yet processed the shlib unload event. */
2474 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2479 b
->inserted
= (is
== mark_inserted
);
2481 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2486 b
->inserted
= (is
== mark_inserted
);
2487 val
= target_remove_watchpoint (b
->address
, b
->length
,
2488 b
->watchpoint_type
);
2490 /* Failure to remove any of the hardware watchpoints comes here. */
2491 if ((is
== mark_uninserted
) && (b
->inserted
))
2492 warning (_("Could not remove hardware watchpoint %d."),
2495 else if (b
->owner
->type
== bp_catchpoint
2496 && breakpoint_enabled (b
->owner
)
2499 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2501 val
= b
->owner
->ops
->remove (b
->owner
);
2504 b
->inserted
= (is
== mark_inserted
);
2511 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2514 struct cleanup
*old_chain
;
2516 if (b
->owner
->enable_state
== bp_permanent
)
2517 /* Permanent breakpoints cannot be inserted or removed. */
2520 /* The type of none suggests that owner is actually deleted.
2521 This should not ever happen. */
2522 gdb_assert (b
->owner
->type
!= bp_none
);
2524 old_chain
= save_current_space_and_thread ();
2526 switch_to_program_space_and_thread (b
->pspace
);
2528 ret
= remove_breakpoint_1 (b
, is
);
2530 do_cleanups (old_chain
);
2534 /* Clear the "inserted" flag in all breakpoints. */
2537 mark_breakpoints_out (void)
2539 struct bp_location
*bpt
, **bptp_tmp
;
2541 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2542 if (bpt
->pspace
== current_program_space
)
2546 /* Clear the "inserted" flag in all breakpoints and delete any
2547 breakpoints which should go away between runs of the program.
2549 Plus other such housekeeping that has to be done for breakpoints
2552 Note: this function gets called at the end of a run (by
2553 generic_mourn_inferior) and when a run begins (by
2554 init_wait_for_inferior). */
2559 breakpoint_init_inferior (enum inf_context context
)
2561 struct breakpoint
*b
, *temp
;
2562 struct bp_location
*bpt
, **bptp_tmp
;
2564 struct program_space
*pspace
= current_program_space
;
2566 /* If breakpoint locations are shared across processes, then there's
2568 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2571 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2573 if (bpt
->pspace
== pspace
2574 && bpt
->owner
->enable_state
!= bp_permanent
)
2578 ALL_BREAKPOINTS_SAFE (b
, temp
)
2580 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2587 /* If the call dummy breakpoint is at the entry point it will
2588 cause problems when the inferior is rerun, so we better get
2591 case bp_watchpoint_scope
:
2593 /* Also get rid of scope breakpoints. */
2595 case bp_shlib_event
:
2597 /* Also remove solib event breakpoints. Their addresses may
2598 have changed since the last time we ran the program.
2599 Actually we may now be debugging against different target;
2600 and so the solib backend that installed this breakpoint may
2601 not be used in by the target. E.g.,
2603 (gdb) file prog-linux
2604 (gdb) run # native linux target
2607 (gdb) file prog-win.exe
2608 (gdb) tar rem :9999 # remote Windows gdbserver.
2611 delete_breakpoint (b
);
2615 case bp_hardware_watchpoint
:
2616 case bp_read_watchpoint
:
2617 case bp_access_watchpoint
:
2619 /* Likewise for watchpoints on local expressions. */
2620 if (b
->exp_valid_block
!= NULL
)
2621 delete_breakpoint (b
);
2622 else if (context
== inf_starting
)
2624 /* Reset val field to force reread of starting value
2625 in insert_breakpoints. */
2627 value_free (b
->val
);
2637 /* Get rid of the moribund locations. */
2638 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2639 free_bp_location (bpt
);
2640 VEC_free (bp_location_p
, moribund_locations
);
2643 /* These functions concern about actual breakpoints inserted in the
2644 target --- to e.g. check if we need to do decr_pc adjustment or if
2645 we need to hop over the bkpt --- so we check for address space
2646 match, not program space. */
2648 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2649 exists at PC. It returns ordinary_breakpoint_here if it's an
2650 ordinary breakpoint, or permanent_breakpoint_here if it's a
2651 permanent breakpoint.
2652 - When continuing from a location with an ordinary breakpoint, we
2653 actually single step once before calling insert_breakpoints.
2654 - When continuing from a localion with a permanent breakpoint, we
2655 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2656 the target, to advance the PC past the breakpoint. */
2658 enum breakpoint_here
2659 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2661 struct bp_location
*bpt
, **bptp_tmp
;
2662 int any_breakpoint_here
= 0;
2664 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2666 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2667 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2670 if ((breakpoint_enabled (bpt
->owner
)
2671 || bpt
->owner
->enable_state
== bp_permanent
)
2672 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2675 if (overlay_debugging
2676 && section_is_overlay (bpt
->section
)
2677 && !section_is_mapped (bpt
->section
))
2678 continue; /* unmapped overlay -- can't be a match */
2679 else if (bpt
->owner
->enable_state
== bp_permanent
)
2680 return permanent_breakpoint_here
;
2682 any_breakpoint_here
= 1;
2686 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2689 /* Return true if there's a moribund breakpoint at PC. */
2692 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2694 struct bp_location
*loc
;
2697 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2698 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2705 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2706 inserted using regular breakpoint_chain / bp_location array mechanism.
2707 This does not check for single-step breakpoints, which are
2708 inserted and removed using direct target manipulation. */
2711 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2713 struct bp_location
*bpt
, **bptp_tmp
;
2715 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2717 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2718 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2722 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2725 if (overlay_debugging
2726 && section_is_overlay (bpt
->section
)
2727 && !section_is_mapped (bpt
->section
))
2728 continue; /* unmapped overlay -- can't be a match */
2736 /* Returns non-zero iff there's either regular breakpoint
2737 or a single step breakpoint inserted at PC. */
2740 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2742 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2745 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2751 /* This function returns non-zero iff there is a software breakpoint
2755 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2757 struct bp_location
*bpt
, **bptp_tmp
;
2758 int any_breakpoint_here
= 0;
2760 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2762 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2766 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2769 if (overlay_debugging
2770 && section_is_overlay (bpt
->section
)
2771 && !section_is_mapped (bpt
->section
))
2772 continue; /* unmapped overlay -- can't be a match */
2778 /* Also check for software single-step breakpoints. */
2779 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2786 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2787 CORE_ADDR addr
, ULONGEST len
)
2789 struct breakpoint
*bpt
;
2791 ALL_BREAKPOINTS (bpt
)
2793 struct bp_location
*loc
;
2795 if (bpt
->type
!= bp_hardware_watchpoint
2796 && bpt
->type
!= bp_access_watchpoint
)
2799 if (!breakpoint_enabled (bpt
))
2802 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2803 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2807 /* Check for intersection. */
2808 l
= max (loc
->address
, addr
);
2809 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2817 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2818 PC is valid for process/thread PTID. */
2821 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2824 struct bp_location
*bpt
, **bptp_tmp
;
2825 /* The thread and task IDs associated to PTID, computed lazily. */
2829 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2831 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2832 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2835 if (!breakpoint_enabled (bpt
->owner
)
2836 && bpt
->owner
->enable_state
!= bp_permanent
)
2839 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2843 if (bpt
->owner
->thread
!= -1)
2845 /* This is a thread-specific breakpoint. Check that ptid
2846 matches that thread. If thread hasn't been computed yet,
2847 it is now time to do so. */
2849 thread
= pid_to_thread_id (ptid
);
2850 if (bpt
->owner
->thread
!= thread
)
2854 if (bpt
->owner
->task
!= 0)
2856 /* This is a task-specific breakpoint. Check that ptid
2857 matches that task. If task hasn't been computed yet,
2858 it is now time to do so. */
2860 task
= ada_get_task_number (ptid
);
2861 if (bpt
->owner
->task
!= task
)
2865 if (overlay_debugging
2866 && section_is_overlay (bpt
->section
)
2867 && !section_is_mapped (bpt
->section
))
2868 continue; /* unmapped overlay -- can't be a match */
2877 /* bpstat stuff. External routines' interfaces are documented
2881 ep_is_catchpoint (struct breakpoint
*ep
)
2883 return (ep
->type
== bp_catchpoint
);
2887 bpstat_free (bpstat bs
)
2889 if (bs
->old_val
!= NULL
)
2890 value_free (bs
->old_val
);
2891 decref_counted_command_line (&bs
->commands
);
2895 /* Clear a bpstat so that it says we are not at any breakpoint.
2896 Also free any storage that is part of a bpstat. */
2899 bpstat_clear (bpstat
*bsp
)
2916 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2917 is part of the bpstat is copied as well. */
2920 bpstat_copy (bpstat bs
)
2924 bpstat retval
= NULL
;
2929 for (; bs
!= NULL
; bs
= bs
->next
)
2931 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2932 memcpy (tmp
, bs
, sizeof (*tmp
));
2933 incref_counted_command_line (tmp
->commands
);
2934 if (bs
->old_val
!= NULL
)
2936 tmp
->old_val
= value_copy (bs
->old_val
);
2937 release_value (tmp
->old_val
);
2941 /* This is the first thing in the chain. */
2951 /* Find the bpstat associated with this breakpoint */
2954 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2959 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2961 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2967 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2968 at. *BSP upon return is a bpstat which points to the remaining
2969 breakpoints stopped at (but which is not guaranteed to be good for
2970 anything but further calls to bpstat_num).
2971 Return 0 if passed a bpstat which does not indicate any breakpoints.
2972 Return -1 if stopped at a breakpoint that has been deleted since
2974 Return 1 otherwise. */
2977 bpstat_num (bpstat
*bsp
, int *num
)
2979 struct breakpoint
*b
;
2982 return 0; /* No more breakpoint values */
2984 /* We assume we'll never have several bpstats that
2985 correspond to a single breakpoint -- otherwise,
2986 this function might return the same number more
2987 than once and this will look ugly. */
2988 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2989 *bsp
= (*bsp
)->next
;
2991 return -1; /* breakpoint that's been deleted since */
2993 *num
= b
->number
; /* We have its number */
2997 /* Modify BS so that the actions will not be performed. */
3000 bpstat_clear_actions (bpstat bs
)
3002 for (; bs
!= NULL
; bs
= bs
->next
)
3004 decref_counted_command_line (&bs
->commands
);
3005 bs
->commands_left
= NULL
;
3006 if (bs
->old_val
!= NULL
)
3008 value_free (bs
->old_val
);
3014 /* Called when a command is about to proceed the inferior. */
3017 breakpoint_about_to_proceed (void)
3019 if (!ptid_equal (inferior_ptid
, null_ptid
))
3021 struct thread_info
*tp
= inferior_thread ();
3023 /* Allow inferior function calls in breakpoint commands to not
3024 interrupt the command list. When the call finishes
3025 successfully, the inferior will be standing at the same
3026 breakpoint as if nothing happened. */
3031 breakpoint_proceeded
= 1;
3034 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3036 cleanup_executing_breakpoints (void *ignore
)
3038 executing_breakpoint_commands
= 0;
3041 /* Execute all the commands associated with all the breakpoints at this
3042 location. Any of these commands could cause the process to proceed
3043 beyond this point, etc. We look out for such changes by checking
3044 the global "breakpoint_proceeded" after each command.
3046 Returns true if a breakpoint command resumed the inferior. In that
3047 case, it is the caller's responsibility to recall it again with the
3048 bpstat of the current thread. */
3051 bpstat_do_actions_1 (bpstat
*bsp
)
3054 struct cleanup
*old_chain
;
3057 /* Avoid endless recursion if a `source' command is contained
3059 if (executing_breakpoint_commands
)
3062 executing_breakpoint_commands
= 1;
3063 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3065 /* This pointer will iterate over the list of bpstat's. */
3068 breakpoint_proceeded
= 0;
3069 for (; bs
!= NULL
; bs
= bs
->next
)
3071 struct counted_command_line
*ccmd
;
3072 struct command_line
*cmd
;
3073 struct cleanup
*this_cmd_tree_chain
;
3075 /* Take ownership of the BSP's command tree, if it has one.
3077 The command tree could legitimately contain commands like
3078 'step' and 'next', which call clear_proceed_status, which
3079 frees stop_bpstat's command tree. To make sure this doesn't
3080 free the tree we're executing out from under us, we need to
3081 take ownership of the tree ourselves. Since a given bpstat's
3082 commands are only executed once, we don't need to copy it; we
3083 can clear the pointer in the bpstat, and make sure we free
3084 the tree when we're done. */
3085 ccmd
= bs
->commands
;
3086 bs
->commands
= NULL
;
3088 = make_cleanup_decref_counted_command_line (&ccmd
);
3089 cmd
= bs
->commands_left
;
3090 bs
->commands_left
= NULL
;
3094 execute_control_command (cmd
);
3096 if (breakpoint_proceeded
)
3102 /* We can free this command tree now. */
3103 do_cleanups (this_cmd_tree_chain
);
3105 if (breakpoint_proceeded
)
3107 if (target_can_async_p ())
3108 /* If we are in async mode, then the target might be still
3109 running, not stopped at any breakpoint, so nothing for
3110 us to do here -- just return to the event loop. */
3113 /* In sync mode, when execute_control_command returns
3114 we're already standing on the next breakpoint.
3115 Breakpoint commands for that stop were not run, since
3116 execute_command does not run breakpoint commands --
3117 only command_line_handler does, but that one is not
3118 involved in execution of breakpoint commands. So, we
3119 can now execute breakpoint commands. It should be
3120 noted that making execute_command do bpstat actions is
3121 not an option -- in this case we'll have recursive
3122 invocation of bpstat for each breakpoint with a
3123 command, and can easily blow up GDB stack. Instead, we
3124 return true, which will trigger the caller to recall us
3125 with the new stop_bpstat. */
3130 do_cleanups (old_chain
);
3135 bpstat_do_actions (void)
3137 /* Do any commands attached to breakpoint we are stopped at. */
3138 while (!ptid_equal (inferior_ptid
, null_ptid
)
3139 && target_has_execution
3140 && !is_exited (inferior_ptid
)
3141 && !is_executing (inferior_ptid
))
3142 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3143 and only return when it is stopped at the next breakpoint, we
3144 keep doing breakpoint actions until it returns false to
3145 indicate the inferior was not resumed. */
3146 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3150 /* Print out the (old or new) value associated with a watchpoint. */
3153 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3156 fprintf_unfiltered (stream
, _("<unreadable>"));
3159 struct value_print_options opts
;
3160 get_user_print_options (&opts
);
3161 value_print (val
, stream
, &opts
);
3165 /* This is the normal print function for a bpstat. In the future,
3166 much of this logic could (should?) be moved to bpstat_stop_status,
3167 by having it set different print_it values.
3169 Current scheme: When we stop, bpstat_print() is called. It loops
3170 through the bpstat list of things causing this stop, calling the
3171 print_bp_stop_message function on each one. The behavior of the
3172 print_bp_stop_message function depends on the print_it field of
3173 bpstat. If such field so indicates, call this function here.
3175 Return values from this routine (ultimately used by bpstat_print()
3176 and normal_stop() to decide what to do):
3177 PRINT_NOTHING: Means we already printed all we needed to print,
3178 don't print anything else.
3179 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3180 that something to be followed by a location.
3181 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3182 that something to be followed by a location.
3183 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3186 static enum print_stop_action
3187 print_it_typical (bpstat bs
)
3189 struct cleanup
*old_chain
;
3190 struct breakpoint
*b
;
3191 const struct bp_location
*bl
;
3192 struct ui_stream
*stb
;
3194 enum print_stop_action result
;
3196 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3197 which has since been deleted. */
3198 if (bs
->breakpoint_at
== NULL
)
3199 return PRINT_UNKNOWN
;
3200 bl
= bs
->breakpoint_at
;
3203 stb
= ui_out_stream_new (uiout
);
3204 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3209 case bp_hardware_breakpoint
:
3210 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3211 if (bl
->address
!= bl
->requested_address
)
3212 breakpoint_adjustment_warning (bl
->requested_address
,
3215 annotate_breakpoint (b
->number
);
3217 ui_out_text (uiout
, "\nTemporary breakpoint ");
3219 ui_out_text (uiout
, "\nBreakpoint ");
3220 if (ui_out_is_mi_like_p (uiout
))
3222 ui_out_field_string (uiout
, "reason",
3223 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3224 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3226 ui_out_field_int (uiout
, "bkptno", b
->number
);
3227 ui_out_text (uiout
, ", ");
3228 result
= PRINT_SRC_AND_LOC
;
3231 case bp_shlib_event
:
3232 /* Did we stop because the user set the stop_on_solib_events
3233 variable? (If so, we report this as a generic, "Stopped due
3234 to shlib event" message.) */
3235 printf_filtered (_("Stopped due to shared library event\n"));
3236 result
= PRINT_NOTHING
;
3239 case bp_thread_event
:
3240 /* Not sure how we will get here.
3241 GDB should not stop for these breakpoints. */
3242 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3243 result
= PRINT_NOTHING
;
3246 case bp_overlay_event
:
3247 /* By analogy with the thread event, GDB should not stop for these. */
3248 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3249 result
= PRINT_NOTHING
;
3252 case bp_longjmp_master
:
3253 /* These should never be enabled. */
3254 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3255 result
= PRINT_NOTHING
;
3258 case bp_std_terminate_master
:
3259 /* These should never be enabled. */
3260 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3261 result
= PRINT_NOTHING
;
3265 case bp_hardware_watchpoint
:
3266 annotate_watchpoint (b
->number
);
3267 if (ui_out_is_mi_like_p (uiout
))
3270 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3272 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3273 ui_out_text (uiout
, "\nOld value = ");
3274 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3275 ui_out_field_stream (uiout
, "old", stb
);
3276 ui_out_text (uiout
, "\nNew value = ");
3277 watchpoint_value_print (b
->val
, stb
->stream
);
3278 ui_out_field_stream (uiout
, "new", stb
);
3279 ui_out_text (uiout
, "\n");
3280 /* More than one watchpoint may have been triggered. */
3281 result
= PRINT_UNKNOWN
;
3284 case bp_read_watchpoint
:
3285 if (ui_out_is_mi_like_p (uiout
))
3288 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3290 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3291 ui_out_text (uiout
, "\nValue = ");
3292 watchpoint_value_print (b
->val
, stb
->stream
);
3293 ui_out_field_stream (uiout
, "value", stb
);
3294 ui_out_text (uiout
, "\n");
3295 result
= PRINT_UNKNOWN
;
3298 case bp_access_watchpoint
:
3299 if (bs
->old_val
!= NULL
)
3301 annotate_watchpoint (b
->number
);
3302 if (ui_out_is_mi_like_p (uiout
))
3305 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3307 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3308 ui_out_text (uiout
, "\nOld value = ");
3309 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3310 ui_out_field_stream (uiout
, "old", stb
);
3311 ui_out_text (uiout
, "\nNew value = ");
3316 if (ui_out_is_mi_like_p (uiout
))
3319 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3320 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3321 ui_out_text (uiout
, "\nValue = ");
3323 watchpoint_value_print (b
->val
, stb
->stream
);
3324 ui_out_field_stream (uiout
, "new", stb
);
3325 ui_out_text (uiout
, "\n");
3326 result
= PRINT_UNKNOWN
;
3329 /* Fall through, we don't deal with these types of breakpoints
3333 if (ui_out_is_mi_like_p (uiout
))
3336 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3337 result
= PRINT_UNKNOWN
;
3341 if (ui_out_is_mi_like_p (uiout
))
3344 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3345 result
= PRINT_UNKNOWN
;
3350 case bp_longjmp_resume
:
3351 case bp_step_resume
:
3352 case bp_watchpoint_scope
:
3354 case bp_std_terminate
:
3356 case bp_fast_tracepoint
:
3359 result
= PRINT_UNKNOWN
;
3363 do_cleanups (old_chain
);
3367 /* Generic routine for printing messages indicating why we
3368 stopped. The behavior of this function depends on the value
3369 'print_it' in the bpstat structure. Under some circumstances we
3370 may decide not to print anything here and delegate the task to
3373 static enum print_stop_action
3374 print_bp_stop_message (bpstat bs
)
3376 switch (bs
->print_it
)
3379 /* Nothing should be printed for this bpstat entry. */
3380 return PRINT_UNKNOWN
;
3384 /* We still want to print the frame, but we already printed the
3385 relevant messages. */
3386 return PRINT_SRC_AND_LOC
;
3389 case print_it_normal
:
3391 const struct bp_location
*bl
= bs
->breakpoint_at
;
3392 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3394 /* Normal case. Call the breakpoint's print_it method, or
3395 print_it_typical. */
3396 /* FIXME: how breakpoint can ever be NULL here? */
3397 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3398 return b
->ops
->print_it (b
);
3400 return print_it_typical (bs
);
3405 internal_error (__FILE__
, __LINE__
,
3406 _("print_bp_stop_message: unrecognized enum value"));
3411 /* Print a message indicating what happened. This is called from
3412 normal_stop(). The input to this routine is the head of the bpstat
3413 list - a list of the eventpoints that caused this stop. This
3414 routine calls the generic print routine for printing a message
3415 about reasons for stopping. This will print (for example) the
3416 "Breakpoint n," part of the output. The return value of this
3419 PRINT_UNKNOWN: Means we printed nothing
3420 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3421 code to print the location. An example is
3422 "Breakpoint 1, " which should be followed by
3424 PRINT_SRC_ONLY: Means we printed something, but there is no need
3425 to also print the location part of the message.
3426 An example is the catch/throw messages, which
3427 don't require a location appended to the end.
3428 PRINT_NOTHING: We have done some printing and we don't need any
3429 further info to be printed.*/
3431 enum print_stop_action
3432 bpstat_print (bpstat bs
)
3436 /* Maybe another breakpoint in the chain caused us to stop.
3437 (Currently all watchpoints go on the bpstat whether hit or not.
3438 That probably could (should) be changed, provided care is taken
3439 with respect to bpstat_explains_signal). */
3440 for (; bs
; bs
= bs
->next
)
3442 val
= print_bp_stop_message (bs
);
3443 if (val
== PRINT_SRC_ONLY
3444 || val
== PRINT_SRC_AND_LOC
3445 || val
== PRINT_NOTHING
)
3449 /* We reached the end of the chain, or we got a null BS to start
3450 with and nothing was printed. */
3451 return PRINT_UNKNOWN
;
3454 /* Evaluate the expression EXP and return 1 if value is zero.
3455 This is used inside a catch_errors to evaluate the breakpoint condition.
3456 The argument is a "struct expression *" that has been cast to char * to
3457 make it pass through catch_errors. */
3460 breakpoint_cond_eval (void *exp
)
3462 struct value
*mark
= value_mark ();
3463 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3464 value_free_to_mark (mark
);
3468 /* Allocate a new bpstat and chain it to the current one. */
3471 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3475 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3477 bs
->breakpoint_at
= bl
;
3478 /* If the condition is false, etc., don't do the commands. */
3479 bs
->commands
= NULL
;
3480 bs
->commands_left
= NULL
;
3482 bs
->print_it
= print_it_normal
;
3486 /* The target has stopped with waitstatus WS. Check if any hardware
3487 watchpoints have triggered, according to the target. */
3490 watchpoints_triggered (struct target_waitstatus
*ws
)
3492 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3494 struct breakpoint
*b
;
3496 if (!stopped_by_watchpoint
)
3498 /* We were not stopped by a watchpoint. Mark all watchpoints
3499 as not triggered. */
3501 if (is_hardware_watchpoint (b
))
3502 b
->watchpoint_triggered
= watch_triggered_no
;
3507 if (!target_stopped_data_address (¤t_target
, &addr
))
3509 /* We were stopped by a watchpoint, but we don't know where.
3510 Mark all watchpoints as unknown. */
3512 if (is_hardware_watchpoint (b
))
3513 b
->watchpoint_triggered
= watch_triggered_unknown
;
3515 return stopped_by_watchpoint
;
3518 /* The target could report the data address. Mark watchpoints
3519 affected by this data address as triggered, and all others as not
3523 if (is_hardware_watchpoint (b
))
3525 struct bp_location
*loc
;
3528 b
->watchpoint_triggered
= watch_triggered_no
;
3529 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3530 /* Exact match not required. Within range is
3532 if (target_watchpoint_addr_within_range (¤t_target
,
3536 b
->watchpoint_triggered
= watch_triggered_yes
;
3544 /* Possible return values for watchpoint_check (this can't be an enum
3545 because of check_errors). */
3546 /* The watchpoint has been deleted. */
3547 #define WP_DELETED 1
3548 /* The value has changed. */
3549 #define WP_VALUE_CHANGED 2
3550 /* The value has not changed. */
3551 #define WP_VALUE_NOT_CHANGED 3
3552 /* Ignore this watchpoint, no matter if the value changed or not. */
3555 #define BP_TEMPFLAG 1
3556 #define BP_HARDWAREFLAG 2
3558 /* Evaluate watchpoint condition expression and check if its value changed.
3560 P should be a pointer to struct bpstat, but is defined as a void *
3561 in order for this function to be usable with catch_errors. */
3564 watchpoint_check (void *p
)
3566 bpstat bs
= (bpstat
) p
;
3567 struct breakpoint
*b
;
3568 struct frame_info
*fr
;
3569 int within_current_scope
;
3571 b
= bs
->breakpoint_at
->owner
;
3573 /* If this is a local watchpoint, we only want to check if the
3574 watchpoint frame is in scope if the current thread is the thread
3575 that was used to create the watchpoint. */
3576 if (!watchpoint_in_thread_scope (b
))
3579 if (b
->exp_valid_block
== NULL
)
3580 within_current_scope
= 1;
3583 struct frame_info
*frame
= get_current_frame ();
3584 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3585 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3587 /* in_function_epilogue_p() returns a non-zero value if we're still
3588 in the function but the stack frame has already been invalidated.
3589 Since we can't rely on the values of local variables after the
3590 stack has been destroyed, we are treating the watchpoint in that
3591 state as `not changed' without further checking. Don't mark
3592 watchpoints as changed if the current frame is in an epilogue -
3593 even if they are in some other frame, our view of the stack
3594 is likely to be wrong and frame_find_by_id could error out. */
3595 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3598 fr
= frame_find_by_id (b
->watchpoint_frame
);
3599 within_current_scope
= (fr
!= NULL
);
3601 /* If we've gotten confused in the unwinder, we might have
3602 returned a frame that can't describe this variable. */
3603 if (within_current_scope
)
3605 struct symbol
*function
;
3607 function
= get_frame_function (fr
);
3608 if (function
== NULL
3609 || !contained_in (b
->exp_valid_block
,
3610 SYMBOL_BLOCK_VALUE (function
)))
3611 within_current_scope
= 0;
3614 if (within_current_scope
)
3615 /* If we end up stopping, the current frame will get selected
3616 in normal_stop. So this call to select_frame won't affect
3621 if (within_current_scope
)
3623 /* We use value_{,free_to_}mark because it could be a
3624 *long* time before we return to the command level and
3625 call free_all_values. We can't call free_all_values because
3626 we might be in the middle of evaluating a function call. */
3628 struct value
*mark
= value_mark ();
3629 struct value
*new_val
;
3631 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3633 /* We use value_equal_contents instead of value_equal because the latter
3634 coerces an array to a pointer, thus comparing just the address of the
3635 array instead of its contents. This is not what we want. */
3636 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3637 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3639 if (new_val
!= NULL
)
3641 release_value (new_val
);
3642 value_free_to_mark (mark
);
3644 bs
->old_val
= b
->val
;
3647 return WP_VALUE_CHANGED
;
3651 /* Nothing changed. */
3652 value_free_to_mark (mark
);
3653 return WP_VALUE_NOT_CHANGED
;
3658 /* This seems like the only logical thing to do because
3659 if we temporarily ignored the watchpoint, then when
3660 we reenter the block in which it is valid it contains
3661 garbage (in the case of a function, it may have two
3662 garbage values, one before and one after the prologue).
3663 So we can't even detect the first assignment to it and
3664 watch after that (since the garbage may or may not equal
3665 the first value assigned). */
3666 /* We print all the stop information in print_it_typical(), but
3667 in this case, by the time we call print_it_typical() this bp
3668 will be deleted already. So we have no choice but print the
3669 information here. */
3670 if (ui_out_is_mi_like_p (uiout
))
3672 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3673 ui_out_text (uiout
, "\nWatchpoint ");
3674 ui_out_field_int (uiout
, "wpnum", b
->number
);
3675 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3676 which its expression is valid.\n");
3678 if (b
->related_breakpoint
)
3680 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3681 b
->related_breakpoint
->related_breakpoint
= NULL
;
3682 b
->related_breakpoint
= NULL
;
3684 b
->disposition
= disp_del_at_next_stop
;
3690 /* Return true if it looks like target has stopped due to hitting
3691 breakpoint location BL. This function does not check if we
3692 should stop, only if BL explains the stop. */
3694 bpstat_check_location (const struct bp_location
*bl
,
3695 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3697 struct breakpoint
*b
= bl
->owner
;
3699 /* By definition, the inferior does not report stops at
3701 if (is_tracepoint (b
))
3704 if (!is_watchpoint (b
)
3705 && b
->type
!= bp_hardware_breakpoint
3706 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3708 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3711 if (overlay_debugging
/* unmapped overlay section */
3712 && section_is_overlay (bl
->section
)
3713 && !section_is_mapped (bl
->section
))
3717 /* Continuable hardware watchpoints are treated as non-existent if the
3718 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3719 some data address). Otherwise gdb won't stop on a break instruction
3720 in the code (not from a breakpoint) when a hardware watchpoint has
3721 been defined. Also skip watchpoints which we know did not trigger
3722 (did not match the data address). */
3724 if (is_hardware_watchpoint (b
)
3725 && b
->watchpoint_triggered
== watch_triggered_no
)
3728 if (b
->type
== bp_hardware_breakpoint
)
3730 if (bl
->address
!= bp_addr
)
3732 if (overlay_debugging
/* unmapped overlay section */
3733 && section_is_overlay (bl
->section
)
3734 && !section_is_mapped (bl
->section
))
3738 if (b
->type
== bp_catchpoint
)
3740 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3741 if (!b
->ops
->breakpoint_hit (b
))
3748 /* If BS refers to a watchpoint, determine if the watched values
3749 has actually changed, and we should stop. If not, set BS->stop
3752 bpstat_check_watchpoint (bpstat bs
)
3754 const struct bp_location
*bl
= bs
->breakpoint_at
;
3755 struct breakpoint
*b
= bl
->owner
;
3757 if (is_watchpoint (b
))
3761 int must_check_value
= 0;
3763 if (b
->type
== bp_watchpoint
)
3764 /* For a software watchpoint, we must always check the
3766 must_check_value
= 1;
3767 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3768 /* We have a hardware watchpoint (read, write, or access)
3769 and the target earlier reported an address watched by
3771 must_check_value
= 1;
3772 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3773 && b
->type
== bp_hardware_watchpoint
)
3774 /* We were stopped by a hardware watchpoint, but the target could
3775 not report the data address. We must check the watchpoint's
3776 value. Access and read watchpoints are out of luck; without
3777 a data address, we can't figure it out. */
3778 must_check_value
= 1;
3780 if (must_check_value
)
3782 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3784 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3785 int e
= catch_errors (watchpoint_check
, bs
, message
,
3787 do_cleanups (cleanups
);
3791 /* We've already printed what needs to be printed. */
3792 bs
->print_it
= print_it_done
;
3796 bs
->print_it
= print_it_noop
;
3799 case WP_VALUE_CHANGED
:
3800 if (b
->type
== bp_read_watchpoint
)
3802 /* There are two cases to consider here:
3804 1. we're watching the triggered memory for reads.
3805 In that case, trust the target, and always report
3806 the watchpoint hit to the user. Even though
3807 reads don't cause value changes, the value may
3808 have changed since the last time it was read, and
3809 since we're not trapping writes, we will not see
3810 those, and as such we should ignore our notion of
3813 2. we're watching the triggered memory for both
3814 reads and writes. There are two ways this may
3817 2.1. this is a target that can't break on data
3818 reads only, but can break on accesses (reads or
3819 writes), such as e.g., x86. We detect this case
3820 at the time we try to insert read watchpoints.
3822 2.2. otherwise, the target supports read
3823 watchpoints, but, the user set an access or write
3824 watchpoint watching the same memory as this read
3827 If we're watching memory writes as well as reads,
3828 ignore watchpoint hits when we find that the
3829 value hasn't changed, as reads don't cause
3830 changes. This still gives false positives when
3831 the program writes the same value to memory as
3832 what there was already in memory (we will confuse
3833 it for a read), but it's much better than
3836 int other_write_watchpoint
= 0;
3838 if (bl
->watchpoint_type
== hw_read
)
3840 struct breakpoint
*other_b
;
3842 ALL_BREAKPOINTS (other_b
)
3843 if ((other_b
->type
== bp_hardware_watchpoint
3844 || other_b
->type
== bp_access_watchpoint
)
3845 && (other_b
->watchpoint_triggered
3846 == watch_triggered_yes
))
3848 other_write_watchpoint
= 1;
3853 if (other_write_watchpoint
3854 || bl
->watchpoint_type
== hw_access
)
3856 /* We're watching the same memory for writes,
3857 and the value changed since the last time we
3858 updated it, so this trap must be for a write.
3860 bs
->print_it
= print_it_noop
;
3865 case WP_VALUE_NOT_CHANGED
:
3866 if (b
->type
== bp_hardware_watchpoint
3867 || b
->type
== bp_watchpoint
)
3869 /* Don't stop: write watchpoints shouldn't fire if
3870 the value hasn't changed. */
3871 bs
->print_it
= print_it_noop
;
3879 /* Error from catch_errors. */
3880 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3881 if (b
->related_breakpoint
)
3882 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3883 b
->disposition
= disp_del_at_next_stop
;
3884 /* We've already printed what needs to be printed. */
3885 bs
->print_it
= print_it_done
;
3889 else /* must_check_value == 0 */
3891 /* This is a case where some watchpoint(s) triggered, but
3892 not at the address of this watchpoint, or else no
3893 watchpoint triggered after all. So don't print
3894 anything for this watchpoint. */
3895 bs
->print_it
= print_it_noop
;
3902 /* Check conditions (condition proper, frame, thread and ignore count)
3903 of breakpoint referred to by BS. If we should not stop for this
3904 breakpoint, set BS->stop to 0. */
3906 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3908 int thread_id
= pid_to_thread_id (ptid
);
3909 const struct bp_location
*bl
= bs
->breakpoint_at
;
3910 struct breakpoint
*b
= bl
->owner
;
3912 if (frame_id_p (b
->frame_id
)
3913 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3917 int value_is_zero
= 0;
3918 struct expression
*cond
;
3920 /* If this is a scope breakpoint, mark the associated
3921 watchpoint as triggered so that we will handle the
3922 out-of-scope event. We'll get to the watchpoint next
3924 if (b
->type
== bp_watchpoint_scope
)
3925 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3927 if (is_watchpoint (b
))
3932 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3934 int within_current_scope
= 1;
3936 /* We use value_mark and value_free_to_mark because it could
3937 be a long time before we return to the command level and
3938 call free_all_values. We can't call free_all_values
3939 because we might be in the middle of evaluating a
3941 struct value
*mark
= value_mark ();
3943 /* Need to select the frame, with all that implies so that
3944 the conditions will have the right context. Because we
3945 use the frame, we will not see an inlined function's
3946 variables when we arrive at a breakpoint at the start
3947 of the inlined function; the current frame will be the
3949 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3950 select_frame (get_current_frame ());
3953 struct frame_info
*frame
;
3955 /* For local watchpoint expressions, which particular
3956 instance of a local is being watched matters, so we
3957 keep track of the frame to evaluate the expression
3958 in. To evaluate the condition however, it doesn't
3959 really matter which instantiation of the function
3960 where the condition makes sense triggers the
3961 watchpoint. This allows an expression like "watch
3962 global if q > 10" set in `func', catch writes to
3963 global on all threads that call `func', or catch
3964 writes on all recursive calls of `func' by a single
3965 thread. We simply always evaluate the condition in
3966 the innermost frame that's executing where it makes
3967 sense to evaluate the condition. It seems
3969 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3971 select_frame (frame
);
3973 within_current_scope
= 0;
3975 if (within_current_scope
)
3977 = catch_errors (breakpoint_cond_eval
, cond
,
3978 "Error in testing breakpoint condition:\n",
3982 warning (_("Watchpoint condition cannot be tested "
3983 "in the current scope"));
3984 /* If we failed to set the right context for this
3985 watchpoint, unconditionally report it. */
3988 /* FIXME-someday, should give breakpoint # */
3989 value_free_to_mark (mark
);
3992 if (cond
&& value_is_zero
)
3996 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4000 else if (b
->ignore_count
> 0)
4003 annotate_ignore_count_change ();
4005 /* Increase the hit count even though we don't
4013 /* Get a bpstat associated with having just stopped at address
4014 BP_ADDR in thread PTID.
4016 Determine whether we stopped at a breakpoint, etc, or whether we
4017 don't understand this stop. Result is a chain of bpstat's such that:
4019 if we don't understand the stop, the result is a null pointer.
4021 if we understand why we stopped, the result is not null.
4023 Each element of the chain refers to a particular breakpoint or
4024 watchpoint at which we have stopped. (We may have stopped for
4025 several reasons concurrently.)
4027 Each element of the chain has valid next, breakpoint_at,
4028 commands, FIXME??? fields. */
4031 bpstat_stop_status (struct address_space
*aspace
,
4032 CORE_ADDR bp_addr
, ptid_t ptid
)
4034 struct breakpoint
*b
= NULL
;
4035 struct bp_location
*bl
, **blp_tmp
;
4036 struct bp_location
*loc
;
4037 /* Root of the chain of bpstat's */
4038 struct bpstats root_bs
[1];
4039 /* Pointer to the last thing in the chain currently. */
4040 bpstat bs
= root_bs
;
4042 int need_remove_insert
;
4044 /* ALL_BP_LOCATIONS iteration would break across
4045 update_global_location_list possibly executed by
4046 bpstat_check_breakpoint_conditions's inferior call. */
4050 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4053 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4055 /* For hardware watchpoints, we look only at the first location.
4056 The watchpoint_check function will work on the entire expression,
4057 not the individual locations. For read watchpoints, the
4058 watchpoints_triggered function has checked all locations
4060 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4063 if (bl
->shlib_disabled
)
4066 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4069 /* Come here if it's a watchpoint, or if the break address matches */
4071 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4073 /* Assume we stop. Should we find watchpoint that is not actually
4074 triggered, or if condition of breakpoint is false, we'll reset
4079 bpstat_check_watchpoint (bs
);
4083 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4084 || b
->type
== bp_longjmp_master
4085 || b
->type
== bp_std_terminate_master
)
4086 /* We do not stop for these. */
4089 bpstat_check_breakpoint_conditions (bs
, ptid
);
4095 /* We will stop here */
4096 if (b
->disposition
== disp_disable
)
4098 if (b
->enable_state
!= bp_permanent
)
4099 b
->enable_state
= bp_disabled
;
4100 update_global_location_list (0);
4104 bs
->commands
= b
->commands
;
4105 incref_counted_command_line (bs
->commands
);
4106 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4107 if (bs
->commands_left
4108 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4111 bs
->commands_left
->line
) == 0)))
4113 bs
->commands_left
= bs
->commands_left
->next
;
4118 /* Print nothing for this entry if we dont stop or dont print. */
4119 if (bs
->stop
== 0 || bs
->print
== 0)
4120 bs
->print_it
= print_it_noop
;
4124 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4126 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4129 bs
= bpstat_alloc (loc
, bs
);
4130 /* For hits of moribund locations, we should just proceed. */
4133 bs
->print_it
= print_it_noop
;
4137 bs
->next
= NULL
; /* Terminate the chain */
4139 /* If we aren't stopping, the value of some hardware watchpoint may
4140 not have changed, but the intermediate memory locations we are
4141 watching may have. Don't bother if we're stopping; this will get
4143 need_remove_insert
= 0;
4144 if (! bpstat_causes_stop (root_bs
->next
))
4145 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4147 && bs
->breakpoint_at
->owner
4148 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4150 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4151 /* Updating watchpoints invalidates bs->breakpoint_at.
4152 Prevent further code from trying to use it. */
4153 bs
->breakpoint_at
= NULL
;
4154 need_remove_insert
= 1;
4157 if (need_remove_insert
)
4158 update_global_location_list (1);
4160 return root_bs
->next
;
4163 /* Tell what to do about this bpstat. */
4165 bpstat_what (bpstat bs
)
4167 /* Classify each bpstat as one of the following. */
4170 /* This bpstat element has no effect on the main_action. */
4173 /* There was a watchpoint, stop but don't print. */
4176 /* There was a watchpoint, stop and print. */
4179 /* There was a breakpoint but we're not stopping. */
4182 /* There was a breakpoint, stop but don't print. */
4185 /* There was a breakpoint, stop and print. */
4188 /* We hit the longjmp breakpoint. */
4191 /* We hit the longjmp_resume breakpoint. */
4194 /* We hit the step_resume breakpoint. */
4197 /* We hit the shared library event breakpoint. */
4200 /* We hit the jit event breakpoint. */
4203 /* This is just used to count how many enums there are. */
4207 /* Here is the table which drives this routine. So that we can
4208 format it pretty, we define some abbreviations for the
4209 enum bpstat_what codes. */
4210 #define kc BPSTAT_WHAT_KEEP_CHECKING
4211 #define ss BPSTAT_WHAT_STOP_SILENT
4212 #define sn BPSTAT_WHAT_STOP_NOISY
4213 #define sgl BPSTAT_WHAT_SINGLE
4214 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4215 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4216 #define sr BPSTAT_WHAT_STEP_RESUME
4217 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4218 #define jit BPSTAT_WHAT_CHECK_JIT
4220 /* "Can't happen." Might want to print an error message.
4221 abort() is not out of the question, but chances are GDB is just
4222 a bit confused, not unusable. */
4223 #define err BPSTAT_WHAT_STOP_NOISY
4225 /* Given an old action and a class, come up with a new action. */
4226 /* One interesting property of this table is that wp_silent is the same
4227 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4228 after stopping, the check for whether to step over a breakpoint
4229 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4230 reference to how we stopped. We retain separate wp_silent and
4231 bp_silent codes in case we want to change that someday.
4233 Another possibly interesting property of this table is that
4234 there's a partial ordering, priority-like, of the actions. Once
4235 you've decided that some action is appropriate, you'll never go
4236 back and decide something of a lower priority is better. The
4239 kc < jit clr sgl shl slr sn sr ss
4240 sgl < jit shl slr sn sr ss
4241 slr < jit err shl sn sr ss
4242 clr < jit err shl sn sr ss
4249 What I think this means is that we don't need a damned table
4250 here. If you just put the rows and columns in the right order,
4251 it'd look awfully regular. We could simply walk the bpstat list
4252 and choose the highest priority action we find, with a little
4253 logic to handle the 'err' cases. */
4255 /* step_resume entries: a step resume breakpoint overrides another
4256 breakpoint of signal handling (see comment in wait_for_inferior
4257 at where we set the step_resume breakpoint). */
4259 static const enum bpstat_what_main_action
4260 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4263 /* kc ss sn sgl slr clr sr shl jit */
4264 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4265 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4266 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4267 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4268 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4269 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4270 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4271 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4272 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4273 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4274 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4288 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4289 struct bpstat_what retval
;
4291 retval
.call_dummy
= STOP_NONE
;
4292 for (; bs
!= NULL
; bs
= bs
->next
)
4294 enum class bs_class
= no_effect
;
4295 if (bs
->breakpoint_at
== NULL
)
4296 /* I suspect this can happen if it was a momentary breakpoint
4297 which has since been deleted. */
4299 if (bs
->breakpoint_at
->owner
== NULL
)
4300 bs_class
= bp_nostop
;
4302 switch (bs
->breakpoint_at
->owner
->type
)
4308 case bp_hardware_breakpoint
:
4314 bs_class
= bp_noisy
;
4316 bs_class
= bp_silent
;
4319 bs_class
= bp_nostop
;
4322 case bp_hardware_watchpoint
:
4323 case bp_read_watchpoint
:
4324 case bp_access_watchpoint
:
4328 bs_class
= wp_noisy
;
4330 bs_class
= wp_silent
;
4333 /* There was a watchpoint, but we're not stopping.
4334 This requires no further action. */
4335 bs_class
= no_effect
;
4338 bs_class
= long_jump
;
4340 case bp_longjmp_resume
:
4341 bs_class
= long_resume
;
4343 case bp_step_resume
:
4346 bs_class
= step_resume
;
4349 /* It is for the wrong frame. */
4350 bs_class
= bp_nostop
;
4352 case bp_watchpoint_scope
:
4353 bs_class
= bp_nostop
;
4355 case bp_shlib_event
:
4356 bs_class
= shlib_event
;
4359 bs_class
= jit_event
;
4361 case bp_thread_event
:
4362 case bp_overlay_event
:
4363 case bp_longjmp_master
:
4364 case bp_std_terminate_master
:
4365 bs_class
= bp_nostop
;
4371 bs_class
= bp_noisy
;
4373 bs_class
= bp_silent
;
4376 /* There was a catchpoint, but we're not stopping.
4377 This requires no further action. */
4378 bs_class
= no_effect
;
4381 /* Make sure the action is stop (silent or noisy),
4382 so infrun.c pops the dummy frame. */
4383 bs_class
= bp_silent
;
4384 retval
.call_dummy
= STOP_STACK_DUMMY
;
4386 case bp_std_terminate
:
4387 /* Make sure the action is stop (silent or noisy),
4388 so infrun.c pops the dummy frame. */
4389 bs_class
= bp_silent
;
4390 retval
.call_dummy
= STOP_STD_TERMINATE
;
4393 case bp_fast_tracepoint
:
4394 /* Tracepoint hits should not be reported back to GDB, and
4395 if one got through somehow, it should have been filtered
4397 internal_error (__FILE__
, __LINE__
,
4398 _("bpstat_what: tracepoint encountered"));
4401 current_action
= table
[(int) bs_class
][(int) current_action
];
4403 retval
.main_action
= current_action
;
4407 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4408 without hardware support). This isn't related to a specific bpstat,
4409 just to things like whether watchpoints are set. */
4412 bpstat_should_step (void)
4414 struct breakpoint
*b
;
4416 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4422 bpstat_causes_stop (bpstat bs
)
4424 for (; bs
!= NULL
; bs
= bs
->next
)
4433 /* Print the LOC location out of the list of B->LOC locations. */
4435 static void print_breakpoint_location (struct breakpoint
*b
,
4436 struct bp_location
*loc
,
4438 struct ui_stream
*stb
)
4440 struct cleanup
*old_chain
= save_current_program_space ();
4442 if (loc
!= NULL
&& loc
->shlib_disabled
)
4446 set_current_program_space (loc
->pspace
);
4448 if (b
->source_file
&& loc
)
4451 = find_pc_sect_function (loc
->address
, loc
->section
);
4454 ui_out_text (uiout
, "in ");
4455 ui_out_field_string (uiout
, "func",
4456 SYMBOL_PRINT_NAME (sym
));
4457 ui_out_wrap_hint (uiout
, wrap_indent
);
4458 ui_out_text (uiout
, " at ");
4460 ui_out_field_string (uiout
, "file", b
->source_file
);
4461 ui_out_text (uiout
, ":");
4463 if (ui_out_is_mi_like_p (uiout
))
4465 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4466 char *fullname
= symtab_to_fullname (sal
.symtab
);
4469 ui_out_field_string (uiout
, "fullname", fullname
);
4472 ui_out_field_int (uiout
, "line", b
->line_number
);
4476 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4478 ui_out_field_stream (uiout
, "at", stb
);
4481 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4483 do_cleanups (old_chain
);
4486 /* Print B to gdb_stdout. */
4488 print_one_breakpoint_location (struct breakpoint
*b
,
4489 struct bp_location
*loc
,
4491 struct bp_location
**last_loc
,
4492 int print_address_bits
,
4495 struct command_line
*l
;
4497 struct ep_type_description
4502 static struct ep_type_description bptypes
[] =
4504 {bp_none
, "?deleted?"},
4505 {bp_breakpoint
, "breakpoint"},
4506 {bp_hardware_breakpoint
, "hw breakpoint"},
4507 {bp_until
, "until"},
4508 {bp_finish
, "finish"},
4509 {bp_watchpoint
, "watchpoint"},
4510 {bp_hardware_watchpoint
, "hw watchpoint"},
4511 {bp_read_watchpoint
, "read watchpoint"},
4512 {bp_access_watchpoint
, "acc watchpoint"},
4513 {bp_longjmp
, "longjmp"},
4514 {bp_longjmp_resume
, "longjmp resume"},
4515 {bp_step_resume
, "step resume"},
4516 {bp_watchpoint_scope
, "watchpoint scope"},
4517 {bp_call_dummy
, "call dummy"},
4518 {bp_std_terminate
, "std::terminate"},
4519 {bp_shlib_event
, "shlib events"},
4520 {bp_thread_event
, "thread events"},
4521 {bp_overlay_event
, "overlay events"},
4522 {bp_longjmp_master
, "longjmp master"},
4523 {bp_std_terminate_master
, "std::terminate master"},
4524 {bp_catchpoint
, "catchpoint"},
4525 {bp_tracepoint
, "tracepoint"},
4526 {bp_fast_tracepoint
, "fast tracepoint"},
4527 {bp_jit_event
, "jit events"},
4530 static char bpenables
[] = "nynny";
4531 char wrap_indent
[80];
4532 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4533 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4534 struct cleanup
*bkpt_chain
;
4536 int header_of_multiple
= 0;
4537 int part_of_multiple
= (loc
!= NULL
);
4538 struct value_print_options opts
;
4540 get_user_print_options (&opts
);
4542 gdb_assert (!loc
|| loc_number
!= 0);
4543 /* See comment in print_one_breakpoint concerning
4544 treatment of breakpoints with single disabled
4548 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4549 header_of_multiple
= 1;
4554 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4558 if (part_of_multiple
)
4561 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4562 ui_out_field_string (uiout
, "number", formatted
);
4567 ui_out_field_int (uiout
, "number", b
->number
);
4572 if (part_of_multiple
)
4573 ui_out_field_skip (uiout
, "type");
4576 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4577 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4578 internal_error (__FILE__
, __LINE__
,
4579 _("bptypes table does not describe type #%d."),
4581 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4586 if (part_of_multiple
)
4587 ui_out_field_skip (uiout
, "disp");
4589 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4594 if (part_of_multiple
)
4595 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4597 ui_out_field_fmt (uiout
, "enabled", "%c",
4598 bpenables
[(int) b
->enable_state
]);
4599 ui_out_spaces (uiout
, 2);
4603 strcpy (wrap_indent
, " ");
4604 if (opts
.addressprint
)
4606 if (print_address_bits
<= 32)
4607 strcat (wrap_indent
, " ");
4609 strcat (wrap_indent
, " ");
4612 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4614 /* Although the print_one can possibly print
4615 all locations, calling it here is not likely
4616 to get any nice result. So, make sure there's
4617 just one location. */
4618 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4619 b
->ops
->print_one (b
, last_loc
);
4625 internal_error (__FILE__
, __LINE__
,
4626 _("print_one_breakpoint: bp_none encountered\n"));
4630 case bp_hardware_watchpoint
:
4631 case bp_read_watchpoint
:
4632 case bp_access_watchpoint
:
4633 /* Field 4, the address, is omitted (which makes the columns
4634 not line up too nicely with the headers, but the effect
4635 is relatively readable). */
4636 if (opts
.addressprint
)
4637 ui_out_field_skip (uiout
, "addr");
4639 ui_out_field_string (uiout
, "what", b
->exp_string
);
4643 case bp_hardware_breakpoint
:
4647 case bp_longjmp_resume
:
4648 case bp_step_resume
:
4649 case bp_watchpoint_scope
:
4651 case bp_std_terminate
:
4652 case bp_shlib_event
:
4653 case bp_thread_event
:
4654 case bp_overlay_event
:
4655 case bp_longjmp_master
:
4656 case bp_std_terminate_master
:
4658 case bp_fast_tracepoint
:
4660 if (opts
.addressprint
)
4663 if (header_of_multiple
)
4664 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4665 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4666 ui_out_field_string (uiout
, "addr", "<PENDING>");
4668 ui_out_field_core_addr (uiout
, "addr",
4669 loc
->gdbarch
, loc
->address
);
4672 if (!header_of_multiple
)
4673 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4680 /* For backward compatibility, don't display inferiors unless there
4683 && !header_of_multiple
4685 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4686 && (number_of_program_spaces () > 1
4687 || number_of_inferiors () > 1)
4688 && loc
->owner
->type
!= bp_catchpoint
)))
4690 struct inferior
*inf
;
4693 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4695 if (inf
->pspace
== loc
->pspace
)
4700 ui_out_text (uiout
, " inf ");
4703 ui_out_text (uiout
, ", ");
4704 ui_out_text (uiout
, plongest (inf
->num
));
4709 if (!part_of_multiple
)
4711 if (b
->thread
!= -1)
4713 /* FIXME: This seems to be redundant and lost here; see the
4714 "stop only in" line a little further down. */
4715 ui_out_text (uiout
, " thread ");
4716 ui_out_field_int (uiout
, "thread", b
->thread
);
4718 else if (b
->task
!= 0)
4720 ui_out_text (uiout
, " task ");
4721 ui_out_field_int (uiout
, "task", b
->task
);
4725 ui_out_text (uiout
, "\n");
4727 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4730 ui_out_text (uiout
, "\tstop only in stack frame at ");
4731 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4733 ui_out_field_core_addr (uiout
, "frame",
4734 b
->gdbarch
, b
->frame_id
.stack_addr
);
4735 ui_out_text (uiout
, "\n");
4738 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4740 /* We do not print the condition for Ada exception catchpoints
4741 because the condition is an internal implementation detail
4742 that we do not want to expose to the user. */
4744 if (is_tracepoint (b
))
4745 ui_out_text (uiout
, "\ttrace only if ");
4747 ui_out_text (uiout
, "\tstop only if ");
4748 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4749 ui_out_text (uiout
, "\n");
4752 if (!part_of_multiple
&& b
->thread
!= -1)
4754 /* FIXME should make an annotation for this */
4755 ui_out_text (uiout
, "\tstop only in thread ");
4756 ui_out_field_int (uiout
, "thread", b
->thread
);
4757 ui_out_text (uiout
, "\n");
4760 if (!part_of_multiple
&& b
->hit_count
)
4762 /* FIXME should make an annotation for this */
4763 if (ep_is_catchpoint (b
))
4764 ui_out_text (uiout
, "\tcatchpoint");
4766 ui_out_text (uiout
, "\tbreakpoint");
4767 ui_out_text (uiout
, " already hit ");
4768 ui_out_field_int (uiout
, "times", b
->hit_count
);
4769 if (b
->hit_count
== 1)
4770 ui_out_text (uiout
, " time\n");
4772 ui_out_text (uiout
, " times\n");
4775 /* Output the count also if it is zero, but only if this is
4776 mi. FIXME: Should have a better test for this. */
4777 if (ui_out_is_mi_like_p (uiout
))
4778 if (!part_of_multiple
&& b
->hit_count
== 0)
4779 ui_out_field_int (uiout
, "times", b
->hit_count
);
4781 if (!part_of_multiple
&& b
->ignore_count
)
4784 ui_out_text (uiout
, "\tignore next ");
4785 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4786 ui_out_text (uiout
, " hits\n");
4789 l
= b
->commands
? b
->commands
->commands
: NULL
;
4790 if (!part_of_multiple
&& l
)
4792 struct cleanup
*script_chain
;
4795 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4796 print_command_lines (uiout
, l
, 4);
4797 do_cleanups (script_chain
);
4800 if (!part_of_multiple
&& b
->pass_count
)
4802 annotate_field (10);
4803 ui_out_text (uiout
, "\tpass count ");
4804 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4805 ui_out_text (uiout
, " \n");
4808 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4811 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4812 else if (b
->exp_string
)
4813 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4816 do_cleanups (bkpt_chain
);
4817 do_cleanups (old_chain
);
4821 print_one_breakpoint (struct breakpoint
*b
,
4822 struct bp_location
**last_loc
, int print_address_bits
,
4825 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4826 print_address_bits
, allflag
);
4828 /* If this breakpoint has custom print function,
4829 it's already printed. Otherwise, print individual
4830 locations, if any. */
4831 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4833 /* If breakpoint has a single location that is
4834 disabled, we print it as if it had
4835 several locations, since otherwise it's hard to
4836 represent "breakpoint enabled, location disabled"
4838 Note that while hardware watchpoints have
4839 several locations internally, that's no a property
4842 && !is_hardware_watchpoint (b
)
4843 && (b
->loc
->next
|| !b
->loc
->enabled
)
4844 && !ui_out_is_mi_like_p (uiout
))
4846 struct bp_location
*loc
;
4848 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4849 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4850 print_address_bits
, allflag
);
4856 breakpoint_address_bits (struct breakpoint
*b
)
4858 int print_address_bits
= 0;
4859 struct bp_location
*loc
;
4861 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4865 /* Software watchpoints that aren't watching memory don't have
4866 an address to print. */
4867 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4870 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4871 if (addr_bit
> print_address_bits
)
4872 print_address_bits
= addr_bit
;
4875 return print_address_bits
;
4878 struct captured_breakpoint_query_args
4884 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4886 struct captured_breakpoint_query_args
*args
= data
;
4887 struct breakpoint
*b
;
4888 struct bp_location
*dummy_loc
= NULL
;
4891 if (args
->bnum
== b
->number
)
4893 int print_address_bits
= breakpoint_address_bits (b
);
4894 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4902 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4904 struct captured_breakpoint_query_args args
;
4906 /* For the moment we don't trust print_one_breakpoint() to not throw
4908 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4909 error_message
, RETURN_MASK_ALL
) < 0)
4915 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4916 catchpoints, et.al.). */
4919 user_settable_breakpoint (const struct breakpoint
*b
)
4921 return (b
->type
== bp_breakpoint
4922 || b
->type
== bp_catchpoint
4923 || b
->type
== bp_hardware_breakpoint
4924 || is_tracepoint (b
)
4925 || is_watchpoint (b
));
4928 /* Print information on user settable breakpoint (watchpoint, etc)
4929 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4930 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4931 FILTER is non-NULL, call it on each breakpoint and only include the
4932 ones for which it returns non-zero. Return the total number of
4933 breakpoints listed. */
4936 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4938 struct breakpoint
*b
;
4939 struct bp_location
*last_loc
= NULL
;
4940 int nr_printable_breakpoints
;
4941 struct cleanup
*bkpttbl_chain
;
4942 struct value_print_options opts
;
4943 int print_address_bits
= 0;
4945 get_user_print_options (&opts
);
4947 /* Compute the number of rows in the table, as well as the
4948 size required for address fields. */
4949 nr_printable_breakpoints
= 0;
4952 || bnum
== b
->number
)
4954 /* If we have a filter, only list the breakpoints it accepts. */
4955 if (filter
&& !filter (b
))
4958 if (allflag
|| user_settable_breakpoint (b
))
4960 int addr_bit
= breakpoint_address_bits (b
);
4961 if (addr_bit
> print_address_bits
)
4962 print_address_bits
= addr_bit
;
4964 nr_printable_breakpoints
++;
4968 if (opts
.addressprint
)
4970 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4974 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4977 if (nr_printable_breakpoints
> 0)
4978 annotate_breakpoints_headers ();
4979 if (nr_printable_breakpoints
> 0)
4981 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4982 if (nr_printable_breakpoints
> 0)
4984 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4985 if (nr_printable_breakpoints
> 0)
4987 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4988 if (nr_printable_breakpoints
> 0)
4990 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4991 if (opts
.addressprint
)
4993 if (nr_printable_breakpoints
> 0)
4995 if (print_address_bits
<= 32)
4996 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4998 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5000 if (nr_printable_breakpoints
> 0)
5002 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5003 ui_out_table_body (uiout
);
5004 if (nr_printable_breakpoints
> 0)
5005 annotate_breakpoints_table ();
5011 || bnum
== b
->number
)
5013 /* If we have a filter, only list the breakpoints it accepts. */
5014 if (filter
&& !filter (b
))
5017 /* We only print out user settable breakpoints unless the
5019 if (allflag
|| user_settable_breakpoint (b
))
5020 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5024 do_cleanups (bkpttbl_chain
);
5026 if (nr_printable_breakpoints
== 0)
5028 /* If there's a filter, let the caller decide how to report empty list. */
5032 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5034 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5040 if (last_loc
&& !server_command
)
5041 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5044 /* FIXME? Should this be moved up so that it is only called when
5045 there have been breakpoints? */
5046 annotate_breakpoints_table_end ();
5048 return nr_printable_breakpoints
;
5051 /* Display the value of default-collect in a way that is generally
5052 compatible with the breakpoint list. */
5055 default_collect_info (void)
5057 /* If it has no value (which is frequently the case), say nothing; a
5058 message like "No default-collect." gets in user's face when it's
5060 if (!*default_collect
)
5063 /* The following phrase lines up nicely with per-tracepoint collect
5065 ui_out_text (uiout
, "default collect ");
5066 ui_out_field_string (uiout
, "default-collect", default_collect
);
5067 ui_out_text (uiout
, " \n");
5071 breakpoints_info (char *bnum_exp
, int from_tty
)
5076 bnum
= parse_and_eval_long (bnum_exp
);
5078 breakpoint_1 (bnum
, 0, NULL
);
5080 default_collect_info ();
5084 watchpoints_info (char *wpnum_exp
, int from_tty
)
5086 int wpnum
= -1, num_printed
;
5089 wpnum
= parse_and_eval_long (wpnum_exp
);
5091 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5093 if (num_printed
== 0)
5096 ui_out_message (uiout
, 0, "No watchpoints.\n");
5098 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5103 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5108 bnum
= parse_and_eval_long (bnum_exp
);
5110 breakpoint_1 (bnum
, 1, NULL
);
5112 default_collect_info ();
5116 breakpoint_has_pc (struct breakpoint
*b
,
5117 struct program_space
*pspace
,
5118 CORE_ADDR pc
, struct obj_section
*section
)
5120 struct bp_location
*bl
= b
->loc
;
5121 for (; bl
; bl
= bl
->next
)
5123 if (bl
->pspace
== pspace
5124 && bl
->address
== pc
5125 && (!overlay_debugging
|| bl
->section
== section
))
5131 /* Print a message describing any breakpoints set at PC. This
5132 concerns with logical breakpoints, so we match program spaces, not
5136 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5137 struct program_space
*pspace
, CORE_ADDR pc
,
5138 struct obj_section
*section
, int thread
)
5141 struct breakpoint
*b
;
5144 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5148 printf_filtered (_("Note: breakpoint "));
5149 else /* if (others == ???) */
5150 printf_filtered (_("Note: breakpoints "));
5152 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5155 printf_filtered ("%d", b
->number
);
5156 if (b
->thread
== -1 && thread
!= -1)
5157 printf_filtered (" (all threads)");
5158 else if (b
->thread
!= -1)
5159 printf_filtered (" (thread %d)", b
->thread
);
5160 printf_filtered ("%s%s ",
5161 ((b
->enable_state
== bp_disabled
5162 || b
->enable_state
== bp_call_disabled
5163 || b
->enable_state
== bp_startup_disabled
)
5165 : b
->enable_state
== bp_permanent
5169 : ((others
== 1) ? " and" : ""));
5171 printf_filtered (_("also set at pc "));
5172 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5173 printf_filtered (".\n");
5177 /* Set the default place to put a breakpoint
5178 for the `break' command with no arguments. */
5181 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5182 CORE_ADDR addr
, struct symtab
*symtab
,
5185 default_breakpoint_valid
= valid
;
5186 default_breakpoint_pspace
= pspace
;
5187 default_breakpoint_address
= addr
;
5188 default_breakpoint_symtab
= symtab
;
5189 default_breakpoint_line
= line
;
5192 /* Return true iff it is meaningful to use the address member of
5193 BPT. For some breakpoint types, the address member is irrelevant
5194 and it makes no sense to attempt to compare it to other addresses
5195 (or use it for any other purpose either).
5197 More specifically, each of the following breakpoint types will always
5198 have a zero valued address and we don't want to mark breakpoints of any of
5199 these types to be a duplicate of an actual breakpoint at address zero:
5207 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5209 enum bptype type
= bpt
->type
;
5211 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5214 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5215 true if LOC1 and LOC2 represent the same watchpoint location. */
5218 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5220 /* Note that this checks the owner's type, not the location's. In
5221 case the target does not support read watchpoints, but does
5222 support access watchpoints, we'll have bp_read_watchpoint
5223 watchpoints with hw_access locations. Those should be considered
5224 duplicates of hw_read locations. The hw_read locations will
5225 become hw_access locations later. */
5226 return (loc1
->owner
->type
== loc2
->owner
->type
5227 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5228 && loc1
->address
== loc2
->address
5229 && loc1
->length
== loc2
->length
);
5232 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5233 same breakpoint location. In most targets, this can only be true
5234 if ASPACE1 matches ASPACE2. On targets that have global
5235 breakpoints, the address space doesn't really matter. */
5238 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5239 struct address_space
*aspace2
, CORE_ADDR addr2
)
5241 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5242 || aspace1
== aspace2
)
5246 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5247 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5248 represent the same location. */
5251 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5253 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5254 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5256 if (hw_point1
!= hw_point2
)
5259 return watchpoint_locations_match (loc1
, loc2
);
5261 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5262 loc2
->pspace
->aspace
, loc2
->address
);
5266 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5267 int bnum
, int have_bnum
)
5272 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5273 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5275 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5276 bnum
, astr1
, astr2
);
5278 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5281 /* Adjust a breakpoint's address to account for architectural constraints
5282 on breakpoint placement. Return the adjusted address. Note: Very
5283 few targets require this kind of adjustment. For most targets,
5284 this function is simply the identity function. */
5287 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5288 CORE_ADDR bpaddr
, enum bptype bptype
)
5290 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5292 /* Very few targets need any kind of breakpoint adjustment. */
5295 else if (bptype
== bp_watchpoint
5296 || bptype
== bp_hardware_watchpoint
5297 || bptype
== bp_read_watchpoint
5298 || bptype
== bp_access_watchpoint
5299 || bptype
== bp_catchpoint
)
5301 /* Watchpoints and the various bp_catch_* eventpoints should not
5302 have their addresses modified. */
5307 CORE_ADDR adjusted_bpaddr
;
5309 /* Some targets have architectural constraints on the placement
5310 of breakpoint instructions. Obtain the adjusted address. */
5311 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5313 /* An adjusted breakpoint address can significantly alter
5314 a user's expectations. Print a warning if an adjustment
5316 if (adjusted_bpaddr
!= bpaddr
)
5317 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5319 return adjusted_bpaddr
;
5323 /* Allocate a struct bp_location. */
5325 static struct bp_location
*
5326 allocate_bp_location (struct breakpoint
*bpt
)
5328 struct bp_location
*loc
, *loc_p
;
5330 loc
= xmalloc (sizeof (struct bp_location
));
5331 memset (loc
, 0, sizeof (*loc
));
5335 loc
->shlib_disabled
= 0;
5344 case bp_longjmp_resume
:
5345 case bp_step_resume
:
5346 case bp_watchpoint_scope
:
5348 case bp_std_terminate
:
5349 case bp_shlib_event
:
5350 case bp_thread_event
:
5351 case bp_overlay_event
:
5353 case bp_longjmp_master
:
5354 case bp_std_terminate_master
:
5355 loc
->loc_type
= bp_loc_software_breakpoint
;
5357 case bp_hardware_breakpoint
:
5358 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5360 case bp_hardware_watchpoint
:
5361 case bp_read_watchpoint
:
5362 case bp_access_watchpoint
:
5363 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5368 case bp_fast_tracepoint
:
5369 loc
->loc_type
= bp_loc_other
;
5372 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5378 static void free_bp_location (struct bp_location
*loc
)
5383 if (loc
->function_name
)
5384 xfree (loc
->function_name
);
5389 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5390 that has type BPTYPE and has no locations as yet. */
5391 /* This function is used in gdbtk sources and thus can not be made static. */
5393 static struct breakpoint
*
5394 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5397 struct breakpoint
*b
, *b1
;
5399 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5400 memset (b
, 0, sizeof (*b
));
5403 b
->gdbarch
= gdbarch
;
5404 b
->language
= current_language
->la_language
;
5405 b
->input_radix
= input_radix
;
5407 b
->enable_state
= bp_enabled
;
5410 b
->ignore_count
= 0;
5412 b
->frame_id
= null_frame_id
;
5413 b
->forked_inferior_pid
= null_ptid
;
5414 b
->exec_pathname
= NULL
;
5415 b
->syscalls_to_be_caught
= NULL
;
5417 b
->condition_not_parsed
= 0;
5419 /* Add this breakpoint to the end of the chain
5420 so that a list of breakpoints will come out in order
5421 of increasing numbers. */
5423 b1
= breakpoint_chain
;
5425 breakpoint_chain
= b
;
5435 /* Initialize loc->function_name. */
5437 set_breakpoint_location_function (struct bp_location
*loc
)
5439 if (loc
->owner
->type
== bp_breakpoint
5440 || loc
->owner
->type
== bp_hardware_breakpoint
5441 || is_tracepoint (loc
->owner
))
5443 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5445 if (loc
->function_name
)
5446 loc
->function_name
= xstrdup (loc
->function_name
);
5450 /* Attempt to determine architecture of location identified by SAL. */
5451 static struct gdbarch
*
5452 get_sal_arch (struct symtab_and_line sal
)
5455 return get_objfile_arch (sal
.section
->objfile
);
5457 return get_objfile_arch (sal
.symtab
->objfile
);
5462 /* set_raw_breakpoint is a low level routine for allocating and
5463 partially initializing a breakpoint of type BPTYPE. The newly
5464 created breakpoint's address, section, source file name, and line
5465 number are provided by SAL. The newly created and partially
5466 initialized breakpoint is added to the breakpoint chain and
5467 is also returned as the value of this function.
5469 It is expected that the caller will complete the initialization of
5470 the newly created breakpoint struct as well as output any status
5471 information regarding the creation of a new breakpoint. In
5472 particular, set_raw_breakpoint does NOT set the breakpoint
5473 number! Care should be taken to not allow an error to occur
5474 prior to completing the initialization of the breakpoint. If this
5475 should happen, a bogus breakpoint will be left on the chain. */
5478 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5479 struct symtab_and_line sal
, enum bptype bptype
)
5481 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5482 CORE_ADDR adjusted_address
;
5483 struct gdbarch
*loc_gdbarch
;
5485 loc_gdbarch
= get_sal_arch (sal
);
5487 loc_gdbarch
= b
->gdbarch
;
5489 if (bptype
!= bp_catchpoint
)
5490 gdb_assert (sal
.pspace
!= NULL
);
5492 /* Adjust the breakpoint's address prior to allocating a location.
5493 Once we call allocate_bp_location(), that mostly uninitialized
5494 location will be placed on the location chain. Adjustment of the
5495 breakpoint may cause target_read_memory() to be called and we do
5496 not want its scan of the location chain to find a breakpoint and
5497 location that's only been partially initialized. */
5498 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5500 b
->loc
= allocate_bp_location (b
);
5501 b
->loc
->gdbarch
= loc_gdbarch
;
5502 b
->loc
->requested_address
= sal
.pc
;
5503 b
->loc
->address
= adjusted_address
;
5504 b
->loc
->pspace
= sal
.pspace
;
5506 /* Store the program space that was used to set the breakpoint, for
5507 breakpoint resetting. */
5508 b
->pspace
= sal
.pspace
;
5510 if (sal
.symtab
== NULL
)
5511 b
->source_file
= NULL
;
5513 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5514 b
->loc
->section
= sal
.section
;
5515 b
->line_number
= sal
.line
;
5517 set_breakpoint_location_function (b
->loc
);
5519 breakpoints_changed ();
5525 /* Note that the breakpoint object B describes a permanent breakpoint
5526 instruction, hard-wired into the inferior's code. */
5528 make_breakpoint_permanent (struct breakpoint
*b
)
5530 struct bp_location
*bl
;
5531 b
->enable_state
= bp_permanent
;
5533 /* By definition, permanent breakpoints are already present in the code.
5534 Mark all locations as inserted. For now, make_breakpoint_permanent
5535 is called in just one place, so it's hard to say if it's reasonable
5536 to have permanent breakpoint with multiple locations or not,
5537 but it's easy to implmement. */
5538 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5542 /* Call this routine when stepping and nexting to enable a breakpoint
5543 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5544 set_longjmp_resume_breakpoint() to figure out where we are going. */
5547 set_longjmp_breakpoint (int thread
)
5549 struct breakpoint
*b
, *temp
;
5551 /* To avoid having to rescan all objfile symbols at every step,
5552 we maintain a list of continually-inserted but always disabled
5553 longjmp "master" breakpoints. Here, we simply create momentary
5554 clones of those and enable them for the requested thread. */
5555 ALL_BREAKPOINTS_SAFE (b
, temp
)
5556 if (b
->pspace
== current_program_space
5557 && b
->type
== bp_longjmp_master
)
5559 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5560 clone
->type
= bp_longjmp
;
5561 clone
->thread
= thread
;
5565 /* Delete all longjmp breakpoints from THREAD. */
5567 delete_longjmp_breakpoint (int thread
)
5569 struct breakpoint
*b
, *temp
;
5571 ALL_BREAKPOINTS_SAFE (b
, temp
)
5572 if (b
->type
== bp_longjmp
)
5574 if (b
->thread
== thread
)
5575 delete_breakpoint (b
);
5580 enable_overlay_breakpoints (void)
5582 struct breakpoint
*b
;
5585 if (b
->type
== bp_overlay_event
)
5587 b
->enable_state
= bp_enabled
;
5588 update_global_location_list (1);
5589 overlay_events_enabled
= 1;
5594 disable_overlay_breakpoints (void)
5596 struct breakpoint
*b
;
5599 if (b
->type
== bp_overlay_event
)
5601 b
->enable_state
= bp_disabled
;
5602 update_global_location_list (0);
5603 overlay_events_enabled
= 0;
5607 /* Set an active std::terminate breakpoint for each std::terminate
5608 master breakpoint. */
5610 set_std_terminate_breakpoint (void)
5612 struct breakpoint
*b
, *temp
;
5614 ALL_BREAKPOINTS_SAFE (b
, temp
)
5615 if (b
->pspace
== current_program_space
5616 && b
->type
== bp_std_terminate_master
)
5618 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5619 clone
->type
= bp_std_terminate
;
5623 /* Delete all the std::terminate breakpoints. */
5625 delete_std_terminate_breakpoint (void)
5627 struct breakpoint
*b
, *temp
;
5629 ALL_BREAKPOINTS_SAFE (b
, temp
)
5630 if (b
->type
== bp_std_terminate
)
5631 delete_breakpoint (b
);
5635 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5637 struct breakpoint
*b
;
5639 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5641 b
->enable_state
= bp_enabled
;
5642 /* addr_string has to be used or breakpoint_re_set will delete me. */
5644 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5646 update_global_location_list_nothrow (1);
5652 remove_thread_event_breakpoints (void)
5654 struct breakpoint
*b
, *temp
;
5656 ALL_BREAKPOINTS_SAFE (b
, temp
)
5657 if (b
->type
== bp_thread_event
5658 && b
->loc
->pspace
== current_program_space
)
5659 delete_breakpoint (b
);
5662 struct captured_parse_breakpoint_args
5665 struct symtabs_and_lines
*sals_p
;
5666 char ***addr_string_p
;
5670 struct lang_and_radix
5676 /* Create a breakpoint for JIT code registration and unregistration. */
5679 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5681 struct breakpoint
*b
;
5683 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5684 update_global_location_list_nothrow (1);
5689 remove_solib_event_breakpoints (void)
5691 struct breakpoint
*b
, *temp
;
5693 ALL_BREAKPOINTS_SAFE (b
, temp
)
5694 if (b
->type
== bp_shlib_event
5695 && b
->loc
->pspace
== current_program_space
)
5696 delete_breakpoint (b
);
5700 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5702 struct breakpoint
*b
;
5704 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5705 update_global_location_list_nothrow (1);
5709 /* Disable any breakpoints that are on code in shared libraries. Only
5710 apply to enabled breakpoints, disabled ones can just stay disabled. */
5713 disable_breakpoints_in_shlibs (void)
5715 struct bp_location
*loc
, **locp_tmp
;
5717 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5719 struct breakpoint
*b
= loc
->owner
;
5720 /* We apply the check to all breakpoints, including disabled
5721 for those with loc->duplicate set. This is so that when breakpoint
5722 becomes enabled, or the duplicate is removed, gdb will try to insert
5723 all breakpoints. If we don't set shlib_disabled here, we'll try
5724 to insert those breakpoints and fail. */
5725 if (((b
->type
== bp_breakpoint
)
5726 || (b
->type
== bp_jit_event
)
5727 || (b
->type
== bp_hardware_breakpoint
)
5728 || (is_tracepoint (b
)))
5729 && loc
->pspace
== current_program_space
5730 && !loc
->shlib_disabled
5732 && PC_SOLIB (loc
->address
)
5734 && solib_name_from_address (loc
->pspace
, loc
->address
)
5738 loc
->shlib_disabled
= 1;
5743 /* Disable any breakpoints that are in in an unloaded shared library. Only
5744 apply to enabled breakpoints, disabled ones can just stay disabled. */
5747 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5749 struct bp_location
*loc
, **locp_tmp
;
5750 int disabled_shlib_breaks
= 0;
5752 /* SunOS a.out shared libraries are always mapped, so do not
5753 disable breakpoints; they will only be reported as unloaded
5754 through clear_solib when GDB discards its shared library
5755 list. See clear_solib for more information. */
5756 if (exec_bfd
!= NULL
5757 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5760 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5762 struct breakpoint
*b
= loc
->owner
;
5763 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5764 || loc
->loc_type
== bp_loc_software_breakpoint
)
5765 && solib
->pspace
== loc
->pspace
5766 && !loc
->shlib_disabled
5767 && (b
->type
== bp_breakpoint
5768 || b
->type
== bp_jit_event
5769 || b
->type
== bp_hardware_breakpoint
)
5770 && solib_contains_address_p (solib
, loc
->address
))
5772 loc
->shlib_disabled
= 1;
5773 /* At this point, we cannot rely on remove_breakpoint
5774 succeeding so we must mark the breakpoint as not inserted
5775 to prevent future errors occurring in remove_breakpoints. */
5777 if (!disabled_shlib_breaks
)
5779 target_terminal_ours_for_output ();
5780 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5783 disabled_shlib_breaks
= 1;
5788 /* FORK & VFORK catchpoints. */
5790 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5793 insert_catch_fork (struct breakpoint
*b
)
5795 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5798 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5801 remove_catch_fork (struct breakpoint
*b
)
5803 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5806 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5810 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5812 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5815 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5817 static enum print_stop_action
5818 print_it_catch_fork (struct breakpoint
*b
)
5820 annotate_catchpoint (b
->number
);
5821 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5822 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5823 return PRINT_SRC_AND_LOC
;
5826 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5829 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5831 struct value_print_options opts
;
5833 get_user_print_options (&opts
);
5835 /* Field 4, the address, is omitted (which makes the columns
5836 not line up too nicely with the headers, but the effect
5837 is relatively readable). */
5838 if (opts
.addressprint
)
5839 ui_out_field_skip (uiout
, "addr");
5841 ui_out_text (uiout
, "fork");
5842 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5844 ui_out_text (uiout
, ", process ");
5845 ui_out_field_int (uiout
, "what",
5846 ptid_get_pid (b
->forked_inferior_pid
));
5847 ui_out_spaces (uiout
, 1);
5851 /* Implement the "print_mention" breakpoint_ops method for fork
5855 print_mention_catch_fork (struct breakpoint
*b
)
5857 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5860 /* Implement the "print_recreate" breakpoint_ops method for fork
5864 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
5866 fprintf_unfiltered (fp
, "catch fork");
5869 /* The breakpoint_ops structure to be used in fork catchpoints. */
5871 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5875 breakpoint_hit_catch_fork
,
5876 print_it_catch_fork
,
5877 print_one_catch_fork
,
5878 print_mention_catch_fork
,
5879 print_recreate_catch_fork
5882 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5885 insert_catch_vfork (struct breakpoint
*b
)
5887 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5890 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5893 remove_catch_vfork (struct breakpoint
*b
)
5895 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5898 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5902 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5904 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5907 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5909 static enum print_stop_action
5910 print_it_catch_vfork (struct breakpoint
*b
)
5912 annotate_catchpoint (b
->number
);
5913 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5914 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5915 return PRINT_SRC_AND_LOC
;
5918 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5921 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5923 struct value_print_options opts
;
5925 get_user_print_options (&opts
);
5926 /* Field 4, the address, is omitted (which makes the columns
5927 not line up too nicely with the headers, but the effect
5928 is relatively readable). */
5929 if (opts
.addressprint
)
5930 ui_out_field_skip (uiout
, "addr");
5932 ui_out_text (uiout
, "vfork");
5933 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5935 ui_out_text (uiout
, ", process ");
5936 ui_out_field_int (uiout
, "what",
5937 ptid_get_pid (b
->forked_inferior_pid
));
5938 ui_out_spaces (uiout
, 1);
5942 /* Implement the "print_mention" breakpoint_ops method for vfork
5946 print_mention_catch_vfork (struct breakpoint
*b
)
5948 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5951 /* Implement the "print_recreate" breakpoint_ops method for vfork
5955 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
5957 fprintf_unfiltered (fp
, "catch vfork");
5960 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5962 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5966 breakpoint_hit_catch_vfork
,
5967 print_it_catch_vfork
,
5968 print_one_catch_vfork
,
5969 print_mention_catch_vfork
,
5970 print_recreate_catch_vfork
5973 /* Implement the "insert" breakpoint_ops method for syscall
5977 insert_catch_syscall (struct breakpoint
*b
)
5979 struct inferior
*inf
= current_inferior ();
5981 ++inf
->total_syscalls_count
;
5982 if (!b
->syscalls_to_be_caught
)
5983 ++inf
->any_syscall_count
;
5988 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5992 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5994 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5995 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5997 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5998 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6000 memset ((void *) vec_addr
, 0,
6001 (iter
+ 1 - old_size
) * sizeof (int));
6003 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6004 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6008 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6009 inf
->total_syscalls_count
!= 0,
6010 inf
->any_syscall_count
,
6011 VEC_length (int, inf
->syscalls_counts
),
6012 VEC_address (int, inf
->syscalls_counts
));
6015 /* Implement the "remove" breakpoint_ops method for syscall
6019 remove_catch_syscall (struct breakpoint
*b
)
6021 struct inferior
*inf
= current_inferior ();
6023 --inf
->total_syscalls_count
;
6024 if (!b
->syscalls_to_be_caught
)
6025 --inf
->any_syscall_count
;
6030 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6034 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6035 /* Shouldn't happen. */
6037 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6038 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6042 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6043 inf
->total_syscalls_count
!= 0,
6044 inf
->any_syscall_count
,
6045 VEC_length (int, inf
->syscalls_counts
),
6046 VEC_address (int, inf
->syscalls_counts
));
6049 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6053 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6055 /* We must check if we are catching specific syscalls in this breakpoint.
6056 If we are, then we must guarantee that the called syscall is the same
6057 syscall we are catching. */
6058 int syscall_number
= 0;
6060 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6063 /* Now, checking if the syscall is the same. */
6064 if (b
->syscalls_to_be_caught
)
6068 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6070 if (syscall_number
== iter
)
6080 /* Implement the "print_it" breakpoint_ops method for syscall
6083 static enum print_stop_action
6084 print_it_catch_syscall (struct breakpoint
*b
)
6086 /* These are needed because we want to know in which state a
6087 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6088 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6089 must print "called syscall" or "returned from syscall". */
6091 struct target_waitstatus last
;
6093 struct cleanup
*old_chain
;
6096 get_last_target_status (&ptid
, &last
);
6098 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6100 annotate_catchpoint (b
->number
);
6103 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6105 syscall_id
= xstrprintf ("'%s'", s
.name
);
6107 old_chain
= make_cleanup (xfree
, syscall_id
);
6109 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6110 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6111 b
->number
, syscall_id
);
6112 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6113 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6114 b
->number
, syscall_id
);
6116 do_cleanups (old_chain
);
6118 return PRINT_SRC_AND_LOC
;
6121 /* Implement the "print_one" breakpoint_ops method for syscall
6125 print_one_catch_syscall (struct breakpoint
*b
,
6126 struct bp_location
**last_loc
)
6128 struct value_print_options opts
;
6130 get_user_print_options (&opts
);
6131 /* Field 4, the address, is omitted (which makes the columns
6132 not line up too nicely with the headers, but the effect
6133 is relatively readable). */
6134 if (opts
.addressprint
)
6135 ui_out_field_skip (uiout
, "addr");
6138 if (b
->syscalls_to_be_caught
6139 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6140 ui_out_text (uiout
, "syscalls \"");
6142 ui_out_text (uiout
, "syscall \"");
6144 if (b
->syscalls_to_be_caught
)
6147 char *text
= xstrprintf ("%s", "");
6149 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6154 get_syscall_by_number (iter
, &s
);
6157 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6159 text
= xstrprintf ("%s%d, ", text
, iter
);
6161 /* We have to xfree the last 'text' (now stored at 'x')
6162 because xstrprintf dinamically allocates new space for it
6166 /* Remove the last comma. */
6167 text
[strlen (text
) - 2] = '\0';
6168 ui_out_field_string (uiout
, "what", text
);
6171 ui_out_field_string (uiout
, "what", "<any syscall>");
6172 ui_out_text (uiout
, "\" ");
6175 /* Implement the "print_mention" breakpoint_ops method for syscall
6179 print_mention_catch_syscall (struct breakpoint
*b
)
6181 if (b
->syscalls_to_be_caught
)
6185 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6186 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6188 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6191 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6195 get_syscall_by_number (iter
, &s
);
6198 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6200 printf_filtered (" %d", s
.number
);
6202 printf_filtered (")");
6205 printf_filtered (_("Catchpoint %d (any syscall)"),
6209 /* Implement the "print_recreate" breakpoint_ops method for syscall
6213 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6215 fprintf_unfiltered (fp
, "catch syscall");
6217 if (b
->syscalls_to_be_caught
)
6222 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6227 get_syscall_by_number (iter
, &s
);
6229 fprintf_unfiltered (fp
, " %s", s
.name
);
6231 fprintf_unfiltered (fp
, " %d", s
.number
);
6236 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6238 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6240 insert_catch_syscall
,
6241 remove_catch_syscall
,
6242 breakpoint_hit_catch_syscall
,
6243 print_it_catch_syscall
,
6244 print_one_catch_syscall
,
6245 print_mention_catch_syscall
,
6246 print_recreate_catch_syscall
6249 /* Returns non-zero if 'b' is a syscall catchpoint. */
6252 syscall_catchpoint_p (struct breakpoint
*b
)
6254 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6257 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6258 but does NOT mention it nor update the global location list.
6259 This is useful if you need to fill more fields in the
6260 struct breakpoint before calling mention.
6262 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6263 If COND_STRING is not NULL, then store it in the breakpoint.
6264 OPS, if not NULL, is the breakpoint_ops structure associated
6265 to the catchpoint. */
6267 static struct breakpoint
*
6268 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6270 struct breakpoint_ops
*ops
)
6272 struct symtab_and_line sal
;
6273 struct breakpoint
*b
;
6276 sal
.pspace
= current_program_space
;
6278 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6279 set_breakpoint_count (breakpoint_count
+ 1);
6280 b
->number
= breakpoint_count
;
6282 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6284 b
->addr_string
= NULL
;
6285 b
->enable_state
= bp_enabled
;
6286 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6292 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6294 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6295 If COND_STRING is not NULL, then store it in the breakpoint.
6296 OPS, if not NULL, is the breakpoint_ops structure associated
6297 to the catchpoint. */
6299 static struct breakpoint
*
6300 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6301 char *cond_string
, struct breakpoint_ops
*ops
)
6303 struct breakpoint
*b
=
6304 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6307 update_global_location_list (1);
6313 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6314 int tempflag
, char *cond_string
,
6315 struct breakpoint_ops
*ops
)
6317 struct breakpoint
*b
6318 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6320 /* FIXME: We should put this information in a breakpoint private data
6322 b
->forked_inferior_pid
= null_ptid
;
6325 /* Exec catchpoints. */
6328 insert_catch_exec (struct breakpoint
*b
)
6330 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6334 remove_catch_exec (struct breakpoint
*b
)
6336 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6340 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6342 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6345 static enum print_stop_action
6346 print_it_catch_exec (struct breakpoint
*b
)
6348 annotate_catchpoint (b
->number
);
6349 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6351 return PRINT_SRC_AND_LOC
;
6355 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6357 struct value_print_options opts
;
6359 get_user_print_options (&opts
);
6361 /* Field 4, the address, is omitted (which makes the columns
6362 not line up too nicely with the headers, but the effect
6363 is relatively readable). */
6364 if (opts
.addressprint
)
6365 ui_out_field_skip (uiout
, "addr");
6367 ui_out_text (uiout
, "exec");
6368 if (b
->exec_pathname
!= NULL
)
6370 ui_out_text (uiout
, ", program \"");
6371 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6372 ui_out_text (uiout
, "\" ");
6377 print_mention_catch_exec (struct breakpoint
*b
)
6379 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6382 /* Implement the "print_recreate" breakpoint_ops method for exec
6386 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6388 fprintf_unfiltered (fp
, "catch exec");
6391 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6395 breakpoint_hit_catch_exec
,
6396 print_it_catch_exec
,
6397 print_one_catch_exec
,
6398 print_mention_catch_exec
,
6399 print_recreate_catch_exec
6403 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6404 struct breakpoint_ops
*ops
)
6406 struct gdbarch
*gdbarch
= get_current_arch ();
6407 struct breakpoint
*b
=
6408 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6410 b
->syscalls_to_be_caught
= filter
;
6412 /* Now, we have to mention the breakpoint and update the global
6415 update_global_location_list (1);
6419 hw_breakpoint_used_count (void)
6421 struct breakpoint
*b
;
6426 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6434 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6436 struct breakpoint
*b
;
6439 *other_type_used
= 0;
6442 if (breakpoint_enabled (b
))
6444 if (b
->type
== type
)
6446 else if (is_hardware_watchpoint (b
))
6447 *other_type_used
= 1;
6454 disable_watchpoints_before_interactive_call_start (void)
6456 struct breakpoint
*b
;
6460 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6462 b
->enable_state
= bp_call_disabled
;
6463 update_global_location_list (0);
6469 enable_watchpoints_after_interactive_call_stop (void)
6471 struct breakpoint
*b
;
6475 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6477 b
->enable_state
= bp_enabled
;
6478 update_global_location_list (1);
6484 disable_breakpoints_before_startup (void)
6486 struct breakpoint
*b
;
6491 if (b
->pspace
!= current_program_space
)
6494 if ((b
->type
== bp_breakpoint
6495 || b
->type
== bp_hardware_breakpoint
)
6496 && breakpoint_enabled (b
))
6498 b
->enable_state
= bp_startup_disabled
;
6504 update_global_location_list (0);
6506 current_program_space
->executing_startup
= 1;
6510 enable_breakpoints_after_startup (void)
6512 struct breakpoint
*b
;
6515 current_program_space
->executing_startup
= 0;
6519 if (b
->pspace
!= current_program_space
)
6522 if ((b
->type
== bp_breakpoint
6523 || b
->type
== bp_hardware_breakpoint
)
6524 && b
->enable_state
== bp_startup_disabled
)
6526 b
->enable_state
= bp_enabled
;
6532 breakpoint_re_set ();
6536 /* Set a breakpoint that will evaporate an end of command
6537 at address specified by SAL.
6538 Restrict it to frame FRAME if FRAME is nonzero. */
6541 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6542 struct frame_id frame_id
, enum bptype type
)
6544 struct breakpoint
*b
;
6546 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6548 gdb_assert (!frame_id_inlined_p (frame_id
));
6550 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6551 b
->enable_state
= bp_enabled
;
6552 b
->disposition
= disp_donttouch
;
6553 b
->frame_id
= frame_id
;
6555 /* If we're debugging a multi-threaded program, then we
6556 want momentary breakpoints to be active in only a
6557 single thread of control. */
6558 if (in_thread_list (inferior_ptid
))
6559 b
->thread
= pid_to_thread_id (inferior_ptid
);
6561 update_global_location_list_nothrow (1);
6566 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6570 clone_momentary_breakpoint (struct breakpoint
*orig
)
6572 struct breakpoint
*copy
;
6574 /* If there's nothing to clone, then return nothing. */
6578 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6579 copy
->loc
= allocate_bp_location (copy
);
6580 set_breakpoint_location_function (copy
->loc
);
6582 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6583 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6584 copy
->loc
->address
= orig
->loc
->address
;
6585 copy
->loc
->section
= orig
->loc
->section
;
6586 copy
->loc
->pspace
= orig
->loc
->pspace
;
6588 if (orig
->source_file
== NULL
)
6589 copy
->source_file
= NULL
;
6591 copy
->source_file
= xstrdup (orig
->source_file
);
6593 copy
->line_number
= orig
->line_number
;
6594 copy
->frame_id
= orig
->frame_id
;
6595 copy
->thread
= orig
->thread
;
6596 copy
->pspace
= orig
->pspace
;
6598 copy
->enable_state
= bp_enabled
;
6599 copy
->disposition
= disp_donttouch
;
6600 copy
->number
= internal_breakpoint_number
--;
6602 update_global_location_list_nothrow (0);
6607 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6610 struct symtab_and_line sal
;
6612 sal
= find_pc_line (pc
, 0);
6614 sal
.section
= find_pc_overlay (pc
);
6615 sal
.explicit_pc
= 1;
6617 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6621 /* Tell the user we have just set a breakpoint B. */
6624 mention (struct breakpoint
*b
)
6627 struct cleanup
*ui_out_chain
;
6628 struct value_print_options opts
;
6630 get_user_print_options (&opts
);
6632 /* FIXME: This is misplaced; mention() is called by things (like
6633 hitting a watchpoint) other than breakpoint creation. It should
6634 be possible to clean this up and at the same time replace the
6635 random calls to breakpoint_changed with this hook. */
6636 observer_notify_breakpoint_created (b
->number
);
6638 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6639 b
->ops
->print_mention (b
);
6644 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6647 ui_out_text (uiout
, "Watchpoint ");
6648 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6649 ui_out_field_int (uiout
, "number", b
->number
);
6650 ui_out_text (uiout
, ": ");
6651 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6652 do_cleanups (ui_out_chain
);
6654 case bp_hardware_watchpoint
:
6655 ui_out_text (uiout
, "Hardware watchpoint ");
6656 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6657 ui_out_field_int (uiout
, "number", b
->number
);
6658 ui_out_text (uiout
, ": ");
6659 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6660 do_cleanups (ui_out_chain
);
6662 case bp_read_watchpoint
:
6663 ui_out_text (uiout
, "Hardware read watchpoint ");
6664 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6665 ui_out_field_int (uiout
, "number", b
->number
);
6666 ui_out_text (uiout
, ": ");
6667 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6668 do_cleanups (ui_out_chain
);
6670 case bp_access_watchpoint
:
6671 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6672 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6673 ui_out_field_int (uiout
, "number", b
->number
);
6674 ui_out_text (uiout
, ": ");
6675 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6676 do_cleanups (ui_out_chain
);
6679 if (ui_out_is_mi_like_p (uiout
))
6684 if (b
->disposition
== disp_del
)
6685 printf_filtered (_("Temporary breakpoint"));
6687 printf_filtered (_("Breakpoint"));
6688 printf_filtered (_(" %d"), b
->number
);
6691 case bp_hardware_breakpoint
:
6692 if (ui_out_is_mi_like_p (uiout
))
6697 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6701 if (ui_out_is_mi_like_p (uiout
))
6706 printf_filtered (_("Tracepoint"));
6707 printf_filtered (_(" %d"), b
->number
);
6710 case bp_fast_tracepoint
:
6711 if (ui_out_is_mi_like_p (uiout
))
6716 printf_filtered (_("Fast tracepoint"));
6717 printf_filtered (_(" %d"), b
->number
);
6724 case bp_longjmp_resume
:
6725 case bp_step_resume
:
6727 case bp_std_terminate
:
6728 case bp_watchpoint_scope
:
6729 case bp_shlib_event
:
6730 case bp_thread_event
:
6731 case bp_overlay_event
:
6733 case bp_longjmp_master
:
6734 case bp_std_terminate_master
:
6740 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6744 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6748 if (opts
.addressprint
|| b
->source_file
== NULL
)
6750 printf_filtered (" at ");
6751 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6755 printf_filtered (": file %s, line %d.",
6756 b
->source_file
, b
->line_number
);
6760 struct bp_location
*loc
= b
->loc
;
6762 for (; loc
; loc
= loc
->next
)
6764 printf_filtered (" (%d locations)", n
);
6769 if (ui_out_is_mi_like_p (uiout
))
6771 printf_filtered ("\n");
6775 static struct bp_location
*
6776 add_location_to_breakpoint (struct breakpoint
*b
,
6777 const struct symtab_and_line
*sal
)
6779 struct bp_location
*loc
, **tmp
;
6781 loc
= allocate_bp_location (b
);
6782 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6785 loc
->gdbarch
= get_sal_arch (*sal
);
6787 loc
->gdbarch
= b
->gdbarch
;
6788 loc
->requested_address
= sal
->pc
;
6789 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6790 loc
->requested_address
, b
->type
);
6791 loc
->pspace
= sal
->pspace
;
6792 gdb_assert (loc
->pspace
!= NULL
);
6793 loc
->section
= sal
->section
;
6795 set_breakpoint_location_function (loc
);
6800 /* Return 1 if LOC is pointing to a permanent breakpoint,
6801 return 0 otherwise. */
6804 bp_loc_is_permanent (struct bp_location
*loc
)
6808 const gdb_byte
*brk
;
6809 gdb_byte
*target_mem
;
6810 struct cleanup
*cleanup
;
6813 gdb_assert (loc
!= NULL
);
6815 addr
= loc
->address
;
6816 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6818 /* Software breakpoints unsupported? */
6822 target_mem
= alloca (len
);
6824 /* Enable the automatic memory restoration from breakpoints while
6825 we read the memory. Otherwise we could say about our temporary
6826 breakpoints they are permanent. */
6827 cleanup
= save_current_space_and_thread ();
6829 switch_to_program_space_and_thread (loc
->pspace
);
6830 make_show_memory_breakpoints_cleanup (0);
6832 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6833 && memcmp (target_mem
, brk
, len
) == 0)
6836 do_cleanups (cleanup
);
6843 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6844 as textual description of the location, and COND_STRING
6845 as condition expression. */
6848 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6849 struct symtabs_and_lines sals
, char *addr_string
,
6851 enum bptype type
, enum bpdisp disposition
,
6852 int thread
, int task
, int ignore_count
,
6853 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6855 struct breakpoint
*b
= NULL
;
6858 if (type
== bp_hardware_breakpoint
)
6860 int i
= hw_breakpoint_used_count ();
6861 int target_resources_ok
=
6862 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6864 if (target_resources_ok
== 0)
6865 error (_("No hardware breakpoint support in the target."));
6866 else if (target_resources_ok
< 0)
6867 error (_("Hardware breakpoints used exceeds limit."));
6870 gdb_assert (sals
.nelts
> 0);
6872 for (i
= 0; i
< sals
.nelts
; ++i
)
6874 struct symtab_and_line sal
= sals
.sals
[i
];
6875 struct bp_location
*loc
;
6879 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6881 loc_gdbarch
= gdbarch
;
6883 describe_other_breakpoints (loc_gdbarch
,
6884 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6889 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6890 set_breakpoint_count (breakpoint_count
+ 1);
6891 b
->number
= breakpoint_count
;
6895 b
->cond_string
= cond_string
;
6896 b
->ignore_count
= ignore_count
;
6897 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6898 b
->disposition
= disposition
;
6900 b
->pspace
= sals
.sals
[0].pspace
;
6902 if (enabled
&& b
->pspace
->executing_startup
6903 && (b
->type
== bp_breakpoint
6904 || b
->type
== bp_hardware_breakpoint
))
6905 b
->enable_state
= bp_startup_disabled
;
6911 loc
= add_location_to_breakpoint (b
, &sal
);
6914 if (bp_loc_is_permanent (loc
))
6915 make_breakpoint_permanent (b
);
6919 char *arg
= b
->cond_string
;
6920 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6922 error (_("Garbage %s follows condition"), arg
);
6927 b
->addr_string
= addr_string
;
6929 /* addr_string has to be used or breakpoint_re_set will delete
6932 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6938 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6939 elements to fill the void space. */
6941 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6943 int i
= index_to_remove
+1;
6944 int last_index
= sal
->nelts
-1;
6946 for (;i
<= last_index
; ++i
)
6947 sal
->sals
[i
-1] = sal
->sals
[i
];
6952 /* If appropriate, obtains all sals that correspond to the same file
6953 and line as SAL, in all program spaces. Users debugging with IDEs,
6954 will want to set a breakpoint at foo.c:line, and not really care
6955 about program spaces. This is done only if SAL does not have
6956 explicit PC and has line and file information. If we got just a
6957 single expanded sal, return the original.
6959 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6960 which the name of enclosing function is different from SAL. This
6961 makes sure that if we have breakpoint originally set in template
6962 instantiation, say foo<int>(), we won't expand SAL to locations at
6963 the same line in all existing instantiations of 'foo'. */
6965 static struct symtabs_and_lines
6966 expand_line_sal_maybe (struct symtab_and_line sal
)
6968 struct symtabs_and_lines expanded
;
6969 CORE_ADDR original_pc
= sal
.pc
;
6970 char *original_function
= NULL
;
6973 struct cleanup
*old_chain
;
6975 /* If we have explicit pc, don't expand.
6976 If we have no line number, we can't expand. */
6977 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6980 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6981 expanded
.sals
[0] = sal
;
6987 old_chain
= save_current_space_and_thread ();
6989 switch_to_program_space_and_thread (sal
.pspace
);
6991 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6993 /* Note that expand_line_sal visits *all* program spaces. */
6994 expanded
= expand_line_sal (sal
);
6996 if (expanded
.nelts
== 1)
6998 /* We had one sal, we got one sal. Return that sal, adjusting it
6999 past the function prologue if necessary. */
7000 xfree (expanded
.sals
);
7002 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7003 sal
.pc
= original_pc
;
7004 expanded
.sals
[0] = sal
;
7005 skip_prologue_sal (&expanded
.sals
[0]);
7006 do_cleanups (old_chain
);
7010 if (!sal
.explicit_line
)
7012 CORE_ADDR func_addr
, func_end
;
7013 for (i
= 0; i
< expanded
.nelts
; ++i
)
7015 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7016 char *this_function
;
7018 /* We need to switch threads as well since we're about to
7020 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7022 if (find_pc_partial_function (pc
, &this_function
,
7023 &func_addr
, &func_end
))
7026 && strcmp (this_function
, original_function
) != 0)
7028 remove_sal (&expanded
, i
);
7035 /* Skip the function prologue if necessary. */
7036 for (i
= 0; i
< expanded
.nelts
; ++i
)
7037 skip_prologue_sal (&expanded
.sals
[i
]);
7039 do_cleanups (old_chain
);
7041 if (expanded
.nelts
<= 1)
7043 /* This is un ugly workaround. If we get zero
7044 expanded sals then something is really wrong.
7045 Fix that by returnign the original sal. */
7046 xfree (expanded
.sals
);
7048 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7049 sal
.pc
= original_pc
;
7050 expanded
.sals
[0] = sal
;
7057 for (i
= 0; i
< expanded
.nelts
; ++i
)
7058 if (expanded
.sals
[i
].pc
== original_pc
)
7069 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7070 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7071 value. COND_STRING, if not NULL, specified the condition to be
7072 used for all breakpoints. Essentially the only case where
7073 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7074 function. In that case, it's still not possible to specify
7075 separate conditions for different overloaded functions, so
7076 we take just a single condition string.
7078 NOTE: If the function succeeds, the caller is expected to cleanup
7079 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7080 array contents). If the function fails (error() is called), the
7081 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7082 COND and SALS arrays and each of those arrays contents. */
7085 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7086 struct symtabs_and_lines sals
, char **addr_string
,
7088 enum bptype type
, enum bpdisp disposition
,
7089 int thread
, int task
, int ignore_count
,
7090 struct breakpoint_ops
*ops
, int from_tty
,
7094 for (i
= 0; i
< sals
.nelts
; ++i
)
7096 struct symtabs_and_lines expanded
=
7097 expand_line_sal_maybe (sals
.sals
[i
]);
7099 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7100 cond_string
, type
, disposition
,
7101 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7105 /* Parse ARG which is assumed to be a SAL specification possibly
7106 followed by conditionals. On return, SALS contains an array of SAL
7107 addresses found. ADDR_STRING contains a vector of (canonical)
7108 address strings. ARG points to the end of the SAL. */
7111 parse_breakpoint_sals (char **address
,
7112 struct symtabs_and_lines
*sals
,
7113 char ***addr_string
,
7116 char *addr_start
= *address
;
7117 *addr_string
= NULL
;
7118 /* If no arg given, or if first arg is 'if ', use the default
7120 if ((*address
) == NULL
7121 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7123 if (default_breakpoint_valid
)
7125 struct symtab_and_line sal
;
7126 init_sal (&sal
); /* initialize to zeroes */
7127 sals
->sals
= (struct symtab_and_line
*)
7128 xmalloc (sizeof (struct symtab_and_line
));
7129 sal
.pc
= default_breakpoint_address
;
7130 sal
.line
= default_breakpoint_line
;
7131 sal
.symtab
= default_breakpoint_symtab
;
7132 sal
.pspace
= default_breakpoint_pspace
;
7133 sal
.section
= find_pc_overlay (sal
.pc
);
7135 /* "break" without arguments is equivalent to "break *PC" where PC is
7136 the default_breakpoint_address. So make sure to set
7137 sal.explicit_pc to prevent GDB from trying to expand the list of
7138 sals to include all other instances with the same symtab and line.
7140 sal
.explicit_pc
= 1;
7142 sals
->sals
[0] = sal
;
7146 error (_("No default breakpoint address now."));
7150 /* Force almost all breakpoints to be in terms of the
7151 current_source_symtab (which is decode_line_1's default). This
7152 should produce the results we want almost all of the time while
7153 leaving default_breakpoint_* alone.
7154 ObjC: However, don't match an Objective-C method name which
7155 may have a '+' or '-' succeeded by a '[' */
7157 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7159 if (default_breakpoint_valid
7161 || ((strchr ("+-", (*address
)[0]) != NULL
)
7162 && ((*address
)[1] != '['))))
7163 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7164 default_breakpoint_line
, addr_string
,
7167 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7168 addr_string
, not_found_ptr
);
7170 /* For any SAL that didn't have a canonical string, fill one in. */
7171 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7172 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7173 if (addr_start
!= (*address
))
7176 for (i
= 0; i
< sals
->nelts
; i
++)
7178 /* Add the string if not present. */
7179 if ((*addr_string
)[i
] == NULL
)
7180 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7186 /* Convert each SAL into a real PC. Verify that the PC can be
7187 inserted as a breakpoint. If it can't throw an error. */
7190 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7194 for (i
= 0; i
< sals
->nelts
; i
++)
7195 resolve_sal_pc (&sals
->sals
[i
]);
7198 /* Fast tracepoints may have restrictions on valid locations. For
7199 instance, a fast tracepoint using a jump instead of a trap will
7200 likely have to overwrite more bytes than a trap would, and so can
7201 only be placed where the instruction is longer than the jump, or a
7202 multi-instruction sequence does not have a jump into the middle of
7206 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7207 struct symtabs_and_lines
*sals
)
7210 struct symtab_and_line
*sal
;
7212 struct cleanup
*old_chain
;
7214 for (i
= 0; i
< sals
->nelts
; i
++)
7216 sal
= &sals
->sals
[i
];
7218 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7220 old_chain
= make_cleanup (xfree
, msg
);
7223 error (_("May not have a fast tracepoint at 0x%s%s"),
7224 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7226 do_cleanups (old_chain
);
7231 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7233 struct captured_parse_breakpoint_args
*args
= data
;
7235 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7236 args
->not_found_ptr
);
7239 /* Given TOK, a string specification of condition and thread, as
7240 accepted by the 'break' command, extract the condition
7241 string and thread number and set *COND_STRING and *THREAD.
7242 PC identifies the context at which the condition should be parsed.
7243 If no condition is found, *COND_STRING is set to NULL.
7244 If no thread is found, *THREAD is set to -1. */
7246 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7247 char **cond_string
, int *thread
, int *task
)
7249 *cond_string
= NULL
;
7255 char *cond_start
= NULL
;
7256 char *cond_end
= NULL
;
7257 while (*tok
== ' ' || *tok
== '\t')
7262 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7265 toklen
= end_tok
- tok
;
7267 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7269 struct expression
*expr
;
7271 tok
= cond_start
= end_tok
+ 1;
7272 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7275 *cond_string
= savestring (cond_start
,
7276 cond_end
- cond_start
);
7278 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7284 *thread
= strtol (tok
, &tok
, 0);
7286 error (_("Junk after thread keyword."));
7287 if (!valid_thread_id (*thread
))
7288 error (_("Unknown thread %d."), *thread
);
7290 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7296 *task
= strtol (tok
, &tok
, 0);
7298 error (_("Junk after task keyword."));
7299 if (!valid_task_id (*task
))
7300 error (_("Unknown task %d."), *task
);
7303 error (_("Junk at end of arguments."));
7307 /* Set a breakpoint. This function is shared between CLI and MI
7308 functions for setting a breakpoint. This function has two major
7309 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7310 parameter. If non-zero, the function will parse arg, extracting
7311 breakpoint location, address and thread. Otherwise, ARG is just the
7312 location of breakpoint, with condition and thread specified by the
7313 COND_STRING and THREAD parameters. Returns true if any breakpoint
7314 was created; false otherwise. */
7317 create_breakpoint (struct gdbarch
*gdbarch
,
7318 char *arg
, char *cond_string
, int thread
,
7319 int parse_condition_and_thread
,
7320 int tempflag
, int hardwareflag
, int traceflag
,
7322 enum auto_boolean pending_break_support
,
7323 struct breakpoint_ops
*ops
,
7327 struct gdb_exception e
;
7328 struct symtabs_and_lines sals
;
7329 struct symtab_and_line pending_sal
;
7332 char *addr_start
= arg
;
7334 struct cleanup
*old_chain
;
7335 struct cleanup
*bkpt_chain
= NULL
;
7336 struct captured_parse_breakpoint_args parse_args
;
7340 enum bptype type_wanted
;
7342 int prev_bkpt_count
= breakpoint_count
;
7348 parse_args
.arg_p
= &arg
;
7349 parse_args
.sals_p
= &sals
;
7350 parse_args
.addr_string_p
= &addr_string
;
7351 parse_args
.not_found_ptr
= ¬_found
;
7353 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7354 &parse_args
, RETURN_MASK_ALL
);
7356 /* If caller is interested in rc value from parse, set value. */
7360 throw_exception (e
);
7364 case NOT_FOUND_ERROR
:
7366 /* If pending breakpoint support is turned off, throw
7369 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7370 throw_exception (e
);
7372 exception_print (gdb_stderr
, e
);
7374 /* If pending breakpoint support is auto query and the user
7375 selects no, then simply return the error code. */
7376 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7377 && !nquery ("Make breakpoint pending on future shared library load? "))
7380 /* At this point, either the user was queried about setting
7381 a pending breakpoint and selected yes, or pending
7382 breakpoint behavior is on and thus a pending breakpoint
7383 is defaulted on behalf of the user. */
7384 copy_arg
= xstrdup (addr_start
);
7385 addr_string
= ©_arg
;
7387 sals
.sals
= &pending_sal
;
7392 throw_exception (e
);
7399 /* Create a chain of things that always need to be cleaned up. */
7400 old_chain
= make_cleanup (null_cleanup
, 0);
7404 /* Make sure that all storage allocated to SALS gets freed. */
7405 make_cleanup (xfree
, sals
.sals
);
7407 /* Cleanup the addr_string array but not its contents. */
7408 make_cleanup (xfree
, addr_string
);
7411 /* ----------------------------- SNIP -----------------------------
7412 Anything added to the cleanup chain beyond this point is assumed
7413 to be part of a breakpoint. If the breakpoint create succeeds
7414 then the memory is not reclaimed. */
7415 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7417 /* Mark the contents of the addr_string for cleanup. These go on
7418 the bkpt_chain and only occur if the breakpoint create fails. */
7419 for (i
= 0; i
< sals
.nelts
; i
++)
7421 if (addr_string
[i
] != NULL
)
7422 make_cleanup (xfree
, addr_string
[i
]);
7425 /* Resolve all line numbers to PC's and verify that the addresses
7426 are ok for the target. */
7428 breakpoint_sals_to_pc (&sals
, addr_start
);
7430 type_wanted
= (traceflag
7431 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7432 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7434 /* Fast tracepoints may have additional restrictions on location. */
7435 if (type_wanted
== bp_fast_tracepoint
)
7436 check_fast_tracepoint_sals (gdbarch
, &sals
);
7438 /* Verify that condition can be parsed, before setting any
7439 breakpoints. Allocate a separate condition expression for each
7443 if (parse_condition_and_thread
)
7445 /* Here we only parse 'arg' to separate condition
7446 from thread number, so parsing in context of first
7447 sal is OK. When setting the breakpoint we'll
7448 re-parse it in context of each sal. */
7451 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7454 make_cleanup (xfree
, cond_string
);
7458 /* Create a private copy of condition string. */
7461 cond_string
= xstrdup (cond_string
);
7462 make_cleanup (xfree
, cond_string
);
7465 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7466 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7467 thread
, task
, ignore_count
, ops
, from_tty
,
7472 struct symtab_and_line sal
= {0};
7473 struct breakpoint
*b
;
7475 make_cleanup (xfree
, copy_arg
);
7477 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7478 set_breakpoint_count (breakpoint_count
+ 1);
7479 b
->number
= breakpoint_count
;
7481 b
->addr_string
= addr_string
[0];
7482 b
->cond_string
= NULL
;
7483 b
->ignore_count
= ignore_count
;
7484 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7485 b
->condition_not_parsed
= 1;
7487 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7488 b
->pspace
= current_program_space
;
7490 if (enabled
&& b
->pspace
->executing_startup
7491 && (b
->type
== bp_breakpoint
7492 || b
->type
== bp_hardware_breakpoint
))
7493 b
->enable_state
= bp_startup_disabled
;
7500 warning (_("Multiple breakpoints were set.\n"
7501 "Use the \"delete\" command to delete unwanted breakpoints."));
7502 prev_breakpoint_count
= prev_bkpt_count
;
7505 /* That's it. Discard the cleanups for data inserted into the
7507 discard_cleanups (bkpt_chain
);
7508 /* But cleanup everything else. */
7509 do_cleanups (old_chain
);
7511 /* error call may happen here - have BKPT_CHAIN already discarded. */
7512 update_global_location_list (1);
7517 /* Set a breakpoint.
7518 ARG is a string describing breakpoint address,
7519 condition, and thread.
7520 FLAG specifies if a breakpoint is hardware on,
7521 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7525 break_command_1 (char *arg
, int flag
, int from_tty
)
7527 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7528 int tempflag
= flag
& BP_TEMPFLAG
;
7530 create_breakpoint (get_current_arch (),
7532 NULL
, 0, 1 /* parse arg */,
7533 tempflag
, hardwareflag
, 0 /* traceflag */,
7534 0 /* Ignore count */,
7535 pending_break_support
,
7536 NULL
/* breakpoint_ops */,
7543 /* Helper function for break_command_1 and disassemble_command. */
7546 resolve_sal_pc (struct symtab_and_line
*sal
)
7550 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7552 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7553 error (_("No line %d in file \"%s\"."),
7554 sal
->line
, sal
->symtab
->filename
);
7557 /* If this SAL corresponds to a breakpoint inserted using
7558 a line number, then skip the function prologue if necessary. */
7559 if (sal
->explicit_line
)
7560 skip_prologue_sal (sal
);
7563 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7565 struct blockvector
*bv
;
7569 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7572 sym
= block_linkage_function (b
);
7575 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7576 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7580 /* It really is worthwhile to have the section, so we'll just
7581 have to look harder. This case can be executed if we have
7582 line numbers but no functions (as can happen in assembly
7585 struct minimal_symbol
*msym
;
7586 struct cleanup
*old_chain
= save_current_space_and_thread ();
7588 switch_to_program_space_and_thread (sal
->pspace
);
7590 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7592 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7594 do_cleanups (old_chain
);
7601 break_command (char *arg
, int from_tty
)
7603 break_command_1 (arg
, 0, from_tty
);
7607 tbreak_command (char *arg
, int from_tty
)
7609 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7613 hbreak_command (char *arg
, int from_tty
)
7615 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7619 thbreak_command (char *arg
, int from_tty
)
7621 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7625 stop_command (char *arg
, int from_tty
)
7627 printf_filtered (_("Specify the type of breakpoint to set.\n\
7628 Usage: stop in <function | address>\n\
7629 stop at <line>\n"));
7633 stopin_command (char *arg
, int from_tty
)
7637 if (arg
== (char *) NULL
)
7639 else if (*arg
!= '*')
7644 /* look for a ':'. If this is a line number specification, then
7645 say it is bad, otherwise, it should be an address or
7646 function/method name */
7647 while (*argptr
&& !hasColon
)
7649 hasColon
= (*argptr
== ':');
7654 badInput
= (*argptr
!= ':'); /* Not a class::method */
7656 badInput
= isdigit (*arg
); /* a simple line number */
7660 printf_filtered (_("Usage: stop in <function | address>\n"));
7662 break_command_1 (arg
, 0, from_tty
);
7666 stopat_command (char *arg
, int from_tty
)
7670 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7677 /* look for a ':'. If there is a '::' then get out, otherwise
7678 it is probably a line number. */
7679 while (*argptr
&& !hasColon
)
7681 hasColon
= (*argptr
== ':');
7686 badInput
= (*argptr
== ':'); /* we have class::method */
7688 badInput
= !isdigit (*arg
); /* not a line number */
7692 printf_filtered (_("Usage: stop at <line>\n"));
7694 break_command_1 (arg
, 0, from_tty
);
7697 /* accessflag: hw_write: watch write,
7698 hw_read: watch read,
7699 hw_access: watch access (read or write) */
7701 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7703 struct gdbarch
*gdbarch
= get_current_arch ();
7704 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7705 struct expression
*exp
;
7706 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7707 struct value
*val
, *mark
;
7708 struct frame_info
*frame
;
7709 char *exp_start
= NULL
;
7710 char *exp_end
= NULL
;
7711 char *tok
, *id_tok_start
, *end_tok
;
7713 char *cond_start
= NULL
;
7714 char *cond_end
= NULL
;
7715 int i
, other_type_used
, target_resources_ok
= 0;
7716 enum bptype bp_type
;
7720 /* Make sure that we actually have parameters to parse. */
7721 if (arg
!= NULL
&& arg
[0] != '\0')
7723 toklen
= strlen (arg
); /* Size of argument list. */
7725 /* Points tok to the end of the argument list. */
7726 tok
= arg
+ toklen
- 1;
7728 /* Go backwards in the parameters list. Skip the last parameter.
7729 If we're expecting a 'thread <thread_num>' parameter, this should
7730 be the thread identifier. */
7731 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7733 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7736 /* Points end_tok to the beginning of the last token. */
7737 id_tok_start
= tok
+ 1;
7739 /* Go backwards in the parameters list. Skip one more parameter.
7740 If we're expecting a 'thread <thread_num>' parameter, we should
7741 reach a "thread" token. */
7742 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7747 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7750 /* Move the pointer forward to skip the whitespace and
7751 calculate the length of the token. */
7753 toklen
= end_tok
- tok
;
7755 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7757 /* At this point we've found a "thread" token, which means
7758 the user is trying to set a watchpoint that triggers
7759 only in a specific thread. */
7762 /* Extract the thread ID from the next token. */
7763 thread
= strtol (id_tok_start
, &endp
, 0);
7765 /* Check if the user provided a valid numeric value for the
7767 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7768 error (_("Invalid thread ID specification %s."), id_tok_start
);
7770 /* Check if the thread actually exists. */
7771 if (!valid_thread_id (thread
))
7772 error (_("Unknown thread %d."), thread
);
7774 /* Truncate the string and get rid of the thread <thread_num>
7775 parameter before the parameter list is parsed by the
7776 evaluate_expression() function. */
7781 /* Parse the rest of the arguments. */
7782 innermost_block
= NULL
;
7784 exp
= parse_exp_1 (&arg
, 0, 0);
7786 /* Remove trailing whitespace from the expression before saving it.
7787 This makes the eventual display of the expression string a bit
7789 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7792 exp_valid_block
= innermost_block
;
7793 mark
= value_mark ();
7794 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7796 release_value (val
);
7799 while (*tok
== ' ' || *tok
== '\t')
7803 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7806 toklen
= end_tok
- tok
;
7807 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7809 struct expression
*cond
;
7811 innermost_block
= NULL
;
7812 tok
= cond_start
= end_tok
+ 1;
7813 cond
= parse_exp_1 (&tok
, 0, 0);
7815 /* The watchpoint expression may not be local, but the condition
7816 may still be. E.g.: `watch global if local > 0'. */
7817 cond_exp_valid_block
= innermost_block
;
7823 error (_("Junk at end of command."));
7825 if (accessflag
== hw_read
)
7826 bp_type
= bp_read_watchpoint
;
7827 else if (accessflag
== hw_access
)
7828 bp_type
= bp_access_watchpoint
;
7830 bp_type
= bp_hardware_watchpoint
;
7832 mem_cnt
= can_use_hardware_watchpoint (val
);
7833 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7834 error (_("Expression cannot be implemented with read/access watchpoint."));
7837 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7838 target_resources_ok
=
7839 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7841 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7842 error (_("Target does not support this type of hardware watchpoint."));
7844 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7845 error (_("Target can only support one kind of HW watchpoint at a time."));
7848 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7849 watchpoint could not be set. */
7850 if (!mem_cnt
|| target_resources_ok
<= 0)
7851 bp_type
= bp_watchpoint
;
7853 frame
= block_innermost_frame (exp_valid_block
);
7855 /* If the expression is "local", then set up a "watchpoint scope"
7856 breakpoint at the point where we've left the scope of the watchpoint
7857 expression. Create the scope breakpoint before the watchpoint, so
7858 that we will encounter it first in bpstat_stop_status. */
7859 if (exp_valid_block
&& frame
)
7861 if (frame_id_p (frame_unwind_caller_id (frame
)))
7864 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7865 frame_unwind_caller_pc (frame
),
7866 bp_watchpoint_scope
);
7868 scope_breakpoint
->enable_state
= bp_enabled
;
7870 /* Automatically delete the breakpoint when it hits. */
7871 scope_breakpoint
->disposition
= disp_del
;
7873 /* Only break in the proper frame (help with recursion). */
7874 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7876 /* Set the address at which we will stop. */
7877 scope_breakpoint
->loc
->gdbarch
7878 = frame_unwind_caller_arch (frame
);
7879 scope_breakpoint
->loc
->requested_address
7880 = frame_unwind_caller_pc (frame
);
7881 scope_breakpoint
->loc
->address
7882 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7883 scope_breakpoint
->loc
->requested_address
,
7884 scope_breakpoint
->type
);
7888 /* Now set up the breakpoint. */
7889 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7890 set_breakpoint_count (breakpoint_count
+ 1);
7891 b
->number
= breakpoint_count
;
7893 b
->disposition
= disp_donttouch
;
7895 b
->exp_valid_block
= exp_valid_block
;
7896 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7897 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7901 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7907 b
->watchpoint_frame
= get_frame_id (frame
);
7908 b
->watchpoint_thread
= inferior_ptid
;
7912 b
->watchpoint_frame
= null_frame_id
;
7913 b
->watchpoint_thread
= null_ptid
;
7916 if (scope_breakpoint
!= NULL
)
7918 /* The scope breakpoint is related to the watchpoint. We will
7919 need to act on them together. */
7920 b
->related_breakpoint
= scope_breakpoint
;
7921 scope_breakpoint
->related_breakpoint
= b
;
7924 value_free_to_mark (mark
);
7926 /* Finally update the new watchpoint. This creates the locations
7927 that should be inserted. */
7928 update_watchpoint (b
, 1);
7931 update_global_location_list (1);
7934 /* Return count of locations need to be watched and can be handled
7935 in hardware. If the watchpoint can not be handled
7936 in hardware return zero. */
7939 can_use_hardware_watchpoint (struct value
*v
)
7941 int found_memory_cnt
= 0;
7942 struct value
*head
= v
;
7944 /* Did the user specifically forbid us to use hardware watchpoints? */
7945 if (!can_use_hw_watchpoints
)
7948 /* Make sure that the value of the expression depends only upon
7949 memory contents, and values computed from them within GDB. If we
7950 find any register references or function calls, we can't use a
7951 hardware watchpoint.
7953 The idea here is that evaluating an expression generates a series
7954 of values, one holding the value of every subexpression. (The
7955 expression a*b+c has five subexpressions: a, b, a*b, c, and
7956 a*b+c.) GDB's values hold almost enough information to establish
7957 the criteria given above --- they identify memory lvalues,
7958 register lvalues, computed values, etcetera. So we can evaluate
7959 the expression, and then scan the chain of values that leaves
7960 behind to decide whether we can detect any possible change to the
7961 expression's final value using only hardware watchpoints.
7963 However, I don't think that the values returned by inferior
7964 function calls are special in any way. So this function may not
7965 notice that an expression involving an inferior function call
7966 can't be watched with hardware watchpoints. FIXME. */
7967 for (; v
; v
= value_next (v
))
7969 if (VALUE_LVAL (v
) == lval_memory
)
7972 /* A lazy memory lvalue is one that GDB never needed to fetch;
7973 we either just used its address (e.g., `a' in `a.b') or
7974 we never needed it at all (e.g., `a' in `a,b'). */
7978 /* Ahh, memory we actually used! Check if we can cover
7979 it with hardware watchpoints. */
7980 struct type
*vtype
= check_typedef (value_type (v
));
7982 /* We only watch structs and arrays if user asked for it
7983 explicitly, never if they just happen to appear in a
7984 middle of some value chain. */
7986 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7987 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7989 CORE_ADDR vaddr
= value_address (v
);
7990 int len
= TYPE_LENGTH (value_type (v
));
7992 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7999 else if (VALUE_LVAL (v
) != not_lval
8000 && deprecated_value_modifiable (v
) == 0)
8001 return 0; /* ??? What does this represent? */
8002 else if (VALUE_LVAL (v
) == lval_register
)
8003 return 0; /* cannot watch a register with a HW watchpoint */
8006 /* The expression itself looks suitable for using a hardware
8007 watchpoint, but give the target machine a chance to reject it. */
8008 return found_memory_cnt
;
8012 watch_command_wrapper (char *arg
, int from_tty
)
8014 watch_command (arg
, from_tty
);
8018 watch_command (char *arg
, int from_tty
)
8020 watch_command_1 (arg
, hw_write
, from_tty
);
8024 rwatch_command_wrapper (char *arg
, int from_tty
)
8026 rwatch_command (arg
, from_tty
);
8030 rwatch_command (char *arg
, int from_tty
)
8032 watch_command_1 (arg
, hw_read
, from_tty
);
8036 awatch_command_wrapper (char *arg
, int from_tty
)
8038 awatch_command (arg
, from_tty
);
8042 awatch_command (char *arg
, int from_tty
)
8044 watch_command_1 (arg
, hw_access
, from_tty
);
8048 /* Helper routines for the until_command routine in infcmd.c. Here
8049 because it uses the mechanisms of breakpoints. */
8051 struct until_break_command_continuation_args
8053 struct breakpoint
*breakpoint
;
8054 struct breakpoint
*breakpoint2
;
8057 /* This function is called by fetch_inferior_event via the
8058 cmd_continuation pointer, to complete the until command. It takes
8059 care of cleaning up the temporary breakpoints set up by the until
8062 until_break_command_continuation (void *arg
)
8064 struct until_break_command_continuation_args
*a
= arg
;
8066 delete_breakpoint (a
->breakpoint
);
8068 delete_breakpoint (a
->breakpoint2
);
8072 until_break_command (char *arg
, int from_tty
, int anywhere
)
8074 struct symtabs_and_lines sals
;
8075 struct symtab_and_line sal
;
8076 struct frame_info
*frame
= get_selected_frame (NULL
);
8077 struct breakpoint
*breakpoint
;
8078 struct breakpoint
*breakpoint2
= NULL
;
8079 struct cleanup
*old_chain
;
8081 clear_proceed_status ();
8083 /* Set a breakpoint where the user wants it and at return from
8086 if (default_breakpoint_valid
)
8087 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8088 default_breakpoint_line
, (char ***) NULL
, NULL
);
8090 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8091 0, (char ***) NULL
, NULL
);
8093 if (sals
.nelts
!= 1)
8094 error (_("Couldn't get information on specified line."));
8097 xfree (sals
.sals
); /* malloc'd, so freed */
8100 error (_("Junk at end of arguments."));
8102 resolve_sal_pc (&sal
);
8105 /* If the user told us to continue until a specified location,
8106 we don't specify a frame at which we need to stop. */
8107 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8108 null_frame_id
, bp_until
);
8110 /* Otherwise, specify the selected frame, because we want to stop only
8111 at the very same frame. */
8112 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8113 get_stack_frame_id (frame
),
8116 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8118 /* Keep within the current frame, or in frames called by the current
8121 if (frame_id_p (frame_unwind_caller_id (frame
)))
8123 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8124 sal
.pc
= frame_unwind_caller_pc (frame
);
8125 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8127 frame_unwind_caller_id (frame
),
8129 make_cleanup_delete_breakpoint (breakpoint2
);
8132 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8134 /* If we are running asynchronously, and proceed call above has actually
8135 managed to start the target, arrange for breakpoints to be
8136 deleted when the target stops. Otherwise, we're already stopped and
8137 delete breakpoints via cleanup chain. */
8139 if (target_can_async_p () && is_running (inferior_ptid
))
8141 struct until_break_command_continuation_args
*args
;
8142 args
= xmalloc (sizeof (*args
));
8144 args
->breakpoint
= breakpoint
;
8145 args
->breakpoint2
= breakpoint2
;
8147 discard_cleanups (old_chain
);
8148 add_continuation (inferior_thread (),
8149 until_break_command_continuation
, args
,
8153 do_cleanups (old_chain
);
8157 ep_skip_leading_whitespace (char **s
)
8159 if ((s
== NULL
) || (*s
== NULL
))
8161 while (isspace (**s
))
8165 /* This function attempts to parse an optional "if <cond>" clause
8166 from the arg string. If one is not found, it returns NULL.
8168 Else, it returns a pointer to the condition string. (It does not
8169 attempt to evaluate the string against a particular block.) And,
8170 it updates arg to point to the first character following the parsed
8171 if clause in the arg string. */
8174 ep_parse_optional_if_clause (char **arg
)
8178 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8181 /* Skip the "if" keyword. */
8184 /* Skip any extra leading whitespace, and record the start of the
8185 condition string. */
8186 ep_skip_leading_whitespace (arg
);
8189 /* Assume that the condition occupies the remainder of the arg string. */
8190 (*arg
) += strlen (cond_string
);
8195 /* Commands to deal with catching events, such as signals, exceptions,
8196 process start/exit, etc. */
8200 catch_fork_temporary
, catch_vfork_temporary
,
8201 catch_fork_permanent
, catch_vfork_permanent
8206 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8208 struct gdbarch
*gdbarch
= get_current_arch ();
8209 char *cond_string
= NULL
;
8210 catch_fork_kind fork_kind
;
8213 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8214 tempflag
= (fork_kind
== catch_fork_temporary
8215 || fork_kind
== catch_vfork_temporary
);
8219 ep_skip_leading_whitespace (&arg
);
8221 /* The allowed syntax is:
8223 catch [v]fork if <cond>
8225 First, check if there's an if clause. */
8226 cond_string
= ep_parse_optional_if_clause (&arg
);
8228 if ((*arg
!= '\0') && !isspace (*arg
))
8229 error (_("Junk at end of arguments."));
8231 /* If this target supports it, create a fork or vfork catchpoint
8232 and enable reporting of such events. */
8235 case catch_fork_temporary
:
8236 case catch_fork_permanent
:
8237 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8238 &catch_fork_breakpoint_ops
);
8240 case catch_vfork_temporary
:
8241 case catch_vfork_permanent
:
8242 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8243 &catch_vfork_breakpoint_ops
);
8246 error (_("unsupported or unknown fork kind; cannot catch it"));
8252 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8254 struct gdbarch
*gdbarch
= get_current_arch ();
8256 char *cond_string
= NULL
;
8258 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8262 ep_skip_leading_whitespace (&arg
);
8264 /* The allowed syntax is:
8266 catch exec if <cond>
8268 First, check if there's an if clause. */
8269 cond_string
= ep_parse_optional_if_clause (&arg
);
8271 if ((*arg
!= '\0') && !isspace (*arg
))
8272 error (_("Junk at end of arguments."));
8274 /* If this target supports it, create an exec catchpoint
8275 and enable reporting of such events. */
8276 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8277 &catch_exec_breakpoint_ops
);
8280 static enum print_stop_action
8281 print_exception_catchpoint (struct breakpoint
*b
)
8283 int bp_temp
, bp_throw
;
8285 annotate_catchpoint (b
->number
);
8287 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8288 if (b
->loc
->address
!= b
->loc
->requested_address
)
8289 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8292 bp_temp
= b
->disposition
== disp_del
;
8294 bp_temp
? "Temporary catchpoint "
8296 if (!ui_out_is_mi_like_p (uiout
))
8297 ui_out_field_int (uiout
, "bkptno", b
->number
);
8299 bp_throw
? " (exception thrown), "
8300 : " (exception caught), ");
8301 if (ui_out_is_mi_like_p (uiout
))
8303 ui_out_field_string (uiout
, "reason",
8304 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8305 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8306 ui_out_field_int (uiout
, "bkptno", b
->number
);
8308 return PRINT_SRC_AND_LOC
;
8312 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8314 struct value_print_options opts
;
8315 get_user_print_options (&opts
);
8316 if (opts
.addressprint
)
8319 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8320 ui_out_field_string (uiout
, "addr", "<PENDING>");
8322 ui_out_field_core_addr (uiout
, "addr",
8323 b
->loc
->gdbarch
, b
->loc
->address
);
8328 if (strstr (b
->addr_string
, "throw") != NULL
)
8329 ui_out_field_string (uiout
, "what", "exception throw");
8331 ui_out_field_string (uiout
, "what", "exception catch");
8335 print_mention_exception_catchpoint (struct breakpoint
*b
)
8340 bp_temp
= b
->disposition
== disp_del
;
8341 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8342 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8343 : _("Catchpoint "));
8344 ui_out_field_int (uiout
, "bkptno", b
->number
);
8345 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8349 /* Implement the "print_recreate" breakpoint_ops method for throw and
8350 catch catchpoints. */
8353 print_recreate_exception_catchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8358 bp_temp
= b
->disposition
== disp_del
;
8359 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8360 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8361 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8364 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8367 NULL
, /* breakpoint_hit */
8368 print_exception_catchpoint
,
8369 print_one_exception_catchpoint
,
8370 print_mention_exception_catchpoint
,
8371 print_recreate_exception_catchpoint
8375 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8376 enum exception_event_kind ex_event
, int from_tty
)
8378 char *trigger_func_name
;
8380 if (ex_event
== EX_EVENT_CATCH
)
8381 trigger_func_name
= "__cxa_begin_catch";
8383 trigger_func_name
= "__cxa_throw";
8385 create_breakpoint (get_current_arch (),
8386 trigger_func_name
, cond_string
, -1,
8387 0 /* condition and thread are valid. */,
8390 AUTO_BOOLEAN_TRUE
/* pending */,
8391 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8397 /* Deal with "catch catch" and "catch throw" commands */
8400 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8401 int tempflag
, int from_tty
)
8403 char *cond_string
= NULL
;
8404 struct symtab_and_line
*sal
= NULL
;
8408 ep_skip_leading_whitespace (&arg
);
8410 cond_string
= ep_parse_optional_if_clause (&arg
);
8412 if ((*arg
!= '\0') && !isspace (*arg
))
8413 error (_("Junk at end of arguments."));
8415 if (ex_event
!= EX_EVENT_THROW
8416 && ex_event
!= EX_EVENT_CATCH
)
8417 error (_("Unsupported or unknown exception event; cannot catch it"));
8419 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8422 warning (_("Unsupported with this platform/compiler combination."));
8425 /* Implementation of "catch catch" command. */
8428 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8430 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8431 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8434 /* Implementation of "catch throw" command. */
8437 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8439 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8440 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8443 /* Create a breakpoint struct for Ada exception catchpoints. */
8446 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8447 struct symtab_and_line sal
,
8451 struct expression
*cond
,
8452 struct breakpoint_ops
*ops
,
8456 struct breakpoint
*b
;
8460 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8462 loc_gdbarch
= gdbarch
;
8464 describe_other_breakpoints (loc_gdbarch
,
8465 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8466 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8467 version for exception catchpoints, because two catchpoints
8468 used for different exception names will use the same address.
8469 In this case, a "breakpoint ... also set at..." warning is
8470 unproductive. Besides. the warning phrasing is also a bit
8471 inapropriate, we should use the word catchpoint, and tell
8472 the user what type of catchpoint it is. The above is good
8473 enough for now, though. */
8476 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8477 set_breakpoint_count (breakpoint_count
+ 1);
8479 b
->enable_state
= bp_enabled
;
8480 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8481 b
->number
= breakpoint_count
;
8482 b
->ignore_count
= 0;
8483 b
->loc
->cond
= cond
;
8484 b
->addr_string
= addr_string
;
8485 b
->language
= language_ada
;
8486 b
->cond_string
= cond_string
;
8487 b
->exp_string
= exp_string
;
8492 update_global_location_list (1);
8495 /* Implement the "catch exception" command. */
8498 catch_ada_exception_command (char *arg
, int from_tty
,
8499 struct cmd_list_element
*command
)
8501 struct gdbarch
*gdbarch
= get_current_arch ();
8503 struct symtab_and_line sal
;
8505 char *addr_string
= NULL
;
8506 char *exp_string
= NULL
;
8507 char *cond_string
= NULL
;
8508 struct expression
*cond
= NULL
;
8509 struct breakpoint_ops
*ops
= NULL
;
8511 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8515 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8516 &cond_string
, &cond
, &ops
);
8517 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8518 cond_string
, cond
, ops
, tempflag
,
8522 /* Cleanup function for a syscall filter list. */
8524 clean_up_filters (void *arg
)
8526 VEC(int) *iter
= *(VEC(int) **) arg
;
8527 VEC_free (int, iter
);
8530 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8531 filter list, or NULL if no filtering is required. */
8533 catch_syscall_split_args (char *arg
)
8535 VEC(int) *result
= NULL
;
8536 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8538 while (*arg
!= '\0')
8540 int i
, syscall_number
;
8545 /* Skip whitespace. */
8546 while (isspace (*arg
))
8549 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8550 cur_name
[i
] = arg
[i
];
8554 /* Check if the user provided a syscall name or a number. */
8555 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8556 if (*endptr
== '\0')
8557 get_syscall_by_number (syscall_number
, &s
);
8560 /* We have a name. Let's check if it's valid and convert it
8562 get_syscall_by_name (cur_name
, &s
);
8564 if (s
.number
== UNKNOWN_SYSCALL
)
8565 /* Here we have to issue an error instead of a warning, because
8566 GDB cannot do anything useful if there's no syscall number to
8568 error (_("Unknown syscall name '%s'."), cur_name
);
8571 /* Ok, it's valid. */
8572 VEC_safe_push (int, result
, s
.number
);
8575 discard_cleanups (cleanup
);
8579 /* Implement the "catch syscall" command. */
8582 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8587 struct gdbarch
*gdbarch
= get_current_arch ();
8589 /* Checking if the feature if supported. */
8590 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8591 error (_("The feature 'catch syscall' is not supported on \
8592 this architeture yet."));
8594 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8596 ep_skip_leading_whitespace (&arg
);
8598 /* We need to do this first "dummy" translation in order
8599 to get the syscall XML file loaded or, most important,
8600 to display a warning to the user if there's no XML file
8601 for his/her architecture. */
8602 get_syscall_by_number (0, &s
);
8604 /* The allowed syntax is:
8606 catch syscall <name | number> [<name | number> ... <name | number>]
8608 Let's check if there's a syscall name. */
8611 filter
= catch_syscall_split_args (arg
);
8615 create_syscall_event_catchpoint (tempflag
, filter
,
8616 &catch_syscall_breakpoint_ops
);
8619 /* Implement the "catch assert" command. */
8622 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8624 struct gdbarch
*gdbarch
= get_current_arch ();
8626 struct symtab_and_line sal
;
8627 char *addr_string
= NULL
;
8628 struct breakpoint_ops
*ops
= NULL
;
8630 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8634 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8635 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8636 ops
, tempflag
, from_tty
);
8640 catch_command (char *arg
, int from_tty
)
8642 error (_("Catch requires an event name."));
8647 tcatch_command (char *arg
, int from_tty
)
8649 error (_("Catch requires an event name."));
8652 /* Delete breakpoints by address or line. */
8655 clear_command (char *arg
, int from_tty
)
8657 struct breakpoint
*b
;
8658 VEC(breakpoint_p
) *found
= 0;
8661 struct symtabs_and_lines sals
;
8662 struct symtab_and_line sal
;
8667 sals
= decode_line_spec (arg
, 1);
8672 sals
.sals
= (struct symtab_and_line
*)
8673 xmalloc (sizeof (struct symtab_and_line
));
8674 make_cleanup (xfree
, sals
.sals
);
8675 init_sal (&sal
); /* initialize to zeroes */
8676 sal
.line
= default_breakpoint_line
;
8677 sal
.symtab
= default_breakpoint_symtab
;
8678 sal
.pc
= default_breakpoint_address
;
8679 sal
.pspace
= default_breakpoint_pspace
;
8680 if (sal
.symtab
== 0)
8681 error (_("No source file specified."));
8689 /* We don't call resolve_sal_pc here. That's not
8690 as bad as it seems, because all existing breakpoints
8691 typically have both file/line and pc set. So, if
8692 clear is given file/line, we can match this to existing
8693 breakpoint without obtaining pc at all.
8695 We only support clearing given the address explicitly
8696 present in breakpoint table. Say, we've set breakpoint
8697 at file:line. There were several PC values for that file:line,
8698 due to optimization, all in one block.
8699 We've picked one PC value. If "clear" is issued with another
8700 PC corresponding to the same file:line, the breakpoint won't
8701 be cleared. We probably can still clear the breakpoint, but
8702 since the other PC value is never presented to user, user
8703 can only find it by guessing, and it does not seem important
8706 /* For each line spec given, delete bps which correspond
8707 to it. Do it in two passes, solely to preserve the current
8708 behavior that from_tty is forced true if we delete more than
8712 for (i
= 0; i
< sals
.nelts
; i
++)
8714 /* If exact pc given, clear bpts at that pc.
8715 If line given (pc == 0), clear all bpts on specified line.
8716 If defaulting, clear all bpts on default line
8719 defaulting sal.pc != 0 tests to do
8724 1 0 <can't happen> */
8728 /* Find all matching breakpoints and add them to
8733 /* Are we going to delete b? */
8734 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
8736 struct bp_location
*loc
= b
->loc
;
8737 for (; loc
; loc
= loc
->next
)
8739 int pc_match
= sal
.pc
8740 && (loc
->pspace
== sal
.pspace
)
8741 && (loc
->address
== sal
.pc
)
8742 && (!section_is_overlay (loc
->section
)
8743 || loc
->section
== sal
.section
);
8744 int line_match
= ((default_match
|| (0 == sal
.pc
))
8745 && b
->source_file
!= NULL
8746 && sal
.symtab
!= NULL
8747 && sal
.pspace
== loc
->pspace
8748 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8749 && b
->line_number
== sal
.line
);
8750 if (pc_match
|| line_match
)
8759 VEC_safe_push(breakpoint_p
, found
, b
);
8762 /* Now go thru the 'found' chain and delete them. */
8763 if (VEC_empty(breakpoint_p
, found
))
8766 error (_("No breakpoint at %s."), arg
);
8768 error (_("No breakpoint at this line."));
8771 if (VEC_length(breakpoint_p
, found
) > 1)
8772 from_tty
= 1; /* Always report if deleted more than one */
8775 if (VEC_length(breakpoint_p
, found
) == 1)
8776 printf_unfiltered (_("Deleted breakpoint "));
8778 printf_unfiltered (_("Deleted breakpoints "));
8780 breakpoints_changed ();
8782 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8785 printf_unfiltered ("%d ", b
->number
);
8786 delete_breakpoint (b
);
8789 putchar_unfiltered ('\n');
8792 /* Delete breakpoint in BS if they are `delete' breakpoints and
8793 all breakpoints that are marked for deletion, whether hit or not.
8794 This is called after any breakpoint is hit, or after errors. */
8797 breakpoint_auto_delete (bpstat bs
)
8799 struct breakpoint
*b
, *temp
;
8801 for (; bs
; bs
= bs
->next
)
8802 if (bs
->breakpoint_at
8803 && bs
->breakpoint_at
->owner
8804 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8806 delete_breakpoint (bs
->breakpoint_at
->owner
);
8808 ALL_BREAKPOINTS_SAFE (b
, temp
)
8810 if (b
->disposition
== disp_del_at_next_stop
)
8811 delete_breakpoint (b
);
8815 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8816 Sort elements primarily by their ADDRESS (no matter what does
8817 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8818 first bp_permanent OWNERed elements and terciarily just ensuring the array
8819 is sorted stable way despite qsort being an instable algorithm. */
8822 bp_location_compare (const void *ap
, const void *bp
)
8824 struct bp_location
*a
= *(void **) ap
;
8825 struct bp_location
*b
= *(void **) bp
;
8826 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8827 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8829 if (a
->address
!= b
->address
)
8830 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8832 /* Sort permanent breakpoints first. */
8833 if (a_perm
!= b_perm
)
8834 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8836 /* Make the user-visible order stable across GDB runs. Locations of the same
8837 breakpoint can be sorted in arbitrary order. */
8839 if (a
->owner
->number
!= b
->owner
->number
)
8840 return (a
->owner
->number
> b
->owner
->number
)
8841 - (a
->owner
->number
< b
->owner
->number
);
8843 return (a
> b
) - (a
< b
);
8846 /* Set bp_location_placed_address_before_address_max and
8847 bp_location_shadow_len_after_address_max according to the current content of
8848 the bp_location array. */
8851 bp_location_target_extensions_update (void)
8853 struct bp_location
*bl
, **blp_tmp
;
8855 bp_location_placed_address_before_address_max
= 0;
8856 bp_location_shadow_len_after_address_max
= 0;
8858 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8860 CORE_ADDR start
, end
, addr
;
8862 if (!bp_location_has_shadow (bl
))
8865 start
= bl
->target_info
.placed_address
;
8866 end
= start
+ bl
->target_info
.shadow_len
;
8868 gdb_assert (bl
->address
>= start
);
8869 addr
= bl
->address
- start
;
8870 if (addr
> bp_location_placed_address_before_address_max
)
8871 bp_location_placed_address_before_address_max
= addr
;
8873 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8875 gdb_assert (bl
->address
< end
);
8876 addr
= end
- bl
->address
;
8877 if (addr
> bp_location_shadow_len_after_address_max
)
8878 bp_location_shadow_len_after_address_max
= addr
;
8882 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8883 into the inferior, only remove already-inserted locations that no
8884 longer should be inserted. Functions that delete a breakpoint or
8885 breakpoints should pass false, so that deleting a breakpoint
8886 doesn't have the side effect of inserting the locations of other
8887 breakpoints that are marked not-inserted, but should_be_inserted
8888 returns true on them.
8890 This behaviour is useful is situations close to tear-down -- e.g.,
8891 after an exec, while the target still has execution, but breakpoint
8892 shadows of the previous executable image should *NOT* be restored
8893 to the new image; or before detaching, where the target still has
8894 execution and wants to delete breakpoints from GDB's lists, and all
8895 breakpoints had already been removed from the inferior. */
8898 update_global_location_list (int should_insert
)
8900 struct breakpoint
*b
;
8901 struct bp_location
**locp
, *loc
;
8902 struct cleanup
*cleanups
;
8904 /* Used in the duplicates detection below. When iterating over all
8905 bp_locations, points to the first bp_location of a given address.
8906 Breakpoints and watchpoints of different types are never
8907 duplicates of each other. Keep one pointer for each type of
8908 breakpoint/watchpoint, so we only need to loop over all locations
8910 struct bp_location
*bp_loc_first
; /* breakpoint */
8911 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8912 struct bp_location
*awp_loc_first
; /* access watchpoint */
8913 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8915 /* Saved former bp_location array which we compare against the newly built
8916 bp_location from the current state of ALL_BREAKPOINTS. */
8917 struct bp_location
**old_location
, **old_locp
;
8918 unsigned old_location_count
;
8920 old_location
= bp_location
;
8921 old_location_count
= bp_location_count
;
8923 bp_location_count
= 0;
8924 cleanups
= make_cleanup (xfree
, old_location
);
8927 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8928 bp_location_count
++;
8930 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8933 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8935 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8936 bp_location_compare
);
8938 bp_location_target_extensions_update ();
8940 /* Identify bp_location instances that are no longer present in the new
8941 list, and therefore should be freed. Note that it's not necessary that
8942 those locations should be removed from inferior -- if there's another
8943 location at the same address (previously marked as duplicate),
8944 we don't need to remove/insert the location.
8946 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8947 former bp_location array state respectively. */
8950 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8953 struct bp_location
*old_loc
= *old_locp
;
8954 struct bp_location
**loc2p
;
8956 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8958 int found_object
= 0;
8959 /* Tells if the location should remain inserted in the target. */
8960 int keep_in_target
= 0;
8963 /* Skip LOCP entries which will definitely never be needed. Stop either
8964 at or being the one matching OLD_LOC. */
8965 while (locp
< bp_location
+ bp_location_count
8966 && (*locp
)->address
< old_loc
->address
)
8970 (loc2p
< bp_location
+ bp_location_count
8971 && (*loc2p
)->address
== old_loc
->address
);
8974 if (*loc2p
== old_loc
)
8981 /* If this location is no longer present, and inserted, look if there's
8982 maybe a new location at the same address. If so, mark that one
8983 inserted, and don't remove this one. This is needed so that we
8984 don't have a time window where a breakpoint at certain location is not
8987 if (old_loc
->inserted
)
8989 /* If the location is inserted now, we might have to remove it. */
8991 if (found_object
&& should_be_inserted (old_loc
))
8993 /* The location is still present in the location list, and still
8994 should be inserted. Don't do anything. */
8999 /* The location is either no longer present, or got disabled.
9000 See if there's another location at the same address, in which
9001 case we don't need to remove this one from the target. */
9003 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9006 (loc2p
< bp_location
+ bp_location_count
9007 && (*loc2p
)->address
== old_loc
->address
);
9010 struct bp_location
*loc2
= *loc2p
;
9012 if (breakpoint_locations_match (loc2
, old_loc
))
9014 /* For the sake of should_be_inserted.
9015 Duplicates check below will fix up this later. */
9016 loc2
->duplicate
= 0;
9018 /* Read watchpoint locations are switched to
9019 access watchpoints, if the former are not
9020 supported, but the latter are. */
9021 if (is_hardware_watchpoint (old_loc
->owner
))
9023 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9024 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9027 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9030 loc2
->target_info
= old_loc
->target_info
;
9039 if (!keep_in_target
)
9041 if (remove_breakpoint (old_loc
, mark_uninserted
))
9043 /* This is just about all we can do. We could keep this
9044 location on the global list, and try to remove it next
9045 time, but there's no particular reason why we will
9048 Note that at this point, old_loc->owner is still valid,
9049 as delete_breakpoint frees the breakpoint only
9050 after calling us. */
9051 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9052 old_loc
->owner
->number
);
9060 if (removed
&& non_stop
9061 && breakpoint_address_is_meaningful (old_loc
->owner
)
9062 && !is_hardware_watchpoint (old_loc
->owner
))
9064 /* This location was removed from the target. In
9065 non-stop mode, a race condition is possible where
9066 we've removed a breakpoint, but stop events for that
9067 breakpoint are already queued and will arrive later.
9068 We apply an heuristic to be able to distinguish such
9069 SIGTRAPs from other random SIGTRAPs: we keep this
9070 breakpoint location for a bit, and will retire it
9071 after we see some number of events. The theory here
9072 is that reporting of events should, "on the average",
9073 be fair, so after a while we'll see events from all
9074 threads that have anything of interest, and no longer
9075 need to keep this breakpoint location around. We
9076 don't hold locations forever so to reduce chances of
9077 mistaking a non-breakpoint SIGTRAP for a breakpoint
9080 The heuristic failing can be disastrous on
9081 decr_pc_after_break targets.
9083 On decr_pc_after_break targets, like e.g., x86-linux,
9084 if we fail to recognize a late breakpoint SIGTRAP,
9085 because events_till_retirement has reached 0 too
9086 soon, we'll fail to do the PC adjustment, and report
9087 a random SIGTRAP to the user. When the user resumes
9088 the inferior, it will most likely immediately crash
9089 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9090 corrupted, because of being resumed e.g., in the
9091 middle of a multi-byte instruction, or skipped a
9092 one-byte instruction. This was actually seen happen
9093 on native x86-linux, and should be less rare on
9094 targets that do not support new thread events, like
9095 remote, due to the heuristic depending on
9098 Mistaking a random SIGTRAP for a breakpoint trap
9099 causes similar symptoms (PC adjustment applied when
9100 it shouldn't), but then again, playing with SIGTRAPs
9101 behind the debugger's back is asking for trouble.
9103 Since hardware watchpoint traps are always
9104 distinguishable from other traps, so we don't need to
9105 apply keep hardware watchpoint moribund locations
9106 around. We simply always ignore hardware watchpoint
9107 traps we can no longer explain. */
9109 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9110 old_loc
->owner
= NULL
;
9112 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9115 free_bp_location (old_loc
);
9119 /* Rescan breakpoints at the same address and section, marking the
9120 first one as "first" and any others as "duplicates". This is so
9121 that the bpt instruction is only inserted once. If we have a
9122 permanent breakpoint at the same place as BPT, make that one the
9123 official one, and the rest as duplicates. Permanent breakpoints
9124 are sorted first for the same address.
9126 Do the same for hardware watchpoints, but also considering the
9127 watchpoint's type (regular/access/read) and length. */
9129 bp_loc_first
= NULL
;
9130 wp_loc_first
= NULL
;
9131 awp_loc_first
= NULL
;
9132 rwp_loc_first
= NULL
;
9133 ALL_BP_LOCATIONS (loc
, locp
)
9135 struct breakpoint
*b
= loc
->owner
;
9136 struct bp_location
**loc_first_p
;
9138 if (b
->enable_state
== bp_disabled
9139 || b
->enable_state
== bp_call_disabled
9140 || b
->enable_state
== bp_startup_disabled
9142 || loc
->shlib_disabled
9143 || !breakpoint_address_is_meaningful (b
)
9144 || is_tracepoint (b
))
9147 /* Permanent breakpoint should always be inserted. */
9148 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9149 internal_error (__FILE__
, __LINE__
,
9150 _("allegedly permanent breakpoint is not "
9151 "actually inserted"));
9153 if (b
->type
== bp_hardware_watchpoint
)
9154 loc_first_p
= &wp_loc_first
;
9155 else if (b
->type
== bp_read_watchpoint
)
9156 loc_first_p
= &rwp_loc_first
;
9157 else if (b
->type
== bp_access_watchpoint
)
9158 loc_first_p
= &awp_loc_first
;
9160 loc_first_p
= &bp_loc_first
;
9162 if (*loc_first_p
== NULL
9163 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9164 || !breakpoint_locations_match (loc
, *loc_first_p
))
9173 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9174 && b
->enable_state
!= bp_permanent
)
9175 internal_error (__FILE__
, __LINE__
,
9176 _("another breakpoint was inserted on top of "
9177 "a permanent breakpoint"));
9180 if (breakpoints_always_inserted_mode () && should_insert
9181 && (have_live_inferiors ()
9182 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9183 insert_breakpoint_locations ();
9185 do_cleanups (cleanups
);
9189 breakpoint_retire_moribund (void)
9191 struct bp_location
*loc
;
9194 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9195 if (--(loc
->events_till_retirement
) == 0)
9197 free_bp_location (loc
);
9198 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9204 update_global_location_list_nothrow (int inserting
)
9206 struct gdb_exception e
;
9207 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9208 update_global_location_list (inserting
);
9211 /* Clear BPT from a BPS. */
9213 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9216 for (bs
= bps
; bs
; bs
= bs
->next
)
9217 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9219 bs
->breakpoint_at
= NULL
;
9221 /* bs->commands will be freed later. */
9225 /* Callback for iterate_over_threads. */
9227 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9229 struct breakpoint
*bpt
= data
;
9230 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9234 /* Delete a breakpoint and clean up all traces of it in the data
9238 delete_breakpoint (struct breakpoint
*bpt
)
9240 struct breakpoint
*b
;
9241 struct bp_location
*loc
, *next
;
9243 gdb_assert (bpt
!= NULL
);
9245 /* Has this bp already been deleted? This can happen because multiple
9246 lists can hold pointers to bp's. bpstat lists are especial culprits.
9248 One example of this happening is a watchpoint's scope bp. When the
9249 scope bp triggers, we notice that the watchpoint is out of scope, and
9250 delete it. We also delete its scope bp. But the scope bp is marked
9251 "auto-deleting", and is already on a bpstat. That bpstat is then
9252 checked for auto-deleting bp's, which are deleted.
9254 A real solution to this problem might involve reference counts in bp's,
9255 and/or giving them pointers back to their referencing bpstat's, and
9256 teaching delete_breakpoint to only free a bp's storage when no more
9257 references were extent. A cheaper bandaid was chosen. */
9258 if (bpt
->type
== bp_none
)
9261 /* At least avoid this stale reference until the reference counting of
9262 breakpoints gets resolved. */
9263 if (bpt
->related_breakpoint
!= NULL
)
9265 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9266 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9267 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9268 bpt
->related_breakpoint
= NULL
;
9271 observer_notify_breakpoint_deleted (bpt
->number
);
9273 if (breakpoint_chain
== bpt
)
9274 breakpoint_chain
= bpt
->next
;
9279 b
->next
= bpt
->next
;
9283 decref_counted_command_line (&bpt
->commands
);
9284 xfree (bpt
->cond_string
);
9285 xfree (bpt
->cond_exp
);
9286 xfree (bpt
->addr_string
);
9288 xfree (bpt
->exp_string
);
9289 value_free (bpt
->val
);
9290 xfree (bpt
->source_file
);
9291 xfree (bpt
->exec_pathname
);
9292 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9294 /* Be sure no bpstat's are pointing at it after it's been freed. */
9295 /* FIXME, how can we find all bpstat's?
9296 We just check stop_bpstat for now. Note that we cannot just
9297 remove bpstats pointing at bpt from the stop_bpstat list
9298 entirely, as breakpoint commands are associated with the bpstat;
9299 if we remove it here, then the later call to
9300 bpstat_do_actions (&stop_bpstat);
9301 in event-top.c won't do anything, and temporary breakpoints
9302 with commands won't work. */
9304 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9306 /* Now that breakpoint is removed from breakpoint
9307 list, update the global location list. This
9308 will remove locations that used to belong to
9309 this breakpoint. Do this before freeing
9310 the breakpoint itself, since remove_breakpoint
9311 looks at location's owner. It might be better
9312 design to have location completely self-contained,
9313 but it's not the case now. */
9314 update_global_location_list (0);
9317 /* On the chance that someone will soon try again to delete this same
9318 bp, we mark it as deleted before freeing its storage. */
9319 bpt
->type
= bp_none
;
9325 do_delete_breakpoint_cleanup (void *b
)
9327 delete_breakpoint (b
);
9331 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9333 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9336 /* A callback for map_breakpoint_numbers that calls
9337 delete_breakpoint. */
9340 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9342 delete_breakpoint (b
);
9346 delete_command (char *arg
, int from_tty
)
9348 struct breakpoint
*b
, *temp
;
9354 int breaks_to_delete
= 0;
9356 /* Delete all breakpoints if no argument.
9357 Do not delete internal or call-dummy breakpoints, these
9358 have to be deleted with an explicit breakpoint number argument. */
9361 if (b
->type
!= bp_call_dummy
9362 && b
->type
!= bp_std_terminate
9363 && b
->type
!= bp_shlib_event
9364 && b
->type
!= bp_jit_event
9365 && b
->type
!= bp_thread_event
9366 && b
->type
!= bp_overlay_event
9367 && b
->type
!= bp_longjmp_master
9368 && b
->type
!= bp_std_terminate_master
9371 breaks_to_delete
= 1;
9376 /* Ask user only if there are some breakpoints to delete. */
9378 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9380 ALL_BREAKPOINTS_SAFE (b
, temp
)
9382 if (b
->type
!= bp_call_dummy
9383 && b
->type
!= bp_std_terminate
9384 && b
->type
!= bp_shlib_event
9385 && b
->type
!= bp_thread_event
9386 && b
->type
!= bp_jit_event
9387 && b
->type
!= bp_overlay_event
9388 && b
->type
!= bp_longjmp_master
9389 && b
->type
!= bp_std_terminate_master
9391 delete_breakpoint (b
);
9396 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9400 all_locations_are_pending (struct bp_location
*loc
)
9402 for (; loc
; loc
= loc
->next
)
9403 if (!loc
->shlib_disabled
)
9408 /* Subroutine of update_breakpoint_locations to simplify it.
9409 Return non-zero if multiple fns in list LOC have the same name.
9410 Null names are ignored. */
9413 ambiguous_names_p (struct bp_location
*loc
)
9415 struct bp_location
*l
;
9416 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9417 (int (*) (const void *, const void *)) streq
,
9418 NULL
, xcalloc
, xfree
);
9420 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9423 const char *name
= l
->function_name
;
9425 /* Allow for some names to be NULL, ignore them. */
9429 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9431 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9446 update_breakpoint_locations (struct breakpoint
*b
,
9447 struct symtabs_and_lines sals
)
9451 struct bp_location
*existing_locations
= b
->loc
;
9453 /* If there's no new locations, and all existing locations
9454 are pending, don't do anything. This optimizes
9455 the common case where all locations are in the same
9456 shared library, that was unloaded. We'd like to
9457 retain the location, so that when the library
9458 is loaded again, we don't loose the enabled/disabled
9459 status of the individual locations. */
9460 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9465 for (i
= 0; i
< sals
.nelts
; ++i
)
9467 struct bp_location
*new_loc
=
9468 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9470 /* Reparse conditions, they might contain references to the
9472 if (b
->cond_string
!= NULL
)
9474 struct gdb_exception e
;
9477 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9479 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9484 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9485 b
->number
, e
.message
);
9486 new_loc
->enabled
= 0;
9490 if (b
->source_file
!= NULL
)
9491 xfree (b
->source_file
);
9492 if (sals
.sals
[i
].symtab
== NULL
)
9493 b
->source_file
= NULL
;
9495 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9497 if (b
->line_number
== 0)
9498 b
->line_number
= sals
.sals
[i
].line
;
9501 /* Update locations of permanent breakpoints. */
9502 if (b
->enable_state
== bp_permanent
)
9503 make_breakpoint_permanent (b
);
9505 /* If possible, carry over 'disable' status from existing breakpoints. */
9507 struct bp_location
*e
= existing_locations
;
9508 /* If there are multiple breakpoints with the same function name,
9509 e.g. for inline functions, comparing function names won't work.
9510 Instead compare pc addresses; this is just a heuristic as things
9511 may have moved, but in practice it gives the correct answer
9512 often enough until a better solution is found. */
9513 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9515 for (; e
; e
= e
->next
)
9517 if (!e
->enabled
&& e
->function_name
)
9519 struct bp_location
*l
= b
->loc
;
9520 if (have_ambiguous_names
)
9522 for (; l
; l
= l
->next
)
9523 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9524 l
->pspace
->aspace
, l
->address
))
9532 for (; l
; l
= l
->next
)
9533 if (l
->function_name
9534 && strcmp (e
->function_name
, l
->function_name
) == 0)
9544 update_global_location_list (1);
9548 /* Reset a breakpoint given it's struct breakpoint * BINT.
9549 The value we return ends up being the return value from catch_errors.
9550 Unused in this case. */
9553 breakpoint_re_set_one (void *bint
)
9555 /* get past catch_errs */
9556 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9560 int *not_found_ptr
= ¬_found
;
9561 struct symtabs_and_lines sals
= {0};
9562 struct symtabs_and_lines expanded
= {0};
9564 enum enable_state save_enable
;
9565 struct gdb_exception e
;
9566 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9571 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9575 case bp_hardware_breakpoint
:
9577 case bp_fast_tracepoint
:
9578 /* Do not attempt to re-set breakpoints disabled during startup. */
9579 if (b
->enable_state
== bp_startup_disabled
)
9582 if (b
->addr_string
== NULL
)
9584 /* Anything without a string can't be re-set. */
9585 delete_breakpoint (b
);
9589 set_language (b
->language
);
9590 input_radix
= b
->input_radix
;
9593 save_current_space_and_thread ();
9594 switch_to_program_space_and_thread (b
->pspace
);
9596 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9598 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9603 int not_found_and_ok
= 0;
9604 /* For pending breakpoints, it's expected that parsing
9605 will fail until the right shared library is loaded.
9606 User has already told to create pending breakpoints and
9607 don't need extra messages. If breakpoint is in bp_shlib_disabled
9608 state, then user already saw the message about that breakpoint
9609 being disabled, and don't want to see more errors. */
9611 && (b
->condition_not_parsed
9612 || (b
->loc
&& b
->loc
->shlib_disabled
)
9613 || b
->enable_state
== bp_disabled
))
9614 not_found_and_ok
= 1;
9616 if (!not_found_and_ok
)
9618 /* We surely don't want to warn about the same breakpoint
9619 10 times. One solution, implemented here, is disable
9620 the breakpoint on error. Another solution would be to
9621 have separate 'warning emitted' flag. Since this
9622 happens only when a binary has changed, I don't know
9623 which approach is better. */
9624 b
->enable_state
= bp_disabled
;
9625 throw_exception (e
);
9631 gdb_assert (sals
.nelts
== 1);
9633 resolve_sal_pc (&sals
.sals
[0]);
9634 if (b
->condition_not_parsed
&& s
&& s
[0])
9636 char *cond_string
= 0;
9640 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9641 &cond_string
, &thread
, &task
);
9643 b
->cond_string
= cond_string
;
9646 b
->condition_not_parsed
= 0;
9649 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9652 make_cleanup (xfree
, sals
.sals
);
9653 update_breakpoint_locations (b
, expanded
);
9657 case bp_hardware_watchpoint
:
9658 case bp_read_watchpoint
:
9659 case bp_access_watchpoint
:
9660 /* Watchpoint can be either on expression using entirely global variables,
9661 or it can be on local variables.
9663 Watchpoints of the first kind are never auto-deleted, and even persist
9664 across program restarts. Since they can use variables from shared
9665 libraries, we need to reparse expression as libraries are loaded
9668 Watchpoints on local variables can also change meaning as result
9669 of solib event. For example, if a watchpoint uses both a local and
9670 a global variables in expression, it's a local watchpoint, but
9671 unloading of a shared library will make the expression invalid.
9672 This is not a very common use case, but we still re-evaluate
9673 expression, to avoid surprises to the user.
9675 Note that for local watchpoints, we re-evaluate it only if
9676 watchpoints frame id is still valid. If it's not, it means
9677 the watchpoint is out of scope and will be deleted soon. In fact,
9678 I'm not sure we'll ever be called in this case.
9680 If a local watchpoint's frame id is still valid, then
9681 b->exp_valid_block is likewise valid, and we can safely use it.
9683 Don't do anything about disabled watchpoints, since they will
9684 be reevaluated again when enabled. */
9685 update_watchpoint (b
, 1 /* reparse */);
9687 /* We needn't really do anything to reset these, since the mask
9688 that requests them is unaffected by e.g., new libraries being
9694 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9696 /* Delete overlay event and longjmp master breakpoints; they will be
9697 reset later by breakpoint_re_set. */
9698 case bp_overlay_event
:
9699 case bp_longjmp_master
:
9700 case bp_std_terminate_master
:
9701 delete_breakpoint (b
);
9704 /* This breakpoint is special, it's set up when the inferior
9705 starts and we really don't want to touch it. */
9706 case bp_shlib_event
:
9708 /* Like bp_shlib_event, this breakpoint type is special.
9709 Once it is set up, we do not want to touch it. */
9710 case bp_thread_event
:
9712 /* Keep temporary breakpoints, which can be encountered when we step
9713 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9714 Otherwise these should have been blown away via the cleanup chain
9715 or by breakpoint_init_inferior when we rerun the executable. */
9718 case bp_watchpoint_scope
:
9720 case bp_std_terminate
:
9721 case bp_step_resume
:
9723 case bp_longjmp_resume
:
9728 do_cleanups (cleanups
);
9732 /* Re-set all breakpoints after symbols have been re-loaded. */
9734 breakpoint_re_set (void)
9736 struct breakpoint
*b
, *temp
;
9737 enum language save_language
;
9738 int save_input_radix
;
9739 struct cleanup
*old_chain
;
9741 save_language
= current_language
->la_language
;
9742 save_input_radix
= input_radix
;
9743 old_chain
= save_current_program_space ();
9745 ALL_BREAKPOINTS_SAFE (b
, temp
)
9747 /* Format possible error msg */
9748 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9750 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9751 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9752 do_cleanups (cleanups
);
9754 set_language (save_language
);
9755 input_radix
= save_input_radix
;
9757 jit_breakpoint_re_set ();
9759 do_cleanups (old_chain
);
9761 create_overlay_event_breakpoint ("_ovly_debug_event");
9762 create_longjmp_master_breakpoint ("longjmp");
9763 create_longjmp_master_breakpoint ("_longjmp");
9764 create_longjmp_master_breakpoint ("siglongjmp");
9765 create_longjmp_master_breakpoint ("_siglongjmp");
9766 create_std_terminate_master_breakpoint ("std::terminate()");
9769 /* Reset the thread number of this breakpoint:
9771 - If the breakpoint is for all threads, leave it as-is.
9772 - Else, reset it to the current thread for inferior_ptid. */
9774 breakpoint_re_set_thread (struct breakpoint
*b
)
9776 if (b
->thread
!= -1)
9778 if (in_thread_list (inferior_ptid
))
9779 b
->thread
= pid_to_thread_id (inferior_ptid
);
9781 /* We're being called after following a fork. The new fork is
9782 selected as current, and unless this was a vfork will have a
9783 different program space from the original thread. Reset that
9785 b
->loc
->pspace
= current_program_space
;
9789 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9790 If from_tty is nonzero, it prints a message to that effect,
9791 which ends with a period (no newline). */
9794 set_ignore_count (int bptnum
, int count
, int from_tty
)
9796 struct breakpoint
*b
;
9802 if (b
->number
== bptnum
)
9804 if (is_tracepoint (b
))
9806 if (from_tty
&& count
!= 0)
9807 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9812 b
->ignore_count
= count
;
9816 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9818 else if (count
== 1)
9819 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9822 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9825 breakpoints_changed ();
9826 observer_notify_breakpoint_modified (b
->number
);
9830 error (_("No breakpoint number %d."), bptnum
);
9834 make_breakpoint_silent (struct breakpoint
*b
)
9836 /* Silence the breakpoint. */
9840 /* Command to set ignore-count of breakpoint N to COUNT. */
9843 ignore_command (char *args
, int from_tty
)
9849 error_no_arg (_("a breakpoint number"));
9851 num
= get_number (&p
);
9853 error (_("bad breakpoint number: '%s'"), args
);
9855 error (_("Second argument (specified ignore-count) is missing."));
9857 set_ignore_count (num
,
9858 longest_to_int (value_as_long (parse_and_eval (p
))),
9861 printf_filtered ("\n");
9864 /* Call FUNCTION on each of the breakpoints
9865 whose numbers are given in ARGS. */
9868 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9875 struct breakpoint
*b
, *tmp
;
9879 error_no_arg (_("one or more breakpoint numbers"));
9886 num
= get_number_or_range (&p1
);
9889 warning (_("bad breakpoint number at or near '%s'"), p
);
9893 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9894 if (b
->number
== num
)
9896 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9899 if (related_breakpoint
)
9900 function (related_breakpoint
, data
);
9904 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9910 static struct bp_location
*
9911 find_location_by_number (char *number
)
9913 char *dot
= strchr (number
, '.');
9917 struct breakpoint
*b
;
9918 struct bp_location
*loc
;
9923 bp_num
= get_number_or_range (&p1
);
9925 error (_("Bad breakpoint number '%s'"), number
);
9928 if (b
->number
== bp_num
)
9933 if (!b
|| b
->number
!= bp_num
)
9934 error (_("Bad breakpoint number '%s'"), number
);
9937 loc_num
= get_number_or_range (&p1
);
9939 error (_("Bad breakpoint location number '%s'"), number
);
9943 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9946 error (_("Bad breakpoint location number '%s'"), dot
+1);
9952 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9953 If from_tty is nonzero, it prints a message to that effect,
9954 which ends with a period (no newline). */
9957 disable_breakpoint (struct breakpoint
*bpt
)
9959 /* Never disable a watchpoint scope breakpoint; we want to
9960 hit them when we leave scope so we can delete both the
9961 watchpoint and its scope breakpoint at that time. */
9962 if (bpt
->type
== bp_watchpoint_scope
)
9965 /* You can't disable permanent breakpoints. */
9966 if (bpt
->enable_state
== bp_permanent
)
9969 bpt
->enable_state
= bp_disabled
;
9971 update_global_location_list (0);
9973 observer_notify_breakpoint_modified (bpt
->number
);
9976 /* A callback for map_breakpoint_numbers that calls
9977 disable_breakpoint. */
9980 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9982 disable_breakpoint (b
);
9986 disable_command (char *args
, int from_tty
)
9988 struct breakpoint
*bpt
;
9990 ALL_BREAKPOINTS (bpt
)
9994 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9999 case bp_fast_tracepoint
:
10000 case bp_catchpoint
:
10001 case bp_hardware_breakpoint
:
10002 case bp_watchpoint
:
10003 case bp_hardware_watchpoint
:
10004 case bp_read_watchpoint
:
10005 case bp_access_watchpoint
:
10006 disable_breakpoint (bpt
);
10010 else if (strchr (args
, '.'))
10012 struct bp_location
*loc
= find_location_by_number (args
);
10015 update_global_location_list (0);
10018 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10022 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10024 int target_resources_ok
, other_type_used
;
10025 struct value
*mark
;
10027 if (bpt
->type
== bp_hardware_breakpoint
)
10030 i
= hw_breakpoint_used_count ();
10031 target_resources_ok
=
10032 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10034 if (target_resources_ok
== 0)
10035 error (_("No hardware breakpoint support in the target."));
10036 else if (target_resources_ok
< 0)
10037 error (_("Hardware breakpoints used exceeds limit."));
10040 if (is_watchpoint (bpt
))
10042 struct gdb_exception e
;
10044 TRY_CATCH (e
, RETURN_MASK_ALL
)
10046 update_watchpoint (bpt
, 1 /* reparse */);
10050 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10056 if (bpt
->enable_state
!= bp_permanent
)
10057 bpt
->enable_state
= bp_enabled
;
10058 bpt
->disposition
= disposition
;
10059 update_global_location_list (1);
10060 breakpoints_changed ();
10062 observer_notify_breakpoint_modified (bpt
->number
);
10067 enable_breakpoint (struct breakpoint
*bpt
)
10069 do_enable_breakpoint (bpt
, bpt
->disposition
);
10072 /* A callback for map_breakpoint_numbers that calls
10073 enable_breakpoint. */
10076 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10078 enable_breakpoint (b
);
10081 /* The enable command enables the specified breakpoints (or all defined
10082 breakpoints) so they once again become (or continue to be) effective
10083 in stopping the inferior. */
10086 enable_command (char *args
, int from_tty
)
10088 struct breakpoint
*bpt
;
10090 ALL_BREAKPOINTS (bpt
)
10094 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10097 case bp_breakpoint
:
10098 case bp_tracepoint
:
10099 case bp_fast_tracepoint
:
10100 case bp_catchpoint
:
10101 case bp_hardware_breakpoint
:
10102 case bp_watchpoint
:
10103 case bp_hardware_watchpoint
:
10104 case bp_read_watchpoint
:
10105 case bp_access_watchpoint
:
10106 enable_breakpoint (bpt
);
10110 else if (strchr (args
, '.'))
10112 struct bp_location
*loc
= find_location_by_number (args
);
10115 update_global_location_list (1);
10118 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10122 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10124 do_enable_breakpoint (bpt
, disp_disable
);
10128 enable_once_command (char *args
, int from_tty
)
10130 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10134 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10136 do_enable_breakpoint (bpt
, disp_del
);
10140 enable_delete_command (char *args
, int from_tty
)
10142 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10146 set_breakpoint_cmd (char *args
, int from_tty
)
10151 show_breakpoint_cmd (char *args
, int from_tty
)
10155 /* Invalidate last known value of any hardware watchpoint if
10156 the memory which that value represents has been written to by
10160 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10161 const bfd_byte
*data
)
10163 struct breakpoint
*bp
;
10165 ALL_BREAKPOINTS (bp
)
10166 if (bp
->enable_state
== bp_enabled
10167 && bp
->type
== bp_hardware_watchpoint
10168 && bp
->val_valid
&& bp
->val
)
10170 struct bp_location
*loc
;
10172 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10173 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10174 && loc
->address
+ loc
->length
> addr
10175 && addr
+ len
> loc
->address
)
10177 value_free (bp
->val
);
10184 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10186 struct symtabs_and_lines
10187 decode_line_spec_1 (char *string
, int funfirstline
)
10189 struct symtabs_and_lines sals
;
10191 error (_("Empty line specification."));
10192 if (default_breakpoint_valid
)
10193 sals
= decode_line_1 (&string
, funfirstline
,
10194 default_breakpoint_symtab
,
10195 default_breakpoint_line
,
10196 (char ***) NULL
, NULL
);
10198 sals
= decode_line_1 (&string
, funfirstline
,
10199 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10201 error (_("Junk at end of line specification: %s"), string
);
10205 /* Create and insert a raw software breakpoint at PC. Return an
10206 identifier, which should be used to remove the breakpoint later.
10207 In general, places which call this should be using something on the
10208 breakpoint chain instead; this function should be eliminated
10212 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10213 struct address_space
*aspace
, CORE_ADDR pc
)
10215 struct bp_target_info
*bp_tgt
;
10217 bp_tgt
= XZALLOC (struct bp_target_info
);
10219 bp_tgt
->placed_address_space
= aspace
;
10220 bp_tgt
->placed_address
= pc
;
10222 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10224 /* Could not insert the breakpoint. */
10232 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10235 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10237 struct bp_target_info
*bp_tgt
= bp
;
10240 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10246 /* One (or perhaps two) breakpoints used for software single stepping. */
10248 static void *single_step_breakpoints
[2];
10249 static struct gdbarch
*single_step_gdbarch
[2];
10251 /* Create and insert a breakpoint for software single step. */
10254 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10255 struct address_space
*aspace
, CORE_ADDR next_pc
)
10259 if (single_step_breakpoints
[0] == NULL
)
10261 bpt_p
= &single_step_breakpoints
[0];
10262 single_step_gdbarch
[0] = gdbarch
;
10266 gdb_assert (single_step_breakpoints
[1] == NULL
);
10267 bpt_p
= &single_step_breakpoints
[1];
10268 single_step_gdbarch
[1] = gdbarch
;
10271 /* NOTE drow/2006-04-11: A future improvement to this function would be
10272 to only create the breakpoints once, and actually put them on the
10273 breakpoint chain. That would let us use set_raw_breakpoint. We could
10274 adjust the addresses each time they were needed. Doing this requires
10275 corresponding changes elsewhere where single step breakpoints are
10276 handled, however. So, for now, we use this. */
10278 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10279 if (*bpt_p
== NULL
)
10280 error (_("Could not insert single-step breakpoint at %s"),
10281 paddress (gdbarch
, next_pc
));
10284 /* Remove and delete any breakpoints used for software single step. */
10287 remove_single_step_breakpoints (void)
10289 gdb_assert (single_step_breakpoints
[0] != NULL
);
10291 /* See insert_single_step_breakpoint for more about this deprecated
10293 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10294 single_step_breakpoints
[0]);
10295 single_step_gdbarch
[0] = NULL
;
10296 single_step_breakpoints
[0] = NULL
;
10298 if (single_step_breakpoints
[1] != NULL
)
10300 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10301 single_step_breakpoints
[1]);
10302 single_step_gdbarch
[1] = NULL
;
10303 single_step_breakpoints
[1] = NULL
;
10307 /* Check whether a software single-step breakpoint is inserted at PC. */
10310 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10314 for (i
= 0; i
< 2; i
++)
10316 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10318 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10319 bp_tgt
->placed_address
,
10327 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10328 non-zero otherwise. */
10330 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10332 if (syscall_catchpoint_p (bp
)
10333 && bp
->enable_state
!= bp_disabled
10334 && bp
->enable_state
!= bp_call_disabled
)
10341 catch_syscall_enabled (void)
10343 struct inferior
*inf
= current_inferior ();
10345 return inf
->total_syscalls_count
!= 0;
10349 catching_syscall_number (int syscall_number
)
10351 struct breakpoint
*bp
;
10353 ALL_BREAKPOINTS (bp
)
10354 if (is_syscall_catchpoint_enabled (bp
))
10356 if (bp
->syscalls_to_be_caught
)
10360 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10362 if (syscall_number
== iter
)
10372 /* Complete syscall names. Used by "catch syscall". */
10374 catch_syscall_completer (struct cmd_list_element
*cmd
,
10375 char *text
, char *word
)
10377 const char **list
= get_syscall_names ();
10378 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10381 /* Tracepoint-specific operations. */
10383 /* Set tracepoint count to NUM. */
10385 set_tracepoint_count (int num
)
10387 tracepoint_count
= num
;
10388 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10392 trace_command (char *arg
, int from_tty
)
10394 if (create_breakpoint (get_current_arch (),
10396 NULL
, 0, 1 /* parse arg */,
10397 0 /* tempflag */, 0 /* hardwareflag */,
10399 0 /* Ignore count */,
10400 pending_break_support
,
10404 set_tracepoint_count (breakpoint_count
);
10408 ftrace_command (char *arg
, int from_tty
)
10410 if (create_breakpoint (get_current_arch (),
10412 NULL
, 0, 1 /* parse arg */,
10413 0 /* tempflag */, 1 /* hardwareflag */,
10415 0 /* Ignore count */,
10416 pending_break_support
,
10420 set_tracepoint_count (breakpoint_count
);
10423 /* Set up a fake reader function that gets command lines from a linked
10424 list that was acquired during tracepoint uploading. */
10426 static struct uploaded_tp
*this_utp
;
10427 static int next_cmd
;
10430 read_uploaded_action (void)
10434 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
10441 /* Given information about a tracepoint as recorded on a target (which
10442 can be either a live system or a trace file), attempt to create an
10443 equivalent GDB tracepoint. This is not a reliable process, since
10444 the target does not necessarily have all the information used when
10445 the tracepoint was originally defined. */
10447 struct breakpoint
*
10448 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10450 char *addr_str
, small_buf
[100];
10451 struct breakpoint
*tp
;
10453 if (utp
->at_string
)
10454 addr_str
= utp
->at_string
;
10457 /* In the absence of a source location, fall back to raw
10458 address. Since there is no way to confirm that the address
10459 means the same thing as when the trace was started, warn the
10461 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10463 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10464 addr_str
= small_buf
;
10467 /* There's not much we can do with a sequence of bytecodes. */
10468 if (utp
->cond
&& !utp
->cond_string
)
10469 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10472 if (!create_breakpoint (get_current_arch (),
10474 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10476 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10478 0 /* Ignore count */,
10479 pending_break_support
,
10482 utp
->enabled
/* enabled */))
10485 set_tracepoint_count (breakpoint_count
);
10487 /* Get the tracepoint we just created. */
10488 tp
= get_tracepoint (tracepoint_count
);
10489 gdb_assert (tp
!= NULL
);
10493 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10495 trace_pass_command (small_buf
, 0);
10498 /* If we have uploaded versions of the original commands, set up a
10499 special-purpose "reader" function and call the usual command line
10500 reader, then pass the result to the breakpoint command-setting
10502 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
10504 struct command_line
*cmd_list
;
10509 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10511 breakpoint_set_commands (tp
, cmd_list
);
10513 else if (!VEC_empty (char_ptr
, utp
->actions
)
10514 || !VEC_empty (char_ptr
, utp
->step_actions
))
10515 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10521 /* Print information on tracepoint number TPNUM_EXP, or all if
10525 tracepoints_info (char *tpnum_exp
, int from_tty
)
10527 int tpnum
= -1, num_printed
;
10530 tpnum
= parse_and_eval_long (tpnum_exp
);
10532 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
10534 if (num_printed
== 0)
10537 ui_out_message (uiout
, 0, "No tracepoints.\n");
10539 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
10542 default_collect_info ();
10545 /* The 'enable trace' command enables tracepoints.
10546 Not supported by all targets. */
10548 enable_trace_command (char *args
, int from_tty
)
10550 enable_command (args
, from_tty
);
10553 /* The 'disable trace' command disables tracepoints.
10554 Not supported by all targets. */
10556 disable_trace_command (char *args
, int from_tty
)
10558 disable_command (args
, from_tty
);
10561 /* Remove a tracepoint (or all if no argument) */
10563 delete_trace_command (char *arg
, int from_tty
)
10565 struct breakpoint
*b
, *temp
;
10571 int breaks_to_delete
= 0;
10573 /* Delete all breakpoints if no argument.
10574 Do not delete internal or call-dummy breakpoints, these
10575 have to be deleted with an explicit breakpoint number argument. */
10576 ALL_TRACEPOINTS (b
)
10578 if (b
->number
>= 0)
10580 breaks_to_delete
= 1;
10585 /* Ask user only if there are some breakpoints to delete. */
10587 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10589 ALL_BREAKPOINTS_SAFE (b
, temp
)
10591 if (is_tracepoint (b
)
10593 delete_breakpoint (b
);
10598 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10601 /* Set passcount for tracepoint.
10603 First command argument is passcount, second is tracepoint number.
10604 If tracepoint number omitted, apply to most recently defined.
10605 Also accepts special argument "all". */
10608 trace_pass_command (char *args
, int from_tty
)
10610 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10611 unsigned int count
;
10614 if (args
== 0 || *args
== 0)
10615 error (_("passcount command requires an argument (count + optional TP num)"));
10617 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10619 while (*args
&& isspace ((int) *args
))
10622 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10624 args
+= 3; /* Skip special argument "all". */
10627 error (_("Junk at end of arguments."));
10630 t1
= get_tracepoint_by_number (&args
, 1, 1);
10636 ALL_TRACEPOINTS (t2
)
10637 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10639 t2
->pass_count
= count
;
10640 observer_notify_tracepoint_modified (t2
->number
);
10642 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10643 t2
->number
, count
);
10645 if (! all
&& *args
)
10646 t1
= get_tracepoint_by_number (&args
, 1, 0);
10652 struct breakpoint
*
10653 get_tracepoint (int num
)
10655 struct breakpoint
*t
;
10657 ALL_TRACEPOINTS (t
)
10658 if (t
->number
== num
)
10664 /* Find the tracepoint with the given target-side number (which may be
10665 different from the tracepoint number after disconnecting and
10668 struct breakpoint
*
10669 get_tracepoint_by_number_on_target (int num
)
10671 struct breakpoint
*t
;
10673 ALL_TRACEPOINTS (t
)
10674 if (t
->number_on_target
== num
)
10680 /* Utility: parse a tracepoint number and look it up in the list.
10681 If MULTI_P is true, there might be a range of tracepoints in ARG.
10682 if OPTIONAL_P is true, then if the argument is missing, the most
10683 recent tracepoint (tracepoint_count) is returned. */
10684 struct breakpoint
*
10685 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10687 extern int tracepoint_count
;
10688 struct breakpoint
*t
;
10690 char *instring
= arg
== NULL
? NULL
: *arg
;
10692 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10695 tpnum
= tracepoint_count
;
10697 error_no_arg (_("tracepoint number"));
10700 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10704 if (instring
&& *instring
)
10705 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10708 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10712 ALL_TRACEPOINTS (t
)
10713 if (t
->number
== tpnum
)
10718 /* FIXME: if we are in the middle of a range we don't want to give
10719 a message. The current interface to get_number_or_range doesn't
10720 allow us to discover this. */
10721 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10725 /* Save information on user settable breakpoints (watchpoints, etc) to
10726 a new script file named FILENAME. If FILTER is non-NULL, call it
10727 on each breakpoint and only include the ones for which it returns
10731 save_breakpoints (char *filename
, int from_tty
,
10732 int (*filter
) (const struct breakpoint
*))
10734 struct breakpoint
*tp
;
10737 struct cleanup
*cleanup
;
10738 struct ui_file
*fp
;
10739 int extra_trace_bits
= 0;
10741 if (filename
== 0 || *filename
== 0)
10742 error (_("Argument required (file name in which to save)"));
10744 /* See if we have anything to save. */
10745 ALL_BREAKPOINTS (tp
)
10747 /* Skip internal and momentary breakpoints. */
10748 if (!user_settable_breakpoint (tp
))
10751 /* If we have a filter, only save the breakpoints it accepts. */
10752 if (filter
&& !filter (tp
))
10757 if (is_tracepoint (tp
))
10759 extra_trace_bits
= 1;
10761 /* We can stop searching. */
10768 warning (_("Nothing to save."));
10772 pathname
= tilde_expand (filename
);
10773 cleanup
= make_cleanup (xfree
, pathname
);
10774 fp
= gdb_fopen (pathname
, "w");
10776 error (_("Unable to open file '%s' for saving (%s)"),
10777 filename
, safe_strerror (errno
));
10778 make_cleanup_ui_file_delete (fp
);
10780 if (extra_trace_bits
)
10781 save_trace_state_variables (fp
);
10783 ALL_BREAKPOINTS (tp
)
10785 /* Skip internal and momentary breakpoints. */
10786 if (!user_settable_breakpoint (tp
))
10789 /* If we have a filter, only save the breakpoints it accepts. */
10790 if (filter
&& !filter (tp
))
10793 if (tp
->ops
!= NULL
)
10794 (tp
->ops
->print_recreate
) (tp
, fp
);
10797 if (tp
->type
== bp_fast_tracepoint
)
10798 fprintf_unfiltered (fp
, "ftrace");
10799 else if (tp
->type
== bp_tracepoint
)
10800 fprintf_unfiltered (fp
, "trace");
10801 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10802 fprintf_unfiltered (fp
, "tbreak");
10803 else if (tp
->type
== bp_breakpoint
)
10804 fprintf_unfiltered (fp
, "break");
10805 else if (tp
->type
== bp_hardware_breakpoint
10806 && tp
->disposition
== disp_del
)
10807 fprintf_unfiltered (fp
, "thbreak");
10808 else if (tp
->type
== bp_hardware_breakpoint
)
10809 fprintf_unfiltered (fp
, "hbreak");
10810 else if (tp
->type
== bp_watchpoint
)
10811 fprintf_unfiltered (fp
, "watch");
10812 else if (tp
->type
== bp_hardware_watchpoint
)
10813 fprintf_unfiltered (fp
, "watch");
10814 else if (tp
->type
== bp_read_watchpoint
)
10815 fprintf_unfiltered (fp
, "rwatch");
10816 else if (tp
->type
== bp_access_watchpoint
)
10817 fprintf_unfiltered (fp
, "awatch");
10819 internal_error (__FILE__
, __LINE__
,
10820 _("unhandled breakpoint type %d"), (int) tp
->type
);
10822 if (tp
->exp_string
)
10823 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
10824 else if (tp
->addr_string
)
10825 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10830 sprintf_vma (tmp
, tp
->loc
->address
);
10831 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10835 if (tp
->thread
!= -1)
10836 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
10839 fprintf_unfiltered (fp
, " task %d", tp
->task
);
10841 fprintf_unfiltered (fp
, "\n");
10843 /* Note, we can't rely on tp->number for anything, as we can't
10844 assume the recreated breakpoint numbers will match. Use $bpnum
10847 if (tp
->cond_string
)
10848 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
10850 if (tp
->ignore_count
)
10851 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
10853 if (tp
->pass_count
)
10854 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10858 volatile struct gdb_exception ex
;
10860 fprintf_unfiltered (fp
, " commands\n");
10862 ui_out_redirect (uiout
, fp
);
10863 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10865 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10867 ui_out_redirect (uiout
, NULL
);
10870 throw_exception (ex
);
10872 fprintf_unfiltered (fp
, " end\n");
10875 if (tp
->enable_state
== bp_disabled
)
10876 fprintf_unfiltered (fp
, "disable\n");
10878 /* If this is a multi-location breakpoint, check if the locations
10879 should be individually disabled. Watchpoint locations are
10880 special, and not user visible. */
10881 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
10883 struct bp_location
*loc
;
10886 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
10888 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
10892 if (extra_trace_bits
&& *default_collect
)
10893 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10895 do_cleanups (cleanup
);
10897 printf_filtered (_("Saved to file '%s'.\n"), filename
);
10900 /* The `save breakpoints' command. */
10903 save_breakpoints_command (char *args
, int from_tty
)
10905 save_breakpoints (args
, from_tty
, NULL
);
10908 /* The `save tracepoints' command. */
10911 save_tracepoints_command (char *args
, int from_tty
)
10913 save_breakpoints (args
, from_tty
, is_tracepoint
);
10916 /* Create a vector of all tracepoints. */
10918 VEC(breakpoint_p
) *
10921 VEC(breakpoint_p
) *tp_vec
= 0;
10922 struct breakpoint
*tp
;
10924 ALL_TRACEPOINTS (tp
)
10926 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10933 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10934 It is defined as a macro to prevent duplication.
10935 COMMAND should be a string constant containing the name of the command. */
10936 #define BREAK_ARGS_HELP(command) \
10937 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10938 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10939 If a line number is specified, break at start of code for that line.\n\
10940 If a function is specified, break at start of code for that function.\n\
10941 If an address is specified, break at that exact address.\n\
10942 With no LOCATION, uses current execution address of selected stack frame.\n\
10943 This is useful for breaking on return to a stack frame.\n\
10945 THREADNUM is the number from \"info threads\".\n\
10946 CONDITION is a boolean expression.\n\
10948 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10950 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10952 /* List of subcommands for "catch". */
10953 static struct cmd_list_element
*catch_cmdlist
;
10955 /* List of subcommands for "tcatch". */
10956 static struct cmd_list_element
*tcatch_cmdlist
;
10958 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10959 lists, and pass some additional user data to the command function. */
10961 add_catch_command (char *name
, char *docstring
,
10962 void (*sfunc
) (char *args
, int from_tty
,
10963 struct cmd_list_element
*command
),
10964 char **(*completer
) (struct cmd_list_element
*cmd
,
10965 char *text
, char *word
),
10966 void *user_data_catch
,
10967 void *user_data_tcatch
)
10969 struct cmd_list_element
*command
;
10971 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10973 set_cmd_sfunc (command
, sfunc
);
10974 set_cmd_context (command
, user_data_catch
);
10975 set_cmd_completer (command
, completer
);
10977 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10979 set_cmd_sfunc (command
, sfunc
);
10980 set_cmd_context (command
, user_data_tcatch
);
10981 set_cmd_completer (command
, completer
);
10985 clear_syscall_counts (struct inferior
*inf
)
10987 inf
->total_syscalls_count
= 0;
10988 inf
->any_syscall_count
= 0;
10989 VEC_free (int, inf
->syscalls_counts
);
10993 save_command (char *arg
, int from_tty
)
10995 printf_unfiltered (_("\
10996 \"save\" must be followed by the name of a save subcommand.\n"));
10997 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11001 _initialize_breakpoint (void)
11003 struct cmd_list_element
*c
;
11005 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11006 observer_attach_inferior_exit (clear_syscall_counts
);
11007 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11009 breakpoint_chain
= 0;
11010 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11011 before a breakpoint is set. */
11012 breakpoint_count
= 0;
11014 tracepoint_count
= 0;
11016 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11017 Set ignore-count of breakpoint number N to COUNT.\n\
11018 Usage is `ignore N COUNT'."));
11020 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11022 add_com ("commands", class_breakpoint
, commands_command
, _("\
11023 Set commands to be executed when a breakpoint is hit.\n\
11024 Give breakpoint number as argument after \"commands\".\n\
11025 With no argument, the targeted breakpoint is the last one set.\n\
11026 The commands themselves follow starting on the next line.\n\
11027 Type a line containing \"end\" to indicate the end of them.\n\
11028 Give \"silent\" as the first line to make the breakpoint silent;\n\
11029 then no output is printed when it is hit, except what the commands print."));
11031 add_com ("condition", class_breakpoint
, condition_command
, _("\
11032 Specify breakpoint number N to break only if COND is true.\n\
11033 Usage is `condition N COND', where N is an integer and COND is an\n\
11034 expression to be evaluated whenever breakpoint N is reached."));
11036 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11037 Set a temporary breakpoint.\n\
11038 Like \"break\" except the breakpoint is only temporary,\n\
11039 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11040 by using \"enable delete\" on the breakpoint number.\n\
11042 BREAK_ARGS_HELP ("tbreak")));
11043 set_cmd_completer (c
, location_completer
);
11045 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11046 Set a hardware assisted breakpoint.\n\
11047 Like \"break\" except the breakpoint requires hardware support,\n\
11048 some target hardware may not have this support.\n\
11050 BREAK_ARGS_HELP ("hbreak")));
11051 set_cmd_completer (c
, location_completer
);
11053 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11054 Set a temporary hardware assisted breakpoint.\n\
11055 Like \"hbreak\" except the breakpoint is only temporary,\n\
11056 so it will be deleted when hit.\n\
11058 BREAK_ARGS_HELP ("thbreak")));
11059 set_cmd_completer (c
, location_completer
);
11061 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11062 Enable some breakpoints.\n\
11063 Give breakpoint numbers (separated by spaces) as arguments.\n\
11064 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11065 This is used to cancel the effect of the \"disable\" command.\n\
11066 With a subcommand you can enable temporarily."),
11067 &enablelist
, "enable ", 1, &cmdlist
);
11069 add_com ("ab", class_breakpoint
, enable_command
, _("\
11070 Enable some breakpoints.\n\
11071 Give breakpoint numbers (separated by spaces) as arguments.\n\
11072 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11073 This is used to cancel the effect of the \"disable\" command.\n\
11074 With a subcommand you can enable temporarily."));
11076 add_com_alias ("en", "enable", class_breakpoint
, 1);
11078 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11079 Enable some breakpoints.\n\
11080 Give breakpoint numbers (separated by spaces) as arguments.\n\
11081 This is used to cancel the effect of the \"disable\" command.\n\
11082 May be abbreviated to simply \"enable\".\n"),
11083 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11085 add_cmd ("once", no_class
, enable_once_command
, _("\
11086 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11087 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11090 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11091 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11092 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11095 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11096 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11097 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11100 add_cmd ("once", no_class
, enable_once_command
, _("\
11101 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11102 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11105 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
11106 Disable some breakpoints.\n\
11107 Arguments are breakpoint numbers with spaces in between.\n\
11108 To disable all breakpoints, give no argument.\n\
11109 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11110 &disablelist
, "disable ", 1, &cmdlist
);
11111 add_com_alias ("dis", "disable", class_breakpoint
, 1);
11112 add_com_alias ("disa", "disable", class_breakpoint
, 1);
11114 add_com ("sb", class_breakpoint
, disable_command
, _("\
11115 Disable some breakpoints.\n\
11116 Arguments are breakpoint numbers with spaces in between.\n\
11117 To disable all breakpoints, give no argument.\n\
11118 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11120 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
11121 Disable some breakpoints.\n\
11122 Arguments are breakpoint numbers with spaces in between.\n\
11123 To disable all breakpoints, give no argument.\n\
11124 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11125 This command may be abbreviated \"disable\"."),
11128 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
11129 Delete some breakpoints or auto-display expressions.\n\
11130 Arguments are breakpoint numbers with spaces in between.\n\
11131 To delete all breakpoints, give no argument.\n\
11133 Also a prefix command for deletion of other GDB objects.\n\
11134 The \"unset\" command is also an alias for \"delete\"."),
11135 &deletelist
, "delete ", 1, &cmdlist
);
11136 add_com_alias ("d", "delete", class_breakpoint
, 1);
11137 add_com_alias ("del", "delete", class_breakpoint
, 1);
11139 add_com ("db", class_breakpoint
, delete_command
, _("\
11140 Delete some breakpoints.\n\
11141 Arguments are breakpoint numbers with spaces in between.\n\
11142 To delete all breakpoints, give no argument.\n"));
11144 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
11145 Delete some breakpoints or auto-display expressions.\n\
11146 Arguments are breakpoint numbers with spaces in between.\n\
11147 To delete all breakpoints, give no argument.\n\
11148 This command may be abbreviated \"delete\"."),
11151 add_com ("clear", class_breakpoint
, clear_command
, _("\
11152 Clear breakpoint at specified line or function.\n\
11153 Argument may be line number, function name, or \"*\" and an address.\n\
11154 If line number is specified, all breakpoints in that line are cleared.\n\
11155 If function is specified, breakpoints at beginning of function are cleared.\n\
11156 If an address is specified, breakpoints at that address are cleared.\n\
11158 With no argument, clears all breakpoints in the line that the selected frame\n\
11159 is executing in.\n\
11161 See also the \"delete\" command which clears breakpoints by number."));
11163 c
= add_com ("break", class_breakpoint
, break_command
, _("\
11164 Set breakpoint at specified line or function.\n"
11165 BREAK_ARGS_HELP ("break")));
11166 set_cmd_completer (c
, location_completer
);
11168 add_com_alias ("b", "break", class_run
, 1);
11169 add_com_alias ("br", "break", class_run
, 1);
11170 add_com_alias ("bre", "break", class_run
, 1);
11171 add_com_alias ("brea", "break", class_run
, 1);
11174 add_com_alias ("ba", "break", class_breakpoint
, 1);
11178 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
11179 Break in function/address or break at a line in the current file."),
11180 &stoplist
, "stop ", 1, &cmdlist
);
11181 add_cmd ("in", class_breakpoint
, stopin_command
,
11182 _("Break in function or address."), &stoplist
);
11183 add_cmd ("at", class_breakpoint
, stopat_command
,
11184 _("Break at a line in the current file."), &stoplist
);
11185 add_com ("status", class_info
, breakpoints_info
, _("\
11186 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11187 The \"Type\" column indicates one of:\n\
11188 \tbreakpoint - normal breakpoint\n\
11189 \twatchpoint - watchpoint\n\
11190 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11191 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11192 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11193 address and file/line number respectively.\n\
11195 Convenience variable \"$_\" and default examine address for \"x\"\n\
11196 are set to the address of the last breakpoint listed unless the command\n\
11197 is prefixed with \"server \".\n\n\
11198 Convenience variable \"$bpnum\" contains the number of the last\n\
11199 breakpoint set."));
11202 add_info ("breakpoints", breakpoints_info
, _("\
11203 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11204 The \"Type\" column indicates one of:\n\
11205 \tbreakpoint - normal breakpoint\n\
11206 \twatchpoint - watchpoint\n\
11207 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11208 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11209 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11210 address and file/line number respectively.\n\
11212 Convenience variable \"$_\" and default examine address for \"x\"\n\
11213 are set to the address of the last breakpoint listed unless the command\n\
11214 is prefixed with \"server \".\n\n\
11215 Convenience variable \"$bpnum\" contains the number of the last\n\
11216 breakpoint set."));
11218 add_info_alias ("b", "breakpoints", 1);
11221 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11222 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11223 The \"Type\" column indicates one of:\n\
11224 \tbreakpoint - normal breakpoint\n\
11225 \twatchpoint - watchpoint\n\
11226 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11227 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11228 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11229 address and file/line number respectively.\n\
11231 Convenience variable \"$_\" and default examine address for \"x\"\n\
11232 are set to the address of the last breakpoint listed unless the command\n\
11233 is prefixed with \"server \".\n\n\
11234 Convenience variable \"$bpnum\" contains the number of the last\n\
11235 breakpoint set."));
11237 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11238 Status of all breakpoints, or breakpoint number NUMBER.\n\
11239 The \"Type\" column indicates one of:\n\
11240 \tbreakpoint - normal breakpoint\n\
11241 \twatchpoint - watchpoint\n\
11242 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11243 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11244 \tuntil - internal breakpoint used by the \"until\" command\n\
11245 \tfinish - internal breakpoint used by the \"finish\" command\n\
11246 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11247 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11248 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11249 address and file/line number respectively.\n\
11251 Convenience variable \"$_\" and default examine address for \"x\"\n\
11252 are set to the address of the last breakpoint listed unless the command\n\
11253 is prefixed with \"server \".\n\n\
11254 Convenience variable \"$bpnum\" contains the number of the last\n\
11256 &maintenanceinfolist
);
11258 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11259 Set catchpoints to catch events."),
11260 &catch_cmdlist
, "catch ",
11261 0/*allow-unknown*/, &cmdlist
);
11263 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11264 Set temporary catchpoints to catch events."),
11265 &tcatch_cmdlist
, "tcatch ",
11266 0/*allow-unknown*/, &cmdlist
);
11268 /* Add catch and tcatch sub-commands. */
11269 add_catch_command ("catch", _("\
11270 Catch an exception, when caught.\n\
11271 With an argument, catch only exceptions with the given name."),
11272 catch_catch_command
,
11276 add_catch_command ("throw", _("\
11277 Catch an exception, when thrown.\n\
11278 With an argument, catch only exceptions with the given name."),
11279 catch_throw_command
,
11283 add_catch_command ("fork", _("Catch calls to fork."),
11284 catch_fork_command_1
,
11286 (void *) (uintptr_t) catch_fork_permanent
,
11287 (void *) (uintptr_t) catch_fork_temporary
);
11288 add_catch_command ("vfork", _("Catch calls to vfork."),
11289 catch_fork_command_1
,
11291 (void *) (uintptr_t) catch_vfork_permanent
,
11292 (void *) (uintptr_t) catch_vfork_temporary
);
11293 add_catch_command ("exec", _("Catch calls to exec."),
11294 catch_exec_command_1
,
11298 add_catch_command ("syscall", _("\
11299 Catch system calls by their names and/or numbers.\n\
11300 Arguments say which system calls to catch. If no arguments\n\
11301 are given, every system call will be caught.\n\
11302 Arguments, if given, should be one or more system call names\n\
11303 (if your system supports that), or system call numbers."),
11304 catch_syscall_command_1
,
11305 catch_syscall_completer
,
11308 add_catch_command ("exception", _("\
11309 Catch Ada exceptions, when raised.\n\
11310 With an argument, catch only exceptions with the given name."),
11311 catch_ada_exception_command
,
11315 add_catch_command ("assert", _("\
11316 Catch failed Ada assertions, when raised.\n\
11317 With an argument, catch only exceptions with the given name."),
11318 catch_assert_command
,
11323 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11324 Set a watchpoint for an expression.\n\
11325 A watchpoint stops execution of your program whenever the value of\n\
11326 an expression changes."));
11327 set_cmd_completer (c
, expression_completer
);
11329 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11330 Set a read watchpoint for an expression.\n\
11331 A watchpoint stops execution of your program whenever the value of\n\
11332 an expression is read."));
11333 set_cmd_completer (c
, expression_completer
);
11335 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11336 Set a watchpoint for an expression.\n\
11337 A watchpoint stops execution of your program whenever the value of\n\
11338 an expression is either read or written."));
11339 set_cmd_completer (c
, expression_completer
);
11341 add_info ("watchpoints", watchpoints_info
, _("\
11342 Status of watchpoints, or watchpoint number NUMBER."));
11346 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11347 respond to changes - contrary to the description. */
11348 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11349 &can_use_hw_watchpoints
, _("\
11350 Set debugger's willingness to use watchpoint hardware."), _("\
11351 Show debugger's willingness to use watchpoint hardware."), _("\
11352 If zero, gdb will not use hardware for new watchpoints, even if\n\
11353 such is available. (However, any hardware watchpoints that were\n\
11354 created before setting this to nonzero, will continue to use watchpoint\n\
11357 show_can_use_hw_watchpoints
,
11358 &setlist
, &showlist
);
11360 can_use_hw_watchpoints
= 1;
11362 /* Tracepoint manipulation commands. */
11364 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11365 Set a tracepoint at specified line or function.\n\
11367 BREAK_ARGS_HELP ("trace") "\n\
11368 Do \"help tracepoints\" for info on other tracepoint commands."));
11369 set_cmd_completer (c
, location_completer
);
11371 add_com_alias ("tp", "trace", class_alias
, 0);
11372 add_com_alias ("tr", "trace", class_alias
, 1);
11373 add_com_alias ("tra", "trace", class_alias
, 1);
11374 add_com_alias ("trac", "trace", class_alias
, 1);
11376 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11377 Set a fast tracepoint at specified line or function.\n\
11379 BREAK_ARGS_HELP ("ftrace") "\n\
11380 Do \"help tracepoints\" for info on other tracepoint commands."));
11381 set_cmd_completer (c
, location_completer
);
11383 add_info ("tracepoints", tracepoints_info
, _("\
11384 Status of tracepoints, or tracepoint number NUMBER.\n\
11385 Convenience variable \"$tpnum\" contains the number of the\n\
11386 last tracepoint set."));
11388 add_info_alias ("tp", "tracepoints", 1);
11390 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11391 Delete specified tracepoints.\n\
11392 Arguments are tracepoint numbers, separated by spaces.\n\
11393 No argument means delete all tracepoints."),
11396 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11397 Disable specified tracepoints.\n\
11398 Arguments are tracepoint numbers, separated by spaces.\n\
11399 No argument means disable all tracepoints."),
11401 deprecate_cmd (c
, "disable");
11403 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11404 Enable specified tracepoints.\n\
11405 Arguments are tracepoint numbers, separated by spaces.\n\
11406 No argument means enable all tracepoints."),
11408 deprecate_cmd (c
, "enable");
11410 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11411 Set the passcount for a tracepoint.\n\
11412 The trace will end when the tracepoint has been passed 'count' times.\n\
11413 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11414 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11416 add_prefix_cmd ("save", class_breakpoint
, save_command
,
11417 _("Save breakpoint definitions as a script."),
11418 &save_cmdlist
, "save ",
11419 0/*allow-unknown*/, &cmdlist
);
11421 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
11422 Save current breakpoint definitions as a script.\n\
11423 This includes all types of breakpoints (breakpoints, watchpoints, \n\
11424 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11425 session to restore them."),
11427 set_cmd_completer (c
, filename_completer
);
11429 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
11430 Save current tracepoint definitions as a script.\n\
11431 Use the 'source' command in another debug session to restore them."),
11433 set_cmd_completer (c
, filename_completer
);
11435 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
11436 deprecate_cmd (c
, "save tracepoints");
11438 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11439 Breakpoint specific settings\n\
11440 Configure various breakpoint-specific variables such as\n\
11441 pending breakpoint behavior"),
11442 &breakpoint_set_cmdlist
, "set breakpoint ",
11443 0/*allow-unknown*/, &setlist
);
11444 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11445 Breakpoint specific settings\n\
11446 Configure various breakpoint-specific variables such as\n\
11447 pending breakpoint behavior"),
11448 &breakpoint_show_cmdlist
, "show breakpoint ",
11449 0/*allow-unknown*/, &showlist
);
11451 add_setshow_auto_boolean_cmd ("pending", no_class
,
11452 &pending_break_support
, _("\
11453 Set debugger's behavior regarding pending breakpoints."), _("\
11454 Show debugger's behavior regarding pending breakpoints."), _("\
11455 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11456 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11457 an error. If auto, an unrecognized breakpoint location results in a\n\
11458 user-query to see if a pending breakpoint should be created."),
11460 show_pending_break_support
,
11461 &breakpoint_set_cmdlist
,
11462 &breakpoint_show_cmdlist
);
11464 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11466 add_setshow_boolean_cmd ("auto-hw", no_class
,
11467 &automatic_hardware_breakpoints
, _("\
11468 Set automatic usage of hardware breakpoints."), _("\
11469 Show automatic usage of hardware breakpoints."), _("\
11470 If set, the debugger will automatically use hardware breakpoints for\n\
11471 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11472 a warning will be emitted for such breakpoints."),
11474 show_automatic_hardware_breakpoints
,
11475 &breakpoint_set_cmdlist
,
11476 &breakpoint_show_cmdlist
);
11478 add_setshow_enum_cmd ("always-inserted", class_support
,
11479 always_inserted_enums
, &always_inserted_mode
, _("\
11480 Set mode for inserting breakpoints."), _("\
11481 Show mode for inserting breakpoints."), _("\
11482 When this mode is off, breakpoints are inserted in inferior when it is\n\
11483 resumed, and removed when execution stops. When this mode is on,\n\
11484 breakpoints are inserted immediately and removed only when the user\n\
11485 deletes the breakpoint. When this mode is auto (which is the default),\n\
11486 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11487 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11488 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11489 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11491 &show_always_inserted_mode
,
11492 &breakpoint_set_cmdlist
,
11493 &breakpoint_show_cmdlist
);
11495 automatic_hardware_breakpoints
= 1;
11497 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);