1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_once_command (char *, int);
84 static void disable_command (char *, int);
86 static void enable_command (char *, int);
88 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 /* This function is used in gdbtk sources and thus can not be made static. */
109 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
110 struct symtab_and_line
,
113 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
115 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
119 static void describe_other_breakpoints (struct gdbarch
*,
120 struct program_space
*, CORE_ADDR
,
121 struct obj_section
*, int);
123 static int breakpoint_address_match (struct address_space
*aspace1
,
125 struct address_space
*aspace2
,
128 static int watchpoint_locations_match (struct bp_location
*loc1
,
129 struct bp_location
*loc2
);
131 static void breakpoints_info (char *, int);
133 static void watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
137 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
147 static int get_number_trailer (char **, int);
156 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
157 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
159 static enum print_stop_action
print_it_typical (bpstat
);
161 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
163 static int watchpoint_check (void *);
165 static void maintenance_info_breakpoints (char *, int);
167 static int hw_breakpoint_used_count (void);
169 static int hw_watchpoint_used_count (enum bptype
, int *);
171 static void hbreak_command (char *, int);
173 static void thbreak_command (char *, int);
175 static void watch_command_1 (char *, int, int);
177 static void rwatch_command (char *, int);
179 static void awatch_command (char *, int);
181 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
183 static void stop_command (char *arg
, int from_tty
);
185 static void stopin_command (char *arg
, int from_tty
);
187 static void stopat_command (char *arg
, int from_tty
);
189 static char *ep_parse_optional_if_clause (char **arg
);
191 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
192 char *arg
, int tempflag
, int from_tty
);
194 static void tcatch_command (char *arg
, int from_tty
);
196 static void ep_skip_leading_whitespace (char **s
);
198 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
201 static void free_bp_location (struct bp_location
*loc
);
203 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
205 static void update_global_location_list (int);
207 static void update_global_location_list_nothrow (int);
209 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
211 static int is_watchpoint (const struct breakpoint
*bpt
);
213 static void insert_breakpoint_locations (void);
215 static int syscall_catchpoint_p (struct breakpoint
*b
);
217 static void tracepoints_info (char *, int);
219 static void delete_trace_command (char *, int);
221 static void enable_trace_command (char *, int);
223 static void disable_trace_command (char *, int);
225 static void trace_pass_command (char *, int);
227 /* A reference-counted struct command_line. This lets multiple
228 breakpoints share a single command list. */
229 struct counted_command_line
231 /* The reference count. */
234 /* The command list. */
235 struct command_line
*commands
;
238 struct command_line
*
239 breakpoint_commands (struct breakpoint
*b
)
241 return b
->commands
? b
->commands
->commands
: NULL
;
244 /* Flag indicating that a command has proceeded the inferior past the
245 current breakpoint. */
247 static int breakpoint_proceeded
;
250 bpdisp_text (enum bpdisp disp
)
252 /* NOTE: the following values are a part of MI protocol and represent
253 values of 'disp' field returned when inferior stops at a breakpoint. */
254 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
255 return bpdisps
[(int) disp
];
258 /* Prototypes for exported functions. */
259 /* If FALSE, gdb will not use hardware support for watchpoints, even
260 if such is available. */
261 static int can_use_hw_watchpoints
;
264 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
,
268 fprintf_filtered (file
, _("\
269 Debugger's willingness to use watchpoint hardware is %s.\n"),
273 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
274 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
275 for unrecognized breakpoint locations.
276 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
277 static enum auto_boolean pending_break_support
;
279 show_pending_break_support (struct ui_file
*file
, int from_tty
,
280 struct cmd_list_element
*c
,
283 fprintf_filtered (file
, _("\
284 Debugger's behavior regarding pending breakpoints is %s.\n"),
288 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
289 set with "break" but falling in read-only memory.
290 If 0, gdb will warn about such breakpoints, but won't automatically
291 use hardware breakpoints. */
292 static int automatic_hardware_breakpoints
;
294 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
295 struct cmd_list_element
*c
,
298 fprintf_filtered (file
, _("\
299 Automatic usage of hardware breakpoints is %s.\n"),
303 /* If on, gdb will keep breakpoints inserted even as inferior is
304 stopped, and immediately insert any new breakpoints. If off, gdb
305 will insert breakpoints into inferior only when resuming it, and
306 will remove breakpoints upon stop. If auto, GDB will behave as ON
307 if in non-stop mode, and as OFF if all-stop mode.*/
309 static const char always_inserted_auto
[] = "auto";
310 static const char always_inserted_on
[] = "on";
311 static const char always_inserted_off
[] = "off";
312 static const char *always_inserted_enums
[] = {
313 always_inserted_auto
,
318 static const char *always_inserted_mode
= always_inserted_auto
;
320 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
321 struct cmd_list_element
*c
, const char *value
)
323 if (always_inserted_mode
== always_inserted_auto
)
324 fprintf_filtered (file
, _("\
325 Always inserted breakpoint mode is %s (currently %s).\n"),
327 breakpoints_always_inserted_mode () ? "on" : "off");
329 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
333 breakpoints_always_inserted_mode (void)
335 return (always_inserted_mode
== always_inserted_on
336 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
339 void _initialize_breakpoint (void);
341 /* Are we executing breakpoint commands? */
342 static int executing_breakpoint_commands
;
344 /* Are overlay event breakpoints enabled? */
345 static int overlay_events_enabled
;
347 /* Walk the following statement or block through all breakpoints.
348 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
351 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
353 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
354 for (B = breakpoint_chain; \
355 B ? (TMP=B->next, 1): 0; \
358 /* Similar iterator for the low-level breakpoints. SAFE variant is not
359 provided so update_global_location_list must not be called while executing
360 the block of ALL_BP_LOCATIONS. */
362 #define ALL_BP_LOCATIONS(B,BP_TMP) \
363 for (BP_TMP = bp_location; \
364 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
367 /* Iterator for tracepoints only. */
369 #define ALL_TRACEPOINTS(B) \
370 for (B = breakpoint_chain; B; B = B->next) \
371 if (is_tracepoint (B))
373 /* Chains of all breakpoints defined. */
375 struct breakpoint
*breakpoint_chain
;
377 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
379 static struct bp_location
**bp_location
;
381 /* Number of elements of BP_LOCATION. */
383 static unsigned bp_location_count
;
385 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
386 for the current elements of BP_LOCATION which get a valid result from
387 bp_location_has_shadow. You can use it for roughly limiting the subrange of
388 BP_LOCATION to scan for shadow bytes for an address you need to read. */
390 static CORE_ADDR bp_location_placed_address_before_address_max
;
392 /* Maximum offset plus alignment between
393 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
394 the current elements of BP_LOCATION which get a valid result from
395 bp_location_has_shadow. You can use it for roughly limiting the subrange of
396 BP_LOCATION to scan for shadow bytes for an address you need to read. */
398 static CORE_ADDR bp_location_shadow_len_after_address_max
;
400 /* The locations that no longer correspond to any breakpoint,
401 unlinked from bp_location array, but for which a hit
402 may still be reported by a target. */
403 VEC(bp_location_p
) *moribund_locations
= NULL
;
405 /* Number of last breakpoint made. */
407 static int breakpoint_count
;
409 /* The value of `breakpoint_count' before the last command that
410 created breakpoints. If the last (break-like) command created more
411 than one breakpoint, then the difference between BREAKPOINT_COUNT
412 and PREV_BREAKPOINT_COUNT is more than one. */
413 static int prev_breakpoint_count
;
415 /* Number of last tracepoint made. */
417 static int tracepoint_count
;
419 /* Return whether a breakpoint is an active enabled breakpoint. */
421 breakpoint_enabled (struct breakpoint
*b
)
423 return (b
->enable_state
== bp_enabled
);
426 /* Set breakpoint count to NUM. */
429 set_breakpoint_count (int num
)
431 prev_breakpoint_count
= breakpoint_count
;
432 breakpoint_count
= num
;
433 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
436 /* Used by `start_rbreak_breakpoints' below, to record the current
437 breakpoint count before "rbreak" creates any breakpoint. */
438 static int rbreak_start_breakpoint_count
;
440 /* Called at the start an "rbreak" command to record the first
444 start_rbreak_breakpoints (void)
446 rbreak_start_breakpoint_count
= breakpoint_count
;
449 /* Called at the end of an "rbreak" command to record the last
453 end_rbreak_breakpoints (void)
455 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
458 /* Used in run_command to zero the hit count when a new run starts. */
461 clear_breakpoint_hit_counts (void)
463 struct breakpoint
*b
;
469 /* Allocate a new counted_command_line with reference count of 1.
470 The new structure owns COMMANDS. */
472 static struct counted_command_line
*
473 alloc_counted_command_line (struct command_line
*commands
)
475 struct counted_command_line
*result
476 = xmalloc (sizeof (struct counted_command_line
));
478 result
->commands
= commands
;
482 /* Increment reference count. This does nothing if CMD is NULL. */
485 incref_counted_command_line (struct counted_command_line
*cmd
)
491 /* Decrement reference count. If the reference count reaches 0,
492 destroy the counted_command_line. Sets *CMDP to NULL. This does
493 nothing if *CMDP is NULL. */
496 decref_counted_command_line (struct counted_command_line
**cmdp
)
500 if (--(*cmdp
)->refc
== 0)
502 free_command_lines (&(*cmdp
)->commands
);
509 /* A cleanup function that calls decref_counted_command_line. */
512 do_cleanup_counted_command_line (void *arg
)
514 decref_counted_command_line (arg
);
517 /* Create a cleanup that calls decref_counted_command_line on the
520 static struct cleanup
*
521 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
523 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
526 /* Default address, symtab and line to put a breakpoint at
527 for "break" command with no arg.
528 if default_breakpoint_valid is zero, the other three are
529 not valid, and "break" with no arg is an error.
531 This set by print_stack_frame, which calls set_default_breakpoint. */
533 int default_breakpoint_valid
;
534 CORE_ADDR default_breakpoint_address
;
535 struct symtab
*default_breakpoint_symtab
;
536 int default_breakpoint_line
;
537 struct program_space
*default_breakpoint_pspace
;
540 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
541 Advance *PP after the string and any trailing whitespace.
543 Currently the string can either be a number or "$" followed by the name
544 of a convenience variable. Making it an expression wouldn't work well
545 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
547 If the string is a NULL pointer, that denotes the last breakpoint.
549 TRAILER is a character which can be found after the number; most
550 commonly this is `-'. If you don't want a trailer, use \0. */
552 get_number_trailer (char **pp
, int trailer
)
554 int retval
= 0; /* default */
558 /* Empty line means refer to the last breakpoint. */
559 return breakpoint_count
;
562 /* Make a copy of the name, so we can null-terminate it
563 to pass to lookup_internalvar(). */
568 while (isalnum (*p
) || *p
== '_')
570 varname
= (char *) alloca (p
- start
+ 1);
571 strncpy (varname
, start
, p
- start
);
572 varname
[p
- start
] = '\0';
573 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
577 printf_filtered (_("Convenience variable must have integer value.\n"));
585 while (*p
>= '0' && *p
<= '9')
588 /* There is no number here. (e.g. "cond a == b"). */
590 /* Skip non-numeric token */
591 while (*p
&& !isspace((int) *p
))
593 /* Return zero, which caller must interpret as error. */
599 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
601 /* Trailing junk: return 0 and let caller print error msg. */
602 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
613 /* Like get_number_trailer, but don't allow a trailer. */
615 get_number (char **pp
)
617 return get_number_trailer (pp
, '\0');
620 /* Parse a number or a range.
621 * A number will be of the form handled by get_number.
622 * A range will be of the form <number1> - <number2>, and
623 * will represent all the integers between number1 and number2,
626 * While processing a range, this fuction is called iteratively;
627 * At each call it will return the next value in the range.
629 * At the beginning of parsing a range, the char pointer PP will
630 * be advanced past <number1> and left pointing at the '-' token.
631 * Subsequent calls will not advance the pointer until the range
632 * is completed. The call that completes the range will advance
633 * pointer PP past <number2>.
637 get_number_or_range (char **pp
)
639 static int last_retval
, end_value
;
640 static char *end_ptr
;
641 static int in_range
= 0;
645 /* Default case: pp is pointing either to a solo number,
646 or to the first number of a range. */
647 last_retval
= get_number_trailer (pp
, '-');
652 /* This is the start of a range (<number1> - <number2>).
653 Skip the '-', parse and remember the second number,
654 and also remember the end of the final token. */
658 while (isspace ((int) *end_ptr
))
659 end_ptr
++; /* skip white space */
660 end_value
= get_number (temp
);
661 if (end_value
< last_retval
)
663 error (_("inverted range"));
665 else if (end_value
== last_retval
)
667 /* degenerate range (number1 == number2). Advance the
668 token pointer so that the range will be treated as a
677 error (_("negative value"));
680 /* pp points to the '-' that betokens a range. All
681 number-parsing has already been done. Return the next
682 integer value (one greater than the saved previous value).
683 Do not advance the token pointer 'pp' until the end of range
686 if (++last_retval
== end_value
)
688 /* End of range reached; advance token pointer. */
696 /* Return the breakpoint with the specified number, or NULL
697 if the number does not refer to an existing breakpoint. */
700 get_breakpoint (int num
)
702 struct breakpoint
*b
;
705 if (b
->number
== num
)
712 /* condition N EXP -- set break condition of breakpoint N to EXP. */
715 condition_command (char *arg
, int from_tty
)
717 struct breakpoint
*b
;
722 error_no_arg (_("breakpoint number"));
725 bnum
= get_number (&p
);
727 error (_("Bad breakpoint argument: '%s'"), arg
);
730 if (b
->number
== bnum
)
732 struct bp_location
*loc
= b
->loc
;
733 for (; loc
; loc
= loc
->next
)
738 xfree (b
->cond_string
);
739 b
->cond_string
= NULL
;
746 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
751 /* I don't know if it matters whether this is the string the user
752 typed in or the decompiled expression. */
753 b
->cond_string
= xstrdup (arg
);
754 b
->condition_not_parsed
= 0;
756 if (is_watchpoint (b
))
758 innermost_block
= NULL
;
760 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
762 error (_("Junk at end of expression"));
763 b
->cond_exp_valid_block
= innermost_block
;
767 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
771 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
773 error (_("Junk at end of expression"));
777 breakpoints_changed ();
778 observer_notify_breakpoint_modified (b
->number
);
782 error (_("No breakpoint number %d."), bnum
);
785 /* Check that COMMAND do not contain commands that are suitable
786 only for tracepoints and not suitable for ordinary breakpoints.
787 Throw if any such commands is found.
790 check_no_tracepoint_commands (struct command_line
*commands
)
792 struct command_line
*c
;
793 for (c
= commands
; c
; c
= c
->next
)
797 if (c
->control_type
== while_stepping_control
)
798 error (_("The 'while-stepping' command can only be used for tracepoints"));
800 for (i
= 0; i
< c
->body_count
; ++i
)
801 check_no_tracepoint_commands ((c
->body_list
)[i
]);
803 /* Not that command parsing removes leading whitespace and comment
804 lines and also empty lines. So, we only need to check for
806 if (strstr (c
->line
, "collect ") == c
->line
)
807 error (_("The 'collect' command can only be used for tracepoints"));
809 if (strstr (c
->line
, "teval ") == c
->line
)
810 error (_("The 'teval' command can only be used for tracepoints"));
814 /* Encapsulate tests for different types of tracepoints. */
817 is_tracepoint (const struct breakpoint
*b
)
819 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
822 /* A helper function that validsates that COMMANDS are valid for a
823 breakpoint. This function will throw an exception if a problem is
827 validate_commands_for_breakpoint (struct breakpoint
*b
,
828 struct command_line
*commands
)
830 if (is_tracepoint (b
))
832 /* We need to verify that each top-level element of commands
833 is valid for tracepoints, that there's at most one while-stepping
834 element, and that while-stepping's body has valid tracing commands
835 excluding nested while-stepping. */
836 struct command_line
*c
;
837 struct command_line
*while_stepping
= 0;
838 for (c
= commands
; c
; c
= c
->next
)
841 if (c
->control_type
== while_stepping_control
)
843 if (b
->type
== bp_fast_tracepoint
)
844 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
847 error (_("The 'while-stepping' command can be used only once"));
854 struct command_line
*c2
;
856 gdb_assert (while_stepping
->body_count
== 1);
857 c2
= while_stepping
->body_list
[0];
858 for (; c2
; c2
= c2
->next
)
861 if (c2
->control_type
== while_stepping_control
)
862 error (_("The 'while-stepping' command cannot be nested"));
868 check_no_tracepoint_commands (commands
);
872 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
873 validate that only allowed commands are included.
877 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
879 validate_commands_for_breakpoint (b
, commands
);
881 decref_counted_command_line (&b
->commands
);
882 b
->commands
= alloc_counted_command_line (commands
);
883 breakpoints_changed ();
884 observer_notify_breakpoint_modified (b
->number
);
888 check_tracepoint_command (char *line
, void *closure
)
890 struct breakpoint
*b
= closure
;
891 validate_actionline (&line
, b
);
894 /* A structure used to pass information through
895 map_breakpoint_numbers. */
899 /* True if the command was typed at a tty. */
902 /* The breakpoint range spec. */
905 /* Non-NULL if the body of the commands are being read from this
906 already-parsed command. */
907 struct command_line
*control
;
909 /* The command lines read from the user, or NULL if they have not
911 struct counted_command_line
*cmd
;
914 /* A callback for map_breakpoint_numbers that sets the commands for
918 do_map_commands_command (struct breakpoint
*b
, void *data
)
920 struct commands_info
*info
= data
;
922 if (info
->cmd
== NULL
)
924 struct command_line
*l
;
926 if (info
->control
!= NULL
)
927 l
= copy_command_lines (info
->control
->body_list
[0]);
930 struct cleanup
*old_chain
;
933 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
936 old_chain
= make_cleanup (xfree
, str
);
938 l
= read_command_lines (str
,
941 ? check_tracepoint_command
: 0),
944 do_cleanups (old_chain
);
947 info
->cmd
= alloc_counted_command_line (l
);
950 /* If a breakpoint was on the list more than once, we don't need to
952 if (b
->commands
!= info
->cmd
)
954 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
955 incref_counted_command_line (info
->cmd
);
956 decref_counted_command_line (&b
->commands
);
957 b
->commands
= info
->cmd
;
958 breakpoints_changed ();
959 observer_notify_breakpoint_modified (b
->number
);
964 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
966 struct cleanup
*cleanups
;
967 struct commands_info info
;
969 info
.from_tty
= from_tty
;
970 info
.control
= control
;
972 /* If we read command lines from the user, then `info' will hold an
973 extra reference to the commands that we must clean up. */
974 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
976 if (arg
== NULL
|| !*arg
)
978 if (breakpoint_count
- prev_breakpoint_count
> 1)
979 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
980 else if (breakpoint_count
> 0)
981 arg
= xstrprintf ("%d", breakpoint_count
);
984 /* So that we don't try to free the incoming non-NULL
985 argument in the cleanup below. Mapping breakpoint
986 numbers will fail in this case. */
991 /* The command loop has some static state, so we need to preserve
996 make_cleanup (xfree
, arg
);
1000 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1002 if (info
.cmd
== NULL
)
1003 error (_("No breakpoints specified."));
1005 do_cleanups (cleanups
);
1009 commands_command (char *arg
, int from_tty
)
1011 commands_command_1 (arg
, from_tty
, NULL
);
1014 /* Like commands_command, but instead of reading the commands from
1015 input stream, takes them from an already parsed command structure.
1017 This is used by cli-script.c to DTRT with breakpoint commands
1018 that are part of if and while bodies. */
1019 enum command_control_type
1020 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1022 commands_command_1 (arg
, 0, cmd
);
1023 return simple_control
;
1026 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1029 bp_location_has_shadow (struct bp_location
*bl
)
1031 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1035 if (bl
->target_info
.shadow_len
== 0)
1036 /* bp isn't valid, or doesn't shadow memory. */
1041 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1042 by replacing any memory breakpoints with their shadowed contents.
1044 The range of shadowed area by each bp_location is:
1045 b->address - bp_location_placed_address_before_address_max
1046 up to b->address + bp_location_shadow_len_after_address_max
1047 The range we were requested to resolve shadows for is:
1048 memaddr ... memaddr + len
1049 Thus the safe cutoff boundaries for performance optimization are
1050 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1052 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1055 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1057 /* Left boundary, right boundary and median element of our binary search. */
1058 unsigned bc_l
, bc_r
, bc
;
1060 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1061 safe to report lower value but a failure to report higher one. */
1064 bc_r
= bp_location_count
;
1065 while (bc_l
+ 1 < bc_r
)
1067 struct bp_location
*b
;
1069 bc
= (bc_l
+ bc_r
) / 2;
1070 b
= bp_location
[bc
];
1072 /* Check first B->ADDRESS will not overflow due to the added constant.
1073 Then advance the left boundary only if we are sure the BC element can
1074 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1076 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1077 we cannot miss a breakpoint with its shadow range tail still reaching
1080 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1081 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1087 /* Now do full processing of the found relevant range of elements. */
1089 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1091 struct bp_location
*b
= bp_location
[bc
];
1092 CORE_ADDR bp_addr
= 0;
1096 if (b
->owner
->type
== bp_none
)
1097 warning (_("reading through apparently deleted breakpoint #%d?"),
1100 /* Performance optimization: any futher element can no longer affect BUF
1103 if (b
->address
>= bp_location_placed_address_before_address_max
1104 && memaddr
+ len
<= b
->address
1105 - bp_location_placed_address_before_address_max
)
1108 if (!bp_location_has_shadow (b
))
1110 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1111 current_program_space
->aspace
, 0))
1114 /* Addresses and length of the part of the breakpoint that
1116 bp_addr
= b
->target_info
.placed_address
;
1117 bp_size
= b
->target_info
.shadow_len
;
1119 if (bp_addr
+ bp_size
<= memaddr
)
1120 /* The breakpoint is entirely before the chunk of memory we
1124 if (bp_addr
>= memaddr
+ len
)
1125 /* The breakpoint is entirely after the chunk of memory we are
1129 /* Offset within shadow_contents. */
1130 if (bp_addr
< memaddr
)
1132 /* Only copy the second part of the breakpoint. */
1133 bp_size
-= memaddr
- bp_addr
;
1134 bptoffset
= memaddr
- bp_addr
;
1138 if (bp_addr
+ bp_size
> memaddr
+ len
)
1140 /* Only copy the first part of the breakpoint. */
1141 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1144 memcpy (buf
+ bp_addr
- memaddr
,
1145 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1150 /* A wrapper function for inserting catchpoints. */
1152 insert_catchpoint (struct ui_out
*uo
, void *args
)
1154 struct breakpoint
*b
= (struct breakpoint
*) args
;
1157 gdb_assert (b
->type
== bp_catchpoint
);
1158 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1163 /* Return true if BPT is of any hardware watchpoint kind. */
1166 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1168 return (bpt
->type
== bp_hardware_watchpoint
1169 || bpt
->type
== bp_read_watchpoint
1170 || bpt
->type
== bp_access_watchpoint
);
1173 /* Return true if BPT is of any watchpoint kind, hardware or
1177 is_watchpoint (const struct breakpoint
*bpt
)
1179 return (is_hardware_watchpoint (bpt
)
1180 || bpt
->type
== bp_watchpoint
);
1183 /* Find the current value of a watchpoint on EXP. Return the value in
1184 *VALP and *RESULTP and the chain of intermediate and final values
1185 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1188 If a memory error occurs while evaluating the expression, *RESULTP will
1189 be set to NULL. *RESULTP may be a lazy value, if the result could
1190 not be read from memory. It is used to determine whether a value
1191 is user-specified (we should watch the whole value) or intermediate
1192 (we should watch only the bit used to locate the final value).
1194 If the final value, or any intermediate value, could not be read
1195 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1196 set to any referenced values. *VALP will never be a lazy value.
1197 This is the value which we store in struct breakpoint.
1199 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1200 value chain. The caller must free the values individually. If
1201 VAL_CHAIN is NULL, all generated values will be left on the value
1205 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1206 struct value
**resultp
, struct value
**val_chain
)
1208 struct value
*mark
, *new_mark
, *result
;
1209 volatile struct gdb_exception ex
;
1217 /* Evaluate the expression. */
1218 mark
= value_mark ();
1221 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1223 result
= evaluate_expression (exp
);
1227 /* Ignore memory errors, we want watchpoints pointing at
1228 inaccessible memory to still be created; otherwise, throw the
1229 error to some higher catcher. */
1235 throw_exception (ex
);
1240 new_mark
= value_mark ();
1241 if (mark
== new_mark
)
1246 /* Make sure it's not lazy, so that after the target stops again we
1247 have a non-lazy previous value to compare with. */
1249 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1254 /* Return the chain of intermediate values. We use this to
1255 decide which addresses to watch. */
1256 *val_chain
= new_mark
;
1257 value_release_to_mark (mark
);
1261 /* Assuming that B is a watchpoint: returns true if the current thread
1262 and its running state are safe to evaluate or update watchpoint B.
1263 Watchpoints on local expressions need to be evaluated in the
1264 context of the thread that was current when the watchpoint was
1265 created, and, that thread needs to be stopped to be able to select
1266 the correct frame context. Watchpoints on global expressions can
1267 be evaluated on any thread, and in any state. It is presently left
1268 to the target allowing memory accesses when threads are
1272 watchpoint_in_thread_scope (struct breakpoint
*b
)
1274 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1275 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1276 && !is_executing (inferior_ptid
)));
1279 /* Assuming that B is a watchpoint:
1280 - Reparse watchpoint expression, if REPARSE is non-zero
1281 - Evaluate expression and store the result in B->val
1282 - Evaluate the condition if there is one, and store the result
1284 - Update the list of values that must be watched in B->loc.
1286 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1287 If this is local watchpoint that is out of scope, delete it.
1289 Even with `set breakpoint always-inserted on' the watchpoints are removed
1290 + inserted on each stop here. Normal breakpoints must never be removed
1291 because they might be missed by a running thread when debugging in non-stop
1292 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1293 processed here) are specific to each LWP since they are stored in each LWP's
1294 hardware debug registers. Therefore, such LWP must be stopped first in
1295 order to be able to modify its hardware watchpoints.
1297 Hardware watchpoints must be reset exactly once after being presented to the
1298 user. It cannot be done sooner, because it would reset the data used to
1299 present the watchpoint hit to the user. And it must not be done later
1300 because it could display the same single watchpoint hit during multiple GDB
1301 stops. Note that the latter is relevant only to the hardware watchpoint
1302 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1303 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1304 memory content has not changed.
1306 The following constraints influence the location where we can reset hardware
1309 * target_stopped_by_watchpoint and target_stopped_data_address are called
1310 several times when GDB stops.
1313 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1314 stop. GDB only presents one hardware watchpoint hit at a time as the
1315 reason for stopping, and all the other hits are presented later, one after
1316 the other, each time the user requests the execution to be resumed.
1317 Execution is not resumed for the threads still having pending hit event
1318 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1319 the inferior on the first stop the thread hit event is kept being reported
1320 from its cached value by linux_nat_stopped_data_address until the real
1321 thread resume happens after the watchpoint gets presented and thus its
1322 LWP_INFO->STATUS gets reset.
1324 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1325 removal from inferior. */
1328 update_watchpoint (struct breakpoint
*b
, int reparse
)
1330 int within_current_scope
;
1331 struct frame_id saved_frame_id
;
1332 struct bp_location
*loc
;
1336 /* If this is a local watchpoint, we only want to check if the
1337 watchpoint frame is in scope if the current thread is the thread
1338 that was used to create the watchpoint. */
1339 if (!watchpoint_in_thread_scope (b
))
1342 /* We don't free locations. They are stored in bp_location array and
1343 update_global_locations will eventually delete them and remove
1344 breakpoints if needed. */
1347 if (b
->disposition
== disp_del_at_next_stop
)
1352 /* Determine if the watchpoint is within scope. */
1353 if (b
->exp_valid_block
== NULL
)
1354 within_current_scope
= 1;
1357 struct frame_info
*fi
;
1359 /* Save the current frame's ID so we can restore it after
1360 evaluating the watchpoint expression on its own frame. */
1361 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1362 took a frame parameter, so that we didn't have to change the
1365 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1367 fi
= frame_find_by_id (b
->watchpoint_frame
);
1368 within_current_scope
= (fi
!= NULL
);
1369 if (within_current_scope
)
1373 if (within_current_scope
&& reparse
)
1382 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1383 /* If the meaning of expression itself changed, the old value is
1384 no longer relevant. We don't want to report a watchpoint hit
1385 to the user when the old value and the new value may actually
1386 be completely different objects. */
1387 value_free (b
->val
);
1391 /* Note that unlike with breakpoints, the watchpoint's condition
1392 expression is stored in the breakpoint object, not in the
1393 locations (re)created below. */
1394 if (b
->cond_string
!= NULL
)
1396 if (b
->cond_exp
!= NULL
)
1398 xfree (b
->cond_exp
);
1403 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1407 /* If we failed to parse the expression, for example because
1408 it refers to a global variable in a not-yet-loaded shared library,
1409 don't try to insert watchpoint. We don't automatically delete
1410 such watchpoint, though, since failure to parse expression
1411 is different from out-of-scope watchpoint. */
1412 if ( !target_has_execution
)
1414 /* Without execution, memory can't change. No use to try and
1415 set watchpoint locations. The watchpoint will be reset when
1416 the target gains execution, through breakpoint_re_set. */
1418 else if (within_current_scope
&& b
->exp
)
1420 struct value
*val_chain
, *v
, *result
, *next
;
1421 struct program_space
*frame_pspace
;
1423 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1425 /* Avoid setting b->val if it's already set. The meaning of
1426 b->val is 'the last value' user saw, and we should update
1427 it only if we reported that last value to user. As it
1428 happens, the code that reports it updates b->val directly. */
1435 /* Change the type of breakpoint between hardware assisted or an
1436 ordinary watchpoint depending on the hardware support and free
1437 hardware slots. REPARSE is set when the inferior is started. */
1438 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1441 int i
, mem_cnt
, other_type_used
;
1443 /* We need to determine how many resources are already used
1444 for all other hardware watchpoints to see if we still have
1445 enough resources to also fit this watchpoint in as well.
1446 To avoid the hw_watchpoint_used_count call below from counting
1447 this watchpoint, make sure that it is marked as a software
1449 b
->type
= bp_watchpoint
;
1450 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1452 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1455 b
->type
= bp_watchpoint
;
1458 int target_resources_ok
= target_can_use_hardware_watchpoint
1459 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1460 if (target_resources_ok
<= 0)
1461 b
->type
= bp_watchpoint
;
1463 b
->type
= bp_hardware_watchpoint
;
1467 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1469 /* Look at each value on the value chain. */
1470 for (v
= val_chain
; v
; v
= next
)
1472 /* If it's a memory location, and GDB actually needed
1473 its contents to evaluate the expression, then we
1474 must watch it. If the first value returned is
1475 still lazy, that means an error occurred reading it;
1476 watch it anyway in case it becomes readable. */
1477 if (VALUE_LVAL (v
) == lval_memory
1478 && (v
== val_chain
|| ! value_lazy (v
)))
1480 struct type
*vtype
= check_typedef (value_type (v
));
1482 /* We only watch structs and arrays if user asked
1483 for it explicitly, never if they just happen to
1484 appear in the middle of some value chain. */
1486 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1487 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1491 struct bp_location
*loc
, **tmp
;
1493 addr
= value_address (v
);
1494 len
= TYPE_LENGTH (value_type (v
));
1496 if (b
->type
== bp_read_watchpoint
)
1498 else if (b
->type
== bp_access_watchpoint
)
1501 loc
= allocate_bp_location (b
);
1502 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1505 loc
->gdbarch
= get_type_arch (value_type (v
));
1507 loc
->pspace
= frame_pspace
;
1508 loc
->address
= addr
;
1510 loc
->watchpoint_type
= type
;
1514 next
= value_next (v
);
1519 /* If a software watchpoint is not watching any memory, then the
1520 above left it without any location set up. But,
1521 bpstat_stop_status requires a location to be able to report
1522 stops, so make sure there's at least a dummy one. */
1523 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1525 b
->loc
= allocate_bp_location (b
);
1526 b
->loc
->pspace
= frame_pspace
;
1527 b
->loc
->address
= -1;
1528 b
->loc
->length
= -1;
1529 b
->loc
->watchpoint_type
= -1;
1532 else if (!within_current_scope
)
1534 printf_filtered (_("\
1535 Watchpoint %d deleted because the program has left the block \n\
1536 in which its expression is valid.\n"),
1538 if (b
->related_breakpoint
)
1540 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1541 b
->related_breakpoint
->related_breakpoint
= NULL
;
1542 b
->related_breakpoint
= NULL
;
1544 b
->disposition
= disp_del_at_next_stop
;
1547 /* Restore the selected frame. */
1549 select_frame (frame_find_by_id (saved_frame_id
));
1553 /* Returns 1 iff breakpoint location should be
1554 inserted in the inferior. */
1556 should_be_inserted (struct bp_location
*bpt
)
1558 if (!breakpoint_enabled (bpt
->owner
))
1561 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1564 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1567 /* This is set for example, when we're attached to the parent of a
1568 vfork, and have detached from the child. The child is running
1569 free, and we expect it to do an exec or exit, at which point the
1570 OS makes the parent schedulable again (and the target reports
1571 that the vfork is done). Until the child is done with the shared
1572 memory region, do not insert breakpoints in the parent, otherwise
1573 the child could still trip on the parent's breakpoints. Since
1574 the parent is blocked anyway, it won't miss any breakpoint. */
1575 if (bpt
->pspace
->breakpoints_not_allowed
)
1578 /* Tracepoints are inserted by the target at a time of its choosing,
1580 if (is_tracepoint (bpt
->owner
))
1586 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1587 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1588 and HW_BREAKPOINT_ERROR are used to report problems.
1590 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1591 method for each breakpoint or catchpoint type. */
1593 insert_bp_location (struct bp_location
*bpt
,
1594 struct ui_file
*tmp_error_stream
,
1595 int *disabled_breaks
,
1596 int *hw_breakpoint_error
)
1600 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1603 /* Initialize the target-specific information. */
1604 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1605 bpt
->target_info
.placed_address
= bpt
->address
;
1606 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1608 if (bpt
->loc_type
== bp_loc_software_breakpoint
1609 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1611 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1613 /* If the explicitly specified breakpoint type
1614 is not hardware breakpoint, check the memory map to see
1615 if the breakpoint address is in read only memory or not.
1616 Two important cases are:
1617 - location type is not hardware breakpoint, memory
1618 is readonly. We change the type of the location to
1619 hardware breakpoint.
1620 - location type is hardware breakpoint, memory is read-write.
1621 This means we've previously made the location hardware one, but
1622 then the memory map changed, so we undo.
1624 When breakpoints are removed, remove_breakpoints will
1625 use location types we've just set here, the only possible
1626 problem is that memory map has changed during running program,
1627 but it's not going to work anyway with current gdb. */
1628 struct mem_region
*mr
1629 = lookup_mem_region (bpt
->target_info
.placed_address
);
1633 if (automatic_hardware_breakpoints
)
1636 enum bp_loc_type new_type
;
1638 if (mr
->attrib
.mode
!= MEM_RW
)
1639 new_type
= bp_loc_hardware_breakpoint
;
1641 new_type
= bp_loc_software_breakpoint
;
1643 if (new_type
!= bpt
->loc_type
)
1645 static int said
= 0;
1646 bpt
->loc_type
= new_type
;
1649 fprintf_filtered (gdb_stdout
, _("\
1650 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1655 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1656 && mr
->attrib
.mode
!= MEM_RW
)
1657 warning (_("cannot set software breakpoint at readonly address %s"),
1658 paddress (bpt
->gdbarch
, bpt
->address
));
1662 /* First check to see if we have to handle an overlay. */
1663 if (overlay_debugging
== ovly_off
1664 || bpt
->section
== NULL
1665 || !(section_is_overlay (bpt
->section
)))
1667 /* No overlay handling: just set the breakpoint. */
1669 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1670 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1673 val
= target_insert_breakpoint (bpt
->gdbarch
,
1678 /* This breakpoint is in an overlay section.
1679 Shall we set a breakpoint at the LMA? */
1680 if (!overlay_events_enabled
)
1682 /* Yes -- overlay event support is not active,
1683 so we must try to set a breakpoint at the LMA.
1684 This will not work for a hardware breakpoint. */
1685 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1686 warning (_("hardware breakpoint %d not supported in overlay!"),
1687 bpt
->owner
->number
);
1690 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1692 /* Set a software (trap) breakpoint at the LMA. */
1693 bpt
->overlay_target_info
= bpt
->target_info
;
1694 bpt
->overlay_target_info
.placed_address
= addr
;
1695 val
= target_insert_breakpoint (bpt
->gdbarch
,
1696 &bpt
->overlay_target_info
);
1698 fprintf_unfiltered (tmp_error_stream
,
1699 "Overlay breakpoint %d failed: in ROM?\n",
1700 bpt
->owner
->number
);
1703 /* Shall we set a breakpoint at the VMA? */
1704 if (section_is_mapped (bpt
->section
))
1706 /* Yes. This overlay section is mapped into memory. */
1707 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1708 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1711 val
= target_insert_breakpoint (bpt
->gdbarch
,
1716 /* No. This breakpoint will not be inserted.
1717 No error, but do not mark the bp as 'inserted'. */
1724 /* Can't set the breakpoint. */
1725 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1727 /* See also: disable_breakpoints_in_shlibs. */
1729 bpt
->shlib_disabled
= 1;
1730 if (!*disabled_breaks
)
1732 fprintf_unfiltered (tmp_error_stream
,
1733 "Cannot insert breakpoint %d.\n",
1734 bpt
->owner
->number
);
1735 fprintf_unfiltered (tmp_error_stream
,
1736 "Temporarily disabling shared library breakpoints:\n");
1738 *disabled_breaks
= 1;
1739 fprintf_unfiltered (tmp_error_stream
,
1740 "breakpoint #%d\n", bpt
->owner
->number
);
1744 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1746 *hw_breakpoint_error
= 1;
1747 fprintf_unfiltered (tmp_error_stream
,
1748 "Cannot insert hardware breakpoint %d.\n",
1749 bpt
->owner
->number
);
1753 fprintf_unfiltered (tmp_error_stream
,
1754 "Cannot insert breakpoint %d.\n",
1755 bpt
->owner
->number
);
1756 fprintf_filtered (tmp_error_stream
,
1757 "Error accessing memory address ");
1758 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1760 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1761 safe_strerror (val
));
1772 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1773 /* NOTE drow/2003-09-08: This state only exists for removing
1774 watchpoints. It's not clear that it's necessary... */
1775 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1777 val
= target_insert_watchpoint (bpt
->address
,
1779 bpt
->watchpoint_type
);
1781 /* If trying to set a read-watchpoint, and it turns out it's not
1782 supported, try emulating one with an access watchpoint. */
1783 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1785 struct bp_location
*loc
, **loc_temp
;
1787 /* But don't try to insert it, if there's already another
1788 hw_access location that would be considered a duplicate
1790 ALL_BP_LOCATIONS (loc
, loc_temp
)
1792 && loc
->watchpoint_type
== hw_access
1793 && watchpoint_locations_match (bpt
, loc
))
1797 bpt
->target_info
= loc
->target_info
;
1798 bpt
->watchpoint_type
= hw_access
;
1805 val
= target_insert_watchpoint (bpt
->address
,
1809 bpt
->watchpoint_type
= hw_access
;
1813 bpt
->inserted
= (val
== 0);
1816 else if (bpt
->owner
->type
== bp_catchpoint
)
1818 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1819 bpt
->owner
, RETURN_MASK_ERROR
);
1820 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1821 bpt
->owner
->number
);
1823 bpt
->owner
->enable_state
= bp_disabled
;
1827 /* We've already printed an error message if there was a problem
1828 inserting this catchpoint, and we've disabled the catchpoint,
1829 so just return success. */
1836 /* This function is called when program space PSPACE is about to be
1837 deleted. It takes care of updating breakpoints to not reference
1841 breakpoint_program_space_exit (struct program_space
*pspace
)
1843 struct breakpoint
*b
, *b_temp
;
1844 struct bp_location
*loc
, **loc_temp
;
1846 /* Remove any breakpoint that was set through this program space. */
1847 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1849 if (b
->pspace
== pspace
)
1850 delete_breakpoint (b
);
1853 /* Breakpoints set through other program spaces could have locations
1854 bound to PSPACE as well. Remove those. */
1855 ALL_BP_LOCATIONS (loc
, loc_temp
)
1857 struct bp_location
*tmp
;
1859 if (loc
->pspace
== pspace
)
1861 if (loc
->owner
->loc
== loc
)
1862 loc
->owner
->loc
= loc
->next
;
1864 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1865 if (tmp
->next
== loc
)
1867 tmp
->next
= loc
->next
;
1873 /* Now update the global location list to permanently delete the
1874 removed locations above. */
1875 update_global_location_list (0);
1878 /* Make sure all breakpoints are inserted in inferior.
1879 Throws exception on any error.
1880 A breakpoint that is already inserted won't be inserted
1881 again, so calling this function twice is safe. */
1883 insert_breakpoints (void)
1885 struct breakpoint
*bpt
;
1887 ALL_BREAKPOINTS (bpt
)
1888 if (is_hardware_watchpoint (bpt
))
1889 update_watchpoint (bpt
, 0 /* don't reparse. */);
1891 update_global_location_list (1);
1893 /* update_global_location_list does not insert breakpoints when
1894 always_inserted_mode is not enabled. Explicitly insert them
1896 if (!breakpoints_always_inserted_mode ())
1897 insert_breakpoint_locations ();
1900 /* insert_breakpoints is used when starting or continuing the program.
1901 remove_breakpoints is used when the program stops.
1902 Both return zero if successful,
1903 or an `errno' value if could not write the inferior. */
1906 insert_breakpoint_locations (void)
1908 struct breakpoint
*bpt
;
1909 struct bp_location
*b
, **bp_tmp
;
1912 int disabled_breaks
= 0;
1913 int hw_breakpoint_error
= 0;
1915 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1916 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1918 /* Explicitly mark the warning -- this will only be printed if
1919 there was an error. */
1920 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1922 save_current_space_and_thread ();
1924 ALL_BP_LOCATIONS (b
, bp_tmp
)
1926 struct thread_info
*tp
;
1927 CORE_ADDR last_addr
;
1929 if (!should_be_inserted (b
) || b
->inserted
)
1932 /* There is no point inserting thread-specific breakpoints if the
1933 thread no longer exists. */
1934 if (b
->owner
->thread
!= -1
1935 && !valid_thread_id (b
->owner
->thread
))
1938 switch_to_program_space_and_thread (b
->pspace
);
1940 /* For targets that support global breakpoints, there's no need
1941 to select an inferior to insert breakpoint to. In fact, even
1942 if we aren't attached to any process yet, we should still
1943 insert breakpoints. */
1944 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1945 && ptid_equal (inferior_ptid
, null_ptid
))
1948 val
= insert_bp_location (b
, tmp_error_stream
,
1950 &hw_breakpoint_error
);
1955 /* If we failed to insert all locations of a watchpoint,
1956 remove them, as half-inserted watchpoint is of limited use. */
1957 ALL_BREAKPOINTS (bpt
)
1959 int some_failed
= 0;
1960 struct bp_location
*loc
;
1962 if (!is_hardware_watchpoint (bpt
))
1965 if (!breakpoint_enabled (bpt
))
1968 if (bpt
->disposition
== disp_del_at_next_stop
)
1971 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1972 if (!loc
->inserted
&& should_be_inserted (loc
))
1979 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1981 remove_breakpoint (loc
, mark_uninserted
);
1983 hw_breakpoint_error
= 1;
1984 fprintf_unfiltered (tmp_error_stream
,
1985 "Could not insert hardware watchpoint %d.\n",
1993 /* If a hardware breakpoint or watchpoint was inserted, add a
1994 message about possibly exhausted resources. */
1995 if (hw_breakpoint_error
)
1997 fprintf_unfiltered (tmp_error_stream
,
1998 "Could not insert hardware breakpoints:\n\
1999 You may have requested too many hardware breakpoints/watchpoints.\n");
2001 target_terminal_ours_for_output ();
2002 error_stream (tmp_error_stream
);
2005 do_cleanups (cleanups
);
2009 remove_breakpoints (void)
2011 struct bp_location
*b
, **bp_tmp
;
2014 ALL_BP_LOCATIONS (b
, bp_tmp
)
2017 val
|= remove_breakpoint (b
, mark_uninserted
);
2022 /* Remove breakpoints of process PID. */
2025 remove_breakpoints_pid (int pid
)
2027 struct bp_location
*b
, **b_tmp
;
2029 struct inferior
*inf
= find_inferior_pid (pid
);
2031 ALL_BP_LOCATIONS (b
, b_tmp
)
2033 if (b
->pspace
!= inf
->pspace
)
2038 val
= remove_breakpoint (b
, mark_uninserted
);
2047 remove_hw_watchpoints (void)
2049 struct bp_location
*b
, **bp_tmp
;
2052 ALL_BP_LOCATIONS (b
, bp_tmp
)
2054 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2055 val
|= remove_breakpoint (b
, mark_uninserted
);
2061 reattach_breakpoints (int pid
)
2063 struct cleanup
*old_chain
;
2064 struct bp_location
*b
, **bp_tmp
;
2066 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2067 int dummy1
= 0, dummy2
= 0;
2068 struct inferior
*inf
;
2069 struct thread_info
*tp
;
2071 tp
= any_live_thread_of_process (pid
);
2075 inf
= find_inferior_pid (pid
);
2076 old_chain
= save_inferior_ptid ();
2078 inferior_ptid
= tp
->ptid
;
2080 make_cleanup_ui_file_delete (tmp_error_stream
);
2082 ALL_BP_LOCATIONS (b
, bp_tmp
)
2084 if (b
->pspace
!= inf
->pspace
)
2090 val
= insert_bp_location (b
, tmp_error_stream
,
2094 do_cleanups (old_chain
);
2099 do_cleanups (old_chain
);
2103 static int internal_breakpoint_number
= -1;
2105 static struct breakpoint
*
2106 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2107 CORE_ADDR address
, enum bptype type
)
2109 struct symtab_and_line sal
;
2110 struct breakpoint
*b
;
2112 init_sal (&sal
); /* initialize to zeroes */
2115 sal
.section
= find_pc_overlay (sal
.pc
);
2116 sal
.pspace
= current_program_space
;
2118 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2119 b
->number
= internal_breakpoint_number
--;
2120 b
->disposition
= disp_donttouch
;
2126 create_overlay_event_breakpoint (char *func_name
)
2128 struct objfile
*objfile
;
2130 ALL_OBJFILES (objfile
)
2132 struct breakpoint
*b
;
2133 struct minimal_symbol
*m
;
2135 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2139 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2140 SYMBOL_VALUE_ADDRESS (m
),
2142 b
->addr_string
= xstrdup (func_name
);
2144 if (overlay_debugging
== ovly_auto
)
2146 b
->enable_state
= bp_enabled
;
2147 overlay_events_enabled
= 1;
2151 b
->enable_state
= bp_disabled
;
2152 overlay_events_enabled
= 0;
2155 update_global_location_list (1);
2159 create_longjmp_master_breakpoint (char *func_name
)
2161 struct program_space
*pspace
;
2162 struct objfile
*objfile
;
2163 struct cleanup
*old_chain
;
2165 old_chain
= save_current_program_space ();
2167 ALL_PSPACES (pspace
)
2168 ALL_OBJFILES (objfile
)
2170 struct breakpoint
*b
;
2171 struct minimal_symbol
*m
;
2173 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2176 set_current_program_space (pspace
);
2178 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2182 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2183 SYMBOL_VALUE_ADDRESS (m
),
2185 b
->addr_string
= xstrdup (func_name
);
2186 b
->enable_state
= bp_disabled
;
2188 update_global_location_list (1);
2190 do_cleanups (old_chain
);
2193 /* Create a master std::terminate breakpoint. The actual function
2194 looked for is named FUNC_NAME. */
2196 create_std_terminate_master_breakpoint (const char *func_name
)
2198 struct program_space
*pspace
;
2199 struct objfile
*objfile
;
2200 struct cleanup
*old_chain
;
2202 old_chain
= save_current_program_space ();
2204 ALL_PSPACES (pspace
)
2205 ALL_OBJFILES (objfile
)
2207 struct breakpoint
*b
;
2208 struct minimal_symbol
*m
;
2210 set_current_program_space (pspace
);
2212 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2213 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2214 && MSYMBOL_TYPE (m
) != mst_file_text
))
2217 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2218 SYMBOL_VALUE_ADDRESS (m
),
2219 bp_std_terminate_master
);
2220 b
->addr_string
= xstrdup (func_name
);
2221 b
->enable_state
= bp_disabled
;
2223 update_global_location_list (1);
2225 do_cleanups (old_chain
);
2229 update_breakpoints_after_exec (void)
2231 struct breakpoint
*b
;
2232 struct breakpoint
*temp
;
2233 struct bp_location
*bploc
, **bplocp_tmp
;
2235 /* We're about to delete breakpoints from GDB's lists. If the
2236 INSERTED flag is true, GDB will try to lift the breakpoints by
2237 writing the breakpoints' "shadow contents" back into memory. The
2238 "shadow contents" are NOT valid after an exec, so GDB should not
2239 do that. Instead, the target is responsible from marking
2240 breakpoints out as soon as it detects an exec. We don't do that
2241 here instead, because there may be other attempts to delete
2242 breakpoints after detecting an exec and before reaching here. */
2243 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2244 if (bploc
->pspace
== current_program_space
)
2245 gdb_assert (!bploc
->inserted
);
2247 ALL_BREAKPOINTS_SAFE (b
, temp
)
2249 if (b
->pspace
!= current_program_space
)
2252 /* Solib breakpoints must be explicitly reset after an exec(). */
2253 if (b
->type
== bp_shlib_event
)
2255 delete_breakpoint (b
);
2259 /* JIT breakpoints must be explicitly reset after an exec(). */
2260 if (b
->type
== bp_jit_event
)
2262 delete_breakpoint (b
);
2266 /* Thread event breakpoints must be set anew after an exec(),
2267 as must overlay event and longjmp master breakpoints. */
2268 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2269 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2271 delete_breakpoint (b
);
2275 /* Step-resume breakpoints are meaningless after an exec(). */
2276 if (b
->type
== bp_step_resume
)
2278 delete_breakpoint (b
);
2282 /* Longjmp and longjmp-resume breakpoints are also meaningless
2284 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2286 delete_breakpoint (b
);
2290 if (b
->type
== bp_catchpoint
)
2292 /* For now, none of the bp_catchpoint breakpoints need to
2293 do anything at this point. In the future, if some of
2294 the catchpoints need to something, we will need to add
2295 a new method, and call this method from here. */
2299 /* bp_finish is a special case. The only way we ought to be able
2300 to see one of these when an exec() has happened, is if the user
2301 caught a vfork, and then said "finish". Ordinarily a finish just
2302 carries them to the call-site of the current callee, by setting
2303 a temporary bp there and resuming. But in this case, the finish
2304 will carry them entirely through the vfork & exec.
2306 We don't want to allow a bp_finish to remain inserted now. But
2307 we can't safely delete it, 'cause finish_command has a handle to
2308 the bp on a bpstat, and will later want to delete it. There's a
2309 chance (and I've seen it happen) that if we delete the bp_finish
2310 here, that its storage will get reused by the time finish_command
2311 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2312 We really must allow finish_command to delete a bp_finish.
2314 In the absense of a general solution for the "how do we know
2315 it's safe to delete something others may have handles to?"
2316 problem, what we'll do here is just uninsert the bp_finish, and
2317 let finish_command delete it.
2319 (We know the bp_finish is "doomed" in the sense that it's
2320 momentary, and will be deleted as soon as finish_command sees
2321 the inferior stopped. So it doesn't matter that the bp's
2322 address is probably bogus in the new a.out, unlike e.g., the
2323 solib breakpoints.) */
2325 if (b
->type
== bp_finish
)
2330 /* Without a symbolic address, we have little hope of the
2331 pre-exec() address meaning the same thing in the post-exec()
2333 if (b
->addr_string
== NULL
)
2335 delete_breakpoint (b
);
2339 /* FIXME what about longjmp breakpoints? Re-create them here? */
2340 create_overlay_event_breakpoint ("_ovly_debug_event");
2341 create_longjmp_master_breakpoint ("longjmp");
2342 create_longjmp_master_breakpoint ("_longjmp");
2343 create_longjmp_master_breakpoint ("siglongjmp");
2344 create_longjmp_master_breakpoint ("_siglongjmp");
2345 create_std_terminate_master_breakpoint ("std::terminate()");
2349 detach_breakpoints (int pid
)
2351 struct bp_location
*b
, **bp_tmp
;
2353 struct cleanup
*old_chain
= save_inferior_ptid ();
2354 struct inferior
*inf
= current_inferior ();
2356 if (pid
== PIDGET (inferior_ptid
))
2357 error (_("Cannot detach breakpoints of inferior_ptid"));
2359 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2360 inferior_ptid
= pid_to_ptid (pid
);
2361 ALL_BP_LOCATIONS (b
, bp_tmp
)
2363 if (b
->pspace
!= inf
->pspace
)
2367 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2369 do_cleanups (old_chain
);
2373 /* Remove the breakpoint location B from the current address space.
2374 Note that this is used to detach breakpoints from a child fork.
2375 When we get here, the child isn't in the inferior list, and neither
2376 do we have objects to represent its address space --- we should
2377 *not* look at b->pspace->aspace here. */
2380 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2383 struct cleanup
*old_chain
;
2385 if (b
->owner
->enable_state
== bp_permanent
)
2386 /* Permanent breakpoints cannot be inserted or removed. */
2389 /* The type of none suggests that owner is actually deleted.
2390 This should not ever happen. */
2391 gdb_assert (b
->owner
->type
!= bp_none
);
2393 if (b
->loc_type
== bp_loc_software_breakpoint
2394 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2396 /* "Normal" instruction breakpoint: either the standard
2397 trap-instruction bp (bp_breakpoint), or a
2398 bp_hardware_breakpoint. */
2400 /* First check to see if we have to handle an overlay. */
2401 if (overlay_debugging
== ovly_off
2402 || b
->section
== NULL
2403 || !(section_is_overlay (b
->section
)))
2405 /* No overlay handling: just remove the breakpoint. */
2407 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2408 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2410 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2414 /* This breakpoint is in an overlay section.
2415 Did we set a breakpoint at the LMA? */
2416 if (!overlay_events_enabled
)
2418 /* Yes -- overlay event support is not active, so we
2419 should have set a breakpoint at the LMA. Remove it.
2421 /* Ignore any failures: if the LMA is in ROM, we will
2422 have already warned when we failed to insert it. */
2423 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2424 target_remove_hw_breakpoint (b
->gdbarch
,
2425 &b
->overlay_target_info
);
2427 target_remove_breakpoint (b
->gdbarch
,
2428 &b
->overlay_target_info
);
2430 /* Did we set a breakpoint at the VMA?
2431 If so, we will have marked the breakpoint 'inserted'. */
2434 /* Yes -- remove it. Previously we did not bother to
2435 remove the breakpoint if the section had been
2436 unmapped, but let's not rely on that being safe. We
2437 don't know what the overlay manager might do. */
2438 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2439 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2442 /* However, we should remove *software* breakpoints only
2443 if the section is still mapped, or else we overwrite
2444 wrong code with the saved shadow contents. */
2445 else if (section_is_mapped (b
->section
))
2446 val
= target_remove_breakpoint (b
->gdbarch
,
2453 /* No -- not inserted, so no need to remove. No error. */
2458 /* In some cases, we might not be able to remove a breakpoint
2459 in a shared library that has already been removed, but we
2460 have not yet processed the shlib unload event. */
2461 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2466 b
->inserted
= (is
== mark_inserted
);
2468 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2473 b
->inserted
= (is
== mark_inserted
);
2474 val
= target_remove_watchpoint (b
->address
, b
->length
,
2475 b
->watchpoint_type
);
2477 /* Failure to remove any of the hardware watchpoints comes here. */
2478 if ((is
== mark_uninserted
) && (b
->inserted
))
2479 warning (_("Could not remove hardware watchpoint %d."),
2482 else if (b
->owner
->type
== bp_catchpoint
2483 && breakpoint_enabled (b
->owner
)
2486 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2488 val
= b
->owner
->ops
->remove (b
->owner
);
2491 b
->inserted
= (is
== mark_inserted
);
2498 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2501 struct cleanup
*old_chain
;
2503 if (b
->owner
->enable_state
== bp_permanent
)
2504 /* Permanent breakpoints cannot be inserted or removed. */
2507 /* The type of none suggests that owner is actually deleted.
2508 This should not ever happen. */
2509 gdb_assert (b
->owner
->type
!= bp_none
);
2511 old_chain
= save_current_space_and_thread ();
2513 switch_to_program_space_and_thread (b
->pspace
);
2515 ret
= remove_breakpoint_1 (b
, is
);
2517 do_cleanups (old_chain
);
2521 /* Clear the "inserted" flag in all breakpoints. */
2524 mark_breakpoints_out (void)
2526 struct bp_location
*bpt
, **bptp_tmp
;
2528 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2529 if (bpt
->pspace
== current_program_space
)
2533 /* Clear the "inserted" flag in all breakpoints and delete any
2534 breakpoints which should go away between runs of the program.
2536 Plus other such housekeeping that has to be done for breakpoints
2539 Note: this function gets called at the end of a run (by
2540 generic_mourn_inferior) and when a run begins (by
2541 init_wait_for_inferior). */
2546 breakpoint_init_inferior (enum inf_context context
)
2548 struct breakpoint
*b
, *temp
;
2549 struct bp_location
*bpt
, **bptp_tmp
;
2551 struct program_space
*pspace
= current_program_space
;
2553 /* If breakpoint locations are shared across processes, then there's
2555 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2558 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2560 if (bpt
->pspace
== pspace
2561 && bpt
->owner
->enable_state
!= bp_permanent
)
2565 ALL_BREAKPOINTS_SAFE (b
, temp
)
2567 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2574 /* If the call dummy breakpoint is at the entry point it will
2575 cause problems when the inferior is rerun, so we better get
2578 case bp_watchpoint_scope
:
2580 /* Also get rid of scope breakpoints. */
2582 case bp_shlib_event
:
2584 /* Also remove solib event breakpoints. Their addresses may
2585 have changed since the last time we ran the program.
2586 Actually we may now be debugging against different target;
2587 and so the solib backend that installed this breakpoint may
2588 not be used in by the target. E.g.,
2590 (gdb) file prog-linux
2591 (gdb) run # native linux target
2594 (gdb) file prog-win.exe
2595 (gdb) tar rem :9999 # remote Windows gdbserver.
2598 delete_breakpoint (b
);
2602 case bp_hardware_watchpoint
:
2603 case bp_read_watchpoint
:
2604 case bp_access_watchpoint
:
2606 /* Likewise for watchpoints on local expressions. */
2607 if (b
->exp_valid_block
!= NULL
)
2608 delete_breakpoint (b
);
2609 else if (context
== inf_starting
)
2611 /* Reset val field to force reread of starting value
2612 in insert_breakpoints. */
2614 value_free (b
->val
);
2624 /* Get rid of the moribund locations. */
2625 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2626 free_bp_location (bpt
);
2627 VEC_free (bp_location_p
, moribund_locations
);
2630 /* These functions concern about actual breakpoints inserted in the
2631 target --- to e.g. check if we need to do decr_pc adjustment or if
2632 we need to hop over the bkpt --- so we check for address space
2633 match, not program space. */
2635 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2636 exists at PC. It returns ordinary_breakpoint_here if it's an
2637 ordinary breakpoint, or permanent_breakpoint_here if it's a
2638 permanent breakpoint.
2639 - When continuing from a location with an ordinary breakpoint, we
2640 actually single step once before calling insert_breakpoints.
2641 - When continuing from a localion with a permanent breakpoint, we
2642 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2643 the target, to advance the PC past the breakpoint. */
2645 enum breakpoint_here
2646 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2648 struct bp_location
*bpt
, **bptp_tmp
;
2649 int any_breakpoint_here
= 0;
2651 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2653 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2654 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2657 if ((breakpoint_enabled (bpt
->owner
)
2658 || bpt
->owner
->enable_state
== bp_permanent
)
2659 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2662 if (overlay_debugging
2663 && section_is_overlay (bpt
->section
)
2664 && !section_is_mapped (bpt
->section
))
2665 continue; /* unmapped overlay -- can't be a match */
2666 else if (bpt
->owner
->enable_state
== bp_permanent
)
2667 return permanent_breakpoint_here
;
2669 any_breakpoint_here
= 1;
2673 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2676 /* Return true if there's a moribund breakpoint at PC. */
2679 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2681 struct bp_location
*loc
;
2684 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2685 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2692 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2693 inserted using regular breakpoint_chain / bp_location array mechanism.
2694 This does not check for single-step breakpoints, which are
2695 inserted and removed using direct target manipulation. */
2698 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2700 struct bp_location
*bpt
, **bptp_tmp
;
2702 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2704 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2705 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2709 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2712 if (overlay_debugging
2713 && section_is_overlay (bpt
->section
)
2714 && !section_is_mapped (bpt
->section
))
2715 continue; /* unmapped overlay -- can't be a match */
2723 /* Returns non-zero iff there's either regular breakpoint
2724 or a single step breakpoint inserted at PC. */
2727 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2729 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2732 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2738 /* This function returns non-zero iff there is a software breakpoint
2742 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2744 struct bp_location
*bpt
, **bptp_tmp
;
2745 int any_breakpoint_here
= 0;
2747 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2749 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2753 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2756 if (overlay_debugging
2757 && section_is_overlay (bpt
->section
)
2758 && !section_is_mapped (bpt
->section
))
2759 continue; /* unmapped overlay -- can't be a match */
2765 /* Also check for software single-step breakpoints. */
2766 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2773 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2774 CORE_ADDR addr
, ULONGEST len
)
2776 struct breakpoint
*bpt
;
2778 ALL_BREAKPOINTS (bpt
)
2780 struct bp_location
*loc
;
2782 if (bpt
->type
!= bp_hardware_watchpoint
2783 && bpt
->type
!= bp_access_watchpoint
)
2786 if (!breakpoint_enabled (bpt
))
2789 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2790 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2794 /* Check for intersection. */
2795 l
= max (loc
->address
, addr
);
2796 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2804 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2805 PC is valid for process/thread PTID. */
2808 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2811 struct bp_location
*bpt
, **bptp_tmp
;
2812 /* The thread and task IDs associated to PTID, computed lazily. */
2816 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2818 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2819 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2822 if (!breakpoint_enabled (bpt
->owner
)
2823 && bpt
->owner
->enable_state
!= bp_permanent
)
2826 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2830 if (bpt
->owner
->thread
!= -1)
2832 /* This is a thread-specific breakpoint. Check that ptid
2833 matches that thread. If thread hasn't been computed yet,
2834 it is now time to do so. */
2836 thread
= pid_to_thread_id (ptid
);
2837 if (bpt
->owner
->thread
!= thread
)
2841 if (bpt
->owner
->task
!= 0)
2843 /* This is a task-specific breakpoint. Check that ptid
2844 matches that task. If task hasn't been computed yet,
2845 it is now time to do so. */
2847 task
= ada_get_task_number (ptid
);
2848 if (bpt
->owner
->task
!= task
)
2852 if (overlay_debugging
2853 && section_is_overlay (bpt
->section
)
2854 && !section_is_mapped (bpt
->section
))
2855 continue; /* unmapped overlay -- can't be a match */
2864 /* bpstat stuff. External routines' interfaces are documented
2868 ep_is_catchpoint (struct breakpoint
*ep
)
2870 return (ep
->type
== bp_catchpoint
);
2874 bpstat_free (bpstat bs
)
2876 if (bs
->old_val
!= NULL
)
2877 value_free (bs
->old_val
);
2878 decref_counted_command_line (&bs
->commands
);
2882 /* Clear a bpstat so that it says we are not at any breakpoint.
2883 Also free any storage that is part of a bpstat. */
2886 bpstat_clear (bpstat
*bsp
)
2903 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2904 is part of the bpstat is copied as well. */
2907 bpstat_copy (bpstat bs
)
2911 bpstat retval
= NULL
;
2916 for (; bs
!= NULL
; bs
= bs
->next
)
2918 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2919 memcpy (tmp
, bs
, sizeof (*tmp
));
2920 incref_counted_command_line (tmp
->commands
);
2921 if (bs
->old_val
!= NULL
)
2923 tmp
->old_val
= value_copy (bs
->old_val
);
2924 release_value (tmp
->old_val
);
2928 /* This is the first thing in the chain. */
2938 /* Find the bpstat associated with this breakpoint */
2941 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2946 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2948 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2954 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2955 at. *BSP upon return is a bpstat which points to the remaining
2956 breakpoints stopped at (but which is not guaranteed to be good for
2957 anything but further calls to bpstat_num).
2958 Return 0 if passed a bpstat which does not indicate any breakpoints.
2959 Return -1 if stopped at a breakpoint that has been deleted since
2961 Return 1 otherwise. */
2964 bpstat_num (bpstat
*bsp
, int *num
)
2966 struct breakpoint
*b
;
2969 return 0; /* No more breakpoint values */
2971 /* We assume we'll never have several bpstats that
2972 correspond to a single breakpoint -- otherwise,
2973 this function might return the same number more
2974 than once and this will look ugly. */
2975 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2976 *bsp
= (*bsp
)->next
;
2978 return -1; /* breakpoint that's been deleted since */
2980 *num
= b
->number
; /* We have its number */
2984 /* Modify BS so that the actions will not be performed. */
2987 bpstat_clear_actions (bpstat bs
)
2989 for (; bs
!= NULL
; bs
= bs
->next
)
2991 decref_counted_command_line (&bs
->commands
);
2992 bs
->commands_left
= NULL
;
2993 if (bs
->old_val
!= NULL
)
2995 value_free (bs
->old_val
);
3001 /* Called when a command is about to proceed the inferior. */
3004 breakpoint_about_to_proceed (void)
3006 if (!ptid_equal (inferior_ptid
, null_ptid
))
3008 struct thread_info
*tp
= inferior_thread ();
3010 /* Allow inferior function calls in breakpoint commands to not
3011 interrupt the command list. When the call finishes
3012 successfully, the inferior will be standing at the same
3013 breakpoint as if nothing happened. */
3018 breakpoint_proceeded
= 1;
3021 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3023 cleanup_executing_breakpoints (void *ignore
)
3025 executing_breakpoint_commands
= 0;
3028 /* Execute all the commands associated with all the breakpoints at this
3029 location. Any of these commands could cause the process to proceed
3030 beyond this point, etc. We look out for such changes by checking
3031 the global "breakpoint_proceeded" after each command.
3033 Returns true if a breakpoint command resumed the inferior. In that
3034 case, it is the caller's responsibility to recall it again with the
3035 bpstat of the current thread. */
3038 bpstat_do_actions_1 (bpstat
*bsp
)
3041 struct cleanup
*old_chain
;
3044 /* Avoid endless recursion if a `source' command is contained
3046 if (executing_breakpoint_commands
)
3049 executing_breakpoint_commands
= 1;
3050 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3052 /* This pointer will iterate over the list of bpstat's. */
3055 breakpoint_proceeded
= 0;
3056 for (; bs
!= NULL
; bs
= bs
->next
)
3058 struct counted_command_line
*ccmd
;
3059 struct command_line
*cmd
;
3060 struct cleanup
*this_cmd_tree_chain
;
3062 /* Take ownership of the BSP's command tree, if it has one.
3064 The command tree could legitimately contain commands like
3065 'step' and 'next', which call clear_proceed_status, which
3066 frees stop_bpstat's command tree. To make sure this doesn't
3067 free the tree we're executing out from under us, we need to
3068 take ownership of the tree ourselves. Since a given bpstat's
3069 commands are only executed once, we don't need to copy it; we
3070 can clear the pointer in the bpstat, and make sure we free
3071 the tree when we're done. */
3072 ccmd
= bs
->commands
;
3073 bs
->commands
= NULL
;
3075 = make_cleanup_decref_counted_command_line (&ccmd
);
3076 cmd
= bs
->commands_left
;
3077 bs
->commands_left
= NULL
;
3081 execute_control_command (cmd
);
3083 if (breakpoint_proceeded
)
3089 /* We can free this command tree now. */
3090 do_cleanups (this_cmd_tree_chain
);
3092 if (breakpoint_proceeded
)
3094 if (target_can_async_p ())
3095 /* If we are in async mode, then the target might be still
3096 running, not stopped at any breakpoint, so nothing for
3097 us to do here -- just return to the event loop. */
3100 /* In sync mode, when execute_control_command returns
3101 we're already standing on the next breakpoint.
3102 Breakpoint commands for that stop were not run, since
3103 execute_command does not run breakpoint commands --
3104 only command_line_handler does, but that one is not
3105 involved in execution of breakpoint commands. So, we
3106 can now execute breakpoint commands. It should be
3107 noted that making execute_command do bpstat actions is
3108 not an option -- in this case we'll have recursive
3109 invocation of bpstat for each breakpoint with a
3110 command, and can easily blow up GDB stack. Instead, we
3111 return true, which will trigger the caller to recall us
3112 with the new stop_bpstat. */
3117 do_cleanups (old_chain
);
3122 bpstat_do_actions (void)
3124 /* Do any commands attached to breakpoint we are stopped at. */
3125 while (!ptid_equal (inferior_ptid
, null_ptid
)
3126 && target_has_execution
3127 && !is_exited (inferior_ptid
)
3128 && !is_executing (inferior_ptid
))
3129 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3130 and only return when it is stopped at the next breakpoint, we
3131 keep doing breakpoint actions until it returns false to
3132 indicate the inferior was not resumed. */
3133 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3137 /* Print out the (old or new) value associated with a watchpoint. */
3140 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3143 fprintf_unfiltered (stream
, _("<unreadable>"));
3146 struct value_print_options opts
;
3147 get_user_print_options (&opts
);
3148 value_print (val
, stream
, &opts
);
3152 /* This is the normal print function for a bpstat. In the future,
3153 much of this logic could (should?) be moved to bpstat_stop_status,
3154 by having it set different print_it values.
3156 Current scheme: When we stop, bpstat_print() is called. It loops
3157 through the bpstat list of things causing this stop, calling the
3158 print_bp_stop_message function on each one. The behavior of the
3159 print_bp_stop_message function depends on the print_it field of
3160 bpstat. If such field so indicates, call this function here.
3162 Return values from this routine (ultimately used by bpstat_print()
3163 and normal_stop() to decide what to do):
3164 PRINT_NOTHING: Means we already printed all we needed to print,
3165 don't print anything else.
3166 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3167 that something to be followed by a location.
3168 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3169 that something to be followed by a location.
3170 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3173 static enum print_stop_action
3174 print_it_typical (bpstat bs
)
3176 struct cleanup
*old_chain
;
3177 struct breakpoint
*b
;
3178 const struct bp_location
*bl
;
3179 struct ui_stream
*stb
;
3181 enum print_stop_action result
;
3183 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3184 which has since been deleted. */
3185 if (bs
->breakpoint_at
== NULL
)
3186 return PRINT_UNKNOWN
;
3187 bl
= bs
->breakpoint_at
;
3190 stb
= ui_out_stream_new (uiout
);
3191 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3196 case bp_hardware_breakpoint
:
3197 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3198 if (bl
->address
!= bl
->requested_address
)
3199 breakpoint_adjustment_warning (bl
->requested_address
,
3202 annotate_breakpoint (b
->number
);
3204 ui_out_text (uiout
, "\nTemporary breakpoint ");
3206 ui_out_text (uiout
, "\nBreakpoint ");
3207 if (ui_out_is_mi_like_p (uiout
))
3209 ui_out_field_string (uiout
, "reason",
3210 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3211 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3213 ui_out_field_int (uiout
, "bkptno", b
->number
);
3214 ui_out_text (uiout
, ", ");
3215 result
= PRINT_SRC_AND_LOC
;
3218 case bp_shlib_event
:
3219 /* Did we stop because the user set the stop_on_solib_events
3220 variable? (If so, we report this as a generic, "Stopped due
3221 to shlib event" message.) */
3222 printf_filtered (_("Stopped due to shared library event\n"));
3223 result
= PRINT_NOTHING
;
3226 case bp_thread_event
:
3227 /* Not sure how we will get here.
3228 GDB should not stop for these breakpoints. */
3229 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3230 result
= PRINT_NOTHING
;
3233 case bp_overlay_event
:
3234 /* By analogy with the thread event, GDB should not stop for these. */
3235 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3236 result
= PRINT_NOTHING
;
3239 case bp_longjmp_master
:
3240 /* These should never be enabled. */
3241 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3242 result
= PRINT_NOTHING
;
3245 case bp_std_terminate_master
:
3246 /* These should never be enabled. */
3247 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3248 result
= PRINT_NOTHING
;
3252 case bp_hardware_watchpoint
:
3253 annotate_watchpoint (b
->number
);
3254 if (ui_out_is_mi_like_p (uiout
))
3257 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3259 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3260 ui_out_text (uiout
, "\nOld value = ");
3261 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3262 ui_out_field_stream (uiout
, "old", stb
);
3263 ui_out_text (uiout
, "\nNew value = ");
3264 watchpoint_value_print (b
->val
, stb
->stream
);
3265 ui_out_field_stream (uiout
, "new", stb
);
3266 ui_out_text (uiout
, "\n");
3267 /* More than one watchpoint may have been triggered. */
3268 result
= PRINT_UNKNOWN
;
3271 case bp_read_watchpoint
:
3272 if (ui_out_is_mi_like_p (uiout
))
3275 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3277 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3278 ui_out_text (uiout
, "\nValue = ");
3279 watchpoint_value_print (b
->val
, stb
->stream
);
3280 ui_out_field_stream (uiout
, "value", stb
);
3281 ui_out_text (uiout
, "\n");
3282 result
= PRINT_UNKNOWN
;
3285 case bp_access_watchpoint
:
3286 if (bs
->old_val
!= NULL
)
3288 annotate_watchpoint (b
->number
);
3289 if (ui_out_is_mi_like_p (uiout
))
3292 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3294 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3295 ui_out_text (uiout
, "\nOld value = ");
3296 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3297 ui_out_field_stream (uiout
, "old", stb
);
3298 ui_out_text (uiout
, "\nNew value = ");
3303 if (ui_out_is_mi_like_p (uiout
))
3306 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3307 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3308 ui_out_text (uiout
, "\nValue = ");
3310 watchpoint_value_print (b
->val
, stb
->stream
);
3311 ui_out_field_stream (uiout
, "new", stb
);
3312 ui_out_text (uiout
, "\n");
3313 result
= PRINT_UNKNOWN
;
3316 /* Fall through, we don't deal with these types of breakpoints
3320 if (ui_out_is_mi_like_p (uiout
))
3323 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3324 result
= PRINT_UNKNOWN
;
3328 if (ui_out_is_mi_like_p (uiout
))
3331 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3332 result
= PRINT_UNKNOWN
;
3337 case bp_longjmp_resume
:
3338 case bp_step_resume
:
3339 case bp_watchpoint_scope
:
3341 case bp_std_terminate
:
3343 case bp_fast_tracepoint
:
3346 result
= PRINT_UNKNOWN
;
3350 do_cleanups (old_chain
);
3354 /* Generic routine for printing messages indicating why we
3355 stopped. The behavior of this function depends on the value
3356 'print_it' in the bpstat structure. Under some circumstances we
3357 may decide not to print anything here and delegate the task to
3360 static enum print_stop_action
3361 print_bp_stop_message (bpstat bs
)
3363 switch (bs
->print_it
)
3366 /* Nothing should be printed for this bpstat entry. */
3367 return PRINT_UNKNOWN
;
3371 /* We still want to print the frame, but we already printed the
3372 relevant messages. */
3373 return PRINT_SRC_AND_LOC
;
3376 case print_it_normal
:
3378 const struct bp_location
*bl
= bs
->breakpoint_at
;
3379 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3381 /* Normal case. Call the breakpoint's print_it method, or
3382 print_it_typical. */
3383 /* FIXME: how breakpoint can ever be NULL here? */
3384 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3385 return b
->ops
->print_it (b
);
3387 return print_it_typical (bs
);
3392 internal_error (__FILE__
, __LINE__
,
3393 _("print_bp_stop_message: unrecognized enum value"));
3398 /* Print a message indicating what happened. This is called from
3399 normal_stop(). The input to this routine is the head of the bpstat
3400 list - a list of the eventpoints that caused this stop. This
3401 routine calls the generic print routine for printing a message
3402 about reasons for stopping. This will print (for example) the
3403 "Breakpoint n," part of the output. The return value of this
3406 PRINT_UNKNOWN: Means we printed nothing
3407 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3408 code to print the location. An example is
3409 "Breakpoint 1, " which should be followed by
3411 PRINT_SRC_ONLY: Means we printed something, but there is no need
3412 to also print the location part of the message.
3413 An example is the catch/throw messages, which
3414 don't require a location appended to the end.
3415 PRINT_NOTHING: We have done some printing and we don't need any
3416 further info to be printed.*/
3418 enum print_stop_action
3419 bpstat_print (bpstat bs
)
3423 /* Maybe another breakpoint in the chain caused us to stop.
3424 (Currently all watchpoints go on the bpstat whether hit or not.
3425 That probably could (should) be changed, provided care is taken
3426 with respect to bpstat_explains_signal). */
3427 for (; bs
; bs
= bs
->next
)
3429 val
= print_bp_stop_message (bs
);
3430 if (val
== PRINT_SRC_ONLY
3431 || val
== PRINT_SRC_AND_LOC
3432 || val
== PRINT_NOTHING
)
3436 /* We reached the end of the chain, or we got a null BS to start
3437 with and nothing was printed. */
3438 return PRINT_UNKNOWN
;
3441 /* Evaluate the expression EXP and return 1 if value is zero.
3442 This is used inside a catch_errors to evaluate the breakpoint condition.
3443 The argument is a "struct expression *" that has been cast to char * to
3444 make it pass through catch_errors. */
3447 breakpoint_cond_eval (void *exp
)
3449 struct value
*mark
= value_mark ();
3450 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3451 value_free_to_mark (mark
);
3455 /* Allocate a new bpstat and chain it to the current one. */
3458 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3462 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3464 bs
->breakpoint_at
= bl
;
3465 /* If the condition is false, etc., don't do the commands. */
3466 bs
->commands
= NULL
;
3467 bs
->commands_left
= NULL
;
3469 bs
->print_it
= print_it_normal
;
3473 /* The target has stopped with waitstatus WS. Check if any hardware
3474 watchpoints have triggered, according to the target. */
3477 watchpoints_triggered (struct target_waitstatus
*ws
)
3479 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3481 struct breakpoint
*b
;
3483 if (!stopped_by_watchpoint
)
3485 /* We were not stopped by a watchpoint. Mark all watchpoints
3486 as not triggered. */
3488 if (b
->type
== bp_hardware_watchpoint
3489 || b
->type
== bp_read_watchpoint
3490 || b
->type
== bp_access_watchpoint
)
3491 b
->watchpoint_triggered
= watch_triggered_no
;
3496 if (!target_stopped_data_address (¤t_target
, &addr
))
3498 /* We were stopped by a watchpoint, but we don't know where.
3499 Mark all watchpoints as unknown. */
3501 if (b
->type
== bp_hardware_watchpoint
3502 || b
->type
== bp_read_watchpoint
3503 || b
->type
== bp_access_watchpoint
)
3504 b
->watchpoint_triggered
= watch_triggered_unknown
;
3506 return stopped_by_watchpoint
;
3509 /* The target could report the data address. Mark watchpoints
3510 affected by this data address as triggered, and all others as not
3514 if (b
->type
== bp_hardware_watchpoint
3515 || b
->type
== bp_read_watchpoint
3516 || b
->type
== bp_access_watchpoint
)
3518 struct bp_location
*loc
;
3521 b
->watchpoint_triggered
= watch_triggered_no
;
3522 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3523 /* Exact match not required. Within range is
3525 if (target_watchpoint_addr_within_range (¤t_target
,
3529 b
->watchpoint_triggered
= watch_triggered_yes
;
3537 /* Possible return values for watchpoint_check (this can't be an enum
3538 because of check_errors). */
3539 /* The watchpoint has been deleted. */
3540 #define WP_DELETED 1
3541 /* The value has changed. */
3542 #define WP_VALUE_CHANGED 2
3543 /* The value has not changed. */
3544 #define WP_VALUE_NOT_CHANGED 3
3545 /* Ignore this watchpoint, no matter if the value changed or not. */
3548 #define BP_TEMPFLAG 1
3549 #define BP_HARDWAREFLAG 2
3551 /* Evaluate watchpoint condition expression and check if its value changed.
3553 P should be a pointer to struct bpstat, but is defined as a void *
3554 in order for this function to be usable with catch_errors. */
3557 watchpoint_check (void *p
)
3559 bpstat bs
= (bpstat
) p
;
3560 struct breakpoint
*b
;
3561 struct frame_info
*fr
;
3562 int within_current_scope
;
3564 b
= bs
->breakpoint_at
->owner
;
3566 /* If this is a local watchpoint, we only want to check if the
3567 watchpoint frame is in scope if the current thread is the thread
3568 that was used to create the watchpoint. */
3569 if (!watchpoint_in_thread_scope (b
))
3572 if (b
->exp_valid_block
== NULL
)
3573 within_current_scope
= 1;
3576 struct frame_info
*frame
= get_current_frame ();
3577 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3578 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3580 /* in_function_epilogue_p() returns a non-zero value if we're still
3581 in the function but the stack frame has already been invalidated.
3582 Since we can't rely on the values of local variables after the
3583 stack has been destroyed, we are treating the watchpoint in that
3584 state as `not changed' without further checking. Don't mark
3585 watchpoints as changed if the current frame is in an epilogue -
3586 even if they are in some other frame, our view of the stack
3587 is likely to be wrong and frame_find_by_id could error out. */
3588 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3591 fr
= frame_find_by_id (b
->watchpoint_frame
);
3592 within_current_scope
= (fr
!= NULL
);
3594 /* If we've gotten confused in the unwinder, we might have
3595 returned a frame that can't describe this variable. */
3596 if (within_current_scope
)
3598 struct symbol
*function
;
3600 function
= get_frame_function (fr
);
3601 if (function
== NULL
3602 || !contained_in (b
->exp_valid_block
,
3603 SYMBOL_BLOCK_VALUE (function
)))
3604 within_current_scope
= 0;
3607 if (within_current_scope
)
3608 /* If we end up stopping, the current frame will get selected
3609 in normal_stop. So this call to select_frame won't affect
3614 if (within_current_scope
)
3616 /* We use value_{,free_to_}mark because it could be a
3617 *long* time before we return to the command level and
3618 call free_all_values. We can't call free_all_values because
3619 we might be in the middle of evaluating a function call. */
3621 struct value
*mark
= value_mark ();
3622 struct value
*new_val
;
3624 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3626 /* We use value_equal_contents instead of value_equal because the latter
3627 coerces an array to a pointer, thus comparing just the address of the
3628 array instead of its contents. This is not what we want. */
3629 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3630 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3632 if (new_val
!= NULL
)
3634 release_value (new_val
);
3635 value_free_to_mark (mark
);
3637 bs
->old_val
= b
->val
;
3640 return WP_VALUE_CHANGED
;
3644 /* Nothing changed. */
3645 value_free_to_mark (mark
);
3646 return WP_VALUE_NOT_CHANGED
;
3651 /* This seems like the only logical thing to do because
3652 if we temporarily ignored the watchpoint, then when
3653 we reenter the block in which it is valid it contains
3654 garbage (in the case of a function, it may have two
3655 garbage values, one before and one after the prologue).
3656 So we can't even detect the first assignment to it and
3657 watch after that (since the garbage may or may not equal
3658 the first value assigned). */
3659 /* We print all the stop information in print_it_typical(), but
3660 in this case, by the time we call print_it_typical() this bp
3661 will be deleted already. So we have no choice but print the
3662 information here. */
3663 if (ui_out_is_mi_like_p (uiout
))
3665 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3666 ui_out_text (uiout
, "\nWatchpoint ");
3667 ui_out_field_int (uiout
, "wpnum", b
->number
);
3668 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3669 which its expression is valid.\n");
3671 if (b
->related_breakpoint
)
3673 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3674 b
->related_breakpoint
->related_breakpoint
= NULL
;
3675 b
->related_breakpoint
= NULL
;
3677 b
->disposition
= disp_del_at_next_stop
;
3683 /* Return true if it looks like target has stopped due to hitting
3684 breakpoint location BL. This function does not check if we
3685 should stop, only if BL explains the stop. */
3687 bpstat_check_location (const struct bp_location
*bl
,
3688 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3690 struct breakpoint
*b
= bl
->owner
;
3692 /* By definition, the inferior does not report stops at
3694 if (is_tracepoint (b
))
3697 if (b
->type
!= bp_watchpoint
3698 && b
->type
!= bp_hardware_watchpoint
3699 && b
->type
!= bp_read_watchpoint
3700 && b
->type
!= bp_access_watchpoint
3701 && b
->type
!= bp_hardware_breakpoint
3702 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3704 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3707 if (overlay_debugging
/* unmapped overlay section */
3708 && section_is_overlay (bl
->section
)
3709 && !section_is_mapped (bl
->section
))
3713 /* Continuable hardware watchpoints are treated as non-existent if the
3714 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3715 some data address). Otherwise gdb won't stop on a break instruction
3716 in the code (not from a breakpoint) when a hardware watchpoint has
3717 been defined. Also skip watchpoints which we know did not trigger
3718 (did not match the data address). */
3720 if ((b
->type
== bp_hardware_watchpoint
3721 || b
->type
== bp_read_watchpoint
3722 || b
->type
== bp_access_watchpoint
)
3723 && b
->watchpoint_triggered
== watch_triggered_no
)
3726 if (b
->type
== bp_hardware_breakpoint
)
3728 if (bl
->address
!= bp_addr
)
3730 if (overlay_debugging
/* unmapped overlay section */
3731 && section_is_overlay (bl
->section
)
3732 && !section_is_mapped (bl
->section
))
3736 if (b
->type
== bp_catchpoint
)
3738 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3739 if (!b
->ops
->breakpoint_hit (b
))
3746 /* If BS refers to a watchpoint, determine if the watched values
3747 has actually changed, and we should stop. If not, set BS->stop
3750 bpstat_check_watchpoint (bpstat bs
)
3752 const struct bp_location
*bl
= bs
->breakpoint_at
;
3753 struct breakpoint
*b
= bl
->owner
;
3755 if (b
->type
== bp_watchpoint
3756 || b
->type
== bp_read_watchpoint
3757 || b
->type
== bp_access_watchpoint
3758 || b
->type
== bp_hardware_watchpoint
)
3762 int must_check_value
= 0;
3764 if (b
->type
== bp_watchpoint
)
3765 /* For a software watchpoint, we must always check the
3767 must_check_value
= 1;
3768 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3769 /* We have a hardware watchpoint (read, write, or access)
3770 and the target earlier reported an address watched by
3772 must_check_value
= 1;
3773 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3774 && b
->type
== bp_hardware_watchpoint
)
3775 /* We were stopped by a hardware watchpoint, but the target could
3776 not report the data address. We must check the watchpoint's
3777 value. Access and read watchpoints are out of luck; without
3778 a data address, we can't figure it out. */
3779 must_check_value
= 1;
3781 if (must_check_value
)
3783 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3785 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3786 int e
= catch_errors (watchpoint_check
, bs
, message
,
3788 do_cleanups (cleanups
);
3792 /* We've already printed what needs to be printed. */
3793 bs
->print_it
= print_it_done
;
3797 bs
->print_it
= print_it_noop
;
3800 case WP_VALUE_CHANGED
:
3801 if (b
->type
== bp_read_watchpoint
)
3803 /* There are two cases to consider here:
3805 1. we're watching the triggered memory for reads.
3806 In that case, trust the target, and always report
3807 the watchpoint hit to the user. Even though
3808 reads don't cause value changes, the value may
3809 have changed since the last time it was read, and
3810 since we're not trapping writes, we will not see
3811 those, and as such we should ignore our notion of
3814 2. we're watching the triggered memory for both
3815 reads and writes. There are two ways this may
3818 2.1. this is a target that can't break on data
3819 reads only, but can break on accesses (reads or
3820 writes), such as e.g., x86. We detect this case
3821 at the time we try to insert read watchpoints.
3823 2.2. otherwise, the target supports read
3824 watchpoints, but, the user set an access or write
3825 watchpoint watching the same memory as this read
3828 If we're watching memory writes as well as reads,
3829 ignore watchpoint hits when we find that the
3830 value hasn't changed, as reads don't cause
3831 changes. This still gives false positives when
3832 the program writes the same value to memory as
3833 what there was already in memory (we will confuse
3834 it for a read), but it's much better than
3837 int other_write_watchpoint
= 0;
3839 if (bl
->watchpoint_type
== hw_read
)
3841 struct breakpoint
*other_b
;
3843 ALL_BREAKPOINTS (other_b
)
3844 if ((other_b
->type
== bp_hardware_watchpoint
3845 || other_b
->type
== bp_access_watchpoint
)
3846 && (other_b
->watchpoint_triggered
3847 == watch_triggered_yes
))
3849 other_write_watchpoint
= 1;
3854 if (other_write_watchpoint
3855 || bl
->watchpoint_type
== hw_access
)
3857 /* We're watching the same memory for writes,
3858 and the value changed since the last time we
3859 updated it, so this trap must be for a write.
3861 bs
->print_it
= print_it_noop
;
3866 case WP_VALUE_NOT_CHANGED
:
3867 if (b
->type
== bp_hardware_watchpoint
3868 || b
->type
== bp_watchpoint
)
3870 /* Don't stop: write watchpoints shouldn't fire if
3871 the value hasn't changed. */
3872 bs
->print_it
= print_it_noop
;
3880 /* Error from catch_errors. */
3881 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3882 if (b
->related_breakpoint
)
3883 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3884 b
->disposition
= disp_del_at_next_stop
;
3885 /* We've already printed what needs to be printed. */
3886 bs
->print_it
= print_it_done
;
3890 else /* must_check_value == 0 */
3892 /* This is a case where some watchpoint(s) triggered, but
3893 not at the address of this watchpoint, or else no
3894 watchpoint triggered after all. So don't print
3895 anything for this watchpoint. */
3896 bs
->print_it
= print_it_noop
;
3903 /* Check conditions (condition proper, frame, thread and ignore count)
3904 of breakpoint referred to by BS. If we should not stop for this
3905 breakpoint, set BS->stop to 0. */
3907 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3909 int thread_id
= pid_to_thread_id (ptid
);
3910 const struct bp_location
*bl
= bs
->breakpoint_at
;
3911 struct breakpoint
*b
= bl
->owner
;
3913 if (frame_id_p (b
->frame_id
)
3914 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3918 int value_is_zero
= 0;
3919 struct expression
*cond
;
3921 /* If this is a scope breakpoint, mark the associated
3922 watchpoint as triggered so that we will handle the
3923 out-of-scope event. We'll get to the watchpoint next
3925 if (b
->type
== bp_watchpoint_scope
)
3926 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3928 if (is_watchpoint (b
))
3933 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3935 int within_current_scope
= 1;
3937 /* We use value_mark and value_free_to_mark because it could
3938 be a long time before we return to the command level and
3939 call free_all_values. We can't call free_all_values
3940 because we might be in the middle of evaluating a
3942 struct value
*mark
= value_mark ();
3944 /* Need to select the frame, with all that implies so that
3945 the conditions will have the right context. Because we
3946 use the frame, we will not see an inlined function's
3947 variables when we arrive at a breakpoint at the start
3948 of the inlined function; the current frame will be the
3950 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3951 select_frame (get_current_frame ());
3954 struct frame_info
*frame
;
3956 /* For local watchpoint expressions, which particular
3957 instance of a local is being watched matters, so we
3958 keep track of the frame to evaluate the expression
3959 in. To evaluate the condition however, it doesn't
3960 really matter which instantiation of the function
3961 where the condition makes sense triggers the
3962 watchpoint. This allows an expression like "watch
3963 global if q > 10" set in `func', catch writes to
3964 global on all threads that call `func', or catch
3965 writes on all recursive calls of `func' by a single
3966 thread. We simply always evaluate the condition in
3967 the innermost frame that's executing where it makes
3968 sense to evaluate the condition. It seems
3970 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3972 select_frame (frame
);
3974 within_current_scope
= 0;
3976 if (within_current_scope
)
3978 = catch_errors (breakpoint_cond_eval
, cond
,
3979 "Error in testing breakpoint condition:\n",
3983 warning (_("Watchpoint condition cannot be tested "
3984 "in the current scope"));
3985 /* If we failed to set the right context for this
3986 watchpoint, unconditionally report it. */
3989 /* FIXME-someday, should give breakpoint # */
3990 value_free_to_mark (mark
);
3993 if (cond
&& value_is_zero
)
3997 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4001 else if (b
->ignore_count
> 0)
4004 annotate_ignore_count_change ();
4006 /* Increase the hit count even though we don't
4014 /* Get a bpstat associated with having just stopped at address
4015 BP_ADDR in thread PTID.
4017 Determine whether we stopped at a breakpoint, etc, or whether we
4018 don't understand this stop. Result is a chain of bpstat's such that:
4020 if we don't understand the stop, the result is a null pointer.
4022 if we understand why we stopped, the result is not null.
4024 Each element of the chain refers to a particular breakpoint or
4025 watchpoint at which we have stopped. (We may have stopped for
4026 several reasons concurrently.)
4028 Each element of the chain has valid next, breakpoint_at,
4029 commands, FIXME??? fields. */
4032 bpstat_stop_status (struct address_space
*aspace
,
4033 CORE_ADDR bp_addr
, ptid_t ptid
)
4035 struct breakpoint
*b
= NULL
;
4036 struct bp_location
*bl
, **blp_tmp
;
4037 struct bp_location
*loc
;
4038 /* Root of the chain of bpstat's */
4039 struct bpstats root_bs
[1];
4040 /* Pointer to the last thing in the chain currently. */
4041 bpstat bs
= root_bs
;
4043 int need_remove_insert
;
4045 /* ALL_BP_LOCATIONS iteration would break across
4046 update_global_location_list possibly executed by
4047 bpstat_check_breakpoint_conditions's inferior call. */
4051 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4054 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4056 /* For hardware watchpoints, we look only at the first location.
4057 The watchpoint_check function will work on entire expression,
4058 not the individual locations. For read watchopints, the
4059 watchpoints_triggered function have checked all locations
4061 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4064 if (bl
->shlib_disabled
)
4067 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4070 /* Come here if it's a watchpoint, or if the break address matches */
4072 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4074 /* Assume we stop. Should we find watchpoint that is not actually
4075 triggered, or if condition of breakpoint is false, we'll reset
4080 bpstat_check_watchpoint (bs
);
4084 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4085 || b
->type
== bp_longjmp_master
4086 || b
->type
== bp_std_terminate_master
)
4087 /* We do not stop for these. */
4090 bpstat_check_breakpoint_conditions (bs
, ptid
);
4096 /* We will stop here */
4097 if (b
->disposition
== disp_disable
)
4099 if (b
->enable_state
!= bp_permanent
)
4100 b
->enable_state
= bp_disabled
;
4101 update_global_location_list (0);
4105 bs
->commands
= b
->commands
;
4106 incref_counted_command_line (bs
->commands
);
4107 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4108 if (bs
->commands_left
4109 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4112 bs
->commands_left
->line
) == 0)))
4114 bs
->commands_left
= bs
->commands_left
->next
;
4119 /* Print nothing for this entry if we dont stop or dont print. */
4120 if (bs
->stop
== 0 || bs
->print
== 0)
4121 bs
->print_it
= print_it_noop
;
4125 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4127 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4130 bs
= bpstat_alloc (loc
, bs
);
4131 /* For hits of moribund locations, we should just proceed. */
4134 bs
->print_it
= print_it_noop
;
4138 bs
->next
= NULL
; /* Terminate the chain */
4140 /* If we aren't stopping, the value of some hardware watchpoint may
4141 not have changed, but the intermediate memory locations we are
4142 watching may have. Don't bother if we're stopping; this will get
4144 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4148 need_remove_insert
= 0;
4150 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4152 && bs
->breakpoint_at
->owner
4153 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4155 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4156 /* Updating watchpoints invalidates bs->breakpoint_at.
4157 Prevent further code from trying to use it. */
4158 bs
->breakpoint_at
= NULL
;
4159 need_remove_insert
= 1;
4162 if (need_remove_insert
)
4163 update_global_location_list (1);
4165 return root_bs
->next
;
4168 /* Tell what to do about this bpstat. */
4170 bpstat_what (bpstat bs
)
4172 /* Classify each bpstat as one of the following. */
4175 /* This bpstat element has no effect on the main_action. */
4178 /* There was a watchpoint, stop but don't print. */
4181 /* There was a watchpoint, stop and print. */
4184 /* There was a breakpoint but we're not stopping. */
4187 /* There was a breakpoint, stop but don't print. */
4190 /* There was a breakpoint, stop and print. */
4193 /* We hit the longjmp breakpoint. */
4196 /* We hit the longjmp_resume breakpoint. */
4199 /* We hit the step_resume breakpoint. */
4202 /* We hit the shared library event breakpoint. */
4205 /* We hit the jit event breakpoint. */
4208 /* This is just used to count how many enums there are. */
4212 /* Here is the table which drives this routine. So that we can
4213 format it pretty, we define some abbreviations for the
4214 enum bpstat_what codes. */
4215 #define kc BPSTAT_WHAT_KEEP_CHECKING
4216 #define ss BPSTAT_WHAT_STOP_SILENT
4217 #define sn BPSTAT_WHAT_STOP_NOISY
4218 #define sgl BPSTAT_WHAT_SINGLE
4219 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4220 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4221 #define sr BPSTAT_WHAT_STEP_RESUME
4222 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4223 #define jit BPSTAT_WHAT_CHECK_JIT
4225 /* "Can't happen." Might want to print an error message.
4226 abort() is not out of the question, but chances are GDB is just
4227 a bit confused, not unusable. */
4228 #define err BPSTAT_WHAT_STOP_NOISY
4230 /* Given an old action and a class, come up with a new action. */
4231 /* One interesting property of this table is that wp_silent is the same
4232 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4233 after stopping, the check for whether to step over a breakpoint
4234 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4235 reference to how we stopped. We retain separate wp_silent and
4236 bp_silent codes in case we want to change that someday.
4238 Another possibly interesting property of this table is that
4239 there's a partial ordering, priority-like, of the actions. Once
4240 you've decided that some action is appropriate, you'll never go
4241 back and decide something of a lower priority is better. The
4244 kc < jit clr sgl shl slr sn sr ss
4245 sgl < jit shl slr sn sr ss
4246 slr < jit err shl sn sr ss
4247 clr < jit err shl sn sr ss
4254 What I think this means is that we don't need a damned table
4255 here. If you just put the rows and columns in the right order,
4256 it'd look awfully regular. We could simply walk the bpstat list
4257 and choose the highest priority action we find, with a little
4258 logic to handle the 'err' cases. */
4260 /* step_resume entries: a step resume breakpoint overrides another
4261 breakpoint of signal handling (see comment in wait_for_inferior
4262 at where we set the step_resume breakpoint). */
4264 static const enum bpstat_what_main_action
4265 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4268 /* kc ss sn sgl slr clr sr shl jit */
4269 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4270 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4271 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4272 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4273 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4274 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4275 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4276 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4277 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4278 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4279 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4293 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4294 struct bpstat_what retval
;
4296 retval
.call_dummy
= STOP_NONE
;
4297 for (; bs
!= NULL
; bs
= bs
->next
)
4299 enum class bs_class
= no_effect
;
4300 if (bs
->breakpoint_at
== NULL
)
4301 /* I suspect this can happen if it was a momentary breakpoint
4302 which has since been deleted. */
4304 if (bs
->breakpoint_at
->owner
== NULL
)
4305 bs_class
= bp_nostop
;
4307 switch (bs
->breakpoint_at
->owner
->type
)
4313 case bp_hardware_breakpoint
:
4319 bs_class
= bp_noisy
;
4321 bs_class
= bp_silent
;
4324 bs_class
= bp_nostop
;
4327 case bp_hardware_watchpoint
:
4328 case bp_read_watchpoint
:
4329 case bp_access_watchpoint
:
4333 bs_class
= wp_noisy
;
4335 bs_class
= wp_silent
;
4338 /* There was a watchpoint, but we're not stopping.
4339 This requires no further action. */
4340 bs_class
= no_effect
;
4343 bs_class
= long_jump
;
4345 case bp_longjmp_resume
:
4346 bs_class
= long_resume
;
4348 case bp_step_resume
:
4351 bs_class
= step_resume
;
4354 /* It is for the wrong frame. */
4355 bs_class
= bp_nostop
;
4357 case bp_watchpoint_scope
:
4358 bs_class
= bp_nostop
;
4360 case bp_shlib_event
:
4361 bs_class
= shlib_event
;
4364 bs_class
= jit_event
;
4366 case bp_thread_event
:
4367 case bp_overlay_event
:
4368 case bp_longjmp_master
:
4369 case bp_std_terminate_master
:
4370 bs_class
= bp_nostop
;
4376 bs_class
= bp_noisy
;
4378 bs_class
= bp_silent
;
4381 /* There was a catchpoint, but we're not stopping.
4382 This requires no further action. */
4383 bs_class
= no_effect
;
4386 /* Make sure the action is stop (silent or noisy),
4387 so infrun.c pops the dummy frame. */
4388 bs_class
= bp_silent
;
4389 retval
.call_dummy
= STOP_STACK_DUMMY
;
4391 case bp_std_terminate
:
4392 /* Make sure the action is stop (silent or noisy),
4393 so infrun.c pops the dummy frame. */
4394 bs_class
= bp_silent
;
4395 retval
.call_dummy
= STOP_STD_TERMINATE
;
4398 case bp_fast_tracepoint
:
4399 /* Tracepoint hits should not be reported back to GDB, and
4400 if one got through somehow, it should have been filtered
4402 internal_error (__FILE__
, __LINE__
,
4403 _("bpstat_what: tracepoint encountered"));
4406 current_action
= table
[(int) bs_class
][(int) current_action
];
4408 retval
.main_action
= current_action
;
4412 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4413 without hardware support). This isn't related to a specific bpstat,
4414 just to things like whether watchpoints are set. */
4417 bpstat_should_step (void)
4419 struct breakpoint
*b
;
4421 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4427 bpstat_causes_stop (bpstat bs
)
4429 for (; bs
!= NULL
; bs
= bs
->next
)
4438 /* Print the LOC location out of the list of B->LOC locations. */
4440 static void print_breakpoint_location (struct breakpoint
*b
,
4441 struct bp_location
*loc
,
4443 struct ui_stream
*stb
)
4445 struct cleanup
*old_chain
= save_current_program_space ();
4447 if (loc
!= NULL
&& loc
->shlib_disabled
)
4451 set_current_program_space (loc
->pspace
);
4453 if (b
->source_file
&& loc
)
4456 = find_pc_sect_function (loc
->address
, loc
->section
);
4459 ui_out_text (uiout
, "in ");
4460 ui_out_field_string (uiout
, "func",
4461 SYMBOL_PRINT_NAME (sym
));
4462 ui_out_wrap_hint (uiout
, wrap_indent
);
4463 ui_out_text (uiout
, " at ");
4465 ui_out_field_string (uiout
, "file", b
->source_file
);
4466 ui_out_text (uiout
, ":");
4468 if (ui_out_is_mi_like_p (uiout
))
4470 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4471 char *fullname
= symtab_to_fullname (sal
.symtab
);
4474 ui_out_field_string (uiout
, "fullname", fullname
);
4477 ui_out_field_int (uiout
, "line", b
->line_number
);
4481 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4483 ui_out_field_stream (uiout
, "at", stb
);
4486 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4488 do_cleanups (old_chain
);
4491 /* Print B to gdb_stdout. */
4493 print_one_breakpoint_location (struct breakpoint
*b
,
4494 struct bp_location
*loc
,
4496 struct bp_location
**last_loc
,
4497 int print_address_bits
,
4500 struct command_line
*l
;
4502 struct ep_type_description
4507 static struct ep_type_description bptypes
[] =
4509 {bp_none
, "?deleted?"},
4510 {bp_breakpoint
, "breakpoint"},
4511 {bp_hardware_breakpoint
, "hw breakpoint"},
4512 {bp_until
, "until"},
4513 {bp_finish
, "finish"},
4514 {bp_watchpoint
, "watchpoint"},
4515 {bp_hardware_watchpoint
, "hw watchpoint"},
4516 {bp_read_watchpoint
, "read watchpoint"},
4517 {bp_access_watchpoint
, "acc watchpoint"},
4518 {bp_longjmp
, "longjmp"},
4519 {bp_longjmp_resume
, "longjmp resume"},
4520 {bp_step_resume
, "step resume"},
4521 {bp_watchpoint_scope
, "watchpoint scope"},
4522 {bp_call_dummy
, "call dummy"},
4523 {bp_std_terminate
, "std::terminate"},
4524 {bp_shlib_event
, "shlib events"},
4525 {bp_thread_event
, "thread events"},
4526 {bp_overlay_event
, "overlay events"},
4527 {bp_longjmp_master
, "longjmp master"},
4528 {bp_std_terminate_master
, "std::terminate master"},
4529 {bp_catchpoint
, "catchpoint"},
4530 {bp_tracepoint
, "tracepoint"},
4531 {bp_fast_tracepoint
, "fast tracepoint"},
4532 {bp_jit_event
, "jit events"},
4535 static char bpenables
[] = "nynny";
4536 char wrap_indent
[80];
4537 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4538 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4539 struct cleanup
*bkpt_chain
;
4541 int header_of_multiple
= 0;
4542 int part_of_multiple
= (loc
!= NULL
);
4543 struct value_print_options opts
;
4545 get_user_print_options (&opts
);
4547 gdb_assert (!loc
|| loc_number
!= 0);
4548 /* See comment in print_one_breakpoint concerning
4549 treatment of breakpoints with single disabled
4553 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4554 header_of_multiple
= 1;
4559 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4563 if (part_of_multiple
)
4566 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4567 ui_out_field_string (uiout
, "number", formatted
);
4572 ui_out_field_int (uiout
, "number", b
->number
);
4577 if (part_of_multiple
)
4578 ui_out_field_skip (uiout
, "type");
4581 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4582 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4583 internal_error (__FILE__
, __LINE__
,
4584 _("bptypes table does not describe type #%d."),
4586 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4591 if (part_of_multiple
)
4592 ui_out_field_skip (uiout
, "disp");
4594 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4599 if (part_of_multiple
)
4600 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4602 ui_out_field_fmt (uiout
, "enabled", "%c",
4603 bpenables
[(int) b
->enable_state
]);
4604 ui_out_spaces (uiout
, 2);
4608 strcpy (wrap_indent
, " ");
4609 if (opts
.addressprint
)
4611 if (print_address_bits
<= 32)
4612 strcat (wrap_indent
, " ");
4614 strcat (wrap_indent
, " ");
4617 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4619 /* Although the print_one can possibly print
4620 all locations, calling it here is not likely
4621 to get any nice result. So, make sure there's
4622 just one location. */
4623 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4624 b
->ops
->print_one (b
, last_loc
);
4630 internal_error (__FILE__
, __LINE__
,
4631 _("print_one_breakpoint: bp_none encountered\n"));
4635 case bp_hardware_watchpoint
:
4636 case bp_read_watchpoint
:
4637 case bp_access_watchpoint
:
4638 /* Field 4, the address, is omitted (which makes the columns
4639 not line up too nicely with the headers, but the effect
4640 is relatively readable). */
4641 if (opts
.addressprint
)
4642 ui_out_field_skip (uiout
, "addr");
4644 ui_out_field_string (uiout
, "what", b
->exp_string
);
4648 case bp_hardware_breakpoint
:
4652 case bp_longjmp_resume
:
4653 case bp_step_resume
:
4654 case bp_watchpoint_scope
:
4656 case bp_std_terminate
:
4657 case bp_shlib_event
:
4658 case bp_thread_event
:
4659 case bp_overlay_event
:
4660 case bp_longjmp_master
:
4661 case bp_std_terminate_master
:
4663 case bp_fast_tracepoint
:
4665 if (opts
.addressprint
)
4668 if (header_of_multiple
)
4669 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4670 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4671 ui_out_field_string (uiout
, "addr", "<PENDING>");
4673 ui_out_field_core_addr (uiout
, "addr",
4674 loc
->gdbarch
, loc
->address
);
4677 if (!header_of_multiple
)
4678 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4685 /* For backward compatibility, don't display inferiors unless there
4688 && !header_of_multiple
4690 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4691 && (number_of_program_spaces () > 1
4692 || number_of_inferiors () > 1)
4693 && loc
->owner
->type
!= bp_catchpoint
)))
4695 struct inferior
*inf
;
4698 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4700 if (inf
->pspace
== loc
->pspace
)
4705 ui_out_text (uiout
, " inf ");
4708 ui_out_text (uiout
, ", ");
4709 ui_out_text (uiout
, plongest (inf
->num
));
4714 if (!part_of_multiple
)
4716 if (b
->thread
!= -1)
4718 /* FIXME: This seems to be redundant and lost here; see the
4719 "stop only in" line a little further down. */
4720 ui_out_text (uiout
, " thread ");
4721 ui_out_field_int (uiout
, "thread", b
->thread
);
4723 else if (b
->task
!= 0)
4725 ui_out_text (uiout
, " task ");
4726 ui_out_field_int (uiout
, "task", b
->task
);
4730 ui_out_text (uiout
, "\n");
4732 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4735 ui_out_text (uiout
, "\tstop only in stack frame at ");
4736 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4738 ui_out_field_core_addr (uiout
, "frame",
4739 b
->gdbarch
, b
->frame_id
.stack_addr
);
4740 ui_out_text (uiout
, "\n");
4743 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4745 /* We do not print the condition for Ada exception catchpoints
4746 because the condition is an internal implementation detail
4747 that we do not want to expose to the user. */
4749 if (is_tracepoint (b
))
4750 ui_out_text (uiout
, "\ttrace only if ");
4752 ui_out_text (uiout
, "\tstop only if ");
4753 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4754 ui_out_text (uiout
, "\n");
4757 if (!part_of_multiple
&& b
->thread
!= -1)
4759 /* FIXME should make an annotation for this */
4760 ui_out_text (uiout
, "\tstop only in thread ");
4761 ui_out_field_int (uiout
, "thread", b
->thread
);
4762 ui_out_text (uiout
, "\n");
4765 if (!part_of_multiple
&& b
->hit_count
)
4767 /* FIXME should make an annotation for this */
4768 if (ep_is_catchpoint (b
))
4769 ui_out_text (uiout
, "\tcatchpoint");
4771 ui_out_text (uiout
, "\tbreakpoint");
4772 ui_out_text (uiout
, " already hit ");
4773 ui_out_field_int (uiout
, "times", b
->hit_count
);
4774 if (b
->hit_count
== 1)
4775 ui_out_text (uiout
, " time\n");
4777 ui_out_text (uiout
, " times\n");
4780 /* Output the count also if it is zero, but only if this is
4781 mi. FIXME: Should have a better test for this. */
4782 if (ui_out_is_mi_like_p (uiout
))
4783 if (!part_of_multiple
&& b
->hit_count
== 0)
4784 ui_out_field_int (uiout
, "times", b
->hit_count
);
4786 if (!part_of_multiple
&& b
->ignore_count
)
4789 ui_out_text (uiout
, "\tignore next ");
4790 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4791 ui_out_text (uiout
, " hits\n");
4794 l
= b
->commands
? b
->commands
->commands
: NULL
;
4795 if (!part_of_multiple
&& l
)
4797 struct cleanup
*script_chain
;
4800 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4801 print_command_lines (uiout
, l
, 4);
4802 do_cleanups (script_chain
);
4805 if (!part_of_multiple
&& b
->pass_count
)
4807 annotate_field (10);
4808 ui_out_text (uiout
, "\tpass count ");
4809 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4810 ui_out_text (uiout
, " \n");
4813 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4816 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4817 else if (b
->exp_string
)
4818 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4821 do_cleanups (bkpt_chain
);
4822 do_cleanups (old_chain
);
4826 print_one_breakpoint (struct breakpoint
*b
,
4827 struct bp_location
**last_loc
, int print_address_bits
,
4830 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4831 print_address_bits
, allflag
);
4833 /* If this breakpoint has custom print function,
4834 it's already printed. Otherwise, print individual
4835 locations, if any. */
4836 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4838 /* If breakpoint has a single location that is
4839 disabled, we print it as if it had
4840 several locations, since otherwise it's hard to
4841 represent "breakpoint enabled, location disabled"
4843 Note that while hardware watchpoints have
4844 several locations internally, that's no a property
4847 && !is_hardware_watchpoint (b
)
4848 && (b
->loc
->next
|| !b
->loc
->enabled
)
4849 && !ui_out_is_mi_like_p (uiout
))
4851 struct bp_location
*loc
;
4853 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4854 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4855 print_address_bits
, allflag
);
4861 breakpoint_address_bits (struct breakpoint
*b
)
4863 int print_address_bits
= 0;
4864 struct bp_location
*loc
;
4866 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4870 /* Software watchpoints that aren't watching memory don't have
4871 an address to print. */
4872 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4875 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4876 if (addr_bit
> print_address_bits
)
4877 print_address_bits
= addr_bit
;
4880 return print_address_bits
;
4883 struct captured_breakpoint_query_args
4889 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4891 struct captured_breakpoint_query_args
*args
= data
;
4892 struct breakpoint
*b
;
4893 struct bp_location
*dummy_loc
= NULL
;
4896 if (args
->bnum
== b
->number
)
4898 int print_address_bits
= breakpoint_address_bits (b
);
4899 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4907 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4909 struct captured_breakpoint_query_args args
;
4911 /* For the moment we don't trust print_one_breakpoint() to not throw
4913 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4914 error_message
, RETURN_MASK_ALL
) < 0)
4920 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4921 catchpoints, et.al.). */
4924 user_settable_breakpoint (const struct breakpoint
*b
)
4926 return (b
->type
== bp_breakpoint
4927 || b
->type
== bp_catchpoint
4928 || b
->type
== bp_hardware_breakpoint
4929 || is_tracepoint (b
)
4930 || b
->type
== bp_watchpoint
4931 || b
->type
== bp_read_watchpoint
4932 || b
->type
== bp_access_watchpoint
4933 || b
->type
== bp_hardware_watchpoint
);
4936 /* Print information on user settable breakpoint (watchpoint, etc)
4937 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4938 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4939 FILTER is non-NULL, call it on each breakpoint and only include the
4940 ones for which it returns non-zero. Return the total number of
4941 breakpoints listed. */
4944 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4946 struct breakpoint
*b
;
4947 struct bp_location
*last_loc
= NULL
;
4948 int nr_printable_breakpoints
;
4949 struct cleanup
*bkpttbl_chain
;
4950 struct value_print_options opts
;
4951 int print_address_bits
= 0;
4953 get_user_print_options (&opts
);
4955 /* Compute the number of rows in the table, as well as the
4956 size required for address fields. */
4957 nr_printable_breakpoints
= 0;
4960 || bnum
== b
->number
)
4962 /* If we have a filter, only list the breakpoints it accepts. */
4963 if (filter
&& !filter (b
))
4966 if (allflag
|| user_settable_breakpoint (b
))
4968 int addr_bit
= breakpoint_address_bits (b
);
4969 if (addr_bit
> print_address_bits
)
4970 print_address_bits
= addr_bit
;
4972 nr_printable_breakpoints
++;
4976 if (opts
.addressprint
)
4978 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4982 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4985 if (nr_printable_breakpoints
> 0)
4986 annotate_breakpoints_headers ();
4987 if (nr_printable_breakpoints
> 0)
4989 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4990 if (nr_printable_breakpoints
> 0)
4992 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4993 if (nr_printable_breakpoints
> 0)
4995 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4996 if (nr_printable_breakpoints
> 0)
4998 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4999 if (opts
.addressprint
)
5001 if (nr_printable_breakpoints
> 0)
5003 if (print_address_bits
<= 32)
5004 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
5006 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
5008 if (nr_printable_breakpoints
> 0)
5010 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5011 ui_out_table_body (uiout
);
5012 if (nr_printable_breakpoints
> 0)
5013 annotate_breakpoints_table ();
5019 || bnum
== b
->number
)
5021 /* If we have a filter, only list the breakpoints it accepts. */
5022 if (filter
&& !filter (b
))
5025 /* We only print out user settable breakpoints unless the
5027 if (allflag
|| user_settable_breakpoint (b
))
5028 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5032 do_cleanups (bkpttbl_chain
);
5034 if (nr_printable_breakpoints
== 0)
5036 /* If there's a filter, let the caller decide how to report empty list. */
5040 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5042 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5048 if (last_loc
&& !server_command
)
5049 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5052 /* FIXME? Should this be moved up so that it is only called when
5053 there have been breakpoints? */
5054 annotate_breakpoints_table_end ();
5056 return nr_printable_breakpoints
;
5060 breakpoints_info (char *bnum_exp
, int from_tty
)
5065 bnum
= parse_and_eval_long (bnum_exp
);
5067 breakpoint_1 (bnum
, 0, NULL
);
5071 watchpoints_info (char *wpnum_exp
, int from_tty
)
5073 int wpnum
= -1, num_printed
;
5076 wpnum
= parse_and_eval_long (wpnum_exp
);
5078 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5080 if (num_printed
== 0)
5083 ui_out_message (uiout
, 0, "No watchpoints.\n");
5085 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5090 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5095 bnum
= parse_and_eval_long (bnum_exp
);
5097 breakpoint_1 (bnum
, 1, NULL
);
5101 breakpoint_has_pc (struct breakpoint
*b
,
5102 struct program_space
*pspace
,
5103 CORE_ADDR pc
, struct obj_section
*section
)
5105 struct bp_location
*bl
= b
->loc
;
5106 for (; bl
; bl
= bl
->next
)
5108 if (bl
->pspace
== pspace
5109 && bl
->address
== pc
5110 && (!overlay_debugging
|| bl
->section
== section
))
5116 /* Print a message describing any breakpoints set at PC. This
5117 concerns with logical breakpoints, so we match program spaces, not
5121 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5122 struct program_space
*pspace
, CORE_ADDR pc
,
5123 struct obj_section
*section
, int thread
)
5126 struct breakpoint
*b
;
5129 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5133 printf_filtered (_("Note: breakpoint "));
5134 else /* if (others == ???) */
5135 printf_filtered (_("Note: breakpoints "));
5137 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5140 printf_filtered ("%d", b
->number
);
5141 if (b
->thread
== -1 && thread
!= -1)
5142 printf_filtered (" (all threads)");
5143 else if (b
->thread
!= -1)
5144 printf_filtered (" (thread %d)", b
->thread
);
5145 printf_filtered ("%s%s ",
5146 ((b
->enable_state
== bp_disabled
5147 || b
->enable_state
== bp_call_disabled
5148 || b
->enable_state
== bp_startup_disabled
)
5150 : b
->enable_state
== bp_permanent
5154 : ((others
== 1) ? " and" : ""));
5156 printf_filtered (_("also set at pc "));
5157 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5158 printf_filtered (".\n");
5162 /* Set the default place to put a breakpoint
5163 for the `break' command with no arguments. */
5166 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5167 CORE_ADDR addr
, struct symtab
*symtab
,
5170 default_breakpoint_valid
= valid
;
5171 default_breakpoint_pspace
= pspace
;
5172 default_breakpoint_address
= addr
;
5173 default_breakpoint_symtab
= symtab
;
5174 default_breakpoint_line
= line
;
5177 /* Return true iff it is meaningful to use the address member of
5178 BPT. For some breakpoint types, the address member is irrelevant
5179 and it makes no sense to attempt to compare it to other addresses
5180 (or use it for any other purpose either).
5182 More specifically, each of the following breakpoint types will always
5183 have a zero valued address and we don't want to mark breakpoints of any of
5184 these types to be a duplicate of an actual breakpoint at address zero:
5192 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5194 enum bptype type
= bpt
->type
;
5196 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5199 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5200 true if LOC1 and LOC2 represent the same watchpoint location. */
5203 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5205 /* Note that this checks the owner's type, not the location's. In
5206 case the target does not support read watchpoints, but does
5207 support access watchpoints, we'll have bp_read_watchpoint
5208 watchpoints with hw_access locations. Those should be considered
5209 duplicates of hw_read locations. The hw_read locations will
5210 become hw_access locations later. */
5211 return (loc1
->owner
->type
== loc2
->owner
->type
5212 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5213 && loc1
->address
== loc2
->address
5214 && loc1
->length
== loc2
->length
);
5217 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5218 same breakpoint location. In most targets, this can only be true
5219 if ASPACE1 matches ASPACE2. On targets that have global
5220 breakpoints, the address space doesn't really matter. */
5223 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5224 struct address_space
*aspace2
, CORE_ADDR addr2
)
5226 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5227 || aspace1
== aspace2
)
5231 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5232 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5233 represent the same location. */
5236 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5238 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5239 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5241 if (hw_point1
!= hw_point2
)
5244 return watchpoint_locations_match (loc1
, loc2
);
5246 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5247 loc2
->pspace
->aspace
, loc2
->address
);
5251 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5252 int bnum
, int have_bnum
)
5257 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5258 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5260 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5261 bnum
, astr1
, astr2
);
5263 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5266 /* Adjust a breakpoint's address to account for architectural constraints
5267 on breakpoint placement. Return the adjusted address. Note: Very
5268 few targets require this kind of adjustment. For most targets,
5269 this function is simply the identity function. */
5272 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5273 CORE_ADDR bpaddr
, enum bptype bptype
)
5275 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5277 /* Very few targets need any kind of breakpoint adjustment. */
5280 else if (bptype
== bp_watchpoint
5281 || bptype
== bp_hardware_watchpoint
5282 || bptype
== bp_read_watchpoint
5283 || bptype
== bp_access_watchpoint
5284 || bptype
== bp_catchpoint
)
5286 /* Watchpoints and the various bp_catch_* eventpoints should not
5287 have their addresses modified. */
5292 CORE_ADDR adjusted_bpaddr
;
5294 /* Some targets have architectural constraints on the placement
5295 of breakpoint instructions. Obtain the adjusted address. */
5296 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5298 /* An adjusted breakpoint address can significantly alter
5299 a user's expectations. Print a warning if an adjustment
5301 if (adjusted_bpaddr
!= bpaddr
)
5302 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5304 return adjusted_bpaddr
;
5308 /* Allocate a struct bp_location. */
5310 static struct bp_location
*
5311 allocate_bp_location (struct breakpoint
*bpt
)
5313 struct bp_location
*loc
, *loc_p
;
5315 loc
= xmalloc (sizeof (struct bp_location
));
5316 memset (loc
, 0, sizeof (*loc
));
5320 loc
->shlib_disabled
= 0;
5329 case bp_longjmp_resume
:
5330 case bp_step_resume
:
5331 case bp_watchpoint_scope
:
5333 case bp_std_terminate
:
5334 case bp_shlib_event
:
5335 case bp_thread_event
:
5336 case bp_overlay_event
:
5338 case bp_longjmp_master
:
5339 case bp_std_terminate_master
:
5340 loc
->loc_type
= bp_loc_software_breakpoint
;
5342 case bp_hardware_breakpoint
:
5343 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5345 case bp_hardware_watchpoint
:
5346 case bp_read_watchpoint
:
5347 case bp_access_watchpoint
:
5348 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5353 case bp_fast_tracepoint
:
5354 loc
->loc_type
= bp_loc_other
;
5357 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5363 static void free_bp_location (struct bp_location
*loc
)
5368 if (loc
->function_name
)
5369 xfree (loc
->function_name
);
5374 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5375 that has type BPTYPE and has no locations as yet. */
5376 /* This function is used in gdbtk sources and thus can not be made static. */
5378 static struct breakpoint
*
5379 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5382 struct breakpoint
*b
, *b1
;
5384 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5385 memset (b
, 0, sizeof (*b
));
5388 b
->gdbarch
= gdbarch
;
5389 b
->language
= current_language
->la_language
;
5390 b
->input_radix
= input_radix
;
5392 b
->enable_state
= bp_enabled
;
5395 b
->ignore_count
= 0;
5397 b
->frame_id
= null_frame_id
;
5398 b
->forked_inferior_pid
= null_ptid
;
5399 b
->exec_pathname
= NULL
;
5400 b
->syscalls_to_be_caught
= NULL
;
5402 b
->condition_not_parsed
= 0;
5404 /* Add this breakpoint to the end of the chain
5405 so that a list of breakpoints will come out in order
5406 of increasing numbers. */
5408 b1
= breakpoint_chain
;
5410 breakpoint_chain
= b
;
5420 /* Initialize loc->function_name. */
5422 set_breakpoint_location_function (struct bp_location
*loc
)
5424 if (loc
->owner
->type
== bp_breakpoint
5425 || loc
->owner
->type
== bp_hardware_breakpoint
5426 || is_tracepoint (loc
->owner
))
5428 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5430 if (loc
->function_name
)
5431 loc
->function_name
= xstrdup (loc
->function_name
);
5435 /* Attempt to determine architecture of location identified by SAL. */
5436 static struct gdbarch
*
5437 get_sal_arch (struct symtab_and_line sal
)
5440 return get_objfile_arch (sal
.section
->objfile
);
5442 return get_objfile_arch (sal
.symtab
->objfile
);
5447 /* set_raw_breakpoint is a low level routine for allocating and
5448 partially initializing a breakpoint of type BPTYPE. The newly
5449 created breakpoint's address, section, source file name, and line
5450 number are provided by SAL. The newly created and partially
5451 initialized breakpoint is added to the breakpoint chain and
5452 is also returned as the value of this function.
5454 It is expected that the caller will complete the initialization of
5455 the newly created breakpoint struct as well as output any status
5456 information regarding the creation of a new breakpoint. In
5457 particular, set_raw_breakpoint does NOT set the breakpoint
5458 number! Care should be taken to not allow an error to occur
5459 prior to completing the initialization of the breakpoint. If this
5460 should happen, a bogus breakpoint will be left on the chain. */
5463 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5464 struct symtab_and_line sal
, enum bptype bptype
)
5466 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5467 CORE_ADDR adjusted_address
;
5468 struct gdbarch
*loc_gdbarch
;
5470 loc_gdbarch
= get_sal_arch (sal
);
5472 loc_gdbarch
= b
->gdbarch
;
5474 if (bptype
!= bp_catchpoint
)
5475 gdb_assert (sal
.pspace
!= NULL
);
5477 /* Adjust the breakpoint's address prior to allocating a location.
5478 Once we call allocate_bp_location(), that mostly uninitialized
5479 location will be placed on the location chain. Adjustment of the
5480 breakpoint may cause target_read_memory() to be called and we do
5481 not want its scan of the location chain to find a breakpoint and
5482 location that's only been partially initialized. */
5483 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5485 b
->loc
= allocate_bp_location (b
);
5486 b
->loc
->gdbarch
= loc_gdbarch
;
5487 b
->loc
->requested_address
= sal
.pc
;
5488 b
->loc
->address
= adjusted_address
;
5489 b
->loc
->pspace
= sal
.pspace
;
5491 /* Store the program space that was used to set the breakpoint, for
5492 breakpoint resetting. */
5493 b
->pspace
= sal
.pspace
;
5495 if (sal
.symtab
== NULL
)
5496 b
->source_file
= NULL
;
5498 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5499 b
->loc
->section
= sal
.section
;
5500 b
->line_number
= sal
.line
;
5502 set_breakpoint_location_function (b
->loc
);
5504 breakpoints_changed ();
5510 /* Note that the breakpoint object B describes a permanent breakpoint
5511 instruction, hard-wired into the inferior's code. */
5513 make_breakpoint_permanent (struct breakpoint
*b
)
5515 struct bp_location
*bl
;
5516 b
->enable_state
= bp_permanent
;
5518 /* By definition, permanent breakpoints are already present in the code.
5519 Mark all locations as inserted. For now, make_breakpoint_permanent
5520 is called in just one place, so it's hard to say if it's reasonable
5521 to have permanent breakpoint with multiple locations or not,
5522 but it's easy to implmement. */
5523 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5527 /* Call this routine when stepping and nexting to enable a breakpoint
5528 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5529 set_longjmp_resume_breakpoint() to figure out where we are going. */
5532 set_longjmp_breakpoint (int thread
)
5534 struct breakpoint
*b
, *temp
;
5536 /* To avoid having to rescan all objfile symbols at every step,
5537 we maintain a list of continually-inserted but always disabled
5538 longjmp "master" breakpoints. Here, we simply create momentary
5539 clones of those and enable them for the requested thread. */
5540 ALL_BREAKPOINTS_SAFE (b
, temp
)
5541 if (b
->pspace
== current_program_space
5542 && b
->type
== bp_longjmp_master
)
5544 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5545 clone
->type
= bp_longjmp
;
5546 clone
->thread
= thread
;
5550 /* Delete all longjmp breakpoints from THREAD. */
5552 delete_longjmp_breakpoint (int thread
)
5554 struct breakpoint
*b
, *temp
;
5556 ALL_BREAKPOINTS_SAFE (b
, temp
)
5557 if (b
->type
== bp_longjmp
)
5559 if (b
->thread
== thread
)
5560 delete_breakpoint (b
);
5565 enable_overlay_breakpoints (void)
5567 struct breakpoint
*b
;
5570 if (b
->type
== bp_overlay_event
)
5572 b
->enable_state
= bp_enabled
;
5573 update_global_location_list (1);
5574 overlay_events_enabled
= 1;
5579 disable_overlay_breakpoints (void)
5581 struct breakpoint
*b
;
5584 if (b
->type
== bp_overlay_event
)
5586 b
->enable_state
= bp_disabled
;
5587 update_global_location_list (0);
5588 overlay_events_enabled
= 0;
5592 /* Set an active std::terminate breakpoint for each std::terminate
5593 master breakpoint. */
5595 set_std_terminate_breakpoint (void)
5597 struct breakpoint
*b
, *temp
;
5599 ALL_BREAKPOINTS_SAFE (b
, temp
)
5600 if (b
->pspace
== current_program_space
5601 && b
->type
== bp_std_terminate_master
)
5603 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5604 clone
->type
= bp_std_terminate
;
5608 /* Delete all the std::terminate breakpoints. */
5610 delete_std_terminate_breakpoint (void)
5612 struct breakpoint
*b
, *temp
;
5614 ALL_BREAKPOINTS_SAFE (b
, temp
)
5615 if (b
->type
== bp_std_terminate
)
5616 delete_breakpoint (b
);
5620 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5622 struct breakpoint
*b
;
5624 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5626 b
->enable_state
= bp_enabled
;
5627 /* addr_string has to be used or breakpoint_re_set will delete me. */
5629 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5631 update_global_location_list_nothrow (1);
5637 remove_thread_event_breakpoints (void)
5639 struct breakpoint
*b
, *temp
;
5641 ALL_BREAKPOINTS_SAFE (b
, temp
)
5642 if (b
->type
== bp_thread_event
5643 && b
->loc
->pspace
== current_program_space
)
5644 delete_breakpoint (b
);
5647 struct captured_parse_breakpoint_args
5650 struct symtabs_and_lines
*sals_p
;
5651 char ***addr_string_p
;
5655 struct lang_and_radix
5661 /* Create a breakpoint for JIT code registration and unregistration. */
5664 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5666 struct breakpoint
*b
;
5668 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5669 update_global_location_list_nothrow (1);
5674 remove_solib_event_breakpoints (void)
5676 struct breakpoint
*b
, *temp
;
5678 ALL_BREAKPOINTS_SAFE (b
, temp
)
5679 if (b
->type
== bp_shlib_event
5680 && b
->loc
->pspace
== current_program_space
)
5681 delete_breakpoint (b
);
5685 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5687 struct breakpoint
*b
;
5689 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5690 update_global_location_list_nothrow (1);
5694 /* Disable any breakpoints that are on code in shared libraries. Only
5695 apply to enabled breakpoints, disabled ones can just stay disabled. */
5698 disable_breakpoints_in_shlibs (void)
5700 struct bp_location
*loc
, **locp_tmp
;
5702 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5704 struct breakpoint
*b
= loc
->owner
;
5705 /* We apply the check to all breakpoints, including disabled
5706 for those with loc->duplicate set. This is so that when breakpoint
5707 becomes enabled, or the duplicate is removed, gdb will try to insert
5708 all breakpoints. If we don't set shlib_disabled here, we'll try
5709 to insert those breakpoints and fail. */
5710 if (((b
->type
== bp_breakpoint
)
5711 || (b
->type
== bp_jit_event
)
5712 || (b
->type
== bp_hardware_breakpoint
)
5713 || (is_tracepoint (b
)))
5714 && loc
->pspace
== current_program_space
5715 && !loc
->shlib_disabled
5717 && PC_SOLIB (loc
->address
)
5719 && solib_name_from_address (loc
->pspace
, loc
->address
)
5723 loc
->shlib_disabled
= 1;
5728 /* Disable any breakpoints that are in in an unloaded shared library. Only
5729 apply to enabled breakpoints, disabled ones can just stay disabled. */
5732 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5734 struct bp_location
*loc
, **locp_tmp
;
5735 int disabled_shlib_breaks
= 0;
5737 /* SunOS a.out shared libraries are always mapped, so do not
5738 disable breakpoints; they will only be reported as unloaded
5739 through clear_solib when GDB discards its shared library
5740 list. See clear_solib for more information. */
5741 if (exec_bfd
!= NULL
5742 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5745 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5747 struct breakpoint
*b
= loc
->owner
;
5748 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5749 || loc
->loc_type
== bp_loc_software_breakpoint
)
5750 && solib
->pspace
== loc
->pspace
5751 && !loc
->shlib_disabled
5752 && (b
->type
== bp_breakpoint
5753 || b
->type
== bp_jit_event
5754 || b
->type
== bp_hardware_breakpoint
)
5755 && solib_contains_address_p (solib
, loc
->address
))
5757 loc
->shlib_disabled
= 1;
5758 /* At this point, we cannot rely on remove_breakpoint
5759 succeeding so we must mark the breakpoint as not inserted
5760 to prevent future errors occurring in remove_breakpoints. */
5762 if (!disabled_shlib_breaks
)
5764 target_terminal_ours_for_output ();
5765 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5768 disabled_shlib_breaks
= 1;
5773 /* FORK & VFORK catchpoints. */
5775 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5778 insert_catch_fork (struct breakpoint
*b
)
5780 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5783 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5786 remove_catch_fork (struct breakpoint
*b
)
5788 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5791 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5795 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5797 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5800 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5802 static enum print_stop_action
5803 print_it_catch_fork (struct breakpoint
*b
)
5805 annotate_catchpoint (b
->number
);
5806 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5807 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5808 return PRINT_SRC_AND_LOC
;
5811 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5814 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5816 struct value_print_options opts
;
5818 get_user_print_options (&opts
);
5820 /* Field 4, the address, is omitted (which makes the columns
5821 not line up too nicely with the headers, but the effect
5822 is relatively readable). */
5823 if (opts
.addressprint
)
5824 ui_out_field_skip (uiout
, "addr");
5826 ui_out_text (uiout
, "fork");
5827 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5829 ui_out_text (uiout
, ", process ");
5830 ui_out_field_int (uiout
, "what",
5831 ptid_get_pid (b
->forked_inferior_pid
));
5832 ui_out_spaces (uiout
, 1);
5836 /* Implement the "print_mention" breakpoint_ops method for fork
5840 print_mention_catch_fork (struct breakpoint
*b
)
5842 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5845 /* The breakpoint_ops structure to be used in fork catchpoints. */
5847 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5851 breakpoint_hit_catch_fork
,
5852 print_it_catch_fork
,
5853 print_one_catch_fork
,
5854 print_mention_catch_fork
5857 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5860 insert_catch_vfork (struct breakpoint
*b
)
5862 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5865 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5868 remove_catch_vfork (struct breakpoint
*b
)
5870 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5873 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5877 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5879 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5882 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5884 static enum print_stop_action
5885 print_it_catch_vfork (struct breakpoint
*b
)
5887 annotate_catchpoint (b
->number
);
5888 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5889 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5890 return PRINT_SRC_AND_LOC
;
5893 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5896 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5898 struct value_print_options opts
;
5900 get_user_print_options (&opts
);
5901 /* Field 4, the address, is omitted (which makes the columns
5902 not line up too nicely with the headers, but the effect
5903 is relatively readable). */
5904 if (opts
.addressprint
)
5905 ui_out_field_skip (uiout
, "addr");
5907 ui_out_text (uiout
, "vfork");
5908 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5910 ui_out_text (uiout
, ", process ");
5911 ui_out_field_int (uiout
, "what",
5912 ptid_get_pid (b
->forked_inferior_pid
));
5913 ui_out_spaces (uiout
, 1);
5917 /* Implement the "print_mention" breakpoint_ops method for vfork
5921 print_mention_catch_vfork (struct breakpoint
*b
)
5923 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5926 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5928 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5932 breakpoint_hit_catch_vfork
,
5933 print_it_catch_vfork
,
5934 print_one_catch_vfork
,
5935 print_mention_catch_vfork
5938 /* Implement the "insert" breakpoint_ops method for syscall
5942 insert_catch_syscall (struct breakpoint
*b
)
5944 struct inferior
*inf
= current_inferior ();
5946 ++inf
->total_syscalls_count
;
5947 if (!b
->syscalls_to_be_caught
)
5948 ++inf
->any_syscall_count
;
5953 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5957 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5959 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5960 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5962 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5963 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5965 memset ((void *) vec_addr
, 0,
5966 (iter
+ 1 - old_size
) * sizeof (int));
5968 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5969 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5973 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5974 inf
->total_syscalls_count
!= 0,
5975 inf
->any_syscall_count
,
5976 VEC_length (int, inf
->syscalls_counts
),
5977 VEC_address (int, inf
->syscalls_counts
));
5980 /* Implement the "remove" breakpoint_ops method for syscall
5984 remove_catch_syscall (struct breakpoint
*b
)
5986 struct inferior
*inf
= current_inferior ();
5988 --inf
->total_syscalls_count
;
5989 if (!b
->syscalls_to_be_caught
)
5990 --inf
->any_syscall_count
;
5995 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5999 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6000 /* Shouldn't happen. */
6002 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6003 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6007 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6008 inf
->total_syscalls_count
!= 0,
6009 inf
->any_syscall_count
,
6010 VEC_length (int, inf
->syscalls_counts
),
6011 VEC_address (int, inf
->syscalls_counts
));
6014 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6018 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6020 /* We must check if we are catching specific syscalls in this breakpoint.
6021 If we are, then we must guarantee that the called syscall is the same
6022 syscall we are catching. */
6023 int syscall_number
= 0;
6025 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6028 /* Now, checking if the syscall is the same. */
6029 if (b
->syscalls_to_be_caught
)
6033 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6035 if (syscall_number
== iter
)
6045 /* Implement the "print_it" breakpoint_ops method for syscall
6048 static enum print_stop_action
6049 print_it_catch_syscall (struct breakpoint
*b
)
6051 /* These are needed because we want to know in which state a
6052 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6053 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6054 must print "called syscall" or "returned from syscall". */
6056 struct target_waitstatus last
;
6058 struct cleanup
*old_chain
;
6061 get_last_target_status (&ptid
, &last
);
6063 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6065 annotate_catchpoint (b
->number
);
6068 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6070 syscall_id
= xstrprintf ("'%s'", s
.name
);
6072 old_chain
= make_cleanup (xfree
, syscall_id
);
6074 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6075 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6076 b
->number
, syscall_id
);
6077 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6078 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6079 b
->number
, syscall_id
);
6081 do_cleanups (old_chain
);
6083 return PRINT_SRC_AND_LOC
;
6086 /* Implement the "print_one" breakpoint_ops method for syscall
6090 print_one_catch_syscall (struct breakpoint
*b
,
6091 struct bp_location
**last_loc
)
6093 struct value_print_options opts
;
6095 get_user_print_options (&opts
);
6096 /* Field 4, the address, is omitted (which makes the columns
6097 not line up too nicely with the headers, but the effect
6098 is relatively readable). */
6099 if (opts
.addressprint
)
6100 ui_out_field_skip (uiout
, "addr");
6103 if (b
->syscalls_to_be_caught
6104 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6105 ui_out_text (uiout
, "syscalls \"");
6107 ui_out_text (uiout
, "syscall \"");
6109 if (b
->syscalls_to_be_caught
)
6112 char *text
= xstrprintf ("%s", "");
6114 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6119 get_syscall_by_number (iter
, &s
);
6122 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6124 text
= xstrprintf ("%s%d, ", text
, iter
);
6126 /* We have to xfree the last 'text' (now stored at 'x')
6127 because xstrprintf dinamically allocates new space for it
6131 /* Remove the last comma. */
6132 text
[strlen (text
) - 2] = '\0';
6133 ui_out_field_string (uiout
, "what", text
);
6136 ui_out_field_string (uiout
, "what", "<any syscall>");
6137 ui_out_text (uiout
, "\" ");
6140 /* Implement the "print_mention" breakpoint_ops method for syscall
6144 print_mention_catch_syscall (struct breakpoint
*b
)
6146 if (b
->syscalls_to_be_caught
)
6150 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6151 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6153 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6156 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6160 get_syscall_by_number (iter
, &s
);
6163 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6165 printf_filtered (" %d", s
.number
);
6167 printf_filtered (")");
6170 printf_filtered (_("Catchpoint %d (any syscall)"),
6174 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6176 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6178 insert_catch_syscall
,
6179 remove_catch_syscall
,
6180 breakpoint_hit_catch_syscall
,
6181 print_it_catch_syscall
,
6182 print_one_catch_syscall
,
6183 print_mention_catch_syscall
6186 /* Returns non-zero if 'b' is a syscall catchpoint. */
6189 syscall_catchpoint_p (struct breakpoint
*b
)
6191 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6194 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6195 but does NOT mention it nor update the global location list.
6196 This is useful if you need to fill more fields in the
6197 struct breakpoint before calling mention.
6199 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6200 If COND_STRING is not NULL, then store it in the breakpoint.
6201 OPS, if not NULL, is the breakpoint_ops structure associated
6202 to the catchpoint. */
6204 static struct breakpoint
*
6205 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6207 struct breakpoint_ops
*ops
)
6209 struct symtab_and_line sal
;
6210 struct breakpoint
*b
;
6213 sal
.pspace
= current_program_space
;
6215 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6216 set_breakpoint_count (breakpoint_count
+ 1);
6217 b
->number
= breakpoint_count
;
6219 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6221 b
->addr_string
= NULL
;
6222 b
->enable_state
= bp_enabled
;
6223 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6229 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6231 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6232 If COND_STRING is not NULL, then store it in the breakpoint.
6233 OPS, if not NULL, is the breakpoint_ops structure associated
6234 to the catchpoint. */
6236 static struct breakpoint
*
6237 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6238 char *cond_string
, struct breakpoint_ops
*ops
)
6240 struct breakpoint
*b
=
6241 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6244 update_global_location_list (1);
6250 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6251 int tempflag
, char *cond_string
,
6252 struct breakpoint_ops
*ops
)
6254 struct breakpoint
*b
6255 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6257 /* FIXME: We should put this information in a breakpoint private data
6259 b
->forked_inferior_pid
= null_ptid
;
6262 /* Exec catchpoints. */
6265 insert_catch_exec (struct breakpoint
*b
)
6267 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6271 remove_catch_exec (struct breakpoint
*b
)
6273 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6277 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6279 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6282 static enum print_stop_action
6283 print_it_catch_exec (struct breakpoint
*b
)
6285 annotate_catchpoint (b
->number
);
6286 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6288 return PRINT_SRC_AND_LOC
;
6292 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6294 struct value_print_options opts
;
6296 get_user_print_options (&opts
);
6298 /* Field 4, the address, is omitted (which makes the columns
6299 not line up too nicely with the headers, but the effect
6300 is relatively readable). */
6301 if (opts
.addressprint
)
6302 ui_out_field_skip (uiout
, "addr");
6304 ui_out_text (uiout
, "exec");
6305 if (b
->exec_pathname
!= NULL
)
6307 ui_out_text (uiout
, ", program \"");
6308 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6309 ui_out_text (uiout
, "\" ");
6314 print_mention_catch_exec (struct breakpoint
*b
)
6316 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6319 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6323 breakpoint_hit_catch_exec
,
6324 print_it_catch_exec
,
6325 print_one_catch_exec
,
6326 print_mention_catch_exec
6330 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6331 struct breakpoint_ops
*ops
)
6333 struct gdbarch
*gdbarch
= get_current_arch ();
6334 struct breakpoint
*b
=
6335 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6337 b
->syscalls_to_be_caught
= filter
;
6339 /* Now, we have to mention the breakpoint and update the global
6342 update_global_location_list (1);
6346 hw_breakpoint_used_count (void)
6348 struct breakpoint
*b
;
6353 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6361 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6363 struct breakpoint
*b
;
6366 *other_type_used
= 0;
6369 if (breakpoint_enabled (b
))
6371 if (b
->type
== type
)
6373 else if ((b
->type
== bp_hardware_watchpoint
6374 || b
->type
== bp_read_watchpoint
6375 || b
->type
== bp_access_watchpoint
))
6376 *other_type_used
= 1;
6383 disable_watchpoints_before_interactive_call_start (void)
6385 struct breakpoint
*b
;
6389 if (((b
->type
== bp_watchpoint
)
6390 || (b
->type
== bp_hardware_watchpoint
)
6391 || (b
->type
== bp_read_watchpoint
)
6392 || (b
->type
== bp_access_watchpoint
))
6393 && breakpoint_enabled (b
))
6395 b
->enable_state
= bp_call_disabled
;
6396 update_global_location_list (0);
6402 enable_watchpoints_after_interactive_call_stop (void)
6404 struct breakpoint
*b
;
6408 if (((b
->type
== bp_watchpoint
)
6409 || (b
->type
== bp_hardware_watchpoint
)
6410 || (b
->type
== bp_read_watchpoint
)
6411 || (b
->type
== bp_access_watchpoint
))
6412 && (b
->enable_state
== bp_call_disabled
))
6414 b
->enable_state
= bp_enabled
;
6415 update_global_location_list (1);
6421 disable_breakpoints_before_startup (void)
6423 struct breakpoint
*b
;
6428 if (b
->pspace
!= current_program_space
)
6431 if ((b
->type
== bp_breakpoint
6432 || b
->type
== bp_hardware_breakpoint
)
6433 && breakpoint_enabled (b
))
6435 b
->enable_state
= bp_startup_disabled
;
6441 update_global_location_list (0);
6443 current_program_space
->executing_startup
= 1;
6447 enable_breakpoints_after_startup (void)
6449 struct breakpoint
*b
;
6452 current_program_space
->executing_startup
= 0;
6456 if (b
->pspace
!= current_program_space
)
6459 if ((b
->type
== bp_breakpoint
6460 || b
->type
== bp_hardware_breakpoint
)
6461 && b
->enable_state
== bp_startup_disabled
)
6463 b
->enable_state
= bp_enabled
;
6469 breakpoint_re_set ();
6473 /* Set a breakpoint that will evaporate an end of command
6474 at address specified by SAL.
6475 Restrict it to frame FRAME if FRAME is nonzero. */
6478 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6479 struct frame_id frame_id
, enum bptype type
)
6481 struct breakpoint
*b
;
6483 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6485 gdb_assert (!frame_id_inlined_p (frame_id
));
6487 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6488 b
->enable_state
= bp_enabled
;
6489 b
->disposition
= disp_donttouch
;
6490 b
->frame_id
= frame_id
;
6492 /* If we're debugging a multi-threaded program, then we
6493 want momentary breakpoints to be active in only a
6494 single thread of control. */
6495 if (in_thread_list (inferior_ptid
))
6496 b
->thread
= pid_to_thread_id (inferior_ptid
);
6498 update_global_location_list_nothrow (1);
6503 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6507 clone_momentary_breakpoint (struct breakpoint
*orig
)
6509 struct breakpoint
*copy
;
6511 /* If there's nothing to clone, then return nothing. */
6515 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6516 copy
->loc
= allocate_bp_location (copy
);
6517 set_breakpoint_location_function (copy
->loc
);
6519 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6520 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6521 copy
->loc
->address
= orig
->loc
->address
;
6522 copy
->loc
->section
= orig
->loc
->section
;
6523 copy
->loc
->pspace
= orig
->loc
->pspace
;
6525 if (orig
->source_file
== NULL
)
6526 copy
->source_file
= NULL
;
6528 copy
->source_file
= xstrdup (orig
->source_file
);
6530 copy
->line_number
= orig
->line_number
;
6531 copy
->frame_id
= orig
->frame_id
;
6532 copy
->thread
= orig
->thread
;
6533 copy
->pspace
= orig
->pspace
;
6535 copy
->enable_state
= bp_enabled
;
6536 copy
->disposition
= disp_donttouch
;
6537 copy
->number
= internal_breakpoint_number
--;
6539 update_global_location_list_nothrow (0);
6544 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6547 struct symtab_and_line sal
;
6549 sal
= find_pc_line (pc
, 0);
6551 sal
.section
= find_pc_overlay (pc
);
6552 sal
.explicit_pc
= 1;
6554 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6558 /* Tell the user we have just set a breakpoint B. */
6561 mention (struct breakpoint
*b
)
6564 struct cleanup
*ui_out_chain
;
6565 struct value_print_options opts
;
6567 get_user_print_options (&opts
);
6569 /* FIXME: This is misplaced; mention() is called by things (like
6570 hitting a watchpoint) other than breakpoint creation. It should
6571 be possible to clean this up and at the same time replace the
6572 random calls to breakpoint_changed with this hook. */
6573 observer_notify_breakpoint_created (b
->number
);
6575 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6576 b
->ops
->print_mention (b
);
6581 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6584 ui_out_text (uiout
, "Watchpoint ");
6585 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6586 ui_out_field_int (uiout
, "number", b
->number
);
6587 ui_out_text (uiout
, ": ");
6588 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6589 do_cleanups (ui_out_chain
);
6591 case bp_hardware_watchpoint
:
6592 ui_out_text (uiout
, "Hardware watchpoint ");
6593 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6594 ui_out_field_int (uiout
, "number", b
->number
);
6595 ui_out_text (uiout
, ": ");
6596 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6597 do_cleanups (ui_out_chain
);
6599 case bp_read_watchpoint
:
6600 ui_out_text (uiout
, "Hardware read watchpoint ");
6601 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6602 ui_out_field_int (uiout
, "number", b
->number
);
6603 ui_out_text (uiout
, ": ");
6604 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6605 do_cleanups (ui_out_chain
);
6607 case bp_access_watchpoint
:
6608 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6609 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6610 ui_out_field_int (uiout
, "number", b
->number
);
6611 ui_out_text (uiout
, ": ");
6612 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6613 do_cleanups (ui_out_chain
);
6616 if (ui_out_is_mi_like_p (uiout
))
6621 if (b
->disposition
== disp_del
)
6622 printf_filtered (_("Temporary breakpoint"));
6624 printf_filtered (_("Breakpoint"));
6625 printf_filtered (_(" %d"), b
->number
);
6628 case bp_hardware_breakpoint
:
6629 if (ui_out_is_mi_like_p (uiout
))
6634 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6638 if (ui_out_is_mi_like_p (uiout
))
6643 printf_filtered (_("Tracepoint"));
6644 printf_filtered (_(" %d"), b
->number
);
6647 case bp_fast_tracepoint
:
6648 if (ui_out_is_mi_like_p (uiout
))
6653 printf_filtered (_("Fast tracepoint"));
6654 printf_filtered (_(" %d"), b
->number
);
6661 case bp_longjmp_resume
:
6662 case bp_step_resume
:
6664 case bp_std_terminate
:
6665 case bp_watchpoint_scope
:
6666 case bp_shlib_event
:
6667 case bp_thread_event
:
6668 case bp_overlay_event
:
6670 case bp_longjmp_master
:
6671 case bp_std_terminate_master
:
6677 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6681 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6685 if (opts
.addressprint
|| b
->source_file
== NULL
)
6687 printf_filtered (" at ");
6688 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6692 printf_filtered (": file %s, line %d.",
6693 b
->source_file
, b
->line_number
);
6697 struct bp_location
*loc
= b
->loc
;
6699 for (; loc
; loc
= loc
->next
)
6701 printf_filtered (" (%d locations)", n
);
6706 if (ui_out_is_mi_like_p (uiout
))
6708 printf_filtered ("\n");
6712 static struct bp_location
*
6713 add_location_to_breakpoint (struct breakpoint
*b
,
6714 const struct symtab_and_line
*sal
)
6716 struct bp_location
*loc
, **tmp
;
6718 loc
= allocate_bp_location (b
);
6719 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6722 loc
->gdbarch
= get_sal_arch (*sal
);
6724 loc
->gdbarch
= b
->gdbarch
;
6725 loc
->requested_address
= sal
->pc
;
6726 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6727 loc
->requested_address
, b
->type
);
6728 loc
->pspace
= sal
->pspace
;
6729 gdb_assert (loc
->pspace
!= NULL
);
6730 loc
->section
= sal
->section
;
6732 set_breakpoint_location_function (loc
);
6737 /* Return 1 if LOC is pointing to a permanent breakpoint,
6738 return 0 otherwise. */
6741 bp_loc_is_permanent (struct bp_location
*loc
)
6745 const gdb_byte
*brk
;
6746 gdb_byte
*target_mem
;
6747 struct cleanup
*cleanup
;
6750 gdb_assert (loc
!= NULL
);
6752 addr
= loc
->address
;
6753 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6755 /* Software breakpoints unsupported? */
6759 target_mem
= alloca (len
);
6761 /* Enable the automatic memory restoration from breakpoints while
6762 we read the memory. Otherwise we could say about our temporary
6763 breakpoints they are permanent. */
6764 cleanup
= save_current_space_and_thread ();
6766 switch_to_program_space_and_thread (loc
->pspace
);
6767 make_show_memory_breakpoints_cleanup (0);
6769 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6770 && memcmp (target_mem
, brk
, len
) == 0)
6773 do_cleanups (cleanup
);
6780 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6781 as textual description of the location, and COND_STRING
6782 as condition expression. */
6785 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6786 struct symtabs_and_lines sals
, char *addr_string
,
6788 enum bptype type
, enum bpdisp disposition
,
6789 int thread
, int task
, int ignore_count
,
6790 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6792 struct breakpoint
*b
= NULL
;
6795 if (type
== bp_hardware_breakpoint
)
6797 int i
= hw_breakpoint_used_count ();
6798 int target_resources_ok
=
6799 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6801 if (target_resources_ok
== 0)
6802 error (_("No hardware breakpoint support in the target."));
6803 else if (target_resources_ok
< 0)
6804 error (_("Hardware breakpoints used exceeds limit."));
6807 gdb_assert (sals
.nelts
> 0);
6809 for (i
= 0; i
< sals
.nelts
; ++i
)
6811 struct symtab_and_line sal
= sals
.sals
[i
];
6812 struct bp_location
*loc
;
6816 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6818 loc_gdbarch
= gdbarch
;
6820 describe_other_breakpoints (loc_gdbarch
,
6821 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6826 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6827 set_breakpoint_count (breakpoint_count
+ 1);
6828 b
->number
= breakpoint_count
;
6832 b
->cond_string
= cond_string
;
6833 b
->ignore_count
= ignore_count
;
6834 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6835 b
->disposition
= disposition
;
6837 b
->pspace
= sals
.sals
[0].pspace
;
6839 if (enabled
&& b
->pspace
->executing_startup
6840 && (b
->type
== bp_breakpoint
6841 || b
->type
== bp_hardware_breakpoint
))
6842 b
->enable_state
= bp_startup_disabled
;
6848 loc
= add_location_to_breakpoint (b
, &sal
);
6851 if (bp_loc_is_permanent (loc
))
6852 make_breakpoint_permanent (b
);
6856 char *arg
= b
->cond_string
;
6857 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6859 error (_("Garbage %s follows condition"), arg
);
6864 b
->addr_string
= addr_string
;
6866 /* addr_string has to be used or breakpoint_re_set will delete
6869 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6875 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6876 elements to fill the void space. */
6878 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6880 int i
= index_to_remove
+1;
6881 int last_index
= sal
->nelts
-1;
6883 for (;i
<= last_index
; ++i
)
6884 sal
->sals
[i
-1] = sal
->sals
[i
];
6889 /* If appropriate, obtains all sals that correspond to the same file
6890 and line as SAL, in all program spaces. Users debugging with IDEs,
6891 will want to set a breakpoint at foo.c:line, and not really care
6892 about program spaces. This is done only if SAL does not have
6893 explicit PC and has line and file information. If we got just a
6894 single expanded sal, return the original.
6896 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6897 which the name of enclosing function is different from SAL. This
6898 makes sure that if we have breakpoint originally set in template
6899 instantiation, say foo<int>(), we won't expand SAL to locations at
6900 the same line in all existing instantiations of 'foo'. */
6902 static struct symtabs_and_lines
6903 expand_line_sal_maybe (struct symtab_and_line sal
)
6905 struct symtabs_and_lines expanded
;
6906 CORE_ADDR original_pc
= sal
.pc
;
6907 char *original_function
= NULL
;
6910 struct cleanup
*old_chain
;
6912 /* If we have explicit pc, don't expand.
6913 If we have no line number, we can't expand. */
6914 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6917 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6918 expanded
.sals
[0] = sal
;
6924 old_chain
= save_current_space_and_thread ();
6926 switch_to_program_space_and_thread (sal
.pspace
);
6928 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6930 /* Note that expand_line_sal visits *all* program spaces. */
6931 expanded
= expand_line_sal (sal
);
6933 if (expanded
.nelts
== 1)
6935 /* We had one sal, we got one sal. Return that sal, adjusting it
6936 past the function prologue if necessary. */
6937 xfree (expanded
.sals
);
6939 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6940 sal
.pc
= original_pc
;
6941 expanded
.sals
[0] = sal
;
6942 skip_prologue_sal (&expanded
.sals
[0]);
6943 do_cleanups (old_chain
);
6947 if (!sal
.explicit_line
)
6949 CORE_ADDR func_addr
, func_end
;
6950 for (i
= 0; i
< expanded
.nelts
; ++i
)
6952 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6953 char *this_function
;
6955 /* We need to switch threads as well since we're about to
6957 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6959 if (find_pc_partial_function (pc
, &this_function
,
6960 &func_addr
, &func_end
))
6963 && strcmp (this_function
, original_function
) != 0)
6965 remove_sal (&expanded
, i
);
6972 /* Skip the function prologue if necessary. */
6973 for (i
= 0; i
< expanded
.nelts
; ++i
)
6974 skip_prologue_sal (&expanded
.sals
[i
]);
6976 do_cleanups (old_chain
);
6978 if (expanded
.nelts
<= 1)
6980 /* This is un ugly workaround. If we get zero
6981 expanded sals then something is really wrong.
6982 Fix that by returnign the original sal. */
6983 xfree (expanded
.sals
);
6985 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6986 sal
.pc
= original_pc
;
6987 expanded
.sals
[0] = sal
;
6994 for (i
= 0; i
< expanded
.nelts
; ++i
)
6995 if (expanded
.sals
[i
].pc
== original_pc
)
7006 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7007 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7008 value. COND_STRING, if not NULL, specified the condition to be
7009 used for all breakpoints. Essentially the only case where
7010 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7011 function. In that case, it's still not possible to specify
7012 separate conditions for different overloaded functions, so
7013 we take just a single condition string.
7015 NOTE: If the function succeeds, the caller is expected to cleanup
7016 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7017 array contents). If the function fails (error() is called), the
7018 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7019 COND and SALS arrays and each of those arrays contents. */
7022 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7023 struct symtabs_and_lines sals
, char **addr_string
,
7025 enum bptype type
, enum bpdisp disposition
,
7026 int thread
, int task
, int ignore_count
,
7027 struct breakpoint_ops
*ops
, int from_tty
,
7031 for (i
= 0; i
< sals
.nelts
; ++i
)
7033 struct symtabs_and_lines expanded
=
7034 expand_line_sal_maybe (sals
.sals
[i
]);
7036 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7037 cond_string
, type
, disposition
,
7038 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7042 /* Parse ARG which is assumed to be a SAL specification possibly
7043 followed by conditionals. On return, SALS contains an array of SAL
7044 addresses found. ADDR_STRING contains a vector of (canonical)
7045 address strings. ARG points to the end of the SAL. */
7048 parse_breakpoint_sals (char **address
,
7049 struct symtabs_and_lines
*sals
,
7050 char ***addr_string
,
7053 char *addr_start
= *address
;
7054 *addr_string
= NULL
;
7055 /* If no arg given, or if first arg is 'if ', use the default
7057 if ((*address
) == NULL
7058 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7060 if (default_breakpoint_valid
)
7062 struct symtab_and_line sal
;
7063 init_sal (&sal
); /* initialize to zeroes */
7064 sals
->sals
= (struct symtab_and_line
*)
7065 xmalloc (sizeof (struct symtab_and_line
));
7066 sal
.pc
= default_breakpoint_address
;
7067 sal
.line
= default_breakpoint_line
;
7068 sal
.symtab
= default_breakpoint_symtab
;
7069 sal
.pspace
= default_breakpoint_pspace
;
7070 sal
.section
= find_pc_overlay (sal
.pc
);
7072 /* "break" without arguments is equivalent to "break *PC" where PC is
7073 the default_breakpoint_address. So make sure to set
7074 sal.explicit_pc to prevent GDB from trying to expand the list of
7075 sals to include all other instances with the same symtab and line.
7077 sal
.explicit_pc
= 1;
7079 sals
->sals
[0] = sal
;
7083 error (_("No default breakpoint address now."));
7087 /* Force almost all breakpoints to be in terms of the
7088 current_source_symtab (which is decode_line_1's default). This
7089 should produce the results we want almost all of the time while
7090 leaving default_breakpoint_* alone.
7091 ObjC: However, don't match an Objective-C method name which
7092 may have a '+' or '-' succeeded by a '[' */
7094 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7096 if (default_breakpoint_valid
7098 || ((strchr ("+-", (*address
)[0]) != NULL
)
7099 && ((*address
)[1] != '['))))
7100 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7101 default_breakpoint_line
, addr_string
,
7104 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7105 addr_string
, not_found_ptr
);
7107 /* For any SAL that didn't have a canonical string, fill one in. */
7108 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7109 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7110 if (addr_start
!= (*address
))
7113 for (i
= 0; i
< sals
->nelts
; i
++)
7115 /* Add the string if not present. */
7116 if ((*addr_string
)[i
] == NULL
)
7117 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7123 /* Convert each SAL into a real PC. Verify that the PC can be
7124 inserted as a breakpoint. If it can't throw an error. */
7127 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7131 for (i
= 0; i
< sals
->nelts
; i
++)
7132 resolve_sal_pc (&sals
->sals
[i
]);
7135 /* Fast tracepoints may have restrictions on valid locations. For
7136 instance, a fast tracepoint using a jump instead of a trap will
7137 likely have to overwrite more bytes than a trap would, and so can
7138 only be placed where the instruction is longer than the jump, or a
7139 multi-instruction sequence does not have a jump into the middle of
7143 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7144 struct symtabs_and_lines
*sals
)
7147 struct symtab_and_line
*sal
;
7149 struct cleanup
*old_chain
;
7151 for (i
= 0; i
< sals
->nelts
; i
++)
7153 sal
= &sals
->sals
[i
];
7155 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7157 old_chain
= make_cleanup (xfree
, msg
);
7160 error (_("May not have a fast tracepoint at 0x%s%s"),
7161 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7163 do_cleanups (old_chain
);
7168 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7170 struct captured_parse_breakpoint_args
*args
= data
;
7172 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7173 args
->not_found_ptr
);
7176 /* Given TOK, a string specification of condition and thread, as
7177 accepted by the 'break' command, extract the condition
7178 string and thread number and set *COND_STRING and *THREAD.
7179 PC identifies the context at which the condition should be parsed.
7180 If no condition is found, *COND_STRING is set to NULL.
7181 If no thread is found, *THREAD is set to -1. */
7183 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7184 char **cond_string
, int *thread
, int *task
)
7186 *cond_string
= NULL
;
7192 char *cond_start
= NULL
;
7193 char *cond_end
= NULL
;
7194 while (*tok
== ' ' || *tok
== '\t')
7199 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7202 toklen
= end_tok
- tok
;
7204 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7206 struct expression
*expr
;
7208 tok
= cond_start
= end_tok
+ 1;
7209 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7212 *cond_string
= savestring (cond_start
,
7213 cond_end
- cond_start
);
7215 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7221 *thread
= strtol (tok
, &tok
, 0);
7223 error (_("Junk after thread keyword."));
7224 if (!valid_thread_id (*thread
))
7225 error (_("Unknown thread %d."), *thread
);
7227 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7233 *task
= strtol (tok
, &tok
, 0);
7235 error (_("Junk after task keyword."));
7236 if (!valid_task_id (*task
))
7237 error (_("Unknown task %d."), *task
);
7240 error (_("Junk at end of arguments."));
7244 /* Set a breakpoint. This function is shared between CLI and MI
7245 functions for setting a breakpoint. This function has two major
7246 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7247 parameter. If non-zero, the function will parse arg, extracting
7248 breakpoint location, address and thread. Otherwise, ARG is just the
7249 location of breakpoint, with condition and thread specified by the
7250 COND_STRING and THREAD parameters. Returns true if any breakpoint
7251 was created; false otherwise. */
7254 create_breakpoint (struct gdbarch
*gdbarch
,
7255 char *arg
, char *cond_string
, int thread
,
7256 int parse_condition_and_thread
,
7257 int tempflag
, int hardwareflag
, int traceflag
,
7259 enum auto_boolean pending_break_support
,
7260 struct breakpoint_ops
*ops
,
7264 struct gdb_exception e
;
7265 struct symtabs_and_lines sals
;
7266 struct symtab_and_line pending_sal
;
7269 char *addr_start
= arg
;
7271 struct cleanup
*old_chain
;
7272 struct cleanup
*bkpt_chain
= NULL
;
7273 struct captured_parse_breakpoint_args parse_args
;
7277 enum bptype type_wanted
;
7279 int prev_bkpt_count
= breakpoint_count
;
7285 parse_args
.arg_p
= &arg
;
7286 parse_args
.sals_p
= &sals
;
7287 parse_args
.addr_string_p
= &addr_string
;
7288 parse_args
.not_found_ptr
= ¬_found
;
7290 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7291 &parse_args
, RETURN_MASK_ALL
);
7293 /* If caller is interested in rc value from parse, set value. */
7297 throw_exception (e
);
7301 case NOT_FOUND_ERROR
:
7303 /* If pending breakpoint support is turned off, throw
7306 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7307 throw_exception (e
);
7309 exception_print (gdb_stderr
, e
);
7311 /* If pending breakpoint support is auto query and the user
7312 selects no, then simply return the error code. */
7313 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7314 && !nquery ("Make breakpoint pending on future shared library load? "))
7317 /* At this point, either the user was queried about setting
7318 a pending breakpoint and selected yes, or pending
7319 breakpoint behavior is on and thus a pending breakpoint
7320 is defaulted on behalf of the user. */
7321 copy_arg
= xstrdup (addr_start
);
7322 addr_string
= ©_arg
;
7324 sals
.sals
= &pending_sal
;
7329 throw_exception (e
);
7336 /* Create a chain of things that always need to be cleaned up. */
7337 old_chain
= make_cleanup (null_cleanup
, 0);
7341 /* Make sure that all storage allocated to SALS gets freed. */
7342 make_cleanup (xfree
, sals
.sals
);
7344 /* Cleanup the addr_string array but not its contents. */
7345 make_cleanup (xfree
, addr_string
);
7348 /* ----------------------------- SNIP -----------------------------
7349 Anything added to the cleanup chain beyond this point is assumed
7350 to be part of a breakpoint. If the breakpoint create succeeds
7351 then the memory is not reclaimed. */
7352 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7354 /* Mark the contents of the addr_string for cleanup. These go on
7355 the bkpt_chain and only occur if the breakpoint create fails. */
7356 for (i
= 0; i
< sals
.nelts
; i
++)
7358 if (addr_string
[i
] != NULL
)
7359 make_cleanup (xfree
, addr_string
[i
]);
7362 /* Resolve all line numbers to PC's and verify that the addresses
7363 are ok for the target. */
7365 breakpoint_sals_to_pc (&sals
, addr_start
);
7367 type_wanted
= (traceflag
7368 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7369 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7371 /* Fast tracepoints may have additional restrictions on location. */
7372 if (type_wanted
== bp_fast_tracepoint
)
7373 check_fast_tracepoint_sals (gdbarch
, &sals
);
7375 /* Verify that condition can be parsed, before setting any
7376 breakpoints. Allocate a separate condition expression for each
7380 if (parse_condition_and_thread
)
7382 /* Here we only parse 'arg' to separate condition
7383 from thread number, so parsing in context of first
7384 sal is OK. When setting the breakpoint we'll
7385 re-parse it in context of each sal. */
7388 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7391 make_cleanup (xfree
, cond_string
);
7395 /* Create a private copy of condition string. */
7398 cond_string
= xstrdup (cond_string
);
7399 make_cleanup (xfree
, cond_string
);
7402 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7403 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7404 thread
, task
, ignore_count
, ops
, from_tty
,
7409 struct symtab_and_line sal
= {0};
7410 struct breakpoint
*b
;
7412 make_cleanup (xfree
, copy_arg
);
7414 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7415 set_breakpoint_count (breakpoint_count
+ 1);
7416 b
->number
= breakpoint_count
;
7418 b
->addr_string
= addr_string
[0];
7419 b
->cond_string
= NULL
;
7420 b
->ignore_count
= ignore_count
;
7421 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7422 b
->condition_not_parsed
= 1;
7424 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7425 b
->pspace
= current_program_space
;
7427 if (enabled
&& b
->pspace
->executing_startup
7428 && (b
->type
== bp_breakpoint
7429 || b
->type
== bp_hardware_breakpoint
))
7430 b
->enable_state
= bp_startup_disabled
;
7437 warning (_("Multiple breakpoints were set.\n"
7438 "Use the \"delete\" command to delete unwanted breakpoints."));
7439 prev_breakpoint_count
= prev_bkpt_count
;
7442 /* That's it. Discard the cleanups for data inserted into the
7444 discard_cleanups (bkpt_chain
);
7445 /* But cleanup everything else. */
7446 do_cleanups (old_chain
);
7448 /* error call may happen here - have BKPT_CHAIN already discarded. */
7449 update_global_location_list (1);
7454 /* Set a breakpoint.
7455 ARG is a string describing breakpoint address,
7456 condition, and thread.
7457 FLAG specifies if a breakpoint is hardware on,
7458 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7462 break_command_1 (char *arg
, int flag
, int from_tty
)
7464 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7465 int tempflag
= flag
& BP_TEMPFLAG
;
7467 create_breakpoint (get_current_arch (),
7469 NULL
, 0, 1 /* parse arg */,
7470 tempflag
, hardwareflag
, 0 /* traceflag */,
7471 0 /* Ignore count */,
7472 pending_break_support
,
7473 NULL
/* breakpoint_ops */,
7480 /* Helper function for break_command_1 and disassemble_command. */
7483 resolve_sal_pc (struct symtab_and_line
*sal
)
7487 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7489 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7490 error (_("No line %d in file \"%s\"."),
7491 sal
->line
, sal
->symtab
->filename
);
7494 /* If this SAL corresponds to a breakpoint inserted using
7495 a line number, then skip the function prologue if necessary. */
7496 if (sal
->explicit_line
)
7497 skip_prologue_sal (sal
);
7500 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7502 struct blockvector
*bv
;
7506 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7509 sym
= block_linkage_function (b
);
7512 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7513 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7517 /* It really is worthwhile to have the section, so we'll just
7518 have to look harder. This case can be executed if we have
7519 line numbers but no functions (as can happen in assembly
7522 struct minimal_symbol
*msym
;
7523 struct cleanup
*old_chain
= save_current_space_and_thread ();
7525 switch_to_program_space_and_thread (sal
->pspace
);
7527 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7529 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7531 do_cleanups (old_chain
);
7538 break_command (char *arg
, int from_tty
)
7540 break_command_1 (arg
, 0, from_tty
);
7544 tbreak_command (char *arg
, int from_tty
)
7546 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7550 hbreak_command (char *arg
, int from_tty
)
7552 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7556 thbreak_command (char *arg
, int from_tty
)
7558 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7562 stop_command (char *arg
, int from_tty
)
7564 printf_filtered (_("Specify the type of breakpoint to set.\n\
7565 Usage: stop in <function | address>\n\
7566 stop at <line>\n"));
7570 stopin_command (char *arg
, int from_tty
)
7574 if (arg
== (char *) NULL
)
7576 else if (*arg
!= '*')
7581 /* look for a ':'. If this is a line number specification, then
7582 say it is bad, otherwise, it should be an address or
7583 function/method name */
7584 while (*argptr
&& !hasColon
)
7586 hasColon
= (*argptr
== ':');
7591 badInput
= (*argptr
!= ':'); /* Not a class::method */
7593 badInput
= isdigit (*arg
); /* a simple line number */
7597 printf_filtered (_("Usage: stop in <function | address>\n"));
7599 break_command_1 (arg
, 0, from_tty
);
7603 stopat_command (char *arg
, int from_tty
)
7607 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7614 /* look for a ':'. If there is a '::' then get out, otherwise
7615 it is probably a line number. */
7616 while (*argptr
&& !hasColon
)
7618 hasColon
= (*argptr
== ':');
7623 badInput
= (*argptr
== ':'); /* we have class::method */
7625 badInput
= !isdigit (*arg
); /* not a line number */
7629 printf_filtered (_("Usage: stop at <line>\n"));
7631 break_command_1 (arg
, 0, from_tty
);
7634 /* accessflag: hw_write: watch write,
7635 hw_read: watch read,
7636 hw_access: watch access (read or write) */
7638 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7640 struct gdbarch
*gdbarch
= get_current_arch ();
7641 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7642 struct expression
*exp
;
7643 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7644 struct value
*val
, *mark
;
7645 struct frame_info
*frame
;
7646 char *exp_start
= NULL
;
7647 char *exp_end
= NULL
;
7648 char *tok
, *id_tok_start
, *end_tok
;
7650 char *cond_start
= NULL
;
7651 char *cond_end
= NULL
;
7652 int i
, other_type_used
, target_resources_ok
= 0;
7653 enum bptype bp_type
;
7657 /* Make sure that we actually have parameters to parse. */
7658 if (arg
!= NULL
&& arg
[0] != '\0')
7660 toklen
= strlen (arg
); /* Size of argument list. */
7662 /* Points tok to the end of the argument list. */
7663 tok
= arg
+ toklen
- 1;
7665 /* Go backwards in the parameters list. Skip the last parameter.
7666 If we're expecting a 'thread <thread_num>' parameter, this should
7667 be the thread identifier. */
7668 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7670 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7673 /* Points end_tok to the beginning of the last token. */
7674 id_tok_start
= tok
+ 1;
7676 /* Go backwards in the parameters list. Skip one more parameter.
7677 If we're expecting a 'thread <thread_num>' parameter, we should
7678 reach a "thread" token. */
7679 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7684 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7687 /* Move the pointer forward to skip the whitespace and
7688 calculate the length of the token. */
7690 toklen
= end_tok
- tok
;
7692 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7694 /* At this point we've found a "thread" token, which means
7695 the user is trying to set a watchpoint that triggers
7696 only in a specific thread. */
7699 /* Extract the thread ID from the next token. */
7700 thread
= strtol (id_tok_start
, &endp
, 0);
7702 /* Check if the user provided a valid numeric value for the
7704 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7705 error (_("Invalid thread ID specification %s."), id_tok_start
);
7707 /* Check if the thread actually exists. */
7708 if (!valid_thread_id (thread
))
7709 error (_("Unknown thread %d."), thread
);
7711 /* Truncate the string and get rid of the thread <thread_num>
7712 parameter before the parameter list is parsed by the
7713 evaluate_expression() function. */
7718 /* Parse the rest of the arguments. */
7719 innermost_block
= NULL
;
7721 exp
= parse_exp_1 (&arg
, 0, 0);
7723 /* Remove trailing whitespace from the expression before saving it.
7724 This makes the eventual display of the expression string a bit
7726 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7729 exp_valid_block
= innermost_block
;
7730 mark
= value_mark ();
7731 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7733 release_value (val
);
7736 while (*tok
== ' ' || *tok
== '\t')
7740 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7743 toklen
= end_tok
- tok
;
7744 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7746 struct expression
*cond
;
7748 innermost_block
= NULL
;
7749 tok
= cond_start
= end_tok
+ 1;
7750 cond
= parse_exp_1 (&tok
, 0, 0);
7752 /* The watchpoint expression may not be local, but the condition
7753 may still be. E.g.: `watch global if local > 0'. */
7754 cond_exp_valid_block
= innermost_block
;
7760 error (_("Junk at end of command."));
7762 if (accessflag
== hw_read
)
7763 bp_type
= bp_read_watchpoint
;
7764 else if (accessflag
== hw_access
)
7765 bp_type
= bp_access_watchpoint
;
7767 bp_type
= bp_hardware_watchpoint
;
7769 mem_cnt
= can_use_hardware_watchpoint (val
);
7770 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7771 error (_("Expression cannot be implemented with read/access watchpoint."));
7774 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7775 target_resources_ok
=
7776 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7778 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7779 error (_("Target does not support this type of hardware watchpoint."));
7781 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7782 error (_("Target can only support one kind of HW watchpoint at a time."));
7785 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7786 watchpoint could not be set. */
7787 if (!mem_cnt
|| target_resources_ok
<= 0)
7788 bp_type
= bp_watchpoint
;
7790 frame
= block_innermost_frame (exp_valid_block
);
7792 /* If the expression is "local", then set up a "watchpoint scope"
7793 breakpoint at the point where we've left the scope of the watchpoint
7794 expression. Create the scope breakpoint before the watchpoint, so
7795 that we will encounter it first in bpstat_stop_status. */
7796 if (exp_valid_block
&& frame
)
7798 if (frame_id_p (frame_unwind_caller_id (frame
)))
7801 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7802 frame_unwind_caller_pc (frame
),
7803 bp_watchpoint_scope
);
7805 scope_breakpoint
->enable_state
= bp_enabled
;
7807 /* Automatically delete the breakpoint when it hits. */
7808 scope_breakpoint
->disposition
= disp_del
;
7810 /* Only break in the proper frame (help with recursion). */
7811 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7813 /* Set the address at which we will stop. */
7814 scope_breakpoint
->loc
->gdbarch
7815 = frame_unwind_caller_arch (frame
);
7816 scope_breakpoint
->loc
->requested_address
7817 = frame_unwind_caller_pc (frame
);
7818 scope_breakpoint
->loc
->address
7819 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7820 scope_breakpoint
->loc
->requested_address
,
7821 scope_breakpoint
->type
);
7825 /* Now set up the breakpoint. */
7826 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7827 set_breakpoint_count (breakpoint_count
+ 1);
7828 b
->number
= breakpoint_count
;
7830 b
->disposition
= disp_donttouch
;
7832 b
->exp_valid_block
= exp_valid_block
;
7833 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7834 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7838 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7844 b
->watchpoint_frame
= get_frame_id (frame
);
7845 b
->watchpoint_thread
= inferior_ptid
;
7849 b
->watchpoint_frame
= null_frame_id
;
7850 b
->watchpoint_thread
= null_ptid
;
7853 if (scope_breakpoint
!= NULL
)
7855 /* The scope breakpoint is related to the watchpoint. We will
7856 need to act on them together. */
7857 b
->related_breakpoint
= scope_breakpoint
;
7858 scope_breakpoint
->related_breakpoint
= b
;
7861 value_free_to_mark (mark
);
7863 /* Finally update the new watchpoint. This creates the locations
7864 that should be inserted. */
7865 update_watchpoint (b
, 1);
7868 update_global_location_list (1);
7871 /* Return count of locations need to be watched and can be handled
7872 in hardware. If the watchpoint can not be handled
7873 in hardware return zero. */
7876 can_use_hardware_watchpoint (struct value
*v
)
7878 int found_memory_cnt
= 0;
7879 struct value
*head
= v
;
7881 /* Did the user specifically forbid us to use hardware watchpoints? */
7882 if (!can_use_hw_watchpoints
)
7885 /* Make sure that the value of the expression depends only upon
7886 memory contents, and values computed from them within GDB. If we
7887 find any register references or function calls, we can't use a
7888 hardware watchpoint.
7890 The idea here is that evaluating an expression generates a series
7891 of values, one holding the value of every subexpression. (The
7892 expression a*b+c has five subexpressions: a, b, a*b, c, and
7893 a*b+c.) GDB's values hold almost enough information to establish
7894 the criteria given above --- they identify memory lvalues,
7895 register lvalues, computed values, etcetera. So we can evaluate
7896 the expression, and then scan the chain of values that leaves
7897 behind to decide whether we can detect any possible change to the
7898 expression's final value using only hardware watchpoints.
7900 However, I don't think that the values returned by inferior
7901 function calls are special in any way. So this function may not
7902 notice that an expression involving an inferior function call
7903 can't be watched with hardware watchpoints. FIXME. */
7904 for (; v
; v
= value_next (v
))
7906 if (VALUE_LVAL (v
) == lval_memory
)
7909 /* A lazy memory lvalue is one that GDB never needed to fetch;
7910 we either just used its address (e.g., `a' in `a.b') or
7911 we never needed it at all (e.g., `a' in `a,b'). */
7915 /* Ahh, memory we actually used! Check if we can cover
7916 it with hardware watchpoints. */
7917 struct type
*vtype
= check_typedef (value_type (v
));
7919 /* We only watch structs and arrays if user asked for it
7920 explicitly, never if they just happen to appear in a
7921 middle of some value chain. */
7923 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7924 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7926 CORE_ADDR vaddr
= value_address (v
);
7927 int len
= TYPE_LENGTH (value_type (v
));
7929 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7936 else if (VALUE_LVAL (v
) != not_lval
7937 && deprecated_value_modifiable (v
) == 0)
7938 return 0; /* ??? What does this represent? */
7939 else if (VALUE_LVAL (v
) == lval_register
)
7940 return 0; /* cannot watch a register with a HW watchpoint */
7943 /* The expression itself looks suitable for using a hardware
7944 watchpoint, but give the target machine a chance to reject it. */
7945 return found_memory_cnt
;
7949 watch_command_wrapper (char *arg
, int from_tty
)
7951 watch_command (arg
, from_tty
);
7955 watch_command (char *arg
, int from_tty
)
7957 watch_command_1 (arg
, hw_write
, from_tty
);
7961 rwatch_command_wrapper (char *arg
, int from_tty
)
7963 rwatch_command (arg
, from_tty
);
7967 rwatch_command (char *arg
, int from_tty
)
7969 watch_command_1 (arg
, hw_read
, from_tty
);
7973 awatch_command_wrapper (char *arg
, int from_tty
)
7975 awatch_command (arg
, from_tty
);
7979 awatch_command (char *arg
, int from_tty
)
7981 watch_command_1 (arg
, hw_access
, from_tty
);
7985 /* Helper routines for the until_command routine in infcmd.c. Here
7986 because it uses the mechanisms of breakpoints. */
7988 struct until_break_command_continuation_args
7990 struct breakpoint
*breakpoint
;
7991 struct breakpoint
*breakpoint2
;
7994 /* This function is called by fetch_inferior_event via the
7995 cmd_continuation pointer, to complete the until command. It takes
7996 care of cleaning up the temporary breakpoints set up by the until
7999 until_break_command_continuation (void *arg
)
8001 struct until_break_command_continuation_args
*a
= arg
;
8003 delete_breakpoint (a
->breakpoint
);
8005 delete_breakpoint (a
->breakpoint2
);
8009 until_break_command (char *arg
, int from_tty
, int anywhere
)
8011 struct symtabs_and_lines sals
;
8012 struct symtab_and_line sal
;
8013 struct frame_info
*frame
= get_selected_frame (NULL
);
8014 struct breakpoint
*breakpoint
;
8015 struct breakpoint
*breakpoint2
= NULL
;
8016 struct cleanup
*old_chain
;
8018 clear_proceed_status ();
8020 /* Set a breakpoint where the user wants it and at return from
8023 if (default_breakpoint_valid
)
8024 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8025 default_breakpoint_line
, (char ***) NULL
, NULL
);
8027 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8028 0, (char ***) NULL
, NULL
);
8030 if (sals
.nelts
!= 1)
8031 error (_("Couldn't get information on specified line."));
8034 xfree (sals
.sals
); /* malloc'd, so freed */
8037 error (_("Junk at end of arguments."));
8039 resolve_sal_pc (&sal
);
8042 /* If the user told us to continue until a specified location,
8043 we don't specify a frame at which we need to stop. */
8044 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8045 null_frame_id
, bp_until
);
8047 /* Otherwise, specify the selected frame, because we want to stop only
8048 at the very same frame. */
8049 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8050 get_stack_frame_id (frame
),
8053 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8055 /* Keep within the current frame, or in frames called by the current
8058 if (frame_id_p (frame_unwind_caller_id (frame
)))
8060 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8061 sal
.pc
= frame_unwind_caller_pc (frame
);
8062 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8064 frame_unwind_caller_id (frame
),
8066 make_cleanup_delete_breakpoint (breakpoint2
);
8069 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8071 /* If we are running asynchronously, and proceed call above has actually
8072 managed to start the target, arrange for breakpoints to be
8073 deleted when the target stops. Otherwise, we're already stopped and
8074 delete breakpoints via cleanup chain. */
8076 if (target_can_async_p () && is_running (inferior_ptid
))
8078 struct until_break_command_continuation_args
*args
;
8079 args
= xmalloc (sizeof (*args
));
8081 args
->breakpoint
= breakpoint
;
8082 args
->breakpoint2
= breakpoint2
;
8084 discard_cleanups (old_chain
);
8085 add_continuation (inferior_thread (),
8086 until_break_command_continuation
, args
,
8090 do_cleanups (old_chain
);
8094 ep_skip_leading_whitespace (char **s
)
8096 if ((s
== NULL
) || (*s
== NULL
))
8098 while (isspace (**s
))
8102 /* This function attempts to parse an optional "if <cond>" clause
8103 from the arg string. If one is not found, it returns NULL.
8105 Else, it returns a pointer to the condition string. (It does not
8106 attempt to evaluate the string against a particular block.) And,
8107 it updates arg to point to the first character following the parsed
8108 if clause in the arg string. */
8111 ep_parse_optional_if_clause (char **arg
)
8115 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8118 /* Skip the "if" keyword. */
8121 /* Skip any extra leading whitespace, and record the start of the
8122 condition string. */
8123 ep_skip_leading_whitespace (arg
);
8126 /* Assume that the condition occupies the remainder of the arg string. */
8127 (*arg
) += strlen (cond_string
);
8132 /* Commands to deal with catching events, such as signals, exceptions,
8133 process start/exit, etc. */
8137 catch_fork_temporary
, catch_vfork_temporary
,
8138 catch_fork_permanent
, catch_vfork_permanent
8143 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8145 struct gdbarch
*gdbarch
= get_current_arch ();
8146 char *cond_string
= NULL
;
8147 catch_fork_kind fork_kind
;
8150 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8151 tempflag
= (fork_kind
== catch_fork_temporary
8152 || fork_kind
== catch_vfork_temporary
);
8156 ep_skip_leading_whitespace (&arg
);
8158 /* The allowed syntax is:
8160 catch [v]fork if <cond>
8162 First, check if there's an if clause. */
8163 cond_string
= ep_parse_optional_if_clause (&arg
);
8165 if ((*arg
!= '\0') && !isspace (*arg
))
8166 error (_("Junk at end of arguments."));
8168 /* If this target supports it, create a fork or vfork catchpoint
8169 and enable reporting of such events. */
8172 case catch_fork_temporary
:
8173 case catch_fork_permanent
:
8174 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8175 &catch_fork_breakpoint_ops
);
8177 case catch_vfork_temporary
:
8178 case catch_vfork_permanent
:
8179 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8180 &catch_vfork_breakpoint_ops
);
8183 error (_("unsupported or unknown fork kind; cannot catch it"));
8189 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8191 struct gdbarch
*gdbarch
= get_current_arch ();
8193 char *cond_string
= NULL
;
8195 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8199 ep_skip_leading_whitespace (&arg
);
8201 /* The allowed syntax is:
8203 catch exec if <cond>
8205 First, check if there's an if clause. */
8206 cond_string
= ep_parse_optional_if_clause (&arg
);
8208 if ((*arg
!= '\0') && !isspace (*arg
))
8209 error (_("Junk at end of arguments."));
8211 /* If this target supports it, create an exec catchpoint
8212 and enable reporting of such events. */
8213 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8214 &catch_exec_breakpoint_ops
);
8217 static enum print_stop_action
8218 print_exception_catchpoint (struct breakpoint
*b
)
8220 int bp_temp
, bp_throw
;
8222 annotate_catchpoint (b
->number
);
8224 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8225 if (b
->loc
->address
!= b
->loc
->requested_address
)
8226 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8229 bp_temp
= b
->disposition
== disp_del
;
8231 bp_temp
? "Temporary catchpoint "
8233 if (!ui_out_is_mi_like_p (uiout
))
8234 ui_out_field_int (uiout
, "bkptno", b
->number
);
8236 bp_throw
? " (exception thrown), "
8237 : " (exception caught), ");
8238 if (ui_out_is_mi_like_p (uiout
))
8240 ui_out_field_string (uiout
, "reason",
8241 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8242 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8243 ui_out_field_int (uiout
, "bkptno", b
->number
);
8245 return PRINT_SRC_AND_LOC
;
8249 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8251 struct value_print_options opts
;
8252 get_user_print_options (&opts
);
8253 if (opts
.addressprint
)
8256 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8257 ui_out_field_string (uiout
, "addr", "<PENDING>");
8259 ui_out_field_core_addr (uiout
, "addr",
8260 b
->loc
->gdbarch
, b
->loc
->address
);
8265 if (strstr (b
->addr_string
, "throw") != NULL
)
8266 ui_out_field_string (uiout
, "what", "exception throw");
8268 ui_out_field_string (uiout
, "what", "exception catch");
8272 print_mention_exception_catchpoint (struct breakpoint
*b
)
8277 bp_temp
= b
->disposition
== disp_del
;
8278 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8279 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8280 : _("Catchpoint "));
8281 ui_out_field_int (uiout
, "bkptno", b
->number
);
8282 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8286 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8289 NULL
, /* breakpoint_hit */
8290 print_exception_catchpoint
,
8291 print_one_exception_catchpoint
,
8292 print_mention_exception_catchpoint
8296 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8297 enum exception_event_kind ex_event
, int from_tty
)
8299 char *trigger_func_name
;
8301 if (ex_event
== EX_EVENT_CATCH
)
8302 trigger_func_name
= "__cxa_begin_catch";
8304 trigger_func_name
= "__cxa_throw";
8306 create_breakpoint (get_current_arch (),
8307 trigger_func_name
, cond_string
, -1,
8308 0 /* condition and thread are valid. */,
8311 AUTO_BOOLEAN_TRUE
/* pending */,
8312 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8318 /* Deal with "catch catch" and "catch throw" commands */
8321 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8322 int tempflag
, int from_tty
)
8324 char *cond_string
= NULL
;
8325 struct symtab_and_line
*sal
= NULL
;
8329 ep_skip_leading_whitespace (&arg
);
8331 cond_string
= ep_parse_optional_if_clause (&arg
);
8333 if ((*arg
!= '\0') && !isspace (*arg
))
8334 error (_("Junk at end of arguments."));
8336 if (ex_event
!= EX_EVENT_THROW
8337 && ex_event
!= EX_EVENT_CATCH
)
8338 error (_("Unsupported or unknown exception event; cannot catch it"));
8340 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8343 warning (_("Unsupported with this platform/compiler combination."));
8346 /* Implementation of "catch catch" command. */
8349 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8351 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8352 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8355 /* Implementation of "catch throw" command. */
8358 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8360 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8361 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8364 /* Create a breakpoint struct for Ada exception catchpoints. */
8367 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8368 struct symtab_and_line sal
,
8372 struct expression
*cond
,
8373 struct breakpoint_ops
*ops
,
8377 struct breakpoint
*b
;
8381 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8383 loc_gdbarch
= gdbarch
;
8385 describe_other_breakpoints (loc_gdbarch
,
8386 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8387 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8388 version for exception catchpoints, because two catchpoints
8389 used for different exception names will use the same address.
8390 In this case, a "breakpoint ... also set at..." warning is
8391 unproductive. Besides. the warning phrasing is also a bit
8392 inapropriate, we should use the word catchpoint, and tell
8393 the user what type of catchpoint it is. The above is good
8394 enough for now, though. */
8397 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8398 set_breakpoint_count (breakpoint_count
+ 1);
8400 b
->enable_state
= bp_enabled
;
8401 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8402 b
->number
= breakpoint_count
;
8403 b
->ignore_count
= 0;
8404 b
->loc
->cond
= cond
;
8405 b
->addr_string
= addr_string
;
8406 b
->language
= language_ada
;
8407 b
->cond_string
= cond_string
;
8408 b
->exp_string
= exp_string
;
8413 update_global_location_list (1);
8416 /* Implement the "catch exception" command. */
8419 catch_ada_exception_command (char *arg
, int from_tty
,
8420 struct cmd_list_element
*command
)
8422 struct gdbarch
*gdbarch
= get_current_arch ();
8424 struct symtab_and_line sal
;
8426 char *addr_string
= NULL
;
8427 char *exp_string
= NULL
;
8428 char *cond_string
= NULL
;
8429 struct expression
*cond
= NULL
;
8430 struct breakpoint_ops
*ops
= NULL
;
8432 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8436 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8437 &cond_string
, &cond
, &ops
);
8438 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8439 cond_string
, cond
, ops
, tempflag
,
8443 /* Cleanup function for a syscall filter list. */
8445 clean_up_filters (void *arg
)
8447 VEC(int) *iter
= *(VEC(int) **) arg
;
8448 VEC_free (int, iter
);
8451 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8452 filter list, or NULL if no filtering is required. */
8454 catch_syscall_split_args (char *arg
)
8456 VEC(int) *result
= NULL
;
8457 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8459 while (*arg
!= '\0')
8461 int i
, syscall_number
;
8466 /* Skip whitespace. */
8467 while (isspace (*arg
))
8470 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8471 cur_name
[i
] = arg
[i
];
8475 /* Check if the user provided a syscall name or a number. */
8476 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8477 if (*endptr
== '\0')
8478 get_syscall_by_number (syscall_number
, &s
);
8481 /* We have a name. Let's check if it's valid and convert it
8483 get_syscall_by_name (cur_name
, &s
);
8485 if (s
.number
== UNKNOWN_SYSCALL
)
8486 /* Here we have to issue an error instead of a warning, because
8487 GDB cannot do anything useful if there's no syscall number to
8489 error (_("Unknown syscall name '%s'."), cur_name
);
8492 /* Ok, it's valid. */
8493 VEC_safe_push (int, result
, s
.number
);
8496 discard_cleanups (cleanup
);
8500 /* Implement the "catch syscall" command. */
8503 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8508 struct gdbarch
*gdbarch
= get_current_arch ();
8510 /* Checking if the feature if supported. */
8511 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8512 error (_("The feature 'catch syscall' is not supported on \
8513 this architeture yet."));
8515 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8517 ep_skip_leading_whitespace (&arg
);
8519 /* We need to do this first "dummy" translation in order
8520 to get the syscall XML file loaded or, most important,
8521 to display a warning to the user if there's no XML file
8522 for his/her architecture. */
8523 get_syscall_by_number (0, &s
);
8525 /* The allowed syntax is:
8527 catch syscall <name | number> [<name | number> ... <name | number>]
8529 Let's check if there's a syscall name. */
8532 filter
= catch_syscall_split_args (arg
);
8536 create_syscall_event_catchpoint (tempflag
, filter
,
8537 &catch_syscall_breakpoint_ops
);
8540 /* Implement the "catch assert" command. */
8543 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8545 struct gdbarch
*gdbarch
= get_current_arch ();
8547 struct symtab_and_line sal
;
8548 char *addr_string
= NULL
;
8549 struct breakpoint_ops
*ops
= NULL
;
8551 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8555 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8556 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8557 ops
, tempflag
, from_tty
);
8561 catch_command (char *arg
, int from_tty
)
8563 error (_("Catch requires an event name."));
8568 tcatch_command (char *arg
, int from_tty
)
8570 error (_("Catch requires an event name."));
8573 /* Delete breakpoints by address or line. */
8576 clear_command (char *arg
, int from_tty
)
8578 struct breakpoint
*b
;
8579 VEC(breakpoint_p
) *found
= 0;
8582 struct symtabs_and_lines sals
;
8583 struct symtab_and_line sal
;
8588 sals
= decode_line_spec (arg
, 1);
8593 sals
.sals
= (struct symtab_and_line
*)
8594 xmalloc (sizeof (struct symtab_and_line
));
8595 make_cleanup (xfree
, sals
.sals
);
8596 init_sal (&sal
); /* initialize to zeroes */
8597 sal
.line
= default_breakpoint_line
;
8598 sal
.symtab
= default_breakpoint_symtab
;
8599 sal
.pc
= default_breakpoint_address
;
8600 sal
.pspace
= default_breakpoint_pspace
;
8601 if (sal
.symtab
== 0)
8602 error (_("No source file specified."));
8610 /* We don't call resolve_sal_pc here. That's not
8611 as bad as it seems, because all existing breakpoints
8612 typically have both file/line and pc set. So, if
8613 clear is given file/line, we can match this to existing
8614 breakpoint without obtaining pc at all.
8616 We only support clearing given the address explicitly
8617 present in breakpoint table. Say, we've set breakpoint
8618 at file:line. There were several PC values for that file:line,
8619 due to optimization, all in one block.
8620 We've picked one PC value. If "clear" is issued with another
8621 PC corresponding to the same file:line, the breakpoint won't
8622 be cleared. We probably can still clear the breakpoint, but
8623 since the other PC value is never presented to user, user
8624 can only find it by guessing, and it does not seem important
8627 /* For each line spec given, delete bps which correspond
8628 to it. Do it in two passes, solely to preserve the current
8629 behavior that from_tty is forced true if we delete more than
8633 for (i
= 0; i
< sals
.nelts
; i
++)
8635 /* If exact pc given, clear bpts at that pc.
8636 If line given (pc == 0), clear all bpts on specified line.
8637 If defaulting, clear all bpts on default line
8640 defaulting sal.pc != 0 tests to do
8645 1 0 <can't happen> */
8649 /* Find all matching breakpoints and add them to
8654 /* Are we going to delete b? */
8655 if (b
->type
!= bp_none
8656 && b
->type
!= bp_watchpoint
8657 && b
->type
!= bp_hardware_watchpoint
8658 && b
->type
!= bp_read_watchpoint
8659 && b
->type
!= bp_access_watchpoint
)
8661 struct bp_location
*loc
= b
->loc
;
8662 for (; loc
; loc
= loc
->next
)
8664 int pc_match
= sal
.pc
8665 && (loc
->pspace
== sal
.pspace
)
8666 && (loc
->address
== sal
.pc
)
8667 && (!section_is_overlay (loc
->section
)
8668 || loc
->section
== sal
.section
);
8669 int line_match
= ((default_match
|| (0 == sal
.pc
))
8670 && b
->source_file
!= NULL
8671 && sal
.symtab
!= NULL
8672 && sal
.pspace
== loc
->pspace
8673 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8674 && b
->line_number
== sal
.line
);
8675 if (pc_match
|| line_match
)
8684 VEC_safe_push(breakpoint_p
, found
, b
);
8687 /* Now go thru the 'found' chain and delete them. */
8688 if (VEC_empty(breakpoint_p
, found
))
8691 error (_("No breakpoint at %s."), arg
);
8693 error (_("No breakpoint at this line."));
8696 if (VEC_length(breakpoint_p
, found
) > 1)
8697 from_tty
= 1; /* Always report if deleted more than one */
8700 if (VEC_length(breakpoint_p
, found
) == 1)
8701 printf_unfiltered (_("Deleted breakpoint "));
8703 printf_unfiltered (_("Deleted breakpoints "));
8705 breakpoints_changed ();
8707 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8710 printf_unfiltered ("%d ", b
->number
);
8711 delete_breakpoint (b
);
8714 putchar_unfiltered ('\n');
8717 /* Delete breakpoint in BS if they are `delete' breakpoints and
8718 all breakpoints that are marked for deletion, whether hit or not.
8719 This is called after any breakpoint is hit, or after errors. */
8722 breakpoint_auto_delete (bpstat bs
)
8724 struct breakpoint
*b
, *temp
;
8726 for (; bs
; bs
= bs
->next
)
8727 if (bs
->breakpoint_at
8728 && bs
->breakpoint_at
->owner
8729 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8731 delete_breakpoint (bs
->breakpoint_at
->owner
);
8733 ALL_BREAKPOINTS_SAFE (b
, temp
)
8735 if (b
->disposition
== disp_del_at_next_stop
)
8736 delete_breakpoint (b
);
8740 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8741 Sort elements primarily by their ADDRESS (no matter what does
8742 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8743 first bp_permanent OWNERed elements and terciarily just ensuring the array
8744 is sorted stable way despite qsort being an instable algorithm. */
8747 bp_location_compare (const void *ap
, const void *bp
)
8749 struct bp_location
*a
= *(void **) ap
;
8750 struct bp_location
*b
= *(void **) bp
;
8751 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8752 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8754 if (a
->address
!= b
->address
)
8755 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8757 /* Sort permanent breakpoints first. */
8758 if (a_perm
!= b_perm
)
8759 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8761 /* Make the user-visible order stable across GDB runs. Locations of the same
8762 breakpoint can be sorted in arbitrary order. */
8764 if (a
->owner
->number
!= b
->owner
->number
)
8765 return (a
->owner
->number
> b
->owner
->number
)
8766 - (a
->owner
->number
< b
->owner
->number
);
8768 return (a
> b
) - (a
< b
);
8771 /* Set bp_location_placed_address_before_address_max and
8772 bp_location_shadow_len_after_address_max according to the current content of
8773 the bp_location array. */
8776 bp_location_target_extensions_update (void)
8778 struct bp_location
*bl
, **blp_tmp
;
8780 bp_location_placed_address_before_address_max
= 0;
8781 bp_location_shadow_len_after_address_max
= 0;
8783 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8785 CORE_ADDR start
, end
, addr
;
8787 if (!bp_location_has_shadow (bl
))
8790 start
= bl
->target_info
.placed_address
;
8791 end
= start
+ bl
->target_info
.shadow_len
;
8793 gdb_assert (bl
->address
>= start
);
8794 addr
= bl
->address
- start
;
8795 if (addr
> bp_location_placed_address_before_address_max
)
8796 bp_location_placed_address_before_address_max
= addr
;
8798 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8800 gdb_assert (bl
->address
< end
);
8801 addr
= end
- bl
->address
;
8802 if (addr
> bp_location_shadow_len_after_address_max
)
8803 bp_location_shadow_len_after_address_max
= addr
;
8807 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8808 into the inferior, only remove already-inserted locations that no
8809 longer should be inserted. Functions that delete a breakpoint or
8810 breakpoints should pass false, so that deleting a breakpoint
8811 doesn't have the side effect of inserting the locations of other
8812 breakpoints that are marked not-inserted, but should_be_inserted
8813 returns true on them.
8815 This behaviour is useful is situations close to tear-down -- e.g.,
8816 after an exec, while the target still has execution, but breakpoint
8817 shadows of the previous executable image should *NOT* be restored
8818 to the new image; or before detaching, where the target still has
8819 execution and wants to delete breakpoints from GDB's lists, and all
8820 breakpoints had already been removed from the inferior. */
8823 update_global_location_list (int should_insert
)
8825 struct breakpoint
*b
;
8826 struct bp_location
**locp
, *loc
;
8827 struct cleanup
*cleanups
;
8829 /* Used in the duplicates detection below. When iterating over all
8830 bp_locations, points to the first bp_location of a given address.
8831 Breakpoints and watchpoints of different types are never
8832 duplicates of each other. Keep one pointer for each type of
8833 breakpoint/watchpoint, so we only need to loop over all locations
8835 struct bp_location
*bp_loc_first
; /* breakpoint */
8836 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8837 struct bp_location
*awp_loc_first
; /* access watchpoint */
8838 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8840 /* Saved former bp_location array which we compare against the newly built
8841 bp_location from the current state of ALL_BREAKPOINTS. */
8842 struct bp_location
**old_location
, **old_locp
;
8843 unsigned old_location_count
;
8845 old_location
= bp_location
;
8846 old_location_count
= bp_location_count
;
8848 bp_location_count
= 0;
8849 cleanups
= make_cleanup (xfree
, old_location
);
8852 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8853 bp_location_count
++;
8855 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8858 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8860 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8861 bp_location_compare
);
8863 bp_location_target_extensions_update ();
8865 /* Identify bp_location instances that are no longer present in the new
8866 list, and therefore should be freed. Note that it's not necessary that
8867 those locations should be removed from inferior -- if there's another
8868 location at the same address (previously marked as duplicate),
8869 we don't need to remove/insert the location.
8871 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8872 former bp_location array state respectively. */
8875 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8878 struct bp_location
*old_loc
= *old_locp
;
8879 struct bp_location
**loc2p
;
8881 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8883 int found_object
= 0;
8884 /* Tells if the location should remain inserted in the target. */
8885 int keep_in_target
= 0;
8888 /* Skip LOCP entries which will definitely never be needed. Stop either
8889 at or being the one matching OLD_LOC. */
8890 while (locp
< bp_location
+ bp_location_count
8891 && (*locp
)->address
< old_loc
->address
)
8895 (loc2p
< bp_location
+ bp_location_count
8896 && (*loc2p
)->address
== old_loc
->address
);
8899 if (*loc2p
== old_loc
)
8906 /* If this location is no longer present, and inserted, look if there's
8907 maybe a new location at the same address. If so, mark that one
8908 inserted, and don't remove this one. This is needed so that we
8909 don't have a time window where a breakpoint at certain location is not
8912 if (old_loc
->inserted
)
8914 /* If the location is inserted now, we might have to remove it. */
8916 if (found_object
&& should_be_inserted (old_loc
))
8918 /* The location is still present in the location list, and still
8919 should be inserted. Don't do anything. */
8924 /* The location is either no longer present, or got disabled.
8925 See if there's another location at the same address, in which
8926 case we don't need to remove this one from the target. */
8928 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8931 (loc2p
< bp_location
+ bp_location_count
8932 && (*loc2p
)->address
== old_loc
->address
);
8935 struct bp_location
*loc2
= *loc2p
;
8937 if (breakpoint_locations_match (loc2
, old_loc
))
8939 /* For the sake of should_be_inserted.
8940 Duplicates check below will fix up this later. */
8941 loc2
->duplicate
= 0;
8943 /* Read watchpoint locations are switched to
8944 access watchpoints, if the former are not
8945 supported, but the latter are. */
8946 if (is_hardware_watchpoint (old_loc
->owner
))
8948 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8949 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8952 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8955 loc2
->target_info
= old_loc
->target_info
;
8964 if (!keep_in_target
)
8966 if (remove_breakpoint (old_loc
, mark_uninserted
))
8968 /* This is just about all we can do. We could keep this
8969 location on the global list, and try to remove it next
8970 time, but there's no particular reason why we will
8973 Note that at this point, old_loc->owner is still valid,
8974 as delete_breakpoint frees the breakpoint only
8975 after calling us. */
8976 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8977 old_loc
->owner
->number
);
8985 if (removed
&& non_stop
8986 && breakpoint_address_is_meaningful (old_loc
->owner
)
8987 && !is_hardware_watchpoint (old_loc
->owner
))
8989 /* This location was removed from the target. In
8990 non-stop mode, a race condition is possible where
8991 we've removed a breakpoint, but stop events for that
8992 breakpoint are already queued and will arrive later.
8993 We apply an heuristic to be able to distinguish such
8994 SIGTRAPs from other random SIGTRAPs: we keep this
8995 breakpoint location for a bit, and will retire it
8996 after we see some number of events. The theory here
8997 is that reporting of events should, "on the average",
8998 be fair, so after a while we'll see events from all
8999 threads that have anything of interest, and no longer
9000 need to keep this breakpoint location around. We
9001 don't hold locations forever so to reduce chances of
9002 mistaking a non-breakpoint SIGTRAP for a breakpoint
9005 The heuristic failing can be disastrous on
9006 decr_pc_after_break targets.
9008 On decr_pc_after_break targets, like e.g., x86-linux,
9009 if we fail to recognize a late breakpoint SIGTRAP,
9010 because events_till_retirement has reached 0 too
9011 soon, we'll fail to do the PC adjustment, and report
9012 a random SIGTRAP to the user. When the user resumes
9013 the inferior, it will most likely immediately crash
9014 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9015 corrupted, because of being resumed e.g., in the
9016 middle of a multi-byte instruction, or skipped a
9017 one-byte instruction. This was actually seen happen
9018 on native x86-linux, and should be less rare on
9019 targets that do not support new thread events, like
9020 remote, due to the heuristic depending on
9023 Mistaking a random SIGTRAP for a breakpoint trap
9024 causes similar symptoms (PC adjustment applied when
9025 it shouldn't), but then again, playing with SIGTRAPs
9026 behind the debugger's back is asking for trouble.
9028 Since hardware watchpoint traps are always
9029 distinguishable from other traps, so we don't need to
9030 apply keep hardware watchpoint moribund locations
9031 around. We simply always ignore hardware watchpoint
9032 traps we can no longer explain. */
9034 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9035 old_loc
->owner
= NULL
;
9037 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9040 free_bp_location (old_loc
);
9044 /* Rescan breakpoints at the same address and section, marking the
9045 first one as "first" and any others as "duplicates". This is so
9046 that the bpt instruction is only inserted once. If we have a
9047 permanent breakpoint at the same place as BPT, make that one the
9048 official one, and the rest as duplicates. Permanent breakpoints
9049 are sorted first for the same address.
9051 Do the same for hardware watchpoints, but also considering the
9052 watchpoint's type (regular/access/read) and length. */
9054 bp_loc_first
= NULL
;
9055 wp_loc_first
= NULL
;
9056 awp_loc_first
= NULL
;
9057 rwp_loc_first
= NULL
;
9058 ALL_BP_LOCATIONS (loc
, locp
)
9060 struct breakpoint
*b
= loc
->owner
;
9061 struct bp_location
**loc_first_p
;
9063 if (b
->enable_state
== bp_disabled
9064 || b
->enable_state
== bp_call_disabled
9065 || b
->enable_state
== bp_startup_disabled
9067 || loc
->shlib_disabled
9068 || !breakpoint_address_is_meaningful (b
)
9069 || is_tracepoint (b
))
9072 /* Permanent breakpoint should always be inserted. */
9073 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9074 internal_error (__FILE__
, __LINE__
,
9075 _("allegedly permanent breakpoint is not "
9076 "actually inserted"));
9078 if (b
->type
== bp_hardware_watchpoint
)
9079 loc_first_p
= &wp_loc_first
;
9080 else if (b
->type
== bp_read_watchpoint
)
9081 loc_first_p
= &rwp_loc_first
;
9082 else if (b
->type
== bp_access_watchpoint
)
9083 loc_first_p
= &awp_loc_first
;
9085 loc_first_p
= &bp_loc_first
;
9087 if (*loc_first_p
== NULL
9088 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9089 || !breakpoint_locations_match (loc
, *loc_first_p
))
9098 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9099 && b
->enable_state
!= bp_permanent
)
9100 internal_error (__FILE__
, __LINE__
,
9101 _("another breakpoint was inserted on top of "
9102 "a permanent breakpoint"));
9105 if (breakpoints_always_inserted_mode () && should_insert
9106 && (have_live_inferiors ()
9107 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9108 insert_breakpoint_locations ();
9110 do_cleanups (cleanups
);
9114 breakpoint_retire_moribund (void)
9116 struct bp_location
*loc
;
9119 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9120 if (--(loc
->events_till_retirement
) == 0)
9122 free_bp_location (loc
);
9123 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9129 update_global_location_list_nothrow (int inserting
)
9131 struct gdb_exception e
;
9132 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9133 update_global_location_list (inserting
);
9136 /* Clear BPT from a BPS. */
9138 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9141 for (bs
= bps
; bs
; bs
= bs
->next
)
9142 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9144 bs
->breakpoint_at
= NULL
;
9146 /* bs->commands will be freed later. */
9150 /* Callback for iterate_over_threads. */
9152 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9154 struct breakpoint
*bpt
= data
;
9155 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9159 /* Delete a breakpoint and clean up all traces of it in the data
9163 delete_breakpoint (struct breakpoint
*bpt
)
9165 struct breakpoint
*b
;
9166 struct bp_location
*loc
, *next
;
9168 gdb_assert (bpt
!= NULL
);
9170 /* Has this bp already been deleted? This can happen because multiple
9171 lists can hold pointers to bp's. bpstat lists are especial culprits.
9173 One example of this happening is a watchpoint's scope bp. When the
9174 scope bp triggers, we notice that the watchpoint is out of scope, and
9175 delete it. We also delete its scope bp. But the scope bp is marked
9176 "auto-deleting", and is already on a bpstat. That bpstat is then
9177 checked for auto-deleting bp's, which are deleted.
9179 A real solution to this problem might involve reference counts in bp's,
9180 and/or giving them pointers back to their referencing bpstat's, and
9181 teaching delete_breakpoint to only free a bp's storage when no more
9182 references were extent. A cheaper bandaid was chosen. */
9183 if (bpt
->type
== bp_none
)
9186 /* At least avoid this stale reference until the reference counting of
9187 breakpoints gets resolved. */
9188 if (bpt
->related_breakpoint
!= NULL
)
9190 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9191 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9192 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9193 bpt
->related_breakpoint
= NULL
;
9196 observer_notify_breakpoint_deleted (bpt
->number
);
9198 if (breakpoint_chain
== bpt
)
9199 breakpoint_chain
= bpt
->next
;
9204 b
->next
= bpt
->next
;
9208 decref_counted_command_line (&bpt
->commands
);
9209 xfree (bpt
->cond_string
);
9210 xfree (bpt
->cond_exp
);
9211 xfree (bpt
->addr_string
);
9213 xfree (bpt
->exp_string
);
9214 value_free (bpt
->val
);
9215 xfree (bpt
->source_file
);
9216 xfree (bpt
->exec_pathname
);
9217 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9219 /* Be sure no bpstat's are pointing at it after it's been freed. */
9220 /* FIXME, how can we find all bpstat's?
9221 We just check stop_bpstat for now. Note that we cannot just
9222 remove bpstats pointing at bpt from the stop_bpstat list
9223 entirely, as breakpoint commands are associated with the bpstat;
9224 if we remove it here, then the later call to
9225 bpstat_do_actions (&stop_bpstat);
9226 in event-top.c won't do anything, and temporary breakpoints
9227 with commands won't work. */
9229 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9231 /* Now that breakpoint is removed from breakpoint
9232 list, update the global location list. This
9233 will remove locations that used to belong to
9234 this breakpoint. Do this before freeing
9235 the breakpoint itself, since remove_breakpoint
9236 looks at location's owner. It might be better
9237 design to have location completely self-contained,
9238 but it's not the case now. */
9239 update_global_location_list (0);
9242 /* On the chance that someone will soon try again to delete this same
9243 bp, we mark it as deleted before freeing its storage. */
9244 bpt
->type
= bp_none
;
9250 do_delete_breakpoint_cleanup (void *b
)
9252 delete_breakpoint (b
);
9256 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9258 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9261 /* A callback for map_breakpoint_numbers that calls
9262 delete_breakpoint. */
9265 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9267 delete_breakpoint (b
);
9271 delete_command (char *arg
, int from_tty
)
9273 struct breakpoint
*b
, *temp
;
9279 int breaks_to_delete
= 0;
9281 /* Delete all breakpoints if no argument.
9282 Do not delete internal or call-dummy breakpoints, these
9283 have to be deleted with an explicit breakpoint number argument. */
9286 if (b
->type
!= bp_call_dummy
9287 && b
->type
!= bp_std_terminate
9288 && b
->type
!= bp_shlib_event
9289 && b
->type
!= bp_jit_event
9290 && b
->type
!= bp_thread_event
9291 && b
->type
!= bp_overlay_event
9292 && b
->type
!= bp_longjmp_master
9293 && b
->type
!= bp_std_terminate_master
9296 breaks_to_delete
= 1;
9301 /* Ask user only if there are some breakpoints to delete. */
9303 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9305 ALL_BREAKPOINTS_SAFE (b
, temp
)
9307 if (b
->type
!= bp_call_dummy
9308 && b
->type
!= bp_std_terminate
9309 && b
->type
!= bp_shlib_event
9310 && b
->type
!= bp_thread_event
9311 && b
->type
!= bp_jit_event
9312 && b
->type
!= bp_overlay_event
9313 && b
->type
!= bp_longjmp_master
9314 && b
->type
!= bp_std_terminate_master
9316 delete_breakpoint (b
);
9321 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9325 all_locations_are_pending (struct bp_location
*loc
)
9327 for (; loc
; loc
= loc
->next
)
9328 if (!loc
->shlib_disabled
)
9333 /* Subroutine of update_breakpoint_locations to simplify it.
9334 Return non-zero if multiple fns in list LOC have the same name.
9335 Null names are ignored. */
9338 ambiguous_names_p (struct bp_location
*loc
)
9340 struct bp_location
*l
;
9341 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9342 (int (*) (const void *, const void *)) streq
,
9343 NULL
, xcalloc
, xfree
);
9345 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9348 const char *name
= l
->function_name
;
9350 /* Allow for some names to be NULL, ignore them. */
9354 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9356 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9371 update_breakpoint_locations (struct breakpoint
*b
,
9372 struct symtabs_and_lines sals
)
9376 struct bp_location
*existing_locations
= b
->loc
;
9378 /* If there's no new locations, and all existing locations
9379 are pending, don't do anything. This optimizes
9380 the common case where all locations are in the same
9381 shared library, that was unloaded. We'd like to
9382 retain the location, so that when the library
9383 is loaded again, we don't loose the enabled/disabled
9384 status of the individual locations. */
9385 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9390 for (i
= 0; i
< sals
.nelts
; ++i
)
9392 struct bp_location
*new_loc
=
9393 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9395 /* Reparse conditions, they might contain references to the
9397 if (b
->cond_string
!= NULL
)
9399 struct gdb_exception e
;
9402 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9404 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9409 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9410 b
->number
, e
.message
);
9411 new_loc
->enabled
= 0;
9415 if (b
->source_file
!= NULL
)
9416 xfree (b
->source_file
);
9417 if (sals
.sals
[i
].symtab
== NULL
)
9418 b
->source_file
= NULL
;
9420 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9422 if (b
->line_number
== 0)
9423 b
->line_number
= sals
.sals
[i
].line
;
9426 /* Update locations of permanent breakpoints. */
9427 if (b
->enable_state
== bp_permanent
)
9428 make_breakpoint_permanent (b
);
9430 /* If possible, carry over 'disable' status from existing breakpoints. */
9432 struct bp_location
*e
= existing_locations
;
9433 /* If there are multiple breakpoints with the same function name,
9434 e.g. for inline functions, comparing function names won't work.
9435 Instead compare pc addresses; this is just a heuristic as things
9436 may have moved, but in practice it gives the correct answer
9437 often enough until a better solution is found. */
9438 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9440 for (; e
; e
= e
->next
)
9442 if (!e
->enabled
&& e
->function_name
)
9444 struct bp_location
*l
= b
->loc
;
9445 if (have_ambiguous_names
)
9447 for (; l
; l
= l
->next
)
9448 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9449 l
->pspace
->aspace
, l
->address
))
9457 for (; l
; l
= l
->next
)
9458 if (l
->function_name
9459 && strcmp (e
->function_name
, l
->function_name
) == 0)
9469 update_global_location_list (1);
9473 /* Reset a breakpoint given it's struct breakpoint * BINT.
9474 The value we return ends up being the return value from catch_errors.
9475 Unused in this case. */
9478 breakpoint_re_set_one (void *bint
)
9480 /* get past catch_errs */
9481 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9485 int *not_found_ptr
= ¬_found
;
9486 struct symtabs_and_lines sals
= {0};
9487 struct symtabs_and_lines expanded
= {0};
9489 enum enable_state save_enable
;
9490 struct gdb_exception e
;
9491 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9496 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9500 case bp_hardware_breakpoint
:
9502 case bp_fast_tracepoint
:
9503 /* Do not attempt to re-set breakpoints disabled during startup. */
9504 if (b
->enable_state
== bp_startup_disabled
)
9507 if (b
->addr_string
== NULL
)
9509 /* Anything without a string can't be re-set. */
9510 delete_breakpoint (b
);
9514 set_language (b
->language
);
9515 input_radix
= b
->input_radix
;
9518 save_current_space_and_thread ();
9519 switch_to_program_space_and_thread (b
->pspace
);
9521 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9523 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9528 int not_found_and_ok
= 0;
9529 /* For pending breakpoints, it's expected that parsing
9530 will fail until the right shared library is loaded.
9531 User has already told to create pending breakpoints and
9532 don't need extra messages. If breakpoint is in bp_shlib_disabled
9533 state, then user already saw the message about that breakpoint
9534 being disabled, and don't want to see more errors. */
9536 && (b
->condition_not_parsed
9537 || (b
->loc
&& b
->loc
->shlib_disabled
)
9538 || b
->enable_state
== bp_disabled
))
9539 not_found_and_ok
= 1;
9541 if (!not_found_and_ok
)
9543 /* We surely don't want to warn about the same breakpoint
9544 10 times. One solution, implemented here, is disable
9545 the breakpoint on error. Another solution would be to
9546 have separate 'warning emitted' flag. Since this
9547 happens only when a binary has changed, I don't know
9548 which approach is better. */
9549 b
->enable_state
= bp_disabled
;
9550 throw_exception (e
);
9556 gdb_assert (sals
.nelts
== 1);
9558 resolve_sal_pc (&sals
.sals
[0]);
9559 if (b
->condition_not_parsed
&& s
&& s
[0])
9561 char *cond_string
= 0;
9565 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9566 &cond_string
, &thread
, &task
);
9568 b
->cond_string
= cond_string
;
9571 b
->condition_not_parsed
= 0;
9574 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9577 make_cleanup (xfree
, sals
.sals
);
9578 update_breakpoint_locations (b
, expanded
);
9582 case bp_hardware_watchpoint
:
9583 case bp_read_watchpoint
:
9584 case bp_access_watchpoint
:
9585 /* Watchpoint can be either on expression using entirely global variables,
9586 or it can be on local variables.
9588 Watchpoints of the first kind are never auto-deleted, and even persist
9589 across program restarts. Since they can use variables from shared
9590 libraries, we need to reparse expression as libraries are loaded
9593 Watchpoints on local variables can also change meaning as result
9594 of solib event. For example, if a watchpoint uses both a local and
9595 a global variables in expression, it's a local watchpoint, but
9596 unloading of a shared library will make the expression invalid.
9597 This is not a very common use case, but we still re-evaluate
9598 expression, to avoid surprises to the user.
9600 Note that for local watchpoints, we re-evaluate it only if
9601 watchpoints frame id is still valid. If it's not, it means
9602 the watchpoint is out of scope and will be deleted soon. In fact,
9603 I'm not sure we'll ever be called in this case.
9605 If a local watchpoint's frame id is still valid, then
9606 b->exp_valid_block is likewise valid, and we can safely use it.
9608 Don't do anything about disabled watchpoints, since they will
9609 be reevaluated again when enabled. */
9610 update_watchpoint (b
, 1 /* reparse */);
9612 /* We needn't really do anything to reset these, since the mask
9613 that requests them is unaffected by e.g., new libraries being
9619 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9621 /* Delete overlay event and longjmp master breakpoints; they will be
9622 reset later by breakpoint_re_set. */
9623 case bp_overlay_event
:
9624 case bp_longjmp_master
:
9625 case bp_std_terminate_master
:
9626 delete_breakpoint (b
);
9629 /* This breakpoint is special, it's set up when the inferior
9630 starts and we really don't want to touch it. */
9631 case bp_shlib_event
:
9633 /* Like bp_shlib_event, this breakpoint type is special.
9634 Once it is set up, we do not want to touch it. */
9635 case bp_thread_event
:
9637 /* Keep temporary breakpoints, which can be encountered when we step
9638 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9639 Otherwise these should have been blown away via the cleanup chain
9640 or by breakpoint_init_inferior when we rerun the executable. */
9643 case bp_watchpoint_scope
:
9645 case bp_std_terminate
:
9646 case bp_step_resume
:
9648 case bp_longjmp_resume
:
9653 do_cleanups (cleanups
);
9657 /* Re-set all breakpoints after symbols have been re-loaded. */
9659 breakpoint_re_set (void)
9661 struct breakpoint
*b
, *temp
;
9662 enum language save_language
;
9663 int save_input_radix
;
9664 struct cleanup
*old_chain
;
9666 save_language
= current_language
->la_language
;
9667 save_input_radix
= input_radix
;
9668 old_chain
= save_current_program_space ();
9670 ALL_BREAKPOINTS_SAFE (b
, temp
)
9672 /* Format possible error msg */
9673 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9675 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9676 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9677 do_cleanups (cleanups
);
9679 set_language (save_language
);
9680 input_radix
= save_input_radix
;
9682 jit_breakpoint_re_set ();
9684 do_cleanups (old_chain
);
9686 create_overlay_event_breakpoint ("_ovly_debug_event");
9687 create_longjmp_master_breakpoint ("longjmp");
9688 create_longjmp_master_breakpoint ("_longjmp");
9689 create_longjmp_master_breakpoint ("siglongjmp");
9690 create_longjmp_master_breakpoint ("_siglongjmp");
9691 create_std_terminate_master_breakpoint ("std::terminate()");
9694 /* Reset the thread number of this breakpoint:
9696 - If the breakpoint is for all threads, leave it as-is.
9697 - Else, reset it to the current thread for inferior_ptid. */
9699 breakpoint_re_set_thread (struct breakpoint
*b
)
9701 if (b
->thread
!= -1)
9703 if (in_thread_list (inferior_ptid
))
9704 b
->thread
= pid_to_thread_id (inferior_ptid
);
9706 /* We're being called after following a fork. The new fork is
9707 selected as current, and unless this was a vfork will have a
9708 different program space from the original thread. Reset that
9710 b
->loc
->pspace
= current_program_space
;
9714 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9715 If from_tty is nonzero, it prints a message to that effect,
9716 which ends with a period (no newline). */
9719 set_ignore_count (int bptnum
, int count
, int from_tty
)
9721 struct breakpoint
*b
;
9727 if (b
->number
== bptnum
)
9729 if (is_tracepoint (b
))
9731 if (from_tty
&& count
!= 0)
9732 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9737 b
->ignore_count
= count
;
9741 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9743 else if (count
== 1)
9744 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9747 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9750 breakpoints_changed ();
9751 observer_notify_breakpoint_modified (b
->number
);
9755 error (_("No breakpoint number %d."), bptnum
);
9759 make_breakpoint_silent (struct breakpoint
*b
)
9761 /* Silence the breakpoint. */
9765 /* Command to set ignore-count of breakpoint N to COUNT. */
9768 ignore_command (char *args
, int from_tty
)
9774 error_no_arg (_("a breakpoint number"));
9776 num
= get_number (&p
);
9778 error (_("bad breakpoint number: '%s'"), args
);
9780 error (_("Second argument (specified ignore-count) is missing."));
9782 set_ignore_count (num
,
9783 longest_to_int (value_as_long (parse_and_eval (p
))),
9786 printf_filtered ("\n");
9789 /* Call FUNCTION on each of the breakpoints
9790 whose numbers are given in ARGS. */
9793 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9800 struct breakpoint
*b
, *tmp
;
9804 error_no_arg (_("one or more breakpoint numbers"));
9811 num
= get_number_or_range (&p1
);
9814 warning (_("bad breakpoint number at or near '%s'"), p
);
9818 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9819 if (b
->number
== num
)
9821 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9824 if (related_breakpoint
)
9825 function (related_breakpoint
, data
);
9829 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9835 static struct bp_location
*
9836 find_location_by_number (char *number
)
9838 char *dot
= strchr (number
, '.');
9842 struct breakpoint
*b
;
9843 struct bp_location
*loc
;
9848 bp_num
= get_number_or_range (&p1
);
9850 error (_("Bad breakpoint number '%s'"), number
);
9853 if (b
->number
== bp_num
)
9858 if (!b
|| b
->number
!= bp_num
)
9859 error (_("Bad breakpoint number '%s'"), number
);
9862 loc_num
= get_number_or_range (&p1
);
9864 error (_("Bad breakpoint location number '%s'"), number
);
9868 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9871 error (_("Bad breakpoint location number '%s'"), dot
+1);
9877 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9878 If from_tty is nonzero, it prints a message to that effect,
9879 which ends with a period (no newline). */
9882 disable_breakpoint (struct breakpoint
*bpt
)
9884 /* Never disable a watchpoint scope breakpoint; we want to
9885 hit them when we leave scope so we can delete both the
9886 watchpoint and its scope breakpoint at that time. */
9887 if (bpt
->type
== bp_watchpoint_scope
)
9890 /* You can't disable permanent breakpoints. */
9891 if (bpt
->enable_state
== bp_permanent
)
9894 bpt
->enable_state
= bp_disabled
;
9896 update_global_location_list (0);
9898 observer_notify_breakpoint_modified (bpt
->number
);
9901 /* A callback for map_breakpoint_numbers that calls
9902 disable_breakpoint. */
9905 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9907 disable_breakpoint (b
);
9911 disable_command (char *args
, int from_tty
)
9913 struct breakpoint
*bpt
;
9915 ALL_BREAKPOINTS (bpt
)
9919 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9924 case bp_fast_tracepoint
:
9926 case bp_hardware_breakpoint
:
9928 case bp_hardware_watchpoint
:
9929 case bp_read_watchpoint
:
9930 case bp_access_watchpoint
:
9931 disable_breakpoint (bpt
);
9935 else if (strchr (args
, '.'))
9937 struct bp_location
*loc
= find_location_by_number (args
);
9940 update_global_location_list (0);
9943 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9947 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9949 int target_resources_ok
, other_type_used
;
9952 if (bpt
->type
== bp_hardware_breakpoint
)
9955 i
= hw_breakpoint_used_count ();
9956 target_resources_ok
=
9957 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9959 if (target_resources_ok
== 0)
9960 error (_("No hardware breakpoint support in the target."));
9961 else if (target_resources_ok
< 0)
9962 error (_("Hardware breakpoints used exceeds limit."));
9965 if (bpt
->type
== bp_watchpoint
9966 || bpt
->type
== bp_hardware_watchpoint
9967 || bpt
->type
== bp_read_watchpoint
9968 || bpt
->type
== bp_access_watchpoint
)
9970 struct gdb_exception e
;
9972 TRY_CATCH (e
, RETURN_MASK_ALL
)
9974 update_watchpoint (bpt
, 1 /* reparse */);
9978 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9984 if (bpt
->enable_state
!= bp_permanent
)
9985 bpt
->enable_state
= bp_enabled
;
9986 bpt
->disposition
= disposition
;
9987 update_global_location_list (1);
9988 breakpoints_changed ();
9990 observer_notify_breakpoint_modified (bpt
->number
);
9995 enable_breakpoint (struct breakpoint
*bpt
)
9997 do_enable_breakpoint (bpt
, bpt
->disposition
);
10000 /* A callback for map_breakpoint_numbers that calls
10001 enable_breakpoint. */
10004 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10006 enable_breakpoint (b
);
10009 /* The enable command enables the specified breakpoints (or all defined
10010 breakpoints) so they once again become (or continue to be) effective
10011 in stopping the inferior. */
10014 enable_command (char *args
, int from_tty
)
10016 struct breakpoint
*bpt
;
10018 ALL_BREAKPOINTS (bpt
)
10022 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10025 case bp_breakpoint
:
10026 case bp_tracepoint
:
10027 case bp_fast_tracepoint
:
10028 case bp_catchpoint
:
10029 case bp_hardware_breakpoint
:
10030 case bp_watchpoint
:
10031 case bp_hardware_watchpoint
:
10032 case bp_read_watchpoint
:
10033 case bp_access_watchpoint
:
10034 enable_breakpoint (bpt
);
10038 else if (strchr (args
, '.'))
10040 struct bp_location
*loc
= find_location_by_number (args
);
10043 update_global_location_list (1);
10046 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10050 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10052 do_enable_breakpoint (bpt
, disp_disable
);
10056 enable_once_command (char *args
, int from_tty
)
10058 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10062 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10064 do_enable_breakpoint (bpt
, disp_del
);
10068 enable_delete_command (char *args
, int from_tty
)
10070 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10074 set_breakpoint_cmd (char *args
, int from_tty
)
10079 show_breakpoint_cmd (char *args
, int from_tty
)
10083 /* Invalidate last known value of any hardware watchpoint if
10084 the memory which that value represents has been written to by
10088 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10089 const bfd_byte
*data
)
10091 struct breakpoint
*bp
;
10093 ALL_BREAKPOINTS (bp
)
10094 if (bp
->enable_state
== bp_enabled
10095 && bp
->type
== bp_hardware_watchpoint
10096 && bp
->val_valid
&& bp
->val
)
10098 struct bp_location
*loc
;
10100 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10101 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10102 && loc
->address
+ loc
->length
> addr
10103 && addr
+ len
> loc
->address
)
10105 value_free (bp
->val
);
10112 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10114 struct symtabs_and_lines
10115 decode_line_spec_1 (char *string
, int funfirstline
)
10117 struct symtabs_and_lines sals
;
10119 error (_("Empty line specification."));
10120 if (default_breakpoint_valid
)
10121 sals
= decode_line_1 (&string
, funfirstline
,
10122 default_breakpoint_symtab
,
10123 default_breakpoint_line
,
10124 (char ***) NULL
, NULL
);
10126 sals
= decode_line_1 (&string
, funfirstline
,
10127 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10129 error (_("Junk at end of line specification: %s"), string
);
10133 /* Create and insert a raw software breakpoint at PC. Return an
10134 identifier, which should be used to remove the breakpoint later.
10135 In general, places which call this should be using something on the
10136 breakpoint chain instead; this function should be eliminated
10140 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10141 struct address_space
*aspace
, CORE_ADDR pc
)
10143 struct bp_target_info
*bp_tgt
;
10145 bp_tgt
= XZALLOC (struct bp_target_info
);
10147 bp_tgt
->placed_address_space
= aspace
;
10148 bp_tgt
->placed_address
= pc
;
10150 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10152 /* Could not insert the breakpoint. */
10160 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10163 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10165 struct bp_target_info
*bp_tgt
= bp
;
10168 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10174 /* One (or perhaps two) breakpoints used for software single stepping. */
10176 static void *single_step_breakpoints
[2];
10177 static struct gdbarch
*single_step_gdbarch
[2];
10179 /* Create and insert a breakpoint for software single step. */
10182 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10183 struct address_space
*aspace
, CORE_ADDR next_pc
)
10187 if (single_step_breakpoints
[0] == NULL
)
10189 bpt_p
= &single_step_breakpoints
[0];
10190 single_step_gdbarch
[0] = gdbarch
;
10194 gdb_assert (single_step_breakpoints
[1] == NULL
);
10195 bpt_p
= &single_step_breakpoints
[1];
10196 single_step_gdbarch
[1] = gdbarch
;
10199 /* NOTE drow/2006-04-11: A future improvement to this function would be
10200 to only create the breakpoints once, and actually put them on the
10201 breakpoint chain. That would let us use set_raw_breakpoint. We could
10202 adjust the addresses each time they were needed. Doing this requires
10203 corresponding changes elsewhere where single step breakpoints are
10204 handled, however. So, for now, we use this. */
10206 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10207 if (*bpt_p
== NULL
)
10208 error (_("Could not insert single-step breakpoint at %s"),
10209 paddress (gdbarch
, next_pc
));
10212 /* Remove and delete any breakpoints used for software single step. */
10215 remove_single_step_breakpoints (void)
10217 gdb_assert (single_step_breakpoints
[0] != NULL
);
10219 /* See insert_single_step_breakpoint for more about this deprecated
10221 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10222 single_step_breakpoints
[0]);
10223 single_step_gdbarch
[0] = NULL
;
10224 single_step_breakpoints
[0] = NULL
;
10226 if (single_step_breakpoints
[1] != NULL
)
10228 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10229 single_step_breakpoints
[1]);
10230 single_step_gdbarch
[1] = NULL
;
10231 single_step_breakpoints
[1] = NULL
;
10235 /* Check whether a software single-step breakpoint is inserted at PC. */
10238 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10242 for (i
= 0; i
< 2; i
++)
10244 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10246 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10247 bp_tgt
->placed_address
,
10255 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10256 non-zero otherwise. */
10258 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10260 if (syscall_catchpoint_p (bp
)
10261 && bp
->enable_state
!= bp_disabled
10262 && bp
->enable_state
!= bp_call_disabled
)
10269 catch_syscall_enabled (void)
10271 struct inferior
*inf
= current_inferior ();
10273 return inf
->total_syscalls_count
!= 0;
10277 catching_syscall_number (int syscall_number
)
10279 struct breakpoint
*bp
;
10281 ALL_BREAKPOINTS (bp
)
10282 if (is_syscall_catchpoint_enabled (bp
))
10284 if (bp
->syscalls_to_be_caught
)
10288 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10290 if (syscall_number
== iter
)
10300 /* Complete syscall names. Used by "catch syscall". */
10302 catch_syscall_completer (struct cmd_list_element
*cmd
,
10303 char *text
, char *word
)
10305 const char **list
= get_syscall_names ();
10306 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10309 /* Tracepoint-specific operations. */
10311 /* Set tracepoint count to NUM. */
10313 set_tracepoint_count (int num
)
10315 tracepoint_count
= num
;
10316 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10320 trace_command (char *arg
, int from_tty
)
10322 if (create_breakpoint (get_current_arch (),
10324 NULL
, 0, 1 /* parse arg */,
10325 0 /* tempflag */, 0 /* hardwareflag */,
10327 0 /* Ignore count */,
10328 pending_break_support
,
10332 set_tracepoint_count (breakpoint_count
);
10336 ftrace_command (char *arg
, int from_tty
)
10338 if (create_breakpoint (get_current_arch (),
10340 NULL
, 0, 1 /* parse arg */,
10341 0 /* tempflag */, 1 /* hardwareflag */,
10343 0 /* Ignore count */,
10344 pending_break_support
,
10348 set_tracepoint_count (breakpoint_count
);
10351 /* Set up a fake reader function that gets command lines from a linked
10352 list that was acquired during tracepoint uploading. */
10354 static struct uploaded_tp
*this_utp
;
10355 static struct uploaded_string
*next_cmd
;
10358 read_uploaded_action (void)
10365 rslt
= next_cmd
->str
;
10366 next_cmd
= next_cmd
->next
;
10371 /* Given information about a tracepoint as recorded on a target (which
10372 can be either a live system or a trace file), attempt to create an
10373 equivalent GDB tracepoint. This is not a reliable process, since
10374 the target does not necessarily have all the information used when
10375 the tracepoint was originally defined. */
10377 struct breakpoint
*
10378 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10380 char *addr_str
, small_buf
[100];
10381 struct breakpoint
*tp
;
10383 if (utp
->at_string
)
10384 addr_str
= utp
->at_string
;
10387 /* In the absence of a source location, fall back to raw
10388 address. Since there is no way to confirm that the address
10389 means the same thing as when the trace was started, warn the
10391 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10393 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10394 addr_str
= small_buf
;
10397 /* There's not much we can do with a sequence of bytecodes. */
10398 if (utp
->cond
&& !utp
->cond_string
)
10399 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10402 if (!create_breakpoint (get_current_arch (),
10404 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10406 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10408 0 /* Ignore count */,
10409 pending_break_support
,
10412 utp
->enabled
/* enabled */))
10415 set_tracepoint_count (breakpoint_count
);
10417 /* Get the tracepoint we just created. */
10418 tp
= get_tracepoint (tracepoint_count
);
10419 gdb_assert (tp
!= NULL
);
10423 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10425 trace_pass_command (small_buf
, 0);
10428 /* If we have uploaded versions of the original commands, set up a
10429 special-purpose "reader" function and call the usual command line
10430 reader, then pass the result to the breakpoint command-setting
10432 if (utp
->cmd_strings
)
10434 struct command_line
*cmd_list
;
10437 next_cmd
= utp
->cmd_strings
;
10439 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10441 breakpoint_set_commands (tp
, cmd_list
);
10443 else if (utp
->numactions
> 0 || utp
->num_step_actions
> 0)
10444 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10450 /* Print information on tracepoint number TPNUM_EXP, or all if
10454 tracepoints_info (char *tpnum_exp
, int from_tty
)
10456 int tpnum
= -1, num_printed
;
10459 tpnum
= parse_and_eval_long (tpnum_exp
);
10461 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
10463 if (num_printed
== 0)
10466 ui_out_message (uiout
, 0, "No tracepoints.\n");
10468 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
10472 /* The 'enable trace' command enables tracepoints.
10473 Not supported by all targets. */
10475 enable_trace_command (char *args
, int from_tty
)
10477 enable_command (args
, from_tty
);
10480 /* The 'disable trace' command disables tracepoints.
10481 Not supported by all targets. */
10483 disable_trace_command (char *args
, int from_tty
)
10485 disable_command (args
, from_tty
);
10488 /* Remove a tracepoint (or all if no argument) */
10490 delete_trace_command (char *arg
, int from_tty
)
10492 struct breakpoint
*b
, *temp
;
10498 int breaks_to_delete
= 0;
10500 /* Delete all breakpoints if no argument.
10501 Do not delete internal or call-dummy breakpoints, these
10502 have to be deleted with an explicit breakpoint number argument. */
10503 ALL_TRACEPOINTS (b
)
10505 if (b
->number
>= 0)
10507 breaks_to_delete
= 1;
10512 /* Ask user only if there are some breakpoints to delete. */
10514 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10516 ALL_BREAKPOINTS_SAFE (b
, temp
)
10518 if (is_tracepoint (b
)
10520 delete_breakpoint (b
);
10525 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10528 /* Set passcount for tracepoint.
10530 First command argument is passcount, second is tracepoint number.
10531 If tracepoint number omitted, apply to most recently defined.
10532 Also accepts special argument "all". */
10535 trace_pass_command (char *args
, int from_tty
)
10537 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10538 unsigned int count
;
10541 if (args
== 0 || *args
== 0)
10542 error (_("passcount command requires an argument (count + optional TP num)"));
10544 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10546 while (*args
&& isspace ((int) *args
))
10549 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10551 args
+= 3; /* Skip special argument "all". */
10554 error (_("Junk at end of arguments."));
10557 t1
= get_tracepoint_by_number (&args
, 1, 1);
10563 ALL_TRACEPOINTS (t2
)
10564 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10566 t2
->pass_count
= count
;
10567 observer_notify_tracepoint_modified (t2
->number
);
10569 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10570 t2
->number
, count
);
10572 if (! all
&& *args
)
10573 t1
= get_tracepoint_by_number (&args
, 1, 0);
10579 struct breakpoint
*
10580 get_tracepoint (int num
)
10582 struct breakpoint
*t
;
10584 ALL_TRACEPOINTS (t
)
10585 if (t
->number
== num
)
10591 /* Find the tracepoint with the given target-side number (which may be
10592 different from the tracepoint number after disconnecting and
10595 struct breakpoint
*
10596 get_tracepoint_by_number_on_target (int num
)
10598 struct breakpoint
*t
;
10600 ALL_TRACEPOINTS (t
)
10601 if (t
->number_on_target
== num
)
10607 /* Utility: parse a tracepoint number and look it up in the list.
10608 If MULTI_P is true, there might be a range of tracepoints in ARG.
10609 if OPTIONAL_P is true, then if the argument is missing, the most
10610 recent tracepoint (tracepoint_count) is returned. */
10611 struct breakpoint
*
10612 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10614 extern int tracepoint_count
;
10615 struct breakpoint
*t
;
10617 char *instring
= arg
== NULL
? NULL
: *arg
;
10619 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10622 tpnum
= tracepoint_count
;
10624 error_no_arg (_("tracepoint number"));
10627 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10631 if (instring
&& *instring
)
10632 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10635 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10639 ALL_TRACEPOINTS (t
)
10640 if (t
->number
== tpnum
)
10645 /* FIXME: if we are in the middle of a range we don't want to give
10646 a message. The current interface to get_number_or_range doesn't
10647 allow us to discover this. */
10648 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10652 /* save-tracepoints command */
10654 tracepoint_save_command (char *args
, int from_tty
)
10656 struct breakpoint
*tp
;
10658 struct command_line
*line
;
10661 struct cleanup
*cleanup
;
10662 struct ui_file
*fp
;
10664 if (args
== 0 || *args
== 0)
10665 error (_("Argument required (file name in which to save tracepoints)"));
10667 /* See if we have anything to save. */
10668 ALL_TRACEPOINTS (tp
)
10675 warning (_("save-tracepoints: no tracepoints to save."));
10679 pathname
= tilde_expand (args
);
10680 cleanup
= make_cleanup (xfree
, pathname
);
10681 fp
= gdb_fopen (pathname
, "w");
10683 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10684 args
, safe_strerror (errno
));
10685 make_cleanup_ui_file_delete (fp
);
10687 save_trace_state_variables (fp
);
10689 ALL_TRACEPOINTS (tp
)
10691 if (tp
->type
== bp_fast_tracepoint
)
10692 fprintf_unfiltered (fp
, "ftrace");
10694 fprintf_unfiltered (fp
, "trace");
10696 if (tp
->addr_string
)
10697 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10700 sprintf_vma (tmp
, tp
->loc
->address
);
10701 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10704 if (tp
->cond_string
)
10705 fprintf_unfiltered (fp
, " if %s", tp
->cond_string
);
10707 fprintf_unfiltered (fp
, "\n");
10709 if (tp
->pass_count
)
10710 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10714 volatile struct gdb_exception ex
;
10716 fprintf_unfiltered (fp
, " actions\n");
10718 ui_out_redirect (uiout
, fp
);
10719 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10721 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10723 ui_out_redirect (uiout
, NULL
);
10726 throw_exception (ex
);
10728 fprintf_unfiltered (fp
, " end\n");
10732 if (*default_collect
)
10733 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10735 do_cleanups (cleanup
);
10737 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10741 /* Create a vector of all tracepoints. */
10743 VEC(breakpoint_p
) *
10746 VEC(breakpoint_p
) *tp_vec
= 0;
10747 struct breakpoint
*tp
;
10749 ALL_TRACEPOINTS (tp
)
10751 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10758 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10759 It is defined as a macro to prevent duplication.
10760 COMMAND should be a string constant containing the name of the command. */
10761 #define BREAK_ARGS_HELP(command) \
10762 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10763 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10764 If a line number is specified, break at start of code for that line.\n\
10765 If a function is specified, break at start of code for that function.\n\
10766 If an address is specified, break at that exact address.\n\
10767 With no LOCATION, uses current execution address of selected stack frame.\n\
10768 This is useful for breaking on return to a stack frame.\n\
10770 THREADNUM is the number from \"info threads\".\n\
10771 CONDITION is a boolean expression.\n\
10773 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10775 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10777 /* List of subcommands for "catch". */
10778 static struct cmd_list_element
*catch_cmdlist
;
10780 /* List of subcommands for "tcatch". */
10781 static struct cmd_list_element
*tcatch_cmdlist
;
10783 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10784 lists, and pass some additional user data to the command function. */
10786 add_catch_command (char *name
, char *docstring
,
10787 void (*sfunc
) (char *args
, int from_tty
,
10788 struct cmd_list_element
*command
),
10789 char **(*completer
) (struct cmd_list_element
*cmd
,
10790 char *text
, char *word
),
10791 void *user_data_catch
,
10792 void *user_data_tcatch
)
10794 struct cmd_list_element
*command
;
10796 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10798 set_cmd_sfunc (command
, sfunc
);
10799 set_cmd_context (command
, user_data_catch
);
10800 set_cmd_completer (command
, completer
);
10802 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10804 set_cmd_sfunc (command
, sfunc
);
10805 set_cmd_context (command
, user_data_tcatch
);
10806 set_cmd_completer (command
, completer
);
10810 clear_syscall_counts (struct inferior
*inf
)
10812 inf
->total_syscalls_count
= 0;
10813 inf
->any_syscall_count
= 0;
10814 VEC_free (int, inf
->syscalls_counts
);
10818 _initialize_breakpoint (void)
10820 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10821 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10822 struct cmd_list_element
*c
;
10824 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10825 observer_attach_inferior_exit (clear_syscall_counts
);
10826 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10828 breakpoint_chain
= 0;
10829 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10830 before a breakpoint is set. */
10831 breakpoint_count
= 0;
10833 tracepoint_count
= 0;
10835 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10836 Set ignore-count of breakpoint number N to COUNT.\n\
10837 Usage is `ignore N COUNT'."));
10839 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10841 add_com ("commands", class_breakpoint
, commands_command
, _("\
10842 Set commands to be executed when a breakpoint is hit.\n\
10843 Give breakpoint number as argument after \"commands\".\n\
10844 With no argument, the targeted breakpoint is the last one set.\n\
10845 The commands themselves follow starting on the next line.\n\
10846 Type a line containing \"end\" to indicate the end of them.\n\
10847 Give \"silent\" as the first line to make the breakpoint silent;\n\
10848 then no output is printed when it is hit, except what the commands print."));
10850 add_com ("condition", class_breakpoint
, condition_command
, _("\
10851 Specify breakpoint number N to break only if COND is true.\n\
10852 Usage is `condition N COND', where N is an integer and COND is an\n\
10853 expression to be evaluated whenever breakpoint N is reached."));
10855 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10856 Set a temporary breakpoint.\n\
10857 Like \"break\" except the breakpoint is only temporary,\n\
10858 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10859 by using \"enable delete\" on the breakpoint number.\n\
10861 BREAK_ARGS_HELP ("tbreak")));
10862 set_cmd_completer (c
, location_completer
);
10864 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10865 Set a hardware assisted breakpoint.\n\
10866 Like \"break\" except the breakpoint requires hardware support,\n\
10867 some target hardware may not have this support.\n\
10869 BREAK_ARGS_HELP ("hbreak")));
10870 set_cmd_completer (c
, location_completer
);
10872 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10873 Set a temporary hardware assisted breakpoint.\n\
10874 Like \"hbreak\" except the breakpoint is only temporary,\n\
10875 so it will be deleted when hit.\n\
10877 BREAK_ARGS_HELP ("thbreak")));
10878 set_cmd_completer (c
, location_completer
);
10880 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10881 Enable some breakpoints.\n\
10882 Give breakpoint numbers (separated by spaces) as arguments.\n\
10883 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10884 This is used to cancel the effect of the \"disable\" command.\n\
10885 With a subcommand you can enable temporarily."),
10886 &enablelist
, "enable ", 1, &cmdlist
);
10888 add_com ("ab", class_breakpoint
, enable_command
, _("\
10889 Enable some breakpoints.\n\
10890 Give breakpoint numbers (separated by spaces) as arguments.\n\
10891 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10892 This is used to cancel the effect of the \"disable\" command.\n\
10893 With a subcommand you can enable temporarily."));
10895 add_com_alias ("en", "enable", class_breakpoint
, 1);
10897 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10898 Enable some breakpoints.\n\
10899 Give breakpoint numbers (separated by spaces) as arguments.\n\
10900 This is used to cancel the effect of the \"disable\" command.\n\
10901 May be abbreviated to simply \"enable\".\n"),
10902 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10904 add_cmd ("once", no_class
, enable_once_command
, _("\
10905 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10906 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10909 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10910 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10911 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10914 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10915 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10916 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10919 add_cmd ("once", no_class
, enable_once_command
, _("\
10920 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10921 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10924 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10925 Disable some breakpoints.\n\
10926 Arguments are breakpoint numbers with spaces in between.\n\
10927 To disable all breakpoints, give no argument.\n\
10928 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10929 &disablelist
, "disable ", 1, &cmdlist
);
10930 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10931 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10933 add_com ("sb", class_breakpoint
, disable_command
, _("\
10934 Disable some breakpoints.\n\
10935 Arguments are breakpoint numbers with spaces in between.\n\
10936 To disable all breakpoints, give no argument.\n\
10937 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10939 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10940 Disable some breakpoints.\n\
10941 Arguments are breakpoint numbers with spaces in between.\n\
10942 To disable all breakpoints, give no argument.\n\
10943 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10944 This command may be abbreviated \"disable\"."),
10947 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10948 Delete some breakpoints or auto-display expressions.\n\
10949 Arguments are breakpoint numbers with spaces in between.\n\
10950 To delete all breakpoints, give no argument.\n\
10952 Also a prefix command for deletion of other GDB objects.\n\
10953 The \"unset\" command is also an alias for \"delete\"."),
10954 &deletelist
, "delete ", 1, &cmdlist
);
10955 add_com_alias ("d", "delete", class_breakpoint
, 1);
10956 add_com_alias ("del", "delete", class_breakpoint
, 1);
10958 add_com ("db", class_breakpoint
, delete_command
, _("\
10959 Delete some breakpoints.\n\
10960 Arguments are breakpoint numbers with spaces in between.\n\
10961 To delete all breakpoints, give no argument.\n"));
10963 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10964 Delete some breakpoints or auto-display expressions.\n\
10965 Arguments are breakpoint numbers with spaces in between.\n\
10966 To delete all breakpoints, give no argument.\n\
10967 This command may be abbreviated \"delete\"."),
10970 add_com ("clear", class_breakpoint
, clear_command
, _("\
10971 Clear breakpoint at specified line or function.\n\
10972 Argument may be line number, function name, or \"*\" and an address.\n\
10973 If line number is specified, all breakpoints in that line are cleared.\n\
10974 If function is specified, breakpoints at beginning of function are cleared.\n\
10975 If an address is specified, breakpoints at that address are cleared.\n\
10977 With no argument, clears all breakpoints in the line that the selected frame\n\
10978 is executing in.\n\
10980 See also the \"delete\" command which clears breakpoints by number."));
10982 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10983 Set breakpoint at specified line or function.\n"
10984 BREAK_ARGS_HELP ("break")));
10985 set_cmd_completer (c
, location_completer
);
10987 add_com_alias ("b", "break", class_run
, 1);
10988 add_com_alias ("br", "break", class_run
, 1);
10989 add_com_alias ("bre", "break", class_run
, 1);
10990 add_com_alias ("brea", "break", class_run
, 1);
10993 add_com_alias ("ba", "break", class_breakpoint
, 1);
10997 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10998 Break in function/address or break at a line in the current file."),
10999 &stoplist
, "stop ", 1, &cmdlist
);
11000 add_cmd ("in", class_breakpoint
, stopin_command
,
11001 _("Break in function or address."), &stoplist
);
11002 add_cmd ("at", class_breakpoint
, stopat_command
,
11003 _("Break at a line in the current file."), &stoplist
);
11004 add_com ("status", class_info
, breakpoints_info
, _("\
11005 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11006 The \"Type\" column indicates one of:\n\
11007 \tbreakpoint - normal breakpoint\n\
11008 \twatchpoint - watchpoint\n\
11009 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11010 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11011 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11012 address and file/line number respectively.\n\
11014 Convenience variable \"$_\" and default examine address for \"x\"\n\
11015 are set to the address of the last breakpoint listed unless the command\n\
11016 is prefixed with \"server \".\n\n\
11017 Convenience variable \"$bpnum\" contains the number of the last\n\
11018 breakpoint set."));
11021 add_info ("breakpoints", breakpoints_info
, _("\
11022 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11023 The \"Type\" column indicates one of:\n\
11024 \tbreakpoint - normal breakpoint\n\
11025 \twatchpoint - watchpoint\n\
11026 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11027 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11028 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11029 address and file/line number respectively.\n\
11031 Convenience variable \"$_\" and default examine address for \"x\"\n\
11032 are set to the address of the last breakpoint listed unless the command\n\
11033 is prefixed with \"server \".\n\n\
11034 Convenience variable \"$bpnum\" contains the number of the last\n\
11035 breakpoint set."));
11037 add_info_alias ("b", "breakpoints", 1);
11040 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11041 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11042 The \"Type\" column indicates one of:\n\
11043 \tbreakpoint - normal breakpoint\n\
11044 \twatchpoint - watchpoint\n\
11045 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11046 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11047 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11048 address and file/line number respectively.\n\
11050 Convenience variable \"$_\" and default examine address for \"x\"\n\
11051 are set to the address of the last breakpoint listed unless the command\n\
11052 is prefixed with \"server \".\n\n\
11053 Convenience variable \"$bpnum\" contains the number of the last\n\
11054 breakpoint set."));
11056 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11057 Status of all breakpoints, or breakpoint number NUMBER.\n\
11058 The \"Type\" column indicates one of:\n\
11059 \tbreakpoint - normal breakpoint\n\
11060 \twatchpoint - watchpoint\n\
11061 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11062 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11063 \tuntil - internal breakpoint used by the \"until\" command\n\
11064 \tfinish - internal breakpoint used by the \"finish\" command\n\
11065 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11066 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11067 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11068 address and file/line number respectively.\n\
11070 Convenience variable \"$_\" and default examine address for \"x\"\n\
11071 are set to the address of the last breakpoint listed unless the command\n\
11072 is prefixed with \"server \".\n\n\
11073 Convenience variable \"$bpnum\" contains the number of the last\n\
11075 &maintenanceinfolist
);
11077 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11078 Set catchpoints to catch events."),
11079 &catch_cmdlist
, "catch ",
11080 0/*allow-unknown*/, &cmdlist
);
11082 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11083 Set temporary catchpoints to catch events."),
11084 &tcatch_cmdlist
, "tcatch ",
11085 0/*allow-unknown*/, &cmdlist
);
11087 /* Add catch and tcatch sub-commands. */
11088 add_catch_command ("catch", _("\
11089 Catch an exception, when caught.\n\
11090 With an argument, catch only exceptions with the given name."),
11091 catch_catch_command
,
11095 add_catch_command ("throw", _("\
11096 Catch an exception, when thrown.\n\
11097 With an argument, catch only exceptions with the given name."),
11098 catch_throw_command
,
11102 add_catch_command ("fork", _("Catch calls to fork."),
11103 catch_fork_command_1
,
11105 (void *) (uintptr_t) catch_fork_permanent
,
11106 (void *) (uintptr_t) catch_fork_temporary
);
11107 add_catch_command ("vfork", _("Catch calls to vfork."),
11108 catch_fork_command_1
,
11110 (void *) (uintptr_t) catch_vfork_permanent
,
11111 (void *) (uintptr_t) catch_vfork_temporary
);
11112 add_catch_command ("exec", _("Catch calls to exec."),
11113 catch_exec_command_1
,
11117 add_catch_command ("syscall", _("\
11118 Catch system calls by their names and/or numbers.\n\
11119 Arguments say which system calls to catch. If no arguments\n\
11120 are given, every system call will be caught.\n\
11121 Arguments, if given, should be one or more system call names\n\
11122 (if your system supports that), or system call numbers."),
11123 catch_syscall_command_1
,
11124 catch_syscall_completer
,
11127 add_catch_command ("exception", _("\
11128 Catch Ada exceptions, when raised.\n\
11129 With an argument, catch only exceptions with the given name."),
11130 catch_ada_exception_command
,
11134 add_catch_command ("assert", _("\
11135 Catch failed Ada assertions, when raised.\n\
11136 With an argument, catch only exceptions with the given name."),
11137 catch_assert_command
,
11142 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11143 Set a watchpoint for an expression.\n\
11144 A watchpoint stops execution of your program whenever the value of\n\
11145 an expression changes."));
11146 set_cmd_completer (c
, expression_completer
);
11148 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11149 Set a read watchpoint for an expression.\n\
11150 A watchpoint stops execution of your program whenever the value of\n\
11151 an expression is read."));
11152 set_cmd_completer (c
, expression_completer
);
11154 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11155 Set a watchpoint for an expression.\n\
11156 A watchpoint stops execution of your program whenever the value of\n\
11157 an expression is either read or written."));
11158 set_cmd_completer (c
, expression_completer
);
11160 add_info ("watchpoints", watchpoints_info
, _("\
11161 Status of watchpoints, or watchpoint number NUMBER."));
11165 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11166 respond to changes - contrary to the description. */
11167 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11168 &can_use_hw_watchpoints
, _("\
11169 Set debugger's willingness to use watchpoint hardware."), _("\
11170 Show debugger's willingness to use watchpoint hardware."), _("\
11171 If zero, gdb will not use hardware for new watchpoints, even if\n\
11172 such is available. (However, any hardware watchpoints that were\n\
11173 created before setting this to nonzero, will continue to use watchpoint\n\
11176 show_can_use_hw_watchpoints
,
11177 &setlist
, &showlist
);
11179 can_use_hw_watchpoints
= 1;
11181 /* Tracepoint manipulation commands. */
11183 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11184 Set a tracepoint at specified line or function.\n\
11186 BREAK_ARGS_HELP ("trace") "\n\
11187 Do \"help tracepoints\" for info on other tracepoint commands."));
11188 set_cmd_completer (c
, location_completer
);
11190 add_com_alias ("tp", "trace", class_alias
, 0);
11191 add_com_alias ("tr", "trace", class_alias
, 1);
11192 add_com_alias ("tra", "trace", class_alias
, 1);
11193 add_com_alias ("trac", "trace", class_alias
, 1);
11195 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11196 Set a fast tracepoint at specified line or function.\n\
11198 BREAK_ARGS_HELP ("ftrace") "\n\
11199 Do \"help tracepoints\" for info on other tracepoint commands."));
11200 set_cmd_completer (c
, location_completer
);
11202 add_info ("tracepoints", tracepoints_info
, _("\
11203 Status of tracepoints, or tracepoint number NUMBER.\n\
11204 Convenience variable \"$tpnum\" contains the number of the\n\
11205 last tracepoint set."));
11207 add_info_alias ("tp", "tracepoints", 1);
11209 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11210 Delete specified tracepoints.\n\
11211 Arguments are tracepoint numbers, separated by spaces.\n\
11212 No argument means delete all tracepoints."),
11215 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11216 Disable specified tracepoints.\n\
11217 Arguments are tracepoint numbers, separated by spaces.\n\
11218 No argument means disable all tracepoints."),
11220 deprecate_cmd (c
, "disable");
11222 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11223 Enable specified tracepoints.\n\
11224 Arguments are tracepoint numbers, separated by spaces.\n\
11225 No argument means enable all tracepoints."),
11227 deprecate_cmd (c
, "enable");
11229 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11230 Set the passcount for a tracepoint.\n\
11231 The trace will end when the tracepoint has been passed 'count' times.\n\
11232 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11233 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11235 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11236 Save current tracepoint definitions as a script.\n\
11237 Use the 'source' command in another debug session to restore them."));
11238 set_cmd_completer (c
, filename_completer
);
11240 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11241 Breakpoint specific settings\n\
11242 Configure various breakpoint-specific variables such as\n\
11243 pending breakpoint behavior"),
11244 &breakpoint_set_cmdlist
, "set breakpoint ",
11245 0/*allow-unknown*/, &setlist
);
11246 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11247 Breakpoint specific settings\n\
11248 Configure various breakpoint-specific variables such as\n\
11249 pending breakpoint behavior"),
11250 &breakpoint_show_cmdlist
, "show breakpoint ",
11251 0/*allow-unknown*/, &showlist
);
11253 add_setshow_auto_boolean_cmd ("pending", no_class
,
11254 &pending_break_support
, _("\
11255 Set debugger's behavior regarding pending breakpoints."), _("\
11256 Show debugger's behavior regarding pending breakpoints."), _("\
11257 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11258 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11259 an error. If auto, an unrecognized breakpoint location results in a\n\
11260 user-query to see if a pending breakpoint should be created."),
11262 show_pending_break_support
,
11263 &breakpoint_set_cmdlist
,
11264 &breakpoint_show_cmdlist
);
11266 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11268 add_setshow_boolean_cmd ("auto-hw", no_class
,
11269 &automatic_hardware_breakpoints
, _("\
11270 Set automatic usage of hardware breakpoints."), _("\
11271 Show automatic usage of hardware breakpoints."), _("\
11272 If set, the debugger will automatically use hardware breakpoints for\n\
11273 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11274 a warning will be emitted for such breakpoints."),
11276 show_automatic_hardware_breakpoints
,
11277 &breakpoint_set_cmdlist
,
11278 &breakpoint_show_cmdlist
);
11280 add_setshow_enum_cmd ("always-inserted", class_support
,
11281 always_inserted_enums
, &always_inserted_mode
, _("\
11282 Set mode for inserting breakpoints."), _("\
11283 Show mode for inserting breakpoints."), _("\
11284 When this mode is off, breakpoints are inserted in inferior when it is\n\
11285 resumed, and removed when execution stops. When this mode is on,\n\
11286 breakpoints are inserted immediately and removed only when the user\n\
11287 deletes the breakpoint. When this mode is auto (which is the default),\n\
11288 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11289 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11290 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11291 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11293 &show_always_inserted_mode
,
11294 &breakpoint_set_cmdlist
,
11295 &breakpoint_show_cmdlist
);
11297 automatic_hardware_breakpoints
= 1;
11299 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);