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 bpstat_remove_bp_location_callback (struct thread_info
*th
,
212 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
214 static int is_watchpoint (const struct breakpoint
*bpt
);
216 static void insert_breakpoint_locations (void);
218 static int syscall_catchpoint_p (struct breakpoint
*b
);
220 static void tracepoints_info (char *, int);
222 static void delete_trace_command (char *, int);
224 static void enable_trace_command (char *, int);
226 static void disable_trace_command (char *, int);
228 static void trace_pass_command (char *, int);
230 /* A reference-counted struct command_line. This lets multiple
231 breakpoints share a single command list. */
232 struct counted_command_line
234 /* The reference count. */
237 /* The command list. */
238 struct command_line
*commands
;
241 struct command_line
*
242 breakpoint_commands (struct breakpoint
*b
)
244 return b
->commands
? b
->commands
->commands
: NULL
;
247 /* Flag indicating that a command has proceeded the inferior past the
248 current breakpoint. */
250 static int breakpoint_proceeded
;
253 bpdisp_text (enum bpdisp disp
)
255 /* NOTE: the following values are a part of MI protocol and represent
256 values of 'disp' field returned when inferior stops at a breakpoint. */
257 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
259 return bpdisps
[(int) disp
];
262 /* Prototypes for exported functions. */
263 /* If FALSE, gdb will not use hardware support for watchpoints, even
264 if such is available. */
265 static int can_use_hw_watchpoints
;
268 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
269 struct cmd_list_element
*c
,
272 fprintf_filtered (file
, _("\
273 Debugger's willingness to use watchpoint hardware is %s.\n"),
277 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
278 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
279 for unrecognized breakpoint locations.
280 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
281 static enum auto_boolean pending_break_support
;
283 show_pending_break_support (struct ui_file
*file
, int from_tty
,
284 struct cmd_list_element
*c
,
287 fprintf_filtered (file
, _("\
288 Debugger's behavior regarding pending breakpoints is %s.\n"),
292 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
293 set with "break" but falling in read-only memory.
294 If 0, gdb will warn about such breakpoints, but won't automatically
295 use hardware breakpoints. */
296 static int automatic_hardware_breakpoints
;
298 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
299 struct cmd_list_element
*c
,
302 fprintf_filtered (file
, _("\
303 Automatic usage of hardware breakpoints is %s.\n"),
307 /* If on, gdb will keep breakpoints inserted even as inferior is
308 stopped, and immediately insert any new breakpoints. If off, gdb
309 will insert breakpoints into inferior only when resuming it, and
310 will remove breakpoints upon stop. If auto, GDB will behave as ON
311 if in non-stop mode, and as OFF if all-stop mode.*/
313 static const char always_inserted_auto
[] = "auto";
314 static const char always_inserted_on
[] = "on";
315 static const char always_inserted_off
[] = "off";
316 static const char *always_inserted_enums
[] = {
317 always_inserted_auto
,
322 static const char *always_inserted_mode
= always_inserted_auto
;
324 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
325 struct cmd_list_element
*c
, const char *value
)
327 if (always_inserted_mode
== always_inserted_auto
)
328 fprintf_filtered (file
, _("\
329 Always inserted breakpoint mode is %s (currently %s).\n"),
331 breakpoints_always_inserted_mode () ? "on" : "off");
333 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
337 breakpoints_always_inserted_mode (void)
339 return (always_inserted_mode
== always_inserted_on
340 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
343 void _initialize_breakpoint (void);
345 /* Are we executing breakpoint commands? */
346 static int executing_breakpoint_commands
;
348 /* Are overlay event breakpoints enabled? */
349 static int overlay_events_enabled
;
351 /* Walk the following statement or block through all breakpoints.
352 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
355 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
357 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
358 for (B = breakpoint_chain; \
359 B ? (TMP=B->next, 1): 0; \
362 /* Similar iterator for the low-level breakpoints. SAFE variant is not
363 provided so update_global_location_list must not be called while executing
364 the block of ALL_BP_LOCATIONS. */
366 #define ALL_BP_LOCATIONS(B,BP_TMP) \
367 for (BP_TMP = bp_location; \
368 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
371 /* Iterator for tracepoints only. */
373 #define ALL_TRACEPOINTS(B) \
374 for (B = breakpoint_chain; B; B = B->next) \
375 if (is_tracepoint (B))
377 /* Chains of all breakpoints defined. */
379 struct breakpoint
*breakpoint_chain
;
381 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
383 static struct bp_location
**bp_location
;
385 /* Number of elements of BP_LOCATION. */
387 static unsigned bp_location_count
;
389 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
390 for the current elements of BP_LOCATION which get a valid result from
391 bp_location_has_shadow. You can use it for roughly limiting the subrange of
392 BP_LOCATION to scan for shadow bytes for an address you need to read. */
394 static CORE_ADDR bp_location_placed_address_before_address_max
;
396 /* Maximum offset plus alignment between
397 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
398 the current elements of BP_LOCATION which get a valid result from
399 bp_location_has_shadow. You can use it for roughly limiting the subrange of
400 BP_LOCATION to scan for shadow bytes for an address you need to read. */
402 static CORE_ADDR bp_location_shadow_len_after_address_max
;
404 /* The locations that no longer correspond to any breakpoint,
405 unlinked from bp_location array, but for which a hit
406 may still be reported by a target. */
407 VEC(bp_location_p
) *moribund_locations
= NULL
;
409 /* Number of last breakpoint made. */
411 static int breakpoint_count
;
413 /* The value of `breakpoint_count' before the last command that
414 created breakpoints. If the last (break-like) command created more
415 than one breakpoint, then the difference between BREAKPOINT_COUNT
416 and PREV_BREAKPOINT_COUNT is more than one. */
417 static int prev_breakpoint_count
;
419 /* Number of last tracepoint made. */
421 static int tracepoint_count
;
423 static struct cmd_list_element
*breakpoint_set_cmdlist
;
424 static struct cmd_list_element
*breakpoint_show_cmdlist
;
425 static struct cmd_list_element
*save_cmdlist
;
427 /* Return whether a breakpoint is an active enabled breakpoint. */
429 breakpoint_enabled (struct breakpoint
*b
)
431 return (b
->enable_state
== bp_enabled
);
434 /* Set breakpoint count to NUM. */
437 set_breakpoint_count (int num
)
439 prev_breakpoint_count
= breakpoint_count
;
440 breakpoint_count
= num
;
441 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
444 /* Used by `start_rbreak_breakpoints' below, to record the current
445 breakpoint count before "rbreak" creates any breakpoint. */
446 static int rbreak_start_breakpoint_count
;
448 /* Called at the start an "rbreak" command to record the first
452 start_rbreak_breakpoints (void)
454 rbreak_start_breakpoint_count
= breakpoint_count
;
457 /* Called at the end of an "rbreak" command to record the last
461 end_rbreak_breakpoints (void)
463 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
466 /* Used in run_command to zero the hit count when a new run starts. */
469 clear_breakpoint_hit_counts (void)
471 struct breakpoint
*b
;
477 /* Allocate a new counted_command_line with reference count of 1.
478 The new structure owns COMMANDS. */
480 static struct counted_command_line
*
481 alloc_counted_command_line (struct command_line
*commands
)
483 struct counted_command_line
*result
484 = xmalloc (sizeof (struct counted_command_line
));
487 result
->commands
= commands
;
491 /* Increment reference count. This does nothing if CMD is NULL. */
494 incref_counted_command_line (struct counted_command_line
*cmd
)
500 /* Decrement reference count. If the reference count reaches 0,
501 destroy the counted_command_line. Sets *CMDP to NULL. This does
502 nothing if *CMDP is NULL. */
505 decref_counted_command_line (struct counted_command_line
**cmdp
)
509 if (--(*cmdp
)->refc
== 0)
511 free_command_lines (&(*cmdp
)->commands
);
518 /* A cleanup function that calls decref_counted_command_line. */
521 do_cleanup_counted_command_line (void *arg
)
523 decref_counted_command_line (arg
);
526 /* Create a cleanup that calls decref_counted_command_line on the
529 static struct cleanup
*
530 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
532 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
535 /* Default address, symtab and line to put a breakpoint at
536 for "break" command with no arg.
537 if default_breakpoint_valid is zero, the other three are
538 not valid, and "break" with no arg is an error.
540 This set by print_stack_frame, which calls set_default_breakpoint. */
542 int default_breakpoint_valid
;
543 CORE_ADDR default_breakpoint_address
;
544 struct symtab
*default_breakpoint_symtab
;
545 int default_breakpoint_line
;
546 struct program_space
*default_breakpoint_pspace
;
549 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
550 Advance *PP after the string and any trailing whitespace.
552 Currently the string can either be a number or "$" followed by the name
553 of a convenience variable. Making it an expression wouldn't work well
554 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
556 If the string is a NULL pointer, that denotes the last breakpoint.
558 TRAILER is a character which can be found after the number; most
559 commonly this is `-'. If you don't want a trailer, use \0. */
561 get_number_trailer (char **pp
, int trailer
)
563 int retval
= 0; /* default */
567 /* Empty line means refer to the last breakpoint. */
568 return breakpoint_count
;
571 /* Make a copy of the name, so we can null-terminate it
572 to pass to lookup_internalvar(). */
577 while (isalnum (*p
) || *p
== '_')
579 varname
= (char *) alloca (p
- start
+ 1);
580 strncpy (varname
, start
, p
- start
);
581 varname
[p
- start
] = '\0';
582 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
586 printf_filtered (_("Convenience variable must have integer value.\n"));
594 while (*p
>= '0' && *p
<= '9')
597 /* There is no number here. (e.g. "cond a == b"). */
599 /* Skip non-numeric token */
600 while (*p
&& !isspace((int) *p
))
602 /* Return zero, which caller must interpret as error. */
608 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
610 /* Trailing junk: return 0 and let caller print error msg. */
611 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
622 /* Like get_number_trailer, but don't allow a trailer. */
624 get_number (char **pp
)
626 return get_number_trailer (pp
, '\0');
629 /* Parse a number or a range.
630 * A number will be of the form handled by get_number.
631 * A range will be of the form <number1> - <number2>, and
632 * will represent all the integers between number1 and number2,
635 * While processing a range, this fuction is called iteratively;
636 * At each call it will return the next value in the range.
638 * At the beginning of parsing a range, the char pointer PP will
639 * be advanced past <number1> and left pointing at the '-' token.
640 * Subsequent calls will not advance the pointer until the range
641 * is completed. The call that completes the range will advance
642 * pointer PP past <number2>.
646 get_number_or_range (char **pp
)
648 static int last_retval
, end_value
;
649 static char *end_ptr
;
650 static int in_range
= 0;
654 /* Default case: pp is pointing either to a solo number,
655 or to the first number of a range. */
656 last_retval
= get_number_trailer (pp
, '-');
661 /* This is the start of a range (<number1> - <number2>).
662 Skip the '-', parse and remember the second number,
663 and also remember the end of the final token. */
667 while (isspace ((int) *end_ptr
))
668 end_ptr
++; /* skip white space */
669 end_value
= get_number (temp
);
670 if (end_value
< last_retval
)
672 error (_("inverted range"));
674 else if (end_value
== last_retval
)
676 /* degenerate range (number1 == number2). Advance the
677 token pointer so that the range will be treated as a
686 error (_("negative value"));
689 /* pp points to the '-' that betokens a range. All
690 number-parsing has already been done. Return the next
691 integer value (one greater than the saved previous value).
692 Do not advance the token pointer 'pp' until the end of range
695 if (++last_retval
== end_value
)
697 /* End of range reached; advance token pointer. */
705 /* Return the breakpoint with the specified number, or NULL
706 if the number does not refer to an existing breakpoint. */
709 get_breakpoint (int num
)
711 struct breakpoint
*b
;
714 if (b
->number
== num
)
723 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
726 struct bp_location
*loc
= b
->loc
;
728 for (; loc
; loc
= loc
->next
)
733 xfree (b
->cond_string
);
734 b
->cond_string
= NULL
;
741 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
747 /* I don't know if it matters whether this is the string the user
748 typed in or the decompiled expression. */
749 b
->cond_string
= xstrdup (arg
);
750 b
->condition_not_parsed
= 0;
752 if (is_watchpoint (b
))
754 innermost_block
= NULL
;
756 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
758 error (_("Junk at end of expression"));
759 b
->cond_exp_valid_block
= innermost_block
;
763 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
767 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
769 error (_("Junk at end of expression"));
773 breakpoints_changed ();
774 observer_notify_breakpoint_modified (b
->number
);
777 /* condition N EXP -- set break condition of breakpoint N to EXP. */
780 condition_command (char *arg
, int from_tty
)
782 struct breakpoint
*b
;
787 error_no_arg (_("breakpoint number"));
790 bnum
= get_number (&p
);
792 error (_("Bad breakpoint argument: '%s'"), arg
);
795 if (b
->number
== bnum
)
797 set_breakpoint_condition (b
, p
, from_tty
);
801 error (_("No breakpoint number %d."), bnum
);
804 /* Check that COMMAND do not contain commands that are suitable
805 only for tracepoints and not suitable for ordinary breakpoints.
806 Throw if any such commands is found.
809 check_no_tracepoint_commands (struct command_line
*commands
)
811 struct command_line
*c
;
813 for (c
= commands
; c
; c
= c
->next
)
817 if (c
->control_type
== while_stepping_control
)
818 error (_("The 'while-stepping' command can only be used for tracepoints"));
820 for (i
= 0; i
< c
->body_count
; ++i
)
821 check_no_tracepoint_commands ((c
->body_list
)[i
]);
823 /* Not that command parsing removes leading whitespace and comment
824 lines and also empty lines. So, we only need to check for
826 if (strstr (c
->line
, "collect ") == c
->line
)
827 error (_("The 'collect' command can only be used for tracepoints"));
829 if (strstr (c
->line
, "teval ") == c
->line
)
830 error (_("The 'teval' command can only be used for tracepoints"));
834 /* Encapsulate tests for different types of tracepoints. */
837 is_tracepoint (const struct breakpoint
*b
)
839 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
842 /* A helper function that validsates that COMMANDS are valid for a
843 breakpoint. This function will throw an exception if a problem is
847 validate_commands_for_breakpoint (struct breakpoint
*b
,
848 struct command_line
*commands
)
850 if (is_tracepoint (b
))
852 /* We need to verify that each top-level element of commands
853 is valid for tracepoints, that there's at most one while-stepping
854 element, and that while-stepping's body has valid tracing commands
855 excluding nested while-stepping. */
856 struct command_line
*c
;
857 struct command_line
*while_stepping
= 0;
858 for (c
= commands
; c
; c
= c
->next
)
860 if (c
->control_type
== while_stepping_control
)
862 if (b
->type
== bp_fast_tracepoint
)
863 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
866 error (_("The 'while-stepping' command can be used only once"));
873 struct command_line
*c2
;
875 gdb_assert (while_stepping
->body_count
== 1);
876 c2
= while_stepping
->body_list
[0];
877 for (; c2
; c2
= c2
->next
)
879 if (c2
->control_type
== while_stepping_control
)
880 error (_("The 'while-stepping' command cannot be nested"));
886 check_no_tracepoint_commands (commands
);
890 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
891 validate that only allowed commands are included.
895 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
897 validate_commands_for_breakpoint (b
, commands
);
899 decref_counted_command_line (&b
->commands
);
900 b
->commands
= alloc_counted_command_line (commands
);
901 breakpoints_changed ();
902 observer_notify_breakpoint_modified (b
->number
);
906 check_tracepoint_command (char *line
, void *closure
)
908 struct breakpoint
*b
= closure
;
910 validate_actionline (&line
, b
);
913 /* A structure used to pass information through
914 map_breakpoint_numbers. */
918 /* True if the command was typed at a tty. */
921 /* The breakpoint range spec. */
924 /* Non-NULL if the body of the commands are being read from this
925 already-parsed command. */
926 struct command_line
*control
;
928 /* The command lines read from the user, or NULL if they have not
930 struct counted_command_line
*cmd
;
933 /* A callback for map_breakpoint_numbers that sets the commands for
937 do_map_commands_command (struct breakpoint
*b
, void *data
)
939 struct commands_info
*info
= data
;
941 if (info
->cmd
== NULL
)
943 struct command_line
*l
;
945 if (info
->control
!= NULL
)
946 l
= copy_command_lines (info
->control
->body_list
[0]);
949 struct cleanup
*old_chain
;
952 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
955 old_chain
= make_cleanup (xfree
, str
);
957 l
= read_command_lines (str
,
960 ? check_tracepoint_command
: 0),
963 do_cleanups (old_chain
);
966 info
->cmd
= alloc_counted_command_line (l
);
969 /* If a breakpoint was on the list more than once, we don't need to
971 if (b
->commands
!= info
->cmd
)
973 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
974 incref_counted_command_line (info
->cmd
);
975 decref_counted_command_line (&b
->commands
);
976 b
->commands
= info
->cmd
;
977 breakpoints_changed ();
978 observer_notify_breakpoint_modified (b
->number
);
983 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
985 struct cleanup
*cleanups
;
986 struct commands_info info
;
988 info
.from_tty
= from_tty
;
989 info
.control
= control
;
991 /* If we read command lines from the user, then `info' will hold an
992 extra reference to the commands that we must clean up. */
993 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
995 if (arg
== NULL
|| !*arg
)
997 if (breakpoint_count
- prev_breakpoint_count
> 1)
998 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
999 else if (breakpoint_count
> 0)
1000 arg
= xstrprintf ("%d", breakpoint_count
);
1003 /* So that we don't try to free the incoming non-NULL
1004 argument in the cleanup below. Mapping breakpoint
1005 numbers will fail in this case. */
1010 /* The command loop has some static state, so we need to preserve
1012 arg
= xstrdup (arg
);
1015 make_cleanup (xfree
, arg
);
1019 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1021 if (info
.cmd
== NULL
)
1022 error (_("No breakpoints specified."));
1024 do_cleanups (cleanups
);
1028 commands_command (char *arg
, int from_tty
)
1030 commands_command_1 (arg
, from_tty
, NULL
);
1033 /* Like commands_command, but instead of reading the commands from
1034 input stream, takes them from an already parsed command structure.
1036 This is used by cli-script.c to DTRT with breakpoint commands
1037 that are part of if and while bodies. */
1038 enum command_control_type
1039 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1041 commands_command_1 (arg
, 0, cmd
);
1042 return simple_control
;
1045 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1048 bp_location_has_shadow (struct bp_location
*bl
)
1050 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1054 if (bl
->target_info
.shadow_len
== 0)
1055 /* bp isn't valid, or doesn't shadow memory. */
1060 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1061 by replacing any memory breakpoints with their shadowed contents.
1063 The range of shadowed area by each bp_location is:
1064 b->address - bp_location_placed_address_before_address_max
1065 up to b->address + bp_location_shadow_len_after_address_max
1066 The range we were requested to resolve shadows for is:
1067 memaddr ... memaddr + len
1068 Thus the safe cutoff boundaries for performance optimization are
1069 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1071 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1074 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1076 /* Left boundary, right boundary and median element of our binary search. */
1077 unsigned bc_l
, bc_r
, bc
;
1079 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1080 safe to report lower value but a failure to report higher one. */
1083 bc_r
= bp_location_count
;
1084 while (bc_l
+ 1 < bc_r
)
1086 struct bp_location
*b
;
1088 bc
= (bc_l
+ bc_r
) / 2;
1089 b
= bp_location
[bc
];
1091 /* Check first B->ADDRESS will not overflow due to the added constant.
1092 Then advance the left boundary only if we are sure the BC element can
1093 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1095 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1096 we cannot miss a breakpoint with its shadow range tail still reaching
1099 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1100 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1106 /* Now do full processing of the found relevant range of elements. */
1108 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1110 struct bp_location
*b
= bp_location
[bc
];
1111 CORE_ADDR bp_addr
= 0;
1115 /* bp_location array has B->OWNER always non-NULL. */
1116 if (b
->owner
->type
== bp_none
)
1117 warning (_("reading through apparently deleted breakpoint #%d?"),
1120 /* Performance optimization: any futher element can no longer affect BUF
1123 if (b
->address
>= bp_location_placed_address_before_address_max
1124 && memaddr
+ len
<= b
->address
1125 - bp_location_placed_address_before_address_max
)
1128 if (!bp_location_has_shadow (b
))
1130 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1131 current_program_space
->aspace
, 0))
1134 /* Addresses and length of the part of the breakpoint that
1136 bp_addr
= b
->target_info
.placed_address
;
1137 bp_size
= b
->target_info
.shadow_len
;
1139 if (bp_addr
+ bp_size
<= memaddr
)
1140 /* The breakpoint is entirely before the chunk of memory we
1144 if (bp_addr
>= memaddr
+ len
)
1145 /* The breakpoint is entirely after the chunk of memory we are
1149 /* Offset within shadow_contents. */
1150 if (bp_addr
< memaddr
)
1152 /* Only copy the second part of the breakpoint. */
1153 bp_size
-= memaddr
- bp_addr
;
1154 bptoffset
= memaddr
- bp_addr
;
1158 if (bp_addr
+ bp_size
> memaddr
+ len
)
1160 /* Only copy the first part of the breakpoint. */
1161 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1164 memcpy (buf
+ bp_addr
- memaddr
,
1165 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1170 /* A wrapper function for inserting catchpoints. */
1172 insert_catchpoint (struct ui_out
*uo
, void *args
)
1174 struct breakpoint
*b
= (struct breakpoint
*) args
;
1176 gdb_assert (b
->type
== bp_catchpoint
);
1177 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1182 /* Return true if BPT is of any hardware watchpoint kind. */
1185 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1187 return (bpt
->type
== bp_hardware_watchpoint
1188 || bpt
->type
== bp_read_watchpoint
1189 || bpt
->type
== bp_access_watchpoint
);
1192 /* Return true if BPT is of any watchpoint kind, hardware or
1196 is_watchpoint (const struct breakpoint
*bpt
)
1198 return (is_hardware_watchpoint (bpt
)
1199 || bpt
->type
== bp_watchpoint
);
1202 /* Find the current value of a watchpoint on EXP. Return the value in
1203 *VALP and *RESULTP and the chain of intermediate and final values
1204 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1207 If a memory error occurs while evaluating the expression, *RESULTP will
1208 be set to NULL. *RESULTP may be a lazy value, if the result could
1209 not be read from memory. It is used to determine whether a value
1210 is user-specified (we should watch the whole value) or intermediate
1211 (we should watch only the bit used to locate the final value).
1213 If the final value, or any intermediate value, could not be read
1214 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1215 set to any referenced values. *VALP will never be a lazy value.
1216 This is the value which we store in struct breakpoint.
1218 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1219 value chain. The caller must free the values individually. If
1220 VAL_CHAIN is NULL, all generated values will be left on the value
1224 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1225 struct value
**resultp
, struct value
**val_chain
)
1227 struct value
*mark
, *new_mark
, *result
;
1228 volatile struct gdb_exception ex
;
1236 /* Evaluate the expression. */
1237 mark
= value_mark ();
1240 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1242 result
= evaluate_expression (exp
);
1246 /* Ignore memory errors, we want watchpoints pointing at
1247 inaccessible memory to still be created; otherwise, throw the
1248 error to some higher catcher. */
1254 throw_exception (ex
);
1259 new_mark
= value_mark ();
1260 if (mark
== new_mark
)
1265 /* Make sure it's not lazy, so that after the target stops again we
1266 have a non-lazy previous value to compare with. */
1268 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1273 /* Return the chain of intermediate values. We use this to
1274 decide which addresses to watch. */
1275 *val_chain
= new_mark
;
1276 value_release_to_mark (mark
);
1280 /* Assuming that B is a watchpoint: returns true if the current thread
1281 and its running state are safe to evaluate or update watchpoint B.
1282 Watchpoints on local expressions need to be evaluated in the
1283 context of the thread that was current when the watchpoint was
1284 created, and, that thread needs to be stopped to be able to select
1285 the correct frame context. Watchpoints on global expressions can
1286 be evaluated on any thread, and in any state. It is presently left
1287 to the target allowing memory accesses when threads are
1291 watchpoint_in_thread_scope (struct breakpoint
*b
)
1293 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1294 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1295 && !is_executing (inferior_ptid
)));
1298 /* Assuming that B is a watchpoint:
1299 - Reparse watchpoint expression, if REPARSE is non-zero
1300 - Evaluate expression and store the result in B->val
1301 - Evaluate the condition if there is one, and store the result
1303 - Update the list of values that must be watched in B->loc.
1305 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1306 If this is local watchpoint that is out of scope, delete it.
1308 Even with `set breakpoint always-inserted on' the watchpoints are removed
1309 + inserted on each stop here. Normal breakpoints must never be removed
1310 because they might be missed by a running thread when debugging in non-stop
1311 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1312 processed here) are specific to each LWP since they are stored in each LWP's
1313 hardware debug registers. Therefore, such LWP must be stopped first in
1314 order to be able to modify its hardware watchpoints.
1316 Hardware watchpoints must be reset exactly once after being presented to the
1317 user. It cannot be done sooner, because it would reset the data used to
1318 present the watchpoint hit to the user. And it must not be done later
1319 because it could display the same single watchpoint hit during multiple GDB
1320 stops. Note that the latter is relevant only to the hardware watchpoint
1321 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1322 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1323 memory content has not changed.
1325 The following constraints influence the location where we can reset hardware
1328 * target_stopped_by_watchpoint and target_stopped_data_address are called
1329 several times when GDB stops.
1332 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1333 stop. GDB only presents one hardware watchpoint hit at a time as the
1334 reason for stopping, and all the other hits are presented later, one after
1335 the other, each time the user requests the execution to be resumed.
1336 Execution is not resumed for the threads still having pending hit event
1337 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1338 the inferior on the first stop the thread hit event is kept being reported
1339 from its cached value by linux_nat_stopped_data_address until the real
1340 thread resume happens after the watchpoint gets presented and thus its
1341 LWP_INFO->STATUS gets reset.
1343 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1344 removal from inferior. */
1347 update_watchpoint (struct breakpoint
*b
, int reparse
)
1349 int within_current_scope
;
1350 struct frame_id saved_frame_id
;
1353 /* If this is a local watchpoint, we only want to check if the
1354 watchpoint frame is in scope if the current thread is the thread
1355 that was used to create the watchpoint. */
1356 if (!watchpoint_in_thread_scope (b
))
1359 /* We don't free locations. They are stored in bp_location array and
1360 update_global_locations will eventually delete them and remove
1361 breakpoints if needed. */
1364 if (b
->disposition
== disp_del_at_next_stop
)
1369 /* Determine if the watchpoint is within scope. */
1370 if (b
->exp_valid_block
== NULL
)
1371 within_current_scope
= 1;
1374 struct frame_info
*fi
;
1376 /* Save the current frame's ID so we can restore it after
1377 evaluating the watchpoint expression on its own frame. */
1378 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1379 took a frame parameter, so that we didn't have to change the
1382 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1384 fi
= frame_find_by_id (b
->watchpoint_frame
);
1385 within_current_scope
= (fi
!= NULL
);
1386 if (within_current_scope
)
1390 if (within_current_scope
&& reparse
)
1399 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1400 /* If the meaning of expression itself changed, the old value is
1401 no longer relevant. We don't want to report a watchpoint hit
1402 to the user when the old value and the new value may actually
1403 be completely different objects. */
1404 value_free (b
->val
);
1408 /* Note that unlike with breakpoints, the watchpoint's condition
1409 expression is stored in the breakpoint object, not in the
1410 locations (re)created below. */
1411 if (b
->cond_string
!= NULL
)
1413 if (b
->cond_exp
!= NULL
)
1415 xfree (b
->cond_exp
);
1420 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1424 /* If we failed to parse the expression, for example because
1425 it refers to a global variable in a not-yet-loaded shared library,
1426 don't try to insert watchpoint. We don't automatically delete
1427 such watchpoint, though, since failure to parse expression
1428 is different from out-of-scope watchpoint. */
1429 if ( !target_has_execution
)
1431 /* Without execution, memory can't change. No use to try and
1432 set watchpoint locations. The watchpoint will be reset when
1433 the target gains execution, through breakpoint_re_set. */
1435 else if (within_current_scope
&& b
->exp
)
1437 struct value
*val_chain
, *v
, *result
, *next
;
1438 struct program_space
*frame_pspace
;
1440 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1442 /* Avoid setting b->val if it's already set. The meaning of
1443 b->val is 'the last value' user saw, and we should update
1444 it only if we reported that last value to user. As it
1445 happens, the code that reports it updates b->val directly. */
1452 /* Change the type of breakpoint between hardware assisted or an
1453 ordinary watchpoint depending on the hardware support and free
1454 hardware slots. REPARSE is set when the inferior is started. */
1455 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1458 int i
, mem_cnt
, other_type_used
;
1460 /* We need to determine how many resources are already used
1461 for all other hardware watchpoints to see if we still have
1462 enough resources to also fit this watchpoint in as well.
1463 To avoid the hw_watchpoint_used_count call below from counting
1464 this watchpoint, make sure that it is marked as a software
1466 b
->type
= bp_watchpoint
;
1467 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1469 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1472 b
->type
= bp_watchpoint
;
1475 int target_resources_ok
= target_can_use_hardware_watchpoint
1476 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1477 if (target_resources_ok
<= 0)
1478 b
->type
= bp_watchpoint
;
1480 b
->type
= bp_hardware_watchpoint
;
1484 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1486 /* Look at each value on the value chain. */
1487 for (v
= val_chain
; v
; v
= next
)
1489 /* If it's a memory location, and GDB actually needed
1490 its contents to evaluate the expression, then we
1491 must watch it. If the first value returned is
1492 still lazy, that means an error occurred reading it;
1493 watch it anyway in case it becomes readable. */
1494 if (VALUE_LVAL (v
) == lval_memory
1495 && (v
== val_chain
|| ! value_lazy (v
)))
1497 struct type
*vtype
= check_typedef (value_type (v
));
1499 /* We only watch structs and arrays if user asked
1500 for it explicitly, never if they just happen to
1501 appear in the middle of some value chain. */
1503 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1504 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1508 struct bp_location
*loc
, **tmp
;
1510 addr
= value_address (v
);
1511 len
= TYPE_LENGTH (value_type (v
));
1513 if (b
->type
== bp_read_watchpoint
)
1515 else if (b
->type
== bp_access_watchpoint
)
1518 loc
= allocate_bp_location (b
);
1519 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1522 loc
->gdbarch
= get_type_arch (value_type (v
));
1524 loc
->pspace
= frame_pspace
;
1525 loc
->address
= addr
;
1527 loc
->watchpoint_type
= type
;
1531 next
= value_next (v
);
1536 /* If a software watchpoint is not watching any memory, then the
1537 above left it without any location set up. But,
1538 bpstat_stop_status requires a location to be able to report
1539 stops, so make sure there's at least a dummy one. */
1540 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1542 b
->loc
= allocate_bp_location (b
);
1543 b
->loc
->pspace
= frame_pspace
;
1544 b
->loc
->address
= -1;
1545 b
->loc
->length
= -1;
1546 b
->loc
->watchpoint_type
= -1;
1549 else if (!within_current_scope
)
1551 printf_filtered (_("\
1552 Watchpoint %d deleted because the program has left the block \n\
1553 in which its expression is valid.\n"),
1555 if (b
->related_breakpoint
)
1557 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1558 b
->related_breakpoint
->related_breakpoint
= NULL
;
1559 b
->related_breakpoint
= NULL
;
1561 b
->disposition
= disp_del_at_next_stop
;
1564 /* Restore the selected frame. */
1566 select_frame (frame_find_by_id (saved_frame_id
));
1570 /* Returns 1 iff breakpoint location should be
1571 inserted in the inferior. */
1573 should_be_inserted (struct bp_location
*bpt
)
1575 if (bpt
->owner
== NULL
|| !breakpoint_enabled (bpt
->owner
))
1578 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1581 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1584 /* This is set for example, when we're attached to the parent of a
1585 vfork, and have detached from the child. The child is running
1586 free, and we expect it to do an exec or exit, at which point the
1587 OS makes the parent schedulable again (and the target reports
1588 that the vfork is done). Until the child is done with the shared
1589 memory region, do not insert breakpoints in the parent, otherwise
1590 the child could still trip on the parent's breakpoints. Since
1591 the parent is blocked anyway, it won't miss any breakpoint. */
1592 if (bpt
->pspace
->breakpoints_not_allowed
)
1595 /* Tracepoints are inserted by the target at a time of its choosing,
1597 if (is_tracepoint (bpt
->owner
))
1603 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1604 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1605 and HW_BREAKPOINT_ERROR are used to report problems.
1607 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1608 method for each breakpoint or catchpoint type. */
1610 insert_bp_location (struct bp_location
*bpt
,
1611 struct ui_file
*tmp_error_stream
,
1612 int *disabled_breaks
,
1613 int *hw_breakpoint_error
)
1617 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1620 /* Initialize the target-specific information. */
1621 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1622 bpt
->target_info
.placed_address
= bpt
->address
;
1623 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1625 if (bpt
->loc_type
== bp_loc_software_breakpoint
1626 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1628 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1630 /* If the explicitly specified breakpoint type
1631 is not hardware breakpoint, check the memory map to see
1632 if the breakpoint address is in read only memory or not.
1633 Two important cases are:
1634 - location type is not hardware breakpoint, memory
1635 is readonly. We change the type of the location to
1636 hardware breakpoint.
1637 - location type is hardware breakpoint, memory is read-write.
1638 This means we've previously made the location hardware one, but
1639 then the memory map changed, so we undo.
1641 When breakpoints are removed, remove_breakpoints will
1642 use location types we've just set here, the only possible
1643 problem is that memory map has changed during running program,
1644 but it's not going to work anyway with current gdb. */
1645 struct mem_region
*mr
1646 = lookup_mem_region (bpt
->target_info
.placed_address
);
1650 if (automatic_hardware_breakpoints
)
1652 enum bp_loc_type new_type
;
1654 if (mr
->attrib
.mode
!= MEM_RW
)
1655 new_type
= bp_loc_hardware_breakpoint
;
1657 new_type
= bp_loc_software_breakpoint
;
1659 if (new_type
!= bpt
->loc_type
)
1661 static int said
= 0;
1663 bpt
->loc_type
= new_type
;
1666 fprintf_filtered (gdb_stdout
, _("\
1667 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1672 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1673 && mr
->attrib
.mode
!= MEM_RW
)
1674 warning (_("cannot set software breakpoint at readonly address %s"),
1675 paddress (bpt
->gdbarch
, bpt
->address
));
1679 /* First check to see if we have to handle an overlay. */
1680 if (overlay_debugging
== ovly_off
1681 || bpt
->section
== NULL
1682 || !(section_is_overlay (bpt
->section
)))
1684 /* No overlay handling: just set the breakpoint. */
1686 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1687 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1690 val
= target_insert_breakpoint (bpt
->gdbarch
,
1695 /* This breakpoint is in an overlay section.
1696 Shall we set a breakpoint at the LMA? */
1697 if (!overlay_events_enabled
)
1699 /* Yes -- overlay event support is not active,
1700 so we must try to set a breakpoint at the LMA.
1701 This will not work for a hardware breakpoint. */
1702 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1703 warning (_("hardware breakpoint %d not supported in overlay!"),
1704 bpt
->owner
->number
);
1707 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1709 /* Set a software (trap) breakpoint at the LMA. */
1710 bpt
->overlay_target_info
= bpt
->target_info
;
1711 bpt
->overlay_target_info
.placed_address
= addr
;
1712 val
= target_insert_breakpoint (bpt
->gdbarch
,
1713 &bpt
->overlay_target_info
);
1715 fprintf_unfiltered (tmp_error_stream
,
1716 "Overlay breakpoint %d failed: in ROM?\n",
1717 bpt
->owner
->number
);
1720 /* Shall we set a breakpoint at the VMA? */
1721 if (section_is_mapped (bpt
->section
))
1723 /* Yes. This overlay section is mapped into memory. */
1724 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1725 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1728 val
= target_insert_breakpoint (bpt
->gdbarch
,
1733 /* No. This breakpoint will not be inserted.
1734 No error, but do not mark the bp as 'inserted'. */
1741 /* Can't set the breakpoint. */
1742 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1744 /* See also: disable_breakpoints_in_shlibs. */
1746 bpt
->shlib_disabled
= 1;
1747 if (!*disabled_breaks
)
1749 fprintf_unfiltered (tmp_error_stream
,
1750 "Cannot insert breakpoint %d.\n",
1751 bpt
->owner
->number
);
1752 fprintf_unfiltered (tmp_error_stream
,
1753 "Temporarily disabling shared library breakpoints:\n");
1755 *disabled_breaks
= 1;
1756 fprintf_unfiltered (tmp_error_stream
,
1757 "breakpoint #%d\n", bpt
->owner
->number
);
1761 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1763 *hw_breakpoint_error
= 1;
1764 fprintf_unfiltered (tmp_error_stream
,
1765 "Cannot insert hardware breakpoint %d.\n",
1766 bpt
->owner
->number
);
1770 fprintf_unfiltered (tmp_error_stream
,
1771 "Cannot insert breakpoint %d.\n",
1772 bpt
->owner
->number
);
1773 fprintf_filtered (tmp_error_stream
,
1774 "Error accessing memory address ");
1775 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1777 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1778 safe_strerror (val
));
1789 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1790 /* NOTE drow/2003-09-08: This state only exists for removing
1791 watchpoints. It's not clear that it's necessary... */
1792 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1794 val
= target_insert_watchpoint (bpt
->address
,
1796 bpt
->watchpoint_type
);
1798 /* If trying to set a read-watchpoint, and it turns out it's not
1799 supported, try emulating one with an access watchpoint. */
1800 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1802 struct bp_location
*loc
, **loc_temp
;
1804 /* But don't try to insert it, if there's already another
1805 hw_access location that would be considered a duplicate
1807 ALL_BP_LOCATIONS (loc
, loc_temp
)
1809 && loc
->watchpoint_type
== hw_access
1810 && watchpoint_locations_match (bpt
, loc
))
1814 bpt
->target_info
= loc
->target_info
;
1815 bpt
->watchpoint_type
= hw_access
;
1822 val
= target_insert_watchpoint (bpt
->address
,
1826 bpt
->watchpoint_type
= hw_access
;
1830 bpt
->inserted
= (val
== 0);
1833 else if (bpt
->owner
->type
== bp_catchpoint
)
1835 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1836 bpt
->owner
, RETURN_MASK_ERROR
);
1837 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1838 bpt
->owner
->number
);
1840 bpt
->owner
->enable_state
= bp_disabled
;
1844 /* We've already printed an error message if there was a problem
1845 inserting this catchpoint, and we've disabled the catchpoint,
1846 so just return success. */
1853 /* This function is called when program space PSPACE is about to be
1854 deleted. It takes care of updating breakpoints to not reference
1858 breakpoint_program_space_exit (struct program_space
*pspace
)
1860 struct breakpoint
*b
, *b_temp
;
1861 struct bp_location
*loc
, **loc_temp
;
1863 /* Remove any breakpoint that was set through this program space. */
1864 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1866 if (b
->pspace
== pspace
)
1867 delete_breakpoint (b
);
1870 /* Breakpoints set through other program spaces could have locations
1871 bound to PSPACE as well. Remove those. */
1872 ALL_BP_LOCATIONS (loc
, loc_temp
)
1874 struct bp_location
*tmp
;
1876 if (loc
->pspace
== pspace
)
1878 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1879 if (loc
->owner
->loc
== loc
)
1880 loc
->owner
->loc
= loc
->next
;
1882 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1883 if (tmp
->next
== loc
)
1885 tmp
->next
= loc
->next
;
1891 /* Now update the global location list to permanently delete the
1892 removed locations above. */
1893 update_global_location_list (0);
1896 /* Make sure all breakpoints are inserted in inferior.
1897 Throws exception on any error.
1898 A breakpoint that is already inserted won't be inserted
1899 again, so calling this function twice is safe. */
1901 insert_breakpoints (void)
1903 struct breakpoint
*bpt
;
1905 ALL_BREAKPOINTS (bpt
)
1906 if (is_hardware_watchpoint (bpt
))
1907 update_watchpoint (bpt
, 0 /* don't reparse. */);
1909 update_global_location_list (1);
1911 /* update_global_location_list does not insert breakpoints when
1912 always_inserted_mode is not enabled. Explicitly insert them
1914 if (!breakpoints_always_inserted_mode ())
1915 insert_breakpoint_locations ();
1918 /* insert_breakpoints is used when starting or continuing the program.
1919 remove_breakpoints is used when the program stops.
1920 Both return zero if successful,
1921 or an `errno' value if could not write the inferior. */
1924 insert_breakpoint_locations (void)
1926 struct breakpoint
*bpt
;
1927 struct bp_location
*b
, **bp_tmp
;
1930 int disabled_breaks
= 0;
1931 int hw_breakpoint_error
= 0;
1933 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1934 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1936 /* Explicitly mark the warning -- this will only be printed if
1937 there was an error. */
1938 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1940 save_current_space_and_thread ();
1942 ALL_BP_LOCATIONS (b
, bp_tmp
)
1944 if (!should_be_inserted (b
) || b
->inserted
)
1947 /* There is no point inserting thread-specific breakpoints if the
1948 thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER
1950 if (b
->owner
->thread
!= -1
1951 && !valid_thread_id (b
->owner
->thread
))
1954 switch_to_program_space_and_thread (b
->pspace
);
1956 /* For targets that support global breakpoints, there's no need
1957 to select an inferior to insert breakpoint to. In fact, even
1958 if we aren't attached to any process yet, we should still
1959 insert breakpoints. */
1960 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1961 && ptid_equal (inferior_ptid
, null_ptid
))
1964 val
= insert_bp_location (b
, tmp_error_stream
,
1966 &hw_breakpoint_error
);
1971 /* If we failed to insert all locations of a watchpoint,
1972 remove them, as half-inserted watchpoint is of limited use. */
1973 ALL_BREAKPOINTS (bpt
)
1975 int some_failed
= 0;
1976 struct bp_location
*loc
;
1978 if (!is_hardware_watchpoint (bpt
))
1981 if (!breakpoint_enabled (bpt
))
1984 if (bpt
->disposition
== disp_del_at_next_stop
)
1987 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1988 if (!loc
->inserted
&& should_be_inserted (loc
))
1995 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1997 remove_breakpoint (loc
, mark_uninserted
);
1999 hw_breakpoint_error
= 1;
2000 fprintf_unfiltered (tmp_error_stream
,
2001 "Could not insert hardware watchpoint %d.\n",
2009 /* If a hardware breakpoint or watchpoint was inserted, add a
2010 message about possibly exhausted resources. */
2011 if (hw_breakpoint_error
)
2013 fprintf_unfiltered (tmp_error_stream
,
2014 "Could not insert hardware breakpoints:\n\
2015 You may have requested too many hardware breakpoints/watchpoints.\n");
2017 target_terminal_ours_for_output ();
2018 error_stream (tmp_error_stream
);
2021 do_cleanups (cleanups
);
2025 remove_breakpoints (void)
2027 struct bp_location
*b
, **bp_tmp
;
2030 ALL_BP_LOCATIONS (b
, bp_tmp
)
2033 val
|= remove_breakpoint (b
, mark_uninserted
);
2038 /* Remove breakpoints of process PID. */
2041 remove_breakpoints_pid (int pid
)
2043 struct bp_location
*b
, **b_tmp
;
2045 struct inferior
*inf
= find_inferior_pid (pid
);
2047 ALL_BP_LOCATIONS (b
, b_tmp
)
2049 if (b
->pspace
!= inf
->pspace
)
2054 val
= remove_breakpoint (b
, mark_uninserted
);
2063 remove_hw_watchpoints (void)
2065 struct bp_location
*b
, **bp_tmp
;
2068 ALL_BP_LOCATIONS (b
, bp_tmp
)
2070 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2071 val
|= remove_breakpoint (b
, mark_uninserted
);
2077 reattach_breakpoints (int pid
)
2079 struct cleanup
*old_chain
;
2080 struct bp_location
*b
, **bp_tmp
;
2082 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2083 int dummy1
= 0, dummy2
= 0;
2084 struct inferior
*inf
;
2085 struct thread_info
*tp
;
2087 tp
= any_live_thread_of_process (pid
);
2091 inf
= find_inferior_pid (pid
);
2092 old_chain
= save_inferior_ptid ();
2094 inferior_ptid
= tp
->ptid
;
2096 make_cleanup_ui_file_delete (tmp_error_stream
);
2098 ALL_BP_LOCATIONS (b
, bp_tmp
)
2100 if (b
->pspace
!= inf
->pspace
)
2106 val
= insert_bp_location (b
, tmp_error_stream
,
2110 do_cleanups (old_chain
);
2115 do_cleanups (old_chain
);
2119 static int internal_breakpoint_number
= -1;
2121 static struct breakpoint
*
2122 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2123 CORE_ADDR address
, enum bptype type
)
2125 struct symtab_and_line sal
;
2126 struct breakpoint
*b
;
2128 init_sal (&sal
); /* initialize to zeroes */
2131 sal
.section
= find_pc_overlay (sal
.pc
);
2132 sal
.pspace
= current_program_space
;
2134 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2135 b
->number
= internal_breakpoint_number
--;
2136 b
->disposition
= disp_donttouch
;
2142 create_overlay_event_breakpoint (char *func_name
)
2144 struct objfile
*objfile
;
2146 ALL_OBJFILES (objfile
)
2148 struct breakpoint
*b
;
2149 struct minimal_symbol
*m
;
2151 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2155 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2156 SYMBOL_VALUE_ADDRESS (m
),
2158 b
->addr_string
= xstrdup (func_name
);
2160 if (overlay_debugging
== ovly_auto
)
2162 b
->enable_state
= bp_enabled
;
2163 overlay_events_enabled
= 1;
2167 b
->enable_state
= bp_disabled
;
2168 overlay_events_enabled
= 0;
2171 update_global_location_list (1);
2175 create_longjmp_master_breakpoint (char *func_name
)
2177 struct program_space
*pspace
;
2178 struct objfile
*objfile
;
2179 struct cleanup
*old_chain
;
2181 old_chain
= save_current_program_space ();
2183 ALL_PSPACES (pspace
)
2184 ALL_OBJFILES (objfile
)
2186 struct breakpoint
*b
;
2187 struct minimal_symbol
*m
;
2189 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2192 set_current_program_space (pspace
);
2194 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2198 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2199 SYMBOL_VALUE_ADDRESS (m
),
2201 b
->addr_string
= xstrdup (func_name
);
2202 b
->enable_state
= bp_disabled
;
2204 update_global_location_list (1);
2206 do_cleanups (old_chain
);
2209 /* Create a master std::terminate breakpoint. The actual function
2210 looked for is named FUNC_NAME. */
2212 create_std_terminate_master_breakpoint (const char *func_name
)
2214 struct program_space
*pspace
;
2215 struct objfile
*objfile
;
2216 struct cleanup
*old_chain
;
2218 old_chain
= save_current_program_space ();
2220 ALL_PSPACES (pspace
)
2221 ALL_OBJFILES (objfile
)
2223 struct breakpoint
*b
;
2224 struct minimal_symbol
*m
;
2226 set_current_program_space (pspace
);
2228 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2229 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2230 && MSYMBOL_TYPE (m
) != mst_file_text
))
2233 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2234 SYMBOL_VALUE_ADDRESS (m
),
2235 bp_std_terminate_master
);
2236 b
->addr_string
= xstrdup (func_name
);
2237 b
->enable_state
= bp_disabled
;
2239 update_global_location_list (1);
2241 do_cleanups (old_chain
);
2245 update_breakpoints_after_exec (void)
2247 struct breakpoint
*b
;
2248 struct breakpoint
*temp
;
2249 struct bp_location
*bploc
, **bplocp_tmp
;
2251 /* We're about to delete breakpoints from GDB's lists. If the
2252 INSERTED flag is true, GDB will try to lift the breakpoints by
2253 writing the breakpoints' "shadow contents" back into memory. The
2254 "shadow contents" are NOT valid after an exec, so GDB should not
2255 do that. Instead, the target is responsible from marking
2256 breakpoints out as soon as it detects an exec. We don't do that
2257 here instead, because there may be other attempts to delete
2258 breakpoints after detecting an exec and before reaching here. */
2259 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2260 if (bploc
->pspace
== current_program_space
)
2261 gdb_assert (!bploc
->inserted
);
2263 ALL_BREAKPOINTS_SAFE (b
, temp
)
2265 if (b
->pspace
!= current_program_space
)
2268 /* Solib breakpoints must be explicitly reset after an exec(). */
2269 if (b
->type
== bp_shlib_event
)
2271 delete_breakpoint (b
);
2275 /* JIT breakpoints must be explicitly reset after an exec(). */
2276 if (b
->type
== bp_jit_event
)
2278 delete_breakpoint (b
);
2282 /* Thread event breakpoints must be set anew after an exec(),
2283 as must overlay event and longjmp master breakpoints. */
2284 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2285 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2287 delete_breakpoint (b
);
2291 /* Step-resume breakpoints are meaningless after an exec(). */
2292 if (b
->type
== bp_step_resume
)
2294 delete_breakpoint (b
);
2298 /* Longjmp and longjmp-resume breakpoints are also meaningless
2300 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2302 delete_breakpoint (b
);
2306 if (b
->type
== bp_catchpoint
)
2308 /* For now, none of the bp_catchpoint breakpoints need to
2309 do anything at this point. In the future, if some of
2310 the catchpoints need to something, we will need to add
2311 a new method, and call this method from here. */
2315 /* bp_finish is a special case. The only way we ought to be able
2316 to see one of these when an exec() has happened, is if the user
2317 caught a vfork, and then said "finish". Ordinarily a finish just
2318 carries them to the call-site of the current callee, by setting
2319 a temporary bp there and resuming. But in this case, the finish
2320 will carry them entirely through the vfork & exec.
2322 We don't want to allow a bp_finish to remain inserted now. But
2323 we can't safely delete it, 'cause finish_command has a handle to
2324 the bp on a bpstat, and will later want to delete it. There's a
2325 chance (and I've seen it happen) that if we delete the bp_finish
2326 here, that its storage will get reused by the time finish_command
2327 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2328 We really must allow finish_command to delete a bp_finish.
2330 In the absense of a general solution for the "how do we know
2331 it's safe to delete something others may have handles to?"
2332 problem, what we'll do here is just uninsert the bp_finish, and
2333 let finish_command delete it.
2335 (We know the bp_finish is "doomed" in the sense that it's
2336 momentary, and will be deleted as soon as finish_command sees
2337 the inferior stopped. So it doesn't matter that the bp's
2338 address is probably bogus in the new a.out, unlike e.g., the
2339 solib breakpoints.) */
2341 if (b
->type
== bp_finish
)
2346 /* Without a symbolic address, we have little hope of the
2347 pre-exec() address meaning the same thing in the post-exec()
2349 if (b
->addr_string
== NULL
)
2351 delete_breakpoint (b
);
2355 /* FIXME what about longjmp breakpoints? Re-create them here? */
2356 create_overlay_event_breakpoint ("_ovly_debug_event");
2357 create_longjmp_master_breakpoint ("longjmp");
2358 create_longjmp_master_breakpoint ("_longjmp");
2359 create_longjmp_master_breakpoint ("siglongjmp");
2360 create_longjmp_master_breakpoint ("_siglongjmp");
2361 create_std_terminate_master_breakpoint ("std::terminate()");
2365 detach_breakpoints (int pid
)
2367 struct bp_location
*b
, **bp_tmp
;
2369 struct cleanup
*old_chain
= save_inferior_ptid ();
2370 struct inferior
*inf
= current_inferior ();
2372 if (pid
== PIDGET (inferior_ptid
))
2373 error (_("Cannot detach breakpoints of inferior_ptid"));
2375 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2376 inferior_ptid
= pid_to_ptid (pid
);
2377 ALL_BP_LOCATIONS (b
, bp_tmp
)
2379 if (b
->pspace
!= inf
->pspace
)
2383 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2385 do_cleanups (old_chain
);
2389 /* Remove the breakpoint location B from the current address space.
2390 Note that this is used to detach breakpoints from a child fork.
2391 When we get here, the child isn't in the inferior list, and neither
2392 do we have objects to represent its address space --- we should
2393 *not* look at b->pspace->aspace here. */
2396 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2400 /* B is never in moribund_locations by our callers. */
2401 gdb_assert (b
->owner
!= NULL
);
2403 if (b
->owner
->enable_state
== bp_permanent
)
2404 /* Permanent breakpoints cannot be inserted or removed. */
2407 /* The type of none suggests that owner is actually deleted.
2408 This should not ever happen. */
2409 gdb_assert (b
->owner
->type
!= bp_none
);
2411 if (b
->loc_type
== bp_loc_software_breakpoint
2412 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2414 /* "Normal" instruction breakpoint: either the standard
2415 trap-instruction bp (bp_breakpoint), or a
2416 bp_hardware_breakpoint. */
2418 /* First check to see if we have to handle an overlay. */
2419 if (overlay_debugging
== ovly_off
2420 || b
->section
== NULL
2421 || !(section_is_overlay (b
->section
)))
2423 /* No overlay handling: just remove the breakpoint. */
2425 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2426 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2428 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2432 /* This breakpoint is in an overlay section.
2433 Did we set a breakpoint at the LMA? */
2434 if (!overlay_events_enabled
)
2436 /* Yes -- overlay event support is not active, so we
2437 should have set a breakpoint at the LMA. Remove it.
2439 /* Ignore any failures: if the LMA is in ROM, we will
2440 have already warned when we failed to insert it. */
2441 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2442 target_remove_hw_breakpoint (b
->gdbarch
,
2443 &b
->overlay_target_info
);
2445 target_remove_breakpoint (b
->gdbarch
,
2446 &b
->overlay_target_info
);
2448 /* Did we set a breakpoint at the VMA?
2449 If so, we will have marked the breakpoint 'inserted'. */
2452 /* Yes -- remove it. Previously we did not bother to
2453 remove the breakpoint if the section had been
2454 unmapped, but let's not rely on that being safe. We
2455 don't know what the overlay manager might do. */
2456 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2457 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2460 /* However, we should remove *software* breakpoints only
2461 if the section is still mapped, or else we overwrite
2462 wrong code with the saved shadow contents. */
2463 else if (section_is_mapped (b
->section
))
2464 val
= target_remove_breakpoint (b
->gdbarch
,
2471 /* No -- not inserted, so no need to remove. No error. */
2476 /* In some cases, we might not be able to remove a breakpoint
2477 in a shared library that has already been removed, but we
2478 have not yet processed the shlib unload event. */
2479 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2484 b
->inserted
= (is
== mark_inserted
);
2486 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2488 b
->inserted
= (is
== mark_inserted
);
2489 val
= target_remove_watchpoint (b
->address
, b
->length
,
2490 b
->watchpoint_type
);
2492 /* Failure to remove any of the hardware watchpoints comes here. */
2493 if ((is
== mark_uninserted
) && (b
->inserted
))
2494 warning (_("Could not remove hardware watchpoint %d."),
2497 else if (b
->owner
->type
== bp_catchpoint
2498 && breakpoint_enabled (b
->owner
)
2501 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2503 val
= b
->owner
->ops
->remove (b
->owner
);
2506 b
->inserted
= (is
== mark_inserted
);
2513 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2516 struct cleanup
*old_chain
;
2518 /* B is never in moribund_locations by our callers. */
2519 gdb_assert (b
->owner
!= NULL
);
2521 if (b
->owner
->enable_state
== bp_permanent
)
2522 /* Permanent breakpoints cannot be inserted or removed. */
2525 /* The type of none suggests that owner is actually deleted.
2526 This should not ever happen. */
2527 gdb_assert (b
->owner
->type
!= bp_none
);
2529 old_chain
= save_current_space_and_thread ();
2531 switch_to_program_space_and_thread (b
->pspace
);
2533 ret
= remove_breakpoint_1 (b
, is
);
2535 do_cleanups (old_chain
);
2539 /* Clear the "inserted" flag in all breakpoints. */
2542 mark_breakpoints_out (void)
2544 struct bp_location
*bpt
, **bptp_tmp
;
2546 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2547 if (bpt
->pspace
== current_program_space
)
2551 /* Clear the "inserted" flag in all breakpoints and delete any
2552 breakpoints which should go away between runs of the program.
2554 Plus other such housekeeping that has to be done for breakpoints
2557 Note: this function gets called at the end of a run (by
2558 generic_mourn_inferior) and when a run begins (by
2559 init_wait_for_inferior). */
2564 breakpoint_init_inferior (enum inf_context context
)
2566 struct breakpoint
*b
, *temp
;
2567 struct bp_location
*bpt
, **bptp_tmp
;
2569 struct program_space
*pspace
= current_program_space
;
2571 /* If breakpoint locations are shared across processes, then there's
2573 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2576 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2578 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2579 if (bpt
->pspace
== pspace
2580 && bpt
->owner
->enable_state
!= bp_permanent
)
2584 ALL_BREAKPOINTS_SAFE (b
, temp
)
2586 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2593 /* If the call dummy breakpoint is at the entry point it will
2594 cause problems when the inferior is rerun, so we better get
2597 case bp_watchpoint_scope
:
2599 /* Also get rid of scope breakpoints. */
2601 case bp_shlib_event
:
2603 /* Also remove solib event breakpoints. Their addresses may
2604 have changed since the last time we ran the program.
2605 Actually we may now be debugging against different target;
2606 and so the solib backend that installed this breakpoint may
2607 not be used in by the target. E.g.,
2609 (gdb) file prog-linux
2610 (gdb) run # native linux target
2613 (gdb) file prog-win.exe
2614 (gdb) tar rem :9999 # remote Windows gdbserver.
2617 delete_breakpoint (b
);
2621 case bp_hardware_watchpoint
:
2622 case bp_read_watchpoint
:
2623 case bp_access_watchpoint
:
2625 /* Likewise for watchpoints on local expressions. */
2626 if (b
->exp_valid_block
!= NULL
)
2627 delete_breakpoint (b
);
2628 else if (context
== inf_starting
)
2630 /* Reset val field to force reread of starting value
2631 in insert_breakpoints. */
2633 value_free (b
->val
);
2643 /* Get rid of the moribund locations. */
2644 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2645 free_bp_location (bpt
);
2646 VEC_free (bp_location_p
, moribund_locations
);
2649 /* These functions concern about actual breakpoints inserted in the
2650 target --- to e.g. check if we need to do decr_pc adjustment or if
2651 we need to hop over the bkpt --- so we check for address space
2652 match, not program space. */
2654 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2655 exists at PC. It returns ordinary_breakpoint_here if it's an
2656 ordinary breakpoint, or permanent_breakpoint_here if it's a
2657 permanent breakpoint.
2658 - When continuing from a location with an ordinary breakpoint, we
2659 actually single step once before calling insert_breakpoints.
2660 - When continuing from a localion with a permanent breakpoint, we
2661 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2662 the target, to advance the PC past the breakpoint. */
2664 enum breakpoint_here
2665 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2667 struct bp_location
*bpt
, **bptp_tmp
;
2668 int any_breakpoint_here
= 0;
2670 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2672 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2673 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2676 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2677 if ((breakpoint_enabled (bpt
->owner
)
2678 || bpt
->owner
->enable_state
== bp_permanent
)
2679 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2682 if (overlay_debugging
2683 && section_is_overlay (bpt
->section
)
2684 && !section_is_mapped (bpt
->section
))
2685 continue; /* unmapped overlay -- can't be a match */
2686 else if (bpt
->owner
->enable_state
== bp_permanent
)
2687 return permanent_breakpoint_here
;
2689 any_breakpoint_here
= 1;
2693 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2696 /* Return true if there's a moribund breakpoint at PC. */
2699 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2701 struct bp_location
*loc
;
2704 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2705 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2712 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2713 inserted using regular breakpoint_chain / bp_location array mechanism.
2714 This does not check for single-step breakpoints, which are
2715 inserted and removed using direct target manipulation. */
2718 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2720 struct bp_location
*bpt
, **bptp_tmp
;
2722 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2724 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2725 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2729 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2732 if (overlay_debugging
2733 && section_is_overlay (bpt
->section
)
2734 && !section_is_mapped (bpt
->section
))
2735 continue; /* unmapped overlay -- can't be a match */
2743 /* Returns non-zero iff there's either regular breakpoint
2744 or a single step breakpoint inserted at PC. */
2747 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2749 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2752 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2758 /* This function returns non-zero iff there is a software breakpoint
2762 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2764 struct bp_location
*bpt
, **bptp_tmp
;
2766 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2768 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2772 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2775 if (overlay_debugging
2776 && section_is_overlay (bpt
->section
)
2777 && !section_is_mapped (bpt
->section
))
2778 continue; /* unmapped overlay -- can't be a match */
2784 /* Also check for software single-step breakpoints. */
2785 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2792 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2793 CORE_ADDR addr
, ULONGEST len
)
2795 struct breakpoint
*bpt
;
2797 ALL_BREAKPOINTS (bpt
)
2799 struct bp_location
*loc
;
2801 if (bpt
->type
!= bp_hardware_watchpoint
2802 && bpt
->type
!= bp_access_watchpoint
)
2805 if (!breakpoint_enabled (bpt
))
2808 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2809 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2813 /* Check for intersection. */
2814 l
= max (loc
->address
, addr
);
2815 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2823 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2824 PC is valid for process/thread PTID. */
2827 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2830 struct bp_location
*bpt
, **bptp_tmp
;
2831 /* The thread and task IDs associated to PTID, computed lazily. */
2835 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2837 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2838 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2841 /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */
2842 if (!breakpoint_enabled (bpt
->owner
)
2843 && bpt
->owner
->enable_state
!= bp_permanent
)
2846 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2850 if (bpt
->owner
->thread
!= -1)
2852 /* This is a thread-specific breakpoint. Check that ptid
2853 matches that thread. If thread hasn't been computed yet,
2854 it is now time to do so. */
2856 thread
= pid_to_thread_id (ptid
);
2857 if (bpt
->owner
->thread
!= thread
)
2861 if (bpt
->owner
->task
!= 0)
2863 /* This is a task-specific breakpoint. Check that ptid
2864 matches that task. If task hasn't been computed yet,
2865 it is now time to do so. */
2867 task
= ada_get_task_number (ptid
);
2868 if (bpt
->owner
->task
!= task
)
2872 if (overlay_debugging
2873 && section_is_overlay (bpt
->section
)
2874 && !section_is_mapped (bpt
->section
))
2875 continue; /* unmapped overlay -- can't be a match */
2884 /* bpstat stuff. External routines' interfaces are documented
2888 ep_is_catchpoint (struct breakpoint
*ep
)
2890 return (ep
->type
== bp_catchpoint
);
2894 bpstat_free (bpstat bs
)
2896 if (bs
->old_val
!= NULL
)
2897 value_free (bs
->old_val
);
2898 decref_counted_command_line (&bs
->commands
);
2902 /* Clear a bpstat so that it says we are not at any breakpoint.
2903 Also free any storage that is part of a bpstat. */
2906 bpstat_clear (bpstat
*bsp
)
2923 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2924 is part of the bpstat is copied as well. */
2927 bpstat_copy (bpstat bs
)
2931 bpstat retval
= NULL
;
2936 for (; bs
!= NULL
; bs
= bs
->next
)
2938 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2939 memcpy (tmp
, bs
, sizeof (*tmp
));
2940 incref_counted_command_line (tmp
->commands
);
2941 if (bs
->old_val
!= NULL
)
2943 tmp
->old_val
= value_copy (bs
->old_val
);
2944 release_value (tmp
->old_val
);
2948 /* This is the first thing in the chain. */
2958 /* Find the bpstat associated with this breakpoint */
2961 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2966 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2968 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2974 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2975 at. *BSP upon return is a bpstat which points to the remaining
2976 breakpoints stopped at (but which is not guaranteed to be good for
2977 anything but further calls to bpstat_num).
2978 Return 0 if passed a bpstat which does not indicate any breakpoints.
2979 Return -1 if stopped at a breakpoint that has been deleted since
2981 Return 1 otherwise. */
2984 bpstat_num (bpstat
*bsp
, int *num
)
2986 struct breakpoint
*b
;
2989 return 0; /* No more breakpoint values */
2991 /* We assume we'll never have several bpstats that
2992 correspond to a single breakpoint -- otherwise,
2993 this function might return the same number more
2994 than once and this will look ugly. */
2995 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2996 *bsp
= (*bsp
)->next
;
2998 return -1; /* breakpoint that's been deleted since */
3000 *num
= b
->number
; /* We have its number */
3004 /* Modify BS so that the actions will not be performed. */
3007 bpstat_clear_actions (bpstat bs
)
3009 for (; bs
!= NULL
; bs
= bs
->next
)
3011 decref_counted_command_line (&bs
->commands
);
3012 bs
->commands_left
= NULL
;
3013 if (bs
->old_val
!= NULL
)
3015 value_free (bs
->old_val
);
3021 /* Called when a command is about to proceed the inferior. */
3024 breakpoint_about_to_proceed (void)
3026 if (!ptid_equal (inferior_ptid
, null_ptid
))
3028 struct thread_info
*tp
= inferior_thread ();
3030 /* Allow inferior function calls in breakpoint commands to not
3031 interrupt the command list. When the call finishes
3032 successfully, the inferior will be standing at the same
3033 breakpoint as if nothing happened. */
3038 breakpoint_proceeded
= 1;
3041 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3043 cleanup_executing_breakpoints (void *ignore
)
3045 executing_breakpoint_commands
= 0;
3048 /* Execute all the commands associated with all the breakpoints at this
3049 location. Any of these commands could cause the process to proceed
3050 beyond this point, etc. We look out for such changes by checking
3051 the global "breakpoint_proceeded" after each command.
3053 Returns true if a breakpoint command resumed the inferior. In that
3054 case, it is the caller's responsibility to recall it again with the
3055 bpstat of the current thread. */
3058 bpstat_do_actions_1 (bpstat
*bsp
)
3061 struct cleanup
*old_chain
;
3064 /* Avoid endless recursion if a `source' command is contained
3066 if (executing_breakpoint_commands
)
3069 executing_breakpoint_commands
= 1;
3070 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3072 /* This pointer will iterate over the list of bpstat's. */
3075 breakpoint_proceeded
= 0;
3076 for (; bs
!= NULL
; bs
= bs
->next
)
3078 struct counted_command_line
*ccmd
;
3079 struct command_line
*cmd
;
3080 struct cleanup
*this_cmd_tree_chain
;
3082 /* Take ownership of the BSP's command tree, if it has one.
3084 The command tree could legitimately contain commands like
3085 'step' and 'next', which call clear_proceed_status, which
3086 frees stop_bpstat's command tree. To make sure this doesn't
3087 free the tree we're executing out from under us, we need to
3088 take ownership of the tree ourselves. Since a given bpstat's
3089 commands are only executed once, we don't need to copy it; we
3090 can clear the pointer in the bpstat, and make sure we free
3091 the tree when we're done. */
3092 ccmd
= bs
->commands
;
3093 bs
->commands
= NULL
;
3095 = make_cleanup_decref_counted_command_line (&ccmd
);
3096 cmd
= bs
->commands_left
;
3097 bs
->commands_left
= NULL
;
3101 execute_control_command (cmd
);
3103 if (breakpoint_proceeded
)
3109 /* We can free this command tree now. */
3110 do_cleanups (this_cmd_tree_chain
);
3112 if (breakpoint_proceeded
)
3114 if (target_can_async_p ())
3115 /* If we are in async mode, then the target might be still
3116 running, not stopped at any breakpoint, so nothing for
3117 us to do here -- just return to the event loop. */
3120 /* In sync mode, when execute_control_command returns
3121 we're already standing on the next breakpoint.
3122 Breakpoint commands for that stop were not run, since
3123 execute_command does not run breakpoint commands --
3124 only command_line_handler does, but that one is not
3125 involved in execution of breakpoint commands. So, we
3126 can now execute breakpoint commands. It should be
3127 noted that making execute_command do bpstat actions is
3128 not an option -- in this case we'll have recursive
3129 invocation of bpstat for each breakpoint with a
3130 command, and can easily blow up GDB stack. Instead, we
3131 return true, which will trigger the caller to recall us
3132 with the new stop_bpstat. */
3137 do_cleanups (old_chain
);
3142 bpstat_do_actions (void)
3144 /* Do any commands attached to breakpoint we are stopped at. */
3145 while (!ptid_equal (inferior_ptid
, null_ptid
)
3146 && target_has_execution
3147 && !is_exited (inferior_ptid
)
3148 && !is_executing (inferior_ptid
))
3149 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3150 and only return when it is stopped at the next breakpoint, we
3151 keep doing breakpoint actions until it returns false to
3152 indicate the inferior was not resumed. */
3153 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3157 /* Print out the (old or new) value associated with a watchpoint. */
3160 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3163 fprintf_unfiltered (stream
, _("<unreadable>"));
3166 struct value_print_options opts
;
3167 get_user_print_options (&opts
);
3168 value_print (val
, stream
, &opts
);
3172 /* This is the normal print function for a bpstat. In the future,
3173 much of this logic could (should?) be moved to bpstat_stop_status,
3174 by having it set different print_it values.
3176 Current scheme: When we stop, bpstat_print() is called. It loops
3177 through the bpstat list of things causing this stop, calling the
3178 print_bp_stop_message function on each one. The behavior of the
3179 print_bp_stop_message function depends on the print_it field of
3180 bpstat. If such field so indicates, call this function here.
3182 Return values from this routine (ultimately used by bpstat_print()
3183 and normal_stop() to decide what to do):
3184 PRINT_NOTHING: Means we already printed all we needed to print,
3185 don't print anything else.
3186 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3187 that something to be followed by a location.
3188 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3189 that something to be followed by a location.
3190 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3193 static enum print_stop_action
3194 print_it_typical (bpstat bs
)
3196 struct cleanup
*old_chain
;
3197 struct breakpoint
*b
;
3198 const struct bp_location
*bl
;
3199 struct ui_stream
*stb
;
3201 enum print_stop_action result
;
3203 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3204 which has since been deleted. */
3205 if (bs
->breakpoint_at
== NULL
)
3206 return PRINT_UNKNOWN
;
3207 bl
= bs
->breakpoint_at
;
3209 /* bl->owner can be NULL if it was a momentary breakpoint
3210 which has since been placed into moribund_locations. */
3211 if (bl
->owner
== NULL
)
3212 return PRINT_UNKNOWN
;
3215 stb
= ui_out_stream_new (uiout
);
3216 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3221 case bp_hardware_breakpoint
:
3222 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3223 if (bl
->address
!= bl
->requested_address
)
3224 breakpoint_adjustment_warning (bl
->requested_address
,
3227 annotate_breakpoint (b
->number
);
3229 ui_out_text (uiout
, "\nTemporary breakpoint ");
3231 ui_out_text (uiout
, "\nBreakpoint ");
3232 if (ui_out_is_mi_like_p (uiout
))
3234 ui_out_field_string (uiout
, "reason",
3235 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3236 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3238 ui_out_field_int (uiout
, "bkptno", b
->number
);
3239 ui_out_text (uiout
, ", ");
3240 result
= PRINT_SRC_AND_LOC
;
3243 case bp_shlib_event
:
3244 /* Did we stop because the user set the stop_on_solib_events
3245 variable? (If so, we report this as a generic, "Stopped due
3246 to shlib event" message.) */
3247 printf_filtered (_("Stopped due to shared library event\n"));
3248 result
= PRINT_NOTHING
;
3251 case bp_thread_event
:
3252 /* Not sure how we will get here.
3253 GDB should not stop for these breakpoints. */
3254 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3255 result
= PRINT_NOTHING
;
3258 case bp_overlay_event
:
3259 /* By analogy with the thread event, GDB should not stop for these. */
3260 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3261 result
= PRINT_NOTHING
;
3264 case bp_longjmp_master
:
3265 /* These should never be enabled. */
3266 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3267 result
= PRINT_NOTHING
;
3270 case bp_std_terminate_master
:
3271 /* These should never be enabled. */
3272 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3273 result
= PRINT_NOTHING
;
3277 case bp_hardware_watchpoint
:
3278 annotate_watchpoint (b
->number
);
3279 if (ui_out_is_mi_like_p (uiout
))
3282 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3284 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3285 ui_out_text (uiout
, "\nOld value = ");
3286 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3287 ui_out_field_stream (uiout
, "old", stb
);
3288 ui_out_text (uiout
, "\nNew value = ");
3289 watchpoint_value_print (b
->val
, stb
->stream
);
3290 ui_out_field_stream (uiout
, "new", stb
);
3291 ui_out_text (uiout
, "\n");
3292 /* More than one watchpoint may have been triggered. */
3293 result
= PRINT_UNKNOWN
;
3296 case bp_read_watchpoint
:
3297 if (ui_out_is_mi_like_p (uiout
))
3300 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3302 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3303 ui_out_text (uiout
, "\nValue = ");
3304 watchpoint_value_print (b
->val
, stb
->stream
);
3305 ui_out_field_stream (uiout
, "value", stb
);
3306 ui_out_text (uiout
, "\n");
3307 result
= PRINT_UNKNOWN
;
3310 case bp_access_watchpoint
:
3311 if (bs
->old_val
!= NULL
)
3313 annotate_watchpoint (b
->number
);
3314 if (ui_out_is_mi_like_p (uiout
))
3317 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3319 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3320 ui_out_text (uiout
, "\nOld value = ");
3321 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3322 ui_out_field_stream (uiout
, "old", stb
);
3323 ui_out_text (uiout
, "\nNew value = ");
3328 if (ui_out_is_mi_like_p (uiout
))
3331 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3332 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3333 ui_out_text (uiout
, "\nValue = ");
3335 watchpoint_value_print (b
->val
, stb
->stream
);
3336 ui_out_field_stream (uiout
, "new", stb
);
3337 ui_out_text (uiout
, "\n");
3338 result
= PRINT_UNKNOWN
;
3341 /* Fall through, we don't deal with these types of breakpoints
3345 if (ui_out_is_mi_like_p (uiout
))
3348 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3349 result
= PRINT_UNKNOWN
;
3353 if (ui_out_is_mi_like_p (uiout
))
3356 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3357 result
= PRINT_UNKNOWN
;
3362 case bp_longjmp_resume
:
3363 case bp_step_resume
:
3364 case bp_watchpoint_scope
:
3366 case bp_std_terminate
:
3368 case bp_fast_tracepoint
:
3371 result
= PRINT_UNKNOWN
;
3375 do_cleanups (old_chain
);
3379 /* Generic routine for printing messages indicating why we
3380 stopped. The behavior of this function depends on the value
3381 'print_it' in the bpstat structure. Under some circumstances we
3382 may decide not to print anything here and delegate the task to
3385 static enum print_stop_action
3386 print_bp_stop_message (bpstat bs
)
3388 switch (bs
->print_it
)
3391 /* Nothing should be printed for this bpstat entry. */
3392 return PRINT_UNKNOWN
;
3396 /* We still want to print the frame, but we already printed the
3397 relevant messages. */
3398 return PRINT_SRC_AND_LOC
;
3401 case print_it_normal
:
3403 const struct bp_location
*bl
= bs
->breakpoint_at
;
3404 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3406 /* Normal case. Call the breakpoint's print_it method, or
3407 print_it_typical. */
3408 /* FIXME: how breakpoint can ever be NULL here? */
3409 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3410 return b
->ops
->print_it (b
);
3412 return print_it_typical (bs
);
3417 internal_error (__FILE__
, __LINE__
,
3418 _("print_bp_stop_message: unrecognized enum value"));
3423 /* Print a message indicating what happened. This is called from
3424 normal_stop(). The input to this routine is the head of the bpstat
3425 list - a list of the eventpoints that caused this stop. This
3426 routine calls the generic print routine for printing a message
3427 about reasons for stopping. This will print (for example) the
3428 "Breakpoint n," part of the output. The return value of this
3431 PRINT_UNKNOWN: Means we printed nothing
3432 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3433 code to print the location. An example is
3434 "Breakpoint 1, " which should be followed by
3436 PRINT_SRC_ONLY: Means we printed something, but there is no need
3437 to also print the location part of the message.
3438 An example is the catch/throw messages, which
3439 don't require a location appended to the end.
3440 PRINT_NOTHING: We have done some printing and we don't need any
3441 further info to be printed.*/
3443 enum print_stop_action
3444 bpstat_print (bpstat bs
)
3448 /* Maybe another breakpoint in the chain caused us to stop.
3449 (Currently all watchpoints go on the bpstat whether hit or not.
3450 That probably could (should) be changed, provided care is taken
3451 with respect to bpstat_explains_signal). */
3452 for (; bs
; bs
= bs
->next
)
3454 val
= print_bp_stop_message (bs
);
3455 if (val
== PRINT_SRC_ONLY
3456 || val
== PRINT_SRC_AND_LOC
3457 || val
== PRINT_NOTHING
)
3461 /* We reached the end of the chain, or we got a null BS to start
3462 with and nothing was printed. */
3463 return PRINT_UNKNOWN
;
3466 /* Evaluate the expression EXP and return 1 if value is zero.
3467 This is used inside a catch_errors to evaluate the breakpoint condition.
3468 The argument is a "struct expression *" that has been cast to char * to
3469 make it pass through catch_errors. */
3472 breakpoint_cond_eval (void *exp
)
3474 struct value
*mark
= value_mark ();
3475 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3477 value_free_to_mark (mark
);
3481 /* Allocate a new bpstat and chain it to the current one. */
3484 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3488 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3490 bs
->breakpoint_at
= bl
;
3491 /* If the condition is false, etc., don't do the commands. */
3492 bs
->commands
= NULL
;
3493 bs
->commands_left
= NULL
;
3495 bs
->print_it
= print_it_normal
;
3499 /* The target has stopped with waitstatus WS. Check if any hardware
3500 watchpoints have triggered, according to the target. */
3503 watchpoints_triggered (struct target_waitstatus
*ws
)
3505 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3507 struct breakpoint
*b
;
3509 if (!stopped_by_watchpoint
)
3511 /* We were not stopped by a watchpoint. Mark all watchpoints
3512 as not triggered. */
3514 if (is_hardware_watchpoint (b
))
3515 b
->watchpoint_triggered
= watch_triggered_no
;
3520 if (!target_stopped_data_address (¤t_target
, &addr
))
3522 /* We were stopped by a watchpoint, but we don't know where.
3523 Mark all watchpoints as unknown. */
3525 if (is_hardware_watchpoint (b
))
3526 b
->watchpoint_triggered
= watch_triggered_unknown
;
3528 return stopped_by_watchpoint
;
3531 /* The target could report the data address. Mark watchpoints
3532 affected by this data address as triggered, and all others as not
3536 if (is_hardware_watchpoint (b
))
3538 struct bp_location
*loc
;
3540 b
->watchpoint_triggered
= watch_triggered_no
;
3541 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3542 /* Exact match not required. Within range is
3544 if (target_watchpoint_addr_within_range (¤t_target
,
3548 b
->watchpoint_triggered
= watch_triggered_yes
;
3556 /* Possible return values for watchpoint_check (this can't be an enum
3557 because of check_errors). */
3558 /* The watchpoint has been deleted. */
3559 #define WP_DELETED 1
3560 /* The value has changed. */
3561 #define WP_VALUE_CHANGED 2
3562 /* The value has not changed. */
3563 #define WP_VALUE_NOT_CHANGED 3
3564 /* Ignore this watchpoint, no matter if the value changed or not. */
3567 #define BP_TEMPFLAG 1
3568 #define BP_HARDWAREFLAG 2
3570 /* Evaluate watchpoint condition expression and check if its value changed.
3572 P should be a pointer to struct bpstat, but is defined as a void *
3573 in order for this function to be usable with catch_errors. */
3576 watchpoint_check (void *p
)
3578 bpstat bs
= (bpstat
) p
;
3579 struct breakpoint
*b
;
3580 struct frame_info
*fr
;
3581 int within_current_scope
;
3583 /* BS is built for existing struct breakpoint. */
3584 gdb_assert (bs
->breakpoint_at
!= NULL
);
3585 gdb_assert (bs
->breakpoint_at
->owner
!= NULL
);
3586 b
= bs
->breakpoint_at
->owner
;
3588 /* If this is a local watchpoint, we only want to check if the
3589 watchpoint frame is in scope if the current thread is the thread
3590 that was used to create the watchpoint. */
3591 if (!watchpoint_in_thread_scope (b
))
3594 if (b
->exp_valid_block
== NULL
)
3595 within_current_scope
= 1;
3598 struct frame_info
*frame
= get_current_frame ();
3599 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3600 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3602 /* in_function_epilogue_p() returns a non-zero value if we're still
3603 in the function but the stack frame has already been invalidated.
3604 Since we can't rely on the values of local variables after the
3605 stack has been destroyed, we are treating the watchpoint in that
3606 state as `not changed' without further checking. Don't mark
3607 watchpoints as changed if the current frame is in an epilogue -
3608 even if they are in some other frame, our view of the stack
3609 is likely to be wrong and frame_find_by_id could error out. */
3610 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3613 fr
= frame_find_by_id (b
->watchpoint_frame
);
3614 within_current_scope
= (fr
!= NULL
);
3616 /* If we've gotten confused in the unwinder, we might have
3617 returned a frame that can't describe this variable. */
3618 if (within_current_scope
)
3620 struct symbol
*function
;
3622 function
= get_frame_function (fr
);
3623 if (function
== NULL
3624 || !contained_in (b
->exp_valid_block
,
3625 SYMBOL_BLOCK_VALUE (function
)))
3626 within_current_scope
= 0;
3629 if (within_current_scope
)
3630 /* If we end up stopping, the current frame will get selected
3631 in normal_stop. So this call to select_frame won't affect
3636 if (within_current_scope
)
3638 /* We use value_{,free_to_}mark because it could be a
3639 *long* time before we return to the command level and
3640 call free_all_values. We can't call free_all_values because
3641 we might be in the middle of evaluating a function call. */
3643 struct value
*mark
= value_mark ();
3644 struct value
*new_val
;
3646 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3648 /* We use value_equal_contents instead of value_equal because the latter
3649 coerces an array to a pointer, thus comparing just the address of the
3650 array instead of its contents. This is not what we want. */
3651 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3652 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3654 if (new_val
!= NULL
)
3656 release_value (new_val
);
3657 value_free_to_mark (mark
);
3659 bs
->old_val
= b
->val
;
3662 return WP_VALUE_CHANGED
;
3666 /* Nothing changed. */
3667 value_free_to_mark (mark
);
3668 return WP_VALUE_NOT_CHANGED
;
3673 /* This seems like the only logical thing to do because
3674 if we temporarily ignored the watchpoint, then when
3675 we reenter the block in which it is valid it contains
3676 garbage (in the case of a function, it may have two
3677 garbage values, one before and one after the prologue).
3678 So we can't even detect the first assignment to it and
3679 watch after that (since the garbage may or may not equal
3680 the first value assigned). */
3681 /* We print all the stop information in print_it_typical(), but
3682 in this case, by the time we call print_it_typical() this bp
3683 will be deleted already. So we have no choice but print the
3684 information here. */
3685 if (ui_out_is_mi_like_p (uiout
))
3687 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3688 ui_out_text (uiout
, "\nWatchpoint ");
3689 ui_out_field_int (uiout
, "wpnum", b
->number
);
3690 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3691 which its expression is valid.\n");
3693 if (b
->related_breakpoint
)
3695 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3696 b
->related_breakpoint
->related_breakpoint
= NULL
;
3697 b
->related_breakpoint
= NULL
;
3699 b
->disposition
= disp_del_at_next_stop
;
3705 /* Return true if it looks like target has stopped due to hitting
3706 breakpoint location BL. This function does not check if we
3707 should stop, only if BL explains the stop. */
3709 bpstat_check_location (const struct bp_location
*bl
,
3710 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3712 struct breakpoint
*b
= bl
->owner
;
3714 /* BL is from existing struct breakpoint. */
3715 gdb_assert (b
!= NULL
);
3717 /* By definition, the inferior does not report stops at
3719 if (is_tracepoint (b
))
3722 if (!is_watchpoint (b
)
3723 && b
->type
!= bp_hardware_breakpoint
3724 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3726 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3729 if (overlay_debugging
/* unmapped overlay section */
3730 && section_is_overlay (bl
->section
)
3731 && !section_is_mapped (bl
->section
))
3735 /* Continuable hardware watchpoints are treated as non-existent if the
3736 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3737 some data address). Otherwise gdb won't stop on a break instruction
3738 in the code (not from a breakpoint) when a hardware watchpoint has
3739 been defined. Also skip watchpoints which we know did not trigger
3740 (did not match the data address). */
3742 if (is_hardware_watchpoint (b
)
3743 && b
->watchpoint_triggered
== watch_triggered_no
)
3746 if (b
->type
== bp_hardware_breakpoint
)
3748 if (bl
->address
!= bp_addr
)
3750 if (overlay_debugging
/* unmapped overlay section */
3751 && section_is_overlay (bl
->section
)
3752 && !section_is_mapped (bl
->section
))
3756 if (b
->type
== bp_catchpoint
)
3758 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3759 if (!b
->ops
->breakpoint_hit (b
))
3766 /* If BS refers to a watchpoint, determine if the watched values
3767 has actually changed, and we should stop. If not, set BS->stop
3770 bpstat_check_watchpoint (bpstat bs
)
3772 const struct bp_location
*bl
;
3773 struct breakpoint
*b
;
3775 /* BS is built for existing struct breakpoint. */
3776 bl
= bs
->breakpoint_at
;
3777 gdb_assert (bl
!= NULL
);
3779 gdb_assert (b
!= NULL
);
3781 if (is_watchpoint (b
))
3783 int must_check_value
= 0;
3785 if (b
->type
== bp_watchpoint
)
3786 /* For a software watchpoint, we must always check the
3788 must_check_value
= 1;
3789 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3790 /* We have a hardware watchpoint (read, write, or access)
3791 and the target earlier reported an address watched by
3793 must_check_value
= 1;
3794 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3795 && b
->type
== bp_hardware_watchpoint
)
3796 /* We were stopped by a hardware watchpoint, but the target could
3797 not report the data address. We must check the watchpoint's
3798 value. Access and read watchpoints are out of luck; without
3799 a data address, we can't figure it out. */
3800 must_check_value
= 1;
3802 if (must_check_value
)
3804 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3806 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3807 int e
= catch_errors (watchpoint_check
, bs
, message
,
3809 do_cleanups (cleanups
);
3813 /* We've already printed what needs to be printed. */
3814 bs
->print_it
= print_it_done
;
3818 bs
->print_it
= print_it_noop
;
3821 case WP_VALUE_CHANGED
:
3822 if (b
->type
== bp_read_watchpoint
)
3824 /* There are two cases to consider here:
3826 1. we're watching the triggered memory for reads.
3827 In that case, trust the target, and always report
3828 the watchpoint hit to the user. Even though
3829 reads don't cause value changes, the value may
3830 have changed since the last time it was read, and
3831 since we're not trapping writes, we will not see
3832 those, and as such we should ignore our notion of
3835 2. we're watching the triggered memory for both
3836 reads and writes. There are two ways this may
3839 2.1. this is a target that can't break on data
3840 reads only, but can break on accesses (reads or
3841 writes), such as e.g., x86. We detect this case
3842 at the time we try to insert read watchpoints.
3844 2.2. otherwise, the target supports read
3845 watchpoints, but, the user set an access or write
3846 watchpoint watching the same memory as this read
3849 If we're watching memory writes as well as reads,
3850 ignore watchpoint hits when we find that the
3851 value hasn't changed, as reads don't cause
3852 changes. This still gives false positives when
3853 the program writes the same value to memory as
3854 what there was already in memory (we will confuse
3855 it for a read), but it's much better than
3858 int other_write_watchpoint
= 0;
3860 if (bl
->watchpoint_type
== hw_read
)
3862 struct breakpoint
*other_b
;
3864 ALL_BREAKPOINTS (other_b
)
3865 if ((other_b
->type
== bp_hardware_watchpoint
3866 || other_b
->type
== bp_access_watchpoint
)
3867 && (other_b
->watchpoint_triggered
3868 == watch_triggered_yes
))
3870 other_write_watchpoint
= 1;
3875 if (other_write_watchpoint
3876 || bl
->watchpoint_type
== hw_access
)
3878 /* We're watching the same memory for writes,
3879 and the value changed since the last time we
3880 updated it, so this trap must be for a write.
3882 bs
->print_it
= print_it_noop
;
3887 case WP_VALUE_NOT_CHANGED
:
3888 if (b
->type
== bp_hardware_watchpoint
3889 || b
->type
== bp_watchpoint
)
3891 /* Don't stop: write watchpoints shouldn't fire if
3892 the value hasn't changed. */
3893 bs
->print_it
= print_it_noop
;
3901 /* Error from catch_errors. */
3902 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3903 if (b
->related_breakpoint
)
3904 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3905 b
->disposition
= disp_del_at_next_stop
;
3906 /* We've already printed what needs to be printed. */
3907 bs
->print_it
= print_it_done
;
3911 else /* must_check_value == 0 */
3913 /* This is a case where some watchpoint(s) triggered, but
3914 not at the address of this watchpoint, or else no
3915 watchpoint triggered after all. So don't print
3916 anything for this watchpoint. */
3917 bs
->print_it
= print_it_noop
;
3924 /* Check conditions (condition proper, frame, thread and ignore count)
3925 of breakpoint referred to by BS. If we should not stop for this
3926 breakpoint, set BS->stop to 0. */
3928 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3930 int thread_id
= pid_to_thread_id (ptid
);
3931 const struct bp_location
*bl
;
3932 struct breakpoint
*b
;
3934 /* BS is built for existing struct breakpoint. */
3935 bl
= bs
->breakpoint_at
;
3936 gdb_assert (bl
!= NULL
);
3938 gdb_assert (b
!= NULL
);
3940 if (frame_id_p (b
->frame_id
)
3941 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3945 int value_is_zero
= 0;
3946 struct expression
*cond
;
3948 /* If this is a scope breakpoint, mark the associated
3949 watchpoint as triggered so that we will handle the
3950 out-of-scope event. We'll get to the watchpoint next
3952 if (b
->type
== bp_watchpoint_scope
)
3953 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3955 if (is_watchpoint (b
))
3960 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3962 int within_current_scope
= 1;
3964 /* We use value_mark and value_free_to_mark because it could
3965 be a long time before we return to the command level and
3966 call free_all_values. We can't call free_all_values
3967 because we might be in the middle of evaluating a
3969 struct value
*mark
= value_mark ();
3971 /* Need to select the frame, with all that implies so that
3972 the conditions will have the right context. Because we
3973 use the frame, we will not see an inlined function's
3974 variables when we arrive at a breakpoint at the start
3975 of the inlined function; the current frame will be the
3977 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3978 select_frame (get_current_frame ());
3981 struct frame_info
*frame
;
3983 /* For local watchpoint expressions, which particular
3984 instance of a local is being watched matters, so we
3985 keep track of the frame to evaluate the expression
3986 in. To evaluate the condition however, it doesn't
3987 really matter which instantiation of the function
3988 where the condition makes sense triggers the
3989 watchpoint. This allows an expression like "watch
3990 global if q > 10" set in `func', catch writes to
3991 global on all threads that call `func', or catch
3992 writes on all recursive calls of `func' by a single
3993 thread. We simply always evaluate the condition in
3994 the innermost frame that's executing where it makes
3995 sense to evaluate the condition. It seems
3997 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3999 select_frame (frame
);
4001 within_current_scope
= 0;
4003 if (within_current_scope
)
4005 = catch_errors (breakpoint_cond_eval
, cond
,
4006 "Error in testing breakpoint condition:\n",
4010 warning (_("Watchpoint condition cannot be tested "
4011 "in the current scope"));
4012 /* If we failed to set the right context for this
4013 watchpoint, unconditionally report it. */
4016 /* FIXME-someday, should give breakpoint # */
4017 value_free_to_mark (mark
);
4020 if (cond
&& value_is_zero
)
4024 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4028 else if (b
->ignore_count
> 0)
4031 annotate_ignore_count_change ();
4033 /* Increase the hit count even though we don't
4041 /* Get a bpstat associated with having just stopped at address
4042 BP_ADDR in thread PTID.
4044 Determine whether we stopped at a breakpoint, etc, or whether we
4045 don't understand this stop. Result is a chain of bpstat's such that:
4047 if we don't understand the stop, the result is a null pointer.
4049 if we understand why we stopped, the result is not null.
4051 Each element of the chain refers to a particular breakpoint or
4052 watchpoint at which we have stopped. (We may have stopped for
4053 several reasons concurrently.)
4055 Each element of the chain has valid next, breakpoint_at,
4056 commands, FIXME??? fields. */
4059 bpstat_stop_status (struct address_space
*aspace
,
4060 CORE_ADDR bp_addr
, ptid_t ptid
)
4062 struct breakpoint
*b
= NULL
;
4063 struct bp_location
*bl
;
4064 struct bp_location
*loc
;
4065 /* Root of the chain of bpstat's */
4066 struct bpstats root_bs
[1];
4067 /* Pointer to the last thing in the chain currently. */
4068 bpstat bs
= root_bs
;
4070 int need_remove_insert
;
4072 /* ALL_BP_LOCATIONS iteration would break across
4073 update_global_location_list possibly executed by
4074 bpstat_check_breakpoint_conditions's inferior call. */
4078 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4081 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4083 /* For hardware watchpoints, we look only at the first location.
4084 The watchpoint_check function will work on the entire expression,
4085 not the individual locations. For read watchpoints, the
4086 watchpoints_triggered function has checked all locations
4088 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4091 if (bl
->shlib_disabled
)
4094 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4097 /* Come here if it's a watchpoint, or if the break address matches */
4099 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4101 /* Assume we stop. Should we find watchpoint that is not actually
4102 triggered, or if condition of breakpoint is false, we'll reset
4107 bpstat_check_watchpoint (bs
);
4111 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4112 || b
->type
== bp_longjmp_master
4113 || b
->type
== bp_std_terminate_master
)
4114 /* We do not stop for these. */
4117 bpstat_check_breakpoint_conditions (bs
, ptid
);
4123 /* We will stop here */
4124 if (b
->disposition
== disp_disable
)
4126 if (b
->enable_state
!= bp_permanent
)
4127 b
->enable_state
= bp_disabled
;
4128 update_global_location_list (0);
4132 bs
->commands
= b
->commands
;
4133 incref_counted_command_line (bs
->commands
);
4134 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4135 if (bs
->commands_left
4136 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4139 bs
->commands_left
->line
) == 0)))
4141 bs
->commands_left
= bs
->commands_left
->next
;
4146 /* Print nothing for this entry if we dont stop or dont print. */
4147 if (bs
->stop
== 0 || bs
->print
== 0)
4148 bs
->print_it
= print_it_noop
;
4152 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4154 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4157 bs
= bpstat_alloc (loc
, bs
);
4158 /* For hits of moribund locations, we should just proceed. */
4161 bs
->print_it
= print_it_noop
;
4165 bs
->next
= NULL
; /* Terminate the chain */
4167 /* If we aren't stopping, the value of some hardware watchpoint may
4168 not have changed, but the intermediate memory locations we are
4169 watching may have. Don't bother if we're stopping; this will get
4171 need_remove_insert
= 0;
4172 if (! bpstat_causes_stop (root_bs
->next
))
4173 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4175 && bs
->breakpoint_at
->owner
4176 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4178 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4179 /* Updating watchpoints invalidates bs->breakpoint_at.
4180 Prevent further code from trying to use it. */
4181 bs
->breakpoint_at
= NULL
;
4182 need_remove_insert
= 1;
4185 if (need_remove_insert
)
4186 update_global_location_list (1);
4188 return root_bs
->next
;
4191 /* Tell what to do about this bpstat. */
4193 bpstat_what (bpstat bs
)
4195 /* Classify each bpstat as one of the following. */
4198 /* This bpstat element has no effect on the main_action. */
4201 /* There was a watchpoint, stop but don't print. */
4204 /* There was a watchpoint, stop and print. */
4207 /* There was a breakpoint but we're not stopping. */
4210 /* There was a breakpoint, stop but don't print. */
4213 /* There was a breakpoint, stop and print. */
4216 /* We hit the longjmp breakpoint. */
4219 /* We hit the longjmp_resume breakpoint. */
4222 /* We hit the step_resume breakpoint. */
4225 /* We hit the shared library event breakpoint. */
4228 /* We hit the jit event breakpoint. */
4231 /* This is just used to count how many enums there are. */
4235 /* Here is the table which drives this routine. So that we can
4236 format it pretty, we define some abbreviations for the
4237 enum bpstat_what codes. */
4238 #define kc BPSTAT_WHAT_KEEP_CHECKING
4239 #define ss BPSTAT_WHAT_STOP_SILENT
4240 #define sn BPSTAT_WHAT_STOP_NOISY
4241 #define sgl BPSTAT_WHAT_SINGLE
4242 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4243 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4244 #define sr BPSTAT_WHAT_STEP_RESUME
4245 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4246 #define jit BPSTAT_WHAT_CHECK_JIT
4248 /* "Can't happen." Might want to print an error message.
4249 abort() is not out of the question, but chances are GDB is just
4250 a bit confused, not unusable. */
4251 #define err BPSTAT_WHAT_STOP_NOISY
4253 /* Given an old action and a class, come up with a new action. */
4254 /* One interesting property of this table is that wp_silent is the same
4255 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4256 after stopping, the check for whether to step over a breakpoint
4257 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4258 reference to how we stopped. We retain separate wp_silent and
4259 bp_silent codes in case we want to change that someday.
4261 Another possibly interesting property of this table is that
4262 there's a partial ordering, priority-like, of the actions. Once
4263 you've decided that some action is appropriate, you'll never go
4264 back and decide something of a lower priority is better. The
4267 kc < jit clr sgl shl slr sn sr ss
4268 sgl < jit shl slr sn sr ss
4269 slr < jit err shl sn sr ss
4270 clr < jit err shl sn sr ss
4277 What I think this means is that we don't need a damned table
4278 here. If you just put the rows and columns in the right order,
4279 it'd look awfully regular. We could simply walk the bpstat list
4280 and choose the highest priority action we find, with a little
4281 logic to handle the 'err' cases. */
4283 /* step_resume entries: a step resume breakpoint overrides another
4284 breakpoint of signal handling (see comment in wait_for_inferior
4285 at where we set the step_resume breakpoint). */
4287 static const enum bpstat_what_main_action
4288 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4291 /* kc ss sn sgl slr clr sr shl jit */
4292 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4293 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4294 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4295 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4296 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4297 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4298 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4299 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4300 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4301 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4302 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4316 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4317 struct bpstat_what retval
;
4319 retval
.call_dummy
= STOP_NONE
;
4320 for (; bs
!= NULL
; bs
= bs
->next
)
4322 enum class bs_class
= no_effect
;
4323 if (bs
->breakpoint_at
== NULL
)
4324 /* I suspect this can happen if it was a momentary breakpoint
4325 which has since been deleted. */
4327 if (bs
->breakpoint_at
->owner
== NULL
)
4328 bs_class
= bp_nostop
;
4330 switch (bs
->breakpoint_at
->owner
->type
)
4336 case bp_hardware_breakpoint
:
4342 bs_class
= bp_noisy
;
4344 bs_class
= bp_silent
;
4347 bs_class
= bp_nostop
;
4350 case bp_hardware_watchpoint
:
4351 case bp_read_watchpoint
:
4352 case bp_access_watchpoint
:
4356 bs_class
= wp_noisy
;
4358 bs_class
= wp_silent
;
4361 /* There was a watchpoint, but we're not stopping.
4362 This requires no further action. */
4363 bs_class
= no_effect
;
4366 bs_class
= long_jump
;
4368 case bp_longjmp_resume
:
4369 bs_class
= long_resume
;
4371 case bp_step_resume
:
4374 bs_class
= step_resume
;
4377 /* It is for the wrong frame. */
4378 bs_class
= bp_nostop
;
4380 case bp_watchpoint_scope
:
4381 bs_class
= bp_nostop
;
4383 case bp_shlib_event
:
4384 bs_class
= shlib_event
;
4387 bs_class
= jit_event
;
4389 case bp_thread_event
:
4390 case bp_overlay_event
:
4391 case bp_longjmp_master
:
4392 case bp_std_terminate_master
:
4393 bs_class
= bp_nostop
;
4399 bs_class
= bp_noisy
;
4401 bs_class
= bp_silent
;
4404 /* There was a catchpoint, but we're not stopping.
4405 This requires no further action. */
4406 bs_class
= no_effect
;
4409 /* Make sure the action is stop (silent or noisy),
4410 so infrun.c pops the dummy frame. */
4411 bs_class
= bp_silent
;
4412 retval
.call_dummy
= STOP_STACK_DUMMY
;
4414 case bp_std_terminate
:
4415 /* Make sure the action is stop (silent or noisy),
4416 so infrun.c pops the dummy frame. */
4417 bs_class
= bp_silent
;
4418 retval
.call_dummy
= STOP_STD_TERMINATE
;
4421 case bp_fast_tracepoint
:
4422 /* Tracepoint hits should not be reported back to GDB, and
4423 if one got through somehow, it should have been filtered
4425 internal_error (__FILE__
, __LINE__
,
4426 _("bpstat_what: tracepoint encountered"));
4429 current_action
= table
[(int) bs_class
][(int) current_action
];
4431 retval
.main_action
= current_action
;
4435 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4436 without hardware support). This isn't related to a specific bpstat,
4437 just to things like whether watchpoints are set. */
4440 bpstat_should_step (void)
4442 struct breakpoint
*b
;
4445 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4451 bpstat_causes_stop (bpstat bs
)
4453 for (; bs
!= NULL
; bs
= bs
->next
)
4462 /* Print the LOC location out of the list of B->LOC locations. */
4464 static void print_breakpoint_location (struct breakpoint
*b
,
4465 struct bp_location
*loc
,
4467 struct ui_stream
*stb
)
4469 struct cleanup
*old_chain
= save_current_program_space ();
4471 if (loc
!= NULL
&& loc
->shlib_disabled
)
4475 set_current_program_space (loc
->pspace
);
4477 if (b
->source_file
&& loc
)
4480 = find_pc_sect_function (loc
->address
, loc
->section
);
4483 ui_out_text (uiout
, "in ");
4484 ui_out_field_string (uiout
, "func",
4485 SYMBOL_PRINT_NAME (sym
));
4486 ui_out_wrap_hint (uiout
, wrap_indent
);
4487 ui_out_text (uiout
, " at ");
4489 ui_out_field_string (uiout
, "file", b
->source_file
);
4490 ui_out_text (uiout
, ":");
4492 if (ui_out_is_mi_like_p (uiout
))
4494 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4495 char *fullname
= symtab_to_fullname (sal
.symtab
);
4498 ui_out_field_string (uiout
, "fullname", fullname
);
4501 ui_out_field_int (uiout
, "line", b
->line_number
);
4505 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4507 ui_out_field_stream (uiout
, "at", stb
);
4510 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4512 do_cleanups (old_chain
);
4515 /* Print B to gdb_stdout. */
4517 print_one_breakpoint_location (struct breakpoint
*b
,
4518 struct bp_location
*loc
,
4520 struct bp_location
**last_loc
,
4521 int print_address_bits
,
4524 struct command_line
*l
;
4525 struct ep_type_description
4530 static struct ep_type_description bptypes
[] =
4532 {bp_none
, "?deleted?"},
4533 {bp_breakpoint
, "breakpoint"},
4534 {bp_hardware_breakpoint
, "hw breakpoint"},
4535 {bp_until
, "until"},
4536 {bp_finish
, "finish"},
4537 {bp_watchpoint
, "watchpoint"},
4538 {bp_hardware_watchpoint
, "hw watchpoint"},
4539 {bp_read_watchpoint
, "read watchpoint"},
4540 {bp_access_watchpoint
, "acc watchpoint"},
4541 {bp_longjmp
, "longjmp"},
4542 {bp_longjmp_resume
, "longjmp resume"},
4543 {bp_step_resume
, "step resume"},
4544 {bp_watchpoint_scope
, "watchpoint scope"},
4545 {bp_call_dummy
, "call dummy"},
4546 {bp_std_terminate
, "std::terminate"},
4547 {bp_shlib_event
, "shlib events"},
4548 {bp_thread_event
, "thread events"},
4549 {bp_overlay_event
, "overlay events"},
4550 {bp_longjmp_master
, "longjmp master"},
4551 {bp_std_terminate_master
, "std::terminate master"},
4552 {bp_catchpoint
, "catchpoint"},
4553 {bp_tracepoint
, "tracepoint"},
4554 {bp_fast_tracepoint
, "fast tracepoint"},
4555 {bp_jit_event
, "jit events"},
4558 static char bpenables
[] = "nynny";
4559 char wrap_indent
[80];
4560 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4561 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4562 struct cleanup
*bkpt_chain
;
4564 int header_of_multiple
= 0;
4565 int part_of_multiple
= (loc
!= NULL
);
4566 struct value_print_options opts
;
4568 get_user_print_options (&opts
);
4570 gdb_assert (!loc
|| loc_number
!= 0);
4571 /* See comment in print_one_breakpoint concerning
4572 treatment of breakpoints with single disabled
4576 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4577 header_of_multiple
= 1;
4582 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4586 if (part_of_multiple
)
4589 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4590 ui_out_field_string (uiout
, "number", formatted
);
4595 ui_out_field_int (uiout
, "number", b
->number
);
4600 if (part_of_multiple
)
4601 ui_out_field_skip (uiout
, "type");
4604 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4605 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4606 internal_error (__FILE__
, __LINE__
,
4607 _("bptypes table does not describe type #%d."),
4609 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4614 if (part_of_multiple
)
4615 ui_out_field_skip (uiout
, "disp");
4617 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4622 if (part_of_multiple
)
4623 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4625 ui_out_field_fmt (uiout
, "enabled", "%c",
4626 bpenables
[(int) b
->enable_state
]);
4627 ui_out_spaces (uiout
, 2);
4631 strcpy (wrap_indent
, " ");
4632 if (opts
.addressprint
)
4634 if (print_address_bits
<= 32)
4635 strcat (wrap_indent
, " ");
4637 strcat (wrap_indent
, " ");
4640 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4642 /* Although the print_one can possibly print
4643 all locations, calling it here is not likely
4644 to get any nice result. So, make sure there's
4645 just one location. */
4646 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4647 b
->ops
->print_one (b
, last_loc
);
4653 internal_error (__FILE__
, __LINE__
,
4654 _("print_one_breakpoint: bp_none encountered\n"));
4658 case bp_hardware_watchpoint
:
4659 case bp_read_watchpoint
:
4660 case bp_access_watchpoint
:
4661 /* Field 4, the address, is omitted (which makes the columns
4662 not line up too nicely with the headers, but the effect
4663 is relatively readable). */
4664 if (opts
.addressprint
)
4665 ui_out_field_skip (uiout
, "addr");
4667 ui_out_field_string (uiout
, "what", b
->exp_string
);
4671 case bp_hardware_breakpoint
:
4675 case bp_longjmp_resume
:
4676 case bp_step_resume
:
4677 case bp_watchpoint_scope
:
4679 case bp_std_terminate
:
4680 case bp_shlib_event
:
4681 case bp_thread_event
:
4682 case bp_overlay_event
:
4683 case bp_longjmp_master
:
4684 case bp_std_terminate_master
:
4686 case bp_fast_tracepoint
:
4688 if (opts
.addressprint
)
4691 if (header_of_multiple
)
4692 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4693 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4694 ui_out_field_string (uiout
, "addr", "<PENDING>");
4696 ui_out_field_core_addr (uiout
, "addr",
4697 loc
->gdbarch
, loc
->address
);
4700 if (!header_of_multiple
)
4701 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4708 /* For backward compatibility, don't display inferiors unless there
4711 && !header_of_multiple
4713 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4714 && (number_of_program_spaces () > 1
4715 || number_of_inferiors () > 1)
4716 /* LOC is for existing B, it cannot be in moribund_locations and
4717 thus having NULL OWNER. */
4718 && loc
->owner
->type
!= bp_catchpoint
)))
4720 struct inferior
*inf
;
4723 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4725 if (inf
->pspace
== loc
->pspace
)
4730 ui_out_text (uiout
, " inf ");
4733 ui_out_text (uiout
, ", ");
4734 ui_out_text (uiout
, plongest (inf
->num
));
4739 if (!part_of_multiple
)
4741 if (b
->thread
!= -1)
4743 /* FIXME: This seems to be redundant and lost here; see the
4744 "stop only in" line a little further down. */
4745 ui_out_text (uiout
, " thread ");
4746 ui_out_field_int (uiout
, "thread", b
->thread
);
4748 else if (b
->task
!= 0)
4750 ui_out_text (uiout
, " task ");
4751 ui_out_field_int (uiout
, "task", b
->task
);
4755 ui_out_text (uiout
, "\n");
4757 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4760 ui_out_text (uiout
, "\tstop only in stack frame at ");
4761 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4763 ui_out_field_core_addr (uiout
, "frame",
4764 b
->gdbarch
, b
->frame_id
.stack_addr
);
4765 ui_out_text (uiout
, "\n");
4768 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4770 /* We do not print the condition for Ada exception catchpoints
4771 because the condition is an internal implementation detail
4772 that we do not want to expose to the user. */
4774 if (is_tracepoint (b
))
4775 ui_out_text (uiout
, "\ttrace only if ");
4777 ui_out_text (uiout
, "\tstop only if ");
4778 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4779 ui_out_text (uiout
, "\n");
4782 if (!part_of_multiple
&& b
->thread
!= -1)
4784 /* FIXME should make an annotation for this */
4785 ui_out_text (uiout
, "\tstop only in thread ");
4786 ui_out_field_int (uiout
, "thread", b
->thread
);
4787 ui_out_text (uiout
, "\n");
4790 if (!part_of_multiple
&& b
->hit_count
)
4792 /* FIXME should make an annotation for this */
4793 if (ep_is_catchpoint (b
))
4794 ui_out_text (uiout
, "\tcatchpoint");
4796 ui_out_text (uiout
, "\tbreakpoint");
4797 ui_out_text (uiout
, " already hit ");
4798 ui_out_field_int (uiout
, "times", b
->hit_count
);
4799 if (b
->hit_count
== 1)
4800 ui_out_text (uiout
, " time\n");
4802 ui_out_text (uiout
, " times\n");
4805 /* Output the count also if it is zero, but only if this is
4806 mi. FIXME: Should have a better test for this. */
4807 if (ui_out_is_mi_like_p (uiout
))
4808 if (!part_of_multiple
&& b
->hit_count
== 0)
4809 ui_out_field_int (uiout
, "times", b
->hit_count
);
4811 if (!part_of_multiple
&& b
->ignore_count
)
4814 ui_out_text (uiout
, "\tignore next ");
4815 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4816 ui_out_text (uiout
, " hits\n");
4819 l
= b
->commands
? b
->commands
->commands
: NULL
;
4820 if (!part_of_multiple
&& l
)
4822 struct cleanup
*script_chain
;
4825 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4826 print_command_lines (uiout
, l
, 4);
4827 do_cleanups (script_chain
);
4830 if (!part_of_multiple
&& b
->pass_count
)
4832 annotate_field (10);
4833 ui_out_text (uiout
, "\tpass count ");
4834 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4835 ui_out_text (uiout
, " \n");
4838 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4841 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4842 else if (b
->exp_string
)
4843 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4846 do_cleanups (bkpt_chain
);
4847 do_cleanups (old_chain
);
4851 print_one_breakpoint (struct breakpoint
*b
,
4852 struct bp_location
**last_loc
, int print_address_bits
,
4855 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4856 print_address_bits
, allflag
);
4858 /* If this breakpoint has custom print function,
4859 it's already printed. Otherwise, print individual
4860 locations, if any. */
4861 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4863 /* If breakpoint has a single location that is
4864 disabled, we print it as if it had
4865 several locations, since otherwise it's hard to
4866 represent "breakpoint enabled, location disabled"
4868 Note that while hardware watchpoints have
4869 several locations internally, that's no a property
4872 && !is_hardware_watchpoint (b
)
4873 && (b
->loc
->next
|| !b
->loc
->enabled
)
4874 && !ui_out_is_mi_like_p (uiout
))
4876 struct bp_location
*loc
;
4878 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4879 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4880 print_address_bits
, allflag
);
4886 breakpoint_address_bits (struct breakpoint
*b
)
4888 int print_address_bits
= 0;
4889 struct bp_location
*loc
;
4891 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4895 /* Software watchpoints that aren't watching memory don't have
4896 an address to print. */
4897 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4900 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4901 if (addr_bit
> print_address_bits
)
4902 print_address_bits
= addr_bit
;
4905 return print_address_bits
;
4908 struct captured_breakpoint_query_args
4914 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4916 struct captured_breakpoint_query_args
*args
= data
;
4917 struct breakpoint
*b
;
4918 struct bp_location
*dummy_loc
= NULL
;
4922 if (args
->bnum
== b
->number
)
4924 int print_address_bits
= breakpoint_address_bits (b
);
4926 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4934 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4936 struct captured_breakpoint_query_args args
;
4939 /* For the moment we don't trust print_one_breakpoint() to not throw
4941 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4942 error_message
, RETURN_MASK_ALL
) < 0)
4948 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4949 catchpoints, et.al.). */
4952 user_settable_breakpoint (const struct breakpoint
*b
)
4954 return (b
->type
== bp_breakpoint
4955 || b
->type
== bp_catchpoint
4956 || b
->type
== bp_hardware_breakpoint
4957 || is_tracepoint (b
)
4958 || is_watchpoint (b
));
4961 /* Print information on user settable breakpoint (watchpoint, etc)
4962 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4963 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4964 FILTER is non-NULL, call it on each breakpoint and only include the
4965 ones for which it returns non-zero. Return the total number of
4966 breakpoints listed. */
4969 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4971 struct breakpoint
*b
;
4972 struct bp_location
*last_loc
= NULL
;
4973 int nr_printable_breakpoints
;
4974 struct cleanup
*bkpttbl_chain
;
4975 struct value_print_options opts
;
4976 int print_address_bits
= 0;
4978 get_user_print_options (&opts
);
4980 /* Compute the number of rows in the table, as well as the
4981 size required for address fields. */
4982 nr_printable_breakpoints
= 0;
4985 || bnum
== b
->number
)
4987 /* If we have a filter, only list the breakpoints it accepts. */
4988 if (filter
&& !filter (b
))
4991 if (allflag
|| user_settable_breakpoint (b
))
4993 int addr_bit
= breakpoint_address_bits (b
);
4994 if (addr_bit
> print_address_bits
)
4995 print_address_bits
= addr_bit
;
4997 nr_printable_breakpoints
++;
5001 if (opts
.addressprint
)
5003 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
5007 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
5010 if (nr_printable_breakpoints
> 0)
5011 annotate_breakpoints_headers ();
5012 if (nr_printable_breakpoints
> 0)
5014 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5015 if (nr_printable_breakpoints
> 0)
5017 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
5018 if (nr_printable_breakpoints
> 0)
5020 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5021 if (nr_printable_breakpoints
> 0)
5023 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5024 if (opts
.addressprint
)
5026 if (nr_printable_breakpoints
> 0)
5028 if (print_address_bits
<= 32)
5029 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
5031 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5033 if (nr_printable_breakpoints
> 0)
5035 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5036 ui_out_table_body (uiout
);
5037 if (nr_printable_breakpoints
> 0)
5038 annotate_breakpoints_table ();
5044 || bnum
== b
->number
)
5046 /* If we have a filter, only list the breakpoints it accepts. */
5047 if (filter
&& !filter (b
))
5050 /* We only print out user settable breakpoints unless the
5052 if (allflag
|| user_settable_breakpoint (b
))
5053 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5057 do_cleanups (bkpttbl_chain
);
5059 if (nr_printable_breakpoints
== 0)
5061 /* If there's a filter, let the caller decide how to report empty list. */
5065 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5067 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5073 if (last_loc
&& !server_command
)
5074 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5077 /* FIXME? Should this be moved up so that it is only called when
5078 there have been breakpoints? */
5079 annotate_breakpoints_table_end ();
5081 return nr_printable_breakpoints
;
5084 /* Display the value of default-collect in a way that is generally
5085 compatible with the breakpoint list. */
5088 default_collect_info (void)
5090 /* If it has no value (which is frequently the case), say nothing; a
5091 message like "No default-collect." gets in user's face when it's
5093 if (!*default_collect
)
5096 /* The following phrase lines up nicely with per-tracepoint collect
5098 ui_out_text (uiout
, "default collect ");
5099 ui_out_field_string (uiout
, "default-collect", default_collect
);
5100 ui_out_text (uiout
, " \n");
5104 breakpoints_info (char *bnum_exp
, int from_tty
)
5109 bnum
= parse_and_eval_long (bnum_exp
);
5111 breakpoint_1 (bnum
, 0, NULL
);
5113 default_collect_info ();
5117 watchpoints_info (char *wpnum_exp
, int from_tty
)
5119 int wpnum
= -1, num_printed
;
5122 wpnum
= parse_and_eval_long (wpnum_exp
);
5124 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5126 if (num_printed
== 0)
5129 ui_out_message (uiout
, 0, "No watchpoints.\n");
5131 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5136 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5141 bnum
= parse_and_eval_long (bnum_exp
);
5143 breakpoint_1 (bnum
, 1, NULL
);
5145 default_collect_info ();
5149 breakpoint_has_pc (struct breakpoint
*b
,
5150 struct program_space
*pspace
,
5151 CORE_ADDR pc
, struct obj_section
*section
)
5153 struct bp_location
*bl
= b
->loc
;
5155 for (; bl
; bl
= bl
->next
)
5157 if (bl
->pspace
== pspace
5158 && bl
->address
== pc
5159 && (!overlay_debugging
|| bl
->section
== section
))
5165 /* Print a message describing any breakpoints set at PC. This
5166 concerns with logical breakpoints, so we match program spaces, not
5170 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5171 struct program_space
*pspace
, CORE_ADDR pc
,
5172 struct obj_section
*section
, int thread
)
5175 struct breakpoint
*b
;
5178 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5182 printf_filtered (_("Note: breakpoint "));
5183 else /* if (others == ???) */
5184 printf_filtered (_("Note: breakpoints "));
5186 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5189 printf_filtered ("%d", b
->number
);
5190 if (b
->thread
== -1 && thread
!= -1)
5191 printf_filtered (" (all threads)");
5192 else if (b
->thread
!= -1)
5193 printf_filtered (" (thread %d)", b
->thread
);
5194 printf_filtered ("%s%s ",
5195 ((b
->enable_state
== bp_disabled
5196 || b
->enable_state
== bp_call_disabled
5197 || b
->enable_state
== bp_startup_disabled
)
5199 : b
->enable_state
== bp_permanent
5203 : ((others
== 1) ? " and" : ""));
5205 printf_filtered (_("also set at pc "));
5206 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5207 printf_filtered (".\n");
5211 /* Set the default place to put a breakpoint
5212 for the `break' command with no arguments. */
5215 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5216 CORE_ADDR addr
, struct symtab
*symtab
,
5219 default_breakpoint_valid
= valid
;
5220 default_breakpoint_pspace
= pspace
;
5221 default_breakpoint_address
= addr
;
5222 default_breakpoint_symtab
= symtab
;
5223 default_breakpoint_line
= line
;
5226 /* Return true iff it is meaningful to use the address member of
5227 BPT. For some breakpoint types, the address member is irrelevant
5228 and it makes no sense to attempt to compare it to other addresses
5229 (or use it for any other purpose either).
5231 More specifically, each of the following breakpoint types will always
5232 have a zero valued address and we don't want to mark breakpoints of any of
5233 these types to be a duplicate of an actual breakpoint at address zero:
5241 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5243 enum bptype type
= bpt
->type
;
5245 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5248 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5249 true if LOC1 and LOC2 represent the same watchpoint location. */
5252 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5254 /* Both of them must not be in moribund_locations. */
5255 gdb_assert (loc1
->owner
!= NULL
);
5256 gdb_assert (loc2
->owner
!= NULL
);
5258 /* Note that this checks the owner's type, not the location's. In
5259 case the target does not support read watchpoints, but does
5260 support access watchpoints, we'll have bp_read_watchpoint
5261 watchpoints with hw_access locations. Those should be considered
5262 duplicates of hw_read locations. The hw_read locations will
5263 become hw_access locations later. */
5264 return (loc1
->owner
->type
== loc2
->owner
->type
5265 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5266 && loc1
->address
== loc2
->address
5267 && loc1
->length
== loc2
->length
);
5270 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5271 same breakpoint location. In most targets, this can only be true
5272 if ASPACE1 matches ASPACE2. On targets that have global
5273 breakpoints, the address space doesn't really matter. */
5276 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5277 struct address_space
*aspace2
, CORE_ADDR addr2
)
5279 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5280 || aspace1
== aspace2
)
5284 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5285 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5286 represent the same location. */
5289 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5291 int hw_point1
, hw_point2
;
5293 /* Both of them must not be in moribund_locations. */
5294 gdb_assert (loc1
->owner
!= NULL
);
5295 gdb_assert (loc2
->owner
!= NULL
);
5297 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5298 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5300 if (hw_point1
!= hw_point2
)
5303 return watchpoint_locations_match (loc1
, loc2
);
5305 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5306 loc2
->pspace
->aspace
, loc2
->address
);
5310 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5311 int bnum
, int have_bnum
)
5316 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5317 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5319 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5320 bnum
, astr1
, astr2
);
5322 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5325 /* Adjust a breakpoint's address to account for architectural constraints
5326 on breakpoint placement. Return the adjusted address. Note: Very
5327 few targets require this kind of adjustment. For most targets,
5328 this function is simply the identity function. */
5331 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5332 CORE_ADDR bpaddr
, enum bptype bptype
)
5334 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5336 /* Very few targets need any kind of breakpoint adjustment. */
5339 else if (bptype
== bp_watchpoint
5340 || bptype
== bp_hardware_watchpoint
5341 || bptype
== bp_read_watchpoint
5342 || bptype
== bp_access_watchpoint
5343 || bptype
== bp_catchpoint
)
5345 /* Watchpoints and the various bp_catch_* eventpoints should not
5346 have their addresses modified. */
5351 CORE_ADDR adjusted_bpaddr
;
5353 /* Some targets have architectural constraints on the placement
5354 of breakpoint instructions. Obtain the adjusted address. */
5355 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5357 /* An adjusted breakpoint address can significantly alter
5358 a user's expectations. Print a warning if an adjustment
5360 if (adjusted_bpaddr
!= bpaddr
)
5361 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5363 return adjusted_bpaddr
;
5367 /* Allocate a struct bp_location. */
5369 static struct bp_location
*
5370 allocate_bp_location (struct breakpoint
*bpt
)
5372 struct bp_location
*loc
;
5374 loc
= xmalloc (sizeof (struct bp_location
));
5375 memset (loc
, 0, sizeof (*loc
));
5379 loc
->shlib_disabled
= 0;
5388 case bp_longjmp_resume
:
5389 case bp_step_resume
:
5390 case bp_watchpoint_scope
:
5392 case bp_std_terminate
:
5393 case bp_shlib_event
:
5394 case bp_thread_event
:
5395 case bp_overlay_event
:
5397 case bp_longjmp_master
:
5398 case bp_std_terminate_master
:
5399 loc
->loc_type
= bp_loc_software_breakpoint
;
5401 case bp_hardware_breakpoint
:
5402 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5404 case bp_hardware_watchpoint
:
5405 case bp_read_watchpoint
:
5406 case bp_access_watchpoint
:
5407 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5412 case bp_fast_tracepoint
:
5413 loc
->loc_type
= bp_loc_other
;
5416 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5422 static void free_bp_location (struct bp_location
*loc
)
5424 /* Be sure no bpstat's are pointing at it after it's been freed. */
5425 /* FIXME, how can we find all bpstat's?
5426 We just check stop_bpstat for now. Note that we cannot just
5427 remove bpstats pointing at bpt from the stop_bpstat list
5428 entirely, as breakpoint commands are associated with the bpstat;
5429 if we remove it here, then the later call to
5430 bpstat_do_actions (&stop_bpstat);
5431 in event-top.c won't do anything, and temporary breakpoints
5432 with commands won't work. */
5434 iterate_over_threads (bpstat_remove_bp_location_callback
, loc
);
5439 if (loc
->function_name
)
5440 xfree (loc
->function_name
);
5445 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5446 that has type BPTYPE and has no locations as yet. */
5447 /* This function is used in gdbtk sources and thus can not be made static. */
5449 static struct breakpoint
*
5450 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5453 struct breakpoint
*b
, *b1
;
5455 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5456 memset (b
, 0, sizeof (*b
));
5459 b
->gdbarch
= gdbarch
;
5460 b
->language
= current_language
->la_language
;
5461 b
->input_radix
= input_radix
;
5463 b
->enable_state
= bp_enabled
;
5466 b
->ignore_count
= 0;
5468 b
->frame_id
= null_frame_id
;
5469 b
->forked_inferior_pid
= null_ptid
;
5470 b
->exec_pathname
= NULL
;
5471 b
->syscalls_to_be_caught
= NULL
;
5473 b
->condition_not_parsed
= 0;
5475 /* Add this breakpoint to the end of the chain
5476 so that a list of breakpoints will come out in order
5477 of increasing numbers. */
5479 b1
= breakpoint_chain
;
5481 breakpoint_chain
= b
;
5491 /* Initialize loc->function_name. */
5493 set_breakpoint_location_function (struct bp_location
*loc
)
5495 gdb_assert (loc
->owner
!= NULL
);
5497 if (loc
->owner
->type
== bp_breakpoint
5498 || loc
->owner
->type
== bp_hardware_breakpoint
5499 || is_tracepoint (loc
->owner
))
5501 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5503 if (loc
->function_name
)
5504 loc
->function_name
= xstrdup (loc
->function_name
);
5508 /* Attempt to determine architecture of location identified by SAL. */
5509 static struct gdbarch
*
5510 get_sal_arch (struct symtab_and_line sal
)
5513 return get_objfile_arch (sal
.section
->objfile
);
5515 return get_objfile_arch (sal
.symtab
->objfile
);
5520 /* set_raw_breakpoint is a low level routine for allocating and
5521 partially initializing a breakpoint of type BPTYPE. The newly
5522 created breakpoint's address, section, source file name, and line
5523 number are provided by SAL. The newly created and partially
5524 initialized breakpoint is added to the breakpoint chain and
5525 is also returned as the value of this function.
5527 It is expected that the caller will complete the initialization of
5528 the newly created breakpoint struct as well as output any status
5529 information regarding the creation of a new breakpoint. In
5530 particular, set_raw_breakpoint does NOT set the breakpoint
5531 number! Care should be taken to not allow an error to occur
5532 prior to completing the initialization of the breakpoint. If this
5533 should happen, a bogus breakpoint will be left on the chain. */
5536 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5537 struct symtab_and_line sal
, enum bptype bptype
)
5539 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5540 CORE_ADDR adjusted_address
;
5541 struct gdbarch
*loc_gdbarch
;
5543 loc_gdbarch
= get_sal_arch (sal
);
5545 loc_gdbarch
= b
->gdbarch
;
5547 if (bptype
!= bp_catchpoint
)
5548 gdb_assert (sal
.pspace
!= NULL
);
5550 /* Adjust the breakpoint's address prior to allocating a location.
5551 Once we call allocate_bp_location(), that mostly uninitialized
5552 location will be placed on the location chain. Adjustment of the
5553 breakpoint may cause target_read_memory() to be called and we do
5554 not want its scan of the location chain to find a breakpoint and
5555 location that's only been partially initialized. */
5556 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5558 b
->loc
= allocate_bp_location (b
);
5559 b
->loc
->gdbarch
= loc_gdbarch
;
5560 b
->loc
->requested_address
= sal
.pc
;
5561 b
->loc
->address
= adjusted_address
;
5562 b
->loc
->pspace
= sal
.pspace
;
5564 /* Store the program space that was used to set the breakpoint, for
5565 breakpoint resetting. */
5566 b
->pspace
= sal
.pspace
;
5568 if (sal
.symtab
== NULL
)
5569 b
->source_file
= NULL
;
5571 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5572 b
->loc
->section
= sal
.section
;
5573 b
->line_number
= sal
.line
;
5575 set_breakpoint_location_function (b
->loc
);
5577 breakpoints_changed ();
5583 /* Note that the breakpoint object B describes a permanent breakpoint
5584 instruction, hard-wired into the inferior's code. */
5586 make_breakpoint_permanent (struct breakpoint
*b
)
5588 struct bp_location
*bl
;
5590 b
->enable_state
= bp_permanent
;
5592 /* By definition, permanent breakpoints are already present in the code.
5593 Mark all locations as inserted. For now, make_breakpoint_permanent
5594 is called in just one place, so it's hard to say if it's reasonable
5595 to have permanent breakpoint with multiple locations or not,
5596 but it's easy to implmement. */
5597 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5601 /* Call this routine when stepping and nexting to enable a breakpoint
5602 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5603 set_longjmp_resume_breakpoint() to figure out where we are going. */
5606 set_longjmp_breakpoint (int thread
)
5608 struct breakpoint
*b
, *temp
;
5610 /* To avoid having to rescan all objfile symbols at every step,
5611 we maintain a list of continually-inserted but always disabled
5612 longjmp "master" breakpoints. Here, we simply create momentary
5613 clones of those and enable them for the requested thread. */
5614 ALL_BREAKPOINTS_SAFE (b
, temp
)
5615 if (b
->pspace
== current_program_space
5616 && b
->type
== bp_longjmp_master
)
5618 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5620 clone
->type
= bp_longjmp
;
5621 clone
->thread
= thread
;
5625 /* Delete all longjmp breakpoints from THREAD. */
5627 delete_longjmp_breakpoint (int thread
)
5629 struct breakpoint
*b
, *temp
;
5631 ALL_BREAKPOINTS_SAFE (b
, temp
)
5632 if (b
->type
== bp_longjmp
)
5634 if (b
->thread
== thread
)
5635 delete_breakpoint (b
);
5640 enable_overlay_breakpoints (void)
5642 struct breakpoint
*b
;
5645 if (b
->type
== bp_overlay_event
)
5647 b
->enable_state
= bp_enabled
;
5648 update_global_location_list (1);
5649 overlay_events_enabled
= 1;
5654 disable_overlay_breakpoints (void)
5656 struct breakpoint
*b
;
5659 if (b
->type
== bp_overlay_event
)
5661 b
->enable_state
= bp_disabled
;
5662 update_global_location_list (0);
5663 overlay_events_enabled
= 0;
5667 /* Set an active std::terminate breakpoint for each std::terminate
5668 master breakpoint. */
5670 set_std_terminate_breakpoint (void)
5672 struct breakpoint
*b
, *temp
;
5674 ALL_BREAKPOINTS_SAFE (b
, temp
)
5675 if (b
->pspace
== current_program_space
5676 && b
->type
== bp_std_terminate_master
)
5678 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5679 clone
->type
= bp_std_terminate
;
5683 /* Delete all the std::terminate breakpoints. */
5685 delete_std_terminate_breakpoint (void)
5687 struct breakpoint
*b
, *temp
;
5689 ALL_BREAKPOINTS_SAFE (b
, temp
)
5690 if (b
->type
== bp_std_terminate
)
5691 delete_breakpoint (b
);
5695 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5697 struct breakpoint
*b
;
5699 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5701 b
->enable_state
= bp_enabled
;
5702 /* addr_string has to be used or breakpoint_re_set will delete me. */
5704 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5706 update_global_location_list_nothrow (1);
5712 remove_thread_event_breakpoints (void)
5714 struct breakpoint
*b
, *temp
;
5716 ALL_BREAKPOINTS_SAFE (b
, temp
)
5717 if (b
->type
== bp_thread_event
5718 && b
->loc
->pspace
== current_program_space
)
5719 delete_breakpoint (b
);
5722 struct captured_parse_breakpoint_args
5725 struct symtabs_and_lines
*sals_p
;
5726 char ***addr_string_p
;
5730 struct lang_and_radix
5736 /* Create a breakpoint for JIT code registration and unregistration. */
5739 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5741 struct breakpoint
*b
;
5743 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5744 update_global_location_list_nothrow (1);
5749 remove_solib_event_breakpoints (void)
5751 struct breakpoint
*b
, *temp
;
5753 ALL_BREAKPOINTS_SAFE (b
, temp
)
5754 if (b
->type
== bp_shlib_event
5755 && b
->loc
->pspace
== current_program_space
)
5756 delete_breakpoint (b
);
5760 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5762 struct breakpoint
*b
;
5764 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5765 update_global_location_list_nothrow (1);
5769 /* Disable any breakpoints that are on code in shared libraries. Only
5770 apply to enabled breakpoints, disabled ones can just stay disabled. */
5773 disable_breakpoints_in_shlibs (void)
5775 struct bp_location
*loc
, **locp_tmp
;
5777 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5779 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5780 struct breakpoint
*b
= loc
->owner
;
5782 /* We apply the check to all breakpoints, including disabled
5783 for those with loc->duplicate set. This is so that when breakpoint
5784 becomes enabled, or the duplicate is removed, gdb will try to insert
5785 all breakpoints. If we don't set shlib_disabled here, we'll try
5786 to insert those breakpoints and fail. */
5787 if (((b
->type
== bp_breakpoint
)
5788 || (b
->type
== bp_jit_event
)
5789 || (b
->type
== bp_hardware_breakpoint
)
5790 || (is_tracepoint (b
)))
5791 && loc
->pspace
== current_program_space
5792 && !loc
->shlib_disabled
5794 && PC_SOLIB (loc
->address
)
5796 && solib_name_from_address (loc
->pspace
, loc
->address
)
5800 loc
->shlib_disabled
= 1;
5805 /* Disable any breakpoints that are in in an unloaded shared library. Only
5806 apply to enabled breakpoints, disabled ones can just stay disabled. */
5809 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5811 struct bp_location
*loc
, **locp_tmp
;
5812 int disabled_shlib_breaks
= 0;
5814 /* SunOS a.out shared libraries are always mapped, so do not
5815 disable breakpoints; they will only be reported as unloaded
5816 through clear_solib when GDB discards its shared library
5817 list. See clear_solib for more information. */
5818 if (exec_bfd
!= NULL
5819 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5822 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5824 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5825 struct breakpoint
*b
= loc
->owner
;
5827 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5828 || loc
->loc_type
== bp_loc_software_breakpoint
)
5829 && solib
->pspace
== loc
->pspace
5830 && !loc
->shlib_disabled
5831 && (b
->type
== bp_breakpoint
5832 || b
->type
== bp_jit_event
5833 || b
->type
== bp_hardware_breakpoint
)
5834 && solib_contains_address_p (solib
, loc
->address
))
5836 loc
->shlib_disabled
= 1;
5837 /* At this point, we cannot rely on remove_breakpoint
5838 succeeding so we must mark the breakpoint as not inserted
5839 to prevent future errors occurring in remove_breakpoints. */
5841 if (!disabled_shlib_breaks
)
5843 target_terminal_ours_for_output ();
5844 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5847 disabled_shlib_breaks
= 1;
5852 /* FORK & VFORK catchpoints. */
5854 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5857 insert_catch_fork (struct breakpoint
*b
)
5859 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5862 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5865 remove_catch_fork (struct breakpoint
*b
)
5867 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5870 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5874 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5876 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5879 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5881 static enum print_stop_action
5882 print_it_catch_fork (struct breakpoint
*b
)
5884 annotate_catchpoint (b
->number
);
5885 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5886 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5887 return PRINT_SRC_AND_LOC
;
5890 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5893 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5895 struct value_print_options opts
;
5897 get_user_print_options (&opts
);
5899 /* Field 4, the address, is omitted (which makes the columns
5900 not line up too nicely with the headers, but the effect
5901 is relatively readable). */
5902 if (opts
.addressprint
)
5903 ui_out_field_skip (uiout
, "addr");
5905 ui_out_text (uiout
, "fork");
5906 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5908 ui_out_text (uiout
, ", process ");
5909 ui_out_field_int (uiout
, "what",
5910 ptid_get_pid (b
->forked_inferior_pid
));
5911 ui_out_spaces (uiout
, 1);
5915 /* Implement the "print_mention" breakpoint_ops method for fork
5919 print_mention_catch_fork (struct breakpoint
*b
)
5921 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5924 /* Implement the "print_recreate" breakpoint_ops method for fork
5928 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
5930 fprintf_unfiltered (fp
, "catch fork");
5933 /* The breakpoint_ops structure to be used in fork catchpoints. */
5935 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5939 breakpoint_hit_catch_fork
,
5940 print_it_catch_fork
,
5941 print_one_catch_fork
,
5942 print_mention_catch_fork
,
5943 print_recreate_catch_fork
5946 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5949 insert_catch_vfork (struct breakpoint
*b
)
5951 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5954 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5957 remove_catch_vfork (struct breakpoint
*b
)
5959 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5962 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5966 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5968 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5971 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5973 static enum print_stop_action
5974 print_it_catch_vfork (struct breakpoint
*b
)
5976 annotate_catchpoint (b
->number
);
5977 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5978 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5979 return PRINT_SRC_AND_LOC
;
5982 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5985 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5987 struct value_print_options opts
;
5989 get_user_print_options (&opts
);
5990 /* Field 4, the address, is omitted (which makes the columns
5991 not line up too nicely with the headers, but the effect
5992 is relatively readable). */
5993 if (opts
.addressprint
)
5994 ui_out_field_skip (uiout
, "addr");
5996 ui_out_text (uiout
, "vfork");
5997 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5999 ui_out_text (uiout
, ", process ");
6000 ui_out_field_int (uiout
, "what",
6001 ptid_get_pid (b
->forked_inferior_pid
));
6002 ui_out_spaces (uiout
, 1);
6006 /* Implement the "print_mention" breakpoint_ops method for vfork
6010 print_mention_catch_vfork (struct breakpoint
*b
)
6012 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6015 /* Implement the "print_recreate" breakpoint_ops method for vfork
6019 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6021 fprintf_unfiltered (fp
, "catch vfork");
6024 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6026 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6030 breakpoint_hit_catch_vfork
,
6031 print_it_catch_vfork
,
6032 print_one_catch_vfork
,
6033 print_mention_catch_vfork
,
6034 print_recreate_catch_vfork
6037 /* Implement the "insert" breakpoint_ops method for syscall
6041 insert_catch_syscall (struct breakpoint
*b
)
6043 struct inferior
*inf
= current_inferior ();
6045 ++inf
->total_syscalls_count
;
6046 if (!b
->syscalls_to_be_caught
)
6047 ++inf
->any_syscall_count
;
6053 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6058 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6060 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6061 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
6063 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6064 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6066 memset ((void *) vec_addr
, 0,
6067 (iter
+ 1 - old_size
) * sizeof (int));
6069 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6070 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6074 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6075 inf
->total_syscalls_count
!= 0,
6076 inf
->any_syscall_count
,
6077 VEC_length (int, inf
->syscalls_counts
),
6078 VEC_address (int, inf
->syscalls_counts
));
6081 /* Implement the "remove" breakpoint_ops method for syscall
6085 remove_catch_syscall (struct breakpoint
*b
)
6087 struct inferior
*inf
= current_inferior ();
6089 --inf
->total_syscalls_count
;
6090 if (!b
->syscalls_to_be_caught
)
6091 --inf
->any_syscall_count
;
6097 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6101 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6102 /* Shouldn't happen. */
6104 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6105 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6109 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6110 inf
->total_syscalls_count
!= 0,
6111 inf
->any_syscall_count
,
6112 VEC_length (int, inf
->syscalls_counts
),
6113 VEC_address (int, inf
->syscalls_counts
));
6116 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6120 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6122 /* We must check if we are catching specific syscalls in this breakpoint.
6123 If we are, then we must guarantee that the called syscall is the same
6124 syscall we are catching. */
6125 int syscall_number
= 0;
6127 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6130 /* Now, checking if the syscall is the same. */
6131 if (b
->syscalls_to_be_caught
)
6136 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6138 if (syscall_number
== iter
)
6148 /* Implement the "print_it" breakpoint_ops method for syscall
6151 static enum print_stop_action
6152 print_it_catch_syscall (struct breakpoint
*b
)
6154 /* These are needed because we want to know in which state a
6155 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6156 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6157 must print "called syscall" or "returned from syscall". */
6159 struct target_waitstatus last
;
6161 struct cleanup
*old_chain
;
6164 get_last_target_status (&ptid
, &last
);
6166 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6168 annotate_catchpoint (b
->number
);
6171 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6173 syscall_id
= xstrprintf ("'%s'", s
.name
);
6175 old_chain
= make_cleanup (xfree
, syscall_id
);
6177 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6178 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6179 b
->number
, syscall_id
);
6180 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6181 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6182 b
->number
, syscall_id
);
6184 do_cleanups (old_chain
);
6186 return PRINT_SRC_AND_LOC
;
6189 /* Implement the "print_one" breakpoint_ops method for syscall
6193 print_one_catch_syscall (struct breakpoint
*b
,
6194 struct bp_location
**last_loc
)
6196 struct value_print_options opts
;
6198 get_user_print_options (&opts
);
6199 /* Field 4, the address, is omitted (which makes the columns
6200 not line up too nicely with the headers, but the effect
6201 is relatively readable). */
6202 if (opts
.addressprint
)
6203 ui_out_field_skip (uiout
, "addr");
6206 if (b
->syscalls_to_be_caught
6207 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6208 ui_out_text (uiout
, "syscalls \"");
6210 ui_out_text (uiout
, "syscall \"");
6212 if (b
->syscalls_to_be_caught
)
6215 char *text
= xstrprintf ("%s", "");
6218 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6223 get_syscall_by_number (iter
, &s
);
6226 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6228 text
= xstrprintf ("%s%d, ", text
, iter
);
6230 /* We have to xfree the last 'text' (now stored at 'x')
6231 because xstrprintf dinamically allocates new space for it
6235 /* Remove the last comma. */
6236 text
[strlen (text
) - 2] = '\0';
6237 ui_out_field_string (uiout
, "what", text
);
6240 ui_out_field_string (uiout
, "what", "<any syscall>");
6241 ui_out_text (uiout
, "\" ");
6244 /* Implement the "print_mention" breakpoint_ops method for syscall
6248 print_mention_catch_syscall (struct breakpoint
*b
)
6250 if (b
->syscalls_to_be_caught
)
6254 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6255 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6257 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6260 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6264 get_syscall_by_number (iter
, &s
);
6267 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6269 printf_filtered (" %d", s
.number
);
6271 printf_filtered (")");
6274 printf_filtered (_("Catchpoint %d (any syscall)"),
6278 /* Implement the "print_recreate" breakpoint_ops method for syscall
6282 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6284 fprintf_unfiltered (fp
, "catch syscall");
6286 if (b
->syscalls_to_be_caught
)
6291 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6296 get_syscall_by_number (iter
, &s
);
6298 fprintf_unfiltered (fp
, " %s", s
.name
);
6300 fprintf_unfiltered (fp
, " %d", s
.number
);
6305 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6307 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6309 insert_catch_syscall
,
6310 remove_catch_syscall
,
6311 breakpoint_hit_catch_syscall
,
6312 print_it_catch_syscall
,
6313 print_one_catch_syscall
,
6314 print_mention_catch_syscall
,
6315 print_recreate_catch_syscall
6318 /* Returns non-zero if 'b' is a syscall catchpoint. */
6321 syscall_catchpoint_p (struct breakpoint
*b
)
6323 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6326 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6327 but does NOT mention it nor update the global location list.
6328 This is useful if you need to fill more fields in the
6329 struct breakpoint before calling mention.
6331 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6332 If COND_STRING is not NULL, then store it in the breakpoint.
6333 OPS, if not NULL, is the breakpoint_ops structure associated
6334 to the catchpoint. */
6336 static struct breakpoint
*
6337 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6339 struct breakpoint_ops
*ops
)
6341 struct symtab_and_line sal
;
6342 struct breakpoint
*b
;
6345 sal
.pspace
= current_program_space
;
6347 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6348 set_breakpoint_count (breakpoint_count
+ 1);
6349 b
->number
= breakpoint_count
;
6351 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6353 b
->addr_string
= NULL
;
6354 b
->enable_state
= bp_enabled
;
6355 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6361 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6363 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6364 If COND_STRING is not NULL, then store it in the breakpoint.
6365 OPS, if not NULL, is the breakpoint_ops structure associated
6366 to the catchpoint. */
6368 static struct breakpoint
*
6369 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6370 char *cond_string
, struct breakpoint_ops
*ops
)
6372 struct breakpoint
*b
=
6373 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6376 update_global_location_list (1);
6382 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6383 int tempflag
, char *cond_string
,
6384 struct breakpoint_ops
*ops
)
6386 struct breakpoint
*b
6387 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6389 /* FIXME: We should put this information in a breakpoint private data
6391 b
->forked_inferior_pid
= null_ptid
;
6394 /* Exec catchpoints. */
6397 insert_catch_exec (struct breakpoint
*b
)
6399 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6403 remove_catch_exec (struct breakpoint
*b
)
6405 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6409 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6411 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6414 static enum print_stop_action
6415 print_it_catch_exec (struct breakpoint
*b
)
6417 annotate_catchpoint (b
->number
);
6418 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6420 return PRINT_SRC_AND_LOC
;
6424 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6426 struct value_print_options opts
;
6428 get_user_print_options (&opts
);
6430 /* Field 4, the address, is omitted (which makes the columns
6431 not line up too nicely with the headers, but the effect
6432 is relatively readable). */
6433 if (opts
.addressprint
)
6434 ui_out_field_skip (uiout
, "addr");
6436 ui_out_text (uiout
, "exec");
6437 if (b
->exec_pathname
!= NULL
)
6439 ui_out_text (uiout
, ", program \"");
6440 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6441 ui_out_text (uiout
, "\" ");
6446 print_mention_catch_exec (struct breakpoint
*b
)
6448 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6451 /* Implement the "print_recreate" breakpoint_ops method for exec
6455 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6457 fprintf_unfiltered (fp
, "catch exec");
6460 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6464 breakpoint_hit_catch_exec
,
6465 print_it_catch_exec
,
6466 print_one_catch_exec
,
6467 print_mention_catch_exec
,
6468 print_recreate_catch_exec
6472 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6473 struct breakpoint_ops
*ops
)
6475 struct gdbarch
*gdbarch
= get_current_arch ();
6476 struct breakpoint
*b
=
6477 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6479 b
->syscalls_to_be_caught
= filter
;
6481 /* Now, we have to mention the breakpoint and update the global
6484 update_global_location_list (1);
6488 hw_breakpoint_used_count (void)
6490 struct breakpoint
*b
;
6495 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6503 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6505 struct breakpoint
*b
;
6508 *other_type_used
= 0;
6511 if (breakpoint_enabled (b
))
6513 if (b
->type
== type
)
6515 else if (is_hardware_watchpoint (b
))
6516 *other_type_used
= 1;
6523 disable_watchpoints_before_interactive_call_start (void)
6525 struct breakpoint
*b
;
6529 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6531 b
->enable_state
= bp_call_disabled
;
6532 update_global_location_list (0);
6538 enable_watchpoints_after_interactive_call_stop (void)
6540 struct breakpoint
*b
;
6544 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6546 b
->enable_state
= bp_enabled
;
6547 update_global_location_list (1);
6553 disable_breakpoints_before_startup (void)
6555 struct breakpoint
*b
;
6560 if (b
->pspace
!= current_program_space
)
6563 if ((b
->type
== bp_breakpoint
6564 || b
->type
== bp_hardware_breakpoint
)
6565 && breakpoint_enabled (b
))
6567 b
->enable_state
= bp_startup_disabled
;
6573 update_global_location_list (0);
6575 current_program_space
->executing_startup
= 1;
6579 enable_breakpoints_after_startup (void)
6581 struct breakpoint
*b
;
6584 current_program_space
->executing_startup
= 0;
6588 if (b
->pspace
!= current_program_space
)
6591 if ((b
->type
== bp_breakpoint
6592 || b
->type
== bp_hardware_breakpoint
)
6593 && b
->enable_state
== bp_startup_disabled
)
6595 b
->enable_state
= bp_enabled
;
6601 breakpoint_re_set ();
6605 /* Set a breakpoint that will evaporate an end of command
6606 at address specified by SAL.
6607 Restrict it to frame FRAME if FRAME is nonzero. */
6610 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6611 struct frame_id frame_id
, enum bptype type
)
6613 struct breakpoint
*b
;
6615 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6617 gdb_assert (!frame_id_inlined_p (frame_id
));
6619 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6620 b
->enable_state
= bp_enabled
;
6621 b
->disposition
= disp_donttouch
;
6622 b
->frame_id
= frame_id
;
6624 /* If we're debugging a multi-threaded program, then we
6625 want momentary breakpoints to be active in only a
6626 single thread of control. */
6627 if (in_thread_list (inferior_ptid
))
6628 b
->thread
= pid_to_thread_id (inferior_ptid
);
6630 update_global_location_list_nothrow (1);
6635 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6639 clone_momentary_breakpoint (struct breakpoint
*orig
)
6641 struct breakpoint
*copy
;
6643 /* If there's nothing to clone, then return nothing. */
6647 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6648 copy
->loc
= allocate_bp_location (copy
);
6649 set_breakpoint_location_function (copy
->loc
);
6651 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6652 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6653 copy
->loc
->address
= orig
->loc
->address
;
6654 copy
->loc
->section
= orig
->loc
->section
;
6655 copy
->loc
->pspace
= orig
->loc
->pspace
;
6657 if (orig
->source_file
== NULL
)
6658 copy
->source_file
= NULL
;
6660 copy
->source_file
= xstrdup (orig
->source_file
);
6662 copy
->line_number
= orig
->line_number
;
6663 copy
->frame_id
= orig
->frame_id
;
6664 copy
->thread
= orig
->thread
;
6665 copy
->pspace
= orig
->pspace
;
6667 copy
->enable_state
= bp_enabled
;
6668 copy
->disposition
= disp_donttouch
;
6669 copy
->number
= internal_breakpoint_number
--;
6671 update_global_location_list_nothrow (0);
6676 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6679 struct symtab_and_line sal
;
6681 sal
= find_pc_line (pc
, 0);
6683 sal
.section
= find_pc_overlay (pc
);
6684 sal
.explicit_pc
= 1;
6686 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6690 /* Tell the user we have just set a breakpoint B. */
6693 mention (struct breakpoint
*b
)
6696 struct cleanup
*ui_out_chain
;
6697 struct value_print_options opts
;
6699 get_user_print_options (&opts
);
6701 /* FIXME: This is misplaced; mention() is called by things (like
6702 hitting a watchpoint) other than breakpoint creation. It should
6703 be possible to clean this up and at the same time replace the
6704 random calls to breakpoint_changed with this hook. */
6705 observer_notify_breakpoint_created (b
->number
);
6707 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6708 b
->ops
->print_mention (b
);
6713 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6716 ui_out_text (uiout
, "Watchpoint ");
6717 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6718 ui_out_field_int (uiout
, "number", b
->number
);
6719 ui_out_text (uiout
, ": ");
6720 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6721 do_cleanups (ui_out_chain
);
6723 case bp_hardware_watchpoint
:
6724 ui_out_text (uiout
, "Hardware watchpoint ");
6725 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6726 ui_out_field_int (uiout
, "number", b
->number
);
6727 ui_out_text (uiout
, ": ");
6728 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6729 do_cleanups (ui_out_chain
);
6731 case bp_read_watchpoint
:
6732 ui_out_text (uiout
, "Hardware read watchpoint ");
6733 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6734 ui_out_field_int (uiout
, "number", b
->number
);
6735 ui_out_text (uiout
, ": ");
6736 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6737 do_cleanups (ui_out_chain
);
6739 case bp_access_watchpoint
:
6740 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6741 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6742 ui_out_field_int (uiout
, "number", b
->number
);
6743 ui_out_text (uiout
, ": ");
6744 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6745 do_cleanups (ui_out_chain
);
6748 if (ui_out_is_mi_like_p (uiout
))
6753 if (b
->disposition
== disp_del
)
6754 printf_filtered (_("Temporary breakpoint"));
6756 printf_filtered (_("Breakpoint"));
6757 printf_filtered (_(" %d"), b
->number
);
6760 case bp_hardware_breakpoint
:
6761 if (ui_out_is_mi_like_p (uiout
))
6766 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6770 if (ui_out_is_mi_like_p (uiout
))
6775 printf_filtered (_("Tracepoint"));
6776 printf_filtered (_(" %d"), b
->number
);
6779 case bp_fast_tracepoint
:
6780 if (ui_out_is_mi_like_p (uiout
))
6785 printf_filtered (_("Fast tracepoint"));
6786 printf_filtered (_(" %d"), b
->number
);
6793 case bp_longjmp_resume
:
6794 case bp_step_resume
:
6796 case bp_std_terminate
:
6797 case bp_watchpoint_scope
:
6798 case bp_shlib_event
:
6799 case bp_thread_event
:
6800 case bp_overlay_event
:
6802 case bp_longjmp_master
:
6803 case bp_std_terminate_master
:
6809 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6813 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6817 if (opts
.addressprint
|| b
->source_file
== NULL
)
6819 printf_filtered (" at ");
6820 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6824 printf_filtered (": file %s, line %d.",
6825 b
->source_file
, b
->line_number
);
6829 struct bp_location
*loc
= b
->loc
;
6831 for (; loc
; loc
= loc
->next
)
6833 printf_filtered (" (%d locations)", n
);
6838 if (ui_out_is_mi_like_p (uiout
))
6840 printf_filtered ("\n");
6844 static struct bp_location
*
6845 add_location_to_breakpoint (struct breakpoint
*b
,
6846 const struct symtab_and_line
*sal
)
6848 struct bp_location
*loc
, **tmp
;
6850 loc
= allocate_bp_location (b
);
6851 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6854 loc
->gdbarch
= get_sal_arch (*sal
);
6856 loc
->gdbarch
= b
->gdbarch
;
6857 loc
->requested_address
= sal
->pc
;
6858 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6859 loc
->requested_address
, b
->type
);
6860 loc
->pspace
= sal
->pspace
;
6861 gdb_assert (loc
->pspace
!= NULL
);
6862 loc
->section
= sal
->section
;
6864 set_breakpoint_location_function (loc
);
6869 /* Return 1 if LOC is pointing to a permanent breakpoint,
6870 return 0 otherwise. */
6873 bp_loc_is_permanent (struct bp_location
*loc
)
6877 const gdb_byte
*brk
;
6878 gdb_byte
*target_mem
;
6879 struct cleanup
*cleanup
;
6882 gdb_assert (loc
!= NULL
);
6884 addr
= loc
->address
;
6885 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6887 /* Software breakpoints unsupported? */
6891 target_mem
= alloca (len
);
6893 /* Enable the automatic memory restoration from breakpoints while
6894 we read the memory. Otherwise we could say about our temporary
6895 breakpoints they are permanent. */
6896 cleanup
= save_current_space_and_thread ();
6898 switch_to_program_space_and_thread (loc
->pspace
);
6899 make_show_memory_breakpoints_cleanup (0);
6901 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6902 && memcmp (target_mem
, brk
, len
) == 0)
6905 do_cleanups (cleanup
);
6912 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6913 as textual description of the location, and COND_STRING
6914 as condition expression. */
6917 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6918 struct symtabs_and_lines sals
, char *addr_string
,
6920 enum bptype type
, enum bpdisp disposition
,
6921 int thread
, int task
, int ignore_count
,
6922 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6924 struct breakpoint
*b
= NULL
;
6927 if (type
== bp_hardware_breakpoint
)
6929 int i
= hw_breakpoint_used_count ();
6930 int target_resources_ok
=
6931 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6933 if (target_resources_ok
== 0)
6934 error (_("No hardware breakpoint support in the target."));
6935 else if (target_resources_ok
< 0)
6936 error (_("Hardware breakpoints used exceeds limit."));
6939 gdb_assert (sals
.nelts
> 0);
6941 for (i
= 0; i
< sals
.nelts
; ++i
)
6943 struct symtab_and_line sal
= sals
.sals
[i
];
6944 struct bp_location
*loc
;
6948 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6950 loc_gdbarch
= gdbarch
;
6952 describe_other_breakpoints (loc_gdbarch
,
6953 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6958 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6959 set_breakpoint_count (breakpoint_count
+ 1);
6960 b
->number
= breakpoint_count
;
6964 b
->cond_string
= cond_string
;
6965 b
->ignore_count
= ignore_count
;
6966 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6967 b
->disposition
= disposition
;
6969 b
->pspace
= sals
.sals
[0].pspace
;
6971 if (enabled
&& b
->pspace
->executing_startup
6972 && (b
->type
== bp_breakpoint
6973 || b
->type
== bp_hardware_breakpoint
))
6974 b
->enable_state
= bp_startup_disabled
;
6980 loc
= add_location_to_breakpoint (b
, &sal
);
6983 if (bp_loc_is_permanent (loc
))
6984 make_breakpoint_permanent (b
);
6988 char *arg
= b
->cond_string
;
6989 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6991 error (_("Garbage %s follows condition"), arg
);
6996 b
->addr_string
= addr_string
;
6998 /* addr_string has to be used or breakpoint_re_set will delete
7001 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7007 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7008 elements to fill the void space. */
7010 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7012 int i
= index_to_remove
+1;
7013 int last_index
= sal
->nelts
-1;
7015 for (;i
<= last_index
; ++i
)
7016 sal
->sals
[i
-1] = sal
->sals
[i
];
7021 /* If appropriate, obtains all sals that correspond to the same file
7022 and line as SAL, in all program spaces. Users debugging with IDEs,
7023 will want to set a breakpoint at foo.c:line, and not really care
7024 about program spaces. This is done only if SAL does not have
7025 explicit PC and has line and file information. If we got just a
7026 single expanded sal, return the original.
7028 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7029 which the name of enclosing function is different from SAL. This
7030 makes sure that if we have breakpoint originally set in template
7031 instantiation, say foo<int>(), we won't expand SAL to locations at
7032 the same line in all existing instantiations of 'foo'. */
7034 static struct symtabs_and_lines
7035 expand_line_sal_maybe (struct symtab_and_line sal
)
7037 struct symtabs_and_lines expanded
;
7038 CORE_ADDR original_pc
= sal
.pc
;
7039 char *original_function
= NULL
;
7042 struct cleanup
*old_chain
;
7044 /* If we have explicit pc, don't expand.
7045 If we have no line number, we can't expand. */
7046 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7049 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7050 expanded
.sals
[0] = sal
;
7056 old_chain
= save_current_space_and_thread ();
7058 switch_to_program_space_and_thread (sal
.pspace
);
7060 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7062 /* Note that expand_line_sal visits *all* program spaces. */
7063 expanded
= expand_line_sal (sal
);
7065 if (expanded
.nelts
== 1)
7067 /* We had one sal, we got one sal. Return that sal, adjusting it
7068 past the function prologue if necessary. */
7069 xfree (expanded
.sals
);
7071 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7072 sal
.pc
= original_pc
;
7073 expanded
.sals
[0] = sal
;
7074 skip_prologue_sal (&expanded
.sals
[0]);
7075 do_cleanups (old_chain
);
7079 if (!sal
.explicit_line
)
7081 CORE_ADDR func_addr
, func_end
;
7082 for (i
= 0; i
< expanded
.nelts
; ++i
)
7084 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7085 char *this_function
;
7087 /* We need to switch threads as well since we're about to
7089 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7091 if (find_pc_partial_function (pc
, &this_function
,
7092 &func_addr
, &func_end
))
7095 && strcmp (this_function
, original_function
) != 0)
7097 remove_sal (&expanded
, i
);
7104 /* Skip the function prologue if necessary. */
7105 for (i
= 0; i
< expanded
.nelts
; ++i
)
7106 skip_prologue_sal (&expanded
.sals
[i
]);
7108 do_cleanups (old_chain
);
7110 if (expanded
.nelts
<= 1)
7112 /* This is un ugly workaround. If we get zero
7113 expanded sals then something is really wrong.
7114 Fix that by returnign the original sal. */
7115 xfree (expanded
.sals
);
7117 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7118 sal
.pc
= original_pc
;
7119 expanded
.sals
[0] = sal
;
7126 for (i
= 0; i
< expanded
.nelts
; ++i
)
7127 if (expanded
.sals
[i
].pc
== original_pc
)
7138 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7139 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7140 value. COND_STRING, if not NULL, specified the condition to be
7141 used for all breakpoints. Essentially the only case where
7142 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7143 function. In that case, it's still not possible to specify
7144 separate conditions for different overloaded functions, so
7145 we take just a single condition string.
7147 NOTE: If the function succeeds, the caller is expected to cleanup
7148 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7149 array contents). If the function fails (error() is called), the
7150 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7151 COND and SALS arrays and each of those arrays contents. */
7154 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7155 struct symtabs_and_lines sals
, char **addr_string
,
7157 enum bptype type
, enum bpdisp disposition
,
7158 int thread
, int task
, int ignore_count
,
7159 struct breakpoint_ops
*ops
, int from_tty
,
7164 for (i
= 0; i
< sals
.nelts
; ++i
)
7166 struct symtabs_and_lines expanded
=
7167 expand_line_sal_maybe (sals
.sals
[i
]);
7169 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7170 cond_string
, type
, disposition
,
7171 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7175 /* Parse ARG which is assumed to be a SAL specification possibly
7176 followed by conditionals. On return, SALS contains an array of SAL
7177 addresses found. ADDR_STRING contains a vector of (canonical)
7178 address strings. ARG points to the end of the SAL. */
7181 parse_breakpoint_sals (char **address
,
7182 struct symtabs_and_lines
*sals
,
7183 char ***addr_string
,
7186 char *addr_start
= *address
;
7188 *addr_string
= NULL
;
7189 /* If no arg given, or if first arg is 'if ', use the default
7191 if ((*address
) == NULL
7192 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7194 if (default_breakpoint_valid
)
7196 struct symtab_and_line sal
;
7198 init_sal (&sal
); /* initialize to zeroes */
7199 sals
->sals
= (struct symtab_and_line
*)
7200 xmalloc (sizeof (struct symtab_and_line
));
7201 sal
.pc
= default_breakpoint_address
;
7202 sal
.line
= default_breakpoint_line
;
7203 sal
.symtab
= default_breakpoint_symtab
;
7204 sal
.pspace
= default_breakpoint_pspace
;
7205 sal
.section
= find_pc_overlay (sal
.pc
);
7207 /* "break" without arguments is equivalent to "break *PC" where PC is
7208 the default_breakpoint_address. So make sure to set
7209 sal.explicit_pc to prevent GDB from trying to expand the list of
7210 sals to include all other instances with the same symtab and line.
7212 sal
.explicit_pc
= 1;
7214 sals
->sals
[0] = sal
;
7218 error (_("No default breakpoint address now."));
7222 /* Force almost all breakpoints to be in terms of the
7223 current_source_symtab (which is decode_line_1's default). This
7224 should produce the results we want almost all of the time while
7225 leaving default_breakpoint_* alone.
7226 ObjC: However, don't match an Objective-C method name which
7227 may have a '+' or '-' succeeded by a '[' */
7229 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7231 if (default_breakpoint_valid
7233 || ((strchr ("+-", (*address
)[0]) != NULL
)
7234 && ((*address
)[1] != '['))))
7235 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7236 default_breakpoint_line
, addr_string
,
7239 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7240 addr_string
, not_found_ptr
);
7242 /* For any SAL that didn't have a canonical string, fill one in. */
7243 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7244 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7245 if (addr_start
!= (*address
))
7249 for (i
= 0; i
< sals
->nelts
; i
++)
7251 /* Add the string if not present. */
7252 if ((*addr_string
)[i
] == NULL
)
7253 (*addr_string
)[i
] = savestring (addr_start
,
7254 (*address
) - addr_start
);
7260 /* Convert each SAL into a real PC. Verify that the PC can be
7261 inserted as a breakpoint. If it can't throw an error. */
7264 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7269 for (i
= 0; i
< sals
->nelts
; i
++)
7270 resolve_sal_pc (&sals
->sals
[i
]);
7273 /* Fast tracepoints may have restrictions on valid locations. For
7274 instance, a fast tracepoint using a jump instead of a trap will
7275 likely have to overwrite more bytes than a trap would, and so can
7276 only be placed where the instruction is longer than the jump, or a
7277 multi-instruction sequence does not have a jump into the middle of
7281 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7282 struct symtabs_and_lines
*sals
)
7285 struct symtab_and_line
*sal
;
7287 struct cleanup
*old_chain
;
7289 for (i
= 0; i
< sals
->nelts
; i
++)
7291 sal
= &sals
->sals
[i
];
7293 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7295 old_chain
= make_cleanup (xfree
, msg
);
7298 error (_("May not have a fast tracepoint at 0x%s%s"),
7299 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7301 do_cleanups (old_chain
);
7306 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7308 struct captured_parse_breakpoint_args
*args
= data
;
7310 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7311 args
->not_found_ptr
);
7314 /* Given TOK, a string specification of condition and thread, as
7315 accepted by the 'break' command, extract the condition
7316 string and thread number and set *COND_STRING and *THREAD.
7317 PC identifies the context at which the condition should be parsed.
7318 If no condition is found, *COND_STRING is set to NULL.
7319 If no thread is found, *THREAD is set to -1. */
7321 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7322 char **cond_string
, int *thread
, int *task
)
7324 *cond_string
= NULL
;
7330 char *cond_start
= NULL
;
7331 char *cond_end
= NULL
;
7333 while (*tok
== ' ' || *tok
== '\t')
7338 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7341 toklen
= end_tok
- tok
;
7343 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7345 struct expression
*expr
;
7347 tok
= cond_start
= end_tok
+ 1;
7348 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7351 *cond_string
= savestring (cond_start
,
7352 cond_end
- cond_start
);
7354 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7360 *thread
= strtol (tok
, &tok
, 0);
7362 error (_("Junk after thread keyword."));
7363 if (!valid_thread_id (*thread
))
7364 error (_("Unknown thread %d."), *thread
);
7366 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7372 *task
= strtol (tok
, &tok
, 0);
7374 error (_("Junk after task keyword."));
7375 if (!valid_task_id (*task
))
7376 error (_("Unknown task %d."), *task
);
7379 error (_("Junk at end of arguments."));
7383 /* Set a breakpoint. This function is shared between CLI and MI
7384 functions for setting a breakpoint. This function has two major
7385 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7386 parameter. If non-zero, the function will parse arg, extracting
7387 breakpoint location, address and thread. Otherwise, ARG is just the
7388 location of breakpoint, with condition and thread specified by the
7389 COND_STRING and THREAD parameters. Returns true if any breakpoint
7390 was created; false otherwise. */
7393 create_breakpoint (struct gdbarch
*gdbarch
,
7394 char *arg
, char *cond_string
, int thread
,
7395 int parse_condition_and_thread
,
7396 int tempflag
, int hardwareflag
, int traceflag
,
7398 enum auto_boolean pending_break_support
,
7399 struct breakpoint_ops
*ops
,
7403 struct gdb_exception e
;
7404 struct symtabs_and_lines sals
;
7405 struct symtab_and_line pending_sal
;
7407 char *addr_start
= arg
;
7409 struct cleanup
*old_chain
;
7410 struct cleanup
*bkpt_chain
= NULL
;
7411 struct captured_parse_breakpoint_args parse_args
;
7415 enum bptype type_wanted
;
7417 int prev_bkpt_count
= breakpoint_count
;
7423 parse_args
.arg_p
= &arg
;
7424 parse_args
.sals_p
= &sals
;
7425 parse_args
.addr_string_p
= &addr_string
;
7426 parse_args
.not_found_ptr
= ¬_found
;
7428 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7429 &parse_args
, RETURN_MASK_ALL
);
7431 /* If caller is interested in rc value from parse, set value. */
7435 throw_exception (e
);
7439 case NOT_FOUND_ERROR
:
7441 /* If pending breakpoint support is turned off, throw
7444 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7445 throw_exception (e
);
7447 exception_print (gdb_stderr
, e
);
7449 /* If pending breakpoint support is auto query and the user
7450 selects no, then simply return the error code. */
7451 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7452 && !nquery ("Make breakpoint pending on future shared library load? "))
7455 /* At this point, either the user was queried about setting
7456 a pending breakpoint and selected yes, or pending
7457 breakpoint behavior is on and thus a pending breakpoint
7458 is defaulted on behalf of the user. */
7459 copy_arg
= xstrdup (addr_start
);
7460 addr_string
= ©_arg
;
7462 sals
.sals
= &pending_sal
;
7467 throw_exception (e
);
7474 /* Create a chain of things that always need to be cleaned up. */
7475 old_chain
= make_cleanup (null_cleanup
, 0);
7479 /* Make sure that all storage allocated to SALS gets freed. */
7480 make_cleanup (xfree
, sals
.sals
);
7482 /* Cleanup the addr_string array but not its contents. */
7483 make_cleanup (xfree
, addr_string
);
7486 /* ----------------------------- SNIP -----------------------------
7487 Anything added to the cleanup chain beyond this point is assumed
7488 to be part of a breakpoint. If the breakpoint create succeeds
7489 then the memory is not reclaimed. */
7490 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7492 /* Mark the contents of the addr_string for cleanup. These go on
7493 the bkpt_chain and only occur if the breakpoint create fails. */
7494 for (i
= 0; i
< sals
.nelts
; i
++)
7496 if (addr_string
[i
] != NULL
)
7497 make_cleanup (xfree
, addr_string
[i
]);
7500 /* Resolve all line numbers to PC's and verify that the addresses
7501 are ok for the target. */
7503 breakpoint_sals_to_pc (&sals
, addr_start
);
7505 type_wanted
= (traceflag
7506 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7507 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7509 /* Fast tracepoints may have additional restrictions on location. */
7510 if (type_wanted
== bp_fast_tracepoint
)
7511 check_fast_tracepoint_sals (gdbarch
, &sals
);
7513 /* Verify that condition can be parsed, before setting any
7514 breakpoints. Allocate a separate condition expression for each
7518 if (parse_condition_and_thread
)
7520 /* Here we only parse 'arg' to separate condition
7521 from thread number, so parsing in context of first
7522 sal is OK. When setting the breakpoint we'll
7523 re-parse it in context of each sal. */
7526 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7529 make_cleanup (xfree
, cond_string
);
7533 /* Create a private copy of condition string. */
7536 cond_string
= xstrdup (cond_string
);
7537 make_cleanup (xfree
, cond_string
);
7540 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7541 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7542 thread
, task
, ignore_count
, ops
, from_tty
,
7547 struct breakpoint
*b
;
7549 make_cleanup (xfree
, copy_arg
);
7551 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7552 set_breakpoint_count (breakpoint_count
+ 1);
7553 b
->number
= breakpoint_count
;
7555 b
->addr_string
= addr_string
[0];
7556 b
->cond_string
= NULL
;
7557 b
->ignore_count
= ignore_count
;
7558 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7559 b
->condition_not_parsed
= 1;
7561 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7562 b
->pspace
= current_program_space
;
7564 if (enabled
&& b
->pspace
->executing_startup
7565 && (b
->type
== bp_breakpoint
7566 || b
->type
== bp_hardware_breakpoint
))
7567 b
->enable_state
= bp_startup_disabled
;
7574 warning (_("Multiple breakpoints were set.\n"
7575 "Use the \"delete\" command to delete unwanted breakpoints."));
7576 prev_breakpoint_count
= prev_bkpt_count
;
7579 /* That's it. Discard the cleanups for data inserted into the
7581 discard_cleanups (bkpt_chain
);
7582 /* But cleanup everything else. */
7583 do_cleanups (old_chain
);
7585 /* error call may happen here - have BKPT_CHAIN already discarded. */
7586 update_global_location_list (1);
7591 /* Set a breakpoint.
7592 ARG is a string describing breakpoint address,
7593 condition, and thread.
7594 FLAG specifies if a breakpoint is hardware on,
7595 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7599 break_command_1 (char *arg
, int flag
, int from_tty
)
7601 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7602 int tempflag
= flag
& BP_TEMPFLAG
;
7604 create_breakpoint (get_current_arch (),
7606 NULL
, 0, 1 /* parse arg */,
7607 tempflag
, hardwareflag
, 0 /* traceflag */,
7608 0 /* Ignore count */,
7609 pending_break_support
,
7610 NULL
/* breakpoint_ops */,
7616 /* Helper function for break_command_1 and disassemble_command. */
7619 resolve_sal_pc (struct symtab_and_line
*sal
)
7623 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7625 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7626 error (_("No line %d in file \"%s\"."),
7627 sal
->line
, sal
->symtab
->filename
);
7630 /* If this SAL corresponds to a breakpoint inserted using
7631 a line number, then skip the function prologue if necessary. */
7632 if (sal
->explicit_line
)
7633 skip_prologue_sal (sal
);
7636 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7638 struct blockvector
*bv
;
7642 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7645 sym
= block_linkage_function (b
);
7648 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7649 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7653 /* It really is worthwhile to have the section, so we'll just
7654 have to look harder. This case can be executed if we have
7655 line numbers but no functions (as can happen in assembly
7658 struct minimal_symbol
*msym
;
7659 struct cleanup
*old_chain
= save_current_space_and_thread ();
7661 switch_to_program_space_and_thread (sal
->pspace
);
7663 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7665 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7667 do_cleanups (old_chain
);
7674 break_command (char *arg
, int from_tty
)
7676 break_command_1 (arg
, 0, from_tty
);
7680 tbreak_command (char *arg
, int from_tty
)
7682 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7686 hbreak_command (char *arg
, int from_tty
)
7688 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7692 thbreak_command (char *arg
, int from_tty
)
7694 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7698 stop_command (char *arg
, int from_tty
)
7700 printf_filtered (_("Specify the type of breakpoint to set.\n\
7701 Usage: stop in <function | address>\n\
7702 stop at <line>\n"));
7706 stopin_command (char *arg
, int from_tty
)
7710 if (arg
== (char *) NULL
)
7712 else if (*arg
!= '*')
7717 /* look for a ':'. If this is a line number specification, then
7718 say it is bad, otherwise, it should be an address or
7719 function/method name */
7720 while (*argptr
&& !hasColon
)
7722 hasColon
= (*argptr
== ':');
7727 badInput
= (*argptr
!= ':'); /* Not a class::method */
7729 badInput
= isdigit (*arg
); /* a simple line number */
7733 printf_filtered (_("Usage: stop in <function | address>\n"));
7735 break_command_1 (arg
, 0, from_tty
);
7739 stopat_command (char *arg
, int from_tty
)
7743 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7750 /* look for a ':'. If there is a '::' then get out, otherwise
7751 it is probably a line number. */
7752 while (*argptr
&& !hasColon
)
7754 hasColon
= (*argptr
== ':');
7759 badInput
= (*argptr
== ':'); /* we have class::method */
7761 badInput
= !isdigit (*arg
); /* not a line number */
7765 printf_filtered (_("Usage: stop at <line>\n"));
7767 break_command_1 (arg
, 0, from_tty
);
7770 /* accessflag: hw_write: watch write,
7771 hw_read: watch read,
7772 hw_access: watch access (read or write) */
7774 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7776 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7777 struct expression
*exp
;
7778 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7779 struct value
*val
, *mark
;
7780 struct frame_info
*frame
;
7781 char *exp_start
= NULL
;
7782 char *exp_end
= NULL
;
7783 char *tok
, *id_tok_start
, *end_tok
;
7785 char *cond_start
= NULL
;
7786 char *cond_end
= NULL
;
7787 int i
, other_type_used
, target_resources_ok
= 0;
7788 enum bptype bp_type
;
7792 /* Make sure that we actually have parameters to parse. */
7793 if (arg
!= NULL
&& arg
[0] != '\0')
7795 toklen
= strlen (arg
); /* Size of argument list. */
7797 /* Points tok to the end of the argument list. */
7798 tok
= arg
+ toklen
- 1;
7800 /* Go backwards in the parameters list. Skip the last parameter.
7801 If we're expecting a 'thread <thread_num>' parameter, this should
7802 be the thread identifier. */
7803 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7805 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7808 /* Points end_tok to the beginning of the last token. */
7809 id_tok_start
= tok
+ 1;
7811 /* Go backwards in the parameters list. Skip one more parameter.
7812 If we're expecting a 'thread <thread_num>' parameter, we should
7813 reach a "thread" token. */
7814 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7819 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7822 /* Move the pointer forward to skip the whitespace and
7823 calculate the length of the token. */
7825 toklen
= end_tok
- tok
;
7827 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7829 /* At this point we've found a "thread" token, which means
7830 the user is trying to set a watchpoint that triggers
7831 only in a specific thread. */
7834 /* Extract the thread ID from the next token. */
7835 thread
= strtol (id_tok_start
, &endp
, 0);
7837 /* Check if the user provided a valid numeric value for the
7839 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7840 error (_("Invalid thread ID specification %s."), id_tok_start
);
7842 /* Check if the thread actually exists. */
7843 if (!valid_thread_id (thread
))
7844 error (_("Unknown thread %d."), thread
);
7846 /* Truncate the string and get rid of the thread <thread_num>
7847 parameter before the parameter list is parsed by the
7848 evaluate_expression() function. */
7853 /* Parse the rest of the arguments. */
7854 innermost_block
= NULL
;
7856 exp
= parse_exp_1 (&arg
, 0, 0);
7858 /* Remove trailing whitespace from the expression before saving it.
7859 This makes the eventual display of the expression string a bit
7861 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7864 exp_valid_block
= innermost_block
;
7865 mark
= value_mark ();
7866 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7868 release_value (val
);
7871 while (*tok
== ' ' || *tok
== '\t')
7875 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7878 toklen
= end_tok
- tok
;
7879 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7881 struct expression
*cond
;
7883 innermost_block
= NULL
;
7884 tok
= cond_start
= end_tok
+ 1;
7885 cond
= parse_exp_1 (&tok
, 0, 0);
7887 /* The watchpoint expression may not be local, but the condition
7888 may still be. E.g.: `watch global if local > 0'. */
7889 cond_exp_valid_block
= innermost_block
;
7895 error (_("Junk at end of command."));
7897 if (accessflag
== hw_read
)
7898 bp_type
= bp_read_watchpoint
;
7899 else if (accessflag
== hw_access
)
7900 bp_type
= bp_access_watchpoint
;
7902 bp_type
= bp_hardware_watchpoint
;
7904 mem_cnt
= can_use_hardware_watchpoint (val
);
7905 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7906 error (_("Expression cannot be implemented with read/access watchpoint."));
7909 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7910 target_resources_ok
=
7911 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7913 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7914 error (_("Target does not support this type of hardware watchpoint."));
7916 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7917 error (_("Target can only support one kind of HW watchpoint at a time."));
7920 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7921 watchpoint could not be set. */
7922 if (!mem_cnt
|| target_resources_ok
<= 0)
7923 bp_type
= bp_watchpoint
;
7925 frame
= block_innermost_frame (exp_valid_block
);
7927 /* If the expression is "local", then set up a "watchpoint scope"
7928 breakpoint at the point where we've left the scope of the watchpoint
7929 expression. Create the scope breakpoint before the watchpoint, so
7930 that we will encounter it first in bpstat_stop_status. */
7931 if (exp_valid_block
&& frame
)
7933 if (frame_id_p (frame_unwind_caller_id (frame
)))
7936 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7937 frame_unwind_caller_pc (frame
),
7938 bp_watchpoint_scope
);
7940 scope_breakpoint
->enable_state
= bp_enabled
;
7942 /* Automatically delete the breakpoint when it hits. */
7943 scope_breakpoint
->disposition
= disp_del
;
7945 /* Only break in the proper frame (help with recursion). */
7946 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7948 /* Set the address at which we will stop. */
7949 scope_breakpoint
->loc
->gdbarch
7950 = frame_unwind_caller_arch (frame
);
7951 scope_breakpoint
->loc
->requested_address
7952 = frame_unwind_caller_pc (frame
);
7953 scope_breakpoint
->loc
->address
7954 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7955 scope_breakpoint
->loc
->requested_address
,
7956 scope_breakpoint
->type
);
7960 /* Now set up the breakpoint. */
7961 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7962 set_breakpoint_count (breakpoint_count
+ 1);
7963 b
->number
= breakpoint_count
;
7965 b
->disposition
= disp_donttouch
;
7967 b
->exp_valid_block
= exp_valid_block
;
7968 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7969 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7973 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7979 b
->watchpoint_frame
= get_frame_id (frame
);
7980 b
->watchpoint_thread
= inferior_ptid
;
7984 b
->watchpoint_frame
= null_frame_id
;
7985 b
->watchpoint_thread
= null_ptid
;
7988 if (scope_breakpoint
!= NULL
)
7990 /* The scope breakpoint is related to the watchpoint. We will
7991 need to act on them together. */
7992 b
->related_breakpoint
= scope_breakpoint
;
7993 scope_breakpoint
->related_breakpoint
= b
;
7996 value_free_to_mark (mark
);
7998 /* Finally update the new watchpoint. This creates the locations
7999 that should be inserted. */
8000 update_watchpoint (b
, 1);
8003 update_global_location_list (1);
8006 /* Return count of locations need to be watched and can be handled
8007 in hardware. If the watchpoint can not be handled
8008 in hardware return zero. */
8011 can_use_hardware_watchpoint (struct value
*v
)
8013 int found_memory_cnt
= 0;
8014 struct value
*head
= v
;
8016 /* Did the user specifically forbid us to use hardware watchpoints? */
8017 if (!can_use_hw_watchpoints
)
8020 /* Make sure that the value of the expression depends only upon
8021 memory contents, and values computed from them within GDB. If we
8022 find any register references or function calls, we can't use a
8023 hardware watchpoint.
8025 The idea here is that evaluating an expression generates a series
8026 of values, one holding the value of every subexpression. (The
8027 expression a*b+c has five subexpressions: a, b, a*b, c, and
8028 a*b+c.) GDB's values hold almost enough information to establish
8029 the criteria given above --- they identify memory lvalues,
8030 register lvalues, computed values, etcetera. So we can evaluate
8031 the expression, and then scan the chain of values that leaves
8032 behind to decide whether we can detect any possible change to the
8033 expression's final value using only hardware watchpoints.
8035 However, I don't think that the values returned by inferior
8036 function calls are special in any way. So this function may not
8037 notice that an expression involving an inferior function call
8038 can't be watched with hardware watchpoints. FIXME. */
8039 for (; v
; v
= value_next (v
))
8041 if (VALUE_LVAL (v
) == lval_memory
)
8044 /* A lazy memory lvalue is one that GDB never needed to fetch;
8045 we either just used its address (e.g., `a' in `a.b') or
8046 we never needed it at all (e.g., `a' in `a,b'). */
8050 /* Ahh, memory we actually used! Check if we can cover
8051 it with hardware watchpoints. */
8052 struct type
*vtype
= check_typedef (value_type (v
));
8054 /* We only watch structs and arrays if user asked for it
8055 explicitly, never if they just happen to appear in a
8056 middle of some value chain. */
8058 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8059 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8061 CORE_ADDR vaddr
= value_address (v
);
8062 int len
= TYPE_LENGTH (value_type (v
));
8064 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
8071 else if (VALUE_LVAL (v
) != not_lval
8072 && deprecated_value_modifiable (v
) == 0)
8073 return 0; /* ??? What does this represent? */
8074 else if (VALUE_LVAL (v
) == lval_register
)
8075 return 0; /* cannot watch a register with a HW watchpoint */
8078 /* The expression itself looks suitable for using a hardware
8079 watchpoint, but give the target machine a chance to reject it. */
8080 return found_memory_cnt
;
8084 watch_command_wrapper (char *arg
, int from_tty
)
8086 watch_command (arg
, from_tty
);
8090 watch_command (char *arg
, int from_tty
)
8092 watch_command_1 (arg
, hw_write
, from_tty
);
8096 rwatch_command_wrapper (char *arg
, int from_tty
)
8098 rwatch_command (arg
, from_tty
);
8102 rwatch_command (char *arg
, int from_tty
)
8104 watch_command_1 (arg
, hw_read
, from_tty
);
8108 awatch_command_wrapper (char *arg
, int from_tty
)
8110 awatch_command (arg
, from_tty
);
8114 awatch_command (char *arg
, int from_tty
)
8116 watch_command_1 (arg
, hw_access
, from_tty
);
8120 /* Helper routines for the until_command routine in infcmd.c. Here
8121 because it uses the mechanisms of breakpoints. */
8123 struct until_break_command_continuation_args
8125 struct breakpoint
*breakpoint
;
8126 struct breakpoint
*breakpoint2
;
8129 /* This function is called by fetch_inferior_event via the
8130 cmd_continuation pointer, to complete the until command. It takes
8131 care of cleaning up the temporary breakpoints set up by the until
8134 until_break_command_continuation (void *arg
)
8136 struct until_break_command_continuation_args
*a
= arg
;
8138 delete_breakpoint (a
->breakpoint
);
8140 delete_breakpoint (a
->breakpoint2
);
8144 until_break_command (char *arg
, int from_tty
, int anywhere
)
8146 struct symtabs_and_lines sals
;
8147 struct symtab_and_line sal
;
8148 struct frame_info
*frame
= get_selected_frame (NULL
);
8149 struct breakpoint
*breakpoint
;
8150 struct breakpoint
*breakpoint2
= NULL
;
8151 struct cleanup
*old_chain
;
8153 clear_proceed_status ();
8155 /* Set a breakpoint where the user wants it and at return from
8158 if (default_breakpoint_valid
)
8159 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8160 default_breakpoint_line
, (char ***) NULL
, NULL
);
8162 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8163 0, (char ***) NULL
, NULL
);
8165 if (sals
.nelts
!= 1)
8166 error (_("Couldn't get information on specified line."));
8169 xfree (sals
.sals
); /* malloc'd, so freed */
8172 error (_("Junk at end of arguments."));
8174 resolve_sal_pc (&sal
);
8177 /* If the user told us to continue until a specified location,
8178 we don't specify a frame at which we need to stop. */
8179 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8180 null_frame_id
, bp_until
);
8182 /* Otherwise, specify the selected frame, because we want to stop only
8183 at the very same frame. */
8184 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8185 get_stack_frame_id (frame
),
8188 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8190 /* Keep within the current frame, or in frames called by the current
8193 if (frame_id_p (frame_unwind_caller_id (frame
)))
8195 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8196 sal
.pc
= frame_unwind_caller_pc (frame
);
8197 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8199 frame_unwind_caller_id (frame
),
8201 make_cleanup_delete_breakpoint (breakpoint2
);
8204 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8206 /* If we are running asynchronously, and proceed call above has actually
8207 managed to start the target, arrange for breakpoints to be
8208 deleted when the target stops. Otherwise, we're already stopped and
8209 delete breakpoints via cleanup chain. */
8211 if (target_can_async_p () && is_running (inferior_ptid
))
8213 struct until_break_command_continuation_args
*args
;
8214 args
= xmalloc (sizeof (*args
));
8216 args
->breakpoint
= breakpoint
;
8217 args
->breakpoint2
= breakpoint2
;
8219 discard_cleanups (old_chain
);
8220 add_continuation (inferior_thread (),
8221 until_break_command_continuation
, args
,
8225 do_cleanups (old_chain
);
8229 ep_skip_leading_whitespace (char **s
)
8231 if ((s
== NULL
) || (*s
== NULL
))
8233 while (isspace (**s
))
8237 /* This function attempts to parse an optional "if <cond>" clause
8238 from the arg string. If one is not found, it returns NULL.
8240 Else, it returns a pointer to the condition string. (It does not
8241 attempt to evaluate the string against a particular block.) And,
8242 it updates arg to point to the first character following the parsed
8243 if clause in the arg string. */
8246 ep_parse_optional_if_clause (char **arg
)
8250 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8253 /* Skip the "if" keyword. */
8256 /* Skip any extra leading whitespace, and record the start of the
8257 condition string. */
8258 ep_skip_leading_whitespace (arg
);
8261 /* Assume that the condition occupies the remainder of the arg string. */
8262 (*arg
) += strlen (cond_string
);
8267 /* Commands to deal with catching events, such as signals, exceptions,
8268 process start/exit, etc. */
8272 catch_fork_temporary
, catch_vfork_temporary
,
8273 catch_fork_permanent
, catch_vfork_permanent
8278 catch_fork_command_1 (char *arg
, int from_tty
,
8279 struct cmd_list_element
*command
)
8281 struct gdbarch
*gdbarch
= get_current_arch ();
8282 char *cond_string
= NULL
;
8283 catch_fork_kind fork_kind
;
8286 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8287 tempflag
= (fork_kind
== catch_fork_temporary
8288 || fork_kind
== catch_vfork_temporary
);
8292 ep_skip_leading_whitespace (&arg
);
8294 /* The allowed syntax is:
8296 catch [v]fork if <cond>
8298 First, check if there's an if clause. */
8299 cond_string
= ep_parse_optional_if_clause (&arg
);
8301 if ((*arg
!= '\0') && !isspace (*arg
))
8302 error (_("Junk at end of arguments."));
8304 /* If this target supports it, create a fork or vfork catchpoint
8305 and enable reporting of such events. */
8308 case catch_fork_temporary
:
8309 case catch_fork_permanent
:
8310 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8311 &catch_fork_breakpoint_ops
);
8313 case catch_vfork_temporary
:
8314 case catch_vfork_permanent
:
8315 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8316 &catch_vfork_breakpoint_ops
);
8319 error (_("unsupported or unknown fork kind; cannot catch it"));
8325 catch_exec_command_1 (char *arg
, int from_tty
,
8326 struct cmd_list_element
*command
)
8328 struct gdbarch
*gdbarch
= get_current_arch ();
8330 char *cond_string
= NULL
;
8332 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8336 ep_skip_leading_whitespace (&arg
);
8338 /* The allowed syntax is:
8340 catch exec if <cond>
8342 First, check if there's an if clause. */
8343 cond_string
= ep_parse_optional_if_clause (&arg
);
8345 if ((*arg
!= '\0') && !isspace (*arg
))
8346 error (_("Junk at end of arguments."));
8348 /* If this target supports it, create an exec catchpoint
8349 and enable reporting of such events. */
8350 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8351 &catch_exec_breakpoint_ops
);
8354 static enum print_stop_action
8355 print_exception_catchpoint (struct breakpoint
*b
)
8357 int bp_temp
, bp_throw
;
8359 annotate_catchpoint (b
->number
);
8361 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8362 if (b
->loc
->address
!= b
->loc
->requested_address
)
8363 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8366 bp_temp
= b
->disposition
== disp_del
;
8368 bp_temp
? "Temporary catchpoint "
8370 if (!ui_out_is_mi_like_p (uiout
))
8371 ui_out_field_int (uiout
, "bkptno", b
->number
);
8373 bp_throw
? " (exception thrown), "
8374 : " (exception caught), ");
8375 if (ui_out_is_mi_like_p (uiout
))
8377 ui_out_field_string (uiout
, "reason",
8378 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8379 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8380 ui_out_field_int (uiout
, "bkptno", b
->number
);
8382 return PRINT_SRC_AND_LOC
;
8386 print_one_exception_catchpoint (struct breakpoint
*b
,
8387 struct bp_location
**last_loc
)
8389 struct value_print_options opts
;
8391 get_user_print_options (&opts
);
8392 if (opts
.addressprint
)
8395 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8396 ui_out_field_string (uiout
, "addr", "<PENDING>");
8398 ui_out_field_core_addr (uiout
, "addr",
8399 b
->loc
->gdbarch
, b
->loc
->address
);
8404 if (strstr (b
->addr_string
, "throw") != NULL
)
8405 ui_out_field_string (uiout
, "what", "exception throw");
8407 ui_out_field_string (uiout
, "what", "exception catch");
8411 print_mention_exception_catchpoint (struct breakpoint
*b
)
8416 bp_temp
= b
->disposition
== disp_del
;
8417 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8418 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8419 : _("Catchpoint "));
8420 ui_out_field_int (uiout
, "bkptno", b
->number
);
8421 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8425 /* Implement the "print_recreate" breakpoint_ops method for throw and
8426 catch catchpoints. */
8429 print_recreate_exception_catchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8434 bp_temp
= b
->disposition
== disp_del
;
8435 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8436 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
8437 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
8440 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8443 NULL
, /* breakpoint_hit */
8444 print_exception_catchpoint
,
8445 print_one_exception_catchpoint
,
8446 print_mention_exception_catchpoint
,
8447 print_recreate_exception_catchpoint
8451 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8452 enum exception_event_kind ex_event
, int from_tty
)
8454 char *trigger_func_name
;
8456 if (ex_event
== EX_EVENT_CATCH
)
8457 trigger_func_name
= "__cxa_begin_catch";
8459 trigger_func_name
= "__cxa_throw";
8461 create_breakpoint (get_current_arch (),
8462 trigger_func_name
, cond_string
, -1,
8463 0 /* condition and thread are valid. */,
8466 AUTO_BOOLEAN_TRUE
/* pending */,
8467 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8473 /* Deal with "catch catch" and "catch throw" commands */
8476 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8477 int tempflag
, int from_tty
)
8479 char *cond_string
= NULL
;
8483 ep_skip_leading_whitespace (&arg
);
8485 cond_string
= ep_parse_optional_if_clause (&arg
);
8487 if ((*arg
!= '\0') && !isspace (*arg
))
8488 error (_("Junk at end of arguments."));
8490 if (ex_event
!= EX_EVENT_THROW
8491 && ex_event
!= EX_EVENT_CATCH
)
8492 error (_("Unsupported or unknown exception event; cannot catch it"));
8494 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8497 warning (_("Unsupported with this platform/compiler combination."));
8500 /* Implementation of "catch catch" command. */
8503 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8505 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8507 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8510 /* Implementation of "catch throw" command. */
8513 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8515 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8517 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8520 /* Create a breakpoint struct for Ada exception catchpoints. */
8523 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8524 struct symtab_and_line sal
,
8528 struct expression
*cond
,
8529 struct breakpoint_ops
*ops
,
8533 struct breakpoint
*b
;
8537 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8539 loc_gdbarch
= gdbarch
;
8541 describe_other_breakpoints (loc_gdbarch
,
8542 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8543 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8544 version for exception catchpoints, because two catchpoints
8545 used for different exception names will use the same address.
8546 In this case, a "breakpoint ... also set at..." warning is
8547 unproductive. Besides. the warning phrasing is also a bit
8548 inapropriate, we should use the word catchpoint, and tell
8549 the user what type of catchpoint it is. The above is good
8550 enough for now, though. */
8553 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8554 set_breakpoint_count (breakpoint_count
+ 1);
8556 b
->enable_state
= bp_enabled
;
8557 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8558 b
->number
= breakpoint_count
;
8559 b
->ignore_count
= 0;
8560 b
->loc
->cond
= cond
;
8561 b
->addr_string
= addr_string
;
8562 b
->language
= language_ada
;
8563 b
->cond_string
= cond_string
;
8564 b
->exp_string
= exp_string
;
8569 update_global_location_list (1);
8572 /* Implement the "catch exception" command. */
8575 catch_ada_exception_command (char *arg
, int from_tty
,
8576 struct cmd_list_element
*command
)
8578 struct gdbarch
*gdbarch
= get_current_arch ();
8580 struct symtab_and_line sal
;
8581 char *addr_string
= NULL
;
8582 char *exp_string
= NULL
;
8583 char *cond_string
= NULL
;
8584 struct expression
*cond
= NULL
;
8585 struct breakpoint_ops
*ops
= NULL
;
8587 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8591 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8592 &cond_string
, &cond
, &ops
);
8593 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8594 cond_string
, cond
, ops
, tempflag
,
8598 /* Cleanup function for a syscall filter list. */
8600 clean_up_filters (void *arg
)
8602 VEC(int) *iter
= *(VEC(int) **) arg
;
8603 VEC_free (int, iter
);
8606 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8607 filter list, or NULL if no filtering is required. */
8609 catch_syscall_split_args (char *arg
)
8611 VEC(int) *result
= NULL
;
8612 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8614 while (*arg
!= '\0')
8616 int i
, syscall_number
;
8621 /* Skip whitespace. */
8622 while (isspace (*arg
))
8625 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8626 cur_name
[i
] = arg
[i
];
8630 /* Check if the user provided a syscall name or a number. */
8631 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8632 if (*endptr
== '\0')
8633 get_syscall_by_number (syscall_number
, &s
);
8636 /* We have a name. Let's check if it's valid and convert it
8638 get_syscall_by_name (cur_name
, &s
);
8640 if (s
.number
== UNKNOWN_SYSCALL
)
8641 /* Here we have to issue an error instead of a warning, because
8642 GDB cannot do anything useful if there's no syscall number to
8644 error (_("Unknown syscall name '%s'."), cur_name
);
8647 /* Ok, it's valid. */
8648 VEC_safe_push (int, result
, s
.number
);
8651 discard_cleanups (cleanup
);
8655 /* Implement the "catch syscall" command. */
8658 catch_syscall_command_1 (char *arg
, int from_tty
,
8659 struct cmd_list_element
*command
)
8664 struct gdbarch
*gdbarch
= get_current_arch ();
8666 /* Checking if the feature if supported. */
8667 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8668 error (_("The feature 'catch syscall' is not supported on \
8669 this architeture yet."));
8671 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8673 ep_skip_leading_whitespace (&arg
);
8675 /* We need to do this first "dummy" translation in order
8676 to get the syscall XML file loaded or, most important,
8677 to display a warning to the user if there's no XML file
8678 for his/her architecture. */
8679 get_syscall_by_number (0, &s
);
8681 /* The allowed syntax is:
8683 catch syscall <name | number> [<name | number> ... <name | number>]
8685 Let's check if there's a syscall name. */
8688 filter
= catch_syscall_split_args (arg
);
8692 create_syscall_event_catchpoint (tempflag
, filter
,
8693 &catch_syscall_breakpoint_ops
);
8696 /* Implement the "catch assert" command. */
8699 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8701 struct gdbarch
*gdbarch
= get_current_arch ();
8703 struct symtab_and_line sal
;
8704 char *addr_string
= NULL
;
8705 struct breakpoint_ops
*ops
= NULL
;
8707 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8711 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8712 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8713 ops
, tempflag
, from_tty
);
8717 catch_command (char *arg
, int from_tty
)
8719 error (_("Catch requires an event name."));
8724 tcatch_command (char *arg
, int from_tty
)
8726 error (_("Catch requires an event name."));
8729 /* Delete breakpoints by address or line. */
8732 clear_command (char *arg
, int from_tty
)
8734 struct breakpoint
*b
;
8735 VEC(breakpoint_p
) *found
= 0;
8738 struct symtabs_and_lines sals
;
8739 struct symtab_and_line sal
;
8744 sals
= decode_line_spec (arg
, 1);
8749 sals
.sals
= (struct symtab_and_line
*)
8750 xmalloc (sizeof (struct symtab_and_line
));
8751 make_cleanup (xfree
, sals
.sals
);
8752 init_sal (&sal
); /* initialize to zeroes */
8753 sal
.line
= default_breakpoint_line
;
8754 sal
.symtab
= default_breakpoint_symtab
;
8755 sal
.pc
= default_breakpoint_address
;
8756 sal
.pspace
= default_breakpoint_pspace
;
8757 if (sal
.symtab
== 0)
8758 error (_("No source file specified."));
8766 /* We don't call resolve_sal_pc here. That's not
8767 as bad as it seems, because all existing breakpoints
8768 typically have both file/line and pc set. So, if
8769 clear is given file/line, we can match this to existing
8770 breakpoint without obtaining pc at all.
8772 We only support clearing given the address explicitly
8773 present in breakpoint table. Say, we've set breakpoint
8774 at file:line. There were several PC values for that file:line,
8775 due to optimization, all in one block.
8776 We've picked one PC value. If "clear" is issued with another
8777 PC corresponding to the same file:line, the breakpoint won't
8778 be cleared. We probably can still clear the breakpoint, but
8779 since the other PC value is never presented to user, user
8780 can only find it by guessing, and it does not seem important
8783 /* For each line spec given, delete bps which correspond
8784 to it. Do it in two passes, solely to preserve the current
8785 behavior that from_tty is forced true if we delete more than
8789 for (i
= 0; i
< sals
.nelts
; i
++)
8791 /* If exact pc given, clear bpts at that pc.
8792 If line given (pc == 0), clear all bpts on specified line.
8793 If defaulting, clear all bpts on default line
8796 defaulting sal.pc != 0 tests to do
8801 1 0 <can't happen> */
8805 /* Find all matching breakpoints and add them to
8810 /* Are we going to delete b? */
8811 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
8813 struct bp_location
*loc
= b
->loc
;
8814 for (; loc
; loc
= loc
->next
)
8816 int pc_match
= sal
.pc
8817 && (loc
->pspace
== sal
.pspace
)
8818 && (loc
->address
== sal
.pc
)
8819 && (!section_is_overlay (loc
->section
)
8820 || loc
->section
== sal
.section
);
8821 int line_match
= ((default_match
|| (0 == sal
.pc
))
8822 && b
->source_file
!= NULL
8823 && sal
.symtab
!= NULL
8824 && sal
.pspace
== loc
->pspace
8825 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8826 && b
->line_number
== sal
.line
);
8827 if (pc_match
|| line_match
)
8836 VEC_safe_push(breakpoint_p
, found
, b
);
8839 /* Now go thru the 'found' chain and delete them. */
8840 if (VEC_empty(breakpoint_p
, found
))
8843 error (_("No breakpoint at %s."), arg
);
8845 error (_("No breakpoint at this line."));
8848 if (VEC_length(breakpoint_p
, found
) > 1)
8849 from_tty
= 1; /* Always report if deleted more than one */
8852 if (VEC_length(breakpoint_p
, found
) == 1)
8853 printf_unfiltered (_("Deleted breakpoint "));
8855 printf_unfiltered (_("Deleted breakpoints "));
8857 breakpoints_changed ();
8859 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8862 printf_unfiltered ("%d ", b
->number
);
8863 delete_breakpoint (b
);
8866 putchar_unfiltered ('\n');
8869 /* Delete breakpoint in BS if they are `delete' breakpoints and
8870 all breakpoints that are marked for deletion, whether hit or not.
8871 This is called after any breakpoint is hit, or after errors. */
8874 breakpoint_auto_delete (bpstat bs
)
8876 struct breakpoint
*b
, *temp
;
8878 for (; bs
; bs
= bs
->next
)
8879 if (bs
->breakpoint_at
8880 && bs
->breakpoint_at
->owner
8881 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8883 delete_breakpoint (bs
->breakpoint_at
->owner
);
8885 ALL_BREAKPOINTS_SAFE (b
, temp
)
8887 if (b
->disposition
== disp_del_at_next_stop
)
8888 delete_breakpoint (b
);
8892 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8893 Sort elements primarily by their ADDRESS (no matter what does
8894 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8895 first bp_permanent OWNERed elements and terciarily just ensuring the array
8896 is sorted stable way despite qsort being an instable algorithm. */
8899 bp_location_compare (const void *ap
, const void *bp
)
8901 struct bp_location
*a
= *(void **) ap
;
8902 struct bp_location
*b
= *(void **) bp
;
8903 /* A and B come from existing breakpoints having non-NULL OWNER. */
8904 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8905 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8907 if (a
->address
!= b
->address
)
8908 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8910 /* Sort permanent breakpoints first. */
8911 if (a_perm
!= b_perm
)
8912 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8914 /* Make the user-visible order stable across GDB runs. Locations of the same
8915 breakpoint can be sorted in arbitrary order. */
8917 if (a
->owner
->number
!= b
->owner
->number
)
8918 return (a
->owner
->number
> b
->owner
->number
)
8919 - (a
->owner
->number
< b
->owner
->number
);
8921 return (a
> b
) - (a
< b
);
8924 /* Set bp_location_placed_address_before_address_max and
8925 bp_location_shadow_len_after_address_max according to the current content of
8926 the bp_location array. */
8929 bp_location_target_extensions_update (void)
8931 struct bp_location
*bl
, **blp_tmp
;
8933 bp_location_placed_address_before_address_max
= 0;
8934 bp_location_shadow_len_after_address_max
= 0;
8936 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8938 CORE_ADDR start
, end
, addr
;
8940 if (!bp_location_has_shadow (bl
))
8943 start
= bl
->target_info
.placed_address
;
8944 end
= start
+ bl
->target_info
.shadow_len
;
8946 gdb_assert (bl
->address
>= start
);
8947 addr
= bl
->address
- start
;
8948 if (addr
> bp_location_placed_address_before_address_max
)
8949 bp_location_placed_address_before_address_max
= addr
;
8951 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8953 gdb_assert (bl
->address
< end
);
8954 addr
= end
- bl
->address
;
8955 if (addr
> bp_location_shadow_len_after_address_max
)
8956 bp_location_shadow_len_after_address_max
= addr
;
8960 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8961 into the inferior, only remove already-inserted locations that no
8962 longer should be inserted. Functions that delete a breakpoint or
8963 breakpoints should pass false, so that deleting a breakpoint
8964 doesn't have the side effect of inserting the locations of other
8965 breakpoints that are marked not-inserted, but should_be_inserted
8966 returns true on them.
8968 This behaviour is useful is situations close to tear-down -- e.g.,
8969 after an exec, while the target still has execution, but breakpoint
8970 shadows of the previous executable image should *NOT* be restored
8971 to the new image; or before detaching, where the target still has
8972 execution and wants to delete breakpoints from GDB's lists, and all
8973 breakpoints had already been removed from the inferior. */
8976 update_global_location_list (int should_insert
)
8978 struct breakpoint
*b
;
8979 struct bp_location
**locp
, *loc
;
8980 struct cleanup
*cleanups
;
8982 /* Used in the duplicates detection below. When iterating over all
8983 bp_locations, points to the first bp_location of a given address.
8984 Breakpoints and watchpoints of different types are never
8985 duplicates of each other. Keep one pointer for each type of
8986 breakpoint/watchpoint, so we only need to loop over all locations
8988 struct bp_location
*bp_loc_first
; /* breakpoint */
8989 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8990 struct bp_location
*awp_loc_first
; /* access watchpoint */
8991 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8993 /* Saved former bp_location array which we compare against the newly built
8994 bp_location from the current state of ALL_BREAKPOINTS. */
8995 struct bp_location
**old_location
, **old_locp
;
8996 unsigned old_location_count
;
8998 old_location
= bp_location
;
8999 old_location_count
= bp_location_count
;
9001 bp_location_count
= 0;
9002 cleanups
= make_cleanup (xfree
, old_location
);
9005 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9006 bp_location_count
++;
9008 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9011 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9013 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9014 bp_location_compare
);
9016 bp_location_target_extensions_update ();
9018 /* Identify bp_location instances that are no longer present in the new
9019 list, and therefore should be freed. Note that it's not necessary that
9020 those locations should be removed from inferior -- if there's another
9021 location at the same address (previously marked as duplicate),
9022 we don't need to remove/insert the location.
9024 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
9025 former bp_location array state respectively. */
9028 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9031 struct bp_location
*old_loc
= *old_locp
;
9032 struct bp_location
**loc2p
;
9034 /* Tells if 'old_loc' is found amoung the new locations. If not, we
9036 int found_object
= 0;
9037 /* Tells if the location should remain inserted in the target. */
9038 int keep_in_target
= 0;
9041 /* Skip LOCP entries which will definitely never be needed. Stop either
9042 at or being the one matching OLD_LOC. */
9043 while (locp
< bp_location
+ bp_location_count
9044 && (*locp
)->address
< old_loc
->address
)
9048 (loc2p
< bp_location
+ bp_location_count
9049 && (*loc2p
)->address
== old_loc
->address
);
9052 if (*loc2p
== old_loc
)
9059 /* If this location is no longer present, and inserted, look if there's
9060 maybe a new location at the same address. If so, mark that one
9061 inserted, and don't remove this one. This is needed so that we
9062 don't have a time window where a breakpoint at certain location is not
9065 if (old_loc
->inserted
)
9067 /* If the location is inserted now, we might have to remove it. */
9069 if (found_object
&& should_be_inserted (old_loc
))
9071 /* The location is still present in the location list, and still
9072 should be inserted. Don't do anything. */
9077 /* The location is either no longer present, or got disabled.
9078 See if there's another location at the same address, in which
9079 case we don't need to remove this one from the target. */
9081 /* OLD_LOC comes from existing struct breakpoint. */
9082 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9085 (loc2p
< bp_location
+ bp_location_count
9086 && (*loc2p
)->address
== old_loc
->address
);
9089 struct bp_location
*loc2
= *loc2p
;
9091 if (breakpoint_locations_match (loc2
, old_loc
))
9093 /* For the sake of should_be_inserted.
9094 Duplicates check below will fix up this later. */
9095 loc2
->duplicate
= 0;
9097 /* Read watchpoint locations are switched to
9098 access watchpoints, if the former are not
9099 supported, but the latter are. */
9100 if (is_hardware_watchpoint (old_loc
->owner
))
9102 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9103 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9106 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9109 loc2
->target_info
= old_loc
->target_info
;
9118 if (!keep_in_target
)
9120 if (remove_breakpoint (old_loc
, mark_uninserted
))
9122 /* This is just about all we can do. We could keep this
9123 location on the global list, and try to remove it next
9124 time, but there's no particular reason why we will
9127 Note that at this point, old_loc->owner is still valid,
9128 as delete_breakpoint frees the breakpoint only
9129 after calling us. */
9130 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9131 old_loc
->owner
->number
);
9139 if (removed
&& non_stop
9140 && breakpoint_address_is_meaningful (old_loc
->owner
)
9141 && !is_hardware_watchpoint (old_loc
->owner
))
9143 /* This location was removed from the target. In
9144 non-stop mode, a race condition is possible where
9145 we've removed a breakpoint, but stop events for that
9146 breakpoint are already queued and will arrive later.
9147 We apply an heuristic to be able to distinguish such
9148 SIGTRAPs from other random SIGTRAPs: we keep this
9149 breakpoint location for a bit, and will retire it
9150 after we see some number of events. The theory here
9151 is that reporting of events should, "on the average",
9152 be fair, so after a while we'll see events from all
9153 threads that have anything of interest, and no longer
9154 need to keep this breakpoint location around. We
9155 don't hold locations forever so to reduce chances of
9156 mistaking a non-breakpoint SIGTRAP for a breakpoint
9159 The heuristic failing can be disastrous on
9160 decr_pc_after_break targets.
9162 On decr_pc_after_break targets, like e.g., x86-linux,
9163 if we fail to recognize a late breakpoint SIGTRAP,
9164 because events_till_retirement has reached 0 too
9165 soon, we'll fail to do the PC adjustment, and report
9166 a random SIGTRAP to the user. When the user resumes
9167 the inferior, it will most likely immediately crash
9168 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9169 corrupted, because of being resumed e.g., in the
9170 middle of a multi-byte instruction, or skipped a
9171 one-byte instruction. This was actually seen happen
9172 on native x86-linux, and should be less rare on
9173 targets that do not support new thread events, like
9174 remote, due to the heuristic depending on
9177 Mistaking a random SIGTRAP for a breakpoint trap
9178 causes similar symptoms (PC adjustment applied when
9179 it shouldn't), but then again, playing with SIGTRAPs
9180 behind the debugger's back is asking for trouble.
9182 Since hardware watchpoint traps are always
9183 distinguishable from other traps, so we don't need to
9184 apply keep hardware watchpoint moribund locations
9185 around. We simply always ignore hardware watchpoint
9186 traps we can no longer explain. */
9188 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9189 old_loc
->owner
= NULL
;
9191 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9194 free_bp_location (old_loc
);
9198 /* Rescan breakpoints at the same address and section, marking the
9199 first one as "first" and any others as "duplicates". This is so
9200 that the bpt instruction is only inserted once. If we have a
9201 permanent breakpoint at the same place as BPT, make that one the
9202 official one, and the rest as duplicates. Permanent breakpoints
9203 are sorted first for the same address.
9205 Do the same for hardware watchpoints, but also considering the
9206 watchpoint's type (regular/access/read) and length. */
9208 bp_loc_first
= NULL
;
9209 wp_loc_first
= NULL
;
9210 awp_loc_first
= NULL
;
9211 rwp_loc_first
= NULL
;
9212 ALL_BP_LOCATIONS (loc
, locp
)
9214 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
9215 struct breakpoint
*b
= loc
->owner
;
9216 struct bp_location
**loc_first_p
;
9218 if (b
->enable_state
== bp_disabled
9219 || b
->enable_state
== bp_call_disabled
9220 || b
->enable_state
== bp_startup_disabled
9222 || loc
->shlib_disabled
9223 || !breakpoint_address_is_meaningful (b
)
9224 || is_tracepoint (b
))
9227 /* Permanent breakpoint should always be inserted. */
9228 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9229 internal_error (__FILE__
, __LINE__
,
9230 _("allegedly permanent breakpoint is not "
9231 "actually inserted"));
9233 if (b
->type
== bp_hardware_watchpoint
)
9234 loc_first_p
= &wp_loc_first
;
9235 else if (b
->type
== bp_read_watchpoint
)
9236 loc_first_p
= &rwp_loc_first
;
9237 else if (b
->type
== bp_access_watchpoint
)
9238 loc_first_p
= &awp_loc_first
;
9240 loc_first_p
= &bp_loc_first
;
9242 if (*loc_first_p
== NULL
9243 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9244 || !breakpoint_locations_match (loc
, *loc_first_p
))
9253 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9254 && b
->enable_state
!= bp_permanent
)
9255 internal_error (__FILE__
, __LINE__
,
9256 _("another breakpoint was inserted on top of "
9257 "a permanent breakpoint"));
9260 if (breakpoints_always_inserted_mode () && should_insert
9261 && (have_live_inferiors ()
9262 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9263 insert_breakpoint_locations ();
9265 do_cleanups (cleanups
);
9269 breakpoint_retire_moribund (void)
9271 struct bp_location
*loc
;
9274 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9275 if (--(loc
->events_till_retirement
) == 0)
9277 free_bp_location (loc
);
9278 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9284 update_global_location_list_nothrow (int inserting
)
9286 struct gdb_exception e
;
9288 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9289 update_global_location_list (inserting
);
9292 /* Clear LOC from a BPS. */
9294 bpstat_remove_bp_location (bpstat bps
, struct bp_location
*loc
)
9298 for (bs
= bps
; bs
; bs
= bs
->next
)
9299 if (bs
->breakpoint_at
== loc
)
9301 bs
->breakpoint_at
= NULL
;
9303 /* bs->commands will be freed later. */
9307 /* Callback for iterate_over_threads. */
9309 bpstat_remove_bp_location_callback (struct thread_info
*th
, void *data
)
9311 struct bp_location
*loc
= data
;
9313 bpstat_remove_bp_location (th
->stop_bpstat
, loc
);
9317 /* Delete a breakpoint and clean up all traces of it in the data
9321 delete_breakpoint (struct breakpoint
*bpt
)
9323 struct breakpoint
*b
;
9325 gdb_assert (bpt
!= NULL
);
9327 /* Has this bp already been deleted? This can happen because multiple
9328 lists can hold pointers to bp's. bpstat lists are especial culprits.
9330 One example of this happening is a watchpoint's scope bp. When the
9331 scope bp triggers, we notice that the watchpoint is out of scope, and
9332 delete it. We also delete its scope bp. But the scope bp is marked
9333 "auto-deleting", and is already on a bpstat. That bpstat is then
9334 checked for auto-deleting bp's, which are deleted.
9336 A real solution to this problem might involve reference counts in bp's,
9337 and/or giving them pointers back to their referencing bpstat's, and
9338 teaching delete_breakpoint to only free a bp's storage when no more
9339 references were extent. A cheaper bandaid was chosen. */
9340 if (bpt
->type
== bp_none
)
9343 /* At least avoid this stale reference until the reference counting of
9344 breakpoints gets resolved. */
9345 if (bpt
->related_breakpoint
!= NULL
)
9347 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9348 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9349 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9350 bpt
->related_breakpoint
= NULL
;
9353 observer_notify_breakpoint_deleted (bpt
->number
);
9355 if (breakpoint_chain
== bpt
)
9356 breakpoint_chain
= bpt
->next
;
9361 b
->next
= bpt
->next
;
9365 decref_counted_command_line (&bpt
->commands
);
9366 xfree (bpt
->cond_string
);
9367 xfree (bpt
->cond_exp
);
9368 xfree (bpt
->addr_string
);
9370 xfree (bpt
->exp_string
);
9371 value_free (bpt
->val
);
9372 xfree (bpt
->source_file
);
9373 xfree (bpt
->exec_pathname
);
9374 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9376 /* Now that breakpoint is removed from breakpoint
9377 list, update the global location list. This
9378 will remove locations that used to belong to
9379 this breakpoint. Do this before freeing
9380 the breakpoint itself, since remove_breakpoint
9381 looks at location's owner. It might be better
9382 design to have location completely self-contained,
9383 but it's not the case now. */
9384 update_global_location_list (0);
9387 /* On the chance that someone will soon try again to delete this same
9388 bp, we mark it as deleted before freeing its storage. */
9389 bpt
->type
= bp_none
;
9395 do_delete_breakpoint_cleanup (void *b
)
9397 delete_breakpoint (b
);
9401 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9403 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9406 /* A callback for map_breakpoint_numbers that calls
9407 delete_breakpoint. */
9410 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9412 delete_breakpoint (b
);
9416 delete_command (char *arg
, int from_tty
)
9418 struct breakpoint
*b
, *temp
;
9424 int breaks_to_delete
= 0;
9426 /* Delete all breakpoints if no argument.
9427 Do not delete internal or call-dummy breakpoints, these
9428 have to be deleted with an explicit breakpoint number argument. */
9431 if (b
->type
!= bp_call_dummy
9432 && b
->type
!= bp_std_terminate
9433 && b
->type
!= bp_shlib_event
9434 && b
->type
!= bp_jit_event
9435 && b
->type
!= bp_thread_event
9436 && b
->type
!= bp_overlay_event
9437 && b
->type
!= bp_longjmp_master
9438 && b
->type
!= bp_std_terminate_master
9441 breaks_to_delete
= 1;
9446 /* Ask user only if there are some breakpoints to delete. */
9448 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9450 ALL_BREAKPOINTS_SAFE (b
, temp
)
9452 if (b
->type
!= bp_call_dummy
9453 && b
->type
!= bp_std_terminate
9454 && b
->type
!= bp_shlib_event
9455 && b
->type
!= bp_thread_event
9456 && b
->type
!= bp_jit_event
9457 && b
->type
!= bp_overlay_event
9458 && b
->type
!= bp_longjmp_master
9459 && b
->type
!= bp_std_terminate_master
9461 delete_breakpoint (b
);
9466 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9470 all_locations_are_pending (struct bp_location
*loc
)
9472 for (; loc
; loc
= loc
->next
)
9473 if (!loc
->shlib_disabled
)
9478 /* Subroutine of update_breakpoint_locations to simplify it.
9479 Return non-zero if multiple fns in list LOC have the same name.
9480 Null names are ignored. */
9483 ambiguous_names_p (struct bp_location
*loc
)
9485 struct bp_location
*l
;
9486 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9487 (int (*) (const void *,
9488 const void *)) streq
,
9489 NULL
, xcalloc
, xfree
);
9491 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9494 const char *name
= l
->function_name
;
9496 /* Allow for some names to be NULL, ignore them. */
9500 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9502 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9517 update_breakpoint_locations (struct breakpoint
*b
,
9518 struct symtabs_and_lines sals
)
9522 struct bp_location
*existing_locations
= b
->loc
;
9524 /* If there's no new locations, and all existing locations
9525 are pending, don't do anything. This optimizes
9526 the common case where all locations are in the same
9527 shared library, that was unloaded. We'd like to
9528 retain the location, so that when the library
9529 is loaded again, we don't loose the enabled/disabled
9530 status of the individual locations. */
9531 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9536 for (i
= 0; i
< sals
.nelts
; ++i
)
9538 struct bp_location
*new_loc
=
9539 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9541 /* Reparse conditions, they might contain references to the
9543 if (b
->cond_string
!= NULL
)
9545 struct gdb_exception e
;
9548 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9550 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9555 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9556 b
->number
, e
.message
);
9557 new_loc
->enabled
= 0;
9561 if (b
->source_file
!= NULL
)
9562 xfree (b
->source_file
);
9563 if (sals
.sals
[i
].symtab
== NULL
)
9564 b
->source_file
= NULL
;
9566 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9568 if (b
->line_number
== 0)
9569 b
->line_number
= sals
.sals
[i
].line
;
9572 /* Update locations of permanent breakpoints. */
9573 if (b
->enable_state
== bp_permanent
)
9574 make_breakpoint_permanent (b
);
9576 /* If possible, carry over 'disable' status from existing breakpoints. */
9578 struct bp_location
*e
= existing_locations
;
9579 /* If there are multiple breakpoints with the same function name,
9580 e.g. for inline functions, comparing function names won't work.
9581 Instead compare pc addresses; this is just a heuristic as things
9582 may have moved, but in practice it gives the correct answer
9583 often enough until a better solution is found. */
9584 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9586 for (; e
; e
= e
->next
)
9588 if (!e
->enabled
&& e
->function_name
)
9590 struct bp_location
*l
= b
->loc
;
9591 if (have_ambiguous_names
)
9593 for (; l
; l
= l
->next
)
9594 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9595 l
->pspace
->aspace
, l
->address
))
9603 for (; l
; l
= l
->next
)
9604 if (l
->function_name
9605 && strcmp (e
->function_name
, l
->function_name
) == 0)
9615 update_global_location_list (1);
9619 /* Reset a breakpoint given it's struct breakpoint * BINT.
9620 The value we return ends up being the return value from catch_errors.
9621 Unused in this case. */
9624 breakpoint_re_set_one (void *bint
)
9626 /* get past catch_errs */
9627 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9629 int *not_found_ptr
= ¬_found
;
9630 struct symtabs_and_lines sals
= {0};
9631 struct symtabs_and_lines expanded
= {0};
9633 struct gdb_exception e
;
9634 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9639 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9643 case bp_hardware_breakpoint
:
9645 case bp_fast_tracepoint
:
9646 /* Do not attempt to re-set breakpoints disabled during startup. */
9647 if (b
->enable_state
== bp_startup_disabled
)
9650 if (b
->addr_string
== NULL
)
9652 /* Anything without a string can't be re-set. */
9653 delete_breakpoint (b
);
9657 set_language (b
->language
);
9658 input_radix
= b
->input_radix
;
9661 save_current_space_and_thread ();
9662 switch_to_program_space_and_thread (b
->pspace
);
9664 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9666 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9671 int not_found_and_ok
= 0;
9672 /* For pending breakpoints, it's expected that parsing
9673 will fail until the right shared library is loaded.
9674 User has already told to create pending breakpoints and
9675 don't need extra messages. If breakpoint is in bp_shlib_disabled
9676 state, then user already saw the message about that breakpoint
9677 being disabled, and don't want to see more errors. */
9679 && (b
->condition_not_parsed
9680 || (b
->loc
&& b
->loc
->shlib_disabled
)
9681 || b
->enable_state
== bp_disabled
))
9682 not_found_and_ok
= 1;
9684 if (!not_found_and_ok
)
9686 /* We surely don't want to warn about the same breakpoint
9687 10 times. One solution, implemented here, is disable
9688 the breakpoint on error. Another solution would be to
9689 have separate 'warning emitted' flag. Since this
9690 happens only when a binary has changed, I don't know
9691 which approach is better. */
9692 b
->enable_state
= bp_disabled
;
9693 throw_exception (e
);
9699 gdb_assert (sals
.nelts
== 1);
9701 resolve_sal_pc (&sals
.sals
[0]);
9702 if (b
->condition_not_parsed
&& s
&& s
[0])
9704 char *cond_string
= 0;
9708 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9709 &cond_string
, &thread
, &task
);
9711 b
->cond_string
= cond_string
;
9714 b
->condition_not_parsed
= 0;
9717 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9720 make_cleanup (xfree
, sals
.sals
);
9721 update_breakpoint_locations (b
, expanded
);
9725 case bp_hardware_watchpoint
:
9726 case bp_read_watchpoint
:
9727 case bp_access_watchpoint
:
9728 /* Watchpoint can be either on expression using entirely global variables,
9729 or it can be on local variables.
9731 Watchpoints of the first kind are never auto-deleted, and even persist
9732 across program restarts. Since they can use variables from shared
9733 libraries, we need to reparse expression as libraries are loaded
9736 Watchpoints on local variables can also change meaning as result
9737 of solib event. For example, if a watchpoint uses both a local and
9738 a global variables in expression, it's a local watchpoint, but
9739 unloading of a shared library will make the expression invalid.
9740 This is not a very common use case, but we still re-evaluate
9741 expression, to avoid surprises to the user.
9743 Note that for local watchpoints, we re-evaluate it only if
9744 watchpoints frame id is still valid. If it's not, it means
9745 the watchpoint is out of scope and will be deleted soon. In fact,
9746 I'm not sure we'll ever be called in this case.
9748 If a local watchpoint's frame id is still valid, then
9749 b->exp_valid_block is likewise valid, and we can safely use it.
9751 Don't do anything about disabled watchpoints, since they will
9752 be reevaluated again when enabled. */
9753 update_watchpoint (b
, 1 /* reparse */);
9755 /* We needn't really do anything to reset these, since the mask
9756 that requests them is unaffected by e.g., new libraries being
9762 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9764 /* Delete overlay event and longjmp master breakpoints; they will be
9765 reset later by breakpoint_re_set. */
9766 case bp_overlay_event
:
9767 case bp_longjmp_master
:
9768 case bp_std_terminate_master
:
9769 delete_breakpoint (b
);
9772 /* This breakpoint is special, it's set up when the inferior
9773 starts and we really don't want to touch it. */
9774 case bp_shlib_event
:
9776 /* Like bp_shlib_event, this breakpoint type is special.
9777 Once it is set up, we do not want to touch it. */
9778 case bp_thread_event
:
9780 /* Keep temporary breakpoints, which can be encountered when we step
9781 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9782 Otherwise these should have been blown away via the cleanup chain
9783 or by breakpoint_init_inferior when we rerun the executable. */
9786 case bp_watchpoint_scope
:
9788 case bp_std_terminate
:
9789 case bp_step_resume
:
9791 case bp_longjmp_resume
:
9796 do_cleanups (cleanups
);
9800 /* Re-set all breakpoints after symbols have been re-loaded. */
9802 breakpoint_re_set (void)
9804 struct breakpoint
*b
, *temp
;
9805 enum language save_language
;
9806 int save_input_radix
;
9807 struct cleanup
*old_chain
;
9809 save_language
= current_language
->la_language
;
9810 save_input_radix
= input_radix
;
9811 old_chain
= save_current_program_space ();
9813 ALL_BREAKPOINTS_SAFE (b
, temp
)
9815 /* Format possible error msg */
9816 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9818 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9819 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9820 do_cleanups (cleanups
);
9822 set_language (save_language
);
9823 input_radix
= save_input_radix
;
9825 jit_breakpoint_re_set ();
9827 do_cleanups (old_chain
);
9829 create_overlay_event_breakpoint ("_ovly_debug_event");
9830 create_longjmp_master_breakpoint ("longjmp");
9831 create_longjmp_master_breakpoint ("_longjmp");
9832 create_longjmp_master_breakpoint ("siglongjmp");
9833 create_longjmp_master_breakpoint ("_siglongjmp");
9834 create_std_terminate_master_breakpoint ("std::terminate()");
9837 /* Reset the thread number of this breakpoint:
9839 - If the breakpoint is for all threads, leave it as-is.
9840 - Else, reset it to the current thread for inferior_ptid. */
9842 breakpoint_re_set_thread (struct breakpoint
*b
)
9844 if (b
->thread
!= -1)
9846 if (in_thread_list (inferior_ptid
))
9847 b
->thread
= pid_to_thread_id (inferior_ptid
);
9849 /* We're being called after following a fork. The new fork is
9850 selected as current, and unless this was a vfork will have a
9851 different program space from the original thread. Reset that
9853 b
->loc
->pspace
= current_program_space
;
9857 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9858 If from_tty is nonzero, it prints a message to that effect,
9859 which ends with a period (no newline). */
9862 set_ignore_count (int bptnum
, int count
, int from_tty
)
9864 struct breakpoint
*b
;
9870 if (b
->number
== bptnum
)
9872 if (is_tracepoint (b
))
9874 if (from_tty
&& count
!= 0)
9875 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9880 b
->ignore_count
= count
;
9884 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9886 else if (count
== 1)
9887 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9890 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9893 breakpoints_changed ();
9894 observer_notify_breakpoint_modified (b
->number
);
9898 error (_("No breakpoint number %d."), bptnum
);
9902 make_breakpoint_silent (struct breakpoint
*b
)
9904 /* Silence the breakpoint. */
9908 /* Command to set ignore-count of breakpoint N to COUNT. */
9911 ignore_command (char *args
, int from_tty
)
9917 error_no_arg (_("a breakpoint number"));
9919 num
= get_number (&p
);
9921 error (_("bad breakpoint number: '%s'"), args
);
9923 error (_("Second argument (specified ignore-count) is missing."));
9925 set_ignore_count (num
,
9926 longest_to_int (value_as_long (parse_and_eval (p
))),
9929 printf_filtered ("\n");
9932 /* Call FUNCTION on each of the breakpoints
9933 whose numbers are given in ARGS. */
9936 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9943 struct breakpoint
*b
, *tmp
;
9947 error_no_arg (_("one or more breakpoint numbers"));
9954 num
= get_number_or_range (&p1
);
9957 warning (_("bad breakpoint number at or near '%s'"), p
);
9961 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9962 if (b
->number
== num
)
9964 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9967 if (related_breakpoint
)
9968 function (related_breakpoint
, data
);
9972 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9978 static struct bp_location
*
9979 find_location_by_number (char *number
)
9981 char *dot
= strchr (number
, '.');
9985 struct breakpoint
*b
;
9986 struct bp_location
*loc
;
9991 bp_num
= get_number_or_range (&p1
);
9993 error (_("Bad breakpoint number '%s'"), number
);
9996 if (b
->number
== bp_num
)
10001 if (!b
|| b
->number
!= bp_num
)
10002 error (_("Bad breakpoint number '%s'"), number
);
10005 loc_num
= get_number_or_range (&p1
);
10007 error (_("Bad breakpoint location number '%s'"), number
);
10011 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10014 error (_("Bad breakpoint location number '%s'"), dot
+1);
10020 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10021 If from_tty is nonzero, it prints a message to that effect,
10022 which ends with a period (no newline). */
10025 disable_breakpoint (struct breakpoint
*bpt
)
10027 /* Never disable a watchpoint scope breakpoint; we want to
10028 hit them when we leave scope so we can delete both the
10029 watchpoint and its scope breakpoint at that time. */
10030 if (bpt
->type
== bp_watchpoint_scope
)
10033 /* You can't disable permanent breakpoints. */
10034 if (bpt
->enable_state
== bp_permanent
)
10037 bpt
->enable_state
= bp_disabled
;
10039 update_global_location_list (0);
10041 observer_notify_breakpoint_modified (bpt
->number
);
10044 /* A callback for map_breakpoint_numbers that calls
10045 disable_breakpoint. */
10048 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10050 disable_breakpoint (b
);
10054 disable_command (char *args
, int from_tty
)
10056 struct breakpoint
*bpt
;
10059 ALL_BREAKPOINTS (bpt
)
10063 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10066 case bp_breakpoint
:
10067 case bp_tracepoint
:
10068 case bp_fast_tracepoint
:
10069 case bp_catchpoint
:
10070 case bp_hardware_breakpoint
:
10071 case bp_watchpoint
:
10072 case bp_hardware_watchpoint
:
10073 case bp_read_watchpoint
:
10074 case bp_access_watchpoint
:
10075 disable_breakpoint (bpt
);
10079 else if (strchr (args
, '.'))
10081 struct bp_location
*loc
= find_location_by_number (args
);
10084 update_global_location_list (0);
10087 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10091 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10093 int target_resources_ok
;
10095 if (bpt
->type
== bp_hardware_breakpoint
)
10098 i
= hw_breakpoint_used_count ();
10099 target_resources_ok
=
10100 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10102 if (target_resources_ok
== 0)
10103 error (_("No hardware breakpoint support in the target."));
10104 else if (target_resources_ok
< 0)
10105 error (_("Hardware breakpoints used exceeds limit."));
10108 if (is_watchpoint (bpt
))
10110 struct gdb_exception e
;
10112 TRY_CATCH (e
, RETURN_MASK_ALL
)
10114 update_watchpoint (bpt
, 1 /* reparse */);
10118 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10124 if (bpt
->enable_state
!= bp_permanent
)
10125 bpt
->enable_state
= bp_enabled
;
10126 bpt
->disposition
= disposition
;
10127 update_global_location_list (1);
10128 breakpoints_changed ();
10130 observer_notify_breakpoint_modified (bpt
->number
);
10135 enable_breakpoint (struct breakpoint
*bpt
)
10137 do_enable_breakpoint (bpt
, bpt
->disposition
);
10140 /* A callback for map_breakpoint_numbers that calls
10141 enable_breakpoint. */
10144 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10146 enable_breakpoint (b
);
10149 /* The enable command enables the specified breakpoints (or all defined
10150 breakpoints) so they once again become (or continue to be) effective
10151 in stopping the inferior. */
10154 enable_command (char *args
, int from_tty
)
10156 struct breakpoint
*bpt
;
10159 ALL_BREAKPOINTS (bpt
)
10163 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10166 case bp_breakpoint
:
10167 case bp_tracepoint
:
10168 case bp_fast_tracepoint
:
10169 case bp_catchpoint
:
10170 case bp_hardware_breakpoint
:
10171 case bp_watchpoint
:
10172 case bp_hardware_watchpoint
:
10173 case bp_read_watchpoint
:
10174 case bp_access_watchpoint
:
10175 enable_breakpoint (bpt
);
10179 else if (strchr (args
, '.'))
10181 struct bp_location
*loc
= find_location_by_number (args
);
10184 update_global_location_list (1);
10187 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10191 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10193 do_enable_breakpoint (bpt
, disp_disable
);
10197 enable_once_command (char *args
, int from_tty
)
10199 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10203 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10205 do_enable_breakpoint (bpt
, disp_del
);
10209 enable_delete_command (char *args
, int from_tty
)
10211 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10215 set_breakpoint_cmd (char *args
, int from_tty
)
10220 show_breakpoint_cmd (char *args
, int from_tty
)
10224 /* Invalidate last known value of any hardware watchpoint if
10225 the memory which that value represents has been written to by
10229 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10230 const bfd_byte
*data
)
10232 struct breakpoint
*bp
;
10234 ALL_BREAKPOINTS (bp
)
10235 if (bp
->enable_state
== bp_enabled
10236 && bp
->type
== bp_hardware_watchpoint
10237 && bp
->val_valid
&& bp
->val
)
10239 struct bp_location
*loc
;
10241 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10242 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10243 && loc
->address
+ loc
->length
> addr
10244 && addr
+ len
> loc
->address
)
10246 value_free (bp
->val
);
10253 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10255 struct symtabs_and_lines
10256 decode_line_spec_1 (char *string
, int funfirstline
)
10258 struct symtabs_and_lines sals
;
10261 error (_("Empty line specification."));
10262 if (default_breakpoint_valid
)
10263 sals
= decode_line_1 (&string
, funfirstline
,
10264 default_breakpoint_symtab
,
10265 default_breakpoint_line
,
10266 (char ***) NULL
, NULL
);
10268 sals
= decode_line_1 (&string
, funfirstline
,
10269 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10271 error (_("Junk at end of line specification: %s"), string
);
10275 /* Create and insert a raw software breakpoint at PC. Return an
10276 identifier, which should be used to remove the breakpoint later.
10277 In general, places which call this should be using something on the
10278 breakpoint chain instead; this function should be eliminated
10282 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10283 struct address_space
*aspace
, CORE_ADDR pc
)
10285 struct bp_target_info
*bp_tgt
;
10287 bp_tgt
= XZALLOC (struct bp_target_info
);
10289 bp_tgt
->placed_address_space
= aspace
;
10290 bp_tgt
->placed_address
= pc
;
10292 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10294 /* Could not insert the breakpoint. */
10302 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10305 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10307 struct bp_target_info
*bp_tgt
= bp
;
10310 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10316 /* One (or perhaps two) breakpoints used for software single stepping. */
10318 static void *single_step_breakpoints
[2];
10319 static struct gdbarch
*single_step_gdbarch
[2];
10321 /* Create and insert a breakpoint for software single step. */
10324 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10325 struct address_space
*aspace
, CORE_ADDR next_pc
)
10329 if (single_step_breakpoints
[0] == NULL
)
10331 bpt_p
= &single_step_breakpoints
[0];
10332 single_step_gdbarch
[0] = gdbarch
;
10336 gdb_assert (single_step_breakpoints
[1] == NULL
);
10337 bpt_p
= &single_step_breakpoints
[1];
10338 single_step_gdbarch
[1] = gdbarch
;
10341 /* NOTE drow/2006-04-11: A future improvement to this function would be
10342 to only create the breakpoints once, and actually put them on the
10343 breakpoint chain. That would let us use set_raw_breakpoint. We could
10344 adjust the addresses each time they were needed. Doing this requires
10345 corresponding changes elsewhere where single step breakpoints are
10346 handled, however. So, for now, we use this. */
10348 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10349 if (*bpt_p
== NULL
)
10350 error (_("Could not insert single-step breakpoint at %s"),
10351 paddress (gdbarch
, next_pc
));
10354 /* Remove and delete any breakpoints used for software single step. */
10357 remove_single_step_breakpoints (void)
10359 gdb_assert (single_step_breakpoints
[0] != NULL
);
10361 /* See insert_single_step_breakpoint for more about this deprecated
10363 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10364 single_step_breakpoints
[0]);
10365 single_step_gdbarch
[0] = NULL
;
10366 single_step_breakpoints
[0] = NULL
;
10368 if (single_step_breakpoints
[1] != NULL
)
10370 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10371 single_step_breakpoints
[1]);
10372 single_step_gdbarch
[1] = NULL
;
10373 single_step_breakpoints
[1] = NULL
;
10377 /* Check whether a software single-step breakpoint is inserted at PC. */
10380 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
10385 for (i
= 0; i
< 2; i
++)
10387 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10389 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10390 bp_tgt
->placed_address
,
10398 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10399 non-zero otherwise. */
10401 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10403 if (syscall_catchpoint_p (bp
)
10404 && bp
->enable_state
!= bp_disabled
10405 && bp
->enable_state
!= bp_call_disabled
)
10412 catch_syscall_enabled (void)
10414 struct inferior
*inf
= current_inferior ();
10416 return inf
->total_syscalls_count
!= 0;
10420 catching_syscall_number (int syscall_number
)
10422 struct breakpoint
*bp
;
10424 ALL_BREAKPOINTS (bp
)
10425 if (is_syscall_catchpoint_enabled (bp
))
10427 if (bp
->syscalls_to_be_caught
)
10431 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10433 if (syscall_number
== iter
)
10443 /* Complete syscall names. Used by "catch syscall". */
10445 catch_syscall_completer (struct cmd_list_element
*cmd
,
10446 char *text
, char *word
)
10448 const char **list
= get_syscall_names ();
10450 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10453 /* Tracepoint-specific operations. */
10455 /* Set tracepoint count to NUM. */
10457 set_tracepoint_count (int num
)
10459 tracepoint_count
= num
;
10460 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10464 trace_command (char *arg
, int from_tty
)
10466 if (create_breakpoint (get_current_arch (),
10468 NULL
, 0, 1 /* parse arg */,
10469 0 /* tempflag */, 0 /* hardwareflag */,
10471 0 /* Ignore count */,
10472 pending_break_support
,
10476 set_tracepoint_count (breakpoint_count
);
10480 ftrace_command (char *arg
, int from_tty
)
10482 if (create_breakpoint (get_current_arch (),
10484 NULL
, 0, 1 /* parse arg */,
10485 0 /* tempflag */, 1 /* hardwareflag */,
10487 0 /* Ignore count */,
10488 pending_break_support
,
10492 set_tracepoint_count (breakpoint_count
);
10495 /* Set up a fake reader function that gets command lines from a linked
10496 list that was acquired during tracepoint uploading. */
10498 static struct uploaded_tp
*this_utp
;
10499 static int next_cmd
;
10502 read_uploaded_action (void)
10506 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
10513 /* Given information about a tracepoint as recorded on a target (which
10514 can be either a live system or a trace file), attempt to create an
10515 equivalent GDB tracepoint. This is not a reliable process, since
10516 the target does not necessarily have all the information used when
10517 the tracepoint was originally defined. */
10519 struct breakpoint
*
10520 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10522 char *addr_str
, small_buf
[100];
10523 struct breakpoint
*tp
;
10525 if (utp
->at_string
)
10526 addr_str
= utp
->at_string
;
10529 /* In the absence of a source location, fall back to raw
10530 address. Since there is no way to confirm that the address
10531 means the same thing as when the trace was started, warn the
10533 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10535 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10536 addr_str
= small_buf
;
10539 /* There's not much we can do with a sequence of bytecodes. */
10540 if (utp
->cond
&& !utp
->cond_string
)
10541 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10544 if (!create_breakpoint (get_current_arch (),
10546 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10548 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10550 0 /* Ignore count */,
10551 pending_break_support
,
10554 utp
->enabled
/* enabled */))
10557 set_tracepoint_count (breakpoint_count
);
10559 /* Get the tracepoint we just created. */
10560 tp
= get_tracepoint (tracepoint_count
);
10561 gdb_assert (tp
!= NULL
);
10565 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10567 trace_pass_command (small_buf
, 0);
10570 /* If we have uploaded versions of the original commands, set up a
10571 special-purpose "reader" function and call the usual command line
10572 reader, then pass the result to the breakpoint command-setting
10574 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
10576 struct command_line
*cmd_list
;
10581 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10583 breakpoint_set_commands (tp
, cmd_list
);
10585 else if (!VEC_empty (char_ptr
, utp
->actions
)
10586 || !VEC_empty (char_ptr
, utp
->step_actions
))
10587 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10593 /* Print information on tracepoint number TPNUM_EXP, or all if
10597 tracepoints_info (char *tpnum_exp
, int from_tty
)
10599 int tpnum
= -1, num_printed
;
10602 tpnum
= parse_and_eval_long (tpnum_exp
);
10604 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
10606 if (num_printed
== 0)
10609 ui_out_message (uiout
, 0, "No tracepoints.\n");
10611 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
10614 default_collect_info ();
10617 /* The 'enable trace' command enables tracepoints.
10618 Not supported by all targets. */
10620 enable_trace_command (char *args
, int from_tty
)
10622 enable_command (args
, from_tty
);
10625 /* The 'disable trace' command disables tracepoints.
10626 Not supported by all targets. */
10628 disable_trace_command (char *args
, int from_tty
)
10630 disable_command (args
, from_tty
);
10633 /* Remove a tracepoint (or all if no argument) */
10635 delete_trace_command (char *arg
, int from_tty
)
10637 struct breakpoint
*b
, *temp
;
10643 int breaks_to_delete
= 0;
10645 /* Delete all breakpoints if no argument.
10646 Do not delete internal or call-dummy breakpoints, these
10647 have to be deleted with an explicit breakpoint number argument. */
10648 ALL_TRACEPOINTS (b
)
10650 if (b
->number
>= 0)
10652 breaks_to_delete
= 1;
10657 /* Ask user only if there are some breakpoints to delete. */
10659 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10661 ALL_BREAKPOINTS_SAFE (b
, temp
)
10663 if (is_tracepoint (b
)
10665 delete_breakpoint (b
);
10670 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10673 /* Set passcount for tracepoint.
10675 First command argument is passcount, second is tracepoint number.
10676 If tracepoint number omitted, apply to most recently defined.
10677 Also accepts special argument "all". */
10680 trace_pass_command (char *args
, int from_tty
)
10682 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10683 unsigned int count
;
10686 if (args
== 0 || *args
== 0)
10687 error (_("passcount command requires an argument (count + optional TP num)"));
10689 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10691 while (*args
&& isspace ((int) *args
))
10694 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10696 args
+= 3; /* Skip special argument "all". */
10699 error (_("Junk at end of arguments."));
10702 t1
= get_tracepoint_by_number (&args
, 1, 1);
10708 ALL_TRACEPOINTS (t2
)
10709 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10711 t2
->pass_count
= count
;
10712 observer_notify_tracepoint_modified (t2
->number
);
10714 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10715 t2
->number
, count
);
10717 if (! all
&& *args
)
10718 t1
= get_tracepoint_by_number (&args
, 1, 0);
10724 struct breakpoint
*
10725 get_tracepoint (int num
)
10727 struct breakpoint
*t
;
10729 ALL_TRACEPOINTS (t
)
10730 if (t
->number
== num
)
10736 /* Find the tracepoint with the given target-side number (which may be
10737 different from the tracepoint number after disconnecting and
10740 struct breakpoint
*
10741 get_tracepoint_by_number_on_target (int num
)
10743 struct breakpoint
*t
;
10745 ALL_TRACEPOINTS (t
)
10746 if (t
->number_on_target
== num
)
10752 /* Utility: parse a tracepoint number and look it up in the list.
10753 If MULTI_P is true, there might be a range of tracepoints in ARG.
10754 if OPTIONAL_P is true, then if the argument is missing, the most
10755 recent tracepoint (tracepoint_count) is returned. */
10756 struct breakpoint
*
10757 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10759 extern int tracepoint_count
;
10760 struct breakpoint
*t
;
10762 char *instring
= arg
== NULL
? NULL
: *arg
;
10764 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10767 tpnum
= tracepoint_count
;
10769 error_no_arg (_("tracepoint number"));
10772 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10776 if (instring
&& *instring
)
10777 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10780 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10784 ALL_TRACEPOINTS (t
)
10785 if (t
->number
== tpnum
)
10790 /* FIXME: if we are in the middle of a range we don't want to give
10791 a message. The current interface to get_number_or_range doesn't
10792 allow us to discover this. */
10793 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10797 /* Save information on user settable breakpoints (watchpoints, etc) to
10798 a new script file named FILENAME. If FILTER is non-NULL, call it
10799 on each breakpoint and only include the ones for which it returns
10803 save_breakpoints (char *filename
, int from_tty
,
10804 int (*filter
) (const struct breakpoint
*))
10806 struct breakpoint
*tp
;
10809 struct cleanup
*cleanup
;
10810 struct ui_file
*fp
;
10811 int extra_trace_bits
= 0;
10813 if (filename
== 0 || *filename
== 0)
10814 error (_("Argument required (file name in which to save)"));
10816 /* See if we have anything to save. */
10817 ALL_BREAKPOINTS (tp
)
10819 /* Skip internal and momentary breakpoints. */
10820 if (!user_settable_breakpoint (tp
))
10823 /* If we have a filter, only save the breakpoints it accepts. */
10824 if (filter
&& !filter (tp
))
10829 if (is_tracepoint (tp
))
10831 extra_trace_bits
= 1;
10833 /* We can stop searching. */
10840 warning (_("Nothing to save."));
10844 pathname
= tilde_expand (filename
);
10845 cleanup
= make_cleanup (xfree
, pathname
);
10846 fp
= gdb_fopen (pathname
, "w");
10848 error (_("Unable to open file '%s' for saving (%s)"),
10849 filename
, safe_strerror (errno
));
10850 make_cleanup_ui_file_delete (fp
);
10852 if (extra_trace_bits
)
10853 save_trace_state_variables (fp
);
10855 ALL_BREAKPOINTS (tp
)
10857 /* Skip internal and momentary breakpoints. */
10858 if (!user_settable_breakpoint (tp
))
10861 /* If we have a filter, only save the breakpoints it accepts. */
10862 if (filter
&& !filter (tp
))
10865 if (tp
->ops
!= NULL
)
10866 (tp
->ops
->print_recreate
) (tp
, fp
);
10869 if (tp
->type
== bp_fast_tracepoint
)
10870 fprintf_unfiltered (fp
, "ftrace");
10871 else if (tp
->type
== bp_tracepoint
)
10872 fprintf_unfiltered (fp
, "trace");
10873 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10874 fprintf_unfiltered (fp
, "tbreak");
10875 else if (tp
->type
== bp_breakpoint
)
10876 fprintf_unfiltered (fp
, "break");
10877 else if (tp
->type
== bp_hardware_breakpoint
10878 && tp
->disposition
== disp_del
)
10879 fprintf_unfiltered (fp
, "thbreak");
10880 else if (tp
->type
== bp_hardware_breakpoint
)
10881 fprintf_unfiltered (fp
, "hbreak");
10882 else if (tp
->type
== bp_watchpoint
)
10883 fprintf_unfiltered (fp
, "watch");
10884 else if (tp
->type
== bp_hardware_watchpoint
)
10885 fprintf_unfiltered (fp
, "watch");
10886 else if (tp
->type
== bp_read_watchpoint
)
10887 fprintf_unfiltered (fp
, "rwatch");
10888 else if (tp
->type
== bp_access_watchpoint
)
10889 fprintf_unfiltered (fp
, "awatch");
10891 internal_error (__FILE__
, __LINE__
,
10892 _("unhandled breakpoint type %d"), (int) tp
->type
);
10894 if (tp
->exp_string
)
10895 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
10896 else if (tp
->addr_string
)
10897 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10902 sprintf_vma (tmp
, tp
->loc
->address
);
10903 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10907 if (tp
->thread
!= -1)
10908 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
10911 fprintf_unfiltered (fp
, " task %d", tp
->task
);
10913 fprintf_unfiltered (fp
, "\n");
10915 /* Note, we can't rely on tp->number for anything, as we can't
10916 assume the recreated breakpoint numbers will match. Use $bpnum
10919 if (tp
->cond_string
)
10920 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
10922 if (tp
->ignore_count
)
10923 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
10925 if (tp
->pass_count
)
10926 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10930 volatile struct gdb_exception ex
;
10932 fprintf_unfiltered (fp
, " commands\n");
10934 ui_out_redirect (uiout
, fp
);
10935 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10937 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10939 ui_out_redirect (uiout
, NULL
);
10942 throw_exception (ex
);
10944 fprintf_unfiltered (fp
, " end\n");
10947 if (tp
->enable_state
== bp_disabled
)
10948 fprintf_unfiltered (fp
, "disable\n");
10950 /* If this is a multi-location breakpoint, check if the locations
10951 should be individually disabled. Watchpoint locations are
10952 special, and not user visible. */
10953 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
10955 struct bp_location
*loc
;
10958 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
10960 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
10964 if (extra_trace_bits
&& *default_collect
)
10965 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10967 do_cleanups (cleanup
);
10969 printf_filtered (_("Saved to file '%s'.\n"), filename
);
10972 /* The `save breakpoints' command. */
10975 save_breakpoints_command (char *args
, int from_tty
)
10977 save_breakpoints (args
, from_tty
, NULL
);
10980 /* The `save tracepoints' command. */
10983 save_tracepoints_command (char *args
, int from_tty
)
10985 save_breakpoints (args
, from_tty
, is_tracepoint
);
10988 /* Create a vector of all tracepoints. */
10990 VEC(breakpoint_p
) *
10993 VEC(breakpoint_p
) *tp_vec
= 0;
10994 struct breakpoint
*tp
;
10996 ALL_TRACEPOINTS (tp
)
10998 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11005 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
11006 It is defined as a macro to prevent duplication.
11007 COMMAND should be a string constant containing the name of the command. */
11008 #define BREAK_ARGS_HELP(command) \
11009 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11010 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11011 If a line number is specified, break at start of code for that line.\n\
11012 If a function is specified, break at start of code for that function.\n\
11013 If an address is specified, break at that exact address.\n\
11014 With no LOCATION, uses current execution address of selected stack frame.\n\
11015 This is useful for breaking on return to a stack frame.\n\
11017 THREADNUM is the number from \"info threads\".\n\
11018 CONDITION is a boolean expression.\n\
11020 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
11022 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11024 /* List of subcommands for "catch". */
11025 static struct cmd_list_element
*catch_cmdlist
;
11027 /* List of subcommands for "tcatch". */
11028 static struct cmd_list_element
*tcatch_cmdlist
;
11030 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11031 lists, and pass some additional user data to the command function. */
11033 add_catch_command (char *name
, char *docstring
,
11034 void (*sfunc
) (char *args
, int from_tty
,
11035 struct cmd_list_element
*command
),
11036 char **(*completer
) (struct cmd_list_element
*cmd
,
11037 char *text
, char *word
),
11038 void *user_data_catch
,
11039 void *user_data_tcatch
)
11041 struct cmd_list_element
*command
;
11043 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11045 set_cmd_sfunc (command
, sfunc
);
11046 set_cmd_context (command
, user_data_catch
);
11047 set_cmd_completer (command
, completer
);
11049 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11051 set_cmd_sfunc (command
, sfunc
);
11052 set_cmd_context (command
, user_data_tcatch
);
11053 set_cmd_completer (command
, completer
);
11057 clear_syscall_counts (struct inferior
*inf
)
11059 inf
->total_syscalls_count
= 0;
11060 inf
->any_syscall_count
= 0;
11061 VEC_free (int, inf
->syscalls_counts
);
11065 save_command (char *arg
, int from_tty
)
11067 printf_unfiltered (_("\
11068 \"save\" must be followed by the name of a save subcommand.\n"));
11069 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11073 _initialize_breakpoint (void)
11075 struct cmd_list_element
*c
;
11077 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
11078 observer_attach_inferior_exit (clear_syscall_counts
);
11079 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
11081 breakpoint_chain
= 0;
11082 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
11083 before a breakpoint is set. */
11084 breakpoint_count
= 0;
11086 tracepoint_count
= 0;
11088 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
11089 Set ignore-count of breakpoint number N to COUNT.\n\
11090 Usage is `ignore N COUNT'."));
11092 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
11094 add_com ("commands", class_breakpoint
, commands_command
, _("\
11095 Set commands to be executed when a breakpoint is hit.\n\
11096 Give breakpoint number as argument after \"commands\".\n\
11097 With no argument, the targeted breakpoint is the last one set.\n\
11098 The commands themselves follow starting on the next line.\n\
11099 Type a line containing \"end\" to indicate the end of them.\n\
11100 Give \"silent\" as the first line to make the breakpoint silent;\n\
11101 then no output is printed when it is hit, except what the commands print."));
11103 add_com ("condition", class_breakpoint
, condition_command
, _("\
11104 Specify breakpoint number N to break only if COND is true.\n\
11105 Usage is `condition N COND', where N is an integer and COND is an\n\
11106 expression to be evaluated whenever breakpoint N is reached."));
11108 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
11109 Set a temporary breakpoint.\n\
11110 Like \"break\" except the breakpoint is only temporary,\n\
11111 so it will be deleted when hit. Equivalent to \"break\" followed\n\
11112 by using \"enable delete\" on the breakpoint number.\n\
11114 BREAK_ARGS_HELP ("tbreak")));
11115 set_cmd_completer (c
, location_completer
);
11117 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
11118 Set a hardware assisted breakpoint.\n\
11119 Like \"break\" except the breakpoint requires hardware support,\n\
11120 some target hardware may not have this support.\n\
11122 BREAK_ARGS_HELP ("hbreak")));
11123 set_cmd_completer (c
, location_completer
);
11125 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
11126 Set a temporary hardware assisted breakpoint.\n\
11127 Like \"hbreak\" except the breakpoint is only temporary,\n\
11128 so it will be deleted when hit.\n\
11130 BREAK_ARGS_HELP ("thbreak")));
11131 set_cmd_completer (c
, location_completer
);
11133 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
11134 Enable some breakpoints.\n\
11135 Give breakpoint numbers (separated by spaces) as arguments.\n\
11136 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11137 This is used to cancel the effect of the \"disable\" command.\n\
11138 With a subcommand you can enable temporarily."),
11139 &enablelist
, "enable ", 1, &cmdlist
);
11141 add_com ("ab", class_breakpoint
, enable_command
, _("\
11142 Enable some breakpoints.\n\
11143 Give breakpoint numbers (separated by spaces) as arguments.\n\
11144 With no subcommand, breakpoints are enabled until you command otherwise.\n\
11145 This is used to cancel the effect of the \"disable\" command.\n\
11146 With a subcommand you can enable temporarily."));
11148 add_com_alias ("en", "enable", class_breakpoint
, 1);
11150 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
11151 Enable some breakpoints.\n\
11152 Give breakpoint numbers (separated by spaces) as arguments.\n\
11153 This is used to cancel the effect of the \"disable\" command.\n\
11154 May be abbreviated to simply \"enable\".\n"),
11155 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
11157 add_cmd ("once", no_class
, enable_once_command
, _("\
11158 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11159 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11162 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11163 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11164 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11167 add_cmd ("delete", no_class
, enable_delete_command
, _("\
11168 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
11169 If a breakpoint is hit while enabled in this fashion, it is deleted."),
11172 add_cmd ("once", no_class
, enable_once_command
, _("\
11173 Enable breakpoints for one hit. Give breakpoint numbers.\n\
11174 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
11177 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
11178 Disable some breakpoints.\n\
11179 Arguments are breakpoint numbers with spaces in between.\n\
11180 To disable all breakpoints, give no argument.\n\
11181 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
11182 &disablelist
, "disable ", 1, &cmdlist
);
11183 add_com_alias ("dis", "disable", class_breakpoint
, 1);
11184 add_com_alias ("disa", "disable", class_breakpoint
, 1);
11186 add_com ("sb", class_breakpoint
, disable_command
, _("\
11187 Disable some breakpoints.\n\
11188 Arguments are breakpoint numbers with spaces in between.\n\
11189 To disable all breakpoints, give no argument.\n\
11190 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
11192 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
11193 Disable some breakpoints.\n\
11194 Arguments are breakpoint numbers with spaces in between.\n\
11195 To disable all breakpoints, give no argument.\n\
11196 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
11197 This command may be abbreviated \"disable\"."),
11200 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
11201 Delete some breakpoints or auto-display expressions.\n\
11202 Arguments are breakpoint numbers with spaces in between.\n\
11203 To delete all breakpoints, give no argument.\n\
11205 Also a prefix command for deletion of other GDB objects.\n\
11206 The \"unset\" command is also an alias for \"delete\"."),
11207 &deletelist
, "delete ", 1, &cmdlist
);
11208 add_com_alias ("d", "delete", class_breakpoint
, 1);
11209 add_com_alias ("del", "delete", class_breakpoint
, 1);
11211 add_com ("db", class_breakpoint
, delete_command
, _("\
11212 Delete some breakpoints.\n\
11213 Arguments are breakpoint numbers with spaces in between.\n\
11214 To delete all breakpoints, give no argument.\n"));
11216 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
11217 Delete some breakpoints or auto-display expressions.\n\
11218 Arguments are breakpoint numbers with spaces in between.\n\
11219 To delete all breakpoints, give no argument.\n\
11220 This command may be abbreviated \"delete\"."),
11223 add_com ("clear", class_breakpoint
, clear_command
, _("\
11224 Clear breakpoint at specified line or function.\n\
11225 Argument may be line number, function name, or \"*\" and an address.\n\
11226 If line number is specified, all breakpoints in that line are cleared.\n\
11227 If function is specified, breakpoints at beginning of function are cleared.\n\
11228 If an address is specified, breakpoints at that address are cleared.\n\
11230 With no argument, clears all breakpoints in the line that the selected frame\n\
11231 is executing in.\n\
11233 See also the \"delete\" command which clears breakpoints by number."));
11235 c
= add_com ("break", class_breakpoint
, break_command
, _("\
11236 Set breakpoint at specified line or function.\n"
11237 BREAK_ARGS_HELP ("break")));
11238 set_cmd_completer (c
, location_completer
);
11240 add_com_alias ("b", "break", class_run
, 1);
11241 add_com_alias ("br", "break", class_run
, 1);
11242 add_com_alias ("bre", "break", class_run
, 1);
11243 add_com_alias ("brea", "break", class_run
, 1);
11246 add_com_alias ("ba", "break", class_breakpoint
, 1);
11250 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
11251 Break in function/address or break at a line in the current file."),
11252 &stoplist
, "stop ", 1, &cmdlist
);
11253 add_cmd ("in", class_breakpoint
, stopin_command
,
11254 _("Break in function or address."), &stoplist
);
11255 add_cmd ("at", class_breakpoint
, stopat_command
,
11256 _("Break at a line in the current file."), &stoplist
);
11257 add_com ("status", class_info
, breakpoints_info
, _("\
11258 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11259 The \"Type\" column indicates one of:\n\
11260 \tbreakpoint - normal breakpoint\n\
11261 \twatchpoint - watchpoint\n\
11262 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11263 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11264 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11265 address and file/line number respectively.\n\
11267 Convenience variable \"$_\" and default examine address for \"x\"\n\
11268 are set to the address of the last breakpoint listed unless the command\n\
11269 is prefixed with \"server \".\n\n\
11270 Convenience variable \"$bpnum\" contains the number of the last\n\
11271 breakpoint set."));
11274 add_info ("breakpoints", breakpoints_info
, _("\
11275 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11276 The \"Type\" column indicates one of:\n\
11277 \tbreakpoint - normal breakpoint\n\
11278 \twatchpoint - watchpoint\n\
11279 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11280 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11281 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11282 address and file/line number respectively.\n\
11284 Convenience variable \"$_\" and default examine address for \"x\"\n\
11285 are set to the address of the last breakpoint listed unless the command\n\
11286 is prefixed with \"server \".\n\n\
11287 Convenience variable \"$bpnum\" contains the number of the last\n\
11288 breakpoint set."));
11290 add_info_alias ("b", "breakpoints", 1);
11293 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11294 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11295 The \"Type\" column indicates one of:\n\
11296 \tbreakpoint - normal breakpoint\n\
11297 \twatchpoint - watchpoint\n\
11298 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11299 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11300 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11301 address and file/line number respectively.\n\
11303 Convenience variable \"$_\" and default examine address for \"x\"\n\
11304 are set to the address of the last breakpoint listed unless the command\n\
11305 is prefixed with \"server \".\n\n\
11306 Convenience variable \"$bpnum\" contains the number of the last\n\
11307 breakpoint set."));
11309 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11310 Status of all breakpoints, or breakpoint number NUMBER.\n\
11311 The \"Type\" column indicates one of:\n\
11312 \tbreakpoint - normal breakpoint\n\
11313 \twatchpoint - watchpoint\n\
11314 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11315 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11316 \tuntil - internal breakpoint used by the \"until\" command\n\
11317 \tfinish - internal breakpoint used by the \"finish\" command\n\
11318 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11319 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11320 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11321 address and file/line number respectively.\n\
11323 Convenience variable \"$_\" and default examine address for \"x\"\n\
11324 are set to the address of the last breakpoint listed unless the command\n\
11325 is prefixed with \"server \".\n\n\
11326 Convenience variable \"$bpnum\" contains the number of the last\n\
11328 &maintenanceinfolist
);
11330 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11331 Set catchpoints to catch events."),
11332 &catch_cmdlist
, "catch ",
11333 0/*allow-unknown*/, &cmdlist
);
11335 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11336 Set temporary catchpoints to catch events."),
11337 &tcatch_cmdlist
, "tcatch ",
11338 0/*allow-unknown*/, &cmdlist
);
11340 /* Add catch and tcatch sub-commands. */
11341 add_catch_command ("catch", _("\
11342 Catch an exception, when caught.\n\
11343 With an argument, catch only exceptions with the given name."),
11344 catch_catch_command
,
11348 add_catch_command ("throw", _("\
11349 Catch an exception, when thrown.\n\
11350 With an argument, catch only exceptions with the given name."),
11351 catch_throw_command
,
11355 add_catch_command ("fork", _("Catch calls to fork."),
11356 catch_fork_command_1
,
11358 (void *) (uintptr_t) catch_fork_permanent
,
11359 (void *) (uintptr_t) catch_fork_temporary
);
11360 add_catch_command ("vfork", _("Catch calls to vfork."),
11361 catch_fork_command_1
,
11363 (void *) (uintptr_t) catch_vfork_permanent
,
11364 (void *) (uintptr_t) catch_vfork_temporary
);
11365 add_catch_command ("exec", _("Catch calls to exec."),
11366 catch_exec_command_1
,
11370 add_catch_command ("syscall", _("\
11371 Catch system calls by their names and/or numbers.\n\
11372 Arguments say which system calls to catch. If no arguments\n\
11373 are given, every system call will be caught.\n\
11374 Arguments, if given, should be one or more system call names\n\
11375 (if your system supports that), or system call numbers."),
11376 catch_syscall_command_1
,
11377 catch_syscall_completer
,
11380 add_catch_command ("exception", _("\
11381 Catch Ada exceptions, when raised.\n\
11382 With an argument, catch only exceptions with the given name."),
11383 catch_ada_exception_command
,
11387 add_catch_command ("assert", _("\
11388 Catch failed Ada assertions, when raised.\n\
11389 With an argument, catch only exceptions with the given name."),
11390 catch_assert_command
,
11395 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11396 Set a watchpoint for an expression.\n\
11397 A watchpoint stops execution of your program whenever the value of\n\
11398 an expression changes."));
11399 set_cmd_completer (c
, expression_completer
);
11401 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11402 Set a read watchpoint for an expression.\n\
11403 A watchpoint stops execution of your program whenever the value of\n\
11404 an expression is read."));
11405 set_cmd_completer (c
, expression_completer
);
11407 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11408 Set a watchpoint for an expression.\n\
11409 A watchpoint stops execution of your program whenever the value of\n\
11410 an expression is either read or written."));
11411 set_cmd_completer (c
, expression_completer
);
11413 add_info ("watchpoints", watchpoints_info
, _("\
11414 Status of watchpoints, or watchpoint number NUMBER."));
11418 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11419 respond to changes - contrary to the description. */
11420 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11421 &can_use_hw_watchpoints
, _("\
11422 Set debugger's willingness to use watchpoint hardware."), _("\
11423 Show debugger's willingness to use watchpoint hardware."), _("\
11424 If zero, gdb will not use hardware for new watchpoints, even if\n\
11425 such is available. (However, any hardware watchpoints that were\n\
11426 created before setting this to nonzero, will continue to use watchpoint\n\
11429 show_can_use_hw_watchpoints
,
11430 &setlist
, &showlist
);
11432 can_use_hw_watchpoints
= 1;
11434 /* Tracepoint manipulation commands. */
11436 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11437 Set a tracepoint at specified line or function.\n\
11439 BREAK_ARGS_HELP ("trace") "\n\
11440 Do \"help tracepoints\" for info on other tracepoint commands."));
11441 set_cmd_completer (c
, location_completer
);
11443 add_com_alias ("tp", "trace", class_alias
, 0);
11444 add_com_alias ("tr", "trace", class_alias
, 1);
11445 add_com_alias ("tra", "trace", class_alias
, 1);
11446 add_com_alias ("trac", "trace", class_alias
, 1);
11448 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11449 Set a fast tracepoint at specified line or function.\n\
11451 BREAK_ARGS_HELP ("ftrace") "\n\
11452 Do \"help tracepoints\" for info on other tracepoint commands."));
11453 set_cmd_completer (c
, location_completer
);
11455 add_info ("tracepoints", tracepoints_info
, _("\
11456 Status of tracepoints, or tracepoint number NUMBER.\n\
11457 Convenience variable \"$tpnum\" contains the number of the\n\
11458 last tracepoint set."));
11460 add_info_alias ("tp", "tracepoints", 1);
11462 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11463 Delete specified tracepoints.\n\
11464 Arguments are tracepoint numbers, separated by spaces.\n\
11465 No argument means delete all tracepoints."),
11468 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11469 Disable specified tracepoints.\n\
11470 Arguments are tracepoint numbers, separated by spaces.\n\
11471 No argument means disable all tracepoints."),
11473 deprecate_cmd (c
, "disable");
11475 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11476 Enable specified tracepoints.\n\
11477 Arguments are tracepoint numbers, separated by spaces.\n\
11478 No argument means enable all tracepoints."),
11480 deprecate_cmd (c
, "enable");
11482 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11483 Set the passcount for a tracepoint.\n\
11484 The trace will end when the tracepoint has been passed 'count' times.\n\
11485 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11486 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11488 add_prefix_cmd ("save", class_breakpoint
, save_command
,
11489 _("Save breakpoint definitions as a script."),
11490 &save_cmdlist
, "save ",
11491 0/*allow-unknown*/, &cmdlist
);
11493 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
11494 Save current breakpoint definitions as a script.\n\
11495 This includes all types of breakpoints (breakpoints, watchpoints, \n\
11496 catchpoints, tracepoints). Use the 'source' command in another debug\n\
11497 session to restore them."),
11499 set_cmd_completer (c
, filename_completer
);
11501 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
11502 Save current tracepoint definitions as a script.\n\
11503 Use the 'source' command in another debug session to restore them."),
11505 set_cmd_completer (c
, filename_completer
);
11507 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
11508 deprecate_cmd (c
, "save tracepoints");
11510 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11511 Breakpoint specific settings\n\
11512 Configure various breakpoint-specific variables such as\n\
11513 pending breakpoint behavior"),
11514 &breakpoint_set_cmdlist
, "set breakpoint ",
11515 0/*allow-unknown*/, &setlist
);
11516 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11517 Breakpoint specific settings\n\
11518 Configure various breakpoint-specific variables such as\n\
11519 pending breakpoint behavior"),
11520 &breakpoint_show_cmdlist
, "show breakpoint ",
11521 0/*allow-unknown*/, &showlist
);
11523 add_setshow_auto_boolean_cmd ("pending", no_class
,
11524 &pending_break_support
, _("\
11525 Set debugger's behavior regarding pending breakpoints."), _("\
11526 Show debugger's behavior regarding pending breakpoints."), _("\
11527 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11528 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11529 an error. If auto, an unrecognized breakpoint location results in a\n\
11530 user-query to see if a pending breakpoint should be created."),
11532 show_pending_break_support
,
11533 &breakpoint_set_cmdlist
,
11534 &breakpoint_show_cmdlist
);
11536 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11538 add_setshow_boolean_cmd ("auto-hw", no_class
,
11539 &automatic_hardware_breakpoints
, _("\
11540 Set automatic usage of hardware breakpoints."), _("\
11541 Show automatic usage of hardware breakpoints."), _("\
11542 If set, the debugger will automatically use hardware breakpoints for\n\
11543 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11544 a warning will be emitted for such breakpoints."),
11546 show_automatic_hardware_breakpoints
,
11547 &breakpoint_set_cmdlist
,
11548 &breakpoint_show_cmdlist
);
11550 add_setshow_enum_cmd ("always-inserted", class_support
,
11551 always_inserted_enums
, &always_inserted_mode
, _("\
11552 Set mode for inserting breakpoints."), _("\
11553 Show mode for inserting breakpoints."), _("\
11554 When this mode is off, breakpoints are inserted in inferior when it is\n\
11555 resumed, and removed when execution stops. When this mode is on,\n\
11556 breakpoints are inserted immediately and removed only when the user\n\
11557 deletes the breakpoint. When this mode is auto (which is the default),\n\
11558 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11559 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11560 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11561 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11563 &show_always_inserted_mode
,
11564 &breakpoint_set_cmdlist
,
11565 &breakpoint_show_cmdlist
);
11567 automatic_hardware_breakpoints
= 1;
11569 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);