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"};
256 return bpdisps
[(int) disp
];
259 /* Prototypes for exported functions. */
260 /* If FALSE, gdb will not use hardware support for watchpoints, even
261 if such is available. */
262 static int can_use_hw_watchpoints
;
265 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
,
269 fprintf_filtered (file
, _("\
270 Debugger's willingness to use watchpoint hardware is %s.\n"),
274 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
275 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
276 for unrecognized breakpoint locations.
277 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
278 static enum auto_boolean pending_break_support
;
280 show_pending_break_support (struct ui_file
*file
, int from_tty
,
281 struct cmd_list_element
*c
,
284 fprintf_filtered (file
, _("\
285 Debugger's behavior regarding pending breakpoints is %s.\n"),
289 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
290 set with "break" but falling in read-only memory.
291 If 0, gdb will warn about such breakpoints, but won't automatically
292 use hardware breakpoints. */
293 static int automatic_hardware_breakpoints
;
295 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
,
299 fprintf_filtered (file
, _("\
300 Automatic usage of hardware breakpoints is %s.\n"),
304 /* If on, gdb will keep breakpoints inserted even as inferior is
305 stopped, and immediately insert any new breakpoints. If off, gdb
306 will insert breakpoints into inferior only when resuming it, and
307 will remove breakpoints upon stop. If auto, GDB will behave as ON
308 if in non-stop mode, and as OFF if all-stop mode.*/
310 static const char always_inserted_auto
[] = "auto";
311 static const char always_inserted_on
[] = "on";
312 static const char always_inserted_off
[] = "off";
313 static const char *always_inserted_enums
[] = {
314 always_inserted_auto
,
319 static const char *always_inserted_mode
= always_inserted_auto
;
321 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
322 struct cmd_list_element
*c
, const char *value
)
324 if (always_inserted_mode
== always_inserted_auto
)
325 fprintf_filtered (file
, _("\
326 Always inserted breakpoint mode is %s (currently %s).\n"),
328 breakpoints_always_inserted_mode () ? "on" : "off");
330 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
334 breakpoints_always_inserted_mode (void)
336 return (always_inserted_mode
== always_inserted_on
337 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
340 void _initialize_breakpoint (void);
342 /* Are we executing breakpoint commands? */
343 static int executing_breakpoint_commands
;
345 /* Are overlay event breakpoints enabled? */
346 static int overlay_events_enabled
;
348 /* Walk the following statement or block through all breakpoints.
349 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
352 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
354 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
355 for (B = breakpoint_chain; \
356 B ? (TMP=B->next, 1): 0; \
359 /* Similar iterator for the low-level breakpoints. SAFE variant is not
360 provided so update_global_location_list must not be called while executing
361 the block of ALL_BP_LOCATIONS. */
363 #define ALL_BP_LOCATIONS(B,BP_TMP) \
364 for (BP_TMP = bp_location; \
365 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
368 /* Iterator for tracepoints only. */
370 #define ALL_TRACEPOINTS(B) \
371 for (B = breakpoint_chain; B; B = B->next) \
372 if (is_tracepoint (B))
374 /* Chains of all breakpoints defined. */
376 struct breakpoint
*breakpoint_chain
;
378 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
380 static struct bp_location
**bp_location
;
382 /* Number of elements of BP_LOCATION. */
384 static unsigned bp_location_count
;
386 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
387 for the current elements of BP_LOCATION which get a valid result from
388 bp_location_has_shadow. You can use it for roughly limiting the subrange of
389 BP_LOCATION to scan for shadow bytes for an address you need to read. */
391 static CORE_ADDR bp_location_placed_address_before_address_max
;
393 /* Maximum offset plus alignment between
394 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
395 the current elements of BP_LOCATION which get a valid result from
396 bp_location_has_shadow. You can use it for roughly limiting the subrange of
397 BP_LOCATION to scan for shadow bytes for an address you need to read. */
399 static CORE_ADDR bp_location_shadow_len_after_address_max
;
401 /* The locations that no longer correspond to any breakpoint,
402 unlinked from bp_location array, but for which a hit
403 may still be reported by a target. */
404 VEC(bp_location_p
) *moribund_locations
= NULL
;
406 /* Number of last breakpoint made. */
408 static int breakpoint_count
;
410 /* The value of `breakpoint_count' before the last command that
411 created breakpoints. If the last (break-like) command created more
412 than one breakpoint, then the difference between BREAKPOINT_COUNT
413 and PREV_BREAKPOINT_COUNT is more than one. */
414 static int prev_breakpoint_count
;
416 /* Number of last tracepoint made. */
418 static int tracepoint_count
;
420 static struct cmd_list_element
*breakpoint_set_cmdlist
;
421 static struct cmd_list_element
*breakpoint_show_cmdlist
;
422 static struct cmd_list_element
*save_cmdlist
;
424 /* Return whether a breakpoint is an active enabled breakpoint. */
426 breakpoint_enabled (struct breakpoint
*b
)
428 return (b
->enable_state
== bp_enabled
);
431 /* Set breakpoint count to NUM. */
434 set_breakpoint_count (int num
)
436 prev_breakpoint_count
= breakpoint_count
;
437 breakpoint_count
= num
;
438 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
441 /* Used by `start_rbreak_breakpoints' below, to record the current
442 breakpoint count before "rbreak" creates any breakpoint. */
443 static int rbreak_start_breakpoint_count
;
445 /* Called at the start an "rbreak" command to record the first
449 start_rbreak_breakpoints (void)
451 rbreak_start_breakpoint_count
= breakpoint_count
;
454 /* Called at the end of an "rbreak" command to record the last
458 end_rbreak_breakpoints (void)
460 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
463 /* Used in run_command to zero the hit count when a new run starts. */
466 clear_breakpoint_hit_counts (void)
468 struct breakpoint
*b
;
474 /* Allocate a new counted_command_line with reference count of 1.
475 The new structure owns COMMANDS. */
477 static struct counted_command_line
*
478 alloc_counted_command_line (struct command_line
*commands
)
480 struct counted_command_line
*result
481 = xmalloc (sizeof (struct counted_command_line
));
484 result
->commands
= commands
;
488 /* Increment reference count. This does nothing if CMD is NULL. */
491 incref_counted_command_line (struct counted_command_line
*cmd
)
497 /* Decrement reference count. If the reference count reaches 0,
498 destroy the counted_command_line. Sets *CMDP to NULL. This does
499 nothing if *CMDP is NULL. */
502 decref_counted_command_line (struct counted_command_line
**cmdp
)
506 if (--(*cmdp
)->refc
== 0)
508 free_command_lines (&(*cmdp
)->commands
);
515 /* A cleanup function that calls decref_counted_command_line. */
518 do_cleanup_counted_command_line (void *arg
)
520 decref_counted_command_line (arg
);
523 /* Create a cleanup that calls decref_counted_command_line on the
526 static struct cleanup
*
527 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
529 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
532 /* Default address, symtab and line to put a breakpoint at
533 for "break" command with no arg.
534 if default_breakpoint_valid is zero, the other three are
535 not valid, and "break" with no arg is an error.
537 This set by print_stack_frame, which calls set_default_breakpoint. */
539 int default_breakpoint_valid
;
540 CORE_ADDR default_breakpoint_address
;
541 struct symtab
*default_breakpoint_symtab
;
542 int default_breakpoint_line
;
543 struct program_space
*default_breakpoint_pspace
;
546 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
547 Advance *PP after the string and any trailing whitespace.
549 Currently the string can either be a number or "$" followed by the name
550 of a convenience variable. Making it an expression wouldn't work well
551 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
553 If the string is a NULL pointer, that denotes the last breakpoint.
555 TRAILER is a character which can be found after the number; most
556 commonly this is `-'. If you don't want a trailer, use \0. */
558 get_number_trailer (char **pp
, int trailer
)
560 int retval
= 0; /* default */
564 /* Empty line means refer to the last breakpoint. */
565 return breakpoint_count
;
568 /* Make a copy of the name, so we can null-terminate it
569 to pass to lookup_internalvar(). */
574 while (isalnum (*p
) || *p
== '_')
576 varname
= (char *) alloca (p
- start
+ 1);
577 strncpy (varname
, start
, p
- start
);
578 varname
[p
- start
] = '\0';
579 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
583 printf_filtered (_("Convenience variable must have integer value.\n"));
591 while (*p
>= '0' && *p
<= '9')
594 /* There is no number here. (e.g. "cond a == b"). */
596 /* Skip non-numeric token */
597 while (*p
&& !isspace((int) *p
))
599 /* Return zero, which caller must interpret as error. */
605 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
607 /* Trailing junk: return 0 and let caller print error msg. */
608 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
619 /* Like get_number_trailer, but don't allow a trailer. */
621 get_number (char **pp
)
623 return get_number_trailer (pp
, '\0');
626 /* Parse a number or a range.
627 * A number will be of the form handled by get_number.
628 * A range will be of the form <number1> - <number2>, and
629 * will represent all the integers between number1 and number2,
632 * While processing a range, this fuction is called iteratively;
633 * At each call it will return the next value in the range.
635 * At the beginning of parsing a range, the char pointer PP will
636 * be advanced past <number1> and left pointing at the '-' token.
637 * Subsequent calls will not advance the pointer until the range
638 * is completed. The call that completes the range will advance
639 * pointer PP past <number2>.
643 get_number_or_range (char **pp
)
645 static int last_retval
, end_value
;
646 static char *end_ptr
;
647 static int in_range
= 0;
651 /* Default case: pp is pointing either to a solo number,
652 or to the first number of a range. */
653 last_retval
= get_number_trailer (pp
, '-');
658 /* This is the start of a range (<number1> - <number2>).
659 Skip the '-', parse and remember the second number,
660 and also remember the end of the final token. */
664 while (isspace ((int) *end_ptr
))
665 end_ptr
++; /* skip white space */
666 end_value
= get_number (temp
);
667 if (end_value
< last_retval
)
669 error (_("inverted range"));
671 else if (end_value
== last_retval
)
673 /* degenerate range (number1 == number2). Advance the
674 token pointer so that the range will be treated as a
683 error (_("negative value"));
686 /* pp points to the '-' that betokens a range. All
687 number-parsing has already been done. Return the next
688 integer value (one greater than the saved previous value).
689 Do not advance the token pointer 'pp' until the end of range
692 if (++last_retval
== end_value
)
694 /* End of range reached; advance token pointer. */
702 /* Return the breakpoint with the specified number, or NULL
703 if the number does not refer to an existing breakpoint. */
706 get_breakpoint (int num
)
708 struct breakpoint
*b
;
711 if (b
->number
== num
)
720 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
723 struct bp_location
*loc
= b
->loc
;
725 for (; loc
; loc
= loc
->next
)
730 xfree (b
->cond_string
);
731 b
->cond_string
= NULL
;
738 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
744 /* I don't know if it matters whether this is the string the user
745 typed in or the decompiled expression. */
746 b
->cond_string
= xstrdup (arg
);
747 b
->condition_not_parsed
= 0;
749 if (is_watchpoint (b
))
751 innermost_block
= NULL
;
753 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
755 error (_("Junk at end of expression"));
756 b
->cond_exp_valid_block
= innermost_block
;
760 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
764 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
766 error (_("Junk at end of expression"));
770 breakpoints_changed ();
771 observer_notify_breakpoint_modified (b
->number
);
774 /* condition N EXP -- set break condition of breakpoint N to EXP. */
777 condition_command (char *arg
, int from_tty
)
779 struct breakpoint
*b
;
784 error_no_arg (_("breakpoint number"));
787 bnum
= get_number (&p
);
789 error (_("Bad breakpoint argument: '%s'"), arg
);
792 if (b
->number
== bnum
)
794 set_breakpoint_condition (b
, p
, from_tty
);
798 error (_("No breakpoint number %d."), bnum
);
801 /* Check that COMMAND do not contain commands that are suitable
802 only for tracepoints and not suitable for ordinary breakpoints.
803 Throw if any such commands is found.
806 check_no_tracepoint_commands (struct command_line
*commands
)
808 struct command_line
*c
;
810 for (c
= commands
; c
; c
= c
->next
)
814 if (c
->control_type
== while_stepping_control
)
815 error (_("The 'while-stepping' command can only be used for tracepoints"));
817 for (i
= 0; i
< c
->body_count
; ++i
)
818 check_no_tracepoint_commands ((c
->body_list
)[i
]);
820 /* Not that command parsing removes leading whitespace and comment
821 lines and also empty lines. So, we only need to check for
823 if (strstr (c
->line
, "collect ") == c
->line
)
824 error (_("The 'collect' command can only be used for tracepoints"));
826 if (strstr (c
->line
, "teval ") == c
->line
)
827 error (_("The 'teval' command can only be used for tracepoints"));
831 /* Encapsulate tests for different types of tracepoints. */
834 is_tracepoint (const struct breakpoint
*b
)
836 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
839 /* A helper function that validsates that COMMANDS are valid for a
840 breakpoint. This function will throw an exception if a problem is
844 validate_commands_for_breakpoint (struct breakpoint
*b
,
845 struct command_line
*commands
)
847 if (is_tracepoint (b
))
849 /* We need to verify that each top-level element of commands
850 is valid for tracepoints, that there's at most one while-stepping
851 element, and that while-stepping's body has valid tracing commands
852 excluding nested while-stepping. */
853 struct command_line
*c
;
854 struct command_line
*while_stepping
= 0;
855 for (c
= commands
; c
; c
= c
->next
)
857 if (c
->control_type
== while_stepping_control
)
859 if (b
->type
== bp_fast_tracepoint
)
860 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
863 error (_("The 'while-stepping' command can be used only once"));
870 struct command_line
*c2
;
872 gdb_assert (while_stepping
->body_count
== 1);
873 c2
= while_stepping
->body_list
[0];
874 for (; c2
; c2
= c2
->next
)
876 if (c2
->control_type
== while_stepping_control
)
877 error (_("The 'while-stepping' command cannot be nested"));
883 check_no_tracepoint_commands (commands
);
887 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
888 validate that only allowed commands are included.
892 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
894 validate_commands_for_breakpoint (b
, commands
);
896 decref_counted_command_line (&b
->commands
);
897 b
->commands
= alloc_counted_command_line (commands
);
898 breakpoints_changed ();
899 observer_notify_breakpoint_modified (b
->number
);
903 check_tracepoint_command (char *line
, void *closure
)
905 struct breakpoint
*b
= closure
;
907 validate_actionline (&line
, b
);
910 /* A structure used to pass information through
911 map_breakpoint_numbers. */
915 /* True if the command was typed at a tty. */
918 /* The breakpoint range spec. */
921 /* Non-NULL if the body of the commands are being read from this
922 already-parsed command. */
923 struct command_line
*control
;
925 /* The command lines read from the user, or NULL if they have not
927 struct counted_command_line
*cmd
;
930 /* A callback for map_breakpoint_numbers that sets the commands for
934 do_map_commands_command (struct breakpoint
*b
, void *data
)
936 struct commands_info
*info
= data
;
938 if (info
->cmd
== NULL
)
940 struct command_line
*l
;
942 if (info
->control
!= NULL
)
943 l
= copy_command_lines (info
->control
->body_list
[0]);
946 struct cleanup
*old_chain
;
949 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
952 old_chain
= make_cleanup (xfree
, str
);
954 l
= read_command_lines (str
,
957 ? check_tracepoint_command
: 0),
960 do_cleanups (old_chain
);
963 info
->cmd
= alloc_counted_command_line (l
);
966 /* If a breakpoint was on the list more than once, we don't need to
968 if (b
->commands
!= info
->cmd
)
970 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
971 incref_counted_command_line (info
->cmd
);
972 decref_counted_command_line (&b
->commands
);
973 b
->commands
= info
->cmd
;
974 breakpoints_changed ();
975 observer_notify_breakpoint_modified (b
->number
);
980 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
982 struct cleanup
*cleanups
;
983 struct commands_info info
;
985 info
.from_tty
= from_tty
;
986 info
.control
= control
;
988 /* If we read command lines from the user, then `info' will hold an
989 extra reference to the commands that we must clean up. */
990 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
992 if (arg
== NULL
|| !*arg
)
994 if (breakpoint_count
- prev_breakpoint_count
> 1)
995 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
996 else if (breakpoint_count
> 0)
997 arg
= xstrprintf ("%d", breakpoint_count
);
1000 /* So that we don't try to free the incoming non-NULL
1001 argument in the cleanup below. Mapping breakpoint
1002 numbers will fail in this case. */
1007 /* The command loop has some static state, so we need to preserve
1009 arg
= xstrdup (arg
);
1012 make_cleanup (xfree
, arg
);
1016 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1018 if (info
.cmd
== NULL
)
1019 error (_("No breakpoints specified."));
1021 do_cleanups (cleanups
);
1025 commands_command (char *arg
, int from_tty
)
1027 commands_command_1 (arg
, from_tty
, NULL
);
1030 /* Like commands_command, but instead of reading the commands from
1031 input stream, takes them from an already parsed command structure.
1033 This is used by cli-script.c to DTRT with breakpoint commands
1034 that are part of if and while bodies. */
1035 enum command_control_type
1036 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1038 commands_command_1 (arg
, 0, cmd
);
1039 return simple_control
;
1042 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1045 bp_location_has_shadow (struct bp_location
*bl
)
1047 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1051 if (bl
->target_info
.shadow_len
== 0)
1052 /* bp isn't valid, or doesn't shadow memory. */
1057 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1058 by replacing any memory breakpoints with their shadowed contents.
1060 The range of shadowed area by each bp_location is:
1061 b->address - bp_location_placed_address_before_address_max
1062 up to b->address + bp_location_shadow_len_after_address_max
1063 The range we were requested to resolve shadows for is:
1064 memaddr ... memaddr + len
1065 Thus the safe cutoff boundaries for performance optimization are
1066 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1068 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1071 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1073 /* Left boundary, right boundary and median element of our binary search. */
1074 unsigned bc_l
, bc_r
, bc
;
1076 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1077 safe to report lower value but a failure to report higher one. */
1080 bc_r
= bp_location_count
;
1081 while (bc_l
+ 1 < bc_r
)
1083 struct bp_location
*b
;
1085 bc
= (bc_l
+ bc_r
) / 2;
1086 b
= bp_location
[bc
];
1088 /* Check first B->ADDRESS will not overflow due to the added constant.
1089 Then advance the left boundary only if we are sure the BC element can
1090 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1092 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1093 we cannot miss a breakpoint with its shadow range tail still reaching
1096 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1097 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1103 /* Now do full processing of the found relevant range of elements. */
1105 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1107 struct bp_location
*b
= bp_location
[bc
];
1108 CORE_ADDR bp_addr
= 0;
1112 if (b
->owner
->type
== bp_none
)
1113 warning (_("reading through apparently deleted breakpoint #%d?"),
1116 /* Performance optimization: any futher element can no longer affect BUF
1119 if (b
->address
>= bp_location_placed_address_before_address_max
1120 && memaddr
+ len
<= b
->address
1121 - bp_location_placed_address_before_address_max
)
1124 if (!bp_location_has_shadow (b
))
1126 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1127 current_program_space
->aspace
, 0))
1130 /* Addresses and length of the part of the breakpoint that
1132 bp_addr
= b
->target_info
.placed_address
;
1133 bp_size
= b
->target_info
.shadow_len
;
1135 if (bp_addr
+ bp_size
<= memaddr
)
1136 /* The breakpoint is entirely before the chunk of memory we
1140 if (bp_addr
>= memaddr
+ len
)
1141 /* The breakpoint is entirely after the chunk of memory we are
1145 /* Offset within shadow_contents. */
1146 if (bp_addr
< memaddr
)
1148 /* Only copy the second part of the breakpoint. */
1149 bp_size
-= memaddr
- bp_addr
;
1150 bptoffset
= memaddr
- bp_addr
;
1154 if (bp_addr
+ bp_size
> memaddr
+ len
)
1156 /* Only copy the first part of the breakpoint. */
1157 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1160 memcpy (buf
+ bp_addr
- memaddr
,
1161 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1166 /* A wrapper function for inserting catchpoints. */
1168 insert_catchpoint (struct ui_out
*uo
, void *args
)
1170 struct breakpoint
*b
= (struct breakpoint
*) args
;
1172 gdb_assert (b
->type
== bp_catchpoint
);
1173 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1178 /* Return true if BPT is of any hardware watchpoint kind. */
1181 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1183 return (bpt
->type
== bp_hardware_watchpoint
1184 || bpt
->type
== bp_read_watchpoint
1185 || bpt
->type
== bp_access_watchpoint
);
1188 /* Return true if BPT is of any watchpoint kind, hardware or
1192 is_watchpoint (const struct breakpoint
*bpt
)
1194 return (is_hardware_watchpoint (bpt
)
1195 || bpt
->type
== bp_watchpoint
);
1198 /* Find the current value of a watchpoint on EXP. Return the value in
1199 *VALP and *RESULTP and the chain of intermediate and final values
1200 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1203 If a memory error occurs while evaluating the expression, *RESULTP will
1204 be set to NULL. *RESULTP may be a lazy value, if the result could
1205 not be read from memory. It is used to determine whether a value
1206 is user-specified (we should watch the whole value) or intermediate
1207 (we should watch only the bit used to locate the final value).
1209 If the final value, or any intermediate value, could not be read
1210 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1211 set to any referenced values. *VALP will never be a lazy value.
1212 This is the value which we store in struct breakpoint.
1214 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1215 value chain. The caller must free the values individually. If
1216 VAL_CHAIN is NULL, all generated values will be left on the value
1220 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1221 struct value
**resultp
, struct value
**val_chain
)
1223 struct value
*mark
, *new_mark
, *result
;
1224 volatile struct gdb_exception ex
;
1232 /* Evaluate the expression. */
1233 mark
= value_mark ();
1236 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1238 result
= evaluate_expression (exp
);
1242 /* Ignore memory errors, we want watchpoints pointing at
1243 inaccessible memory to still be created; otherwise, throw the
1244 error to some higher catcher. */
1250 throw_exception (ex
);
1255 new_mark
= value_mark ();
1256 if (mark
== new_mark
)
1261 /* Make sure it's not lazy, so that after the target stops again we
1262 have a non-lazy previous value to compare with. */
1264 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1269 /* Return the chain of intermediate values. We use this to
1270 decide which addresses to watch. */
1271 *val_chain
= new_mark
;
1272 value_release_to_mark (mark
);
1276 /* Assuming that B is a watchpoint: returns true if the current thread
1277 and its running state are safe to evaluate or update watchpoint B.
1278 Watchpoints on local expressions need to be evaluated in the
1279 context of the thread that was current when the watchpoint was
1280 created, and, that thread needs to be stopped to be able to select
1281 the correct frame context. Watchpoints on global expressions can
1282 be evaluated on any thread, and in any state. It is presently left
1283 to the target allowing memory accesses when threads are
1287 watchpoint_in_thread_scope (struct breakpoint
*b
)
1289 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1290 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1291 && !is_executing (inferior_ptid
)));
1294 /* Assuming that B is a watchpoint:
1295 - Reparse watchpoint expression, if REPARSE is non-zero
1296 - Evaluate expression and store the result in B->val
1297 - Evaluate the condition if there is one, and store the result
1299 - Update the list of values that must be watched in B->loc.
1301 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1302 If this is local watchpoint that is out of scope, delete it.
1304 Even with `set breakpoint always-inserted on' the watchpoints are removed
1305 + inserted on each stop here. Normal breakpoints must never be removed
1306 because they might be missed by a running thread when debugging in non-stop
1307 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1308 processed here) are specific to each LWP since they are stored in each LWP's
1309 hardware debug registers. Therefore, such LWP must be stopped first in
1310 order to be able to modify its hardware watchpoints.
1312 Hardware watchpoints must be reset exactly once after being presented to the
1313 user. It cannot be done sooner, because it would reset the data used to
1314 present the watchpoint hit to the user. And it must not be done later
1315 because it could display the same single watchpoint hit during multiple GDB
1316 stops. Note that the latter is relevant only to the hardware watchpoint
1317 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1318 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1319 memory content has not changed.
1321 The following constraints influence the location where we can reset hardware
1324 * target_stopped_by_watchpoint and target_stopped_data_address are called
1325 several times when GDB stops.
1328 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1329 stop. GDB only presents one hardware watchpoint hit at a time as the
1330 reason for stopping, and all the other hits are presented later, one after
1331 the other, each time the user requests the execution to be resumed.
1332 Execution is not resumed for the threads still having pending hit event
1333 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1334 the inferior on the first stop the thread hit event is kept being reported
1335 from its cached value by linux_nat_stopped_data_address until the real
1336 thread resume happens after the watchpoint gets presented and thus its
1337 LWP_INFO->STATUS gets reset.
1339 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1340 removal from inferior. */
1343 update_watchpoint (struct breakpoint
*b
, int reparse
)
1345 int within_current_scope
;
1346 struct frame_id saved_frame_id
;
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
)
1648 enum bp_loc_type new_type
;
1650 if (mr
->attrib
.mode
!= MEM_RW
)
1651 new_type
= bp_loc_hardware_breakpoint
;
1653 new_type
= bp_loc_software_breakpoint
;
1655 if (new_type
!= bpt
->loc_type
)
1657 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 if (!should_be_inserted (b
) || b
->inserted
)
1942 /* There is no point inserting thread-specific breakpoints if the
1943 thread no longer exists. */
1944 if (b
->owner
->thread
!= -1
1945 && !valid_thread_id (b
->owner
->thread
))
1948 switch_to_program_space_and_thread (b
->pspace
);
1950 /* For targets that support global breakpoints, there's no need
1951 to select an inferior to insert breakpoint to. In fact, even
1952 if we aren't attached to any process yet, we should still
1953 insert breakpoints. */
1954 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1955 && ptid_equal (inferior_ptid
, null_ptid
))
1958 val
= insert_bp_location (b
, tmp_error_stream
,
1960 &hw_breakpoint_error
);
1965 /* If we failed to insert all locations of a watchpoint,
1966 remove them, as half-inserted watchpoint is of limited use. */
1967 ALL_BREAKPOINTS (bpt
)
1969 int some_failed
= 0;
1970 struct bp_location
*loc
;
1972 if (!is_hardware_watchpoint (bpt
))
1975 if (!breakpoint_enabled (bpt
))
1978 if (bpt
->disposition
== disp_del_at_next_stop
)
1981 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1982 if (!loc
->inserted
&& should_be_inserted (loc
))
1989 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1991 remove_breakpoint (loc
, mark_uninserted
);
1993 hw_breakpoint_error
= 1;
1994 fprintf_unfiltered (tmp_error_stream
,
1995 "Could not insert hardware watchpoint %d.\n",
2003 /* If a hardware breakpoint or watchpoint was inserted, add a
2004 message about possibly exhausted resources. */
2005 if (hw_breakpoint_error
)
2007 fprintf_unfiltered (tmp_error_stream
,
2008 "Could not insert hardware breakpoints:\n\
2009 You may have requested too many hardware breakpoints/watchpoints.\n");
2011 target_terminal_ours_for_output ();
2012 error_stream (tmp_error_stream
);
2015 do_cleanups (cleanups
);
2019 remove_breakpoints (void)
2021 struct bp_location
*b
, **bp_tmp
;
2024 ALL_BP_LOCATIONS (b
, bp_tmp
)
2027 val
|= remove_breakpoint (b
, mark_uninserted
);
2032 /* Remove breakpoints of process PID. */
2035 remove_breakpoints_pid (int pid
)
2037 struct bp_location
*b
, **b_tmp
;
2039 struct inferior
*inf
= find_inferior_pid (pid
);
2041 ALL_BP_LOCATIONS (b
, b_tmp
)
2043 if (b
->pspace
!= inf
->pspace
)
2048 val
= remove_breakpoint (b
, mark_uninserted
);
2057 remove_hw_watchpoints (void)
2059 struct bp_location
*b
, **bp_tmp
;
2062 ALL_BP_LOCATIONS (b
, bp_tmp
)
2064 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2065 val
|= remove_breakpoint (b
, mark_uninserted
);
2071 reattach_breakpoints (int pid
)
2073 struct cleanup
*old_chain
;
2074 struct bp_location
*b
, **bp_tmp
;
2076 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2077 int dummy1
= 0, dummy2
= 0;
2078 struct inferior
*inf
;
2079 struct thread_info
*tp
;
2081 tp
= any_live_thread_of_process (pid
);
2085 inf
= find_inferior_pid (pid
);
2086 old_chain
= save_inferior_ptid ();
2088 inferior_ptid
= tp
->ptid
;
2090 make_cleanup_ui_file_delete (tmp_error_stream
);
2092 ALL_BP_LOCATIONS (b
, bp_tmp
)
2094 if (b
->pspace
!= inf
->pspace
)
2100 val
= insert_bp_location (b
, tmp_error_stream
,
2104 do_cleanups (old_chain
);
2109 do_cleanups (old_chain
);
2113 static int internal_breakpoint_number
= -1;
2115 static struct breakpoint
*
2116 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2117 CORE_ADDR address
, enum bptype type
)
2119 struct symtab_and_line sal
;
2120 struct breakpoint
*b
;
2122 init_sal (&sal
); /* initialize to zeroes */
2125 sal
.section
= find_pc_overlay (sal
.pc
);
2126 sal
.pspace
= current_program_space
;
2128 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2129 b
->number
= internal_breakpoint_number
--;
2130 b
->disposition
= disp_donttouch
;
2136 create_overlay_event_breakpoint (char *func_name
)
2138 struct objfile
*objfile
;
2140 ALL_OBJFILES (objfile
)
2142 struct breakpoint
*b
;
2143 struct minimal_symbol
*m
;
2145 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2149 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2150 SYMBOL_VALUE_ADDRESS (m
),
2152 b
->addr_string
= xstrdup (func_name
);
2154 if (overlay_debugging
== ovly_auto
)
2156 b
->enable_state
= bp_enabled
;
2157 overlay_events_enabled
= 1;
2161 b
->enable_state
= bp_disabled
;
2162 overlay_events_enabled
= 0;
2165 update_global_location_list (1);
2169 create_longjmp_master_breakpoint (char *func_name
)
2171 struct program_space
*pspace
;
2172 struct objfile
*objfile
;
2173 struct cleanup
*old_chain
;
2175 old_chain
= save_current_program_space ();
2177 ALL_PSPACES (pspace
)
2178 ALL_OBJFILES (objfile
)
2180 struct breakpoint
*b
;
2181 struct minimal_symbol
*m
;
2183 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2186 set_current_program_space (pspace
);
2188 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2192 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2193 SYMBOL_VALUE_ADDRESS (m
),
2195 b
->addr_string
= xstrdup (func_name
);
2196 b
->enable_state
= bp_disabled
;
2198 update_global_location_list (1);
2200 do_cleanups (old_chain
);
2203 /* Create a master std::terminate breakpoint. The actual function
2204 looked for is named FUNC_NAME. */
2206 create_std_terminate_master_breakpoint (const char *func_name
)
2208 struct program_space
*pspace
;
2209 struct objfile
*objfile
;
2210 struct cleanup
*old_chain
;
2212 old_chain
= save_current_program_space ();
2214 ALL_PSPACES (pspace
)
2215 ALL_OBJFILES (objfile
)
2217 struct breakpoint
*b
;
2218 struct minimal_symbol
*m
;
2220 set_current_program_space (pspace
);
2222 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2223 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2224 && MSYMBOL_TYPE (m
) != mst_file_text
))
2227 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2228 SYMBOL_VALUE_ADDRESS (m
),
2229 bp_std_terminate_master
);
2230 b
->addr_string
= xstrdup (func_name
);
2231 b
->enable_state
= bp_disabled
;
2233 update_global_location_list (1);
2235 do_cleanups (old_chain
);
2239 update_breakpoints_after_exec (void)
2241 struct breakpoint
*b
;
2242 struct breakpoint
*temp
;
2243 struct bp_location
*bploc
, **bplocp_tmp
;
2245 /* We're about to delete breakpoints from GDB's lists. If the
2246 INSERTED flag is true, GDB will try to lift the breakpoints by
2247 writing the breakpoints' "shadow contents" back into memory. The
2248 "shadow contents" are NOT valid after an exec, so GDB should not
2249 do that. Instead, the target is responsible from marking
2250 breakpoints out as soon as it detects an exec. We don't do that
2251 here instead, because there may be other attempts to delete
2252 breakpoints after detecting an exec and before reaching here. */
2253 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2254 if (bploc
->pspace
== current_program_space
)
2255 gdb_assert (!bploc
->inserted
);
2257 ALL_BREAKPOINTS_SAFE (b
, temp
)
2259 if (b
->pspace
!= current_program_space
)
2262 /* Solib breakpoints must be explicitly reset after an exec(). */
2263 if (b
->type
== bp_shlib_event
)
2265 delete_breakpoint (b
);
2269 /* JIT breakpoints must be explicitly reset after an exec(). */
2270 if (b
->type
== bp_jit_event
)
2272 delete_breakpoint (b
);
2276 /* Thread event breakpoints must be set anew after an exec(),
2277 as must overlay event and longjmp master breakpoints. */
2278 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2279 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2281 delete_breakpoint (b
);
2285 /* Step-resume breakpoints are meaningless after an exec(). */
2286 if (b
->type
== bp_step_resume
)
2288 delete_breakpoint (b
);
2292 /* Longjmp and longjmp-resume breakpoints are also meaningless
2294 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2296 delete_breakpoint (b
);
2300 if (b
->type
== bp_catchpoint
)
2302 /* For now, none of the bp_catchpoint breakpoints need to
2303 do anything at this point. In the future, if some of
2304 the catchpoints need to something, we will need to add
2305 a new method, and call this method from here. */
2309 /* bp_finish is a special case. The only way we ought to be able
2310 to see one of these when an exec() has happened, is if the user
2311 caught a vfork, and then said "finish". Ordinarily a finish just
2312 carries them to the call-site of the current callee, by setting
2313 a temporary bp there and resuming. But in this case, the finish
2314 will carry them entirely through the vfork & exec.
2316 We don't want to allow a bp_finish to remain inserted now. But
2317 we can't safely delete it, 'cause finish_command has a handle to
2318 the bp on a bpstat, and will later want to delete it. There's a
2319 chance (and I've seen it happen) that if we delete the bp_finish
2320 here, that its storage will get reused by the time finish_command
2321 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2322 We really must allow finish_command to delete a bp_finish.
2324 In the absense of a general solution for the "how do we know
2325 it's safe to delete something others may have handles to?"
2326 problem, what we'll do here is just uninsert the bp_finish, and
2327 let finish_command delete it.
2329 (We know the bp_finish is "doomed" in the sense that it's
2330 momentary, and will be deleted as soon as finish_command sees
2331 the inferior stopped. So it doesn't matter that the bp's
2332 address is probably bogus in the new a.out, unlike e.g., the
2333 solib breakpoints.) */
2335 if (b
->type
== bp_finish
)
2340 /* Without a symbolic address, we have little hope of the
2341 pre-exec() address meaning the same thing in the post-exec()
2343 if (b
->addr_string
== NULL
)
2345 delete_breakpoint (b
);
2349 /* FIXME what about longjmp breakpoints? Re-create them here? */
2350 create_overlay_event_breakpoint ("_ovly_debug_event");
2351 create_longjmp_master_breakpoint ("longjmp");
2352 create_longjmp_master_breakpoint ("_longjmp");
2353 create_longjmp_master_breakpoint ("siglongjmp");
2354 create_longjmp_master_breakpoint ("_siglongjmp");
2355 create_std_terminate_master_breakpoint ("std::terminate()");
2359 detach_breakpoints (int pid
)
2361 struct bp_location
*b
, **bp_tmp
;
2363 struct cleanup
*old_chain
= save_inferior_ptid ();
2364 struct inferior
*inf
= current_inferior ();
2366 if (pid
== PIDGET (inferior_ptid
))
2367 error (_("Cannot detach breakpoints of inferior_ptid"));
2369 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2370 inferior_ptid
= pid_to_ptid (pid
);
2371 ALL_BP_LOCATIONS (b
, bp_tmp
)
2373 if (b
->pspace
!= inf
->pspace
)
2377 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2379 do_cleanups (old_chain
);
2383 /* Remove the breakpoint location B from the current address space.
2384 Note that this is used to detach breakpoints from a child fork.
2385 When we get here, the child isn't in the inferior list, and neither
2386 do we have objects to represent its address space --- we should
2387 *not* look at b->pspace->aspace here. */
2390 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2394 if (b
->owner
->enable_state
== bp_permanent
)
2395 /* Permanent breakpoints cannot be inserted or removed. */
2398 /* The type of none suggests that owner is actually deleted.
2399 This should not ever happen. */
2400 gdb_assert (b
->owner
->type
!= bp_none
);
2402 if (b
->loc_type
== bp_loc_software_breakpoint
2403 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2405 /* "Normal" instruction breakpoint: either the standard
2406 trap-instruction bp (bp_breakpoint), or a
2407 bp_hardware_breakpoint. */
2409 /* First check to see if we have to handle an overlay. */
2410 if (overlay_debugging
== ovly_off
2411 || b
->section
== NULL
2412 || !(section_is_overlay (b
->section
)))
2414 /* No overlay handling: just remove the breakpoint. */
2416 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2417 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2419 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2423 /* This breakpoint is in an overlay section.
2424 Did we set a breakpoint at the LMA? */
2425 if (!overlay_events_enabled
)
2427 /* Yes -- overlay event support is not active, so we
2428 should have set a breakpoint at the LMA. Remove it.
2430 /* Ignore any failures: if the LMA is in ROM, we will
2431 have already warned when we failed to insert it. */
2432 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2433 target_remove_hw_breakpoint (b
->gdbarch
,
2434 &b
->overlay_target_info
);
2436 target_remove_breakpoint (b
->gdbarch
,
2437 &b
->overlay_target_info
);
2439 /* Did we set a breakpoint at the VMA?
2440 If so, we will have marked the breakpoint 'inserted'. */
2443 /* Yes -- remove it. Previously we did not bother to
2444 remove the breakpoint if the section had been
2445 unmapped, but let's not rely on that being safe. We
2446 don't know what the overlay manager might do. */
2447 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2448 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2451 /* However, we should remove *software* breakpoints only
2452 if the section is still mapped, or else we overwrite
2453 wrong code with the saved shadow contents. */
2454 else if (section_is_mapped (b
->section
))
2455 val
= target_remove_breakpoint (b
->gdbarch
,
2462 /* No -- not inserted, so no need to remove. No error. */
2467 /* In some cases, we might not be able to remove a breakpoint
2468 in a shared library that has already been removed, but we
2469 have not yet processed the shlib unload event. */
2470 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2475 b
->inserted
= (is
== mark_inserted
);
2477 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2479 b
->inserted
= (is
== mark_inserted
);
2480 val
= target_remove_watchpoint (b
->address
, b
->length
,
2481 b
->watchpoint_type
);
2483 /* Failure to remove any of the hardware watchpoints comes here. */
2484 if ((is
== mark_uninserted
) && (b
->inserted
))
2485 warning (_("Could not remove hardware watchpoint %d."),
2488 else if (b
->owner
->type
== bp_catchpoint
2489 && breakpoint_enabled (b
->owner
)
2492 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2494 val
= b
->owner
->ops
->remove (b
->owner
);
2497 b
->inserted
= (is
== mark_inserted
);
2504 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2507 struct cleanup
*old_chain
;
2509 if (b
->owner
->enable_state
== bp_permanent
)
2510 /* Permanent breakpoints cannot be inserted or removed. */
2513 /* The type of none suggests that owner is actually deleted.
2514 This should not ever happen. */
2515 gdb_assert (b
->owner
->type
!= bp_none
);
2517 old_chain
= save_current_space_and_thread ();
2519 switch_to_program_space_and_thread (b
->pspace
);
2521 ret
= remove_breakpoint_1 (b
, is
);
2523 do_cleanups (old_chain
);
2527 /* Clear the "inserted" flag in all breakpoints. */
2530 mark_breakpoints_out (void)
2532 struct bp_location
*bpt
, **bptp_tmp
;
2534 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2535 if (bpt
->pspace
== current_program_space
)
2539 /* Clear the "inserted" flag in all breakpoints and delete any
2540 breakpoints which should go away between runs of the program.
2542 Plus other such housekeeping that has to be done for breakpoints
2545 Note: this function gets called at the end of a run (by
2546 generic_mourn_inferior) and when a run begins (by
2547 init_wait_for_inferior). */
2552 breakpoint_init_inferior (enum inf_context context
)
2554 struct breakpoint
*b
, *temp
;
2555 struct bp_location
*bpt
, **bptp_tmp
;
2557 struct program_space
*pspace
= current_program_space
;
2559 /* If breakpoint locations are shared across processes, then there's
2561 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2564 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2566 if (bpt
->pspace
== pspace
2567 && bpt
->owner
->enable_state
!= bp_permanent
)
2571 ALL_BREAKPOINTS_SAFE (b
, temp
)
2573 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2580 /* If the call dummy breakpoint is at the entry point it will
2581 cause problems when the inferior is rerun, so we better get
2584 case bp_watchpoint_scope
:
2586 /* Also get rid of scope breakpoints. */
2588 case bp_shlib_event
:
2590 /* Also remove solib event breakpoints. Their addresses may
2591 have changed since the last time we ran the program.
2592 Actually we may now be debugging against different target;
2593 and so the solib backend that installed this breakpoint may
2594 not be used in by the target. E.g.,
2596 (gdb) file prog-linux
2597 (gdb) run # native linux target
2600 (gdb) file prog-win.exe
2601 (gdb) tar rem :9999 # remote Windows gdbserver.
2604 delete_breakpoint (b
);
2608 case bp_hardware_watchpoint
:
2609 case bp_read_watchpoint
:
2610 case bp_access_watchpoint
:
2612 /* Likewise for watchpoints on local expressions. */
2613 if (b
->exp_valid_block
!= NULL
)
2614 delete_breakpoint (b
);
2615 else if (context
== inf_starting
)
2617 /* Reset val field to force reread of starting value
2618 in insert_breakpoints. */
2620 value_free (b
->val
);
2630 /* Get rid of the moribund locations. */
2631 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2632 free_bp_location (bpt
);
2633 VEC_free (bp_location_p
, moribund_locations
);
2636 /* These functions concern about actual breakpoints inserted in the
2637 target --- to e.g. check if we need to do decr_pc adjustment or if
2638 we need to hop over the bkpt --- so we check for address space
2639 match, not program space. */
2641 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2642 exists at PC. It returns ordinary_breakpoint_here if it's an
2643 ordinary breakpoint, or permanent_breakpoint_here if it's a
2644 permanent breakpoint.
2645 - When continuing from a location with an ordinary breakpoint, we
2646 actually single step once before calling insert_breakpoints.
2647 - When continuing from a localion with a permanent breakpoint, we
2648 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2649 the target, to advance the PC past the breakpoint. */
2651 enum breakpoint_here
2652 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2654 struct bp_location
*bpt
, **bptp_tmp
;
2655 int any_breakpoint_here
= 0;
2657 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2659 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2660 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2663 if ((breakpoint_enabled (bpt
->owner
)
2664 || bpt
->owner
->enable_state
== bp_permanent
)
2665 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2668 if (overlay_debugging
2669 && section_is_overlay (bpt
->section
)
2670 && !section_is_mapped (bpt
->section
))
2671 continue; /* unmapped overlay -- can't be a match */
2672 else if (bpt
->owner
->enable_state
== bp_permanent
)
2673 return permanent_breakpoint_here
;
2675 any_breakpoint_here
= 1;
2679 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2682 /* Return true if there's a moribund breakpoint at PC. */
2685 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2687 struct bp_location
*loc
;
2690 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2691 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2698 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2699 inserted using regular breakpoint_chain / bp_location array mechanism.
2700 This does not check for single-step breakpoints, which are
2701 inserted and removed using direct target manipulation. */
2704 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2706 struct bp_location
*bpt
, **bptp_tmp
;
2708 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2710 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2711 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2715 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2718 if (overlay_debugging
2719 && section_is_overlay (bpt
->section
)
2720 && !section_is_mapped (bpt
->section
))
2721 continue; /* unmapped overlay -- can't be a match */
2729 /* Returns non-zero iff there's either regular breakpoint
2730 or a single step breakpoint inserted at PC. */
2733 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2735 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2738 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2744 /* This function returns non-zero iff there is a software breakpoint
2748 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2750 struct bp_location
*bpt
, **bptp_tmp
;
2752 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2754 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2758 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2761 if (overlay_debugging
2762 && section_is_overlay (bpt
->section
)
2763 && !section_is_mapped (bpt
->section
))
2764 continue; /* unmapped overlay -- can't be a match */
2770 /* Also check for software single-step breakpoints. */
2771 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2778 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2779 CORE_ADDR addr
, ULONGEST len
)
2781 struct breakpoint
*bpt
;
2783 ALL_BREAKPOINTS (bpt
)
2785 struct bp_location
*loc
;
2787 if (bpt
->type
!= bp_hardware_watchpoint
2788 && bpt
->type
!= bp_access_watchpoint
)
2791 if (!breakpoint_enabled (bpt
))
2794 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2795 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2799 /* Check for intersection. */
2800 l
= max (loc
->address
, addr
);
2801 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2809 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2810 PC is valid for process/thread PTID. */
2813 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2816 struct bp_location
*bpt
, **bptp_tmp
;
2817 /* The thread and task IDs associated to PTID, computed lazily. */
2821 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2823 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2824 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2827 if (!breakpoint_enabled (bpt
->owner
)
2828 && bpt
->owner
->enable_state
!= bp_permanent
)
2831 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2835 if (bpt
->owner
->thread
!= -1)
2837 /* This is a thread-specific breakpoint. Check that ptid
2838 matches that thread. If thread hasn't been computed yet,
2839 it is now time to do so. */
2841 thread
= pid_to_thread_id (ptid
);
2842 if (bpt
->owner
->thread
!= thread
)
2846 if (bpt
->owner
->task
!= 0)
2848 /* This is a task-specific breakpoint. Check that ptid
2849 matches that task. If task hasn't been computed yet,
2850 it is now time to do so. */
2852 task
= ada_get_task_number (ptid
);
2853 if (bpt
->owner
->task
!= task
)
2857 if (overlay_debugging
2858 && section_is_overlay (bpt
->section
)
2859 && !section_is_mapped (bpt
->section
))
2860 continue; /* unmapped overlay -- can't be a match */
2869 /* bpstat stuff. External routines' interfaces are documented
2873 ep_is_catchpoint (struct breakpoint
*ep
)
2875 return (ep
->type
== bp_catchpoint
);
2879 bpstat_free (bpstat bs
)
2881 if (bs
->old_val
!= NULL
)
2882 value_free (bs
->old_val
);
2883 decref_counted_command_line (&bs
->commands
);
2887 /* Clear a bpstat so that it says we are not at any breakpoint.
2888 Also free any storage that is part of a bpstat. */
2891 bpstat_clear (bpstat
*bsp
)
2908 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2909 is part of the bpstat is copied as well. */
2912 bpstat_copy (bpstat bs
)
2916 bpstat retval
= NULL
;
2921 for (; bs
!= NULL
; bs
= bs
->next
)
2923 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2924 memcpy (tmp
, bs
, sizeof (*tmp
));
2925 incref_counted_command_line (tmp
->commands
);
2926 if (bs
->old_val
!= NULL
)
2928 tmp
->old_val
= value_copy (bs
->old_val
);
2929 release_value (tmp
->old_val
);
2933 /* This is the first thing in the chain. */
2943 /* Find the bpstat associated with this breakpoint */
2946 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2951 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2953 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2959 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2960 at. *BSP upon return is a bpstat which points to the remaining
2961 breakpoints stopped at (but which is not guaranteed to be good for
2962 anything but further calls to bpstat_num).
2963 Return 0 if passed a bpstat which does not indicate any breakpoints.
2964 Return -1 if stopped at a breakpoint that has been deleted since
2966 Return 1 otherwise. */
2969 bpstat_num (bpstat
*bsp
, int *num
)
2971 struct breakpoint
*b
;
2974 return 0; /* No more breakpoint values */
2976 /* We assume we'll never have several bpstats that
2977 correspond to a single breakpoint -- otherwise,
2978 this function might return the same number more
2979 than once and this will look ugly. */
2980 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2981 *bsp
= (*bsp
)->next
;
2983 return -1; /* breakpoint that's been deleted since */
2985 *num
= b
->number
; /* We have its number */
2989 /* Modify BS so that the actions will not be performed. */
2992 bpstat_clear_actions (bpstat bs
)
2994 for (; bs
!= NULL
; bs
= bs
->next
)
2996 decref_counted_command_line (&bs
->commands
);
2997 bs
->commands_left
= NULL
;
2998 if (bs
->old_val
!= NULL
)
3000 value_free (bs
->old_val
);
3006 /* Called when a command is about to proceed the inferior. */
3009 breakpoint_about_to_proceed (void)
3011 if (!ptid_equal (inferior_ptid
, null_ptid
))
3013 struct thread_info
*tp
= inferior_thread ();
3015 /* Allow inferior function calls in breakpoint commands to not
3016 interrupt the command list. When the call finishes
3017 successfully, the inferior will be standing at the same
3018 breakpoint as if nothing happened. */
3023 breakpoint_proceeded
= 1;
3026 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3028 cleanup_executing_breakpoints (void *ignore
)
3030 executing_breakpoint_commands
= 0;
3033 /* Execute all the commands associated with all the breakpoints at this
3034 location. Any of these commands could cause the process to proceed
3035 beyond this point, etc. We look out for such changes by checking
3036 the global "breakpoint_proceeded" after each command.
3038 Returns true if a breakpoint command resumed the inferior. In that
3039 case, it is the caller's responsibility to recall it again with the
3040 bpstat of the current thread. */
3043 bpstat_do_actions_1 (bpstat
*bsp
)
3046 struct cleanup
*old_chain
;
3049 /* Avoid endless recursion if a `source' command is contained
3051 if (executing_breakpoint_commands
)
3054 executing_breakpoint_commands
= 1;
3055 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3057 /* This pointer will iterate over the list of bpstat's. */
3060 breakpoint_proceeded
= 0;
3061 for (; bs
!= NULL
; bs
= bs
->next
)
3063 struct counted_command_line
*ccmd
;
3064 struct command_line
*cmd
;
3065 struct cleanup
*this_cmd_tree_chain
;
3067 /* Take ownership of the BSP's command tree, if it has one.
3069 The command tree could legitimately contain commands like
3070 'step' and 'next', which call clear_proceed_status, which
3071 frees stop_bpstat's command tree. To make sure this doesn't
3072 free the tree we're executing out from under us, we need to
3073 take ownership of the tree ourselves. Since a given bpstat's
3074 commands are only executed once, we don't need to copy it; we
3075 can clear the pointer in the bpstat, and make sure we free
3076 the tree when we're done. */
3077 ccmd
= bs
->commands
;
3078 bs
->commands
= NULL
;
3080 = make_cleanup_decref_counted_command_line (&ccmd
);
3081 cmd
= bs
->commands_left
;
3082 bs
->commands_left
= NULL
;
3086 execute_control_command (cmd
);
3088 if (breakpoint_proceeded
)
3094 /* We can free this command tree now. */
3095 do_cleanups (this_cmd_tree_chain
);
3097 if (breakpoint_proceeded
)
3099 if (target_can_async_p ())
3100 /* If we are in async mode, then the target might be still
3101 running, not stopped at any breakpoint, so nothing for
3102 us to do here -- just return to the event loop. */
3105 /* In sync mode, when execute_control_command returns
3106 we're already standing on the next breakpoint.
3107 Breakpoint commands for that stop were not run, since
3108 execute_command does not run breakpoint commands --
3109 only command_line_handler does, but that one is not
3110 involved in execution of breakpoint commands. So, we
3111 can now execute breakpoint commands. It should be
3112 noted that making execute_command do bpstat actions is
3113 not an option -- in this case we'll have recursive
3114 invocation of bpstat for each breakpoint with a
3115 command, and can easily blow up GDB stack. Instead, we
3116 return true, which will trigger the caller to recall us
3117 with the new stop_bpstat. */
3122 do_cleanups (old_chain
);
3127 bpstat_do_actions (void)
3129 /* Do any commands attached to breakpoint we are stopped at. */
3130 while (!ptid_equal (inferior_ptid
, null_ptid
)
3131 && target_has_execution
3132 && !is_exited (inferior_ptid
)
3133 && !is_executing (inferior_ptid
))
3134 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3135 and only return when it is stopped at the next breakpoint, we
3136 keep doing breakpoint actions until it returns false to
3137 indicate the inferior was not resumed. */
3138 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3142 /* Print out the (old or new) value associated with a watchpoint. */
3145 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3148 fprintf_unfiltered (stream
, _("<unreadable>"));
3151 struct value_print_options opts
;
3152 get_user_print_options (&opts
);
3153 value_print (val
, stream
, &opts
);
3157 /* This is the normal print function for a bpstat. In the future,
3158 much of this logic could (should?) be moved to bpstat_stop_status,
3159 by having it set different print_it values.
3161 Current scheme: When we stop, bpstat_print() is called. It loops
3162 through the bpstat list of things causing this stop, calling the
3163 print_bp_stop_message function on each one. The behavior of the
3164 print_bp_stop_message function depends on the print_it field of
3165 bpstat. If such field so indicates, call this function here.
3167 Return values from this routine (ultimately used by bpstat_print()
3168 and normal_stop() to decide what to do):
3169 PRINT_NOTHING: Means we already printed all we needed to print,
3170 don't print anything else.
3171 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3172 that something to be followed by a location.
3173 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3174 that something to be followed by a location.
3175 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3178 static enum print_stop_action
3179 print_it_typical (bpstat bs
)
3181 struct cleanup
*old_chain
;
3182 struct breakpoint
*b
;
3183 const struct bp_location
*bl
;
3184 struct ui_stream
*stb
;
3186 enum print_stop_action result
;
3188 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3189 which has since been deleted. */
3190 if (bs
->breakpoint_at
== NULL
)
3191 return PRINT_UNKNOWN
;
3192 bl
= bs
->breakpoint_at
;
3195 stb
= ui_out_stream_new (uiout
);
3196 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3201 case bp_hardware_breakpoint
:
3202 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3203 if (bl
->address
!= bl
->requested_address
)
3204 breakpoint_adjustment_warning (bl
->requested_address
,
3207 annotate_breakpoint (b
->number
);
3209 ui_out_text (uiout
, "\nTemporary breakpoint ");
3211 ui_out_text (uiout
, "\nBreakpoint ");
3212 if (ui_out_is_mi_like_p (uiout
))
3214 ui_out_field_string (uiout
, "reason",
3215 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3216 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3218 ui_out_field_int (uiout
, "bkptno", b
->number
);
3219 ui_out_text (uiout
, ", ");
3220 result
= PRINT_SRC_AND_LOC
;
3223 case bp_shlib_event
:
3224 /* Did we stop because the user set the stop_on_solib_events
3225 variable? (If so, we report this as a generic, "Stopped due
3226 to shlib event" message.) */
3227 printf_filtered (_("Stopped due to shared library event\n"));
3228 result
= PRINT_NOTHING
;
3231 case bp_thread_event
:
3232 /* Not sure how we will get here.
3233 GDB should not stop for these breakpoints. */
3234 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3235 result
= PRINT_NOTHING
;
3238 case bp_overlay_event
:
3239 /* By analogy with the thread event, GDB should not stop for these. */
3240 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3241 result
= PRINT_NOTHING
;
3244 case bp_longjmp_master
:
3245 /* These should never be enabled. */
3246 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3247 result
= PRINT_NOTHING
;
3250 case bp_std_terminate_master
:
3251 /* These should never be enabled. */
3252 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3253 result
= PRINT_NOTHING
;
3257 case bp_hardware_watchpoint
:
3258 annotate_watchpoint (b
->number
);
3259 if (ui_out_is_mi_like_p (uiout
))
3262 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3264 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3265 ui_out_text (uiout
, "\nOld value = ");
3266 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3267 ui_out_field_stream (uiout
, "old", stb
);
3268 ui_out_text (uiout
, "\nNew value = ");
3269 watchpoint_value_print (b
->val
, stb
->stream
);
3270 ui_out_field_stream (uiout
, "new", stb
);
3271 ui_out_text (uiout
, "\n");
3272 /* More than one watchpoint may have been triggered. */
3273 result
= PRINT_UNKNOWN
;
3276 case bp_read_watchpoint
:
3277 if (ui_out_is_mi_like_p (uiout
))
3280 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3282 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3283 ui_out_text (uiout
, "\nValue = ");
3284 watchpoint_value_print (b
->val
, stb
->stream
);
3285 ui_out_field_stream (uiout
, "value", stb
);
3286 ui_out_text (uiout
, "\n");
3287 result
= PRINT_UNKNOWN
;
3290 case bp_access_watchpoint
:
3291 if (bs
->old_val
!= NULL
)
3293 annotate_watchpoint (b
->number
);
3294 if (ui_out_is_mi_like_p (uiout
))
3297 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3299 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3300 ui_out_text (uiout
, "\nOld value = ");
3301 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3302 ui_out_field_stream (uiout
, "old", stb
);
3303 ui_out_text (uiout
, "\nNew value = ");
3308 if (ui_out_is_mi_like_p (uiout
))
3311 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3312 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3313 ui_out_text (uiout
, "\nValue = ");
3315 watchpoint_value_print (b
->val
, stb
->stream
);
3316 ui_out_field_stream (uiout
, "new", stb
);
3317 ui_out_text (uiout
, "\n");
3318 result
= PRINT_UNKNOWN
;
3321 /* Fall through, we don't deal with these types of breakpoints
3325 if (ui_out_is_mi_like_p (uiout
))
3328 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3329 result
= PRINT_UNKNOWN
;
3333 if (ui_out_is_mi_like_p (uiout
))
3336 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3337 result
= PRINT_UNKNOWN
;
3342 case bp_longjmp_resume
:
3343 case bp_step_resume
:
3344 case bp_watchpoint_scope
:
3346 case bp_std_terminate
:
3348 case bp_fast_tracepoint
:
3351 result
= PRINT_UNKNOWN
;
3355 do_cleanups (old_chain
);
3359 /* Generic routine for printing messages indicating why we
3360 stopped. The behavior of this function depends on the value
3361 'print_it' in the bpstat structure. Under some circumstances we
3362 may decide not to print anything here and delegate the task to
3365 static enum print_stop_action
3366 print_bp_stop_message (bpstat bs
)
3368 switch (bs
->print_it
)
3371 /* Nothing should be printed for this bpstat entry. */
3372 return PRINT_UNKNOWN
;
3376 /* We still want to print the frame, but we already printed the
3377 relevant messages. */
3378 return PRINT_SRC_AND_LOC
;
3381 case print_it_normal
:
3383 const struct bp_location
*bl
= bs
->breakpoint_at
;
3384 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3386 /* Normal case. Call the breakpoint's print_it method, or
3387 print_it_typical. */
3388 /* FIXME: how breakpoint can ever be NULL here? */
3389 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3390 return b
->ops
->print_it (b
);
3392 return print_it_typical (bs
);
3397 internal_error (__FILE__
, __LINE__
,
3398 _("print_bp_stop_message: unrecognized enum value"));
3403 /* Print a message indicating what happened. This is called from
3404 normal_stop(). The input to this routine is the head of the bpstat
3405 list - a list of the eventpoints that caused this stop. This
3406 routine calls the generic print routine for printing a message
3407 about reasons for stopping. This will print (for example) the
3408 "Breakpoint n," part of the output. The return value of this
3411 PRINT_UNKNOWN: Means we printed nothing
3412 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3413 code to print the location. An example is
3414 "Breakpoint 1, " which should be followed by
3416 PRINT_SRC_ONLY: Means we printed something, but there is no need
3417 to also print the location part of the message.
3418 An example is the catch/throw messages, which
3419 don't require a location appended to the end.
3420 PRINT_NOTHING: We have done some printing and we don't need any
3421 further info to be printed.*/
3423 enum print_stop_action
3424 bpstat_print (bpstat bs
)
3428 /* Maybe another breakpoint in the chain caused us to stop.
3429 (Currently all watchpoints go on the bpstat whether hit or not.
3430 That probably could (should) be changed, provided care is taken
3431 with respect to bpstat_explains_signal). */
3432 for (; bs
; bs
= bs
->next
)
3434 val
= print_bp_stop_message (bs
);
3435 if (val
== PRINT_SRC_ONLY
3436 || val
== PRINT_SRC_AND_LOC
3437 || val
== PRINT_NOTHING
)
3441 /* We reached the end of the chain, or we got a null BS to start
3442 with and nothing was printed. */
3443 return PRINT_UNKNOWN
;
3446 /* Evaluate the expression EXP and return 1 if value is zero.
3447 This is used inside a catch_errors to evaluate the breakpoint condition.
3448 The argument is a "struct expression *" that has been cast to char * to
3449 make it pass through catch_errors. */
3452 breakpoint_cond_eval (void *exp
)
3454 struct value
*mark
= value_mark ();
3455 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3457 value_free_to_mark (mark
);
3461 /* Allocate a new bpstat and chain it to the current one. */
3464 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3468 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3470 bs
->breakpoint_at
= bl
;
3471 /* If the condition is false, etc., don't do the commands. */
3472 bs
->commands
= NULL
;
3473 bs
->commands_left
= NULL
;
3475 bs
->print_it
= print_it_normal
;
3479 /* The target has stopped with waitstatus WS. Check if any hardware
3480 watchpoints have triggered, according to the target. */
3483 watchpoints_triggered (struct target_waitstatus
*ws
)
3485 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3487 struct breakpoint
*b
;
3489 if (!stopped_by_watchpoint
)
3491 /* We were not stopped by a watchpoint. Mark all watchpoints
3492 as not triggered. */
3494 if (is_hardware_watchpoint (b
))
3495 b
->watchpoint_triggered
= watch_triggered_no
;
3500 if (!target_stopped_data_address (¤t_target
, &addr
))
3502 /* We were stopped by a watchpoint, but we don't know where.
3503 Mark all watchpoints as unknown. */
3505 if (is_hardware_watchpoint (b
))
3506 b
->watchpoint_triggered
= watch_triggered_unknown
;
3508 return stopped_by_watchpoint
;
3511 /* The target could report the data address. Mark watchpoints
3512 affected by this data address as triggered, and all others as not
3516 if (is_hardware_watchpoint (b
))
3518 struct bp_location
*loc
;
3520 b
->watchpoint_triggered
= watch_triggered_no
;
3521 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3522 /* Exact match not required. Within range is
3524 if (target_watchpoint_addr_within_range (¤t_target
,
3528 b
->watchpoint_triggered
= watch_triggered_yes
;
3536 /* Possible return values for watchpoint_check (this can't be an enum
3537 because of check_errors). */
3538 /* The watchpoint has been deleted. */
3539 #define WP_DELETED 1
3540 /* The value has changed. */
3541 #define WP_VALUE_CHANGED 2
3542 /* The value has not changed. */
3543 #define WP_VALUE_NOT_CHANGED 3
3544 /* Ignore this watchpoint, no matter if the value changed or not. */
3547 #define BP_TEMPFLAG 1
3548 #define BP_HARDWAREFLAG 2
3550 /* Evaluate watchpoint condition expression and check if its value changed.
3552 P should be a pointer to struct bpstat, but is defined as a void *
3553 in order for this function to be usable with catch_errors. */
3556 watchpoint_check (void *p
)
3558 bpstat bs
= (bpstat
) p
;
3559 struct breakpoint
*b
;
3560 struct frame_info
*fr
;
3561 int within_current_scope
;
3563 b
= bs
->breakpoint_at
->owner
;
3565 /* If this is a local watchpoint, we only want to check if the
3566 watchpoint frame is in scope if the current thread is the thread
3567 that was used to create the watchpoint. */
3568 if (!watchpoint_in_thread_scope (b
))
3571 if (b
->exp_valid_block
== NULL
)
3572 within_current_scope
= 1;
3575 struct frame_info
*frame
= get_current_frame ();
3576 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3577 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3579 /* in_function_epilogue_p() returns a non-zero value if we're still
3580 in the function but the stack frame has already been invalidated.
3581 Since we can't rely on the values of local variables after the
3582 stack has been destroyed, we are treating the watchpoint in that
3583 state as `not changed' without further checking. Don't mark
3584 watchpoints as changed if the current frame is in an epilogue -
3585 even if they are in some other frame, our view of the stack
3586 is likely to be wrong and frame_find_by_id could error out. */
3587 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3590 fr
= frame_find_by_id (b
->watchpoint_frame
);
3591 within_current_scope
= (fr
!= NULL
);
3593 /* If we've gotten confused in the unwinder, we might have
3594 returned a frame that can't describe this variable. */
3595 if (within_current_scope
)
3597 struct symbol
*function
;
3599 function
= get_frame_function (fr
);
3600 if (function
== NULL
3601 || !contained_in (b
->exp_valid_block
,
3602 SYMBOL_BLOCK_VALUE (function
)))
3603 within_current_scope
= 0;
3606 if (within_current_scope
)
3607 /* If we end up stopping, the current frame will get selected
3608 in normal_stop. So this call to select_frame won't affect
3613 if (within_current_scope
)
3615 /* We use value_{,free_to_}mark because it could be a
3616 *long* time before we return to the command level and
3617 call free_all_values. We can't call free_all_values because
3618 we might be in the middle of evaluating a function call. */
3620 struct value
*mark
= value_mark ();
3621 struct value
*new_val
;
3623 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3625 /* We use value_equal_contents instead of value_equal because the latter
3626 coerces an array to a pointer, thus comparing just the address of the
3627 array instead of its contents. This is not what we want. */
3628 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3629 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3631 if (new_val
!= NULL
)
3633 release_value (new_val
);
3634 value_free_to_mark (mark
);
3636 bs
->old_val
= b
->val
;
3639 return WP_VALUE_CHANGED
;
3643 /* Nothing changed. */
3644 value_free_to_mark (mark
);
3645 return WP_VALUE_NOT_CHANGED
;
3650 /* This seems like the only logical thing to do because
3651 if we temporarily ignored the watchpoint, then when
3652 we reenter the block in which it is valid it contains
3653 garbage (in the case of a function, it may have two
3654 garbage values, one before and one after the prologue).
3655 So we can't even detect the first assignment to it and
3656 watch after that (since the garbage may or may not equal
3657 the first value assigned). */
3658 /* We print all the stop information in print_it_typical(), but
3659 in this case, by the time we call print_it_typical() this bp
3660 will be deleted already. So we have no choice but print the
3661 information here. */
3662 if (ui_out_is_mi_like_p (uiout
))
3664 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3665 ui_out_text (uiout
, "\nWatchpoint ");
3666 ui_out_field_int (uiout
, "wpnum", b
->number
);
3667 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3668 which its expression is valid.\n");
3670 if (b
->related_breakpoint
)
3672 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3673 b
->related_breakpoint
->related_breakpoint
= NULL
;
3674 b
->related_breakpoint
= NULL
;
3676 b
->disposition
= disp_del_at_next_stop
;
3682 /* Return true if it looks like target has stopped due to hitting
3683 breakpoint location BL. This function does not check if we
3684 should stop, only if BL explains the stop. */
3686 bpstat_check_location (const struct bp_location
*bl
,
3687 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3689 struct breakpoint
*b
= bl
->owner
;
3691 /* By definition, the inferior does not report stops at
3693 if (is_tracepoint (b
))
3696 if (!is_watchpoint (b
)
3697 && b
->type
!= bp_hardware_breakpoint
3698 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3700 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3703 if (overlay_debugging
/* unmapped overlay section */
3704 && section_is_overlay (bl
->section
)
3705 && !section_is_mapped (bl
->section
))
3709 /* Continuable hardware watchpoints are treated as non-existent if the
3710 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3711 some data address). Otherwise gdb won't stop on a break instruction
3712 in the code (not from a breakpoint) when a hardware watchpoint has
3713 been defined. Also skip watchpoints which we know did not trigger
3714 (did not match the data address). */
3716 if (is_hardware_watchpoint (b
)
3717 && b
->watchpoint_triggered
== watch_triggered_no
)
3720 if (b
->type
== bp_hardware_breakpoint
)
3722 if (bl
->address
!= bp_addr
)
3724 if (overlay_debugging
/* unmapped overlay section */
3725 && section_is_overlay (bl
->section
)
3726 && !section_is_mapped (bl
->section
))
3730 if (b
->type
== bp_catchpoint
)
3732 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3733 if (!b
->ops
->breakpoint_hit (b
))
3740 /* If BS refers to a watchpoint, determine if the watched values
3741 has actually changed, and we should stop. If not, set BS->stop
3744 bpstat_check_watchpoint (bpstat bs
)
3746 const struct bp_location
*bl
= bs
->breakpoint_at
;
3747 struct breakpoint
*b
= bl
->owner
;
3749 if (is_watchpoint (b
))
3751 int must_check_value
= 0;
3753 if (b
->type
== bp_watchpoint
)
3754 /* For a software watchpoint, we must always check the
3756 must_check_value
= 1;
3757 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3758 /* We have a hardware watchpoint (read, write, or access)
3759 and the target earlier reported an address watched by
3761 must_check_value
= 1;
3762 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3763 && b
->type
== bp_hardware_watchpoint
)
3764 /* We were stopped by a hardware watchpoint, but the target could
3765 not report the data address. We must check the watchpoint's
3766 value. Access and read watchpoints are out of luck; without
3767 a data address, we can't figure it out. */
3768 must_check_value
= 1;
3770 if (must_check_value
)
3772 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3774 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3775 int e
= catch_errors (watchpoint_check
, bs
, message
,
3777 do_cleanups (cleanups
);
3781 /* We've already printed what needs to be printed. */
3782 bs
->print_it
= print_it_done
;
3786 bs
->print_it
= print_it_noop
;
3789 case WP_VALUE_CHANGED
:
3790 if (b
->type
== bp_read_watchpoint
)
3792 /* There are two cases to consider here:
3794 1. we're watching the triggered memory for reads.
3795 In that case, trust the target, and always report
3796 the watchpoint hit to the user. Even though
3797 reads don't cause value changes, the value may
3798 have changed since the last time it was read, and
3799 since we're not trapping writes, we will not see
3800 those, and as such we should ignore our notion of
3803 2. we're watching the triggered memory for both
3804 reads and writes. There are two ways this may
3807 2.1. this is a target that can't break on data
3808 reads only, but can break on accesses (reads or
3809 writes), such as e.g., x86. We detect this case
3810 at the time we try to insert read watchpoints.
3812 2.2. otherwise, the target supports read
3813 watchpoints, but, the user set an access or write
3814 watchpoint watching the same memory as this read
3817 If we're watching memory writes as well as reads,
3818 ignore watchpoint hits when we find that the
3819 value hasn't changed, as reads don't cause
3820 changes. This still gives false positives when
3821 the program writes the same value to memory as
3822 what there was already in memory (we will confuse
3823 it for a read), but it's much better than
3826 int other_write_watchpoint
= 0;
3828 if (bl
->watchpoint_type
== hw_read
)
3830 struct breakpoint
*other_b
;
3832 ALL_BREAKPOINTS (other_b
)
3833 if ((other_b
->type
== bp_hardware_watchpoint
3834 || other_b
->type
== bp_access_watchpoint
)
3835 && (other_b
->watchpoint_triggered
3836 == watch_triggered_yes
))
3838 other_write_watchpoint
= 1;
3843 if (other_write_watchpoint
3844 || bl
->watchpoint_type
== hw_access
)
3846 /* We're watching the same memory for writes,
3847 and the value changed since the last time we
3848 updated it, so this trap must be for a write.
3850 bs
->print_it
= print_it_noop
;
3855 case WP_VALUE_NOT_CHANGED
:
3856 if (b
->type
== bp_hardware_watchpoint
3857 || b
->type
== bp_watchpoint
)
3859 /* Don't stop: write watchpoints shouldn't fire if
3860 the value hasn't changed. */
3861 bs
->print_it
= print_it_noop
;
3869 /* Error from catch_errors. */
3870 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3871 if (b
->related_breakpoint
)
3872 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3873 b
->disposition
= disp_del_at_next_stop
;
3874 /* We've already printed what needs to be printed. */
3875 bs
->print_it
= print_it_done
;
3879 else /* must_check_value == 0 */
3881 /* This is a case where some watchpoint(s) triggered, but
3882 not at the address of this watchpoint, or else no
3883 watchpoint triggered after all. So don't print
3884 anything for this watchpoint. */
3885 bs
->print_it
= print_it_noop
;
3892 /* Check conditions (condition proper, frame, thread and ignore count)
3893 of breakpoint referred to by BS. If we should not stop for this
3894 breakpoint, set BS->stop to 0. */
3896 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3898 int thread_id
= pid_to_thread_id (ptid
);
3899 const struct bp_location
*bl
= bs
->breakpoint_at
;
3900 struct breakpoint
*b
= bl
->owner
;
3902 if (frame_id_p (b
->frame_id
)
3903 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3907 int value_is_zero
= 0;
3908 struct expression
*cond
;
3910 /* If this is a scope breakpoint, mark the associated
3911 watchpoint as triggered so that we will handle the
3912 out-of-scope event. We'll get to the watchpoint next
3914 if (b
->type
== bp_watchpoint_scope
)
3915 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3917 if (is_watchpoint (b
))
3922 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3924 int within_current_scope
= 1;
3926 /* We use value_mark and value_free_to_mark because it could
3927 be a long time before we return to the command level and
3928 call free_all_values. We can't call free_all_values
3929 because we might be in the middle of evaluating a
3931 struct value
*mark
= value_mark ();
3933 /* Need to select the frame, with all that implies so that
3934 the conditions will have the right context. Because we
3935 use the frame, we will not see an inlined function's
3936 variables when we arrive at a breakpoint at the start
3937 of the inlined function; the current frame will be the
3939 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3940 select_frame (get_current_frame ());
3943 struct frame_info
*frame
;
3945 /* For local watchpoint expressions, which particular
3946 instance of a local is being watched matters, so we
3947 keep track of the frame to evaluate the expression
3948 in. To evaluate the condition however, it doesn't
3949 really matter which instantiation of the function
3950 where the condition makes sense triggers the
3951 watchpoint. This allows an expression like "watch
3952 global if q > 10" set in `func', catch writes to
3953 global on all threads that call `func', or catch
3954 writes on all recursive calls of `func' by a single
3955 thread. We simply always evaluate the condition in
3956 the innermost frame that's executing where it makes
3957 sense to evaluate the condition. It seems
3959 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3961 select_frame (frame
);
3963 within_current_scope
= 0;
3965 if (within_current_scope
)
3967 = catch_errors (breakpoint_cond_eval
, cond
,
3968 "Error in testing breakpoint condition:\n",
3972 warning (_("Watchpoint condition cannot be tested "
3973 "in the current scope"));
3974 /* If we failed to set the right context for this
3975 watchpoint, unconditionally report it. */
3978 /* FIXME-someday, should give breakpoint # */
3979 value_free_to_mark (mark
);
3982 if (cond
&& value_is_zero
)
3986 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3990 else if (b
->ignore_count
> 0)
3993 annotate_ignore_count_change ();
3995 /* Increase the hit count even though we don't
4003 /* Get a bpstat associated with having just stopped at address
4004 BP_ADDR in thread PTID.
4006 Determine whether we stopped at a breakpoint, etc, or whether we
4007 don't understand this stop. Result is a chain of bpstat's such that:
4009 if we don't understand the stop, the result is a null pointer.
4011 if we understand why we stopped, the result is not null.
4013 Each element of the chain refers to a particular breakpoint or
4014 watchpoint at which we have stopped. (We may have stopped for
4015 several reasons concurrently.)
4017 Each element of the chain has valid next, breakpoint_at,
4018 commands, FIXME??? fields. */
4021 bpstat_stop_status (struct address_space
*aspace
,
4022 CORE_ADDR bp_addr
, ptid_t ptid
)
4024 struct breakpoint
*b
= NULL
;
4025 struct bp_location
*bl
;
4026 struct bp_location
*loc
;
4027 /* Root of the chain of bpstat's */
4028 struct bpstats root_bs
[1];
4029 /* Pointer to the last thing in the chain currently. */
4030 bpstat bs
= root_bs
;
4032 int need_remove_insert
;
4034 /* ALL_BP_LOCATIONS iteration would break across
4035 update_global_location_list possibly executed by
4036 bpstat_check_breakpoint_conditions's inferior call. */
4040 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4043 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4045 /* For hardware watchpoints, we look only at the first location.
4046 The watchpoint_check function will work on the entire expression,
4047 not the individual locations. For read watchpoints, the
4048 watchpoints_triggered function has checked all locations
4050 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4053 if (bl
->shlib_disabled
)
4056 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4059 /* Come here if it's a watchpoint, or if the break address matches */
4061 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4063 /* Assume we stop. Should we find watchpoint that is not actually
4064 triggered, or if condition of breakpoint is false, we'll reset
4069 bpstat_check_watchpoint (bs
);
4073 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4074 || b
->type
== bp_longjmp_master
4075 || b
->type
== bp_std_terminate_master
)
4076 /* We do not stop for these. */
4079 bpstat_check_breakpoint_conditions (bs
, ptid
);
4085 /* We will stop here */
4086 if (b
->disposition
== disp_disable
)
4088 if (b
->enable_state
!= bp_permanent
)
4089 b
->enable_state
= bp_disabled
;
4090 update_global_location_list (0);
4094 bs
->commands
= b
->commands
;
4095 incref_counted_command_line (bs
->commands
);
4096 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4097 if (bs
->commands_left
4098 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4101 bs
->commands_left
->line
) == 0)))
4103 bs
->commands_left
= bs
->commands_left
->next
;
4108 /* Print nothing for this entry if we dont stop or dont print. */
4109 if (bs
->stop
== 0 || bs
->print
== 0)
4110 bs
->print_it
= print_it_noop
;
4114 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4116 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4119 bs
= bpstat_alloc (loc
, bs
);
4120 /* For hits of moribund locations, we should just proceed. */
4123 bs
->print_it
= print_it_noop
;
4127 bs
->next
= NULL
; /* Terminate the chain */
4129 /* If we aren't stopping, the value of some hardware watchpoint may
4130 not have changed, but the intermediate memory locations we are
4131 watching may have. Don't bother if we're stopping; this will get
4133 need_remove_insert
= 0;
4134 if (! bpstat_causes_stop (root_bs
->next
))
4135 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4137 && bs
->breakpoint_at
->owner
4138 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4140 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4141 /* Updating watchpoints invalidates bs->breakpoint_at.
4142 Prevent further code from trying to use it. */
4143 bs
->breakpoint_at
= NULL
;
4144 need_remove_insert
= 1;
4147 if (need_remove_insert
)
4148 update_global_location_list (1);
4150 return root_bs
->next
;
4153 /* Tell what to do about this bpstat. */
4155 bpstat_what (bpstat bs
)
4157 /* Classify each bpstat as one of the following. */
4160 /* This bpstat element has no effect on the main_action. */
4163 /* There was a watchpoint, stop but don't print. */
4166 /* There was a watchpoint, stop and print. */
4169 /* There was a breakpoint but we're not stopping. */
4172 /* There was a breakpoint, stop but don't print. */
4175 /* There was a breakpoint, stop and print. */
4178 /* We hit the longjmp breakpoint. */
4181 /* We hit the longjmp_resume breakpoint. */
4184 /* We hit the step_resume breakpoint. */
4187 /* We hit the shared library event breakpoint. */
4190 /* We hit the jit event breakpoint. */
4193 /* This is just used to count how many enums there are. */
4197 /* Here is the table which drives this routine. So that we can
4198 format it pretty, we define some abbreviations for the
4199 enum bpstat_what codes. */
4200 #define kc BPSTAT_WHAT_KEEP_CHECKING
4201 #define ss BPSTAT_WHAT_STOP_SILENT
4202 #define sn BPSTAT_WHAT_STOP_NOISY
4203 #define sgl BPSTAT_WHAT_SINGLE
4204 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4205 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4206 #define sr BPSTAT_WHAT_STEP_RESUME
4207 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4208 #define jit BPSTAT_WHAT_CHECK_JIT
4210 /* "Can't happen." Might want to print an error message.
4211 abort() is not out of the question, but chances are GDB is just
4212 a bit confused, not unusable. */
4213 #define err BPSTAT_WHAT_STOP_NOISY
4215 /* Given an old action and a class, come up with a new action. */
4216 /* One interesting property of this table is that wp_silent is the same
4217 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4218 after stopping, the check for whether to step over a breakpoint
4219 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4220 reference to how we stopped. We retain separate wp_silent and
4221 bp_silent codes in case we want to change that someday.
4223 Another possibly interesting property of this table is that
4224 there's a partial ordering, priority-like, of the actions. Once
4225 you've decided that some action is appropriate, you'll never go
4226 back and decide something of a lower priority is better. The
4229 kc < jit clr sgl shl slr sn sr ss
4230 sgl < jit shl slr sn sr ss
4231 slr < jit err shl sn sr ss
4232 clr < jit err shl sn sr ss
4239 What I think this means is that we don't need a damned table
4240 here. If you just put the rows and columns in the right order,
4241 it'd look awfully regular. We could simply walk the bpstat list
4242 and choose the highest priority action we find, with a little
4243 logic to handle the 'err' cases. */
4245 /* step_resume entries: a step resume breakpoint overrides another
4246 breakpoint of signal handling (see comment in wait_for_inferior
4247 at where we set the step_resume breakpoint). */
4249 static const enum bpstat_what_main_action
4250 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4253 /* kc ss sn sgl slr clr sr shl jit */
4254 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4255 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4256 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4257 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4258 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4259 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4260 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4261 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4262 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4263 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4264 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4278 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4279 struct bpstat_what retval
;
4281 retval
.call_dummy
= STOP_NONE
;
4282 for (; bs
!= NULL
; bs
= bs
->next
)
4284 enum class bs_class
= no_effect
;
4285 if (bs
->breakpoint_at
== NULL
)
4286 /* I suspect this can happen if it was a momentary breakpoint
4287 which has since been deleted. */
4289 if (bs
->breakpoint_at
->owner
== NULL
)
4290 bs_class
= bp_nostop
;
4292 switch (bs
->breakpoint_at
->owner
->type
)
4298 case bp_hardware_breakpoint
:
4304 bs_class
= bp_noisy
;
4306 bs_class
= bp_silent
;
4309 bs_class
= bp_nostop
;
4312 case bp_hardware_watchpoint
:
4313 case bp_read_watchpoint
:
4314 case bp_access_watchpoint
:
4318 bs_class
= wp_noisy
;
4320 bs_class
= wp_silent
;
4323 /* There was a watchpoint, but we're not stopping.
4324 This requires no further action. */
4325 bs_class
= no_effect
;
4328 bs_class
= long_jump
;
4330 case bp_longjmp_resume
:
4331 bs_class
= long_resume
;
4333 case bp_step_resume
:
4336 bs_class
= step_resume
;
4339 /* It is for the wrong frame. */
4340 bs_class
= bp_nostop
;
4342 case bp_watchpoint_scope
:
4343 bs_class
= bp_nostop
;
4345 case bp_shlib_event
:
4346 bs_class
= shlib_event
;
4349 bs_class
= jit_event
;
4351 case bp_thread_event
:
4352 case bp_overlay_event
:
4353 case bp_longjmp_master
:
4354 case bp_std_terminate_master
:
4355 bs_class
= bp_nostop
;
4361 bs_class
= bp_noisy
;
4363 bs_class
= bp_silent
;
4366 /* There was a catchpoint, but we're not stopping.
4367 This requires no further action. */
4368 bs_class
= no_effect
;
4371 /* Make sure the action is stop (silent or noisy),
4372 so infrun.c pops the dummy frame. */
4373 bs_class
= bp_silent
;
4374 retval
.call_dummy
= STOP_STACK_DUMMY
;
4376 case bp_std_terminate
:
4377 /* Make sure the action is stop (silent or noisy),
4378 so infrun.c pops the dummy frame. */
4379 bs_class
= bp_silent
;
4380 retval
.call_dummy
= STOP_STD_TERMINATE
;
4383 case bp_fast_tracepoint
:
4384 /* Tracepoint hits should not be reported back to GDB, and
4385 if one got through somehow, it should have been filtered
4387 internal_error (__FILE__
, __LINE__
,
4388 _("bpstat_what: tracepoint encountered"));
4391 current_action
= table
[(int) bs_class
][(int) current_action
];
4393 retval
.main_action
= current_action
;
4397 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4398 without hardware support). This isn't related to a specific bpstat,
4399 just to things like whether watchpoints are set. */
4402 bpstat_should_step (void)
4404 struct breakpoint
*b
;
4407 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4413 bpstat_causes_stop (bpstat bs
)
4415 for (; bs
!= NULL
; bs
= bs
->next
)
4424 /* Print the LOC location out of the list of B->LOC locations. */
4426 static void print_breakpoint_location (struct breakpoint
*b
,
4427 struct bp_location
*loc
,
4429 struct ui_stream
*stb
)
4431 struct cleanup
*old_chain
= save_current_program_space ();
4433 if (loc
!= NULL
&& loc
->shlib_disabled
)
4437 set_current_program_space (loc
->pspace
);
4439 if (b
->source_file
&& loc
)
4442 = find_pc_sect_function (loc
->address
, loc
->section
);
4445 ui_out_text (uiout
, "in ");
4446 ui_out_field_string (uiout
, "func",
4447 SYMBOL_PRINT_NAME (sym
));
4448 ui_out_wrap_hint (uiout
, wrap_indent
);
4449 ui_out_text (uiout
, " at ");
4451 ui_out_field_string (uiout
, "file", b
->source_file
);
4452 ui_out_text (uiout
, ":");
4454 if (ui_out_is_mi_like_p (uiout
))
4456 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4457 char *fullname
= symtab_to_fullname (sal
.symtab
);
4460 ui_out_field_string (uiout
, "fullname", fullname
);
4463 ui_out_field_int (uiout
, "line", b
->line_number
);
4467 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4469 ui_out_field_stream (uiout
, "at", stb
);
4472 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4474 do_cleanups (old_chain
);
4477 /* Print B to gdb_stdout. */
4479 print_one_breakpoint_location (struct breakpoint
*b
,
4480 struct bp_location
*loc
,
4482 struct bp_location
**last_loc
,
4483 int print_address_bits
,
4486 struct command_line
*l
;
4487 struct ep_type_description
4492 static struct ep_type_description bptypes
[] =
4494 {bp_none
, "?deleted?"},
4495 {bp_breakpoint
, "breakpoint"},
4496 {bp_hardware_breakpoint
, "hw breakpoint"},
4497 {bp_until
, "until"},
4498 {bp_finish
, "finish"},
4499 {bp_watchpoint
, "watchpoint"},
4500 {bp_hardware_watchpoint
, "hw watchpoint"},
4501 {bp_read_watchpoint
, "read watchpoint"},
4502 {bp_access_watchpoint
, "acc watchpoint"},
4503 {bp_longjmp
, "longjmp"},
4504 {bp_longjmp_resume
, "longjmp resume"},
4505 {bp_step_resume
, "step resume"},
4506 {bp_watchpoint_scope
, "watchpoint scope"},
4507 {bp_call_dummy
, "call dummy"},
4508 {bp_std_terminate
, "std::terminate"},
4509 {bp_shlib_event
, "shlib events"},
4510 {bp_thread_event
, "thread events"},
4511 {bp_overlay_event
, "overlay events"},
4512 {bp_longjmp_master
, "longjmp master"},
4513 {bp_std_terminate_master
, "std::terminate master"},
4514 {bp_catchpoint
, "catchpoint"},
4515 {bp_tracepoint
, "tracepoint"},
4516 {bp_fast_tracepoint
, "fast tracepoint"},
4517 {bp_jit_event
, "jit events"},
4520 static char bpenables
[] = "nynny";
4521 char wrap_indent
[80];
4522 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4523 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4524 struct cleanup
*bkpt_chain
;
4526 int header_of_multiple
= 0;
4527 int part_of_multiple
= (loc
!= NULL
);
4528 struct value_print_options opts
;
4530 get_user_print_options (&opts
);
4532 gdb_assert (!loc
|| loc_number
!= 0);
4533 /* See comment in print_one_breakpoint concerning
4534 treatment of breakpoints with single disabled
4538 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4539 header_of_multiple
= 1;
4544 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4548 if (part_of_multiple
)
4551 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4552 ui_out_field_string (uiout
, "number", formatted
);
4557 ui_out_field_int (uiout
, "number", b
->number
);
4562 if (part_of_multiple
)
4563 ui_out_field_skip (uiout
, "type");
4566 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4567 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4568 internal_error (__FILE__
, __LINE__
,
4569 _("bptypes table does not describe type #%d."),
4571 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4576 if (part_of_multiple
)
4577 ui_out_field_skip (uiout
, "disp");
4579 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4584 if (part_of_multiple
)
4585 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4587 ui_out_field_fmt (uiout
, "enabled", "%c",
4588 bpenables
[(int) b
->enable_state
]);
4589 ui_out_spaces (uiout
, 2);
4593 strcpy (wrap_indent
, " ");
4594 if (opts
.addressprint
)
4596 if (print_address_bits
<= 32)
4597 strcat (wrap_indent
, " ");
4599 strcat (wrap_indent
, " ");
4602 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4604 /* Although the print_one can possibly print
4605 all locations, calling it here is not likely
4606 to get any nice result. So, make sure there's
4607 just one location. */
4608 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4609 b
->ops
->print_one (b
, last_loc
);
4615 internal_error (__FILE__
, __LINE__
,
4616 _("print_one_breakpoint: bp_none encountered\n"));
4620 case bp_hardware_watchpoint
:
4621 case bp_read_watchpoint
:
4622 case bp_access_watchpoint
:
4623 /* Field 4, the address, is omitted (which makes the columns
4624 not line up too nicely with the headers, but the effect
4625 is relatively readable). */
4626 if (opts
.addressprint
)
4627 ui_out_field_skip (uiout
, "addr");
4629 ui_out_field_string (uiout
, "what", b
->exp_string
);
4633 case bp_hardware_breakpoint
:
4637 case bp_longjmp_resume
:
4638 case bp_step_resume
:
4639 case bp_watchpoint_scope
:
4641 case bp_std_terminate
:
4642 case bp_shlib_event
:
4643 case bp_thread_event
:
4644 case bp_overlay_event
:
4645 case bp_longjmp_master
:
4646 case bp_std_terminate_master
:
4648 case bp_fast_tracepoint
:
4650 if (opts
.addressprint
)
4653 if (header_of_multiple
)
4654 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4655 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4656 ui_out_field_string (uiout
, "addr", "<PENDING>");
4658 ui_out_field_core_addr (uiout
, "addr",
4659 loc
->gdbarch
, loc
->address
);
4662 if (!header_of_multiple
)
4663 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4670 /* For backward compatibility, don't display inferiors unless there
4673 && !header_of_multiple
4675 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4676 && (number_of_program_spaces () > 1
4677 || number_of_inferiors () > 1)
4678 && loc
->owner
->type
!= bp_catchpoint
)))
4680 struct inferior
*inf
;
4683 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4685 if (inf
->pspace
== loc
->pspace
)
4690 ui_out_text (uiout
, " inf ");
4693 ui_out_text (uiout
, ", ");
4694 ui_out_text (uiout
, plongest (inf
->num
));
4699 if (!part_of_multiple
)
4701 if (b
->thread
!= -1)
4703 /* FIXME: This seems to be redundant and lost here; see the
4704 "stop only in" line a little further down. */
4705 ui_out_text (uiout
, " thread ");
4706 ui_out_field_int (uiout
, "thread", b
->thread
);
4708 else if (b
->task
!= 0)
4710 ui_out_text (uiout
, " task ");
4711 ui_out_field_int (uiout
, "task", b
->task
);
4715 ui_out_text (uiout
, "\n");
4717 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4720 ui_out_text (uiout
, "\tstop only in stack frame at ");
4721 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4723 ui_out_field_core_addr (uiout
, "frame",
4724 b
->gdbarch
, b
->frame_id
.stack_addr
);
4725 ui_out_text (uiout
, "\n");
4728 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4730 /* We do not print the condition for Ada exception catchpoints
4731 because the condition is an internal implementation detail
4732 that we do not want to expose to the user. */
4734 if (is_tracepoint (b
))
4735 ui_out_text (uiout
, "\ttrace only if ");
4737 ui_out_text (uiout
, "\tstop only if ");
4738 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4739 ui_out_text (uiout
, "\n");
4742 if (!part_of_multiple
&& b
->thread
!= -1)
4744 /* FIXME should make an annotation for this */
4745 ui_out_text (uiout
, "\tstop only in thread ");
4746 ui_out_field_int (uiout
, "thread", b
->thread
);
4747 ui_out_text (uiout
, "\n");
4750 if (!part_of_multiple
&& b
->hit_count
)
4752 /* FIXME should make an annotation for this */
4753 if (ep_is_catchpoint (b
))
4754 ui_out_text (uiout
, "\tcatchpoint");
4756 ui_out_text (uiout
, "\tbreakpoint");
4757 ui_out_text (uiout
, " already hit ");
4758 ui_out_field_int (uiout
, "times", b
->hit_count
);
4759 if (b
->hit_count
== 1)
4760 ui_out_text (uiout
, " time\n");
4762 ui_out_text (uiout
, " times\n");
4765 /* Output the count also if it is zero, but only if this is
4766 mi. FIXME: Should have a better test for this. */
4767 if (ui_out_is_mi_like_p (uiout
))
4768 if (!part_of_multiple
&& b
->hit_count
== 0)
4769 ui_out_field_int (uiout
, "times", b
->hit_count
);
4771 if (!part_of_multiple
&& b
->ignore_count
)
4774 ui_out_text (uiout
, "\tignore next ");
4775 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4776 ui_out_text (uiout
, " hits\n");
4779 l
= b
->commands
? b
->commands
->commands
: NULL
;
4780 if (!part_of_multiple
&& l
)
4782 struct cleanup
*script_chain
;
4785 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4786 print_command_lines (uiout
, l
, 4);
4787 do_cleanups (script_chain
);
4790 if (!part_of_multiple
&& b
->pass_count
)
4792 annotate_field (10);
4793 ui_out_text (uiout
, "\tpass count ");
4794 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4795 ui_out_text (uiout
, " \n");
4798 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4801 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4802 else if (b
->exp_string
)
4803 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4806 do_cleanups (bkpt_chain
);
4807 do_cleanups (old_chain
);
4811 print_one_breakpoint (struct breakpoint
*b
,
4812 struct bp_location
**last_loc
, int print_address_bits
,
4815 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4816 print_address_bits
, allflag
);
4818 /* If this breakpoint has custom print function,
4819 it's already printed. Otherwise, print individual
4820 locations, if any. */
4821 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4823 /* If breakpoint has a single location that is
4824 disabled, we print it as if it had
4825 several locations, since otherwise it's hard to
4826 represent "breakpoint enabled, location disabled"
4828 Note that while hardware watchpoints have
4829 several locations internally, that's no a property
4832 && !is_hardware_watchpoint (b
)
4833 && (b
->loc
->next
|| !b
->loc
->enabled
)
4834 && !ui_out_is_mi_like_p (uiout
))
4836 struct bp_location
*loc
;
4838 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4839 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4840 print_address_bits
, allflag
);
4846 breakpoint_address_bits (struct breakpoint
*b
)
4848 int print_address_bits
= 0;
4849 struct bp_location
*loc
;
4851 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4855 /* Software watchpoints that aren't watching memory don't have
4856 an address to print. */
4857 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4860 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4861 if (addr_bit
> print_address_bits
)
4862 print_address_bits
= addr_bit
;
4865 return print_address_bits
;
4868 struct captured_breakpoint_query_args
4874 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4876 struct captured_breakpoint_query_args
*args
= data
;
4877 struct breakpoint
*b
;
4878 struct bp_location
*dummy_loc
= NULL
;
4882 if (args
->bnum
== b
->number
)
4884 int print_address_bits
= breakpoint_address_bits (b
);
4886 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4894 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4896 struct captured_breakpoint_query_args args
;
4899 /* For the moment we don't trust print_one_breakpoint() to not throw
4901 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4902 error_message
, RETURN_MASK_ALL
) < 0)
4908 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4909 catchpoints, et.al.). */
4912 user_settable_breakpoint (const struct breakpoint
*b
)
4914 return (b
->type
== bp_breakpoint
4915 || b
->type
== bp_catchpoint
4916 || b
->type
== bp_hardware_breakpoint
4917 || is_tracepoint (b
)
4918 || is_watchpoint (b
));
4921 /* Print information on user settable breakpoint (watchpoint, etc)
4922 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4923 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4924 FILTER is non-NULL, call it on each breakpoint and only include the
4925 ones for which it returns non-zero. Return the total number of
4926 breakpoints listed. */
4929 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4931 struct breakpoint
*b
;
4932 struct bp_location
*last_loc
= NULL
;
4933 int nr_printable_breakpoints
;
4934 struct cleanup
*bkpttbl_chain
;
4935 struct value_print_options opts
;
4936 int print_address_bits
= 0;
4938 get_user_print_options (&opts
);
4940 /* Compute the number of rows in the table, as well as the
4941 size required for address fields. */
4942 nr_printable_breakpoints
= 0;
4945 || bnum
== b
->number
)
4947 /* If we have a filter, only list the breakpoints it accepts. */
4948 if (filter
&& !filter (b
))
4951 if (allflag
|| user_settable_breakpoint (b
))
4953 int addr_bit
= breakpoint_address_bits (b
);
4954 if (addr_bit
> print_address_bits
)
4955 print_address_bits
= addr_bit
;
4957 nr_printable_breakpoints
++;
4961 if (opts
.addressprint
)
4963 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4967 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4970 if (nr_printable_breakpoints
> 0)
4971 annotate_breakpoints_headers ();
4972 if (nr_printable_breakpoints
> 0)
4974 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4975 if (nr_printable_breakpoints
> 0)
4977 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4978 if (nr_printable_breakpoints
> 0)
4980 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4981 if (nr_printable_breakpoints
> 0)
4983 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4984 if (opts
.addressprint
)
4986 if (nr_printable_breakpoints
> 0)
4988 if (print_address_bits
<= 32)
4989 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4991 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4993 if (nr_printable_breakpoints
> 0)
4995 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4996 ui_out_table_body (uiout
);
4997 if (nr_printable_breakpoints
> 0)
4998 annotate_breakpoints_table ();
5004 || bnum
== b
->number
)
5006 /* If we have a filter, only list the breakpoints it accepts. */
5007 if (filter
&& !filter (b
))
5010 /* We only print out user settable breakpoints unless the
5012 if (allflag
|| user_settable_breakpoint (b
))
5013 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5017 do_cleanups (bkpttbl_chain
);
5019 if (nr_printable_breakpoints
== 0)
5021 /* If there's a filter, let the caller decide how to report empty list. */
5025 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5027 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5033 if (last_loc
&& !server_command
)
5034 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5037 /* FIXME? Should this be moved up so that it is only called when
5038 there have been breakpoints? */
5039 annotate_breakpoints_table_end ();
5041 return nr_printable_breakpoints
;
5044 /* Display the value of default-collect in a way that is generally
5045 compatible with the breakpoint list. */
5048 default_collect_info (void)
5050 /* If it has no value (which is frequently the case), say nothing; a
5051 message like "No default-collect." gets in user's face when it's
5053 if (!*default_collect
)
5056 /* The following phrase lines up nicely with per-tracepoint collect
5058 ui_out_text (uiout
, "default collect ");
5059 ui_out_field_string (uiout
, "default-collect", default_collect
);
5060 ui_out_text (uiout
, " \n");
5064 breakpoints_info (char *bnum_exp
, int from_tty
)
5069 bnum
= parse_and_eval_long (bnum_exp
);
5071 breakpoint_1 (bnum
, 0, NULL
);
5073 default_collect_info ();
5077 watchpoints_info (char *wpnum_exp
, int from_tty
)
5079 int wpnum
= -1, num_printed
;
5082 wpnum
= parse_and_eval_long (wpnum_exp
);
5084 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5086 if (num_printed
== 0)
5089 ui_out_message (uiout
, 0, "No watchpoints.\n");
5091 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5096 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5101 bnum
= parse_and_eval_long (bnum_exp
);
5103 breakpoint_1 (bnum
, 1, NULL
);
5105 default_collect_info ();
5109 breakpoint_has_pc (struct breakpoint
*b
,
5110 struct program_space
*pspace
,
5111 CORE_ADDR pc
, struct obj_section
*section
)
5113 struct bp_location
*bl
= b
->loc
;
5115 for (; bl
; bl
= bl
->next
)
5117 if (bl
->pspace
== pspace
5118 && bl
->address
== pc
5119 && (!overlay_debugging
|| bl
->section
== section
))
5125 /* Print a message describing any breakpoints set at PC. This
5126 concerns with logical breakpoints, so we match program spaces, not
5130 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5131 struct program_space
*pspace
, CORE_ADDR pc
,
5132 struct obj_section
*section
, int thread
)
5135 struct breakpoint
*b
;
5138 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5142 printf_filtered (_("Note: breakpoint "));
5143 else /* if (others == ???) */
5144 printf_filtered (_("Note: breakpoints "));
5146 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5149 printf_filtered ("%d", b
->number
);
5150 if (b
->thread
== -1 && thread
!= -1)
5151 printf_filtered (" (all threads)");
5152 else if (b
->thread
!= -1)
5153 printf_filtered (" (thread %d)", b
->thread
);
5154 printf_filtered ("%s%s ",
5155 ((b
->enable_state
== bp_disabled
5156 || b
->enable_state
== bp_call_disabled
5157 || b
->enable_state
== bp_startup_disabled
)
5159 : b
->enable_state
== bp_permanent
5163 : ((others
== 1) ? " and" : ""));
5165 printf_filtered (_("also set at pc "));
5166 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5167 printf_filtered (".\n");
5171 /* Set the default place to put a breakpoint
5172 for the `break' command with no arguments. */
5175 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5176 CORE_ADDR addr
, struct symtab
*symtab
,
5179 default_breakpoint_valid
= valid
;
5180 default_breakpoint_pspace
= pspace
;
5181 default_breakpoint_address
= addr
;
5182 default_breakpoint_symtab
= symtab
;
5183 default_breakpoint_line
= line
;
5186 /* Return true iff it is meaningful to use the address member of
5187 BPT. For some breakpoint types, the address member is irrelevant
5188 and it makes no sense to attempt to compare it to other addresses
5189 (or use it for any other purpose either).
5191 More specifically, each of the following breakpoint types will always
5192 have a zero valued address and we don't want to mark breakpoints of any of
5193 these types to be a duplicate of an actual breakpoint at address zero:
5201 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5203 enum bptype type
= bpt
->type
;
5205 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5208 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5209 true if LOC1 and LOC2 represent the same watchpoint location. */
5212 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5214 /* Note that this checks the owner's type, not the location's. In
5215 case the target does not support read watchpoints, but does
5216 support access watchpoints, we'll have bp_read_watchpoint
5217 watchpoints with hw_access locations. Those should be considered
5218 duplicates of hw_read locations. The hw_read locations will
5219 become hw_access locations later. */
5220 return (loc1
->owner
->type
== loc2
->owner
->type
5221 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5222 && loc1
->address
== loc2
->address
5223 && loc1
->length
== loc2
->length
);
5226 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5227 same breakpoint location. In most targets, this can only be true
5228 if ASPACE1 matches ASPACE2. On targets that have global
5229 breakpoints, the address space doesn't really matter. */
5232 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5233 struct address_space
*aspace2
, CORE_ADDR addr2
)
5235 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5236 || aspace1
== aspace2
)
5240 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5241 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5242 represent the same location. */
5245 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5247 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5248 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5250 if (hw_point1
!= hw_point2
)
5253 return watchpoint_locations_match (loc1
, loc2
);
5255 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5256 loc2
->pspace
->aspace
, loc2
->address
);
5260 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5261 int bnum
, int have_bnum
)
5266 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5267 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5269 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5270 bnum
, astr1
, astr2
);
5272 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5275 /* Adjust a breakpoint's address to account for architectural constraints
5276 on breakpoint placement. Return the adjusted address. Note: Very
5277 few targets require this kind of adjustment. For most targets,
5278 this function is simply the identity function. */
5281 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5282 CORE_ADDR bpaddr
, enum bptype bptype
)
5284 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5286 /* Very few targets need any kind of breakpoint adjustment. */
5289 else if (bptype
== bp_watchpoint
5290 || bptype
== bp_hardware_watchpoint
5291 || bptype
== bp_read_watchpoint
5292 || bptype
== bp_access_watchpoint
5293 || bptype
== bp_catchpoint
)
5295 /* Watchpoints and the various bp_catch_* eventpoints should not
5296 have their addresses modified. */
5301 CORE_ADDR adjusted_bpaddr
;
5303 /* Some targets have architectural constraints on the placement
5304 of breakpoint instructions. Obtain the adjusted address. */
5305 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5307 /* An adjusted breakpoint address can significantly alter
5308 a user's expectations. Print a warning if an adjustment
5310 if (adjusted_bpaddr
!= bpaddr
)
5311 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5313 return adjusted_bpaddr
;
5317 /* Allocate a struct bp_location. */
5319 static struct bp_location
*
5320 allocate_bp_location (struct breakpoint
*bpt
)
5322 struct bp_location
*loc
;
5324 loc
= xmalloc (sizeof (struct bp_location
));
5325 memset (loc
, 0, sizeof (*loc
));
5329 loc
->shlib_disabled
= 0;
5338 case bp_longjmp_resume
:
5339 case bp_step_resume
:
5340 case bp_watchpoint_scope
:
5342 case bp_std_terminate
:
5343 case bp_shlib_event
:
5344 case bp_thread_event
:
5345 case bp_overlay_event
:
5347 case bp_longjmp_master
:
5348 case bp_std_terminate_master
:
5349 loc
->loc_type
= bp_loc_software_breakpoint
;
5351 case bp_hardware_breakpoint
:
5352 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5354 case bp_hardware_watchpoint
:
5355 case bp_read_watchpoint
:
5356 case bp_access_watchpoint
:
5357 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5362 case bp_fast_tracepoint
:
5363 loc
->loc_type
= bp_loc_other
;
5366 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5372 static void free_bp_location (struct bp_location
*loc
)
5377 if (loc
->function_name
)
5378 xfree (loc
->function_name
);
5383 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5384 that has type BPTYPE and has no locations as yet. */
5385 /* This function is used in gdbtk sources and thus can not be made static. */
5387 static struct breakpoint
*
5388 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5391 struct breakpoint
*b
, *b1
;
5393 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5394 memset (b
, 0, sizeof (*b
));
5397 b
->gdbarch
= gdbarch
;
5398 b
->language
= current_language
->la_language
;
5399 b
->input_radix
= input_radix
;
5401 b
->enable_state
= bp_enabled
;
5404 b
->ignore_count
= 0;
5406 b
->frame_id
= null_frame_id
;
5407 b
->forked_inferior_pid
= null_ptid
;
5408 b
->exec_pathname
= NULL
;
5409 b
->syscalls_to_be_caught
= NULL
;
5411 b
->condition_not_parsed
= 0;
5413 /* Add this breakpoint to the end of the chain
5414 so that a list of breakpoints will come out in order
5415 of increasing numbers. */
5417 b1
= breakpoint_chain
;
5419 breakpoint_chain
= b
;
5429 /* Initialize loc->function_name. */
5431 set_breakpoint_location_function (struct bp_location
*loc
)
5433 if (loc
->owner
->type
== bp_breakpoint
5434 || loc
->owner
->type
== bp_hardware_breakpoint
5435 || is_tracepoint (loc
->owner
))
5437 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5439 if (loc
->function_name
)
5440 loc
->function_name
= xstrdup (loc
->function_name
);
5444 /* Attempt to determine architecture of location identified by SAL. */
5445 static struct gdbarch
*
5446 get_sal_arch (struct symtab_and_line sal
)
5449 return get_objfile_arch (sal
.section
->objfile
);
5451 return get_objfile_arch (sal
.symtab
->objfile
);
5456 /* set_raw_breakpoint is a low level routine for allocating and
5457 partially initializing a breakpoint of type BPTYPE. The newly
5458 created breakpoint's address, section, source file name, and line
5459 number are provided by SAL. The newly created and partially
5460 initialized breakpoint is added to the breakpoint chain and
5461 is also returned as the value of this function.
5463 It is expected that the caller will complete the initialization of
5464 the newly created breakpoint struct as well as output any status
5465 information regarding the creation of a new breakpoint. In
5466 particular, set_raw_breakpoint does NOT set the breakpoint
5467 number! Care should be taken to not allow an error to occur
5468 prior to completing the initialization of the breakpoint. If this
5469 should happen, a bogus breakpoint will be left on the chain. */
5472 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5473 struct symtab_and_line sal
, enum bptype bptype
)
5475 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5476 CORE_ADDR adjusted_address
;
5477 struct gdbarch
*loc_gdbarch
;
5479 loc_gdbarch
= get_sal_arch (sal
);
5481 loc_gdbarch
= b
->gdbarch
;
5483 if (bptype
!= bp_catchpoint
)
5484 gdb_assert (sal
.pspace
!= NULL
);
5486 /* Adjust the breakpoint's address prior to allocating a location.
5487 Once we call allocate_bp_location(), that mostly uninitialized
5488 location will be placed on the location chain. Adjustment of the
5489 breakpoint may cause target_read_memory() to be called and we do
5490 not want its scan of the location chain to find a breakpoint and
5491 location that's only been partially initialized. */
5492 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5494 b
->loc
= allocate_bp_location (b
);
5495 b
->loc
->gdbarch
= loc_gdbarch
;
5496 b
->loc
->requested_address
= sal
.pc
;
5497 b
->loc
->address
= adjusted_address
;
5498 b
->loc
->pspace
= sal
.pspace
;
5500 /* Store the program space that was used to set the breakpoint, for
5501 breakpoint resetting. */
5502 b
->pspace
= sal
.pspace
;
5504 if (sal
.symtab
== NULL
)
5505 b
->source_file
= NULL
;
5507 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5508 b
->loc
->section
= sal
.section
;
5509 b
->line_number
= sal
.line
;
5511 set_breakpoint_location_function (b
->loc
);
5513 breakpoints_changed ();
5519 /* Note that the breakpoint object B describes a permanent breakpoint
5520 instruction, hard-wired into the inferior's code. */
5522 make_breakpoint_permanent (struct breakpoint
*b
)
5524 struct bp_location
*bl
;
5526 b
->enable_state
= bp_permanent
;
5528 /* By definition, permanent breakpoints are already present in the code.
5529 Mark all locations as inserted. For now, make_breakpoint_permanent
5530 is called in just one place, so it's hard to say if it's reasonable
5531 to have permanent breakpoint with multiple locations or not,
5532 but it's easy to implmement. */
5533 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5537 /* Call this routine when stepping and nexting to enable a breakpoint
5538 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5539 set_longjmp_resume_breakpoint() to figure out where we are going. */
5542 set_longjmp_breakpoint (int thread
)
5544 struct breakpoint
*b
, *temp
;
5546 /* To avoid having to rescan all objfile symbols at every step,
5547 we maintain a list of continually-inserted but always disabled
5548 longjmp "master" breakpoints. Here, we simply create momentary
5549 clones of those and enable them for the requested thread. */
5550 ALL_BREAKPOINTS_SAFE (b
, temp
)
5551 if (b
->pspace
== current_program_space
5552 && b
->type
== bp_longjmp_master
)
5554 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5556 clone
->type
= bp_longjmp
;
5557 clone
->thread
= thread
;
5561 /* Delete all longjmp breakpoints from THREAD. */
5563 delete_longjmp_breakpoint (int thread
)
5565 struct breakpoint
*b
, *temp
;
5567 ALL_BREAKPOINTS_SAFE (b
, temp
)
5568 if (b
->type
== bp_longjmp
)
5570 if (b
->thread
== thread
)
5571 delete_breakpoint (b
);
5576 enable_overlay_breakpoints (void)
5578 struct breakpoint
*b
;
5581 if (b
->type
== bp_overlay_event
)
5583 b
->enable_state
= bp_enabled
;
5584 update_global_location_list (1);
5585 overlay_events_enabled
= 1;
5590 disable_overlay_breakpoints (void)
5592 struct breakpoint
*b
;
5595 if (b
->type
== bp_overlay_event
)
5597 b
->enable_state
= bp_disabled
;
5598 update_global_location_list (0);
5599 overlay_events_enabled
= 0;
5603 /* Set an active std::terminate breakpoint for each std::terminate
5604 master breakpoint. */
5606 set_std_terminate_breakpoint (void)
5608 struct breakpoint
*b
, *temp
;
5610 ALL_BREAKPOINTS_SAFE (b
, temp
)
5611 if (b
->pspace
== current_program_space
5612 && b
->type
== bp_std_terminate_master
)
5614 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5615 clone
->type
= bp_std_terminate
;
5619 /* Delete all the std::terminate breakpoints. */
5621 delete_std_terminate_breakpoint (void)
5623 struct breakpoint
*b
, *temp
;
5625 ALL_BREAKPOINTS_SAFE (b
, temp
)
5626 if (b
->type
== bp_std_terminate
)
5627 delete_breakpoint (b
);
5631 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5633 struct breakpoint
*b
;
5635 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5637 b
->enable_state
= bp_enabled
;
5638 /* addr_string has to be used or breakpoint_re_set will delete me. */
5640 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5642 update_global_location_list_nothrow (1);
5648 remove_thread_event_breakpoints (void)
5650 struct breakpoint
*b
, *temp
;
5652 ALL_BREAKPOINTS_SAFE (b
, temp
)
5653 if (b
->type
== bp_thread_event
5654 && b
->loc
->pspace
== current_program_space
)
5655 delete_breakpoint (b
);
5658 struct captured_parse_breakpoint_args
5661 struct symtabs_and_lines
*sals_p
;
5662 char ***addr_string_p
;
5666 struct lang_and_radix
5672 /* Create a breakpoint for JIT code registration and unregistration. */
5675 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5677 struct breakpoint
*b
;
5679 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5680 update_global_location_list_nothrow (1);
5685 remove_solib_event_breakpoints (void)
5687 struct breakpoint
*b
, *temp
;
5689 ALL_BREAKPOINTS_SAFE (b
, temp
)
5690 if (b
->type
== bp_shlib_event
5691 && b
->loc
->pspace
== current_program_space
)
5692 delete_breakpoint (b
);
5696 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5698 struct breakpoint
*b
;
5700 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5701 update_global_location_list_nothrow (1);
5705 /* Disable any breakpoints that are on code in shared libraries. Only
5706 apply to enabled breakpoints, disabled ones can just stay disabled. */
5709 disable_breakpoints_in_shlibs (void)
5711 struct bp_location
*loc
, **locp_tmp
;
5713 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5715 struct breakpoint
*b
= loc
->owner
;
5716 /* We apply the check to all breakpoints, including disabled
5717 for those with loc->duplicate set. This is so that when breakpoint
5718 becomes enabled, or the duplicate is removed, gdb will try to insert
5719 all breakpoints. If we don't set shlib_disabled here, we'll try
5720 to insert those breakpoints and fail. */
5721 if (((b
->type
== bp_breakpoint
)
5722 || (b
->type
== bp_jit_event
)
5723 || (b
->type
== bp_hardware_breakpoint
)
5724 || (is_tracepoint (b
)))
5725 && loc
->pspace
== current_program_space
5726 && !loc
->shlib_disabled
5728 && PC_SOLIB (loc
->address
)
5730 && solib_name_from_address (loc
->pspace
, loc
->address
)
5734 loc
->shlib_disabled
= 1;
5739 /* Disable any breakpoints that are in in an unloaded shared library. Only
5740 apply to enabled breakpoints, disabled ones can just stay disabled. */
5743 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5745 struct bp_location
*loc
, **locp_tmp
;
5746 int disabled_shlib_breaks
= 0;
5748 /* SunOS a.out shared libraries are always mapped, so do not
5749 disable breakpoints; they will only be reported as unloaded
5750 through clear_solib when GDB discards its shared library
5751 list. See clear_solib for more information. */
5752 if (exec_bfd
!= NULL
5753 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5756 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5758 struct breakpoint
*b
= loc
->owner
;
5760 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5761 || loc
->loc_type
== bp_loc_software_breakpoint
)
5762 && solib
->pspace
== loc
->pspace
5763 && !loc
->shlib_disabled
5764 && (b
->type
== bp_breakpoint
5765 || b
->type
== bp_jit_event
5766 || b
->type
== bp_hardware_breakpoint
)
5767 && solib_contains_address_p (solib
, loc
->address
))
5769 loc
->shlib_disabled
= 1;
5770 /* At this point, we cannot rely on remove_breakpoint
5771 succeeding so we must mark the breakpoint as not inserted
5772 to prevent future errors occurring in remove_breakpoints. */
5774 if (!disabled_shlib_breaks
)
5776 target_terminal_ours_for_output ();
5777 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5780 disabled_shlib_breaks
= 1;
5785 /* FORK & VFORK catchpoints. */
5787 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5790 insert_catch_fork (struct breakpoint
*b
)
5792 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5795 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5798 remove_catch_fork (struct breakpoint
*b
)
5800 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5803 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5807 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5809 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5812 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5814 static enum print_stop_action
5815 print_it_catch_fork (struct breakpoint
*b
)
5817 annotate_catchpoint (b
->number
);
5818 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5819 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5820 return PRINT_SRC_AND_LOC
;
5823 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5826 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5828 struct value_print_options opts
;
5830 get_user_print_options (&opts
);
5832 /* Field 4, the address, is omitted (which makes the columns
5833 not line up too nicely with the headers, but the effect
5834 is relatively readable). */
5835 if (opts
.addressprint
)
5836 ui_out_field_skip (uiout
, "addr");
5838 ui_out_text (uiout
, "fork");
5839 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5841 ui_out_text (uiout
, ", process ");
5842 ui_out_field_int (uiout
, "what",
5843 ptid_get_pid (b
->forked_inferior_pid
));
5844 ui_out_spaces (uiout
, 1);
5848 /* Implement the "print_mention" breakpoint_ops method for fork
5852 print_mention_catch_fork (struct breakpoint
*b
)
5854 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5857 /* Implement the "print_recreate" breakpoint_ops method for fork
5861 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
5863 fprintf_unfiltered (fp
, "catch fork");
5866 /* The breakpoint_ops structure to be used in fork catchpoints. */
5868 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5872 breakpoint_hit_catch_fork
,
5873 print_it_catch_fork
,
5874 print_one_catch_fork
,
5875 print_mention_catch_fork
,
5876 print_recreate_catch_fork
5879 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5882 insert_catch_vfork (struct breakpoint
*b
)
5884 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5887 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5890 remove_catch_vfork (struct breakpoint
*b
)
5892 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5895 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5899 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5901 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5904 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5906 static enum print_stop_action
5907 print_it_catch_vfork (struct breakpoint
*b
)
5909 annotate_catchpoint (b
->number
);
5910 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5911 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5912 return PRINT_SRC_AND_LOC
;
5915 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5918 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5920 struct value_print_options opts
;
5922 get_user_print_options (&opts
);
5923 /* Field 4, the address, is omitted (which makes the columns
5924 not line up too nicely with the headers, but the effect
5925 is relatively readable). */
5926 if (opts
.addressprint
)
5927 ui_out_field_skip (uiout
, "addr");
5929 ui_out_text (uiout
, "vfork");
5930 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5932 ui_out_text (uiout
, ", process ");
5933 ui_out_field_int (uiout
, "what",
5934 ptid_get_pid (b
->forked_inferior_pid
));
5935 ui_out_spaces (uiout
, 1);
5939 /* Implement the "print_mention" breakpoint_ops method for vfork
5943 print_mention_catch_vfork (struct breakpoint
*b
)
5945 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5948 /* Implement the "print_recreate" breakpoint_ops method for vfork
5952 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
5954 fprintf_unfiltered (fp
, "catch vfork");
5957 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5959 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5963 breakpoint_hit_catch_vfork
,
5964 print_it_catch_vfork
,
5965 print_one_catch_vfork
,
5966 print_mention_catch_vfork
,
5967 print_recreate_catch_vfork
5970 /* Implement the "insert" breakpoint_ops method for syscall
5974 insert_catch_syscall (struct breakpoint
*b
)
5976 struct inferior
*inf
= current_inferior ();
5978 ++inf
->total_syscalls_count
;
5979 if (!b
->syscalls_to_be_caught
)
5980 ++inf
->any_syscall_count
;
5986 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5991 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5993 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5994 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5996 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5997 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5999 memset ((void *) vec_addr
, 0,
6000 (iter
+ 1 - old_size
) * sizeof (int));
6002 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6003 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6007 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6008 inf
->total_syscalls_count
!= 0,
6009 inf
->any_syscall_count
,
6010 VEC_length (int, inf
->syscalls_counts
),
6011 VEC_address (int, inf
->syscalls_counts
));
6014 /* Implement the "remove" breakpoint_ops method for syscall
6018 remove_catch_syscall (struct breakpoint
*b
)
6020 struct inferior
*inf
= current_inferior ();
6022 --inf
->total_syscalls_count
;
6023 if (!b
->syscalls_to_be_caught
)
6024 --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
)
6069 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6071 if (syscall_number
== iter
)
6081 /* Implement the "print_it" breakpoint_ops method for syscall
6084 static enum print_stop_action
6085 print_it_catch_syscall (struct breakpoint
*b
)
6087 /* These are needed because we want to know in which state a
6088 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6089 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6090 must print "called syscall" or "returned from syscall". */
6092 struct target_waitstatus last
;
6094 struct cleanup
*old_chain
;
6097 get_last_target_status (&ptid
, &last
);
6099 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6101 annotate_catchpoint (b
->number
);
6104 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6106 syscall_id
= xstrprintf ("'%s'", s
.name
);
6108 old_chain
= make_cleanup (xfree
, syscall_id
);
6110 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6111 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6112 b
->number
, syscall_id
);
6113 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6114 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6115 b
->number
, syscall_id
);
6117 do_cleanups (old_chain
);
6119 return PRINT_SRC_AND_LOC
;
6122 /* Implement the "print_one" breakpoint_ops method for syscall
6126 print_one_catch_syscall (struct breakpoint
*b
,
6127 struct bp_location
**last_loc
)
6129 struct value_print_options opts
;
6131 get_user_print_options (&opts
);
6132 /* Field 4, the address, is omitted (which makes the columns
6133 not line up too nicely with the headers, but the effect
6134 is relatively readable). */
6135 if (opts
.addressprint
)
6136 ui_out_field_skip (uiout
, "addr");
6139 if (b
->syscalls_to_be_caught
6140 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6141 ui_out_text (uiout
, "syscalls \"");
6143 ui_out_text (uiout
, "syscall \"");
6145 if (b
->syscalls_to_be_caught
)
6148 char *text
= xstrprintf ("%s", "");
6151 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6156 get_syscall_by_number (iter
, &s
);
6159 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6161 text
= xstrprintf ("%s%d, ", text
, iter
);
6163 /* We have to xfree the last 'text' (now stored at 'x')
6164 because xstrprintf dinamically allocates new space for it
6168 /* Remove the last comma. */
6169 text
[strlen (text
) - 2] = '\0';
6170 ui_out_field_string (uiout
, "what", text
);
6173 ui_out_field_string (uiout
, "what", "<any syscall>");
6174 ui_out_text (uiout
, "\" ");
6177 /* Implement the "print_mention" breakpoint_ops method for syscall
6181 print_mention_catch_syscall (struct breakpoint
*b
)
6183 if (b
->syscalls_to_be_caught
)
6187 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6188 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6190 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6193 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6197 get_syscall_by_number (iter
, &s
);
6200 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6202 printf_filtered (" %d", s
.number
);
6204 printf_filtered (")");
6207 printf_filtered (_("Catchpoint %d (any syscall)"),
6211 /* Implement the "print_recreate" breakpoint_ops method for syscall
6215 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6217 fprintf_unfiltered (fp
, "catch syscall");
6219 if (b
->syscalls_to_be_caught
)
6224 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6229 get_syscall_by_number (iter
, &s
);
6231 fprintf_unfiltered (fp
, " %s", s
.name
);
6233 fprintf_unfiltered (fp
, " %d", s
.number
);
6238 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6240 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6242 insert_catch_syscall
,
6243 remove_catch_syscall
,
6244 breakpoint_hit_catch_syscall
,
6245 print_it_catch_syscall
,
6246 print_one_catch_syscall
,
6247 print_mention_catch_syscall
,
6248 print_recreate_catch_syscall
6251 /* Returns non-zero if 'b' is a syscall catchpoint. */
6254 syscall_catchpoint_p (struct breakpoint
*b
)
6256 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6259 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6260 but does NOT mention it nor update the global location list.
6261 This is useful if you need to fill more fields in the
6262 struct breakpoint before calling mention.
6264 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6265 If COND_STRING is not NULL, then store it in the breakpoint.
6266 OPS, if not NULL, is the breakpoint_ops structure associated
6267 to the catchpoint. */
6269 static struct breakpoint
*
6270 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6272 struct breakpoint_ops
*ops
)
6274 struct symtab_and_line sal
;
6275 struct breakpoint
*b
;
6278 sal
.pspace
= current_program_space
;
6280 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6281 set_breakpoint_count (breakpoint_count
+ 1);
6282 b
->number
= breakpoint_count
;
6284 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6286 b
->addr_string
= NULL
;
6287 b
->enable_state
= bp_enabled
;
6288 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6294 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6296 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6297 If COND_STRING is not NULL, then store it in the breakpoint.
6298 OPS, if not NULL, is the breakpoint_ops structure associated
6299 to the catchpoint. */
6301 static struct breakpoint
*
6302 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6303 char *cond_string
, struct breakpoint_ops
*ops
)
6305 struct breakpoint
*b
=
6306 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6309 update_global_location_list (1);
6315 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6316 int tempflag
, char *cond_string
,
6317 struct breakpoint_ops
*ops
)
6319 struct breakpoint
*b
6320 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6322 /* FIXME: We should put this information in a breakpoint private data
6324 b
->forked_inferior_pid
= null_ptid
;
6327 /* Exec catchpoints. */
6330 insert_catch_exec (struct breakpoint
*b
)
6332 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6336 remove_catch_exec (struct breakpoint
*b
)
6338 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6342 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6344 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6347 static enum print_stop_action
6348 print_it_catch_exec (struct breakpoint
*b
)
6350 annotate_catchpoint (b
->number
);
6351 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6353 return PRINT_SRC_AND_LOC
;
6357 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6359 struct value_print_options opts
;
6361 get_user_print_options (&opts
);
6363 /* Field 4, the address, is omitted (which makes the columns
6364 not line up too nicely with the headers, but the effect
6365 is relatively readable). */
6366 if (opts
.addressprint
)
6367 ui_out_field_skip (uiout
, "addr");
6369 ui_out_text (uiout
, "exec");
6370 if (b
->exec_pathname
!= NULL
)
6372 ui_out_text (uiout
, ", program \"");
6373 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6374 ui_out_text (uiout
, "\" ");
6379 print_mention_catch_exec (struct breakpoint
*b
)
6381 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6384 /* Implement the "print_recreate" breakpoint_ops method for exec
6388 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6390 fprintf_unfiltered (fp
, "catch exec");
6393 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6397 breakpoint_hit_catch_exec
,
6398 print_it_catch_exec
,
6399 print_one_catch_exec
,
6400 print_mention_catch_exec
,
6401 print_recreate_catch_exec
6405 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6406 struct breakpoint_ops
*ops
)
6408 struct gdbarch
*gdbarch
= get_current_arch ();
6409 struct breakpoint
*b
=
6410 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6412 b
->syscalls_to_be_caught
= filter
;
6414 /* Now, we have to mention the breakpoint and update the global
6417 update_global_location_list (1);
6421 hw_breakpoint_used_count (void)
6423 struct breakpoint
*b
;
6428 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6436 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6438 struct breakpoint
*b
;
6441 *other_type_used
= 0;
6444 if (breakpoint_enabled (b
))
6446 if (b
->type
== type
)
6448 else if (is_hardware_watchpoint (b
))
6449 *other_type_used
= 1;
6456 disable_watchpoints_before_interactive_call_start (void)
6458 struct breakpoint
*b
;
6462 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6464 b
->enable_state
= bp_call_disabled
;
6465 update_global_location_list (0);
6471 enable_watchpoints_after_interactive_call_stop (void)
6473 struct breakpoint
*b
;
6477 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6479 b
->enable_state
= bp_enabled
;
6480 update_global_location_list (1);
6486 disable_breakpoints_before_startup (void)
6488 struct breakpoint
*b
;
6493 if (b
->pspace
!= current_program_space
)
6496 if ((b
->type
== bp_breakpoint
6497 || b
->type
== bp_hardware_breakpoint
)
6498 && breakpoint_enabled (b
))
6500 b
->enable_state
= bp_startup_disabled
;
6506 update_global_location_list (0);
6508 current_program_space
->executing_startup
= 1;
6512 enable_breakpoints_after_startup (void)
6514 struct breakpoint
*b
;
6517 current_program_space
->executing_startup
= 0;
6521 if (b
->pspace
!= current_program_space
)
6524 if ((b
->type
== bp_breakpoint
6525 || b
->type
== bp_hardware_breakpoint
)
6526 && b
->enable_state
== bp_startup_disabled
)
6528 b
->enable_state
= bp_enabled
;
6534 breakpoint_re_set ();
6538 /* Set a breakpoint that will evaporate an end of command
6539 at address specified by SAL.
6540 Restrict it to frame FRAME if FRAME is nonzero. */
6543 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6544 struct frame_id frame_id
, enum bptype type
)
6546 struct breakpoint
*b
;
6548 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6550 gdb_assert (!frame_id_inlined_p (frame_id
));
6552 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6553 b
->enable_state
= bp_enabled
;
6554 b
->disposition
= disp_donttouch
;
6555 b
->frame_id
= frame_id
;
6557 /* If we're debugging a multi-threaded program, then we
6558 want momentary breakpoints to be active in only a
6559 single thread of control. */
6560 if (in_thread_list (inferior_ptid
))
6561 b
->thread
= pid_to_thread_id (inferior_ptid
);
6563 update_global_location_list_nothrow (1);
6568 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6572 clone_momentary_breakpoint (struct breakpoint
*orig
)
6574 struct breakpoint
*copy
;
6576 /* If there's nothing to clone, then return nothing. */
6580 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6581 copy
->loc
= allocate_bp_location (copy
);
6582 set_breakpoint_location_function (copy
->loc
);
6584 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6585 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6586 copy
->loc
->address
= orig
->loc
->address
;
6587 copy
->loc
->section
= orig
->loc
->section
;
6588 copy
->loc
->pspace
= orig
->loc
->pspace
;
6590 if (orig
->source_file
== NULL
)
6591 copy
->source_file
= NULL
;
6593 copy
->source_file
= xstrdup (orig
->source_file
);
6595 copy
->line_number
= orig
->line_number
;
6596 copy
->frame_id
= orig
->frame_id
;
6597 copy
->thread
= orig
->thread
;
6598 copy
->pspace
= orig
->pspace
;
6600 copy
->enable_state
= bp_enabled
;
6601 copy
->disposition
= disp_donttouch
;
6602 copy
->number
= internal_breakpoint_number
--;
6604 update_global_location_list_nothrow (0);
6609 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6612 struct symtab_and_line sal
;
6614 sal
= find_pc_line (pc
, 0);
6616 sal
.section
= find_pc_overlay (pc
);
6617 sal
.explicit_pc
= 1;
6619 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6623 /* Tell the user we have just set a breakpoint B. */
6626 mention (struct breakpoint
*b
)
6629 struct cleanup
*ui_out_chain
;
6630 struct value_print_options opts
;
6632 get_user_print_options (&opts
);
6634 /* FIXME: This is misplaced; mention() is called by things (like
6635 hitting a watchpoint) other than breakpoint creation. It should
6636 be possible to clean this up and at the same time replace the
6637 random calls to breakpoint_changed with this hook. */
6638 observer_notify_breakpoint_created (b
->number
);
6640 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6641 b
->ops
->print_mention (b
);
6646 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6649 ui_out_text (uiout
, "Watchpoint ");
6650 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6651 ui_out_field_int (uiout
, "number", b
->number
);
6652 ui_out_text (uiout
, ": ");
6653 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6654 do_cleanups (ui_out_chain
);
6656 case bp_hardware_watchpoint
:
6657 ui_out_text (uiout
, "Hardware watchpoint ");
6658 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6659 ui_out_field_int (uiout
, "number", b
->number
);
6660 ui_out_text (uiout
, ": ");
6661 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6662 do_cleanups (ui_out_chain
);
6664 case bp_read_watchpoint
:
6665 ui_out_text (uiout
, "Hardware read watchpoint ");
6666 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6667 ui_out_field_int (uiout
, "number", b
->number
);
6668 ui_out_text (uiout
, ": ");
6669 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6670 do_cleanups (ui_out_chain
);
6672 case bp_access_watchpoint
:
6673 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6674 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6675 ui_out_field_int (uiout
, "number", b
->number
);
6676 ui_out_text (uiout
, ": ");
6677 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6678 do_cleanups (ui_out_chain
);
6681 if (ui_out_is_mi_like_p (uiout
))
6686 if (b
->disposition
== disp_del
)
6687 printf_filtered (_("Temporary breakpoint"));
6689 printf_filtered (_("Breakpoint"));
6690 printf_filtered (_(" %d"), b
->number
);
6693 case bp_hardware_breakpoint
:
6694 if (ui_out_is_mi_like_p (uiout
))
6699 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6703 if (ui_out_is_mi_like_p (uiout
))
6708 printf_filtered (_("Tracepoint"));
6709 printf_filtered (_(" %d"), b
->number
);
6712 case bp_fast_tracepoint
:
6713 if (ui_out_is_mi_like_p (uiout
))
6718 printf_filtered (_("Fast tracepoint"));
6719 printf_filtered (_(" %d"), b
->number
);
6726 case bp_longjmp_resume
:
6727 case bp_step_resume
:
6729 case bp_std_terminate
:
6730 case bp_watchpoint_scope
:
6731 case bp_shlib_event
:
6732 case bp_thread_event
:
6733 case bp_overlay_event
:
6735 case bp_longjmp_master
:
6736 case bp_std_terminate_master
:
6742 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6746 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6750 if (opts
.addressprint
|| b
->source_file
== NULL
)
6752 printf_filtered (" at ");
6753 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6757 printf_filtered (": file %s, line %d.",
6758 b
->source_file
, b
->line_number
);
6762 struct bp_location
*loc
= b
->loc
;
6764 for (; loc
; loc
= loc
->next
)
6766 printf_filtered (" (%d locations)", n
);
6771 if (ui_out_is_mi_like_p (uiout
))
6773 printf_filtered ("\n");
6777 static struct bp_location
*
6778 add_location_to_breakpoint (struct breakpoint
*b
,
6779 const struct symtab_and_line
*sal
)
6781 struct bp_location
*loc
, **tmp
;
6783 loc
= allocate_bp_location (b
);
6784 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6787 loc
->gdbarch
= get_sal_arch (*sal
);
6789 loc
->gdbarch
= b
->gdbarch
;
6790 loc
->requested_address
= sal
->pc
;
6791 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6792 loc
->requested_address
, b
->type
);
6793 loc
->pspace
= sal
->pspace
;
6794 gdb_assert (loc
->pspace
!= NULL
);
6795 loc
->section
= sal
->section
;
6797 set_breakpoint_location_function (loc
);
6802 /* Return 1 if LOC is pointing to a permanent breakpoint,
6803 return 0 otherwise. */
6806 bp_loc_is_permanent (struct bp_location
*loc
)
6810 const gdb_byte
*brk
;
6811 gdb_byte
*target_mem
;
6812 struct cleanup
*cleanup
;
6815 gdb_assert (loc
!= NULL
);
6817 addr
= loc
->address
;
6818 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6820 /* Software breakpoints unsupported? */
6824 target_mem
= alloca (len
);
6826 /* Enable the automatic memory restoration from breakpoints while
6827 we read the memory. Otherwise we could say about our temporary
6828 breakpoints they are permanent. */
6829 cleanup
= save_current_space_and_thread ();
6831 switch_to_program_space_and_thread (loc
->pspace
);
6832 make_show_memory_breakpoints_cleanup (0);
6834 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6835 && memcmp (target_mem
, brk
, len
) == 0)
6838 do_cleanups (cleanup
);
6845 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6846 as textual description of the location, and COND_STRING
6847 as condition expression. */
6850 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6851 struct symtabs_and_lines sals
, char *addr_string
,
6853 enum bptype type
, enum bpdisp disposition
,
6854 int thread
, int task
, int ignore_count
,
6855 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6857 struct breakpoint
*b
= NULL
;
6860 if (type
== bp_hardware_breakpoint
)
6862 int i
= hw_breakpoint_used_count ();
6863 int target_resources_ok
=
6864 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6866 if (target_resources_ok
== 0)
6867 error (_("No hardware breakpoint support in the target."));
6868 else if (target_resources_ok
< 0)
6869 error (_("Hardware breakpoints used exceeds limit."));
6872 gdb_assert (sals
.nelts
> 0);
6874 for (i
= 0; i
< sals
.nelts
; ++i
)
6876 struct symtab_and_line sal
= sals
.sals
[i
];
6877 struct bp_location
*loc
;
6881 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6883 loc_gdbarch
= gdbarch
;
6885 describe_other_breakpoints (loc_gdbarch
,
6886 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6891 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6892 set_breakpoint_count (breakpoint_count
+ 1);
6893 b
->number
= breakpoint_count
;
6897 b
->cond_string
= cond_string
;
6898 b
->ignore_count
= ignore_count
;
6899 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6900 b
->disposition
= disposition
;
6902 b
->pspace
= sals
.sals
[0].pspace
;
6904 if (enabled
&& b
->pspace
->executing_startup
6905 && (b
->type
== bp_breakpoint
6906 || b
->type
== bp_hardware_breakpoint
))
6907 b
->enable_state
= bp_startup_disabled
;
6913 loc
= add_location_to_breakpoint (b
, &sal
);
6916 if (bp_loc_is_permanent (loc
))
6917 make_breakpoint_permanent (b
);
6921 char *arg
= b
->cond_string
;
6922 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6924 error (_("Garbage %s follows condition"), arg
);
6929 b
->addr_string
= addr_string
;
6931 /* addr_string has to be used or breakpoint_re_set will delete
6934 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6940 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6941 elements to fill the void space. */
6943 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6945 int i
= index_to_remove
+1;
6946 int last_index
= sal
->nelts
-1;
6948 for (;i
<= last_index
; ++i
)
6949 sal
->sals
[i
-1] = sal
->sals
[i
];
6954 /* If appropriate, obtains all sals that correspond to the same file
6955 and line as SAL, in all program spaces. Users debugging with IDEs,
6956 will want to set a breakpoint at foo.c:line, and not really care
6957 about program spaces. This is done only if SAL does not have
6958 explicit PC and has line and file information. If we got just a
6959 single expanded sal, return the original.
6961 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6962 which the name of enclosing function is different from SAL. This
6963 makes sure that if we have breakpoint originally set in template
6964 instantiation, say foo<int>(), we won't expand SAL to locations at
6965 the same line in all existing instantiations of 'foo'. */
6967 static struct symtabs_and_lines
6968 expand_line_sal_maybe (struct symtab_and_line sal
)
6970 struct symtabs_and_lines expanded
;
6971 CORE_ADDR original_pc
= sal
.pc
;
6972 char *original_function
= NULL
;
6975 struct cleanup
*old_chain
;
6977 /* If we have explicit pc, don't expand.
6978 If we have no line number, we can't expand. */
6979 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6982 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6983 expanded
.sals
[0] = sal
;
6989 old_chain
= save_current_space_and_thread ();
6991 switch_to_program_space_and_thread (sal
.pspace
);
6993 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6995 /* Note that expand_line_sal visits *all* program spaces. */
6996 expanded
= expand_line_sal (sal
);
6998 if (expanded
.nelts
== 1)
7000 /* We had one sal, we got one sal. Return that sal, adjusting it
7001 past the function prologue if necessary. */
7002 xfree (expanded
.sals
);
7004 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7005 sal
.pc
= original_pc
;
7006 expanded
.sals
[0] = sal
;
7007 skip_prologue_sal (&expanded
.sals
[0]);
7008 do_cleanups (old_chain
);
7012 if (!sal
.explicit_line
)
7014 CORE_ADDR func_addr
, func_end
;
7015 for (i
= 0; i
< expanded
.nelts
; ++i
)
7017 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7018 char *this_function
;
7020 /* We need to switch threads as well since we're about to
7022 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7024 if (find_pc_partial_function (pc
, &this_function
,
7025 &func_addr
, &func_end
))
7028 && strcmp (this_function
, original_function
) != 0)
7030 remove_sal (&expanded
, i
);
7037 /* Skip the function prologue if necessary. */
7038 for (i
= 0; i
< expanded
.nelts
; ++i
)
7039 skip_prologue_sal (&expanded
.sals
[i
]);
7041 do_cleanups (old_chain
);
7043 if (expanded
.nelts
<= 1)
7045 /* This is un ugly workaround. If we get zero
7046 expanded sals then something is really wrong.
7047 Fix that by returnign the original sal. */
7048 xfree (expanded
.sals
);
7050 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7051 sal
.pc
= original_pc
;
7052 expanded
.sals
[0] = sal
;
7059 for (i
= 0; i
< expanded
.nelts
; ++i
)
7060 if (expanded
.sals
[i
].pc
== original_pc
)
7071 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7072 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7073 value. COND_STRING, if not NULL, specified the condition to be
7074 used for all breakpoints. Essentially the only case where
7075 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7076 function. In that case, it's still not possible to specify
7077 separate conditions for different overloaded functions, so
7078 we take just a single condition string.
7080 NOTE: If the function succeeds, the caller is expected to cleanup
7081 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7082 array contents). If the function fails (error() is called), the
7083 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7084 COND and SALS arrays and each of those arrays contents. */
7087 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7088 struct symtabs_and_lines sals
, char **addr_string
,
7090 enum bptype type
, enum bpdisp disposition
,
7091 int thread
, int task
, int ignore_count
,
7092 struct breakpoint_ops
*ops
, int from_tty
,
7097 for (i
= 0; i
< sals
.nelts
; ++i
)
7099 struct symtabs_and_lines expanded
=
7100 expand_line_sal_maybe (sals
.sals
[i
]);
7102 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7103 cond_string
, type
, disposition
,
7104 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7108 /* Parse ARG which is assumed to be a SAL specification possibly
7109 followed by conditionals. On return, SALS contains an array of SAL
7110 addresses found. ADDR_STRING contains a vector of (canonical)
7111 address strings. ARG points to the end of the SAL. */
7114 parse_breakpoint_sals (char **address
,
7115 struct symtabs_and_lines
*sals
,
7116 char ***addr_string
,
7119 char *addr_start
= *address
;
7121 *addr_string
= NULL
;
7122 /* If no arg given, or if first arg is 'if ', use the default
7124 if ((*address
) == NULL
7125 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7127 if (default_breakpoint_valid
)
7129 struct symtab_and_line sal
;
7131 init_sal (&sal
); /* initialize to zeroes */
7132 sals
->sals
= (struct symtab_and_line
*)
7133 xmalloc (sizeof (struct symtab_and_line
));
7134 sal
.pc
= default_breakpoint_address
;
7135 sal
.line
= default_breakpoint_line
;
7136 sal
.symtab
= default_breakpoint_symtab
;
7137 sal
.pspace
= default_breakpoint_pspace
;
7138 sal
.section
= find_pc_overlay (sal
.pc
);
7140 /* "break" without arguments is equivalent to "break *PC" where PC is
7141 the default_breakpoint_address. So make sure to set
7142 sal.explicit_pc to prevent GDB from trying to expand the list of
7143 sals to include all other instances with the same symtab and line.
7145 sal
.explicit_pc
= 1;
7147 sals
->sals
[0] = sal
;
7151 error (_("No default breakpoint address now."));
7155 /* Force almost all breakpoints to be in terms of the
7156 current_source_symtab (which is decode_line_1's default). This
7157 should produce the results we want almost all of the time while
7158 leaving default_breakpoint_* alone.
7159 ObjC: However, don't match an Objective-C method name which
7160 may have a '+' or '-' succeeded by a '[' */
7162 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7164 if (default_breakpoint_valid
7166 || ((strchr ("+-", (*address
)[0]) != NULL
)
7167 && ((*address
)[1] != '['))))
7168 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7169 default_breakpoint_line
, addr_string
,
7172 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7173 addr_string
, not_found_ptr
);
7175 /* For any SAL that didn't have a canonical string, fill one in. */
7176 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7177 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7178 if (addr_start
!= (*address
))
7182 for (i
= 0; i
< sals
->nelts
; i
++)
7184 /* Add the string if not present. */
7185 if ((*addr_string
)[i
] == NULL
)
7186 (*addr_string
)[i
] = savestring (addr_start
,
7187 (*address
) - addr_start
);
7193 /* Convert each SAL into a real PC. Verify that the PC can be
7194 inserted as a breakpoint. If it can't throw an error. */
7197 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7202 for (i
= 0; i
< sals
->nelts
; i
++)
7203 resolve_sal_pc (&sals
->sals
[i
]);
7206 /* Fast tracepoints may have restrictions on valid locations. For
7207 instance, a fast tracepoint using a jump instead of a trap will
7208 likely have to overwrite more bytes than a trap would, and so can
7209 only be placed where the instruction is longer than the jump, or a
7210 multi-instruction sequence does not have a jump into the middle of
7214 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7215 struct symtabs_and_lines
*sals
)
7218 struct symtab_and_line
*sal
;
7220 struct cleanup
*old_chain
;
7222 for (i
= 0; i
< sals
->nelts
; i
++)
7224 sal
= &sals
->sals
[i
];
7226 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7228 old_chain
= make_cleanup (xfree
, msg
);
7231 error (_("May not have a fast tracepoint at 0x%s%s"),
7232 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7234 do_cleanups (old_chain
);
7239 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7241 struct captured_parse_breakpoint_args
*args
= data
;
7243 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7244 args
->not_found_ptr
);
7247 /* Given TOK, a string specification of condition and thread, as
7248 accepted by the 'break' command, extract the condition
7249 string and thread number and set *COND_STRING and *THREAD.
7250 PC identifies the context at which the condition should be parsed.
7251 If no condition is found, *COND_STRING is set to NULL.
7252 If no thread is found, *THREAD is set to -1. */
7254 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7255 char **cond_string
, int *thread
, int *task
)
7257 *cond_string
= NULL
;
7263 char *cond_start
= NULL
;
7264 char *cond_end
= NULL
;
7266 while (*tok
== ' ' || *tok
== '\t')
7271 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7274 toklen
= end_tok
- tok
;
7276 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7278 struct expression
*expr
;
7280 tok
= cond_start
= end_tok
+ 1;
7281 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7284 *cond_string
= savestring (cond_start
,
7285 cond_end
- cond_start
);
7287 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7293 *thread
= strtol (tok
, &tok
, 0);
7295 error (_("Junk after thread keyword."));
7296 if (!valid_thread_id (*thread
))
7297 error (_("Unknown thread %d."), *thread
);
7299 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7305 *task
= strtol (tok
, &tok
, 0);
7307 error (_("Junk after task keyword."));
7308 if (!valid_task_id (*task
))
7309 error (_("Unknown task %d."), *task
);
7312 error (_("Junk at end of arguments."));
7316 /* Set a breakpoint. This function is shared between CLI and MI
7317 functions for setting a breakpoint. This function has two major
7318 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7319 parameter. If non-zero, the function will parse arg, extracting
7320 breakpoint location, address and thread. Otherwise, ARG is just the
7321 location of breakpoint, with condition and thread specified by the
7322 COND_STRING and THREAD parameters. Returns true if any breakpoint
7323 was created; false otherwise. */
7326 create_breakpoint (struct gdbarch
*gdbarch
,
7327 char *arg
, char *cond_string
, int thread
,
7328 int parse_condition_and_thread
,
7329 int tempflag
, int hardwareflag
, int traceflag
,
7331 enum auto_boolean pending_break_support
,
7332 struct breakpoint_ops
*ops
,
7336 struct gdb_exception e
;
7337 struct symtabs_and_lines sals
;
7338 struct symtab_and_line pending_sal
;
7340 char *addr_start
= arg
;
7342 struct cleanup
*old_chain
;
7343 struct cleanup
*bkpt_chain
= NULL
;
7344 struct captured_parse_breakpoint_args parse_args
;
7348 enum bptype type_wanted
;
7350 int prev_bkpt_count
= breakpoint_count
;
7356 parse_args
.arg_p
= &arg
;
7357 parse_args
.sals_p
= &sals
;
7358 parse_args
.addr_string_p
= &addr_string
;
7359 parse_args
.not_found_ptr
= ¬_found
;
7361 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7362 &parse_args
, RETURN_MASK_ALL
);
7364 /* If caller is interested in rc value from parse, set value. */
7368 throw_exception (e
);
7372 case NOT_FOUND_ERROR
:
7374 /* If pending breakpoint support is turned off, throw
7377 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7378 throw_exception (e
);
7380 exception_print (gdb_stderr
, e
);
7382 /* If pending breakpoint support is auto query and the user
7383 selects no, then simply return the error code. */
7384 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7385 && !nquery ("Make breakpoint pending on future shared library load? "))
7388 /* At this point, either the user was queried about setting
7389 a pending breakpoint and selected yes, or pending
7390 breakpoint behavior is on and thus a pending breakpoint
7391 is defaulted on behalf of the user. */
7392 copy_arg
= xstrdup (addr_start
);
7393 addr_string
= ©_arg
;
7395 sals
.sals
= &pending_sal
;
7400 throw_exception (e
);
7407 /* Create a chain of things that always need to be cleaned up. */
7408 old_chain
= make_cleanup (null_cleanup
, 0);
7412 /* Make sure that all storage allocated to SALS gets freed. */
7413 make_cleanup (xfree
, sals
.sals
);
7415 /* Cleanup the addr_string array but not its contents. */
7416 make_cleanup (xfree
, addr_string
);
7419 /* ----------------------------- SNIP -----------------------------
7420 Anything added to the cleanup chain beyond this point is assumed
7421 to be part of a breakpoint. If the breakpoint create succeeds
7422 then the memory is not reclaimed. */
7423 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7425 /* Mark the contents of the addr_string for cleanup. These go on
7426 the bkpt_chain and only occur if the breakpoint create fails. */
7427 for (i
= 0; i
< sals
.nelts
; i
++)
7429 if (addr_string
[i
] != NULL
)
7430 make_cleanup (xfree
, addr_string
[i
]);
7433 /* Resolve all line numbers to PC's and verify that the addresses
7434 are ok for the target. */
7436 breakpoint_sals_to_pc (&sals
, addr_start
);
7438 type_wanted
= (traceflag
7439 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7440 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7442 /* Fast tracepoints may have additional restrictions on location. */
7443 if (type_wanted
== bp_fast_tracepoint
)
7444 check_fast_tracepoint_sals (gdbarch
, &sals
);
7446 /* Verify that condition can be parsed, before setting any
7447 breakpoints. Allocate a separate condition expression for each
7451 if (parse_condition_and_thread
)
7453 /* Here we only parse 'arg' to separate condition
7454 from thread number, so parsing in context of first
7455 sal is OK. When setting the breakpoint we'll
7456 re-parse it in context of each sal. */
7459 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7462 make_cleanup (xfree
, cond_string
);
7466 /* Create a private copy of condition string. */
7469 cond_string
= xstrdup (cond_string
);
7470 make_cleanup (xfree
, cond_string
);
7473 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7474 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7475 thread
, task
, ignore_count
, ops
, from_tty
,
7480 struct breakpoint
*b
;
7482 make_cleanup (xfree
, copy_arg
);
7484 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7485 set_breakpoint_count (breakpoint_count
+ 1);
7486 b
->number
= breakpoint_count
;
7488 b
->addr_string
= addr_string
[0];
7489 b
->cond_string
= NULL
;
7490 b
->ignore_count
= ignore_count
;
7491 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7492 b
->condition_not_parsed
= 1;
7494 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7495 b
->pspace
= current_program_space
;
7497 if (enabled
&& b
->pspace
->executing_startup
7498 && (b
->type
== bp_breakpoint
7499 || b
->type
== bp_hardware_breakpoint
))
7500 b
->enable_state
= bp_startup_disabled
;
7507 warning (_("Multiple breakpoints were set.\n"
7508 "Use the \"delete\" command to delete unwanted breakpoints."));
7509 prev_breakpoint_count
= prev_bkpt_count
;
7512 /* That's it. Discard the cleanups for data inserted into the
7514 discard_cleanups (bkpt_chain
);
7515 /* But cleanup everything else. */
7516 do_cleanups (old_chain
);
7518 /* error call may happen here - have BKPT_CHAIN already discarded. */
7519 update_global_location_list (1);
7524 /* Set a breakpoint.
7525 ARG is a string describing breakpoint address,
7526 condition, and thread.
7527 FLAG specifies if a breakpoint is hardware on,
7528 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7532 break_command_1 (char *arg
, int flag
, int from_tty
)
7534 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7535 int tempflag
= flag
& BP_TEMPFLAG
;
7537 create_breakpoint (get_current_arch (),
7539 NULL
, 0, 1 /* parse arg */,
7540 tempflag
, hardwareflag
, 0 /* traceflag */,
7541 0 /* Ignore count */,
7542 pending_break_support
,
7543 NULL
/* breakpoint_ops */,
7549 /* Helper function for break_command_1 and disassemble_command. */
7552 resolve_sal_pc (struct symtab_and_line
*sal
)
7556 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7558 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7559 error (_("No line %d in file \"%s\"."),
7560 sal
->line
, sal
->symtab
->filename
);
7563 /* If this SAL corresponds to a breakpoint inserted using
7564 a line number, then skip the function prologue if necessary. */
7565 if (sal
->explicit_line
)
7566 skip_prologue_sal (sal
);
7569 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7571 struct blockvector
*bv
;
7575 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7578 sym
= block_linkage_function (b
);
7581 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7582 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7586 /* It really is worthwhile to have the section, so we'll just
7587 have to look harder. This case can be executed if we have
7588 line numbers but no functions (as can happen in assembly
7591 struct minimal_symbol
*msym
;
7592 struct cleanup
*old_chain
= save_current_space_and_thread ();
7594 switch_to_program_space_and_thread (sal
->pspace
);
7596 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7598 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7600 do_cleanups (old_chain
);
7607 break_command (char *arg
, int from_tty
)
7609 break_command_1 (arg
, 0, from_tty
);
7613 tbreak_command (char *arg
, int from_tty
)
7615 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7619 hbreak_command (char *arg
, int from_tty
)
7621 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7625 thbreak_command (char *arg
, int from_tty
)
7627 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7631 stop_command (char *arg
, int from_tty
)
7633 printf_filtered (_("Specify the type of breakpoint to set.\n\
7634 Usage: stop in <function | address>\n\
7635 stop at <line>\n"));
7639 stopin_command (char *arg
, int from_tty
)
7643 if (arg
== (char *) NULL
)
7645 else if (*arg
!= '*')
7650 /* look for a ':'. If this is a line number specification, then
7651 say it is bad, otherwise, it should be an address or
7652 function/method name */
7653 while (*argptr
&& !hasColon
)
7655 hasColon
= (*argptr
== ':');
7660 badInput
= (*argptr
!= ':'); /* Not a class::method */
7662 badInput
= isdigit (*arg
); /* a simple line number */
7666 printf_filtered (_("Usage: stop in <function | address>\n"));
7668 break_command_1 (arg
, 0, from_tty
);
7672 stopat_command (char *arg
, int from_tty
)
7676 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7683 /* look for a ':'. If there is a '::' then get out, otherwise
7684 it is probably a line number. */
7685 while (*argptr
&& !hasColon
)
7687 hasColon
= (*argptr
== ':');
7692 badInput
= (*argptr
== ':'); /* we have class::method */
7694 badInput
= !isdigit (*arg
); /* not a line number */
7698 printf_filtered (_("Usage: stop at <line>\n"));
7700 break_command_1 (arg
, 0, from_tty
);
7703 /* accessflag: hw_write: watch write,
7704 hw_read: watch read,
7705 hw_access: watch access (read or write) */
7707 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7709 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7710 struct expression
*exp
;
7711 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7712 struct value
*val
, *mark
;
7713 struct frame_info
*frame
;
7714 char *exp_start
= NULL
;
7715 char *exp_end
= NULL
;
7716 char *tok
, *id_tok_start
, *end_tok
;
7718 char *cond_start
= NULL
;
7719 char *cond_end
= NULL
;
7720 int i
, other_type_used
, target_resources_ok
= 0;
7721 enum bptype bp_type
;
7725 /* Make sure that we actually have parameters to parse. */
7726 if (arg
!= NULL
&& arg
[0] != '\0')
7728 toklen
= strlen (arg
); /* Size of argument list. */
7730 /* Points tok to the end of the argument list. */
7731 tok
= arg
+ toklen
- 1;
7733 /* Go backwards in the parameters list. Skip the last parameter.
7734 If we're expecting a 'thread <thread_num>' parameter, this should
7735 be the thread identifier. */
7736 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7738 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7741 /* Points end_tok to the beginning of the last token. */
7742 id_tok_start
= tok
+ 1;
7744 /* Go backwards in the parameters list. Skip one more parameter.
7745 If we're expecting a 'thread <thread_num>' parameter, we should
7746 reach a "thread" token. */
7747 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7752 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7755 /* Move the pointer forward to skip the whitespace and
7756 calculate the length of the token. */
7758 toklen
= end_tok
- tok
;
7760 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7762 /* At this point we've found a "thread" token, which means
7763 the user is trying to set a watchpoint that triggers
7764 only in a specific thread. */
7767 /* Extract the thread ID from the next token. */
7768 thread
= strtol (id_tok_start
, &endp
, 0);
7770 /* Check if the user provided a valid numeric value for the
7772 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7773 error (_("Invalid thread ID specification %s."), id_tok_start
);
7775 /* Check if the thread actually exists. */
7776 if (!valid_thread_id (thread
))
7777 error (_("Unknown thread %d."), thread
);
7779 /* Truncate the string and get rid of the thread <thread_num>
7780 parameter before the parameter list is parsed by the
7781 evaluate_expression() function. */
7786 /* Parse the rest of the arguments. */
7787 innermost_block
= NULL
;
7789 exp
= parse_exp_1 (&arg
, 0, 0);
7791 /* Remove trailing whitespace from the expression before saving it.
7792 This makes the eventual display of the expression string a bit
7794 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7797 exp_valid_block
= innermost_block
;
7798 mark
= value_mark ();
7799 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7801 release_value (val
);
7804 while (*tok
== ' ' || *tok
== '\t')
7808 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7811 toklen
= end_tok
- tok
;
7812 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7814 struct expression
*cond
;
7816 innermost_block
= NULL
;
7817 tok
= cond_start
= end_tok
+ 1;
7818 cond
= parse_exp_1 (&tok
, 0, 0);
7820 /* The watchpoint expression may not be local, but the condition
7821 may still be. E.g.: `watch global if local > 0'. */
7822 cond_exp_valid_block
= innermost_block
;
7828 error (_("Junk at end of command."));
7830 if (accessflag
== hw_read
)
7831 bp_type
= bp_read_watchpoint
;
7832 else if (accessflag
== hw_access
)
7833 bp_type
= bp_access_watchpoint
;
7835 bp_type
= bp_hardware_watchpoint
;
7837 mem_cnt
= can_use_hardware_watchpoint (val
);
7838 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7839 error (_("Expression cannot be implemented with read/access watchpoint."));
7842 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7843 target_resources_ok
=
7844 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7846 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7847 error (_("Target does not support this type of hardware watchpoint."));
7849 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7850 error (_("Target can only support one kind of HW watchpoint at a time."));
7853 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7854 watchpoint could not be set. */
7855 if (!mem_cnt
|| target_resources_ok
<= 0)
7856 bp_type
= bp_watchpoint
;
7858 frame
= block_innermost_frame (exp_valid_block
);
7860 /* If the expression is "local", then set up a "watchpoint scope"
7861 breakpoint at the point where we've left the scope of the watchpoint
7862 expression. Create the scope breakpoint before the watchpoint, so
7863 that we will encounter it first in bpstat_stop_status. */
7864 if (exp_valid_block
&& frame
)
7866 if (frame_id_p (frame_unwind_caller_id (frame
)))
7869 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7870 frame_unwind_caller_pc (frame
),
7871 bp_watchpoint_scope
);
7873 scope_breakpoint
->enable_state
= bp_enabled
;
7875 /* Automatically delete the breakpoint when it hits. */
7876 scope_breakpoint
->disposition
= disp_del
;
7878 /* Only break in the proper frame (help with recursion). */
7879 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7881 /* Set the address at which we will stop. */
7882 scope_breakpoint
->loc
->gdbarch
7883 = frame_unwind_caller_arch (frame
);
7884 scope_breakpoint
->loc
->requested_address
7885 = frame_unwind_caller_pc (frame
);
7886 scope_breakpoint
->loc
->address
7887 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7888 scope_breakpoint
->loc
->requested_address
,
7889 scope_breakpoint
->type
);
7893 /* Now set up the breakpoint. */
7894 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7895 set_breakpoint_count (breakpoint_count
+ 1);
7896 b
->number
= breakpoint_count
;
7898 b
->disposition
= disp_donttouch
;
7900 b
->exp_valid_block
= exp_valid_block
;
7901 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7902 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7906 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7912 b
->watchpoint_frame
= get_frame_id (frame
);
7913 b
->watchpoint_thread
= inferior_ptid
;
7917 b
->watchpoint_frame
= null_frame_id
;
7918 b
->watchpoint_thread
= null_ptid
;
7921 if (scope_breakpoint
!= NULL
)
7923 /* The scope breakpoint is related to the watchpoint. We will
7924 need to act on them together. */
7925 b
->related_breakpoint
= scope_breakpoint
;
7926 scope_breakpoint
->related_breakpoint
= b
;
7929 value_free_to_mark (mark
);
7931 /* Finally update the new watchpoint. This creates the locations
7932 that should be inserted. */
7933 update_watchpoint (b
, 1);
7936 update_global_location_list (1);
7939 /* Return count of locations need to be watched and can be handled
7940 in hardware. If the watchpoint can not be handled
7941 in hardware return zero. */
7944 can_use_hardware_watchpoint (struct value
*v
)
7946 int found_memory_cnt
= 0;
7947 struct value
*head
= v
;
7949 /* Did the user specifically forbid us to use hardware watchpoints? */
7950 if (!can_use_hw_watchpoints
)
7953 /* Make sure that the value of the expression depends only upon
7954 memory contents, and values computed from them within GDB. If we
7955 find any register references or function calls, we can't use a
7956 hardware watchpoint.
7958 The idea here is that evaluating an expression generates a series
7959 of values, one holding the value of every subexpression. (The
7960 expression a*b+c has five subexpressions: a, b, a*b, c, and
7961 a*b+c.) GDB's values hold almost enough information to establish
7962 the criteria given above --- they identify memory lvalues,
7963 register lvalues, computed values, etcetera. So we can evaluate
7964 the expression, and then scan the chain of values that leaves
7965 behind to decide whether we can detect any possible change to the
7966 expression's final value using only hardware watchpoints.
7968 However, I don't think that the values returned by inferior
7969 function calls are special in any way. So this function may not
7970 notice that an expression involving an inferior function call
7971 can't be watched with hardware watchpoints. FIXME. */
7972 for (; v
; v
= value_next (v
))
7974 if (VALUE_LVAL (v
) == lval_memory
)
7977 /* A lazy memory lvalue is one that GDB never needed to fetch;
7978 we either just used its address (e.g., `a' in `a.b') or
7979 we never needed it at all (e.g., `a' in `a,b'). */
7983 /* Ahh, memory we actually used! Check if we can cover
7984 it with hardware watchpoints. */
7985 struct type
*vtype
= check_typedef (value_type (v
));
7987 /* We only watch structs and arrays if user asked for it
7988 explicitly, never if they just happen to appear in a
7989 middle of some value chain. */
7991 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7992 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7994 CORE_ADDR vaddr
= value_address (v
);
7995 int len
= TYPE_LENGTH (value_type (v
));
7997 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
8004 else if (VALUE_LVAL (v
) != not_lval
8005 && deprecated_value_modifiable (v
) == 0)
8006 return 0; /* ??? What does this represent? */
8007 else if (VALUE_LVAL (v
) == lval_register
)
8008 return 0; /* cannot watch a register with a HW watchpoint */
8011 /* The expression itself looks suitable for using a hardware
8012 watchpoint, but give the target machine a chance to reject it. */
8013 return found_memory_cnt
;
8017 watch_command_wrapper (char *arg
, int from_tty
)
8019 watch_command (arg
, from_tty
);
8023 watch_command (char *arg
, int from_tty
)
8025 watch_command_1 (arg
, hw_write
, from_tty
);
8029 rwatch_command_wrapper (char *arg
, int from_tty
)
8031 rwatch_command (arg
, from_tty
);
8035 rwatch_command (char *arg
, int from_tty
)
8037 watch_command_1 (arg
, hw_read
, from_tty
);
8041 awatch_command_wrapper (char *arg
, int from_tty
)
8043 awatch_command (arg
, from_tty
);
8047 awatch_command (char *arg
, int from_tty
)
8049 watch_command_1 (arg
, hw_access
, from_tty
);
8053 /* Helper routines for the until_command routine in infcmd.c. Here
8054 because it uses the mechanisms of breakpoints. */
8056 struct until_break_command_continuation_args
8058 struct breakpoint
*breakpoint
;
8059 struct breakpoint
*breakpoint2
;
8062 /* This function is called by fetch_inferior_event via the
8063 cmd_continuation pointer, to complete the until command. It takes
8064 care of cleaning up the temporary breakpoints set up by the until
8067 until_break_command_continuation (void *arg
)
8069 struct until_break_command_continuation_args
*a
= arg
;
8071 delete_breakpoint (a
->breakpoint
);
8073 delete_breakpoint (a
->breakpoint2
);
8077 until_break_command (char *arg
, int from_tty
, int anywhere
)
8079 struct symtabs_and_lines sals
;
8080 struct symtab_and_line sal
;
8081 struct frame_info
*frame
= get_selected_frame (NULL
);
8082 struct breakpoint
*breakpoint
;
8083 struct breakpoint
*breakpoint2
= NULL
;
8084 struct cleanup
*old_chain
;
8086 clear_proceed_status ();
8088 /* Set a breakpoint where the user wants it and at return from
8091 if (default_breakpoint_valid
)
8092 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8093 default_breakpoint_line
, (char ***) NULL
, NULL
);
8095 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8096 0, (char ***) NULL
, NULL
);
8098 if (sals
.nelts
!= 1)
8099 error (_("Couldn't get information on specified line."));
8102 xfree (sals
.sals
); /* malloc'd, so freed */
8105 error (_("Junk at end of arguments."));
8107 resolve_sal_pc (&sal
);
8110 /* If the user told us to continue until a specified location,
8111 we don't specify a frame at which we need to stop. */
8112 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8113 null_frame_id
, bp_until
);
8115 /* Otherwise, specify the selected frame, because we want to stop only
8116 at the very same frame. */
8117 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8118 get_stack_frame_id (frame
),
8121 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8123 /* Keep within the current frame, or in frames called by the current
8126 if (frame_id_p (frame_unwind_caller_id (frame
)))
8128 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8129 sal
.pc
= frame_unwind_caller_pc (frame
);
8130 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8132 frame_unwind_caller_id (frame
),
8134 make_cleanup_delete_breakpoint (breakpoint2
);
8137 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8139 /* If we are running asynchronously, and proceed call above has actually
8140 managed to start the target, arrange for breakpoints to be
8141 deleted when the target stops. Otherwise, we're already stopped and
8142 delete breakpoints via cleanup chain. */
8144 if (target_can_async_p () && is_running (inferior_ptid
))
8146 struct until_break_command_continuation_args
*args
;
8147 args
= xmalloc (sizeof (*args
));
8149 args
->breakpoint
= breakpoint
;
8150 args
->breakpoint2
= breakpoint2
;
8152 discard_cleanups (old_chain
);
8153 add_continuation (inferior_thread (),
8154 until_break_command_continuation
, args
,
8158 do_cleanups (old_chain
);
8162 ep_skip_leading_whitespace (char **s
)
8164 if ((s
== NULL
) || (*s
== NULL
))
8166 while (isspace (**s
))
8170 /* This function attempts to parse an optional "if <cond>" clause
8171 from the arg string. If one is not found, it returns NULL.
8173 Else, it returns a pointer to the condition string. (It does not
8174 attempt to evaluate the string against a particular block.) And,
8175 it updates arg to point to the first character following the parsed
8176 if clause in the arg string. */
8179 ep_parse_optional_if_clause (char **arg
)
8183 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8186 /* Skip the "if" keyword. */
8189 /* Skip any extra leading whitespace, and record the start of the
8190 condition string. */
8191 ep_skip_leading_whitespace (arg
);
8194 /* Assume that the condition occupies the remainder of the arg string. */
8195 (*arg
) += strlen (cond_string
);
8200 /* Commands to deal with catching events, such as signals, exceptions,
8201 process start/exit, etc. */
8205 catch_fork_temporary
, catch_vfork_temporary
,
8206 catch_fork_permanent
, catch_vfork_permanent
8211 catch_fork_command_1 (char *arg
, int from_tty
,
8212 struct cmd_list_element
*command
)
8214 struct gdbarch
*gdbarch
= get_current_arch ();
8215 char *cond_string
= NULL
;
8216 catch_fork_kind fork_kind
;
8219 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8220 tempflag
= (fork_kind
== catch_fork_temporary
8221 || fork_kind
== catch_vfork_temporary
);
8225 ep_skip_leading_whitespace (&arg
);
8227 /* The allowed syntax is:
8229 catch [v]fork if <cond>
8231 First, check if there's an if clause. */
8232 cond_string
= ep_parse_optional_if_clause (&arg
);
8234 if ((*arg
!= '\0') && !isspace (*arg
))
8235 error (_("Junk at end of arguments."));
8237 /* If this target supports it, create a fork or vfork catchpoint
8238 and enable reporting of such events. */
8241 case catch_fork_temporary
:
8242 case catch_fork_permanent
:
8243 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8244 &catch_fork_breakpoint_ops
);
8246 case catch_vfork_temporary
:
8247 case catch_vfork_permanent
:
8248 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8249 &catch_vfork_breakpoint_ops
);
8252 error (_("unsupported or unknown fork kind; cannot catch it"));
8258 catch_exec_command_1 (char *arg
, int from_tty
,
8259 struct cmd_list_element
*command
)
8261 struct gdbarch
*gdbarch
= get_current_arch ();
8263 char *cond_string
= NULL
;
8265 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8269 ep_skip_leading_whitespace (&arg
);
8271 /* The allowed syntax is:
8273 catch exec if <cond>
8275 First, check if there's an if clause. */
8276 cond_string
= ep_parse_optional_if_clause (&arg
);
8278 if ((*arg
!= '\0') && !isspace (*arg
))
8279 error (_("Junk at end of arguments."));
8281 /* If this target supports it, create an exec catchpoint
8282 and enable reporting of such events. */
8283 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8284 &catch_exec_breakpoint_ops
);
8287 static enum print_stop_action
8288 print_exception_catchpoint (struct breakpoint
*b
)
8290 int bp_temp
, bp_throw
;
8292 annotate_catchpoint (b
->number
);
8294 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8295 if (b
->loc
->address
!= b
->loc
->requested_address
)
8296 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8299 bp_temp
= b
->disposition
== disp_del
;
8301 bp_temp
? "Temporary catchpoint "
8303 if (!ui_out_is_mi_like_p (uiout
))
8304 ui_out_field_int (uiout
, "bkptno", b
->number
);
8306 bp_throw
? " (exception thrown), "
8307 : " (exception caught), ");
8308 if (ui_out_is_mi_like_p (uiout
))
8310 ui_out_field_string (uiout
, "reason",
8311 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8312 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8313 ui_out_field_int (uiout
, "bkptno", b
->number
);
8315 return PRINT_SRC_AND_LOC
;
8319 print_one_exception_catchpoint (struct breakpoint
*b
,
8320 struct bp_location
**last_loc
)
8322 struct value_print_options opts
;
8324 get_user_print_options (&opts
);
8325 if (opts
.addressprint
)
8328 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8329 ui_out_field_string (uiout
, "addr", "<PENDING>");
8331 ui_out_field_core_addr (uiout
, "addr",
8332 b
->loc
->gdbarch
, b
->loc
->address
);
8337 if (strstr (b
->addr_string
, "throw") != NULL
)
8338 ui_out_field_string (uiout
, "what", "exception throw");
8340 ui_out_field_string (uiout
, "what", "exception catch");
8344 print_mention_exception_catchpoint (struct breakpoint
*b
)
8349 bp_temp
= b
->disposition
== disp_del
;
8350 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8351 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8352 : _("Catchpoint "));
8353 ui_out_field_int (uiout
, "bkptno", b
->number
);
8354 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8358 /* Implement the "print_recreate" breakpoint_ops method for throw and
8359 catch catchpoints. */
8362 print_recreate_exception_catchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8367 bp_temp
= b
->disposition
== disp_del
;
8368 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8369 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8370 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8373 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8376 NULL
, /* breakpoint_hit */
8377 print_exception_catchpoint
,
8378 print_one_exception_catchpoint
,
8379 print_mention_exception_catchpoint
,
8380 print_recreate_exception_catchpoint
8384 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8385 enum exception_event_kind ex_event
, int from_tty
)
8387 char *trigger_func_name
;
8389 if (ex_event
== EX_EVENT_CATCH
)
8390 trigger_func_name
= "__cxa_begin_catch";
8392 trigger_func_name
= "__cxa_throw";
8394 create_breakpoint (get_current_arch (),
8395 trigger_func_name
, cond_string
, -1,
8396 0 /* condition and thread are valid. */,
8399 AUTO_BOOLEAN_TRUE
/* pending */,
8400 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8406 /* Deal with "catch catch" and "catch throw" commands */
8409 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8410 int tempflag
, int from_tty
)
8412 char *cond_string
= NULL
;
8416 ep_skip_leading_whitespace (&arg
);
8418 cond_string
= ep_parse_optional_if_clause (&arg
);
8420 if ((*arg
!= '\0') && !isspace (*arg
))
8421 error (_("Junk at end of arguments."));
8423 if (ex_event
!= EX_EVENT_THROW
8424 && ex_event
!= EX_EVENT_CATCH
)
8425 error (_("Unsupported or unknown exception event; cannot catch it"));
8427 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8430 warning (_("Unsupported with this platform/compiler combination."));
8433 /* Implementation of "catch catch" command. */
8436 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8438 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8440 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8443 /* Implementation of "catch throw" command. */
8446 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8448 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8450 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8453 /* Create a breakpoint struct for Ada exception catchpoints. */
8456 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8457 struct symtab_and_line sal
,
8461 struct expression
*cond
,
8462 struct breakpoint_ops
*ops
,
8466 struct breakpoint
*b
;
8470 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8472 loc_gdbarch
= gdbarch
;
8474 describe_other_breakpoints (loc_gdbarch
,
8475 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8476 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8477 version for exception catchpoints, because two catchpoints
8478 used for different exception names will use the same address.
8479 In this case, a "breakpoint ... also set at..." warning is
8480 unproductive. Besides. the warning phrasing is also a bit
8481 inapropriate, we should use the word catchpoint, and tell
8482 the user what type of catchpoint it is. The above is good
8483 enough for now, though. */
8486 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8487 set_breakpoint_count (breakpoint_count
+ 1);
8489 b
->enable_state
= bp_enabled
;
8490 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8491 b
->number
= breakpoint_count
;
8492 b
->ignore_count
= 0;
8493 b
->loc
->cond
= cond
;
8494 b
->addr_string
= addr_string
;
8495 b
->language
= language_ada
;
8496 b
->cond_string
= cond_string
;
8497 b
->exp_string
= exp_string
;
8502 update_global_location_list (1);
8505 /* Implement the "catch exception" command. */
8508 catch_ada_exception_command (char *arg
, int from_tty
,
8509 struct cmd_list_element
*command
)
8511 struct gdbarch
*gdbarch
= get_current_arch ();
8513 struct symtab_and_line sal
;
8514 char *addr_string
= NULL
;
8515 char *exp_string
= NULL
;
8516 char *cond_string
= NULL
;
8517 struct expression
*cond
= NULL
;
8518 struct breakpoint_ops
*ops
= NULL
;
8520 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8524 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8525 &cond_string
, &cond
, &ops
);
8526 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8527 cond_string
, cond
, ops
, tempflag
,
8531 /* Cleanup function for a syscall filter list. */
8533 clean_up_filters (void *arg
)
8535 VEC(int) *iter
= *(VEC(int) **) arg
;
8536 VEC_free (int, iter
);
8539 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8540 filter list, or NULL if no filtering is required. */
8542 catch_syscall_split_args (char *arg
)
8544 VEC(int) *result
= NULL
;
8545 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8547 while (*arg
!= '\0')
8549 int i
, syscall_number
;
8554 /* Skip whitespace. */
8555 while (isspace (*arg
))
8558 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8559 cur_name
[i
] = arg
[i
];
8563 /* Check if the user provided a syscall name or a number. */
8564 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8565 if (*endptr
== '\0')
8566 get_syscall_by_number (syscall_number
, &s
);
8569 /* We have a name. Let's check if it's valid and convert it
8571 get_syscall_by_name (cur_name
, &s
);
8573 if (s
.number
== UNKNOWN_SYSCALL
)
8574 /* Here we have to issue an error instead of a warning, because
8575 GDB cannot do anything useful if there's no syscall number to
8577 error (_("Unknown syscall name '%s'."), cur_name
);
8580 /* Ok, it's valid. */
8581 VEC_safe_push (int, result
, s
.number
);
8584 discard_cleanups (cleanup
);
8588 /* Implement the "catch syscall" command. */
8591 catch_syscall_command_1 (char *arg
, int from_tty
,
8592 struct cmd_list_element
*command
)
8597 struct gdbarch
*gdbarch
= get_current_arch ();
8599 /* Checking if the feature if supported. */
8600 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8601 error (_("The feature 'catch syscall' is not supported on \
8602 this architeture yet."));
8604 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8606 ep_skip_leading_whitespace (&arg
);
8608 /* We need to do this first "dummy" translation in order
8609 to get the syscall XML file loaded or, most important,
8610 to display a warning to the user if there's no XML file
8611 for his/her architecture. */
8612 get_syscall_by_number (0, &s
);
8614 /* The allowed syntax is:
8616 catch syscall <name | number> [<name | number> ... <name | number>]
8618 Let's check if there's a syscall name. */
8621 filter
= catch_syscall_split_args (arg
);
8625 create_syscall_event_catchpoint (tempflag
, filter
,
8626 &catch_syscall_breakpoint_ops
);
8629 /* Implement the "catch assert" command. */
8632 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8634 struct gdbarch
*gdbarch
= get_current_arch ();
8636 struct symtab_and_line sal
;
8637 char *addr_string
= NULL
;
8638 struct breakpoint_ops
*ops
= NULL
;
8640 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8644 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8645 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8646 ops
, tempflag
, from_tty
);
8650 catch_command (char *arg
, int from_tty
)
8652 error (_("Catch requires an event name."));
8657 tcatch_command (char *arg
, int from_tty
)
8659 error (_("Catch requires an event name."));
8662 /* Delete breakpoints by address or line. */
8665 clear_command (char *arg
, int from_tty
)
8667 struct breakpoint
*b
;
8668 VEC(breakpoint_p
) *found
= 0;
8671 struct symtabs_and_lines sals
;
8672 struct symtab_and_line sal
;
8677 sals
= decode_line_spec (arg
, 1);
8682 sals
.sals
= (struct symtab_and_line
*)
8683 xmalloc (sizeof (struct symtab_and_line
));
8684 make_cleanup (xfree
, sals
.sals
);
8685 init_sal (&sal
); /* initialize to zeroes */
8686 sal
.line
= default_breakpoint_line
;
8687 sal
.symtab
= default_breakpoint_symtab
;
8688 sal
.pc
= default_breakpoint_address
;
8689 sal
.pspace
= default_breakpoint_pspace
;
8690 if (sal
.symtab
== 0)
8691 error (_("No source file specified."));
8699 /* We don't call resolve_sal_pc here. That's not
8700 as bad as it seems, because all existing breakpoints
8701 typically have both file/line and pc set. So, if
8702 clear is given file/line, we can match this to existing
8703 breakpoint without obtaining pc at all.
8705 We only support clearing given the address explicitly
8706 present in breakpoint table. Say, we've set breakpoint
8707 at file:line. There were several PC values for that file:line,
8708 due to optimization, all in one block.
8709 We've picked one PC value. If "clear" is issued with another
8710 PC corresponding to the same file:line, the breakpoint won't
8711 be cleared. We probably can still clear the breakpoint, but
8712 since the other PC value is never presented to user, user
8713 can only find it by guessing, and it does not seem important
8716 /* For each line spec given, delete bps which correspond
8717 to it. Do it in two passes, solely to preserve the current
8718 behavior that from_tty is forced true if we delete more than
8722 for (i
= 0; i
< sals
.nelts
; i
++)
8724 /* If exact pc given, clear bpts at that pc.
8725 If line given (pc == 0), clear all bpts on specified line.
8726 If defaulting, clear all bpts on default line
8729 defaulting sal.pc != 0 tests to do
8734 1 0 <can't happen> */
8738 /* Find all matching breakpoints and add them to
8743 /* Are we going to delete b? */
8744 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
8746 struct bp_location
*loc
= b
->loc
;
8747 for (; loc
; loc
= loc
->next
)
8749 int pc_match
= sal
.pc
8750 && (loc
->pspace
== sal
.pspace
)
8751 && (loc
->address
== sal
.pc
)
8752 && (!section_is_overlay (loc
->section
)
8753 || loc
->section
== sal
.section
);
8754 int line_match
= ((default_match
|| (0 == sal
.pc
))
8755 && b
->source_file
!= NULL
8756 && sal
.symtab
!= NULL
8757 && sal
.pspace
== loc
->pspace
8758 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8759 && b
->line_number
== sal
.line
);
8760 if (pc_match
|| line_match
)
8769 VEC_safe_push(breakpoint_p
, found
, b
);
8772 /* Now go thru the 'found' chain and delete them. */
8773 if (VEC_empty(breakpoint_p
, found
))
8776 error (_("No breakpoint at %s."), arg
);
8778 error (_("No breakpoint at this line."));
8781 if (VEC_length(breakpoint_p
, found
) > 1)
8782 from_tty
= 1; /* Always report if deleted more than one */
8785 if (VEC_length(breakpoint_p
, found
) == 1)
8786 printf_unfiltered (_("Deleted breakpoint "));
8788 printf_unfiltered (_("Deleted breakpoints "));
8790 breakpoints_changed ();
8792 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8795 printf_unfiltered ("%d ", b
->number
);
8796 delete_breakpoint (b
);
8799 putchar_unfiltered ('\n');
8802 /* Delete breakpoint in BS if they are `delete' breakpoints and
8803 all breakpoints that are marked for deletion, whether hit or not.
8804 This is called after any breakpoint is hit, or after errors. */
8807 breakpoint_auto_delete (bpstat bs
)
8809 struct breakpoint
*b
, *temp
;
8811 for (; bs
; bs
= bs
->next
)
8812 if (bs
->breakpoint_at
8813 && bs
->breakpoint_at
->owner
8814 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8816 delete_breakpoint (bs
->breakpoint_at
->owner
);
8818 ALL_BREAKPOINTS_SAFE (b
, temp
)
8820 if (b
->disposition
== disp_del_at_next_stop
)
8821 delete_breakpoint (b
);
8825 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8826 Sort elements primarily by their ADDRESS (no matter what does
8827 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8828 first bp_permanent OWNERed elements and terciarily just ensuring the array
8829 is sorted stable way despite qsort being an instable algorithm. */
8832 bp_location_compare (const void *ap
, const void *bp
)
8834 struct bp_location
*a
= *(void **) ap
;
8835 struct bp_location
*b
= *(void **) bp
;
8836 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8837 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8839 if (a
->address
!= b
->address
)
8840 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8842 /* Sort permanent breakpoints first. */
8843 if (a_perm
!= b_perm
)
8844 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8846 /* Make the user-visible order stable across GDB runs. Locations of the same
8847 breakpoint can be sorted in arbitrary order. */
8849 if (a
->owner
->number
!= b
->owner
->number
)
8850 return (a
->owner
->number
> b
->owner
->number
)
8851 - (a
->owner
->number
< b
->owner
->number
);
8853 return (a
> b
) - (a
< b
);
8856 /* Set bp_location_placed_address_before_address_max and
8857 bp_location_shadow_len_after_address_max according to the current content of
8858 the bp_location array. */
8861 bp_location_target_extensions_update (void)
8863 struct bp_location
*bl
, **blp_tmp
;
8865 bp_location_placed_address_before_address_max
= 0;
8866 bp_location_shadow_len_after_address_max
= 0;
8868 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8870 CORE_ADDR start
, end
, addr
;
8872 if (!bp_location_has_shadow (bl
))
8875 start
= bl
->target_info
.placed_address
;
8876 end
= start
+ bl
->target_info
.shadow_len
;
8878 gdb_assert (bl
->address
>= start
);
8879 addr
= bl
->address
- start
;
8880 if (addr
> bp_location_placed_address_before_address_max
)
8881 bp_location_placed_address_before_address_max
= addr
;
8883 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8885 gdb_assert (bl
->address
< end
);
8886 addr
= end
- bl
->address
;
8887 if (addr
> bp_location_shadow_len_after_address_max
)
8888 bp_location_shadow_len_after_address_max
= addr
;
8892 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8893 into the inferior, only remove already-inserted locations that no
8894 longer should be inserted. Functions that delete a breakpoint or
8895 breakpoints should pass false, so that deleting a breakpoint
8896 doesn't have the side effect of inserting the locations of other
8897 breakpoints that are marked not-inserted, but should_be_inserted
8898 returns true on them.
8900 This behaviour is useful is situations close to tear-down -- e.g.,
8901 after an exec, while the target still has execution, but breakpoint
8902 shadows of the previous executable image should *NOT* be restored
8903 to the new image; or before detaching, where the target still has
8904 execution and wants to delete breakpoints from GDB's lists, and all
8905 breakpoints had already been removed from the inferior. */
8908 update_global_location_list (int should_insert
)
8910 struct breakpoint
*b
;
8911 struct bp_location
**locp
, *loc
;
8912 struct cleanup
*cleanups
;
8914 /* Used in the duplicates detection below. When iterating over all
8915 bp_locations, points to the first bp_location of a given address.
8916 Breakpoints and watchpoints of different types are never
8917 duplicates of each other. Keep one pointer for each type of
8918 breakpoint/watchpoint, so we only need to loop over all locations
8920 struct bp_location
*bp_loc_first
; /* breakpoint */
8921 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8922 struct bp_location
*awp_loc_first
; /* access watchpoint */
8923 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8925 /* Saved former bp_location array which we compare against the newly built
8926 bp_location from the current state of ALL_BREAKPOINTS. */
8927 struct bp_location
**old_location
, **old_locp
;
8928 unsigned old_location_count
;
8930 old_location
= bp_location
;
8931 old_location_count
= bp_location_count
;
8933 bp_location_count
= 0;
8934 cleanups
= make_cleanup (xfree
, old_location
);
8937 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8938 bp_location_count
++;
8940 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8943 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8945 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8946 bp_location_compare
);
8948 bp_location_target_extensions_update ();
8950 /* Identify bp_location instances that are no longer present in the new
8951 list, and therefore should be freed. Note that it's not necessary that
8952 those locations should be removed from inferior -- if there's another
8953 location at the same address (previously marked as duplicate),
8954 we don't need to remove/insert the location.
8956 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8957 former bp_location array state respectively. */
8960 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8963 struct bp_location
*old_loc
= *old_locp
;
8964 struct bp_location
**loc2p
;
8966 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8968 int found_object
= 0;
8969 /* Tells if the location should remain inserted in the target. */
8970 int keep_in_target
= 0;
8973 /* Skip LOCP entries which will definitely never be needed. Stop either
8974 at or being the one matching OLD_LOC. */
8975 while (locp
< bp_location
+ bp_location_count
8976 && (*locp
)->address
< old_loc
->address
)
8980 (loc2p
< bp_location
+ bp_location_count
8981 && (*loc2p
)->address
== old_loc
->address
);
8984 if (*loc2p
== old_loc
)
8991 /* If this location is no longer present, and inserted, look if there's
8992 maybe a new location at the same address. If so, mark that one
8993 inserted, and don't remove this one. This is needed so that we
8994 don't have a time window where a breakpoint at certain location is not
8997 if (old_loc
->inserted
)
8999 /* If the location is inserted now, we might have to remove it. */
9001 if (found_object
&& should_be_inserted (old_loc
))
9003 /* The location is still present in the location list, and still
9004 should be inserted. Don't do anything. */
9009 /* The location is either no longer present, or got disabled.
9010 See if there's another location at the same address, in which
9011 case we don't need to remove this one from the target. */
9013 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9016 (loc2p
< bp_location
+ bp_location_count
9017 && (*loc2p
)->address
== old_loc
->address
);
9020 struct bp_location
*loc2
= *loc2p
;
9022 if (breakpoint_locations_match (loc2
, old_loc
))
9024 /* For the sake of should_be_inserted.
9025 Duplicates check below will fix up this later. */
9026 loc2
->duplicate
= 0;
9028 /* Read watchpoint locations are switched to
9029 access watchpoints, if the former are not
9030 supported, but the latter are. */
9031 if (is_hardware_watchpoint (old_loc
->owner
))
9033 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9034 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9037 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9040 loc2
->target_info
= old_loc
->target_info
;
9049 if (!keep_in_target
)
9051 if (remove_breakpoint (old_loc
, mark_uninserted
))
9053 /* This is just about all we can do. We could keep this
9054 location on the global list, and try to remove it next
9055 time, but there's no particular reason why we will
9058 Note that at this point, old_loc->owner is still valid,
9059 as delete_breakpoint frees the breakpoint only
9060 after calling us. */
9061 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9062 old_loc
->owner
->number
);
9070 if (removed
&& non_stop
9071 && breakpoint_address_is_meaningful (old_loc
->owner
)
9072 && !is_hardware_watchpoint (old_loc
->owner
))
9074 /* This location was removed from the target. In
9075 non-stop mode, a race condition is possible where
9076 we've removed a breakpoint, but stop events for that
9077 breakpoint are already queued and will arrive later.
9078 We apply an heuristic to be able to distinguish such
9079 SIGTRAPs from other random SIGTRAPs: we keep this
9080 breakpoint location for a bit, and will retire it
9081 after we see some number of events. The theory here
9082 is that reporting of events should, "on the average",
9083 be fair, so after a while we'll see events from all
9084 threads that have anything of interest, and no longer
9085 need to keep this breakpoint location around. We
9086 don't hold locations forever so to reduce chances of
9087 mistaking a non-breakpoint SIGTRAP for a breakpoint
9090 The heuristic failing can be disastrous on
9091 decr_pc_after_break targets.
9093 On decr_pc_after_break targets, like e.g., x86-linux,
9094 if we fail to recognize a late breakpoint SIGTRAP,
9095 because events_till_retirement has reached 0 too
9096 soon, we'll fail to do the PC adjustment, and report
9097 a random SIGTRAP to the user. When the user resumes
9098 the inferior, it will most likely immediately crash
9099 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9100 corrupted, because of being resumed e.g., in the
9101 middle of a multi-byte instruction, or skipped a
9102 one-byte instruction. This was actually seen happen
9103 on native x86-linux, and should be less rare on
9104 targets that do not support new thread events, like
9105 remote, due to the heuristic depending on
9108 Mistaking a random SIGTRAP for a breakpoint trap
9109 causes similar symptoms (PC adjustment applied when
9110 it shouldn't), but then again, playing with SIGTRAPs
9111 behind the debugger's back is asking for trouble.
9113 Since hardware watchpoint traps are always
9114 distinguishable from other traps, so we don't need to
9115 apply keep hardware watchpoint moribund locations
9116 around. We simply always ignore hardware watchpoint
9117 traps we can no longer explain. */
9119 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9120 old_loc
->owner
= NULL
;
9122 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9125 free_bp_location (old_loc
);
9129 /* Rescan breakpoints at the same address and section, marking the
9130 first one as "first" and any others as "duplicates". This is so
9131 that the bpt instruction is only inserted once. If we have a
9132 permanent breakpoint at the same place as BPT, make that one the
9133 official one, and the rest as duplicates. Permanent breakpoints
9134 are sorted first for the same address.
9136 Do the same for hardware watchpoints, but also considering the
9137 watchpoint's type (regular/access/read) and length. */
9139 bp_loc_first
= NULL
;
9140 wp_loc_first
= NULL
;
9141 awp_loc_first
= NULL
;
9142 rwp_loc_first
= NULL
;
9143 ALL_BP_LOCATIONS (loc
, locp
)
9145 struct breakpoint
*b
= loc
->owner
;
9146 struct bp_location
**loc_first_p
;
9148 if (b
->enable_state
== bp_disabled
9149 || b
->enable_state
== bp_call_disabled
9150 || b
->enable_state
== bp_startup_disabled
9152 || loc
->shlib_disabled
9153 || !breakpoint_address_is_meaningful (b
)
9154 || is_tracepoint (b
))
9157 /* Permanent breakpoint should always be inserted. */
9158 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9159 internal_error (__FILE__
, __LINE__
,
9160 _("allegedly permanent breakpoint is not "
9161 "actually inserted"));
9163 if (b
->type
== bp_hardware_watchpoint
)
9164 loc_first_p
= &wp_loc_first
;
9165 else if (b
->type
== bp_read_watchpoint
)
9166 loc_first_p
= &rwp_loc_first
;
9167 else if (b
->type
== bp_access_watchpoint
)
9168 loc_first_p
= &awp_loc_first
;
9170 loc_first_p
= &bp_loc_first
;
9172 if (*loc_first_p
== NULL
9173 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9174 || !breakpoint_locations_match (loc
, *loc_first_p
))
9183 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9184 && b
->enable_state
!= bp_permanent
)
9185 internal_error (__FILE__
, __LINE__
,
9186 _("another breakpoint was inserted on top of "
9187 "a permanent breakpoint"));
9190 if (breakpoints_always_inserted_mode () && should_insert
9191 && (have_live_inferiors ()
9192 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9193 insert_breakpoint_locations ();
9195 do_cleanups (cleanups
);
9199 breakpoint_retire_moribund (void)
9201 struct bp_location
*loc
;
9204 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9205 if (--(loc
->events_till_retirement
) == 0)
9207 free_bp_location (loc
);
9208 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9214 update_global_location_list_nothrow (int inserting
)
9216 struct gdb_exception e
;
9218 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9219 update_global_location_list (inserting
);
9222 /* Clear BPT from a BPS. */
9224 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9228 for (bs
= bps
; bs
; bs
= bs
->next
)
9229 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9231 bs
->breakpoint_at
= NULL
;
9233 /* bs->commands will be freed later. */
9237 /* Callback for iterate_over_threads. */
9239 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9241 struct breakpoint
*bpt
= data
;
9243 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9247 /* Delete a breakpoint and clean up all traces of it in the data
9251 delete_breakpoint (struct breakpoint
*bpt
)
9253 struct breakpoint
*b
;
9255 gdb_assert (bpt
!= NULL
);
9257 /* Has this bp already been deleted? This can happen because multiple
9258 lists can hold pointers to bp's. bpstat lists are especial culprits.
9260 One example of this happening is a watchpoint's scope bp. When the
9261 scope bp triggers, we notice that the watchpoint is out of scope, and
9262 delete it. We also delete its scope bp. But the scope bp is marked
9263 "auto-deleting", and is already on a bpstat. That bpstat is then
9264 checked for auto-deleting bp's, which are deleted.
9266 A real solution to this problem might involve reference counts in bp's,
9267 and/or giving them pointers back to their referencing bpstat's, and
9268 teaching delete_breakpoint to only free a bp's storage when no more
9269 references were extent. A cheaper bandaid was chosen. */
9270 if (bpt
->type
== bp_none
)
9273 /* At least avoid this stale reference until the reference counting of
9274 breakpoints gets resolved. */
9275 if (bpt
->related_breakpoint
!= NULL
)
9277 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9278 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9279 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9280 bpt
->related_breakpoint
= NULL
;
9283 observer_notify_breakpoint_deleted (bpt
->number
);
9285 if (breakpoint_chain
== bpt
)
9286 breakpoint_chain
= bpt
->next
;
9291 b
->next
= bpt
->next
;
9295 decref_counted_command_line (&bpt
->commands
);
9296 xfree (bpt
->cond_string
);
9297 xfree (bpt
->cond_exp
);
9298 xfree (bpt
->addr_string
);
9300 xfree (bpt
->exp_string
);
9301 value_free (bpt
->val
);
9302 xfree (bpt
->source_file
);
9303 xfree (bpt
->exec_pathname
);
9304 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9306 /* Be sure no bpstat's are pointing at it after it's been freed. */
9307 /* FIXME, how can we find all bpstat's?
9308 We just check stop_bpstat for now. Note that we cannot just
9309 remove bpstats pointing at bpt from the stop_bpstat list
9310 entirely, as breakpoint commands are associated with the bpstat;
9311 if we remove it here, then the later call to
9312 bpstat_do_actions (&stop_bpstat);
9313 in event-top.c won't do anything, and temporary breakpoints
9314 with commands won't work. */
9316 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9318 /* Now that breakpoint is removed from breakpoint
9319 list, update the global location list. This
9320 will remove locations that used to belong to
9321 this breakpoint. Do this before freeing
9322 the breakpoint itself, since remove_breakpoint
9323 looks at location's owner. It might be better
9324 design to have location completely self-contained,
9325 but it's not the case now. */
9326 update_global_location_list (0);
9329 /* On the chance that someone will soon try again to delete this same
9330 bp, we mark it as deleted before freeing its storage. */
9331 bpt
->type
= bp_none
;
9337 do_delete_breakpoint_cleanup (void *b
)
9339 delete_breakpoint (b
);
9343 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9345 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9348 /* A callback for map_breakpoint_numbers that calls
9349 delete_breakpoint. */
9352 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9354 delete_breakpoint (b
);
9358 delete_command (char *arg
, int from_tty
)
9360 struct breakpoint
*b
, *temp
;
9366 int breaks_to_delete
= 0;
9368 /* Delete all breakpoints if no argument.
9369 Do not delete internal or call-dummy breakpoints, these
9370 have to be deleted with an explicit breakpoint number argument. */
9373 if (b
->type
!= bp_call_dummy
9374 && b
->type
!= bp_std_terminate
9375 && b
->type
!= bp_shlib_event
9376 && b
->type
!= bp_jit_event
9377 && b
->type
!= bp_thread_event
9378 && b
->type
!= bp_overlay_event
9379 && b
->type
!= bp_longjmp_master
9380 && b
->type
!= bp_std_terminate_master
9383 breaks_to_delete
= 1;
9388 /* Ask user only if there are some breakpoints to delete. */
9390 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9392 ALL_BREAKPOINTS_SAFE (b
, temp
)
9394 if (b
->type
!= bp_call_dummy
9395 && b
->type
!= bp_std_terminate
9396 && b
->type
!= bp_shlib_event
9397 && b
->type
!= bp_thread_event
9398 && b
->type
!= bp_jit_event
9399 && b
->type
!= bp_overlay_event
9400 && b
->type
!= bp_longjmp_master
9401 && b
->type
!= bp_std_terminate_master
9403 delete_breakpoint (b
);
9408 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9412 all_locations_are_pending (struct bp_location
*loc
)
9414 for (; loc
; loc
= loc
->next
)
9415 if (!loc
->shlib_disabled
)
9420 /* Subroutine of update_breakpoint_locations to simplify it.
9421 Return non-zero if multiple fns in list LOC have the same name.
9422 Null names are ignored. */
9425 ambiguous_names_p (struct bp_location
*loc
)
9427 struct bp_location
*l
;
9428 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9429 (int (*) (const void *,
9430 const void *)) streq
,
9431 NULL
, xcalloc
, xfree
);
9433 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9436 const char *name
= l
->function_name
;
9438 /* Allow for some names to be NULL, ignore them. */
9442 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9444 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9459 update_breakpoint_locations (struct breakpoint
*b
,
9460 struct symtabs_and_lines sals
)
9464 struct bp_location
*existing_locations
= b
->loc
;
9466 /* If there's no new locations, and all existing locations
9467 are pending, don't do anything. This optimizes
9468 the common case where all locations are in the same
9469 shared library, that was unloaded. We'd like to
9470 retain the location, so that when the library
9471 is loaded again, we don't loose the enabled/disabled
9472 status of the individual locations. */
9473 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9478 for (i
= 0; i
< sals
.nelts
; ++i
)
9480 struct bp_location
*new_loc
=
9481 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9483 /* Reparse conditions, they might contain references to the
9485 if (b
->cond_string
!= NULL
)
9487 struct gdb_exception e
;
9490 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9492 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9497 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9498 b
->number
, e
.message
);
9499 new_loc
->enabled
= 0;
9503 if (b
->source_file
!= NULL
)
9504 xfree (b
->source_file
);
9505 if (sals
.sals
[i
].symtab
== NULL
)
9506 b
->source_file
= NULL
;
9508 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9510 if (b
->line_number
== 0)
9511 b
->line_number
= sals
.sals
[i
].line
;
9514 /* Update locations of permanent breakpoints. */
9515 if (b
->enable_state
== bp_permanent
)
9516 make_breakpoint_permanent (b
);
9518 /* If possible, carry over 'disable' status from existing breakpoints. */
9520 struct bp_location
*e
= existing_locations
;
9521 /* If there are multiple breakpoints with the same function name,
9522 e.g. for inline functions, comparing function names won't work.
9523 Instead compare pc addresses; this is just a heuristic as things
9524 may have moved, but in practice it gives the correct answer
9525 often enough until a better solution is found. */
9526 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9528 for (; e
; e
= e
->next
)
9530 if (!e
->enabled
&& e
->function_name
)
9532 struct bp_location
*l
= b
->loc
;
9533 if (have_ambiguous_names
)
9535 for (; l
; l
= l
->next
)
9536 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9537 l
->pspace
->aspace
, l
->address
))
9545 for (; l
; l
= l
->next
)
9546 if (l
->function_name
9547 && strcmp (e
->function_name
, l
->function_name
) == 0)
9557 update_global_location_list (1);
9561 /* Reset a breakpoint given it's struct breakpoint * BINT.
9562 The value we return ends up being the return value from catch_errors.
9563 Unused in this case. */
9566 breakpoint_re_set_one (void *bint
)
9568 /* get past catch_errs */
9569 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9571 int *not_found_ptr
= ¬_found
;
9572 struct symtabs_and_lines sals
= {0};
9573 struct symtabs_and_lines expanded
= {0};
9575 struct gdb_exception e
;
9576 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9581 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9585 case bp_hardware_breakpoint
:
9587 case bp_fast_tracepoint
:
9588 /* Do not attempt to re-set breakpoints disabled during startup. */
9589 if (b
->enable_state
== bp_startup_disabled
)
9592 if (b
->addr_string
== NULL
)
9594 /* Anything without a string can't be re-set. */
9595 delete_breakpoint (b
);
9599 set_language (b
->language
);
9600 input_radix
= b
->input_radix
;
9603 save_current_space_and_thread ();
9604 switch_to_program_space_and_thread (b
->pspace
);
9606 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9608 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9613 int not_found_and_ok
= 0;
9614 /* For pending breakpoints, it's expected that parsing
9615 will fail until the right shared library is loaded.
9616 User has already told to create pending breakpoints and
9617 don't need extra messages. If breakpoint is in bp_shlib_disabled
9618 state, then user already saw the message about that breakpoint
9619 being disabled, and don't want to see more errors. */
9621 && (b
->condition_not_parsed
9622 || (b
->loc
&& b
->loc
->shlib_disabled
)
9623 || b
->enable_state
== bp_disabled
))
9624 not_found_and_ok
= 1;
9626 if (!not_found_and_ok
)
9628 /* We surely don't want to warn about the same breakpoint
9629 10 times. One solution, implemented here, is disable
9630 the breakpoint on error. Another solution would be to
9631 have separate 'warning emitted' flag. Since this
9632 happens only when a binary has changed, I don't know
9633 which approach is better. */
9634 b
->enable_state
= bp_disabled
;
9635 throw_exception (e
);
9641 gdb_assert (sals
.nelts
== 1);
9643 resolve_sal_pc (&sals
.sals
[0]);
9644 if (b
->condition_not_parsed
&& s
&& s
[0])
9646 char *cond_string
= 0;
9650 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9651 &cond_string
, &thread
, &task
);
9653 b
->cond_string
= cond_string
;
9656 b
->condition_not_parsed
= 0;
9659 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9662 make_cleanup (xfree
, sals
.sals
);
9663 update_breakpoint_locations (b
, expanded
);
9667 case bp_hardware_watchpoint
:
9668 case bp_read_watchpoint
:
9669 case bp_access_watchpoint
:
9670 /* Watchpoint can be either on expression using entirely global variables,
9671 or it can be on local variables.
9673 Watchpoints of the first kind are never auto-deleted, and even persist
9674 across program restarts. Since they can use variables from shared
9675 libraries, we need to reparse expression as libraries are loaded
9678 Watchpoints on local variables can also change meaning as result
9679 of solib event. For example, if a watchpoint uses both a local and
9680 a global variables in expression, it's a local watchpoint, but
9681 unloading of a shared library will make the expression invalid.
9682 This is not a very common use case, but we still re-evaluate
9683 expression, to avoid surprises to the user.
9685 Note that for local watchpoints, we re-evaluate it only if
9686 watchpoints frame id is still valid. If it's not, it means
9687 the watchpoint is out of scope and will be deleted soon. In fact,
9688 I'm not sure we'll ever be called in this case.
9690 If a local watchpoint's frame id is still valid, then
9691 b->exp_valid_block is likewise valid, and we can safely use it.
9693 Don't do anything about disabled watchpoints, since they will
9694 be reevaluated again when enabled. */
9695 update_watchpoint (b
, 1 /* reparse */);
9697 /* We needn't really do anything to reset these, since the mask
9698 that requests them is unaffected by e.g., new libraries being
9704 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9706 /* Delete overlay event and longjmp master breakpoints; they will be
9707 reset later by breakpoint_re_set. */
9708 case bp_overlay_event
:
9709 case bp_longjmp_master
:
9710 case bp_std_terminate_master
:
9711 delete_breakpoint (b
);
9714 /* This breakpoint is special, it's set up when the inferior
9715 starts and we really don't want to touch it. */
9716 case bp_shlib_event
:
9718 /* Like bp_shlib_event, this breakpoint type is special.
9719 Once it is set up, we do not want to touch it. */
9720 case bp_thread_event
:
9722 /* Keep temporary breakpoints, which can be encountered when we step
9723 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9724 Otherwise these should have been blown away via the cleanup chain
9725 or by breakpoint_init_inferior when we rerun the executable. */
9728 case bp_watchpoint_scope
:
9730 case bp_std_terminate
:
9731 case bp_step_resume
:
9733 case bp_longjmp_resume
:
9738 do_cleanups (cleanups
);
9742 /* Re-set all breakpoints after symbols have been re-loaded. */
9744 breakpoint_re_set (void)
9746 struct breakpoint
*b
, *temp
;
9747 enum language save_language
;
9748 int save_input_radix
;
9749 struct cleanup
*old_chain
;
9751 save_language
= current_language
->la_language
;
9752 save_input_radix
= input_radix
;
9753 old_chain
= save_current_program_space ();
9755 ALL_BREAKPOINTS_SAFE (b
, temp
)
9757 /* Format possible error msg */
9758 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9760 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9761 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9762 do_cleanups (cleanups
);
9764 set_language (save_language
);
9765 input_radix
= save_input_radix
;
9767 jit_breakpoint_re_set ();
9769 do_cleanups (old_chain
);
9771 create_overlay_event_breakpoint ("_ovly_debug_event");
9772 create_longjmp_master_breakpoint ("longjmp");
9773 create_longjmp_master_breakpoint ("_longjmp");
9774 create_longjmp_master_breakpoint ("siglongjmp");
9775 create_longjmp_master_breakpoint ("_siglongjmp");
9776 create_std_terminate_master_breakpoint ("std::terminate()");
9779 /* Reset the thread number of this breakpoint:
9781 - If the breakpoint is for all threads, leave it as-is.
9782 - Else, reset it to the current thread for inferior_ptid. */
9784 breakpoint_re_set_thread (struct breakpoint
*b
)
9786 if (b
->thread
!= -1)
9788 if (in_thread_list (inferior_ptid
))
9789 b
->thread
= pid_to_thread_id (inferior_ptid
);
9791 /* We're being called after following a fork. The new fork is
9792 selected as current, and unless this was a vfork will have a
9793 different program space from the original thread. Reset that
9795 b
->loc
->pspace
= current_program_space
;
9799 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9800 If from_tty is nonzero, it prints a message to that effect,
9801 which ends with a period (no newline). */
9804 set_ignore_count (int bptnum
, int count
, int from_tty
)
9806 struct breakpoint
*b
;
9812 if (b
->number
== bptnum
)
9814 if (is_tracepoint (b
))
9816 if (from_tty
&& count
!= 0)
9817 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9822 b
->ignore_count
= count
;
9826 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9828 else if (count
== 1)
9829 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9832 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9835 breakpoints_changed ();
9836 observer_notify_breakpoint_modified (b
->number
);
9840 error (_("No breakpoint number %d."), bptnum
);
9844 make_breakpoint_silent (struct breakpoint
*b
)
9846 /* Silence the breakpoint. */
9850 /* Command to set ignore-count of breakpoint N to COUNT. */
9853 ignore_command (char *args
, int from_tty
)
9859 error_no_arg (_("a breakpoint number"));
9861 num
= get_number (&p
);
9863 error (_("bad breakpoint number: '%s'"), args
);
9865 error (_("Second argument (specified ignore-count) is missing."));
9867 set_ignore_count (num
,
9868 longest_to_int (value_as_long (parse_and_eval (p
))),
9871 printf_filtered ("\n");
9874 /* Call FUNCTION on each of the breakpoints
9875 whose numbers are given in ARGS. */
9878 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9885 struct breakpoint
*b
, *tmp
;
9889 error_no_arg (_("one or more breakpoint numbers"));
9896 num
= get_number_or_range (&p1
);
9899 warning (_("bad breakpoint number at or near '%s'"), p
);
9903 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9904 if (b
->number
== num
)
9906 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9909 if (related_breakpoint
)
9910 function (related_breakpoint
, data
);
9914 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9920 static struct bp_location
*
9921 find_location_by_number (char *number
)
9923 char *dot
= strchr (number
, '.');
9927 struct breakpoint
*b
;
9928 struct bp_location
*loc
;
9933 bp_num
= get_number_or_range (&p1
);
9935 error (_("Bad breakpoint number '%s'"), number
);
9938 if (b
->number
== bp_num
)
9943 if (!b
|| b
->number
!= bp_num
)
9944 error (_("Bad breakpoint number '%s'"), number
);
9947 loc_num
= get_number_or_range (&p1
);
9949 error (_("Bad breakpoint location number '%s'"), number
);
9953 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9956 error (_("Bad breakpoint location number '%s'"), dot
+1);
9962 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9963 If from_tty is nonzero, it prints a message to that effect,
9964 which ends with a period (no newline). */
9967 disable_breakpoint (struct breakpoint
*bpt
)
9969 /* Never disable a watchpoint scope breakpoint; we want to
9970 hit them when we leave scope so we can delete both the
9971 watchpoint and its scope breakpoint at that time. */
9972 if (bpt
->type
== bp_watchpoint_scope
)
9975 /* You can't disable permanent breakpoints. */
9976 if (bpt
->enable_state
== bp_permanent
)
9979 bpt
->enable_state
= bp_disabled
;
9981 update_global_location_list (0);
9983 observer_notify_breakpoint_modified (bpt
->number
);
9986 /* A callback for map_breakpoint_numbers that calls
9987 disable_breakpoint. */
9990 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9992 disable_breakpoint (b
);
9996 disable_command (char *args
, int from_tty
)
9998 struct breakpoint
*bpt
;
10001 ALL_BREAKPOINTS (bpt
)
10005 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10008 case bp_breakpoint
:
10009 case bp_tracepoint
:
10010 case bp_fast_tracepoint
:
10011 case bp_catchpoint
:
10012 case bp_hardware_breakpoint
:
10013 case bp_watchpoint
:
10014 case bp_hardware_watchpoint
:
10015 case bp_read_watchpoint
:
10016 case bp_access_watchpoint
:
10017 disable_breakpoint (bpt
);
10021 else if (strchr (args
, '.'))
10023 struct bp_location
*loc
= find_location_by_number (args
);
10026 update_global_location_list (0);
10029 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10033 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10035 int target_resources_ok
;
10037 if (bpt
->type
== bp_hardware_breakpoint
)
10040 i
= hw_breakpoint_used_count ();
10041 target_resources_ok
=
10042 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10044 if (target_resources_ok
== 0)
10045 error (_("No hardware breakpoint support in the target."));
10046 else if (target_resources_ok
< 0)
10047 error (_("Hardware breakpoints used exceeds limit."));
10050 if (is_watchpoint (bpt
))
10052 struct gdb_exception e
;
10054 TRY_CATCH (e
, RETURN_MASK_ALL
)
10056 update_watchpoint (bpt
, 1 /* reparse */);
10060 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10066 if (bpt
->enable_state
!= bp_permanent
)
10067 bpt
->enable_state
= bp_enabled
;
10068 bpt
->disposition
= disposition
;
10069 update_global_location_list (1);
10070 breakpoints_changed ();
10072 observer_notify_breakpoint_modified (bpt
->number
);
10077 enable_breakpoint (struct breakpoint
*bpt
)
10079 do_enable_breakpoint (bpt
, bpt
->disposition
);
10082 /* A callback for map_breakpoint_numbers that calls
10083 enable_breakpoint. */
10086 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10088 enable_breakpoint (b
);
10091 /* The enable command enables the specified breakpoints (or all defined
10092 breakpoints) so they once again become (or continue to be) effective
10093 in stopping the inferior. */
10096 enable_command (char *args
, int from_tty
)
10098 struct breakpoint
*bpt
;
10101 ALL_BREAKPOINTS (bpt
)
10105 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10108 case bp_breakpoint
:
10109 case bp_tracepoint
:
10110 case bp_fast_tracepoint
:
10111 case bp_catchpoint
:
10112 case bp_hardware_breakpoint
:
10113 case bp_watchpoint
:
10114 case bp_hardware_watchpoint
:
10115 case bp_read_watchpoint
:
10116 case bp_access_watchpoint
:
10117 enable_breakpoint (bpt
);
10121 else if (strchr (args
, '.'))
10123 struct bp_location
*loc
= find_location_by_number (args
);
10126 update_global_location_list (1);
10129 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10133 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10135 do_enable_breakpoint (bpt
, disp_disable
);
10139 enable_once_command (char *args
, int from_tty
)
10141 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10145 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10147 do_enable_breakpoint (bpt
, disp_del
);
10151 enable_delete_command (char *args
, int from_tty
)
10153 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10157 set_breakpoint_cmd (char *args
, int from_tty
)
10162 show_breakpoint_cmd (char *args
, int from_tty
)
10166 /* Invalidate last known value of any hardware watchpoint if
10167 the memory which that value represents has been written to by
10171 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10172 const bfd_byte
*data
)
10174 struct breakpoint
*bp
;
10176 ALL_BREAKPOINTS (bp
)
10177 if (bp
->enable_state
== bp_enabled
10178 && bp
->type
== bp_hardware_watchpoint
10179 && bp
->val_valid
&& bp
->val
)
10181 struct bp_location
*loc
;
10183 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10184 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10185 && loc
->address
+ loc
->length
> addr
10186 && addr
+ len
> loc
->address
)
10188 value_free (bp
->val
);
10195 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10197 struct symtabs_and_lines
10198 decode_line_spec_1 (char *string
, int funfirstline
)
10200 struct symtabs_and_lines sals
;
10203 error (_("Empty line specification."));
10204 if (default_breakpoint_valid
)
10205 sals
= decode_line_1 (&string
, funfirstline
,
10206 default_breakpoint_symtab
,
10207 default_breakpoint_line
,
10208 (char ***) NULL
, NULL
);
10210 sals
= decode_line_1 (&string
, funfirstline
,
10211 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10213 error (_("Junk at end of line specification: %s"), string
);
10217 /* Create and insert a raw software breakpoint at PC. Return an
10218 identifier, which should be used to remove the breakpoint later.
10219 In general, places which call this should be using something on the
10220 breakpoint chain instead; this function should be eliminated
10224 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10225 struct address_space
*aspace
, CORE_ADDR pc
)
10227 struct bp_target_info
*bp_tgt
;
10229 bp_tgt
= XZALLOC (struct bp_target_info
);
10231 bp_tgt
->placed_address_space
= aspace
;
10232 bp_tgt
->placed_address
= pc
;
10234 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10236 /* Could not insert the breakpoint. */
10244 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10247 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10249 struct bp_target_info
*bp_tgt
= bp
;
10252 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10258 /* One (or perhaps two) breakpoints used for software single stepping. */
10260 static void *single_step_breakpoints
[2];
10261 static struct gdbarch
*single_step_gdbarch
[2];
10263 /* Create and insert a breakpoint for software single step. */
10266 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10267 struct address_space
*aspace
, CORE_ADDR next_pc
)
10271 if (single_step_breakpoints
[0] == NULL
)
10273 bpt_p
= &single_step_breakpoints
[0];
10274 single_step_gdbarch
[0] = gdbarch
;
10278 gdb_assert (single_step_breakpoints
[1] == NULL
);
10279 bpt_p
= &single_step_breakpoints
[1];
10280 single_step_gdbarch
[1] = gdbarch
;
10283 /* NOTE drow/2006-04-11: A future improvement to this function would be
10284 to only create the breakpoints once, and actually put them on the
10285 breakpoint chain. That would let us use set_raw_breakpoint. We could
10286 adjust the addresses each time they were needed. Doing this requires
10287 corresponding changes elsewhere where single step breakpoints are
10288 handled, however. So, for now, we use this. */
10290 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10291 if (*bpt_p
== NULL
)
10292 error (_("Could not insert single-step breakpoint at %s"),
10293 paddress (gdbarch
, next_pc
));
10296 /* Remove and delete any breakpoints used for software single step. */
10299 remove_single_step_breakpoints (void)
10301 gdb_assert (single_step_breakpoints
[0] != NULL
);
10303 /* See insert_single_step_breakpoint for more about this deprecated
10305 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10306 single_step_breakpoints
[0]);
10307 single_step_gdbarch
[0] = NULL
;
10308 single_step_breakpoints
[0] = NULL
;
10310 if (single_step_breakpoints
[1] != NULL
)
10312 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10313 single_step_breakpoints
[1]);
10314 single_step_gdbarch
[1] = NULL
;
10315 single_step_breakpoints
[1] = NULL
;
10319 /* Check whether a software single-step breakpoint is inserted at PC. */
10322 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
10327 for (i
= 0; i
< 2; i
++)
10329 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10331 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10332 bp_tgt
->placed_address
,
10340 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10341 non-zero otherwise. */
10343 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10345 if (syscall_catchpoint_p (bp
)
10346 && bp
->enable_state
!= bp_disabled
10347 && bp
->enable_state
!= bp_call_disabled
)
10354 catch_syscall_enabled (void)
10356 struct inferior
*inf
= current_inferior ();
10358 return inf
->total_syscalls_count
!= 0;
10362 catching_syscall_number (int syscall_number
)
10364 struct breakpoint
*bp
;
10366 ALL_BREAKPOINTS (bp
)
10367 if (is_syscall_catchpoint_enabled (bp
))
10369 if (bp
->syscalls_to_be_caught
)
10373 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10375 if (syscall_number
== iter
)
10385 /* Complete syscall names. Used by "catch syscall". */
10387 catch_syscall_completer (struct cmd_list_element
*cmd
,
10388 char *text
, char *word
)
10390 const char **list
= get_syscall_names ();
10392 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10395 /* Tracepoint-specific operations. */
10397 /* Set tracepoint count to NUM. */
10399 set_tracepoint_count (int num
)
10401 tracepoint_count
= num
;
10402 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10406 trace_command (char *arg
, int from_tty
)
10408 if (create_breakpoint (get_current_arch (),
10410 NULL
, 0, 1 /* parse arg */,
10411 0 /* tempflag */, 0 /* hardwareflag */,
10413 0 /* Ignore count */,
10414 pending_break_support
,
10418 set_tracepoint_count (breakpoint_count
);
10422 ftrace_command (char *arg
, int from_tty
)
10424 if (create_breakpoint (get_current_arch (),
10426 NULL
, 0, 1 /* parse arg */,
10427 0 /* tempflag */, 1 /* hardwareflag */,
10429 0 /* Ignore count */,
10430 pending_break_support
,
10434 set_tracepoint_count (breakpoint_count
);
10437 /* Set up a fake reader function that gets command lines from a linked
10438 list that was acquired during tracepoint uploading. */
10440 static struct uploaded_tp
*this_utp
;
10441 static int next_cmd
;
10444 read_uploaded_action (void)
10448 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
10455 /* Given information about a tracepoint as recorded on a target (which
10456 can be either a live system or a trace file), attempt to create an
10457 equivalent GDB tracepoint. This is not a reliable process, since
10458 the target does not necessarily have all the information used when
10459 the tracepoint was originally defined. */
10461 struct breakpoint
*
10462 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10464 char *addr_str
, small_buf
[100];
10465 struct breakpoint
*tp
;
10467 if (utp
->at_string
)
10468 addr_str
= utp
->at_string
;
10471 /* In the absence of a source location, fall back to raw
10472 address. Since there is no way to confirm that the address
10473 means the same thing as when the trace was started, warn the
10475 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10477 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10478 addr_str
= small_buf
;
10481 /* There's not much we can do with a sequence of bytecodes. */
10482 if (utp
->cond
&& !utp
->cond_string
)
10483 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10486 if (!create_breakpoint (get_current_arch (),
10488 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10490 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10492 0 /* Ignore count */,
10493 pending_break_support
,
10496 utp
->enabled
/* enabled */))
10499 set_tracepoint_count (breakpoint_count
);
10501 /* Get the tracepoint we just created. */
10502 tp
= get_tracepoint (tracepoint_count
);
10503 gdb_assert (tp
!= NULL
);
10507 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10509 trace_pass_command (small_buf
, 0);
10512 /* If we have uploaded versions of the original commands, set up a
10513 special-purpose "reader" function and call the usual command line
10514 reader, then pass the result to the breakpoint command-setting
10516 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
10518 struct command_line
*cmd_list
;
10523 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10525 breakpoint_set_commands (tp
, cmd_list
);
10527 else if (!VEC_empty (char_ptr
, utp
->actions
)
10528 || !VEC_empty (char_ptr
, utp
->step_actions
))
10529 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10535 /* Print information on tracepoint number TPNUM_EXP, or all if
10539 tracepoints_info (char *tpnum_exp
, int from_tty
)
10541 int tpnum
= -1, num_printed
;
10544 tpnum
= parse_and_eval_long (tpnum_exp
);
10546 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
10548 if (num_printed
== 0)
10551 ui_out_message (uiout
, 0, "No tracepoints.\n");
10553 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
10556 default_collect_info ();
10559 /* The 'enable trace' command enables tracepoints.
10560 Not supported by all targets. */
10562 enable_trace_command (char *args
, int from_tty
)
10564 enable_command (args
, from_tty
);
10567 /* The 'disable trace' command disables tracepoints.
10568 Not supported by all targets. */
10570 disable_trace_command (char *args
, int from_tty
)
10572 disable_command (args
, from_tty
);
10575 /* Remove a tracepoint (or all if no argument) */
10577 delete_trace_command (char *arg
, int from_tty
)
10579 struct breakpoint
*b
, *temp
;
10585 int breaks_to_delete
= 0;
10587 /* Delete all breakpoints if no argument.
10588 Do not delete internal or call-dummy breakpoints, these
10589 have to be deleted with an explicit breakpoint number argument. */
10590 ALL_TRACEPOINTS (b
)
10592 if (b
->number
>= 0)
10594 breaks_to_delete
= 1;
10599 /* Ask user only if there are some breakpoints to delete. */
10601 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10603 ALL_BREAKPOINTS_SAFE (b
, temp
)
10605 if (is_tracepoint (b
)
10607 delete_breakpoint (b
);
10612 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10615 /* Set passcount for tracepoint.
10617 First command argument is passcount, second is tracepoint number.
10618 If tracepoint number omitted, apply to most recently defined.
10619 Also accepts special argument "all". */
10622 trace_pass_command (char *args
, int from_tty
)
10624 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10625 unsigned int count
;
10628 if (args
== 0 || *args
== 0)
10629 error (_("passcount command requires an argument (count + optional TP num)"));
10631 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10633 while (*args
&& isspace ((int) *args
))
10636 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10638 args
+= 3; /* Skip special argument "all". */
10641 error (_("Junk at end of arguments."));
10644 t1
= get_tracepoint_by_number (&args
, 1, 1);
10650 ALL_TRACEPOINTS (t2
)
10651 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10653 t2
->pass_count
= count
;
10654 observer_notify_tracepoint_modified (t2
->number
);
10656 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10657 t2
->number
, count
);
10659 if (! all
&& *args
)
10660 t1
= get_tracepoint_by_number (&args
, 1, 0);
10666 struct breakpoint
*
10667 get_tracepoint (int num
)
10669 struct breakpoint
*t
;
10671 ALL_TRACEPOINTS (t
)
10672 if (t
->number
== num
)
10678 /* Find the tracepoint with the given target-side number (which may be
10679 different from the tracepoint number after disconnecting and
10682 struct breakpoint
*
10683 get_tracepoint_by_number_on_target (int num
)
10685 struct breakpoint
*t
;
10687 ALL_TRACEPOINTS (t
)
10688 if (t
->number_on_target
== num
)
10694 /* Utility: parse a tracepoint number and look it up in the list.
10695 If MULTI_P is true, there might be a range of tracepoints in ARG.
10696 if OPTIONAL_P is true, then if the argument is missing, the most
10697 recent tracepoint (tracepoint_count) is returned. */
10698 struct breakpoint
*
10699 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10701 extern int tracepoint_count
;
10702 struct breakpoint
*t
;
10704 char *instring
= arg
== NULL
? NULL
: *arg
;
10706 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10709 tpnum
= tracepoint_count
;
10711 error_no_arg (_("tracepoint number"));
10714 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10718 if (instring
&& *instring
)
10719 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10722 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10726 ALL_TRACEPOINTS (t
)
10727 if (t
->number
== tpnum
)
10732 /* FIXME: if we are in the middle of a range we don't want to give
10733 a message. The current interface to get_number_or_range doesn't
10734 allow us to discover this. */
10735 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10739 /* Save information on user settable breakpoints (watchpoints, etc) to
10740 a new script file named FILENAME. If FILTER is non-NULL, call it
10741 on each breakpoint and only include the ones for which it returns
10745 save_breakpoints (char *filename
, int from_tty
,
10746 int (*filter
) (const struct breakpoint
*))
10748 struct breakpoint
*tp
;
10751 struct cleanup
*cleanup
;
10752 struct ui_file
*fp
;
10753 int extra_trace_bits
= 0;
10755 if (filename
== 0 || *filename
== 0)
10756 error (_("Argument required (file name in which to save)"));
10758 /* See if we have anything to save. */
10759 ALL_BREAKPOINTS (tp
)
10761 /* Skip internal and momentary breakpoints. */
10762 if (!user_settable_breakpoint (tp
))
10765 /* If we have a filter, only save the breakpoints it accepts. */
10766 if (filter
&& !filter (tp
))
10771 if (is_tracepoint (tp
))
10773 extra_trace_bits
= 1;
10775 /* We can stop searching. */
10782 warning (_("Nothing to save."));
10786 pathname
= tilde_expand (filename
);
10787 cleanup
= make_cleanup (xfree
, pathname
);
10788 fp
= gdb_fopen (pathname
, "w");
10790 error (_("Unable to open file '%s' for saving (%s)"),
10791 filename
, safe_strerror (errno
));
10792 make_cleanup_ui_file_delete (fp
);
10794 if (extra_trace_bits
)
10795 save_trace_state_variables (fp
);
10797 ALL_BREAKPOINTS (tp
)
10799 /* Skip internal and momentary breakpoints. */
10800 if (!user_settable_breakpoint (tp
))
10803 /* If we have a filter, only save the breakpoints it accepts. */
10804 if (filter
&& !filter (tp
))
10807 if (tp
->ops
!= NULL
)
10808 (tp
->ops
->print_recreate
) (tp
, fp
);
10811 if (tp
->type
== bp_fast_tracepoint
)
10812 fprintf_unfiltered (fp
, "ftrace");
10813 else if (tp
->type
== bp_tracepoint
)
10814 fprintf_unfiltered (fp
, "trace");
10815 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10816 fprintf_unfiltered (fp
, "tbreak");
10817 else if (tp
->type
== bp_breakpoint
)
10818 fprintf_unfiltered (fp
, "break");
10819 else if (tp
->type
== bp_hardware_breakpoint
10820 && tp
->disposition
== disp_del
)
10821 fprintf_unfiltered (fp
, "thbreak");
10822 else if (tp
->type
== bp_hardware_breakpoint
)
10823 fprintf_unfiltered (fp
, "hbreak");
10824 else if (tp
->type
== bp_watchpoint
)
10825 fprintf_unfiltered (fp
, "watch");
10826 else if (tp
->type
== bp_hardware_watchpoint
)
10827 fprintf_unfiltered (fp
, "watch");
10828 else if (tp
->type
== bp_read_watchpoint
)
10829 fprintf_unfiltered (fp
, "rwatch");
10830 else if (tp
->type
== bp_access_watchpoint
)
10831 fprintf_unfiltered (fp
, "awatch");
10833 internal_error (__FILE__
, __LINE__
,
10834 _("unhandled breakpoint type %d"), (int) tp
->type
);
10836 if (tp
->exp_string
)
10837 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
10838 else if (tp
->addr_string
)
10839 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10844 sprintf_vma (tmp
, tp
->loc
->address
);
10845 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10849 if (tp
->thread
!= -1)
10850 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
10853 fprintf_unfiltered (fp
, " task %d", tp
->task
);
10855 fprintf_unfiltered (fp
, "\n");
10857 /* Note, we can't rely on tp->number for anything, as we can't
10858 assume the recreated breakpoint numbers will match. Use $bpnum
10861 if (tp
->cond_string
)
10862 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
10864 if (tp
->ignore_count
)
10865 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
10867 if (tp
->pass_count
)
10868 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10872 volatile struct gdb_exception ex
;
10874 fprintf_unfiltered (fp
, " commands\n");
10876 ui_out_redirect (uiout
, fp
);
10877 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10879 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10881 ui_out_redirect (uiout
, NULL
);
10884 throw_exception (ex
);
10886 fprintf_unfiltered (fp
, " end\n");
10889 if (tp
->enable_state
== bp_disabled
)
10890 fprintf_unfiltered (fp
, "disable\n");
10892 /* If this is a multi-location breakpoint, check if the locations
10893 should be individually disabled. Watchpoint locations are
10894 special, and not user visible. */
10895 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
10897 struct bp_location
*loc
;
10900 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
10902 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
10906 if (extra_trace_bits
&& *default_collect
)
10907 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10909 do_cleanups (cleanup
);
10911 printf_filtered (_("Saved to file '%s'.\n"), filename
);
10914 /* The `save breakpoints' command. */
10917 save_breakpoints_command (char *args
, int from_tty
)
10919 save_breakpoints (args
, from_tty
, NULL
);
10922 /* The `save tracepoints' command. */
10925 save_tracepoints_command (char *args
, int from_tty
)
10927 save_breakpoints (args
, from_tty
, is_tracepoint
);
10930 /* Create a vector of all tracepoints. */
10932 VEC(breakpoint_p
) *
10935 VEC(breakpoint_p
) *tp_vec
= 0;
10936 struct breakpoint
*tp
;
10938 ALL_TRACEPOINTS (tp
)
10940 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10947 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10948 It is defined as a macro to prevent duplication.
10949 COMMAND should be a string constant containing the name of the command. */
10950 #define BREAK_ARGS_HELP(command) \
10951 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10952 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10953 If a line number is specified, break at start of code for that line.\n\
10954 If a function is specified, break at start of code for that function.\n\
10955 If an address is specified, break at that exact address.\n\
10956 With no LOCATION, uses current execution address of selected stack frame.\n\
10957 This is useful for breaking on return to a stack frame.\n\
10959 THREADNUM is the number from \"info threads\".\n\
10960 CONDITION is a boolean expression.\n\
10962 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10964 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10966 /* List of subcommands for "catch". */
10967 static struct cmd_list_element
*catch_cmdlist
;
10969 /* List of subcommands for "tcatch". */
10970 static struct cmd_list_element
*tcatch_cmdlist
;
10972 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10973 lists, and pass some additional user data to the command function. */
10975 add_catch_command (char *name
, char *docstring
,
10976 void (*sfunc
) (char *args
, int from_tty
,
10977 struct cmd_list_element
*command
),
10978 char **(*completer
) (struct cmd_list_element
*cmd
,
10979 char *text
, char *word
),
10980 void *user_data_catch
,
10981 void *user_data_tcatch
)
10983 struct cmd_list_element
*command
;
10985 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10987 set_cmd_sfunc (command
, sfunc
);
10988 set_cmd_context (command
, user_data_catch
);
10989 set_cmd_completer (command
, completer
);
10991 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10993 set_cmd_sfunc (command
, sfunc
);
10994 set_cmd_context (command
, user_data_tcatch
);
10995 set_cmd_completer (command
, completer
);
10999 clear_syscall_counts (struct inferior
*inf
)
11001 inf
->total_syscalls_count
= 0;
11002 inf
->any_syscall_count
= 0;
11003 VEC_free (int, inf
->syscalls_counts
);
11007 save_command (char *arg
, int from_tty
)
11009 printf_unfiltered (_("\
11010 \"save\" must be followed by the name of a save subcommand.\n"));
11011 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11015 _initialize_breakpoint (void)
11017 struct cmd_list_element
*c
;
11019 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11020 observer_attach_inferior_exit (clear_syscall_counts
);
11021 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11023 breakpoint_chain
= 0;
11024 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11025 before a breakpoint is set. */
11026 breakpoint_count
= 0;
11028 tracepoint_count
= 0;
11030 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11031 Set ignore-count of breakpoint number N to COUNT.\n\
11032 Usage is `ignore N COUNT'."));
11034 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11036 add_com ("commands", class_breakpoint
, commands_command
, _("\
11037 Set commands to be executed when a breakpoint is hit.\n\
11038 Give breakpoint number as argument after \"commands\".\n\
11039 With no argument, the targeted breakpoint is the last one set.\n\
11040 The commands themselves follow starting on the next line.\n\
11041 Type a line containing \"end\" to indicate the end of them.\n\
11042 Give \"silent\" as the first line to make the breakpoint silent;\n\
11043 then no output is printed when it is hit, except what the commands print."));
11045 add_com ("condition", class_breakpoint
, condition_command
, _("\
11046 Specify breakpoint number N to break only if COND is true.\n\
11047 Usage is `condition N COND', where N is an integer and COND is an\n\
11048 expression to be evaluated whenever breakpoint N is reached."));
11050 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11051 Set a temporary breakpoint.\n\
11052 Like \"break\" except the breakpoint is only temporary,\n\
11053 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11054 by using \"enable delete\" on the breakpoint number.\n\
11056 BREAK_ARGS_HELP ("tbreak")));
11057 set_cmd_completer (c
, location_completer
);
11059 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11060 Set a hardware assisted breakpoint.\n\
11061 Like \"break\" except the breakpoint requires hardware support,\n\
11062 some target hardware may not have this support.\n\
11064 BREAK_ARGS_HELP ("hbreak")));
11065 set_cmd_completer (c
, location_completer
);
11067 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11068 Set a temporary hardware assisted breakpoint.\n\
11069 Like \"hbreak\" except the breakpoint is only temporary,\n\
11070 so it will be deleted when hit.\n\
11072 BREAK_ARGS_HELP ("thbreak")));
11073 set_cmd_completer (c
, location_completer
);
11075 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11076 Enable some breakpoints.\n\
11077 Give breakpoint numbers (separated by spaces) as arguments.\n\
11078 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11079 This is used to cancel the effect of the \"disable\" command.\n\
11080 With a subcommand you can enable temporarily."),
11081 &enablelist
, "enable ", 1, &cmdlist
);
11083 add_com ("ab", class_breakpoint
, enable_command
, _("\
11084 Enable some breakpoints.\n\
11085 Give breakpoint numbers (separated by spaces) as arguments.\n\
11086 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11087 This is used to cancel the effect of the \"disable\" command.\n\
11088 With a subcommand you can enable temporarily."));
11090 add_com_alias ("en", "enable", class_breakpoint
, 1);
11092 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11093 Enable some breakpoints.\n\
11094 Give breakpoint numbers (separated by spaces) as arguments.\n\
11095 This is used to cancel the effect of the \"disable\" command.\n\
11096 May be abbreviated to simply \"enable\".\n"),
11097 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11099 add_cmd ("once", no_class
, enable_once_command
, _("\
11100 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11101 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11104 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11105 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11106 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11109 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11110 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11111 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11114 add_cmd ("once", no_class
, enable_once_command
, _("\
11115 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11116 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11119 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
11120 Disable some breakpoints.\n\
11121 Arguments are breakpoint numbers with spaces in between.\n\
11122 To disable all breakpoints, give no argument.\n\
11123 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11124 &disablelist
, "disable ", 1, &cmdlist
);
11125 add_com_alias ("dis", "disable", class_breakpoint
, 1);
11126 add_com_alias ("disa", "disable", class_breakpoint
, 1);
11128 add_com ("sb", class_breakpoint
, disable_command
, _("\
11129 Disable some breakpoints.\n\
11130 Arguments are breakpoint numbers with spaces in between.\n\
11131 To disable all breakpoints, give no argument.\n\
11132 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11134 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
11135 Disable some breakpoints.\n\
11136 Arguments are breakpoint numbers with spaces in between.\n\
11137 To disable all breakpoints, give no argument.\n\
11138 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11139 This command may be abbreviated \"disable\"."),
11142 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
11143 Delete some breakpoints or auto-display expressions.\n\
11144 Arguments are breakpoint numbers with spaces in between.\n\
11145 To delete all breakpoints, give no argument.\n\
11147 Also a prefix command for deletion of other GDB objects.\n\
11148 The \"unset\" command is also an alias for \"delete\"."),
11149 &deletelist
, "delete ", 1, &cmdlist
);
11150 add_com_alias ("d", "delete", class_breakpoint
, 1);
11151 add_com_alias ("del", "delete", class_breakpoint
, 1);
11153 add_com ("db", class_breakpoint
, delete_command
, _("\
11154 Delete some breakpoints.\n\
11155 Arguments are breakpoint numbers with spaces in between.\n\
11156 To delete all breakpoints, give no argument.\n"));
11158 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
11159 Delete some breakpoints or auto-display expressions.\n\
11160 Arguments are breakpoint numbers with spaces in between.\n\
11161 To delete all breakpoints, give no argument.\n\
11162 This command may be abbreviated \"delete\"."),
11165 add_com ("clear", class_breakpoint
, clear_command
, _("\
11166 Clear breakpoint at specified line or function.\n\
11167 Argument may be line number, function name, or \"*\" and an address.\n\
11168 If line number is specified, all breakpoints in that line are cleared.\n\
11169 If function is specified, breakpoints at beginning of function are cleared.\n\
11170 If an address is specified, breakpoints at that address are cleared.\n\
11172 With no argument, clears all breakpoints in the line that the selected frame\n\
11173 is executing in.\n\
11175 See also the \"delete\" command which clears breakpoints by number."));
11177 c
= add_com ("break", class_breakpoint
, break_command
, _("\
11178 Set breakpoint at specified line or function.\n"
11179 BREAK_ARGS_HELP ("break")));
11180 set_cmd_completer (c
, location_completer
);
11182 add_com_alias ("b", "break", class_run
, 1);
11183 add_com_alias ("br", "break", class_run
, 1);
11184 add_com_alias ("bre", "break", class_run
, 1);
11185 add_com_alias ("brea", "break", class_run
, 1);
11188 add_com_alias ("ba", "break", class_breakpoint
, 1);
11192 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
11193 Break in function/address or break at a line in the current file."),
11194 &stoplist
, "stop ", 1, &cmdlist
);
11195 add_cmd ("in", class_breakpoint
, stopin_command
,
11196 _("Break in function or address."), &stoplist
);
11197 add_cmd ("at", class_breakpoint
, stopat_command
,
11198 _("Break at a line in the current file."), &stoplist
);
11199 add_com ("status", class_info
, breakpoints_info
, _("\
11200 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11201 The \"Type\" column indicates one of:\n\
11202 \tbreakpoint - normal breakpoint\n\
11203 \twatchpoint - watchpoint\n\
11204 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11205 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11206 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11207 address and file/line number respectively.\n\
11209 Convenience variable \"$_\" and default examine address for \"x\"\n\
11210 are set to the address of the last breakpoint listed unless the command\n\
11211 is prefixed with \"server \".\n\n\
11212 Convenience variable \"$bpnum\" contains the number of the last\n\
11213 breakpoint set."));
11216 add_info ("breakpoints", breakpoints_info
, _("\
11217 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11218 The \"Type\" column indicates one of:\n\
11219 \tbreakpoint - normal breakpoint\n\
11220 \twatchpoint - watchpoint\n\
11221 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11222 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11223 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11224 address and file/line number respectively.\n\
11226 Convenience variable \"$_\" and default examine address for \"x\"\n\
11227 are set to the address of the last breakpoint listed unless the command\n\
11228 is prefixed with \"server \".\n\n\
11229 Convenience variable \"$bpnum\" contains the number of the last\n\
11230 breakpoint set."));
11232 add_info_alias ("b", "breakpoints", 1);
11235 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11236 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11237 The \"Type\" column indicates one of:\n\
11238 \tbreakpoint - normal breakpoint\n\
11239 \twatchpoint - watchpoint\n\
11240 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11241 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11242 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11243 address and file/line number respectively.\n\
11245 Convenience variable \"$_\" and default examine address for \"x\"\n\
11246 are set to the address of the last breakpoint listed unless the command\n\
11247 is prefixed with \"server \".\n\n\
11248 Convenience variable \"$bpnum\" contains the number of the last\n\
11249 breakpoint set."));
11251 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11252 Status of all breakpoints, or breakpoint number NUMBER.\n\
11253 The \"Type\" column indicates one of:\n\
11254 \tbreakpoint - normal breakpoint\n\
11255 \twatchpoint - watchpoint\n\
11256 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11257 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11258 \tuntil - internal breakpoint used by the \"until\" command\n\
11259 \tfinish - internal breakpoint used by the \"finish\" command\n\
11260 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11261 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11262 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11263 address and file/line number respectively.\n\
11265 Convenience variable \"$_\" and default examine address for \"x\"\n\
11266 are set to the address of the last breakpoint listed unless the command\n\
11267 is prefixed with \"server \".\n\n\
11268 Convenience variable \"$bpnum\" contains the number of the last\n\
11270 &maintenanceinfolist
);
11272 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11273 Set catchpoints to catch events."),
11274 &catch_cmdlist
, "catch ",
11275 0/*allow-unknown*/, &cmdlist
);
11277 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11278 Set temporary catchpoints to catch events."),
11279 &tcatch_cmdlist
, "tcatch ",
11280 0/*allow-unknown*/, &cmdlist
);
11282 /* Add catch and tcatch sub-commands. */
11283 add_catch_command ("catch", _("\
11284 Catch an exception, when caught.\n\
11285 With an argument, catch only exceptions with the given name."),
11286 catch_catch_command
,
11290 add_catch_command ("throw", _("\
11291 Catch an exception, when thrown.\n\
11292 With an argument, catch only exceptions with the given name."),
11293 catch_throw_command
,
11297 add_catch_command ("fork", _("Catch calls to fork."),
11298 catch_fork_command_1
,
11300 (void *) (uintptr_t) catch_fork_permanent
,
11301 (void *) (uintptr_t) catch_fork_temporary
);
11302 add_catch_command ("vfork", _("Catch calls to vfork."),
11303 catch_fork_command_1
,
11305 (void *) (uintptr_t) catch_vfork_permanent
,
11306 (void *) (uintptr_t) catch_vfork_temporary
);
11307 add_catch_command ("exec", _("Catch calls to exec."),
11308 catch_exec_command_1
,
11312 add_catch_command ("syscall", _("\
11313 Catch system calls by their names and/or numbers.\n\
11314 Arguments say which system calls to catch. If no arguments\n\
11315 are given, every system call will be caught.\n\
11316 Arguments, if given, should be one or more system call names\n\
11317 (if your system supports that), or system call numbers."),
11318 catch_syscall_command_1
,
11319 catch_syscall_completer
,
11322 add_catch_command ("exception", _("\
11323 Catch Ada exceptions, when raised.\n\
11324 With an argument, catch only exceptions with the given name."),
11325 catch_ada_exception_command
,
11329 add_catch_command ("assert", _("\
11330 Catch failed Ada assertions, when raised.\n\
11331 With an argument, catch only exceptions with the given name."),
11332 catch_assert_command
,
11337 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11338 Set a watchpoint for an expression.\n\
11339 A watchpoint stops execution of your program whenever the value of\n\
11340 an expression changes."));
11341 set_cmd_completer (c
, expression_completer
);
11343 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11344 Set a read watchpoint for an expression.\n\
11345 A watchpoint stops execution of your program whenever the value of\n\
11346 an expression is read."));
11347 set_cmd_completer (c
, expression_completer
);
11349 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11350 Set a watchpoint for an expression.\n\
11351 A watchpoint stops execution of your program whenever the value of\n\
11352 an expression is either read or written."));
11353 set_cmd_completer (c
, expression_completer
);
11355 add_info ("watchpoints", watchpoints_info
, _("\
11356 Status of watchpoints, or watchpoint number NUMBER."));
11360 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11361 respond to changes - contrary to the description. */
11362 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11363 &can_use_hw_watchpoints
, _("\
11364 Set debugger's willingness to use watchpoint hardware."), _("\
11365 Show debugger's willingness to use watchpoint hardware."), _("\
11366 If zero, gdb will not use hardware for new watchpoints, even if\n\
11367 such is available. (However, any hardware watchpoints that were\n\
11368 created before setting this to nonzero, will continue to use watchpoint\n\
11371 show_can_use_hw_watchpoints
,
11372 &setlist
, &showlist
);
11374 can_use_hw_watchpoints
= 1;
11376 /* Tracepoint manipulation commands. */
11378 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11379 Set a tracepoint at specified line or function.\n\
11381 BREAK_ARGS_HELP ("trace") "\n\
11382 Do \"help tracepoints\" for info on other tracepoint commands."));
11383 set_cmd_completer (c
, location_completer
);
11385 add_com_alias ("tp", "trace", class_alias
, 0);
11386 add_com_alias ("tr", "trace", class_alias
, 1);
11387 add_com_alias ("tra", "trace", class_alias
, 1);
11388 add_com_alias ("trac", "trace", class_alias
, 1);
11390 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11391 Set a fast tracepoint at specified line or function.\n\
11393 BREAK_ARGS_HELP ("ftrace") "\n\
11394 Do \"help tracepoints\" for info on other tracepoint commands."));
11395 set_cmd_completer (c
, location_completer
);
11397 add_info ("tracepoints", tracepoints_info
, _("\
11398 Status of tracepoints, or tracepoint number NUMBER.\n\
11399 Convenience variable \"$tpnum\" contains the number of the\n\
11400 last tracepoint set."));
11402 add_info_alias ("tp", "tracepoints", 1);
11404 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11405 Delete specified tracepoints.\n\
11406 Arguments are tracepoint numbers, separated by spaces.\n\
11407 No argument means delete all tracepoints."),
11410 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11411 Disable specified tracepoints.\n\
11412 Arguments are tracepoint numbers, separated by spaces.\n\
11413 No argument means disable all tracepoints."),
11415 deprecate_cmd (c
, "disable");
11417 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11418 Enable specified tracepoints.\n\
11419 Arguments are tracepoint numbers, separated by spaces.\n\
11420 No argument means enable all tracepoints."),
11422 deprecate_cmd (c
, "enable");
11424 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11425 Set the passcount for a tracepoint.\n\
11426 The trace will end when the tracepoint has been passed 'count' times.\n\
11427 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11428 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11430 add_prefix_cmd ("save", class_breakpoint
, save_command
,
11431 _("Save breakpoint definitions as a script."),
11432 &save_cmdlist
, "save ",
11433 0/*allow-unknown*/, &cmdlist
);
11435 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
11436 Save current breakpoint definitions as a script.\n\
11437 This includes all types of breakpoints (breakpoints, watchpoints, \n\
11438 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11439 session to restore them."),
11441 set_cmd_completer (c
, filename_completer
);
11443 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
11444 Save current tracepoint definitions as a script.\n\
11445 Use the 'source' command in another debug session to restore them."),
11447 set_cmd_completer (c
, filename_completer
);
11449 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
11450 deprecate_cmd (c
, "save tracepoints");
11452 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11453 Breakpoint specific settings\n\
11454 Configure various breakpoint-specific variables such as\n\
11455 pending breakpoint behavior"),
11456 &breakpoint_set_cmdlist
, "set breakpoint ",
11457 0/*allow-unknown*/, &setlist
);
11458 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11459 Breakpoint specific settings\n\
11460 Configure various breakpoint-specific variables such as\n\
11461 pending breakpoint behavior"),
11462 &breakpoint_show_cmdlist
, "show breakpoint ",
11463 0/*allow-unknown*/, &showlist
);
11465 add_setshow_auto_boolean_cmd ("pending", no_class
,
11466 &pending_break_support
, _("\
11467 Set debugger's behavior regarding pending breakpoints."), _("\
11468 Show debugger's behavior regarding pending breakpoints."), _("\
11469 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11470 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11471 an error. If auto, an unrecognized breakpoint location results in a\n\
11472 user-query to see if a pending breakpoint should be created."),
11474 show_pending_break_support
,
11475 &breakpoint_set_cmdlist
,
11476 &breakpoint_show_cmdlist
);
11478 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11480 add_setshow_boolean_cmd ("auto-hw", no_class
,
11481 &automatic_hardware_breakpoints
, _("\
11482 Set automatic usage of hardware breakpoints."), _("\
11483 Show automatic usage of hardware breakpoints."), _("\
11484 If set, the debugger will automatically use hardware breakpoints for\n\
11485 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11486 a warning will be emitted for such breakpoints."),
11488 show_automatic_hardware_breakpoints
,
11489 &breakpoint_set_cmdlist
,
11490 &breakpoint_show_cmdlist
);
11492 add_setshow_enum_cmd ("always-inserted", class_support
,
11493 always_inserted_enums
, &always_inserted_mode
, _("\
11494 Set mode for inserting breakpoints."), _("\
11495 Show mode for inserting breakpoints."), _("\
11496 When this mode is off, breakpoints are inserted in inferior when it is\n\
11497 resumed, and removed when execution stops. When this mode is on,\n\
11498 breakpoints are inserted immediately and removed only when the user\n\
11499 deletes the breakpoint. When this mode is auto (which is the default),\n\
11500 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11501 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11502 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11503 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11505 &show_always_inserted_mode
,
11506 &breakpoint_set_cmdlist
,
11507 &breakpoint_show_cmdlist
);
11509 automatic_hardware_breakpoints
= 1;
11511 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);