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
)
714 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
717 struct bp_location
*loc
= b
->loc
;
719 for (; loc
; loc
= loc
->next
)
724 xfree (b
->cond_string
);
725 b
->cond_string
= NULL
;
732 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
737 /* I don't know if it matters whether this is the string the user
738 typed in or the decompiled expression. */
739 b
->cond_string
= xstrdup (arg
);
740 b
->condition_not_parsed
= 0;
742 if (is_watchpoint (b
))
744 innermost_block
= NULL
;
746 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
748 error (_("Junk at end of expression"));
749 b
->cond_exp_valid_block
= innermost_block
;
753 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
757 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
759 error (_("Junk at end of expression"));
763 breakpoints_changed ();
764 observer_notify_breakpoint_modified (b
->number
);
767 /* condition N EXP -- set break condition of breakpoint N to EXP. */
770 condition_command (char *arg
, int from_tty
)
772 struct breakpoint
*b
;
777 error_no_arg (_("breakpoint number"));
780 bnum
= get_number (&p
);
782 error (_("Bad breakpoint argument: '%s'"), arg
);
785 if (b
->number
== bnum
)
787 set_breakpoint_condition (b
, p
, from_tty
);
791 error (_("No breakpoint number %d."), bnum
);
794 /* Check that COMMAND do not contain commands that are suitable
795 only for tracepoints and not suitable for ordinary breakpoints.
796 Throw if any such commands is found.
799 check_no_tracepoint_commands (struct command_line
*commands
)
801 struct command_line
*c
;
802 for (c
= commands
; c
; c
= c
->next
)
806 if (c
->control_type
== while_stepping_control
)
807 error (_("The 'while-stepping' command can only be used for tracepoints"));
809 for (i
= 0; i
< c
->body_count
; ++i
)
810 check_no_tracepoint_commands ((c
->body_list
)[i
]);
812 /* Not that command parsing removes leading whitespace and comment
813 lines and also empty lines. So, we only need to check for
815 if (strstr (c
->line
, "collect ") == c
->line
)
816 error (_("The 'collect' command can only be used for tracepoints"));
818 if (strstr (c
->line
, "teval ") == c
->line
)
819 error (_("The 'teval' command can only be used for tracepoints"));
823 /* Encapsulate tests for different types of tracepoints. */
826 is_tracepoint (const struct breakpoint
*b
)
828 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
831 /* A helper function that validsates that COMMANDS are valid for a
832 breakpoint. This function will throw an exception if a problem is
836 validate_commands_for_breakpoint (struct breakpoint
*b
,
837 struct command_line
*commands
)
839 if (is_tracepoint (b
))
841 /* We need to verify that each top-level element of commands
842 is valid for tracepoints, that there's at most one while-stepping
843 element, and that while-stepping's body has valid tracing commands
844 excluding nested while-stepping. */
845 struct command_line
*c
;
846 struct command_line
*while_stepping
= 0;
847 for (c
= commands
; c
; c
= c
->next
)
850 if (c
->control_type
== while_stepping_control
)
852 if (b
->type
== bp_fast_tracepoint
)
853 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
856 error (_("The 'while-stepping' command can be used only once"));
863 struct command_line
*c2
;
865 gdb_assert (while_stepping
->body_count
== 1);
866 c2
= while_stepping
->body_list
[0];
867 for (; c2
; c2
= c2
->next
)
870 if (c2
->control_type
== while_stepping_control
)
871 error (_("The 'while-stepping' command cannot be nested"));
877 check_no_tracepoint_commands (commands
);
881 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
882 validate that only allowed commands are included.
886 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
888 validate_commands_for_breakpoint (b
, commands
);
890 decref_counted_command_line (&b
->commands
);
891 b
->commands
= alloc_counted_command_line (commands
);
892 breakpoints_changed ();
893 observer_notify_breakpoint_modified (b
->number
);
897 check_tracepoint_command (char *line
, void *closure
)
899 struct breakpoint
*b
= closure
;
900 validate_actionline (&line
, b
);
903 /* A structure used to pass information through
904 map_breakpoint_numbers. */
908 /* True if the command was typed at a tty. */
911 /* The breakpoint range spec. */
914 /* Non-NULL if the body of the commands are being read from this
915 already-parsed command. */
916 struct command_line
*control
;
918 /* The command lines read from the user, or NULL if they have not
920 struct counted_command_line
*cmd
;
923 /* A callback for map_breakpoint_numbers that sets the commands for
927 do_map_commands_command (struct breakpoint
*b
, void *data
)
929 struct commands_info
*info
= data
;
931 if (info
->cmd
== NULL
)
933 struct command_line
*l
;
935 if (info
->control
!= NULL
)
936 l
= copy_command_lines (info
->control
->body_list
[0]);
939 struct cleanup
*old_chain
;
942 str
= xstrprintf (_("Type commands for breakpoint(s) %s, one per line."),
945 old_chain
= make_cleanup (xfree
, str
);
947 l
= read_command_lines (str
,
950 ? check_tracepoint_command
: 0),
953 do_cleanups (old_chain
);
956 info
->cmd
= alloc_counted_command_line (l
);
959 /* If a breakpoint was on the list more than once, we don't need to
961 if (b
->commands
!= info
->cmd
)
963 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
964 incref_counted_command_line (info
->cmd
);
965 decref_counted_command_line (&b
->commands
);
966 b
->commands
= info
->cmd
;
967 breakpoints_changed ();
968 observer_notify_breakpoint_modified (b
->number
);
973 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
975 struct cleanup
*cleanups
;
976 struct commands_info info
;
978 info
.from_tty
= from_tty
;
979 info
.control
= control
;
981 /* If we read command lines from the user, then `info' will hold an
982 extra reference to the commands that we must clean up. */
983 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
985 if (arg
== NULL
|| !*arg
)
987 if (breakpoint_count
- prev_breakpoint_count
> 1)
988 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1, breakpoint_count
);
989 else if (breakpoint_count
> 0)
990 arg
= xstrprintf ("%d", breakpoint_count
);
993 /* So that we don't try to free the incoming non-NULL
994 argument in the cleanup below. Mapping breakpoint
995 numbers will fail in this case. */
1000 /* The command loop has some static state, so we need to preserve
1002 arg
= xstrdup (arg
);
1005 make_cleanup (xfree
, arg
);
1009 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1011 if (info
.cmd
== NULL
)
1012 error (_("No breakpoints specified."));
1014 do_cleanups (cleanups
);
1018 commands_command (char *arg
, int from_tty
)
1020 commands_command_1 (arg
, from_tty
, NULL
);
1023 /* Like commands_command, but instead of reading the commands from
1024 input stream, takes them from an already parsed command structure.
1026 This is used by cli-script.c to DTRT with breakpoint commands
1027 that are part of if and while bodies. */
1028 enum command_control_type
1029 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1031 commands_command_1 (arg
, 0, cmd
);
1032 return simple_control
;
1035 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1038 bp_location_has_shadow (struct bp_location
*bl
)
1040 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1044 if (bl
->target_info
.shadow_len
== 0)
1045 /* bp isn't valid, or doesn't shadow memory. */
1050 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1051 by replacing any memory breakpoints with their shadowed contents.
1053 The range of shadowed area by each bp_location is:
1054 b->address - bp_location_placed_address_before_address_max
1055 up to b->address + bp_location_shadow_len_after_address_max
1056 The range we were requested to resolve shadows for is:
1057 memaddr ... memaddr + len
1058 Thus the safe cutoff boundaries for performance optimization are
1059 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1061 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1064 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1066 /* Left boundary, right boundary and median element of our binary search. */
1067 unsigned bc_l
, bc_r
, bc
;
1069 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1070 safe to report lower value but a failure to report higher one. */
1073 bc_r
= bp_location_count
;
1074 while (bc_l
+ 1 < bc_r
)
1076 struct bp_location
*b
;
1078 bc
= (bc_l
+ bc_r
) / 2;
1079 b
= bp_location
[bc
];
1081 /* Check first B->ADDRESS will not overflow due to the added constant.
1082 Then advance the left boundary only if we are sure the BC element can
1083 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1085 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1086 we cannot miss a breakpoint with its shadow range tail still reaching
1089 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1090 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1096 /* Now do full processing of the found relevant range of elements. */
1098 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1100 struct bp_location
*b
= bp_location
[bc
];
1101 CORE_ADDR bp_addr
= 0;
1105 if (b
->owner
->type
== bp_none
)
1106 warning (_("reading through apparently deleted breakpoint #%d?"),
1109 /* Performance optimization: any futher element can no longer affect BUF
1112 if (b
->address
>= bp_location_placed_address_before_address_max
1113 && memaddr
+ len
<= b
->address
1114 - bp_location_placed_address_before_address_max
)
1117 if (!bp_location_has_shadow (b
))
1119 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1120 current_program_space
->aspace
, 0))
1123 /* Addresses and length of the part of the breakpoint that
1125 bp_addr
= b
->target_info
.placed_address
;
1126 bp_size
= b
->target_info
.shadow_len
;
1128 if (bp_addr
+ bp_size
<= memaddr
)
1129 /* The breakpoint is entirely before the chunk of memory we
1133 if (bp_addr
>= memaddr
+ len
)
1134 /* The breakpoint is entirely after the chunk of memory we are
1138 /* Offset within shadow_contents. */
1139 if (bp_addr
< memaddr
)
1141 /* Only copy the second part of the breakpoint. */
1142 bp_size
-= memaddr
- bp_addr
;
1143 bptoffset
= memaddr
- bp_addr
;
1147 if (bp_addr
+ bp_size
> memaddr
+ len
)
1149 /* Only copy the first part of the breakpoint. */
1150 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1153 memcpy (buf
+ bp_addr
- memaddr
,
1154 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1159 /* A wrapper function for inserting catchpoints. */
1161 insert_catchpoint (struct ui_out
*uo
, void *args
)
1163 struct breakpoint
*b
= (struct breakpoint
*) args
;
1166 gdb_assert (b
->type
== bp_catchpoint
);
1167 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1172 /* Return true if BPT is of any hardware watchpoint kind. */
1175 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1177 return (bpt
->type
== bp_hardware_watchpoint
1178 || bpt
->type
== bp_read_watchpoint
1179 || bpt
->type
== bp_access_watchpoint
);
1182 /* Return true if BPT is of any watchpoint kind, hardware or
1186 is_watchpoint (const struct breakpoint
*bpt
)
1188 return (is_hardware_watchpoint (bpt
)
1189 || bpt
->type
== bp_watchpoint
);
1192 /* Find the current value of a watchpoint on EXP. Return the value in
1193 *VALP and *RESULTP and the chain of intermediate and final values
1194 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1197 If a memory error occurs while evaluating the expression, *RESULTP will
1198 be set to NULL. *RESULTP may be a lazy value, if the result could
1199 not be read from memory. It is used to determine whether a value
1200 is user-specified (we should watch the whole value) or intermediate
1201 (we should watch only the bit used to locate the final value).
1203 If the final value, or any intermediate value, could not be read
1204 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1205 set to any referenced values. *VALP will never be a lazy value.
1206 This is the value which we store in struct breakpoint.
1208 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1209 value chain. The caller must free the values individually. If
1210 VAL_CHAIN is NULL, all generated values will be left on the value
1214 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1215 struct value
**resultp
, struct value
**val_chain
)
1217 struct value
*mark
, *new_mark
, *result
;
1218 volatile struct gdb_exception ex
;
1226 /* Evaluate the expression. */
1227 mark
= value_mark ();
1230 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1232 result
= evaluate_expression (exp
);
1236 /* Ignore memory errors, we want watchpoints pointing at
1237 inaccessible memory to still be created; otherwise, throw the
1238 error to some higher catcher. */
1244 throw_exception (ex
);
1249 new_mark
= value_mark ();
1250 if (mark
== new_mark
)
1255 /* Make sure it's not lazy, so that after the target stops again we
1256 have a non-lazy previous value to compare with. */
1258 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1263 /* Return the chain of intermediate values. We use this to
1264 decide which addresses to watch. */
1265 *val_chain
= new_mark
;
1266 value_release_to_mark (mark
);
1270 /* Assuming that B is a watchpoint: returns true if the current thread
1271 and its running state are safe to evaluate or update watchpoint B.
1272 Watchpoints on local expressions need to be evaluated in the
1273 context of the thread that was current when the watchpoint was
1274 created, and, that thread needs to be stopped to be able to select
1275 the correct frame context. Watchpoints on global expressions can
1276 be evaluated on any thread, and in any state. It is presently left
1277 to the target allowing memory accesses when threads are
1281 watchpoint_in_thread_scope (struct breakpoint
*b
)
1283 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1284 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1285 && !is_executing (inferior_ptid
)));
1288 /* Assuming that B is a watchpoint:
1289 - Reparse watchpoint expression, if REPARSE is non-zero
1290 - Evaluate expression and store the result in B->val
1291 - Evaluate the condition if there is one, and store the result
1293 - Update the list of values that must be watched in B->loc.
1295 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1296 If this is local watchpoint that is out of scope, delete it.
1298 Even with `set breakpoint always-inserted on' the watchpoints are removed
1299 + inserted on each stop here. Normal breakpoints must never be removed
1300 because they might be missed by a running thread when debugging in non-stop
1301 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1302 processed here) are specific to each LWP since they are stored in each LWP's
1303 hardware debug registers. Therefore, such LWP must be stopped first in
1304 order to be able to modify its hardware watchpoints.
1306 Hardware watchpoints must be reset exactly once after being presented to the
1307 user. It cannot be done sooner, because it would reset the data used to
1308 present the watchpoint hit to the user. And it must not be done later
1309 because it could display the same single watchpoint hit during multiple GDB
1310 stops. Note that the latter is relevant only to the hardware watchpoint
1311 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1312 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1313 memory content has not changed.
1315 The following constraints influence the location where we can reset hardware
1318 * target_stopped_by_watchpoint and target_stopped_data_address are called
1319 several times when GDB stops.
1322 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1323 stop. GDB only presents one hardware watchpoint hit at a time as the
1324 reason for stopping, and all the other hits are presented later, one after
1325 the other, each time the user requests the execution to be resumed.
1326 Execution is not resumed for the threads still having pending hit event
1327 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1328 the inferior on the first stop the thread hit event is kept being reported
1329 from its cached value by linux_nat_stopped_data_address until the real
1330 thread resume happens after the watchpoint gets presented and thus its
1331 LWP_INFO->STATUS gets reset.
1333 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1334 removal from inferior. */
1337 update_watchpoint (struct breakpoint
*b
, int reparse
)
1339 int within_current_scope
;
1340 struct frame_id saved_frame_id
;
1341 struct bp_location
*loc
;
1345 /* If this is a local watchpoint, we only want to check if the
1346 watchpoint frame is in scope if the current thread is the thread
1347 that was used to create the watchpoint. */
1348 if (!watchpoint_in_thread_scope (b
))
1351 /* We don't free locations. They are stored in bp_location array and
1352 update_global_locations will eventually delete them and remove
1353 breakpoints if needed. */
1356 if (b
->disposition
== disp_del_at_next_stop
)
1361 /* Determine if the watchpoint is within scope. */
1362 if (b
->exp_valid_block
== NULL
)
1363 within_current_scope
= 1;
1366 struct frame_info
*fi
;
1368 /* Save the current frame's ID so we can restore it after
1369 evaluating the watchpoint expression on its own frame. */
1370 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1371 took a frame parameter, so that we didn't have to change the
1374 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1376 fi
= frame_find_by_id (b
->watchpoint_frame
);
1377 within_current_scope
= (fi
!= NULL
);
1378 if (within_current_scope
)
1382 if (within_current_scope
&& reparse
)
1391 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1392 /* If the meaning of expression itself changed, the old value is
1393 no longer relevant. We don't want to report a watchpoint hit
1394 to the user when the old value and the new value may actually
1395 be completely different objects. */
1396 value_free (b
->val
);
1400 /* Note that unlike with breakpoints, the watchpoint's condition
1401 expression is stored in the breakpoint object, not in the
1402 locations (re)created below. */
1403 if (b
->cond_string
!= NULL
)
1405 if (b
->cond_exp
!= NULL
)
1407 xfree (b
->cond_exp
);
1412 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1416 /* If we failed to parse the expression, for example because
1417 it refers to a global variable in a not-yet-loaded shared library,
1418 don't try to insert watchpoint. We don't automatically delete
1419 such watchpoint, though, since failure to parse expression
1420 is different from out-of-scope watchpoint. */
1421 if ( !target_has_execution
)
1423 /* Without execution, memory can't change. No use to try and
1424 set watchpoint locations. The watchpoint will be reset when
1425 the target gains execution, through breakpoint_re_set. */
1427 else if (within_current_scope
&& b
->exp
)
1429 struct value
*val_chain
, *v
, *result
, *next
;
1430 struct program_space
*frame_pspace
;
1432 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1434 /* Avoid setting b->val if it's already set. The meaning of
1435 b->val is 'the last value' user saw, and we should update
1436 it only if we reported that last value to user. As it
1437 happens, the code that reports it updates b->val directly. */
1444 /* Change the type of breakpoint between hardware assisted or an
1445 ordinary watchpoint depending on the hardware support and free
1446 hardware slots. REPARSE is set when the inferior is started. */
1447 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1450 int i
, mem_cnt
, other_type_used
;
1452 /* We need to determine how many resources are already used
1453 for all other hardware watchpoints to see if we still have
1454 enough resources to also fit this watchpoint in as well.
1455 To avoid the hw_watchpoint_used_count call below from counting
1456 this watchpoint, make sure that it is marked as a software
1458 b
->type
= bp_watchpoint
;
1459 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1461 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1464 b
->type
= bp_watchpoint
;
1467 int target_resources_ok
= target_can_use_hardware_watchpoint
1468 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1469 if (target_resources_ok
<= 0)
1470 b
->type
= bp_watchpoint
;
1472 b
->type
= bp_hardware_watchpoint
;
1476 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1478 /* Look at each value on the value chain. */
1479 for (v
= val_chain
; v
; v
= next
)
1481 /* If it's a memory location, and GDB actually needed
1482 its contents to evaluate the expression, then we
1483 must watch it. If the first value returned is
1484 still lazy, that means an error occurred reading it;
1485 watch it anyway in case it becomes readable. */
1486 if (VALUE_LVAL (v
) == lval_memory
1487 && (v
== val_chain
|| ! value_lazy (v
)))
1489 struct type
*vtype
= check_typedef (value_type (v
));
1491 /* We only watch structs and arrays if user asked
1492 for it explicitly, never if they just happen to
1493 appear in the middle of some value chain. */
1495 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1496 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1500 struct bp_location
*loc
, **tmp
;
1502 addr
= value_address (v
);
1503 len
= TYPE_LENGTH (value_type (v
));
1505 if (b
->type
== bp_read_watchpoint
)
1507 else if (b
->type
== bp_access_watchpoint
)
1510 loc
= allocate_bp_location (b
);
1511 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1514 loc
->gdbarch
= get_type_arch (value_type (v
));
1516 loc
->pspace
= frame_pspace
;
1517 loc
->address
= addr
;
1519 loc
->watchpoint_type
= type
;
1523 next
= value_next (v
);
1528 /* If a software watchpoint is not watching any memory, then the
1529 above left it without any location set up. But,
1530 bpstat_stop_status requires a location to be able to report
1531 stops, so make sure there's at least a dummy one. */
1532 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1534 b
->loc
= allocate_bp_location (b
);
1535 b
->loc
->pspace
= frame_pspace
;
1536 b
->loc
->address
= -1;
1537 b
->loc
->length
= -1;
1538 b
->loc
->watchpoint_type
= -1;
1541 else if (!within_current_scope
)
1543 printf_filtered (_("\
1544 Watchpoint %d deleted because the program has left the block \n\
1545 in which its expression is valid.\n"),
1547 if (b
->related_breakpoint
)
1549 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1550 b
->related_breakpoint
->related_breakpoint
= NULL
;
1551 b
->related_breakpoint
= NULL
;
1553 b
->disposition
= disp_del_at_next_stop
;
1556 /* Restore the selected frame. */
1558 select_frame (frame_find_by_id (saved_frame_id
));
1562 /* Returns 1 iff breakpoint location should be
1563 inserted in the inferior. */
1565 should_be_inserted (struct bp_location
*bpt
)
1567 if (!breakpoint_enabled (bpt
->owner
))
1570 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1573 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1576 /* This is set for example, when we're attached to the parent of a
1577 vfork, and have detached from the child. The child is running
1578 free, and we expect it to do an exec or exit, at which point the
1579 OS makes the parent schedulable again (and the target reports
1580 that the vfork is done). Until the child is done with the shared
1581 memory region, do not insert breakpoints in the parent, otherwise
1582 the child could still trip on the parent's breakpoints. Since
1583 the parent is blocked anyway, it won't miss any breakpoint. */
1584 if (bpt
->pspace
->breakpoints_not_allowed
)
1587 /* Tracepoints are inserted by the target at a time of its choosing,
1589 if (is_tracepoint (bpt
->owner
))
1595 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1596 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1597 and HW_BREAKPOINT_ERROR are used to report problems.
1599 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1600 method for each breakpoint or catchpoint type. */
1602 insert_bp_location (struct bp_location
*bpt
,
1603 struct ui_file
*tmp_error_stream
,
1604 int *disabled_breaks
,
1605 int *hw_breakpoint_error
)
1609 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1612 /* Initialize the target-specific information. */
1613 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1614 bpt
->target_info
.placed_address
= bpt
->address
;
1615 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1617 if (bpt
->loc_type
== bp_loc_software_breakpoint
1618 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1620 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1622 /* If the explicitly specified breakpoint type
1623 is not hardware breakpoint, check the memory map to see
1624 if the breakpoint address is in read only memory or not.
1625 Two important cases are:
1626 - location type is not hardware breakpoint, memory
1627 is readonly. We change the type of the location to
1628 hardware breakpoint.
1629 - location type is hardware breakpoint, memory is read-write.
1630 This means we've previously made the location hardware one, but
1631 then the memory map changed, so we undo.
1633 When breakpoints are removed, remove_breakpoints will
1634 use location types we've just set here, the only possible
1635 problem is that memory map has changed during running program,
1636 but it's not going to work anyway with current gdb. */
1637 struct mem_region
*mr
1638 = lookup_mem_region (bpt
->target_info
.placed_address
);
1642 if (automatic_hardware_breakpoints
)
1645 enum bp_loc_type new_type
;
1647 if (mr
->attrib
.mode
!= MEM_RW
)
1648 new_type
= bp_loc_hardware_breakpoint
;
1650 new_type
= bp_loc_software_breakpoint
;
1652 if (new_type
!= bpt
->loc_type
)
1654 static int said
= 0;
1655 bpt
->loc_type
= new_type
;
1658 fprintf_filtered (gdb_stdout
, _("\
1659 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1664 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1665 && mr
->attrib
.mode
!= MEM_RW
)
1666 warning (_("cannot set software breakpoint at readonly address %s"),
1667 paddress (bpt
->gdbarch
, bpt
->address
));
1671 /* First check to see if we have to handle an overlay. */
1672 if (overlay_debugging
== ovly_off
1673 || bpt
->section
== NULL
1674 || !(section_is_overlay (bpt
->section
)))
1676 /* No overlay handling: just set the breakpoint. */
1678 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1679 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1682 val
= target_insert_breakpoint (bpt
->gdbarch
,
1687 /* This breakpoint is in an overlay section.
1688 Shall we set a breakpoint at the LMA? */
1689 if (!overlay_events_enabled
)
1691 /* Yes -- overlay event support is not active,
1692 so we must try to set a breakpoint at the LMA.
1693 This will not work for a hardware breakpoint. */
1694 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1695 warning (_("hardware breakpoint %d not supported in overlay!"),
1696 bpt
->owner
->number
);
1699 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1701 /* Set a software (trap) breakpoint at the LMA. */
1702 bpt
->overlay_target_info
= bpt
->target_info
;
1703 bpt
->overlay_target_info
.placed_address
= addr
;
1704 val
= target_insert_breakpoint (bpt
->gdbarch
,
1705 &bpt
->overlay_target_info
);
1707 fprintf_unfiltered (tmp_error_stream
,
1708 "Overlay breakpoint %d failed: in ROM?\n",
1709 bpt
->owner
->number
);
1712 /* Shall we set a breakpoint at the VMA? */
1713 if (section_is_mapped (bpt
->section
))
1715 /* Yes. This overlay section is mapped into memory. */
1716 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1717 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1720 val
= target_insert_breakpoint (bpt
->gdbarch
,
1725 /* No. This breakpoint will not be inserted.
1726 No error, but do not mark the bp as 'inserted'. */
1733 /* Can't set the breakpoint. */
1734 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1736 /* See also: disable_breakpoints_in_shlibs. */
1738 bpt
->shlib_disabled
= 1;
1739 if (!*disabled_breaks
)
1741 fprintf_unfiltered (tmp_error_stream
,
1742 "Cannot insert breakpoint %d.\n",
1743 bpt
->owner
->number
);
1744 fprintf_unfiltered (tmp_error_stream
,
1745 "Temporarily disabling shared library breakpoints:\n");
1747 *disabled_breaks
= 1;
1748 fprintf_unfiltered (tmp_error_stream
,
1749 "breakpoint #%d\n", bpt
->owner
->number
);
1753 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1755 *hw_breakpoint_error
= 1;
1756 fprintf_unfiltered (tmp_error_stream
,
1757 "Cannot insert hardware breakpoint %d.\n",
1758 bpt
->owner
->number
);
1762 fprintf_unfiltered (tmp_error_stream
,
1763 "Cannot insert breakpoint %d.\n",
1764 bpt
->owner
->number
);
1765 fprintf_filtered (tmp_error_stream
,
1766 "Error accessing memory address ");
1767 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1769 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1770 safe_strerror (val
));
1781 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1782 /* NOTE drow/2003-09-08: This state only exists for removing
1783 watchpoints. It's not clear that it's necessary... */
1784 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1786 val
= target_insert_watchpoint (bpt
->address
,
1788 bpt
->watchpoint_type
);
1790 /* If trying to set a read-watchpoint, and it turns out it's not
1791 supported, try emulating one with an access watchpoint. */
1792 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1794 struct bp_location
*loc
, **loc_temp
;
1796 /* But don't try to insert it, if there's already another
1797 hw_access location that would be considered a duplicate
1799 ALL_BP_LOCATIONS (loc
, loc_temp
)
1801 && loc
->watchpoint_type
== hw_access
1802 && watchpoint_locations_match (bpt
, loc
))
1806 bpt
->target_info
= loc
->target_info
;
1807 bpt
->watchpoint_type
= hw_access
;
1814 val
= target_insert_watchpoint (bpt
->address
,
1818 bpt
->watchpoint_type
= hw_access
;
1822 bpt
->inserted
= (val
== 0);
1825 else if (bpt
->owner
->type
== bp_catchpoint
)
1827 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1828 bpt
->owner
, RETURN_MASK_ERROR
);
1829 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1830 bpt
->owner
->number
);
1832 bpt
->owner
->enable_state
= bp_disabled
;
1836 /* We've already printed an error message if there was a problem
1837 inserting this catchpoint, and we've disabled the catchpoint,
1838 so just return success. */
1845 /* This function is called when program space PSPACE is about to be
1846 deleted. It takes care of updating breakpoints to not reference
1850 breakpoint_program_space_exit (struct program_space
*pspace
)
1852 struct breakpoint
*b
, *b_temp
;
1853 struct bp_location
*loc
, **loc_temp
;
1855 /* Remove any breakpoint that was set through this program space. */
1856 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1858 if (b
->pspace
== pspace
)
1859 delete_breakpoint (b
);
1862 /* Breakpoints set through other program spaces could have locations
1863 bound to PSPACE as well. Remove those. */
1864 ALL_BP_LOCATIONS (loc
, loc_temp
)
1866 struct bp_location
*tmp
;
1868 if (loc
->pspace
== pspace
)
1870 if (loc
->owner
->loc
== loc
)
1871 loc
->owner
->loc
= loc
->next
;
1873 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1874 if (tmp
->next
== loc
)
1876 tmp
->next
= loc
->next
;
1882 /* Now update the global location list to permanently delete the
1883 removed locations above. */
1884 update_global_location_list (0);
1887 /* Make sure all breakpoints are inserted in inferior.
1888 Throws exception on any error.
1889 A breakpoint that is already inserted won't be inserted
1890 again, so calling this function twice is safe. */
1892 insert_breakpoints (void)
1894 struct breakpoint
*bpt
;
1896 ALL_BREAKPOINTS (bpt
)
1897 if (is_hardware_watchpoint (bpt
))
1898 update_watchpoint (bpt
, 0 /* don't reparse. */);
1900 update_global_location_list (1);
1902 /* update_global_location_list does not insert breakpoints when
1903 always_inserted_mode is not enabled. Explicitly insert them
1905 if (!breakpoints_always_inserted_mode ())
1906 insert_breakpoint_locations ();
1909 /* insert_breakpoints is used when starting or continuing the program.
1910 remove_breakpoints is used when the program stops.
1911 Both return zero if successful,
1912 or an `errno' value if could not write the inferior. */
1915 insert_breakpoint_locations (void)
1917 struct breakpoint
*bpt
;
1918 struct bp_location
*b
, **bp_tmp
;
1921 int disabled_breaks
= 0;
1922 int hw_breakpoint_error
= 0;
1924 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1925 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1927 /* Explicitly mark the warning -- this will only be printed if
1928 there was an error. */
1929 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1931 save_current_space_and_thread ();
1933 ALL_BP_LOCATIONS (b
, bp_tmp
)
1935 struct thread_info
*tp
;
1936 CORE_ADDR last_addr
;
1938 if (!should_be_inserted (b
) || b
->inserted
)
1941 /* There is no point inserting thread-specific breakpoints if the
1942 thread no longer exists. */
1943 if (b
->owner
->thread
!= -1
1944 && !valid_thread_id (b
->owner
->thread
))
1947 switch_to_program_space_and_thread (b
->pspace
);
1949 /* For targets that support global breakpoints, there's no need
1950 to select an inferior to insert breakpoint to. In fact, even
1951 if we aren't attached to any process yet, we should still
1952 insert breakpoints. */
1953 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1954 && ptid_equal (inferior_ptid
, null_ptid
))
1957 val
= insert_bp_location (b
, tmp_error_stream
,
1959 &hw_breakpoint_error
);
1964 /* If we failed to insert all locations of a watchpoint,
1965 remove them, as half-inserted watchpoint is of limited use. */
1966 ALL_BREAKPOINTS (bpt
)
1968 int some_failed
= 0;
1969 struct bp_location
*loc
;
1971 if (!is_hardware_watchpoint (bpt
))
1974 if (!breakpoint_enabled (bpt
))
1977 if (bpt
->disposition
== disp_del_at_next_stop
)
1980 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1981 if (!loc
->inserted
&& should_be_inserted (loc
))
1988 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1990 remove_breakpoint (loc
, mark_uninserted
);
1992 hw_breakpoint_error
= 1;
1993 fprintf_unfiltered (tmp_error_stream
,
1994 "Could not insert hardware watchpoint %d.\n",
2002 /* If a hardware breakpoint or watchpoint was inserted, add a
2003 message about possibly exhausted resources. */
2004 if (hw_breakpoint_error
)
2006 fprintf_unfiltered (tmp_error_stream
,
2007 "Could not insert hardware breakpoints:\n\
2008 You may have requested too many hardware breakpoints/watchpoints.\n");
2010 target_terminal_ours_for_output ();
2011 error_stream (tmp_error_stream
);
2014 do_cleanups (cleanups
);
2018 remove_breakpoints (void)
2020 struct bp_location
*b
, **bp_tmp
;
2023 ALL_BP_LOCATIONS (b
, bp_tmp
)
2026 val
|= remove_breakpoint (b
, mark_uninserted
);
2031 /* Remove breakpoints of process PID. */
2034 remove_breakpoints_pid (int pid
)
2036 struct bp_location
*b
, **b_tmp
;
2038 struct inferior
*inf
= find_inferior_pid (pid
);
2040 ALL_BP_LOCATIONS (b
, b_tmp
)
2042 if (b
->pspace
!= inf
->pspace
)
2047 val
= remove_breakpoint (b
, mark_uninserted
);
2056 remove_hw_watchpoints (void)
2058 struct bp_location
*b
, **bp_tmp
;
2061 ALL_BP_LOCATIONS (b
, bp_tmp
)
2063 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2064 val
|= remove_breakpoint (b
, mark_uninserted
);
2070 reattach_breakpoints (int pid
)
2072 struct cleanup
*old_chain
;
2073 struct bp_location
*b
, **bp_tmp
;
2075 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2076 int dummy1
= 0, dummy2
= 0;
2077 struct inferior
*inf
;
2078 struct thread_info
*tp
;
2080 tp
= any_live_thread_of_process (pid
);
2084 inf
= find_inferior_pid (pid
);
2085 old_chain
= save_inferior_ptid ();
2087 inferior_ptid
= tp
->ptid
;
2089 make_cleanup_ui_file_delete (tmp_error_stream
);
2091 ALL_BP_LOCATIONS (b
, bp_tmp
)
2093 if (b
->pspace
!= inf
->pspace
)
2099 val
= insert_bp_location (b
, tmp_error_stream
,
2103 do_cleanups (old_chain
);
2108 do_cleanups (old_chain
);
2112 static int internal_breakpoint_number
= -1;
2114 static struct breakpoint
*
2115 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2116 CORE_ADDR address
, enum bptype type
)
2118 struct symtab_and_line sal
;
2119 struct breakpoint
*b
;
2121 init_sal (&sal
); /* initialize to zeroes */
2124 sal
.section
= find_pc_overlay (sal
.pc
);
2125 sal
.pspace
= current_program_space
;
2127 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2128 b
->number
= internal_breakpoint_number
--;
2129 b
->disposition
= disp_donttouch
;
2135 create_overlay_event_breakpoint (char *func_name
)
2137 struct objfile
*objfile
;
2139 ALL_OBJFILES (objfile
)
2141 struct breakpoint
*b
;
2142 struct minimal_symbol
*m
;
2144 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2148 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2149 SYMBOL_VALUE_ADDRESS (m
),
2151 b
->addr_string
= xstrdup (func_name
);
2153 if (overlay_debugging
== ovly_auto
)
2155 b
->enable_state
= bp_enabled
;
2156 overlay_events_enabled
= 1;
2160 b
->enable_state
= bp_disabled
;
2161 overlay_events_enabled
= 0;
2164 update_global_location_list (1);
2168 create_longjmp_master_breakpoint (char *func_name
)
2170 struct program_space
*pspace
;
2171 struct objfile
*objfile
;
2172 struct cleanup
*old_chain
;
2174 old_chain
= save_current_program_space ();
2176 ALL_PSPACES (pspace
)
2177 ALL_OBJFILES (objfile
)
2179 struct breakpoint
*b
;
2180 struct minimal_symbol
*m
;
2182 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2185 set_current_program_space (pspace
);
2187 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2191 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2192 SYMBOL_VALUE_ADDRESS (m
),
2194 b
->addr_string
= xstrdup (func_name
);
2195 b
->enable_state
= bp_disabled
;
2197 update_global_location_list (1);
2199 do_cleanups (old_chain
);
2202 /* Create a master std::terminate breakpoint. The actual function
2203 looked for is named FUNC_NAME. */
2205 create_std_terminate_master_breakpoint (const char *func_name
)
2207 struct program_space
*pspace
;
2208 struct objfile
*objfile
;
2209 struct cleanup
*old_chain
;
2211 old_chain
= save_current_program_space ();
2213 ALL_PSPACES (pspace
)
2214 ALL_OBJFILES (objfile
)
2216 struct breakpoint
*b
;
2217 struct minimal_symbol
*m
;
2219 set_current_program_space (pspace
);
2221 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2222 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2223 && MSYMBOL_TYPE (m
) != mst_file_text
))
2226 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2227 SYMBOL_VALUE_ADDRESS (m
),
2228 bp_std_terminate_master
);
2229 b
->addr_string
= xstrdup (func_name
);
2230 b
->enable_state
= bp_disabled
;
2232 update_global_location_list (1);
2234 do_cleanups (old_chain
);
2238 update_breakpoints_after_exec (void)
2240 struct breakpoint
*b
;
2241 struct breakpoint
*temp
;
2242 struct bp_location
*bploc
, **bplocp_tmp
;
2244 /* We're about to delete breakpoints from GDB's lists. If the
2245 INSERTED flag is true, GDB will try to lift the breakpoints by
2246 writing the breakpoints' "shadow contents" back into memory. The
2247 "shadow contents" are NOT valid after an exec, so GDB should not
2248 do that. Instead, the target is responsible from marking
2249 breakpoints out as soon as it detects an exec. We don't do that
2250 here instead, because there may be other attempts to delete
2251 breakpoints after detecting an exec and before reaching here. */
2252 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2253 if (bploc
->pspace
== current_program_space
)
2254 gdb_assert (!bploc
->inserted
);
2256 ALL_BREAKPOINTS_SAFE (b
, temp
)
2258 if (b
->pspace
!= current_program_space
)
2261 /* Solib breakpoints must be explicitly reset after an exec(). */
2262 if (b
->type
== bp_shlib_event
)
2264 delete_breakpoint (b
);
2268 /* JIT breakpoints must be explicitly reset after an exec(). */
2269 if (b
->type
== bp_jit_event
)
2271 delete_breakpoint (b
);
2275 /* Thread event breakpoints must be set anew after an exec(),
2276 as must overlay event and longjmp master breakpoints. */
2277 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2278 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2280 delete_breakpoint (b
);
2284 /* Step-resume breakpoints are meaningless after an exec(). */
2285 if (b
->type
== bp_step_resume
)
2287 delete_breakpoint (b
);
2291 /* Longjmp and longjmp-resume breakpoints are also meaningless
2293 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2295 delete_breakpoint (b
);
2299 if (b
->type
== bp_catchpoint
)
2301 /* For now, none of the bp_catchpoint breakpoints need to
2302 do anything at this point. In the future, if some of
2303 the catchpoints need to something, we will need to add
2304 a new method, and call this method from here. */
2308 /* bp_finish is a special case. The only way we ought to be able
2309 to see one of these when an exec() has happened, is if the user
2310 caught a vfork, and then said "finish". Ordinarily a finish just
2311 carries them to the call-site of the current callee, by setting
2312 a temporary bp there and resuming. But in this case, the finish
2313 will carry them entirely through the vfork & exec.
2315 We don't want to allow a bp_finish to remain inserted now. But
2316 we can't safely delete it, 'cause finish_command has a handle to
2317 the bp on a bpstat, and will later want to delete it. There's a
2318 chance (and I've seen it happen) that if we delete the bp_finish
2319 here, that its storage will get reused by the time finish_command
2320 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2321 We really must allow finish_command to delete a bp_finish.
2323 In the absense of a general solution for the "how do we know
2324 it's safe to delete something others may have handles to?"
2325 problem, what we'll do here is just uninsert the bp_finish, and
2326 let finish_command delete it.
2328 (We know the bp_finish is "doomed" in the sense that it's
2329 momentary, and will be deleted as soon as finish_command sees
2330 the inferior stopped. So it doesn't matter that the bp's
2331 address is probably bogus in the new a.out, unlike e.g., the
2332 solib breakpoints.) */
2334 if (b
->type
== bp_finish
)
2339 /* Without a symbolic address, we have little hope of the
2340 pre-exec() address meaning the same thing in the post-exec()
2342 if (b
->addr_string
== NULL
)
2344 delete_breakpoint (b
);
2348 /* FIXME what about longjmp breakpoints? Re-create them here? */
2349 create_overlay_event_breakpoint ("_ovly_debug_event");
2350 create_longjmp_master_breakpoint ("longjmp");
2351 create_longjmp_master_breakpoint ("_longjmp");
2352 create_longjmp_master_breakpoint ("siglongjmp");
2353 create_longjmp_master_breakpoint ("_siglongjmp");
2354 create_std_terminate_master_breakpoint ("std::terminate()");
2358 detach_breakpoints (int pid
)
2360 struct bp_location
*b
, **bp_tmp
;
2362 struct cleanup
*old_chain
= save_inferior_ptid ();
2363 struct inferior
*inf
= current_inferior ();
2365 if (pid
== PIDGET (inferior_ptid
))
2366 error (_("Cannot detach breakpoints of inferior_ptid"));
2368 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2369 inferior_ptid
= pid_to_ptid (pid
);
2370 ALL_BP_LOCATIONS (b
, bp_tmp
)
2372 if (b
->pspace
!= inf
->pspace
)
2376 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2378 do_cleanups (old_chain
);
2382 /* Remove the breakpoint location B from the current address space.
2383 Note that this is used to detach breakpoints from a child fork.
2384 When we get here, the child isn't in the inferior list, and neither
2385 do we have objects to represent its address space --- we should
2386 *not* look at b->pspace->aspace here. */
2389 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2392 struct cleanup
*old_chain
;
2394 if (b
->owner
->enable_state
== bp_permanent
)
2395 /* Permanent breakpoints cannot be inserted or removed. */
2398 /* The type of none suggests that owner is actually deleted.
2399 This should not ever happen. */
2400 gdb_assert (b
->owner
->type
!= bp_none
);
2402 if (b
->loc_type
== bp_loc_software_breakpoint
2403 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2405 /* "Normal" instruction breakpoint: either the standard
2406 trap-instruction bp (bp_breakpoint), or a
2407 bp_hardware_breakpoint. */
2409 /* First check to see if we have to handle an overlay. */
2410 if (overlay_debugging
== ovly_off
2411 || b
->section
== NULL
2412 || !(section_is_overlay (b
->section
)))
2414 /* No overlay handling: just remove the breakpoint. */
2416 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2417 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2419 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2423 /* This breakpoint is in an overlay section.
2424 Did we set a breakpoint at the LMA? */
2425 if (!overlay_events_enabled
)
2427 /* Yes -- overlay event support is not active, so we
2428 should have set a breakpoint at the LMA. Remove it.
2430 /* Ignore any failures: if the LMA is in ROM, we will
2431 have already warned when we failed to insert it. */
2432 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2433 target_remove_hw_breakpoint (b
->gdbarch
,
2434 &b
->overlay_target_info
);
2436 target_remove_breakpoint (b
->gdbarch
,
2437 &b
->overlay_target_info
);
2439 /* Did we set a breakpoint at the VMA?
2440 If so, we will have marked the breakpoint 'inserted'. */
2443 /* Yes -- remove it. Previously we did not bother to
2444 remove the breakpoint if the section had been
2445 unmapped, but let's not rely on that being safe. We
2446 don't know what the overlay manager might do. */
2447 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2448 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2451 /* However, we should remove *software* breakpoints only
2452 if the section is still mapped, or else we overwrite
2453 wrong code with the saved shadow contents. */
2454 else if (section_is_mapped (b
->section
))
2455 val
= target_remove_breakpoint (b
->gdbarch
,
2462 /* No -- not inserted, so no need to remove. No error. */
2467 /* In some cases, we might not be able to remove a breakpoint
2468 in a shared library that has already been removed, but we
2469 have not yet processed the shlib unload event. */
2470 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2475 b
->inserted
= (is
== mark_inserted
);
2477 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2482 b
->inserted
= (is
== mark_inserted
);
2483 val
= target_remove_watchpoint (b
->address
, b
->length
,
2484 b
->watchpoint_type
);
2486 /* Failure to remove any of the hardware watchpoints comes here. */
2487 if ((is
== mark_uninserted
) && (b
->inserted
))
2488 warning (_("Could not remove hardware watchpoint %d."),
2491 else if (b
->owner
->type
== bp_catchpoint
2492 && breakpoint_enabled (b
->owner
)
2495 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2497 val
= b
->owner
->ops
->remove (b
->owner
);
2500 b
->inserted
= (is
== mark_inserted
);
2507 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2510 struct cleanup
*old_chain
;
2512 if (b
->owner
->enable_state
== bp_permanent
)
2513 /* Permanent breakpoints cannot be inserted or removed. */
2516 /* The type of none suggests that owner is actually deleted.
2517 This should not ever happen. */
2518 gdb_assert (b
->owner
->type
!= bp_none
);
2520 old_chain
= save_current_space_and_thread ();
2522 switch_to_program_space_and_thread (b
->pspace
);
2524 ret
= remove_breakpoint_1 (b
, is
);
2526 do_cleanups (old_chain
);
2530 /* Clear the "inserted" flag in all breakpoints. */
2533 mark_breakpoints_out (void)
2535 struct bp_location
*bpt
, **bptp_tmp
;
2537 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2538 if (bpt
->pspace
== current_program_space
)
2542 /* Clear the "inserted" flag in all breakpoints and delete any
2543 breakpoints which should go away between runs of the program.
2545 Plus other such housekeeping that has to be done for breakpoints
2548 Note: this function gets called at the end of a run (by
2549 generic_mourn_inferior) and when a run begins (by
2550 init_wait_for_inferior). */
2555 breakpoint_init_inferior (enum inf_context context
)
2557 struct breakpoint
*b
, *temp
;
2558 struct bp_location
*bpt
, **bptp_tmp
;
2560 struct program_space
*pspace
= current_program_space
;
2562 /* If breakpoint locations are shared across processes, then there's
2564 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2567 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2569 if (bpt
->pspace
== pspace
2570 && bpt
->owner
->enable_state
!= bp_permanent
)
2574 ALL_BREAKPOINTS_SAFE (b
, temp
)
2576 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2583 /* If the call dummy breakpoint is at the entry point it will
2584 cause problems when the inferior is rerun, so we better get
2587 case bp_watchpoint_scope
:
2589 /* Also get rid of scope breakpoints. */
2591 case bp_shlib_event
:
2593 /* Also remove solib event breakpoints. Their addresses may
2594 have changed since the last time we ran the program.
2595 Actually we may now be debugging against different target;
2596 and so the solib backend that installed this breakpoint may
2597 not be used in by the target. E.g.,
2599 (gdb) file prog-linux
2600 (gdb) run # native linux target
2603 (gdb) file prog-win.exe
2604 (gdb) tar rem :9999 # remote Windows gdbserver.
2607 delete_breakpoint (b
);
2611 case bp_hardware_watchpoint
:
2612 case bp_read_watchpoint
:
2613 case bp_access_watchpoint
:
2615 /* Likewise for watchpoints on local expressions. */
2616 if (b
->exp_valid_block
!= NULL
)
2617 delete_breakpoint (b
);
2618 else if (context
== inf_starting
)
2620 /* Reset val field to force reread of starting value
2621 in insert_breakpoints. */
2623 value_free (b
->val
);
2633 /* Get rid of the moribund locations. */
2634 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2635 free_bp_location (bpt
);
2636 VEC_free (bp_location_p
, moribund_locations
);
2639 /* These functions concern about actual breakpoints inserted in the
2640 target --- to e.g. check if we need to do decr_pc adjustment or if
2641 we need to hop over the bkpt --- so we check for address space
2642 match, not program space. */
2644 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2645 exists at PC. It returns ordinary_breakpoint_here if it's an
2646 ordinary breakpoint, or permanent_breakpoint_here if it's a
2647 permanent breakpoint.
2648 - When continuing from a location with an ordinary breakpoint, we
2649 actually single step once before calling insert_breakpoints.
2650 - When continuing from a localion with a permanent breakpoint, we
2651 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2652 the target, to advance the PC past the breakpoint. */
2654 enum breakpoint_here
2655 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2657 struct bp_location
*bpt
, **bptp_tmp
;
2658 int any_breakpoint_here
= 0;
2660 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2662 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2663 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2666 if ((breakpoint_enabled (bpt
->owner
)
2667 || bpt
->owner
->enable_state
== bp_permanent
)
2668 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2671 if (overlay_debugging
2672 && section_is_overlay (bpt
->section
)
2673 && !section_is_mapped (bpt
->section
))
2674 continue; /* unmapped overlay -- can't be a match */
2675 else if (bpt
->owner
->enable_state
== bp_permanent
)
2676 return permanent_breakpoint_here
;
2678 any_breakpoint_here
= 1;
2682 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2685 /* Return true if there's a moribund breakpoint at PC. */
2688 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2690 struct bp_location
*loc
;
2693 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2694 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2701 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2702 inserted using regular breakpoint_chain / bp_location array mechanism.
2703 This does not check for single-step breakpoints, which are
2704 inserted and removed using direct target manipulation. */
2707 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2709 struct bp_location
*bpt
, **bptp_tmp
;
2711 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2713 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2714 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2718 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2721 if (overlay_debugging
2722 && section_is_overlay (bpt
->section
)
2723 && !section_is_mapped (bpt
->section
))
2724 continue; /* unmapped overlay -- can't be a match */
2732 /* Returns non-zero iff there's either regular breakpoint
2733 or a single step breakpoint inserted at PC. */
2736 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2738 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2741 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2747 /* This function returns non-zero iff there is a software breakpoint
2751 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2753 struct bp_location
*bpt
, **bptp_tmp
;
2754 int any_breakpoint_here
= 0;
2756 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2758 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2762 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2765 if (overlay_debugging
2766 && section_is_overlay (bpt
->section
)
2767 && !section_is_mapped (bpt
->section
))
2768 continue; /* unmapped overlay -- can't be a match */
2774 /* Also check for software single-step breakpoints. */
2775 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2782 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2783 CORE_ADDR addr
, ULONGEST len
)
2785 struct breakpoint
*bpt
;
2787 ALL_BREAKPOINTS (bpt
)
2789 struct bp_location
*loc
;
2791 if (bpt
->type
!= bp_hardware_watchpoint
2792 && bpt
->type
!= bp_access_watchpoint
)
2795 if (!breakpoint_enabled (bpt
))
2798 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2799 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2803 /* Check for intersection. */
2804 l
= max (loc
->address
, addr
);
2805 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2813 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2814 PC is valid for process/thread PTID. */
2817 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2820 struct bp_location
*bpt
, **bptp_tmp
;
2821 /* The thread and task IDs associated to PTID, computed lazily. */
2825 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2827 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2828 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2831 if (!breakpoint_enabled (bpt
->owner
)
2832 && bpt
->owner
->enable_state
!= bp_permanent
)
2835 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2839 if (bpt
->owner
->thread
!= -1)
2841 /* This is a thread-specific breakpoint. Check that ptid
2842 matches that thread. If thread hasn't been computed yet,
2843 it is now time to do so. */
2845 thread
= pid_to_thread_id (ptid
);
2846 if (bpt
->owner
->thread
!= thread
)
2850 if (bpt
->owner
->task
!= 0)
2852 /* This is a task-specific breakpoint. Check that ptid
2853 matches that task. If task hasn't been computed yet,
2854 it is now time to do so. */
2856 task
= ada_get_task_number (ptid
);
2857 if (bpt
->owner
->task
!= task
)
2861 if (overlay_debugging
2862 && section_is_overlay (bpt
->section
)
2863 && !section_is_mapped (bpt
->section
))
2864 continue; /* unmapped overlay -- can't be a match */
2873 /* bpstat stuff. External routines' interfaces are documented
2877 ep_is_catchpoint (struct breakpoint
*ep
)
2879 return (ep
->type
== bp_catchpoint
);
2883 bpstat_free (bpstat bs
)
2885 if (bs
->old_val
!= NULL
)
2886 value_free (bs
->old_val
);
2887 decref_counted_command_line (&bs
->commands
);
2891 /* Clear a bpstat so that it says we are not at any breakpoint.
2892 Also free any storage that is part of a bpstat. */
2895 bpstat_clear (bpstat
*bsp
)
2912 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2913 is part of the bpstat is copied as well. */
2916 bpstat_copy (bpstat bs
)
2920 bpstat retval
= NULL
;
2925 for (; bs
!= NULL
; bs
= bs
->next
)
2927 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2928 memcpy (tmp
, bs
, sizeof (*tmp
));
2929 incref_counted_command_line (tmp
->commands
);
2930 if (bs
->old_val
!= NULL
)
2932 tmp
->old_val
= value_copy (bs
->old_val
);
2933 release_value (tmp
->old_val
);
2937 /* This is the first thing in the chain. */
2947 /* Find the bpstat associated with this breakpoint */
2950 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2955 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2957 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2963 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2964 at. *BSP upon return is a bpstat which points to the remaining
2965 breakpoints stopped at (but which is not guaranteed to be good for
2966 anything but further calls to bpstat_num).
2967 Return 0 if passed a bpstat which does not indicate any breakpoints.
2968 Return -1 if stopped at a breakpoint that has been deleted since
2970 Return 1 otherwise. */
2973 bpstat_num (bpstat
*bsp
, int *num
)
2975 struct breakpoint
*b
;
2978 return 0; /* No more breakpoint values */
2980 /* We assume we'll never have several bpstats that
2981 correspond to a single breakpoint -- otherwise,
2982 this function might return the same number more
2983 than once and this will look ugly. */
2984 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2985 *bsp
= (*bsp
)->next
;
2987 return -1; /* breakpoint that's been deleted since */
2989 *num
= b
->number
; /* We have its number */
2993 /* Modify BS so that the actions will not be performed. */
2996 bpstat_clear_actions (bpstat bs
)
2998 for (; bs
!= NULL
; bs
= bs
->next
)
3000 decref_counted_command_line (&bs
->commands
);
3001 bs
->commands_left
= NULL
;
3002 if (bs
->old_val
!= NULL
)
3004 value_free (bs
->old_val
);
3010 /* Called when a command is about to proceed the inferior. */
3013 breakpoint_about_to_proceed (void)
3015 if (!ptid_equal (inferior_ptid
, null_ptid
))
3017 struct thread_info
*tp
= inferior_thread ();
3019 /* Allow inferior function calls in breakpoint commands to not
3020 interrupt the command list. When the call finishes
3021 successfully, the inferior will be standing at the same
3022 breakpoint as if nothing happened. */
3027 breakpoint_proceeded
= 1;
3030 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3032 cleanup_executing_breakpoints (void *ignore
)
3034 executing_breakpoint_commands
= 0;
3037 /* Execute all the commands associated with all the breakpoints at this
3038 location. Any of these commands could cause the process to proceed
3039 beyond this point, etc. We look out for such changes by checking
3040 the global "breakpoint_proceeded" after each command.
3042 Returns true if a breakpoint command resumed the inferior. In that
3043 case, it is the caller's responsibility to recall it again with the
3044 bpstat of the current thread. */
3047 bpstat_do_actions_1 (bpstat
*bsp
)
3050 struct cleanup
*old_chain
;
3053 /* Avoid endless recursion if a `source' command is contained
3055 if (executing_breakpoint_commands
)
3058 executing_breakpoint_commands
= 1;
3059 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3061 /* This pointer will iterate over the list of bpstat's. */
3064 breakpoint_proceeded
= 0;
3065 for (; bs
!= NULL
; bs
= bs
->next
)
3067 struct counted_command_line
*ccmd
;
3068 struct command_line
*cmd
;
3069 struct cleanup
*this_cmd_tree_chain
;
3071 /* Take ownership of the BSP's command tree, if it has one.
3073 The command tree could legitimately contain commands like
3074 'step' and 'next', which call clear_proceed_status, which
3075 frees stop_bpstat's command tree. To make sure this doesn't
3076 free the tree we're executing out from under us, we need to
3077 take ownership of the tree ourselves. Since a given bpstat's
3078 commands are only executed once, we don't need to copy it; we
3079 can clear the pointer in the bpstat, and make sure we free
3080 the tree when we're done. */
3081 ccmd
= bs
->commands
;
3082 bs
->commands
= NULL
;
3084 = make_cleanup_decref_counted_command_line (&ccmd
);
3085 cmd
= bs
->commands_left
;
3086 bs
->commands_left
= NULL
;
3090 execute_control_command (cmd
);
3092 if (breakpoint_proceeded
)
3098 /* We can free this command tree now. */
3099 do_cleanups (this_cmd_tree_chain
);
3101 if (breakpoint_proceeded
)
3103 if (target_can_async_p ())
3104 /* If we are in async mode, then the target might be still
3105 running, not stopped at any breakpoint, so nothing for
3106 us to do here -- just return to the event loop. */
3109 /* In sync mode, when execute_control_command returns
3110 we're already standing on the next breakpoint.
3111 Breakpoint commands for that stop were not run, since
3112 execute_command does not run breakpoint commands --
3113 only command_line_handler does, but that one is not
3114 involved in execution of breakpoint commands. So, we
3115 can now execute breakpoint commands. It should be
3116 noted that making execute_command do bpstat actions is
3117 not an option -- in this case we'll have recursive
3118 invocation of bpstat for each breakpoint with a
3119 command, and can easily blow up GDB stack. Instead, we
3120 return true, which will trigger the caller to recall us
3121 with the new stop_bpstat. */
3126 do_cleanups (old_chain
);
3131 bpstat_do_actions (void)
3133 /* Do any commands attached to breakpoint we are stopped at. */
3134 while (!ptid_equal (inferior_ptid
, null_ptid
)
3135 && target_has_execution
3136 && !is_exited (inferior_ptid
)
3137 && !is_executing (inferior_ptid
))
3138 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3139 and only return when it is stopped at the next breakpoint, we
3140 keep doing breakpoint actions until it returns false to
3141 indicate the inferior was not resumed. */
3142 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3146 /* Print out the (old or new) value associated with a watchpoint. */
3149 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3152 fprintf_unfiltered (stream
, _("<unreadable>"));
3155 struct value_print_options opts
;
3156 get_user_print_options (&opts
);
3157 value_print (val
, stream
, &opts
);
3161 /* This is the normal print function for a bpstat. In the future,
3162 much of this logic could (should?) be moved to bpstat_stop_status,
3163 by having it set different print_it values.
3165 Current scheme: When we stop, bpstat_print() is called. It loops
3166 through the bpstat list of things causing this stop, calling the
3167 print_bp_stop_message function on each one. The behavior of the
3168 print_bp_stop_message function depends on the print_it field of
3169 bpstat. If such field so indicates, call this function here.
3171 Return values from this routine (ultimately used by bpstat_print()
3172 and normal_stop() to decide what to do):
3173 PRINT_NOTHING: Means we already printed all we needed to print,
3174 don't print anything else.
3175 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3176 that something to be followed by a location.
3177 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3178 that something to be followed by a location.
3179 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3182 static enum print_stop_action
3183 print_it_typical (bpstat bs
)
3185 struct cleanup
*old_chain
;
3186 struct breakpoint
*b
;
3187 const struct bp_location
*bl
;
3188 struct ui_stream
*stb
;
3190 enum print_stop_action result
;
3192 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3193 which has since been deleted. */
3194 if (bs
->breakpoint_at
== NULL
)
3195 return PRINT_UNKNOWN
;
3196 bl
= bs
->breakpoint_at
;
3199 stb
= ui_out_stream_new (uiout
);
3200 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3205 case bp_hardware_breakpoint
:
3206 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3207 if (bl
->address
!= bl
->requested_address
)
3208 breakpoint_adjustment_warning (bl
->requested_address
,
3211 annotate_breakpoint (b
->number
);
3213 ui_out_text (uiout
, "\nTemporary breakpoint ");
3215 ui_out_text (uiout
, "\nBreakpoint ");
3216 if (ui_out_is_mi_like_p (uiout
))
3218 ui_out_field_string (uiout
, "reason",
3219 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3220 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3222 ui_out_field_int (uiout
, "bkptno", b
->number
);
3223 ui_out_text (uiout
, ", ");
3224 result
= PRINT_SRC_AND_LOC
;
3227 case bp_shlib_event
:
3228 /* Did we stop because the user set the stop_on_solib_events
3229 variable? (If so, we report this as a generic, "Stopped due
3230 to shlib event" message.) */
3231 printf_filtered (_("Stopped due to shared library event\n"));
3232 result
= PRINT_NOTHING
;
3235 case bp_thread_event
:
3236 /* Not sure how we will get here.
3237 GDB should not stop for these breakpoints. */
3238 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3239 result
= PRINT_NOTHING
;
3242 case bp_overlay_event
:
3243 /* By analogy with the thread event, GDB should not stop for these. */
3244 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3245 result
= PRINT_NOTHING
;
3248 case bp_longjmp_master
:
3249 /* These should never be enabled. */
3250 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3251 result
= PRINT_NOTHING
;
3254 case bp_std_terminate_master
:
3255 /* These should never be enabled. */
3256 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3257 result
= PRINT_NOTHING
;
3261 case bp_hardware_watchpoint
:
3262 annotate_watchpoint (b
->number
);
3263 if (ui_out_is_mi_like_p (uiout
))
3266 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3268 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3269 ui_out_text (uiout
, "\nOld value = ");
3270 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3271 ui_out_field_stream (uiout
, "old", stb
);
3272 ui_out_text (uiout
, "\nNew value = ");
3273 watchpoint_value_print (b
->val
, stb
->stream
);
3274 ui_out_field_stream (uiout
, "new", stb
);
3275 ui_out_text (uiout
, "\n");
3276 /* More than one watchpoint may have been triggered. */
3277 result
= PRINT_UNKNOWN
;
3280 case bp_read_watchpoint
:
3281 if (ui_out_is_mi_like_p (uiout
))
3284 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3286 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3287 ui_out_text (uiout
, "\nValue = ");
3288 watchpoint_value_print (b
->val
, stb
->stream
);
3289 ui_out_field_stream (uiout
, "value", stb
);
3290 ui_out_text (uiout
, "\n");
3291 result
= PRINT_UNKNOWN
;
3294 case bp_access_watchpoint
:
3295 if (bs
->old_val
!= NULL
)
3297 annotate_watchpoint (b
->number
);
3298 if (ui_out_is_mi_like_p (uiout
))
3301 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3303 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3304 ui_out_text (uiout
, "\nOld value = ");
3305 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3306 ui_out_field_stream (uiout
, "old", stb
);
3307 ui_out_text (uiout
, "\nNew value = ");
3312 if (ui_out_is_mi_like_p (uiout
))
3315 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3316 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3317 ui_out_text (uiout
, "\nValue = ");
3319 watchpoint_value_print (b
->val
, stb
->stream
);
3320 ui_out_field_stream (uiout
, "new", stb
);
3321 ui_out_text (uiout
, "\n");
3322 result
= PRINT_UNKNOWN
;
3325 /* Fall through, we don't deal with these types of breakpoints
3329 if (ui_out_is_mi_like_p (uiout
))
3332 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3333 result
= PRINT_UNKNOWN
;
3337 if (ui_out_is_mi_like_p (uiout
))
3340 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3341 result
= PRINT_UNKNOWN
;
3346 case bp_longjmp_resume
:
3347 case bp_step_resume
:
3348 case bp_watchpoint_scope
:
3350 case bp_std_terminate
:
3352 case bp_fast_tracepoint
:
3355 result
= PRINT_UNKNOWN
;
3359 do_cleanups (old_chain
);
3363 /* Generic routine for printing messages indicating why we
3364 stopped. The behavior of this function depends on the value
3365 'print_it' in the bpstat structure. Under some circumstances we
3366 may decide not to print anything here and delegate the task to
3369 static enum print_stop_action
3370 print_bp_stop_message (bpstat bs
)
3372 switch (bs
->print_it
)
3375 /* Nothing should be printed for this bpstat entry. */
3376 return PRINT_UNKNOWN
;
3380 /* We still want to print the frame, but we already printed the
3381 relevant messages. */
3382 return PRINT_SRC_AND_LOC
;
3385 case print_it_normal
:
3387 const struct bp_location
*bl
= bs
->breakpoint_at
;
3388 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3390 /* Normal case. Call the breakpoint's print_it method, or
3391 print_it_typical. */
3392 /* FIXME: how breakpoint can ever be NULL here? */
3393 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3394 return b
->ops
->print_it (b
);
3396 return print_it_typical (bs
);
3401 internal_error (__FILE__
, __LINE__
,
3402 _("print_bp_stop_message: unrecognized enum value"));
3407 /* Print a message indicating what happened. This is called from
3408 normal_stop(). The input to this routine is the head of the bpstat
3409 list - a list of the eventpoints that caused this stop. This
3410 routine calls the generic print routine for printing a message
3411 about reasons for stopping. This will print (for example) the
3412 "Breakpoint n," part of the output. The return value of this
3415 PRINT_UNKNOWN: Means we printed nothing
3416 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3417 code to print the location. An example is
3418 "Breakpoint 1, " which should be followed by
3420 PRINT_SRC_ONLY: Means we printed something, but there is no need
3421 to also print the location part of the message.
3422 An example is the catch/throw messages, which
3423 don't require a location appended to the end.
3424 PRINT_NOTHING: We have done some printing and we don't need any
3425 further info to be printed.*/
3427 enum print_stop_action
3428 bpstat_print (bpstat bs
)
3432 /* Maybe another breakpoint in the chain caused us to stop.
3433 (Currently all watchpoints go on the bpstat whether hit or not.
3434 That probably could (should) be changed, provided care is taken
3435 with respect to bpstat_explains_signal). */
3436 for (; bs
; bs
= bs
->next
)
3438 val
= print_bp_stop_message (bs
);
3439 if (val
== PRINT_SRC_ONLY
3440 || val
== PRINT_SRC_AND_LOC
3441 || val
== PRINT_NOTHING
)
3445 /* We reached the end of the chain, or we got a null BS to start
3446 with and nothing was printed. */
3447 return PRINT_UNKNOWN
;
3450 /* Evaluate the expression EXP and return 1 if value is zero.
3451 This is used inside a catch_errors to evaluate the breakpoint condition.
3452 The argument is a "struct expression *" that has been cast to char * to
3453 make it pass through catch_errors. */
3456 breakpoint_cond_eval (void *exp
)
3458 struct value
*mark
= value_mark ();
3459 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3460 value_free_to_mark (mark
);
3464 /* Allocate a new bpstat and chain it to the current one. */
3467 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3471 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3473 bs
->breakpoint_at
= bl
;
3474 /* If the condition is false, etc., don't do the commands. */
3475 bs
->commands
= NULL
;
3476 bs
->commands_left
= NULL
;
3478 bs
->print_it
= print_it_normal
;
3482 /* The target has stopped with waitstatus WS. Check if any hardware
3483 watchpoints have triggered, according to the target. */
3486 watchpoints_triggered (struct target_waitstatus
*ws
)
3488 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3490 struct breakpoint
*b
;
3492 if (!stopped_by_watchpoint
)
3494 /* We were not stopped by a watchpoint. Mark all watchpoints
3495 as not triggered. */
3497 if (is_hardware_watchpoint (b
))
3498 b
->watchpoint_triggered
= watch_triggered_no
;
3503 if (!target_stopped_data_address (¤t_target
, &addr
))
3505 /* We were stopped by a watchpoint, but we don't know where.
3506 Mark all watchpoints as unknown. */
3508 if (is_hardware_watchpoint (b
))
3509 b
->watchpoint_triggered
= watch_triggered_unknown
;
3511 return stopped_by_watchpoint
;
3514 /* The target could report the data address. Mark watchpoints
3515 affected by this data address as triggered, and all others as not
3519 if (is_hardware_watchpoint (b
))
3521 struct bp_location
*loc
;
3524 b
->watchpoint_triggered
= watch_triggered_no
;
3525 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3526 /* Exact match not required. Within range is
3528 if (target_watchpoint_addr_within_range (¤t_target
,
3532 b
->watchpoint_triggered
= watch_triggered_yes
;
3540 /* Possible return values for watchpoint_check (this can't be an enum
3541 because of check_errors). */
3542 /* The watchpoint has been deleted. */
3543 #define WP_DELETED 1
3544 /* The value has changed. */
3545 #define WP_VALUE_CHANGED 2
3546 /* The value has not changed. */
3547 #define WP_VALUE_NOT_CHANGED 3
3548 /* Ignore this watchpoint, no matter if the value changed or not. */
3551 #define BP_TEMPFLAG 1
3552 #define BP_HARDWAREFLAG 2
3554 /* Evaluate watchpoint condition expression and check if its value changed.
3556 P should be a pointer to struct bpstat, but is defined as a void *
3557 in order for this function to be usable with catch_errors. */
3560 watchpoint_check (void *p
)
3562 bpstat bs
= (bpstat
) p
;
3563 struct breakpoint
*b
;
3564 struct frame_info
*fr
;
3565 int within_current_scope
;
3567 b
= bs
->breakpoint_at
->owner
;
3569 /* If this is a local watchpoint, we only want to check if the
3570 watchpoint frame is in scope if the current thread is the thread
3571 that was used to create the watchpoint. */
3572 if (!watchpoint_in_thread_scope (b
))
3575 if (b
->exp_valid_block
== NULL
)
3576 within_current_scope
= 1;
3579 struct frame_info
*frame
= get_current_frame ();
3580 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3581 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3583 /* in_function_epilogue_p() returns a non-zero value if we're still
3584 in the function but the stack frame has already been invalidated.
3585 Since we can't rely on the values of local variables after the
3586 stack has been destroyed, we are treating the watchpoint in that
3587 state as `not changed' without further checking. Don't mark
3588 watchpoints as changed if the current frame is in an epilogue -
3589 even if they are in some other frame, our view of the stack
3590 is likely to be wrong and frame_find_by_id could error out. */
3591 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3594 fr
= frame_find_by_id (b
->watchpoint_frame
);
3595 within_current_scope
= (fr
!= NULL
);
3597 /* If we've gotten confused in the unwinder, we might have
3598 returned a frame that can't describe this variable. */
3599 if (within_current_scope
)
3601 struct symbol
*function
;
3603 function
= get_frame_function (fr
);
3604 if (function
== NULL
3605 || !contained_in (b
->exp_valid_block
,
3606 SYMBOL_BLOCK_VALUE (function
)))
3607 within_current_scope
= 0;
3610 if (within_current_scope
)
3611 /* If we end up stopping, the current frame will get selected
3612 in normal_stop. So this call to select_frame won't affect
3617 if (within_current_scope
)
3619 /* We use value_{,free_to_}mark because it could be a
3620 *long* time before we return to the command level and
3621 call free_all_values. We can't call free_all_values because
3622 we might be in the middle of evaluating a function call. */
3624 struct value
*mark
= value_mark ();
3625 struct value
*new_val
;
3627 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3629 /* We use value_equal_contents instead of value_equal because the latter
3630 coerces an array to a pointer, thus comparing just the address of the
3631 array instead of its contents. This is not what we want. */
3632 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3633 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3635 if (new_val
!= NULL
)
3637 release_value (new_val
);
3638 value_free_to_mark (mark
);
3640 bs
->old_val
= b
->val
;
3643 return WP_VALUE_CHANGED
;
3647 /* Nothing changed. */
3648 value_free_to_mark (mark
);
3649 return WP_VALUE_NOT_CHANGED
;
3654 /* This seems like the only logical thing to do because
3655 if we temporarily ignored the watchpoint, then when
3656 we reenter the block in which it is valid it contains
3657 garbage (in the case of a function, it may have two
3658 garbage values, one before and one after the prologue).
3659 So we can't even detect the first assignment to it and
3660 watch after that (since the garbage may or may not equal
3661 the first value assigned). */
3662 /* We print all the stop information in print_it_typical(), but
3663 in this case, by the time we call print_it_typical() this bp
3664 will be deleted already. So we have no choice but print the
3665 information here. */
3666 if (ui_out_is_mi_like_p (uiout
))
3668 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3669 ui_out_text (uiout
, "\nWatchpoint ");
3670 ui_out_field_int (uiout
, "wpnum", b
->number
);
3671 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3672 which its expression is valid.\n");
3674 if (b
->related_breakpoint
)
3676 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3677 b
->related_breakpoint
->related_breakpoint
= NULL
;
3678 b
->related_breakpoint
= NULL
;
3680 b
->disposition
= disp_del_at_next_stop
;
3686 /* Return true if it looks like target has stopped due to hitting
3687 breakpoint location BL. This function does not check if we
3688 should stop, only if BL explains the stop. */
3690 bpstat_check_location (const struct bp_location
*bl
,
3691 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3693 struct breakpoint
*b
= bl
->owner
;
3695 /* By definition, the inferior does not report stops at
3697 if (is_tracepoint (b
))
3700 if (!is_watchpoint (b
)
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 (is_hardware_watchpoint (b
)
3721 && b
->watchpoint_triggered
== watch_triggered_no
)
3724 if (b
->type
== bp_hardware_breakpoint
)
3726 if (bl
->address
!= bp_addr
)
3728 if (overlay_debugging
/* unmapped overlay section */
3729 && section_is_overlay (bl
->section
)
3730 && !section_is_mapped (bl
->section
))
3734 if (b
->type
== bp_catchpoint
)
3736 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3737 if (!b
->ops
->breakpoint_hit (b
))
3744 /* If BS refers to a watchpoint, determine if the watched values
3745 has actually changed, and we should stop. If not, set BS->stop
3748 bpstat_check_watchpoint (bpstat bs
)
3750 const struct bp_location
*bl
= bs
->breakpoint_at
;
3751 struct breakpoint
*b
= bl
->owner
;
3753 if (is_watchpoint (b
))
3757 int must_check_value
= 0;
3759 if (b
->type
== bp_watchpoint
)
3760 /* For a software watchpoint, we must always check the
3762 must_check_value
= 1;
3763 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3764 /* We have a hardware watchpoint (read, write, or access)
3765 and the target earlier reported an address watched by
3767 must_check_value
= 1;
3768 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3769 && b
->type
== bp_hardware_watchpoint
)
3770 /* We were stopped by a hardware watchpoint, but the target could
3771 not report the data address. We must check the watchpoint's
3772 value. Access and read watchpoints are out of luck; without
3773 a data address, we can't figure it out. */
3774 must_check_value
= 1;
3776 if (must_check_value
)
3778 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3780 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3781 int e
= catch_errors (watchpoint_check
, bs
, message
,
3783 do_cleanups (cleanups
);
3787 /* We've already printed what needs to be printed. */
3788 bs
->print_it
= print_it_done
;
3792 bs
->print_it
= print_it_noop
;
3795 case WP_VALUE_CHANGED
:
3796 if (b
->type
== bp_read_watchpoint
)
3798 /* There are two cases to consider here:
3800 1. we're watching the triggered memory for reads.
3801 In that case, trust the target, and always report
3802 the watchpoint hit to the user. Even though
3803 reads don't cause value changes, the value may
3804 have changed since the last time it was read, and
3805 since we're not trapping writes, we will not see
3806 those, and as such we should ignore our notion of
3809 2. we're watching the triggered memory for both
3810 reads and writes. There are two ways this may
3813 2.1. this is a target that can't break on data
3814 reads only, but can break on accesses (reads or
3815 writes), such as e.g., x86. We detect this case
3816 at the time we try to insert read watchpoints.
3818 2.2. otherwise, the target supports read
3819 watchpoints, but, the user set an access or write
3820 watchpoint watching the same memory as this read
3823 If we're watching memory writes as well as reads,
3824 ignore watchpoint hits when we find that the
3825 value hasn't changed, as reads don't cause
3826 changes. This still gives false positives when
3827 the program writes the same value to memory as
3828 what there was already in memory (we will confuse
3829 it for a read), but it's much better than
3832 int other_write_watchpoint
= 0;
3834 if (bl
->watchpoint_type
== hw_read
)
3836 struct breakpoint
*other_b
;
3838 ALL_BREAKPOINTS (other_b
)
3839 if ((other_b
->type
== bp_hardware_watchpoint
3840 || other_b
->type
== bp_access_watchpoint
)
3841 && (other_b
->watchpoint_triggered
3842 == watch_triggered_yes
))
3844 other_write_watchpoint
= 1;
3849 if (other_write_watchpoint
3850 || bl
->watchpoint_type
== hw_access
)
3852 /* We're watching the same memory for writes,
3853 and the value changed since the last time we
3854 updated it, so this trap must be for a write.
3856 bs
->print_it
= print_it_noop
;
3861 case WP_VALUE_NOT_CHANGED
:
3862 if (b
->type
== bp_hardware_watchpoint
3863 || b
->type
== bp_watchpoint
)
3865 /* Don't stop: write watchpoints shouldn't fire if
3866 the value hasn't changed. */
3867 bs
->print_it
= print_it_noop
;
3875 /* Error from catch_errors. */
3876 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3877 if (b
->related_breakpoint
)
3878 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3879 b
->disposition
= disp_del_at_next_stop
;
3880 /* We've already printed what needs to be printed. */
3881 bs
->print_it
= print_it_done
;
3885 else /* must_check_value == 0 */
3887 /* This is a case where some watchpoint(s) triggered, but
3888 not at the address of this watchpoint, or else no
3889 watchpoint triggered after all. So don't print
3890 anything for this watchpoint. */
3891 bs
->print_it
= print_it_noop
;
3898 /* Check conditions (condition proper, frame, thread and ignore count)
3899 of breakpoint referred to by BS. If we should not stop for this
3900 breakpoint, set BS->stop to 0. */
3902 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3904 int thread_id
= pid_to_thread_id (ptid
);
3905 const struct bp_location
*bl
= bs
->breakpoint_at
;
3906 struct breakpoint
*b
= bl
->owner
;
3908 if (frame_id_p (b
->frame_id
)
3909 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3913 int value_is_zero
= 0;
3914 struct expression
*cond
;
3916 /* If this is a scope breakpoint, mark the associated
3917 watchpoint as triggered so that we will handle the
3918 out-of-scope event. We'll get to the watchpoint next
3920 if (b
->type
== bp_watchpoint_scope
)
3921 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3923 if (is_watchpoint (b
))
3928 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3930 int within_current_scope
= 1;
3932 /* We use value_mark and value_free_to_mark because it could
3933 be a long time before we return to the command level and
3934 call free_all_values. We can't call free_all_values
3935 because we might be in the middle of evaluating a
3937 struct value
*mark
= value_mark ();
3939 /* Need to select the frame, with all that implies so that
3940 the conditions will have the right context. Because we
3941 use the frame, we will not see an inlined function's
3942 variables when we arrive at a breakpoint at the start
3943 of the inlined function; the current frame will be the
3945 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3946 select_frame (get_current_frame ());
3949 struct frame_info
*frame
;
3951 /* For local watchpoint expressions, which particular
3952 instance of a local is being watched matters, so we
3953 keep track of the frame to evaluate the expression
3954 in. To evaluate the condition however, it doesn't
3955 really matter which instantiation of the function
3956 where the condition makes sense triggers the
3957 watchpoint. This allows an expression like "watch
3958 global if q > 10" set in `func', catch writes to
3959 global on all threads that call `func', or catch
3960 writes on all recursive calls of `func' by a single
3961 thread. We simply always evaluate the condition in
3962 the innermost frame that's executing where it makes
3963 sense to evaluate the condition. It seems
3965 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3967 select_frame (frame
);
3969 within_current_scope
= 0;
3971 if (within_current_scope
)
3973 = catch_errors (breakpoint_cond_eval
, cond
,
3974 "Error in testing breakpoint condition:\n",
3978 warning (_("Watchpoint condition cannot be tested "
3979 "in the current scope"));
3980 /* If we failed to set the right context for this
3981 watchpoint, unconditionally report it. */
3984 /* FIXME-someday, should give breakpoint # */
3985 value_free_to_mark (mark
);
3988 if (cond
&& value_is_zero
)
3992 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3996 else if (b
->ignore_count
> 0)
3999 annotate_ignore_count_change ();
4001 /* Increase the hit count even though we don't
4009 /* Get a bpstat associated with having just stopped at address
4010 BP_ADDR in thread PTID.
4012 Determine whether we stopped at a breakpoint, etc, or whether we
4013 don't understand this stop. Result is a chain of bpstat's such that:
4015 if we don't understand the stop, the result is a null pointer.
4017 if we understand why we stopped, the result is not null.
4019 Each element of the chain refers to a particular breakpoint or
4020 watchpoint at which we have stopped. (We may have stopped for
4021 several reasons concurrently.)
4023 Each element of the chain has valid next, breakpoint_at,
4024 commands, FIXME??? fields. */
4027 bpstat_stop_status (struct address_space
*aspace
,
4028 CORE_ADDR bp_addr
, ptid_t ptid
)
4030 struct breakpoint
*b
= NULL
;
4031 struct bp_location
*bl
, **blp_tmp
;
4032 struct bp_location
*loc
;
4033 /* Root of the chain of bpstat's */
4034 struct bpstats root_bs
[1];
4035 /* Pointer to the last thing in the chain currently. */
4036 bpstat bs
= root_bs
;
4038 int need_remove_insert
;
4040 /* ALL_BP_LOCATIONS iteration would break across
4041 update_global_location_list possibly executed by
4042 bpstat_check_breakpoint_conditions's inferior call. */
4046 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4049 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4051 /* For hardware watchpoints, we look only at the first location.
4052 The watchpoint_check function will work on the entire expression,
4053 not the individual locations. For read watchpoints, the
4054 watchpoints_triggered function has checked all locations
4056 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4059 if (bl
->shlib_disabled
)
4062 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4065 /* Come here if it's a watchpoint, or if the break address matches */
4067 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4069 /* Assume we stop. Should we find watchpoint that is not actually
4070 triggered, or if condition of breakpoint is false, we'll reset
4075 bpstat_check_watchpoint (bs
);
4079 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4080 || b
->type
== bp_longjmp_master
4081 || b
->type
== bp_std_terminate_master
)
4082 /* We do not stop for these. */
4085 bpstat_check_breakpoint_conditions (bs
, ptid
);
4091 /* We will stop here */
4092 if (b
->disposition
== disp_disable
)
4094 if (b
->enable_state
!= bp_permanent
)
4095 b
->enable_state
= bp_disabled
;
4096 update_global_location_list (0);
4100 bs
->commands
= b
->commands
;
4101 incref_counted_command_line (bs
->commands
);
4102 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4103 if (bs
->commands_left
4104 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4107 bs
->commands_left
->line
) == 0)))
4109 bs
->commands_left
= bs
->commands_left
->next
;
4114 /* Print nothing for this entry if we dont stop or dont print. */
4115 if (bs
->stop
== 0 || bs
->print
== 0)
4116 bs
->print_it
= print_it_noop
;
4120 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4122 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4125 bs
= bpstat_alloc (loc
, bs
);
4126 /* For hits of moribund locations, we should just proceed. */
4129 bs
->print_it
= print_it_noop
;
4133 bs
->next
= NULL
; /* Terminate the chain */
4135 /* If we aren't stopping, the value of some hardware watchpoint may
4136 not have changed, but the intermediate memory locations we are
4137 watching may have. Don't bother if we're stopping; this will get
4139 need_remove_insert
= 0;
4140 if (! bpstat_causes_stop (root_bs
->next
))
4141 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4143 && bs
->breakpoint_at
->owner
4144 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4146 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4147 /* Updating watchpoints invalidates bs->breakpoint_at.
4148 Prevent further code from trying to use it. */
4149 bs
->breakpoint_at
= NULL
;
4150 need_remove_insert
= 1;
4153 if (need_remove_insert
)
4154 update_global_location_list (1);
4156 return root_bs
->next
;
4159 /* Tell what to do about this bpstat. */
4161 bpstat_what (bpstat bs
)
4163 /* Classify each bpstat as one of the following. */
4166 /* This bpstat element has no effect on the main_action. */
4169 /* There was a watchpoint, stop but don't print. */
4172 /* There was a watchpoint, stop and print. */
4175 /* There was a breakpoint but we're not stopping. */
4178 /* There was a breakpoint, stop but don't print. */
4181 /* There was a breakpoint, stop and print. */
4184 /* We hit the longjmp breakpoint. */
4187 /* We hit the longjmp_resume breakpoint. */
4190 /* We hit the step_resume breakpoint. */
4193 /* We hit the shared library event breakpoint. */
4196 /* We hit the jit event breakpoint. */
4199 /* This is just used to count how many enums there are. */
4203 /* Here is the table which drives this routine. So that we can
4204 format it pretty, we define some abbreviations for the
4205 enum bpstat_what codes. */
4206 #define kc BPSTAT_WHAT_KEEP_CHECKING
4207 #define ss BPSTAT_WHAT_STOP_SILENT
4208 #define sn BPSTAT_WHAT_STOP_NOISY
4209 #define sgl BPSTAT_WHAT_SINGLE
4210 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4211 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4212 #define sr BPSTAT_WHAT_STEP_RESUME
4213 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4214 #define jit BPSTAT_WHAT_CHECK_JIT
4216 /* "Can't happen." Might want to print an error message.
4217 abort() is not out of the question, but chances are GDB is just
4218 a bit confused, not unusable. */
4219 #define err BPSTAT_WHAT_STOP_NOISY
4221 /* Given an old action and a class, come up with a new action. */
4222 /* One interesting property of this table is that wp_silent is the same
4223 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4224 after stopping, the check for whether to step over a breakpoint
4225 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4226 reference to how we stopped. We retain separate wp_silent and
4227 bp_silent codes in case we want to change that someday.
4229 Another possibly interesting property of this table is that
4230 there's a partial ordering, priority-like, of the actions. Once
4231 you've decided that some action is appropriate, you'll never go
4232 back and decide something of a lower priority is better. The
4235 kc < jit clr sgl shl slr sn sr ss
4236 sgl < jit shl slr sn sr ss
4237 slr < jit err shl sn sr ss
4238 clr < jit err shl sn sr ss
4245 What I think this means is that we don't need a damned table
4246 here. If you just put the rows and columns in the right order,
4247 it'd look awfully regular. We could simply walk the bpstat list
4248 and choose the highest priority action we find, with a little
4249 logic to handle the 'err' cases. */
4251 /* step_resume entries: a step resume breakpoint overrides another
4252 breakpoint of signal handling (see comment in wait_for_inferior
4253 at where we set the step_resume breakpoint). */
4255 static const enum bpstat_what_main_action
4256 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4259 /* kc ss sn sgl slr clr sr shl jit */
4260 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4261 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4262 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4263 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4264 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4265 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4266 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4267 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4268 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4269 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4270 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4284 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4285 struct bpstat_what retval
;
4287 retval
.call_dummy
= STOP_NONE
;
4288 for (; bs
!= NULL
; bs
= bs
->next
)
4290 enum class bs_class
= no_effect
;
4291 if (bs
->breakpoint_at
== NULL
)
4292 /* I suspect this can happen if it was a momentary breakpoint
4293 which has since been deleted. */
4295 if (bs
->breakpoint_at
->owner
== NULL
)
4296 bs_class
= bp_nostop
;
4298 switch (bs
->breakpoint_at
->owner
->type
)
4304 case bp_hardware_breakpoint
:
4310 bs_class
= bp_noisy
;
4312 bs_class
= bp_silent
;
4315 bs_class
= bp_nostop
;
4318 case bp_hardware_watchpoint
:
4319 case bp_read_watchpoint
:
4320 case bp_access_watchpoint
:
4324 bs_class
= wp_noisy
;
4326 bs_class
= wp_silent
;
4329 /* There was a watchpoint, but we're not stopping.
4330 This requires no further action. */
4331 bs_class
= no_effect
;
4334 bs_class
= long_jump
;
4336 case bp_longjmp_resume
:
4337 bs_class
= long_resume
;
4339 case bp_step_resume
:
4342 bs_class
= step_resume
;
4345 /* It is for the wrong frame. */
4346 bs_class
= bp_nostop
;
4348 case bp_watchpoint_scope
:
4349 bs_class
= bp_nostop
;
4351 case bp_shlib_event
:
4352 bs_class
= shlib_event
;
4355 bs_class
= jit_event
;
4357 case bp_thread_event
:
4358 case bp_overlay_event
:
4359 case bp_longjmp_master
:
4360 case bp_std_terminate_master
:
4361 bs_class
= bp_nostop
;
4367 bs_class
= bp_noisy
;
4369 bs_class
= bp_silent
;
4372 /* There was a catchpoint, but we're not stopping.
4373 This requires no further action. */
4374 bs_class
= no_effect
;
4377 /* Make sure the action is stop (silent or noisy),
4378 so infrun.c pops the dummy frame. */
4379 bs_class
= bp_silent
;
4380 retval
.call_dummy
= STOP_STACK_DUMMY
;
4382 case bp_std_terminate
:
4383 /* Make sure the action is stop (silent or noisy),
4384 so infrun.c pops the dummy frame. */
4385 bs_class
= bp_silent
;
4386 retval
.call_dummy
= STOP_STD_TERMINATE
;
4389 case bp_fast_tracepoint
:
4390 /* Tracepoint hits should not be reported back to GDB, and
4391 if one got through somehow, it should have been filtered
4393 internal_error (__FILE__
, __LINE__
,
4394 _("bpstat_what: tracepoint encountered"));
4397 current_action
= table
[(int) bs_class
][(int) current_action
];
4399 retval
.main_action
= current_action
;
4403 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4404 without hardware support). This isn't related to a specific bpstat,
4405 just to things like whether watchpoints are set. */
4408 bpstat_should_step (void)
4410 struct breakpoint
*b
;
4412 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4418 bpstat_causes_stop (bpstat bs
)
4420 for (; bs
!= NULL
; bs
= bs
->next
)
4429 /* Print the LOC location out of the list of B->LOC locations. */
4431 static void print_breakpoint_location (struct breakpoint
*b
,
4432 struct bp_location
*loc
,
4434 struct ui_stream
*stb
)
4436 struct cleanup
*old_chain
= save_current_program_space ();
4438 if (loc
!= NULL
&& loc
->shlib_disabled
)
4442 set_current_program_space (loc
->pspace
);
4444 if (b
->source_file
&& loc
)
4447 = find_pc_sect_function (loc
->address
, loc
->section
);
4450 ui_out_text (uiout
, "in ");
4451 ui_out_field_string (uiout
, "func",
4452 SYMBOL_PRINT_NAME (sym
));
4453 ui_out_wrap_hint (uiout
, wrap_indent
);
4454 ui_out_text (uiout
, " at ");
4456 ui_out_field_string (uiout
, "file", b
->source_file
);
4457 ui_out_text (uiout
, ":");
4459 if (ui_out_is_mi_like_p (uiout
))
4461 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4462 char *fullname
= symtab_to_fullname (sal
.symtab
);
4465 ui_out_field_string (uiout
, "fullname", fullname
);
4468 ui_out_field_int (uiout
, "line", b
->line_number
);
4472 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4474 ui_out_field_stream (uiout
, "at", stb
);
4477 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4479 do_cleanups (old_chain
);
4482 /* Print B to gdb_stdout. */
4484 print_one_breakpoint_location (struct breakpoint
*b
,
4485 struct bp_location
*loc
,
4487 struct bp_location
**last_loc
,
4488 int print_address_bits
,
4491 struct command_line
*l
;
4493 struct ep_type_description
4498 static struct ep_type_description bptypes
[] =
4500 {bp_none
, "?deleted?"},
4501 {bp_breakpoint
, "breakpoint"},
4502 {bp_hardware_breakpoint
, "hw breakpoint"},
4503 {bp_until
, "until"},
4504 {bp_finish
, "finish"},
4505 {bp_watchpoint
, "watchpoint"},
4506 {bp_hardware_watchpoint
, "hw watchpoint"},
4507 {bp_read_watchpoint
, "read watchpoint"},
4508 {bp_access_watchpoint
, "acc watchpoint"},
4509 {bp_longjmp
, "longjmp"},
4510 {bp_longjmp_resume
, "longjmp resume"},
4511 {bp_step_resume
, "step resume"},
4512 {bp_watchpoint_scope
, "watchpoint scope"},
4513 {bp_call_dummy
, "call dummy"},
4514 {bp_std_terminate
, "std::terminate"},
4515 {bp_shlib_event
, "shlib events"},
4516 {bp_thread_event
, "thread events"},
4517 {bp_overlay_event
, "overlay events"},
4518 {bp_longjmp_master
, "longjmp master"},
4519 {bp_std_terminate_master
, "std::terminate master"},
4520 {bp_catchpoint
, "catchpoint"},
4521 {bp_tracepoint
, "tracepoint"},
4522 {bp_fast_tracepoint
, "fast tracepoint"},
4523 {bp_jit_event
, "jit events"},
4526 static char bpenables
[] = "nynny";
4527 char wrap_indent
[80];
4528 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4529 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4530 struct cleanup
*bkpt_chain
;
4532 int header_of_multiple
= 0;
4533 int part_of_multiple
= (loc
!= NULL
);
4534 struct value_print_options opts
;
4536 get_user_print_options (&opts
);
4538 gdb_assert (!loc
|| loc_number
!= 0);
4539 /* See comment in print_one_breakpoint concerning
4540 treatment of breakpoints with single disabled
4544 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4545 header_of_multiple
= 1;
4550 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4554 if (part_of_multiple
)
4557 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4558 ui_out_field_string (uiout
, "number", formatted
);
4563 ui_out_field_int (uiout
, "number", b
->number
);
4568 if (part_of_multiple
)
4569 ui_out_field_skip (uiout
, "type");
4572 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4573 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4574 internal_error (__FILE__
, __LINE__
,
4575 _("bptypes table does not describe type #%d."),
4577 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4582 if (part_of_multiple
)
4583 ui_out_field_skip (uiout
, "disp");
4585 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4590 if (part_of_multiple
)
4591 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4593 ui_out_field_fmt (uiout
, "enabled", "%c",
4594 bpenables
[(int) b
->enable_state
]);
4595 ui_out_spaces (uiout
, 2);
4599 strcpy (wrap_indent
, " ");
4600 if (opts
.addressprint
)
4602 if (print_address_bits
<= 32)
4603 strcat (wrap_indent
, " ");
4605 strcat (wrap_indent
, " ");
4608 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4610 /* Although the print_one can possibly print
4611 all locations, calling it here is not likely
4612 to get any nice result. So, make sure there's
4613 just one location. */
4614 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4615 b
->ops
->print_one (b
, last_loc
);
4621 internal_error (__FILE__
, __LINE__
,
4622 _("print_one_breakpoint: bp_none encountered\n"));
4626 case bp_hardware_watchpoint
:
4627 case bp_read_watchpoint
:
4628 case bp_access_watchpoint
:
4629 /* Field 4, the address, is omitted (which makes the columns
4630 not line up too nicely with the headers, but the effect
4631 is relatively readable). */
4632 if (opts
.addressprint
)
4633 ui_out_field_skip (uiout
, "addr");
4635 ui_out_field_string (uiout
, "what", b
->exp_string
);
4639 case bp_hardware_breakpoint
:
4643 case bp_longjmp_resume
:
4644 case bp_step_resume
:
4645 case bp_watchpoint_scope
:
4647 case bp_std_terminate
:
4648 case bp_shlib_event
:
4649 case bp_thread_event
:
4650 case bp_overlay_event
:
4651 case bp_longjmp_master
:
4652 case bp_std_terminate_master
:
4654 case bp_fast_tracepoint
:
4656 if (opts
.addressprint
)
4659 if (header_of_multiple
)
4660 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4661 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4662 ui_out_field_string (uiout
, "addr", "<PENDING>");
4664 ui_out_field_core_addr (uiout
, "addr",
4665 loc
->gdbarch
, loc
->address
);
4668 if (!header_of_multiple
)
4669 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4676 /* For backward compatibility, don't display inferiors unless there
4679 && !header_of_multiple
4681 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4682 && (number_of_program_spaces () > 1
4683 || number_of_inferiors () > 1)
4684 && loc
->owner
->type
!= bp_catchpoint
)))
4686 struct inferior
*inf
;
4689 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4691 if (inf
->pspace
== loc
->pspace
)
4696 ui_out_text (uiout
, " inf ");
4699 ui_out_text (uiout
, ", ");
4700 ui_out_text (uiout
, plongest (inf
->num
));
4705 if (!part_of_multiple
)
4707 if (b
->thread
!= -1)
4709 /* FIXME: This seems to be redundant and lost here; see the
4710 "stop only in" line a little further down. */
4711 ui_out_text (uiout
, " thread ");
4712 ui_out_field_int (uiout
, "thread", b
->thread
);
4714 else if (b
->task
!= 0)
4716 ui_out_text (uiout
, " task ");
4717 ui_out_field_int (uiout
, "task", b
->task
);
4721 ui_out_text (uiout
, "\n");
4723 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4726 ui_out_text (uiout
, "\tstop only in stack frame at ");
4727 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4729 ui_out_field_core_addr (uiout
, "frame",
4730 b
->gdbarch
, b
->frame_id
.stack_addr
);
4731 ui_out_text (uiout
, "\n");
4734 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4736 /* We do not print the condition for Ada exception catchpoints
4737 because the condition is an internal implementation detail
4738 that we do not want to expose to the user. */
4740 if (is_tracepoint (b
))
4741 ui_out_text (uiout
, "\ttrace only if ");
4743 ui_out_text (uiout
, "\tstop only if ");
4744 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4745 ui_out_text (uiout
, "\n");
4748 if (!part_of_multiple
&& b
->thread
!= -1)
4750 /* FIXME should make an annotation for this */
4751 ui_out_text (uiout
, "\tstop only in thread ");
4752 ui_out_field_int (uiout
, "thread", b
->thread
);
4753 ui_out_text (uiout
, "\n");
4756 if (!part_of_multiple
&& b
->hit_count
)
4758 /* FIXME should make an annotation for this */
4759 if (ep_is_catchpoint (b
))
4760 ui_out_text (uiout
, "\tcatchpoint");
4762 ui_out_text (uiout
, "\tbreakpoint");
4763 ui_out_text (uiout
, " already hit ");
4764 ui_out_field_int (uiout
, "times", b
->hit_count
);
4765 if (b
->hit_count
== 1)
4766 ui_out_text (uiout
, " time\n");
4768 ui_out_text (uiout
, " times\n");
4771 /* Output the count also if it is zero, but only if this is
4772 mi. FIXME: Should have a better test for this. */
4773 if (ui_out_is_mi_like_p (uiout
))
4774 if (!part_of_multiple
&& b
->hit_count
== 0)
4775 ui_out_field_int (uiout
, "times", b
->hit_count
);
4777 if (!part_of_multiple
&& b
->ignore_count
)
4780 ui_out_text (uiout
, "\tignore next ");
4781 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4782 ui_out_text (uiout
, " hits\n");
4785 l
= b
->commands
? b
->commands
->commands
: NULL
;
4786 if (!part_of_multiple
&& l
)
4788 struct cleanup
*script_chain
;
4791 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4792 print_command_lines (uiout
, l
, 4);
4793 do_cleanups (script_chain
);
4796 if (!part_of_multiple
&& b
->pass_count
)
4798 annotate_field (10);
4799 ui_out_text (uiout
, "\tpass count ");
4800 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4801 ui_out_text (uiout
, " \n");
4804 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4807 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4808 else if (b
->exp_string
)
4809 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4812 do_cleanups (bkpt_chain
);
4813 do_cleanups (old_chain
);
4817 print_one_breakpoint (struct breakpoint
*b
,
4818 struct bp_location
**last_loc
, int print_address_bits
,
4821 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4822 print_address_bits
, allflag
);
4824 /* If this breakpoint has custom print function,
4825 it's already printed. Otherwise, print individual
4826 locations, if any. */
4827 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4829 /* If breakpoint has a single location that is
4830 disabled, we print it as if it had
4831 several locations, since otherwise it's hard to
4832 represent "breakpoint enabled, location disabled"
4834 Note that while hardware watchpoints have
4835 several locations internally, that's no a property
4838 && !is_hardware_watchpoint (b
)
4839 && (b
->loc
->next
|| !b
->loc
->enabled
)
4840 && !ui_out_is_mi_like_p (uiout
))
4842 struct bp_location
*loc
;
4844 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4845 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4846 print_address_bits
, allflag
);
4852 breakpoint_address_bits (struct breakpoint
*b
)
4854 int print_address_bits
= 0;
4855 struct bp_location
*loc
;
4857 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4861 /* Software watchpoints that aren't watching memory don't have
4862 an address to print. */
4863 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4866 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4867 if (addr_bit
> print_address_bits
)
4868 print_address_bits
= addr_bit
;
4871 return print_address_bits
;
4874 struct captured_breakpoint_query_args
4880 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4882 struct captured_breakpoint_query_args
*args
= data
;
4883 struct breakpoint
*b
;
4884 struct bp_location
*dummy_loc
= NULL
;
4887 if (args
->bnum
== b
->number
)
4889 int print_address_bits
= breakpoint_address_bits (b
);
4890 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4898 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4900 struct captured_breakpoint_query_args args
;
4902 /* For the moment we don't trust print_one_breakpoint() to not throw
4904 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4905 error_message
, RETURN_MASK_ALL
) < 0)
4911 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4912 catchpoints, et.al.). */
4915 user_settable_breakpoint (const struct breakpoint
*b
)
4917 return (b
->type
== bp_breakpoint
4918 || b
->type
== bp_catchpoint
4919 || b
->type
== bp_hardware_breakpoint
4920 || is_tracepoint (b
)
4921 || is_watchpoint (b
));
4924 /* Print information on user settable breakpoint (watchpoint, etc)
4925 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4926 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4927 FILTER is non-NULL, call it on each breakpoint and only include the
4928 ones for which it returns non-zero. Return the total number of
4929 breakpoints listed. */
4932 breakpoint_1 (int bnum
, int allflag
, int (*filter
) (const struct breakpoint
*))
4934 struct breakpoint
*b
;
4935 struct bp_location
*last_loc
= NULL
;
4936 int nr_printable_breakpoints
;
4937 struct cleanup
*bkpttbl_chain
;
4938 struct value_print_options opts
;
4939 int print_address_bits
= 0;
4941 get_user_print_options (&opts
);
4943 /* Compute the number of rows in the table, as well as the
4944 size required for address fields. */
4945 nr_printable_breakpoints
= 0;
4948 || bnum
== b
->number
)
4950 /* If we have a filter, only list the breakpoints it accepts. */
4951 if (filter
&& !filter (b
))
4954 if (allflag
|| user_settable_breakpoint (b
))
4956 int addr_bit
= breakpoint_address_bits (b
);
4957 if (addr_bit
> print_address_bits
)
4958 print_address_bits
= addr_bit
;
4960 nr_printable_breakpoints
++;
4964 if (opts
.addressprint
)
4966 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4970 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4973 if (nr_printable_breakpoints
> 0)
4974 annotate_breakpoints_headers ();
4975 if (nr_printable_breakpoints
> 0)
4977 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4978 if (nr_printable_breakpoints
> 0)
4980 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4981 if (nr_printable_breakpoints
> 0)
4983 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4984 if (nr_printable_breakpoints
> 0)
4986 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4987 if (opts
.addressprint
)
4989 if (nr_printable_breakpoints
> 0)
4991 if (print_address_bits
<= 32)
4992 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4994 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4996 if (nr_printable_breakpoints
> 0)
4998 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4999 ui_out_table_body (uiout
);
5000 if (nr_printable_breakpoints
> 0)
5001 annotate_breakpoints_table ();
5007 || bnum
== b
->number
)
5009 /* If we have a filter, only list the breakpoints it accepts. */
5010 if (filter
&& !filter (b
))
5013 /* We only print out user settable breakpoints unless the
5015 if (allflag
|| user_settable_breakpoint (b
))
5016 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5020 do_cleanups (bkpttbl_chain
);
5022 if (nr_printable_breakpoints
== 0)
5024 /* If there's a filter, let the caller decide how to report empty list. */
5028 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5030 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5036 if (last_loc
&& !server_command
)
5037 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5040 /* FIXME? Should this be moved up so that it is only called when
5041 there have been breakpoints? */
5042 annotate_breakpoints_table_end ();
5044 return nr_printable_breakpoints
;
5047 /* Display the value of default-collect in a way that is generally
5048 compatible with the breakpoint list. */
5051 default_collect_info (void)
5053 /* If it has no value (which is frequently the case), say nothing; a
5054 message like "No default-collect." gets in user's face when it's
5056 if (!*default_collect
)
5059 /* The following phrase lines up nicely with per-tracepoint collect
5061 ui_out_text (uiout
, "default collect ");
5062 ui_out_field_string (uiout
, "default-collect", default_collect
);
5063 ui_out_text (uiout
, " \n");
5067 breakpoints_info (char *bnum_exp
, int from_tty
)
5072 bnum
= parse_and_eval_long (bnum_exp
);
5074 breakpoint_1 (bnum
, 0, NULL
);
5076 default_collect_info ();
5080 watchpoints_info (char *wpnum_exp
, int from_tty
)
5082 int wpnum
= -1, num_printed
;
5085 wpnum
= parse_and_eval_long (wpnum_exp
);
5087 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5089 if (num_printed
== 0)
5092 ui_out_message (uiout
, 0, "No watchpoints.\n");
5094 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5099 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5104 bnum
= parse_and_eval_long (bnum_exp
);
5106 breakpoint_1 (bnum
, 1, NULL
);
5108 default_collect_info ();
5112 breakpoint_has_pc (struct breakpoint
*b
,
5113 struct program_space
*pspace
,
5114 CORE_ADDR pc
, struct obj_section
*section
)
5116 struct bp_location
*bl
= b
->loc
;
5117 for (; bl
; bl
= bl
->next
)
5119 if (bl
->pspace
== pspace
5120 && bl
->address
== pc
5121 && (!overlay_debugging
|| bl
->section
== section
))
5127 /* Print a message describing any breakpoints set at PC. This
5128 concerns with logical breakpoints, so we match program spaces, not
5132 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5133 struct program_space
*pspace
, CORE_ADDR pc
,
5134 struct obj_section
*section
, int thread
)
5137 struct breakpoint
*b
;
5140 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5144 printf_filtered (_("Note: breakpoint "));
5145 else /* if (others == ???) */
5146 printf_filtered (_("Note: breakpoints "));
5148 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5151 printf_filtered ("%d", b
->number
);
5152 if (b
->thread
== -1 && thread
!= -1)
5153 printf_filtered (" (all threads)");
5154 else if (b
->thread
!= -1)
5155 printf_filtered (" (thread %d)", b
->thread
);
5156 printf_filtered ("%s%s ",
5157 ((b
->enable_state
== bp_disabled
5158 || b
->enable_state
== bp_call_disabled
5159 || b
->enable_state
== bp_startup_disabled
)
5161 : b
->enable_state
== bp_permanent
5165 : ((others
== 1) ? " and" : ""));
5167 printf_filtered (_("also set at pc "));
5168 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5169 printf_filtered (".\n");
5173 /* Set the default place to put a breakpoint
5174 for the `break' command with no arguments. */
5177 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5178 CORE_ADDR addr
, struct symtab
*symtab
,
5181 default_breakpoint_valid
= valid
;
5182 default_breakpoint_pspace
= pspace
;
5183 default_breakpoint_address
= addr
;
5184 default_breakpoint_symtab
= symtab
;
5185 default_breakpoint_line
= line
;
5188 /* Return true iff it is meaningful to use the address member of
5189 BPT. For some breakpoint types, the address member is irrelevant
5190 and it makes no sense to attempt to compare it to other addresses
5191 (or use it for any other purpose either).
5193 More specifically, each of the following breakpoint types will always
5194 have a zero valued address and we don't want to mark breakpoints of any of
5195 these types to be a duplicate of an actual breakpoint at address zero:
5203 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5205 enum bptype type
= bpt
->type
;
5207 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5210 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5211 true if LOC1 and LOC2 represent the same watchpoint location. */
5214 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5216 /* Note that this checks the owner's type, not the location's. In
5217 case the target does not support read watchpoints, but does
5218 support access watchpoints, we'll have bp_read_watchpoint
5219 watchpoints with hw_access locations. Those should be considered
5220 duplicates of hw_read locations. The hw_read locations will
5221 become hw_access locations later. */
5222 return (loc1
->owner
->type
== loc2
->owner
->type
5223 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5224 && loc1
->address
== loc2
->address
5225 && loc1
->length
== loc2
->length
);
5228 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5229 same breakpoint location. In most targets, this can only be true
5230 if ASPACE1 matches ASPACE2. On targets that have global
5231 breakpoints, the address space doesn't really matter. */
5234 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5235 struct address_space
*aspace2
, CORE_ADDR addr2
)
5237 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5238 || aspace1
== aspace2
)
5242 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5243 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5244 represent the same location. */
5247 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5249 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5250 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5252 if (hw_point1
!= hw_point2
)
5255 return watchpoint_locations_match (loc1
, loc2
);
5257 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5258 loc2
->pspace
->aspace
, loc2
->address
);
5262 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5263 int bnum
, int have_bnum
)
5268 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5269 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5271 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5272 bnum
, astr1
, astr2
);
5274 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5277 /* Adjust a breakpoint's address to account for architectural constraints
5278 on breakpoint placement. Return the adjusted address. Note: Very
5279 few targets require this kind of adjustment. For most targets,
5280 this function is simply the identity function. */
5283 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5284 CORE_ADDR bpaddr
, enum bptype bptype
)
5286 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5288 /* Very few targets need any kind of breakpoint adjustment. */
5291 else if (bptype
== bp_watchpoint
5292 || bptype
== bp_hardware_watchpoint
5293 || bptype
== bp_read_watchpoint
5294 || bptype
== bp_access_watchpoint
5295 || bptype
== bp_catchpoint
)
5297 /* Watchpoints and the various bp_catch_* eventpoints should not
5298 have their addresses modified. */
5303 CORE_ADDR adjusted_bpaddr
;
5305 /* Some targets have architectural constraints on the placement
5306 of breakpoint instructions. Obtain the adjusted address. */
5307 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5309 /* An adjusted breakpoint address can significantly alter
5310 a user's expectations. Print a warning if an adjustment
5312 if (adjusted_bpaddr
!= bpaddr
)
5313 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5315 return adjusted_bpaddr
;
5319 /* Allocate a struct bp_location. */
5321 static struct bp_location
*
5322 allocate_bp_location (struct breakpoint
*bpt
)
5324 struct bp_location
*loc
, *loc_p
;
5326 loc
= xmalloc (sizeof (struct bp_location
));
5327 memset (loc
, 0, sizeof (*loc
));
5331 loc
->shlib_disabled
= 0;
5340 case bp_longjmp_resume
:
5341 case bp_step_resume
:
5342 case bp_watchpoint_scope
:
5344 case bp_std_terminate
:
5345 case bp_shlib_event
:
5346 case bp_thread_event
:
5347 case bp_overlay_event
:
5349 case bp_longjmp_master
:
5350 case bp_std_terminate_master
:
5351 loc
->loc_type
= bp_loc_software_breakpoint
;
5353 case bp_hardware_breakpoint
:
5354 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5356 case bp_hardware_watchpoint
:
5357 case bp_read_watchpoint
:
5358 case bp_access_watchpoint
:
5359 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5364 case bp_fast_tracepoint
:
5365 loc
->loc_type
= bp_loc_other
;
5368 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5374 static void free_bp_location (struct bp_location
*loc
)
5379 if (loc
->function_name
)
5380 xfree (loc
->function_name
);
5385 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5386 that has type BPTYPE and has no locations as yet. */
5387 /* This function is used in gdbtk sources and thus can not be made static. */
5389 static struct breakpoint
*
5390 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5393 struct breakpoint
*b
, *b1
;
5395 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5396 memset (b
, 0, sizeof (*b
));
5399 b
->gdbarch
= gdbarch
;
5400 b
->language
= current_language
->la_language
;
5401 b
->input_radix
= input_radix
;
5403 b
->enable_state
= bp_enabled
;
5406 b
->ignore_count
= 0;
5408 b
->frame_id
= null_frame_id
;
5409 b
->forked_inferior_pid
= null_ptid
;
5410 b
->exec_pathname
= NULL
;
5411 b
->syscalls_to_be_caught
= NULL
;
5413 b
->condition_not_parsed
= 0;
5415 /* Add this breakpoint to the end of the chain
5416 so that a list of breakpoints will come out in order
5417 of increasing numbers. */
5419 b1
= breakpoint_chain
;
5421 breakpoint_chain
= b
;
5431 /* Initialize loc->function_name. */
5433 set_breakpoint_location_function (struct bp_location
*loc
)
5435 if (loc
->owner
->type
== bp_breakpoint
5436 || loc
->owner
->type
== bp_hardware_breakpoint
5437 || is_tracepoint (loc
->owner
))
5439 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5441 if (loc
->function_name
)
5442 loc
->function_name
= xstrdup (loc
->function_name
);
5446 /* Attempt to determine architecture of location identified by SAL. */
5447 static struct gdbarch
*
5448 get_sal_arch (struct symtab_and_line sal
)
5451 return get_objfile_arch (sal
.section
->objfile
);
5453 return get_objfile_arch (sal
.symtab
->objfile
);
5458 /* set_raw_breakpoint is a low level routine for allocating and
5459 partially initializing a breakpoint of type BPTYPE. The newly
5460 created breakpoint's address, section, source file name, and line
5461 number are provided by SAL. The newly created and partially
5462 initialized breakpoint is added to the breakpoint chain and
5463 is also returned as the value of this function.
5465 It is expected that the caller will complete the initialization of
5466 the newly created breakpoint struct as well as output any status
5467 information regarding the creation of a new breakpoint. In
5468 particular, set_raw_breakpoint does NOT set the breakpoint
5469 number! Care should be taken to not allow an error to occur
5470 prior to completing the initialization of the breakpoint. If this
5471 should happen, a bogus breakpoint will be left on the chain. */
5474 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5475 struct symtab_and_line sal
, enum bptype bptype
)
5477 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5478 CORE_ADDR adjusted_address
;
5479 struct gdbarch
*loc_gdbarch
;
5481 loc_gdbarch
= get_sal_arch (sal
);
5483 loc_gdbarch
= b
->gdbarch
;
5485 if (bptype
!= bp_catchpoint
)
5486 gdb_assert (sal
.pspace
!= NULL
);
5488 /* Adjust the breakpoint's address prior to allocating a location.
5489 Once we call allocate_bp_location(), that mostly uninitialized
5490 location will be placed on the location chain. Adjustment of the
5491 breakpoint may cause target_read_memory() to be called and we do
5492 not want its scan of the location chain to find a breakpoint and
5493 location that's only been partially initialized. */
5494 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5496 b
->loc
= allocate_bp_location (b
);
5497 b
->loc
->gdbarch
= loc_gdbarch
;
5498 b
->loc
->requested_address
= sal
.pc
;
5499 b
->loc
->address
= adjusted_address
;
5500 b
->loc
->pspace
= sal
.pspace
;
5502 /* Store the program space that was used to set the breakpoint, for
5503 breakpoint resetting. */
5504 b
->pspace
= sal
.pspace
;
5506 if (sal
.symtab
== NULL
)
5507 b
->source_file
= NULL
;
5509 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5510 b
->loc
->section
= sal
.section
;
5511 b
->line_number
= sal
.line
;
5513 set_breakpoint_location_function (b
->loc
);
5515 breakpoints_changed ();
5521 /* Note that the breakpoint object B describes a permanent breakpoint
5522 instruction, hard-wired into the inferior's code. */
5524 make_breakpoint_permanent (struct breakpoint
*b
)
5526 struct bp_location
*bl
;
5527 b
->enable_state
= bp_permanent
;
5529 /* By definition, permanent breakpoints are already present in the code.
5530 Mark all locations as inserted. For now, make_breakpoint_permanent
5531 is called in just one place, so it's hard to say if it's reasonable
5532 to have permanent breakpoint with multiple locations or not,
5533 but it's easy to implmement. */
5534 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5538 /* Call this routine when stepping and nexting to enable a breakpoint
5539 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5540 set_longjmp_resume_breakpoint() to figure out where we are going. */
5543 set_longjmp_breakpoint (int thread
)
5545 struct breakpoint
*b
, *temp
;
5547 /* To avoid having to rescan all objfile symbols at every step,
5548 we maintain a list of continually-inserted but always disabled
5549 longjmp "master" breakpoints. Here, we simply create momentary
5550 clones of those and enable them for the requested thread. */
5551 ALL_BREAKPOINTS_SAFE (b
, temp
)
5552 if (b
->pspace
== current_program_space
5553 && b
->type
== bp_longjmp_master
)
5555 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5556 clone
->type
= bp_longjmp
;
5557 clone
->thread
= thread
;
5561 /* Delete all longjmp breakpoints from THREAD. */
5563 delete_longjmp_breakpoint (int thread
)
5565 struct breakpoint
*b
, *temp
;
5567 ALL_BREAKPOINTS_SAFE (b
, temp
)
5568 if (b
->type
== bp_longjmp
)
5570 if (b
->thread
== thread
)
5571 delete_breakpoint (b
);
5576 enable_overlay_breakpoints (void)
5578 struct breakpoint
*b
;
5581 if (b
->type
== bp_overlay_event
)
5583 b
->enable_state
= bp_enabled
;
5584 update_global_location_list (1);
5585 overlay_events_enabled
= 1;
5590 disable_overlay_breakpoints (void)
5592 struct breakpoint
*b
;
5595 if (b
->type
== bp_overlay_event
)
5597 b
->enable_state
= bp_disabled
;
5598 update_global_location_list (0);
5599 overlay_events_enabled
= 0;
5603 /* Set an active std::terminate breakpoint for each std::terminate
5604 master breakpoint. */
5606 set_std_terminate_breakpoint (void)
5608 struct breakpoint
*b
, *temp
;
5610 ALL_BREAKPOINTS_SAFE (b
, temp
)
5611 if (b
->pspace
== current_program_space
5612 && b
->type
== bp_std_terminate_master
)
5614 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5615 clone
->type
= bp_std_terminate
;
5619 /* Delete all the std::terminate breakpoints. */
5621 delete_std_terminate_breakpoint (void)
5623 struct breakpoint
*b
, *temp
;
5625 ALL_BREAKPOINTS_SAFE (b
, temp
)
5626 if (b
->type
== bp_std_terminate
)
5627 delete_breakpoint (b
);
5631 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5633 struct breakpoint
*b
;
5635 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5637 b
->enable_state
= bp_enabled
;
5638 /* addr_string has to be used or breakpoint_re_set will delete me. */
5640 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5642 update_global_location_list_nothrow (1);
5648 remove_thread_event_breakpoints (void)
5650 struct breakpoint
*b
, *temp
;
5652 ALL_BREAKPOINTS_SAFE (b
, temp
)
5653 if (b
->type
== bp_thread_event
5654 && b
->loc
->pspace
== current_program_space
)
5655 delete_breakpoint (b
);
5658 struct captured_parse_breakpoint_args
5661 struct symtabs_and_lines
*sals_p
;
5662 char ***addr_string_p
;
5666 struct lang_and_radix
5672 /* Create a breakpoint for JIT code registration and unregistration. */
5675 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5677 struct breakpoint
*b
;
5679 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5680 update_global_location_list_nothrow (1);
5685 remove_solib_event_breakpoints (void)
5687 struct breakpoint
*b
, *temp
;
5689 ALL_BREAKPOINTS_SAFE (b
, temp
)
5690 if (b
->type
== bp_shlib_event
5691 && b
->loc
->pspace
== current_program_space
)
5692 delete_breakpoint (b
);
5696 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5698 struct breakpoint
*b
;
5700 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5701 update_global_location_list_nothrow (1);
5705 /* Disable any breakpoints that are on code in shared libraries. Only
5706 apply to enabled breakpoints, disabled ones can just stay disabled. */
5709 disable_breakpoints_in_shlibs (void)
5711 struct bp_location
*loc
, **locp_tmp
;
5713 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5715 struct breakpoint
*b
= loc
->owner
;
5716 /* We apply the check to all breakpoints, including disabled
5717 for those with loc->duplicate set. This is so that when breakpoint
5718 becomes enabled, or the duplicate is removed, gdb will try to insert
5719 all breakpoints. If we don't set shlib_disabled here, we'll try
5720 to insert those breakpoints and fail. */
5721 if (((b
->type
== bp_breakpoint
)
5722 || (b
->type
== bp_jit_event
)
5723 || (b
->type
== bp_hardware_breakpoint
)
5724 || (is_tracepoint (b
)))
5725 && loc
->pspace
== current_program_space
5726 && !loc
->shlib_disabled
5728 && PC_SOLIB (loc
->address
)
5730 && solib_name_from_address (loc
->pspace
, loc
->address
)
5734 loc
->shlib_disabled
= 1;
5739 /* Disable any breakpoints that are in in an unloaded shared library. Only
5740 apply to enabled breakpoints, disabled ones can just stay disabled. */
5743 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5745 struct bp_location
*loc
, **locp_tmp
;
5746 int disabled_shlib_breaks
= 0;
5748 /* SunOS a.out shared libraries are always mapped, so do not
5749 disable breakpoints; they will only be reported as unloaded
5750 through clear_solib when GDB discards its shared library
5751 list. See clear_solib for more information. */
5752 if (exec_bfd
!= NULL
5753 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5756 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5758 struct breakpoint
*b
= loc
->owner
;
5759 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5760 || loc
->loc_type
== bp_loc_software_breakpoint
)
5761 && solib
->pspace
== loc
->pspace
5762 && !loc
->shlib_disabled
5763 && (b
->type
== bp_breakpoint
5764 || b
->type
== bp_jit_event
5765 || b
->type
== bp_hardware_breakpoint
)
5766 && solib_contains_address_p (solib
, loc
->address
))
5768 loc
->shlib_disabled
= 1;
5769 /* At this point, we cannot rely on remove_breakpoint
5770 succeeding so we must mark the breakpoint as not inserted
5771 to prevent future errors occurring in remove_breakpoints. */
5773 if (!disabled_shlib_breaks
)
5775 target_terminal_ours_for_output ();
5776 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5779 disabled_shlib_breaks
= 1;
5784 /* FORK & VFORK catchpoints. */
5786 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5789 insert_catch_fork (struct breakpoint
*b
)
5791 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5794 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5797 remove_catch_fork (struct breakpoint
*b
)
5799 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5802 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5806 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5808 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5811 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5813 static enum print_stop_action
5814 print_it_catch_fork (struct breakpoint
*b
)
5816 annotate_catchpoint (b
->number
);
5817 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5818 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5819 return PRINT_SRC_AND_LOC
;
5822 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5825 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5827 struct value_print_options opts
;
5829 get_user_print_options (&opts
);
5831 /* Field 4, the address, is omitted (which makes the columns
5832 not line up too nicely with the headers, but the effect
5833 is relatively readable). */
5834 if (opts
.addressprint
)
5835 ui_out_field_skip (uiout
, "addr");
5837 ui_out_text (uiout
, "fork");
5838 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5840 ui_out_text (uiout
, ", process ");
5841 ui_out_field_int (uiout
, "what",
5842 ptid_get_pid (b
->forked_inferior_pid
));
5843 ui_out_spaces (uiout
, 1);
5847 /* Implement the "print_mention" breakpoint_ops method for fork
5851 print_mention_catch_fork (struct breakpoint
*b
)
5853 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5856 /* The breakpoint_ops structure to be used in fork catchpoints. */
5858 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5862 breakpoint_hit_catch_fork
,
5863 print_it_catch_fork
,
5864 print_one_catch_fork
,
5865 print_mention_catch_fork
5868 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5871 insert_catch_vfork (struct breakpoint
*b
)
5873 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5876 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5879 remove_catch_vfork (struct breakpoint
*b
)
5881 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5884 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5888 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5890 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5893 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5895 static enum print_stop_action
5896 print_it_catch_vfork (struct breakpoint
*b
)
5898 annotate_catchpoint (b
->number
);
5899 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5900 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5901 return PRINT_SRC_AND_LOC
;
5904 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5907 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5909 struct value_print_options opts
;
5911 get_user_print_options (&opts
);
5912 /* Field 4, the address, is omitted (which makes the columns
5913 not line up too nicely with the headers, but the effect
5914 is relatively readable). */
5915 if (opts
.addressprint
)
5916 ui_out_field_skip (uiout
, "addr");
5918 ui_out_text (uiout
, "vfork");
5919 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5921 ui_out_text (uiout
, ", process ");
5922 ui_out_field_int (uiout
, "what",
5923 ptid_get_pid (b
->forked_inferior_pid
));
5924 ui_out_spaces (uiout
, 1);
5928 /* Implement the "print_mention" breakpoint_ops method for vfork
5932 print_mention_catch_vfork (struct breakpoint
*b
)
5934 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5937 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5939 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5943 breakpoint_hit_catch_vfork
,
5944 print_it_catch_vfork
,
5945 print_one_catch_vfork
,
5946 print_mention_catch_vfork
5949 /* Implement the "insert" breakpoint_ops method for syscall
5953 insert_catch_syscall (struct breakpoint
*b
)
5955 struct inferior
*inf
= current_inferior ();
5957 ++inf
->total_syscalls_count
;
5958 if (!b
->syscalls_to_be_caught
)
5959 ++inf
->any_syscall_count
;
5964 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5968 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5970 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5971 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5973 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5974 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5976 memset ((void *) vec_addr
, 0,
5977 (iter
+ 1 - old_size
) * sizeof (int));
5979 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5980 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5984 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5985 inf
->total_syscalls_count
!= 0,
5986 inf
->any_syscall_count
,
5987 VEC_length (int, inf
->syscalls_counts
),
5988 VEC_address (int, inf
->syscalls_counts
));
5991 /* Implement the "remove" breakpoint_ops method for syscall
5995 remove_catch_syscall (struct breakpoint
*b
)
5997 struct inferior
*inf
= current_inferior ();
5999 --inf
->total_syscalls_count
;
6000 if (!b
->syscalls_to_be_caught
)
6001 --inf
->any_syscall_count
;
6006 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6010 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6011 /* Shouldn't happen. */
6013 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6014 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6018 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6019 inf
->total_syscalls_count
!= 0,
6020 inf
->any_syscall_count
,
6021 VEC_length (int, inf
->syscalls_counts
),
6022 VEC_address (int, inf
->syscalls_counts
));
6025 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6029 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6031 /* We must check if we are catching specific syscalls in this breakpoint.
6032 If we are, then we must guarantee that the called syscall is the same
6033 syscall we are catching. */
6034 int syscall_number
= 0;
6036 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6039 /* Now, checking if the syscall is the same. */
6040 if (b
->syscalls_to_be_caught
)
6044 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6046 if (syscall_number
== iter
)
6056 /* Implement the "print_it" breakpoint_ops method for syscall
6059 static enum print_stop_action
6060 print_it_catch_syscall (struct breakpoint
*b
)
6062 /* These are needed because we want to know in which state a
6063 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6064 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6065 must print "called syscall" or "returned from syscall". */
6067 struct target_waitstatus last
;
6069 struct cleanup
*old_chain
;
6072 get_last_target_status (&ptid
, &last
);
6074 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6076 annotate_catchpoint (b
->number
);
6079 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6081 syscall_id
= xstrprintf ("'%s'", s
.name
);
6083 old_chain
= make_cleanup (xfree
, syscall_id
);
6085 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6086 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6087 b
->number
, syscall_id
);
6088 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6089 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6090 b
->number
, syscall_id
);
6092 do_cleanups (old_chain
);
6094 return PRINT_SRC_AND_LOC
;
6097 /* Implement the "print_one" breakpoint_ops method for syscall
6101 print_one_catch_syscall (struct breakpoint
*b
,
6102 struct bp_location
**last_loc
)
6104 struct value_print_options opts
;
6106 get_user_print_options (&opts
);
6107 /* Field 4, the address, is omitted (which makes the columns
6108 not line up too nicely with the headers, but the effect
6109 is relatively readable). */
6110 if (opts
.addressprint
)
6111 ui_out_field_skip (uiout
, "addr");
6114 if (b
->syscalls_to_be_caught
6115 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6116 ui_out_text (uiout
, "syscalls \"");
6118 ui_out_text (uiout
, "syscall \"");
6120 if (b
->syscalls_to_be_caught
)
6123 char *text
= xstrprintf ("%s", "");
6125 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6130 get_syscall_by_number (iter
, &s
);
6133 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6135 text
= xstrprintf ("%s%d, ", text
, iter
);
6137 /* We have to xfree the last 'text' (now stored at 'x')
6138 because xstrprintf dinamically allocates new space for it
6142 /* Remove the last comma. */
6143 text
[strlen (text
) - 2] = '\0';
6144 ui_out_field_string (uiout
, "what", text
);
6147 ui_out_field_string (uiout
, "what", "<any syscall>");
6148 ui_out_text (uiout
, "\" ");
6151 /* Implement the "print_mention" breakpoint_ops method for syscall
6155 print_mention_catch_syscall (struct breakpoint
*b
)
6157 if (b
->syscalls_to_be_caught
)
6161 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6162 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6164 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6167 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6171 get_syscall_by_number (iter
, &s
);
6174 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6176 printf_filtered (" %d", s
.number
);
6178 printf_filtered (")");
6181 printf_filtered (_("Catchpoint %d (any syscall)"),
6185 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6187 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6189 insert_catch_syscall
,
6190 remove_catch_syscall
,
6191 breakpoint_hit_catch_syscall
,
6192 print_it_catch_syscall
,
6193 print_one_catch_syscall
,
6194 print_mention_catch_syscall
6197 /* Returns non-zero if 'b' is a syscall catchpoint. */
6200 syscall_catchpoint_p (struct breakpoint
*b
)
6202 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6205 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6206 but does NOT mention it nor update the global location list.
6207 This is useful if you need to fill more fields in the
6208 struct breakpoint before calling mention.
6210 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6211 If COND_STRING is not NULL, then store it in the breakpoint.
6212 OPS, if not NULL, is the breakpoint_ops structure associated
6213 to the catchpoint. */
6215 static struct breakpoint
*
6216 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6218 struct breakpoint_ops
*ops
)
6220 struct symtab_and_line sal
;
6221 struct breakpoint
*b
;
6224 sal
.pspace
= current_program_space
;
6226 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6227 set_breakpoint_count (breakpoint_count
+ 1);
6228 b
->number
= breakpoint_count
;
6230 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6232 b
->addr_string
= NULL
;
6233 b
->enable_state
= bp_enabled
;
6234 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6240 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6242 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6243 If COND_STRING is not NULL, then store it in the breakpoint.
6244 OPS, if not NULL, is the breakpoint_ops structure associated
6245 to the catchpoint. */
6247 static struct breakpoint
*
6248 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6249 char *cond_string
, struct breakpoint_ops
*ops
)
6251 struct breakpoint
*b
=
6252 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6255 update_global_location_list (1);
6261 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6262 int tempflag
, char *cond_string
,
6263 struct breakpoint_ops
*ops
)
6265 struct breakpoint
*b
6266 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6268 /* FIXME: We should put this information in a breakpoint private data
6270 b
->forked_inferior_pid
= null_ptid
;
6273 /* Exec catchpoints. */
6276 insert_catch_exec (struct breakpoint
*b
)
6278 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6282 remove_catch_exec (struct breakpoint
*b
)
6284 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6288 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6290 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6293 static enum print_stop_action
6294 print_it_catch_exec (struct breakpoint
*b
)
6296 annotate_catchpoint (b
->number
);
6297 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6299 return PRINT_SRC_AND_LOC
;
6303 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6305 struct value_print_options opts
;
6307 get_user_print_options (&opts
);
6309 /* Field 4, the address, is omitted (which makes the columns
6310 not line up too nicely with the headers, but the effect
6311 is relatively readable). */
6312 if (opts
.addressprint
)
6313 ui_out_field_skip (uiout
, "addr");
6315 ui_out_text (uiout
, "exec");
6316 if (b
->exec_pathname
!= NULL
)
6318 ui_out_text (uiout
, ", program \"");
6319 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6320 ui_out_text (uiout
, "\" ");
6325 print_mention_catch_exec (struct breakpoint
*b
)
6327 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6330 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6334 breakpoint_hit_catch_exec
,
6335 print_it_catch_exec
,
6336 print_one_catch_exec
,
6337 print_mention_catch_exec
6341 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6342 struct breakpoint_ops
*ops
)
6344 struct gdbarch
*gdbarch
= get_current_arch ();
6345 struct breakpoint
*b
=
6346 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6348 b
->syscalls_to_be_caught
= filter
;
6350 /* Now, we have to mention the breakpoint and update the global
6353 update_global_location_list (1);
6357 hw_breakpoint_used_count (void)
6359 struct breakpoint
*b
;
6364 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6372 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6374 struct breakpoint
*b
;
6377 *other_type_used
= 0;
6380 if (breakpoint_enabled (b
))
6382 if (b
->type
== type
)
6384 else if (is_hardware_watchpoint (b
))
6385 *other_type_used
= 1;
6392 disable_watchpoints_before_interactive_call_start (void)
6394 struct breakpoint
*b
;
6398 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6400 b
->enable_state
= bp_call_disabled
;
6401 update_global_location_list (0);
6407 enable_watchpoints_after_interactive_call_stop (void)
6409 struct breakpoint
*b
;
6413 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6415 b
->enable_state
= bp_enabled
;
6416 update_global_location_list (1);
6422 disable_breakpoints_before_startup (void)
6424 struct breakpoint
*b
;
6429 if (b
->pspace
!= current_program_space
)
6432 if ((b
->type
== bp_breakpoint
6433 || b
->type
== bp_hardware_breakpoint
)
6434 && breakpoint_enabled (b
))
6436 b
->enable_state
= bp_startup_disabled
;
6442 update_global_location_list (0);
6444 current_program_space
->executing_startup
= 1;
6448 enable_breakpoints_after_startup (void)
6450 struct breakpoint
*b
;
6453 current_program_space
->executing_startup
= 0;
6457 if (b
->pspace
!= current_program_space
)
6460 if ((b
->type
== bp_breakpoint
6461 || b
->type
== bp_hardware_breakpoint
)
6462 && b
->enable_state
== bp_startup_disabled
)
6464 b
->enable_state
= bp_enabled
;
6470 breakpoint_re_set ();
6474 /* Set a breakpoint that will evaporate an end of command
6475 at address specified by SAL.
6476 Restrict it to frame FRAME if FRAME is nonzero. */
6479 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6480 struct frame_id frame_id
, enum bptype type
)
6482 struct breakpoint
*b
;
6484 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6486 gdb_assert (!frame_id_inlined_p (frame_id
));
6488 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6489 b
->enable_state
= bp_enabled
;
6490 b
->disposition
= disp_donttouch
;
6491 b
->frame_id
= frame_id
;
6493 /* If we're debugging a multi-threaded program, then we
6494 want momentary breakpoints to be active in only a
6495 single thread of control. */
6496 if (in_thread_list (inferior_ptid
))
6497 b
->thread
= pid_to_thread_id (inferior_ptid
);
6499 update_global_location_list_nothrow (1);
6504 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6508 clone_momentary_breakpoint (struct breakpoint
*orig
)
6510 struct breakpoint
*copy
;
6512 /* If there's nothing to clone, then return nothing. */
6516 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6517 copy
->loc
= allocate_bp_location (copy
);
6518 set_breakpoint_location_function (copy
->loc
);
6520 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6521 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6522 copy
->loc
->address
= orig
->loc
->address
;
6523 copy
->loc
->section
= orig
->loc
->section
;
6524 copy
->loc
->pspace
= orig
->loc
->pspace
;
6526 if (orig
->source_file
== NULL
)
6527 copy
->source_file
= NULL
;
6529 copy
->source_file
= xstrdup (orig
->source_file
);
6531 copy
->line_number
= orig
->line_number
;
6532 copy
->frame_id
= orig
->frame_id
;
6533 copy
->thread
= orig
->thread
;
6534 copy
->pspace
= orig
->pspace
;
6536 copy
->enable_state
= bp_enabled
;
6537 copy
->disposition
= disp_donttouch
;
6538 copy
->number
= internal_breakpoint_number
--;
6540 update_global_location_list_nothrow (0);
6545 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6548 struct symtab_and_line sal
;
6550 sal
= find_pc_line (pc
, 0);
6552 sal
.section
= find_pc_overlay (pc
);
6553 sal
.explicit_pc
= 1;
6555 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6559 /* Tell the user we have just set a breakpoint B. */
6562 mention (struct breakpoint
*b
)
6565 struct cleanup
*ui_out_chain
;
6566 struct value_print_options opts
;
6568 get_user_print_options (&opts
);
6570 /* FIXME: This is misplaced; mention() is called by things (like
6571 hitting a watchpoint) other than breakpoint creation. It should
6572 be possible to clean this up and at the same time replace the
6573 random calls to breakpoint_changed with this hook. */
6574 observer_notify_breakpoint_created (b
->number
);
6576 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6577 b
->ops
->print_mention (b
);
6582 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6585 ui_out_text (uiout
, "Watchpoint ");
6586 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6587 ui_out_field_int (uiout
, "number", b
->number
);
6588 ui_out_text (uiout
, ": ");
6589 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6590 do_cleanups (ui_out_chain
);
6592 case bp_hardware_watchpoint
:
6593 ui_out_text (uiout
, "Hardware watchpoint ");
6594 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6595 ui_out_field_int (uiout
, "number", b
->number
);
6596 ui_out_text (uiout
, ": ");
6597 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6598 do_cleanups (ui_out_chain
);
6600 case bp_read_watchpoint
:
6601 ui_out_text (uiout
, "Hardware read watchpoint ");
6602 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6603 ui_out_field_int (uiout
, "number", b
->number
);
6604 ui_out_text (uiout
, ": ");
6605 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6606 do_cleanups (ui_out_chain
);
6608 case bp_access_watchpoint
:
6609 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6610 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6611 ui_out_field_int (uiout
, "number", b
->number
);
6612 ui_out_text (uiout
, ": ");
6613 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6614 do_cleanups (ui_out_chain
);
6617 if (ui_out_is_mi_like_p (uiout
))
6622 if (b
->disposition
== disp_del
)
6623 printf_filtered (_("Temporary breakpoint"));
6625 printf_filtered (_("Breakpoint"));
6626 printf_filtered (_(" %d"), b
->number
);
6629 case bp_hardware_breakpoint
:
6630 if (ui_out_is_mi_like_p (uiout
))
6635 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6639 if (ui_out_is_mi_like_p (uiout
))
6644 printf_filtered (_("Tracepoint"));
6645 printf_filtered (_(" %d"), b
->number
);
6648 case bp_fast_tracepoint
:
6649 if (ui_out_is_mi_like_p (uiout
))
6654 printf_filtered (_("Fast tracepoint"));
6655 printf_filtered (_(" %d"), b
->number
);
6662 case bp_longjmp_resume
:
6663 case bp_step_resume
:
6665 case bp_std_terminate
:
6666 case bp_watchpoint_scope
:
6667 case bp_shlib_event
:
6668 case bp_thread_event
:
6669 case bp_overlay_event
:
6671 case bp_longjmp_master
:
6672 case bp_std_terminate_master
:
6678 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6682 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6686 if (opts
.addressprint
|| b
->source_file
== NULL
)
6688 printf_filtered (" at ");
6689 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6693 printf_filtered (": file %s, line %d.",
6694 b
->source_file
, b
->line_number
);
6698 struct bp_location
*loc
= b
->loc
;
6700 for (; loc
; loc
= loc
->next
)
6702 printf_filtered (" (%d locations)", n
);
6707 if (ui_out_is_mi_like_p (uiout
))
6709 printf_filtered ("\n");
6713 static struct bp_location
*
6714 add_location_to_breakpoint (struct breakpoint
*b
,
6715 const struct symtab_and_line
*sal
)
6717 struct bp_location
*loc
, **tmp
;
6719 loc
= allocate_bp_location (b
);
6720 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6723 loc
->gdbarch
= get_sal_arch (*sal
);
6725 loc
->gdbarch
= b
->gdbarch
;
6726 loc
->requested_address
= sal
->pc
;
6727 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6728 loc
->requested_address
, b
->type
);
6729 loc
->pspace
= sal
->pspace
;
6730 gdb_assert (loc
->pspace
!= NULL
);
6731 loc
->section
= sal
->section
;
6733 set_breakpoint_location_function (loc
);
6738 /* Return 1 if LOC is pointing to a permanent breakpoint,
6739 return 0 otherwise. */
6742 bp_loc_is_permanent (struct bp_location
*loc
)
6746 const gdb_byte
*brk
;
6747 gdb_byte
*target_mem
;
6748 struct cleanup
*cleanup
;
6751 gdb_assert (loc
!= NULL
);
6753 addr
= loc
->address
;
6754 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6756 /* Software breakpoints unsupported? */
6760 target_mem
= alloca (len
);
6762 /* Enable the automatic memory restoration from breakpoints while
6763 we read the memory. Otherwise we could say about our temporary
6764 breakpoints they are permanent. */
6765 cleanup
= save_current_space_and_thread ();
6767 switch_to_program_space_and_thread (loc
->pspace
);
6768 make_show_memory_breakpoints_cleanup (0);
6770 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6771 && memcmp (target_mem
, brk
, len
) == 0)
6774 do_cleanups (cleanup
);
6781 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6782 as textual description of the location, and COND_STRING
6783 as condition expression. */
6786 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6787 struct symtabs_and_lines sals
, char *addr_string
,
6789 enum bptype type
, enum bpdisp disposition
,
6790 int thread
, int task
, int ignore_count
,
6791 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6793 struct breakpoint
*b
= NULL
;
6796 if (type
== bp_hardware_breakpoint
)
6798 int i
= hw_breakpoint_used_count ();
6799 int target_resources_ok
=
6800 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6802 if (target_resources_ok
== 0)
6803 error (_("No hardware breakpoint support in the target."));
6804 else if (target_resources_ok
< 0)
6805 error (_("Hardware breakpoints used exceeds limit."));
6808 gdb_assert (sals
.nelts
> 0);
6810 for (i
= 0; i
< sals
.nelts
; ++i
)
6812 struct symtab_and_line sal
= sals
.sals
[i
];
6813 struct bp_location
*loc
;
6817 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6819 loc_gdbarch
= gdbarch
;
6821 describe_other_breakpoints (loc_gdbarch
,
6822 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6827 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6828 set_breakpoint_count (breakpoint_count
+ 1);
6829 b
->number
= breakpoint_count
;
6833 b
->cond_string
= cond_string
;
6834 b
->ignore_count
= ignore_count
;
6835 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6836 b
->disposition
= disposition
;
6838 b
->pspace
= sals
.sals
[0].pspace
;
6840 if (enabled
&& b
->pspace
->executing_startup
6841 && (b
->type
== bp_breakpoint
6842 || b
->type
== bp_hardware_breakpoint
))
6843 b
->enable_state
= bp_startup_disabled
;
6849 loc
= add_location_to_breakpoint (b
, &sal
);
6852 if (bp_loc_is_permanent (loc
))
6853 make_breakpoint_permanent (b
);
6857 char *arg
= b
->cond_string
;
6858 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6860 error (_("Garbage %s follows condition"), arg
);
6865 b
->addr_string
= addr_string
;
6867 /* addr_string has to be used or breakpoint_re_set will delete
6870 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6876 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6877 elements to fill the void space. */
6879 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6881 int i
= index_to_remove
+1;
6882 int last_index
= sal
->nelts
-1;
6884 for (;i
<= last_index
; ++i
)
6885 sal
->sals
[i
-1] = sal
->sals
[i
];
6890 /* If appropriate, obtains all sals that correspond to the same file
6891 and line as SAL, in all program spaces. Users debugging with IDEs,
6892 will want to set a breakpoint at foo.c:line, and not really care
6893 about program spaces. This is done only if SAL does not have
6894 explicit PC and has line and file information. If we got just a
6895 single expanded sal, return the original.
6897 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6898 which the name of enclosing function is different from SAL. This
6899 makes sure that if we have breakpoint originally set in template
6900 instantiation, say foo<int>(), we won't expand SAL to locations at
6901 the same line in all existing instantiations of 'foo'. */
6903 static struct symtabs_and_lines
6904 expand_line_sal_maybe (struct symtab_and_line sal
)
6906 struct symtabs_and_lines expanded
;
6907 CORE_ADDR original_pc
= sal
.pc
;
6908 char *original_function
= NULL
;
6911 struct cleanup
*old_chain
;
6913 /* If we have explicit pc, don't expand.
6914 If we have no line number, we can't expand. */
6915 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6918 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6919 expanded
.sals
[0] = sal
;
6925 old_chain
= save_current_space_and_thread ();
6927 switch_to_program_space_and_thread (sal
.pspace
);
6929 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6931 /* Note that expand_line_sal visits *all* program spaces. */
6932 expanded
= expand_line_sal (sal
);
6934 if (expanded
.nelts
== 1)
6936 /* We had one sal, we got one sal. Return that sal, adjusting it
6937 past the function prologue if necessary. */
6938 xfree (expanded
.sals
);
6940 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6941 sal
.pc
= original_pc
;
6942 expanded
.sals
[0] = sal
;
6943 skip_prologue_sal (&expanded
.sals
[0]);
6944 do_cleanups (old_chain
);
6948 if (!sal
.explicit_line
)
6950 CORE_ADDR func_addr
, func_end
;
6951 for (i
= 0; i
< expanded
.nelts
; ++i
)
6953 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6954 char *this_function
;
6956 /* We need to switch threads as well since we're about to
6958 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6960 if (find_pc_partial_function (pc
, &this_function
,
6961 &func_addr
, &func_end
))
6964 && strcmp (this_function
, original_function
) != 0)
6966 remove_sal (&expanded
, i
);
6973 /* Skip the function prologue if necessary. */
6974 for (i
= 0; i
< expanded
.nelts
; ++i
)
6975 skip_prologue_sal (&expanded
.sals
[i
]);
6977 do_cleanups (old_chain
);
6979 if (expanded
.nelts
<= 1)
6981 /* This is un ugly workaround. If we get zero
6982 expanded sals then something is really wrong.
6983 Fix that by returnign the original sal. */
6984 xfree (expanded
.sals
);
6986 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6987 sal
.pc
= original_pc
;
6988 expanded
.sals
[0] = sal
;
6995 for (i
= 0; i
< expanded
.nelts
; ++i
)
6996 if (expanded
.sals
[i
].pc
== original_pc
)
7007 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7008 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7009 value. COND_STRING, if not NULL, specified the condition to be
7010 used for all breakpoints. Essentially the only case where
7011 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7012 function. In that case, it's still not possible to specify
7013 separate conditions for different overloaded functions, so
7014 we take just a single condition string.
7016 NOTE: If the function succeeds, the caller is expected to cleanup
7017 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7018 array contents). If the function fails (error() is called), the
7019 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7020 COND and SALS arrays and each of those arrays contents. */
7023 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7024 struct symtabs_and_lines sals
, char **addr_string
,
7026 enum bptype type
, enum bpdisp disposition
,
7027 int thread
, int task
, int ignore_count
,
7028 struct breakpoint_ops
*ops
, int from_tty
,
7032 for (i
= 0; i
< sals
.nelts
; ++i
)
7034 struct symtabs_and_lines expanded
=
7035 expand_line_sal_maybe (sals
.sals
[i
]);
7037 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7038 cond_string
, type
, disposition
,
7039 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7043 /* Parse ARG which is assumed to be a SAL specification possibly
7044 followed by conditionals. On return, SALS contains an array of SAL
7045 addresses found. ADDR_STRING contains a vector of (canonical)
7046 address strings. ARG points to the end of the SAL. */
7049 parse_breakpoint_sals (char **address
,
7050 struct symtabs_and_lines
*sals
,
7051 char ***addr_string
,
7054 char *addr_start
= *address
;
7055 *addr_string
= NULL
;
7056 /* If no arg given, or if first arg is 'if ', use the default
7058 if ((*address
) == NULL
7059 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7061 if (default_breakpoint_valid
)
7063 struct symtab_and_line sal
;
7064 init_sal (&sal
); /* initialize to zeroes */
7065 sals
->sals
= (struct symtab_and_line
*)
7066 xmalloc (sizeof (struct symtab_and_line
));
7067 sal
.pc
= default_breakpoint_address
;
7068 sal
.line
= default_breakpoint_line
;
7069 sal
.symtab
= default_breakpoint_symtab
;
7070 sal
.pspace
= default_breakpoint_pspace
;
7071 sal
.section
= find_pc_overlay (sal
.pc
);
7073 /* "break" without arguments is equivalent to "break *PC" where PC is
7074 the default_breakpoint_address. So make sure to set
7075 sal.explicit_pc to prevent GDB from trying to expand the list of
7076 sals to include all other instances with the same symtab and line.
7078 sal
.explicit_pc
= 1;
7080 sals
->sals
[0] = sal
;
7084 error (_("No default breakpoint address now."));
7088 /* Force almost all breakpoints to be in terms of the
7089 current_source_symtab (which is decode_line_1's default). This
7090 should produce the results we want almost all of the time while
7091 leaving default_breakpoint_* alone.
7092 ObjC: However, don't match an Objective-C method name which
7093 may have a '+' or '-' succeeded by a '[' */
7095 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7097 if (default_breakpoint_valid
7099 || ((strchr ("+-", (*address
)[0]) != NULL
)
7100 && ((*address
)[1] != '['))))
7101 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7102 default_breakpoint_line
, addr_string
,
7105 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7106 addr_string
, not_found_ptr
);
7108 /* For any SAL that didn't have a canonical string, fill one in. */
7109 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7110 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7111 if (addr_start
!= (*address
))
7114 for (i
= 0; i
< sals
->nelts
; i
++)
7116 /* Add the string if not present. */
7117 if ((*addr_string
)[i
] == NULL
)
7118 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7124 /* Convert each SAL into a real PC. Verify that the PC can be
7125 inserted as a breakpoint. If it can't throw an error. */
7128 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7132 for (i
= 0; i
< sals
->nelts
; i
++)
7133 resolve_sal_pc (&sals
->sals
[i
]);
7136 /* Fast tracepoints may have restrictions on valid locations. For
7137 instance, a fast tracepoint using a jump instead of a trap will
7138 likely have to overwrite more bytes than a trap would, and so can
7139 only be placed where the instruction is longer than the jump, or a
7140 multi-instruction sequence does not have a jump into the middle of
7144 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7145 struct symtabs_and_lines
*sals
)
7148 struct symtab_and_line
*sal
;
7150 struct cleanup
*old_chain
;
7152 for (i
= 0; i
< sals
->nelts
; i
++)
7154 sal
= &sals
->sals
[i
];
7156 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7158 old_chain
= make_cleanup (xfree
, msg
);
7161 error (_("May not have a fast tracepoint at 0x%s%s"),
7162 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7164 do_cleanups (old_chain
);
7169 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7171 struct captured_parse_breakpoint_args
*args
= data
;
7173 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7174 args
->not_found_ptr
);
7177 /* Given TOK, a string specification of condition and thread, as
7178 accepted by the 'break' command, extract the condition
7179 string and thread number and set *COND_STRING and *THREAD.
7180 PC identifies the context at which the condition should be parsed.
7181 If no condition is found, *COND_STRING is set to NULL.
7182 If no thread is found, *THREAD is set to -1. */
7184 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7185 char **cond_string
, int *thread
, int *task
)
7187 *cond_string
= NULL
;
7193 char *cond_start
= NULL
;
7194 char *cond_end
= NULL
;
7195 while (*tok
== ' ' || *tok
== '\t')
7200 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7203 toklen
= end_tok
- tok
;
7205 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7207 struct expression
*expr
;
7209 tok
= cond_start
= end_tok
+ 1;
7210 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7213 *cond_string
= savestring (cond_start
,
7214 cond_end
- cond_start
);
7216 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7222 *thread
= strtol (tok
, &tok
, 0);
7224 error (_("Junk after thread keyword."));
7225 if (!valid_thread_id (*thread
))
7226 error (_("Unknown thread %d."), *thread
);
7228 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7234 *task
= strtol (tok
, &tok
, 0);
7236 error (_("Junk after task keyword."));
7237 if (!valid_task_id (*task
))
7238 error (_("Unknown task %d."), *task
);
7241 error (_("Junk at end of arguments."));
7245 /* Set a breakpoint. This function is shared between CLI and MI
7246 functions for setting a breakpoint. This function has two major
7247 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7248 parameter. If non-zero, the function will parse arg, extracting
7249 breakpoint location, address and thread. Otherwise, ARG is just the
7250 location of breakpoint, with condition and thread specified by the
7251 COND_STRING and THREAD parameters. Returns true if any breakpoint
7252 was created; false otherwise. */
7255 create_breakpoint (struct gdbarch
*gdbarch
,
7256 char *arg
, char *cond_string
, int thread
,
7257 int parse_condition_and_thread
,
7258 int tempflag
, int hardwareflag
, int traceflag
,
7260 enum auto_boolean pending_break_support
,
7261 struct breakpoint_ops
*ops
,
7265 struct gdb_exception e
;
7266 struct symtabs_and_lines sals
;
7267 struct symtab_and_line pending_sal
;
7270 char *addr_start
= arg
;
7272 struct cleanup
*old_chain
;
7273 struct cleanup
*bkpt_chain
= NULL
;
7274 struct captured_parse_breakpoint_args parse_args
;
7278 enum bptype type_wanted
;
7280 int prev_bkpt_count
= breakpoint_count
;
7286 parse_args
.arg_p
= &arg
;
7287 parse_args
.sals_p
= &sals
;
7288 parse_args
.addr_string_p
= &addr_string
;
7289 parse_args
.not_found_ptr
= ¬_found
;
7291 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7292 &parse_args
, RETURN_MASK_ALL
);
7294 /* If caller is interested in rc value from parse, set value. */
7298 throw_exception (e
);
7302 case NOT_FOUND_ERROR
:
7304 /* If pending breakpoint support is turned off, throw
7307 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7308 throw_exception (e
);
7310 exception_print (gdb_stderr
, e
);
7312 /* If pending breakpoint support is auto query and the user
7313 selects no, then simply return the error code. */
7314 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7315 && !nquery ("Make breakpoint pending on future shared library load? "))
7318 /* At this point, either the user was queried about setting
7319 a pending breakpoint and selected yes, or pending
7320 breakpoint behavior is on and thus a pending breakpoint
7321 is defaulted on behalf of the user. */
7322 copy_arg
= xstrdup (addr_start
);
7323 addr_string
= ©_arg
;
7325 sals
.sals
= &pending_sal
;
7330 throw_exception (e
);
7337 /* Create a chain of things that always need to be cleaned up. */
7338 old_chain
= make_cleanup (null_cleanup
, 0);
7342 /* Make sure that all storage allocated to SALS gets freed. */
7343 make_cleanup (xfree
, sals
.sals
);
7345 /* Cleanup the addr_string array but not its contents. */
7346 make_cleanup (xfree
, addr_string
);
7349 /* ----------------------------- SNIP -----------------------------
7350 Anything added to the cleanup chain beyond this point is assumed
7351 to be part of a breakpoint. If the breakpoint create succeeds
7352 then the memory is not reclaimed. */
7353 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7355 /* Mark the contents of the addr_string for cleanup. These go on
7356 the bkpt_chain and only occur if the breakpoint create fails. */
7357 for (i
= 0; i
< sals
.nelts
; i
++)
7359 if (addr_string
[i
] != NULL
)
7360 make_cleanup (xfree
, addr_string
[i
]);
7363 /* Resolve all line numbers to PC's and verify that the addresses
7364 are ok for the target. */
7366 breakpoint_sals_to_pc (&sals
, addr_start
);
7368 type_wanted
= (traceflag
7369 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7370 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7372 /* Fast tracepoints may have additional restrictions on location. */
7373 if (type_wanted
== bp_fast_tracepoint
)
7374 check_fast_tracepoint_sals (gdbarch
, &sals
);
7376 /* Verify that condition can be parsed, before setting any
7377 breakpoints. Allocate a separate condition expression for each
7381 if (parse_condition_and_thread
)
7383 /* Here we only parse 'arg' to separate condition
7384 from thread number, so parsing in context of first
7385 sal is OK. When setting the breakpoint we'll
7386 re-parse it in context of each sal. */
7389 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7392 make_cleanup (xfree
, cond_string
);
7396 /* Create a private copy of condition string. */
7399 cond_string
= xstrdup (cond_string
);
7400 make_cleanup (xfree
, cond_string
);
7403 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7404 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7405 thread
, task
, ignore_count
, ops
, from_tty
,
7410 struct symtab_and_line sal
= {0};
7411 struct breakpoint
*b
;
7413 make_cleanup (xfree
, copy_arg
);
7415 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7416 set_breakpoint_count (breakpoint_count
+ 1);
7417 b
->number
= breakpoint_count
;
7419 b
->addr_string
= addr_string
[0];
7420 b
->cond_string
= NULL
;
7421 b
->ignore_count
= ignore_count
;
7422 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7423 b
->condition_not_parsed
= 1;
7425 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7426 b
->pspace
= current_program_space
;
7428 if (enabled
&& b
->pspace
->executing_startup
7429 && (b
->type
== bp_breakpoint
7430 || b
->type
== bp_hardware_breakpoint
))
7431 b
->enable_state
= bp_startup_disabled
;
7438 warning (_("Multiple breakpoints were set.\n"
7439 "Use the \"delete\" command to delete unwanted breakpoints."));
7440 prev_breakpoint_count
= prev_bkpt_count
;
7443 /* That's it. Discard the cleanups for data inserted into the
7445 discard_cleanups (bkpt_chain
);
7446 /* But cleanup everything else. */
7447 do_cleanups (old_chain
);
7449 /* error call may happen here - have BKPT_CHAIN already discarded. */
7450 update_global_location_list (1);
7455 /* Set a breakpoint.
7456 ARG is a string describing breakpoint address,
7457 condition, and thread.
7458 FLAG specifies if a breakpoint is hardware on,
7459 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7463 break_command_1 (char *arg
, int flag
, int from_tty
)
7465 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7466 int tempflag
= flag
& BP_TEMPFLAG
;
7468 create_breakpoint (get_current_arch (),
7470 NULL
, 0, 1 /* parse arg */,
7471 tempflag
, hardwareflag
, 0 /* traceflag */,
7472 0 /* Ignore count */,
7473 pending_break_support
,
7474 NULL
/* breakpoint_ops */,
7481 /* Helper function for break_command_1 and disassemble_command. */
7484 resolve_sal_pc (struct symtab_and_line
*sal
)
7488 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7490 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7491 error (_("No line %d in file \"%s\"."),
7492 sal
->line
, sal
->symtab
->filename
);
7495 /* If this SAL corresponds to a breakpoint inserted using
7496 a line number, then skip the function prologue if necessary. */
7497 if (sal
->explicit_line
)
7498 skip_prologue_sal (sal
);
7501 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7503 struct blockvector
*bv
;
7507 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7510 sym
= block_linkage_function (b
);
7513 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7514 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7518 /* It really is worthwhile to have the section, so we'll just
7519 have to look harder. This case can be executed if we have
7520 line numbers but no functions (as can happen in assembly
7523 struct minimal_symbol
*msym
;
7524 struct cleanup
*old_chain
= save_current_space_and_thread ();
7526 switch_to_program_space_and_thread (sal
->pspace
);
7528 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7530 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7532 do_cleanups (old_chain
);
7539 break_command (char *arg
, int from_tty
)
7541 break_command_1 (arg
, 0, from_tty
);
7545 tbreak_command (char *arg
, int from_tty
)
7547 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7551 hbreak_command (char *arg
, int from_tty
)
7553 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7557 thbreak_command (char *arg
, int from_tty
)
7559 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7563 stop_command (char *arg
, int from_tty
)
7565 printf_filtered (_("Specify the type of breakpoint to set.\n\
7566 Usage: stop in <function | address>\n\
7567 stop at <line>\n"));
7571 stopin_command (char *arg
, int from_tty
)
7575 if (arg
== (char *) NULL
)
7577 else if (*arg
!= '*')
7582 /* look for a ':'. If this is a line number specification, then
7583 say it is bad, otherwise, it should be an address or
7584 function/method name */
7585 while (*argptr
&& !hasColon
)
7587 hasColon
= (*argptr
== ':');
7592 badInput
= (*argptr
!= ':'); /* Not a class::method */
7594 badInput
= isdigit (*arg
); /* a simple line number */
7598 printf_filtered (_("Usage: stop in <function | address>\n"));
7600 break_command_1 (arg
, 0, from_tty
);
7604 stopat_command (char *arg
, int from_tty
)
7608 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7615 /* look for a ':'. If there is a '::' then get out, otherwise
7616 it is probably a line number. */
7617 while (*argptr
&& !hasColon
)
7619 hasColon
= (*argptr
== ':');
7624 badInput
= (*argptr
== ':'); /* we have class::method */
7626 badInput
= !isdigit (*arg
); /* not a line number */
7630 printf_filtered (_("Usage: stop at <line>\n"));
7632 break_command_1 (arg
, 0, from_tty
);
7635 /* accessflag: hw_write: watch write,
7636 hw_read: watch read,
7637 hw_access: watch access (read or write) */
7639 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7641 struct gdbarch
*gdbarch
= get_current_arch ();
7642 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7643 struct expression
*exp
;
7644 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7645 struct value
*val
, *mark
;
7646 struct frame_info
*frame
;
7647 char *exp_start
= NULL
;
7648 char *exp_end
= NULL
;
7649 char *tok
, *id_tok_start
, *end_tok
;
7651 char *cond_start
= NULL
;
7652 char *cond_end
= NULL
;
7653 int i
, other_type_used
, target_resources_ok
= 0;
7654 enum bptype bp_type
;
7658 /* Make sure that we actually have parameters to parse. */
7659 if (arg
!= NULL
&& arg
[0] != '\0')
7661 toklen
= strlen (arg
); /* Size of argument list. */
7663 /* Points tok to the end of the argument list. */
7664 tok
= arg
+ toklen
- 1;
7666 /* Go backwards in the parameters list. Skip the last parameter.
7667 If we're expecting a 'thread <thread_num>' parameter, this should
7668 be the thread identifier. */
7669 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7671 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7674 /* Points end_tok to the beginning of the last token. */
7675 id_tok_start
= tok
+ 1;
7677 /* Go backwards in the parameters list. Skip one more parameter.
7678 If we're expecting a 'thread <thread_num>' parameter, we should
7679 reach a "thread" token. */
7680 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7685 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7688 /* Move the pointer forward to skip the whitespace and
7689 calculate the length of the token. */
7691 toklen
= end_tok
- tok
;
7693 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7695 /* At this point we've found a "thread" token, which means
7696 the user is trying to set a watchpoint that triggers
7697 only in a specific thread. */
7700 /* Extract the thread ID from the next token. */
7701 thread
= strtol (id_tok_start
, &endp
, 0);
7703 /* Check if the user provided a valid numeric value for the
7705 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7706 error (_("Invalid thread ID specification %s."), id_tok_start
);
7708 /* Check if the thread actually exists. */
7709 if (!valid_thread_id (thread
))
7710 error (_("Unknown thread %d."), thread
);
7712 /* Truncate the string and get rid of the thread <thread_num>
7713 parameter before the parameter list is parsed by the
7714 evaluate_expression() function. */
7719 /* Parse the rest of the arguments. */
7720 innermost_block
= NULL
;
7722 exp
= parse_exp_1 (&arg
, 0, 0);
7724 /* Remove trailing whitespace from the expression before saving it.
7725 This makes the eventual display of the expression string a bit
7727 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7730 exp_valid_block
= innermost_block
;
7731 mark
= value_mark ();
7732 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7734 release_value (val
);
7737 while (*tok
== ' ' || *tok
== '\t')
7741 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7744 toklen
= end_tok
- tok
;
7745 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7747 struct expression
*cond
;
7749 innermost_block
= NULL
;
7750 tok
= cond_start
= end_tok
+ 1;
7751 cond
= parse_exp_1 (&tok
, 0, 0);
7753 /* The watchpoint expression may not be local, but the condition
7754 may still be. E.g.: `watch global if local > 0'. */
7755 cond_exp_valid_block
= innermost_block
;
7761 error (_("Junk at end of command."));
7763 if (accessflag
== hw_read
)
7764 bp_type
= bp_read_watchpoint
;
7765 else if (accessflag
== hw_access
)
7766 bp_type
= bp_access_watchpoint
;
7768 bp_type
= bp_hardware_watchpoint
;
7770 mem_cnt
= can_use_hardware_watchpoint (val
);
7771 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7772 error (_("Expression cannot be implemented with read/access watchpoint."));
7775 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7776 target_resources_ok
=
7777 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7779 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7780 error (_("Target does not support this type of hardware watchpoint."));
7782 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7783 error (_("Target can only support one kind of HW watchpoint at a time."));
7786 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7787 watchpoint could not be set. */
7788 if (!mem_cnt
|| target_resources_ok
<= 0)
7789 bp_type
= bp_watchpoint
;
7791 frame
= block_innermost_frame (exp_valid_block
);
7793 /* If the expression is "local", then set up a "watchpoint scope"
7794 breakpoint at the point where we've left the scope of the watchpoint
7795 expression. Create the scope breakpoint before the watchpoint, so
7796 that we will encounter it first in bpstat_stop_status. */
7797 if (exp_valid_block
&& frame
)
7799 if (frame_id_p (frame_unwind_caller_id (frame
)))
7802 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7803 frame_unwind_caller_pc (frame
),
7804 bp_watchpoint_scope
);
7806 scope_breakpoint
->enable_state
= bp_enabled
;
7808 /* Automatically delete the breakpoint when it hits. */
7809 scope_breakpoint
->disposition
= disp_del
;
7811 /* Only break in the proper frame (help with recursion). */
7812 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7814 /* Set the address at which we will stop. */
7815 scope_breakpoint
->loc
->gdbarch
7816 = frame_unwind_caller_arch (frame
);
7817 scope_breakpoint
->loc
->requested_address
7818 = frame_unwind_caller_pc (frame
);
7819 scope_breakpoint
->loc
->address
7820 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7821 scope_breakpoint
->loc
->requested_address
,
7822 scope_breakpoint
->type
);
7826 /* Now set up the breakpoint. */
7827 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7828 set_breakpoint_count (breakpoint_count
+ 1);
7829 b
->number
= breakpoint_count
;
7831 b
->disposition
= disp_donttouch
;
7833 b
->exp_valid_block
= exp_valid_block
;
7834 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7835 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7839 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7845 b
->watchpoint_frame
= get_frame_id (frame
);
7846 b
->watchpoint_thread
= inferior_ptid
;
7850 b
->watchpoint_frame
= null_frame_id
;
7851 b
->watchpoint_thread
= null_ptid
;
7854 if (scope_breakpoint
!= NULL
)
7856 /* The scope breakpoint is related to the watchpoint. We will
7857 need to act on them together. */
7858 b
->related_breakpoint
= scope_breakpoint
;
7859 scope_breakpoint
->related_breakpoint
= b
;
7862 value_free_to_mark (mark
);
7864 /* Finally update the new watchpoint. This creates the locations
7865 that should be inserted. */
7866 update_watchpoint (b
, 1);
7869 update_global_location_list (1);
7872 /* Return count of locations need to be watched and can be handled
7873 in hardware. If the watchpoint can not be handled
7874 in hardware return zero. */
7877 can_use_hardware_watchpoint (struct value
*v
)
7879 int found_memory_cnt
= 0;
7880 struct value
*head
= v
;
7882 /* Did the user specifically forbid us to use hardware watchpoints? */
7883 if (!can_use_hw_watchpoints
)
7886 /* Make sure that the value of the expression depends only upon
7887 memory contents, and values computed from them within GDB. If we
7888 find any register references or function calls, we can't use a
7889 hardware watchpoint.
7891 The idea here is that evaluating an expression generates a series
7892 of values, one holding the value of every subexpression. (The
7893 expression a*b+c has five subexpressions: a, b, a*b, c, and
7894 a*b+c.) GDB's values hold almost enough information to establish
7895 the criteria given above --- they identify memory lvalues,
7896 register lvalues, computed values, etcetera. So we can evaluate
7897 the expression, and then scan the chain of values that leaves
7898 behind to decide whether we can detect any possible change to the
7899 expression's final value using only hardware watchpoints.
7901 However, I don't think that the values returned by inferior
7902 function calls are special in any way. So this function may not
7903 notice that an expression involving an inferior function call
7904 can't be watched with hardware watchpoints. FIXME. */
7905 for (; v
; v
= value_next (v
))
7907 if (VALUE_LVAL (v
) == lval_memory
)
7910 /* A lazy memory lvalue is one that GDB never needed to fetch;
7911 we either just used its address (e.g., `a' in `a.b') or
7912 we never needed it at all (e.g., `a' in `a,b'). */
7916 /* Ahh, memory we actually used! Check if we can cover
7917 it with hardware watchpoints. */
7918 struct type
*vtype
= check_typedef (value_type (v
));
7920 /* We only watch structs and arrays if user asked for it
7921 explicitly, never if they just happen to appear in a
7922 middle of some value chain. */
7924 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7925 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7927 CORE_ADDR vaddr
= value_address (v
);
7928 int len
= TYPE_LENGTH (value_type (v
));
7930 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7937 else if (VALUE_LVAL (v
) != not_lval
7938 && deprecated_value_modifiable (v
) == 0)
7939 return 0; /* ??? What does this represent? */
7940 else if (VALUE_LVAL (v
) == lval_register
)
7941 return 0; /* cannot watch a register with a HW watchpoint */
7944 /* The expression itself looks suitable for using a hardware
7945 watchpoint, but give the target machine a chance to reject it. */
7946 return found_memory_cnt
;
7950 watch_command_wrapper (char *arg
, int from_tty
)
7952 watch_command (arg
, from_tty
);
7956 watch_command (char *arg
, int from_tty
)
7958 watch_command_1 (arg
, hw_write
, from_tty
);
7962 rwatch_command_wrapper (char *arg
, int from_tty
)
7964 rwatch_command (arg
, from_tty
);
7968 rwatch_command (char *arg
, int from_tty
)
7970 watch_command_1 (arg
, hw_read
, from_tty
);
7974 awatch_command_wrapper (char *arg
, int from_tty
)
7976 awatch_command (arg
, from_tty
);
7980 awatch_command (char *arg
, int from_tty
)
7982 watch_command_1 (arg
, hw_access
, from_tty
);
7986 /* Helper routines for the until_command routine in infcmd.c. Here
7987 because it uses the mechanisms of breakpoints. */
7989 struct until_break_command_continuation_args
7991 struct breakpoint
*breakpoint
;
7992 struct breakpoint
*breakpoint2
;
7995 /* This function is called by fetch_inferior_event via the
7996 cmd_continuation pointer, to complete the until command. It takes
7997 care of cleaning up the temporary breakpoints set up by the until
8000 until_break_command_continuation (void *arg
)
8002 struct until_break_command_continuation_args
*a
= arg
;
8004 delete_breakpoint (a
->breakpoint
);
8006 delete_breakpoint (a
->breakpoint2
);
8010 until_break_command (char *arg
, int from_tty
, int anywhere
)
8012 struct symtabs_and_lines sals
;
8013 struct symtab_and_line sal
;
8014 struct frame_info
*frame
= get_selected_frame (NULL
);
8015 struct breakpoint
*breakpoint
;
8016 struct breakpoint
*breakpoint2
= NULL
;
8017 struct cleanup
*old_chain
;
8019 clear_proceed_status ();
8021 /* Set a breakpoint where the user wants it and at return from
8024 if (default_breakpoint_valid
)
8025 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8026 default_breakpoint_line
, (char ***) NULL
, NULL
);
8028 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8029 0, (char ***) NULL
, NULL
);
8031 if (sals
.nelts
!= 1)
8032 error (_("Couldn't get information on specified line."));
8035 xfree (sals
.sals
); /* malloc'd, so freed */
8038 error (_("Junk at end of arguments."));
8040 resolve_sal_pc (&sal
);
8043 /* If the user told us to continue until a specified location,
8044 we don't specify a frame at which we need to stop. */
8045 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8046 null_frame_id
, bp_until
);
8048 /* Otherwise, specify the selected frame, because we want to stop only
8049 at the very same frame. */
8050 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8051 get_stack_frame_id (frame
),
8054 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8056 /* Keep within the current frame, or in frames called by the current
8059 if (frame_id_p (frame_unwind_caller_id (frame
)))
8061 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8062 sal
.pc
= frame_unwind_caller_pc (frame
);
8063 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8065 frame_unwind_caller_id (frame
),
8067 make_cleanup_delete_breakpoint (breakpoint2
);
8070 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8072 /* If we are running asynchronously, and proceed call above has actually
8073 managed to start the target, arrange for breakpoints to be
8074 deleted when the target stops. Otherwise, we're already stopped and
8075 delete breakpoints via cleanup chain. */
8077 if (target_can_async_p () && is_running (inferior_ptid
))
8079 struct until_break_command_continuation_args
*args
;
8080 args
= xmalloc (sizeof (*args
));
8082 args
->breakpoint
= breakpoint
;
8083 args
->breakpoint2
= breakpoint2
;
8085 discard_cleanups (old_chain
);
8086 add_continuation (inferior_thread (),
8087 until_break_command_continuation
, args
,
8091 do_cleanups (old_chain
);
8095 ep_skip_leading_whitespace (char **s
)
8097 if ((s
== NULL
) || (*s
== NULL
))
8099 while (isspace (**s
))
8103 /* This function attempts to parse an optional "if <cond>" clause
8104 from the arg string. If one is not found, it returns NULL.
8106 Else, it returns a pointer to the condition string. (It does not
8107 attempt to evaluate the string against a particular block.) And,
8108 it updates arg to point to the first character following the parsed
8109 if clause in the arg string. */
8112 ep_parse_optional_if_clause (char **arg
)
8116 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8119 /* Skip the "if" keyword. */
8122 /* Skip any extra leading whitespace, and record the start of the
8123 condition string. */
8124 ep_skip_leading_whitespace (arg
);
8127 /* Assume that the condition occupies the remainder of the arg string. */
8128 (*arg
) += strlen (cond_string
);
8133 /* Commands to deal with catching events, such as signals, exceptions,
8134 process start/exit, etc. */
8138 catch_fork_temporary
, catch_vfork_temporary
,
8139 catch_fork_permanent
, catch_vfork_permanent
8144 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8146 struct gdbarch
*gdbarch
= get_current_arch ();
8147 char *cond_string
= NULL
;
8148 catch_fork_kind fork_kind
;
8151 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8152 tempflag
= (fork_kind
== catch_fork_temporary
8153 || fork_kind
== catch_vfork_temporary
);
8157 ep_skip_leading_whitespace (&arg
);
8159 /* The allowed syntax is:
8161 catch [v]fork if <cond>
8163 First, check if there's an if clause. */
8164 cond_string
= ep_parse_optional_if_clause (&arg
);
8166 if ((*arg
!= '\0') && !isspace (*arg
))
8167 error (_("Junk at end of arguments."));
8169 /* If this target supports it, create a fork or vfork catchpoint
8170 and enable reporting of such events. */
8173 case catch_fork_temporary
:
8174 case catch_fork_permanent
:
8175 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8176 &catch_fork_breakpoint_ops
);
8178 case catch_vfork_temporary
:
8179 case catch_vfork_permanent
:
8180 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8181 &catch_vfork_breakpoint_ops
);
8184 error (_("unsupported or unknown fork kind; cannot catch it"));
8190 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8192 struct gdbarch
*gdbarch
= get_current_arch ();
8194 char *cond_string
= NULL
;
8196 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8200 ep_skip_leading_whitespace (&arg
);
8202 /* The allowed syntax is:
8204 catch exec if <cond>
8206 First, check if there's an if clause. */
8207 cond_string
= ep_parse_optional_if_clause (&arg
);
8209 if ((*arg
!= '\0') && !isspace (*arg
))
8210 error (_("Junk at end of arguments."));
8212 /* If this target supports it, create an exec catchpoint
8213 and enable reporting of such events. */
8214 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8215 &catch_exec_breakpoint_ops
);
8218 static enum print_stop_action
8219 print_exception_catchpoint (struct breakpoint
*b
)
8221 int bp_temp
, bp_throw
;
8223 annotate_catchpoint (b
->number
);
8225 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8226 if (b
->loc
->address
!= b
->loc
->requested_address
)
8227 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8230 bp_temp
= b
->disposition
== disp_del
;
8232 bp_temp
? "Temporary catchpoint "
8234 if (!ui_out_is_mi_like_p (uiout
))
8235 ui_out_field_int (uiout
, "bkptno", b
->number
);
8237 bp_throw
? " (exception thrown), "
8238 : " (exception caught), ");
8239 if (ui_out_is_mi_like_p (uiout
))
8241 ui_out_field_string (uiout
, "reason",
8242 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8243 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8244 ui_out_field_int (uiout
, "bkptno", b
->number
);
8246 return PRINT_SRC_AND_LOC
;
8250 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8252 struct value_print_options opts
;
8253 get_user_print_options (&opts
);
8254 if (opts
.addressprint
)
8257 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8258 ui_out_field_string (uiout
, "addr", "<PENDING>");
8260 ui_out_field_core_addr (uiout
, "addr",
8261 b
->loc
->gdbarch
, b
->loc
->address
);
8266 if (strstr (b
->addr_string
, "throw") != NULL
)
8267 ui_out_field_string (uiout
, "what", "exception throw");
8269 ui_out_field_string (uiout
, "what", "exception catch");
8273 print_mention_exception_catchpoint (struct breakpoint
*b
)
8278 bp_temp
= b
->disposition
== disp_del
;
8279 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8280 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8281 : _("Catchpoint "));
8282 ui_out_field_int (uiout
, "bkptno", b
->number
);
8283 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8287 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8290 NULL
, /* breakpoint_hit */
8291 print_exception_catchpoint
,
8292 print_one_exception_catchpoint
,
8293 print_mention_exception_catchpoint
8297 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8298 enum exception_event_kind ex_event
, int from_tty
)
8300 char *trigger_func_name
;
8302 if (ex_event
== EX_EVENT_CATCH
)
8303 trigger_func_name
= "__cxa_begin_catch";
8305 trigger_func_name
= "__cxa_throw";
8307 create_breakpoint (get_current_arch (),
8308 trigger_func_name
, cond_string
, -1,
8309 0 /* condition and thread are valid. */,
8312 AUTO_BOOLEAN_TRUE
/* pending */,
8313 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8319 /* Deal with "catch catch" and "catch throw" commands */
8322 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8323 int tempflag
, int from_tty
)
8325 char *cond_string
= NULL
;
8326 struct symtab_and_line
*sal
= NULL
;
8330 ep_skip_leading_whitespace (&arg
);
8332 cond_string
= ep_parse_optional_if_clause (&arg
);
8334 if ((*arg
!= '\0') && !isspace (*arg
))
8335 error (_("Junk at end of arguments."));
8337 if (ex_event
!= EX_EVENT_THROW
8338 && ex_event
!= EX_EVENT_CATCH
)
8339 error (_("Unsupported or unknown exception event; cannot catch it"));
8341 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8344 warning (_("Unsupported with this platform/compiler combination."));
8347 /* Implementation of "catch catch" command. */
8350 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8352 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8353 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8356 /* Implementation of "catch throw" command. */
8359 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8361 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8362 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8365 /* Create a breakpoint struct for Ada exception catchpoints. */
8368 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8369 struct symtab_and_line sal
,
8373 struct expression
*cond
,
8374 struct breakpoint_ops
*ops
,
8378 struct breakpoint
*b
;
8382 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8384 loc_gdbarch
= gdbarch
;
8386 describe_other_breakpoints (loc_gdbarch
,
8387 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8388 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8389 version for exception catchpoints, because two catchpoints
8390 used for different exception names will use the same address.
8391 In this case, a "breakpoint ... also set at..." warning is
8392 unproductive. Besides. the warning phrasing is also a bit
8393 inapropriate, we should use the word catchpoint, and tell
8394 the user what type of catchpoint it is. The above is good
8395 enough for now, though. */
8398 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8399 set_breakpoint_count (breakpoint_count
+ 1);
8401 b
->enable_state
= bp_enabled
;
8402 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8403 b
->number
= breakpoint_count
;
8404 b
->ignore_count
= 0;
8405 b
->loc
->cond
= cond
;
8406 b
->addr_string
= addr_string
;
8407 b
->language
= language_ada
;
8408 b
->cond_string
= cond_string
;
8409 b
->exp_string
= exp_string
;
8414 update_global_location_list (1);
8417 /* Implement the "catch exception" command. */
8420 catch_ada_exception_command (char *arg
, int from_tty
,
8421 struct cmd_list_element
*command
)
8423 struct gdbarch
*gdbarch
= get_current_arch ();
8425 struct symtab_and_line sal
;
8427 char *addr_string
= NULL
;
8428 char *exp_string
= NULL
;
8429 char *cond_string
= NULL
;
8430 struct expression
*cond
= NULL
;
8431 struct breakpoint_ops
*ops
= NULL
;
8433 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8437 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8438 &cond_string
, &cond
, &ops
);
8439 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8440 cond_string
, cond
, ops
, tempflag
,
8444 /* Cleanup function for a syscall filter list. */
8446 clean_up_filters (void *arg
)
8448 VEC(int) *iter
= *(VEC(int) **) arg
;
8449 VEC_free (int, iter
);
8452 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8453 filter list, or NULL if no filtering is required. */
8455 catch_syscall_split_args (char *arg
)
8457 VEC(int) *result
= NULL
;
8458 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8460 while (*arg
!= '\0')
8462 int i
, syscall_number
;
8467 /* Skip whitespace. */
8468 while (isspace (*arg
))
8471 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8472 cur_name
[i
] = arg
[i
];
8476 /* Check if the user provided a syscall name or a number. */
8477 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8478 if (*endptr
== '\0')
8479 get_syscall_by_number (syscall_number
, &s
);
8482 /* We have a name. Let's check if it's valid and convert it
8484 get_syscall_by_name (cur_name
, &s
);
8486 if (s
.number
== UNKNOWN_SYSCALL
)
8487 /* Here we have to issue an error instead of a warning, because
8488 GDB cannot do anything useful if there's no syscall number to
8490 error (_("Unknown syscall name '%s'."), cur_name
);
8493 /* Ok, it's valid. */
8494 VEC_safe_push (int, result
, s
.number
);
8497 discard_cleanups (cleanup
);
8501 /* Implement the "catch syscall" command. */
8504 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8509 struct gdbarch
*gdbarch
= get_current_arch ();
8511 /* Checking if the feature if supported. */
8512 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8513 error (_("The feature 'catch syscall' is not supported on \
8514 this architeture yet."));
8516 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8518 ep_skip_leading_whitespace (&arg
);
8520 /* We need to do this first "dummy" translation in order
8521 to get the syscall XML file loaded or, most important,
8522 to display a warning to the user if there's no XML file
8523 for his/her architecture. */
8524 get_syscall_by_number (0, &s
);
8526 /* The allowed syntax is:
8528 catch syscall <name | number> [<name | number> ... <name | number>]
8530 Let's check if there's a syscall name. */
8533 filter
= catch_syscall_split_args (arg
);
8537 create_syscall_event_catchpoint (tempflag
, filter
,
8538 &catch_syscall_breakpoint_ops
);
8541 /* Implement the "catch assert" command. */
8544 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8546 struct gdbarch
*gdbarch
= get_current_arch ();
8548 struct symtab_and_line sal
;
8549 char *addr_string
= NULL
;
8550 struct breakpoint_ops
*ops
= NULL
;
8552 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8556 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8557 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8558 ops
, tempflag
, from_tty
);
8562 catch_command (char *arg
, int from_tty
)
8564 error (_("Catch requires an event name."));
8569 tcatch_command (char *arg
, int from_tty
)
8571 error (_("Catch requires an event name."));
8574 /* Delete breakpoints by address or line. */
8577 clear_command (char *arg
, int from_tty
)
8579 struct breakpoint
*b
;
8580 VEC(breakpoint_p
) *found
= 0;
8583 struct symtabs_and_lines sals
;
8584 struct symtab_and_line sal
;
8589 sals
= decode_line_spec (arg
, 1);
8594 sals
.sals
= (struct symtab_and_line
*)
8595 xmalloc (sizeof (struct symtab_and_line
));
8596 make_cleanup (xfree
, sals
.sals
);
8597 init_sal (&sal
); /* initialize to zeroes */
8598 sal
.line
= default_breakpoint_line
;
8599 sal
.symtab
= default_breakpoint_symtab
;
8600 sal
.pc
= default_breakpoint_address
;
8601 sal
.pspace
= default_breakpoint_pspace
;
8602 if (sal
.symtab
== 0)
8603 error (_("No source file specified."));
8611 /* We don't call resolve_sal_pc here. That's not
8612 as bad as it seems, because all existing breakpoints
8613 typically have both file/line and pc set. So, if
8614 clear is given file/line, we can match this to existing
8615 breakpoint without obtaining pc at all.
8617 We only support clearing given the address explicitly
8618 present in breakpoint table. Say, we've set breakpoint
8619 at file:line. There were several PC values for that file:line,
8620 due to optimization, all in one block.
8621 We've picked one PC value. If "clear" is issued with another
8622 PC corresponding to the same file:line, the breakpoint won't
8623 be cleared. We probably can still clear the breakpoint, but
8624 since the other PC value is never presented to user, user
8625 can only find it by guessing, and it does not seem important
8628 /* For each line spec given, delete bps which correspond
8629 to it. Do it in two passes, solely to preserve the current
8630 behavior that from_tty is forced true if we delete more than
8634 for (i
= 0; i
< sals
.nelts
; i
++)
8636 /* If exact pc given, clear bpts at that pc.
8637 If line given (pc == 0), clear all bpts on specified line.
8638 If defaulting, clear all bpts on default line
8641 defaulting sal.pc != 0 tests to do
8646 1 0 <can't happen> */
8650 /* Find all matching breakpoints and add them to
8655 /* Are we going to delete b? */
8656 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
8658 struct bp_location
*loc
= b
->loc
;
8659 for (; loc
; loc
= loc
->next
)
8661 int pc_match
= sal
.pc
8662 && (loc
->pspace
== sal
.pspace
)
8663 && (loc
->address
== sal
.pc
)
8664 && (!section_is_overlay (loc
->section
)
8665 || loc
->section
== sal
.section
);
8666 int line_match
= ((default_match
|| (0 == sal
.pc
))
8667 && b
->source_file
!= NULL
8668 && sal
.symtab
!= NULL
8669 && sal
.pspace
== loc
->pspace
8670 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8671 && b
->line_number
== sal
.line
);
8672 if (pc_match
|| line_match
)
8681 VEC_safe_push(breakpoint_p
, found
, b
);
8684 /* Now go thru the 'found' chain and delete them. */
8685 if (VEC_empty(breakpoint_p
, found
))
8688 error (_("No breakpoint at %s."), arg
);
8690 error (_("No breakpoint at this line."));
8693 if (VEC_length(breakpoint_p
, found
) > 1)
8694 from_tty
= 1; /* Always report if deleted more than one */
8697 if (VEC_length(breakpoint_p
, found
) == 1)
8698 printf_unfiltered (_("Deleted breakpoint "));
8700 printf_unfiltered (_("Deleted breakpoints "));
8702 breakpoints_changed ();
8704 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8707 printf_unfiltered ("%d ", b
->number
);
8708 delete_breakpoint (b
);
8711 putchar_unfiltered ('\n');
8714 /* Delete breakpoint in BS if they are `delete' breakpoints and
8715 all breakpoints that are marked for deletion, whether hit or not.
8716 This is called after any breakpoint is hit, or after errors. */
8719 breakpoint_auto_delete (bpstat bs
)
8721 struct breakpoint
*b
, *temp
;
8723 for (; bs
; bs
= bs
->next
)
8724 if (bs
->breakpoint_at
8725 && bs
->breakpoint_at
->owner
8726 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8728 delete_breakpoint (bs
->breakpoint_at
->owner
);
8730 ALL_BREAKPOINTS_SAFE (b
, temp
)
8732 if (b
->disposition
== disp_del_at_next_stop
)
8733 delete_breakpoint (b
);
8737 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8738 Sort elements primarily by their ADDRESS (no matter what does
8739 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8740 first bp_permanent OWNERed elements and terciarily just ensuring the array
8741 is sorted stable way despite qsort being an instable algorithm. */
8744 bp_location_compare (const void *ap
, const void *bp
)
8746 struct bp_location
*a
= *(void **) ap
;
8747 struct bp_location
*b
= *(void **) bp
;
8748 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8749 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8751 if (a
->address
!= b
->address
)
8752 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8754 /* Sort permanent breakpoints first. */
8755 if (a_perm
!= b_perm
)
8756 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8758 /* Make the user-visible order stable across GDB runs. Locations of the same
8759 breakpoint can be sorted in arbitrary order. */
8761 if (a
->owner
->number
!= b
->owner
->number
)
8762 return (a
->owner
->number
> b
->owner
->number
)
8763 - (a
->owner
->number
< b
->owner
->number
);
8765 return (a
> b
) - (a
< b
);
8768 /* Set bp_location_placed_address_before_address_max and
8769 bp_location_shadow_len_after_address_max according to the current content of
8770 the bp_location array. */
8773 bp_location_target_extensions_update (void)
8775 struct bp_location
*bl
, **blp_tmp
;
8777 bp_location_placed_address_before_address_max
= 0;
8778 bp_location_shadow_len_after_address_max
= 0;
8780 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8782 CORE_ADDR start
, end
, addr
;
8784 if (!bp_location_has_shadow (bl
))
8787 start
= bl
->target_info
.placed_address
;
8788 end
= start
+ bl
->target_info
.shadow_len
;
8790 gdb_assert (bl
->address
>= start
);
8791 addr
= bl
->address
- start
;
8792 if (addr
> bp_location_placed_address_before_address_max
)
8793 bp_location_placed_address_before_address_max
= addr
;
8795 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8797 gdb_assert (bl
->address
< end
);
8798 addr
= end
- bl
->address
;
8799 if (addr
> bp_location_shadow_len_after_address_max
)
8800 bp_location_shadow_len_after_address_max
= addr
;
8804 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8805 into the inferior, only remove already-inserted locations that no
8806 longer should be inserted. Functions that delete a breakpoint or
8807 breakpoints should pass false, so that deleting a breakpoint
8808 doesn't have the side effect of inserting the locations of other
8809 breakpoints that are marked not-inserted, but should_be_inserted
8810 returns true on them.
8812 This behaviour is useful is situations close to tear-down -- e.g.,
8813 after an exec, while the target still has execution, but breakpoint
8814 shadows of the previous executable image should *NOT* be restored
8815 to the new image; or before detaching, where the target still has
8816 execution and wants to delete breakpoints from GDB's lists, and all
8817 breakpoints had already been removed from the inferior. */
8820 update_global_location_list (int should_insert
)
8822 struct breakpoint
*b
;
8823 struct bp_location
**locp
, *loc
;
8824 struct cleanup
*cleanups
;
8826 /* Used in the duplicates detection below. When iterating over all
8827 bp_locations, points to the first bp_location of a given address.
8828 Breakpoints and watchpoints of different types are never
8829 duplicates of each other. Keep one pointer for each type of
8830 breakpoint/watchpoint, so we only need to loop over all locations
8832 struct bp_location
*bp_loc_first
; /* breakpoint */
8833 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8834 struct bp_location
*awp_loc_first
; /* access watchpoint */
8835 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8837 /* Saved former bp_location array which we compare against the newly built
8838 bp_location from the current state of ALL_BREAKPOINTS. */
8839 struct bp_location
**old_location
, **old_locp
;
8840 unsigned old_location_count
;
8842 old_location
= bp_location
;
8843 old_location_count
= bp_location_count
;
8845 bp_location_count
= 0;
8846 cleanups
= make_cleanup (xfree
, old_location
);
8849 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8850 bp_location_count
++;
8852 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8855 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8857 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8858 bp_location_compare
);
8860 bp_location_target_extensions_update ();
8862 /* Identify bp_location instances that are no longer present in the new
8863 list, and therefore should be freed. Note that it's not necessary that
8864 those locations should be removed from inferior -- if there's another
8865 location at the same address (previously marked as duplicate),
8866 we don't need to remove/insert the location.
8868 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8869 former bp_location array state respectively. */
8872 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8875 struct bp_location
*old_loc
= *old_locp
;
8876 struct bp_location
**loc2p
;
8878 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8880 int found_object
= 0;
8881 /* Tells if the location should remain inserted in the target. */
8882 int keep_in_target
= 0;
8885 /* Skip LOCP entries which will definitely never be needed. Stop either
8886 at or being the one matching OLD_LOC. */
8887 while (locp
< bp_location
+ bp_location_count
8888 && (*locp
)->address
< old_loc
->address
)
8892 (loc2p
< bp_location
+ bp_location_count
8893 && (*loc2p
)->address
== old_loc
->address
);
8896 if (*loc2p
== old_loc
)
8903 /* If this location is no longer present, and inserted, look if there's
8904 maybe a new location at the same address. If so, mark that one
8905 inserted, and don't remove this one. This is needed so that we
8906 don't have a time window where a breakpoint at certain location is not
8909 if (old_loc
->inserted
)
8911 /* If the location is inserted now, we might have to remove it. */
8913 if (found_object
&& should_be_inserted (old_loc
))
8915 /* The location is still present in the location list, and still
8916 should be inserted. Don't do anything. */
8921 /* The location is either no longer present, or got disabled.
8922 See if there's another location at the same address, in which
8923 case we don't need to remove this one from the target. */
8925 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8928 (loc2p
< bp_location
+ bp_location_count
8929 && (*loc2p
)->address
== old_loc
->address
);
8932 struct bp_location
*loc2
= *loc2p
;
8934 if (breakpoint_locations_match (loc2
, old_loc
))
8936 /* For the sake of should_be_inserted.
8937 Duplicates check below will fix up this later. */
8938 loc2
->duplicate
= 0;
8940 /* Read watchpoint locations are switched to
8941 access watchpoints, if the former are not
8942 supported, but the latter are. */
8943 if (is_hardware_watchpoint (old_loc
->owner
))
8945 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8946 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8949 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8952 loc2
->target_info
= old_loc
->target_info
;
8961 if (!keep_in_target
)
8963 if (remove_breakpoint (old_loc
, mark_uninserted
))
8965 /* This is just about all we can do. We could keep this
8966 location on the global list, and try to remove it next
8967 time, but there's no particular reason why we will
8970 Note that at this point, old_loc->owner is still valid,
8971 as delete_breakpoint frees the breakpoint only
8972 after calling us. */
8973 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8974 old_loc
->owner
->number
);
8982 if (removed
&& non_stop
8983 && breakpoint_address_is_meaningful (old_loc
->owner
)
8984 && !is_hardware_watchpoint (old_loc
->owner
))
8986 /* This location was removed from the target. In
8987 non-stop mode, a race condition is possible where
8988 we've removed a breakpoint, but stop events for that
8989 breakpoint are already queued and will arrive later.
8990 We apply an heuristic to be able to distinguish such
8991 SIGTRAPs from other random SIGTRAPs: we keep this
8992 breakpoint location for a bit, and will retire it
8993 after we see some number of events. The theory here
8994 is that reporting of events should, "on the average",
8995 be fair, so after a while we'll see events from all
8996 threads that have anything of interest, and no longer
8997 need to keep this breakpoint location around. We
8998 don't hold locations forever so to reduce chances of
8999 mistaking a non-breakpoint SIGTRAP for a breakpoint
9002 The heuristic failing can be disastrous on
9003 decr_pc_after_break targets.
9005 On decr_pc_after_break targets, like e.g., x86-linux,
9006 if we fail to recognize a late breakpoint SIGTRAP,
9007 because events_till_retirement has reached 0 too
9008 soon, we'll fail to do the PC adjustment, and report
9009 a random SIGTRAP to the user. When the user resumes
9010 the inferior, it will most likely immediately crash
9011 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9012 corrupted, because of being resumed e.g., in the
9013 middle of a multi-byte instruction, or skipped a
9014 one-byte instruction. This was actually seen happen
9015 on native x86-linux, and should be less rare on
9016 targets that do not support new thread events, like
9017 remote, due to the heuristic depending on
9020 Mistaking a random SIGTRAP for a breakpoint trap
9021 causes similar symptoms (PC adjustment applied when
9022 it shouldn't), but then again, playing with SIGTRAPs
9023 behind the debugger's back is asking for trouble.
9025 Since hardware watchpoint traps are always
9026 distinguishable from other traps, so we don't need to
9027 apply keep hardware watchpoint moribund locations
9028 around. We simply always ignore hardware watchpoint
9029 traps we can no longer explain. */
9031 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9032 old_loc
->owner
= NULL
;
9034 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9037 free_bp_location (old_loc
);
9041 /* Rescan breakpoints at the same address and section, marking the
9042 first one as "first" and any others as "duplicates". This is so
9043 that the bpt instruction is only inserted once. If we have a
9044 permanent breakpoint at the same place as BPT, make that one the
9045 official one, and the rest as duplicates. Permanent breakpoints
9046 are sorted first for the same address.
9048 Do the same for hardware watchpoints, but also considering the
9049 watchpoint's type (regular/access/read) and length. */
9051 bp_loc_first
= NULL
;
9052 wp_loc_first
= NULL
;
9053 awp_loc_first
= NULL
;
9054 rwp_loc_first
= NULL
;
9055 ALL_BP_LOCATIONS (loc
, locp
)
9057 struct breakpoint
*b
= loc
->owner
;
9058 struct bp_location
**loc_first_p
;
9060 if (b
->enable_state
== bp_disabled
9061 || b
->enable_state
== bp_call_disabled
9062 || b
->enable_state
== bp_startup_disabled
9064 || loc
->shlib_disabled
9065 || !breakpoint_address_is_meaningful (b
)
9066 || is_tracepoint (b
))
9069 /* Permanent breakpoint should always be inserted. */
9070 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9071 internal_error (__FILE__
, __LINE__
,
9072 _("allegedly permanent breakpoint is not "
9073 "actually inserted"));
9075 if (b
->type
== bp_hardware_watchpoint
)
9076 loc_first_p
= &wp_loc_first
;
9077 else if (b
->type
== bp_read_watchpoint
)
9078 loc_first_p
= &rwp_loc_first
;
9079 else if (b
->type
== bp_access_watchpoint
)
9080 loc_first_p
= &awp_loc_first
;
9082 loc_first_p
= &bp_loc_first
;
9084 if (*loc_first_p
== NULL
9085 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9086 || !breakpoint_locations_match (loc
, *loc_first_p
))
9095 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9096 && b
->enable_state
!= bp_permanent
)
9097 internal_error (__FILE__
, __LINE__
,
9098 _("another breakpoint was inserted on top of "
9099 "a permanent breakpoint"));
9102 if (breakpoints_always_inserted_mode () && should_insert
9103 && (have_live_inferiors ()
9104 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9105 insert_breakpoint_locations ();
9107 do_cleanups (cleanups
);
9111 breakpoint_retire_moribund (void)
9113 struct bp_location
*loc
;
9116 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9117 if (--(loc
->events_till_retirement
) == 0)
9119 free_bp_location (loc
);
9120 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9126 update_global_location_list_nothrow (int inserting
)
9128 struct gdb_exception e
;
9129 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9130 update_global_location_list (inserting
);
9133 /* Clear BPT from a BPS. */
9135 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9138 for (bs
= bps
; bs
; bs
= bs
->next
)
9139 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9141 bs
->breakpoint_at
= NULL
;
9143 /* bs->commands will be freed later. */
9147 /* Callback for iterate_over_threads. */
9149 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9151 struct breakpoint
*bpt
= data
;
9152 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9156 /* Delete a breakpoint and clean up all traces of it in the data
9160 delete_breakpoint (struct breakpoint
*bpt
)
9162 struct breakpoint
*b
;
9163 struct bp_location
*loc
, *next
;
9165 gdb_assert (bpt
!= NULL
);
9167 /* Has this bp already been deleted? This can happen because multiple
9168 lists can hold pointers to bp's. bpstat lists are especial culprits.
9170 One example of this happening is a watchpoint's scope bp. When the
9171 scope bp triggers, we notice that the watchpoint is out of scope, and
9172 delete it. We also delete its scope bp. But the scope bp is marked
9173 "auto-deleting", and is already on a bpstat. That bpstat is then
9174 checked for auto-deleting bp's, which are deleted.
9176 A real solution to this problem might involve reference counts in bp's,
9177 and/or giving them pointers back to their referencing bpstat's, and
9178 teaching delete_breakpoint to only free a bp's storage when no more
9179 references were extent. A cheaper bandaid was chosen. */
9180 if (bpt
->type
== bp_none
)
9183 /* At least avoid this stale reference until the reference counting of
9184 breakpoints gets resolved. */
9185 if (bpt
->related_breakpoint
!= NULL
)
9187 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9188 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9189 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9190 bpt
->related_breakpoint
= NULL
;
9193 observer_notify_breakpoint_deleted (bpt
->number
);
9195 if (breakpoint_chain
== bpt
)
9196 breakpoint_chain
= bpt
->next
;
9201 b
->next
= bpt
->next
;
9205 decref_counted_command_line (&bpt
->commands
);
9206 xfree (bpt
->cond_string
);
9207 xfree (bpt
->cond_exp
);
9208 xfree (bpt
->addr_string
);
9210 xfree (bpt
->exp_string
);
9211 value_free (bpt
->val
);
9212 xfree (bpt
->source_file
);
9213 xfree (bpt
->exec_pathname
);
9214 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9216 /* Be sure no bpstat's are pointing at it after it's been freed. */
9217 /* FIXME, how can we find all bpstat's?
9218 We just check stop_bpstat for now. Note that we cannot just
9219 remove bpstats pointing at bpt from the stop_bpstat list
9220 entirely, as breakpoint commands are associated with the bpstat;
9221 if we remove it here, then the later call to
9222 bpstat_do_actions (&stop_bpstat);
9223 in event-top.c won't do anything, and temporary breakpoints
9224 with commands won't work. */
9226 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9228 /* Now that breakpoint is removed from breakpoint
9229 list, update the global location list. This
9230 will remove locations that used to belong to
9231 this breakpoint. Do this before freeing
9232 the breakpoint itself, since remove_breakpoint
9233 looks at location's owner. It might be better
9234 design to have location completely self-contained,
9235 but it's not the case now. */
9236 update_global_location_list (0);
9239 /* On the chance that someone will soon try again to delete this same
9240 bp, we mark it as deleted before freeing its storage. */
9241 bpt
->type
= bp_none
;
9247 do_delete_breakpoint_cleanup (void *b
)
9249 delete_breakpoint (b
);
9253 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9255 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9258 /* A callback for map_breakpoint_numbers that calls
9259 delete_breakpoint. */
9262 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9264 delete_breakpoint (b
);
9268 delete_command (char *arg
, int from_tty
)
9270 struct breakpoint
*b
, *temp
;
9276 int breaks_to_delete
= 0;
9278 /* Delete all breakpoints if no argument.
9279 Do not delete internal or call-dummy breakpoints, these
9280 have to be deleted with an explicit breakpoint number argument. */
9283 if (b
->type
!= bp_call_dummy
9284 && b
->type
!= bp_std_terminate
9285 && b
->type
!= bp_shlib_event
9286 && b
->type
!= bp_jit_event
9287 && b
->type
!= bp_thread_event
9288 && b
->type
!= bp_overlay_event
9289 && b
->type
!= bp_longjmp_master
9290 && b
->type
!= bp_std_terminate_master
9293 breaks_to_delete
= 1;
9298 /* Ask user only if there are some breakpoints to delete. */
9300 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9302 ALL_BREAKPOINTS_SAFE (b
, temp
)
9304 if (b
->type
!= bp_call_dummy
9305 && b
->type
!= bp_std_terminate
9306 && b
->type
!= bp_shlib_event
9307 && b
->type
!= bp_thread_event
9308 && b
->type
!= bp_jit_event
9309 && b
->type
!= bp_overlay_event
9310 && b
->type
!= bp_longjmp_master
9311 && b
->type
!= bp_std_terminate_master
9313 delete_breakpoint (b
);
9318 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9322 all_locations_are_pending (struct bp_location
*loc
)
9324 for (; loc
; loc
= loc
->next
)
9325 if (!loc
->shlib_disabled
)
9330 /* Subroutine of update_breakpoint_locations to simplify it.
9331 Return non-zero if multiple fns in list LOC have the same name.
9332 Null names are ignored. */
9335 ambiguous_names_p (struct bp_location
*loc
)
9337 struct bp_location
*l
;
9338 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9339 (int (*) (const void *, const void *)) streq
,
9340 NULL
, xcalloc
, xfree
);
9342 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9345 const char *name
= l
->function_name
;
9347 /* Allow for some names to be NULL, ignore them. */
9351 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9353 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9368 update_breakpoint_locations (struct breakpoint
*b
,
9369 struct symtabs_and_lines sals
)
9373 struct bp_location
*existing_locations
= b
->loc
;
9375 /* If there's no new locations, and all existing locations
9376 are pending, don't do anything. This optimizes
9377 the common case where all locations are in the same
9378 shared library, that was unloaded. We'd like to
9379 retain the location, so that when the library
9380 is loaded again, we don't loose the enabled/disabled
9381 status of the individual locations. */
9382 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9387 for (i
= 0; i
< sals
.nelts
; ++i
)
9389 struct bp_location
*new_loc
=
9390 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9392 /* Reparse conditions, they might contain references to the
9394 if (b
->cond_string
!= NULL
)
9396 struct gdb_exception e
;
9399 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9401 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9406 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9407 b
->number
, e
.message
);
9408 new_loc
->enabled
= 0;
9412 if (b
->source_file
!= NULL
)
9413 xfree (b
->source_file
);
9414 if (sals
.sals
[i
].symtab
== NULL
)
9415 b
->source_file
= NULL
;
9417 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9419 if (b
->line_number
== 0)
9420 b
->line_number
= sals
.sals
[i
].line
;
9423 /* Update locations of permanent breakpoints. */
9424 if (b
->enable_state
== bp_permanent
)
9425 make_breakpoint_permanent (b
);
9427 /* If possible, carry over 'disable' status from existing breakpoints. */
9429 struct bp_location
*e
= existing_locations
;
9430 /* If there are multiple breakpoints with the same function name,
9431 e.g. for inline functions, comparing function names won't work.
9432 Instead compare pc addresses; this is just a heuristic as things
9433 may have moved, but in practice it gives the correct answer
9434 often enough until a better solution is found. */
9435 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9437 for (; e
; e
= e
->next
)
9439 if (!e
->enabled
&& e
->function_name
)
9441 struct bp_location
*l
= b
->loc
;
9442 if (have_ambiguous_names
)
9444 for (; l
; l
= l
->next
)
9445 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9446 l
->pspace
->aspace
, l
->address
))
9454 for (; l
; l
= l
->next
)
9455 if (l
->function_name
9456 && strcmp (e
->function_name
, l
->function_name
) == 0)
9466 update_global_location_list (1);
9470 /* Reset a breakpoint given it's struct breakpoint * BINT.
9471 The value we return ends up being the return value from catch_errors.
9472 Unused in this case. */
9475 breakpoint_re_set_one (void *bint
)
9477 /* get past catch_errs */
9478 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9482 int *not_found_ptr
= ¬_found
;
9483 struct symtabs_and_lines sals
= {0};
9484 struct symtabs_and_lines expanded
= {0};
9486 enum enable_state save_enable
;
9487 struct gdb_exception e
;
9488 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9493 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9497 case bp_hardware_breakpoint
:
9499 case bp_fast_tracepoint
:
9500 /* Do not attempt to re-set breakpoints disabled during startup. */
9501 if (b
->enable_state
== bp_startup_disabled
)
9504 if (b
->addr_string
== NULL
)
9506 /* Anything without a string can't be re-set. */
9507 delete_breakpoint (b
);
9511 set_language (b
->language
);
9512 input_radix
= b
->input_radix
;
9515 save_current_space_and_thread ();
9516 switch_to_program_space_and_thread (b
->pspace
);
9518 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9520 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9525 int not_found_and_ok
= 0;
9526 /* For pending breakpoints, it's expected that parsing
9527 will fail until the right shared library is loaded.
9528 User has already told to create pending breakpoints and
9529 don't need extra messages. If breakpoint is in bp_shlib_disabled
9530 state, then user already saw the message about that breakpoint
9531 being disabled, and don't want to see more errors. */
9533 && (b
->condition_not_parsed
9534 || (b
->loc
&& b
->loc
->shlib_disabled
)
9535 || b
->enable_state
== bp_disabled
))
9536 not_found_and_ok
= 1;
9538 if (!not_found_and_ok
)
9540 /* We surely don't want to warn about the same breakpoint
9541 10 times. One solution, implemented here, is disable
9542 the breakpoint on error. Another solution would be to
9543 have separate 'warning emitted' flag. Since this
9544 happens only when a binary has changed, I don't know
9545 which approach is better. */
9546 b
->enable_state
= bp_disabled
;
9547 throw_exception (e
);
9553 gdb_assert (sals
.nelts
== 1);
9555 resolve_sal_pc (&sals
.sals
[0]);
9556 if (b
->condition_not_parsed
&& s
&& s
[0])
9558 char *cond_string
= 0;
9562 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9563 &cond_string
, &thread
, &task
);
9565 b
->cond_string
= cond_string
;
9568 b
->condition_not_parsed
= 0;
9571 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9574 make_cleanup (xfree
, sals
.sals
);
9575 update_breakpoint_locations (b
, expanded
);
9579 case bp_hardware_watchpoint
:
9580 case bp_read_watchpoint
:
9581 case bp_access_watchpoint
:
9582 /* Watchpoint can be either on expression using entirely global variables,
9583 or it can be on local variables.
9585 Watchpoints of the first kind are never auto-deleted, and even persist
9586 across program restarts. Since they can use variables from shared
9587 libraries, we need to reparse expression as libraries are loaded
9590 Watchpoints on local variables can also change meaning as result
9591 of solib event. For example, if a watchpoint uses both a local and
9592 a global variables in expression, it's a local watchpoint, but
9593 unloading of a shared library will make the expression invalid.
9594 This is not a very common use case, but we still re-evaluate
9595 expression, to avoid surprises to the user.
9597 Note that for local watchpoints, we re-evaluate it only if
9598 watchpoints frame id is still valid. If it's not, it means
9599 the watchpoint is out of scope and will be deleted soon. In fact,
9600 I'm not sure we'll ever be called in this case.
9602 If a local watchpoint's frame id is still valid, then
9603 b->exp_valid_block is likewise valid, and we can safely use it.
9605 Don't do anything about disabled watchpoints, since they will
9606 be reevaluated again when enabled. */
9607 update_watchpoint (b
, 1 /* reparse */);
9609 /* We needn't really do anything to reset these, since the mask
9610 that requests them is unaffected by e.g., new libraries being
9616 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9618 /* Delete overlay event and longjmp master breakpoints; they will be
9619 reset later by breakpoint_re_set. */
9620 case bp_overlay_event
:
9621 case bp_longjmp_master
:
9622 case bp_std_terminate_master
:
9623 delete_breakpoint (b
);
9626 /* This breakpoint is special, it's set up when the inferior
9627 starts and we really don't want to touch it. */
9628 case bp_shlib_event
:
9630 /* Like bp_shlib_event, this breakpoint type is special.
9631 Once it is set up, we do not want to touch it. */
9632 case bp_thread_event
:
9634 /* Keep temporary breakpoints, which can be encountered when we step
9635 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9636 Otherwise these should have been blown away via the cleanup chain
9637 or by breakpoint_init_inferior when we rerun the executable. */
9640 case bp_watchpoint_scope
:
9642 case bp_std_terminate
:
9643 case bp_step_resume
:
9645 case bp_longjmp_resume
:
9650 do_cleanups (cleanups
);
9654 /* Re-set all breakpoints after symbols have been re-loaded. */
9656 breakpoint_re_set (void)
9658 struct breakpoint
*b
, *temp
;
9659 enum language save_language
;
9660 int save_input_radix
;
9661 struct cleanup
*old_chain
;
9663 save_language
= current_language
->la_language
;
9664 save_input_radix
= input_radix
;
9665 old_chain
= save_current_program_space ();
9667 ALL_BREAKPOINTS_SAFE (b
, temp
)
9669 /* Format possible error msg */
9670 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9672 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9673 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9674 do_cleanups (cleanups
);
9676 set_language (save_language
);
9677 input_radix
= save_input_radix
;
9679 jit_breakpoint_re_set ();
9681 do_cleanups (old_chain
);
9683 create_overlay_event_breakpoint ("_ovly_debug_event");
9684 create_longjmp_master_breakpoint ("longjmp");
9685 create_longjmp_master_breakpoint ("_longjmp");
9686 create_longjmp_master_breakpoint ("siglongjmp");
9687 create_longjmp_master_breakpoint ("_siglongjmp");
9688 create_std_terminate_master_breakpoint ("std::terminate()");
9691 /* Reset the thread number of this breakpoint:
9693 - If the breakpoint is for all threads, leave it as-is.
9694 - Else, reset it to the current thread for inferior_ptid. */
9696 breakpoint_re_set_thread (struct breakpoint
*b
)
9698 if (b
->thread
!= -1)
9700 if (in_thread_list (inferior_ptid
))
9701 b
->thread
= pid_to_thread_id (inferior_ptid
);
9703 /* We're being called after following a fork. The new fork is
9704 selected as current, and unless this was a vfork will have a
9705 different program space from the original thread. Reset that
9707 b
->loc
->pspace
= current_program_space
;
9711 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9712 If from_tty is nonzero, it prints a message to that effect,
9713 which ends with a period (no newline). */
9716 set_ignore_count (int bptnum
, int count
, int from_tty
)
9718 struct breakpoint
*b
;
9724 if (b
->number
== bptnum
)
9726 if (is_tracepoint (b
))
9728 if (from_tty
&& count
!= 0)
9729 printf_filtered (_("Ignore count ignored for tracepoint %d."),
9734 b
->ignore_count
= count
;
9738 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9740 else if (count
== 1)
9741 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9744 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9747 breakpoints_changed ();
9748 observer_notify_breakpoint_modified (b
->number
);
9752 error (_("No breakpoint number %d."), bptnum
);
9756 make_breakpoint_silent (struct breakpoint
*b
)
9758 /* Silence the breakpoint. */
9762 /* Command to set ignore-count of breakpoint N to COUNT. */
9765 ignore_command (char *args
, int from_tty
)
9771 error_no_arg (_("a breakpoint number"));
9773 num
= get_number (&p
);
9775 error (_("bad breakpoint number: '%s'"), args
);
9777 error (_("Second argument (specified ignore-count) is missing."));
9779 set_ignore_count (num
,
9780 longest_to_int (value_as_long (parse_and_eval (p
))),
9783 printf_filtered ("\n");
9786 /* Call FUNCTION on each of the breakpoints
9787 whose numbers are given in ARGS. */
9790 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9797 struct breakpoint
*b
, *tmp
;
9801 error_no_arg (_("one or more breakpoint numbers"));
9808 num
= get_number_or_range (&p1
);
9811 warning (_("bad breakpoint number at or near '%s'"), p
);
9815 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9816 if (b
->number
== num
)
9818 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9821 if (related_breakpoint
)
9822 function (related_breakpoint
, data
);
9826 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9832 static struct bp_location
*
9833 find_location_by_number (char *number
)
9835 char *dot
= strchr (number
, '.');
9839 struct breakpoint
*b
;
9840 struct bp_location
*loc
;
9845 bp_num
= get_number_or_range (&p1
);
9847 error (_("Bad breakpoint number '%s'"), number
);
9850 if (b
->number
== bp_num
)
9855 if (!b
|| b
->number
!= bp_num
)
9856 error (_("Bad breakpoint number '%s'"), number
);
9859 loc_num
= get_number_or_range (&p1
);
9861 error (_("Bad breakpoint location number '%s'"), number
);
9865 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9868 error (_("Bad breakpoint location number '%s'"), dot
+1);
9874 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9875 If from_tty is nonzero, it prints a message to that effect,
9876 which ends with a period (no newline). */
9879 disable_breakpoint (struct breakpoint
*bpt
)
9881 /* Never disable a watchpoint scope breakpoint; we want to
9882 hit them when we leave scope so we can delete both the
9883 watchpoint and its scope breakpoint at that time. */
9884 if (bpt
->type
== bp_watchpoint_scope
)
9887 /* You can't disable permanent breakpoints. */
9888 if (bpt
->enable_state
== bp_permanent
)
9891 bpt
->enable_state
= bp_disabled
;
9893 update_global_location_list (0);
9895 observer_notify_breakpoint_modified (bpt
->number
);
9898 /* A callback for map_breakpoint_numbers that calls
9899 disable_breakpoint. */
9902 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9904 disable_breakpoint (b
);
9908 disable_command (char *args
, int from_tty
)
9910 struct breakpoint
*bpt
;
9912 ALL_BREAKPOINTS (bpt
)
9916 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9921 case bp_fast_tracepoint
:
9923 case bp_hardware_breakpoint
:
9925 case bp_hardware_watchpoint
:
9926 case bp_read_watchpoint
:
9927 case bp_access_watchpoint
:
9928 disable_breakpoint (bpt
);
9932 else if (strchr (args
, '.'))
9934 struct bp_location
*loc
= find_location_by_number (args
);
9937 update_global_location_list (0);
9940 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9944 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9946 int target_resources_ok
, other_type_used
;
9949 if (bpt
->type
== bp_hardware_breakpoint
)
9952 i
= hw_breakpoint_used_count ();
9953 target_resources_ok
=
9954 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9956 if (target_resources_ok
== 0)
9957 error (_("No hardware breakpoint support in the target."));
9958 else if (target_resources_ok
< 0)
9959 error (_("Hardware breakpoints used exceeds limit."));
9962 if (is_watchpoint (bpt
))
9964 struct gdb_exception e
;
9966 TRY_CATCH (e
, RETURN_MASK_ALL
)
9968 update_watchpoint (bpt
, 1 /* reparse */);
9972 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9978 if (bpt
->enable_state
!= bp_permanent
)
9979 bpt
->enable_state
= bp_enabled
;
9980 bpt
->disposition
= disposition
;
9981 update_global_location_list (1);
9982 breakpoints_changed ();
9984 observer_notify_breakpoint_modified (bpt
->number
);
9989 enable_breakpoint (struct breakpoint
*bpt
)
9991 do_enable_breakpoint (bpt
, bpt
->disposition
);
9994 /* A callback for map_breakpoint_numbers that calls
9995 enable_breakpoint. */
9998 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10000 enable_breakpoint (b
);
10003 /* The enable command enables the specified breakpoints (or all defined
10004 breakpoints) so they once again become (or continue to be) effective
10005 in stopping the inferior. */
10008 enable_command (char *args
, int from_tty
)
10010 struct breakpoint
*bpt
;
10012 ALL_BREAKPOINTS (bpt
)
10016 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10019 case bp_breakpoint
:
10020 case bp_tracepoint
:
10021 case bp_fast_tracepoint
:
10022 case bp_catchpoint
:
10023 case bp_hardware_breakpoint
:
10024 case bp_watchpoint
:
10025 case bp_hardware_watchpoint
:
10026 case bp_read_watchpoint
:
10027 case bp_access_watchpoint
:
10028 enable_breakpoint (bpt
);
10032 else if (strchr (args
, '.'))
10034 struct bp_location
*loc
= find_location_by_number (args
);
10037 update_global_location_list (1);
10040 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10044 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10046 do_enable_breakpoint (bpt
, disp_disable
);
10050 enable_once_command (char *args
, int from_tty
)
10052 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10056 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10058 do_enable_breakpoint (bpt
, disp_del
);
10062 enable_delete_command (char *args
, int from_tty
)
10064 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10068 set_breakpoint_cmd (char *args
, int from_tty
)
10073 show_breakpoint_cmd (char *args
, int from_tty
)
10077 /* Invalidate last known value of any hardware watchpoint if
10078 the memory which that value represents has been written to by
10082 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10083 const bfd_byte
*data
)
10085 struct breakpoint
*bp
;
10087 ALL_BREAKPOINTS (bp
)
10088 if (bp
->enable_state
== bp_enabled
10089 && bp
->type
== bp_hardware_watchpoint
10090 && bp
->val_valid
&& bp
->val
)
10092 struct bp_location
*loc
;
10094 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10095 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10096 && loc
->address
+ loc
->length
> addr
10097 && addr
+ len
> loc
->address
)
10099 value_free (bp
->val
);
10106 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10108 struct symtabs_and_lines
10109 decode_line_spec_1 (char *string
, int funfirstline
)
10111 struct symtabs_and_lines sals
;
10113 error (_("Empty line specification."));
10114 if (default_breakpoint_valid
)
10115 sals
= decode_line_1 (&string
, funfirstline
,
10116 default_breakpoint_symtab
,
10117 default_breakpoint_line
,
10118 (char ***) NULL
, NULL
);
10120 sals
= decode_line_1 (&string
, funfirstline
,
10121 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10123 error (_("Junk at end of line specification: %s"), string
);
10127 /* Create and insert a raw software breakpoint at PC. Return an
10128 identifier, which should be used to remove the breakpoint later.
10129 In general, places which call this should be using something on the
10130 breakpoint chain instead; this function should be eliminated
10134 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10135 struct address_space
*aspace
, CORE_ADDR pc
)
10137 struct bp_target_info
*bp_tgt
;
10139 bp_tgt
= XZALLOC (struct bp_target_info
);
10141 bp_tgt
->placed_address_space
= aspace
;
10142 bp_tgt
->placed_address
= pc
;
10144 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10146 /* Could not insert the breakpoint. */
10154 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10157 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10159 struct bp_target_info
*bp_tgt
= bp
;
10162 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10168 /* One (or perhaps two) breakpoints used for software single stepping. */
10170 static void *single_step_breakpoints
[2];
10171 static struct gdbarch
*single_step_gdbarch
[2];
10173 /* Create and insert a breakpoint for software single step. */
10176 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10177 struct address_space
*aspace
, CORE_ADDR next_pc
)
10181 if (single_step_breakpoints
[0] == NULL
)
10183 bpt_p
= &single_step_breakpoints
[0];
10184 single_step_gdbarch
[0] = gdbarch
;
10188 gdb_assert (single_step_breakpoints
[1] == NULL
);
10189 bpt_p
= &single_step_breakpoints
[1];
10190 single_step_gdbarch
[1] = gdbarch
;
10193 /* NOTE drow/2006-04-11: A future improvement to this function would be
10194 to only create the breakpoints once, and actually put them on the
10195 breakpoint chain. That would let us use set_raw_breakpoint. We could
10196 adjust the addresses each time they were needed. Doing this requires
10197 corresponding changes elsewhere where single step breakpoints are
10198 handled, however. So, for now, we use this. */
10200 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10201 if (*bpt_p
== NULL
)
10202 error (_("Could not insert single-step breakpoint at %s"),
10203 paddress (gdbarch
, next_pc
));
10206 /* Remove and delete any breakpoints used for software single step. */
10209 remove_single_step_breakpoints (void)
10211 gdb_assert (single_step_breakpoints
[0] != NULL
);
10213 /* See insert_single_step_breakpoint for more about this deprecated
10215 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10216 single_step_breakpoints
[0]);
10217 single_step_gdbarch
[0] = NULL
;
10218 single_step_breakpoints
[0] = NULL
;
10220 if (single_step_breakpoints
[1] != NULL
)
10222 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10223 single_step_breakpoints
[1]);
10224 single_step_gdbarch
[1] = NULL
;
10225 single_step_breakpoints
[1] = NULL
;
10229 /* Check whether a software single-step breakpoint is inserted at PC. */
10232 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10236 for (i
= 0; i
< 2; i
++)
10238 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10240 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10241 bp_tgt
->placed_address
,
10249 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10250 non-zero otherwise. */
10252 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10254 if (syscall_catchpoint_p (bp
)
10255 && bp
->enable_state
!= bp_disabled
10256 && bp
->enable_state
!= bp_call_disabled
)
10263 catch_syscall_enabled (void)
10265 struct inferior
*inf
= current_inferior ();
10267 return inf
->total_syscalls_count
!= 0;
10271 catching_syscall_number (int syscall_number
)
10273 struct breakpoint
*bp
;
10275 ALL_BREAKPOINTS (bp
)
10276 if (is_syscall_catchpoint_enabled (bp
))
10278 if (bp
->syscalls_to_be_caught
)
10282 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10284 if (syscall_number
== iter
)
10294 /* Complete syscall names. Used by "catch syscall". */
10296 catch_syscall_completer (struct cmd_list_element
*cmd
,
10297 char *text
, char *word
)
10299 const char **list
= get_syscall_names ();
10300 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10303 /* Tracepoint-specific operations. */
10305 /* Set tracepoint count to NUM. */
10307 set_tracepoint_count (int num
)
10309 tracepoint_count
= num
;
10310 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10314 trace_command (char *arg
, int from_tty
)
10316 if (create_breakpoint (get_current_arch (),
10318 NULL
, 0, 1 /* parse arg */,
10319 0 /* tempflag */, 0 /* hardwareflag */,
10321 0 /* Ignore count */,
10322 pending_break_support
,
10326 set_tracepoint_count (breakpoint_count
);
10330 ftrace_command (char *arg
, int from_tty
)
10332 if (create_breakpoint (get_current_arch (),
10334 NULL
, 0, 1 /* parse arg */,
10335 0 /* tempflag */, 1 /* hardwareflag */,
10337 0 /* Ignore count */,
10338 pending_break_support
,
10342 set_tracepoint_count (breakpoint_count
);
10345 /* Set up a fake reader function that gets command lines from a linked
10346 list that was acquired during tracepoint uploading. */
10348 static struct uploaded_tp
*this_utp
;
10349 static int next_cmd
;
10352 read_uploaded_action (void)
10356 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
10363 /* Given information about a tracepoint as recorded on a target (which
10364 can be either a live system or a trace file), attempt to create an
10365 equivalent GDB tracepoint. This is not a reliable process, since
10366 the target does not necessarily have all the information used when
10367 the tracepoint was originally defined. */
10369 struct breakpoint
*
10370 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10372 char *addr_str
, small_buf
[100];
10373 struct breakpoint
*tp
;
10375 if (utp
->at_string
)
10376 addr_str
= utp
->at_string
;
10379 /* In the absence of a source location, fall back to raw
10380 address. Since there is no way to confirm that the address
10381 means the same thing as when the trace was started, warn the
10383 warning (_("Uploaded tracepoint %d has no source location, using raw address"),
10385 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
10386 addr_str
= small_buf
;
10389 /* There's not much we can do with a sequence of bytecodes. */
10390 if (utp
->cond
&& !utp
->cond_string
)
10391 warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"),
10394 if (!create_breakpoint (get_current_arch (),
10396 utp
->cond_string
, -1, 0 /* parse cond/thread */,
10398 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10400 0 /* Ignore count */,
10401 pending_break_support
,
10404 utp
->enabled
/* enabled */))
10407 set_tracepoint_count (breakpoint_count
);
10409 /* Get the tracepoint we just created. */
10410 tp
= get_tracepoint (tracepoint_count
);
10411 gdb_assert (tp
!= NULL
);
10415 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
10417 trace_pass_command (small_buf
, 0);
10420 /* If we have uploaded versions of the original commands, set up a
10421 special-purpose "reader" function and call the usual command line
10422 reader, then pass the result to the breakpoint command-setting
10424 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
10426 struct command_line
*cmd_list
;
10431 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
10433 breakpoint_set_commands (tp
, cmd_list
);
10435 else if (!VEC_empty (char_ptr
, utp
->actions
)
10436 || !VEC_empty (char_ptr
, utp
->step_actions
))
10437 warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"),
10443 /* Print information on tracepoint number TPNUM_EXP, or all if
10447 tracepoints_info (char *tpnum_exp
, int from_tty
)
10449 int tpnum
= -1, num_printed
;
10452 tpnum
= parse_and_eval_long (tpnum_exp
);
10454 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
10456 if (num_printed
== 0)
10459 ui_out_message (uiout
, 0, "No tracepoints.\n");
10461 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
10464 default_collect_info ();
10467 /* The 'enable trace' command enables tracepoints.
10468 Not supported by all targets. */
10470 enable_trace_command (char *args
, int from_tty
)
10472 enable_command (args
, from_tty
);
10475 /* The 'disable trace' command disables tracepoints.
10476 Not supported by all targets. */
10478 disable_trace_command (char *args
, int from_tty
)
10480 disable_command (args
, from_tty
);
10483 /* Remove a tracepoint (or all if no argument) */
10485 delete_trace_command (char *arg
, int from_tty
)
10487 struct breakpoint
*b
, *temp
;
10493 int breaks_to_delete
= 0;
10495 /* Delete all breakpoints if no argument.
10496 Do not delete internal or call-dummy breakpoints, these
10497 have to be deleted with an explicit breakpoint number argument. */
10498 ALL_TRACEPOINTS (b
)
10500 if (b
->number
>= 0)
10502 breaks_to_delete
= 1;
10507 /* Ask user only if there are some breakpoints to delete. */
10509 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10511 ALL_BREAKPOINTS_SAFE (b
, temp
)
10513 if (is_tracepoint (b
)
10515 delete_breakpoint (b
);
10520 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10523 /* Set passcount for tracepoint.
10525 First command argument is passcount, second is tracepoint number.
10526 If tracepoint number omitted, apply to most recently defined.
10527 Also accepts special argument "all". */
10530 trace_pass_command (char *args
, int from_tty
)
10532 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10533 unsigned int count
;
10536 if (args
== 0 || *args
== 0)
10537 error (_("passcount command requires an argument (count + optional TP num)"));
10539 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10541 while (*args
&& isspace ((int) *args
))
10544 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10546 args
+= 3; /* Skip special argument "all". */
10549 error (_("Junk at end of arguments."));
10552 t1
= get_tracepoint_by_number (&args
, 1, 1);
10558 ALL_TRACEPOINTS (t2
)
10559 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10561 t2
->pass_count
= count
;
10562 observer_notify_tracepoint_modified (t2
->number
);
10564 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10565 t2
->number
, count
);
10567 if (! all
&& *args
)
10568 t1
= get_tracepoint_by_number (&args
, 1, 0);
10574 struct breakpoint
*
10575 get_tracepoint (int num
)
10577 struct breakpoint
*t
;
10579 ALL_TRACEPOINTS (t
)
10580 if (t
->number
== num
)
10586 /* Find the tracepoint with the given target-side number (which may be
10587 different from the tracepoint number after disconnecting and
10590 struct breakpoint
*
10591 get_tracepoint_by_number_on_target (int num
)
10593 struct breakpoint
*t
;
10595 ALL_TRACEPOINTS (t
)
10596 if (t
->number_on_target
== num
)
10602 /* Utility: parse a tracepoint number and look it up in the list.
10603 If MULTI_P is true, there might be a range of tracepoints in ARG.
10604 if OPTIONAL_P is true, then if the argument is missing, the most
10605 recent tracepoint (tracepoint_count) is returned. */
10606 struct breakpoint
*
10607 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10609 extern int tracepoint_count
;
10610 struct breakpoint
*t
;
10612 char *instring
= arg
== NULL
? NULL
: *arg
;
10614 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10617 tpnum
= tracepoint_count
;
10619 error_no_arg (_("tracepoint number"));
10622 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10626 if (instring
&& *instring
)
10627 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10630 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10634 ALL_TRACEPOINTS (t
)
10635 if (t
->number
== tpnum
)
10640 /* FIXME: if we are in the middle of a range we don't want to give
10641 a message. The current interface to get_number_or_range doesn't
10642 allow us to discover this. */
10643 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10647 /* save-tracepoints command */
10649 tracepoint_save_command (char *args
, int from_tty
)
10651 struct breakpoint
*tp
;
10653 struct command_line
*line
;
10656 struct cleanup
*cleanup
;
10657 struct ui_file
*fp
;
10659 if (args
== 0 || *args
== 0)
10660 error (_("Argument required (file name in which to save tracepoints)"));
10662 /* See if we have anything to save. */
10663 ALL_TRACEPOINTS (tp
)
10670 warning (_("save-tracepoints: no tracepoints to save."));
10674 pathname
= tilde_expand (args
);
10675 cleanup
= make_cleanup (xfree
, pathname
);
10676 fp
= gdb_fopen (pathname
, "w");
10678 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10679 args
, safe_strerror (errno
));
10680 make_cleanup_ui_file_delete (fp
);
10682 save_trace_state_variables (fp
);
10684 ALL_TRACEPOINTS (tp
)
10686 if (tp
->type
== bp_fast_tracepoint
)
10687 fprintf_unfiltered (fp
, "ftrace");
10689 fprintf_unfiltered (fp
, "trace");
10691 if (tp
->addr_string
)
10692 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10695 sprintf_vma (tmp
, tp
->loc
->address
);
10696 fprintf_unfiltered (fp
, " *0x%s", tmp
);
10699 if (tp
->cond_string
)
10700 fprintf_unfiltered (fp
, " if %s", tp
->cond_string
);
10702 fprintf_unfiltered (fp
, "\n");
10704 if (tp
->pass_count
)
10705 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10709 volatile struct gdb_exception ex
;
10711 fprintf_unfiltered (fp
, " actions\n");
10713 ui_out_redirect (uiout
, fp
);
10714 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10716 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10718 ui_out_redirect (uiout
, NULL
);
10721 throw_exception (ex
);
10723 fprintf_unfiltered (fp
, " end\n");
10727 if (*default_collect
)
10728 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
10730 do_cleanups (cleanup
);
10732 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10736 /* Create a vector of all tracepoints. */
10738 VEC(breakpoint_p
) *
10741 VEC(breakpoint_p
) *tp_vec
= 0;
10742 struct breakpoint
*tp
;
10744 ALL_TRACEPOINTS (tp
)
10746 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10753 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10754 It is defined as a macro to prevent duplication.
10755 COMMAND should be a string constant containing the name of the command. */
10756 #define BREAK_ARGS_HELP(command) \
10757 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10758 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10759 If a line number is specified, break at start of code for that line.\n\
10760 If a function is specified, break at start of code for that function.\n\
10761 If an address is specified, break at that exact address.\n\
10762 With no LOCATION, uses current execution address of selected stack frame.\n\
10763 This is useful for breaking on return to a stack frame.\n\
10765 THREADNUM is the number from \"info threads\".\n\
10766 CONDITION is a boolean expression.\n\
10768 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10770 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10772 /* List of subcommands for "catch". */
10773 static struct cmd_list_element
*catch_cmdlist
;
10775 /* List of subcommands for "tcatch". */
10776 static struct cmd_list_element
*tcatch_cmdlist
;
10778 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10779 lists, and pass some additional user data to the command function. */
10781 add_catch_command (char *name
, char *docstring
,
10782 void (*sfunc
) (char *args
, int from_tty
,
10783 struct cmd_list_element
*command
),
10784 char **(*completer
) (struct cmd_list_element
*cmd
,
10785 char *text
, char *word
),
10786 void *user_data_catch
,
10787 void *user_data_tcatch
)
10789 struct cmd_list_element
*command
;
10791 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10793 set_cmd_sfunc (command
, sfunc
);
10794 set_cmd_context (command
, user_data_catch
);
10795 set_cmd_completer (command
, completer
);
10797 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10799 set_cmd_sfunc (command
, sfunc
);
10800 set_cmd_context (command
, user_data_tcatch
);
10801 set_cmd_completer (command
, completer
);
10805 clear_syscall_counts (struct inferior
*inf
)
10807 inf
->total_syscalls_count
= 0;
10808 inf
->any_syscall_count
= 0;
10809 VEC_free (int, inf
->syscalls_counts
);
10813 _initialize_breakpoint (void)
10815 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10816 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10817 struct cmd_list_element
*c
;
10819 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10820 observer_attach_inferior_exit (clear_syscall_counts
);
10821 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10823 breakpoint_chain
= 0;
10824 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10825 before a breakpoint is set. */
10826 breakpoint_count
= 0;
10828 tracepoint_count
= 0;
10830 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10831 Set ignore-count of breakpoint number N to COUNT.\n\
10832 Usage is `ignore N COUNT'."));
10834 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10836 add_com ("commands", class_breakpoint
, commands_command
, _("\
10837 Set commands to be executed when a breakpoint is hit.\n\
10838 Give breakpoint number as argument after \"commands\".\n\
10839 With no argument, the targeted breakpoint is the last one set.\n\
10840 The commands themselves follow starting on the next line.\n\
10841 Type a line containing \"end\" to indicate the end of them.\n\
10842 Give \"silent\" as the first line to make the breakpoint silent;\n\
10843 then no output is printed when it is hit, except what the commands print."));
10845 add_com ("condition", class_breakpoint
, condition_command
, _("\
10846 Specify breakpoint number N to break only if COND is true.\n\
10847 Usage is `condition N COND', where N is an integer and COND is an\n\
10848 expression to be evaluated whenever breakpoint N is reached."));
10850 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10851 Set a temporary breakpoint.\n\
10852 Like \"break\" except the breakpoint is only temporary,\n\
10853 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10854 by using \"enable delete\" on the breakpoint number.\n\
10856 BREAK_ARGS_HELP ("tbreak")));
10857 set_cmd_completer (c
, location_completer
);
10859 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10860 Set a hardware assisted breakpoint.\n\
10861 Like \"break\" except the breakpoint requires hardware support,\n\
10862 some target hardware may not have this support.\n\
10864 BREAK_ARGS_HELP ("hbreak")));
10865 set_cmd_completer (c
, location_completer
);
10867 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10868 Set a temporary hardware assisted breakpoint.\n\
10869 Like \"hbreak\" except the breakpoint is only temporary,\n\
10870 so it will be deleted when hit.\n\
10872 BREAK_ARGS_HELP ("thbreak")));
10873 set_cmd_completer (c
, location_completer
);
10875 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10876 Enable some breakpoints.\n\
10877 Give breakpoint numbers (separated by spaces) as arguments.\n\
10878 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10879 This is used to cancel the effect of the \"disable\" command.\n\
10880 With a subcommand you can enable temporarily."),
10881 &enablelist
, "enable ", 1, &cmdlist
);
10883 add_com ("ab", class_breakpoint
, enable_command
, _("\
10884 Enable some breakpoints.\n\
10885 Give breakpoint numbers (separated by spaces) as arguments.\n\
10886 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10887 This is used to cancel the effect of the \"disable\" command.\n\
10888 With a subcommand you can enable temporarily."));
10890 add_com_alias ("en", "enable", class_breakpoint
, 1);
10892 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10893 Enable some breakpoints.\n\
10894 Give breakpoint numbers (separated by spaces) as arguments.\n\
10895 This is used to cancel the effect of the \"disable\" command.\n\
10896 May be abbreviated to simply \"enable\".\n"),
10897 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10899 add_cmd ("once", no_class
, enable_once_command
, _("\
10900 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10901 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10904 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10905 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10906 If a breakpoint is hit while enabled in this fashion, it is deleted."),
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 ("once", no_class
, enable_once_command
, _("\
10915 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10916 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10919 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10920 Disable some breakpoints.\n\
10921 Arguments are breakpoint numbers with spaces in between.\n\
10922 To disable all breakpoints, give no argument.\n\
10923 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10924 &disablelist
, "disable ", 1, &cmdlist
);
10925 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10926 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10928 add_com ("sb", class_breakpoint
, disable_command
, _("\
10929 Disable some breakpoints.\n\
10930 Arguments are breakpoint numbers with spaces in between.\n\
10931 To disable all breakpoints, give no argument.\n\
10932 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10934 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10935 Disable some breakpoints.\n\
10936 Arguments are breakpoint numbers with spaces in between.\n\
10937 To disable all breakpoints, give no argument.\n\
10938 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10939 This command may be abbreviated \"disable\"."),
10942 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10943 Delete some breakpoints or auto-display expressions.\n\
10944 Arguments are breakpoint numbers with spaces in between.\n\
10945 To delete all breakpoints, give no argument.\n\
10947 Also a prefix command for deletion of other GDB objects.\n\
10948 The \"unset\" command is also an alias for \"delete\"."),
10949 &deletelist
, "delete ", 1, &cmdlist
);
10950 add_com_alias ("d", "delete", class_breakpoint
, 1);
10951 add_com_alias ("del", "delete", class_breakpoint
, 1);
10953 add_com ("db", class_breakpoint
, delete_command
, _("\
10954 Delete some breakpoints.\n\
10955 Arguments are breakpoint numbers with spaces in between.\n\
10956 To delete all breakpoints, give no argument.\n"));
10958 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10959 Delete some breakpoints or auto-display expressions.\n\
10960 Arguments are breakpoint numbers with spaces in between.\n\
10961 To delete all breakpoints, give no argument.\n\
10962 This command may be abbreviated \"delete\"."),
10965 add_com ("clear", class_breakpoint
, clear_command
, _("\
10966 Clear breakpoint at specified line or function.\n\
10967 Argument may be line number, function name, or \"*\" and an address.\n\
10968 If line number is specified, all breakpoints in that line are cleared.\n\
10969 If function is specified, breakpoints at beginning of function are cleared.\n\
10970 If an address is specified, breakpoints at that address are cleared.\n\
10972 With no argument, clears all breakpoints in the line that the selected frame\n\
10973 is executing in.\n\
10975 See also the \"delete\" command which clears breakpoints by number."));
10977 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10978 Set breakpoint at specified line or function.\n"
10979 BREAK_ARGS_HELP ("break")));
10980 set_cmd_completer (c
, location_completer
);
10982 add_com_alias ("b", "break", class_run
, 1);
10983 add_com_alias ("br", "break", class_run
, 1);
10984 add_com_alias ("bre", "break", class_run
, 1);
10985 add_com_alias ("brea", "break", class_run
, 1);
10988 add_com_alias ("ba", "break", class_breakpoint
, 1);
10992 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10993 Break in function/address or break at a line in the current file."),
10994 &stoplist
, "stop ", 1, &cmdlist
);
10995 add_cmd ("in", class_breakpoint
, stopin_command
,
10996 _("Break in function or address."), &stoplist
);
10997 add_cmd ("at", class_breakpoint
, stopat_command
,
10998 _("Break at a line in the current file."), &stoplist
);
10999 add_com ("status", class_info
, breakpoints_info
, _("\
11000 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11001 The \"Type\" column indicates one of:\n\
11002 \tbreakpoint - normal breakpoint\n\
11003 \twatchpoint - watchpoint\n\
11004 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11005 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11006 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11007 address and file/line number respectively.\n\
11009 Convenience variable \"$_\" and default examine address for \"x\"\n\
11010 are set to the address of the last breakpoint listed unless the command\n\
11011 is prefixed with \"server \".\n\n\
11012 Convenience variable \"$bpnum\" contains the number of the last\n\
11013 breakpoint set."));
11016 add_info ("breakpoints", breakpoints_info
, _("\
11017 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11018 The \"Type\" column indicates one of:\n\
11019 \tbreakpoint - normal breakpoint\n\
11020 \twatchpoint - watchpoint\n\
11021 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11022 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11023 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11024 address and file/line number respectively.\n\
11026 Convenience variable \"$_\" and default examine address for \"x\"\n\
11027 are set to the address of the last breakpoint listed unless the command\n\
11028 is prefixed with \"server \".\n\n\
11029 Convenience variable \"$bpnum\" contains the number of the last\n\
11030 breakpoint set."));
11032 add_info_alias ("b", "breakpoints", 1);
11035 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11036 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11037 The \"Type\" column indicates one of:\n\
11038 \tbreakpoint - normal breakpoint\n\
11039 \twatchpoint - watchpoint\n\
11040 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11041 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11042 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11043 address and file/line number respectively.\n\
11045 Convenience variable \"$_\" and default examine address for \"x\"\n\
11046 are set to the address of the last breakpoint listed unless the command\n\
11047 is prefixed with \"server \".\n\n\
11048 Convenience variable \"$bpnum\" contains the number of the last\n\
11049 breakpoint set."));
11051 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11052 Status of all breakpoints, or breakpoint number NUMBER.\n\
11053 The \"Type\" column indicates one of:\n\
11054 \tbreakpoint - normal breakpoint\n\
11055 \twatchpoint - watchpoint\n\
11056 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11057 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11058 \tuntil - internal breakpoint used by the \"until\" command\n\
11059 \tfinish - internal breakpoint used by the \"finish\" command\n\
11060 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11061 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11062 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11063 address and file/line number respectively.\n\
11065 Convenience variable \"$_\" and default examine address for \"x\"\n\
11066 are set to the address of the last breakpoint listed unless the command\n\
11067 is prefixed with \"server \".\n\n\
11068 Convenience variable \"$bpnum\" contains the number of the last\n\
11070 &maintenanceinfolist
);
11072 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11073 Set catchpoints to catch events."),
11074 &catch_cmdlist
, "catch ",
11075 0/*allow-unknown*/, &cmdlist
);
11077 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11078 Set temporary catchpoints to catch events."),
11079 &tcatch_cmdlist
, "tcatch ",
11080 0/*allow-unknown*/, &cmdlist
);
11082 /* Add catch and tcatch sub-commands. */
11083 add_catch_command ("catch", _("\
11084 Catch an exception, when caught.\n\
11085 With an argument, catch only exceptions with the given name."),
11086 catch_catch_command
,
11090 add_catch_command ("throw", _("\
11091 Catch an exception, when thrown.\n\
11092 With an argument, catch only exceptions with the given name."),
11093 catch_throw_command
,
11097 add_catch_command ("fork", _("Catch calls to fork."),
11098 catch_fork_command_1
,
11100 (void *) (uintptr_t) catch_fork_permanent
,
11101 (void *) (uintptr_t) catch_fork_temporary
);
11102 add_catch_command ("vfork", _("Catch calls to vfork."),
11103 catch_fork_command_1
,
11105 (void *) (uintptr_t) catch_vfork_permanent
,
11106 (void *) (uintptr_t) catch_vfork_temporary
);
11107 add_catch_command ("exec", _("Catch calls to exec."),
11108 catch_exec_command_1
,
11112 add_catch_command ("syscall", _("\
11113 Catch system calls by their names and/or numbers.\n\
11114 Arguments say which system calls to catch. If no arguments\n\
11115 are given, every system call will be caught.\n\
11116 Arguments, if given, should be one or more system call names\n\
11117 (if your system supports that), or system call numbers."),
11118 catch_syscall_command_1
,
11119 catch_syscall_completer
,
11122 add_catch_command ("exception", _("\
11123 Catch Ada exceptions, when raised.\n\
11124 With an argument, catch only exceptions with the given name."),
11125 catch_ada_exception_command
,
11129 add_catch_command ("assert", _("\
11130 Catch failed Ada assertions, when raised.\n\
11131 With an argument, catch only exceptions with the given name."),
11132 catch_assert_command
,
11137 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11138 Set a watchpoint for an expression.\n\
11139 A watchpoint stops execution of your program whenever the value of\n\
11140 an expression changes."));
11141 set_cmd_completer (c
, expression_completer
);
11143 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11144 Set a read watchpoint for an expression.\n\
11145 A watchpoint stops execution of your program whenever the value of\n\
11146 an expression is read."));
11147 set_cmd_completer (c
, expression_completer
);
11149 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11150 Set a watchpoint for an expression.\n\
11151 A watchpoint stops execution of your program whenever the value of\n\
11152 an expression is either read or written."));
11153 set_cmd_completer (c
, expression_completer
);
11155 add_info ("watchpoints", watchpoints_info
, _("\
11156 Status of watchpoints, or watchpoint number NUMBER."));
11160 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11161 respond to changes - contrary to the description. */
11162 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11163 &can_use_hw_watchpoints
, _("\
11164 Set debugger's willingness to use watchpoint hardware."), _("\
11165 Show debugger's willingness to use watchpoint hardware."), _("\
11166 If zero, gdb will not use hardware for new watchpoints, even if\n\
11167 such is available. (However, any hardware watchpoints that were\n\
11168 created before setting this to nonzero, will continue to use watchpoint\n\
11171 show_can_use_hw_watchpoints
,
11172 &setlist
, &showlist
);
11174 can_use_hw_watchpoints
= 1;
11176 /* Tracepoint manipulation commands. */
11178 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11179 Set a tracepoint at specified line or function.\n\
11181 BREAK_ARGS_HELP ("trace") "\n\
11182 Do \"help tracepoints\" for info on other tracepoint commands."));
11183 set_cmd_completer (c
, location_completer
);
11185 add_com_alias ("tp", "trace", class_alias
, 0);
11186 add_com_alias ("tr", "trace", class_alias
, 1);
11187 add_com_alias ("tra", "trace", class_alias
, 1);
11188 add_com_alias ("trac", "trace", class_alias
, 1);
11190 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11191 Set a fast tracepoint at specified line or function.\n\
11193 BREAK_ARGS_HELP ("ftrace") "\n\
11194 Do \"help tracepoints\" for info on other tracepoint commands."));
11195 set_cmd_completer (c
, location_completer
);
11197 add_info ("tracepoints", tracepoints_info
, _("\
11198 Status of tracepoints, or tracepoint number NUMBER.\n\
11199 Convenience variable \"$tpnum\" contains the number of the\n\
11200 last tracepoint set."));
11202 add_info_alias ("tp", "tracepoints", 1);
11204 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11205 Delete specified tracepoints.\n\
11206 Arguments are tracepoint numbers, separated by spaces.\n\
11207 No argument means delete all tracepoints."),
11210 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11211 Disable specified tracepoints.\n\
11212 Arguments are tracepoint numbers, separated by spaces.\n\
11213 No argument means disable all tracepoints."),
11215 deprecate_cmd (c
, "disable");
11217 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11218 Enable specified tracepoints.\n\
11219 Arguments are tracepoint numbers, separated by spaces.\n\
11220 No argument means enable all tracepoints."),
11222 deprecate_cmd (c
, "enable");
11224 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11225 Set the passcount for a tracepoint.\n\
11226 The trace will end when the tracepoint has been passed 'count' times.\n\
11227 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11228 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11230 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11231 Save current tracepoint definitions as a script.\n\
11232 Use the 'source' command in another debug session to restore them."));
11233 set_cmd_completer (c
, filename_completer
);
11235 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11236 Breakpoint specific settings\n\
11237 Configure various breakpoint-specific variables such as\n\
11238 pending breakpoint behavior"),
11239 &breakpoint_set_cmdlist
, "set breakpoint ",
11240 0/*allow-unknown*/, &setlist
);
11241 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11242 Breakpoint specific settings\n\
11243 Configure various breakpoint-specific variables such as\n\
11244 pending breakpoint behavior"),
11245 &breakpoint_show_cmdlist
, "show breakpoint ",
11246 0/*allow-unknown*/, &showlist
);
11248 add_setshow_auto_boolean_cmd ("pending", no_class
,
11249 &pending_break_support
, _("\
11250 Set debugger's behavior regarding pending breakpoints."), _("\
11251 Show debugger's behavior regarding pending breakpoints."), _("\
11252 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11253 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11254 an error. If auto, an unrecognized breakpoint location results in a\n\
11255 user-query to see if a pending breakpoint should be created."),
11257 show_pending_break_support
,
11258 &breakpoint_set_cmdlist
,
11259 &breakpoint_show_cmdlist
);
11261 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11263 add_setshow_boolean_cmd ("auto-hw", no_class
,
11264 &automatic_hardware_breakpoints
, _("\
11265 Set automatic usage of hardware breakpoints."), _("\
11266 Show automatic usage of hardware breakpoints."), _("\
11267 If set, the debugger will automatically use hardware breakpoints for\n\
11268 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11269 a warning will be emitted for such breakpoints."),
11271 show_automatic_hardware_breakpoints
,
11272 &breakpoint_set_cmdlist
,
11273 &breakpoint_show_cmdlist
);
11275 add_setshow_enum_cmd ("always-inserted", class_support
,
11276 always_inserted_enums
, &always_inserted_mode
, _("\
11277 Set mode for inserting breakpoints."), _("\
11278 Show mode for inserting breakpoints."), _("\
11279 When this mode is off, breakpoints are inserted in inferior when it is\n\
11280 resumed, and removed when execution stops. When this mode is on,\n\
11281 breakpoints are inserted immediately and removed only when the user\n\
11282 deletes the breakpoint. When this mode is auto (which is the default),\n\
11283 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11284 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11285 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11286 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11288 &show_always_inserted_mode
,
11289 &breakpoint_set_cmdlist
,
11290 &breakpoint_show_cmdlist
);
11292 automatic_hardware_breakpoints
= 1;
11294 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);